public function delCache($request) { if (isset($request['del_preview_map']) && $request['del_preview_map'] == 'T') { R3EcoGisCacheHelper::resetMapPreviewCache(null); } if (isset($request['del_preview_photo']) && $request['del_preview_photo'] == 'T') { R3EcoGisCacheHelper::resetPhotoPreviewCache(null); } if (isset($request['del_temp_files']) && $request['del_temp_files'] == 'T') { R3EcoGisCacheHelper::removeTmpFiles(); R3EcoGisCacheHelper::removeMapOutputFiles(null, true); } return array('status' => R3_AJAX_NO_ERROR); }
/** * 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) { $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})"); } } }
public static function addCacheElement($do_id, $object, $object_id, $fileName, $lang, $tollerance) { ezcLog::getInstance()->log(__METHOD__ . "({$do_id}, {$object}, {$object_id}, {$fileName}, {$lang}, {$tollerance}) called", ezcLog::DEBUG); $db = ezcDbInstance::get(); $ca_id = R3EcoGisCacheHelper::getCacheId(); ezcLog::getInstance()->log(__METHOD__ . ": CacheID: {$ca_id}", ezcLog::INFO); $cat_id = $db->query("SELECT cat_id FROM cache_type WHERE cat_code=" . $db->quote(strtoupper($object)))->fetchColumn(); $sql = "INSERT INTO cache (ca_id, do_id, ca_object_id, cat_id, ca_lang, ca_tollerance)\r\n VALUES ({$ca_id}, {$do_id}, {$object_id}, {$cat_id}, {$lang}, " . $db->quote($tollerance) . ")"; $db->exec($sql); $path = R3_CACHE_DIR . strtolower($object) . '/' . sprintf(CACHE_MASK, $object_id / CACHE_DIR_LIMIT) . '/'; $name = sprintf(CACHE_MASK, $object_id) . "_{$lang}_{$tollerance}" . CACHE_EXT; if (!file_exists($path)) { ezcLog::getInstance()->log(__METHOD__ . ": Creating directory {$path}", ezcLog::INFO); mkdir($path); } if ($fileName != '') { ezcLog::getInstance()->log(__METHOD__ . ": Coping {$fileName} => {$path}{$name}", ezcLog::INFO); copy($fileName, "{$path}{$name}"); return $ca_id; } return false; }