Skip to content

Commit

Permalink
Added way to store projects inside client subfolder. Look wiki for de…
Browse files Browse the repository at this point in the history
…tails
  • Loading branch information
uprel committed Apr 26, 2017
1 parent 6066cbf commit 7da56ef
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
17 changes: 17 additions & 0 deletions admin/class.Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ public static function getQgsTimeStamp($map) {

public function getProjectConfigs($file)
{
$file .= '.json';

if (file_exists($file)) {
try {
$filestr = file_get_contents($file, true);
Expand All @@ -157,8 +159,23 @@ public function getProjectConfigs($file)
}
}

public function getQgsFullProjectPath($project, $client) {

//first check in PROJECT_PATH
if (file_exists(PROJECT_PATH . $project . '.qgs')) {
return self::msg(true, PROJECT_PATH . $project);
} else if (file_exists(PROJECT_PATH . $client . DIRECTORY_SEPARATOR . $project . '.qgs')) {
return self::msg(true, PROJECT_PATH . $client . DIRECTORY_SEPARATOR . $project);
} else {
return self::msg(false, PROJECT_PATH . $project . '.qgs NOT FOUND!');
}
}


public function getQgsProjectProperties($map)
{
$map .= '.qgs';

$qgs = self::getQgsProject($map);
$time = self::getQgsTimeStamp($map);
$prop = new \stdClass();
Expand Down
15 changes: 13 additions & 2 deletions admin/class.Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,21 +266,32 @@ private function checkPasswordCorrectnessAndLogin()
//get all GIS projects for user for themeswitcher
$gis_projects = $gisApp->getGisProjectsFromDB();

//get client alias
$client = json_decode($project_data)->client_name;

//get QGIS project location
$projectPath = $helpers->getQgsFullProjectPath($project, $client);
if (!($projectPath['status'])){
$this->feedback = $projectPath['message'];
return false;
}

//get QGIS project properties
$project_qgs = $helpers->getQgsProjectProperties(PROJECT_PATH . $project . '.qgs');
$project_qgs = $helpers->getQgsProjectProperties($projectPath['message']);
if (property_exists($project_qgs,"message")) {
$this->feedback = $project_qgs->message;
return false;
}

//search configs
$project_settings = $helpers->getProjectConfigs(PROJECT_PATH . $project . '.json');
$project_settings = $helpers->getProjectConfigs($projectPath['message']);
if ($project_settings['status']) {
// write user data into PHP SESSION
$_SESSION['user_name'] = $user;
$_SESSION['user_email'] = $email;
$_SESSION['user_is_logged_in'] = true;
$_SESSION['project'] = $project;
$_SESSION['project_path'] = $projectPath['message'];
$_SESSION['data'] = $project_data;
$_SESSION['settings'] = $project_settings['message'];
$_SESSION['gis_projects'] = $gis_projects;
Expand Down
9 changes: 6 additions & 3 deletions admin/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function prepareFile($layername, $map, $query_arr, $destinationFormat)
//$fsize = -1;

// Get project
$project = Helpers::getQgsProject(PROJECT_PATH . $map . '.qgs');
$project = Helpers::getQgsProject($map . '.qgs');
if (!($project["status"])) {
throw new Exception ($project["message"]);
}
Expand Down Expand Up @@ -134,7 +134,7 @@ function prepareFile($layername, $map, $query_arr, $destinationFormat)
//$mycmd = OGR2OGR . ' -f "' . $format_name . '" "' . $fileName . '.' . strtolower($destinationFormat) . '" ' . $options . ' "' . $conn . '" -sql "SELECT * FROM ' . $table . ' WHERE ' . $geom . ' && ST_Transform(ST_MakeEnvelope(' . $xmin . ', ' . $ymin . ', ' . $xmax . ', ' . $ymax . ', ' . $srid . '),' . $source_srid . ')" -progress';
$mycmd = OGR2OGR . ' -s_srs EPSG:' . $source_srid . ' -t_srs EPSG:' . $srid . $options . '-f "' . $format_name . '" "' . $fileName . '.' . strtolower($destinationFormat) . '"' .$source . ' -progress';

chdir(PROJECT_PATH);
chdir(dirname($map));
$output = shell_exec($mycmd);

//if ($output==null) {
Expand Down Expand Up @@ -254,9 +254,12 @@ function sendFile($ctype, $key)
throw new Exception("Session time out or unathorized access!");
}

//get project path from session
$projectPath = $_SESSION["project_path"];

//check command
if ($cmd == 'prepare') {
$resultFile = prepareFile($layername, $map, $query_arr, $format);
$resultFile = prepareFile($layername, $projectPath, $query_arr, $format);
echo json_encode(["success" => true, "message" => base64_encode($resultFile)]);
} elseif ($cmd == 'get') {
$key = $query_arr["key"];
Expand Down
7 changes: 6 additions & 1 deletion admin/qgisproxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ function doGetRequest($query_arr, $map, $client, $http_ver)
} else {
$map = explode(".", $query_arr["map"])[0];
}
$query_arr["map"] = PROJECT_PATH . $query_arr["map"];


//session check
session_start();
Expand All @@ -238,6 +238,11 @@ function doGetRequest($query_arr, $map, $client, $http_ver)
throw new Exception\ClientException("Session time out or unathorized access!", new Request('GET', QGISSERVERURL));
}

//get project path from session
$projectPath = $_SESSION["project_path"];

$query_arr["map"] = $projectPath . '.qgs';

$client = new Client();

if ($request_method == 'GET') {
Expand Down

0 comments on commit 7da56ef

Please sign in to comment.