示例#1
0
 /**
  * Generate the preview map
  */
 static function generateMapPreview($layer, $key, $lang, $tollerance = '10%')
 {
     require_once R3_LIB_DIR . 'maplib.php';
     require_once R3_LIB_DIR . 'custom.map.php';
     global $languages;
     ezcLog::getInstance()->log(__METHOD__ . "({$layer}, {$key}, {$lang}, {$tollerance}) called", ezcLog::DEBUG);
     $db = ezcDbInstance::get();
     $auth = R3AuthInstance::get();
     list($width, $height) = explode('x', $auth->getConfigValue('APPLICATION', 'MAP_PREVIEW_SIZE', '200x200'));
     $cus_schema = R3EcoGisHelper::getGeoSchema();
     $domain_name = strtolower(R3EcoGisHelper::getDomainCodeFromID($_SESSION['do_id']));
     $mapfileDir = R3_CONFIG_DIR . $domain_name . '/map/';
     $mapPrev = new mapPreview($mapfileDir, $languages[$lang], $width, $height);
     if (function_exists('custom_map_edit_map_file')) {
         custom_map_edit_map_file($mapPrev->map);
     }
     switch ($layer) {
         case 'building':
             $opt = $auth->getConfigValue('APPLICATION', 'BUILDING_TABLE');
             $options['outlinecolor'] = isset($opt['outlinecolor']) ? $opt['outlinecolor'] : array();
             $sql = "SELECT ST_Extent(the_geom) FROM building WHERE bu_id=" . (int) $key;
             $mapPrev->highlight('ecogis_building_outline_selected', "the_geom FROM (SELECT * FROM {$cus_schema}.building WHERE bu_id=" . (int) $key . ") AS foo USING UNIQUE bu_id ", $options);
             break;
         case 'edit_building':
             // Edit building
             $opt = $auth->getConfigValue('APPLICATION', 'BUILDING_TABLE');
             $options['outlinecolor'] = isset($opt['outlinecolor']) ? $opt['outlinecolor'] : array();
             $sql = "SELECT ST_Extent(the_geom) FROM edit_tmp_polygon WHERE session_id=" . $db->quote($key);
             $mapPrev->highlight('ecogis_building_outline_selected', "the_geom FROM (SELECT gid AS bu_id, the_geom FROM ecogis.edit_tmp_polygon WHERE session_id=" . $db->quote($key) . ") AS foo USING UNIQUE bu_id ", $options);
             break;
         case 'street_lighting':
             $opt = $auth->getConfigValue('APPLICATION', 'STREET_LIGHTING_TABLE');
             $options['outlinecolor'] = isset($opt['outlinecolor']) ? $opt['outlinecolor'] : array();
             $sql = "SELECT ST_Extent(the_geom) FROM street_lighting WHERE sl_id=" . (int) $key;
             $mapPrev->highlight('ecogis_street_lighting_outline_selected', "the_geom FROM (SELECT * FROM {$cus_schema}.street_lighting WHERE sl_id=" . (int) $key . ") AS foo USING UNIQUE sl_id ", $options);
             break;
         case 'edit_street_lighting':
             $opt = $auth->getConfigValue('APPLICATION', 'BUILDING_TABLE');
             $options['outlinecolor'] = isset($opt['outlinecolor']) ? $opt['outlinecolor'] : array();
             $sql = "SELECT ST_Extent(the_geom) FROM edit_tmp_polygon WHERE session_id=" . $db->quote($key);
             $mapPrev->highlight('ecogis_street_lighting_outline_selected', "the_geom FROM (SELECT gid AS sl_id, the_geom FROM ecogis.edit_tmp_polygon WHERE session_id=" . $db->quote($key) . ") AS foo USING UNIQUE sl_id ", $options);
             break;
         default:
             $this->deliverError(sprintf(_("Il layer \"{$this->layer}\" non e' valido")));
             die;
     }
     $the_geom = $db->query($sql)->fetchColumn(0);
     if ($the_geom != '') {
         $extentArr = array();
         $extentArr = ST_FetchBox($the_geom);
         $extentArr['geox1'] = $extentArr[0];
         $extentArr['geoy1'] = $extentArr[1];
         $extentArr['geox2'] = $extentArr[2];
         $extentArr['geoy2'] = $extentArr[3];
         $deltaX = $deltaY = $tollerance;
         $layer = @$mapPrev->map->getLayerByName('comuni_overlay');
         if ($layer) {
             $class0 = @$layer->getClass(0);
             if ($class0) {
                 $class0->setExpression("('[istat]' != '" . $vlu['mu_id'] . "')");
             }
         }
         $PrevFile = $mapPrev->getMapImgByBox($extentArr['geox1'], $extentArr['geoy1'], $extentArr['geox2'], $extentArr['geoy2'], max($deltaX, $deltaY));
         return $PrevFile;
     }
     return null;
 }
示例#2
0
 /**
  * Ajax request to submit data
  * @param array $request   the request
  * @return array           ajax format status
  */
 public function submitFormData($request)
 {
     global $dbini, $dsn, $mdb2, $languages;
     if ($this->act == 'del') {
         $id = $this->deleteCustomer($request);
         return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataDoneCustomer({$id})");
     }
     $errors = array();
     $errors = $this->checkFormData($request, $errors);
     if ($request['municipality'] == '') {
         $errors['municipality'] = array('CUSTOM_ERROR' => _("Almeno un comune deve essere selezionato"));
     }
     $catalog = R3DbCatalog::factory('pgsql', $mdb2);
     $data = $catalog->getUserData();
     if (count($errors) > 0) {
         return $this->getAjaxErrorResult($errors);
     } else {
         if ($request['cus_srid'] == '') {
             $request['cus_srid'] = 4326;
         }
         $db = ezcDbInstance::get();
         $do_id = R3EcoGisCustomerHelper::createDomain($request['dn_name'], $request['dn_name_alias']);
         R3EcoGisCustomerHelper::createCustomer($do_id, $request);
         R3EcoGisCustomerHelper::createUser($do_id, $request);
         R3EcoGisCustomerHelper::setMunicipality($do_id, explode(',', $request['municipality']));
         $dataPath = R3_UPLOAD_DATA_DIR . strtolower($request['dn_name']);
         $dataLogoPath = $dataPath . '/logo';
         $dataStylePath = $dataPath . '/style';
         $dataJSPath = $dataPath . '/js';
         if (!file_exists($dataPath)) {
             if (!@mkdir($dataPath)) {
                 throw new Exception("Can't create path {$dataPath}");
             }
         }
         if (!file_exists($dataLogoPath)) {
             if (!@mkdir($dataLogoPath)) {
                 throw new Exception("Can't create path {$dataLogoPath}");
             }
         }
         if (!file_exists($dataStylePath)) {
             if (!@mkdir($dataStylePath)) {
                 throw new Exception("Can't create path {$dataStylePath}");
             }
         }
         if (!file_exists($dataJSPath)) {
             if (!@mkdir($dataJSPath)) {
                 throw new Exception("Can't create path {$dataJSPath}");
             }
         }
         R3EcoGisCustomerHelper::saveImages($request['dn_name'], $request);
         R3EcoGisCustomerHelper::saveCSS($request['dn_name'], $request);
         if ($request['consumption_end_year'] > 0 && $request['consumption_start_year'] > 0) {
             $viewOpt = array('totYears' => $request['consumption_end_year'] - $request['consumption_start_year'] + 1);
         } else {
             $viewOpt = array('totYears' => 100);
         }
         $schema = R3EcoGisHelper::getGeoSchema($do_id);
         //'geo_' . strtolower($request['dn_name']);
         R3EcoGisCustomerHelper::createSchema($schema, $dsn['dbuser']);
         R3EcoGisCustomerHelper::createViews($schema, $dsn['dbuser'], $request['cus_srid'], $do_id, $viewOpt);
         R3EcoGisCustomerHelper::setLoggerTrigger();
         R3EcoGisCustomerHelper::grantTables($schema, $dsn['dbuser']);
         R3EcoGisCustomerHelper::applyConsumptionInterval($request['consumption_start_year'], $request['consumption_end_year']);
         if (R3_AUTO_POPULATE_GEOMETRY_COLUMNS && !isset($request['skip_geometry_check'])) {
             R3EcoGisCustomerHelper::populateGeometryColumns(R3_DB_SCHEMA);
             R3EcoGisCustomerHelper::populateGeometryColumns($schema);
         }
         R3EcoGisCustomerHelper::copyEnergySource($do_id);
         if ($this->isMultiDomain()) {
             R3EcoGisCustomerHelper::copySettings('SYSTEM', $request['dn_name']);
         }
         if ($this->act == 'add') {
             $sql = "INSERT INTO auth.settings (do_id, app_id, se_section, se_param, se_value, se_descr, se_type, se_type_ext, se_private, se_order)\r\n                        SELECT DISTINCT (SELECT do_id FROM auth.domains_name WHERE dn_type='N' and dn_name='{$request['dn_name']}'), s.app_id, se_section, se_param, se_value, se_descr, se_type, se_type_ext, se_private, se_order\r\n                        FROM auth.settings s\r\n                        INNER JOIN auth.domains_name dn on s.do_id=dn.do_id and dn_type='N' AND dn_name='{$request['do_template']}'\r\n                        INNER JOIN auth.applications app on s.app_id=app.app_id AND app_code='" . APPLICATION_CODE . "'\r\n                        WHERE us_id IS NULL \r\n                        ORDER BY se_section, se_param";
             $db->exec($sql);
         }
         //Salva dati nuovo ente (DBINI)
         $gridSize = forceInteger($request['do_grid_size'], 0, false, '.');
         if ($this->auth->getConfigValueFor($request['dn_name'], APPLICATION_CODE, null, 'APPLICATION', 'STAT_GRID_SIZE', 0) != $gridSize) {
             $this->create_grid(array('do_id' => $do_id, 'sg_size' => $request['do_grid_size']));
         }
         $dbini2 = clone $dbini;
         $dbini2->setDomainName($request['dn_name']);
         $dbini2->setValue('APPLICATION', 'NUM_LANGUAGES', $request['app_language']);
         $dbini2->setValue('APPLICATION', 'CATASTRAL_TYPE', $request['app_cat_type']);
         $dbini2->setValue('APPLICATION', 'BUILDING_CODE_TYPE', $request['do_building_code_type']);
         $dbini2->setValue('APPLICATION', 'BUILDING_CODE_REQUIRED', $request['do_building_code_required']);
         $dbini2->setValue('APPLICATION', 'CALCULATE_GLOBAL_PLAIN_TOTALS', $request['do_calculate_global_plain_totals']);
         $dbini2->setValue('APPLICATION', 'BUILDING_CODE_UNIQUE', $request['do_building_code_unique']);
         $dbini2->setValue('APPLICATION', 'BUILDING_EXTRA_DESCR', $request['do_building_extra_descr']);
         $dbini2->setValue('APPLICATION', 'PUBLIC_CSS_URL', $request['do_public_css_url']);
         $dbini2->setValue('APPLICATION', 'ENABLE_PUBLIC_SITE', $request['do_public_site']);
         $dbini2->setValue('APPLICATION', 'STAT_GRID_SIZE', $gridSize > 0 ? $gridSize : null);
         $dbini2->setValue('APPLICATION', 'BUILDING_SHOW_ID', $request['do_building_show_id']);
         $dbini2->setValue('APPLICATION', 'BUILDING_YEAR_TYPE', $request['do_build_year_type']);
         $dbini2->setValue('APPLICATION', 'BUILDING_RESTRUCTURE_YEAR_TYPE', $request['do_build_restructure_year_type']);
         $dbini2->setValue('APPLICATION', 'BUILDING_MUNICIPALITY_MODE', $request['do_municipality_mode']);
         $dbini2->setValue('APPLICATION', 'BUILDING_FRACTION_MODE', $request['do_fraction_mode']);
         $dbini2->setValue('APPLICATION', 'BUILDING_STREET_MODE', $request['do_street_mode']);
         $dbini2->setValue('APPLICATION', 'BUILDING_CATASTRAL_MODE', $request['do_catastral_mode']);
         $dbini2->setValue('APPLICATION', 'CONSUMPTION_START_YEAR', $request['consumption_start_year']);
         $dbini2->setValue('APPLICATION', 'CONSUMPTION_END_YEAR', $request['consumption_end_year']);
         if ($request['app_language'] == 1) {
             $dbini2->setValue('APPLICATION', 'LANG_NAME_SHORT_1', '');
             $dbini2->setValue('APPLICATION', 'LANG_NAME_SHORT_2', '');
         } else {
             $dbini2->setValue('APPLICATION', 'LANG_NAME_SHORT_1', sprintf(' (%s)', $languages[1]));
             $dbini2->setValue('APPLICATION', 'LANG_NAME_SHORT_2', sprintf(' (%s)', $languages[2]));
         }
         $dbini2->setValue('APPLICATION', 'LANG_NAME_SHORT_3', ' (en)');
         // Gisclient settings
         $dbini2->setValue('GISCLIENT', 'PROJECT', $request['do_gc_project']);
         $dbini2->setValue('GISCLIENT', 'MAPSET', $request['do_gc_mapset']);
         $dbini2->setValue('GISCLIENT', 'HAS_STREETVIEW', $request['do_gc_streeview']);
         $dbini2->setValue('GISCLIENT', 'HAS_QUICK_SEARCH', $request['do_gc_quick_search']);
         $dbini2->setValue('GISCLIENT', 'DIGITIZE_HAS_SELECTION', $request['do_gc_digitize_has_selection']);
         $dbini2->setValue('GISCLIENT', 'DIGITIZE_HAS_EDITING', $request['do_gc_digitize_has_editing']);
         if (R3_AUTO_SAVE_DATABASE_VERSION) {
             R3EcoGisCustomerHelper::updateDatabaseVersion(DATABASE_VERSION);
             // Setup database version
         }
         $id = 0;
         R3EcoGisEventNotifier::notifyDataChanged($this, array('data_changed' => true));
         return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataDoneCustomer({$id})");
     }
 }
示例#3
0
function municipalityHasGeometry($mu_id)
{
    $schema = R3EcoGisHelper::getGeoSchema($_SESSION['do_id']);
    $sql = "SELECT CASE WHEN the_geom IS NULL THEN FALSE ELSE TRUE END AS has_geometry FROM {$schema}.municipality WHERE mu_id=?";
    return hasGeometry($sql, $mu_id);
}