[Chameleon] costum query
Jason Fournier
jfournier at dmsolutions.ca
Thu Aug 12 22:02:26 EDT 2004
Alberto,
QueryResults.phtml is divided up into 3 sections (to account for
different datasources - MS WMS, CubeWerx WMS, and local datasources).
You need to modify the local data source block of code (if, in fact,
your data is local) with the supplied check.
You'll want to a) check for correct layer and b) search an inclusion
array of fields with in_array for the fields you want.
Hope this helps,
Jay
Alberto Cavalli wrote:
> Hi dear, I've found this interesting post about custom query and I tried it,
> but it doesn't work. I replaced the code in my query.phtml file but the
> result of query remain the same. I've 6 field in my dbf (info_id, info,
> num_foglio; num_part;area; espr1) and I'd like to see in my query only 3 of
> them
> Can someone hel me?
> thanks
> Alberto
>
>
>
>
> http://lists.maptools.org/pipermail/chameleon/2004-May/000842.html
>
> THIS IS MY CODE
>
>
> <?php
>
> *
>
> ****************************************************************************
> */
>
> // include the global preferences
> include_once( "./globprefs.php" );
>
> /*
> ============================================================================
> * HTTP_FORM_VARS array contains the HTTP GET or POST parameters
> * =========================================================================
> */
> $http_form_vars = count( $_POST ) > 0 ? $_POST :
> ( count($_GET) > 0 ? $_GET : array("")
> );
>
> //DEBUG
> /*foreach ($http_form_vars as $key => $value)
> {
> echo "Key: $key; Value: $value<br>\n";
> }
>
> /*
> ============================================================================
> * Re-instate the previous map state
> * =========================================================================
> */
> // determine previous state key
> if ( isset( $http_form_vars["PrevStateKey"] ) )
> $szPrevStateKey = $http_form_vars["PrevStateKey"];
> else
> $szPrevStateKey = "";
>
> // restore the previous state
> $oMapSession->restoreState( $szPrevStateKey, MAPFILE );
>
> /*
> ============================================================================
> * Run query
> * =========================================================================
> */
> // only process if coordinates are given
> if ( isset( $http_form_vars["INPUT_COORD"] ) &&
> strlen( trim( $http_form_vars["INPUT_COORD"] ) ) > 0 )
> {
> // initalize vars
> $gaszWMSResults = array();
>
> // process coordinates
> $aszMinMax = explode(";", $http_form_vars["INPUT_COORD"]);
> $adMin = explode(",", $aszMinMax[0]);
> $adMax = explode(",", $aszMinMax[1]);
>
> // loop through all layers and add to list of layers to query
> // NOTE: Layers will only have results generated for them if they
> // have a "template" value set. The template value does not have
> // to be valid, it could be as simple as "ttt".
> $aszLayers = array();
> $oMap = $oMapSession->oMap;
> $nCount = $oMap->numlayers;
> for ( $i=0; $i<$nCount; $i++ )
> {
> // get layer name
> $oLayer = $oMap->getLayer( $i );
>
> // only add if on
> if ( $oLayer->status == MS_ON || $oLayer->status == MS_DEFAULT )
> array_push( $aszLayers, $oLayer->name );
>
> }
>
> // commit
> $oMapQuery->setQueryLayersByName( $aszLayers );
>
> // execute query
> if ( is_numeric( $adMax[0] ) && is_numeric( $adMax[1] ) )
> $oResultSet = $oMapQuery->executeRectQuery( $adMin[0],
> $adMin[1],$adMax[0], $adMax[1] );
> else
> $oResultSet = $oMapQuery->executePointQuery( $adMin[0],
> $adMin[1] );
>
> // format the query results
> $szResults = formatQueryResults( $oResultSet, $aszLayers );
> }
> else
> $szResults = "Nessun Risultato";
>
>
> /**
> * This function takes the query result set object and processes all result
> * sets and formats them into a single html table string.
> *
> * @param $oResultSet object - The result set object to read.
> * @return string - An html table of result values.
> **/
> function formatQueryResults( $oResultSet, $aszLayers )
> {
> global $gaszWMSResults;
>
> // initialize the variables
> $szReturnValue = "";
> $aszNoResults = array();
>
> // loop through each result set and return
> $nCount = $oResultSet->nNumResults;
>
> for ( $i=0; $i<$nCount; $i++ )
> {
>
> // process each result set
> $aRows = $oResultSet->getResultSet( $i );
>
> // check if single or multiple results were returned
> if ( is_array( $aRows ) )
> {
> // build title rows
> $szReturnValue .= "<tr>\n";
> $szReturnValue .= "<td>\n";
> $szReturnValue .= "<table bgcolor=\"#c1d8e3\" width=\"100%\"
> border=\"0\" cellspacing=\"1\" cellpadding=\"2\">\n";
> $szReturnValue .= "<tr>\n";
>
> $szReturnValue .= "<td colspan=".count($aRows[0])."
> bgcolor=\"C1D8E3\"><font face=\"Arial, Helvetica, sans-serif\"
> size=\"2\"><u><b>".$aszLayers[$i]."</b></u></font></td>\n";
>
> $szReturnValue .= "</tr>\n";
> $szReturnValue .= "<tr>\n";
>
> ########### NEW CODE
>
> // loop and use key for titles
> foreach ($aRows[0] as $key => $value)INFO_ID; INFO;
> NUM_FOGLIO;NUM_PART; AREA;
> {
> $szReturnValue .= "<td class=\"PARTICELLE\"><p>>
> class=\"text\">".$key."</p></td>\n";
> }
> $szReturnValue .= "</tr>\n";
>
> // loop through the results and format each row
> foreach ( $aRows as $aRow )
> {
> // add a row for each
> $szReturnValue .= "<tr>\n";
>
> // loop and add a cell for each result
> foreach ( $aRow as $xCell )
> {
> $szReturnValue .= "<td
> class=\"subContentArea1\"><p class=\"text\">". $xCell."</p></td>\n";
> }
>
> $szReturnValue .= "</tr>\n";
> }
>
> // loop and use key for titles
> foreach ($aRows[0] as $key => $value)
> {
> if (strcasecmp($key, "espr1") == 0 ||
> strcasecmp($key, "num_foglio") == 0)
> continue;
> $szReturnValue .= "<td class=\"subContentArea2\"><p
> class=\"text\">".$key."</p></td>\n";
> }
> $szReturnValue .= "</tr>\n";
>
> // loop through the results and format each row
> foreach ( $aRows as $aRow )
> {
> // add a row for each
> $szReturnValue .= "<tr>\n";
>
> // loop and add a cell for each result
> foreach ( $aRow as $key => $xCell )
> {
> if (strcasecmp($key, "espr1") == 0 ||
> strcasecmp($key, "num_foglio") == 0)
> continue;
> $szReturnValue .= "<td class=\"subContentArea1\"><p
> class=\"text\">". $xCell."</p></td>\n";
> }
>
> $szReturnValue .= "</tr>\n";
> }
>
>
> ##################### ENDING MY CODE
>
>
> // close the table
> $szReturnValue .= "</table>\n";
> $szReturnValue .= "</td>\n";
> $szReturnValue .= "</tr>\n";
> }
> else
> {
> // check if wms
> if ( substr( $aRows, 0, 26 ) == "No results found for layer" )
> array_push( $aszNoResults, $aszLayers[$i] );
> else
> {
> $nTmpCount = count( $gaszWMSResults );
> $gaszWMSResults[$nTmpCount][0] = $aRows;
> $gaszWMSResults[$nTmpCount][1] = $aszLayers[$i];
> }
> }
>
> // end loop of layers
> }
>
> // add the list of layer that return no results
> $nCountNoResults = count( $aszNoResults );
> if ( $nCountNoResults > 0 )
> {
> $szReturnValue .= "<tr>\n";
> $szReturnValue .= "<td>\n";
> $szReturnValue .= "<table bgcolor=\"#999999\" width=\"100%\"
> border=\"0\" cellspacing=\"1\" cellpadding=\"2\">\n";
> $szReturnValue .= "<tr>\n";
>
> // $szReturnValue .="<th align=\"LEFT\" width=\"50%\">\n";
>
> $szReturnValue .= "<td bgcolor=\"#C1D8E3\"><font face=\"Arial,
> Helvetica, sans-serif\" size=\"2\"><b>I seguenti layer non hanno fornito
> alcun risultato:</b></font></td>\n";
>
> //$szReturnValue .="</th>\n";
>
>
> $szReturnValue .= "</tr>\n";
> $szReturnValue .= "<tr>\n";
> $szReturnValue .= "<td bgcolor=\"E2EFF5\"><font face=\"Arial,
> Helvetica, sans-serif\" size=\"2\">";
>
> for ($i=0; $i<$nCountNoResults; $i++)
> {
> $szReturnValue .= $aszNoResults[$i];
> if ( $i < $nCountNoResults - 1) $szReturnValue .= ", ";
> }
> $szReturnValue .= "</font></td>\n";
> $szReturnValue .= "</tr>\n";
> $szReturnValue .= "</table>\n";
> $szReturnValue .= "</td>\n";
> $szReturnValue .= "</tr>\n";
> }
>
> // return the formated string
> return $szReturnValue;
>
> // end formatQueryResults function
> }
>
> ?>
> <html>
> <head>
> <title>Query Results</title>
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
> <body bgcolor="#ebebeB" leftmargin="0" topmargin="0" marginwidth="0"
> marginheight="0">
>
>
> <table bgcolor="#ebebeB" border="0" width="100%">
> <tr>
> <th align="LEFT" width="50%">
> <h1><font color="#005de8" size="6"><b>COMUNE DI SAN
> GIORGIO P.no</b></font></h1>
> <h1><font color="#005de8" size="2"><b>Piazza Torrione,
> 4 - Tel. 0523.370711</b></font></h1>
>
> </th>
> <th align="right" width="50%">
> <h1><A HREF="http://www.sintranet.it"><IMG
> SRC="http://devserver/testsite/maplab213/projects/gmf_apps/SGiorgio_cadastra
> l/images//Stemma.gif" WIDTH="80" HEIGHT="120" BORDER="0" ></A></h1>
>
> </th>
>
>
>
>
> </tr>
>
>
>
> </table>
>
>
>
>
>
> <form name="main">
> <table bgcolor="#FFCC99" border=0 cellspacing=10 cellpadding=0>
> <?php
> // process wms layers first
> $nCountWMS = count( $gaszWMSResults );
> if ( $nCountWMS > 0 )
> {
> // add a warnning message for WMS layers
> echo "<tr>\n";
> echo "<td>\n";
> echo "<table bgcolor=\"#999999\" width=\"100%\" border=\"0\"
> cellspacing=\"1\" cellpadding=\"2\">\n";
> echo "<tr>\n";
> echo "<td bgcolor=\"ffffff\"><font face=\"Arial, Helvetica, sans-serif\"
> size=\"2\" color=\"999999\">Note: WMS layers can only be queried as a point.
> If a rectangle query is used, the center of the rectangle will be used as
> the query location.</font></td>\n";
> echo "</tr>\n";
> echo "</table>\n";
> echo "</td>\n";
> echo "</tr>\n";
>
> // loop
> for ( $i=0; $i<$nCountWMS; $i++ )
> {
> // add header
> echo "<tr>\n";
> echo "<td>\n";
> echo "<table bgcolor=\"#999999\" width=\"100%\" border=\"0\"
> cellspacing=\"1\" cellpadding=\"2\">\n";
> echo "<tr>\n";
> echo "<td bgcolor=\"C1D8E3\"><font face=\"Arial, Helvetica,
> sans-serif\"
> size=\"2\"><u><b>".$gaszWMSResults[$i][1]."</b></u></font></td>\n";
> echo "</tr>\n";
>
> // begin new row
> echo "<tr>\n";
> echo "<td bgcolor=\"#E2EFF5\"><pre>\n";
>
> // read URL
> readfile( $gaszWMSResults[$i][0] );
>
> // close row
> echo "</pre></td>\n";
> echo "</tr>\n";
> echo "</table>\n";
> echo "</td>\n";
> echo "</tr>\n";
> }
> }
>
> // display the rest if the query results
> echo $szResults;
>
>
>
> ?>
> </table>
> </form>
> </body>
> </html>
> _______________________________________________
> Chameleon mailing list
> Chameleon at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/chameleon
>
--
_____________________________
10 Jason Fournier
20 Applications Development
40 DM Solutions Group Inc.
50 jfournier at dmsolutions.ca
60 GOTO www.dmsolutions.ca
70 REM 613.565.5056 x18
More information about the Chameleon
mailing list