public static function getSiteInfos($siteId) { $strings = ArkeoGIS::load_strings(); $siteInfos = array(); $query = "SELECT si_name AS name, si_code AS code, ST_AsGeoJSON(si_geom) AS geom, si_centroid AS centroid, si_occupation AS occupation, to_char(si_creation, 'dd/mm/yyyy') AS creation, to_char(si_modification, 'dd/mm/yyyy') AS modification, si_city_name AS city_name, si_city_code AS city_code, da_name AS dbname, da_owner_id as author FROM ark_site AS si "; $query .= "LEFT JOIN ark_database AS da ON si.si_database_id=da.da_id "; $query .= "WHERE si.si_id=?"; $infos = \core\Core::$db->fetchAll($query, array($siteId)); if (sizeof($infos) > 1) { throw new \Exception("Multiple result found for a site id"); } else { if (sizeof($infos) < 1) { return NULL; } } $geom = json_decode($infos[0]['geom']); $siteInfos['database'] = $infos[0]['dbname']; $siteInfos['name'] = $infos[0]['name']; $siteInfos['code'] = $infos[0]['code']; $siteInfos['author'] = \mod\user\Main::getUserFullNameById($infos[0]['author']); $siteInfos['geom'] = $geom->coordinates; $siteInfos['centroid'] = $infos[0]['centroid']; $siteInfos['occupation'] = $infos[0]['occupation']; $siteInfos['creation'] = $infos[0]['creation']; $siteInfos['modification'] = $infos[0]['modification']; $siteInfos['city']['name'] = $infos[0]['city_name']; $siteInfos['city']['code'] = $infos[0]['city_code']; // Get site periods $query = "SELECT sp_id AS id, (SELECT node_path FROM ark_period WHERE pe_id=sp_period_start) AS period_start_path, (SELECT node_path FROM ark_period WHERE pe_id=sp_period_end) AS period_end_path, sp_period_isrange AS isrange, sp_knowledge_type AS knowledge, sp_comment AS comment, sp_bibliography AS bibliography FROM ark_site_period WHERE sp_site_id = ?"; $datas = array(); $caracs = array('realestate' => array(), 'production' => array(), 'furniture' => array(), 'landscape' => array()); foreach (\core\Core::$db->fetchAll($query, array($siteId)) as $pInfos) { $periodHash = md5($pInfos['period_start_path'] . $pInfos['period_end_path']); if (!isset($siteInfos['characteristics'][$periodHash])) { $datas['start'] = Arkeogis::node_path_to_array($pInfos['period_start_path'], $strings['period']); $datas['end'] = Arkeogis::node_path_to_array($pInfos['period_end_path'], $strings['period']); $datas['knowledge'] = $pInfos['knowledge']; $datas['comment'] = $pInfos['comment']; $datas['bibliography'] = $pInfos['bibliography']; $siteInfos['characteristics'][$periodHash]['datas'] = $datas; unset($datas); } $i = sizeof($periodHash); // Realestate $q = "SELECT node_path, sr_exceptional FROM ark_siteperiod_realestate LEFT JOIN ark_realestate ON ark_siteperiod_realestate.sr_realestate_id=ark_realestate.re_id WHERE ark_siteperiod_realestate.sr_site_period_id = ?"; foreach (\core\Core::$db->fetchAll($q, array($pInfos['id'])) as $carac) { $siteInfos['characteristics'][$periodHash]['caracs'][$i]['realestate'][] = array(Arkeogis::node_path_to_array($carac['node_path'], $strings['realestate']), $carac['sr_exceptional']); } // Production $q = "SELECT node_path, sp_exceptional FROM ark_siteperiod_production LEFT JOIN ark_production ON ark_siteperiod_production.sp_production_id=ark_production.pr_id WHERE ark_siteperiod_production.sp_site_period_id = ?"; foreach (\core\Core::$db->fetchAll($q, array($pInfos['id'])) as $carac) { $siteInfos['characteristics'][$periodHash]['caracs'][$i]['production'][] = array(Arkeogis::node_path_to_array($carac['node_path'], $strings['production']), $carac['sp_exceptional']); } // Furniture $q = "SELECT node_path, sf_exceptional FROM ark_siteperiod_furniture LEFT JOIN ark_furniture ON ark_siteperiod_furniture.sf_furniture_id=ark_furniture.fu_id WHERE ark_siteperiod_furniture.sf_site_period_id = ?"; foreach (\core\Core::$db->fetchAll($q, array($pInfos['id'])) as $carac) { $siteInfos['characteristics'][$periodHash]['caracs'][$i]['furniture'][] = array(Arkeogis::node_path_to_array($carac['node_path'], $strings['furniture']), $carac['sf_exceptional']); } // Landscape $q = "SELECT node_path, sl_exceptional FROM ark_siteperiod_landscape LEFT JOIN ark_landscape ON ark_siteperiod_landscape.sl_landscape_id=ark_landscape.la_id WHERE ark_siteperiod_landscape.sl_site_period_id = ?"; foreach (\core\Core::$db->fetchAll($q, array($pInfos['id'])) as $carac) { $siteInfos['characteristics'][$periodHash]['caracs'][$i]['landscape'][] = array(Arkeogis::node_path_to_array($carac['node_path'], $strings['landscape']), $carac['sl_exceptional']); } } // \core\Core::log($siteInfos); return $siteInfos; }
public static function deleteDatabase($params) { if (!\mod\user\Main::userIsLoggedIn() || !\mod\user\Main::userBelongsToGroup('Admin') || !$params['id']) { return false; } \mod\arkeogis\ArkeoGIS::deleteDatabase($params['id']); return true; }
public static function hook_mod_arkeogis_export_database($hookname, $userdata, $matches) { $dbId = (int) $matches[1]; if (!\mod\user\Main::userIsLoggedIn() || (!\mod\user\Main::userBelongsToGroup('Admin') && !\mod\arkeogis\ArkeoGIS::isDatabaseOwner($dbId, \mod\user\Main::getUserId($_SESSION['login'])) || !$dbId)) { return false; } $q = "SELECT si_id, si_code, si_name, si_description, si_city_name, si_city_code, ST_AsGeoJSON(si_geom) as coords, si_centroid, si_occupation, si_creation, si_modification"; // ark_site $q .= ", da_name, da_description, da_creation, da_modification"; // ark_database $q .= ", sp_id, sp_knowledge_type, sp_comment, sp_bibliography"; // ark_site_period $q .= ", (SELECT node_path FROM ark_period WHERE pe_id=sp_period_start) AS period_start"; $q .= ", (SELECT node_path FROM ark_period WHERE pe_id=sp_period_end) AS period_end"; $q .= " FROM ark_site s LEFT JOIN ark_database d ON s.si_database_id = d.da_id LEFT JOIN ark_site_period sp ON s.si_id = sp.sp_site_id"; $q .= " WHERE da_id = ?"; $q .= " GROUP BY si_id, sp_id, da_id"; $q .= " ORDER BY si_code, si_id, sp_id"; $infos = \mod\arkeogis\ArkeoGIS::getFullDatabaseInfos($dbId); $name = str_replace(' ', '_', \core\Tools::removeAccents($infos[0]['name'])); $author = str_replace(' ', '_', \core\Tools::removeAccents($infos[0]['author'])); $filename = 'ArkeoGIS-export-' . date("d-m-Y-H-i") . '-' . $name . '-' . $author; \mod\arkeogis\ArkeoGIS::sitesToCsv(\core\Core::$db->fetchAll($q, array((int) $dbId)), $filename); }
private static function _processDatabaseName($dbName, $fields, $ownerId) { // Db name provided if (!empty($dbName)) { // we check if it matches previously stored db dbName if (isset(self::$_database['name']) && !empty(self::$_database['name'])) { if ($dbName != self::$_database['name']) { self::_addError("Database name ({$dbName}) is different from the database name previously defined (" . self::$_database['name'] . ")"); return false; } else { return; } } $dbId = \mod\arkeogis\ArkeoGIS::getDatabaseId($dbName); // Check if owner owns the database if (!\mod\user\Main::userhasRight('Manage all databases') && !\mod\user\Main::userhasRight('Manage personal database')) { self::_addError('You are not allowed to import a database'); return false; } else { if ($dbId && !\mod\user\Main::userhasRight('Manage all databases') && (\mod\user\Main::userhasRight('Manage personal database') && !\mod\arkeogis\ArkeoGIS::isDatabaseOwner($dbId, $ownerId))) { self::_addError('Database ' . self::$_database['name'] . ' already exists and not belongs to you'); return false; } } self::$_database['name'] = $dbName; if (!empty($dbId)) { self::$_database['id'] = $dbId; self::$_database['name'] = $dbName; if (sizeof($fields) > 0) { \mod\arkeogis\ArkeoGIS::updateDatabase($dbId, $fields); } } else { try { self::$_database['id'] = \mod\arkeogis\ArkeoGIS::addDatabase($dbName, $fields, $ownerId); self::$_database['name'] = $dbName; } catch (\Exception $e) { self::_addError("Unable to register database name {$dbName}: " . $e->getMessage()); } } // No db name provided } else { if (empty(self::$_database['name'])) { self::_addError('No database name provided and no database already registered'); } } self::$_current['database'] = self::$_database; return; }
public static function getUserGroups($uid) { return implode('', \mod\user\Main::getUserGroups($uid, 'name')); }