diff --git a/conf/Gruntfile.js b/conf/Gruntfile.js index a6c6c7485d5db0cd7d11b9c5b36617c1b1c1ed5e..1b2bf24a44aa4f0dca8b4536c215a80680979e48 100755 --- a/conf/Gruntfile.js +++ b/conf/Gruntfile.js @@ -44,7 +44,9 @@ module.exports = function (grunt) { // Fichiers ANC sHome + 'modules/anc/javascript/**/*.js', // Fichiers suivi_prod_immo - sHome + 'modules/suivi_prod_immo/**/*.js' + sHome + 'modules/suivi_prod_immo/**/*.js', + // Fichiers patrimoine + sHome + 'modules/patrimoine/**/*.js', ] }, options: { @@ -129,6 +131,8 @@ module.exports = function (grunt) { '"' + sHome + 'modules/anc/javascript ' + sClosureDepsHome + 'modules/anc/javascript"', // Fichiers suivi_prod_immo '"' + sHome + 'modules/suivi_prod_immo ' + sClosureDepsHome + 'modules/suivi_prod_immo"', + // Fichiers patrimoine + '"' + sHome + 'modules/patrimoine ' + sClosureDepsHome + 'modules/patrimoine"', // Closure library '"' + sHome + 'conf/node_modules/google-closure-library/closure/goog ' + sClosureDepsHome + 'conf/node_modules/google-closure-library/closure/goog"' ] diff --git a/conf/closure/depswriter/source.pyc b/conf/closure/depswriter/source.pyc index 8cb70a6f55b18a17cb890b203e331a1391296b7d..84bbb039b8647836b7666d656e4c7650d88a8f53 100644 Binary files a/conf/closure/depswriter/source.pyc and b/conf/closure/depswriter/source.pyc differ diff --git a/conf/closure/depswriter/treescan.pyc b/conf/closure/depswriter/treescan.pyc index d347bd4532c0f1dcbabbbf47a7dcaf414c2371b4..44bd2d78f6e593e2d317dc2de9db1c3f3d600f34 100644 Binary files a/conf/closure/depswriter/treescan.pyc and b/conf/closure/depswriter/treescan.pyc differ diff --git a/src/module_suivi_prod_immo/web_service/ws/Ilots.class.inc b/src/module_suivi_prod_immo/web_service/ws/Ilots.class.inc index a5a553db751a136b53476f3e0c8cd10c41949bc1..a75c7a4b110b01c63a7711a6b1b9a262ea3dea63 100644 --- a/src/module_suivi_prod_immo/web_service/ws/Ilots.class.inc +++ b/src/module_suivi_prod_immo/web_service/ws/Ilots.class.inc @@ -1,322 +1,322 @@ -<?php - -/** - * \file Ilots.class.inc - * \class Ilots - * - * \author Fabien Marty <f.marty@urbalyon.org>. - * - * \brief This file contains the Ilots php class - * - * This class defines Rest Api to Vitis Ilots - * - */ -require_once __DIR__ . '/Suivi_prod_immo.class.inc'; -require_once 'Ilot.class.inc'; - - -class Ilots extends Suivi_prod_immo { - /** - * @SWG\Definition( - * definition="/ilots", - * allOf={ - * @SWG\Schema(ref="#/definitions/ilots") - * } - * ) - * * @SWG\Tag( - * name="Ilots", - * description="Ilots about Ilots" - * ) - */ - - /** - * construct - * @param type $aPath url of the request - * @param type $aValues parameters of the request - * @param type $properties properties - */ - function __construct($aPath, $aValues, $properties) { - $this->aValues = $aValues; - $this->aPath = $aPath; - $this->aProperties = $properties; - $this->oConnection = new Connection($this->aValues, $properties); - } - - /** - * @SWG\Get(path="/ilots", - * tags={"Ilots"}, - * summary="Get Ilots", - * description="Request to get Ilots", - * operationId="GET", - * produces={"application/xml", "application/json", "application/x-vm-json"}, - * @SWG\Parameter( - * name="token", - * in="query", - * description="user token", - * required=true, - * type="string" - * ), - * @SWG\Parameter( - * name="order_by", - * in="query", - * description="list of ordering fields", - * required=false, - * type="string" - * ), - * @SWG\Parameter( - * name="sort_order", - * in="query", - * description="sort_order", - * required=false, - * type="string" - * ), - * @SWG\Parameter( - * name="limit", - * in="query", - * description="number of element", - * required=false, - * type="integer", - * format="int32" - * ), - * @SWG\Parameter( - * name="offset", - * in="query", - * description="index of first element", - * required=false, - * type="string", - * format="int32" - * ), - * @SWG\Parameter( - * name="attributs", - * in="query", - * description="list of attributs", - * required=false, - * type="string" - * ), - * @SWG\Parameter( - * name="filter", - * in="query", - * description="filter results", - * required=false, - * type="string" - * ), - * @SWG\Parameter( - * name="distinct", - * in="query", - * description="delete duplicates", - * required=false, - * type="boolean" - * ), - * @SWG\Response( - * response=200, - * description="traitement Response", - * @SWG\Schema(ref="#/definitions/ilots") - * ) - * ) - */ - - /** - * get Ilots - * @return Ilots - */ - function GET(){ - if($this->setRestriction()){ - $aReturn = $this->genericGet('prod_immo', "ilot", "id_ilot"); - $sMessage = $aReturn['sMessage']; - return $sMessage; - }else{ - // si pas d'autorisation, on retourne une liste vide - return json_encode(array("list_count"=>0,"total_row_number"=>0,"status"=>1)); - } - } - - - /** - * set filter restriction for user connected - */ - function setRestriction(){ - require $this->sRessourcesFile; - $aParams = array(); - $aParams['sSchemaFramework'] = array('value' => 'prod_immo', 'type' => 'schema_name'); - $oPDOresult = $this->oConnection->oBd->executeWithParams($aSql['getRestrictionUpdate'], $aParams); - if($oPDOresult->rowCount()==1){ - // le user existe dans la table de restriction - $oPDOresult = $this->oConnection->oBd->fermeResultat(); - $oPDOresult2 = $this->oConnection->oBd->executeWithParams($aSql['getRestrictionUpdateIdOperation'], $aParams); - if($oPDOresult2->rowCount()>0){ - // il y a un ou plusieurs ID pour le user, on filtre - $aID=array(); - while ($aIdOperation = $this->oConnection->oBd->ligneSuivante($oPDOresult2)){ - $aID[] = $aIdOperation["id_operation"]; - } - $oPDOresult2 = $this->oConnection->oBd->fermeResultat(); - // injection du filtre - if (isset($this->aValues['filter'])){ - // il existe déjà un filtre - $aFilter=json_decode($this->aValues['filter'],true); - $aOperators=$aFilter['operators']; - $aOperators[]=array("column"=>"id_operation","compare_operator"=>"IN","value"=>$aID); - $aFilter['operators']=$aOperators; - $this->aValues['filter']=json_encode($aFilter); - }else{ - // il n'y a pas de filtre, on le crée - $this->aValues['filter']=json_encode(array('relation'=>'AND','operators'=>array(array("column"=>"id_operation","compare_operator"=>"IN","value"=>$aID)))); - } - return true; - }else{ - return false; - } - }else{ - // le user n'existe pas dans la table de restriction, on affiche rien - $oPDOresult = $this->oConnection->oBd->fermeResultat(); - error_log("Aucunes opérations autorisées en saisie, ajouter l'utilisateur dans la table prod_immo.user_restriction ."); - return false; - } - } - /** - * @SWG\Post(path="/ilots", - * tags={"Ilots"}, - * summary="Add traitement", - * description="Request to add Ilots", - * operationId="POST", - * produces={"application/xml", "application/json"}, - * @SWG\Parameter( - * name="token", - * in="query", - * description="user token", - * required=true, - * type="string" - * ), - * @SWG\Response( - * response=200, - * description="traitement Response", - * @SWG\Schema(ref="#/definitions/ilots") - * ) - * ) - */ - - /** - * insert traitement - * @return id of the traitement created - */ - function POST() { - //$this->aValues['create'] = $_SESSION["ses_Login"]; - //$this->aValues['create_date'] = date('Y-m-d'); - $aReturn = $this->genericPost('prod_immo', 'ilot', 'prod_immo.ilot_id_ilot_seq', 'id_ilot'); - return $aReturn['sMessage']; - } - - /** - * @SWG\Put(path="/ilots/{id_ilot}", - * tags={"Ilots"}, - * summary="update Ilots", - * description="Request to update Ilots", - * operationId="PUT", - * produces={"application/xml", "application/json"}, - * @SWG\Parameter( - * name="token", - * in="query", - * description="Traitement token", - * required=true, - * type="string" - * ), - * * @SWG\Parameter( - * name="id_ilot", - * in="path", - * description="id of the Ilots", - * required=true, - * type="integer", - * format = "int32" - * ), - * @SWG\Response( - * response=200, - * description="Poprerties Response", - * @SWG\Schema(ref="#/definitions/ilots") - * ) - * ) - */ - - /** - * update ilots - * @return id of ilots updated or error object if a ilots is not updated - */ - function PUT() { - /*if (empty($this->aValues['maj'])) - $this->aValues['maj'] = $_SESSION["ses_Login"]; - if (empty($this->aValues['maj_date'])) - $this->aValues['maj_date'] = date('Y-m-d');*/ - $aReturn = $this->genericPut('prod_immo', 'ilot', 'id_ilot'); - return $aReturn['sMessage']; - } - - /** - * @SWG\Delete(path="/ilots", - * tags={"Ilots"}, - * summary="delete Ilots", - * description="Request to delete Ilots", - * operationId="DELETE", - * produces={"application/xml", "application/json"}, - * @SWG\Parameter( - * name="token", - * in="query", - * description="token", - * required=true, - * type="string" - * ), - * * @SWG\Parameter( - * name="idList", - * in="query", - * description="id of the traitement", - * required=true, - * type="string" - * ), - * @SWG\Response( - * response=200, - * description="traitement Response", - * @SWG\Schema(ref="#/definitions/ilots") - * ) - * ) - */ - /** - * @SWG\Delete(path="/ilots/{id_ilot}", - * tags={"Ilots"}, - * summary="delete Ilots", - * description="Request to delete Ilots", - * operationId="DELETE", - * produces={"application/xml", "application/json"}, - * @SWG\Parameter( - * name="token", - * in="query", - * description="Traitement token", - * required=true, - * type="string" - * ), - * * @SWG\Parameter( - * name="id_ilot", - * in="path", - * description="id of the Ilots", - * required=true, - * type="integer", - * format = "int32" - * ), - * @SWG\Response( - * response=200, - * description="Poprerties Response", - * @SWG\Schema(ref="#/definitions/ilots") - * ) - * ) - */ - - /** - * delete ilots - * @return id of ilots deleted or error object if a ilots is not deleted - */ - function DELETE() { - $aReturn = $this->genericDelete('prod_immo', 'ilot', 'id_ilot'); - return $aReturn['sMessage']; - } - - -} - +<?php + +/** + * \file Ilots.class.inc + * \class Ilots + * + * \author Fabien Marty <f.marty@urbalyon.org>. + * + * \brief This file contains the Ilots php class + * + * This class defines Rest Api to Vitis Ilots + * + */ +require_once __DIR__ . '/Suivi_prod_immo.class.inc'; +require_once 'Ilot.class.inc'; + + +class Ilots extends Suivi_prod_immo { + /** + * @SWG\Definition( + * definition="/ilots", + * allOf={ + * @SWG\Schema(ref="#/definitions/ilots") + * } + * ) + * * @SWG\Tag( + * name="Ilots", + * description="Ilots about Ilots" + * ) + */ + + /** + * construct + * @param type $aPath url of the request + * @param type $aValues parameters of the request + * @param type $properties properties + */ + function __construct($aPath, $aValues, $properties) { + $this->aValues = $aValues; + $this->aPath = $aPath; + $this->aProperties = $properties; + $this->oConnection = new Connection($this->aValues, $properties); + } + + /** + * @SWG\Get(path="/ilots", + * tags={"Ilots"}, + * summary="Get Ilots", + * description="Request to get Ilots", + * operationId="GET", + * produces={"application/xml", "application/json", "application/x-vm-json"}, + * @SWG\Parameter( + * name="token", + * in="query", + * description="user token", + * required=true, + * type="string" + * ), + * @SWG\Parameter( + * name="order_by", + * in="query", + * description="list of ordering fields", + * required=false, + * type="string" + * ), + * @SWG\Parameter( + * name="sort_order", + * in="query", + * description="sort_order", + * required=false, + * type="string" + * ), + * @SWG\Parameter( + * name="limit", + * in="query", + * description="number of element", + * required=false, + * type="integer", + * format="int32" + * ), + * @SWG\Parameter( + * name="offset", + * in="query", + * description="index of first element", + * required=false, + * type="string", + * format="int32" + * ), + * @SWG\Parameter( + * name="attributs", + * in="query", + * description="list of attributs", + * required=false, + * type="string" + * ), + * @SWG\Parameter( + * name="filter", + * in="query", + * description="filter results", + * required=false, + * type="string" + * ), + * @SWG\Parameter( + * name="distinct", + * in="query", + * description="delete duplicates", + * required=false, + * type="boolean" + * ), + * @SWG\Response( + * response=200, + * description="traitement Response", + * @SWG\Schema(ref="#/definitions/ilots") + * ) + * ) + */ + + /** + * get Ilots + * @return Ilots + */ + function GET(){ + if($this->setRestriction()){ + $aReturn = $this->genericGet('prod_immo', "ilot", "id_ilot"); + $sMessage = $aReturn['sMessage']; + return $sMessage; + }else{ + // si pas d'autorisation, on retourne une liste vide + return json_encode(array("list_count"=>0,"total_row_number"=>0,"status"=>1)); + } + } + + + /** + * set filter restriction for user connected + */ + function setRestriction(){ + require $this->sRessourcesFile; + $aParams = array(); + $aParams['sSchemaFramework'] = array('value' => 'prod_immo', 'type' => 'schema_name'); + $oPDOresult = $this->oConnection->oBd->executeWithParams($aSql['getRestrictionUpdate'], $aParams); + if($oPDOresult->rowCount()==1){ + // le user existe dans la table de restriction + $oPDOresult = $this->oConnection->oBd->fermeResultat(); + $oPDOresult2 = $this->oConnection->oBd->executeWithParams($aSql['getRestrictionUpdateIdOperation'], $aParams); + if($oPDOresult2->rowCount()>0){ + // il y a un ou plusieurs ID pour le user, on filtre + $aID=array(); + while ($aIdOperation = $this->oConnection->oBd->ligneSuivante($oPDOresult2)){ + $aID[] = $aIdOperation["id_operation"]; + } + $oPDOresult2 = $this->oConnection->oBd->fermeResultat(); + // injection du filtre + if (isset($this->aValues['filter'])){ + // il existe d�j� un filtre + $aFilter=json_decode($this->aValues['filter'],true); + $aOperators=$aFilter['operators']; + $aOperators[]=array("column"=>"id_operation","compare_operator"=>"IN","value"=>$aID); + $aFilter['operators']=$aOperators; + $this->aValues['filter']=json_encode($aFilter); + }else{ + // il n'y a pas de filtre, on le cr�e + $this->aValues['filter']=json_encode(array('relation'=>'AND','operators'=>array(array("column"=>"id_operation","compare_operator"=>"IN","value"=>$aID)))); + } + return true; + }else{ + return false; + } + }else{ + // le user n'existe pas dans la table de restriction, on affiche rien + $oPDOresult = $this->oConnection->oBd->fermeResultat(); + error_log("Aucunes op�rations autoris�es en saisie, ajouter l'utilisateur dans la table prod_immo.user_restriction ."); + return false; + } + } + /** + * @SWG\Post(path="/ilots", + * tags={"Ilots"}, + * summary="Add traitement", + * description="Request to add Ilots", + * operationId="POST", + * produces={"application/xml", "application/json"}, + * @SWG\Parameter( + * name="token", + * in="query", + * description="user token", + * required=true, + * type="string" + * ), + * @SWG\Response( + * response=200, + * description="traitement Response", + * @SWG\Schema(ref="#/definitions/ilots") + * ) + * ) + */ + + /** + * insert traitement + * @return id of the traitement created + */ + function POST() { + //$this->aValues['create'] = $_SESSION["ses_Login"]; + //$this->aValues['create_date'] = date('Y-m-d'); + $aReturn = $this->genericPost('prod_immo', 'ilot', 'prod_immo.ilot_id_ilot_seq', 'id_ilot'); + return $aReturn['sMessage']; + } + + /** + * @SWG\Put(path="/ilots/{id_ilot}", + * tags={"Ilots"}, + * summary="update Ilots", + * description="Request to update Ilots", + * operationId="PUT", + * produces={"application/xml", "application/json"}, + * @SWG\Parameter( + * name="token", + * in="query", + * description="Traitement token", + * required=true, + * type="string" + * ), + * * @SWG\Parameter( + * name="id_ilot", + * in="path", + * description="id of the Ilots", + * required=true, + * type="integer", + * format = "int32" + * ), + * @SWG\Response( + * response=200, + * description="Poprerties Response", + * @SWG\Schema(ref="#/definitions/ilots") + * ) + * ) + */ + + /** + * update ilots + * @return id of ilots updated or error object if a ilots is not updated + */ + function PUT() { + /*if (empty($this->aValues['maj'])) + $this->aValues['maj'] = $_SESSION["ses_Login"]; + if (empty($this->aValues['maj_date'])) + $this->aValues['maj_date'] = date('Y-m-d');*/ + $aReturn = $this->genericPut('prod_immo', 'ilot', 'id_ilot'); + return $aReturn['sMessage']; + } + + /** + * @SWG\Delete(path="/ilots", + * tags={"Ilots"}, + * summary="delete Ilots", + * description="Request to delete Ilots", + * operationId="DELETE", + * produces={"application/xml", "application/json"}, + * @SWG\Parameter( + * name="token", + * in="query", + * description="token", + * required=true, + * type="string" + * ), + * * @SWG\Parameter( + * name="idList", + * in="query", + * description="id of the traitement", + * required=true, + * type="string" + * ), + * @SWG\Response( + * response=200, + * description="traitement Response", + * @SWG\Schema(ref="#/definitions/ilots") + * ) + * ) + */ + /** + * @SWG\Delete(path="/ilots/{id_ilot}", + * tags={"Ilots"}, + * summary="delete Ilots", + * description="Request to delete Ilots", + * operationId="DELETE", + * produces={"application/xml", "application/json"}, + * @SWG\Parameter( + * name="token", + * in="query", + * description="Traitement token", + * required=true, + * type="string" + * ), + * * @SWG\Parameter( + * name="id_ilot", + * in="path", + * description="id of the Ilots", + * required=true, + * type="integer", + * format = "int32" + * ), + * @SWG\Response( + * response=200, + * description="Poprerties Response", + * @SWG\Schema(ref="#/definitions/ilots") + * ) + * ) + */ + + /** + * delete ilots + * @return id of ilots deleted or error object if a ilots is not deleted + */ + function DELETE() { + $aReturn = $this->genericDelete('prod_immo', 'ilot', 'id_ilot'); + return $aReturn['sMessage']; + } + + +} + ?> \ No newline at end of file diff --git a/src/module_suivi_prod_immo/web_service/ws/Programmes.class.inc b/src/module_suivi_prod_immo/web_service/ws/Programmes.class.inc index 3cbf19d2d8a7b7a83c3bd054adcfd05b8e93800e..16bc88b41fc7469594998d8aaf2e11979a70c96a 100644 --- a/src/module_suivi_prod_immo/web_service/ws/Programmes.class.inc +++ b/src/module_suivi_prod_immo/web_service/ws/Programmes.class.inc @@ -1,425 +1,425 @@ -<?php - -/** - * \file Programmes.class.inc - * \class Programmes - * - * \author Fabien Marty <f.marty@urbalyon.org>. - * - * \brief This file contains the Programmes php class - * - * This class defines Rest Api to Vitis Programmes - * - */ -require_once __DIR__ . '/Suivi_prod_immo.class.inc'; -require_once 'Programme.class.inc'; - - -class Programmes extends Suivi_prod_immo { - /** - * @SWG\Definition( - * definition="/programmes", - * allOf={ - * @SWG\Schema(ref="#/definitions/programmes") - * } - * ) - * * @SWG\Tag( - * name="Programmes", - * description="Programmes about Programmes" - * ) - */ - - /** - * construct - * @param type $aPath url of the request - * @param type $aValues parameters of the request - * @param type $properties properties - */ - function __construct($aPath, $aValues, $properties) { - $this->aValues = $aValues; - $this->aPath = $aPath; - $this->aProperties = $properties; - $this->oConnection = new Connection($this->aValues, $properties); - } - - /** - * @SWG\Get(path="/programmes", - * tags={"Programmes"}, - * summary="Get Programmes", - * description="Request to get Programmes", - * operationId="GET", - * produces={"application/xml", "application/json", "application/x-vm-json"}, - * @SWG\Parameter( - * name="token", - * in="query", - * description="user token", - * required=true, - * type="string" - * ), - * @SWG\Parameter( - * name="order_by", - * in="query", - * description="list of ordering fields", - * required=false, - * type="string" - * ), - * @SWG\Parameter( - * name="sort_order", - * in="query", - * description="sort_order", - * required=false, - * type="string" - * ), - * @SWG\Parameter( - * name="limit", - * in="query", - * description="number of element", - * required=false, - * type="integer", - * format="int32" - * ), - * @SWG\Parameter( - * name="offset", - * in="query", - * description="index of first element", - * required=false, - * type="string", - * format="int32" - * ), - * @SWG\Parameter( - * name="attributs", - * in="query", - * description="list of attributs", - * required=false, - * type="string" - * ), - * @SWG\Parameter( - * name="filter", - * in="query", - * description="filter results", - * required=false, - * type="string" - * ), - * @SWG\Parameter( - * name="distinct", - * in="query", - * description="delete duplicates", - * required=false, - * type="boolean" - * ), - * @SWG\Response( - * response=200, - * description="traitement Response", - * @SWG\Schema(ref="#/definitions/programmes") - * ) - * ) - */ - - /** - * get Programmes - * @return Programmes - */ - function GET() { - if($this->setRestriction()){ - $aReturn = $this->genericGet('prod_immo', "programme_immobilier", "id_programme"); - $aProgrammes=json_decode($aReturn['sMessage'],true); - $aProgrammes2=array(); - foreach ($aProgrammes['programmes'] as $aProgramme){ - unset($aProgramme['geom']); - $aProgramme['nom_commune']= $this->getCommune($aProgramme['id_commune']); - $aProgramme['nom_ilot']= $this->getIlot($aProgramme['id_ilot']); - $aProgramme['nom_operation']= $this->getOperation($aProgramme['id_ilot']); - $aProgrammes2[count($aProgrammes2)]=$aProgramme; - } - $sProgrammes=json_encode(array("programmes"=>$aProgrammes2,"list_count"=>$aProgrammes['list_count'],"total_row_number"=>$aProgrammes['total_row_number'],"status"=>$aProgrammes['status'])); - return $sProgrammes; - }else{ - // si pas d'autorisation, on retourne une liste vide - return json_encode(array("list_count"=>0,"total_row_number"=>0,"status"=>1)); - } - } - - /** - * get commune of programme - */ - function getCommune($iId) { - if(isset($iId) and !is_null($iId)){ - require $this->sRessourcesFile; - $aParams['sSchemaFramework'] = array('value' => 'prod_immo', 'type' => 'schema_name'); - $aParams['id_commune'] = array('value' => $iId, 'type' => 'number'); - $oPDOresult = $this->oConnection->oBd->executeWithParams($aSql['getCommune'], $aParams); - $aLigne = $this->oConnection->oBd->ligneSuivante($oPDOresult); - $oPDOresult = $this->oConnection->oBd->fermeResultat(); - return $aLigne["nom_commune"]; - }else{ - return null; - } - } - - /** - * get ilot of programme - */ - function getIlot($iId) { - if(isset($iId) and !is_null($iId)){ - require $this->sRessourcesFile; - $aParams['sSchemaFramework'] = array('value' => 'prod_immo', 'type' => 'schema_name'); - $aParams['id_ilot'] = array('value' => $iId, 'type' => 'number'); - $oPDOresult = $this->oConnection->oBd->executeWithParams($aSql['getIlot'], $aParams); - $aLigne = $this->oConnection->oBd->ligneSuivante($oPDOresult); - $oPDOresult = $this->oConnection->oBd->fermeResultat(); - return $aLigne["nom_ilot"]; - }else{ - return null; - } - } - - /** - * get operation of programme - */ - function getOperation($iId) { - if(isset($iId) and !is_null($iId)){ - require $this->sRessourcesFile; - $aParams['sSchemaFramework'] = array('value' => 'prod_immo', 'type' => 'schema_name'); - $aParams['id_ilot'] = array('value' => $iId, 'type' => 'number'); - $oPDOresult = $this->oConnection->oBd->executeWithParams($aSql['getOperationIlot'], $aParams); - $aLigne = $this->oConnection->oBd->ligneSuivante($oPDOresult); - $oPDOresult = $this->oConnection->oBd->fermeResultat(); - return $aLigne["nom_operation"]; - }else{ - return null; - } - } - - /** - * set filter restriction for user connected - */ - function setRestriction(){ - require $this->sRessourcesFile; - $aParams = array(); - $aParams['sSchemaFramework'] = array('value' => 'prod_immo', 'type' => 'schema_name'); - $oPDOresult = $this->oConnection->oBd->executeWithParams($aSql['getRestrictionUpdate'], $aParams); - if($oPDOresult->rowCount()==1){ - // le user existe dans la table de restriction - $oPDOresult = $this->oConnection->oBd->fermeResultat(); - $oPDOresult2 = $this->oConnection->oBd->executeWithParams($aSql['getRestrictionUpdateIdIlot'], $aParams); - if($oPDOresult2->rowCount()>0){ - // il y a un ou plusieurs ID pour le user, on filtre - $aID=array(); - while ($aIdIlot=$this->oConnection->oBd->ligneSuivante($oPDOresult2)){ - $aID[]=$aIdIlot["id_ilot"]; - } - $oPDOresult2=$this->oConnection->oBd->fermeResultat(); - // injection du filtre - if (isset($this->aValues['filter'])){ - // il existe déjà un filtre - $aFilter=json_decode($this->aValues['filter'],true); - $aOperators=$aFilter['operators']; - $aOperators[]=array("column"=>"id_ilot","compare_operator"=>"IN","value"=>$aID); - $aFilter['operators']=$aOperators; - $this->aValues['filter']=json_encode($aFilter); - }else{ - // il n'y a pas de filtre, on le crée - $this->aValues['filter']=json_encode(array('relation'=>'AND','operators'=>array(array("column"=>"id_ilot","compare_operator"=>"IN","value"=>$aID)))); - } - return true; - }else{ - return false; - } - }else{ - // le user n'existe pas dans la table de restriction, on affiche rien - $oPDOresult = $this->oConnection->oBd->fermeResultat(); - error_log("Aucunes opérations autorisées en saisie, ajouter l'utilisateur dans la table prod_immo.user_restriction ."); - return false; - } - } - - /** - * @SWG\Post(path="/programmes", - * tags={"Programmes"}, - * summary="Add programme", - * description="Request to add Programmes", - * operationId="POST", - * produces={"application/xml", "application/json"}, - * @SWG\Parameter( - * name="token", - * in="query", - * description="user token", - * required=true, - * type="string" - * ), - * @SWG\Response( - * response=200, - * description= Response", - * @SWG\Schema(ref="#/definitions/programmes") - * ) - * ) - */ - - /** - * insert programme - * @return id of the programme created - */ - function POST() { - //$this->aValues['create'] = $_SESSION["ses_Login"]; - //$this->aValues['create_date'] = date('Y-m-d'); - $aReturn = $this->genericPost('prod_immo', 'programme_immobilier', 'prod_immo.programme_immobilier_id_programme_seq', 'id_programme'); - return $aReturn['sMessage']; - } - - /** - * @SWG\Put(path="/programmes/{id_programme}", - * tags={"Programmes"}, - * summary="update Programmes", - * description="Request to update Programmes", - * operationId="PUT", - * produces={"application/xml", "application/json"}, - * @SWG\Parameter( - * name="token", - * in="query", - * description="Traitement token", - * required=true, - * type="string" - * ), - * * @SWG\Parameter( - * name="id_programme", - * in="path", - * description="id of the Programmes", - * required=true, - * type="integer", - * format = "int32" - * ), - * @SWG\Response( - * response=200, - * description="Poprerties Response", - * @SWG\Schema(ref="#/definitions/programmes") - * ) - * ) - */ - - /** - * update programmes - * @return id of programmes updated or error object if a programmes is not updated - */ - function PUT() { - require $this->sRessourcesFile; - $oConnection=$this->oConnection->oBd; - $aParams['sSchemaFramework'] = array('value' => 'prod_immo', 'type' => 'schema_name'); - $aParams['id_programme'] = array('value' => $this->aValues['my_vitis_id'], 'type' => 'number'); - if(isset($this->aValues['logement_familliaux_location_nom_bailleur'])){ - $aParams['nom_bailleur'] = array('value' => $this->aValues['logement_familliaux_location_nom_bailleur'], 'type' => 'string'); - $oPDOresult = $oConnection->executeWithParams($aSql['setLogementFamilliauxLocationNomBailleur'], $aParams); - if (!$oPDOresult){ - $aError=$oConnection->errorInfo(); - error_log($aError[2]); - } - $oPDOresult = $oConnection->fermeResultat(); - unset($this->aValues['logement_familliaux_location_nom_bailleur']); - unset($aParams['nom_bailleur']); - } - if(isset($this->aValues['logement_familliaux_location_nom_investisseur'])){ - $aParams['nom_investisseur'] = array('value' => $this->aValues['logement_familliaux_location_nom_investisseur'], 'type' => 'string'); - $oPDOresult = $oConnection->executeWithParams($aSql['setLogementFamilliauxLocationNomInvestisseur'], $aParams); - if (!$oPDOresult){ - $aError=$oConnection->errorInfo(); - error_log($aError[2]); - } - $oPDOresult = $oConnection->fermeResultat(); - unset($this->aValues['logement_familliaux_location_nom_investisseur']); - unset($aParams['nom_investisseur']); - } - if(isset($this->aValues['habitat_specifique_nom_bailleur'])){ - $aParams['nom_bailleur'] = array('value' => $this->aValues['habitat_specifique_nom_bailleur'], 'type' => 'string'); - $oPDOresult = $oConnection->executeWithParams($aSql['setHabitatSpecifiqueNomBailleur'], $aParams); - if (!$oPDOresult){ - $aError=$oConnection->errorInfo(); - error_log($aError[2]); - } - $oPDOresult = $oConnection->fermeResultat(); - unset($this->aValues['habitat_specifique_nom_bailleur']); - unset($aParams['nom_bailleur']); - } - if(isset($this->aValues['habitat_specifique_nom_gestionnaire'])){ - $aParams['nom_gestionnaire'] = array('value' => $this->aValues['habitat_specifique_nom_gestionnaire'], 'type' => 'string'); - $oPDOresult = $oConnection->executeWithParams($aSql['setHabitatSpecifiqueNomGestionnaire'], $aParams); - if (!$oPDOresult){ - $aError=$oConnection->errorInfo(); - error_log($aError[2]); - } - $oPDOresult = $oConnection->fermeResultat(); - unset($this->aValues['habitat_specifique_nom_gestionnaire']); - } - $aReturn = $this->genericPut('prod_immo', 'programme_immobilier', 'id_programme'); - return $aReturn['sMessage']; - } - - /** - * @SWG\Delete(path="/programmes", - * tags={"Programmes"}, - * summary="delete Programmes", - * description="Request to delete Programmes", - * operationId="DELETE", - * produces={"application/xml", "application/json"}, - * @SWG\Parameter( - * name="token", - * in="query", - * description="token", - * required=true, - * type="string" - * ), - * * @SWG\Parameter( - * name="idList", - * in="query", - * description="id of the programme", - * required=true, - * type="string" - * ), - * @SWG\Response( - * response=200, - * description="Response", - * @SWG\Schema(ref="#/definitions/programmes") - * ) - * ) - */ - /** - * @SWG\Delete(path="/programmes/{id_programme}", - * tags={"Programmes"}, - * summary="delete Programmes", - * description="Request to delete Programmes", - * operationId="DELETE", - * produces={"application/xml", "application/json"}, - * @SWG\Parameter( - * name="token", - * in="query", - * description="token", - * required=true, - * type="string" - * ), - * * @SWG\Parameter( - * name="id_programme", - * in="path", - * description="id of the Programmes", - * required=true, - * type="integer", - * format = "int32" - * ), - * @SWG\Response( - * response=200, - * description="Poprerties Response", - * @SWG\Schema(ref="#/definitions/programmes") - * ) - * ) - */ - - /** - * delete programmes - * @return id of programmes deleted or error object if a programmes is not deleted - */ - function DELETE() { - $aReturn = $this->genericDelete('prod_immo', 'programme_immobilier', 'id_programme'); - return $aReturn['sMessage']; - } - - -} - +<?php + +/** + * \file Programmes.class.inc + * \class Programmes + * + * \author Fabien Marty <f.marty@urbalyon.org>. + * + * \brief This file contains the Programmes php class + * + * This class defines Rest Api to Vitis Programmes + * + */ +require_once __DIR__ . '/Suivi_prod_immo.class.inc'; +require_once 'Programme.class.inc'; + + +class Programmes extends Suivi_prod_immo { + /** + * @SWG\Definition( + * definition="/programmes", + * allOf={ + * @SWG\Schema(ref="#/definitions/programmes") + * } + * ) + * * @SWG\Tag( + * name="Programmes", + * description="Programmes about Programmes" + * ) + */ + + /** + * construct + * @param type $aPath url of the request + * @param type $aValues parameters of the request + * @param type $properties properties + */ + function __construct($aPath, $aValues, $properties) { + $this->aValues = $aValues; + $this->aPath = $aPath; + $this->aProperties = $properties; + $this->oConnection = new Connection($this->aValues, $properties); + } + + /** + * @SWG\Get(path="/programmes", + * tags={"Programmes"}, + * summary="Get Programmes", + * description="Request to get Programmes", + * operationId="GET", + * produces={"application/xml", "application/json", "application/x-vm-json"}, + * @SWG\Parameter( + * name="token", + * in="query", + * description="user token", + * required=true, + * type="string" + * ), + * @SWG\Parameter( + * name="order_by", + * in="query", + * description="list of ordering fields", + * required=false, + * type="string" + * ), + * @SWG\Parameter( + * name="sort_order", + * in="query", + * description="sort_order", + * required=false, + * type="string" + * ), + * @SWG\Parameter( + * name="limit", + * in="query", + * description="number of element", + * required=false, + * type="integer", + * format="int32" + * ), + * @SWG\Parameter( + * name="offset", + * in="query", + * description="index of first element", + * required=false, + * type="string", + * format="int32" + * ), + * @SWG\Parameter( + * name="attributs", + * in="query", + * description="list of attributs", + * required=false, + * type="string" + * ), + * @SWG\Parameter( + * name="filter", + * in="query", + * description="filter results", + * required=false, + * type="string" + * ), + * @SWG\Parameter( + * name="distinct", + * in="query", + * description="delete duplicates", + * required=false, + * type="boolean" + * ), + * @SWG\Response( + * response=200, + * description="traitement Response", + * @SWG\Schema(ref="#/definitions/programmes") + * ) + * ) + */ + + /** + * get Programmes + * @return Programmes + */ + function GET() { + if($this->setRestriction()){ + $aReturn = $this->genericGet('prod_immo', "programme_immobilier", "id_programme"); + $aProgrammes=json_decode($aReturn['sMessage'],true); + $aProgrammes2=array(); + foreach ($aProgrammes['programmes'] as $aProgramme){ + unset($aProgramme['geom']); + $aProgramme['nom_commune']= $this->getCommune($aProgramme['id_commune']); + $aProgramme['nom_ilot']= $this->getIlot($aProgramme['id_ilot']); + $aProgramme['nom_operation']= $this->getOperation($aProgramme['id_ilot']); + $aProgrammes2[count($aProgrammes2)]=$aProgramme; + } + $sProgrammes=json_encode(array("programmes"=>$aProgrammes2,"list_count"=>$aProgrammes['list_count'],"total_row_number"=>$aProgrammes['total_row_number'],"status"=>$aProgrammes['status'])); + return $sProgrammes; + }else{ + // si pas d'autorisation, on retourne une liste vide + return json_encode(array("list_count"=>0,"total_row_number"=>0,"status"=>1)); + } + } + + /** + * get commune of programme + */ + function getCommune($iId) { + if(isset($iId) and !is_null($iId)){ + require $this->sRessourcesFile; + $aParams['sSchemaFramework'] = array('value' => 'prod_immo', 'type' => 'schema_name'); + $aParams['id_commune'] = array('value' => $iId, 'type' => 'number'); + $oPDOresult = $this->oConnection->oBd->executeWithParams($aSql['getCommune'], $aParams); + $aLigne = $this->oConnection->oBd->ligneSuivante($oPDOresult); + $oPDOresult = $this->oConnection->oBd->fermeResultat(); + return $aLigne["nom_commune"]; + }else{ + return null; + } + } + + /** + * get ilot of programme + */ + function getIlot($iId) { + if(isset($iId) and !is_null($iId)){ + require $this->sRessourcesFile; + $aParams['sSchemaFramework'] = array('value' => 'prod_immo', 'type' => 'schema_name'); + $aParams['id_ilot'] = array('value' => $iId, 'type' => 'number'); + $oPDOresult = $this->oConnection->oBd->executeWithParams($aSql['getIlot'], $aParams); + $aLigne = $this->oConnection->oBd->ligneSuivante($oPDOresult); + $oPDOresult = $this->oConnection->oBd->fermeResultat(); + return $aLigne["nom_ilot"]; + }else{ + return null; + } + } + + /** + * get operation of programme + */ + function getOperation($iId) { + if(isset($iId) and !is_null($iId)){ + require $this->sRessourcesFile; + $aParams['sSchemaFramework'] = array('value' => 'prod_immo', 'type' => 'schema_name'); + $aParams['id_ilot'] = array('value' => $iId, 'type' => 'number'); + $oPDOresult = $this->oConnection->oBd->executeWithParams($aSql['getOperationIlot'], $aParams); + $aLigne = $this->oConnection->oBd->ligneSuivante($oPDOresult); + $oPDOresult = $this->oConnection->oBd->fermeResultat(); + return $aLigne["nom_operation"]; + }else{ + return null; + } + } + + /** + * set filter restriction for user connected + */ + function setRestriction(){ + require $this->sRessourcesFile; + $aParams = array(); + $aParams['sSchemaFramework'] = array('value' => 'prod_immo', 'type' => 'schema_name'); + $oPDOresult = $this->oConnection->oBd->executeWithParams($aSql['getRestrictionUpdate'], $aParams); + if($oPDOresult->rowCount()==1){ + // le user existe dans la table de restriction + $oPDOresult = $this->oConnection->oBd->fermeResultat(); + $oPDOresult2 = $this->oConnection->oBd->executeWithParams($aSql['getRestrictionUpdateIdIlot'], $aParams); + if($oPDOresult2->rowCount()>0){ + // il y a un ou plusieurs ID pour le user, on filtre + $aID=array(); + while ($aIdIlot=$this->oConnection->oBd->ligneSuivante($oPDOresult2)){ + $aID[]=$aIdIlot["id_ilot"]; + } + $oPDOresult2=$this->oConnection->oBd->fermeResultat(); + // injection du filtre + if (isset($this->aValues['filter'])){ + // il existe d�j� un filtre + $aFilter=json_decode($this->aValues['filter'],true); + $aOperators=$aFilter['operators']; + $aOperators[]=array("column"=>"id_ilot","compare_operator"=>"IN","value"=>$aID); + $aFilter['operators']=$aOperators; + $this->aValues['filter']=json_encode($aFilter); + }else{ + // il n'y a pas de filtre, on le cr�e + $this->aValues['filter']=json_encode(array('relation'=>'AND','operators'=>array(array("column"=>"id_ilot","compare_operator"=>"IN","value"=>$aID)))); + } + return true; + }else{ + return false; + } + }else{ + // le user n'existe pas dans la table de restriction, on affiche rien + $oPDOresult = $this->oConnection->oBd->fermeResultat(); + error_log("Aucunes op�rations autoris�es en saisie, ajouter l'utilisateur dans la table prod_immo.user_restriction ."); + return false; + } + } + + /** + * @SWG\Post(path="/programmes", + * tags={"Programmes"}, + * summary="Add programme", + * description="Request to add Programmes", + * operationId="POST", + * produces={"application/xml", "application/json"}, + * @SWG\Parameter( + * name="token", + * in="query", + * description="user token", + * required=true, + * type="string" + * ), + * @SWG\Response( + * response=200, + * description= Response", + * @SWG\Schema(ref="#/definitions/programmes") + * ) + * ) + */ + + /** + * insert programme + * @return id of the programme created + */ + function POST() { + //$this->aValues['create'] = $_SESSION["ses_Login"]; + //$this->aValues['create_date'] = date('Y-m-d'); + $aReturn = $this->genericPost('prod_immo', 'programme_immobilier', 'prod_immo.programme_immobilier_id_programme_seq', 'id_programme'); + return $aReturn['sMessage']; + } + + /** + * @SWG\Put(path="/programmes/{id_programme}", + * tags={"Programmes"}, + * summary="update Programmes", + * description="Request to update Programmes", + * operationId="PUT", + * produces={"application/xml", "application/json"}, + * @SWG\Parameter( + * name="token", + * in="query", + * description="Traitement token", + * required=true, + * type="string" + * ), + * * @SWG\Parameter( + * name="id_programme", + * in="path", + * description="id of the Programmes", + * required=true, + * type="integer", + * format = "int32" + * ), + * @SWG\Response( + * response=200, + * description="Poprerties Response", + * @SWG\Schema(ref="#/definitions/programmes") + * ) + * ) + */ + + /** + * update programmes + * @return id of programmes updated or error object if a programmes is not updated + */ + function PUT() { + require $this->sRessourcesFile; + $oConnection=$this->oConnection->oBd; + $aParams['sSchemaFramework'] = array('value' => 'prod_immo', 'type' => 'schema_name'); + $aParams['id_programme'] = array('value' => $this->aValues['my_vitis_id'], 'type' => 'number'); + if(isset($this->aValues['logement_familliaux_location_nom_bailleur'])){ + $aParams['nom_bailleur'] = array('value' => $this->aValues['logement_familliaux_location_nom_bailleur'], 'type' => 'string'); + $oPDOresult = $oConnection->executeWithParams($aSql['setLogementFamilliauxLocationNomBailleur'], $aParams); + if (!$oPDOresult){ + $aError=$oConnection->errorInfo(); + error_log($aError[2]); + } + $oPDOresult = $oConnection->fermeResultat(); + unset($this->aValues['logement_familliaux_location_nom_bailleur']); + unset($aParams['nom_bailleur']); + } + if(isset($this->aValues['logement_familliaux_location_nom_investisseur'])){ + $aParams['nom_investisseur'] = array('value' => $this->aValues['logement_familliaux_location_nom_investisseur'], 'type' => 'string'); + $oPDOresult = $oConnection->executeWithParams($aSql['setLogementFamilliauxLocationNomInvestisseur'], $aParams); + if (!$oPDOresult){ + $aError=$oConnection->errorInfo(); + error_log($aError[2]); + } + $oPDOresult = $oConnection->fermeResultat(); + unset($this->aValues['logement_familliaux_location_nom_investisseur']); + unset($aParams['nom_investisseur']); + } + if(isset($this->aValues['habitat_specifique_nom_bailleur'])){ + $aParams['nom_bailleur'] = array('value' => $this->aValues['habitat_specifique_nom_bailleur'], 'type' => 'string'); + $oPDOresult = $oConnection->executeWithParams($aSql['setHabitatSpecifiqueNomBailleur'], $aParams); + if (!$oPDOresult){ + $aError=$oConnection->errorInfo(); + error_log($aError[2]); + } + $oPDOresult = $oConnection->fermeResultat(); + unset($this->aValues['habitat_specifique_nom_bailleur']); + unset($aParams['nom_bailleur']); + } + if(isset($this->aValues['habitat_specifique_nom_gestionnaire'])){ + $aParams['nom_gestionnaire'] = array('value' => $this->aValues['habitat_specifique_nom_gestionnaire'], 'type' => 'string'); + $oPDOresult = $oConnection->executeWithParams($aSql['setHabitatSpecifiqueNomGestionnaire'], $aParams); + if (!$oPDOresult){ + $aError=$oConnection->errorInfo(); + error_log($aError[2]); + } + $oPDOresult = $oConnection->fermeResultat(); + unset($this->aValues['habitat_specifique_nom_gestionnaire']); + } + $aReturn = $this->genericPut('prod_immo', 'programme_immobilier', 'id_programme'); + return $aReturn['sMessage']; + } + + /** + * @SWG\Delete(path="/programmes", + * tags={"Programmes"}, + * summary="delete Programmes", + * description="Request to delete Programmes", + * operationId="DELETE", + * produces={"application/xml", "application/json"}, + * @SWG\Parameter( + * name="token", + * in="query", + * description="token", + * required=true, + * type="string" + * ), + * * @SWG\Parameter( + * name="idList", + * in="query", + * description="id of the programme", + * required=true, + * type="string" + * ), + * @SWG\Response( + * response=200, + * description="Response", + * @SWG\Schema(ref="#/definitions/programmes") + * ) + * ) + */ + /** + * @SWG\Delete(path="/programmes/{id_programme}", + * tags={"Programmes"}, + * summary="delete Programmes", + * description="Request to delete Programmes", + * operationId="DELETE", + * produces={"application/xml", "application/json"}, + * @SWG\Parameter( + * name="token", + * in="query", + * description="token", + * required=true, + * type="string" + * ), + * * @SWG\Parameter( + * name="id_programme", + * in="path", + * description="id of the Programmes", + * required=true, + * type="integer", + * format = "int32" + * ), + * @SWG\Response( + * response=200, + * description="Poprerties Response", + * @SWG\Schema(ref="#/definitions/programmes") + * ) + * ) + */ + + /** + * delete programmes + * @return id of programmes deleted or error object if a programmes is not deleted + */ + function DELETE() { + $aReturn = $this->genericDelete('prod_immo', 'programme_immobilier', 'id_programme'); + return $aReturn['sMessage']; + } + + +} + ?> \ No newline at end of file diff --git a/src/module_suivi_prod_immo/web_service/ws/Suivi_prod_immo.class.sql.inc b/src/module_suivi_prod_immo/web_service/ws/Suivi_prod_immo.class.sql.inc index 02e97329ea197a2920a93b9e140348b0c7efd9f8..5228e39e7cf0e991f6118cdaab2c25187c89ff74 100644 --- a/src/module_suivi_prod_immo/web_service/ws/Suivi_prod_immo.class.sql.inc +++ b/src/module_suivi_prod_immo/web_service/ws/Suivi_prod_immo.class.sql.inc @@ -1,105 +1,105 @@ -<?php -//Définition des requêtes de l'api Vitis -$aSql['checkIP'] = "SELECT user_id, ip_constraint FROM [sSchemaFramework].user WHERE login ='[sLogin]'"; -$aSql['getGroups'] = "SELECT group_id FROM [sSchemaFramework].user_group WHERE user_id = [user_id]"; -$aSql['loginUnique'] = 'SELECT UPPER("login") FROM [sSchemaFramework]."user" WHERE UPPER("login")=UPPER(\'sLoginUser\')'; -$aSql['getLoginbyId'] = 'SELECT "login" FROM [sSchemaFramework]."user" WHERE user_id=[user_id]'; -$aSql['getTableColumn'] = 'SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = \'[sSchemaFramework]\' and table_name= \'[sTable]\''; -$aSql['getUserPrivileges'] = 'SELECT groname FROM pg_user s LEFT OUTER JOIN pg_group g on (s.usesysid = any(g.grolist) )inner join [sSchemaFramework].user on "user".login = usename WHERE user_id = [user_id]'; -$aSql['listDomain'] = 'SELECT distinct domain, alias FROM [sSchemaFramework].domain WHERE "type" = \'AD\''; -$aSql['createRolname'] = 'CREATE ROLE "vitis_[sDomain]" NOSUPERUSER INHERIT NOCREATEDB CREATEROLE;'; -$aSql['getInfoRolname'] = 'SELECT * FROM pg_catalog.pg_roles WHERE rolname = \'vitis_[sDomain]\''; -// Communes -$aSql['getOperationCommunes'] = "SELECT operation_commune.id_commune, \"commune\".nom_commune FROM [sSchemaFramework].operation_commune LEFT JOIN [sSchemaFramework].commune ON operation_commune.id_commune = \"commune\".id_commune WHERE operation_commune.id_operation = [id_operation]"; -$aSql['insertOperationCommunes'] = "INSERT INTO [sSchemaFramework].operation_commune(id_commune, id_operation) VALUES([id_commune], [id_operation])"; -// CTM -$aSql['getOperationCTM'] = "SELECT operation_ctm.id_ctm, \"conference_territoriale_maire\".nom_ctm FROM [sSchemaFramework].operation_ctm LEFT JOIN [sSchemaFramework].conference_territoriale_maire ON operation_ctm.id_ctm = \"conference_territoriale_maire\".id_ctm WHERE operation_ctm.id_operation = [id_operation]"; -$aSql['insertOperationCTM'] = "INSERT INTO [sSchemaFramework].operation_ctm(id_ctm, id_operation) VALUES([id_ctm], [id_operation])"; -// Perimetres -$aSql['getOperationPerimetre'] = "SELECT operation_perimetre.id_perimetre, \"perimetre\".nom_perimetre FROM [sSchemaFramework].operation_perimetre LEFT JOIN [sSchemaFramework].perimetre ON operation_perimetre.id_perimetre = \"perimetre\".id_perimetre WHERE operation_perimetre.id_operation = [id_operation]"; -$aSql['insertOperationPerimetre'] = "INSERT INTO [sSchemaFramework].operation_perimetre(id_perimetre, id_operation) VALUES([id_perimetre], [id_operation])"; -// Modes financement -$aSql['getOperationModesFinancement'] = "SELECT operation_tr_financement_equ_public.code_financement_equ_public, \"tr_financement_equ_public\".financement_equ_public FROM [sSchemaFramework].operation_tr_financement_equ_public LEFT JOIN [sSchemaFramework].tr_financement_equ_public ON operation_tr_financement_equ_public.code_financement_equ_public = \"tr_financement_equ_public\".code_financement_equ_public WHERE operation_tr_financement_equ_public.id_operation = [id_operation]"; -$aSql['insertOperationModesFinancement'] = "INSERT INTO [sSchemaFramework].operation_tr_financement_equ_public(code_financement_equ_public, id_operation) VALUES([code_financement_equ_public], [id_operation])"; -// Commune -$aSql['getCommune'] = "SELECT \"commune\".id_commune, \"commune\".nom_commune FROM [sSchemaFramework].commune WHERE id_commune = [id_commune]"; -// Type opérateur -$aSql['getTypeOperateur'] = "SELECT \"tr_type_operateur\".code_type_operateur, \"tr_type_operateur\".type_operateur FROM [sSchemaFramework].tr_type_operateur WHERE code_type_operateur = [code_type_operateur]"; -// Mode consultation -$aSql['getModeConsultation'] = "SELECT \"tr_consultation\".code_consultation, \"tr_consultation\".consultation FROM [sSchemaFramework].tr_consultation WHERE code_consultation = [code_consultation]"; -// Opération / Ilot -$aSql['getOperationIlot'] = "SELECT nom_ilot, nom_operation FROM [sSchemaFramework].ilot INNER JOIN [sSchemaFramework].operation ON ilot.id_operation=operation.id_operation WHERE id_ilot=[id_ilot]"; -// Ilot -$aSql['getIlot'] = "SELECT nom_ilot FROM [sSchemaFramework].ilot WHERE id_ilot=[id_ilot]"; -// Perimetre projet urbain -$aSql['getPerimetre'] = "SELECT \"perimetre\".id_perimetre, \"perimetre\".nom_perimetre, \"perimetre\".type_perimetre FROM [sSchemaFramework].perimetre WHERE id_perimetre = [id_perimetre]"; -// Avancement -$aSql['getAvancement'] = "SELECT \"tr_avancement\".code_avancement, \"tr_avancement\".avancement FROM [sSchemaFramework].tr_avancement WHERE code_avancement = [code_avancement]"; -// Contexte urbain -$aSql['getContexteUrbain'] = "SELECT \"tr_contexte_urbain\".code_contexte_urbain, \"tr_contexte_urbain\".contexte_urbain FROM [sSchemaFramework].tr_contexte_urbain WHERE code_contexte_urbain = [code_contexte_urbain]"; -// Suivi de l'opération -$aSql['getSuivi'] = "SELECT \"tr_suivi\".code_suivi, \"tr_suivi\".suivi FROM [sSchemaFramework].tr_suivi WHERE code_suivi = [code_suivi]"; -// Procédure d'aménagement -$aSql['getProcedureAmenagement'] = "SELECT \"tr_procedure_amenagement\".code_procedure_amenagement, \"tr_procedure_amenagement\".procedure_amenagement FROM [sSchemaFramework].tr_procedure_amenagement WHERE code_procedure_amenagement = [code_procedure_amenagement]"; -// Vocation -$aSql['getVocation'] = "SELECT \"tr_vocation\".code_vocation, \"tr_vocation\".vocation FROM [sSchemaFramework].tr_vocation WHERE code_vocation = [code_vocation]"; -// Logement Familliaux Location -$aSql['getLogementFamLocation'] = "SELECT nom_bailleur, nom_investisseur, id_logement_familliaux_location FROM [sSchemaFramework].logement_familliaux_location WHERE id_programme=[id_programme]"; -// Logement Habitat spécifique -$aSql['getHabitatSpecifique'] = "SELECT nom_bailleur, nom_gestionnaire, id_habitat_specifique FROM [sSchemaFramework].habitat_specifique WHERE id_programme =[id_programme]"; -// Répartition logement -$aSql['getRepartition'] = "SELECT repartition FROM prod_immo.repartition WHERE code_repartition =[code_repartition]"; -$aSql['getTypeLogement'] = "SELECT type_logement FROM prod_immo.type_logement WHERE code_type_logement =[code_type_logement]"; -$aSql['getSequenceRepartition_type_logement'] = "SELECT nextval('prod_immo.repartition_type_logement_id_repartition_type_logement_seq')"; -// Granulométrie -$aSql['getCompositionProgramme'] = "SELECT composition_programme FROM prod_immo.composition_programme WHERE code_composition_programme =[code_composition_programme]"; -$aSql['getTypeGranulometrie'] = "SELECT type_granulometrie FROM prod_immo.type_granulometrie WHERE code_type_granulometrie =[code_type_granulometrie]"; -$aSql['getSequenceGranulometrie'] = "SELECT nextval('prod_immo.granulometrie_id_granulometrie_seq')"; -// Logement familliaux en accession -$aSql['getIndicateur_logement_familliaux_accession'] = "SELECT indicateur_logement_familliaux_accession FROM prod_immo.indicateur_logement_familliaux_accession WHERE id_indicateur_logement_familliaux_accession =[id_indicateur_logement_familliaux_accession]"; -$aSql['getSequenceLogement_familliaux_accession'] = "SELECT nextval('prod_immo.logement_familliaux_accession_id_logement_familliaux_access_seq')"; -// Profil acheteur accession libre -$aSql['getType_acheteur_accession_libre'] = "SELECT type_acheteur_accession_libre FROM prod_immo.type_acheteur_accession_libre WHERE id_type_acheteur_accession_libre =[id_type_acheteur_accession_libre]"; -$aSql['getSequenceProfil_acheteur_accession_libre'] = "SELECT nextval('prod_immo.profil_acheteur_accession_lib_id_profil_acheteur_accession__seq')"; -// Logement familliaux en location -$aSql['getIndicateur_logement_familliaux_location'] = "SELECT indicateur_logement_familliaux_location FROM prod_immo.indicateur_logement_familliaux_location WHERE id_indicateur_logement_familliaux_location =[id_indicateur_logement_familliaux_location]"; -$aSql['getSequenceComposition_logement_familliaux_location_cp'] = "SELECT nextval('prod_immo.composition_logement_famillia_id_composition_logement_famil_seq')"; -$aSql['setLogementFamilliauxLocationNomBailleur'] = "UPDATE [sSchemaFramework].logement_familliaux_location SET nom_bailleur=[nom_bailleur] WHERE id_programme=[id_programme]"; -$aSql['setLogementFamilliauxLocationNomInvestisseur'] = "UPDATE [sSchemaFramework].logement_familliaux_location SET nom_investisseur=[nom_investisseur] WHERE id_programme=[id_programme]"; -// Habitat spécifique -$aSql['getIndicateur_habitat_specifique'] = "SELECT indicateur_habitat_specifique FROM prod_immo.indicateur_habitat_specifique WHERE id_indicateur_habitat_specifique =[id_indicateur_habitat_specifique]"; -$aSql['getSequenceComposition_habitat_specifique_cp'] = "SELECT nextval('prod_immo.composition_habitat_specifiqu_id_composition_habitat_specif_seq')"; -$aSql['setHabitatSpecifiqueNomBailleur'] = "UPDATE [sSchemaFramework].habitat_specifique SET nom_bailleur=[nom_bailleur] WHERE id_programme=[id_programme]"; -$aSql['setHabitatSpecifiqueNomGestionnaire'] = "UPDATE [sSchemaFramework].habitat_specifique SET nom_gestionnaire=[nom_gestionnaire] WHERE id_programme=[id_programme]"; -// Activité et industrie -$aSql['getIndicateur_activite_industrie'] = "SELECT indicateur_activite_industrie FROM prod_immo.indicateur_activite_industrie WHERE id_indicateur_activite_industrie =[id_indicateur_activite_industrie]"; -$aSql['getSequenceActivite_industrie'] = "SELECT nextval('prod_immo.activite_industrie_id_activite_industrie_seq')"; -// Bureau -$aSql['getIndicateur_bureau'] = "SELECT indicateur_bureau FROM prod_immo.indicateur_bureau WHERE id_indicateur_bureau =[id_indicateur_bureau]"; -$aSql['getSequenceBureau'] = "SELECT nextval('prod_immo.bureau_id_bureau_seq')"; -// Equipement de superstructure -$aSql['getIndicateur_equipement_structure'] = "SELECT indicateur_equipement_structure FROM prod_immo.indicateur_equipement_structure WHERE id_indicateur_equipement_structure =[id_indicateur_equipement_structure]"; -$aSql['getSequenceEquipement_structure'] = "SELECT nextval('prod_immo.equipement_structure_id_equipement_structure_seq')"; -// Hotel commerce service -$aSql['getIndicateur_hotel_commerce_service'] = "SELECT indicateur_hotel_commerce_service FROM prod_immo.indicateur_hotel_commerce_service WHERE id_indicateur_hotel_commerce_service =[id_indicateur_hotel_commerce_service]"; -$aSql['getSequenceHotel_commerce_service'] = "SELECT nextval('prod_immo.hotel_commerce_service_id_hotel_commerce_service_seq')"; -// Stationnement -$aSql['getIndicateur_stationnement'] = "SELECT indicateur_stationnement FROM prod_immo.indicateur_stationnement WHERE id_indicateur_stationnement =[id_indicateur_stationnement]"; -$aSql['getSequenceStationnement'] = "SELECT nextval('prod_immo.stationnement_id_stationnement_seq')"; -// TooltipLastUpdate -$aSql['getUpdateTrackingOperation'] = "SELECT \"user\" AS user_update, date AS date_update, old_value FROM prod_immo.update_tracking_operation WHERE id_operation=[iIdOperation] AND field='[sField]' ORDER BY date_update DESC LIMIT 1"; -$aSql['getUpdateTrackingProgramme'] = "SELECT \"user\" AS user_update, date AS date_update, old_value FROM prod_immo.update_tracking_programme WHERE id_programme=[iIdProgramme] AND field='[sField]' ORDER BY date_update DESC LIMIT 1"; -// Restriction -$aSql['getRestrictionUpdate'] = 'SELECT restriction_update FROM [sSchemaFramework].user_restriction WHERE login::name = "current_user"()'; -$aSql['getRestrictionUpdateIdOperation'] = 'SELECT id_operation FROM [sSchemaFramework].operation WHERE id_operation::text ~ similar_escape(( SELECT restriction_update FROM [sSchemaFramework].user_restriction WHERE login::name = "current_user"()), NULL::text);'; -$aSql['getRestrictionUpdateIdIlot'] = 'SELECT id_ilot FROM [sSchemaFramework].ilot WHERE id_operation::text ~ similar_escape(( SELECT restriction_update FROM [sSchemaFramework].user_restriction WHERE login::name = "current_user"()), NULL::text);'; -// Module Analyse - LIST -$aSql['getListOperation'] = "SELECT id_operation, nom_operation FROM prod_immo.operation ORDER BY nom_operation"; -$aSql['getListAmenageur'] = "SELECT DISTINCT nom_amenageur, count(nom_amenageur) FROM prod_immo.operation WHERE nom_amenageur IS NOT NULL GROUP BY nom_amenageur ORDER BY count DESC, nom_amenageur"; -$aSql['getListCTM'] = "SELECT id_ctm, nom_ctm FROM prod_immo.conference_territoriale_maire ORDER BY nom_ctm"; -$aSql['getListCommune'] = "SELECT id_commune, nom_commune FROM prod_immo.commune ORDER BY nom_commune"; -$aSql['getListFinancement'] = "SELECT code_financement_equ_public, financement_equ_public FROM prod_immo.tr_financement_equ_public ORDER BY financement_equ_public"; -$aSql['getListSuivi'] = "SELECT code_suivi, suivi FROM prod_immo.tr_suivi ORDER BY suivi"; -$aSql['getListProcedureAmenagement'] = "SELECT code_procedure_amenagement, procedure_amenagement FROM prod_immo.tr_procedure_amenagement ORDER BY procedure_amenagement"; - +<?php +//Définition des requêtes de l'api Vitis +$aSql['checkIP'] = "SELECT user_id, ip_constraint FROM [sSchemaFramework].user WHERE login ='[sLogin]'"; +$aSql['getGroups'] = "SELECT group_id FROM [sSchemaFramework].user_group WHERE user_id = [user_id]"; +$aSql['loginUnique'] = 'SELECT UPPER("login") FROM [sSchemaFramework]."user" WHERE UPPER("login")=UPPER(\'sLoginUser\')'; +$aSql['getLoginbyId'] = 'SELECT "login" FROM [sSchemaFramework]."user" WHERE user_id=[user_id]'; +$aSql['getTableColumn'] = 'SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = \'[sSchemaFramework]\' and table_name= \'[sTable]\''; +$aSql['getUserPrivileges'] = 'SELECT groname FROM pg_user s LEFT OUTER JOIN pg_group g on (s.usesysid = any(g.grolist) )inner join [sSchemaFramework].user on "user".login = usename WHERE user_id = [user_id]'; +$aSql['listDomain'] = 'SELECT distinct domain, alias FROM [sSchemaFramework].domain WHERE "type" = \'AD\''; +$aSql['createRolname'] = 'CREATE ROLE "vitis_[sDomain]" NOSUPERUSER INHERIT NOCREATEDB CREATEROLE;'; +$aSql['getInfoRolname'] = 'SELECT * FROM pg_catalog.pg_roles WHERE rolname = \'vitis_[sDomain]\''; +// Communes +$aSql['getOperationCommunes'] = "SELECT operation_commune.id_commune, \"commune\".nom_commune FROM [sSchemaFramework].operation_commune LEFT JOIN [sSchemaFramework].commune ON operation_commune.id_commune = \"commune\".id_commune WHERE operation_commune.id_operation = [id_operation]"; +$aSql['insertOperationCommunes'] = "INSERT INTO [sSchemaFramework].operation_commune(id_commune, id_operation) VALUES([id_commune], [id_operation])"; +// CTM +$aSql['getOperationCTM'] = "SELECT operation_ctm.id_ctm, \"conference_territoriale_maire\".nom_ctm FROM [sSchemaFramework].operation_ctm LEFT JOIN [sSchemaFramework].conference_territoriale_maire ON operation_ctm.id_ctm = \"conference_territoriale_maire\".id_ctm WHERE operation_ctm.id_operation = [id_operation]"; +$aSql['insertOperationCTM'] = "INSERT INTO [sSchemaFramework].operation_ctm(id_ctm, id_operation) VALUES([id_ctm], [id_operation])"; +// Perimetres +$aSql['getOperationPerimetre'] = "SELECT operation_perimetre.id_perimetre, \"perimetre\".nom_perimetre FROM [sSchemaFramework].operation_perimetre LEFT JOIN [sSchemaFramework].perimetre ON operation_perimetre.id_perimetre = \"perimetre\".id_perimetre WHERE operation_perimetre.id_operation = [id_operation]"; +$aSql['insertOperationPerimetre'] = "INSERT INTO [sSchemaFramework].operation_perimetre(id_perimetre, id_operation) VALUES([id_perimetre], [id_operation])"; +// Modes financement +$aSql['getOperationModesFinancement'] = "SELECT operation_tr_financement_equ_public.code_financement_equ_public, \"tr_financement_equ_public\".financement_equ_public FROM [sSchemaFramework].operation_tr_financement_equ_public LEFT JOIN [sSchemaFramework].tr_financement_equ_public ON operation_tr_financement_equ_public.code_financement_equ_public = \"tr_financement_equ_public\".code_financement_equ_public WHERE operation_tr_financement_equ_public.id_operation = [id_operation]"; +$aSql['insertOperationModesFinancement'] = "INSERT INTO [sSchemaFramework].operation_tr_financement_equ_public(code_financement_equ_public, id_operation) VALUES([code_financement_equ_public], [id_operation])"; +// Commune +$aSql['getCommune'] = "SELECT \"commune\".id_commune, \"commune\".nom_commune FROM [sSchemaFramework].commune WHERE id_commune = [id_commune]"; +// Type opérateur +$aSql['getTypeOperateur'] = "SELECT \"tr_type_operateur\".code_type_operateur, \"tr_type_operateur\".type_operateur FROM [sSchemaFramework].tr_type_operateur WHERE code_type_operateur = [code_type_operateur]"; +// Mode consultation +$aSql['getModeConsultation'] = "SELECT \"tr_consultation\".code_consultation, \"tr_consultation\".consultation FROM [sSchemaFramework].tr_consultation WHERE code_consultation = [code_consultation]"; +// Opération / Ilot +$aSql['getOperationIlot'] = "SELECT nom_ilot, nom_operation FROM [sSchemaFramework].ilot INNER JOIN [sSchemaFramework].operation ON ilot.id_operation=operation.id_operation WHERE id_ilot=[id_ilot]"; +// Ilot +$aSql['getIlot'] = "SELECT nom_ilot FROM [sSchemaFramework].ilot WHERE id_ilot=[id_ilot]"; +// Perimetre projet urbain +$aSql['getPerimetre'] = "SELECT \"perimetre\".id_perimetre, \"perimetre\".nom_perimetre, \"perimetre\".type_perimetre FROM [sSchemaFramework].perimetre WHERE id_perimetre = [id_perimetre]"; +// Avancement +$aSql['getAvancement'] = "SELECT \"tr_avancement\".code_avancement, \"tr_avancement\".avancement FROM [sSchemaFramework].tr_avancement WHERE code_avancement = [code_avancement]"; +// Contexte urbain +$aSql['getContexteUrbain'] = "SELECT \"tr_contexte_urbain\".code_contexte_urbain, \"tr_contexte_urbain\".contexte_urbain FROM [sSchemaFramework].tr_contexte_urbain WHERE code_contexte_urbain = [code_contexte_urbain]"; +// Suivi de l'opération +$aSql['getSuivi'] = "SELECT \"tr_suivi\".code_suivi, \"tr_suivi\".suivi FROM [sSchemaFramework].tr_suivi WHERE code_suivi = [code_suivi]"; +// Procédure d'aménagement +$aSql['getProcedureAmenagement'] = "SELECT \"tr_procedure_amenagement\".code_procedure_amenagement, \"tr_procedure_amenagement\".procedure_amenagement FROM [sSchemaFramework].tr_procedure_amenagement WHERE code_procedure_amenagement = [code_procedure_amenagement]"; +// Vocation +$aSql['getVocation'] = "SELECT \"tr_vocation\".code_vocation, \"tr_vocation\".vocation FROM [sSchemaFramework].tr_vocation WHERE code_vocation = [code_vocation]"; +// Logement Familliaux Location +$aSql['getLogementFamLocation'] = "SELECT nom_bailleur, nom_investisseur, id_logement_familliaux_location FROM [sSchemaFramework].logement_familliaux_location WHERE id_programme=[id_programme]"; +// Logement Habitat spécifique +$aSql['getHabitatSpecifique'] = "SELECT nom_bailleur, nom_gestionnaire, id_habitat_specifique FROM [sSchemaFramework].habitat_specifique WHERE id_programme =[id_programme]"; +// Répartition logement +$aSql['getRepartition'] = "SELECT repartition FROM prod_immo.repartition WHERE code_repartition =[code_repartition]"; +$aSql['getTypeLogement'] = "SELECT type_logement FROM prod_immo.type_logement WHERE code_type_logement =[code_type_logement]"; +$aSql['getSequenceRepartition_type_logement'] = "SELECT nextval('prod_immo.repartition_type_logement_id_repartition_type_logement_seq')"; +// Granulométrie +$aSql['getCompositionProgramme'] = "SELECT composition_programme FROM prod_immo.composition_programme WHERE code_composition_programme =[code_composition_programme]"; +$aSql['getTypeGranulometrie'] = "SELECT type_granulometrie FROM prod_immo.type_granulometrie WHERE code_type_granulometrie =[code_type_granulometrie]"; +$aSql['getSequenceGranulometrie'] = "SELECT nextval('prod_immo.granulometrie_id_granulometrie_seq')"; +// Logement familliaux en accession +$aSql['getIndicateur_logement_familliaux_accession'] = "SELECT indicateur_logement_familliaux_accession FROM prod_immo.indicateur_logement_familliaux_accession WHERE id_indicateur_logement_familliaux_accession =[id_indicateur_logement_familliaux_accession]"; +$aSql['getSequenceLogement_familliaux_accession'] = "SELECT nextval('prod_immo.logement_familliaux_accession_id_logement_familliaux_access_seq')"; +// Profil acheteur accession libre +$aSql['getType_acheteur_accession_libre'] = "SELECT type_acheteur_accession_libre FROM prod_immo.type_acheteur_accession_libre WHERE id_type_acheteur_accession_libre =[id_type_acheteur_accession_libre]"; +$aSql['getSequenceProfil_acheteur_accession_libre'] = "SELECT nextval('prod_immo.profil_acheteur_accession_lib_id_profil_acheteur_accession__seq')"; +// Logement familliaux en location +$aSql['getIndicateur_logement_familliaux_location'] = "SELECT indicateur_logement_familliaux_location FROM prod_immo.indicateur_logement_familliaux_location WHERE id_indicateur_logement_familliaux_location =[id_indicateur_logement_familliaux_location]"; +$aSql['getSequenceComposition_logement_familliaux_location_cp'] = "SELECT nextval('prod_immo.composition_logement_famillia_id_composition_logement_famil_seq')"; +$aSql['setLogementFamilliauxLocationNomBailleur'] = "UPDATE [sSchemaFramework].logement_familliaux_location SET nom_bailleur=[nom_bailleur] WHERE id_programme=[id_programme]"; +$aSql['setLogementFamilliauxLocationNomInvestisseur'] = "UPDATE [sSchemaFramework].logement_familliaux_location SET nom_investisseur=[nom_investisseur] WHERE id_programme=[id_programme]"; +// Habitat spécifique +$aSql['getIndicateur_habitat_specifique'] = "SELECT indicateur_habitat_specifique FROM prod_immo.indicateur_habitat_specifique WHERE id_indicateur_habitat_specifique =[id_indicateur_habitat_specifique]"; +$aSql['getSequenceComposition_habitat_specifique_cp'] = "SELECT nextval('prod_immo.composition_habitat_specifiqu_id_composition_habitat_specif_seq')"; +$aSql['setHabitatSpecifiqueNomBailleur'] = "UPDATE [sSchemaFramework].habitat_specifique SET nom_bailleur=[nom_bailleur] WHERE id_programme=[id_programme]"; +$aSql['setHabitatSpecifiqueNomGestionnaire'] = "UPDATE [sSchemaFramework].habitat_specifique SET nom_gestionnaire=[nom_gestionnaire] WHERE id_programme=[id_programme]"; +// Activité et industrie +$aSql['getIndicateur_activite_industrie'] = "SELECT indicateur_activite_industrie FROM prod_immo.indicateur_activite_industrie WHERE id_indicateur_activite_industrie =[id_indicateur_activite_industrie]"; +$aSql['getSequenceActivite_industrie'] = "SELECT nextval('prod_immo.activite_industrie_id_activite_industrie_seq')"; +// Bureau +$aSql['getIndicateur_bureau'] = "SELECT indicateur_bureau FROM prod_immo.indicateur_bureau WHERE id_indicateur_bureau =[id_indicateur_bureau]"; +$aSql['getSequenceBureau'] = "SELECT nextval('prod_immo.bureau_id_bureau_seq')"; +// Equipement de superstructure +$aSql['getIndicateur_equipement_structure'] = "SELECT indicateur_equipement_structure FROM prod_immo.indicateur_equipement_structure WHERE id_indicateur_equipement_structure =[id_indicateur_equipement_structure]"; +$aSql['getSequenceEquipement_structure'] = "SELECT nextval('prod_immo.equipement_structure_id_equipement_structure_seq')"; +// Hotel commerce service +$aSql['getIndicateur_hotel_commerce_service'] = "SELECT indicateur_hotel_commerce_service FROM prod_immo.indicateur_hotel_commerce_service WHERE id_indicateur_hotel_commerce_service =[id_indicateur_hotel_commerce_service]"; +$aSql['getSequenceHotel_commerce_service'] = "SELECT nextval('prod_immo.hotel_commerce_service_id_hotel_commerce_service_seq')"; +// Stationnement +$aSql['getIndicateur_stationnement'] = "SELECT indicateur_stationnement FROM prod_immo.indicateur_stationnement WHERE id_indicateur_stationnement =[id_indicateur_stationnement]"; +$aSql['getSequenceStationnement'] = "SELECT nextval('prod_immo.stationnement_id_stationnement_seq')"; +// TooltipLastUpdate +$aSql['getUpdateTrackingOperation'] = "SELECT \"user\" AS user_update, date AS date_update, old_value FROM prod_immo.update_tracking_operation WHERE id_operation=[iIdOperation] AND field='[sField]' ORDER BY date_update DESC LIMIT 1"; +$aSql['getUpdateTrackingProgramme'] = "SELECT \"user\" AS user_update, date AS date_update, old_value FROM prod_immo.update_tracking_programme WHERE id_programme=[iIdProgramme] AND field='[sField]' ORDER BY date_update DESC LIMIT 1"; +// Restriction +$aSql['getRestrictionUpdate'] = 'SELECT restriction_update FROM [sSchemaFramework].user_restriction WHERE login::name = "current_user"()'; +$aSql['getRestrictionUpdateIdOperation'] = 'SELECT id_operation FROM [sSchemaFramework].operation WHERE id_operation::text ~ similar_escape(( SELECT restriction_update FROM [sSchemaFramework].user_restriction WHERE login::name = "current_user"()), NULL::text);'; +$aSql['getRestrictionUpdateIdIlot'] = 'SELECT id_ilot FROM [sSchemaFramework].ilot WHERE id_operation::text ~ similar_escape(( SELECT restriction_update FROM [sSchemaFramework].user_restriction WHERE login::name = "current_user"()), NULL::text);'; +// Module Analyse - LIST +$aSql['getListOperation'] = "SELECT id_operation, nom_operation FROM prod_immo.operation ORDER BY nom_operation"; +$aSql['getListAmenageur'] = "SELECT DISTINCT nom_amenageur, count(nom_amenageur) FROM prod_immo.operation WHERE nom_amenageur IS NOT NULL GROUP BY nom_amenageur ORDER BY count DESC, nom_amenageur"; +$aSql['getListCTM'] = "SELECT id_ctm, nom_ctm FROM prod_immo.conference_territoriale_maire ORDER BY nom_ctm"; +$aSql['getListCommune'] = "SELECT id_commune, nom_commune FROM prod_immo.commune ORDER BY nom_commune"; +$aSql['getListFinancement'] = "SELECT code_financement_equ_public, financement_equ_public FROM prod_immo.tr_financement_equ_public ORDER BY financement_equ_public"; +$aSql['getListSuivi'] = "SELECT code_suivi, suivi FROM prod_immo.tr_suivi ORDER BY suivi"; +$aSql['getListProcedureAmenagement'] = "SELECT code_procedure_amenagement, procedure_amenagement FROM prod_immo.tr_procedure_amenagement ORDER BY procedure_amenagement"; + ?> \ No newline at end of file diff --git a/src/module_vmap/web_service/ws/Querys.class.inc b/src/module_vmap/web_service/ws/Querys.class.inc index 41656427c4bfaae5f067386cae79fe4eceff5579..b62667d93f00a6f6a3ad9d7298c5ee2bfe6372f7 100755 --- a/src/module_vmap/web_service/ws/Querys.class.inc +++ b/src/module_vmap/web_service/ws/Querys.class.inc @@ -579,7 +579,7 @@ class Querys extends Vmap { * @return array */ function queryBusinessObject($type, $bOnlyResult = false) { - require $this->sRessourcesFile; + require $this->sRessourcesFile; if (!empty($this->oConnection->oError)) { $aXmlRacineAttribute['status'] = 0; @@ -732,7 +732,6 @@ class Querys extends Vmap { // Execute la requête $this->aValues['my_vitis_id'] = ""; - $oResult = $this->oConnection->oBd->executeWithParams($sSql, $aParams); if ($this->oConnection->oBd->enErreur()) { @@ -742,9 +741,8 @@ class Querys extends Vmap { } else { if (!$this->oConnection->oBd->enErreur() && $this->oConnection->oBd->nombreLigne($oResult) > 0) { while ($aLigne = $this->oConnection->oBd->ligneSuivante($oResult)) { - + if ($type !== 'table') { - // Image à la une if ($get_image === true || $get_image === 'true') { if (isset($aLigne['[bo_image]'])) { @@ -782,7 +780,6 @@ class Querys extends Vmap { $aLigne = $aResult; } else { - // Récupère le forulaire JSON if ($type === 'form') { $jsonContent = file_get_contents($this->aProperties['ws_data_dir'] . '/vmap/business_object/' . $bo_id . '/forms/published.json'); diff --git a/src/vitis/client/css/icons/style.css b/src/vitis/client/css/icons/style.css index 0dad7299c1f03dec2eddd99452cf8a91d8b98796..3345c4aa5ba694458760825ef29ef9de7a94346f 100755 --- a/src/vitis/client/css/icons/style.css +++ b/src/vitis/client/css/icons/style.css @@ -1058,3 +1058,13 @@ .icon-scissors:before { content: "\f0c4"; } +/******* URBALYON *********/ +.icon-suivi_prod_immo_saisie:before { + content: "\e94e"; +} +.icon-patrimoine_saisie:before { + content: "\f015"; +} +.icon-suivi_prod_immo_bi:before { + content: "\f043"; +} \ No newline at end of file diff --git a/src/vitis/client/javascript/externs/formReader/formReaderDrtv.js b/src/vitis/client/javascript/externs/formReader/formReaderDrtv.js index 1f06b76313ed6aa6562126cabe95a300238b9aaa..d1d861d545be6bf508e08a9f7d72753228518049 100755 --- a/src/vitis/client/javascript/externs/formReader/formReaderDrtv.js +++ b/src/vitis/client/javascript/externs/formReader/formReaderDrtv.js @@ -3066,6 +3066,7 @@ formReader.appSubformGridDrtv = function ($timeout, $translate, propertiesSrvc, } } } + var sFilter = formReaderService['parseFilter'](oSearchValues); /** * Fonction qui permet d'ajouter un enregistrement de l'objet métier en question @@ -3110,7 +3111,7 @@ formReader.appSubformGridDrtv = function ($timeout, $translate, propertiesSrvc, $('#' + sModalId).modal('hide'); // Rafraichit la grille setTimeout(function () { - formReaderService['getSectionRessourceData'](scope['oSection']['ressource_id']).then(function (oNewResult) { + formReaderService['getSectionRessourceData'](scope['oSection']['ressource_id'], sFilter).then(function (oNewResult) { scope['gridOptions']['data'] = oNewResult; }); }); @@ -3151,7 +3152,7 @@ formReader.appSubformGridDrtv = function ($timeout, $translate, propertiesSrvc, formReaderService['deleteSectionElements'](scope['oSection']['ressource_id'], aIds).then(function (oResponse) { // Rafraichit la grille setTimeout(function () { - formReaderService['getSectionRessourceData'](scope['oSection']['ressource_id']).then(function (oNewResult) { + formReaderService['getSectionRessourceData'](scope['oSection']['ressource_id'], sFilter).then(function (oNewResult) { scope['gridOptions']['data'] = oNewResult; }); }); @@ -3245,7 +3246,7 @@ formReader.appSubformGridDrtv = function ($timeout, $translate, propertiesSrvc, formReaderService['getSectionRessourceTab'](scope['oSection']['ressource_id']).then(function (oRessourceTab) { scope['oRessourceTab'] = oRessourceTab; - formReaderService['getSectionRessourceData'](scope['oSection']['ressource_id']).then(function (aRessourceData) { + formReaderService['getSectionRessourceData'](scope['oSection']['ressource_id'],sFilter).then(function (aRessourceData) { scope['aRessourceData'] = aRessourceData; formReaderService['getSectionForm'](scope['oSection'], true).then(function (oSubformDefinition) { @@ -3336,7 +3337,7 @@ formReader.appSubformGridDrtv = function ($timeout, $translate, propertiesSrvc, $('#' + sModalId).modal('hide'); // Rafraichit la grille setTimeout(function () { - formReaderService['getSectionRessourceData'](scope['oSection']['ressource_id']).then(function (oNewResult) { + formReaderService['getSectionRessourceData'](scope['oSection']['ressource_id'], sFilter).then(function (oNewResult) { scope['gridOptions']['data'] = oNewResult; }); }); diff --git a/src/vitis/client/javascript/externs/formReader/formReaderSrvc.js b/src/vitis/client/javascript/externs/formReader/formReaderSrvc.js index 93574a2a9a32824fdd00b43361840beb8a9a3d1b..48653b9367aa04aefd7265065772148f6b7cb193 100755 --- a/src/vitis/client/javascript/externs/formReader/formReaderSrvc.js +++ b/src/vitis/client/javascript/externs/formReader/formReaderSrvc.js @@ -1881,15 +1881,15 @@ formReader.formReaderService = function ($translate, $rootScope, $q, $log, $time }, "success": function (response) { if (!goog.isDef(response['data'])) { - $translate('NO_VALUES_RETURNED').then(function (sTranslation) { + /*$translate('NO_VALUES_RETURNED').then(function (sTranslation) { bootbox.alert(sTranslation); - }); + });*/ return 0; } if (!goog.isDef(response['data']['data'])) { - $translate('NO_VALUES_RETURNED').then(function (sTranslation) { + /*$translate('NO_VALUES_RETURNED').then(function (sTranslation) { bootbox.alert(sTranslation); - }); + });*/ return 0; } if (!goog.isDef(response['data']['data'][0])) { diff --git a/src/vitis/vas/doc/suivi_prod_immo/get_1_operation.php b/src/vitis/vas/doc/suivi_prod_immo/get_1_operation.php index a6a560b82740a5327e69c969602f3b367c6328f1..9147e6d69f96f457c1a041b74b277e9d239a7bd3 100644 --- a/src/vitis/vas/doc/suivi_prod_immo/get_1_operation.php +++ b/src/vitis/vas/doc/suivi_prod_immo/get_1_operation.php @@ -1,275 +1,275 @@ -<?php -// https://geo.urbalyon.org/doc/suivi_prod_immo/get_1_operation.php?id_operation=1041 - -if (isset($_REQUEST['token']) && !is_null($_REQUEST['token'])){ - session_id($_REQUEST['token']); - if (session_status() == PHP_SESSION_NONE) - session_start(); - - if (empty($_SESSION)) { - $sError="ERREUR : token invalide."; - include ('get_error.html'); - }else{ - if (isset($_REQUEST['id_operation']) && !is_null($_REQUEST['id_operation'])){ - require_once("../../rest/conf/properties.inc"); - require_once("properties_suivi_prod_immo.inc"); - $sSchema=$properties['schema_prod_immo']; - - try{ - $oConn = new PDO('pgsql:host='.$properties['server'].';port='.$properties['port'].';dbname='.$properties['db_prod_immo'], $properties['db_user_prod_immo'], $properties['db_pass_prod_immo']); - $oConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - $oConn->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL); - - if($oConn){ - // get data Opérations - $sWhereIdOperation=" WHERE id_operation=".$_REQUEST['id_operation']; - $oResult = $oConn->prepare("SELECT *, ST_XMin(ST_Buffer(geom,50)) AS xmin, ST_YMin(ST_Buffer(geom,50)) AS ymin, ST_XMax(ST_Buffer(geom,50)) AS xmax, ST_YMax(ST_Buffer(geom,50)) AS ymax FROM ".$sSchema.".v_operation_layer".$sWhereIdOperation); - $oResult->execute(); - - if ($oResult->rowCount()>0){ - $aOperations = $oResult->fetchAll(); - $oResult->closeCursor(); - $aOperation =$aOperations[0]; - $aOperation['date_mise_a_jour'] = date("d/m/Y", strtotime($aOperation['date_mise_a_jour'])); - $sDataSdpPrev= $aOperation['sdp_logement'].",".$aOperation['sdp_bureau'].",".$aOperation['sdp_commerce_service'].",".$aOperation['sdp_locaux'].",".$aOperation['sdp_equipement']; - // get map image - $sNameMapImage=$_REQUEST['id_operation']."_operation.png"; - $sCommand = escapeshellcmd('python get_map_image_1_operation.py '.$aOperation['xmin'].' '.$aOperation['ymin'].' '.$aOperation['xmax'].' '.$aOperation['ymax'].' '.$sNameMapImage.' '.$_REQUEST['id_operation']); - $output = shell_exec($sCommand); - $sUrlMapImage=$properties['web_server_name']."/ws_data/vm4ms/map/tmp/".$sNameMapImage; - - // get data ilot - $oResult1 = $oConn->prepare("SELECT count(id_ilot) FROM ".$sSchema.".ilot".$sWhereIdOperation); - $oResult1->execute(); - $aIlot = $oResult1->fetch(PDO::FETCH_ASSOC); - $oResult1->closeCursor(); - $oResult2 = $oConn->prepare("SELECT count(DISTINCT programme_immobilier.id_ilot) FROM ".$sSchema.".programme_immobilier INNER JOIN ".$sSchema.".ilot ON programme_immobilier.id_ilot=ilot.id_ilot".$sWhereIdOperation); - $oResult2->execute(); - $aIlotProgramme = $oResult2->fetch(PDO::FETCH_ASSOC); - $iIlotSansProgramme = $aIlot['count']-$aIlotProgramme['count']; - $oResult2->closeCursor(); - // get data programme - $oResult3 = $oConn->prepare("SELECT array_to_string(array_agg(id_programme), ',') AS id_programme, round(avg(cout_construction_moyen)) AS cout_construction_moyen,round( avg(charge_fonciere_nette)) AS charge_fonciere_nette FROM ".$sSchema.".programme_immobilier INNER JOIN ".$sSchema.".ilot ON ilot.id_ilot=programme_immobilier.id_ilot ".$sWhereIdOperation." GROUP BY id_operation"); - $oResult3->execute(); - if ($oResult3->rowCount()>0){ - $aProgrammesStat=$oResult3->fetch(PDO::FETCH_ASSOC); - $sIdsProgramme = $aProgrammesStat['id_programme']; - $sWhereIdProgramme = " WHERE id_programme IN (".$sIdsProgramme.")"; - //echo $sWhereIdProgramme; - $oResult3->closeCursor(); - $oResult11=$oConn->prepare("SELECT nom_ilot, numero_pc, surface, id_programme, nom_programme, code_type_operateur, nom_demandeur, annee_debut, annee_fin FROM ".$sSchema.".programme_immobilier INNER JOIN ".$sSchema.".ilot ON ilot.id_ilot=programme_immobilier.id_ilot ".$sWhereIdOperation); - $oResult11->execute(); - $aProgrammes = $oResult11->fetchAll(); - $aSyntheseProgrammes=array(); - foreach ($aProgrammes as $iKey => $aProgramme){ - $aSyntheseProgrammes[$aProgramme['id_programme']]=array(); - $sSql12="SELECT code_composition_programme, code_type_granulometrie, valeur FROM ".$sSchema.".granulometrie WHERE id_programme IN (".$aProgramme['id_programme'].") ORDER BY code_composition_programme, code_type_granulometrie"; - foreach ($oConn->query($sSql12) as $aRow){ - if (!isset($aSyntheseProgrammes[$aProgramme['id_programme']][$aRow['code_composition_programme']])) $aSyntheseProgrammes[$aProgramme['id_programme']][$aRow['code_composition_programme']]=array(); - $aSyntheseProgrammes[$aProgramme['id_programme']][$aRow['code_composition_programme']][$aRow['code_type_granulometrie']]=$aRow['valeur']; - } - } - $oResult11->closeCursor(); - - - // get accession libre aidee - $sSql8="SELECT id_indicateur_logement_familliaux_accession, round(sum(accession_libre::numeric)) AS sum_accession_libre, round(coalesce(sum(accession_abordable::numeric),0)+coalesce(sum(accession_sociale_securise ::numeric),0)+coalesce(sum(psla::numeric),0)) AS sum_accession_aide, round(avg(accession_libre::numeric)) AS avg_accession_libre, round(avg(accession_abordable::numeric)) AS avg_accession_abordable, round(avg(accession_sociale_securise ::numeric)) AS avg_accession_sociale_securise , round(avg(psla::numeric)) AS avg_psla FROM ".$sSchema.".logement_familliaux_accession".$sWhereIdProgramme." AND id_indicateur_logement_familliaux_accession IN (1,2,4,5,8,9) GROUP BY id_indicateur_logement_familliaux_accession"; - foreach ($oConn->query($sSql8) as $aRow){ - if ($aRow['id_indicateur_logement_familliaux_accession']==1){ - isset($iNbLgtFam) ? $iNbLgtFam=$iNbLgtFam+$aRow['sum_accession_libre'] : $iNbLgtFam=$aRow['sum_accession_libre']; - isset($iNbLgtFam) ? $iNbLgtFam=$iNbLgtFam+$aRow['sum_accession_aide'] : $iNbLgtFam=$aRow['sum_accession_aide']; - } - if ($aRow['id_indicateur_logement_familliaux_accession']==2){ - $iSdpAccessionLibre=$aRow['sum_accession_libre']; - $iSdpAccessionAide=$aRow['sum_accession_aide']; - } - if ($aRow['id_indicateur_logement_familliaux_accession']==4 or $aRow['id_indicateur_logement_familliaux_accession']==5){ - if(!isset($aCFAccessionLibre)) $aCFAccessionLibre=array(); - if(!is_null($aRow['avg_accession_libre'])) array_push($aCFAccessionLibre,$aRow['avg_accession_libre']); - if(!isset($aCFAccessionAidee)) $aCFAccessionAidee=array(); - if(!is_null($aRow['avg_accession_abordable'])) array_push($aCFAccessionAidee,$aRow['avg_accession_abordable']); - if(!is_null($aRow['avg_accession_sociale_securise '])) array_push($aCFAccessionAidee,$aRow['avg_accession_sociale_securise ']); - if(!is_null($aRow['avg_psla'])) array_push($aCFAccessionAidee,$aRow['avg_psla']); - } - if ($aRow['id_indicateur_logement_familliaux_accession']==8 or $aRow['id_indicateur_logement_familliaux_accession']==9){ - if(!isset($aPVAccessionLibre)) $aPVAccessionLibre=array(); - if(!is_null($aRow['avg_accession_libre'])) array_push($aPVAccessionLibre,$aRow['avg_accession_libre']); - if(!isset($aPVAccessionAidee)) $aPVAccessionAidee=array(); - if(!is_null($aRow['avg_accession_abordable'])) array_push($aPVAccessionAidee,$aRow['avg_accession_abordable']); - if(!is_null($aRow['avg_accession_sociale_securise '])) array_push($aPVAccessionAidee,$aRow['avg_accession_sociale_securise ']); - if(!is_null($aRow['avg_psla'])) array_push($aPVAccessionAidee,$aRow['avg_psla']); - } - } - if(isset($aPVAccessionLibre) and count($aPVAccessionLibre)>0) $iPVAccessionLibre = round(array_sum($aPVAccessionLibre)/count($aPVAccessionLibre)); - if(isset($aPVAccessionAidee) and count($aPVAccessionAidee)>0) $iPVAccessionAidee = round(array_sum($aPVAccessionAidee)/count($aPVAccessionAidee)); - if(isset($aCFAccessionLibre) and count($aCFAccessionLibre)>0) $iCFAccessionLibre = round(array_sum($aCFAccessionLibre)/count($aCFAccessionLibre)); - if(isset($aCFAccessionAidee) and count($aCFAccessionAidee)>0) $iCFAccessionAidee = round(array_sum($aCFAccessionAidee)/count($aCFAccessionAidee)); - // get locatif social - $sSql9="SELECT id_indicateur_logement_familliaux_location, round(coalesce(sum(social_pls),0)+coalesce(sum(social_plus_plai),0)) AS sum_social, round(coalesce(sum(intermediaire_pli),0)+coalesce(sum(intermediaire_afl),0)) AS sum_intermediaire, round(avg(social_pls)) AS avg_social_pls, round(avg(social_plus_plai)) AS avg_social_plus_plai, round(avg(intermediaire_pli)) AS avg_intermediaire_pli, round(avg(intermediaire_afl)) AS avg_intermediaire_afl FROM ".$sSchema.".composition_logement_familliaux_location_cp INNER JOIN ".$sSchema.".logement_familliaux_location ON logement_familliaux_location.id_logement_familliaux_location=composition_logement_familliaux_location_cp.id_logement_familliaux_location".$sWhereIdProgramme." AND id_indicateur_logement_familliaux_location IN (1,2,4,5,8) GROUP BY id_indicateur_logement_familliaux_location"; - foreach ($oConn->query($sSql9) as $aRow){ - if ($aRow['id_indicateur_logement_familliaux_location']==1){ - isset($iNbLgtFam) ? $iNbLgtFam=$iNbLgtFam+$aRow['sum_social'] : $iNbLgtFam=$aRow['sum_social']; - isset($iNbLgtFam) ? $iNbLgtFam=$iNbLgtFam+$aRow['sum_intermediaire'] : $iNbLgtFam=$aRow['sum_intermediaire']; - } - if ($aRow['id_indicateur_logement_familliaux_location']==2){ - $iSdpLocSocial=$aRow['sum_social']; - $iSdpLocIntermediaire=$aRow['sum_intermediaire']; - } - if ($aRow['id_indicateur_logement_familliaux_location']==4 or $aRow['id_indicateur_logement_familliaux_location']==5){ - if(!isset($aCFSocial)) $aCFSocial=array(); - if(!is_null($aRow['avg_social_pls'])) array_push($aCFSocial,$aRow['avg_social_pls']); - if(!is_null($aRow['avg_social_plus_plai'])) array_push($aCFSocial,$aRow['avg_social_plus_plai']); - if(!isset($aCFIntermediaire)) $aCFIntermediaire=array(); - if(!is_null($aRow['avg_intermediaire_pli'])) array_push($aCFIntermediaire,$aRow['avg_intermediaire_pli']); - if(!is_null($aRow['avg_intermediaire_afl'])) array_push($aCFIntermediaire,$aRow['avg_intermediaire_afl']); - } - if ($aRow['id_indicateur_logement_familliaux_location']==8){ - $aPrixVenteSocial=array(); - if(!is_null($aRow['avg_social_pls'])) array_push($aPrixVenteSocial,$aRow['avg_social_pls']); - if(!is_null($aRow['avg_social_plus_plai'])) array_push($aPrixVenteSocial,$aRow['avg_social_plus_plai']); - if(count($aPrixVenteSocial)>0) $iPrixVenteSocial = round(array_sum($aPrixVenteSocial)/count($aPrixVenteSocial)); - $aPrixVenteIntermediaire=array(); - if(!is_null($aRow['avg_intermediaire_pli'])) array_push($aPrixVenteIntermediaire,$aRow['avg_intermediaire_pli']); - if(!is_null($aRow['avg_intermediaire_afl'])) array_push($aPrixVenteIntermediaire,$aRow['avg_intermediaire_afl']); - if(count($aPrixVenteIntermediaire)>0) $iPrixVenteIntermediaire = round(array_sum($aPrixVenteIntermediaire)/count($aPrixVenteIntermediaire)); - } - } - if(isset($aCFSocial) and count($aCFSocial)>0) $iCFSocial = round(array_sum($aCFSocial)/count($aCFSocial)); - if(isset($aCFIntermediaire)and count($aCFIntermediaire)>0) $iCFIntermediaire = round(array_sum($aCFIntermediaire)/count($aCFIntermediaire)); - // get habitat spe - $oResult10=$oConn->prepare("SELECT id_indicateur_habitat_specifique, round(coalesce(sum(residence_etudiant),0)+coalesce(sum(residence_personne_agee),0)+coalesce(sum(autre),0)) AS total FROM ".$sSchema.".composition_habitat_specifique_cp INNER JOIN ".$sSchema.".habitat_specifique ON composition_habitat_specifique_cp.id_habitat_specifique=habitat_specifique.id_habitat_specifique".$sWhereIdProgramme." AND id_indicateur_habitat_specifique IN (1,2) GROUP BY id_indicateur_habitat_specifique ORDER BY id_indicateur_habitat_specifique"); - $oResult10->execute(); - $iNbHabitatSpe=$oResult10->fetch(PDO::FETCH_ASSOC)['total']; - $iSdpHabitatSpe=$oResult10->fetch(PDO::FETCH_ASSOC)['total']; - $oResult10->closeCursor(); - // get bureau - $sSql6="SELECT id_indicateur_bureau, round(sum(total)::numeric) AS sum, round(avg(total)::numeric) AS avg FROM ".$sSchema.".bureau".$sWhereIdProgramme." AND id_indicateur_bureau IN (1,2,3,6) GROUP BY id_indicateur_bureau"; - foreach ($oConn->query($sSql6) as $aRow) { - if ($aRow['id_indicateur_bureau']==1) $iSdpBureau = $aRow['sum']; - if ($aRow['id_indicateur_bureau']==2 or $aRow['id_indicateur_bureau']==3) - isset($iCFBureau) ? array_push($iCFBureau,$aRow['avg']) : $iCFBureau=array($aRow['avg']); - if ($aRow['id_indicateur_bureau']==6) $iPrixVenteBureau = $aRow['avg']; - } - //echo print_r($iCFBureau,true); - if (isset($iCFBureau)) $iCFBureau = round(array_sum($iCFBureau)/count($iCFBureau)); - //get commerce/hotel - $sSql4="SELECT id_indicateur_hotel_commerce_service, round(coalesce(sum(commerce),0)+coalesce(sum(loisir_marchand),0)+coalesce(sum(service_act_artisanale),0)) AS sum_commerce, round(sum(hotel)) AS sum_hotel, round(avg(commerce)) AS avg_commerce, round(avg(loisir_marchand)) AS avg_loisir_marchand, round(avg(service_act_artisanale)) AS avg_service_act_artisanale, round(avg(hotel)) AS avg_hotel FROM ".$sSchema.".hotel_commerce_service".$sWhereIdProgramme." AND id_indicateur_hotel_commerce_service IN (2,3,4,8) GROUP BY id_indicateur_hotel_commerce_service"; - foreach ($oConn->query($sSql4) as $aRow) { - if ($aRow['id_indicateur_hotel_commerce_service']==2){ - $iSdpCommerce=$aRow['sum_commerce']; - $iSdpHotel=$aRow['sum_hotel']; - } - if ($aRow['id_indicateur_hotel_commerce_service']==3 or $aRow['id_indicateur_hotel_commerce_service']==4){ - if(!isset($aCFCommerce)) $aCFCommerce=array(); - if(!is_null($aRow['avg_commerce'])) array_push($aCFCommerce,$aRow['avg_commerce']); - if(!is_null($aRow['avg_loisir_marchand'])) array_push($aCFCommerce,$aRow['avg_loisir_marchand']); - if(!is_null($aRow['avg_service_act_artisanale'])) array_push($aCFCommerce,$aRow['avg_service_act_artisanale']); - if(!isset($aCFHotel)) $aCFHotel=array(); - if(!is_null($aRow['avg_hotel'])) array_push($aCFHotel,$aRow['avg_hotel']); - } - if ($aRow['id_indicateur_hotel_commerce_service']==8){ - $aPrixVenteCommerce=array(); - if(!is_null($aRow['avg_commerce'])) array_push($aPrixVenteCommerce,$aRow['avg_commerce']); - if(!is_null($aRow['avg_loisir_marchand'])) array_push($aPrixVenteCommerce,$aRow['avg_loisir_marchand']); - if(!is_null($aRow['avg_service_act_artisanale'])) array_push($aPrixVenteCommerce,$aRow['avg_service_act_artisanale']); - if(count($aPrixVenteCommerce)>0) $iPrixVenteCommerce = round(array_sum($aPrixVenteCommerce)/count($aPrixVenteCommerce)); - $iPrixVenteHotel = $aRow['avg_hotel']; - } - } - if (isset($aCFCommerce)) $iCFCommerce = round(array_sum($aCFCommerce)/count($aCFCommerce)); - if (isset($aCFHotel)) $iCFHotel = round(array_sum($aCFHotel)/count($aCFHotel)); - //get prod/activite - $sSql7="SELECT id_indicateur_activite_industrie, round(sum(production_industrie)) AS sum_production_industrie, round(sum(logistique)) AS sum_logistique, round(sum(autre)) AS sum_autre, round(avg(production_industrie)) AS avg_production_industrie, round(avg(logistique)) AS avg_logistique, round(avg(autre)) AS avg_autre FROM ".$sSchema.".activite_industrie".$sWhereIdProgramme." AND id_indicateur_activite_industrie IN (2,3,4,7) GROUP BY id_indicateur_activite_industrie"; - foreach ($oConn->query($sSql7) as $aRow){ - if ($aRow['id_indicateur_activite_industrie']==2){ - $iSdpProd=$aRow['sum_production_industrie']; - $iSdpLogistique=$aRow['sum_logistique']; - $iSdpActAutre=$aRow['avg_autre']; - } - if ($aRow['id_indicateur_activite_industrie']==3 or $aRow['id_indicateur_activite_industrie']==4){ - isset($iCFProd) ? array_push($iCFProd,$aRow['avg_production_industrie']) : $iCFProd=array($aRow['avg_production_industrie']); - isset($iCFLogistique) ? array_push($iCFProd,$aRow['avg_logistique']) : $iCFProd=array($aRow['avg_logistique']); - isset($iCFActAutre) ? array_push($iCFActAutre,$aRow['avg_autre']) : $iCFActAutre=array($aRow['avg_autre']); - } - if ($aRow['id_indicateur_activite_industrie']==7){ - $iPrixVenteProd = $aRow['avg_production_industrie']; - $iPrixVenteLogistique = $aRow['avg_logistique']; - $iPrixVenteActAutre = $aRow['avg_autre']; - } - } - if (isset($iCFProd)) $iCFProd = round(array_sum($iCFProd)/count($iCFProd)); - if (isset($iCFLogistique)) $iCFLogistique = round(array_sum($iCFLogistique)/count($iCFLogistique)); - if (isset($iCFActAutre)) $iCFActAutre = round(array_sum($iCFActAutre)/count($iCFActAutre)); - // get equipement - $oResult5 = $oConn->prepare("SELECT round(sum(sdp)::numeric) AS sdp FROM ".$sSchema.".equipement_structure".$sWhereIdProgramme); - $oResult5->execute(); - $iSdpEquipement = $oResult5->fetch(PDO::FETCH_ASSOC)['sdp']; - $oResult5->closeCursor(); - //get profil - $sSql12="SELECT id_type_acheteur_accession_libre, round(sum(nb)) AS nb, round(avg(pourc)) AS pourc FROM ".$sSchema.".profil_acheteur_accession_libre".$sWhereIdProgramme." AND id_type_acheteur_accession_libre IN (1,2) GROUP BY id_type_acheteur_accession_libre"; - foreach ($oConn->query($sSql12) as $aRow){ - if ($aRow['id_type_acheteur_accession_libre']==1){ - $iNbProprioOcc=$aRow['nb']; - $iPourcProprioOcc=$aRow['pourc']; - } - if ($aRow['id_type_acheteur_accession_libre']==2){ - $iNbInvest=$aRow['nb']; - $iPourcInvest=$aRow['pourc']; - } - } - // get granulometrie - $aGranulometrie=array(); - $aGranulometrie2=array('LG_FAM_ACC'=>array('T1'=>0,'T2'=>0,'T3'=>0,'T4'=>0,'T5'=>0,'T6'=>0), 'LG_FAM_LOC'=>array('T1'=>0,'T2'=>0,'T3'=>0,'T4'=>0,'T5'=>0,'T6'=>0), 'TOT_LG_SPE'=>array('T1'=>0,'T2'=>0,'T3'=>0,'T4'=>0,'T5'=>0,'T6'=>0)); - $aTypeGranulometrie=array('T1','T2','T3','T4','T5','T6','NB'); - foreach ($aTypeGranulometrie as $sTypeGranulometrie){ - $aTmp=array(); - $sSql13="SELECT code_composition_programme, sum(valeur) AS valeur FROM ".$sSchema.".granulometrie".$sWhereIdProgramme." AND code_type_granulometrie ='".$sTypeGranulometrie."' AND code_composition_programme IN ('TOT_LG_SPE','LG_FAM_ACC','LG_FAM_LOC','TOT_LG_FAM') GROUP BY code_composition_programme"; - foreach ($oConn->query($sSql13) as $aRow){ - if ($sTypeGranulometrie=='NB' && ($aRow['code_composition_programme']=='TOT_LG_FAM' || $aRow['code_composition_programme']=='TOT_LG_SPE')) $aTmp['TOT'] = $aTmp['TOT'] + $aRow['valeur']; - $aTmp[$aRow['code_composition_programme']]=$aRow['valeur']; - } - if (count($aTmp)>0) $aGranulometrie[$sTypeGranulometrie]=$aTmp; - if ($sTypeGranulometrie!='NB') - if (isset($sDataGranulometrie)) - $sDataGranulometrie=$sDataGranulometrie.','.array_sum($aTmp); - else - $sDataGranulometrie=array_sum($aTmp); - } - foreach ($aGranulometrie as $sTypeGranulometrie=>$aValues){ - if ($sTypeGranulometrie!='NB') - foreach ($aValues as $sCodeCompo=>$iValue){ - if (isset($aGranulometrie2[$sCodeCompo])) - $aGranulometrie2[$sCodeCompo][$sTypeGranulometrie]=$aGranulometrie2[$sCodeCompo][$sTypeGranulometrie]+$iValue; - } - - } - foreach ($aGranulometrie2 as $sCodeCompo=>$aValues) - $aGranulometrie2[$sCodeCompo] = implode(",", $aValues); - //echo '<br>'.print_r($aGranulometrie2,true); - } - - - include ('get_1_operation.html'); - }else{ - $sError="Erreur : ".$oResult->rowCount()." opération(s) trouvée(s)."; - $oResult->closeCursor(); - include ('get_error.html'); - } - } - }catch (PDOException $e){ - $sError="ERROR : ".$e->getMessage(); - include ('get_error.html'); - } - - }else{ - $sError="ERREUR : Pas d'opération passée en paramètre !"; - include ('get_error.html'); - } - } - -}else{ - $sError="ERREUR : Pas de token passé."; - include ('get_error.html'); -} - +<?php +// https://geo.urbalyon.org/doc/suivi_prod_immo/get_1_operation.php?id_operation=1041 + +if (isset($_REQUEST['token']) && !is_null($_REQUEST['token'])){ + session_id($_REQUEST['token']); + if (session_status() == PHP_SESSION_NONE) + session_start(); + + if (empty($_SESSION)) { + $sError="ERREUR : token invalide."; + include ('get_error.html'); + }else{ + if (isset($_REQUEST['id_operation']) && !is_null($_REQUEST['id_operation'])){ + require_once("../../rest/conf/properties.inc"); + require_once("properties_suivi_prod_immo.inc"); + $sSchema=$properties['schema_prod_immo']; + + try{ + $oConn = new PDO('pgsql:host='.$properties['server'].';port='.$properties['port'].';dbname='.$properties['db_prod_immo'], $properties['db_user_prod_immo'], $properties['db_pass_prod_immo']); + $oConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $oConn->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL); + + if($oConn){ + // get data Opérations + $sWhereIdOperation=" WHERE id_operation=".$_REQUEST['id_operation']; + $oResult = $oConn->prepare("SELECT *, ST_XMin(ST_Buffer(geom,50)) AS xmin, ST_YMin(ST_Buffer(geom,50)) AS ymin, ST_XMax(ST_Buffer(geom,50)) AS xmax, ST_YMax(ST_Buffer(geom,50)) AS ymax FROM ".$sSchema.".v_operation_layer".$sWhereIdOperation); + $oResult->execute(); + + if ($oResult->rowCount()>0){ + $aOperations = $oResult->fetchAll(); + $oResult->closeCursor(); + $aOperation =$aOperations[0]; + $aOperation['date_mise_a_jour'] = date("d/m/Y", strtotime($aOperation['date_mise_a_jour'])); + $sDataSdpPrev= $aOperation['sdp_logement'].",".$aOperation['sdp_bureau'].",".$aOperation['sdp_commerce_service'].",".$aOperation['sdp_locaux'].",".$aOperation['sdp_equipement']; + // get map image + $sNameMapImage=$_REQUEST['id_operation']."_operation.png"; + $sCommand = escapeshellcmd('python get_map_image_1_operation.py '.$aOperation['xmin'].' '.$aOperation['ymin'].' '.$aOperation['xmax'].' '.$aOperation['ymax'].' '.$sNameMapImage.' '.$_REQUEST['id_operation']); + $output = shell_exec($sCommand); + $sUrlMapImage=$properties['web_server_name']."/ws_data/vm4ms/map/tmp/".$sNameMapImage; + + // get data ilot + $oResult1 = $oConn->prepare("SELECT count(id_ilot) FROM ".$sSchema.".ilot".$sWhereIdOperation); + $oResult1->execute(); + $aIlot = $oResult1->fetch(PDO::FETCH_ASSOC); + $oResult1->closeCursor(); + $oResult2 = $oConn->prepare("SELECT count(DISTINCT programme_immobilier.id_ilot) FROM ".$sSchema.".programme_immobilier INNER JOIN ".$sSchema.".ilot ON programme_immobilier.id_ilot=ilot.id_ilot".$sWhereIdOperation); + $oResult2->execute(); + $aIlotProgramme = $oResult2->fetch(PDO::FETCH_ASSOC); + $iIlotSansProgramme = $aIlot['count']-$aIlotProgramme['count']; + $oResult2->closeCursor(); + // get data programme + $oResult3 = $oConn->prepare("SELECT array_to_string(array_agg(id_programme), ',') AS id_programme, round(avg(cout_construction_moyen)) AS cout_construction_moyen,round( avg(charge_fonciere_nette)) AS charge_fonciere_nette FROM ".$sSchema.".programme_immobilier INNER JOIN ".$sSchema.".ilot ON ilot.id_ilot=programme_immobilier.id_ilot ".$sWhereIdOperation." GROUP BY id_operation"); + $oResult3->execute(); + if ($oResult3->rowCount()>0){ + $aProgrammesStat=$oResult3->fetch(PDO::FETCH_ASSOC); + $sIdsProgramme = $aProgrammesStat['id_programme']; + $sWhereIdProgramme = " WHERE id_programme IN (".$sIdsProgramme.")"; + //echo $sWhereIdProgramme; + $oResult3->closeCursor(); + $oResult11=$oConn->prepare("SELECT nom_ilot, numero_pc, surface, id_programme, nom_programme, code_type_operateur, nom_demandeur, annee_debut, annee_fin FROM ".$sSchema.".programme_immobilier INNER JOIN ".$sSchema.".ilot ON ilot.id_ilot=programme_immobilier.id_ilot ".$sWhereIdOperation); + $oResult11->execute(); + $aProgrammes = $oResult11->fetchAll(); + $aSyntheseProgrammes=array(); + foreach ($aProgrammes as $iKey => $aProgramme){ + $aSyntheseProgrammes[$aProgramme['id_programme']]=array(); + $sSql12="SELECT code_composition_programme, code_type_granulometrie, valeur FROM ".$sSchema.".granulometrie WHERE id_programme IN (".$aProgramme['id_programme'].") ORDER BY code_composition_programme, code_type_granulometrie"; + foreach ($oConn->query($sSql12) as $aRow){ + if (!isset($aSyntheseProgrammes[$aProgramme['id_programme']][$aRow['code_composition_programme']])) $aSyntheseProgrammes[$aProgramme['id_programme']][$aRow['code_composition_programme']]=array(); + $aSyntheseProgrammes[$aProgramme['id_programme']][$aRow['code_composition_programme']][$aRow['code_type_granulometrie']]=$aRow['valeur']; + } + } + $oResult11->closeCursor(); + + + // get accession libre aidee + $sSql8="SELECT id_indicateur_logement_familliaux_accession, round(sum(accession_libre::numeric)) AS sum_accession_libre, round(coalesce(sum(accession_abordable::numeric),0)+coalesce(sum(accession_sociale_securise ::numeric),0)+coalesce(sum(psla::numeric),0)) AS sum_accession_aide, round(avg(accession_libre::numeric)) AS avg_accession_libre, round(avg(accession_abordable::numeric)) AS avg_accession_abordable, round(avg(accession_sociale_securise ::numeric)) AS avg_accession_sociale_securise , round(avg(psla::numeric)) AS avg_psla FROM ".$sSchema.".logement_familliaux_accession".$sWhereIdProgramme." AND id_indicateur_logement_familliaux_accession IN (1,2,4,5,8,9) GROUP BY id_indicateur_logement_familliaux_accession"; + foreach ($oConn->query($sSql8) as $aRow){ + if ($aRow['id_indicateur_logement_familliaux_accession']==1){ + isset($iNbLgtFam) ? $iNbLgtFam=$iNbLgtFam+$aRow['sum_accession_libre'] : $iNbLgtFam=$aRow['sum_accession_libre']; + isset($iNbLgtFam) ? $iNbLgtFam=$iNbLgtFam+$aRow['sum_accession_aide'] : $iNbLgtFam=$aRow['sum_accession_aide']; + } + if ($aRow['id_indicateur_logement_familliaux_accession']==2){ + $iSdpAccessionLibre=$aRow['sum_accession_libre']; + $iSdpAccessionAide=$aRow['sum_accession_aide']; + } + if ($aRow['id_indicateur_logement_familliaux_accession']==4 or $aRow['id_indicateur_logement_familliaux_accession']==5){ + if(!isset($aCFAccessionLibre)) $aCFAccessionLibre=array(); + if(!is_null($aRow['avg_accession_libre'])) array_push($aCFAccessionLibre,$aRow['avg_accession_libre']); + if(!isset($aCFAccessionAidee)) $aCFAccessionAidee=array(); + if(!is_null($aRow['avg_accession_abordable'])) array_push($aCFAccessionAidee,$aRow['avg_accession_abordable']); + if(!is_null($aRow['avg_accession_sociale_securise '])) array_push($aCFAccessionAidee,$aRow['avg_accession_sociale_securise ']); + if(!is_null($aRow['avg_psla'])) array_push($aCFAccessionAidee,$aRow['avg_psla']); + } + if ($aRow['id_indicateur_logement_familliaux_accession']==8 or $aRow['id_indicateur_logement_familliaux_accession']==9){ + if(!isset($aPVAccessionLibre)) $aPVAccessionLibre=array(); + if(!is_null($aRow['avg_accession_libre'])) array_push($aPVAccessionLibre,$aRow['avg_accession_libre']); + if(!isset($aPVAccessionAidee)) $aPVAccessionAidee=array(); + if(!is_null($aRow['avg_accession_abordable'])) array_push($aPVAccessionAidee,$aRow['avg_accession_abordable']); + if(!is_null($aRow['avg_accession_sociale_securise '])) array_push($aPVAccessionAidee,$aRow['avg_accession_sociale_securise ']); + if(!is_null($aRow['avg_psla'])) array_push($aPVAccessionAidee,$aRow['avg_psla']); + } + } + if(isset($aPVAccessionLibre) and count($aPVAccessionLibre)>0) $iPVAccessionLibre = round(array_sum($aPVAccessionLibre)/count($aPVAccessionLibre)); + if(isset($aPVAccessionAidee) and count($aPVAccessionAidee)>0) $iPVAccessionAidee = round(array_sum($aPVAccessionAidee)/count($aPVAccessionAidee)); + if(isset($aCFAccessionLibre) and count($aCFAccessionLibre)>0) $iCFAccessionLibre = round(array_sum($aCFAccessionLibre)/count($aCFAccessionLibre)); + if(isset($aCFAccessionAidee) and count($aCFAccessionAidee)>0) $iCFAccessionAidee = round(array_sum($aCFAccessionAidee)/count($aCFAccessionAidee)); + // get locatif social + $sSql9="SELECT id_indicateur_logement_familliaux_location, round(coalesce(sum(social_pls),0)+coalesce(sum(social_plus_plai),0)) AS sum_social, round(coalesce(sum(intermediaire_pli),0)+coalesce(sum(intermediaire_afl),0)) AS sum_intermediaire, round(avg(social_pls)) AS avg_social_pls, round(avg(social_plus_plai)) AS avg_social_plus_plai, round(avg(intermediaire_pli)) AS avg_intermediaire_pli, round(avg(intermediaire_afl)) AS avg_intermediaire_afl FROM ".$sSchema.".composition_logement_familliaux_location_cp INNER JOIN ".$sSchema.".logement_familliaux_location ON logement_familliaux_location.id_logement_familliaux_location=composition_logement_familliaux_location_cp.id_logement_familliaux_location".$sWhereIdProgramme." AND id_indicateur_logement_familliaux_location IN (1,2,4,5,8) GROUP BY id_indicateur_logement_familliaux_location"; + foreach ($oConn->query($sSql9) as $aRow){ + if ($aRow['id_indicateur_logement_familliaux_location']==1){ + isset($iNbLgtFam) ? $iNbLgtFam=$iNbLgtFam+$aRow['sum_social'] : $iNbLgtFam=$aRow['sum_social']; + isset($iNbLgtFam) ? $iNbLgtFam=$iNbLgtFam+$aRow['sum_intermediaire'] : $iNbLgtFam=$aRow['sum_intermediaire']; + } + if ($aRow['id_indicateur_logement_familliaux_location']==2){ + $iSdpLocSocial=$aRow['sum_social']; + $iSdpLocIntermediaire=$aRow['sum_intermediaire']; + } + if ($aRow['id_indicateur_logement_familliaux_location']==4 or $aRow['id_indicateur_logement_familliaux_location']==5){ + if(!isset($aCFSocial)) $aCFSocial=array(); + if(!is_null($aRow['avg_social_pls'])) array_push($aCFSocial,$aRow['avg_social_pls']); + if(!is_null($aRow['avg_social_plus_plai'])) array_push($aCFSocial,$aRow['avg_social_plus_plai']); + if(!isset($aCFIntermediaire)) $aCFIntermediaire=array(); + if(!is_null($aRow['avg_intermediaire_pli'])) array_push($aCFIntermediaire,$aRow['avg_intermediaire_pli']); + if(!is_null($aRow['avg_intermediaire_afl'])) array_push($aCFIntermediaire,$aRow['avg_intermediaire_afl']); + } + if ($aRow['id_indicateur_logement_familliaux_location']==8){ + $aPrixVenteSocial=array(); + if(!is_null($aRow['avg_social_pls'])) array_push($aPrixVenteSocial,$aRow['avg_social_pls']); + if(!is_null($aRow['avg_social_plus_plai'])) array_push($aPrixVenteSocial,$aRow['avg_social_plus_plai']); + if(count($aPrixVenteSocial)>0) $iPrixVenteSocial = round(array_sum($aPrixVenteSocial)/count($aPrixVenteSocial)); + $aPrixVenteIntermediaire=array(); + if(!is_null($aRow['avg_intermediaire_pli'])) array_push($aPrixVenteIntermediaire,$aRow['avg_intermediaire_pli']); + if(!is_null($aRow['avg_intermediaire_afl'])) array_push($aPrixVenteIntermediaire,$aRow['avg_intermediaire_afl']); + if(count($aPrixVenteIntermediaire)>0) $iPrixVenteIntermediaire = round(array_sum($aPrixVenteIntermediaire)/count($aPrixVenteIntermediaire)); + } + } + if(isset($aCFSocial) and count($aCFSocial)>0) $iCFSocial = round(array_sum($aCFSocial)/count($aCFSocial)); + if(isset($aCFIntermediaire)and count($aCFIntermediaire)>0) $iCFIntermediaire = round(array_sum($aCFIntermediaire)/count($aCFIntermediaire)); + // get habitat spe + $oResult10=$oConn->prepare("SELECT id_indicateur_habitat_specifique, round(coalesce(sum(residence_etudiant),0)+coalesce(sum(residence_personne_agee),0)+coalesce(sum(autre),0)) AS total FROM ".$sSchema.".composition_habitat_specifique_cp INNER JOIN ".$sSchema.".habitat_specifique ON composition_habitat_specifique_cp.id_habitat_specifique=habitat_specifique.id_habitat_specifique".$sWhereIdProgramme." AND id_indicateur_habitat_specifique IN (1,2) GROUP BY id_indicateur_habitat_specifique ORDER BY id_indicateur_habitat_specifique"); + $oResult10->execute(); + $iNbHabitatSpe=$oResult10->fetch(PDO::FETCH_ASSOC)['total']; + $iSdpHabitatSpe=$oResult10->fetch(PDO::FETCH_ASSOC)['total']; + $oResult10->closeCursor(); + // get bureau + $sSql6="SELECT id_indicateur_bureau, round(sum(total)::numeric) AS sum, round(avg(total)::numeric) AS avg FROM ".$sSchema.".bureau".$sWhereIdProgramme." AND id_indicateur_bureau IN (1,2,3,6) GROUP BY id_indicateur_bureau"; + foreach ($oConn->query($sSql6) as $aRow) { + if ($aRow['id_indicateur_bureau']==1) $iSdpBureau = $aRow['sum']; + if ($aRow['id_indicateur_bureau']==2 or $aRow['id_indicateur_bureau']==3) + isset($iCFBureau) ? array_push($iCFBureau,$aRow['avg']) : $iCFBureau=array($aRow['avg']); + if ($aRow['id_indicateur_bureau']==6) $iPrixVenteBureau = $aRow['avg']; + } + //echo print_r($iCFBureau,true); + if (isset($iCFBureau)) $iCFBureau = round(array_sum($iCFBureau)/count($iCFBureau)); + //get commerce/hotel + $sSql4="SELECT id_indicateur_hotel_commerce_service, round(coalesce(sum(commerce),0)+coalesce(sum(loisir_marchand),0)+coalesce(sum(service_act_artisanale),0)) AS sum_commerce, round(sum(hotel)) AS sum_hotel, round(avg(commerce)) AS avg_commerce, round(avg(loisir_marchand)) AS avg_loisir_marchand, round(avg(service_act_artisanale)) AS avg_service_act_artisanale, round(avg(hotel)) AS avg_hotel FROM ".$sSchema.".hotel_commerce_service".$sWhereIdProgramme." AND id_indicateur_hotel_commerce_service IN (2,3,4,8) GROUP BY id_indicateur_hotel_commerce_service"; + foreach ($oConn->query($sSql4) as $aRow) { + if ($aRow['id_indicateur_hotel_commerce_service']==2){ + $iSdpCommerce=$aRow['sum_commerce']; + $iSdpHotel=$aRow['sum_hotel']; + } + if ($aRow['id_indicateur_hotel_commerce_service']==3 or $aRow['id_indicateur_hotel_commerce_service']==4){ + if(!isset($aCFCommerce)) $aCFCommerce=array(); + if(!is_null($aRow['avg_commerce'])) array_push($aCFCommerce,$aRow['avg_commerce']); + if(!is_null($aRow['avg_loisir_marchand'])) array_push($aCFCommerce,$aRow['avg_loisir_marchand']); + if(!is_null($aRow['avg_service_act_artisanale'])) array_push($aCFCommerce,$aRow['avg_service_act_artisanale']); + if(!isset($aCFHotel)) $aCFHotel=array(); + if(!is_null($aRow['avg_hotel'])) array_push($aCFHotel,$aRow['avg_hotel']); + } + if ($aRow['id_indicateur_hotel_commerce_service']==8){ + $aPrixVenteCommerce=array(); + if(!is_null($aRow['avg_commerce'])) array_push($aPrixVenteCommerce,$aRow['avg_commerce']); + if(!is_null($aRow['avg_loisir_marchand'])) array_push($aPrixVenteCommerce,$aRow['avg_loisir_marchand']); + if(!is_null($aRow['avg_service_act_artisanale'])) array_push($aPrixVenteCommerce,$aRow['avg_service_act_artisanale']); + if(count($aPrixVenteCommerce)>0) $iPrixVenteCommerce = round(array_sum($aPrixVenteCommerce)/count($aPrixVenteCommerce)); + $iPrixVenteHotel = $aRow['avg_hotel']; + } + } + if (isset($aCFCommerce)) $iCFCommerce = round(array_sum($aCFCommerce)/count($aCFCommerce)); + if (isset($aCFHotel)) $iCFHotel = round(array_sum($aCFHotel)/count($aCFHotel)); + //get prod/activite + $sSql7="SELECT id_indicateur_activite_industrie, round(sum(production_industrie)) AS sum_production_industrie, round(sum(logistique)) AS sum_logistique, round(sum(autre)) AS sum_autre, round(avg(production_industrie)) AS avg_production_industrie, round(avg(logistique)) AS avg_logistique, round(avg(autre)) AS avg_autre FROM ".$sSchema.".activite_industrie".$sWhereIdProgramme." AND id_indicateur_activite_industrie IN (2,3,4,7) GROUP BY id_indicateur_activite_industrie"; + foreach ($oConn->query($sSql7) as $aRow){ + if ($aRow['id_indicateur_activite_industrie']==2){ + $iSdpProd=$aRow['sum_production_industrie']; + $iSdpLogistique=$aRow['sum_logistique']; + $iSdpActAutre=$aRow['avg_autre']; + } + if ($aRow['id_indicateur_activite_industrie']==3 or $aRow['id_indicateur_activite_industrie']==4){ + isset($iCFProd) ? array_push($iCFProd,$aRow['avg_production_industrie']) : $iCFProd=array($aRow['avg_production_industrie']); + isset($iCFLogistique) ? array_push($iCFProd,$aRow['avg_logistique']) : $iCFProd=array($aRow['avg_logistique']); + isset($iCFActAutre) ? array_push($iCFActAutre,$aRow['avg_autre']) : $iCFActAutre=array($aRow['avg_autre']); + } + if ($aRow['id_indicateur_activite_industrie']==7){ + $iPrixVenteProd = $aRow['avg_production_industrie']; + $iPrixVenteLogistique = $aRow['avg_logistique']; + $iPrixVenteActAutre = $aRow['avg_autre']; + } + } + if (isset($iCFProd)) $iCFProd = round(array_sum($iCFProd)/count($iCFProd)); + if (isset($iCFLogistique)) $iCFLogistique = round(array_sum($iCFLogistique)/count($iCFLogistique)); + if (isset($iCFActAutre)) $iCFActAutre = round(array_sum($iCFActAutre)/count($iCFActAutre)); + // get equipement + $oResult5 = $oConn->prepare("SELECT round(sum(sdp)::numeric) AS sdp FROM ".$sSchema.".equipement_structure".$sWhereIdProgramme); + $oResult5->execute(); + $iSdpEquipement = $oResult5->fetch(PDO::FETCH_ASSOC)['sdp']; + $oResult5->closeCursor(); + //get profil + $sSql12="SELECT id_type_acheteur_accession_libre, round(sum(nb)) AS nb, round(avg(pourc)) AS pourc FROM ".$sSchema.".profil_acheteur_accession_libre".$sWhereIdProgramme." AND id_type_acheteur_accession_libre IN (1,2) GROUP BY id_type_acheteur_accession_libre"; + foreach ($oConn->query($sSql12) as $aRow){ + if ($aRow['id_type_acheteur_accession_libre']==1){ + $iNbProprioOcc=$aRow['nb']; + $iPourcProprioOcc=$aRow['pourc']; + } + if ($aRow['id_type_acheteur_accession_libre']==2){ + $iNbInvest=$aRow['nb']; + $iPourcInvest=$aRow['pourc']; + } + } + // get granulometrie + $aGranulometrie=array(); + $aGranulometrie2=array('LG_FAM_ACC'=>array('T1'=>0,'T2'=>0,'T3'=>0,'T4'=>0,'T5'=>0,'T6'=>0), 'LG_FAM_LOC'=>array('T1'=>0,'T2'=>0,'T3'=>0,'T4'=>0,'T5'=>0,'T6'=>0), 'TOT_LG_SPE'=>array('T1'=>0,'T2'=>0,'T3'=>0,'T4'=>0,'T5'=>0,'T6'=>0)); + $aTypeGranulometrie=array('T1','T2','T3','T4','T5','T6','NB'); + foreach ($aTypeGranulometrie as $sTypeGranulometrie){ + $aTmp=array(); + $sSql13="SELECT code_composition_programme, sum(valeur) AS valeur FROM ".$sSchema.".granulometrie".$sWhereIdProgramme." AND code_type_granulometrie ='".$sTypeGranulometrie."' AND code_composition_programme IN ('TOT_LG_SPE','LG_FAM_ACC','LG_FAM_LOC','TOT_LG_FAM') GROUP BY code_composition_programme"; + foreach ($oConn->query($sSql13) as $aRow){ + if ($sTypeGranulometrie=='NB' && ($aRow['code_composition_programme']=='TOT_LG_FAM' || $aRow['code_composition_programme']=='TOT_LG_SPE')) $aTmp['TOT'] = $aTmp['TOT'] + $aRow['valeur']; + $aTmp[$aRow['code_composition_programme']]=$aRow['valeur']; + } + if (count($aTmp)>0) $aGranulometrie[$sTypeGranulometrie]=$aTmp; + if ($sTypeGranulometrie!='NB') + if (isset($sDataGranulometrie)) + $sDataGranulometrie=$sDataGranulometrie.','.array_sum($aTmp); + else + $sDataGranulometrie=array_sum($aTmp); + } + foreach ($aGranulometrie as $sTypeGranulometrie=>$aValues){ + if ($sTypeGranulometrie!='NB') + foreach ($aValues as $sCodeCompo=>$iValue){ + if (isset($aGranulometrie2[$sCodeCompo])) + $aGranulometrie2[$sCodeCompo][$sTypeGranulometrie]=$aGranulometrie2[$sCodeCompo][$sTypeGranulometrie]+$iValue; + } + + } + foreach ($aGranulometrie2 as $sCodeCompo=>$aValues) + $aGranulometrie2[$sCodeCompo] = implode(",", $aValues); + //echo '<br>'.print_r($aGranulometrie2,true); + } + + + include ('get_1_operation.html'); + }else{ + $sError="Erreur : ".$oResult->rowCount()." opération(s) trouvée(s)."; + $oResult->closeCursor(); + include ('get_error.html'); + } + } + }catch (PDOException $e){ + $sError="ERROR : ".$e->getMessage(); + include ('get_error.html'); + } + + }else{ + $sError="ERREUR : Pas d'opération passée en paramètre !"; + include ('get_error.html'); + } + } + +}else{ + $sError="ERREUR : Pas de token passé."; + include ('get_error.html'); +} + ?> \ No newline at end of file diff --git a/src/vitis/vas/doc/suivi_prod_immo/get_2_type.php b/src/vitis/vas/doc/suivi_prod_immo/get_2_type.php index 258036413949ad9aff3474f75537391dae5de6cc..3a50e02bbf8f5486be7d75b52c9d2a88e64bc29f 100644 --- a/src/vitis/vas/doc/suivi_prod_immo/get_2_type.php +++ b/src/vitis/vas/doc/suivi_prod_immo/get_2_type.php @@ -1,125 +1,125 @@ -<?php -// https://geo.urbalyon.org/doc/suivi_prod_immo/get_2_type.php?id_ctm=5 -if (isset($_REQUEST['token']) && !is_null($_REQUEST['token'])){ - session_id($_REQUEST['token']); - if (session_status() == PHP_SESSION_NONE) - session_start(); - - if (empty($_SESSION)) { - $sError="ERREUR : token invalide."; - include ('get_error.html'); - }else{ - - if ((isset($_REQUEST['id_ctm']) && !is_null($_REQUEST['id_ctm'])) or (isset($_REQUEST['id_commune']) && !is_null($_REQUEST['id_commune']))){ - require_once("../../rest/conf/properties.inc"); - require_once("properties_suivi_prod_immo.inc"); - $sSchema=$properties['schema_prod_immo']; - - try{ - $oConn = new PDO('pgsql:host='.$properties['server'].';port='.$properties['port'].';dbname='.$properties['db_prod_immo'], $properties['db_user_prod_immo'], $properties['db_pass_prod_immo']); - $oConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - $oConn->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL); - - if($oConn){ - $sFiltre=""; - // get data Opérations - if (isset($_REQUEST['id_ctm'])) $sWhereClause=" WHERE id_ctm=".$_REQUEST['id_ctm']; - if (isset($_REQUEST['id_commune'])) $sWhereClause=" WHERE operation.id_commune=".$_REQUEST['id_commune']; - $sWhereClause2=$sWhereClause; - if (isset($_REQUEST['code_procedure_amenagement']) && !is_null($_REQUEST['code_procedure_amenagement'])){ - if($sFiltre!='') $sFiltre.="<br>"; - $sFiltre.="Procédure d'aménagement : ".$_REQUEST['code_procedure_amenagement']; - if($_REQUEST['code_procedure_amenagement']=='ND') - $sWhereClause2=$sWhereClause2." AND (code_procedure_amenagement='ND' OR code_procedure_amenagement IS NULL)"; - else - $sWhereClause2=$sWhereClause2." AND code_procedure_amenagement='".$_REQUEST['code_procedure_amenagement']."'"; - } - if (isset($_REQUEST['code_financement_equ_public']) && !is_null($_REQUEST['code_financement_equ_public'])){ - if($sFiltre!='') $sFiltre.="<br>"; - $sFiltre.="Type de financement : ".$_REQUEST['code_financement_equ_public']; - if($_REQUEST['code_financement_equ_public']=='ND') - $sWhereClause2=$sWhereClause2." AND (operation_tr_financement_equ_public.code_financement_equ_public='ND' OR operation_tr_financement_equ_public.code_financement_equ_public IS NULL) "; - else - $sWhereClause2=$sWhereClause2." AND operation_tr_financement_equ_public.code_financement_equ_public='".$_REQUEST['code_financement_equ_public']."'"; - } - if (isset($_REQUEST['code_suivi']) && !is_null($_REQUEST['code_suivi'])){ - if($sFiltre!='') $sFiltre.="<br>"; - $sFiltre.="Suivi de l'opération : ".$_REQUEST['code_suivi']; - if($_REQUEST['code_suivi']=='ND') - $sWhereClause2=$sWhereClause2." AND (code_suivi='ND' OR code_suivi IS NULL) "; - else - $sWhereClause2=$sWhereClause2." AND code_suivi='".$_REQUEST['code_suivi']."'"; - } - - if (isset($_REQUEST['id_ctm'])){ - $oResult = $oConn->prepare("SELECT nom_ctm, ST_XMin(ST_Buffer(geom,150)) AS xmin, ST_YMin(ST_Buffer(geom,150)) AS ymin, ST_XMax(ST_Buffer(geom,150)) AS xmax, ST_YMax(ST_Buffer(geom,150)) AS ymax FROM ".$sSchema.".conference_territoriale_maire ".$sWhereClause); - $sNameMapImage="ctm_".$_REQUEST['id_ctm']."_porteur.png"; - } - if (isset($_REQUEST['id_commune'])){ - $oResult = $oConn->prepare("SELECT nom_commune, ST_XMin(ST_Buffer(geom,150)) AS xmin, ST_YMin(ST_Buffer(geom,150)) AS ymin, ST_XMax(ST_Buffer(geom,150)) AS xmax, ST_YMax(ST_Buffer(geom,150)) AS ymax FROM ".$sSchema.".commune WHERE id_commune=".$_REQUEST['id_commune']); - $sNameMapImage="commune_".$_REQUEST['id_commune']."_porteur.png"; - } - $oResult->execute(); - - if ($oResult->rowCount()>0){ - $aCTM = $oResult->fetchAll(); - $aCTM = $aCTM[0]; - $oResult->closeCursor(); - // get map image - $aIdOperation=array(); - // echo "SELECT id_ctm, array_to_string(array_agg(operation.id_operation), ',') AS id_operation FROM (".$sSchema.".operation INNER JOIN ".$sSchema.".operation_ctm ON operation.id_operation=operation_ctm.id_operation) INNER JOIN ".$sSchema.".operation_tr_financement_equ_public ON operation.id_operation=operation_tr_financement_equ_public.id_operation ".$sWhereClause2." GROUP BY id_ctm"; - $oResult2 = $oConn->prepare("SELECT id_ctm, array_to_string(array_agg(operation.id_operation), ',') AS id_operation FROM (".$sSchema.".operation INNER JOIN ".$sSchema.".operation_ctm ON operation.id_operation=operation_ctm.id_operation) INNER JOIN ".$sSchema.".operation_tr_financement_equ_public ON operation.id_operation=operation_tr_financement_equ_public.id_operation ".$sWhereClause2." GROUP BY id_ctm"); - $oResult2->execute(); - $aOperations = $oResult2->fetchAll(); - $oResult2->closeCursor(); - if(count($aOperations[0])>0){ - $aOperations = $aOperations[0]; - $sCommand = escapeshellcmd('python get_map_image_2_type.py '.$aCTM['xmin'].' '.$aCTM['ymin'].' '.$aCTM['xmax'].' '.$aCTM['ymax'].' '.$sNameMapImage.' '.$aOperations['id_operation']); - // echo $sCommand; - $output = shell_exec($sCommand);/**/ - $sUrlMapImage=$properties['web_server_name']."/ws_data/vm4ms/map/tmp/".$sNameMapImage; - $sSql="SELECT code_financement_equ_public, count(DISTINCT id_programme), array_to_string(array_agg(id_programme), ',') AS id_programme, round(avg(charge_fonciere_moy::numeric)) AS charge_fonciere_moy FROM (SELECT id_programme, CASE WHEN operation_tr_financement_equ_public.code_financement_equ_public='PUP' THEN operation_tr_financement_equ_public.code_financement_equ_public WHEN operation_tr_financement_equ_public.code_financement_equ_public='FINZAC' THEN operation_tr_financement_equ_public.code_financement_equ_public WHEN operation_tr_financement_equ_public.code_financement_equ_public='TA' THEN operation_tr_financement_equ_public.code_financement_equ_public WHEN operation_tr_financement_equ_public.code_financement_equ_public='TAM' THEN operation_tr_financement_equ_public.code_financement_equ_public WHEN operation_tr_financement_equ_public.code_financement_equ_public='AUT' THEN operation_tr_financement_equ_public.code_financement_equ_public WHEN operation_tr_financement_equ_public.code_financement_equ_public='PEPE' THEN operation_tr_financement_equ_public.code_financement_equ_public ELSE 'ND' END AS code_financement_equ_public, charge_fonciere_moy FROM (((".$sSchema.".operation LEFT JOIN ".$sSchema.".operation_tr_financement_equ_public ON operation.id_operation=operation_tr_financement_equ_public.id_operation) INNER JOIN ".$sSchema.".ilot ON ilot.id_operation=operation.id_operation) INNER JOIN ".$sSchema.".programme_immobilier ON programme_immobilier.id_ilot=ilot.id_ilot) INNER JOIN ".$sSchema.".operation_ctm ON operation_ctm.id_operation=operation.id_operation ".$sWhereClause2.") AS t GROUP BY code_financement_equ_public"; - // echo $sSql; - $aPourcCFPV=$aPV=$aCF=$aNb=array(); - foreach ($oConn->query($sSql) as $aRow){ - if(!is_null($aRow['count'])) $aNb[$aRow['code_financement_equ_public']]=$aRow['count']; - if(!is_null($aRow['charge_fonciere_moy'])) $aCF[$aRow['code_financement_equ_public']]=$aRow['charge_fonciere_moy']; - $oResult3 = $oConn->prepare("SELECT round((COALESCE(avg1, 0) + COALESCE(avg2, 0) + COALESCE(avg3, 0) + COALESCE(avg4)) / ( CASE WHEN avg1 IS NULL THEN 0 ELSE 1 END + CASE WHEN avg2 IS NULL THEN 0 ELSE 1 END + CASE WHEN avg3 IS NULL THEN 0 ELSE 1 END + CASE WHEN avg4 IS NULL THEN 0 ELSE 1 END)) AS pv_moy FROM (SELECT round(avg(accession_libre::numeric)) AS avg1, round(avg(accession_abordable::numeric)) AS avg2, round(avg(accession_sociale_securise::numeric)) AS avg3, round(avg(psla::numeric)) AS avg4 FROM ".$sSchema.".logement_familliaux_accession WHERE id_programme IN (".$aRow['id_programme'].") AND id_indicateur_logement_familliaux_accession IN (8,9)) AS t"); - $oResult3->execute(); - $aPrixVenteMoy = $oResult3->fetchAll(); - if (isset($aPrixVenteMoy[0])) $aPV[$aRow['code_financement_equ_public']]=$aPrixVenteMoy[0]['pv_moy']; - $oResult3->closeCursor(); - } - if(isset($aCF['PUP']) && isset($aPV['PUP'])) $aPourcCFPV['PUP']=round(($aCF['PUP']/$aPV['PUP'])*100,1); - if(isset($aCF['FINZAC']) && isset($aPV['FINZAC'])) $aPourcCFPV['FINZAC']=round(($aCF['FINZAC']/$aPV['FINZAC'])*100,1); - if(isset($aCF['TA']) && isset($aPV['TA'])) $aPourcCFPV['TA']=round(($aCF['TA']/$aPV['TA'])*100,1); - if(isset($aCF['TAM']) && isset($aPV['TAM'])) $aPourcCFPV['TAM']=round(($aCF['TAM']/$aPV['TAM'])*100,1); - if(isset($aCF['PEPE']) && isset($aPV['PEPE'])) $aPourcCFPV['PEPE']=round(($aCF['PEPE']/$aPV['PEPE'])*100,1); - if(isset($aCF['AUT']) && isset($aPV['AUT'])) $aPourcCFPV['AUT']=round(($aCF['AUT']/$aPV['AUT'])*100,1); - if(isset($aCF['ND']) && isset($aPV['ND'])) $aPourcCFPV['ND']=round(($aCF['ND']/$aPV['ND'])*100,1); - // Moyenne pondérée au nombre d'opération total - // TODO pondérer au nombre d'opération ayant une valeur - } - include ('get_2_type.html'); - }else{ - $sError="Erreur : ".$oResult->rowCount()." conférence des maires trouvée."; - $oResult->closeCursor(); - include ('get_error.html'); - } - } - }catch (PDOException $e){ - $sError="ERROR : ".$e->getMessage(); - include ('get_error.html'); - } - - }else{ - $sError="ERREUR : Pas de CTM ou de communes passé en paramètre !"; - include ('get_error.html'); - } - } - -}else{ - $sError="ERREUR : Pas de token passé."; - include ('get_error.html'); -} +<?php +// https://geo.urbalyon.org/doc/suivi_prod_immo/get_2_type.php?id_ctm=5 +if (isset($_REQUEST['token']) && !is_null($_REQUEST['token'])){ + session_id($_REQUEST['token']); + if (session_status() == PHP_SESSION_NONE) + session_start(); + + if (empty($_SESSION)) { + $sError="ERREUR : token invalide."; + include ('get_error.html'); + }else{ + + if ((isset($_REQUEST['id_ctm']) && !is_null($_REQUEST['id_ctm'])) or (isset($_REQUEST['id_commune']) && !is_null($_REQUEST['id_commune']))){ + require_once("../../rest/conf/properties.inc"); + require_once("properties_suivi_prod_immo.inc"); + $sSchema=$properties['schema_prod_immo']; + + try{ + $oConn = new PDO('pgsql:host='.$properties['server'].';port='.$properties['port'].';dbname='.$properties['db_prod_immo'], $properties['db_user_prod_immo'], $properties['db_pass_prod_immo']); + $oConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $oConn->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL); + + if($oConn){ + $sFiltre=""; + // get data Opérations + if (isset($_REQUEST['id_ctm'])) $sWhereClause=" WHERE id_ctm=".$_REQUEST['id_ctm']; + if (isset($_REQUEST['id_commune'])) $sWhereClause=" WHERE operation.id_commune=".$_REQUEST['id_commune']; + $sWhereClause2=$sWhereClause; + if (isset($_REQUEST['code_procedure_amenagement']) && !is_null($_REQUEST['code_procedure_amenagement'])){ + if($sFiltre!='') $sFiltre.="<br>"; + $sFiltre.="Procédure d'aménagement : ".$_REQUEST['code_procedure_amenagement']; + if($_REQUEST['code_procedure_amenagement']=='ND') + $sWhereClause2=$sWhereClause2." AND (code_procedure_amenagement='ND' OR code_procedure_amenagement IS NULL)"; + else + $sWhereClause2=$sWhereClause2." AND code_procedure_amenagement='".$_REQUEST['code_procedure_amenagement']."'"; + } + if (isset($_REQUEST['code_financement_equ_public']) && !is_null($_REQUEST['code_financement_equ_public'])){ + if($sFiltre!='') $sFiltre.="<br>"; + $sFiltre.="Type de financement : ".$_REQUEST['code_financement_equ_public']; + if($_REQUEST['code_financement_equ_public']=='ND') + $sWhereClause2=$sWhereClause2." AND (operation_tr_financement_equ_public.code_financement_equ_public='ND' OR operation_tr_financement_equ_public.code_financement_equ_public IS NULL) "; + else + $sWhereClause2=$sWhereClause2." AND operation_tr_financement_equ_public.code_financement_equ_public='".$_REQUEST['code_financement_equ_public']."'"; + } + if (isset($_REQUEST['code_suivi']) && !is_null($_REQUEST['code_suivi'])){ + if($sFiltre!='') $sFiltre.="<br>"; + $sFiltre.="Suivi de l'opération : ".$_REQUEST['code_suivi']; + if($_REQUEST['code_suivi']=='ND') + $sWhereClause2=$sWhereClause2." AND (code_suivi='ND' OR code_suivi IS NULL) "; + else + $sWhereClause2=$sWhereClause2." AND code_suivi='".$_REQUEST['code_suivi']."'"; + } + + if (isset($_REQUEST['id_ctm'])){ + $oResult = $oConn->prepare("SELECT nom_ctm, ST_XMin(ST_Buffer(geom,150)) AS xmin, ST_YMin(ST_Buffer(geom,150)) AS ymin, ST_XMax(ST_Buffer(geom,150)) AS xmax, ST_YMax(ST_Buffer(geom,150)) AS ymax FROM ".$sSchema.".conference_territoriale_maire ".$sWhereClause); + $sNameMapImage="ctm_".$_REQUEST['id_ctm']."_porteur.png"; + } + if (isset($_REQUEST['id_commune'])){ + $oResult = $oConn->prepare("SELECT nom_commune, ST_XMin(ST_Buffer(geom,150)) AS xmin, ST_YMin(ST_Buffer(geom,150)) AS ymin, ST_XMax(ST_Buffer(geom,150)) AS xmax, ST_YMax(ST_Buffer(geom,150)) AS ymax FROM ".$sSchema.".commune WHERE id_commune=".$_REQUEST['id_commune']); + $sNameMapImage="commune_".$_REQUEST['id_commune']."_porteur.png"; + } + $oResult->execute(); + + if ($oResult->rowCount()>0){ + $aCTM = $oResult->fetchAll(); + $aCTM = $aCTM[0]; + $oResult->closeCursor(); + // get map image + $aIdOperation=array(); + // echo "SELECT id_ctm, array_to_string(array_agg(operation.id_operation), ',') AS id_operation FROM (".$sSchema.".operation INNER JOIN ".$sSchema.".operation_ctm ON operation.id_operation=operation_ctm.id_operation) INNER JOIN ".$sSchema.".operation_tr_financement_equ_public ON operation.id_operation=operation_tr_financement_equ_public.id_operation ".$sWhereClause2." GROUP BY id_ctm"; + $oResult2 = $oConn->prepare("SELECT id_ctm, array_to_string(array_agg(operation.id_operation), ',') AS id_operation FROM (".$sSchema.".operation INNER JOIN ".$sSchema.".operation_ctm ON operation.id_operation=operation_ctm.id_operation) INNER JOIN ".$sSchema.".operation_tr_financement_equ_public ON operation.id_operation=operation_tr_financement_equ_public.id_operation ".$sWhereClause2." GROUP BY id_ctm"); + $oResult2->execute(); + $aOperations = $oResult2->fetchAll(); + $oResult2->closeCursor(); + if(count($aOperations[0])>0){ + $aOperations = $aOperations[0]; + $sCommand = escapeshellcmd('python get_map_image_2_type.py '.$aCTM['xmin'].' '.$aCTM['ymin'].' '.$aCTM['xmax'].' '.$aCTM['ymax'].' '.$sNameMapImage.' '.$aOperations['id_operation']); + // echo $sCommand; + $output = shell_exec($sCommand);/**/ + $sUrlMapImage=$properties['web_server_name']."/ws_data/vm4ms/map/tmp/".$sNameMapImage; + $sSql="SELECT code_financement_equ_public, count(DISTINCT id_programme), array_to_string(array_agg(id_programme), ',') AS id_programme, round(avg(charge_fonciere_moy::numeric)) AS charge_fonciere_moy FROM (SELECT id_programme, CASE WHEN operation_tr_financement_equ_public.code_financement_equ_public='PUP' THEN operation_tr_financement_equ_public.code_financement_equ_public WHEN operation_tr_financement_equ_public.code_financement_equ_public='FINZAC' THEN operation_tr_financement_equ_public.code_financement_equ_public WHEN operation_tr_financement_equ_public.code_financement_equ_public='TA' THEN operation_tr_financement_equ_public.code_financement_equ_public WHEN operation_tr_financement_equ_public.code_financement_equ_public='TAM' THEN operation_tr_financement_equ_public.code_financement_equ_public WHEN operation_tr_financement_equ_public.code_financement_equ_public='AUT' THEN operation_tr_financement_equ_public.code_financement_equ_public WHEN operation_tr_financement_equ_public.code_financement_equ_public='PEPE' THEN operation_tr_financement_equ_public.code_financement_equ_public ELSE 'ND' END AS code_financement_equ_public, charge_fonciere_moy FROM (((".$sSchema.".operation LEFT JOIN ".$sSchema.".operation_tr_financement_equ_public ON operation.id_operation=operation_tr_financement_equ_public.id_operation) INNER JOIN ".$sSchema.".ilot ON ilot.id_operation=operation.id_operation) INNER JOIN ".$sSchema.".programme_immobilier ON programme_immobilier.id_ilot=ilot.id_ilot) INNER JOIN ".$sSchema.".operation_ctm ON operation_ctm.id_operation=operation.id_operation ".$sWhereClause2.") AS t GROUP BY code_financement_equ_public"; + // echo $sSql; + $aPourcCFPV=$aPV=$aCF=$aNb=array(); + foreach ($oConn->query($sSql) as $aRow){ + if(!is_null($aRow['count'])) $aNb[$aRow['code_financement_equ_public']]=$aRow['count']; + if(!is_null($aRow['charge_fonciere_moy'])) $aCF[$aRow['code_financement_equ_public']]=$aRow['charge_fonciere_moy']; + $oResult3 = $oConn->prepare("SELECT round((COALESCE(avg1, 0) + COALESCE(avg2, 0) + COALESCE(avg3, 0) + COALESCE(avg4)) / ( CASE WHEN avg1 IS NULL THEN 0 ELSE 1 END + CASE WHEN avg2 IS NULL THEN 0 ELSE 1 END + CASE WHEN avg3 IS NULL THEN 0 ELSE 1 END + CASE WHEN avg4 IS NULL THEN 0 ELSE 1 END)) AS pv_moy FROM (SELECT round(avg(accession_libre::numeric)) AS avg1, round(avg(accession_abordable::numeric)) AS avg2, round(avg(accession_sociale_securise::numeric)) AS avg3, round(avg(psla::numeric)) AS avg4 FROM ".$sSchema.".logement_familliaux_accession WHERE id_programme IN (".$aRow['id_programme'].") AND id_indicateur_logement_familliaux_accession IN (8,9)) AS t"); + $oResult3->execute(); + $aPrixVenteMoy = $oResult3->fetchAll(); + if (isset($aPrixVenteMoy[0])) $aPV[$aRow['code_financement_equ_public']]=$aPrixVenteMoy[0]['pv_moy']; + $oResult3->closeCursor(); + } + if(isset($aCF['PUP']) && isset($aPV['PUP'])) $aPourcCFPV['PUP']=round(($aCF['PUP']/$aPV['PUP'])*100,1); + if(isset($aCF['FINZAC']) && isset($aPV['FINZAC'])) $aPourcCFPV['FINZAC']=round(($aCF['FINZAC']/$aPV['FINZAC'])*100,1); + if(isset($aCF['TA']) && isset($aPV['TA'])) $aPourcCFPV['TA']=round(($aCF['TA']/$aPV['TA'])*100,1); + if(isset($aCF['TAM']) && isset($aPV['TAM'])) $aPourcCFPV['TAM']=round(($aCF['TAM']/$aPV['TAM'])*100,1); + if(isset($aCF['PEPE']) && isset($aPV['PEPE'])) $aPourcCFPV['PEPE']=round(($aCF['PEPE']/$aPV['PEPE'])*100,1); + if(isset($aCF['AUT']) && isset($aPV['AUT'])) $aPourcCFPV['AUT']=round(($aCF['AUT']/$aPV['AUT'])*100,1); + if(isset($aCF['ND']) && isset($aPV['ND'])) $aPourcCFPV['ND']=round(($aCF['ND']/$aPV['ND'])*100,1); + // Moyenne pondérée au nombre d'opération total + // TODO pondérer au nombre d'opération ayant une valeur + } + include ('get_2_type.html'); + }else{ + $sError="Erreur : ".$oResult->rowCount()." conférence des maires trouvée."; + $oResult->closeCursor(); + include ('get_error.html'); + } + } + }catch (PDOException $e){ + $sError="ERROR : ".$e->getMessage(); + include ('get_error.html'); + } + + }else{ + $sError="ERREUR : Pas de CTM ou de communes passé en paramètre !"; + include ('get_error.html'); + } + } + +}else{ + $sError="ERREUR : Pas de token passé."; + include ('get_error.html'); +} ?> \ No newline at end of file diff --git a/src/vitis/vas/doc/suivi_prod_immo/get_3_porteur.php b/src/vitis/vas/doc/suivi_prod_immo/get_3_porteur.php index b2d7db463b93500bc8afb2e217d879c2d8d30b41..64e8b46c18a8092d29b567fc90b9256902c4aec2 100644 --- a/src/vitis/vas/doc/suivi_prod_immo/get_3_porteur.php +++ b/src/vitis/vas/doc/suivi_prod_immo/get_3_porteur.php @@ -1,111 +1,111 @@ -<?php -// https://geo.urbalyon.org/doc/suivi_prod_immo/get_3_porteur.php?concessionnaire_amenagement=1041 -if (isset($_REQUEST['token']) && !is_null($_REQUEST['token'])){ - session_id($_REQUEST['token']); - if (session_status() == PHP_SESSION_NONE) - session_start(); - - if (empty($_SESSION)) { - $sError="ERREUR : token invalide."; - include ('get_error.html'); - }else{ - - if (isset($_REQUEST['concessionnaire_amenagement']) && !is_null($_REQUEST['concessionnaire_amenagement'])){ - require_once("../../rest/conf/properties.inc"); - require_once("properties_suivi_prod_immo.inc"); - $sSchema=$properties['schema_prod_immo']; - - try{ - $oConn = new PDO('pgsql:host='.$properties['server'].';port='.$properties['port'].';dbname='.$properties['db_prod_immo'], $properties['db_user_prod_immo'], $properties['db_pass_prod_immo']); - $oConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - $oConn->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL); - - if($oConn){ - // get data Opérations - $sWhereAmenageur=" WHERE concessionnaire_amenagement='".$_REQUEST['concessionnaire_amenagement']."'"; - $oResult = $oConn->prepare("SELECT * FROM ".$sSchema.".v_operation_layer".$sWhereAmenageur); - $oResult->execute(); - - if ($oResult->rowCount()>0){ - $iNbOperation=$oResult->rowCount(); - $aOperations = $oResult->fetchAll(); - $oResult->closeCursor(); - // get map image - $aIdOperation=array(); - foreach ($aOperations as $aOperation) - array_push($aIdOperation, $aOperation["id_operation"]); - $sNameMapImage=strtolower(preg_replace("#[^a-zA-Z]#", "", str_replace(' ', '_', $_REQUEST['concessionnaire_amenagement'])))."_porteur.png"; - $oResult2 = $oConn->prepare("SELECT round(st_xmin(st_buffer(st_envelope(st_union(geom)),150))) AS xmin, round(st_ymin(st_buffer(st_envelope(st_union(geom)),150))) AS ymin, round(st_ymax(st_buffer(st_envelope(st_union(geom)),150))) AS ymax, round(st_xmax(st_buffer(st_envelope(st_union(geom)),150))) AS xmax FROM ".$sSchema.".operation".$sWhereAmenageur); - $oResult2->execute(); - $aOperations2 = $oResult2->fetchAll(); - $oResult2->closeCursor(); - $aOperations2 = $aOperations2[0]; - $sCommand = escapeshellcmd('python get_map_image_3_porteur.py '.$aOperations2['xmin'].' '.$aOperations2['ymin'].' '.$aOperations2['xmax'].' '.$aOperations2['ymax'].' '.$sNameMapImage.' '.implode(",", $aIdOperation)); - // echo $sCommand; - $output = shell_exec($sCommand);/**/ - $sUrlMapImage=$properties['web_server_name']."/ws_data/vm4ms/map/tmp/".$sNameMapImage; - - $sSql="SELECT code_financement_equ_public, count(DISTINCT id_programme), array_to_string(array_agg(id_programme), ',') AS id_programme, round(avg(charge_fonciere_moy)) AS charge_fonciere_moy FROM (SELECT id_programme, CASE WHEN operation_tr_financement_equ_public.code_financement_equ_public='PUP' THEN operation_tr_financement_equ_public.code_financement_equ_public WHEN operation_tr_financement_equ_public.code_financement_equ_public='FINZAC' THEN operation_tr_financement_equ_public.code_financement_equ_public WHEN operation_tr_financement_equ_public.code_financement_equ_public='TA' THEN operation_tr_financement_equ_public.code_financement_equ_public WHEN operation_tr_financement_equ_public.code_financement_equ_public='TAM' THEN operation_tr_financement_equ_public.code_financement_equ_public WHEN operation_tr_financement_equ_public.code_financement_equ_public='AUT' THEN operation_tr_financement_equ_public.code_financement_equ_public WHEN operation_tr_financement_equ_public.code_financement_equ_public='PEPE' THEN operation_tr_financement_equ_public.code_financement_equ_public ELSE 'ND' END AS code_financement_equ_public, charge_fonciere_moy FROM ((".$sSchema.".operation LEFT JOIN ".$sSchema.".operation_tr_financement_equ_public ON operation.id_operation=operation_tr_financement_equ_public.id_operation) INNER JOIN ".$sSchema.".ilot ON ilot.id_operation=operation.id_operation) INNER JOIN ".$sSchema.".programme_immobilier ON programme_immobilier.id_ilot=ilot.id_ilot ".$sWhereAmenageur.") AS t GROUP BY code_financement_equ_public"; - $aPourcCFPV=$aPV=$aCF=$aNb=array(); - foreach ($oConn->query($sSql) as $aRow){ - if(!is_null($aRow['count'])) $aNb[$aRow['code_financement_equ_public']]=$aRow['count']; - if(!is_null($aRow['charge_fonciere_moy'])) $aCF[$aRow['code_financement_equ_public']]=$aRow['charge_fonciere_moy']; - $oResult3 = $oConn->prepare("SELECT round((COALESCE(avg1, 0) + COALESCE(avg2, 0) + COALESCE(avg3, 0) + COALESCE(avg4)) / ( CASE WHEN avg1 IS NULL THEN 0 ELSE 1 END + CASE WHEN avg2 IS NULL THEN 0 ELSE 1 END + CASE WHEN avg3 IS NULL THEN 0 ELSE 1 END + CASE WHEN avg4 IS NULL THEN 0 ELSE 1 END)) AS pv_moy FROM (SELECT round(avg(accession_libre::numeric)) AS avg1, round(avg(accession_abordable::numeric)) AS avg2, round(avg(accession_sociale_securise::numeric)) AS avg3, round(avg(psla::numeric)) AS avg4 FROM ".$sSchema.".logement_familliaux_accession WHERE id_programme IN (".$aRow['id_programme'].") AND id_indicateur_logement_familliaux_accession IN (8,9)) AS t"); - $oResult3->execute(); - $aPrixVenteMoy = $oResult3->fetchAll(); - if (isset($aPrixVenteMoy[0])) $aPV[$aRow['code_financement_equ_public']]=$aPrixVenteMoy[0]['pv_moy']; - $oResult3->closeCursor(); - } - if(isset($aCF['PUP']) && isset($aPV['PUP'])) $aPourcCFPV['PUP']=round(($aCF['PUP']/$aPV['PUP'])*100,1); - if(isset($aCF['FINZAC']) && isset($aPV['FINZAC'])) $aPourcCFPV['FINZAC']=round(($aCF['FINZAC']/$aPV['FINZAC'])*100,1); - if(isset($aCF['TA']) && isset($aPV['TA'])) $aPourcCFPV['TA']=round(($aCF['TA']/$aPV['TA'])*100,1); - if(isset($aCF['TAM']) && isset($aPV['TAM'])) $aPourcCFPV['TAM']=round(($aCF['TAM']/$aPV['TAM'])*100,1); - if(isset($aCF['PEPE']) && isset($aPV['PEPE'])) $aPourcCFPV['PEPE']=round(($aCF['PEPE']/$aPV['PEPE'])*100,1); - if(isset($aCF['AUT']) && isset($aPV['AUT'])) $aPourcCFPV['AUT']=round(($aCF['AUT']/$aPV['AUT'])*100,1); - if(isset($aCF['ND']) && isset($aPV['ND'])) $aPourcCFPV['ND']=round(($aCF['ND']/$aPV['ND'])*100,1); - $aNb['TOTAL']=array_sum($aNb); - // Moyenne pondérée au nombre d'opération total - // TODO pondérer au nombre d'opération ayant une valeur - $iCFTotal=$iPVTotal=$iCFPVTotal=0; - foreach ($aNb as $sFinancement=>$iNB){ - $iCFTotal=$iCFTotal+($aCF[$sFinancement]*$iNB); - $iPVTotal=$iPVTotal+($aPV[$sFinancement]*$iNB); - $iCFPVTotal=$iCFPVTotal+($aPourcCFPV[$sFinancement]*$iNB); - } - $aCF['MOY']=round($iCFTotal/$aNb['TOTAL']); - $aPV['MOY']=round($iPVTotal/$aNb['TOTAL']); - $aPourcCFPV['MOY']=round($iCFPVTotal/$aNb['TOTAL'],1); - // label title - $sTitle="Opérateur immobilier"; - $aPromoteurs=array("Cogedim", "Vinci Immobilier"); - $aAmenageurs=array("SERL", "LMH"); - $aRegies=array("Métropole de Lyon"); - if (in_array($_REQUEST['concessionnaire_amenagement'], $aPromoteurs)) $sTitle="Promoteur immobilier"; - if (in_array($_REQUEST['concessionnaire_amenagement'], $aAmenageurs)) $sTitle="Aménageur"; - if (in_array($_REQUEST['concessionnaire_amenagement'], $aRegies)) $sTitle="Opération(s) suivi en régie"; - - - - include ('get_3_porteur.html'); - }else{ - $sError="Erreur : ".$oResult->rowCount()." opération(s) trouvée(s) pour l'aménageur ".$_REQUEST['concessionnaire_amenagement']."."; - $oResult->closeCursor(); - include ('get_error.html'); - } - } - }catch (PDOException $e){ - $sError="ERROR : ".$e->getMessage(); - include ('get_error.html'); - } - - }else{ - $sError="ERREUR : Pas de nom d'aménageur passé en paramètre !"; - include ('get_error.html'); - } - } - -}else{ - $sError="ERREUR : Pas de token passé."; - include ('get_error.html'); -} +<?php +// https://geo.urbalyon.org/doc/suivi_prod_immo/get_3_porteur.php?concessionnaire_amenagement=1041 +if (isset($_REQUEST['token']) && !is_null($_REQUEST['token'])){ + session_id($_REQUEST['token']); + if (session_status() == PHP_SESSION_NONE) + session_start(); + + if (empty($_SESSION)) { + $sError="ERREUR : token invalide."; + include ('get_error.html'); + }else{ + + if (isset($_REQUEST['concessionnaire_amenagement']) && !is_null($_REQUEST['concessionnaire_amenagement'])){ + require_once("../../rest/conf/properties.inc"); + require_once("properties_suivi_prod_immo.inc"); + $sSchema=$properties['schema_prod_immo']; + + try{ + $oConn = new PDO('pgsql:host='.$properties['server'].';port='.$properties['port'].';dbname='.$properties['db_prod_immo'], $properties['db_user_prod_immo'], $properties['db_pass_prod_immo']); + $oConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $oConn->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL); + + if($oConn){ + // get data Opérations + $sWhereAmenageur=" WHERE concessionnaire_amenagement='".$_REQUEST['concessionnaire_amenagement']."'"; + $oResult = $oConn->prepare("SELECT * FROM ".$sSchema.".v_operation_layer".$sWhereAmenageur); + $oResult->execute(); + + if ($oResult->rowCount()>0){ + $iNbOperation=$oResult->rowCount(); + $aOperations = $oResult->fetchAll(); + $oResult->closeCursor(); + // get map image + $aIdOperation=array(); + foreach ($aOperations as $aOperation) + array_push($aIdOperation, $aOperation["id_operation"]); + $sNameMapImage=strtolower(preg_replace("#[^a-zA-Z]#", "", str_replace(' ', '_', $_REQUEST['concessionnaire_amenagement'])))."_porteur.png"; + $oResult2 = $oConn->prepare("SELECT round(st_xmin(st_buffer(st_envelope(st_union(geom)),150))) AS xmin, round(st_ymin(st_buffer(st_envelope(st_union(geom)),150))) AS ymin, round(st_ymax(st_buffer(st_envelope(st_union(geom)),150))) AS ymax, round(st_xmax(st_buffer(st_envelope(st_union(geom)),150))) AS xmax FROM ".$sSchema.".operation".$sWhereAmenageur); + $oResult2->execute(); + $aOperations2 = $oResult2->fetchAll(); + $oResult2->closeCursor(); + $aOperations2 = $aOperations2[0]; + $sCommand = escapeshellcmd('python get_map_image_3_porteur.py '.$aOperations2['xmin'].' '.$aOperations2['ymin'].' '.$aOperations2['xmax'].' '.$aOperations2['ymax'].' '.$sNameMapImage.' '.implode(",", $aIdOperation)); + // echo $sCommand; + $output = shell_exec($sCommand);/**/ + $sUrlMapImage=$properties['web_server_name']."/ws_data/vm4ms/map/tmp/".$sNameMapImage; + + $sSql="SELECT code_financement_equ_public, count(DISTINCT id_programme), array_to_string(array_agg(id_programme), ',') AS id_programme, round(avg(charge_fonciere_moy)) AS charge_fonciere_moy FROM (SELECT id_programme, CASE WHEN operation_tr_financement_equ_public.code_financement_equ_public='PUP' THEN operation_tr_financement_equ_public.code_financement_equ_public WHEN operation_tr_financement_equ_public.code_financement_equ_public='FINZAC' THEN operation_tr_financement_equ_public.code_financement_equ_public WHEN operation_tr_financement_equ_public.code_financement_equ_public='TA' THEN operation_tr_financement_equ_public.code_financement_equ_public WHEN operation_tr_financement_equ_public.code_financement_equ_public='TAM' THEN operation_tr_financement_equ_public.code_financement_equ_public WHEN operation_tr_financement_equ_public.code_financement_equ_public='AUT' THEN operation_tr_financement_equ_public.code_financement_equ_public WHEN operation_tr_financement_equ_public.code_financement_equ_public='PEPE' THEN operation_tr_financement_equ_public.code_financement_equ_public ELSE 'ND' END AS code_financement_equ_public, charge_fonciere_moy FROM ((".$sSchema.".operation LEFT JOIN ".$sSchema.".operation_tr_financement_equ_public ON operation.id_operation=operation_tr_financement_equ_public.id_operation) INNER JOIN ".$sSchema.".ilot ON ilot.id_operation=operation.id_operation) INNER JOIN ".$sSchema.".programme_immobilier ON programme_immobilier.id_ilot=ilot.id_ilot ".$sWhereAmenageur.") AS t GROUP BY code_financement_equ_public"; + $aPourcCFPV=$aPV=$aCF=$aNb=array(); + foreach ($oConn->query($sSql) as $aRow){ + if(!is_null($aRow['count'])) $aNb[$aRow['code_financement_equ_public']]=$aRow['count']; + if(!is_null($aRow['charge_fonciere_moy'])) $aCF[$aRow['code_financement_equ_public']]=$aRow['charge_fonciere_moy']; + $oResult3 = $oConn->prepare("SELECT round((COALESCE(avg1, 0) + COALESCE(avg2, 0) + COALESCE(avg3, 0) + COALESCE(avg4)) / ( CASE WHEN avg1 IS NULL THEN 0 ELSE 1 END + CASE WHEN avg2 IS NULL THEN 0 ELSE 1 END + CASE WHEN avg3 IS NULL THEN 0 ELSE 1 END + CASE WHEN avg4 IS NULL THEN 0 ELSE 1 END)) AS pv_moy FROM (SELECT round(avg(accession_libre::numeric)) AS avg1, round(avg(accession_abordable::numeric)) AS avg2, round(avg(accession_sociale_securise::numeric)) AS avg3, round(avg(psla::numeric)) AS avg4 FROM ".$sSchema.".logement_familliaux_accession WHERE id_programme IN (".$aRow['id_programme'].") AND id_indicateur_logement_familliaux_accession IN (8,9)) AS t"); + $oResult3->execute(); + $aPrixVenteMoy = $oResult3->fetchAll(); + if (isset($aPrixVenteMoy[0])) $aPV[$aRow['code_financement_equ_public']]=$aPrixVenteMoy[0]['pv_moy']; + $oResult3->closeCursor(); + } + if(isset($aCF['PUP']) && isset($aPV['PUP'])) $aPourcCFPV['PUP']=round(($aCF['PUP']/$aPV['PUP'])*100,1); + if(isset($aCF['FINZAC']) && isset($aPV['FINZAC'])) $aPourcCFPV['FINZAC']=round(($aCF['FINZAC']/$aPV['FINZAC'])*100,1); + if(isset($aCF['TA']) && isset($aPV['TA'])) $aPourcCFPV['TA']=round(($aCF['TA']/$aPV['TA'])*100,1); + if(isset($aCF['TAM']) && isset($aPV['TAM'])) $aPourcCFPV['TAM']=round(($aCF['TAM']/$aPV['TAM'])*100,1); + if(isset($aCF['PEPE']) && isset($aPV['PEPE'])) $aPourcCFPV['PEPE']=round(($aCF['PEPE']/$aPV['PEPE'])*100,1); + if(isset($aCF['AUT']) && isset($aPV['AUT'])) $aPourcCFPV['AUT']=round(($aCF['AUT']/$aPV['AUT'])*100,1); + if(isset($aCF['ND']) && isset($aPV['ND'])) $aPourcCFPV['ND']=round(($aCF['ND']/$aPV['ND'])*100,1); + $aNb['TOTAL']=array_sum($aNb); + // Moyenne pondérée au nombre d'opération total + // TODO pondérer au nombre d'opération ayant une valeur + $iCFTotal=$iPVTotal=$iCFPVTotal=0; + foreach ($aNb as $sFinancement=>$iNB){ + $iCFTotal=$iCFTotal+($aCF[$sFinancement]*$iNB); + $iPVTotal=$iPVTotal+($aPV[$sFinancement]*$iNB); + $iCFPVTotal=$iCFPVTotal+($aPourcCFPV[$sFinancement]*$iNB); + } + $aCF['MOY']=round($iCFTotal/$aNb['TOTAL']); + $aPV['MOY']=round($iPVTotal/$aNb['TOTAL']); + $aPourcCFPV['MOY']=round($iCFPVTotal/$aNb['TOTAL'],1); + // label title + $sTitle="Opérateur immobilier"; + $aPromoteurs=array("Cogedim", "Vinci Immobilier"); + $aAmenageurs=array("SERL", "LMH"); + $aRegies=array("Métropole de Lyon"); + if (in_array($_REQUEST['concessionnaire_amenagement'], $aPromoteurs)) $sTitle="Promoteur immobilier"; + if (in_array($_REQUEST['concessionnaire_amenagement'], $aAmenageurs)) $sTitle="Aménageur"; + if (in_array($_REQUEST['concessionnaire_amenagement'], $aRegies)) $sTitle="Opération(s) suivi en régie"; + + + + include ('get_3_porteur.html'); + }else{ + $sError="Erreur : ".$oResult->rowCount()." opération(s) trouvée(s) pour l'aménageur ".$_REQUEST['concessionnaire_amenagement']."."; + $oResult->closeCursor(); + include ('get_error.html'); + } + } + }catch (PDOException $e){ + $sError="ERROR : ".$e->getMessage(); + include ('get_error.html'); + } + + }else{ + $sError="ERREUR : Pas de nom d'aménageur passé en paramètre !"; + include ('get_error.html'); + } + } + +}else{ + $sError="ERREUR : Pas de token passé."; + include ('get_error.html'); +} ?> \ No newline at end of file diff --git a/src/vitis/vas/doc/suivi_prod_immo/get_4_logement.php b/src/vitis/vas/doc/suivi_prod_immo/get_4_logement.php index a4679d5cb80a9281fc9dc6bef35dc4b58eaf5463..8c8d515e5a670ecd1f0cef6db8acbbc22518b39c 100644 --- a/src/vitis/vas/doc/suivi_prod_immo/get_4_logement.php +++ b/src/vitis/vas/doc/suivi_prod_immo/get_4_logement.php @@ -1,267 +1,267 @@ -<?php -// https://geo.urbalyon.org/doc/suivi_prod_immo/get_4_logement.php?code_finanacment=TA -if (isset($_REQUEST['token']) && !is_null($_REQUEST['token'])){ - session_id($_REQUEST['token']); - if (session_status() == PHP_SESSION_NONE) - session_start(); - - if (empty($_SESSION)) { - $sError="ERREUR : token invalide."; - include ('get_error.html'); - }else{ - - require_once("../../rest/conf/properties.inc"); - require_once("properties_suivi_prod_immo.inc"); - $sSchema=$properties['schema_prod_immo']; - - function avg($sum=0,$count=0){ - return ($count)? round($sum / $count): null; - } - - try{ - $oConn = new PDO('pgsql:host='.$properties['server'].';port='.$properties['port'].';dbname='.$properties['db_prod_immo'], $properties['db_user_prod_immo'], $properties['db_pass_prod_immo']); - $oConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - $oConn->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL); - - $bSetAccessionLibre=$bSetAccessionAbordable=$bSetAccessionSecurisee=$bSetBRS=$bSetLogementSocial=$bSetLogementIntermediaire=false; - - if($oConn){ - $sWhereOperation=''; - $aOperations=array(); - if (isset($_REQUEST['code_financement']) && !is_null($_REQUEST['code_financement'])){ - $sWhereOperation="WHERE operation_tr_financement_equ_public.code_financement_equ_public='".$_REQUEST['code_financement']."'"; - } - - if (isset($_REQUEST['id_commune']) && !is_null($_REQUEST['id_commune'])){ - if ($sWhereOperation=='') - $sWhereOperation="WHERE operation_commune.id_commune=".$_REQUEST['id_commune']; - else - $sWhereOperation=$sWhereOperation." AND operation_commune.id_commune=".$_REQUEST['id_commune']; - }else{ - if (isset($_REQUEST['id_ctm']) && !is_null($_REQUEST['id_ctm'])){ - $oResult2 = $oConn->prepare("SELECT array_to_string(array_agg(id_commune),', ') AS id_commune FROM ".$sSchema.".commune WHERE id_ctm=".$_REQUEST['id_ctm']." GROUP BY id_ctm"); - $oResult2->execute(); - if ($oResult2->rowCount()>0){ - $aCTMs=$oResult2->fetchAll(); - if ($sWhereOperation=='') - $sWhereOperation="WHERE operation_commune.id_commune IN (".$aCTMs[0]['id_commune'].")"; - else - $sWhereOperation=$sWhereOperation." AND operation_commune.id_commune IN (".$aCTMs[0]['id_commune'].")";/**/ - } - $oResult2->closeCursor(); - } - } - $sSql='SELECT DISTINCT operation.id_operation, nom_operation, array_to_string(array_agg(DISTINCT operation_tr_financement_equ_public.code_financement_equ_public),\', \') AS code_financement_equ_public, array_to_string(array_agg(DISTINCT nom_commune),\', \') AS nom_commune, nom_ilot, ilot.id_ilot, id_programme, nom_demandeur FROM (((('.$sSchema.'.operation INNER JOIN '.$sSchema.'.operation_tr_financement_equ_public ON operation_tr_financement_equ_public.id_operation=operation.id_operation) INNER JOIN '.$sSchema.'.operation_commune ON operation_commune.id_operation=operation.id_operation) INNER JOIN '.$sSchema.'.commune ON operation_commune.id_commune=commune.id_commune) INNER JOIN '.$sSchema.'.ilot ON ilot.id_operation=operation.id_operation) INNER JOIN '.$sSchema.'.programme_immobilier ON ilot.id_ilot=programme_immobilier.id_ilot '.$sWhereOperation.' GROUP BY id_programme, ilot.id_ilot, operation.id_operation ORDER BY nom_commune, nom_operation, nom_ilot'; - $oResult = $oConn->prepare($sSql); - $oResult->execute(); - if($oResult->rowCount()>0){ - $aProgrammes=$oResult->fetchAll(); - $aCptCommunes=array(); - $aCptOperations=array(); - $aCptIlots=array(); - $aTotaux=array('sdp'=>0,'nb'=>0,'nb_accession_libre'=>0,'cfi_accession_libre'=>array(),'pv_accession_libre'=>array(),'nb_accession_abordable'=>0,'cfi_accession_abordable'=>array(),'pv_accession_abordable'=>array(),'nb_accession_sociale_securise'=>0,'cfi_accession_sociale_securise'=>array(),'pv_accession_sociale_securise'=>array(),'nb_lls'=>0,'cfi_lls'=>array(),'pv_lls'=>array(),'nb_lli'=>0,'cfi_lli'=>array()); - $aProgrammes2=array(); - foreach ($aProgrammes as $aProgramme){ - // **** Compteurs pour fusion des cellules du tableau - if(isset($aCptCommunes[$aProgramme['nom_commune']])) - $aCptCommunes[$aProgramme['nom_commune']]=$aCptCommunes[$aProgramme['nom_commune']]+1; - else - $aCptCommunes[$aProgramme['nom_commune']]=1; - if(isset($aCptOperations[$aProgramme['id_operation']])) - $aCptOperations[$aProgramme['id_operation']]=$aCptOperations[$aProgramme['id_operation']]+1; - else - $aCptOperations[$aProgramme['id_operation']]=1; - if(isset($aCptIlots[$aProgramme['id_ilot']])) - $aCptIlots[$aProgramme['id_ilot']]=$aCptIlots[$aProgramme['id_ilot']]+1; - else - $aCptIlots[$aProgramme['id_ilot']]=1; - // **** Récupération des données tables associées - $iIdProgramme=$aProgramme['id_programme']; - $aProgramme2=array(); - // Granulométrie - $oResult3=$oConn->prepare("SELECT id_programme, code_type_granulometrie, sum(valeur) AS valeur FROM ".$sSchema.".granulometrie WHERE id_programme=".$iIdProgramme." AND code_type_granulometrie IN ('NB','SDP') AND code_composition_programme='TOT_LG_FAM' GROUP BY id_programme, code_composition_programme, code_type_granulometrie"); - $oResult3->execute(); - if($oResult3->rowCount()>0){ - $aGranulometries=$oResult3->fetchAll(); - foreach ($aGranulometries as $aGranulometrie){ - $aProgramme2[strtolower($aGranulometrie['code_type_granulometrie'])]=$aGranulometrie['valeur']; - $aTotaux[strtolower($aGranulometrie['code_type_granulometrie'])]=$aTotaux[strtolower($aGranulometrie['code_type_granulometrie'])]+$aGranulometrie['valeur']; - } - } - $oResult3->closeCursor(); - // profil - $oResult6=$oConn->prepare("SELECT pourc FROM prod_immo.profil_acheteur_accession_libre WHERE id_type_acheteur_accession_libre=2 AND pourc IS NOT NULL AND id_programme=".$iIdProgramme); - $oResult6->execute(); - if($oResult6->rowCount()>0){ - $aProfil=$oResult6->fetchAll(); - $aProgramme2['profil']=$aProfil[0]['pourc'].'%'; - } - $oResult6->closeCursor(); - // logement social - $oResult4=$oConn->prepare("SELECT id_programme, array_to_string(array_agg(DISTINCT nom_bailleur),',') AS nom_bailleur, id_indicateur_logement_familliaux_location, CASE WHEN id_indicateur_logement_familliaux_location=1 THEN sum(COALESCE(social_pls,0)) ELSE avg(COALESCE(social_pls,0)) END AS social_pls, CASE WHEN id_indicateur_logement_familliaux_location=1 THEN sum(COALESCE(social_plus_plai,0)) ELSE avg(COALESCE(social_plus_plai,0)) END AS social_plus_plai, CASE WHEN id_indicateur_logement_familliaux_location=1 THEN sum(COALESCE(intermediaire_pli,0)) ELSE avg(COALESCE(intermediaire_pli,0)) END AS intermediaire_pli, CASE WHEN id_indicateur_logement_familliaux_location=1 THEN sum(COALESCE(intermediaire_afl,0)) ELSE avg(COALESCE(intermediaire_afl,0)) END AS intermediaire_afl FROM ".$sSchema.".logement_familliaux_location INNER JOIN ".$sSchema.".composition_logement_familliaux_location_cp ON logement_familliaux_location.id_logement_familliaux_location=composition_logement_familliaux_location_cp.id_logement_familliaux_location WHERE id_programme=".$iIdProgramme." AND id_indicateur_logement_familliaux_location IN (1,4,5,8) GROUP BY id_programme, composition_logement_familliaux_location_cp.id_logement_familliaux_location, id_indicateur_logement_familliaux_location"); - $oResult4->execute(); - if($oResult4->rowCount()>0){ - $aLogSocials=$oResult4->fetchAll(); - $aProgramme2['nom_bailleur']=$aLogSocials[0]['nom_bailleur']; - $aCFIlls=array(); - $aCFIlli=array(); - foreach ($aLogSocials as $aLogSocial){ - switch ($aLogSocial['id_indicateur_logement_familliaux_location']) { - case 1: - if($aLogSocial['social_pls']>0 or $aLogSocial['social_plus_plai']>0){ - $bSetLogementSocial=true; - $aProgramme2['nb_lls']=$aLogSocial['social_pls']+$aLogSocial['social_plus_plai']; - $aTotaux['nb_lls']=$aTotaux['nb_lls']+$aLogSocial['social_pls']+$aLogSocial['social_plus_plai']; - } - if($aLogSocial['intermediaire_pli']>0 or $aLogSocial['intermediaire_afl']>0){ - $bSetLogementIntermediaire=true; - $aProgramme2['nb_lli']=$aLogSocial['intermediaire_pli']+$aLogSocial['intermediaire_afl']; - $aTotaux['nb_lli']=$aTotaux['nb_lli']+$aLogSocial['intermediaire_pli']+$aLogSocial['intermediaire_afl']; - } - break; - case 4: - case 5: - if(!is_null($aLogSocial['social_pls']) and $aLogSocial['social_pls']>0){ - $bSetLogementSocial=true; - $aCFIlls[count($aCFIlls)]=$aLogSocial['social_pls']; - $aTotaux['cfi_lls'][count($aTotaux['cfi_lls'])]=$aLogSocial['social_pls']; - } - if(!is_null($aLogSocial['social_plus_plai']) and $aLogSocial['social_plus_plai']>0){ - $bSetLogementSocial=true; - $aCFIlls[count($aCFIlls)]=$aLogSocial['social_plus_plai']; - $aTotaux['cfi_lls'][count($aTotaux['cfi_lls'])]=$aLogSocial['social_plus_plai']; - } - if(!is_null($aLogSocial['intermediaire_pli']) and $aLogSocial['intermediaire_pli']>0){ - $bSetLogementIntermediaire=true; - $aCFIlli[count($aCFIlli)]=$aLogSocial['intermediaire_pli']; - $aTotaux['cfi_lli'][count($aTotaux['cfi_lli'])]=$aLogSocial['intermediaire_pli']; - } - if(!is_null($aLogSocial['intermediaire_afl']) and $aLogSocial['intermediaire_afl']>0){ - $bSetLogementIntermediaire=true; - $aCFIlli[count($aCFIlli)]=$aLogSocial['intermediaire_afl']; - $aTotaux['cfi_lli'][count($aTotaux['cfi_lli'])]=$aLogSocial['intermediaire_afl']; - } - break; - case 8: - $aPVlls=array(); - if(!is_null($aLogSocial['social_pls']) and $aLogSocial['social_pls']>0){ - $bSetLogementSocial=true; - $aPVlls[count($aPVlls)]=$aLogSocial['social_pls']; - $aTotaux['pv_lls'][count($aTotaux['pv_lls'])]=$aLogSocial['social_pls']; - } - if(!is_null($aLogSocial['social_plus_plai']) and $aLogSocial['social_plus_plai']>0){ - $bSetLogementSocial=true; - $aPVlls[count($aPVlls)]=$aLogSocial['social_plus_plai']; - $aTotaux['pv_lls'][count($aTotaux['pv_lls'])]=$aLogSocial['social_plus_plai']; - } - $aProgramme2['pv_lls']=avg(array_sum($aPVlls),count($aPVlls)); - // pas de prix de vente en lli - break; - } - } - $aProgramme2['cfi_lls']=avg(array_sum($aCFIlls),count($aCFIlls)); - $aProgramme2['cfi_lli']=avg(array_sum($aCFIlli),count($aCFIlli)); - } - - $oResult4->closeCursor(); - // logement accession - $oResult5=$oConn->prepare("SELECT id_programme, id_indicateur_logement_familliaux_accession, CASE WHEN id_indicateur_logement_familliaux_accession=1 THEN sum(COALESCE(accession_libre::numeric,0)) ELSE avg(COALESCE(accession_libre::numeric,0)) END AS accession_libre, CASE WHEN id_indicateur_logement_familliaux_accession=1 THEN sum(COALESCE(accession_abordable::numeric,0)) ELSE avg(COALESCE(accession_abordable::numeric,0)) END AS accession_abordable, CASE WHEN id_indicateur_logement_familliaux_accession=1 THEN sum(COALESCE(accession_sociale_securise::numeric,0)) ELSE avg(COALESCE(accession_sociale_securise::numeric,0)) END AS accession_sociale_securise, CASE WHEN id_indicateur_logement_familliaux_accession=1 THEN sum(COALESCE(psla::numeric,0)) ELSE avg(COALESCE(psla::numeric,0)) END AS psla FROM ".$sSchema.".logement_familliaux_accession WHERE id_programme=".$iIdProgramme." AND id_indicateur_logement_familliaux_accession IN (1,4,5,8,9) GROUP BY id_programme, id_indicateur_logement_familliaux_accession"); - $oResult5->execute(); - if($oResult5->rowCount()>0){ - $aLogAccessions=$oResult5->fetchAll(); - $aCFIAccessionLibre=$aCFIAccessionAbordable=$aCFIAccessionSocialeSecurise=array(); - $aPVAccessionLibre=$aPVAccessionAbordable=$aPVAccessionSocialeSecurise=array(); - foreach ($aLogAccessions as $aLogAccession){ - switch ($aLogAccession['id_indicateur_logement_familliaux_accession']){ - case 1: - if($aLogAccession['accession_libre']>0){ - $bSetAccessionLibre=true; - $aProgramme2['nb_accession_libre']=$aLogAccession['accession_libre']; - $aTotaux['nb_accession_libre']=$aTotaux['nb_accession_libre']+$aLogAccession['accession_libre']; - } - if($aLogAccession['accession_abordable']>0){ - $bSetAccessionAbordable=true; - $aProgramme2['nb_accession_abordable']=$aLogAccession['accession_abordable']; - $aTotaux['nb_accession_abordable']=$aTotaux['nb_accession_abordable']+$aLogAccession['accession_abordable']; - } - if($aLogAccession['accession_sociale_securise']>0){ - $bSetAccessionSecurisee=true; - $aProgramme2['nb_accession_sociale_securise']=$aLogAccession['accession_sociale_securise']; - $aTotaux['nb_accession_sociale_securise']=$aTotaux['nb_accession_sociale_securise']+$aLogAccession['accession_sociale_securise']; - } - if($aLogAccession['psla']>0) $aProgramme2['nb_psla']=$aLogAccession['psla']; - break; - case 4: - case 5: - if(!is_null($aLogAccession['accession_libre']) and $aLogAccession['accession_libre']>0){ - $bSetAccessionLibre=true; - $aCFIAccessionLibre[count($aCFIAccessionLibre)]=$aLogAccession['accession_libre']; - $aTotaux['cfi_accession_libre'][count($aTotaux['cfi_accession_libre'])]=$aLogAccession['accession_libre']; - } - if(!is_null($aLogAccession['accession_abordable']) and $aLogAccession['accession_abordable']>0){ - $bSetAccessionAbordable=true; - $aCFIAccessionAbordable[count($aCFIAccessionAbordable)]=$aLogAccession['accession_abordable']; - $aTotaux['cfi_accession_abordable'][count($aTotaux['cfi_accession_abordable'])]=$aLogAccession['accession_abordable']; - } - if(!is_null($aLogAccession['accession_sociale_securise']) and $aLogAccession['accession_sociale_securise']>0){ - $bSetAccessionSecurisee=true; - $aCFIAccessionSocialeSecurise[count($aCFIAccessionSocialeSecurise)]=$aLogAccession['accession_sociale_securise']; - $aTotaux['cfi_accession_sociale_securise'][count($aTotaux['cfi_accession_sociale_securise'])]=$aLogAccession['accession_sociale_securise']; - } - break; - case 8: - case 9: - if(!is_null($aLogAccession['accession_libre']) and $aLogAccession['accession_libre']>0){ - $bSetAccessionLibre=true; - $aPVAccessionLibre[count($aPVAccessionLibre)]=$aLogAccession['accession_libre']; - $aTotaux['pv_accession_libre'][count($aTotaux['pv_accession_libre'])]=$aLogAccession['accession_libre']; - } - if(!is_null($aLogAccession['accession_abordable']) and $aLogAccession['accession_abordable']>0){ - $bSetAccessionAbordable=true; - $aPVAccessionAbordable[count($aPVAccessionAbordable)]=$aLogAccession['accession_abordable']; - $aTotaux['pv_accession_abordable'][count($aTotaux['pv_accession_abordable'])]=$aLogAccession['accession_abordable']; - } - if(!is_null($aLogAccession['accession_sociale_securise']) and $aLogAccession['accession_sociale_securise']>0){ - $bSetAccessionSecurisee=true; - $aPVAccessionSocialeSecurise[count($aPVAccessionSocialeSecurise)]=$aLogAccession['accession_sociale_securise']; - $aTotaux['pv_accession_sociale_securise'][count($aTotaux['pv_accession_sociale_securise'])]=$aLogAccession['accession_sociale_securise']; - } - break; - } - } - $aProgramme2['cfi_accession_libre']=avg(array_sum($aCFIAccessionLibre),count($aCFIAccessionLibre)); - $aProgramme2['cfi_accession_abordable']=avg(array_sum($aCFIAccessionAbordable),count($aCFIAccessionAbordable)); - $aProgramme2['cfi_accession_sociale_securise']=avg(array_sum($aCFIAccessionSocialeSecurise),count($aCFIAccessionSocialeSecurise)); - $aProgramme2['pv_accession_libre']=avg(array_sum($aPVAccessionLibre),count($aPVAccessionLibre)); - $aProgramme2['pv_accession_abordable']=avg(array_sum($aPVAccessionAbordable),count($aPVAccessionAbordable)); - $aProgramme2['pv_accession_sociale_securise']=avg(array_sum($aPVAccessionSocialeSecurise),count($aPVAccessionSocialeSecurise)); - } - $oResult5->closeCursor(); - $aProgrammes2[$aProgramme['id_programme']]=$aProgramme2; - } - $oResult->closeCursor(); - $aTotaux['cfi_accession_libre']=avg(array_sum($aTotaux['cfi_accession_libre']),count($aTotaux['cfi_accession_libre'])); - $aTotaux['pv_accession_libre']=avg(array_sum($aTotaux['pv_accession_libre']),count($aTotaux['pv_accession_libre'])); - $aTotaux['cfi_accession_abordable']=avg(array_sum($aTotaux['cfi_accession_abordable']),count($aTotaux['cfi_accession_abordable'])); - $aTotaux['pv_accession_abordable']=avg(array_sum($aTotaux['pv_accession_abordable']),count($aTotaux['pv_accession_abordable'])); - $aTotaux['cfi_accession_sociale_securise']=avg(array_sum($aTotaux['cfi_accession_sociale_securise']),count($aTotaux['cfi_accession_sociale_securise'])); - $aTotaux['pv_accession_sociale_securise']=avg(array_sum($aTotaux['pv_accession_sociale_securise']),count($aTotaux['pv_accession_sociale_securise'])); - $aTotaux['cfi_lls']=avg(array_sum($aTotaux['cfi_lls']),count($aTotaux['cfi_lls'])); - $aTotaux['pv_lls']=avg(array_sum($aTotaux['pv_lls']),count($aTotaux['pv_lls'])); - $aTotaux['cfi_lli']=avg(array_sum($aTotaux['cfi_lli']),count($aTotaux['cfi_lli'])); - } - $sCssColor='blue'; - include ('get_4_logement.html'); - } - }catch (PDOException $e){ - $sError="ERROR : ".$e->getMessage(); - include ('get_error.html'); - } - } - -}else{ - $sError="ERREUR : Pas de token passé."; - include ('get_error.html'); -} - +<?php +// https://geo.urbalyon.org/doc/suivi_prod_immo/get_4_logement.php?code_finanacment=TA +if (isset($_REQUEST['token']) && !is_null($_REQUEST['token'])){ + session_id($_REQUEST['token']); + if (session_status() == PHP_SESSION_NONE) + session_start(); + + if (empty($_SESSION)) { + $sError="ERREUR : token invalide."; + include ('get_error.html'); + }else{ + + require_once("../../rest/conf/properties.inc"); + require_once("properties_suivi_prod_immo.inc"); + $sSchema=$properties['schema_prod_immo']; + + function avg($sum=0,$count=0){ + return ($count)? round($sum / $count): null; + } + + try{ + $oConn = new PDO('pgsql:host='.$properties['server'].';port='.$properties['port'].';dbname='.$properties['db_prod_immo'], $properties['db_user_prod_immo'], $properties['db_pass_prod_immo']); + $oConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $oConn->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL); + + $bSetAccessionLibre=$bSetAccessionAbordable=$bSetAccessionSecurisee=$bSetBRS=$bSetLogementSocial=$bSetLogementIntermediaire=false; + + if($oConn){ + $sWhereOperation=''; + $aOperations=array(); + if (isset($_REQUEST['code_financement']) && !is_null($_REQUEST['code_financement'])){ + $sWhereOperation="WHERE operation_tr_financement_equ_public.code_financement_equ_public='".$_REQUEST['code_financement']."'"; + } + + if (isset($_REQUEST['id_commune']) && !is_null($_REQUEST['id_commune'])){ + if ($sWhereOperation=='') + $sWhereOperation="WHERE operation_commune.id_commune=".$_REQUEST['id_commune']; + else + $sWhereOperation=$sWhereOperation." AND operation_commune.id_commune=".$_REQUEST['id_commune']; + }else{ + if (isset($_REQUEST['id_ctm']) && !is_null($_REQUEST['id_ctm'])){ + $oResult2 = $oConn->prepare("SELECT array_to_string(array_agg(id_commune),', ') AS id_commune FROM ".$sSchema.".commune WHERE id_ctm=".$_REQUEST['id_ctm']." GROUP BY id_ctm"); + $oResult2->execute(); + if ($oResult2->rowCount()>0){ + $aCTMs=$oResult2->fetchAll(); + if ($sWhereOperation=='') + $sWhereOperation="WHERE operation_commune.id_commune IN (".$aCTMs[0]['id_commune'].")"; + else + $sWhereOperation=$sWhereOperation." AND operation_commune.id_commune IN (".$aCTMs[0]['id_commune'].")";/**/ + } + $oResult2->closeCursor(); + } + } + $sSql='SELECT DISTINCT operation.id_operation, nom_operation, array_to_string(array_agg(DISTINCT operation_tr_financement_equ_public.code_financement_equ_public),\', \') AS code_financement_equ_public, array_to_string(array_agg(DISTINCT nom_commune),\', \') AS nom_commune, nom_ilot, ilot.id_ilot, id_programme, nom_demandeur FROM (((('.$sSchema.'.operation INNER JOIN '.$sSchema.'.operation_tr_financement_equ_public ON operation_tr_financement_equ_public.id_operation=operation.id_operation) INNER JOIN '.$sSchema.'.operation_commune ON operation_commune.id_operation=operation.id_operation) INNER JOIN '.$sSchema.'.commune ON operation_commune.id_commune=commune.id_commune) INNER JOIN '.$sSchema.'.ilot ON ilot.id_operation=operation.id_operation) INNER JOIN '.$sSchema.'.programme_immobilier ON ilot.id_ilot=programme_immobilier.id_ilot '.$sWhereOperation.' GROUP BY id_programme, ilot.id_ilot, operation.id_operation ORDER BY nom_commune, nom_operation, nom_ilot'; + $oResult = $oConn->prepare($sSql); + $oResult->execute(); + if($oResult->rowCount()>0){ + $aProgrammes=$oResult->fetchAll(); + $aCptCommunes=array(); + $aCptOperations=array(); + $aCptIlots=array(); + $aTotaux=array('sdp'=>0,'nb'=>0,'nb_accession_libre'=>0,'cfi_accession_libre'=>array(),'pv_accession_libre'=>array(),'nb_accession_abordable'=>0,'cfi_accession_abordable'=>array(),'pv_accession_abordable'=>array(),'nb_accession_sociale_securise'=>0,'cfi_accession_sociale_securise'=>array(),'pv_accession_sociale_securise'=>array(),'nb_lls'=>0,'cfi_lls'=>array(),'pv_lls'=>array(),'nb_lli'=>0,'cfi_lli'=>array()); + $aProgrammes2=array(); + foreach ($aProgrammes as $aProgramme){ + // **** Compteurs pour fusion des cellules du tableau + if(isset($aCptCommunes[$aProgramme['nom_commune']])) + $aCptCommunes[$aProgramme['nom_commune']]=$aCptCommunes[$aProgramme['nom_commune']]+1; + else + $aCptCommunes[$aProgramme['nom_commune']]=1; + if(isset($aCptOperations[$aProgramme['id_operation']])) + $aCptOperations[$aProgramme['id_operation']]=$aCptOperations[$aProgramme['id_operation']]+1; + else + $aCptOperations[$aProgramme['id_operation']]=1; + if(isset($aCptIlots[$aProgramme['id_ilot']])) + $aCptIlots[$aProgramme['id_ilot']]=$aCptIlots[$aProgramme['id_ilot']]+1; + else + $aCptIlots[$aProgramme['id_ilot']]=1; + // **** Récupération des données tables associées + $iIdProgramme=$aProgramme['id_programme']; + $aProgramme2=array(); + // Granulométrie + $oResult3=$oConn->prepare("SELECT id_programme, code_type_granulometrie, sum(valeur) AS valeur FROM ".$sSchema.".granulometrie WHERE id_programme=".$iIdProgramme." AND code_type_granulometrie IN ('NB','SDP') AND code_composition_programme='TOT_LG_FAM' GROUP BY id_programme, code_composition_programme, code_type_granulometrie"); + $oResult3->execute(); + if($oResult3->rowCount()>0){ + $aGranulometries=$oResult3->fetchAll(); + foreach ($aGranulometries as $aGranulometrie){ + $aProgramme2[strtolower($aGranulometrie['code_type_granulometrie'])]=$aGranulometrie['valeur']; + $aTotaux[strtolower($aGranulometrie['code_type_granulometrie'])]=$aTotaux[strtolower($aGranulometrie['code_type_granulometrie'])]+$aGranulometrie['valeur']; + } + } + $oResult3->closeCursor(); + // profil + $oResult6=$oConn->prepare("SELECT pourc FROM prod_immo.profil_acheteur_accession_libre WHERE id_type_acheteur_accession_libre=2 AND pourc IS NOT NULL AND id_programme=".$iIdProgramme); + $oResult6->execute(); + if($oResult6->rowCount()>0){ + $aProfil=$oResult6->fetchAll(); + $aProgramme2['profil']=$aProfil[0]['pourc'].'%'; + } + $oResult6->closeCursor(); + // logement social + $oResult4=$oConn->prepare("SELECT id_programme, array_to_string(array_agg(DISTINCT nom_bailleur),',') AS nom_bailleur, id_indicateur_logement_familliaux_location, CASE WHEN id_indicateur_logement_familliaux_location=1 THEN sum(COALESCE(social_pls,0)) ELSE avg(COALESCE(social_pls,0)) END AS social_pls, CASE WHEN id_indicateur_logement_familliaux_location=1 THEN sum(COALESCE(social_plus_plai,0)) ELSE avg(COALESCE(social_plus_plai,0)) END AS social_plus_plai, CASE WHEN id_indicateur_logement_familliaux_location=1 THEN sum(COALESCE(intermediaire_pli,0)) ELSE avg(COALESCE(intermediaire_pli,0)) END AS intermediaire_pli, CASE WHEN id_indicateur_logement_familliaux_location=1 THEN sum(COALESCE(intermediaire_afl,0)) ELSE avg(COALESCE(intermediaire_afl,0)) END AS intermediaire_afl FROM ".$sSchema.".logement_familliaux_location INNER JOIN ".$sSchema.".composition_logement_familliaux_location_cp ON logement_familliaux_location.id_logement_familliaux_location=composition_logement_familliaux_location_cp.id_logement_familliaux_location WHERE id_programme=".$iIdProgramme." AND id_indicateur_logement_familliaux_location IN (1,4,5,8) GROUP BY id_programme, composition_logement_familliaux_location_cp.id_logement_familliaux_location, id_indicateur_logement_familliaux_location"); + $oResult4->execute(); + if($oResult4->rowCount()>0){ + $aLogSocials=$oResult4->fetchAll(); + $aProgramme2['nom_bailleur']=$aLogSocials[0]['nom_bailleur']; + $aCFIlls=array(); + $aCFIlli=array(); + foreach ($aLogSocials as $aLogSocial){ + switch ($aLogSocial['id_indicateur_logement_familliaux_location']) { + case 1: + if($aLogSocial['social_pls']>0 or $aLogSocial['social_plus_plai']>0){ + $bSetLogementSocial=true; + $aProgramme2['nb_lls']=$aLogSocial['social_pls']+$aLogSocial['social_plus_plai']; + $aTotaux['nb_lls']=$aTotaux['nb_lls']+$aLogSocial['social_pls']+$aLogSocial['social_plus_plai']; + } + if($aLogSocial['intermediaire_pli']>0 or $aLogSocial['intermediaire_afl']>0){ + $bSetLogementIntermediaire=true; + $aProgramme2['nb_lli']=$aLogSocial['intermediaire_pli']+$aLogSocial['intermediaire_afl']; + $aTotaux['nb_lli']=$aTotaux['nb_lli']+$aLogSocial['intermediaire_pli']+$aLogSocial['intermediaire_afl']; + } + break; + case 4: + case 5: + if(!is_null($aLogSocial['social_pls']) and $aLogSocial['social_pls']>0){ + $bSetLogementSocial=true; + $aCFIlls[count($aCFIlls)]=$aLogSocial['social_pls']; + $aTotaux['cfi_lls'][count($aTotaux['cfi_lls'])]=$aLogSocial['social_pls']; + } + if(!is_null($aLogSocial['social_plus_plai']) and $aLogSocial['social_plus_plai']>0){ + $bSetLogementSocial=true; + $aCFIlls[count($aCFIlls)]=$aLogSocial['social_plus_plai']; + $aTotaux['cfi_lls'][count($aTotaux['cfi_lls'])]=$aLogSocial['social_plus_plai']; + } + if(!is_null($aLogSocial['intermediaire_pli']) and $aLogSocial['intermediaire_pli']>0){ + $bSetLogementIntermediaire=true; + $aCFIlli[count($aCFIlli)]=$aLogSocial['intermediaire_pli']; + $aTotaux['cfi_lli'][count($aTotaux['cfi_lli'])]=$aLogSocial['intermediaire_pli']; + } + if(!is_null($aLogSocial['intermediaire_afl']) and $aLogSocial['intermediaire_afl']>0){ + $bSetLogementIntermediaire=true; + $aCFIlli[count($aCFIlli)]=$aLogSocial['intermediaire_afl']; + $aTotaux['cfi_lli'][count($aTotaux['cfi_lli'])]=$aLogSocial['intermediaire_afl']; + } + break; + case 8: + $aPVlls=array(); + if(!is_null($aLogSocial['social_pls']) and $aLogSocial['social_pls']>0){ + $bSetLogementSocial=true; + $aPVlls[count($aPVlls)]=$aLogSocial['social_pls']; + $aTotaux['pv_lls'][count($aTotaux['pv_lls'])]=$aLogSocial['social_pls']; + } + if(!is_null($aLogSocial['social_plus_plai']) and $aLogSocial['social_plus_plai']>0){ + $bSetLogementSocial=true; + $aPVlls[count($aPVlls)]=$aLogSocial['social_plus_plai']; + $aTotaux['pv_lls'][count($aTotaux['pv_lls'])]=$aLogSocial['social_plus_plai']; + } + $aProgramme2['pv_lls']=avg(array_sum($aPVlls),count($aPVlls)); + // pas de prix de vente en lli + break; + } + } + $aProgramme2['cfi_lls']=avg(array_sum($aCFIlls),count($aCFIlls)); + $aProgramme2['cfi_lli']=avg(array_sum($aCFIlli),count($aCFIlli)); + } + + $oResult4->closeCursor(); + // logement accession + $oResult5=$oConn->prepare("SELECT id_programme, id_indicateur_logement_familliaux_accession, CASE WHEN id_indicateur_logement_familliaux_accession=1 THEN sum(COALESCE(accession_libre::numeric,0)) ELSE avg(COALESCE(accession_libre::numeric,0)) END AS accession_libre, CASE WHEN id_indicateur_logement_familliaux_accession=1 THEN sum(COALESCE(accession_abordable::numeric,0)) ELSE avg(COALESCE(accession_abordable::numeric,0)) END AS accession_abordable, CASE WHEN id_indicateur_logement_familliaux_accession=1 THEN sum(COALESCE(accession_sociale_securise::numeric,0)) ELSE avg(COALESCE(accession_sociale_securise::numeric,0)) END AS accession_sociale_securise, CASE WHEN id_indicateur_logement_familliaux_accession=1 THEN sum(COALESCE(psla::numeric,0)) ELSE avg(COALESCE(psla::numeric,0)) END AS psla FROM ".$sSchema.".logement_familliaux_accession WHERE id_programme=".$iIdProgramme." AND id_indicateur_logement_familliaux_accession IN (1,4,5,8,9) GROUP BY id_programme, id_indicateur_logement_familliaux_accession"); + $oResult5->execute(); + if($oResult5->rowCount()>0){ + $aLogAccessions=$oResult5->fetchAll(); + $aCFIAccessionLibre=$aCFIAccessionAbordable=$aCFIAccessionSocialeSecurise=array(); + $aPVAccessionLibre=$aPVAccessionAbordable=$aPVAccessionSocialeSecurise=array(); + foreach ($aLogAccessions as $aLogAccession){ + switch ($aLogAccession['id_indicateur_logement_familliaux_accession']){ + case 1: + if($aLogAccession['accession_libre']>0){ + $bSetAccessionLibre=true; + $aProgramme2['nb_accession_libre']=$aLogAccession['accession_libre']; + $aTotaux['nb_accession_libre']=$aTotaux['nb_accession_libre']+$aLogAccession['accession_libre']; + } + if($aLogAccession['accession_abordable']>0){ + $bSetAccessionAbordable=true; + $aProgramme2['nb_accession_abordable']=$aLogAccession['accession_abordable']; + $aTotaux['nb_accession_abordable']=$aTotaux['nb_accession_abordable']+$aLogAccession['accession_abordable']; + } + if($aLogAccession['accession_sociale_securise']>0){ + $bSetAccessionSecurisee=true; + $aProgramme2['nb_accession_sociale_securise']=$aLogAccession['accession_sociale_securise']; + $aTotaux['nb_accession_sociale_securise']=$aTotaux['nb_accession_sociale_securise']+$aLogAccession['accession_sociale_securise']; + } + if($aLogAccession['psla']>0) $aProgramme2['nb_psla']=$aLogAccession['psla']; + break; + case 4: + case 5: + if(!is_null($aLogAccession['accession_libre']) and $aLogAccession['accession_libre']>0){ + $bSetAccessionLibre=true; + $aCFIAccessionLibre[count($aCFIAccessionLibre)]=$aLogAccession['accession_libre']; + $aTotaux['cfi_accession_libre'][count($aTotaux['cfi_accession_libre'])]=$aLogAccession['accession_libre']; + } + if(!is_null($aLogAccession['accession_abordable']) and $aLogAccession['accession_abordable']>0){ + $bSetAccessionAbordable=true; + $aCFIAccessionAbordable[count($aCFIAccessionAbordable)]=$aLogAccession['accession_abordable']; + $aTotaux['cfi_accession_abordable'][count($aTotaux['cfi_accession_abordable'])]=$aLogAccession['accession_abordable']; + } + if(!is_null($aLogAccession['accession_sociale_securise']) and $aLogAccession['accession_sociale_securise']>0){ + $bSetAccessionSecurisee=true; + $aCFIAccessionSocialeSecurise[count($aCFIAccessionSocialeSecurise)]=$aLogAccession['accession_sociale_securise']; + $aTotaux['cfi_accession_sociale_securise'][count($aTotaux['cfi_accession_sociale_securise'])]=$aLogAccession['accession_sociale_securise']; + } + break; + case 8: + case 9: + if(!is_null($aLogAccession['accession_libre']) and $aLogAccession['accession_libre']>0){ + $bSetAccessionLibre=true; + $aPVAccessionLibre[count($aPVAccessionLibre)]=$aLogAccession['accession_libre']; + $aTotaux['pv_accession_libre'][count($aTotaux['pv_accession_libre'])]=$aLogAccession['accession_libre']; + } + if(!is_null($aLogAccession['accession_abordable']) and $aLogAccession['accession_abordable']>0){ + $bSetAccessionAbordable=true; + $aPVAccessionAbordable[count($aPVAccessionAbordable)]=$aLogAccession['accession_abordable']; + $aTotaux['pv_accession_abordable'][count($aTotaux['pv_accession_abordable'])]=$aLogAccession['accession_abordable']; + } + if(!is_null($aLogAccession['accession_sociale_securise']) and $aLogAccession['accession_sociale_securise']>0){ + $bSetAccessionSecurisee=true; + $aPVAccessionSocialeSecurise[count($aPVAccessionSocialeSecurise)]=$aLogAccession['accession_sociale_securise']; + $aTotaux['pv_accession_sociale_securise'][count($aTotaux['pv_accession_sociale_securise'])]=$aLogAccession['accession_sociale_securise']; + } + break; + } + } + $aProgramme2['cfi_accession_libre']=avg(array_sum($aCFIAccessionLibre),count($aCFIAccessionLibre)); + $aProgramme2['cfi_accession_abordable']=avg(array_sum($aCFIAccessionAbordable),count($aCFIAccessionAbordable)); + $aProgramme2['cfi_accession_sociale_securise']=avg(array_sum($aCFIAccessionSocialeSecurise),count($aCFIAccessionSocialeSecurise)); + $aProgramme2['pv_accession_libre']=avg(array_sum($aPVAccessionLibre),count($aPVAccessionLibre)); + $aProgramme2['pv_accession_abordable']=avg(array_sum($aPVAccessionAbordable),count($aPVAccessionAbordable)); + $aProgramme2['pv_accession_sociale_securise']=avg(array_sum($aPVAccessionSocialeSecurise),count($aPVAccessionSocialeSecurise)); + } + $oResult5->closeCursor(); + $aProgrammes2[$aProgramme['id_programme']]=$aProgramme2; + } + $oResult->closeCursor(); + $aTotaux['cfi_accession_libre']=avg(array_sum($aTotaux['cfi_accession_libre']),count($aTotaux['cfi_accession_libre'])); + $aTotaux['pv_accession_libre']=avg(array_sum($aTotaux['pv_accession_libre']),count($aTotaux['pv_accession_libre'])); + $aTotaux['cfi_accession_abordable']=avg(array_sum($aTotaux['cfi_accession_abordable']),count($aTotaux['cfi_accession_abordable'])); + $aTotaux['pv_accession_abordable']=avg(array_sum($aTotaux['pv_accession_abordable']),count($aTotaux['pv_accession_abordable'])); + $aTotaux['cfi_accession_sociale_securise']=avg(array_sum($aTotaux['cfi_accession_sociale_securise']),count($aTotaux['cfi_accession_sociale_securise'])); + $aTotaux['pv_accession_sociale_securise']=avg(array_sum($aTotaux['pv_accession_sociale_securise']),count($aTotaux['pv_accession_sociale_securise'])); + $aTotaux['cfi_lls']=avg(array_sum($aTotaux['cfi_lls']),count($aTotaux['cfi_lls'])); + $aTotaux['pv_lls']=avg(array_sum($aTotaux['pv_lls']),count($aTotaux['pv_lls'])); + $aTotaux['cfi_lli']=avg(array_sum($aTotaux['cfi_lli']),count($aTotaux['cfi_lli'])); + } + $sCssColor='blue'; + include ('get_4_logement.html'); + } + }catch (PDOException $e){ + $sError="ERROR : ".$e->getMessage(); + include ('get_error.html'); + } + } + +}else{ + $sError="ERREUR : Pas de token passé."; + include ('get_error.html'); +} + ?> \ No newline at end of file