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

root/Chameleon/trunk/Chameleon/Locate/Locate.phtml

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

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3  * Locate popup application
4  *
5  * @project     CWC2
6  * @revision    $Id:
7  * @purpose     This page is the locate popup window
8  * @author      Sacha Fournier (sfournier@dmsolutions.ca)
9  * @copyright
10  * <b>Copyright (c) 2001, 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  //set the language resource file
31 $szLanguageResource = str_replace("\\","/",dirname(__FILE__))."/Locate.dbf";
32
33
34 // include the supporting php functions
35 include("../session.inc.php");
36 include_once("../CWC2ButtonCache.php");
37
38 // Include geocoder API
39 include_once(COMMON."phpgeocoder/geocoder.php" );
40
41 // List of search services to use
42 include_once(COMMON."phpgeocoder/services/gazetteer_server.php");
43 include_once(COMMON."phpgeocoder/services/gmap_server.php");
44 include_once(COMMON."phpgeocoder/services/postalcode_server.php");
45 include_once(COMMON."phpgeocoder/services/NTS_server.php");
46 include_once(COMMON."phpgeocoder/services/watershed_server.php");
47
48 $szOnload = "";
49 if (isset($http_form_vars['szField']) &&
50     $http_form_vars['szField'] != "")
51 {
52     $szOnload = "removeSpinner()";
53
54     $oGeoCoder = new PHPGeoCoder();
55     $oGeoCoder->oErrorManager =& $_SESSION['gErrorManager'];
56
57     switch($http_form_vars['szField'])
58     {
59     case "placename" :
60     {
61         $oGeoCoder->addSearchAttribute(new PlaceName($http_form_vars['szPlaceName']));
62         $oGeoCoder->addSearchService(new GazetteerServer($oGeoCoder));
63     }break;
64     case "postalcode" :
65     {
66         $oGeoCoder->addSearchAttribute(new PostalCode($http_form_vars['szPostalCode']));
67         $oGeoCoder->addSearchService(new PostalCodeServer($oGeoCoder)) ;
68     }break;
69     case "nts" :
70     {
71         $oGeoCoder->addSearchAttribute(new MapSheet($http_form_vars['szNTS']));
72         $oGeoCoder->addSearchService(new NTSServer($oGeoCoder)) ;
73     } break;
74     case "watershed" :
75     {
76         $oGeoCoder->addSearchAttribute(new WatershedCode($http_form_vars['szWatershed']));
77         $oGeoCoder->addSearchService(new WatershedServer($oGeoCoder)) ;
78     } break;
79     default : break;
80     }
81 }
82
83 $szPlaceName  = ((isset($http_form_vars['szPlaceName'])) ? $http_form_vars['szPlaceName'] :  "");
84 $szPostalCode = ((isset($http_form_vars['szPostalCode'])) ? $http_form_vars['szPostalCode'] : "");
85 $szNTS        = ((isset($http_form_vars['szNTS'])) ? $http_form_vars['szNTS'] : "");
86 $szWatershed  = ((isset($http_form_vars['szWatershed'])) ? $http_form_vars['szWatershed'] : "");
87 ?>
88 <html>
89 <head>
90 <title><?php echo trim($oMLT->get("0", "Find a location")); ?></title>
91 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
92 <script language="JavaScript" src="<?php echo $_SESSION['gszCoreWebPath']; ?>/widgets/js/cwc_dhtml.js" type="text/javascript"></script>
93 <script language="JavaScript" src="<?php echo $_SESSION['gszCoreWebPath']; ?>/widgets/js/cwc_button.js" type="text/javascript"></script>
94 <script language="JavaScript"  type="text/javascript">
95 var szLatLong = "";
96 var bZoomTo = 1;
97 var bAddPoint = 0;
98 var szElementType = "POINT";
99
100 function removeSpinner()
101 {
102     if (document.layers)
103         document.layers[0].visibility = "hide";
104     else
105     if (document.all)
106         document.all.spinner.style.visibility = "hidden";
107     else
108     {
109         objEle = document.getElementById("spinner");
110         objEle.style.visibility = "hidden";
111     }
112 }
113
114 function apply(button, bClose)
115 {
116     if (document.forms[0].placeCoor.selectedIndex != -1)
117     {
118     if (document.forms[0].bZoomTo.checked == true)
119         bZoomTo = 1;
120     else
121         bZoomTo = 0;
122
123     if (document.forms[0].bAddPoint.checked == true)
124         bAddPoint = 1;
125     else
126         bAddPoint = 0;
127
128     szLatLong = document.forms[0].placeCoor[document.forms[0].placeCoor.selectedIndex].value;
129
130     /*
131      * szLatLong is a | delimited string.  First element is the name,
132      * second is the coords ... third is possibly a feature
133      */
134     var aVals = szLatLong.split( "|" );
135
136     if (aVals.length > 2)
137     {
138         szElementType = "FEATURE";
139         szElementType = "RECTANGLE";
140     }
141     else if (aVals.length > 2)
142     {
143         if (aVals[1].indexOf( ";" ) != -1)
144         {
145             szElementType = "RECTANGLE";
146         }
147     }
148
149     if (bClose)
150         CallBackFunc(0);
151     else
152         CallBackFunc(1);
153     }
154     else
155         alert("<?php echo trim($oMLT->get("14", "Please select an item before clicking Ok or Apply")); ?>");
156 }
157
158 function CallBackFunc(actionId)
159 {
160 <?php
161 if (!isset($http_form_vars['szCallbackFunc']))
162 {
163     $_SESSION['gErrorManager']->setError(ERR_WARNING, $oMLT->get( "", "Callback function not set in Locate.phtml"));
164     echo "window.close();\n";
165 }
166 else
167     echo "opener.".$http_form_vars['szCallbackFunc']."(actionId, self);\n";
168 ?>
169 }
170
171 function CloseWindow()
172 {
173     CallBackFunc(2);
174 }
175
176 function OpenWindow()
177 {
178     CallBackFunc(3);
179
180     self.focus();
181 }
182
183 function search(button, name)
184 {
185     document.forms[0].szField.value = name;
186     document.forms[0].submit();
187 }
188
189 </script>
190
191 <link href="<?php echo $szCSSFile; ?>" rel="stylesheet" type="text/css">
192 </head>
193 <body class="page" onLoad="OpenWindow();<?php echo $szOnload; ?>">
194 <?php
195 if (isset($http_form_vars['szField']) &&
196     $http_form_vars['szField'] != "")
197     echo "<div id=spinner style=\"position:absolute;left:25%;top:40%;\"><layer left=10 top=100><img src='".$_SESSION['WAITIMAGE']."' width='".$_SESSION['WAITIMAGEWIDTH']."' height='".$_SESSION['WAITIMAGEHEIGHT']."'></layer></div>";
198     ?>
199 <form name="main" method="POST" action="Locate.phtml?<?php echo SID; ?>">
200
201 <table border=0 cellpadding=1 cellspacing=10>
202   <tr>
203     <td class="layoutTable">
204           <table class="titleArea" width="100%" border="0" cellpadding="4" cellspacing="0">
205         <tr>
206           <td><img src="title_gazetteer.gif" width="22" height="22" align="texttop">&nbsp;<span class="title"><?php echo trim($oMLT->get("1", "Gazetteer Service")); ?></span></td>
207         </tr>
208       </table>
209       <table class="contentArea" width="100%" border="0" cellpadding="4" cellspacing="0">
210         <tr>
211           <td align="center"><p class="helpArea"><?php echo trim($oMLT->get("2", "Please enter the name of the place or feature that you are trying to find in the field below.")); ?></p></td>
212         </tr>
213       </table>
214       <table class="contentArea" border="0" cellspacing="0" cellpadding="4" width="100%">
215         <tr>
216           <td>
217             <table border="0" cellspacing="0" cellpadding="2">
218               <tr>
219                 <td><img src="icon_find_ca_place.gif" width="22" height="22"></td>
220                 <td><span class="label"><?php echo trim($oMLT->get("3", "Place or Feature")); ?>:</span></td>
221                 <td><input class="inputBox" type="text" name="szPlaceName" size="20" value="<?php echo $szPlaceName; ?>"></td>
222                 <td><?php echo makeButton( 'search', 'placename', 'Locate', "icons/icon_locate.png", trim($oMLT->get("6", "Locate Place")), trim($oMLT->get("6", "Locate Place")), array( "width" => 140 ) ); ?></td>
223               </tr>
224               <tr>
225                 <td><img src="icon_find_ca_pcode.gif" width="22" height="22"></td>
226                 <td><span class="label"><?php echo trim($oMLT->get("4", "Postal Code")); ?>:</span></td>
227                 <td><input class="inputBox" type="text" name="szPostalCode" size="20" value="<?php echo $szPostalCode; ?>"></td>
228                 <td><?php echo makeButton( 'search', 'postalcode', 'Locate', "icons/icon_locate.png", trim($oMLT->get("7", "Locate Code")), trim($oMLT->get("7", "Locate Code")), array( "width" => 140 ) ); ?></td>
229               </tr>
230               <tr>
231                 <td><img src="icon_find_ca_nts.gif" width="22" height="22"></td>
232                 <td><span class="label"><?php echo trim($oMLT->get("5", "NTS Map Sheet")); ?>:</span></td>
233                 <td><input class="inputBox" type="text" name="szNTS" size="20" value="<?php echo $szNTS; ?>"></td>
234                 <td><?php echo makeButton( 'search', 'nts', 'Locate', "icons/icon_locate.png", trim($oMLT->get("8", "Locate NTS")), trim($oMLT->get("8", "Locate NTS")), array( "width" => 140 ) ); ?></td>
235               </tr>
236               <tr>
237                 <td><img src="icon_find_ca_watershed.gif" width="22" height="22"></td>
238                 <td><span class="label"><?php echo trim($oMLT->get("18", "Watershed")); ?>:</span></td>
239                 <td><input class="inputBox" type="text" name="szWatershed" size="20" value="<?php echo $szWatershed; ?>"></td>
240                 <td><?php echo makeButton( 'search', 'watershed', 'Locate', "icons/icon_locate.png", trim($oMLT->get("19", "Locate Watershed")), trim($oMLT->get("20", "Locate Watershed by Code")), array( "width" => 140 ) ); ?></td>
241               </tr>
242             </table>
243           </td>
244         </tr>
245       </table>
246     </td>
247   </tr>
248   <tr>
249     <td class="layoutTable">
250           <table class="titleArea" width="100%" border="0" cellpadding="4" cellspacing="0">
251         <tr>
252           <td><img src="title_gazetteer_results.gif" width="22" height="22" align="texttop">&nbsp;<span class="title"><?php echo trim($oMLT->get("9", "Search Results")); ?></span></td>
253         </tr>
254       </table>
255             <table class="contentArea" width="100%" border="0" cellpadding="4" cellspacing="0">
256         <tr>
257           <td align="center"><p class="helpArea"><?php echo trim($oMLT->get("10", "Below are the results of the search. Select one of the locations from the list to display on your map. It may be assigned a point on the map, and/or the map view can be adjusted to better view the selected location.")); ?></p></td>
258                 </tr>
259             </table>
260             <table class="contentArea" border="0" cellspacing="0" cellpadding="4" width="100%">
261                 <tr>
262                     <td>
263                         <span class="nnInputWrap"><select class="inputList" name="placeCoor" size="7">
264 <?php
265 $bResult = false;
266 if (isset($http_form_vars['szField']) &&
267     $http_form_vars['szField'] != "")
268 {
269   $bres = $oGeoCoder->searchServices("", true);
270
271   $aoResult = $oGeoCoder->getResult();
272   $nResult = count($aoResult);
273
274   $bResult = true;
275 }
276 if (!$bResult || $nResult == 0)
277     echo "<option class=\"listItem\" value=\"\">".trim($oMLT->get("11", "No Results Found"))."</options>";
278 else
279 {
280     $i=1;
281     foreach(array_keys($aoResult) as $szKey)
282     {
283         // check if map sheet
284         $aszBBOX     = explode(",", $aoResult[$szKey]->getAttributeValueByName("BBOX"));
285         $nScale      = $aoResult[$szKey]->getAttributeValueByName("SCALE");
286         $szMapSheet  = $aoResult[$szKey]->getAttributeValueByName("MAP_SHEET");
287         $szWatershed = $aoResult[$szKey]->getAttributeValueByName("WATERSHED_NAME");
288
289         if( $szWatershed != "" && count($aszBBOX) == 4)
290         {
291             echo "<option class=\"inputList\" value=\"".$http_form_vars['szWatershed']."|";
292             echo $aszBBOX[0].','.$aszBBOX[1].";";
293             echo $aszBBOX[2].','.$aszBBOX[3]."|";
294             echo $aoResult[$szKey]->getAttributeValueByName("POLYGON")."\">";
295             echo $szWatershed.": ".$aoResult[$szKey]->getAttributeValueByName('NAME_EN');
296             echo "</option>";
297             $i++;
298         }
299         elseif ($nScale != "" && count($aszBBOX) == 4)
300         {
301             echo "<option class=\"inputList\" value=\"".$http_form_vars['szNTS']."|";
302             echo (($aszBBOX[0]+$aszBBOX[2])/2).",";
303             echo (($aszBBOX[1]+$aszBBOX[3])/2).",";
304             echo $nScale."\">";
305             echo (($szMapSheet != "") ? $szMapSheet:$http_form_vars['szNTS']);
306             echo "</option>";
307             $i++;
308         }
309         else
310         {
311             $szPlaceName = $aoResult[$szKey]->getAttributeValueByName("PLACE_NAME");
312             $szEntity    = (($aoResult[$szKey]->getAttributeValueByName("ENTITY")!="") ? "(".$aoResult[$szKey]->getAttributeValueByName("ENTITY").")" : "");
313             $szProvince  = $aoResult[$szKey]->getAttributeValueByName("STATE_PROVINCE");
314             $szLatLong   = $aoResult[$szKey]->getAttributeValueByName("LAT_LONG");
315
316             if ($szPlaceName != "" && $szLatLong != "")
317             {
318                 echo "<option class=\"inputList\" value=\"$szPlaceName, $szProvince|$szLatLong\">$i) $szPlaceName, $szProvince $szEntity</option>";
319                 $i++;
320             }
321         }
322     }
323 }
324 ?>
325             </select></span>
326           </td>
327           <td width=100%>
328 <?php
329 if (isset($oGeoCoder))
330     while ($oErr = $oGeoCoder->oErrorManager->popLastError())
331     {
332         echo "<font face=Arial size=2 color=red>ERROR ".$oErr->nErrorType.": ".$oErr->szMessage."</FONT>";
333     }
334 ?>
335           </td>
336         </tr>
337         <tr>
338           <td colspan=2 align="right"><span class="label">&nbsp;</span>
339                         <table border="0" cellspacing="0" cellpadding="2">
340                             <tr>
341                                 <td><span class="label">
342                                     <!--
343 <input type="checkbox" name="bNewPoint" value="1" checked>
344 -->
345                     </span></td>
346                 <td>
347                         <!--
348 <span class="label">Place a point on my map for this location.</span>
349 -->
350                 </td>
351               </tr>
352               <tr>
353                   <td>
354                     <span class="label"><input type="checkbox" name="bZoomTo" value="1" checked></span><br>
355                       <span class="label"><input type="checkbox" name="bAddPoint" value="1"></span>
356                   </td>
357                   <td>
358                       <span class="label"><?php echo trim($oMLT->get("12", "Set map view to better see this location.")); ?></span><br>
359                       <span class="label"><?php echo trim($oMLT->get("13", "Add a point to this location.")); ?></span>
360                   </td>
361               </tr>
362             </table>
363           </td>
364         </tr>
365       </table>
366     </td>
367   </tr>
368   <tr>
369     <td align=right>
370       <table border="0" cellspacing="0" cellpadding="0">
371         <tr>
372           <td><?php echo makeButton( 'apply', 'false', 'Locate', "icons/icon_update.png", trim($oCommonMLT->get("Apply", "Apply")), trim($oCommonMLT->get("Apply", "Apply")), array( "width" => 100 ) ); ?></td>
373           <td>&nbsp;&nbsp;</td>
374           <td><?php echo makeButton( 'apply', 'true', 'Locate', "icons/icon_ok.png", trim($oCommonMLT->get("Ok", "Ok")), trim($oCommonMLT->get("OkTip", "Apply and close")), array( "width" => 100 ) ); ?></td>
375           <td>&nbsp;&nbsp;</td>
376           <td><?php echo makeButton( 'CloseWindow', '', 'Locate', "icons/icon_cancel.png", trim($oCommonMLT->get("Cancel", "Cancel")), trim($oCommonMLT->get("CancelTip", "Close Dialog")), array( "width" => 100 ) ); ?></td>
377         </tr>
378       </table>
379     </td>
380   </tr>
381 </table>
382
383 <!--------------------------->
384 <!-- HIDDEN VARIABLES BEGIN-->
385 <!--------------------------->
386 <input type="HIDDEN" name="szCallbackFunc" value="<?php echo $http_form_vars['szCallbackFunc']; ?>">
387 <input type="HIDDEN" name="szField" value="">
388 </form>
389 </body>
390 </html>
Note: See TracBrowser for help on using the browser.