Exemplo n.º 1
0
 /**
  * Return the data for a single customer
  */
 public function getData($id = null)
 {
     $lang = R3Locale::getLanguageID();
     $db = ezcDbInstance::get();
     if ($this->auth->getParam('mu_id') != '') {
         // override the default action if it is a municipality user
         $sql = "SELECT gst_id FROM global_strategy WHERE mu_id=" . $db->quote($this->auth->getParam('mu_id'));
         $this->id = $db->query($sql)->fetchColumn();
         $this->act = $this->id > 0 ? 'mod' : 'add';
     }
     $vlu = array();
     if ($this->act != 'add') {
         R3Security::checkGlobalStrategy($this->id);
         $q = $db->createSelectQuery();
         $q->select('*')->from('global_strategy_data')->where("gst_id={$this->id}");
         $vlu = $db->query($q)->fetch(PDO::FETCH_ASSOC);
         $vlu['mu_name'] = $vlu["mu_name_{$lang}"];
         // Autocomplete
         $vlu = array_merge($vlu, R3EcoGisHelper::getChangeLogData('global_strategy', $this->id));
     } else {
         $vlu['do_id'] = $this->do_id;
         $mu_values = R3EcoGisGlobalStrategyHelper::getAvailableMunicipalityList($this->do_id);
         if (count($mu_values) == 1) {
             $vlu['mu_id'] = key($mu_values);
         } else {
             if ($this->auth->getParam('mu_id') > 0) {
                 $vlu['mu_id'] = $this->auth->getParam('mu_id');
             }
         }
         if (isset($vlu['mu_id']) && $vlu['mu_id'] != '') {
             $vlu['gst_name_1'] = 'Adesione al Patto dei Sindaci - Comune di ' . R3EcoGisHelper::getMunicipalityName($vlu['mu_id'], 1);
             $vlu['gst_name_2'] = 'Bürgermeisterkonvents - Gemeinde ' . R3EcoGisHelper::getMunicipalityName($vlu['mu_id'], 2);
         } else {
             $vlu['gst_name_1'] = 'Adesione al Patto dei Sindaci';
             $vlu['gst_name_2'] = 'Bürgermeisterkonvents';
         }
         $vlu['gst_reduction_target'] = 20;
         $vlu['gst_reduction_target_year'] = 2020;
         $vlu['gst_reduction_target_absolute'] = $vlu['gst_reduction_target_absolute_long_term'] = 'T';
         $vlu['gst_emission_factor_type_ipcc'] = $vlu['gst_emission_unit_co2'] = 'T';
     }
     $this->data = $vlu;
     // Save the data (prevent multiple sql)
     return $vlu;
 }
Exemplo n.º 2
0
 /**
  * Return the data for a single customer
  */
 public function getData($id = null)
 {
     $lang = R3Locale::getLanguageID();
     $db = ezcDbInstance::get();
     if ($this->act != 'add') {
         $q = $db->createSelectQuery();
         $q->select('*')->from('building_data')->where("bu_id={$this->id}");
         $vlu = $db->query($q)->fetch(PDO::FETCH_ASSOC);
         $vlu['mu_name'] = $vlu["mu_name_{$lang}"];
         // Autocomplete
         $vlu['fr_name'] = $vlu["fr_name_{$lang}"];
         // Autocomplete
         $vlu['st_name'] = $vlu["st_name_{$lang}"];
         // Autocomplete
         $vlu['bu_usage_h_from'] = substr($vlu['bu_usage_h_from'], 0, 5);
         $vlu['bu_usage_h_to'] = substr($vlu['bu_usage_h_to'], 0, 5);
         $vlu['bu_build_year_as_string'] = $vlu['bu_build_year'];
         // Prevent number format
         $vlu['bu_restructure_year_as_string'] = $vlu['bu_restructure_year'];
         // Prevent number format
         // Immgini
         $sql = "SELECT doc_file_id, doct_code\n                    FROM document doc\n                    INNER JOIN document_type doct ON doc.doct_id=doct.doct_id\n                    WHERE doc_object_id={$this->id} AND doct_code IN ('BUILDING_PHOTO', 'BUILDING_THERMOGRAPHY', 'BUILDING_LABEL')";
         // echo $sql;
         $images = array();
         foreach ($db->query($sql) as $row) {
             $images[strtolower($row['doct_code'])][] = $row['doc_file_id'];
         }
         $vlu['images'] = $images;
         if ($vlu['has_geometry']) {
             $vlu['map_preview_url'] = htmlspecialchars(R3EcoGisHelper::getMapPreviewURL($this->do_id, 'building', $this->id, $lang));
         }
         $vlu = array_merge($vlu, R3EcoGisHelper::getChangeLogData('building', $vlu['bu_id']));
     } else {
         $vlu = array();
         $vlu['do_id'] = $this->do_id;
         $vlu['cus_name'] = R3EcoGisHelper::getDomainName($this->do_id);
         $mu_values = R3EcoGisHelper::getMunicipalityList($this->do_id);
         if (count($mu_values) == 1) {
             $vlu['mu_id'] = key($mu_values);
         } else {
             if ($this->auth->getParam('mu_id') > 0) {
                 $vlu['mu_id'] = $this->auth->getParam('mu_id');
             }
         }
         if (isset($vlu['mu_id']) && $vlu['mu_id'] != '') {
             $vlu['mu_name'] = R3EcoGisHelper::getMunicipalityName($vlu['mu_id']);
             if ($this->auth->getConfigValue('APPLICATION', 'BUILDING_CODE_TYPE') == 'AUTO' || $this->auth->getConfigValue('APPLICATION', 'BUILDING_CODE_TYPE') == 'PROPOSED') {
                 $fmt = $this->auth->getConfigValue('APPLICATION', 'BUILDING_CODE_FORMAT');
                 try {
                     $vlu['bu_code'] = sprintf($fmt == '' ? '%s' : $fmt, $db->query("SELECT MAX(bu_code::integer) FROM building WHERE mu_id={$vlu['mu_id']}")->fetchColumn() + 1);
                 } catch (Exception $e) {
                 }
             }
         }
         $vlu['ez_id'] = null;
         $vlu['ec_id'] = null;
     }
     $this->data = $vlu;
     // Save the data (prevent multiple sql)
     return $vlu;
 }
Exemplo n.º 3
0
 /**
  * Return the data for a single customer 
  */
 public function getData($id = null)
 {
     $lang = R3Locale::getLanguageID();
     if ($id === null) {
         $id = $this->id;
     }
     if ($this->auth->hasPerm('SHOW', 'ALL_DOMAINS')) {
         $do_id = $_SESSION['do_id'];
     } else {
         $do_id = $this->auth->getDomainID();
     }
     $db = ezcDbInstance::get();
     $vlu = array();
     if ($this->act != 'add') {
         if ($id === null) {
             throw new Exception("Missing ID for customer");
         }
         $q = $db->createSelectQuery();
         $where = array();
         $where[] = 'sl_id=' . (int) $id;
         if (!$this->auth->hasPerm('SHOW', 'ALL_DOMAINS')) {
             $where[] = $q->expr->eq('do_id', (int) $this->auth->getDomainID());
         }
         $q->select('*')->from('street_lighting_data')->where($where);
         $vlu = $db->query($q)->fetch(PDO::FETCH_ASSOC);
         $vlu['cus_name'] = $vlu['cus_name_' . $lang];
         $vlu['mu_name'] = $vlu['mu_name_' . $lang];
         if ($vlu['has_geometry']) {
             $vlu['map_preview_url'] = R3EcoGisHelper::getMapPreviewURL($this->do_id, 'street_lighting', $this->id, $lang);
         }
         $vlu = array_merge($vlu, R3EcoGisHelper::getChangeLogData('street_lighting', $vlu['sl_id']));
     } else {
         $vlu = array();
         $vlu['do_id'] = $_SESSION['do_id'];
         $vlu['cus_name'] = R3EcoGisHelper::getDomainName($_SESSION['do_id']);
         $mu_values = R3EcoGisHelper::getMunicipalityList($this->do_id);
         if (count($mu_values) == 1) {
             $vlu['mu_id'] = key($mu_values);
         } else {
             if ($this->auth->getParam('mu_id') > 0) {
                 $vlu['mu_id'] = $this->auth->getParam('mu_id');
             }
         }
         if (isset($vlu['mu_id']) && $vlu['mu_id'] != '') {
             $vlu['mu_name'] = R3EcoGisHelper::getMunicipalityName($vlu['mu_id']);
         }
     }
     $this->data = $vlu;
     // Save the data (prevent multiple sql)
     return $vlu;
 }
Exemplo n.º 4
0
 /**
  * Return the data for a single customer
  */
 public function getData($id = null)
 {
     $lang = R3Locale::getLanguageID();
     if ($id === null) {
         $id = $this->id;
     }
     $db = ezcDbInstance::get();
     if ($this->act != 'add') {
         $q = $db->createSelectQuery();
         $q->select('*')->from('global_entry_data')->where('ge_id=' . (int) $id);
         $vlu = $db->query($q)->fetch(PDO::FETCH_ASSOC);
         $vlu['cus_name'] = $vlu['cus_name_' . $lang];
         $vlu['mu_name'] = $vlu['mu_name_' . $lang];
         // Autocomplete
         $vlu['ge_year_as_string'] = $vlu['ge_year'];
         // Prevent number format
         $vlu['ge_green_electricity_purchase'] = $vlu['ge_green_electricity_purchase'] / 1000;
         // Revert to MWh
         $vlu = array_merge($vlu, R3EcoGisHelper::getChangeLogData('global_entry', $vlu['ge_id']));
     } else {
         $vlu = array();
         $vlu['do_id'] = $_SESSION['do_id'];
         $vlu['cus_name'] = R3EcoGisHelper::getDomainName($_SESSION['do_id']);
         $mu_values = R3EcoGisHelper::getMunicipalityList($this->do_id);
         if (count($mu_values) == 1) {
             $vlu['mu_id'] = key($mu_values);
         } else {
             if ($this->auth->getParam('mu_id') > 0) {
                 $vlu['mu_id'] = $this->auth->getParam('mu_id');
             }
         }
         if ($this->auth->getParam('mu_id') > 0) {
             $vlu['mu_id'] = $this->auth->getParam('mu_id');
             $vlu['mu_name'] = R3EcoGisHelper::getMunicipalityName($this->auth->getParam('mu_id'));
         }
     }
     $this->data = $vlu;
     // Save the data (prevent multiple sql)
     return $vlu;
 }
Exemplo n.º 5
0
 /**
  * Return the data for a single customer
  */
 public function getData($id = null)
 {
     $lang = R3Locale::getLanguageID();
     $db = ezcDbInstance::get();
     if ($this->act != 'add') {
         $q = $db->createSelectQuery();
         $q->select('*')->from('action_catalog_data ac')->where("ac_id={$this->id}");
         $vlu = $db->query($q)->fetch(PDO::FETCH_ASSOC);
         $vlu['mu_name'] = $vlu["mu_name_{$lang}"];
         // Autocomplete
         $vlu['ac_expected_co2_reduction'] = $vlu['ac_expected_co2_reduction_calc'] / 1000;
         // Get the calculated value - the db value is not used
         $vlu['ac_expected_energy_saving_mwh'] = $vlu['ac_expected_energy_saving_kwh'] / 1000;
         $vlu['ac_green_electricity_purchase_mwh'] = R3NumberFormat($vlu['ac_green_electricity_purchase_kwh'] / 1000, 2, true);
         $vlu['ac_co2_reduction_tco2'] = R3NumberFormat($vlu['ac_co2_reduction'] / 1000, 2, true);
         $vlu['ac_expected_renewable_energy_production_mwh'] = $vlu['ac_expected_renewable_energy_production_kwh'] / 1000;
         // Get the calculated value - the db value is not used
         // get expected energy savings
         $vlu['ac_expected_energy_savings'] = array();
         $sql = "SELECT action_catalog_energy.*, energy_source_udm.*, " . "      esu_kwh_factor * ace_expected_energy_saving AS ace_expected_energy_saving_kwh, " . "      esu_co2_factor * ace_expected_energy_saving AS ace_expected_co2_reduction_calc " . " FROM action_catalog_energy " . " INNER JOIN energy_source_udm USING(esu_id) " . " WHERE ac_id={$this->id} " . "ORDER BY ace_id";
         $r = $db->query($sql);
         while ($row = $r->fetch()) {
             $lkp = $this->getLookupDataForEnergySavings($row['ges_id']);
             $tmp = array('ges_id' => $row['ges_id'], 'es_id' => $row['es_id'], 'udm_id' => $row['udm_id'], 'ac_expected_energy_saving' => R3NumberFormat($row['ace_expected_energy_saving'], 2, true), 'ac_expected_energy_saving_mwh' => R3NumberFormat($row['ace_expected_energy_saving_kwh'] / 1000, 2, true), 'ac_expected_co2_reduction' => R3NumberFormat($row['ace_expected_co2_reduction_calc'] / 1000, 2, true), 'es_id_consumption_values' => $lkp['es_id_consumption_values'], 'udm_id_consumption_values' => $lkp['udm_id_consumption_values']);
             $vlu['ac_expected_energy_savings'][] = $tmp;
         }
         // get related actions
         $vlu['ac_related_actions'] = array();
         $vlu['ac_related_required_actions'] = array();
         $vlu['ac_related_excluded_actions'] = array();
         $sql = "SELECT action_catalog.ac_id, ac_name_{$lang}, acd_type " . " FROM action_catalog " . " INNER JOIN action_catalog_dependencies on action_catalog.ac_id = action_catalog_dependencies.ac_related_id " . " WHERE action_catalog_dependencies.ac_id={$this->id}";
         $r = $db->query($sql);
         while ($row = $r->fetch()) {
             if ($row['acd_type'] == 'R') {
                 $index = 'ac_related_required_actions';
             } else {
                 if ($row['acd_type'] == 'D') {
                     $index = 'ac_related_actions';
                 } else {
                     if ($row['acd_type'] == 'E') {
                         $index = 'ac_related_excluded_actions';
                     } else {
                         throw new exceltion('Invalid value for acd_type');
                     }
                 }
             }
             $tmp = array('ac_id' => $row['ac_id'], 'ac_name' => $row['ac_name_' . $lang]);
             array_push($vlu[$index], $tmp);
         }
         // get benefit year
         $vlu['ac_benefit_year'] = array();
         $sql = "SELECT acby_year, acby_benefit \r\n                    FROM action_catalog_benefit_year\r\n                    WHERE ac_id={$this->id}\r\n                    ORDER BY acby_year";
         $vlu['enable_benefit_year'] = 'F';
         foreach ($db->query($sql, PDO::FETCH_ASSOC) as $row) {
             $vlu['ac_benefit_year'][] = $row;
             $vlu['enable_benefit_year'] = 'T';
         }
         if ($this->bu_id != '') {
             $vlu['bu_id'] = $this->bu_id;
         }
         $vlu = array_merge($vlu, R3EcoGisHelper::getChangeLogData('action_catalog', $vlu['ac_id']));
     } else {
         $vlu = array();
         $vlu['ac_id'] = null;
         $vlu['bu_id'] = $this->bu_id;
         $mu_values = R3EcoGisHelper::getMunicipalityList($this->do_id);
         if (count($mu_values) == 1) {
             $vlu['mu_id'] = key($mu_values);
         } else {
             if ($this->auth->getParam('mu_id') > 0) {
                 $vlu['mu_id'] = $this->auth->getParam('mu_id');
             }
         }
         if (isset($vlu['mu_id']) && $vlu['mu_id'] != '') {
             $vlu['mu_name'] = R3EcoGisHelper::getMunicipalityName($vlu['mu_id']);
         }
         if ($this->bu_id != '') {
             $vlu['mu_id'] = $db->query('SELECT mu_id FROM building WHERE bu_id=' . (int) $this->bu_id)->fetchColumn();
             $emo_id = R3EcoGisHelper::getEnergyMeterObjectIdByCode('BUILDING');
             $codePart1 = $db->query('SELECT bu_code FROM building WHERE bu_id=' . (int) $this->bu_id)->fetchColumn();
             $codePart2 = $db->query("SELECT LPAD((COUNT(ac_code) + 1)::TEXT, 2, '0') FROM action_catalog WHERE emo_id={$emo_id} AND ac_object_id=" . (int) $this->bu_id)->fetchColumn();
             if ($codePart1 == '') {
                 $vlu['ac_code'] = $codePart2;
             } else {
                 $vlu['ac_code'] = "{$codePart1}-{$codePart2}";
             }
             // Ricavo Macro-settore, Settore, Sub-settore
             list($gc_id, $gc_id_parent) = R3EcoGisHelper::getGlobalCategoryForActionCatalogBuilding($this->bu_id);
             if ($gc_id_parent === null || $gc_id === null) {
                 throw new Exception(_("Destinazione d'uso dell'edificio mancante, o categoria PAES non valida"));
             }
             $vlu['gc_parent_id'] = $gc_id_parent;
             $vlu['gc_id'] = $gc_id;
         } else {
             if (isset($vlu['mu_id'])) {
                 $vlu['ac_code'] = (int) $db->query('SELECT MAX(ac_code) FROM action_catalog WHERE mu_id=' . (int) $vlu['mu_id'])->fetchColumn() + 1;
             }
         }
         $vlu['ac_benefit_end_date'] = $this->auth->getConfigValue('APPLICATION', 'DEFAULT_ACTION_BENEFIT_END_DATE', '2020-12-31');
     }
     $this->data = $vlu;
     // Save the data (prevent multiple sql)
     return $vlu;
 }
Exemplo n.º 6
0
 public function askDelESU($request)
 {
     $db = ezcDbInstance::get();
     $lang = R3Locale::getLanguageID();
     $id = forceInteger($request['id'], 0, false, '.');
     $data = $db->query("SELECT es_name_{$lang} AS es_name, udm_name_{$lang} AS udm_name, mu_id FROM energy_source_udm_data WHERE esu_id={$id}")->fetch(PDO::FETCH_ASSOC);
     if ($request['type'] == 'MUNICIPALITY') {
         $mu_name = R3EcoGisHelper::getMunicipalityName($data['mu_id']);
         return array('status' => R3_AJAX_NO_ERROR, 'confirm' => sprintf(_("Sei sicuro di voler cancellare il fattore di conversione \"%s (%s)\" e ripristinare il valore standard per i consumi già inseriti nel comune di \"%s\"?"), $data['es_name'], $data['udm_name'], $mu_name));
     } else {
         if ($this->tryDeleteData($id)) {
             return array('status' => R3_AJAX_NO_ERROR, 'confirm' => sprintf(_("Sei sicuro di voler cancellare il fattore di conversione \"%s (%s)\"?"), $data['es_name'], $data['udm_name']));
         } else {
             return array('status' => R3_AJAX_NO_ERROR, 'alert' => _('Impossibile cancellare questo fattore di conversione poichè vi sono dei dati ad esso legati'));
         }
     }
 }
Exemplo n.º 7
0
 /**
  * Return the data for a single customer
  */
 public function getData($id = null)
 {
     $lang = R3Locale::getLanguageID();
     $db = ezcDbInstance::get();
     if ($this->act != 'add') {
         $q = $db->createSelectQuery();
         $q->select('*')->from('global_plain_data')->where("gp_id={$this->id}");
         $vlu = $db->query($q)->fetch(PDO::FETCH_ASSOC);
         $vlu['mu_name'] = $vlu["mu_name_{$lang}"];
         // Autocomplete
         $vlu['gp_url_1'] = $this->adjURL($vlu["gp_url_1"], true);
         if (isset($vlu["gp_url_2"])) {
             $vlu['gp_url_2'] = $this->adjURL($vlu["gp_url_2"], true);
         }
         $vlu = array_merge($vlu, R3EcoGisHelper::getChangeLogData('global_plain', $vlu['gp_id']));
     } else {
         $vlu = array();
         $vlu['do_id'] = $this->do_id;
         $mu_values = R3EcoGisHelper::getMunicipalityList($this->do_id);
         if (count($mu_values) == 1) {
             $vlu['mu_id'] = key($mu_values);
         } else {
             if ($this->auth->getParam('mu_id') > 0) {
                 $vlu['mu_id'] = $this->auth->getParam('mu_id');
             }
         }
         if (isset($vlu['mu_id']) && $vlu['mu_id'] != '') {
             $vlu['mu_name'] = R3EcoGisHelper::getMunicipalityName($vlu['mu_id']);
         }
         $vlu['gp_url_1'] = $this->adjURL('', true);
         $vlu['gp_url_2'] = $this->adjURL('', true);
     }
     $this->data = $vlu;
     // Save the data (prevent multiple sql)
     return $vlu;
 }
Exemplo n.º 8
0
 /**
  * Return the data for a single customer 
  */
 public function getData($id = null)
 {
     return;
     $lang = R3Locale::getLanguageID();
     if ($id === null) {
         $id = $this->id;
     }
     if ($this->auth->hasPerm('SHOW', 'ALL_DOMAINS')) {
         $do_id = $_SESSION['do_id'];
     } else {
         $do_id = $this->auth->getDomainID();
     }
     $db = ezcDbInstance::get();
     $vlu = array();
     if ($this->act != 'add') {
         if ($id === null) {
             throw new Exception("Missing ID for customer");
         }
         $q = $db->createSelectQuery();
         $where = array();
         $where[] = 'sl_id=' . (int) $id;
         if (!$this->auth->hasPerm('SHOW', 'ALL_DOMAINS')) {
             $where[] = $q->expr->eq('do_id', (int) $this->auth->getDomainID());
         }
         $q->select('*')->from('street_lighting_data')->where($where);
         $vlu = $db->query($q)->fetch(PDO::FETCH_ASSOC);
         $vlu['cus_name'] = $vlu['cus_name_' . $lang];
         $vlu['mu_name'] = $vlu['mu_name_' . $lang];
     } else {
         $vlu = array();
         // Default value
         $vlu['do_id'] = $_SESSION['do_id'];
         $vlu['cus_name'] = R3EcoGisHelper::getDomainName($_SESSION['do_id']);
         if ($this->auth->getParam('mu_id') > 0) {
             $vlu['mu_id'] = $this->auth->getParam('mu_id');
             $vlu['mu_name'] = R3EcoGisHelper::getMunicipalityName($this->auth->getParam('mu_id'));
         }
     }
     $this->data = $vlu;
     // Save the data (prevent multiple sql)
     return $vlu;
 }
Exemplo n.º 9
0
$smarty->assign('LANG_NAME_SHORT_FMT_3', getLangNameShort(3));
$smarty->assign('LANG_NAME_1', getLangName(1, true));
$smarty->assign('LANG_NAME_2', getLangName(2, true));
$smarty->assign('LANG_NAME_3', getLangName(3, true));
$smarty->assign('R3_CSS_URL', R3_CSS_URL);
$smarty->assign('R3_JS_URL', R3_JS_URL);
$smarty->assign('R3_ICONS_URL', R3_ICONS_URL);
/* ------------------------------ Permission & DB settings assignment ------------------------------ */
if (isset($auth) && ($auth->isAuth() || $auth->getStatus() == AUTH_PASSWORD_EXPIRED || $auth->getStatus() == AUTH_PASSWORD_REPLACE)) {
    // Some user information
    $smarty->assign('USER_ID', $auth->getUID());
    $smarty->assign('USER_MUNICIPALITY', $auth->getParam('mu_id'));
    $smarty->assign('USER_LOGIN', $auth->getLogin());
    $smarty->assign('USER_NAME', $auth->getParam('us_name'));
    if ($auth->getParam('mu_id') != '') {
        $smarty->assign('USER_MUNICIPALITY', R3EcoGisHelper::getMunicipalityName($auth->getParam('mu_id')));
    }
    $smarty->assign('USER_IP', $auth->getParam('us_last_ip'));
    $smarty->assign('DOMAIN_NAME', $auth->getDomainName());
    $smarty->assign('APPLICATION_CODE', $auth->getParam('app_code'));
    $smarty->assign('APPLICATION_NAME', $auth->getParam('app_name'));
    $numLanguages = $auth->getConfigValue('APPLICATION', 'NUM_LANGUAGES');
    /** Permission */
    foreach ($auth->getAllPermsAsString() as $_value) {
        $smarty->assign($_value, true);
    }
    /** DB Configuration */
    foreach ($auth->getAllConfigValuesAsString() as $_key => $_value) {
        $smarty->assign($_key, $_value);
    }
    if ($auth->hasPerm('SHOW', 'ALL_DOMAINS') && $auth->getDomainID() != $_SESSION['do_id']) {