Skip to content

Commit

Permalink
Make the new stuff work with HelloWorld sample project.
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Jan 13, 2014
1 parent ed36e78 commit 8dca812
Show file tree
Hide file tree
Showing 16 changed files with 304 additions and 392 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Expand Up @@ -12,3 +12,8 @@ README.toc
index.xml
qgis-web-client.conf
*.swp

site/js/Customizations.js
site/js/GlobalOptions.js
.gitignore

1 change: 0 additions & 1 deletion cgi-bin/qgis_mapserv.fcgi

This file was deleted.

20 changes: 20 additions & 0 deletions cgi-bin/qgis_mapserv.fcgi
@@ -0,0 +1,20 @@
#!/bin/bash


if [ ! -z "$1" ]; then
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/ale/apps/lib ; export LD_LIBRARY_PATH
QGIS_PROJECT_FILE=/home/ale/public_html/asti/QGIS-Web-Client/projects/asti.qgs \
QGIS_DEBUG=1 \
QGIS_LOG_FILE=/tmp/qgis.log \
QUERY_STRING=$1 \
/home/ale/apps/bin/qgis_mapserv.fcgi

else

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/ale/apps/lib ; export LD_LIBRARY_PATH
QGIS_PROJECT_FILE=/home/ale/public_html/asti/QGIS-Web-Client/projects/asti.qgs \
QGIS_DEBUG=1 \
QGIS_LOG_FILE=/tmp/qgis.log \
/home/ale/apps/bin/qgis_mapserv.fcgi

fi
3 changes: 2 additions & 1 deletion php/README.rst
Expand Up @@ -43,7 +43,8 @@ table names, this in order to not disclose internal DB details.
Configuration
-------------

Configuration for the services is stored in `config.php`.
Configuration for the services is stored in `config.php`. You can use
the provided `config.php.tpl` as a starting point.

Example:

Expand Down
54 changes: 0 additions & 54 deletions php/config.php

This file was deleted.

38 changes: 27 additions & 11 deletions php/helpers.php
Expand Up @@ -36,14 +36,14 @@ function get_project($map){
}

/**
* Get postgis layer connection and geom info
* Get layer connection and geom info
*/
function get_pg_layer_info($layer, $project){
function get_layer_info($layer, $project){
// Cache
static $pg_layer_infos = array();

if(!$layer->provider == 'postgis'){
err500('not a postgis layer');
if((string)$layer->provider != 'postgis' && (string)$layer->provider != 'spatialite'){
err500('only postgis or spatialite layers are supported');
}
// Datasource
$datasource = (string)$layer->datasource;
Expand All @@ -52,9 +52,10 @@ function get_pg_layer_info($layer, $project){
return $pg_layer_infos[$datasource];
}


// Parse datasource
$ds_parms = array();
$ds_parms = array(
'provider' => (string)$layer->provider
);
// First extract sql=
if(preg_match('/sql=(.*)/', $datasource, $matches)){
$datasource = str_replace($matches[0], '', $datasource);
Expand Down Expand Up @@ -121,17 +122,32 @@ function get_categories($layer){
/**
* Get connection from layer
*/
function get_connection($layer, $project){

$ds_parms = get_pg_layer_info($layer, $project);
$PDO_DSN="pgsql:host=${ds_parms['host']};port=${ds_parms['port']};dbname=${ds_parms['dbname']}";
function get_connection($layer, $project, $map_path){

$ds_parms = get_layer_info($layer, $project);
if($ds_parms['provider'] == 'postgis') {
$PDO_DSN="pgsql:host=${ds_parms['host']};port=${ds_parms['port']};dbname=${ds_parms['dbname']}";
} else { // Spatialite
// Calculate directory
$dbpath = preg_replace("/'?([^']+)'?/", '\1', $ds_parms['dbname']);
if($dbpath[0] != DIRECTORY_SEPARATOR){
$dbpath = dirname($map_path) . DIRECTORY_SEPARATOR . $dbpath;
}
if(!file_exists($dbpath)){
err500('sqlite fle not found.');
}
$PDO_DSN="sqlite:$dbpath";
}

try {
$dbh = new PDO($PDO_DSN, $ds_parms['user'], $ds_parms['password']);
$dbh = new PDO($PDO_DSN, @$ds_parms['user'], @$ds_parms['password']);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
err500('db error: ' . $e->getMessage());
}
if($ds_parms['provider'] == 'sqlite') {
$dbh->loadExtension('libspatialite.so');
}
return $dbh;
}

Expand Down
61 changes: 46 additions & 15 deletions php/search.php
Expand Up @@ -40,31 +40,23 @@
}

/**
* Build SQL query, here also searchtable is layer name
* Build postgis SQL query, here also searchtable is layer name
*/
function build_search_query($dbtable, $search_column, $geom_column, $layername, $querystrings, $sql_filter){
function build_postgis_search_query($dbtable, $search_column, $geom_column, $layername, $querystrings, $sql_filter){
$sql = "SELECT $search_column as displaytext, '$layername' AS searchtable, '$layername' as search_category, ";
# the following line is responsible for zooming in to the features
# this is supposed to work in PostgreSQL since version 9.0
$sql .= "'['||replace(regexp_replace(BOX2D($geom_column)::text,'BOX\(|\)','','g'),' ',',')||']'::text AS bbox ";
# if the above line does not work for you, deactivate it and uncomment the next line
#sql += "'['||replace(regexp_replace(BOX2D(the_geom)::text,'BOX[(]|[)]','','g'),' ',',')||']'::text AS bbox "
#sql .= "'['||replace(regexp_replace(BOX2D(the_geom)::text,'BOX[(]|[)]','','g'),' ',',')||']'::text AS bbox ";
$sql .= "FROM ".$dbtable." WHERE ";
// Add sql filter if any
if($sql_filter){
$sql .= $sql_filter . ' AND ';
}
#for each querystring
for($j = 0; $j < count($querystrings); $j++){
# to implement a search method uncomment the sql and its following data line
# for tsvector issues see the docs, use whichever version works best for you
# this search does not use the field searchstring_tsvector at all but converts searchstring into a tsvector, its use is discouraged!
#sql += "searchstring::tsvector @@ lower(%s)::tsquery"
#data += (querystrings[j]+":*",)
# this search uses the searchstring_tsvector field, which _must_ have been filled with to_tsvector('not_your_language', 'yourstring')
#sql += "searchstring_tsvector @@ to_tsquery(\'not_your_language\', %s)"
#data += (querystrings[j]+":*",)
# if all tsvector stuff fails you can use this string comparison on the searchstring field

$sql .= "$search_column ILIKE '%" . $querystrings[$j] . "%'";

if ($j < count($querystrings) - 1){
Expand All @@ -74,19 +66,58 @@ function build_search_query($dbtable, $search_column, $geom_column, $layername,
return $sql;
}


/**
* Build spatialite SQL query, here also searchtable is layer name
*/
function build_spatialite_search_query($dbtable, $search_column, $geom_column, $layername, $querystrings, $sql_filter){
$sql = "SELECT load_extension('libspatialite.so'); PRAGMA case_sensitive_like=OFF; SELECT $search_column as displaytext, '$layername' AS searchtable, '$layername' as search_category, ";
# the following line is responsible for zooming in to the features
# this is supposed to work in PostgreSQL since version 9.0
$sql .= "'['||replace(regexp_replace(envelope($geom_column),'BOX\(|\)','','g'),' ',',')||']' AS bbox ";
# if the above line does not work for you, deactivate it and uncomment the next line
#sql .= "'['||replace(regexp_replace(BOX2D(the_geom)::text,'BOX[(]|[)]','','g'),' ',',')||']'::text AS bbox ";
$sql .= "FROM ".$dbtable." WHERE ";
// Add sql filter if any
if($sql_filter){
$sql .= $sql_filter . ' AND ';
}
#for each querystring
for($j = 0; $j < count($querystrings); $j++){

$sql .= "$search_column LIKE '%" . $querystrings[$j] . "%'";

if ($j < count($querystrings) - 1){
$sql .= " AND ";
}
}
return $sql;
}

$sql = array();
foreach($searchlayers as $layername){
// Get layer
$layer = get_layer($layername, $project);
$ds_params = get_pg_layer_info($layer, $project);
$ds_params = get_layer_info($layer, $project);
if(array_key_exists($layername, $searchlayers_config)){
$sql[] = build_search_query($ds_params['table'],
if($ds_params == 'postgis'){
$sql[] = build_postgis_search_query($ds_params['table'],
$searchlayers_config[$layername]['search_column'],
$ds_params['geom_column'],
$layername,
$querystrings,
$ds_params['sql']
);
} else {
// Spatialite
$sql[] = build_spatialite_search_query($ds_params['table'],
$searchlayers_config[$layername]['search_column'],
$ds_params['geom_column'],
$layername,
$querystrings,
$ds_params['sql']
);
}
} else {
// Silently skip...
}
Expand All @@ -101,7 +132,7 @@ function build_search_query($dbtable, $search_column, $geom_column, $layername,
$sql .= ';';
//die($sql);
// Get connection from the last layer
$dbh = get_connection($layer, $project);
$dbh = get_connection($layer, $project, $map);
$stmt = $dbh->prepare($sql);
$stmt->execute();

Expand Down
2 changes: 1 addition & 1 deletion php/search_geom.php
Expand Up @@ -34,7 +34,7 @@
// Get layer
$layer = get_layer($layername, $project);

$ds_params = get_pg_layer_info($layer, $project);
$ds_params = get_layer_info($layer, $project);

$sql = "SELECT ST_AsText(${ds_params['geom_column']}) AS geom FROM " . $ds_params['table'] . " WHERE ${layer_config['search_column']} = ?";
$dbh = get_connection($layer, $project);
Expand Down
2 changes: 1 addition & 1 deletion php/unique_list.php
Expand Up @@ -30,7 +30,7 @@

try {
$dbh = get_connection($layer, $project);
$ds_parms = get_pg_layer_info($layer, $project);
$ds_parms = get_layer_info($layer, $project);
$_field = preg_replace('/[^A-z0-9_-]]/','',$field);
$stmt = $dbh->prepare("SELECT DISTINCT $_field FROM ${ds_parms['table']} ORDER BY $_field");
$stmt->execute();
Expand Down
4 changes: 2 additions & 2 deletions site/gis_icons/.directory
@@ -1,4 +1,4 @@
[Dolphin]
Timestamp=2012,11,13,14,37,47
PreviewsShown=true
Timestamp=2014,1,1,9,55,53
Version=3
ViewMode=1

0 comments on commit 8dca812

Please sign in to comment.