示例#1
0
 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;
 }
示例#2
0
文件: Ajax.php 项目: hakimam/ArkeoGIS
 public static function editDatabase($params)
 {
     if (!\mod\user\Main::userIsLoggedIn() || (!\mod\user\Main::userBelongsToGroup('Admin') && !\mod\arkeogis\ArkeoGIS::isDatabaseOwner((int) $params['id'], \mod\user\Main::getUserId($_SESSION['login'])) || !$params['id'])) {
         return false;
     }
     $acceptedParams = array('name', 'declared_modification', 'issn', 'scale_resolution', 'type', 'geographical_limit', 'geographical_limit_de', 'description', 'description_de', 'published');
     $dbParans = array();
     while (list($k, $v) = each($params)) {
         if (in_array($k, $acceptedParams)) {
             $dbParams[$k] = $v;
         }
     }
     if (isset($dbParams['declared_modification']) && empty($dbParams['declared_modification'])) {
         unset($dbParams['declared_modification']);
     }
     if (isset($dbParams['published'])) {
         $dbParams['published'] = $dbParams['published'] == 0 ? 'f' : 't';
     }
     if (!\mod\user\Main::userBelongsToGroup('Admin')) {
         unset($dbParams['published']);
     }
     $owner_id = \core\Core::$db->fetchOne('SELECT uid FROM "ch_user" WHERE full_name = ?', array($params['author']));
     if ($owner_id) {
         $dbParams['owner_id'] = $owner_id;
     }
     \mod\arkeogis\ArkeoGIS::updateDatabase((int) $params['id'], $dbParams);
     \core\Core::log($dbParams);
     return true;
 }
示例#3
0
文件: Main.php 项目: hakimam/ArkeoGIS
 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);
 }