コード例 #1
0
ファイル: obj.document.php プロジェクト: r3-gis/EcoGIS
 /**
  * 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})");
     }
 }
コード例 #2
0
ファイル: obj.building.php プロジェクト: r3-gis/EcoGIS
 /**
  * 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})");
     }
 }
コード例 #3
0
ファイル: obj.import_seap.php プロジェクト: r3-gis/EcoGIS
 /**
  * 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})");
 }