/** * 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})"); } }