]> git.openstreetmap.org Git - nominatim.git/blob - lib/template/search-html.php
Add simple/structured query selector to HTML search page (#1722)
[nominatim.git] / lib / template / search-html.php
1 <?php
2     header("content-type: text/html; charset=UTF-8");
3 ?>
4 <?php include(CONST_BasePath.'/lib/template/includes/html-header.php'); ?>
5     <link href="css/common.css" rel="stylesheet" type="text/css" />
6     <link href="css/search.css" rel="stylesheet" type="text/css" />
7 </head>
8
9 <body id="search-page">
10
11     <?php include(CONST_BasePath.'/lib/template/includes/html-top-navigation.php'); ?>
12
13         <div class="top-bar" id="structured-query-selector">
14             <div class="search-type-link">
15                 <a id="switch-to-reverse" href="<?php echo CONST_Website_BaseURL; ?>reverse.php?format=html">reverse search</a>
16             </div>
17         <?php
18         if (empty($aMoreParams['q']) and empty($aMoreParams['street']) and empty($aMoreParams['city']) and empty($aMoreParams['county']) and empty($aMoreParams['state']) and empty($aMoreParams['country']) and empty($aMoreParams['postalcode'])) {
19             echo '<div class="radio-inline"><input type="radio" name="query-selector" id="simple" value="simple" checked="checked">';
20             echo '<label for="simple">simple</label></div>';
21             echo '<div class="radio-inline"><input type="radio" name="query-selector" id="structured" value="structured">';
22             echo '<label for="structured">structured</label></div>';
23         }
24         elseif (!empty($aMoreParams['q'])) {
25             echo '<div class="radio-inline"><input type="radio" name="query-selector" id="simple" value="simple" checked="checked">';
26             echo '<label for="simple">simple</label></div>';
27             echo '<div class="radio-inline"><input type="radio" name="query-selector" id="structured" value="structured">';
28             echo '<label for="structured">structured</label></div>';
29         }
30         else {
31             echo '<div class="radio-inline"><input type="radio" name="query-selector" id="simple" value="simple">';
32             echo '<label for="simple">simple</label></div>';
33             echo '<div class="radio-inline"><input type="radio" name="query-selector" id="structured" value="structured" checked="checked">';
34             echo '<label for="structured">structured</label></div>';
35         }
36         ?>
37
38     <form role="search" accept-charset="UTF-8" action="<?php echo CONST_Website_BaseURL; ?>search.php">
39         <div class="form-group-simple"
40         <?php
41         if (empty($aMoreParams['q']) and empty($aMoreParams['street']) and empty($aMoreParams['city']) and empty($aMoreParams['county']) and empty($aMoreParams['state']) and empty($aMoreParams['country']) and empty($aMoreParams['postalcode'])) {
42             echo "style='display:block;'";
43         }
44         elseif (empty($aMoreParams['q'])) {
45             echo "style='display:none;'";
46         }
47         ?>>
48             <input id="q" name="q" type="text" class="form-control input-sm" placeholder="Search" value="<?php echo htmlspecialchars($aMoreParams['q']); ?>" >
49         </div>
50         <div class="form-group-structured"
51         <?php
52         if (empty($aMoreParams['street']) and empty($aMoreParams['city']) and empty($aMoreParams['county']) and empty($aMoreParams['state']) and empty($aMoreParams['country']) and empty($aMoreParams['postalcode'])) {
53             echo "style='display:none;'";
54         }
55         else {
56             echo "style='display:block;'";
57         }
58         ?>>
59 <div class="form-inline">
60             <input id="street" name="street" type="text" class="form-control input-sm" placeholder="House number/Street" value="<?php echo htmlspecialchars($aMoreParams['street']); ?>" >
61             <input id="city" name="city" type="text" class="form-control input-sm" placeholder="City" value="<?php echo htmlspecialchars($aMoreParams['city']); ?>" >
62             <input id="county" name="county" type="text" class="form-control input-sm" placeholder="County" value="<?php echo htmlspecialchars($aMoreParams['county']); ?>" >
63             <input id="state" name="state" type="text" class="form-control input-sm" placeholder="State" value="<?php echo htmlspecialchars($aMoreParams['state']); ?>" >
64             <input id="country" name="country" type="text" class="form-control input-sm" placeholder="Country" value="<?php echo htmlspecialchars($aMoreParams['country']); ?>" >
65             <input id="postalcode" name="postalcode" type="text" class="form-control input-sm" placeholder="Postal Code" value="<?php echo htmlspecialchars($aMoreParams['postalcode']); ?>" >
66         </div></div>
67         <div class="form-group search-button-group">
68             <button type="submit" class="btn btn-primary btn-sm">Search</button>
69             <?php if (CONST_Search_AreaPolygons) { ?>
70                 <input type="hidden" value="1" name="polygon_geojson" />
71             <?php } ?>
72             <input type="hidden" name="viewbox" value="<?php if (isset($aMoreParams['viewbox'])) echo ($aMoreParams['viewbox']); ?>" />
73             <div class="checkbox-inline">
74                 <input type="checkbox" id="use_viewbox" <?php if (isset($aMoreParams['viewbox'])) echo "checked='checked'"; ?>>
75                 <label for="use_viewbox">apply viewbox</label>
76             </div>
77         </div>
78     </form>
79 </div>
80
81     <div id="content">
82
83 <?php if ($sQuery) { ?>
84
85         <div id="searchresults" class="sidebar">
86         <?php
87             $i = 0;
88             foreach($aSearchResults as $iResNum => $aResult)
89             {
90
91                 echo '<div class="result" data-position=' . $i . '>';
92
93                 echo (isset($aResult['icon'])?'<img alt="icon" src="'.$aResult['icon'].'"/>':'');
94                 echo ' <span class="name">'.htmlspecialchars($aResult['name']).'</span>';
95                 // echo ' <span class="latlon">'.round($aResult['lat'],3).','.round($aResult['lon'],3).'</span>';
96                 // echo ' <span class="place_id">'.$aResult['place_id'].'</span>';
97                 if (isset($aResult['label']))
98                     echo ' <span class="type">('.$aResult['label'].')</span>';
99                 else if ($aResult['type'] == 'yes')
100                     echo ' <span class="type">('.ucwords(str_replace('_',' ',$aResult['class'])).')</span>';
101                 else
102                     echo ' <span class="type">('.ucwords(str_replace('_',' ',$aResult['type'])).')</span>';
103                 echo detailsPermaLink($aResult, 'details', 'class="btn btn-default btn-xs details"');
104                 echo '</div>';
105                 $i = $i+1;
106             }
107             if (!empty($aSearchResults) && $sMoreURL)
108             {
109                 echo '<div class="more"><a class="btn btn-primary" href="'.htmlentities($sMoreURL).'">Search for more results</a></div>';
110             }
111             else
112             {
113                 echo '<div class="noresults">No search results found</div>';
114             }
115
116         ?>
117         </div>
118
119 <?php } else { ?>
120
121         <div id="intro" class="sidebar">
122             <?php include(CONST_BasePath.'/lib/template/includes/introduction.php'); ?>
123         </div>
124
125 <?php } ?>
126
127         <div id="map-wrapper">
128             <div id="map-position">
129                 <div id="map-position-inner"></div>
130                 <div id="map-position-close"><a href="#">hide</a></div>
131             </div>
132             <div id="map"></div>
133         </div>
134
135     </div> <!-- /content -->
136
137
138
139     <script type="text/javascript">
140     <?php
141
142         $aNominatimMapInit = array(
143             'zoom' => CONST_Default_Zoom,
144             'lat' => CONST_Default_Lat,
145             'lon' => CONST_Default_Lon,
146             'tile_url' => CONST_Map_Tile_URL,
147             'tile_attribution' => CONST_Map_Tile_Attribution
148         );
149         echo 'var nominatim_map_init = ' . json_encode($aNominatimMapInit, JSON_PRETTY_PRINT) . ';';
150
151         echo 'var nominatim_results = ' . json_encode($aSearchResults, JSON_PRETTY_PRINT) . ';'; 
152     ?>
153     </script>
154     <?php include(CONST_BasePath.'/lib/template/includes/html-footer.php'); ?>
155
156 </body>
157 </html>