1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Psli-BingMaps |
---|
4 | Author: psli |
---|
5 | Description: Admin function for plugin "Psli-BingMaps" |
---|
6 | */ |
---|
7 | |
---|
8 | // Chech whether we are indeed included by Piwigo. |
---|
9 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
10 | |
---|
11 | // Hook on to event on administration page. |
---|
12 | add_event_handler('get_admin_plugin_menu_links', 'PSLIBINGMAPS_admin_menu'); |
---|
13 | |
---|
14 | // Hook on to event on category page |
---|
15 | add_event_handler('loc_end_cat_modify', 'PSLIBINGMAPS_Add_Category_Prefilter', 55); |
---|
16 | add_event_handler('loc_end_cat_modify', 'PSLIBINGMAPS_Category_Process'); |
---|
17 | |
---|
18 | /********************************************************************************************/ |
---|
19 | // Process localisation data on category page for Psli-BingMaps plugin |
---|
20 | /********************************************************************************************/ |
---|
21 | function PSLIBINGMAPS_Category_Process() |
---|
22 | { |
---|
23 | // Process click on submit button |
---|
24 | if (isset($_POST['pslibingmapssubmitremove'])) |
---|
25 | { |
---|
26 | if (($_POST['pslibingmapsentity'] != "--null--") and ($_POST['pslibingmapssubmitremovecheck'] == "on")) |
---|
27 | { |
---|
28 | $q = ' |
---|
29 | DELETE FROM '.PSLI_ENTITIES_TABLE.' |
---|
30 | WHERE id = '.$_POST['pslibingmapsentity'].';'; |
---|
31 | pwg_query($q); |
---|
32 | |
---|
33 | $q = ' |
---|
34 | DELETE FROM '.PSLI_DATAPOINT_TABLE.' WHERE id_entity = '.$_POST['pslibingmapsentity'].';'; |
---|
35 | pwg_query($q); |
---|
36 | } |
---|
37 | } |
---|
38 | |
---|
39 | if (isset($_POST['pslibingmapssubmitcategory'])) |
---|
40 | { |
---|
41 | if ($_POST['pslibingmapsentity'] == "--null--") |
---|
42 | { |
---|
43 | $q = ' |
---|
44 | INSERT INTO '.PSLI_ENTITIES_TABLE.' (lat, lon, action, zoomMin, zoomMax, title, id_category) |
---|
45 | VALUES (' |
---|
46 | .$_POST['pslibingmapslat'].', ' |
---|
47 | .$_POST['pslibingmapslon'].', ' |
---|
48 | .$_POST['pslibingmapsselect'].', ' |
---|
49 | .$_POST['pslibingmapszoommin'].', ' |
---|
50 | .$_POST['pslibingmapszoommax'].", '".addslashes($_POST['pslibingmapsname'])."', " |
---|
51 | .$_GET['cat_id'].');'; |
---|
52 | pwg_query($q); |
---|
53 | } |
---|
54 | else |
---|
55 | { |
---|
56 | $q = ' |
---|
57 | UPDATE '.PSLI_ENTITIES_TABLE.' |
---|
58 | SET lat = '.$_POST['pslibingmapslat'].', |
---|
59 | lon = '.$_POST['pslibingmapslon'].', |
---|
60 | action = '.$_POST['pslibingmapsselect'].', |
---|
61 | zoomMin = '.$_POST['pslibingmapszoommin'].', |
---|
62 | zoomMax = '.$_POST['pslibingmapszoommax'].", |
---|
63 | title = '".addslashes($_POST['pslibingmapsname'])."' |
---|
64 | WHERE id = ".$_POST['pslibingmapsentity'].';'; |
---|
65 | pwg_query($q); |
---|
66 | |
---|
67 | if ($_POST['pslibingmapszone'] != "--null--") |
---|
68 | { |
---|
69 | $q = ' |
---|
70 | DELETE FROM '.PSLI_DATAPOINT_TABLE.' WHERE id_entity = '.$_POST['pslibingmapsentity'].';'; |
---|
71 | pwg_query($q); |
---|
72 | |
---|
73 | if ($_POST['pslibingmapszone'] != "delete all") |
---|
74 | { |
---|
75 | $q = ' |
---|
76 | INSERT INTO '.PSLI_DATAPOINT_TABLE.' (id_entity, lat, lon) |
---|
77 | VALUES '.$_POST['pslibingmapszone']; |
---|
78 | pwg_query($q); |
---|
79 | } |
---|
80 | } |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | // Initialize data on the fieldset "Psli Bing Maps" |
---|
85 | if (isset($_GET['cat_id'])) |
---|
86 | { |
---|
87 | global $template, $prefixeTable; |
---|
88 | |
---|
89 | // Extract data fro this entities |
---|
90 | $query_entity = ' |
---|
91 | select id, lat, lon, zoomMin, zoomMax, action |
---|
92 | FROM '.PSLI_ENTITIES_TABLE.' |
---|
93 | WHERE id_category = '.$_GET['cat_id'].' |
---|
94 | ;'; |
---|
95 | $result_entity = pwg_query($query_entity); |
---|
96 | $query_category = ' |
---|
97 | SELECT name |
---|
98 | FROM piwigo_categories |
---|
99 | WHERE id = '.$_GET['cat_id'].' |
---|
100 | ;'; |
---|
101 | $result_category = pwg_query($query_category); |
---|
102 | $row_category = pwg_db_fetch_assoc($result_category); |
---|
103 | |
---|
104 | // Data for this entity already in the table ? |
---|
105 | if (pwg_db_num_rows($result_entity) > 0) |
---|
106 | { |
---|
107 | $row_entity = pwg_db_fetch_assoc($result_entity); |
---|
108 | |
---|
109 | $template->assign( |
---|
110 | array( |
---|
111 | 'PSLIBINGMAPSLAT' => $row_entity['lat'], |
---|
112 | 'PSLIBINGMAPSLON' => $row_entity['lon'], |
---|
113 | 'PSLIBINGMAPSZOOMMIN' => $row_entity['zoomMin'], |
---|
114 | 'PSLIBINGMAPSZOOMMAX' => $row_entity['zoomMax'], |
---|
115 | 'PSLIBINGMAPSACTION' => $row_entity['action'], |
---|
116 | 'PSLIBINGMAPID' => $row_entity['id'], |
---|
117 | 'PSLIBINGMAPNAME' => $row_category['name'] |
---|
118 | )); |
---|
119 | $psli_id = $row_entity['id']; |
---|
120 | } |
---|
121 | else |
---|
122 | { |
---|
123 | $template->assign( |
---|
124 | array( |
---|
125 | 'PSLIBINGMAPSLAT' => 0, |
---|
126 | 'PSLIBINGMAPSLON' => 0, |
---|
127 | 'PSLIBINGMAPSZOOMMIN' => 1, |
---|
128 | 'PSLIBINGMAPSZOOMMAX' => 20, |
---|
129 | 'PSLIBINGMAPSACTION' => 0, |
---|
130 | 'PSLIBINGMAPID' => "--null--", |
---|
131 | 'PSLIBINGMAPNAME' => $row_category['name'] |
---|
132 | )); |
---|
133 | $psli_id = "--null--"; |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|
137 | |
---|
138 | if ($psli_id == "--null--") |
---|
139 | { |
---|
140 | $initialView = "psli_g_Map.entities.clear();"; |
---|
141 | } |
---|
142 | else |
---|
143 | { |
---|
144 | $query_datapoint = ' |
---|
145 | SELECT lat, lon |
---|
146 | FROM '.PSLI_DATAPOINT_TABLE.' |
---|
147 | WHERE id_entity = '.$psli_id.' ORDER BY id;' ; |
---|
148 | $result_datapoint = pwg_query($query_datapoint); |
---|
149 | if (pwg_db_num_rows($result_datapoint) > 0) |
---|
150 | { |
---|
151 | $initialView = ""; |
---|
152 | while ($row = pwg_db_fetch_assoc($result_datapoint)) |
---|
153 | { |
---|
154 | $initialView .= 'psli_g_VerticeInitial.push(new Microsoft.Maps.Location('.$row['lat'].','.$row['lon'].'));'."\n"; |
---|
155 | } |
---|
156 | $initialView .= ' |
---|
157 | psli_CopyInitial(); |
---|
158 | var psli_l_Pin = new Microsoft.Maps.Polygon(psli_g_Vertice,{fillColor: psli_g_PolygonColor, strokeColor: psli_g_PolygonColor}); |
---|
159 | psli_g_Map.entities.clear(); |
---|
160 | psli_g_Map.entities.push(psli_l_Pin); |
---|
161 | psli_g_ZoneDraw = true; |
---|
162 | document.getElementById("pslibingmapsbuttonall").disabled = false; |
---|
163 | document.getElementById("pslibingmapsbuttondelete").disabled = false; |
---|
164 | document.getElementById("pslibingmapsbuttonsave").disabled = false; |
---|
165 | document.getElementById("pslibingmapsbuttoncancel").disabled = false; |
---|
166 | document.getElementById("pslibingmapsbuttonstart").disabled = true; |
---|
167 | '."\n"; |
---|
168 | } |
---|
169 | else |
---|
170 | { |
---|
171 | $initialView = ' |
---|
172 | var psli_l_Pin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(document.getElementById("pslibingmapslat").value, document.getElementById("pslibingmapslon").value)); |
---|
173 | psli_g_Map.entities.clear(); |
---|
174 | psli_g_Map.entities.push(psli_l_Pin);'."\n"; |
---|
175 | } |
---|
176 | } |
---|
177 | |
---|
178 | $query = ' |
---|
179 | SELECT value |
---|
180 | FROM '.CONFIG_TABLE.' |
---|
181 | WHERE param = "'.PSLI_CONF_KEY.'";'; |
---|
182 | $result = pwg_query($query); |
---|
183 | $row = pwg_db_fetch_assoc($result); |
---|
184 | $template->assign( |
---|
185 | array( |
---|
186 | 'PSLIBINGMAPSKEY' => $row['value'], |
---|
187 | 'PSLIBINGMAPSVIEW' => $initialView, |
---|
188 | 'JSPATH' => PSLI_BINGMAPS_JS |
---|
189 | )); |
---|
190 | |
---|
191 | // Language data |
---|
192 | load_language('plugin.lang', PSLI_BINGMAPS_TEMPLATE_PATH); |
---|
193 | } |
---|
194 | |
---|
195 | /********************************************************************************************/ |
---|
196 | // function to add prefilter on categories rendering |
---|
197 | /********************************************************************************************/ |
---|
198 | function PSLIBINGMAPS_Add_Category_Prefilter() |
---|
199 | { |
---|
200 | global $template; |
---|
201 | $template->set_prefilter('categories', 'PSLIBINGMAPS_Category_Prefilter_1_1a'); |
---|
202 | } |
---|
203 | |
---|
204 | /********************************************************************************************/ |
---|
205 | // Function prefilter on categories rendering |
---|
206 | // Add fieldset with data for Psli-BingMaps plugin |
---|
207 | /********************************************************************************************/ |
---|
208 | function PSLIBINGMAPS_Category_Prefilter_1_1a($content, &$smarty) |
---|
209 | { |
---|
210 | $search = '#name="reset"> |
---|
211 | </p>#'; |
---|
212 | |
---|
213 | $replacement = 'name="reset"> |
---|
214 | </p> |
---|
215 | |
---|
216 | <div> |
---|
217 | <form method="post" > |
---|
218 | <fieldset> |
---|
219 | <legend>{\'Localisation - Plugin Psli-BingMaps\'|@translate}</legend> |
---|
220 | <table style="margin-bottom:10px;width:95%;"> |
---|
221 | <colgroup> |
---|
222 | <col width="150px"> |
---|
223 | <col width="210px"> |
---|
224 | <col width="50px"> |
---|
225 | <col width="*"> |
---|
226 | <col width="*"> |
---|
227 | </colgroup> |
---|
228 | <tr> |
---|
229 | <td>{\'Latitude\'|@translate} :</td> |
---|
230 | <td><input id="pslibingmapslat" type="text" name="pslibingmapslat" value="{$PSLIBINGMAPSLAT}" style="width:200px;" maxlength="21" /></td> |
---|
231 | <td> </td> |
---|
232 | <td style="text-align:right;"> |
---|
233 | <button id="pslibingmapsbuttonstart" style="width:180px;" type="button" onclick="psli_StartZone();" DISABLED>{\'Creer une zone\'|@translate}</button> |
---|
234 | </td> |
---|
235 | <td style="text-align:left;"> |
---|
236 | <button id="pslibingmapsbuttondelete" style="width:180px;" type="button" onclick="psli_DeleteLast();" DISABLED>{\'Supprimer le dernier point\'|@translate}</button> |
---|
237 | </td> |
---|
238 | </tr> |
---|
239 | <tr> |
---|
240 | <td>{\'Longitude\'|@translate} :</td> |
---|
241 | <td> |
---|
242 | <input id="pslibingmapslon" type="text" name="pslibingmapslon" value="{$PSLIBINGMAPSLON}" style="width:200px;" maxlength="21"> |
---|
243 | </td> |
---|
244 | <td> </td> |
---|
245 | <td style="text-align:right;"> |
---|
246 | <button id="pslibingmapsbuttonsave" style="width:180px;" type="button" onclick="psli_SaveZone();" DISABLED>{\'Enregistrer la zone\'|@translate}</button> |
---|
247 | <input id="pslibingmapszone" type="hidden" name="pslibingmapszone" value="--null--" /> |
---|
248 | </td> |
---|
249 | <td style="text-align:left;"> |
---|
250 | <button id="pslibingmapsbuttonall" style="width:180px;" type="button" onclick="psli_DeleteAll();" DISABLED>{\'Tout effacer\'|@translate}</button> |
---|
251 | </td> |
---|
252 | </tr> |
---|
253 | <tr> |
---|
254 | <td>{\'Zoom minimum\'|@translate} :</td> |
---|
255 | <td> |
---|
256 | <input id="pslibingmapszoommin" type="text" name="pslibingmapszoommin" value="{$PSLIBINGMAPSZOOMMIN}" style="width:200px;margin-right:5px;" maxlength="2"> |
---|
257 | </td> |
---|
258 | <td style="text-align:left;"> |
---|
259 | <button type="button" onclick="psli_SetMinimum();">{\'Set\'|@translate}</button> |
---|
260 | </td> |
---|
261 | <td style="text-align:right;"> |
---|
262 | <button id="pslibingmapsbuttoncancel" style="width:180px;" type="button" onclick="psli_CancelZone();" DISABLED>{\'Annuler le mode creation\'|@translate}</button> |
---|
263 | </td> |
---|
264 | </tr> |
---|
265 | <tr> |
---|
266 | <td>{\'Zoom maximum\'|@translate} :</td> |
---|
267 | <td> |
---|
268 | <input id="pslibingmapszoommax" type="text" name="pslibingmapszoommax" value="{$PSLIBINGMAPSZOOMMAX}" style="width:200px;margin-right:5px;" maxlength="2"> |
---|
269 | </td> |
---|
270 | <td style="text-align:left;"> |
---|
271 | <button type="button" onclick="psli_SetMaximum();">{\'Set\'|@translate}</button> |
---|
272 | </td> |
---|
273 | </tr> |
---|
274 | <tr> |
---|
275 | <td>{\'Action\'|@translate} :</td> |
---|
276 | <td> |
---|
277 | <select id="pslibingmapsselect" name="pslibingmapsselect" style="width:200px;" > |
---|
278 | <option value="0">{\'Contenu\'|@translate}</option> |
---|
279 | <option value="1">{\'Zoom niveau 1\'|@translate}</option> |
---|
280 | <option value="2">{\'Zoom niveau 2\'|@translate}</option> |
---|
281 | <option value="3">{\'Zoom niveau 3\'|@translate}</option> |
---|
282 | <option value="4">{\'Zoom niveau 4\'|@translate}</option> |
---|
283 | <option value="5">{\'Zoom niveau 5\'|@translate}</option> |
---|
284 | <option value="6">{\'Zoom niveau 6\'|@translate}</option> |
---|
285 | <option value="7">{\'Zoom niveau 7\'|@translate}</option> |
---|
286 | <option value="8">{\'Zoom niveau 8\'|@translate}</option> |
---|
287 | <option value="9">{\'Zoom niveau 9\'|@translate}</option> |
---|
288 | <option value="10">{\'Zoom niveau 10\'|@translate}</option> |
---|
289 | <option value="11">{\'Zoom niveau 11\'|@translate}</option> |
---|
290 | <option value="12">{\'Zoom niveau 12\'|@translate}</option> |
---|
291 | <option value="13">{\'Zoom niveau 13\'|@translate}</option> |
---|
292 | <option value="14">{\'Zoom niveau 14\'|@translate}</option> |
---|
293 | <option value="15">{\'Zoom niveau 15\'|@translate}</option> |
---|
294 | <option value="16">{\'Zoom niveau 16\'|@translate}</option> |
---|
295 | <option value="17">{\'Zoom niveau 17\'|@translate}</option> |
---|
296 | <option value="18">{\'Zoom niveau 18\'|@translate}</option> |
---|
297 | <option value="19">{\'Zoom niveau 19\'|@translate}</option> |
---|
298 | <option value="20">{\'Zoom niveau 20\'|@translate}</option> |
---|
299 | </select> |
---|
300 | </td> |
---|
301 | <td style="text-align:left;"> |
---|
302 | <button type="button" onclick="psli_SetAction();">{\'Set\'|@translate}</button> |
---|
303 | </td> |
---|
304 | <td> </td> |
---|
305 | <td style="text-align:left;"> |
---|
306 | <input name="pslibingmapssubmitremove" style="width:180px;" type="submit" value="{\'Supprimer la localisation\'|@translate}" {$TAG_INPUT_ENABLED} /> |
---|
307 | <input type="checkbox" name="pslibingmapssubmitremovecheck">{\'Etes-vous sur ?\'|@translate}</input> |
---|
308 | </td> |
---|
309 | </tr> |
---|
310 | <tr> |
---|
311 | <td colspan="5" style="text-align:center;"> |
---|
312 | <input id="pslibingmapsaction" type="hidden" name="pslibingmapsaction" value="{$PSLIBINGMAPSACTION}" /> |
---|
313 | <input id="pslibingmapsname" type="hidden" name="pslibingmapsname" value="{$PSLIBINGMAPNAME}" /> |
---|
314 | <input id="pslibingmapsentity" type="hidden" name="pslibingmapsentity" value="{$PSLIBINGMAPID}" /> |
---|
315 | <input class="submit" name="pslibingmapssubmitcategory" type="submit" value="{\'Valider\'|@translate}" {$TAG_INPUT_ENABLED} /> |
---|
316 | </td> |
---|
317 | </tr> |
---|
318 | </table> |
---|
319 | <div id=\'pslibingmapsmap\' style="position:relative; text-align:center; height:439px; margin-bottom:15px; margin-right:15px; margin-left:15px; border:2px solid white"> |
---|
320 | </div> |
---|
321 | <script charset="UTF-8" type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script> |
---|
322 | <script charset="UTF-8" type="text/javascript" src="{$JSPATH}"></script> |
---|
323 | <script> |
---|
324 | psli_g_BingKey = "{$PSLIBINGMAPSKEY}"; |
---|
325 | psli_InitCategoryMap(); |
---|
326 | {$PSLIBINGMAPSVIEW} |
---|
327 | </script> |
---|
328 | </fieldset> |
---|
329 | </form> |
---|
330 | </div> |
---|
331 | '; |
---|
332 | |
---|
333 | return preg_replace($search, $replacement, $content); |
---|
334 | } |
---|
335 | |
---|
336 | /********************************************************************************************/ |
---|
337 | // Add an entry to the 'Plugins' menu. |
---|
338 | /********************************************************************************************/ |
---|
339 | function PSLIBINGMAPS_admin_menu($menu) { |
---|
340 | array_push( |
---|
341 | $menu, |
---|
342 | array( |
---|
343 | 'NAME' => 'PSLI-BingMaps', |
---|
344 | 'URL' => get_admin_plugin_menu_link(PSLI_BINGMAPS_ADMIN_PHP) |
---|
345 | ) |
---|
346 | ); |
---|
347 | return $menu; |
---|
348 | } |
---|
349 | |
---|
350 | ?> |
---|