Example #1
0
 public function prepareFieldValue($act, $key, $value, $type, $size = null, $default = null)
 {
     $db = ezcDbInstance::get();
     switch ($type) {
         case 'real':
         case 'double':
         case 'number':
         case 'float':
             if ((string) $value == '') {
                 return $this->null2text($default);
             }
             if (!is_numeric($value)) {
                 $value = forceFloat($value, null, '.');
             }
             return (string) $value;
         case 'year':
         case 'integer':
             if ((string) $value == '') {
                 return $this->null2text($default);
             }
             if (!is_numeric($value)) {
                 $value = forceInteger($value);
             }
             return (string) $value;
         case 'boolean':
             if ($value == '') {
                 return 'FALSE';
             }
             return strtoupper(substr($value, 0, 1)) == 'T' || $value == 1 || $value === true ? 'TRUE' : 'FALSE';
         case 'lookup':
         case 'domain':
             if ((string) $value == '') {
                 return $this->null2text($default);
             }
             return $value;
         case 'date':
             if ($value == '') {
                 return $this->null2text($default);
             }
             return $db->quote(forceISODate($value, null, 'ISO'));
         case 'string':
         case 'color':
         case 'text':
         case 'memo':
             if ($value == '') {
                 return $this->null2text($default, true, true);
             }
             if ($size > 0) {
                 return $db->quote(mb_substr($value, 0, $size));
             }
             return $db->quote($value);
         case 'geometry':
             if ($value == '') {
                 return $this->null2text($default);
             }
             return $db->quote($value);
         default:
             return $value;
     }
 }
Example #2
0
 public function submitFormDataDetail($request)
 {
     $db = ezcDbInstance::get();
     if (isset($request['gpm_date']) && isset($request['gpm_value_1'])) {
         // Insert details
         $sql = "DELETE FROM ecogis.global_plain_monitor WHERE gpr_id={$request['gpr_id']}";
         $db->exec($sql);
         $sql = "INSERT INTO ecogis.global_plain_monitor (gpr_id, gpg_id, gpm_date, gpm_value_1, gpm_value_2) VALUES (?, ?, ?, ?, ?)";
         $stmt = $db->prepare($sql);
         for ($i = 0; $i < count($request['gpg_id']); $i++) {
             $gpg_id = empty($request['gpg_id'][$i]) ? null : $request['gpg_id'][$i];
             $gpm_date = forceISODate($request['gpm_date'][$i]);
             $gpm_value_1 = forceFloat($request['gpm_value_1'][$i], null, '.');
             $gpm_value_2 = forceFloat($request['gpm_value_2'][$i], null, '.');
             if (!empty($gpm_date) && !empty($gpm_value_1)) {
                 $stmt->execute(array($request['gpr_id'], $gpg_id, $gpm_date, $gpm_value_1, $gpm_value_2));
             }
         }
     }
 }
Example #3
0
 public function __construct(array $request = array(), array $opt = array())
 {
     parent::__construct($request, $opt);
     $this->fields = $this->defFields();
     $storeVar = isset($_GET['act']) && $_GET['act'] == 'list';
     // if true store the filter variables
     $this->alternativeSimulation = false;
     // Simulazione su tutti gli oggetti e non solo quelli comunali
     $init = array_key_exists('init', $this->request);
     $reset = array_key_exists('reset', $this->request);
     if ($init || $reset) {
         $storeVar = true;
     }
     $this->id = initVar('id');
     $this->last_id = initVar('last_id');
     $this->act = initVar('act', 'list');
     $this->select_done = initVar('select_done');
     $this->do_id = $_SESSION['do_id'];
     $this->pr_id = PageVar('pr_id', null, $init | $reset, false, $this->baseName, $storeVar);
     $this->mu_id = PageVar('mu_id', null, $init | $reset, false, $this->baseName, $storeVar);
     $this->mu_name = PageVar('mu_name', null, $init | $reset, false, $this->baseName, $storeVar);
     $this->sw_title = PageVar('sw_title', null, $init | $reset, false, $this->baseName, $storeVar);
     $this->sw_date_from = forceISODate(PageVar('sw_date_from', null, $init | $reset, false, $this->baseName, $storeVar));
     $this->sw_date_to = forceISODate(PageVar('sw_date_to', null, $init | $reset, false, $this->baseName, $storeVar));
     $this->order = PageVar('order', '1A', $init, false, $this->baseName, $storeVar);
     $this->pg = PageVar('pg', 0, $init | $reset, false, $this->baseName, $storeVar);
     $this->registerAjaxFunction('getHelp');
     $this->registerAjaxFunction('calculateTotals');
     $this->registerAjaxFunction('recalculateSimulation');
     $this->registerAjaxFunction('getSummaryTable');
     $this->registerAjaxFunction('askDelSimulation');
     $this->registerAjaxFunction('getGlobalStrategy');
     $this->registerAjaxFunction('submitFormData');
 }
Example #4
0
 /**
  * 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']}')");
     }
 }