public function submitFormData($request) { $params = array('label', 'visible', 'width'); // get data from class $obj = R3Controller::factory(array('on' => $this->module)); $tableConfig = new R3BaseTableConfig(R3AuthInstance::get()); $defaultConfig = $obj->getTableColumnConfig(); $config = array(); $positions = explode(',', $request['fields_position']); foreach ($defaultConfig as $key => $data) { foreach ($params as $param) { if (isset($request["{$key}_{$param}"])) { if ($request["{$key}_{$param}"] == '' || $param == 'width' && strtoupper($request["{$key}_{$param}"]) == 'AUTO') { $config[$key][$param] = null; } else { $config[$key][$param] = $request["{$key}_{$param}"]; } } } } foreach ($positions as $order => $key) { $config[$key]['position'] = $order + 1; } $tableConfig->setConfig($config, $this->module, $defaultConfig); R3EcoGisEventNotifier::notifyDataChanged($this, array('data_changed' => true)); return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataDoneSetupTableColumn()"); }
public function submitFormData($request) { $errors = array(); $db = ezcDbInstance::get(); $errors = $this->checkFormData($request); if (count($errors) > 0) { return $this->getAjaxErrorResult($errors); } else { $request['gps_id'] = $db->query("SELECT gps_id FROM global_plain_sum WHERE gp_id={$request['gp_id']} AND gc_id={$request['gc_id']}")->fetchColumn(); if ($request['act'] != 'del') { if ($request['gps_id'] > 0) { $request['act'] = $request['gps_expected_energy_saving'] == '' && $request['gps_expected_renewable_energy_production'] == '' && $request['gps_expected_co2_reduction'] == '' ? 'del' : 'mod'; } else { $request['act'] = 'add'; } } $id = $this->applyData($request); R3EcoGisEventNotifier::notifyDataChanged($this, array('data_changed' => true)); return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataDoneGlobalPlainSum({$id}, '{$this->kind}')"); } }
/** * Ajax request to submit data * @param array $request the request * @return array ajax format status */ public function submitFormData($request) { $errors = array(); $db = ezcDbInstance::get(); if ($this->act != 'add') { // Security check //R3Security::checkStreetLighting(@$request['id']); } $request['sl_id'] = $request['id']; if ($this->act != 'del') { $request['mu_id'] = $this->checkFormDataForMunicipality($request, $errors); $errors = $this->checkFormData($request, $errors); } if (count($errors) > 0) { return $this->getAjaxErrorResult($errors); } else { $db->beginTransaction(); $id = $this->applyData($request); if (isset($request['geometryStatus']) && strtoupper($request['geometryStatus']) == 'CHANGED') { $session_id = session_id(); $sql = "UPDATE street_lighting\r\n SET the_geom=foo.the_geom\r\n FROM (SELECT MULTI(ST_Force_2d(ST_union(ST_Buffer(the_geom, 0.0)))) AS the_geom FROM edit_tmp_polygon WHERE session_id='{$session_id}') AS foo\r\n WHERE sl_id={$id}"; $db->exec($sql); // Remove cache $sql = "UPDATE cache SET ca_expire_time=CURRENT_TIMESTAMP\r\n WHERE ca_object_id={$id} AND cat_id=2"; $db->exec($sql); } $db->commit(); R3EcoGisEventNotifier::notifyDataChanged($this, array('data_changed' => true)); R3EcoGisCacheHelper::resetMapPreviewCache(null); return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataDoneStreetLighting({$id})"); } }
/** * Ajax request to submit data * @param array $request the request * @return array ajax format status */ public function submitFormData($request) { $errors = array(); $db = ezcDbInstance::get(); $request = array_merge(array('ac_object_id' => null, 'gc_id' => null), $request); $request['wo_id'] = null; $request['ac_id'] = $request['id']; if (isset($request['mu_name'])) { $request['mu_id'] = R3EcoGisHelper::getMunicipalityIdByName($this->do_id, $request['mu_name'], $this->auth->getParam('mu_id')); } if ($this->act != 'del') { $request['ac_green_electricity_purchase'] = forceFloat($request['ac_green_electricity_purchase_mwh'], null, '.') * 1000; // Convert MWh to kWh $request['ac_co2_reduction'] = forceFloat($request['ac_co2_reduction_tco2'], null, '.') * 1000; // Convert tCO2 to kCO2 $tmpGesIdConsumption = array(); $tmpEsIdConsumption = array(); $tmpUdmIdConsumption = array(); $tmpAcExpectedEnergySaving = array(); $tmpAcExpectedEnergySavingMwh = array(); for ($i = 0; $i < count($request['es_id_consumption']); $i++) { if ($request['udm_id_consumption'][$i] != '' || $request['ac_expected_energy_saving'][$i] != '') { $tmpGesIdConsumption[] = $request['ges_id_consumption'][$i]; $tmpEsIdConsumption[] = $request['es_id_consumption'][$i]; $tmpUdmIdConsumption[] = $request['udm_id_consumption'][$i]; $tmpAcExpectedEnergySaving[] = $request['ac_expected_energy_saving'][$i]; $tmpAcExpectedEnergySavingMwh[] = $request['ac_expected_energy_saving_mwh'][$i]; } } $request['ges_id_consumption'] = $tmpGesIdConsumption; $request['es_id_consumption'] = $tmpEsIdConsumption; $request['udm_id_consumption'] = $tmpUdmIdConsumption; $request['ac_expected_energy_saving'] = $tmpAcExpectedEnergySaving; $request['ac_expected_energy_saving_mwh'] = $tmpAcExpectedEnergySavingMwh; $request['esu_id_consumption'] = R3EcoGisHelper::getMultipleEnergySourceUdmID($_SESSION['do_id'], $request['es_id_consumption'], $request['udm_id_consumption'], $request['mu_id']); $request['esu_id_production'] = R3EcoGisHelper::getEnergySourceUdmID($_SESSION['do_id'], $request['es_id_production'], $request['udm_id_production'], $request['mu_id'], true); $request['emo_id'] = self::getEnergyMeterObjectByID($request['mu_id'], $request['ac_object_id'], $request['gc_id']); if (isset($request['mu_name']) && $request['mu_name'] != '' && $request['mu_id'] == '') { $errors['mu_name'] = array('CUSTOM_ERROR' => _('Il comune immesso non è stato trovato')); } if (!isset($request['gc_id_parent']) || $request['gc_id_parent'] == '') { $errors['gc_id_parent'] = array('CUSTOM_ERROR' => _('Il campo "Macro-settore" è obbligatorio')); } $errors = $this->checkFormData($request, $errors); $selectedRelatedActions = array(); if (isset($request['related_required_action_id'])) { for ($i = 0; $i < count($request['related_required_action_id']); $i++) { if ($request['related_required_action_id'][$i] > 0 && in_array($request['related_required_action_id'][$i], $selectedRelatedActions)) { $errors['related_required_action_' . $i] = array('CUSTOM_ERROR' => _("L'azione ") . $this->getActionName($request['related_required_action_id'][$i]) . _(" è già stata selezionata")); } array_push($selectedRelatedActions, $request['related_required_action_id'][$i]); } } if (isset($request['related_action_id'])) { for ($i = 0; $i < count($request['related_action_id']); $i++) { if ($request['related_action_id'][$i] > 0 && in_array($request['related_action_id'][$i], $selectedRelatedActions)) { $errors['related_action_' . $i] = array('CUSTOM_ERROR' => _("L'azione ") . $this->getActionName($request['related_action_id'][$i]) . _(" è già stata selezionata")); } array_push($selectedRelatedActions, $request['related_action_id'][$i]); } } if (isset($request['related_excluded_action_id'])) { for ($i = 0; $i < count($request['related_excluded_action_id']); $i++) { if ($request['related_excluded_action_id'][$i] > 0 && in_array($request['related_excluded_action_id'][$i], $selectedRelatedActions)) { $errors['related_required_action_' . $i] = array('CUSTOM_ERROR' => _("L'azione ") . $this->getActionName($request['related_excluded_action_id'][$i]) . _(" è già stata selezionata")); } array_push($selectedRelatedActions, $request['related_excluded_action_id'][$i]); } } if (isset($request['enable_benefit_year']) && $request['enable_benefit_year'] == 'T' && isset($request['benefit_year'])) { $startBenefitYear = (int) substr($request['ac_benefit_start_date'], 0, 4); $endBenefitYear = (int) substr($request['ac_benefit_end_date'], 0, 4); $lastBenefitPerc = 0; for ($i = 0; $i < count($request['benefit_year']); $i++) { if ($request['benefit_year'][$i] != '' && $request['benefit_year'][$i] < $startBenefitYear) { $errors['benefit_year_' . $i] = array('CUSTOM_ERROR' => sprintf(_("L'anno del beneficio \"%s\" è antecedente al %s (anno inizio beneficio)"), $request['benefit_year'][$i], $startBenefitYear)); } else { if ($request['benefit_year'][$i] != '' && $request['benefit_year'][$i] > $endBenefitYear) { $errors['benefit_year_' . $i] = array('CUSTOM_ERROR' => sprintf(_("L'anno del beneficio \"%s\" è oltre al %s (anno fine beneficio)"), $request['benefit_year'][$i], $endBenefitYear)); } } if ($request['benefit_benefit'][$i] != '' && $request['benefit_benefit'][$i] < 0 || $request['benefit_benefit'][$i] != '' && $request['benefit_benefit'][$i] > 100) { $errors['benefit_benefit_' . $i] = array('CUSTOM_ERROR' => _("Il valore del beneficio deve essere compreso tra 0 e 100")); } } } } if (count($errors) > 0) { return $this->getAjaxErrorResult($errors); } else { setLocale(LC_ALL, 'C'); $db->beginTransaction(); $id = $this->applyData($request); $sql = "DELETE FROM ecogis.action_catalog_energy WHERE ac_id=" . $db->quote($id, PDO::PARAM_INT); $db->exec($sql); if ($this->act != 'del') { for ($i = 0; $i < count($request['esu_id_consumption']); $i++) { $sql = "INSERT INTO ecogis.action_catalog_energy (ac_id, esu_id, ace_expected_energy_saving) " . " VALUES (" . $db->quote($id, PDO::PARAM_INT) . ", " . $db->quote($request['esu_id_consumption'][$i], PDO::PARAM_INT) . ", " . $db->quote($request['ac_expected_energy_saving'][$i], PDO::PARAM_INT) . ")"; $db->exec($sql); } } $sql = "DELETE FROM ecogis.action_catalog_dependencies WHERE ac_id=" . $db->quote($id, PDO::PARAM_INT); $db->exec($sql); if ($this->act != 'del') { $relatedActions = array(); if (isset($request['related_action_id'])) { for ($i = 0; $i < count($request['related_action_id']); $i++) { array_push($relatedActions, array('related_action_id' => $request['related_action_id'][$i], 'acd_required' => 'D')); } } if (isset($request['related_required_action_id'])) { for ($i = 0; $i < count($request['related_required_action_id']); $i++) { array_push($relatedActions, array('related_action_id' => $request['related_required_action_id'][$i], 'acd_required' => 'R')); } } if (isset($request['related_excluded_action_id'])) { for ($i = 0; $i < count($request['related_excluded_action_id']); $i++) { array_push($relatedActions, array('related_action_id' => $request['related_excluded_action_id'][$i], 'acd_required' => 'E')); } } foreach ($relatedActions as $relatedAction) { $sql = "INSERT INTO ecogis.action_catalog_dependencies (ac_id, ac_related_id, acd_type) " . " VALUES (" . $db->quote($id, PDO::PARAM_INT) . ", " . $db->quote($relatedAction['related_action_id'], PDO::PARAM_INT) . ", " . $db->quote($relatedAction['acd_required'], PDO::PARAM_BOOL) . ")"; if ($relatedAction['related_action_id'] > 0) { $db->exec($sql); } } } $sql = "DELETE FROM ecogis.action_catalog_benefit_year WHERE ac_id=" . $db->quote($id); $db->exec($sql); if ($this->act != 'del') { if (isset($request['enable_benefit_year']) && $request['enable_benefit_year'] == 'T') { for ($i = 0; $i < count($request['benefit_year']); $i++) { $year = forceInteger($request['benefit_year'][$i]); $benefit = forceFloat($request['benefit_benefit'][$i], null, '.'); if ($year > 1970 && $request['benefit_benefit'][$i] != '') { $sql = "INSERT INTO ecogis.action_catalog_benefit_year (ac_id, acby_year, acby_benefit) " . "VALUES ({$id}, {$year}, {$benefit})"; $db->exec($sql); } } } } $db->commit(); R3EcoGisCacheHelper::resetMapPreviewCache(null); R3EcoGisEventNotifier::notifyDataChanged($this, array('data_changed' => true)); if ($this->bu_id == '') { return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataDoneActionCatalog({$id})"); } else { return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataDoneActionCatalogFromBuilding({$id})"); } } }
/** * Ajax request to submit data * @param array $request the request * @return array ajax format status */ public function submitFormData($request) { global $dbini, $dsn, $mdb2, $languages; if ($this->act == 'del') { $id = $this->deleteCustomer($request); return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataDoneCustomer({$id})"); } $errors = array(); $errors = $this->checkFormData($request, $errors); if ($request['municipality'] == '') { $errors['municipality'] = array('CUSTOM_ERROR' => _("Almeno un comune deve essere selezionato")); } $catalog = R3DbCatalog::factory('pgsql', $mdb2); $data = $catalog->getUserData(); if (count($errors) > 0) { return $this->getAjaxErrorResult($errors); } else { if ($request['cus_srid'] == '') { $request['cus_srid'] = 4326; } $db = ezcDbInstance::get(); $do_id = R3EcoGisCustomerHelper::createDomain($request['dn_name'], $request['dn_name_alias']); R3EcoGisCustomerHelper::createCustomer($do_id, $request); R3EcoGisCustomerHelper::createUser($do_id, $request); R3EcoGisCustomerHelper::setMunicipality($do_id, explode(',', $request['municipality'])); $dataPath = R3_UPLOAD_DATA_DIR . strtolower($request['dn_name']); $dataLogoPath = $dataPath . '/logo'; $dataStylePath = $dataPath . '/style'; $dataJSPath = $dataPath . '/js'; if (!file_exists($dataPath)) { if (!@mkdir($dataPath)) { throw new Exception("Can't create path {$dataPath}"); } } if (!file_exists($dataLogoPath)) { if (!@mkdir($dataLogoPath)) { throw new Exception("Can't create path {$dataLogoPath}"); } } if (!file_exists($dataStylePath)) { if (!@mkdir($dataStylePath)) { throw new Exception("Can't create path {$dataStylePath}"); } } if (!file_exists($dataJSPath)) { if (!@mkdir($dataJSPath)) { throw new Exception("Can't create path {$dataJSPath}"); } } R3EcoGisCustomerHelper::saveImages($request['dn_name'], $request); R3EcoGisCustomerHelper::saveCSS($request['dn_name'], $request); if ($request['consumption_end_year'] > 0 && $request['consumption_start_year'] > 0) { $viewOpt = array('totYears' => $request['consumption_end_year'] - $request['consumption_start_year'] + 1); } else { $viewOpt = array('totYears' => 100); } $schema = R3EcoGisHelper::getGeoSchema($do_id); //'geo_' . strtolower($request['dn_name']); R3EcoGisCustomerHelper::createSchema($schema, $dsn['dbuser']); R3EcoGisCustomerHelper::createViews($schema, $dsn['dbuser'], $request['cus_srid'], $do_id, $viewOpt); R3EcoGisCustomerHelper::setLoggerTrigger(); R3EcoGisCustomerHelper::grantTables($schema, $dsn['dbuser']); R3EcoGisCustomerHelper::applyConsumptionInterval($request['consumption_start_year'], $request['consumption_end_year']); if (R3_AUTO_POPULATE_GEOMETRY_COLUMNS && !isset($request['skip_geometry_check'])) { R3EcoGisCustomerHelper::populateGeometryColumns(R3_DB_SCHEMA); R3EcoGisCustomerHelper::populateGeometryColumns($schema); } R3EcoGisCustomerHelper::copyEnergySource($do_id); if ($this->isMultiDomain()) { R3EcoGisCustomerHelper::copySettings('SYSTEM', $request['dn_name']); } if ($this->act == 'add') { $sql = "INSERT INTO auth.settings (do_id, app_id, se_section, se_param, se_value, se_descr, se_type, se_type_ext, se_private, se_order)\r\n SELECT DISTINCT (SELECT do_id FROM auth.domains_name WHERE dn_type='N' and dn_name='{$request['dn_name']}'), s.app_id, se_section, se_param, se_value, se_descr, se_type, se_type_ext, se_private, se_order\r\n FROM auth.settings s\r\n INNER JOIN auth.domains_name dn on s.do_id=dn.do_id and dn_type='N' AND dn_name='{$request['do_template']}'\r\n INNER JOIN auth.applications app on s.app_id=app.app_id AND app_code='" . APPLICATION_CODE . "'\r\n WHERE us_id IS NULL \r\n ORDER BY se_section, se_param"; $db->exec($sql); } //Salva dati nuovo ente (DBINI) $gridSize = forceInteger($request['do_grid_size'], 0, false, '.'); if ($this->auth->getConfigValueFor($request['dn_name'], APPLICATION_CODE, null, 'APPLICATION', 'STAT_GRID_SIZE', 0) != $gridSize) { $this->create_grid(array('do_id' => $do_id, 'sg_size' => $request['do_grid_size'])); } $dbini2 = clone $dbini; $dbini2->setDomainName($request['dn_name']); $dbini2->setValue('APPLICATION', 'NUM_LANGUAGES', $request['app_language']); $dbini2->setValue('APPLICATION', 'CATASTRAL_TYPE', $request['app_cat_type']); $dbini2->setValue('APPLICATION', 'BUILDING_CODE_TYPE', $request['do_building_code_type']); $dbini2->setValue('APPLICATION', 'BUILDING_CODE_REQUIRED', $request['do_building_code_required']); $dbini2->setValue('APPLICATION', 'CALCULATE_GLOBAL_PLAIN_TOTALS', $request['do_calculate_global_plain_totals']); $dbini2->setValue('APPLICATION', 'BUILDING_CODE_UNIQUE', $request['do_building_code_unique']); $dbini2->setValue('APPLICATION', 'BUILDING_EXTRA_DESCR', $request['do_building_extra_descr']); $dbini2->setValue('APPLICATION', 'PUBLIC_CSS_URL', $request['do_public_css_url']); $dbini2->setValue('APPLICATION', 'ENABLE_PUBLIC_SITE', $request['do_public_site']); $dbini2->setValue('APPLICATION', 'STAT_GRID_SIZE', $gridSize > 0 ? $gridSize : null); $dbini2->setValue('APPLICATION', 'BUILDING_SHOW_ID', $request['do_building_show_id']); $dbini2->setValue('APPLICATION', 'BUILDING_YEAR_TYPE', $request['do_build_year_type']); $dbini2->setValue('APPLICATION', 'BUILDING_RESTRUCTURE_YEAR_TYPE', $request['do_build_restructure_year_type']); $dbini2->setValue('APPLICATION', 'BUILDING_MUNICIPALITY_MODE', $request['do_municipality_mode']); $dbini2->setValue('APPLICATION', 'BUILDING_FRACTION_MODE', $request['do_fraction_mode']); $dbini2->setValue('APPLICATION', 'BUILDING_STREET_MODE', $request['do_street_mode']); $dbini2->setValue('APPLICATION', 'BUILDING_CATASTRAL_MODE', $request['do_catastral_mode']); $dbini2->setValue('APPLICATION', 'CONSUMPTION_START_YEAR', $request['consumption_start_year']); $dbini2->setValue('APPLICATION', 'CONSUMPTION_END_YEAR', $request['consumption_end_year']); if ($request['app_language'] == 1) { $dbini2->setValue('APPLICATION', 'LANG_NAME_SHORT_1', ''); $dbini2->setValue('APPLICATION', 'LANG_NAME_SHORT_2', ''); } else { $dbini2->setValue('APPLICATION', 'LANG_NAME_SHORT_1', sprintf(' (%s)', $languages[1])); $dbini2->setValue('APPLICATION', 'LANG_NAME_SHORT_2', sprintf(' (%s)', $languages[2])); } $dbini2->setValue('APPLICATION', 'LANG_NAME_SHORT_3', ' (en)'); // Gisclient settings $dbini2->setValue('GISCLIENT', 'PROJECT', $request['do_gc_project']); $dbini2->setValue('GISCLIENT', 'MAPSET', $request['do_gc_mapset']); $dbini2->setValue('GISCLIENT', 'HAS_STREETVIEW', $request['do_gc_streeview']); $dbini2->setValue('GISCLIENT', 'HAS_QUICK_SEARCH', $request['do_gc_quick_search']); $dbini2->setValue('GISCLIENT', 'DIGITIZE_HAS_SELECTION', $request['do_gc_digitize_has_selection']); $dbini2->setValue('GISCLIENT', 'DIGITIZE_HAS_EDITING', $request['do_gc_digitize_has_editing']); if (R3_AUTO_SAVE_DATABASE_VERSION) { R3EcoGisCustomerHelper::updateDatabaseVersion(DATABASE_VERSION); // Setup database version } $id = 0; R3EcoGisEventNotifier::notifyDataChanged($this, array('data_changed' => true)); return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataDoneCustomer({$id})"); } }
/** * 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})"); } }
/** * 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})"); } }
/** * Ajax request to submit data * @param array $request the request * @return array ajax format status */ public function submitFormData($request) { $errors = array(); $data = R3EcoGisHelper::getBuildingData($this->bu_id); $this->mu_id = $data['mu_id']; $request = array_merge(array('us_id' => ''), $request); $request['em_id'] = forceInteger($request['id'], 0, false, '.'); if ($this->act != 'del') { // Change required fields if ($request['em_is_production'] == 'T') { $request['up_id'] = null; $this->setFieldAttrib('esu_id', array('required' => true)); } else { if ($request['us_id'] == '') { $this->setFieldAttrib('esu_id', array('required' => true)); } else { $this->setFieldAttrib('up_id', array('required' => true)); } } if ($request['us_id'] == '') { $request['esu_id'] = R3EcoGisHelper::getEnergySourceUdmID($this->do_id, $request['es_id'], $request['udm_id'], $this->mu_id); } else { $request['esu_id'] = ''; } $request['emo_id'] = R3EcoGisHelper::getEnergyMeterObjectIdByCode('BUILDING'); $request['em_object_id'] = $request['bu_id']; $errors = $this->checkFormData($request); } if (count($errors) > 0) { return $this->getAjaxErrorResult($errors); } else { $id = $this->applyData($request); R3EcoGisEventNotifier::notifyDataChanged($this, array('data_changed' => true)); return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataDoneMeter({$id})"); } }
/** * Ajax request to submit data * @param array $request the request * @return array ajax format status */ public function submitFormData($request) { $errors = array(); $db = ezcDbInstance::get(); $request['us_id'] = (int) $request['id']; $request['do_id'] = $this->do_id; if ($this->act != 'del') { $errors = $this->checkFormData($request); } if (count($errors) > 0) { return $this->getAjaxErrorResult($errors); } else { $oldLocale = getLocale(); setLocale(LC_ALL, 'C'); $db->beginTransaction(); $oldIds = R3EcoGisUtilityHelper::getProductId($request['us_id']); if ($this->act == 'del') { // Cancella comuni vecchi R3EcoGisUtilityHelper::setMunicipality($request['us_id'], array()); foreach ($db->query("SELECT up_id FROM utility_product WHERE us_id=" . (int) $request['us_id']) as $row) { R3EcoGisUtilityHelper::deleteProduct(array('up_id' => $row['up_id'])); } } $id = $this->applyData($request); $newIds = array(0, 1, 2); // valori nuovo $cantDelete = 'F'; if ($this->act == 'add' || $this->act == 'mod') { $order = 0; R3EcoGisUtilityHelper::setMunicipality($id, explode(',', $request['municipality'])); // Modifica valori vecchi foreach ($oldIds as $up_id) { $order += 10; if (isset($request["up_name_1_{$up_id}"]) && $request["up_name_1_{$up_id}"] != '') { R3EcoGisUtilityHelper::updateProduct(array('up_id' => $up_id, 'up_name_1' => $request["up_name_1_{$up_id}"], 'up_name_2' => @$request["up_name_2_{$up_id}"], 'esu_co2_factor' => $request["esu_co2_factor_{$up_id}"], 'ges_id' => $request["ges_id_{$up_id}"], 'up_order' => $order)); } else { try { R3EcoGisUtilityHelper::deleteProduct(array('up_id' => $up_id)); } catch (Exception $e) { $cantDelete = 'T'; } } } // Aggiunge valori nuovi foreach ($newIds as $up_id) { // echo $request["up_name_1_new_{$up_id}"]; $order += 10; if (isset($request["up_name_1_new_{$up_id}"]) && $request["up_name_1_new_{$up_id}"] != '') { R3EcoGisUtilityHelper::addProduct(array('do_id' => $this->do_id, 'us_id' => $id, 'up_name_1' => $request["up_name_1_new_{$up_id}"], 'up_name_2' => @$request["up_name_2_new_{$up_id}"], 'up_order' => $order, 'esu_co2_factor' => $request["esu_co2_factor_new_{$up_id}"], 'ges_id' => $request["ges_id_new_{$up_id}"], 'et_code' => $request["et_code_new_{$up_id}"])); } } } $db->commit(); R3EcoGisEventNotifier::notifyDataChanged($this, array('data_changed' => true)); setLocale(LC_ALL, $oldLocale); return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataUtilityDone({$id}, '{$cantDelete}')"); } }
public function submitFormData($request) { $errors = array(); $db = ezcDbInstance::get(); $request['gpr_id'] = (int) $request['id']; //R3Security::checkGlobalPlainRow(@$request['gc_id'], @$request['gp_id']); if ($this->act != 'add') { $isImportedRow = $this->isImportedRow($request['gpr_id']); } else { $isImportedRow = false; } if ($this->is_paes_action && empty($request['gpr_id'])) { // Ricava il paes dal comune if (empty($request['mu_id'])) { $errors['mu_id'] = array('CUSTOM_ERROR' => _("Il campo \"Comune\" è obbligatorio. Se il comune non è presente, verificare un PAES sia associato al comune")); } $sql = "SELECT gp_id FROM ecogis.global_strategy WHERE gp_id IS NOT NULL AND mu_id=" . (int) $request['mu_id']; $gp_id = $db->query($sql)->fetchColumn(); if (empty($gp_id)) { $errors['mu_id'] = array('CUSTOM_ERROR' => _("Per poter inserire un azione assicurarsi di aver associato il PAES al comune nei parametri principali")); } $request['gp_id'] = $gp_id; } if ($this->act != 'del') { if (!$isImportedRow) { $errors = array_merge($errors, $this->checkFormData($request)); } $errors = array_merge($errors, $this->checkFormDataDetail($request, $errors)); } if (count($errors) > 0) { return $this->getAjaxErrorResult($errors); } $db->beginTransaction(); if ($this->hasGauge($request['gpr_id'])) { $request['gpr_gauge_type'] = 'G'; } if ($isImportedRow) { // Only update and delete if ($this->act == 'del') { $errors['gpr_imported_row'] = array('CUSTOM_ERROR' => _("Impossibile cancellare i dati importati")); return $this->getAjaxErrorResult($errors); } $id = $request['gpr_id']; $this->updateGaugeType($id, $request['gpr_gauge_type']); if (isset($request['gpr_descr_1'])) { $this->updateDescription($id, $request); } $this->submitFormDataDetail($request); } else { // Standard $id = $this->applyData($request); $this->submitFormDataDetail($request); } $db->Commit(); R3EcoGisEventNotifier::notifyDataChanged($this, array('data_changed' => true)); return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataDoneGlobalPlainRow({$id})"); }
/** * Ajax request to submit data * @param array $request the request * @return array ajax format status */ public function submitFormData($request) { $errors = array(); $db = ezcDbInstance::get(); $db->beginTransaction(); $id = (int) $request['id']; R3EcoGisGlobalActionHelper::setGlobalAction($id, explode(',', $request['gpa_id_list'])); $db->commit(); R3EcoGisEventNotifier::notifyDataChanged($this, array('data_changed' => true)); return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataDoneGlobalActionBuilder({$id})"); }
/** * Ajax request to submit data * @param array $request the request * @return array ajax format status */ public function submitFormData($request) { $errors = array(); if ($this->act != 'add') { // Security check // R3Security::checkDevice(@$request['id']); } $request['dev_id'] = $request['id']; if ($this->act != 'del') { $errors = $this->checkFormData($request); } else { $request['dt_extradata'] = null; } if (count($errors) > 0) { return $this->getAjaxErrorResult($errors); } else { $db = ezcDbInstance::get(); $id = $this->applyData($request); R3EcoGisEventNotifier::notifyDataChanged($this, array('data_changed' => true)); return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataDoneDevice({$id})"); } }
/** * Ajax request to submit data * @param array $request the request * @return array ajax format status */ public function submitFormData($request) { $errors = array(); $db = ezcDbInstance::get(); $request['gp_id'] = $request['id']; if ($this->act != 'del') { if (isset($request['mu_name'])) { $request['mu_id'] = R3EcoGisHelper::getMunicipalityIdByName($this->do_id, $request['mu_name'], $this->auth->getParam('mu_id')); } $request['gp_url_1'] = $this->adjURL($request["gp_url_1"]); if (isset($request["gp_url_2"])) { $request['gp_url_2'] = $this->adjURL($request["gp_url_2"]); } $errors = $this->checkFormData($request); if (isset($request['mu_name']) && $request['mu_name'] != '' & $request['mu_id'] == '') { $errors['mu_name'] = array('CUSTOM_ERROR' => _('Il comune immesso non è stato trovato')); } if ($request['gp_url_1'] != '' && !$this->isValidURL($request['gp_url_1'])) { $errors['gp_url_1'] = array('CUSTOM_ERROR' => _("L'indirizzo immesso non è valido")); } if (isset($request["gp_url_2"]) && $request['gp_url_2'] != '' && !$this->isValidURL($request['gp_url_2'])) { $errors['gp_url_2'] = array('CUSTOM_ERROR' => _("L'indirizzo immesso non è valido")); } } if (count($errors) > 0) { return $this->getAjaxErrorResult($errors); } else { $this->act == 'add' ? R3Security::checkMunicipality($request['mu_id']) : R3Security::checkGlobalPlain(@$request['id']); if ($this->act == 'del') { $sql = "DELETE FROM global_plain_row WHERE gp_id={$request['gp_id']}"; $db->exec($sql); $sql = "DELETE FROM global_plain_sum WHERE gp_id={$request['gp_id']}"; $db->exec($sql); } $id = $this->applyData($request); R3EcoGisEventNotifier::notifyDataChanged($this, array('data_changed' => true)); return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataDoneGlobalPlain({$id})"); } }
public function submitFormData($request) { $errors = array(); $db = ezcDbInstance::get(); setLocale(LC_ALL, 'C'); setLangInfo(array('thousands_sep' => ".")); $request['gs_id'] = forceInteger($request['id'], 0, false, '.'); if ($this->act == 'mod') { $sql = "SELECT ge_id, gc_id FROM global_subcategory WHERE gs_id={$request['gs_id']}"; list($request['ge_id'], $request['gc_id']) = $db->query($sql)->fetch(PDO::FETCH_NUM); } if ($this->act != 'del') { $errors = $this->checkFormData($request, $request['kind']); } if (count($errors) > 0) { return $this->getAjaxErrorResult($errors); } else { $db->beginTransaction(); // Remove consumption $em_list = $this->getEnergyMeterList($request['gs_id']); if (count($em_list) > 0) { $sql = "DELETE FROM consumption WHERE em_id IN (" . implode(', ', $em_list) . ")"; // Remove consumption $db->exec($sql); $sql = "DELETE FROM energy_meter WHERE em_id IN (" . implode(', ', $em_list) . ")"; // Remove energy_meter $db->exec($sql); } $sql = "DELETE FROM global_data WHERE gs_id=" . $request['gs_id']; $db->exec($sql); if ($this->act == 'del') { $sql = "DELETE FROM global_subcategory WHERE gs_id=" . $request['gs_id']; $db->exec($sql); } else { if (isset($request['gs_tot_value'])) { $request['gs_tot_value'] = $request['gs_tot_value'] * 1000; } if (isset($request['gs_tot_production_value'])) { $request['gs_tot_production_value'] = $request['gs_tot_production_value'] * 1000; } if (isset($request['gs_tot_emission_value'])) { $request['gs_tot_emission_value'] = $request['gs_tot_emission_value'] * 1000; } if (isset($request['gs_tot_emission_factor'])) { $request['gs_tot_emission_factor'] = $request['gs_tot_emission_factor'] * 1000; } $id = $this->applyData($request); $geData = $db->query("SELECT mu_id, ge_year FROM global_entry WHERE ge_id={$request['ge_id']}")->fetch(PDO::FETCH_ASSOC); $year = $geData['ge_year']; $mu_id = $geData['mu_id']; $totalOnly = $db->query("SELECT gc_total_only FROM global_category WHERE gc_id=" . (int) $request['gc_id'])->fetchColumn() == true; if (!$totalOnly) { foreach ($request['ges_id_consumption'] as $key => $value) { if (empty($request['ac_expected_energy_saving'][$key])) { continue; } $ges_id = $this->getGlobalEnergySource($request['es_id_consumption'][$key], $request['udm_id_consumption'][$key]); if (empty($ges_id)) { throw new Exception("getGlobalEnergySource(" . $request['es_id_consumption'][$key] . ', ' . $request['udm_id_consumption'][$key] . ") key={$key} faild"); } $sql = "INSERT INTO global_data (ges_id, gs_id) VALUES ({$ges_id}, {$id})"; $db->exec($sql); $gd_id = $db->lastInsertId('global_data_gd_id_seq'); $esu_id = R3EcoGisHelper::getEnergySourceUdmID($this->do_id, $request['es_id_consumption'][$key], $request['udm_id_consumption'][$key], $mu_id, false); if (!empty($esu_id)) { $em_id = R3EcoGisHelper::addDummyEnergyMeter(array('esu_id' => $esu_id, 'em_object_id' => $gd_id), 'GLOBAL_ENERGY'); $data = array(); $data['co_start_date'] = "'{$year}-01-01'"; $data['co_end_date'] = "'{$year}-12-31'"; $data['co_value'] = forceFloat($request['ac_expected_energy_saving'][$key], null, '.'); $data['co_bill'] = 0; $data['em_id'] = $em_id; if (in_array($this->kind, array('ENERGY_PRODUCTION', 'HEATH_PRODUCTION'))) { $data['co_production_co2_factor'] = (double) forceFloat($request['co_production_co2_factor'][$key], null, '.'); } $sql = "INSERT INTO consumption (" . implode(', ', array_keys($data)) . ") VALUES (" . implode(', ', $data) . ")"; $db->exec($sql); } else { throw new Exception("Unknown esu [es_id={$request['es_id_consumption'][$key]}; udm_id={$request['udm_id_consumption'][$key]}; do_id={$this->do_id}; mu_id={$mu_id}]"); } } } if (isset($request['geometryStatus']) && strtoupper($request['geometryStatus']) == 'CHANGED') { $session_id = session_id(); $sql = "UPDATE global_subcategory\r\n SET the_geom=foo.the_geom\r\n FROM (SELECT MULTI(ST_Force_2d(ST_union(ST_Buffer(the_geom, 0.0)))) AS the_geom FROM edit_tmp_polygon WHERE session_id='{$session_id}') AS foo\r\n WHERE gs_id={$id}"; $db->exec($sql); } } $db->commit(); R3EcoGisEventNotifier::notifyDataChanged($this, array('data_changed' => true)); return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataDoneEnergySourceRow({$id}, '{$this->kind}')"); } }
/** * Ajax request to submit data * @param array $request the request * @return array ajax format status */ public function submitFormData($request) { $errors = array(); $request = array_merge(array('us_id' => ''), $request); $request['ge_id'] = forceInteger($request['id'], 0, false, '.'); if ($this->act != 'del') { $request['mu_id'] = $this->checkFormDataForMunicipality($request, $errors); $errors = $this->checkFormData($request, $errors); } if (count($errors) > 0) { return $this->getAjaxErrorResult($errors); } else { if ($this->act == 'mod') { $this->removeField('mu_id'); $this->removeField('ge_year'); } // Convert from MWh to kWh if (isset($request['ge_green_electricity_purchase'])) { $request['ge_green_electricity_purchase'] = $request['ge_green_electricity_purchase'] * 1000; } $id = $this->applyData($request); R3EcoGisEventNotifier::notifyDataChanged($this, array('data_changed' => true)); return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataDoneGlobalResult({$id})"); } }
/** * Ajax request to submit data * @param array $request the request * @return array ajax format status */ public function submitFormData($request) { $errors = array(); $db = ezcDbInstance::get(); $request['esu_id'] = (int) $request['id']; $request['do_id'] = $this->do_id; $this->setMunicipalityForUser($request); if ($this->act == 'add' && $request['mu_id'] == '') { $errors['mu_id'] = array('CUSTOM_ERROR' => _("Indicare il comune su cui attivare questo fattore di conversione")); } if ($this->act != 'del') { $request['es_id'] = (int) $request['es_id']; $request['udm_id'] = (int) $request['udm_id']; $request['mu_id'] = (int) $request['mu_id']; $errors = $this->checkFormData($request, $errors); $sql = "SELECT COUNT(*) FROM energy_source_udm WHERE es_id={$request['es_id']} AND udm_id={$request['udm_id']} AND do_id={$request['do_id']} AND mu_id={$request['mu_id']}"; if ($this->act == 'mod') { $sql .= " AND esu_id<>" . $request['esu_id']; } if ($db->query($sql)->fetchColumn() > 0) { $errors['es_id'] = array('CUSTOM_ERROR' => _("L'alimentazione e l'unità di misura immesse esistono già")); } $request['mu_id'] = $mu_id = (int) $request['mu_id'] > 0 ? (int) $request['mu_id'] : null; if ($mu_id == 0) { $request['mu_id'] = $mu_id = null; } } else { // Ricavo valori per spostamento fattori di conversione $data = $db->query("SELECT es_id, udm_id, mu_id FROM energy_source_udm WHERE esu_id={$request['esu_id']}")->fetch(PDO::FETCH_ASSOC); $request['es_id'] = $data['es_id']; $request['udm_id'] = $data['udm_id']; $mu_id = $data['mu_id']; } if (count($errors) > 0) { return $this->getAjaxErrorResult($errors); } else { $db->beginTransaction(); $request['ges_id'] = R3EcoGisESUHelper::getGlobalEnergySource($this->do_id, $request['es_id'], $request['udm_id']); $changed = 0; if ($mu_id > 0 && $this->act == 'del') { // Converte la fonte del comune in fonte generica (del dominio) $changed = R3EcoGisESUHelper::updateEnergySourceUDM($this->do_id, $request['es_id'], $request['udm_id'], $mu_id, true); } $id = $this->applyData($request); if ($mu_id > 0 && $this->act == 'add') { // Converte la vecchia fonte con la nuova per tutto il comune $changed = R3EcoGisESUHelper::updateEnergySourceUDM($this->do_id, $request['es_id'], $request['udm_id'], $mu_id); } $db->commit(); R3EcoGisEventNotifier::notifyDataChanged($this, array('data_changed' => true)); return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataEnergySourceUDMDone({$id}, " . ($changed ? 1 : 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})"); }
/** * Ajax request to submit data * @param array $request the request * @return array ajax format status */ public function submitFormData($request) { $errors = array(); $db = ezcDbInstance::get(); $default = array('ge_id' => null, 'ge_id_2' => null); $request = array_merge($default, $request); 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'; $request['act'] = $this->act; } if ($this->act != 'add') { R3Security::checkGlobalStrategy(@$request['id']); } $request['gst_id'] = $request['id']; if (isset($request['mu_name'])) { $request['mu_id'] = R3EcoGisHelper::getMunicipalityIdByName($this->do_id, $request['mu_name'], $this->auth->getParam('mu_id')); } if ($this->act != 'del') { $errors = $this->checkFormData($request); if (isset($request['mu_name']) && $request['mu_name'] != '' & $request['mu_id'] == '') { $errors['mu_name'] = array('CUSTOM_ERROR' => _('Il comune immesso non è stato trovato')); } if ($request['gst_reduction_target'] < 20) { $errors['gst_reduction_target'] = array('CUSTOM_ERROR' => _("L'obiettivo previsto deve essere di almento 20%%")); } if ($request['gst_reduction_target_year'] != 2020) { $errors['gst_reduction_target_year'] = array('CUSTOM_ERROR' => _("L'anno dell'obiettivo deve essere 2020")); } if ($request['gst_reduction_target_long_term'] != '' && ($request['gst_reduction_target_year_long_term'] != '' xor $request['gst_reduction_target_citizen_long_term'] != '')) { $errors['gst_reduction_target_long_term'] = array('CUSTOM_ERROR' => _('I valori "Obiettivo a lungo termine", "Anno lungo termine" e "Abitanti lungo temine", (se indicati) devono essere presenti')); } if ($request['ge_id'] != '' && $request['ge_id_2'] != '' && $request['ge_id'] == $request['ge_id_2']) { $errors['ge_id_2'] = array('CUSTOM_ERROR' => _("L'inventario e l'inventario 2 devono essere diversi")); } } if (count($errors) > 0) { return $this->getAjaxErrorResult($errors); } else { $id = $this->applyData($request); R3EcoGisEventNotifier::notifyDataChanged($this, array('data_changed' => true)); return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataDoneGlobalStrategy({$id})"); } }
/** * Ajax request to submit data * @param array $request the request * @return array ajax format status */ public function submitFormData($request) { $errors = array(); $db = ezcDbInstance::get(); $request['gt_id'] = $request['id']; if ($this->act != 'del') { $request['gt_code'] = strtoupper($request['gt_code']); $errors = $this->checkFormData($request); } if (count($errors) > 0) { return $this->getAjaxErrorResult($errors); } else { $db->beginTransaction(); $id = $this->applyData($request); if ($this->act != 'del') { R3EcoGisGlobalResultTableHelper::setGlobalEnergySourceType($id, explode(',', $request['global_energy_source_type'])); R3EcoGisGlobalResultTableHelper::setGlobalCategoryType($id, explode(',', $request['global_category'])); } $db->commit(); R3EcoGisEventNotifier::notifyDataChanged($this, array('data_changed' => true)); return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataDoneGlobalResultTableBuilder({$id})"); } }
/** * Ajax request to submit data * @param array $request the request * @return array ajax format status */ public function submitFormData($request) { $errors = array(); $db = ezcDbInstance::get(); $auth = R3AuthInstance::get(); $this->setMunicipalityForUser($request); if ($this->act != 'add' && !defined('UNIT_TEST_MODE')) { // Security check R3Security::checkBuilding(@$request['id']); } $request['bu_id'] = $request['id']; if (isset($request['mu_name'])) { $request['mu_id'] = R3EcoGisHelper::getMunicipalityIdByName($this->do_id, $request['mu_name'], $this->auth->getParam('mu_id')); } if (isset($request['fr_name'])) { $request['fr_id'] = R3EcoGisHelper::getFractionIdByName($this->do_id, $request['mu_id'], $request['fr_name']); } if (isset($request['st_name'])) { $request['st_id'] = R3EcoGisHelper::getStreetIdByName($this->do_id, $request['mu_id'], $request['st_name']); } if ($this->act != 'del') { $errors = $this->checkFormData($request); if ($auth->getConfigValue('APPLICATION', 'BUILDING_CODE_REQUIRED') == 'T' && trim($request['bu_code']) == '') { $errors['bu_code'] = array('CUSTOM_ERROR' => _('Il campo "Codice edificio" è obbligatorio')); } if (isset($request['mu_name']) && $request['mu_name'] != '' && $request['mu_id'] == '') { $errors['mu_name'] = array('CUSTOM_ERROR' => _('Il comune immesso non è stato trovato')); } if (isset($request['fr_name']) && $request['fr_name'] != '' && $request['fr_id'] == '') { $errors['fr_name'] = array('CUSTOM_ERROR' => _('La frazione immessa non è stata trovata')); } if (isset($request['st_name']) && $request['st_name'] != '' && $request['st_id'] == '') { $errors['st_name'] = array('CUSTOM_ERROR' => _('La strada immessa non è stata trovata')); } if ($request['bu_usage_weeks'] > 52) { $errors['bu_usage_weeks'] = array('CUSTOM_ERROR' => _('Numero di settimane massimo inseribile: 52')); } if ($auth->getConfigValue('APPLICATION', 'BUILDING_CODE_UNIQUE') == 'T' && !$this->checkBuildingCodeUnique($request['mu_id'], $request['bu_code'], $request['id'])) { $errors['bu_code'] = array('CUSTOM_ERROR' => _('Il campo "Codice edificio" non è univoco')); } if ($this->act == 'mod') { // Check compatibility between action and building purpose use $this->checkBuildingPurposeUseCompatibility($request['id'], $request['bpu_id'], $errors); } } if (count($errors) > 0) { return $this->getAjaxErrorResult($errors); } else { $deleteIDs = array(); // Array che contiene l'elenco delle immagini da cancellare (processato dopo il commit per evitare perdita di dati!) $db->beginTransaction(); if ($this->act != 'del') { $id = $this->applyData($request); // Update compatibility between action and building purpose use $this->updateBuildingPurposeUseCompatibility($request['id'], $request['bpu_id']); // Delete photo marked as delete foreach ($this->getOldImagesIDs($id, null) as $photoID) { if (isset($request["photo_{$photoID}_delete"]) || isset($request["label_{$photoID}_delete"]) || isset($request["thermography_{$photoID}_delete"])) { $deleteIDs[] = $photoID; } } // Save images $uploads = array('bu_photo' => 'photo', 'bu_label' => 'label', 'bu_thermography' => 'thermography'); foreach ($uploads as $upload => $kind) { if (isset($_FILES[$upload])) { $tot = count($_FILES[$upload]['name']); for ($i = 0; $i < $tot; $i++) { if ($_FILES[$upload]['error'][$i] == 0) { $deleteIDs = array_merge($deleteIDs, $this->getOldImagesIDs($id, $kind)); $doc_file_id = $this->getDocFileId(); $this->addFile($_FILES[$upload]['name'][$i], 'building', $kind, $doc_file_id, $_FILES[$upload]['tmp_name'][$i]); $doct_id = R3EcoGisHelper::getDocumentTypeIdByCode(strtoupper("BUILDING_{$kind}")); $sql = "INSERT INTO document (doc_object_id, doct_id, doc_file_id, doc_file, doc_date) VALUES ({$id}, {$doct_id}, {$doc_file_id}, " . $db->quote($_FILES[$upload]['name'][$i]) . ", NOW()) "; $db->exec($sql); } } } } // Save map if (isset($request['geometryStatus']) && strtoupper($request['geometryStatus']) == 'CHANGED') { $session_id = session_id(); $sql = "UPDATE building\n SET the_geom=foo.the_geom\n FROM (SELECT MULTI(ST_Force_2d(ST_union(ST_Buffer(the_geom, 0.0)))) AS the_geom FROM edit_tmp_polygon WHERE session_id='{$session_id}') AS foo\n WHERE bu_id={$id}"; $db->exec($sql); } } else { $id = $this->applyData($request); $deleteIDs = $this->getOldImagesIDs($id, null); // Delete old images } $db->commit(); R3EcoGisEventNotifier::notifyDataChanged($this, array('data_changed' => true)); $this->removeOldFilesByIDs(array_unique($deleteIDs)); R3EcoGisCacheHelper::resetMapPreviewCache(null); return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataDoneBuilding({$id})"); } }
/** * Ajax request to submit data * @param array $request the request * @return array ajax format status */ public function submitFormData($request) { $request = array_merge(array('insert_type' => 'free', 'reinsert' => ''), $request); $db = ezcDbInstance::get(); $data = array(); $errors = array(); if ($request['kind'] == 'street_lighting' && $this->act == 'add') { // Valore finto per bypassare controlli automatici $request['em_id'] = '-1'; } $checkDate = false; if ($this->act != 'del') { switch ($request['insert_type']) { case 'free': $checkDate = true; $data[] = array('act' => $request['act'], 'co_start_date' => forceISODate($request['co_start_date_free']), 'co_end_date' => forceISODate($request['co_end_date_free']), 'co_value' => forceFloat($request['co_value_free'], null, '.'), 'co_bill' => forceFloat($request['co_bill_free'], null, '.'), 'co_bill_is_calculated' => 'F', 'em_id' => $request['em_id'], 'co_id' => forceInteger($request['id'], 0, false, '.')); break; case 'month': for ($i = 0; $i < 12; $i++) { if ($request['co_start_date_month'][$i] != '' && $request['co_end_date_month'][$i] != '' && $request['co_value_month'][$i] != '' && $request['co_bill_month'][$i] != '') { $data[] = array('act' => $request['act'], 'co_start_date' => forceISODate($request['co_start_date_month'][$i]), 'co_end_date' => forceISODate($request['co_end_date_month'][$i]), 'co_value' => forceFloat($request['co_value_month'][$i], null, '.'), 'co_bill' => forceFloat($request['co_bill_month'][$i], null, '.'), 'co_bill_is_calculated' => 'F', 'em_id' => $request['em_id']); } } if (count($data) == 0) { $errors['dummy'] = array('CUSTOM_ERROR' => _('Impossibile salvare. Nessun dato valido inserito')); } break; case 'year': $data[] = array('act' => $request['act'], 'co_start_date' => forceISODate($request['co_start_date_year']), 'co_end_date' => forceISODate($request['co_end_date_year']), 'co_value' => forceFloat($request['co_value_year'], null, '.'), 'co_bill' => forceFloat($request['co_bill_year'], null, '.'), 'co_bill_is_calculated' => 'F', 'em_id' => $request['em_id']); break; } foreach ($data as $values) { $errors = $this->checkFormData($values, $errors); } if ($checkDate) { // Verifica data inserimento per bollette singole if (forceISODate($request['co_start_date_free']) > forceISODate($request['co_end_date_free'])) { $errors['co_end_date_bis'] = array('CUSTOM_ERROR' => _("La data di fine periodo precedenta a quella di inizio")); } } } if (count($errors) > 0) { return $this->getAjaxErrorResult($errors); } else { if ($this->act == 'del') { $request['co_id'] = forceInteger($request['id'], 0, false, '.'); if ($request['kind'] == 'street_lighting') { // Ricavo contatore finto per cancellazione $db->beginTransaction(); $em_id = $db->query("SELECT em_id FROM consumption WHERE co_id={$request['co_id']}")->fetchColumn(); $id = $this->applyData($request); if ($db->query("SELECT COUNT(*) FROM consumption WHERE em_id={$em_id}")->fetchColumn() == 0) { $db->exec("DELETE FROM energy_meter WHERE em_id={$em_id}"); } $db->commit(); } else { $id = $this->applyData($request); } } else { $db->beginTransaction(); if ($request['kind'] == 'street_lighting' && $this->act == 'add') { $em_id = R3EcoGisHelper::getDummyEnergyMeter('STREET_LIGHTING', $request['sl_id']); if ($em_id == '') { // Aggiungo contatore finto per tratto stradale $electricityData = $this->getElectricityUDMData($_SESSION['do_id']); $em_id = R3EcoGisHelper::addDummyEnergyMeter(array('esu_id' => $electricityData['esu_id'], 'em_object_id' => $request['sl_id']), 'STREET_LIGHTING'); } $data[0]['em_id'] = $em_id; } $id = array(); foreach ($data as $values) { $id[] = $this->applyData($values); } $db->commit(); } R3EcoGisEventNotifier::notifyDataChanged($this, array('data_changed' => true)); return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataDoneConsumption(" . json_encode($id) . ", '{$request['reinsert']}')"); } }