Ejemplo n.º 1
0
 public function getFilterValues()
 {
     $filters = array();
     $filters['do_values'] = R3EcoGisHelper::getDomainList();
     $filters['us_name_email'] = $this->us_name_email;
     if ($this->auth->getConfigValue('PUBLIC_SITE', 'REGISTRATION_NEED_OPERATOR_CONFIRM', 'F') == 'T') {
         $filters['us_status_list'] = array('E' => _('Attivo'), 'D' => _('In attesa di attivazione'));
     }
     $filters['us_status'] = $this->us_status;
     return $filters;
 }
Ejemplo n.º 2
0
 /**
  * Return the data for a single customer
  */
 public function getLookupData()
 {
     $lkp = array();
     $energyMeterData = $this->data['em_data'];
     $lkp['dt_values'] = R3EcoGisHelper::getDeviceTypeList($_SESSION['do_id'], $this->kind, array('production' => $energyMeterData['em_is_production'] == 'T' ? true : null, 'consumption' => $energyMeterData['em_is_production'] == 'T' ? null : true));
     if (1 == 2) {
         // Inizio e fine impianto sono solo anni
         $lkp['dev_install_date_values'] = R3EcoGisHelper::getDeviceInstallYearList($_SESSION['do_id'], $this->kind);
         $lkp['dev_end_date_values'] = R3EcoGisHelper::getDeviceEndYearList($_SESSION['do_id'], $this->kind);
     }
     return $lkp;
 }
Ejemplo n.º 3
0
 /**
  * Return the data for a single customer
  */
 public function getData($id = null)
 {
     $db = ezcDbInstance::get();
     $sql = "SELECT * FROM stat_general WHERE do_id=" . $this->do_id;
     $vlu = $db->query($sql)->fetch(PDO::FETCH_ASSOC);
     if ($vlu === false) {
         $vlu = array('sg_id' => null);
     }
     $vlu = array_merge($vlu, R3EcoGisHelper::getChangeLogData('stat_general', $vlu['sg_id']));
     $this->data = $vlu;
     // Save the data (prevent multiple sql)
     return $vlu;
 }
Ejemplo n.º 4
0
 /**
  * Return the filter values (list form)
  */
 public function getFilterValues()
 {
     $filters = array();
     if ($this->auth->hasPerm('SHOW', 'ALL_DOMAINS')) {
         $do_id = null;
         $filters['do_values'] = R3EcoGisHelper::getDomainList();
     } else {
         $do_id = $this->auth->getDomainID();
     }
     $filters['pr_values'] = R3EcoGisHelper::getProvinceList($do_id);
     $filters['mu_values'] = R3EcoGisHelper::getMunicipalityList($do_id);
     $filters['bpu_values'] = R3EcoGisHelper::getBuildingPurposeUseList($do_id);
     $filters['do_id'] = $this->do_id;
     $filters['pr_id'] = $this->pr_id;
     $filters['mu_id'] = $this->mu_id;
     $filters['bpu_id'] = $this->bpu_id;
     return $filters;
 }
Ejemplo n.º 5
0
 public function getPageVars()
 {
     $hasReductionOrPruduction = count(R3EcoGisHelper::getGlobalPlainGaugeTypeList($_SESSION['do_id'], $this->gpr_id)) > 0;
     return array('hasReductionOrPruduction' => $hasReductionOrPruduction, 'gpr_id' => $this->gpr_id, 'tab_mode' => $this->tab_mode, 'parent_act' => $this->parent_act, 'date_format' => R3Locale::getJQueryDateFormat());
 }
Ejemplo n.º 6
0
 public function create_grid($request)
 {
     global $dbini;
     $db = ezcDbInstance::get();
     session_write_close();
     ignore_user_abort();
     //transaction
     $gridSize = (int) $request['sg_size'];
     $db->beginTransaction();
     R3EcoGisCustomerHelper::createGrid((int) $request['do_id'], $gridSize);
     $dnName = R3EcoGisHelper::getDomainCodeFromID($request['do_id']);
     $dbini2 = clone $dbini;
     $dbini2->setDomainName($dnName);
     $dbini2->setValue('APPLICATION', 'STAT_GRID_SIZE', $gridSize > 0 ? $gridSize : null);
     $db->commit();
     return array('status' => R3_AJAX_NO_ERROR);
 }
Ejemplo n.º 7
0
 public function performActionCatalogCalc($request)
 {
     setlocale(LC_ALL, 'C');
     $energySavingData = R3EcoGisHelper::getEnergySourceUdmData($_SESSION['do_id'], $request['es_id_consumption'], $request['udm_id_consumption'], $request['mu_id']);
     $energyProductionData = R3EcoGisHelper::getEnergySourceUdmData($_SESSION['do_id'], $request['es_id_production'], $request['udm_id_production'], $request['mu_id']);
     $ac_expected_co2_reduction_total = 0;
     $ac_expected_co2_reduction = array();
     $ac_expected_energy_saving_mwh = array();
     foreach ($energySavingData as $i => $val) {
         $ac_expected_co2_reduction_total += $request['ac_expected_energy_saving'][$i] == '' ? null : $request['ac_expected_energy_saving'][$i] * $energySavingData[$i]['esu_co2_factor'] / 1000;
         $ac_expected_co2_reduction[$i] = R3NumberFormat($request['ac_expected_energy_saving'][$i] == '' ? null : $request['ac_expected_energy_saving'][$i] * $energySavingData[$i]['esu_co2_factor'] / 1000, 2, true);
         $ac_expected_energy_saving_mwh[$i] = R3NumberFormat($request['ac_expected_energy_saving'][$i] == '' ? null : $request['ac_expected_energy_saving'][$i] * $energySavingData[$i]['esu_kwh_factor'] / 1000, 2, true);
     }
     if ($energyProductionData === null) {
         $energyProductionMWh = null;
     } else {
         $energyProductionMWh = $request['ac_expected_renewable_energy_production'] == '' ? null : $request['ac_expected_renewable_energy_production'] * $energyProductionData[0]['esu_kwh_factor'] / 1000;
     }
     return array('status' => R3_AJAX_NO_ERROR, 'data' => array('ac_expected_co2_reduction_total' => R3NumberFormat($ac_expected_co2_reduction_total, null, true), 'ac_expected_co2_reduction' => $ac_expected_co2_reduction, 'ac_expected_energy_saving_mwh' => $ac_expected_energy_saving_mwh, 'ac_expected_renewable_energy_production_mwh' => R3NumberFormat($energyProductionMWh, null, true)));
 }
Ejemplo n.º 8
0
/**
 * Build the js if necessary
 *
 */
function R3BuildJS($force = false)
{
    global $auth, $jsPacker;
    $appCode = strtolower(APPLICATION_CODE);
    $jsDestPath = R3_UPLOAD_DATA_DIR . strtolower(R3EcoGisHelper::getCurrentDomainName()) . "/js/";
    $masterFileName = "{$jsDestPath}{$appCode}_all.js";
    if (!$force) {
        $rebuild = !file_exists($masterFileName);
        if (!$rebuild) {
            $compiledAge = filemtime($masterFileName);
            $files = $jsPacker['JS_files'];
            if (isset($jsPacker['files'])) {
                foreach ($jsPacker['files'] as $name => $fileGroup) {
                    $name = str_replace('<LANG>', R3Locale::getLanguageCode(), $name);
                    if (!file_exists("{$jsDestPath}{$name}")) {
                        $rebuild = true;
                        ezcLog::getInstance()->log("JavaScript file \"{$jsDestPath}{$name}\" not found. Rebuild necessary", ezcLog::DEBUG);
                        break;
                    }
                    foreach ($fileGroup as $file) {
                        $files[] = $file;
                    }
                }
            }
            foreach ($files as $file) {
                $file = str_replace('<LANG>', R3Locale::getLanguageCode(), $file);
                if (filemtime(R3_WEB_JS_DIR . $file) > $compiledAge) {
                    // Complie needed
                    $rebuild = true;
                    break;
                }
            }
        }
    }
    if ($force || $rebuild) {
        checkPath(dirname($masterFileName), true, true);
        // Non packed files
        if (isset($jsPacker['files'])) {
            foreach ($jsPacker['files'] as $name => $fileGroup) {
                $script = '';
                foreach ($fileGroup as $file) {
                    $file = str_replace('<LANG>', R3Locale::getLanguageCode(), $file);
                    $script .= "/*** " . basename($file) . " ***/\n\n\n" . file_get_contents(R3_WEB_JS_DIR . $file) . "\n\n\n";
                }
                $name = str_replace('<LANG>', R3Locale::getLanguageCode(), dirname($masterFileName) . '/' . $name);
                ezcLog::getInstance()->log("JavaScript rebuild for \"{$name}\"", ezcLog::DEBUG);
                file_put_contents($name, $script);
            }
        }
        require_once R3_LIB_DIR . 'class.JavaScriptPacker.php';
        $script = '';
        $funcList = array();
        foreach ($jsPacker['JS_files'] as $file) {
            $data = file_get_contents(R3_WEB_JS_DIR . $file);
            $script .= "{$data}\n\n\n";
            // Check function averride!
            foreach (explode("\n", $data) as $lineNo => $line) {
                if (substr($line, 0, 9) == 'function ' && ($p = strpos($line, '(')) !== false) {
                    $name = trim(substr($line, 9, $p - 9));
                    if (isset($funcList[$name])) {
                        echo "<b>Warning</b>: JavaScript function \"{$name}\" in file {$file}:{$lineNo} already declared in file {$funcList[$name]['file']}:{$funcList[$name]['line']}.<br />\n";
                    }
                    $funcList[$name] = array('file' => $file, 'line' => $lineNo);
                }
            }
        }
        if (!isset($jsPacker['minify_output'])) {
            ezcLog::getInstance()->log("JavaScript rebuild for \"{$masterFileName}\"", ezcLog::DEBUG);
            file_put_contents($masterFileName, $script);
        } else {
            $packer = new JavaScriptPacker($script, $jsPacker['minify_output'] ? 'Normal' : 'None', true, false);
            $packed = $packer->pack();
            ezcLog::getInstance()->log("JavaScript rebuild for \"{$masterFileName}\"", ezcLog::DEBUG);
            file_put_contents($masterFileName, $packed);
        }
    }
}
Ejemplo n.º 9
0
 /**
  * Ajax request to submit data
  * @param array $request   the request
  * @return array           ajax format status
  */
 public function submitFormData($request)
 {
     $errors = array();
     if (isset($_FILES['doc_file'])) {
         if (is_array($_FILES['doc_file']['name'])) {
             // Consider only the first file
             $files = array('name' => $_FILES['doc_file']['name'][0], 'type' => $_FILES['doc_file']['type'][0], 'tmp_name' => $_FILES['doc_file']['tmp_name'][0], 'error' => $_FILES['doc_file']['error'][0], 'size' => $_FILES['doc_file']['size'][0]);
         } else {
             $files = array('name' => $_FILES['doc_file']['name'], 'type' => $_FILES['doc_file']['type'], 'tmp_name' => $_FILES['doc_file']['tmp_name'], 'error' => $_FILES['doc_file']['error'], 'size' => $_FILES['doc_file']['size']);
         }
     } else {
         $files = array('name' => null, 'type' => null, 'tmp_name' => null, 'error' => UPLOAD_ERR_NO_FILE, 'size' => null);
     }
     $request['doc_id'] = forceInteger($request['id'], 0, false, '.');
     $request['type'] = strtoupper($request['type']);
     // Foreign key
     $file_info = $this->getDocFileInfo($request['doc_id']);
     if ($this->act == 'mod') {
         // Rimuove il campo: Evita lo spostamento di oggetti da una tipologia ad un altra
         $this->removeField('doc_object_id');
     } else {
         if (in_array($request['type'], array('BUILDING', 'BUILDING_PHOTO', 'BUILDING_THERMOGRAPHY', 'BUILDING_LABEL'))) {
             // Check foreign key per edifici
             $this->setFieldAttrib('doc_object_id', array('lookup' => array('table' => 'building', 'field' => 'bu_id')));
         } else {
             if (in_array($request['type'], array('STREET_LIGHTING'))) {
                 // Check foreign key per illuminazione pubblica
                 $this->setFieldAttrib('doc_object_id', array('lookup' => array('table' => 'street_lighting', 'field' => 'sl_id')));
             } else {
                 if (in_array($request['type'], array('GLOBAL_ENTRY'))) {
                     // Check foreign key per illuminazione pubblica
                     $this->setFieldAttrib('doc_object_id', array('lookup' => array('table' => 'global_entry', 'field' => 'ge_id')));
                 } else {
                     if (in_array($request['type'], array('GLOBAL_PLAIN'))) {
                         // Check foreign key per illuminazione pubblica
                         $this->setFieldAttrib('doc_object_id', array('lookup' => array('table' => 'global_plain', 'field' => 'gp_id')));
                     }
                 }
             }
         }
     }
     if ($files['error'] == 0) {
         $request['doc_file'] = $files['name'];
     }
     if ($this->act != 'del') {
         if ($this->act == 'add') {
             $request['doct_id'] = R3EcoGisHelper::getDocumentTypeIdByCode($request['type']);
         } else {
             $request['doct_id'] = R3EcoGisHelper::getDocumentTypeByDocumentId($request['doc_id']);
         }
         $errors = $this->checkFormData($request);
     }
     if (count($errors) > 0) {
         return $this->getAjaxErrorResult($errors);
     } else {
         $db = ezcDbInstance::get();
         $db->beginTransaction();
         if ($files['error'] == 0) {
             if ($this->hasVirus($files['tmp_name']) === true) {
                 // Verifica la presenza di un virus nel file da caricare
                 return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataDocumentVirusError()");
             }
             if ($file_info !== false) {
                 //Remove the old file (Replacement)
                 $this->removeOldFile($file_info['doc_file'], 'document', '', $file_info['doc_file_id']);
             }
             $new_id = $this->getDocFileId($request['doc_id']);
             $request['doc_file_id'] = $new_id;
             $this->addFile($request['doc_file'], 'document', '', $request['doc_file_id'], $files['tmp_name']);
         } else {
             if ($this->act == 'del') {
                 $this->removeOldFile($file_info['doc_file'], 'document', '', $file_info['doc_file_id']);
             } else {
                 // Keey the old values
                 $request['doc_file'] = $file_info['doc_file'];
                 $request['doc_file_id'] = $file_info['doc_file_id'];
             }
         }
         $id = $this->applyData($request);
         $db->commit();
         R3EcoGisEventNotifier::notifyDataChanged($this, array('data_changed' => true));
         return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataDoneDocument({$id})");
     }
 }
Ejemplo n.º 10
0
 public function loadEmissionDataFrominventory($ge_id)
 {
     $db = ezcDbInstance::get();
     R3EcoGisHelper::includeHelperClass('obj.global_result_table.php');
     // Emissioni
     $data = R3EcoGisGlobalTableHelper::getCategoriesData($ge_id, 'EMISSION', 1);
     $result['emission']['total'] = $data['table_sum'];
     // Consumi
     $consumptionData = R3EcoGisGlobalTableHelper::getCategoriesData($ge_id, 'CONSUMPTION', 1);
     // Ricavo ID PAES Elettricità (dovrebbe essere 1 nei db standard)
     $sql = "SELECT ges_id\r\n                FROM global_energy_source ges\r\n                INNER JOIN global_energy_type get ON ges.get_id=get.get_id WHERE get_code='ELECTRICITY'";
     $electricityGesId = $db->query($sql)->fetchColumn();
     if (!isset($data['sum']['source'][$electricityGesId])) {
         $result['consumption']['electricity'] = null;
     } else {
         $result['consumption']['electricity'] = isset($consumptionData['sum']['source'][$electricityGesId]) ? $consumptionData['sum']['source'][$electricityGesId] : 0;
     }
     $result['consumption']['total'] = $consumptionData['sum']['total'];
     // Produzione
     $productionData = R3EcoGisGlobalTableHelper::getCategoriesData($ge_id, 'ENERGY_PRODUCTION', 1);
     $result['production']['electricity'] = $productionData['production_sum']['tot'];
     $result['production']['production_emission'] = $productionData['production_emission_sum']['tot'];
     // Energia verde
     $sql = "SELECT ge_green_electricity_purchase, ge_green_electricity_co2_factor\r\n                FROM global_entry\r\n                WHERE ge_id=?";
     $stmt = $db->prepare($sql);
     $stmt->execute(array($ge_id));
     $data = $stmt->fetch(PDO::FETCH_ASSOC);
     $result['green_energy']['consumption'] = $data['ge_green_electricity_purchase'];
     $result['green_energy']['factor'] = $data['ge_green_electricity_co2_factor'];
     $result['green_energy']['emission'] = $result['green_energy']['consumption'] * $result['green_energy']['factor'];
     // Energia rinnovabile
     $sql = "SELECT ges.ges_id, ges_name_1 AS ges_name\r\nFROM global_energy_source ges\r\nINNER JOIN global_energy_type get ON ges.get_id=get.get_id\r\nINNER JOIN global_energy_source_type gest ON ges.ges_id=gest.ges_id\r\nINNER JOIN global_type gt ON gt.gt_id=gest.gt_id\r\nWHERE get_code='RENEWABLE' AND gt_code='CONSUMPTION'\r\nORDER BY gest_order";
     $renewableConsumption = 0;
     foreach ($db->query($sql, PDO::FETCH_ASSOC) as $row) {
         $tot = 0;
         foreach ($consumptionData['data'] as $data) {
             if (isset($data['sum']['source'][$row['ges_id']])) {
                 $tot += $data['sum']['source'][$row['ges_id']];
             }
         }
         $gesIds[$row['ges_id']] = array('id' => $row['ges_id'], 'name' => $row['ges_name'], 'tot' => $tot);
         $renewableConsumption += $tot;
     }
     $result['green_energy']['production'] = $renewableConsumption;
     return $result;
 }
Ejemplo n.º 11
0
 /**
  * Return the UDM
  * @param array $request    the request
  * @return array            the result data
  */
 public function fetchUDM($request)
 {
     return array('status' => R3_AJAX_NO_ERROR, 'data' => R3EcoGisHelper::forceJSonArray(R3EcogisHelper::getEnergyUDMListByEnergySource($this->do_id, $request['kind'], $request['es_id'], array('constraints' => 'esu_allow_in_building IS TRUE'))));
 }
Ejemplo n.º 12
0
 /**
  * Return the data for a single customer 
  */
 public function getLookupData($id = null)
 {
     $lkp = array();
     if ($this->auth->getParam('mu_id') == '') {
         $lkp['pr_values'] = R3EcoGisHelper::getProvinceList($this->do_id);
         $lkp['mu_values'] = R3EcoGisHelper::getMunicipalityAndMunicipalityCollectionList($this->do_id);
     } else {
         $lkp['mu_values'] = array($this->auth->getParam('mu_id') => '');
     }
     $mu_id = $this->auth->getParam('mu_id');
     if ($this->act == 'add' && count($lkp['mu_values']) == 1) {
         $mu_id = key($lkp['mu_values']);
     } else {
         if ($this->act == 'mod') {
             $mu_id = $this->data['mu_id'];
         }
     }
     return $lkp;
 }
Ejemplo n.º 13
0
 /**
  * Return the data for a single customer
  */
 public function getLookupData($id = null)
 {
     $lang = R3Locale::getLanguageID();
     $db = ezcDbInstance::get();
     $lkp = array();
     $lkp['kind_values'] = array('HEATING' => _('Riscaldamento'), 'ELECTRICITY' => _('Elettrico'));
     $lkp['pr_list'] = R3EcoGisHelper::getProvinceList($this->do_id);
     $lkp['mu_list'] = R3EcoGisUtilityHelper::getAvailableMunicipalityList($this->do_id, $this->id);
     $lkp['mu_selected'] = $this->data['municipality'];
     $lkp['ges_values'] = R3EcoGisUtilityHelper::getGlobalEnergySourceList();
     return $lkp;
 }
Ejemplo n.º 14
0
 /**
  * Return the data for a single customer 
  */
 public function getLookupData($id = null)
 {
     $lkp = array();
     $lkp['do_values'] = R3EcoGisHelper::getDomainList();
     if (count($lkp['do_values']) == 1) {
         $lkp['mu_list'] = R3EcoGisMunicipalityCollectionHelper::getAvailableMunicipalityList(key($lkp['do_values']));
     }
     if ($this->act == 'mod') {
         $lkp['mu_selected'] = R3EcoGisMunicipalityCollectionHelper::getSelectedMunicipalityList($this->id);
     }
     return $lkp;
 }
Ejemplo n.º 15
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'));
         }
     }
 }
Ejemplo n.º 16
0
 public function getPageVars()
 {
     if ($this->act != 'list') {
         $mu_id = $this->auth->getParam('mu_id');
         if ($this->act == 'add') {
             $mu_values = R3EcoGisHelper::getMunicipalityList($this->do_id);
             if (count($mu_values) == 1) {
                 $mu_id = key($mu_values);
             }
         } else {
             if ($this->act == 'mod' || $this->act == 'show') {
                 $mu_id = $this->data['mu_id'];
             }
         }
         if ($mu_id > 0) {
             $autoSelectedActions = $this->select_done == 'T' && $this->data['actions']['ac_id_list'] != '';
             return array('catalog_html' => R3EcoGisSimulationHelper::getCatalogDataHTML($this->do_id, $mu_id, array('alternative_data_only' => $this->alternativeSimulation)), 'selected_html' => R3EcoGisSimulationHelper::getSelectedCatalogDataHTML($this->do_id, $mu_id), 'auto_selected_actions' => $autoSelectedActions);
         }
     }
     return array();
 }
Ejemplo n.º 17
0
 public function getGlobalAction($request)
 {
     return array('status' => R3_AJAX_NO_ERROR, 'data' => R3EcoGisHelper::forceJSonArray(R3EcoGisGlobalPlainHelper::getPlainActionList($_SESSION['do_id'], $request['gc_id'], array('allow_empty' => true))));
 }
Ejemplo n.º 18
0
 /**
  * Return the data for a single customer 
  */
 public function getData($id = null)
 {
     $lang = R3Locale::getLanguageID();
     $db = ezcDbInstance::get();
     $sql = "SELECT gc1.gc_id, gc2.gc_name_{$lang} AS gc_name_main, gc1.gc_name_{$lang} AS gc_name\r\n                FROM global_category gc1\r\n                INNER JOIN global_category gc2 ON gc1.gc_parent_id=gc2.gc_id\r\n                WHERE gc1.gc_id=" . (int) $this->id;
     $vlu = $db->query($sql)->fetch(PDO::FETCH_ASSOC);
     $gpac_id = $db->query("SELECT gpac_id FROM ecogis.global_plain_action_category WHERE gc_id={$this->id} ORDER BY gpac_id LIMIT 1")->fetchColumn();
     // Ricavo il primo record per determinare la data di modifica
     $vlu = array_merge($vlu, R3EcoGisHelper::getChangeLogData('global_plain_action_category', $gpac_id));
     return $vlu;
 }
Ejemplo n.º 19
0
 /**
  * Return the UDM
  * @param array $request    the request
  * @return array            the result data
  */
 public function confirmDeleteStreetLighting($request)
 {
     $db = ezcDbInstance::get();
     $lang = R3Locale::getLanguageID();
     $id = (int) $request['id'];
     $name = $db->query("SELECT sl_full_name_{$lang} AS sw_title FROM street_lighting_data WHERE sl_id={$id}")->fetchColumn();
     $hasEnergyMeter = R3EcoGisHelper::hasEnergyMeter('STREET_LIGHTING', $id);
     $hasDocument = R3EcoGisHelper::hasDocument('STREET_LIGHTING', $id);
     if (!$hasEnergyMeter && !$hasDocument && $this->tryDeleteData($id)) {
         return array('status' => R3_AJAX_NO_ERROR, 'confirm' => sprintf(_('Sei sicuro di voler cancellare il tratto "%s"?'), $name));
     }
     return array('status' => R3_AJAX_NO_ERROR, 'alert' => sprintf(_('Impossibile cancellare il tratto "%s", poichè vi sono dei dati ad esso associati'), $name));
 }
Ejemplo n.º 20
0
 public function getData()
 {
     $lang = R3Locale::getLanguageID();
     $db = ezcDbInstance::get();
     $id = $this->id;
     $vlu = array();
     if ($this->act != 'add') {
         $id = (int) $this->id;
         try {
             $this->checkLookupDomainSecurity($id, $this->act);
         } catch (Exception $e) {
             die('Security error');
         }
         $pkName = $this->getPrimaryKeyName();
         $q = "SELECT * FROM {$this->table} WHERE {$pkName}={$id}";
         $vlu = $db->query($q)->fetch(PDO::FETCH_ASSOC);
         $vlu = array_merge($vlu, R3EcoGisHelper::getChangeLogData($this->table, $id));
     } else {
         $vlu = array();
         foreach ($this->fields as $key => $field) {
             if (isset($field['name'])) {
                 $key = $field['name'];
             }
             if (isset($field['default'])) {
                 $vlu[$key] = $field['default'];
             }
         }
     }
     $this->data = $vlu;
     // Save the data (prevent multiple sql)
     return $vlu;
 }
Ejemplo n.º 21
0
 /**
  * Generate the preview map
  */
 static function generateMapPreview($layer, $key, $lang, $tollerance = '10%')
 {
     require_once R3_LIB_DIR . 'maplib.php';
     require_once R3_LIB_DIR . 'custom.map.php';
     global $languages;
     ezcLog::getInstance()->log(__METHOD__ . "({$layer}, {$key}, {$lang}, {$tollerance}) called", ezcLog::DEBUG);
     $db = ezcDbInstance::get();
     $auth = R3AuthInstance::get();
     list($width, $height) = explode('x', $auth->getConfigValue('APPLICATION', 'MAP_PREVIEW_SIZE', '200x200'));
     $cus_schema = R3EcoGisHelper::getGeoSchema();
     $domain_name = strtolower(R3EcoGisHelper::getDomainCodeFromID($_SESSION['do_id']));
     $mapfileDir = R3_CONFIG_DIR . $domain_name . '/map/';
     $mapPrev = new mapPreview($mapfileDir, $languages[$lang], $width, $height);
     if (function_exists('custom_map_edit_map_file')) {
         custom_map_edit_map_file($mapPrev->map);
     }
     switch ($layer) {
         case 'building':
             $opt = $auth->getConfigValue('APPLICATION', 'BUILDING_TABLE');
             $options['outlinecolor'] = isset($opt['outlinecolor']) ? $opt['outlinecolor'] : array();
             $sql = "SELECT ST_Extent(the_geom) FROM building WHERE bu_id=" . (int) $key;
             $mapPrev->highlight('ecogis_building_outline_selected', "the_geom FROM (SELECT * FROM {$cus_schema}.building WHERE bu_id=" . (int) $key . ") AS foo USING UNIQUE bu_id ", $options);
             break;
         case 'edit_building':
             // Edit building
             $opt = $auth->getConfigValue('APPLICATION', 'BUILDING_TABLE');
             $options['outlinecolor'] = isset($opt['outlinecolor']) ? $opt['outlinecolor'] : array();
             $sql = "SELECT ST_Extent(the_geom) FROM edit_tmp_polygon WHERE session_id=" . $db->quote($key);
             $mapPrev->highlight('ecogis_building_outline_selected', "the_geom FROM (SELECT gid AS bu_id, the_geom FROM ecogis.edit_tmp_polygon WHERE session_id=" . $db->quote($key) . ") AS foo USING UNIQUE bu_id ", $options);
             break;
         case 'street_lighting':
             $opt = $auth->getConfigValue('APPLICATION', 'STREET_LIGHTING_TABLE');
             $options['outlinecolor'] = isset($opt['outlinecolor']) ? $opt['outlinecolor'] : array();
             $sql = "SELECT ST_Extent(the_geom) FROM street_lighting WHERE sl_id=" . (int) $key;
             $mapPrev->highlight('ecogis_street_lighting_outline_selected', "the_geom FROM (SELECT * FROM {$cus_schema}.street_lighting WHERE sl_id=" . (int) $key . ") AS foo USING UNIQUE sl_id ", $options);
             break;
         case 'edit_street_lighting':
             $opt = $auth->getConfigValue('APPLICATION', 'BUILDING_TABLE');
             $options['outlinecolor'] = isset($opt['outlinecolor']) ? $opt['outlinecolor'] : array();
             $sql = "SELECT ST_Extent(the_geom) FROM edit_tmp_polygon WHERE session_id=" . $db->quote($key);
             $mapPrev->highlight('ecogis_street_lighting_outline_selected', "the_geom FROM (SELECT gid AS sl_id, the_geom FROM ecogis.edit_tmp_polygon WHERE session_id=" . $db->quote($key) . ") AS foo USING UNIQUE sl_id ", $options);
             break;
         default:
             $this->deliverError(sprintf(_("Il layer \"{$this->layer}\" non e' valido")));
             die;
     }
     $the_geom = $db->query($sql)->fetchColumn(0);
     if ($the_geom != '') {
         $extentArr = array();
         $extentArr = ST_FetchBox($the_geom);
         $extentArr['geox1'] = $extentArr[0];
         $extentArr['geoy1'] = $extentArr[1];
         $extentArr['geox2'] = $extentArr[2];
         $extentArr['geoy2'] = $extentArr[3];
         $deltaX = $deltaY = $tollerance;
         $layer = @$mapPrev->map->getLayerByName('comuni_overlay');
         if ($layer) {
             $class0 = @$layer->getClass(0);
             if ($class0) {
                 $class0->setExpression("('[istat]' != '" . $vlu['mu_id'] . "')");
             }
         }
         $PrevFile = $mapPrev->getMapImgByBox($extentArr['geox1'], $extentArr['geoy1'], $extentArr['geox2'], $extentArr['geoy2'], max($deltaX, $deltaY));
         return $PrevFile;
     }
     return null;
 }
Ejemplo n.º 22
0
 public function askDelGlobalPlain($request)
 {
     $db = ezcDbInstance::get();
     $id = (int) @$request['id'];
     R3Security::checkGlobalPlain($id);
     $lang = R3Locale::getLanguageID();
     $name = $db->query("SELECT gp_name_{$lang} AS gp_name FROM global_plain_data WHERE gp_id=" . (int) $request['id'])->fetchColumn();
     if (R3EcoGisHelper::hasGlobalPlainRowHasGauge($id)) {
         return array('status' => R3_AJAX_NO_ERROR, 'alert' => _("Impossibile cancellare questo piano d'azione, poichè vi sono definiti degli indicatori ad esso legati"));
     }
     if (R3EcoGisHelper::hasDocument('GLOBAL_PLAIN', $id)) {
         return array('status' => R3_AJAX_NO_ERROR, 'alert' => _("Impossibile cancellare questo piano d'azione, poichè vi sono dei documenti ad esso legati"));
     }
     return array('status' => R3_AJAX_NO_ERROR, 'confirm' => sprintf(_("Sei sicuro di voler cancellare il piano di azione \"%s\"?"), $name));
 }
Ejemplo n.º 23
0
 /**
  * Ajax request to submit data
  * @param array $request   the request
  * @return array           ajax format status
  */
 public function submitFormData($request)
 {
     $db = ezcDbInstance::get();
     if ($this->act == 'del') {
         $id = (int) $request['id'];
         $mu_id = $db->query("SELECT mu_id\r\n                                 FROM ecogis.document_data doc\r\n                                 INNER JOIN ecogis.municipality mu ON doc.doc_object_id=mu_id AND doct_code='SEAP'\r\n                                 WHERE do_id={$this->do_id} AND doc_id={$id}")->fetchColumn();
         $db->beginTransaction();
         $this->deleteImportedData($mu_id);
         // Delete document
         $file_info = $this->getDocFileInfo($id);
         $this->removeOldFile($file_info['doc_file'], 'import_seap', '', $file_info['doc_file_id']);
         $request['doc_id'] = $id;
         $id = $this->applyData($request);
         $db->commit();
         die;
     }
     $files = R3EcoGisHelper::getUploadedFile('doc_file');
     $errors = array();
     if ($files['error'] != 0) {
         if ($files['error'] == UPLOAD_ERR_NO_FILE) {
             $errors['doc_file'] = array('CUSTOM_ERROR' => _('Bisogna indicare il file da caricare'));
         } else {
             $errors['doc_file'] = array('CUSTOM_ERROR' => _("Si è veificato un errore durante il caricamento del file. Si prega di riprovare. Errore #") . $files['error']);
         }
     }
     $mu_id = $this->auth->getParam('mu_id') != '' ? $this->auth->getParam('mu_id') : (int) $this->mu_id;
     $istat = $db->query("SELECT mu_istat FROM ecogis.municipality WHERE do_id={$this->do_id} AND mu_id={$mu_id}")->fetchColumn();
     if ($istat == '') {
         $errors['mu_id'] = array('CUSTOM_ERROR' => _("Indicare il comune per cui si intende importare i dati"));
     }
     if (count($errors) > 0) {
         return $this->getAjaxErrorResult($errors);
     }
     $db->beginTransaction();
     $result = $this->importDataFromTemplate($files['tmp_name'], $istat);
     if (!$result['done']) {
         $errors['doc_file'] = array('CUSTOM_ERROR' => $result['log']);
         return $this->getAjaxErrorResult($errors);
     }
     // Insert into document
     // Remove old document
     $doc_id = $db->query("SELECT doc_id\r\n                              FROM ecogis.document_data doc\r\n                              INNER JOIN ecogis.municipality mu ON mu_id=doc_object_id\r\n                              WHERE doct_code='SEAP' AND do_id={$this->do_id} AND doc_object_id={$mu_id}")->fetchColumn();
     if ($doc_id != '') {
         $file_info = $this->getDocFileInfo($doc_id);
         $this->removeOldFile($file_info['doc_file'], 'import_seap', '', $file_info['doc_file_id']);
         $db->exec("DELETE FROM ecogis.document WHERE doc_id={$doc_id}");
     }
     $request['doc_title_1'] = _('Import PAES');
     $request['doc_descr_1'] = json_encode($result['log']);
     $request['doc_object_id'] = $mu_id;
     $request['doc_file'] = $files['name'];
     $request['doc_file_id'] = $this->getDocFileId();
     $request['doct_id'] = R3EcoGisHelper::getDocumentTypeIdByCode('SEAP');
     $request['doc_date'] = date('Y-m-d');
     $this->addFile($request['doc_file'], 'import_seap', '', $request['doc_file_id'], $files['tmp_name']);
     $id = $this->applyData($request);
     $db->commit();
     R3EcoGisEventNotifier::notifyDataChanged($this, array('data_changed' => true));
     return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataDoneImportSeap({$id})");
 }
Ejemplo n.º 24
0
 /**
  * Set the mu_id for the user from auth, installation, mu_id & mu_name
  * @param type $request 
  */
 public function setMunicipalityForUser(&$request)
 {
     if ($this->auth->getParam('mu_id') != '') {
         $request['mu_id'] = $this->auth->getParam('mu_id');
         return true;
     }
     $muList = R3EcoGisHelper::getMunicipalityList($this->do_id);
     if (count($muList) == 1) {
         $request['mu_id'] = key($muList);
         return true;
     }
     if (isset($request['mu_name'])) {
         $request['mu_id'] = R3EcoGisHelper::getMunicipalityIdByName($this->do_id, $request['mu_name'], $this->auth->getParam('mu_id'));
         return true;
     }
     // User has more municipality
     return false;
 }
Ejemplo n.º 25
0
 public function loadGE_GS($request)
 {
     $db = ezcDbInstance::get();
     $lang = R3Locale::getLanguageID();
     if (isset($request['mu_name'])) {
         $request['mu_id'] = R3EcoGisHelper::getMunicipalityIdByName($this->do_id, $request['mu_name'], $this->auth->getParam('mu_id'));
     }
     $data = R3EcoGisGlobalStrategyHelper::getGlobalData($_SESSION['do_id'], $request['mu_id'], array('allow_empty' => true));
     return array('status' => 0, 'data' => array('mu_id_selected' => (int) $request['mu_id'], 'ge_id' => array('options' => $data['ge_values']), 'ge_id_2' => array('options' => $data['ge_values']), 'gp_id' => array('options' => $data['gp_values']), 'info_text' => $data['info_text']));
 }
Ejemplo n.º 26
0
 private static function getCategoriesDataMunicipality($ge_id, $kind, $divider, $returnAsLocale, $gc_id)
 {
     $db = ezcDbInstance::get();
     $lang = R3Locale::getLanguageID();
     $ge_id = (int) $ge_id;
     $decimals = $divider == 1 ? 0 : 1;
     $em_is_production = $kind == 'ENERGY_PRODUCTION' || $kind == 'HEATH_PRODUCTION' ? 'T' : 'F';
     $sql = "SELECT mu_id, ge_year, ge_national_efe, ge_local_efe FROM global_entry WHERE ge_id={$ge_id}";
     list($mu_id, $year, $nationalEFE, $localEFE) = $db->query($sql)->fetch(PDO::FETCH_NUM);
     $mu_id = (int) $mu_id;
     $year = (int) $year;
     // EFE migliore: Locale inventario, nazionale inventario, locale globale, nazionale
     if ($localEFE != '') {
         $efe = $localEFE;
     } else {
         if ($nationalEFE != '') {
             $efe = $nationalEFE;
         } else {
             $efe = R3EcoGisHelper::getElectricityCO2Factor($_SESSION['do_id'], $mu_id);
         }
     }
     $sql = "SELECT gest_id, get.get_id, BOOL2TEXT(get_show_label) AS get_show_label, get_name_{$lang} AS get_name, ges.ges_id, ges_name_{$lang} AS ges_name\r\n                FROM ecogis.global_type gt\r\n                INNER JOIN ecogis.global_energy_source_type gest ON gt.gt_id=gest.gt_id\r\n                INNER JOIN ecogis.global_energy_source ges ON gest.ges_id=ges.ges_id\r\n                INNER JOIN ecogis.global_energy_type get ON get.get_id=ges.get_id\r\n                WHERE gt_code='{$kind}'\r\n                ORDER BY gest_order, get_order, ges_order";
     $parameters = array();
     $globalSumSourceDefault = array();
     foreach ($db->query($sql, PDO::FETCH_ASSOC) as $row) {
         $parameters[$row['ges_id']] = $row;
         $globalSumSourceDefault[$row['ges_id']] = null;
     }
     $sql = "SELECT gc1.gc_id AS main_id, gc1.gc_code AS main_code, gc1.gc_name_{$lang} AS main_name, gc1.gc_show_label AS main_show_label,\r\n                       gc2.gc_id AS gc_id, gc2.gc_code AS gc_code, gc2.gc_name_{$lang} AS gc_name, gc2.gc_total_only\r\n                FROM global_category gc1\r\n                INNER JOIN global_category gc2 ON gc2.gc_parent_id=gc1.gc_id\r\n                INNER JOIN ecogis.global_category_type gcat ON gc2.gc_id=gcat.gc_id\r\n                INNER JOIN global_type gt ON gt.gt_id=gcat.gt_id\r\n                WHERE gt_code='{$kind}' ";
     if ($gc_id !== null) {
         $gc_id = (int) $gc_id;
         $sql .= " AND gc2.gc_id={$gc_id} ";
     }
     $sql .= "ORDER BY gc1.gc_order, gc1.gc_name_{$lang}, gc1.gc_id, gcat_order, gc2.gc_order, gc2.gc_name_{$lang}, gc2.gc_id";
     $categories = array();
     foreach ($db->query($sql, PDO::FETCH_ASSOC) as $row) {
         $categories[$row['gc_id']] = $row;
     }
     $fieldName = $kind == 'EMISSION' ? 'co_value_co2' : 'co_value_kwh';
     $data = array();
     $buildingProduction = array();
     //Ricavo dati inseriti da form (non edifici e non illuminazione) e i totali
     $sql = "SELECT 'GLOBAL' AS kind, ge_id, gs_id, gs_name_{$lang} AS gs_name, gc_id, ges_id, co_value_kwh, co_value_co2, NULL AS gs_tot_value, the_geom IS NOT NULL AS has_geometry\r\n                FROM ecogis.consumption_year_global\r\n                WHERE mu_id={$mu_id} AND ge_id={$ge_id} AND ge_year={$year}\r\n\r\n                UNION\r\n\r\n                SELECT 'GLOBAL' AS kind, ge_id, gs_id, gs_name_{$lang} AS gs_name, gc.gc_id, NULL AS ges_id, NULL AS co_value_kwh, NULL AS co_value_co2, gs_tot_value, the_geom IS NOT NULL AS has_geometry\r\n                FROM ecogis.global_subcategory gs\r\n                INNER JOIN ecogis.global_category gc ON gs.gc_id=gc.gc_id\r\n                WHERE ge_id={$ge_id} \r\n\r\n                ORDER BY gs_name";
     foreach ($db->query($sql, PDO::FETCH_ASSOC) as $row) {
         $gcIdList[$row['gc_id']] = $row['gc_id'];
         $data[$row['gc_id']][$row['gs_id']]['header'] = array('kind' => $row['kind'], 'id' => $row['gs_id'], 'name' => $row['gs_name'], 'sum' => R3EcoGisGlobalTableHelper::applyDivider($row['gs_tot_value'], $divider), 'co2_sum' => null, 'has_geometry' => $row['has_geometry']);
         if ($row['ges_id'] != '') {
             if ($kind == 'EMISSION' && self::getEnergyTypeBySourceId($row['ges_id']) == 'ELECTRICITY') {
                 $data[$row['gc_id']][$row['gs_id']]['data'][$row['ges_id']] = R3EcoGisGlobalTableHelper::applyDivider($efe * $row['co_value_kwh'], $divider);
             } else {
                 $data[$row['gc_id']][$row['gs_id']]['data'][$row['ges_id']] = R3EcoGisGlobalTableHelper::applyDivider($row[$fieldName], $divider);
             }
             $data[$row['gc_id']][$row['gs_id']]['co2_value'][$row['ges_id']] = $row['co_value_co2'];
         }
     }
     // Ricavo dati edifici
     $sql = "SELECT 'BUILDING' AS kind, 10000000+bu_id as bu_id, bu_name_{$lang} AS bu_name, gc_id, ges_id, co_value_kwh, co_value_co2, the_geom IS NOT NULL AS has_geometry\r\n                FROM consumption_year_building \r\n                WHERE mu_id={$mu_id} AND co_year={$year} AND ges_id IS NOT NULL AND em_is_production='{$em_is_production}'\r\n                ORDER BY bu_name";
     foreach ($db->query($sql, PDO::FETCH_ASSOC) as $row) {
         if ($em_is_production) {
             $buildingProduction[$row['gc_id']][$row['bu_id']] = $row['co_value_kwh'];
         }
         $data[$row['gc_id']][$row['bu_id']]['header'] = array('kind' => $row['kind'], 'id' => $row['bu_id'], 'name' => $row['bu_name'], 'sum' => null, 'co2_sum' => null, 'has_geometry' => $row['has_geometry']);
         if ($kind == 'EMISSION' && $row['co_value_co2'] > 0 && self::getEnergyTypeBySourceId($row['ges_id']) == 'ELECTRICITY') {
             // Applico efe locale o nazionale se presenti nell'inventario
             $data[$row['gc_id']][$row['bu_id']]['data'][$row['ges_id']] = R3EcoGisGlobalTableHelper::applyDivider($efe * $row['co_value_kwh'], $divider);
         } else {
             $data[$row['gc_id']][$row['bu_id']]['data'][$row['ges_id']] = R3EcoGisGlobalTableHelper::applyDivider($row[$fieldName], $divider);
         }
     }
     //Ricavo dati illuminazione pubblica
     $sql = "SELECT 'STREET_LIGHTING' AS kind, 11000000+sl_id as sl_id, sl_full_name_{$lang} AS sl_name, gc_id, ges_id, co_value_kwh, co_value_co2, the_geom IS NOT NULL AS has_geometry\r\n                FROM consumption_year_street_lighting\r\n                WHERE mu_id={$mu_id} AND co_year={$year} AND ges_id IS NOT NULL AND em_is_production='{$em_is_production}'\r\n                ORDER BY sl_name";
     foreach ($db->query($sql, PDO::FETCH_ASSOC) as $row) {
         $data[$row['gc_id']][$row['sl_id']]['header'] = array('kind' => $row['kind'], 'id' => $row['sl_id'], 'name' => $row['sl_name'], 'sum' => null, 'co2_sum' => null, 'has_geometry' => $row['has_geometry']);
         if ($kind == 'EMISSION' && self::getEnergyTypeBySourceId($row['ges_id']) == 'ELECTRICITY') {
             $data[$row['gc_id']][$row['sl_id']]['data'][$row['ges_id']] = R3EcoGisGlobalTableHelper::applyDivider($efe * $row['co_value_kwh'], $divider);
         } else {
             $data[$row['gc_id']][$row['sl_id']]['data'][$row['ges_id']] = R3EcoGisGlobalTableHelper::applyDivider($row[$fieldName], $divider);
         }
     }
     // Ricavo i dati aggiuntivi per produzione elettricità e calore/freddo (Nel db i valori sono in kWH)
     $sql = "SELECT gs.gc_id, gs_id, gs_tot_production_value, gs_tot_emission_value, gs_tot_emission_factor\r\n                FROM global_subcategory gs\r\n                INNER JOIN global_category gc on gs.gc_id=gc.gc_id\r\n                INNER JOIN global_category_type gcat on gc.gc_id=gcat.gc_id\r\n                INNER JOIN global_type gt on gt.gt_id=gcat.gt_id\r\n                WHERE gt_code='{$kind}' AND ge_id={$ge_id} AND gs_tot_production_value IS NOT NULL";
     $productionData = array();
     $productionSum = array();
     $productionEmissionSum = array();
     $productionEmissionSumFactor = array();
     // Imposto array (serve per export)
     foreach ($categories as $gc_id => $dummy) {
         $productionSum['category'][$gc_id] = null;
         $productionEmissionSum['category'][$gc_id] = null;
     }
     // Add building production data
     $productionTot = 0;
     $productionEmissionTot = 0;
     foreach ($buildingProduction as $gc_id => $buildingProductionData) {
         foreach ($buildingProductionData as $bu_id => $val) {
             $val = R3EcoGisGlobalTableHelper::applyDivider($val, $divider);
             if (isset($categories[$gc_id])) {
                 $productionData[$gc_id][$bu_id]['production'] = $returnAsLocale ? R3NumberFormat($val, $decimals, true) : $val;
                 if (!isset($productionSum['category'][$gc_id])) {
                     $productionSum['category'][$gc_id] = 0;
                     $productionEmissionSum['category'][$gc_id] = 0;
                 }
                 $productionSum['category'][$gc_id] += $val;
                 $productionTot += $val;
             }
         }
     }
     $canSumFactor = array();
     foreach ($db->query($sql, PDO::FETCH_ASSOC) as $row) {
         $val = R3EcoGisGlobalTableHelper::applyDivider($row['gs_tot_production_value'], $divider);
         $emissionVal = R3EcoGisGlobalTableHelper::applyDivider($row['gs_tot_emission_value'], $divider);
         $emissionFactorVal = R3EcoGisGlobalTableHelper::applyDivider($row['gs_tot_emission_factor'], $divider);
         $productionData[$row['gc_id']][$row['gs_id']]['production'] = $returnAsLocale ? R3NumberFormat($val, $decimals, true) : $val;
         $productionData[$row['gc_id']][$row['gs_id']]['production_emission'] = $returnAsLocale ? R3NumberFormat($emissionVal, $decimals, true) : $emissionVal;
         $productionData[$row['gc_id']][$row['gs_id']]['production_emission_factor'] = $returnAsLocale ? R3NumberFormat($emissionFactorVal, $decimals, true) : $emissionFactorVal;
         if (!isset($productionSum['category'][$row['gc_id']])) {
             $productionSum['category'][$row['gc_id']] = 0;
             $productionEmissionSum['category'][$row['gc_id']] = 0;
         }
         $productionSum['category'][$row['gc_id']] += $val;
         $productionEmissionSum['category'][$row['gc_id']] += $emissionVal;
         // Solo se ho un singolo entry posso sommare i fattori di conversione
         if (!isset($canSumFactor[$row['gc_id']])) {
             $canSumFactor[$row['gc_id']] = $emissionVal;
             $productionEmissionSumFactor['category'][$row['gc_id']] = $emissionFactorVal;
         } else {
             $productionEmissionSumFactor['category'][$row['gc_id']] = 'N/A';
         }
         $productionTot += $val;
         $productionEmissionTot += $emissionVal;
     }
     $productionSum['tot'] = $returnAsLocale ? R3NumberFormat($productionTot, $decimals, true) : $productionTot;
     $productionEmissionSum['tot'] = $returnAsLocale ? R3NumberFormat($productionEmissionTot, $decimals, true) : $productionEmissionTot;
     if (isset($productionSum['category']) && $returnAsLocale) {
         foreach ($productionSum['category'] as $key => $val) {
             $productionSum['category'][$key] = R3NumberFormat($val, $decimals, true);
         }
         foreach ($productionEmissionSum['category'] as $key => $val) {
             $productionEmissionSum['category'][$key] = R3NumberFormat($val, $decimals, true);
         }
     }
     // Generazione tabella
     $result = array();
     foreach ($categories as $gc_id => $cat) {
         $result[$cat['main_id']]['code'] = $cat['main_code'];
         $result[$cat['main_id']]['name'] = $cat['main_name'];
         $result[$cat['main_id']]['sub_total'] = 'T';
         $result[$cat['main_id']]['sub_total_label'] = _('Totale parziale') . ' ' . mb_strtolower($cat['main_name'], 'UTF-8');
         $result[$cat['main_id']]['show_label'] = $cat['main_show_label'] ? 'T' : 'F';
         $result[$cat['main_id']]['options']['xls_style'] = 'category-header';
         $result[$cat['main_id']]['options']['xls_style_sub_total_header'] = 'subtotal-header';
         $result[$cat['main_id']]['options']['xls_style_sub_total_data'] = 'subtotal-data';
         $result[$cat['main_id']]['options']['xls_style_sub_total_data_sum'] = 'subtotal-data-sum';
         $result[$cat['main_id']]['options']['xls_style_category'] = 'category';
         $result[$cat['main_id']]['options']['xls_style_category_data'] = 'category-data';
         $result[$cat['main_id']]['options']['xls_style_category_sum'] = 'category-sum';
         $result[$cat['main_id']]['sum'] = array();
         $result[$cat['main_id']]['categories'][$cat['gc_id']]['header'] = array('id' => $cat['gc_id'], 'code' => $cat['gc_code'], 'name' => $cat['gc_name'], 'total_only' => $cat['gc_total_only'] ? 'T' : 'F', 'sum' => '', 'method' => self::getGlobalMethod($ge_id, $cat['gc_id']));
         if (isset($data[$gc_id])) {
             $row = array();
             $sum = array();
             foreach ($parameters as $ges_id => $dummy) {
                 $sum[$ges_id] = '';
             }
             foreach ($data[$gc_id] as $id => $data2) {
                 $row[$id]['header'] = $data2['header'];
                 $row[$id]['header']['sum'] = '';
                 foreach ($parameters as $ges_id => $param) {
                     if (isset($data2['data'][$ges_id])) {
                         $row[$id]['data'][$ges_id] = $data2['data'][$ges_id];
                         if (isset($data2['co2_value'][$ges_id])) {
                             $row[$id]['co2_value'][$ges_id] = $data2['co2_value'][$ges_id];
                         } else {
                             $row[$id]['co2_value'][$ges_id] = 0;
                         }
                         $row[$id]['header']['sum'] += $data2['data'][$ges_id];
                         $sum[$ges_id] += $data2['data'][$ges_id];
                         $result[$cat['main_id']]['categories'][$cat['gc_id']]['header']['sum'] += $data2['data'][$ges_id];
                     } else {
                         $row[$id]['data'][$ges_id] = '';
                     }
                 }
                 if ($data2['header']['sum'] != '') {
                     $row[$id]['header']['sum'] = $data2['header']['sum'] == '' ? '' : $data2['header']['sum'];
                     $result[$cat['main_id']]['categories'][$cat['gc_id']]['header']['sum'] += $data2['header']['sum'];
                 }
             }
             // Check sum
             $result[$cat['main_id']]['categories'][$cat['gc_id']]['sum'] = $sum;
             $result[$cat['main_id']]['categories'][$cat['gc_id']]['sub_categories'] = $row;
         } else {
             $sum = array();
             foreach ($parameters as $ges_id => $dummy) {
                 $sum[$ges_id] = '';
             }
             $result[$cat['main_id']]['categories'][$cat['gc_id']]['sum'] = $sum;
         }
     }
     $tableSum = self::getTableSum($result);
     // Formatto numeri
     $mainCategorySum = array();
     $globalSum = array('label' => _('Totale'), 'total' => null, 'source' => $globalSumSourceDefault);
     foreach ($result as $key1 => $val1) {
         $mainCategorySum[$key1]['total'] = null;
         foreach ($val1['categories'] as $key2 => $val2) {
             // Totale di categoria
             $mainCategorySum[$key1]['total'] += $result[$key1]['categories'][$key2]['header']['sum'];
             // totale
             $globalSum['total'] += $result[$key1]['categories'][$key2]['header']['sum'];
             // totale
             $result[$key1]['categories'][$key2]['header']['sum'] = $returnAsLocale ? R3NumberFormat($result[$key1]['categories'][$key2]['header']['sum'], $decimals, true) : $result[$key1]['categories'][$key2]['header']['sum'];
             foreach ($val2['sum'] as $key3 => $val3) {
                 // Totale parziale categoria
                 $result[$key1]['categories'][$key2]['sum'][$key3] = $returnAsLocale ? R3NumberFormat($result[$key1]['categories'][$key2]['sum'][$key3], $decimals, true) : $result[$key1]['categories'][$key2]['sum'][$key3];
             }
             if (isset($val2['sub_categories'])) {
                 foreach ($val2['sub_categories'] as $key3 => $val3) {
                     // Totale sottocategoria
                     $result[$key1]['categories'][$key2]['sub_categories'][$key3]['header']['sum'] = $returnAsLocale ? R3NumberFormat($result[$key1]['categories'][$key2]['sub_categories'][$key3]['header']['sum'], $decimals, true) : $result[$key1]['categories'][$key2]['sub_categories'][$key3]['header']['sum'];
                     foreach ($val3['data'] as $key4 => $val4) {
                         if (!isset($mainCategorySum[$key1]['source'][$key4])) {
                             $mainCategorySum[$key1]['source'][$key4] = null;
                         }
                         if (!isset($globalSum['source'][$key4])) {
                             $globalSum['source'][$key4] = null;
                         }
                         if ($result[$key1]['categories'][$key2]['sub_categories'][$key3]['data'][$key4] != null) {
                             $mainCategorySum[$key1]['source'][$key4] += $result[$key1]['categories'][$key2]['sub_categories'][$key3]['data'][$key4];
                             $globalSum['source'][$key4] += $result[$key1]['categories'][$key2]['sub_categories'][$key3]['data'][$key4];
                         }
                         // Dato
                         $result[$key1]['categories'][$key2]['sub_categories'][$key3]['data'][$key4] = $returnAsLocale ? R3NumberFormat($result[$key1]['categories'][$key2]['sub_categories'][$key3]['data'][$key4], $decimals, true) : $result[$key1]['categories'][$key2]['sub_categories'][$key3]['data'][$key4];
                     }
                 }
             }
         }
         $result[$key1]['sum'] = $mainCategorySum[$key1];
     }
     if ($returnAsLocale) {
         // Conversione in locale
         foreach ($result as $key => $val) {
             $result[$key]['sum']['total'] = R3NumberFormat($result[$key]['sum']['total'], $decimals, true);
             if (isset($val['sum']['source'])) {
                 foreach ($val['sum']['source'] as $key2 => $val2) {
                     $result[$key]['sum']['source'][$key2] = R3NumberFormat($val2, $decimals, true);
                 }
             }
         }
         $globalSum['total'] = R3NumberFormat($globalSum['total'], $decimals, true);
         if (isset($globalSum['source'])) {
             foreach ($globalSum['source'] as $key => $val) {
                 $globalSum['source'][$key] = R3NumberFormat($val, $decimals, true);
             }
         }
     }
     return array('data' => $result, 'table_sum' => $tableSum, 'sum' => $globalSum, 'production_data' => $productionData, 'production_sum' => $productionSum, 'production_emission_sum' => $productionEmissionSum, 'production_emission_sum_factor' => $productionEmissionSumFactor);
 }
Ejemplo n.º 27
0
 public function getLookupData($id = null)
 {
     $lkp = parent::getLookupData($id);
     if ($this->auth->getParam('mu_id') == '') {
         $lkp['pr_values'] = R3EcoGisHelper::getProvinceList($this->do_id);
         $lkp['mu_values'] = R3EcoGisHelper::getMunicipalityAndMunicipalityCollectionList($this->do_id, null, null, array('join_with_global_strategy_paes' => true));
     } else {
         $lkp['mu_values'] = array($this->auth->getParam('mu_id') => '');
     }
     $mu_id = $this->auth->getParam('mu_id');
     if ($this->act == 'add' && count($lkp['mu_values']) == 1) {
         $mu_id = key($lkp['mu_values']);
     } else {
         if ($this->act == 'mod') {
             $mu_id = $this->data['mu_id'];
         }
     }
     $lkp['gpa_gauge_values'] = R3EcoGisHelper::getGlobalPlainActionTypeList($_SESSION['do_id']);
     return $lkp;
 }
 /**
  * Return the data for a single customer 
  */
 public function getData($id = null)
 {
     $lang = R3Locale::getLanguageID();
     $db = ezcDbInstance::get();
     if ($this->act == 'add') {
         $vlu = array();
         $vlu['gt_id'] = null;
     } else {
         $sql = "SELECT *\r\n                    FROM global_type\r\n                    WHERE gt_id=" . $this->id;
         $vlu = $db->query($sql)->fetch(PDO::FETCH_ASSOC);
         $vlu = array_merge($vlu, R3EcoGisHelper::getChangeLogData('global_type', $vlu['gt_id']));
     }
     $this->data = $vlu;
     // Save the data (prevent multiple sql)
     return $vlu;
 }
Ejemplo n.º 29
0
 public function askDelBuilding($request)
 {
     $db = ezcDbInstance::get();
     $lang = R3Locale::getLanguageID();
     $id = forceInteger($request['id'], 0, false, '.');
     $name = $db->query("SELECT bu_name_{$lang} FROM building WHERE bu_id={$id}")->fetchColumn();
     $hasEnergyMeter = R3EcoGisHelper::hasEnergyMeter('BUILDING', $id);
     $hasDocument = R3EcoGisHelper::hasDocument('BUILDING', $id);
     if (!$hasEnergyMeter && !$hasDocument && $this->tryDeleteData($id)) {
         return array('status' => R3_AJAX_NO_ERROR, 'confirm' => sprintf(_("Sei sicuro di voler cancellare l'edificio \"%s\"?"), $name));
     } else {
         return array('status' => R3_AJAX_NO_ERROR, 'alert' => _('Impossibile cancellare questo edificio poichè vi sono dei dati ad esso legati'));
     }
 }
Ejemplo n.º 30
0
 /**
  * Ajax request to submit data
  * @param array $request   the request
  * @return array           ajax format status
  */
 public function submitFormData($request)
 {
     $this->defFields();
     // Definisce i campi in base al parametro kind
     $request = $this->translateFields($request);
     // Converte i nomi generici della richiesta in nomi specifici (fr, st_cm)
     if (!R3EcoGisHelper::isValidMunicipality($request['mu_id'])) {
         die("INVALID MUNICIPALITY [{$request['mu_id']}]");
     }
     // Security trap
     $errors = $this->checkFormData($request);
     for ($langId = 1; $langId <= R3AuthInstance::get()->getConfigValue('APPLICATION', 'NUM_LANGUAGES', 1); $langId++) {
         if ($this->objectExistsByName($langId, $request['mu_id'], $request["{$this->prefix}_name_{$langId}"])) {
             $errors["popup_name_{$langId}"] = array('CUSTOM_ERROR' => sprintf(_("{$this->lookupName} con nome \"%s\" esiste già"), $request["{$this->prefix}_name_{$langId}"]));
         }
     }
     if (count($errors) > 0) {
         return $this->getAjaxErrorResult($errors);
     } else {
         $id = $this->applyData($request);
         if ($this->kind == 'fraction') {
             $jsFunc = 'addFractionDlgDone';
         } else {
             if ($this->kind == 'street') {
                 $jsFunc = 'addStreetDlgDone';
             } else {
                 if ($this->kind == 'catmunic') {
                     $jsFunc = 'addCatMunicDlgDone';
                 }
             }
         }
         R3EcoGisEventNotifier::notifyDataChanged($this, array('data_changed' => true));
         return array('status' => R3_AJAX_NO_ERROR, 'js' => "{$jsFunc}({$id})");
     }
 }