NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/Chameleon/trunk/Chameleon/Z39Query/Z39Query.php

Revision 13 (checked in by jcleary, 17 years ago)

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3  * Z39Query Helper script
4  *
5  * @project     Chameleon
6  * @revision    $Id: Z39Query.php,v 1.3 2004/12/03 03:31:57 pspencer Exp $
7  * @purpose     Help build and execute Z39 Queries
8  * @author      Jason Fournier (dev@dmsolutions.ca)
9  * @copyright
10  * <b>Copyright (c) 2003, DM Solutions Group Inc.</b>
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included
19  * in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  */
29
30 /**
31  * set the flag to setup the mapsession
32  */
33 //if ( !defined("LOAD_MAPSESSION") )
34 //    define("LOAD_MAPSESSION", 1);
35
36 /**
37  * include the session handling file
38  */
39 include_once("./session.inc.php");
40 include_once("../CWC2ButtonCache.php");
41
42 /**
43  * get the form vars
44  */
45 $_FORM = array_merge( $_GET, $_POST );
46 $szMapFile = "D:/ms4w/apps/scihi/map/testbed11.map";
47
48 /**
49  * Check for submit
50  * Process as required
51  */
52 if( isset($_FORM['formSubmit']) && ($_FORM['formSubmit'] == 1) )
53 {
54     // Construct the URL
55    
56     // these two vars should have come from the widget declaration
57     $szSearchURL = $_POST['SearchServer'];
58     //$szSearchURL .= '&responsestylesheet='.$_FORM['responsestylesheet'];
59    
60     // Comma Delimited Collection
61     $szSearchURL .= '&collection='.urlencode($_FORM['collection']);
62    
63     // Comma Delimited Search String
64     $szSearchURL .= '&searchstring='.$_FORM['searchstring'];
65     $szSearchURL .= "&searchtype=".$_FORM['searchtype'];
66    
67     // Dates
68     $szSearchURL .= "&begdate=".$_FORM['begdate'];
69     $szSearchURL .= "&enddate=".$_FORM['enddate'];
70    
71     // BBOX - checked for consistency onSubmit through javascript
72     $szSearchURL .= "&north=".$_FORM['north'];
73     $szSearchURL .= "&east=".$_FORM['east'];
74     $szSearchURL .= "&south=".$_FORM['south'];
75     $szSearchURL .= "&west=".$_FORM['west'];
76    
77     // Integer delimiters
78     $szSearchURL .= "&searchoffset=".$_FORM['searchoffset'];
79     $szSearchURL .= "&searchdisplaycount=".$_FORM['searchdisplaycount'];
80     $szSearchURL .= "&outputmethod=GML";
81     $szSearchURL .= "&displaytype=BRIEF";
82    
83     //echo "Searching server with URL: $szSearchURL <BR>";
84     $time_start = getmicrotime();
85     if( !$szResponse = trim( @file_get_contents( $szSearchURL ) ) )
86         echo $szErrMsg = "<b><font color=maroon>Could not contact Server</b></font><br>";
87        
88     $time_end = getmicrotime();
89     $time = $time_end - $time_start;
90
91     // We got something back from the file_get_contents
92     if ($szResponse != '')
93     {
94         // At least one record returned?
95         if( stristr($szResponse, 'envirodatMetadataMember') )
96         {
97             //$szFilePath = getSessionSavePath() . $_FORM['GMLName'];
98             $szFilePath = 'D:/ms4w/apps/scihi/data/GML/sampleGML.gml';
99             $hOutFile = @fopen( $szFilePath, "w+" );
100             if ($hOutFile)
101             {
102                 // Successfully opened the GML document for writing
103                 // Write the contents to the doc
104                 fwrite( $hOutFile, $szResponse );
105                 fclose( $hOutFile );
106                 $bUpdateMap = 1;
107             }
108             else
109             {
110                 // Error opening the static GML document for writing
111                 echo $szErrMsg = "<b><font color=maroon>There was a problem opening the GML document in write mode</b></font><br>";
112                 $bUpdateMap = 0;
113             }
114         }
115         else
116         {
117             // Zero records returned from the query
118             echo $szErrMsg = "<b><font color=maroon>No Records found in resulting dataset</b></font><br>";
119             $bUpdateMap = 0;
120         }
121     }
122     else
123     {
124         // Error getting the GML from the server
125         echo $szErrMsg = "<b><font color=maroon>There was a problem obtaining the GML from the server</b></font><br>";
126         $bUpdateMap = 0;
127     }
128    
129     // Assuming there was no problem obtaining the GML let's
130     // write the results to a SharedResource
131    
132    
133    
134    
135     echo "<br><br>Query for ".$_FORM['searchdisplaycount']." stations took ". round($time, 3) ." seconds<br><br>";
136    
137     if( $bUpdateMap == 1 )
138     {
139    
140         // Set the file path in the mapfile
141         // if (!extension_loaded('MapScript'))
142         //     dl( "php_mapscript_40.dll" );
143         //$oMap = ms_newMapObj( $szMapFile );
144         //$oLayer = $oMap->GetLayerByName( 'envirodatGML' );
145         //$oLayer->set( "CONNECTION", $szFilePath );
146
147         // Call the opener function as defined in the widget
148         echo "<script language='JavaScript  type='text/javascript'>\n";
149         echo "opener.location.reload();";
150         //
151         //echo window.opener.applyZ39BoundingBox($_FORM['west'], $_FORM['south'], $_FORM['east'], $_FORM['north']);
152         //
153         echo "self.focus();";
154         echo "</script>\n";
155        
156     }
157    
158 }
159 else // this else populates the bbox
160 {
161     // take coords from FORM is available
162     if (isset( $_FORM['north'] ) )
163     {
164         $nMinX = $_FORM['west'];
165         $nMinY = $_FORM['south'];
166         $nMaxX = $_FORM['east'];
167         $nMaxY = $_FORM['north'];
168
169         $bSetDD = false;
170     }
171
172     // Check for the ROIManager inputs and set coords appropriately
173     else if ( isset( $_SESSION['ROIRENDERER'] ) &&
174               is_array( $_SESSION['ROIRENDERER'] ) &&
175               isset( $_SESSION['ROIRENDERER'][0]["aGeoCoords"] ) &&
176               is_array( $_SESSION['ROIRENDERER'][0]["aGeoCoords"] )
177             )
178     {
179         // set extents form ROIManager
180         // hardcoded for one AOI box only
181         $nMinX = $_SESSION['ROIRENDERER'][0]["aGeoCoords"][0];
182         $nMinY = $_SESSION['ROIRENDERER'][0]["aGeoCoords"][1];
183         $nMaxX = $_SESSION['ROIRENDERER'][0]["aGeoCoords"][2];
184         $nMaxY = $_SESSION['ROIRENDERER'][0]["aGeoCoords"][3];
185        
186         $bSetDD = true;
187     }
188     elseif( isset( $oMapSession->oMap->extent->minx  ) )
189     {
190         // default to current extents
191         $nMinX = round( $oMapSession->oMap->extent->minx, 4 );
192         $nMinY = round( $oMapSession->oMap->extent->miny, 4 );
193         $nMaxX = round( $oMapSession->oMap->extent->maxx, 4 );
194         $nMaxY = round( $oMapSession->oMap->extent->maxy, 4 );
195
196         $bSetDD = true;
197     }
198     else
199     {
200         // default to arbitrary extents
201         $nMinX = 0;
202         $nMinY = 0;
203         $nMaxX = 0;
204         $nMaxY = 0;
205
206         $bSetDD = false;
207     }
208    
209     if( $bSetDD )
210     {
211    
212         // What's the projection?  If it's not 4326 then we convert to DD
213         if (!extension_loaded( 'MapScript' ))
214             dl( "php_mapscript_40.dll" );
215         $oNewMap = ms_newMapObj($szMapFile);
216         $szCurrProj = $oNewMap->getProjection();
217         if( !stristr( strtolower($szCurrProj), 'init=epsg:4326' ) )
218         {
219             $oProjIn = ms_newprojectionobj( $szCurrProj );
220             $oProjOut = ms_newprojectionobj( "init=epsg:4326" );
221             $oRect = ms_newRectObj();
222             $oRect->setextent( $nMinX, $nMinY, $nMaxX, $nMaxY );
223             $oRect->project( $oProjIn, $oProjOut );
224
225             $nMinX = round( $oRect->minx, 4 );
226             $nMinY = round( $oRect->miny, 4 );
227             $nMaxX = round( $oRect->maxx, 4 );
228             $nMaxY = round( $oRect->maxy, 4 );
229         }
230     }
231
232 }
233
234
235
236
237 /**
238  * Helper functions
239  */
240 function getmicrotime()
241 {
242     list($usec, $sec) = explode(" ",microtime());
243     return ((float)$usec + (float)$sec);
244 }
245
246
247 ?>
Note: See TracBrowser for help on using the browser.