function submitForm($elems, $doneFunc = 'AjaxFormObj.checkDone', $errFunc = 'AjaxFormObj.checkError') { global $lbl, $txt; $auth = R3AuthInstance::get(); $fieldDescr = array('app_code' => array(MISSING_FIELD => "Il campo 'applicazione' e' obbligatorio", INVALID_FIELD => "Il campo 'applicazione' contiene caratteri non validi. Solo lettere e numeri sono accettati", PK_ERROR => "Il campo 'codice' immesso esiste gia'"), 'app_name' => array(MISSING_FIELD => "Il campo 'nome' e' obbligatorio")); $elems = AjaxSplitArray($elems); $objResponse = new xajaxResponse(); $error = array(); try { $privileges = array(); if (isset($elems['selectedPrivileges'])) { foreach (explode(",", $elems['selectedPrivileges']) as $value) { $a = explode("|", $value); if (count($a) == 2) { $privileges[] = array('ac_verb' => $a[0], 'ac_name' => $a[1], 'ga_kind' => 'ALLOW'); } } } if ($elems['act'] == 'add') { /** add a new application */ $auth->addGroup(strtoupper(trim($elems['app_code'])), strtoupper(trim($elems['gr_name'])), strtoupper(trim($elems['dn_name'])), $elems['gr_descr'], $privileges); } else { if ($elems['act'] == 'mod') { /** modify an application */ $auth->modGroup(strtoupper(trim($elems['old_app_code'])), strtoupper(trim($elems['old_gr_name'])), strtoupper(trim($elems['app_code'])), strtoupper(trim($elems['gr_name'])), strtoupper(trim($elems['dn_name'])), $elems['gr_descr'], $privileges); } else { if ($elems['act'] == 'del') { /** delete an application */ $auth->delGroup($elems['app_code'], $elems['gr_name']); } else { throw new Exception('Invalid action'); } } } } catch (EPermissionDenied $e) { $error['element'][] = ''; $error['message'][] = $e->getMessage(); } catch (EDatabaseError $e) { $error['element'][] = ''; $error['message'][] = "Database error: " . $e->getMessage(); } catch (EInputError $e) { $error['element'][] = $e->getField(); if (isset($fieldDescr[$e->getField()][$e->getCode()])) { $error['message'][] = $fieldDescr[$e->getField()][$e->getCode()]; } else { $error['message'][] = $e->getMessage(); } } catch (Exception $e) { $error['element'][] = ''; $error['message'][] = 'Generic error: ' . $e->getMessage(); } // Action if (count($error) > 0) { $errText = $txt['err_store_failed'] . "\n - " . implode("\n - ", $error['message']); $objResponse->addScriptCall($errFunc, $errText, $error['element'][0]); } else { $objResponse->addScriptCall($doneFunc); } return $objResponse->getXML(); }
public function resetTableColumnToDefault($result) { // get data from class $obj = R3Controller::factory(array('on' => $this->module)); $tableConfig = new R3BaseTableConfig(R3AuthInstance::get()); $tableConfig->resetConfig($this->module); return array('status' => R3_AJAX_NO_ERROR); }
function submitForm($elems, $doneFunc = 'AjaxFormObj.checkDone', $errFunc = 'AjaxFormObj.checkError') { global $lbl, $txt; $auth = R3AuthInstance::get(); $fieldDescr = array('app_code' => array(MISSING_FIELD => !isset($txt['missing_fld_app']) ? _("Il campo 'applicazione' e' obbligatorio") : $txt['missing_fld_app'], INVALID_FIELD => "Il campo 'codice' contiene caratteri non validi. Solo lettere e numeri sono accettati", PK_ERROR => "Il campo 'codice' immesso esiste gia'"), 'app_name' => array(MISSING_FIELD => "Il campo 'nome' e' obbligatorio")); // print_r($elems); $elems = AjaxSplitArray($elems); //print_r($elems); $objResponse = new xajaxResponse(); $error = array(); try { if ($elems['act'] == 'add') { /** add a new acname */ foreach (explode(',', str_replace(';', ',', $elems['ac_verb'])) as $verb) { $auth->addACName($elems['app_code'], strtoupper(trim($verb)), strtoupper(trim($elems['ac_name'])), trim($elems['ac_descr']), trim($elems['ac_order']), strtoupper($elems['ac_active']) == 'T', array('ac_type' => strtoupper($elems['ac_type']))); } } else { if ($elems['act'] == 'mod') { /** modify an acname */ $auth->modACName($elems['old_app_code'], $elems['old_ac_verb'], $elems['old_ac_name'], $elems['app_code'], strtoupper(trim($elems['ac_verb'])), strtoupper(trim($elems['ac_name'])), trim($elems['ac_descr']), trim($elems['ac_order']), strtoupper($elems['ac_active']) == 'T', array('ac_type' => strtoupper($elems['ac_type']))); } else { if ($elems['act'] == 'del') { /** delete an acname */ $auth->delACName($elems['app_code'], $elems['ac_verb'], $elems['ac_name']); } else { throw new Exception('Invalid action'); } } } } catch (EPermissionDenied $e) { $error['element'][] = ''; $error['message'][] = $e->getMessage(); } catch (EDatabaseError $e) { $error['element'][] = ''; $error['message'][] = "Database error: " . $e->getMessage(); } catch (EInputError $e) { $error['element'][] = $e->getField(); if (isset($fieldDescr[$e->getField()][$e->getCode()])) { $error['message'][] = $fieldDescr[$e->getField()][$e->getCode()]; } else { $error['message'][] = $e->getMessage(); } } catch (Exception $e) { $error['element'][] = ''; $error['message'][] = 'Generic error: ' . $e->getMessage(); } // Action if (count($error) > 0) { $errText = (!isset($txt['err_store_failed']) ? _("Salvataggio fallito") . ":" : $txt['err_store_failed']) . "\n - " . implode("\n - ", $error['message']); $objResponse->addScriptCall($errFunc, $errText, $error['element'][0]); } else { $objResponse->addScriptCall($doneFunc); } return $objResponse->getXML(); }
/** * Create the table header * param string $order The table order */ public function createListTableHeader(&$order) { $tableConfig = new R3BaseTableConfig(R3AuthInstance::get()); $tableColumns = $tableConfig->getConfig($this->getTableColumnConfig(), $this->baseName); foreach ($tableColumns as $fieldName => $colDef) { if ($colDef['visible']) { $this->simpleTable->addSimpleField($colDef['label'], $fieldName, $colDef['type'], $colDef['width'], $colDef['options']); } } $this->simpleTable->addSimpleField(_('Azione'), '', 'link', 85); $this->tableHtml = $this->simpleTable->CreateTableHeader($order, 'global_strategy_list_table'); }
public function __construct() { global $lang; // Need this to avoid problems with the application (while lang is global) $objlang = $lang; if (empty($objlang)) { $objlang = isset($_SESSION['lang']) ? $_SESSION['lang'] : 'it'; } if ($objlang == 1) { $objlang = 'it'; } if ($objlang == 2) { $objlang = 'de'; } $auth = R3AuthInstance::get(); $this->jsDefaultVars = array('js_lang' => $objlang); if (!defined('R3_UM_JQUERY') || !R3_UM_JQUERY) { $this->jsDefaultFiles = array(R3_JS_URL . "simplecalendar.js"); } else { $this->jsDefaultFiles = array(R3_JS_URL . "jquery/jquery.js", R3_JS_URL . "jquery/plugins/jquery.cookie.js", R3_JS_URL . "jquery/ui/ui.core.js", R3_JS_URL . "jquery/ui/ui.tabs.js", R3_JS_URL . "jquery/ui/ui.datepicker.js", R3_JS_URL . "jquery/ui/i18n/ui.datepicker-{$objlang}.js", R3_JS_URL . "r3um.js"); } $this->jsDefaultFiles[] = R3_JS_URL . "charset.js"; $this->jsDefaultFiles[] = R3_JS_URL . "xajax_required_tag.js"; $this->jsDefaultFiles[] = R3_JS_URL . "ajax_select.js"; $this->cssDefaultFiles = array(R3_CSS_URL . "default.css", R3_CSS_URL . "user_manager.css", R3_CSS_URL . "simpletable.css"); if (!defined('R3_UM_JQUERY') || !R3_UM_JQUERY) { $this->cssDefaultFiles[] = R3_CSS_URL . "calendar.css"; } else { if ($auth->getConfigValue('SETTINGS', 'THEMA', '') != '') { $this->cssDefaultFiles[] = R3_CSS_URL . $auth->getConfigValue('SETTINGS', 'THEMA', '') . ".css"; $this->cssDefaultFiles[] = R3_JS_URL . "jquery/themes/r3gis/" . $auth->getConfigValue('SETTINGS', 'THEMA', '') . "/r3gis.css"; } else { $this->cssDefaultFiles[] = R3_JS_URL . "jquery/themes/r3gis/r3gis.css"; } } }
static function set(IR3Auth $auth) { return self::$instance = $auth; }
/** * Create the table header * param string $order The table order */ public function createListTableHeader(&$order) { $this->simpleTable->addSimpleField(_('Codice'), 'gt_code', 'text', 150, array('sortable' => true)); $this->simpleTable->addSimpleField(_('Nome') . getLangNameShort(1), 'gt_name_1', 'text', null, array('sortable' => true)); if (R3AuthInstance::get()->getConfigValue('APPLICATION', 'NUM_LANGUAGES', 1) > 1) { $this->simpleTable->addSimpleField(_('Nome') . getLangNameShort(2), 'gt_name_2', 'text', null, array('sortable' => true)); } $this->simpleTable->addSimpleField(_('Nome') . getLangNameShort(3), 'gt_name_3', 'text', null, array('sortable' => true)); $this->simpleTable->addSimpleField(_('Azione'), '', 'link', 50); $this->tableHtml = $this->simpleTable->CreateTableHeader($order); }
require_once R3_APP_ROOT . 'lib/r3_auth_gui_start.php'; } if (!defined("__R3_AUTH__")) { require_once R3_APP_ROOT . 'lib/r3auth.php'; } require_once R3_APP_ROOT . 'lib/r3auth_manager.php'; require_once R3_APP_ROOT . 'lib/default.um.php'; require_once R3_APP_ROOT . 'lib/r3auth_impexp.php'; require_once R3_APP_ROOT . 'lib/storevar.php'; require_once R3_APP_ROOT . 'lib/xajax.php'; require_once R3_APP_ROOT . 'lang/lang.php'; /** Authentication and permission check */ $auth = new R3AuthManagerImpExp($mdb2, $auth_options, APPLICATION_CODE); if (is_null($auth)) { $auth = new R3AuthManagerImpExp($mdb2, $auth_options, APPLICATION_CODE); R3AuthInstance::set($auth); } if (!$auth->isAuth()) { Header("location: logout.php?status=" . $auth->getStatusText()); die; } if (!$auth->hasPerm('IMPORT', 'CONFIG') && !$auth->hasPerm('IMPORT', 'ACNAME')) { die("PERMISSION DENIED\n"); } if (file_exists(R3_APP_ROOT . 'lib/custom.um.php')) { require_once R3_APP_ROOT . 'lib/custom.um.php'; $umDependenciesObj = getUmDependenciesObject(); } else { $umDependenciesObj = new R3UmDependenciesDefault(); } $smarty->assign('umDependencies', $umDependenciesObj->get());
/** * ecogis.building_purpose_use fields definition */ public function defFields() { $fields = array(array('name' => 'bpu_id', 'type' => 'number', 'is_primary_key' => true), array('name' => 'do_id', 'type' => 'domain'), array('name' => 'bpu_name_1', 'type' => 'text', 'size' => 80, 'width' => array(null, 300), 'required' => true, 'label' => _('Nome') . getLangNameShort(1), 'list' => true, 'edit' => true, 'delete_name' => true), array('name' => 'bpu_name_2', 'type' => 'text', 'size' => 80, 'width' => array(null, 300), 'label' => _('Nome') . getLangNameShort(2), 'required' => R3AuthInstance::get()->getConfigValue('APPLICATION', 'NUM_LANGUAGES', 1) > 1, 'visible' => R3AuthInstance::get()->getConfigValue('APPLICATION', 'NUM_LANGUAGES', 1) > 1), array('name' => 'bpu_has_extradata', 'type' => 'boolean', 'width' => 80, 'label' => _('Dati aggiuntivi'), 'visible' => true), array('name' => 'bpu_order', 'type' => 'number', 'required' => true, 'default' => 0, 'width' => 100, 'label' => _('Ordinamento')), array('name' => 'gc_id', 'type' => 'lookup', 'label' => _('Categoria inventario fissa'), 'lookup' => array('table' => 'global_category_data', 'list_field' => "gc_full_name_<LANG>")), array('name' => 'sbpu_id', 'type' => 'lookup', 'label' => _('Categoria pubblica'), 'width' => 150, 'lookup' => array('table' => 'stat_building_purpose_use', 'list_field' => "sbpu_name_<LANG>"), 'visible' => R3AuthInstance::get()->getConfigValue('APPLICATION', 'ENABLE_PUBLIC_SITE', 'F') == 'T')); return $fields; }
public function defFields() { $fields = array(array('name' => 'st_id', 'type' => 'number', 'is_primary_key' => true), array('name' => 'st_parent_id', 'type' => 'lookup', 'label' => _('Principale'), 'required' => true, 'width' => 200, 'lookup' => array('table' => $this->table, 'list_field' => 'st_title_short_<LANG>', 'alias' => 'get_name', 'pk' => array('st_parent_id', 'st_id'), 'where' => "st_parent_id IS NULL AND (do_id IS NULL OR do_id={$this->do_id})"), 'filter' => array('type' => 'select', 'fields' => array('st_id', 'st_title_short_<LANG>'), 'where' => "st_parent_id IS NULL AND (do_id IS NULL OR do_id={$this->do_id})", 'orderby' => 'st_order, st_title_short_<LANG>')), array('name' => 'st_order', 'type' => 'number', 'required' => true, 'default' => 0, 'width' => 40, 'label' => _('Ordinamento')), array('name' => 'st_code', 'type' => 'text', 'required' => true, 'label' => _('Codice')), array('name' => 'st_title_short_1', 'type' => 'text', 'required' => true, 'label' => _('Titolo corto') . getLangNameShort(1)), array('name' => 'st_title_short_2', 'type' => 'text', 'label' => _('Titolo corto') . getLangNameShort(2), 'required' => R3AuthInstance::get()->getConfigValue('APPLICATION', 'NUM_LANGUAGES', 1) > 1, 'visible' => R3AuthInstance::get()->getConfigValue('APPLICATION', 'NUM_LANGUAGES', 1) > 1), array('name' => 'st_title_long_1', 'type' => 'text', 'label' => _('Titolo lungo') . getLangNameShort(1), 'list' => false), array('name' => 'st_title_long_2', 'type' => 'text', 'label' => _('Titolo lungo') . getLangNameShort(2), 'visible' => R3AuthInstance::get()->getConfigValue('APPLICATION', 'NUM_LANGUAGES', 1) > 1, 'list' => false), array('name' => 'st_has_absolute_data', 'type' => 'boolean', 'width' => 50, 'label' => _('Dati assoluti')), array('name' => 'st_udm_1', 'type' => 'text', 'label' => _('Unità di misura assoluta') . getLangNameShort(1), 'list' => false), array('name' => 'st_udm_2', 'type' => 'text', 'label' => _('Unità di misura assoluta') . getLangNameShort(2), 'visible' => R3AuthInstance::get()->getConfigValue('APPLICATION', 'NUM_LANGUAGES', 1) > 1, 'list' => false), array('name' => 'st_has_relative_data', 'type' => 'boolean', 'width' => 50, 'label' => _('Dati relativi')), array('name' => 'st_udm_relative_1', 'type' => 'text', 'label' => _('Unità di misura relativa') . getLangNameShort(1), 'list' => false), array('name' => 'st_udm_relative_2', 'type' => 'text', 'label' => _('Unità di misura relativa') . getLangNameShort(2), 'visible' => R3AuthInstance::get()->getConfigValue('APPLICATION', 'NUM_LANGUAGES', 1) > 1, 'list' => false), array('name' => 'st_descr_1', 'type' => 'memo', 'label' => _('Descrizione superiore') . getLangNameShort(1), 'list' => false), array('name' => 'st_descr_2', 'type' => 'memo', 'label' => _('Descrizione superiore') . getLangNameShort(2), 'visible' => R3AuthInstance::get()->getConfigValue('APPLICATION', 'NUM_LANGUAGES', 1) > 1, 'list' => false), array('name' => 'st_lower_descr_1', 'type' => 'memo', 'label' => _('Descrizione inferiore') . getLangNameShort(1), 'list' => false), array('name' => 'st_lower_descr_2', 'type' => 'memo', 'label' => _('Descrizione inferiore') . getLangNameShort(2), 'visible' => R3AuthInstance::get()->getConfigValue('APPLICATION', 'NUM_LANGUAGES', 1) > 1, 'list' => false), array('name' => 'st_enable', 'type' => 'boolean', 'width' => 50, 'label' => _('Attiva (calcolata)')), array('name' => 'st_visible', 'type' => 'boolean', 'width' => 50, 'label' => _('Visibile (su sito pubblico)')), array('name' => 'st_has_province_data', 'type' => 'boolean', 'width' => 50, 'label' => _('Statistica con dati provinciali')), array('name' => 'st_has_municipality_data', 'type' => 'boolean', 'width' => 50, 'label' => _('Statistica con dati comunali')), array('name' => 'st_has_year', 'type' => 'boolean', 'width' => 50, 'label' => _('Statistica con periodo temporale')), array('name' => 'st_has_building_purpose_use', 'type' => 'boolean', 'width' => 50, 'label' => _("Filtro per dest.uso")), array('name' => 'st_has_building_build_year', 'type' => 'boolean', 'width' => 50, 'label' => _('Filtro per periodo costruzione')), array('name' => 'st_render_preview_as_grid', 'type' => 'boolean', 'width' => 50, 'label' => _('Rendering anteprima con griglia'))); return $fields; }
public function canAdd() { return R3AuthInstance::get()->hasPerm('ADD', 'STREET'); }
$menu->addSimpleItem('config', 'utility', array('label' => _('Fornitori di energia'), 'js' => R3MenuNavigate('list', 'utility', 'init'))); if ($auth->hasPerm('SHOW', 'ALL_DOMAINS')) { $menu->addSimpleItem('config', 'global_energy_source_main', array('label' => _('Tipo fonte (PAES)'), 'js' => R3MenuNavigate('lookup_list', 'global_energy_source_main', 'init'))); $menu->addSimpleItem('config', 'global_energy_source', array('label' => _('Tipo alimentazione (PAES)'), 'js' => R3MenuNavigate('lookup_list', 'global_energy_source', 'init'))); $menu->addSimpleItem('config', 'global_category_main', array('label' => _('Macrocategorie/macrosettori tabelle (PAES)'), 'js' => R3MenuNavigate('lookup_list', 'global_category_main', 'init'))); $menu->addSimpleItem('config', 'global_category', array('label' => _('Categorie/settori tabelle (PAES)'), 'js' => R3MenuNavigate('lookup_list', 'global_category', 'init'))); if ($auth->hasPerm('SHOW', 'GLOBAL_RESULT_TABLE_BUILDER')) { $menu->addSimpleItem('config', 'global_result_table_builder', array('label' => _('Tabelle inventario (PAES)'), 'js' => R3MenuNavigate('list', 'global_result_table_builder', 'init'))); } $menu->addSimpleItem('config', 'global_action', array('label' => _('Azioni principali (PAES)'), 'js' => R3MenuNavigate('lookup_list', 'global_action', 'init'))); if ($auth->hasPerm('SHOW', 'GLOBAL_ACTION_BUILDER')) { $menu->addSimpleItem('config', 'global_action_builder', array('label' => _('Azioni principali/categoria (PAES)'), 'js' => R3MenuNavigate('list', 'global_action_builder', 'init'))); } } $menu->addSimpleItem('config', 'global_method', array('label' => _('Fonte dati inventario (PAES)'), 'js' => R3MenuNavigate('lookup_list', 'global_method', 'init'))); if (R3AuthInstance::get()->getConfigValue('APPLICATION', 'ENABLE_PUBLIC_SITE', 'F') == 'T') { $menu->addItem('config', '', '-'); $menu->addSimpleItem('config', 'stat_general', array('label' => _("Statistiche - Generale"), 'js' => R3MenuNavigate('edit', 'stat_general', 'init'))); $menu->addSimpleItem('config', 'stat_type', array('label' => _('Statistiche - Definizioni'), 'js' => R3MenuNavigate('list', 'stat_type', 'init'))); } } if ($auth->hasPerm('SHOW', 'ALL_DOMAINS') && $auth->hasPerm('SET', 'CACHE')) { $menu->addSimpleItem('admin', 'cache', array('label' => _('Gestione cache'), 'js' => R3MenuNavigate('edit', 'cache', 'init'))); } if ($auth->hasPerm('SHOW', 'ALL_DOMAINS') && $auth->hasPerm('SHOW', 'CUSTOMER')) { $menu->addSimpleItem('admin', 'customer', array('label' => _('Gestione enti'), 'js' => R3MenuNavigate('list', 'customer', 'init'))); } if ($auth->hasPerm('SHOW', 'MUNICIPALITY_COLLECTION')) { $menu->addSimpleItem('admin', 'municipality_collection', array('label' => _('Raggruppamenti di comuni'), 'js' => R3MenuNavigate('list', 'municipality_collection', 'init'))); } if ($auth->hasPerm('SHOW', 'PUBLIC_USER')) {
public function canAdd() { return R3AuthInstance::get()->hasPerm('ADD', 'ALL_LOOKUP'); }
public function createListTableHeader(&$order) { $this->columnTypes = array(); $tableConfig = new R3BaseTableConfig(R3AuthInstance::get()); $tableColumns = $tableConfig->getConfig($this->getTableColumnConfig(), $this->baseName); foreach ($tableColumns as $fieldName => $colDef) { $this->columnTypes[$fieldName] = array('type' => strtolower($colDef['type']), 'options' => $colDef['options']); if ($colDef['visible']) { $this->simpleTable->addSimpleField($colDef['label'], $fieldName, 'CALCULATED', $colDef['width'], $colDef['options']); } } if ($this->hasInvalidSimulation()) { $this->simpleTable->addSimpleField(_('Stato'), 'status', 'CALCULATED', 100); } $this->simpleTable->addSimpleField(_('Azione'), '', 'link', 85); $this->tableHtml = $this->simpleTable->CreateTableHeader($order, 'global_strategy_list_table'); }
/** * * @param <type> $ge_id * @param <type> $kind * @param <type> $divider Return the table data */ private static function getDataMunicipality($do_id, $gp_id) { $lang = R3Locale::getLanguageID(); $db = ezcDbInstance::get(); $auth = R3AuthInstance::get(); $calculateCategorySum = $auth->getConfigValue('APPLICATION', 'CALCULATE_GLOBAL_PLAIN_TOTALS', 'T') == 'T'; $other = _('Altro'); $sql = "SELECT gc1.gc_id,gc1.gc_parent_id,gc1.do_id,\r\n gc2.gc_code AS gc_code_main,gc2.gc_name_{$lang} AS gc_name_main,gc2.gc_order AS gc_order_main,\r\n gc1.gc_code, gc1.gc_name_{$lang} AS gc_name, gc1.gc_order,\r\n gps_id,gps.gp_id AS pg_id_sum,gps_expected_energy_saving,gps_expected_renewable_energy_production,gps_expected_co2_reduction,\r\n BOOL2TEXT(gc1.gc_has_extradata) AS gc_has_extradata, gpr_id,\r\n CASE WHEN gc_extradata_{$lang} IS NULL THEN gc1.gc_name_{$lang} ELSE gc1.gc_name_{$lang} || ' - ' || gc_extradata_{$lang} END AS gc_fullname,\r\n gpr.gpa_id, gpa.gpa_code, \r\n \r\n CASE WHEN gpr.gpa_extradata_{$lang} IS NULL THEN gpa_name_{$lang}\r\n ELSE CASE WHEN UPPER(gpa_name_{$lang})=UPPER('{$other}') THEN gpr.gpa_extradata_{$lang}\r\n ELSE gpa_name_{$lang} || ' - ' || gpr.gpa_extradata_{$lang}\r\n END \r\n END AS gpa_name,\r\n gpr_descr_{$lang} AS gpr_descr, gpr_responsible_department_{$lang} AS gpr_responsible_department,\r\n gpr_start_date, gpr_end_date, gpr_estimated_cost, gpr_expected_energy_saving, gpr_expected_renewable_energy_production,\r\n gpr_expected_co2_reduction, gpr_imported_row, gpr_gauge_type\r\n FROM ecogis.global_category gc1\r\n INNER JOIN ecogis.global_category gc2 ON gc1.gc_parent_id=gc2.gc_id\r\n LEFT JOIN ecogis.global_plain_row gpr ON gc1.gc_id=gpr.gc_id AND gpr.gp_id={$gp_id}\r\n LEFT JOIN ecogis.global_plain_action gpa ON gpa.gpa_id=gpr.gpa_id\r\n LEFT JOIN ecogis.global_plain_sum gps ON gc2.gc_id=gps.gc_id and gps.gp_id={$gp_id}\r\n WHERE (gc1.do_id IS NULL OR gc1.do_id={$do_id}) AND gc1.gc_global_plain IS TRUE AND gc2.gc_global_plain IS TRUE AND\r\n gc1.gc_visible IS TRUE and gc2.gc_visible IS TRUE\r\n ORDER BY gc_order_main, gc_name_main, gc_order, gc_name, gc_fullname, gpr_order, gpa_name, gpr_id"; $result = array(); $sumData = array(); // Serve per somme di categoria e totali foreach ($db->query($sql, PDO::FETCH_ASSOC) as $row) { $progress = R3EcoGisGlobalPlainHelper::getActionStatus($row['gpr_id']); // Dati per somma totali categoria (e totalone) if (!isset($sumData[$row['gc_parent_id']])) { $sumData[$row['gc_parent_id']] = array('energy_tot' => null, 'emission_tot' => null); } if ($progress['energy_tot'] != '') { $sumData[$row['gc_parent_id']]['energy_tot'] += $progress['energy_tot']; } if ($progress['emission_tot'] != '') { $sumData[$row['gc_parent_id']]['emission_tot'] += $progress['emission_tot']; } if (!isset($result['data'][$row['gc_parent_id']]['rowspan'])) { $result['data'][$row['gc_parent_id']]['rowspan'] = 0; } if (!isset($result['data'][$row['gc_parent_id']]['sum'])) { $result['data'][$row['gc_parent_id']]['sum'] = array('expected_energy_saving' => null, 'expected_renewable_energy_production' => null, 'expected_co2_reduction' => null, 'progress_energy' => null, 'progress_emission' => null); } $result['data'][$row['gc_parent_id']]['rowspan']++; $result['data'][$row['gc_parent_id']]['gc_id'] = $row['gc_id']; $result['data'][$row['gc_parent_id']]['gc_parent_id'] = $row['gc_parent_id']; $result['data'][$row['gc_parent_id']]['code'] = $row['gc_code_main']; $result['data'][$row['gc_parent_id']]['name'] = $row['gc_name_main']; if ($calculateCategorySum) { // Sum data (ignoring database entry) - New configuration if ($row['gpr_expected_energy_saving'] !== null) { $result['data'][$row['gc_parent_id']]['sum']['expected_energy_saving'] += $row['gpr_expected_energy_saving']; } if ($row['gpr_expected_renewable_energy_production'] !== null) { $result['data'][$row['gc_parent_id']]['sum']['expected_renewable_energy_production'] += $row['gpr_expected_renewable_energy_production']; } if ($row['gpr_expected_co2_reduction'] !== null) { $result['data'][$row['gc_parent_id']]['sum']['expected_co2_reduction'] += $row['gpr_expected_co2_reduction']; } } else { // Use database entry for sum category data (table ecogis.global_plain_sum) - Old configuration. SHould be switched to automatic calculation $result['data'][$row['gc_parent_id']]['sum']['expected_energy_saving'] = $row['gps_expected_energy_saving']; $result['data'][$row['gc_parent_id']]['sum']['expected_renewable_energy_production'] = $row['gps_expected_renewable_energy_production']; $result['data'][$row['gc_parent_id']]['sum']['expected_co2_reduction'] = $row['gps_expected_co2_reduction']; } $result['data'][$row['gc_parent_id']]['categories'][$row['gc_id']]['name'] = $row['gc_name']; $result['data'][$row['gc_parent_id']]['categories'][$row['gc_id']]['code'] = $row['gc_code']; $result['data'][$row['gc_parent_id']]['categories'][$row['gc_id']]['has_extradata'] = $row['gc_has_extradata']; $result['data'][$row['gc_parent_id']]['categories'][$row['gc_id']]['data'][$row['gpr_id']] = array('code' => $row['gpa_code'], 'imported_row' => $row['gpr_imported_row'], 'gauge_type' => $row['gpr_gauge_type'], 'progress_energy' => round($progress['energy_perc'], 1), 'progress_emission' => round($progress['emission_perc'], 1), 'name' => $row['gpa_name'], 'fullname' => $row['gc_fullname'], 'descr' => $row['gpr_descr'], 'responsible_department' => $row['gpr_responsible_department'], 'start_date' => $row['gpr_start_date'], 'end_date' => $row['gpr_end_date'], 'estimated_cost' => $row['gpr_estimated_cost'], 'expected_energy_saving' => $row['gpr_expected_energy_saving'], 'expected_renewable_energy_production' => $row['gpr_expected_renewable_energy_production'], 'expected_co2_reduction' => $row['gpr_expected_co2_reduction']); } $sum = array('expected_energy_saving' => null, 'expected_renewable_energy_production' => null, 'expected_co2_reduction' => null, 'progress_energy' => null, 'progress_emission' => null); $energyTot = null; $emisisonTot = null; foreach ($result['data'] as $row) { if ($row['sum']['expected_energy_saving'] != '') { $sum['expected_energy_saving'] += $row['sum']['expected_energy_saving']; } if ($row['sum']['expected_renewable_energy_production'] != '') { $sum['expected_renewable_energy_production'] += $row['sum']['expected_renewable_energy_production']; } if ($row['sum']['expected_co2_reduction'] != '') { $sum['expected_co2_reduction'] += $row['sum']['expected_co2_reduction']; } // Imposto Percentuali completamento if ($row['sum']['expected_energy_saving'] + $row['sum']['expected_renewable_energy_production'] != 0) { $energyTot += $sumData[$row['gc_parent_id']]['energy_tot']; $result['data'][$row['gc_parent_id']]['sum']['progress_energy'] = round($sumData[$row['gc_parent_id']]['energy_tot'] / ($row['sum']['expected_energy_saving'] + $row['sum']['expected_renewable_energy_production']) * 100, 1); } if ($row['sum']['expected_co2_reduction'] != 0) { $emisisonTot += $sumData[$row['gc_parent_id']]['emission_tot']; $result['data'][$row['gc_parent_id']]['sum']['progress_emission'] = round($sumData[$row['gc_parent_id']]['emission_tot'] / $row['sum']['expected_co2_reduction'] * 100, 1); } } if ($sum['expected_energy_saving'] + $sum['expected_renewable_energy_production'] != 0) { $sum['progress_energy'] = round($energyTot / ($sum['expected_energy_saving'] + $sum['expected_renewable_energy_production']) * 100, 1); } if ($sum['expected_co2_reduction'] != 0) { $sum['progress_emission'] = round($emisisonTot / $sum['expected_co2_reduction'] * 100, 1); } $result['sum'] = $sum; return $result; }
public function getListWhere() { return "t0.do_id={$this->do_id} " . (R3AuthInstance::get()->getParam('mu_id') == '' ? '' : 'AND mu_id=' . R3AuthInstance::get()->getParam('mu_id')); }
/** * ecogis.device_type fields definition */ public function defFields() { $fields = array(array('name' => 'dt_id', 'type' => 'number', 'is_primary_key' => true), array('name' => 'do_id', 'type' => 'domain'), array('name' => 'et_id', 'type' => 'lookup', 'label' => _('Tipo fonte'), 'required' => true, 'width' => 200, 'lookup' => array('table' => 'energy_type', 'list_field' => 'et_name_<LANG>', 'where' => "et_is_private IS FALSE AND et_code IN ('HEATING', 'ELECTRICITY', 'WATER')")), array('name' => 'dt_name_1', 'type' => 'text', 'size' => 80, 'width' => array(null, 300), 'required' => true, 'label' => _('Nome') . getLangNameShort(1), 'list' => true, 'edit' => true, 'delete_name' => true), array('name' => 'dt_name_2', 'type' => 'text', 'size' => 80, 'width' => array(null, 300), 'label' => _('Nome') . getLangNameShort(2), 'required' => R3AuthInstance::get()->getConfigValue('APPLICATION', 'NUM_LANGUAGES', 1) > 1, 'visible' => R3AuthInstance::get()->getConfigValue('APPLICATION', 'NUM_LANGUAGES', 1) > 1), array('name' => 'dt_has_extradata', 'type' => 'boolean', 'width' => 80, 'label' => _('Dati aggiuntivi'), 'visible' => true), array('name' => 'dt_is_consumption', 'type' => 'boolean', 'width' => 80, 'default' => true, 'label' => _('Impianto a consumo'), 'visible' => true), array('name' => 'dt_is_production', 'type' => 'boolean', 'width' => 80, 'label' => _('Impianto a produzione'), 'visible' => true), array('name' => 'dt_order', 'type' => 'number', 'required' => true, 'default' => 0, 'width' => 100, 'label' => _('Ordinamento'))); return $fields; }
public static function checkActionCatalog($ac_id) { static $cache = array(); $db = ezcDbInstance::get(); $auth = R3AuthInstance::get(); R3Security::checkDefault($ac_id, 'action_catalog'); if (!isset($cache[$ac_id])) { $q = $db->createSelectQuery(); $where = array(); $where[] = $q->expr->eq('do_id', $_SESSION['do_id']); $where[] = $q->expr->eq('ac_id', $ac_id); if (!$auth->hasPerm('SHOW', 'ALL_DOMAINS') && $auth->getParam('mu_id') != '') { $where[] = $q->expr->eq('mu_id', $db->quote((int) $auth->getParam('mu_id'))); } $q->select('COUNT(*)')->from('action_catalog_data')->where($where); // echo $q; if ($db->query($q)->fetchColumn() != 1) { throw new Exception("Action catalog #{$ac_id} not found"); } $cache[$ac_id] = true; } return true; }
$url = $page; } $hasMenu = true; $MenuItem = $auth->getConfigValue('APPLICATION', 'LOGON_ACCESS_MENU', 'building_list'); $parsedURL = parse_url($url); if (isset($parsedURL['query'])) { $p = strpos($parsedURL['query'], 'menu_item'); if ($p !== false) { $MenuItem = substr($parsedURL['query'], $p + 10); } } /* ------------------------------ Init Settings ------------------------------ */ require_once R3_WEB_ADMIN_DIR . 'smarty_assign.php'; require_once R3_WEB_ADMIN_DIR . 'menu.php'; /* ------------------------------ Output ------------------------------ */ $auth = R3AuthInstance::get(); $files = array(); $domainName = strtolower($auth->getDomainName()); $smarty->assign('prefetchTime', 0); if ($auth->getConfigValue('PREFETCH', 'START_DELAY_TIME', 0) > 0) { $what = array('CSS' => array('fs' => R3_WEB_CSS_DIR, 'url' => R3_CSS_URL . BUILD), 'JS' => array('fs' => R3_WEB_JS_DIR, 'url' => R3_JS_URL . BUILD), 'IMAGE' => array('fs' => R3_WEB_IMAGES_DIR, 'url' => R3_IMAGES_URL . BUILD), 'MAP_JS' => array('fs' => R3_WEB_MAP_DIR . 'javascript/', 'url' => R3_MAP_URL . 'javascript/' . BUILD), 'MAP_CSS' => array('fs' => R3_WEB_MAP_DIR . 'style/', 'url' => R3_MAP_URL . 'style/' . BUILD), 'MAP_IMAGE' => array('fs' => R3_WEB_MAP_DIR . 'mapimages/', 'url' => R3_MAP_URL . 'mapimages/' . BUILD), 'MAP_IMAGE_BUTTON' => array('fs' => R3_WEB_MAP_DIR . 'mapimages/buttons/', 'url' => R3_MAP_URL . 'mapimages/' . BUILD . '/buttons/'), 'MAP_IMAGE_SLIDER' => array('fs' => R3_WEB_MAP_DIR . 'mapimages/slider/', 'url' => R3_MAP_URL . 'mapimages/' . BUILD . '/slider/'), 'MAP_LEGEND' => array('fs' => R3_OUTPUT_DIR . "{$domainName}/legend/", 'url' => R3_APP_URL . "output/{$domainName}/legend/")); foreach ($what as $param => $data) { foreach (explode(':', str_replace(array(',', ';'), ':', $auth->getConfigValue('PREFETCH', $param, ''))) as $fileMask) { foreach (glob($data['fs'] . basename(trim($fileMask))) as $file) { if (is_file($file)) { //$url = $data['url'] . BUILD . '/' . substr($file, strlen($data['fs'])); $url = "{$data['url']}/" . substr($file, strlen($data['fs'])); // echo "[$url]"; $files[$url] = $url; } }
/** * Handle all the active stuff that usually happens in config.php. * This are things as opening db connections, start sessions etc. * * Session is started * The folloy object are created: * - $smarty * - $auth */ function R3AppInit($type = null, array $opt = array()) { global $smarty, $auth, $pdo, $mdb2, $dbini; // output object global $mdb2_dsn, $lang; // output var global $dsn, $sessionOpt, $mdb2_options; // input vars global $auth_options; // input vars global $scriptStartTime; /* Default application type */ if ($type === null) { $type = 'admin'; } $opt = array_merge(array('session_start' => true, 'auth' => true, 'auth_manager' => false, 'dbini' => false), $opt); /* Session */ foreach ($sessionOpt as $key => $val) { switch ($key) { case 'name': session_name($val); break; case 'cache_limiter': session_cache_limiter($val); break; case 'save_path': session_save_path($val); break; case 'timeout': session_cache_expire(ceil($val / 60)); break; case 'warning_timeout': // do nothing; break; default: ini_set("session." . $key, $val); } } if ($opt['session_start'] === true && session_id() == '') { session_start(); } /* Smarty */ require_once R3_SMARTY_ROOT_DIR . 'Smarty.class.php'; $smarty = new Smarty(); $smarty->config_dir = R3_SMARTY_ROOT_DIR . 'configs/'; $smarty->cache_dir = R3_SMARTY_ROOT_DIR . 'cache/'; if (defined('R3_SMARTY_PLUGIN_DIR')) { $smarty->plugins_dir[] = R3_SMARTY_PLUGIN_DIR; } if ($type == 'admin') { $smarty->template_dir = R3_SMARTY_TEMPLATE_DIR_ADMIN; $smarty->compile_dir = R3_SMARTY_TEMPLATE_C_DIR_ADMIN; } else { if ($type == 'public') { // for public sites $smarty->template_dir = R3_SMARTY_TEMPLATE_DIR_PUBLIC; $smarty->compile_dir = R3_SMARTY_TEMPLATE_C_DIR_PUBLIC; } else { if ($type == 'map') { $smarty->template_dir = R3_SMARTY_TEMPLATE_DIR_MAP; $smarty->compile_dir = R3_SMARTY_TEMPLATE_C_DIR_MAP; } else { throw new Exception("Unknown smarty specialization"); } } } $smarty->load_filter('pre', 'r3quotevalue'); R3AppInitDB(); /* Authentication */ if ($opt['auth'] === true && !isset($auth_options)) { throw new Exception('Missing $auth_options'); } if ($opt['auth'] === true) { if ($opt['auth_manager'] === true) { require_once R3_LIB_DIR . 'r3auth_manager.php'; $auth = new R3AuthManager($mdb2, $auth_options, APPLICATION_CODE); } else { require_once R3_LIB_DIR . 'r3auth.php'; $auth = new R3Auth($mdb2, $auth_options, APPLICATION_CODE); } R3AuthInstance::set($auth); } /* DBIni */ if ($opt['dbini'] === true) { require_once R3_LIB_DIR . 'r3dbini.php'; $domainName = R3_IS_MULTIDOMAIN ? 'SYSTEM' : DOMAIN_NAME; $dbini = new R3DBIni($mdb2, $auth_options, $domainName, APPLICATION_CODE); } }
public static function createUser($do_id, $data) { if (isset($data['us_login']) && $data['us_login'] != '') { ezcLog::getInstance()->log("R3EcoGisCustomerHelper::createUser({$do_id}, {$data['us_login']})", ezcLog::DEBUG); $auth = R3AuthInstance::get(); if (!$auth->getUserData($data['dn_name'], APPLICATION_CODE, $data['us_login'])) { $auth->addUserFromArray($data['dn_name'], $data['us_login'], array('us_name' => $data['us_name'], 'us_password' => $data['us_password'], 'us_status' => 'ENABLED', 'groups' => array(array('app_code' => APPLICATION_CODE, 'gr_name' => $data['us_group'])), 'us_pw_expire' => null, 'us_pw_expire_alert' => null, 'us_start_date' => null, 'us_expire_date' => null, 'perms' => array(), 'ip' => array(), 'forceChangePassword' => false)); } return true; } return false; }
static function removeMapOutputFiles($do_id, $removeLegend = false) { $auth = R3AuthInstance::get(); if ($do_id === null) { $domains = array(); foreach ($auth->getDomainsList() as $val) { $domains[$val['dn_name']] = $val['dn_name']; } } else { $domains[] = $auth->getDomainCodeFromID($do_id); } $mask = array('*.png', '*.gif', '*.jpg'); foreach ($domains as $domain) { $path = R3_OUTPUT_DIR . strtolower($domain) . '/'; foreach ($mask as $m) { foreach (glob("{$path}{$m}") as $file) { unlink($file); } if ($removeLegend) { foreach (glob("{$path}legend/{$m}") as $file) { ezcLog::getInstance()->log(__METHOD__ . ": Removing {$file}", ezcLog::INFO); unlink($file); } if (file_exists("{$path}legend/createimg.log")) { ezcLog::getInstance()->log(__METHOD__ . ": Removing {$path}legend/createimg.log", ezcLog::INFO); unlink("{$path}legend/createimg.log"); } } } } return true; }
function submitForm($elems, $doneFunc = 'AjaxFormObj.checkDone', $errFunc = 'AjaxFormObj.checkError') { global $lbl, $txt, $dbini; $auth = R3AuthInstance::get(); if (!$auth->hasPerm('EDIT', 'CONFIG') && !$auth->hasPerm('MOD', 'CONFIG')) { die("PERMISSION DENIED [EDIT|MOD/CONFIG]\n"); } /*$fieldDescr = array('do_names'=>array(MISSING_FIELD=>"Il campo 'nome dominio' e' obbligatorio", INVALID_FIELD=>"Il campo 'nome dominio' contiene caratteri non validi. Solo lettere e numeri sono accettati", PK_ERROR=>"Il campo 'nome dominio' immesso esiste gia'"), 'do_auth_type'=>array(MISSING_FIELD=>"Il campo 'tipo autenticazione' e' obbligatorio"), INVALID_FIELD=>"Il campo 'tipo autenticazione' non è valido",); */ $elems = AjaxSplitArray($elems); if (!isset($elems['old_us_login'])) { $elems['old_us_login'] = ''; } // print_r($elems); $objResponse = new xajaxResponse(); $error = array(); try { if (($p = strpos($elems['us_login'], '|')) !== false) { $elems['us_login'] = substr($elems['us_login'], $p + 1); } if (($p = strpos($elems['old_us_login'], '|')) !== false) { $elems['old_us_login'] = substr($elems['old_us_login'], $p + 1); } if (!$auth->hasPerm('SHOW', 'ALL_DOMAINS')) { $elems['dn_name'] = $auth->domain; } if (!$auth->hasPerm('SHOW', 'ALL_APPLICATIONS')) { $elems['app_code'] = $auth->application; } if (!$auth->hasPerm('SHOW', 'ALL_USERS')) { $elems['us_login'] = $auth->login; } if ($elems['act'] == 'del') { $dbini->removeAttribute($elems['dn_name'], $elems['app_code'], $elems['us_login'], $elems['se_section'], $elems['se_param']); } else { $se_section = strtoupper(trim($elems['se_section'])); $se_param = strtoupper(trim($elems['se_param'])); if ($elems['se_type'] == 'STRING') { $se_type_ext = $elems['se_type_ext_STRING']; } else { if ($elems['se_type'] == 'ENUM') { $se_type_ext = $elems['se_type_ext_ENUM']; } else { $se_type_ext = ''; } } if ($elems['se_type'] == 'ARRAY') { $se_value = trim($elems['se_value_TEXT']); @eval('$my_array = array(' . $se_value . ');'); if (!isset($my_array)) { throw new Exception('Invalid value'); } $se_value = serialize($my_array); // echo $se_value; } else { if ($elems['se_type'] == 'JSON') { if (trim($elems['se_value_TEXT']) == '') { $se_value = null; } else { $se_value = $elems['se_value_TEXT']; $jsonData = @json_decode($se_value, true); if ($jsonData === null) { throw new Exception('JSon error: ' . json_last_error_msg()); } } } else { if ($elems['se_type'] == 'TEXT') { $se_value = $elems['se_value_TEXT']; } else { $se_value = $elems['se_value_normal']; } } } $dbini->replaceAttribute($elems['old_dn_name'], $elems['old_app_code'], $elems['old_us_login'], $elems['old_se_section'], $elems['old_se_param'], $elems['dn_name'], $elems['app_code'], $elems['us_login'], $se_section, $se_param, $se_value, $elems['se_type'], $se_type_ext, $elems['se_private'], $elems['se_order'], $elems['se_descr']); } } catch (EPermissionDenied $e) { $error['element'][] = ''; $error['message'][] = $e->getMessage(); } catch (EDatabaseError $e) { $error['element'][] = ''; $error['message'][] = "Database error: " . $e->getMessage(); } catch (Exception $e) { $error['element'][] = ''; $error['message'][] = 'Generic error: ' . $e->getMessage(); } // Action if (count($error) > 0) { $errText = $txt['err_store_failed'] . "\n - " . implode("\n - ", $error['message']); $objResponse->addScriptCall($errFunc, $errText, $error['element'][0]); } else { $objResponse->addScriptCall($doneFunc); } return $objResponse->getXML(); }
/** * 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})"); } }
/** * ecogis.global_subcategory fields definition */ public function defFields() { $fields = array(array('name' => 'ft_id', 'type' => 'number', 'is_primary_key' => true), array('name' => 'do_id', 'type' => 'domain'), array('name' => 'ft_name_1', 'type' => 'text', 'size' => 80, 'width' => array(null, 300), 'required' => true, 'label' => _('Nome') . getLangNameShort(1), 'list' => true, 'edit' => true, 'delete_name' => true), array('name' => 'ft_name_2', 'type' => 'text', 'size' => 80, 'width' => array(null, 300), 'label' => _('Nome') . getLangNameShort(2), 'required' => R3AuthInstance::get()->getConfigValue('APPLICATION', 'NUM_LANGUAGES', 1) > 1, 'visible' => R3AuthInstance::get()->getConfigValue('APPLICATION', 'NUM_LANGUAGES', 1) > 1), array('name' => 'ft_has_extradata', 'type' => 'boolean', 'width' => 80, 'label' => _('Dati aggiuntivi'), 'visible' => true), array('name' => 'ft_order', 'type' => 'number', 'required' => true, 'default' => 0, 'width' => 100, 'label' => _('Ordinamento'))); return $fields; }
public function defFields() { $fields = array(array('name' => 'bry_id', 'type' => 'number', 'is_primary_key' => true), array('name' => 'do_id', 'type' => 'domain'), array('name' => 'bry_name_1', 'type' => 'text', 'required' => true, 'label' => _('Descrizione') . getLangNameShort(1), 'delete_name' => true), array('name' => 'bry_name_2', 'type' => 'text', 'label' => _('Descrizione') . getLangNameShort(2), 'required' => R3AuthInstance::get()->getConfigValue('APPLICATION', 'NUM_LANGUAGES', 1) > 1, 'visible' => R3AuthInstance::get()->getConfigValue('APPLICATION', 'NUM_LANGUAGES', 1) > 1), array('name' => 'bry_start_year', 'type' => 'text', 'required' => true, 'label' => _('Anno inizio') . getLangNameShort(1)), array('name' => 'bry_end_year', 'type' => 'text', 'label' => _('Anno fine') . getLangNameShort(2), 'required' => R3AuthInstance::get()->getConfigValue('APPLICATION', 'NUM_LANGUAGES', 1) > 1), array('name' => 'bry_order', 'type' => 'number', 'required' => true, 'default' => 0, 'width' => 100, 'label' => _('Ordinamento'))); return $fields; }
function submitForm($elems, $doneFunc = 'AjaxFormObj.checkDone', $errFunc = 'AjaxFormObj.checkError') { global $lbl, $txt, $users_extra_fields; $auth = R3AuthInstance::get(); $fieldDescr = array('app_code' => array(MISSING_FIELD => _("Il campo 'applicazione' e' obbligatorio"), INVALID_FIELD => _("Il campo 'applicazione' contiene caratteri non validi. Solo lettere e numeri sono accettati"), PK_ERROR => _("Il campo 'codice' immesso esiste gia'")), 'app_name' => array(MISSING_FIELD => _("Il campo 'nome' e' obbligatorio"))); // print_r($elems); $elems = AjaxSplitArray($elems); // print_r($elems); $objResponse = new xajaxResponse(); /** User extra field for the common section */ $extra_fields = $auth->getConfigValue('USER_MANAGER', 'EXTRA_FIELDS', array()); if (isset($users_extra_fields)) { $extra_fields = array_merge($extra_fields, $users_extra_fields); } $error = array(); try { $errors = checkReq($extra_fields, $elems); if (!empty($errors)) { $errorMsg = implode('\\n', $errors); throw new Exception($errorMsg); } if ($auth->passwordStatus < 0 && $elems['us_password'] == '') { throw new Exception('Password must be set'); } /** Extra fields in user table */ $extras = array(); foreach ($extra_fields as $key => $val) { if (!isset($val['inistorage']) && !isset($val['kind'])) { if (isset($elems[$key])) { $extras[$key] = $elems[$key]; } } } /** password check */ if ($elems['us_password'] != '' && $elems['us_password'] != $elems['us_password2']) { throw new Exception('Invalid password'); } if ($elems['us_password'] != '') { $auth->setParam('us_password', $elems['us_password'], true); } foreach ($extras as $key => $val) { $auth->setParam($key, $val, true); } /** Extra fields in user table */ foreach ($extra_fields as $key => $val) { if (isset($val['inistorage']) && !isset($val['kind'])) { if (isset($elems[$key])) { $auth->setConfigValue($val['inistorage'][0], $val['inistorage'][1], $elems[$key]); } } } } catch (EPermissionDenied $e) { $error['element'][] = ''; $error['message'][] = $e->getMessage(); } catch (EDatabaseError $e) { $error['element'][] = ''; $error['message'][] = "Database error: " . $e->getMessage(); } catch (EInputError $e) { $error['element'][] = $e->getField(); if (isset($fieldDescr[$e->getField()][$e->getCode()])) { $error['message'][] = $fieldDescr[$e->getField()][$e->getCode()]; } else { $error['message'][] = $e->getMessage(); } } catch (Exception $e) { $error['element'][] = ''; //$error['message'][] = 'Generic error: ' . $e->getMessage(); $error['message'][] = $e->getMessage(); } // Action if (count($error) > 0) { $errText = $txt['err_store_failed'] . "\n - " . implode("\n - ", $error['message']); $objResponse->addScriptCall($errFunc, $errText, $error['element'][0]); } else { $objResponse->addScriptCall($doneFunc); } return $objResponse->getXML(); }
function submitForm($elems, $doneFunc = 'AjaxFormObj.checkDone', $errFunc = 'AjaxFormObj.checkError') { global $lbl, $txt; $auth = R3AuthInstance::get(); $fieldDescr = array('do_names' => array(MISSING_FIELD => "Il campo 'nome dominio' e' obbligatorio", INVALID_FIELD => "Il campo 'nome dominio' contiene caratteri non validi. Solo lettere e numeri sono accettati", PK_ERROR => "Il campo 'nome dominio' immesso esiste gia'"), 'do_auth_type' => array(MISSING_FIELD => "Il campo 'tipo autenticazione' e' obbligatorio"), INVALID_FIELD => "Il campo 'tipo autenticazione' non è valido"); $elems = AjaxSplitArray($elems); $objResponse = new xajaxResponse(); $error = array(); try { if (isset($elems['do_name'])) { $do_names = array(strtoupper($elems['do_name'])); } if (isset($elems['do_alias'])) { foreach (explode("\n", $elems['do_alias']) as $value) { $s = trim(strtoupper(str_replace("\r", '', $value))); if ($s != '') { $do_names[] = $s; } } } if (isset($elems['selectedApplications'])) { foreach (explode(",", $elems['selectedApplications']) as $value) { $applications[] = strtoupper($value); } } if ($elems['act'] == 'add') { /** add a new somain */ $auth->addDomain($do_names, $elems['do_auth_type'], $elems['do_auth_data'], $applications); } else { if ($elems['act'] == 'mod') { /** modify a domain */ $auth->modDomain($elems['old_do_name'], $do_names, $elems['do_auth_type'], $elems['do_auth_data'], $applications); } else { if ($elems['act'] == 'del') { /** delete an application */ $auth->delDomain($elems['name']); } else { throw new Exception('Invalid action'); } } } } catch (EPermissionDenied $e) { $error['element'][] = ''; $error['message'][] = $e->getMessage(); } catch (EDatabaseError $e) { $error['element'][] = ''; $error['message'][] = "Database error: " . $e->getMessage(); } catch (EInputError $e) { $error['element'][] = $e->getField(); if (isset($fieldDescr[$e->getField()][$e->getCode()])) { $error['message'][] = $fieldDescr[$e->getField()][$e->getCode()]; } else { $error['message'][] = $e->getMessage(); } } catch (Exception $e) { $error['element'][] = ''; $error['message'][] = 'Generic error: ' . $e->getMessage(); } // Action if (count($error) > 0) { $errText = $txt['err_store_failed'] . "\n - " . implode("\n - ", $error['message']); $objResponse->addScriptCall($errFunc, $errText, $error['element'][0]); } else { $objResponse->addScriptCall($doneFunc); } return $objResponse->getXML(); }
/** * 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})"); } }
public function canDel() { return R3AuthInstance::get()->hasPerm('DEL', 'ALL_LOOKUP'); }