| 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 | )); |
|---|
| 189 | |
|---|
| 190 | // Language data |
|---|
| 191 | load_language('plugin.lang', PSLI_BINGMAPS_DIRECTORY); |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | /********************************************************************************************/ |
|---|
| 195 | // function to add prefilter on categories rendering |
|---|
| 196 | /********************************************************************************************/ |
|---|
| 197 | function PSLIBINGMAPS_Add_Category_Prefilter() |
|---|
| 198 | { |
|---|
| 199 | global $template; |
|---|
| 200 | $template->set_prefilter('categories', 'PSLIBINGMAPS_Category_Prefilter_1_1'); |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | /********************************************************************************************/ |
|---|
| 204 | // Function prefilter on categories rendering |
|---|
| 205 | // Add fieldset with data for Psli-BingMaps plugin |
|---|
| 206 | /********************************************************************************************/ |
|---|
| 207 | function PSLIBINGMAPS_Category_Prefilter_1_1($content, &$smarty) |
|---|
| 208 | { |
|---|
| 209 | $search = '#name="reset"> |
|---|
| 210 | </p>#'; |
|---|
| 211 | |
|---|
| 212 | $replacement = 'name="reset"> |
|---|
| 213 | </p> |
|---|
| 214 | |
|---|
| 215 | <div> |
|---|
| 216 | <form method="post" > |
|---|
| 217 | <fieldset> |
|---|
| 218 | <legend>{\'Localisation - Plugin Psli-BingMaps\'|@translate}</legend> |
|---|
| 219 | <table style="margin-bottom:10px;width:95%;"> |
|---|
| 220 | <colgroup> |
|---|
| 221 | <col width="150px"> |
|---|
| 222 | <col width="210px"> |
|---|
| 223 | <col width="50px"> |
|---|
| 224 | <col width="*"> |
|---|
| 225 | <col width="*"> |
|---|
| 226 | </colgroup> |
|---|
| 227 | <tr> |
|---|
| 228 | <td>{\'Latitude\'|@translate} :</td> |
|---|
| 229 | <td><input id="pslibingmapslat" type="text" name="pslibingmapslat" value="{$PSLIBINGMAPSLAT}" style="width:200px;" maxlength="21" /></td> |
|---|
| 230 | <td> </td> |
|---|
| 231 | <td style="text-align:right;"> |
|---|
| 232 | <button id="pslibingmapsbuttonstart" style="width:180px;" type="button" onclick="psli_StartZone();" DISABLED>{\'Creer une zone\'|@translate}</button> |
|---|
| 233 | </td> |
|---|
| 234 | <td style="text-align:left;"> |
|---|
| 235 | <button id="pslibingmapsbuttondelete" style="width:180px;" type="button" onclick="psli_DeleteLast();" DISABLED>{\'Supprimer le dernier point\'|@translate}</button> |
|---|
| 236 | </td> |
|---|
| 237 | </tr> |
|---|
| 238 | <tr> |
|---|
| 239 | <td>{\'Longitude\'|@translate} :</td> |
|---|
| 240 | <td> |
|---|
| 241 | <input id="pslibingmapslon" type="text" name="pslibingmapslon" value="{$PSLIBINGMAPSLON}" style="width:200px;" maxlength="21"> |
|---|
| 242 | </td> |
|---|
| 243 | <td> </td> |
|---|
| 244 | <td style="text-align:right;"> |
|---|
| 245 | <button id="pslibingmapsbuttonsave" style="width:180px;" type="button" onclick="psli_SaveZone();" DISABLED>{\'Enregistrer la zone\'|@translate}</button> |
|---|
| 246 | <input id="pslibingmapszone" type="hidden" name="pslibingmapszone" value="--null--" /> |
|---|
| 247 | </td> |
|---|
| 248 | <td style="text-align:left;"> |
|---|
| 249 | <button id="pslibingmapsbuttonall" style="width:180px;" type="button" onclick="psli_DeleteAll();" DISABLED>{\'Tout effacer\'|@translate}</button> |
|---|
| 250 | </td> |
|---|
| 251 | </tr> |
|---|
| 252 | <tr> |
|---|
| 253 | <td>{\'Zoom minimum\'|@translate} :</td> |
|---|
| 254 | <td> |
|---|
| 255 | <input id="pslibingmapszoommin" type="text" name="pslibingmapszoommin" value="{$PSLIBINGMAPSZOOMMIN}" style="width:200px;margin-right:5px;" maxlength="2"> |
|---|
| 256 | </td> |
|---|
| 257 | <td style="text-align:left;"> |
|---|
| 258 | <button type="button" onclick="psli_SetMinimum();">{\'Set\'|@translate}</button> |
|---|
| 259 | </td> |
|---|
| 260 | <td style="text-align:right;"> |
|---|
| 261 | <button id="pslibingmapsbuttoncancel" style="width:180px;" type="button" onclick="psli_CancelZone();" DISABLED>{\'Annuler le mode creation\'|@translate}</button> |
|---|
| 262 | </td> |
|---|
| 263 | </tr> |
|---|
| 264 | <tr> |
|---|
| 265 | <td>{\'Zoom maximum\'|@translate} :</td> |
|---|
| 266 | <td> |
|---|
| 267 | <input id="pslibingmapszoommax" type="text" name="pslibingmapszoommax" value="{$PSLIBINGMAPSZOOMMAX}" style="width:200px;margin-right:5px;" maxlength="2"> |
|---|
| 268 | </td> |
|---|
| 269 | <td style="text-align:left;"> |
|---|
| 270 | <button type="button" onclick="psli_SetMaximum();">{\'Set\'|@translate}</button> |
|---|
| 271 | </td> |
|---|
| 272 | </tr> |
|---|
| 273 | <tr> |
|---|
| 274 | <td>{\'Action\'|@translate} :</td> |
|---|
| 275 | <td> |
|---|
| 276 | <select id="pslibingmapsselect" name="pslibingmapsselect" style="width:200px;" > |
|---|
| 277 | <option value="0">{\'Contenu\'|@translate}</option> |
|---|
| 278 | <option value="1">{\'Zoom niveau 1\'|@translate}</option> |
|---|
| 279 | <option value="2">{\'Zoom niveau 2\'|@translate}</option> |
|---|
| 280 | <option value="3">{\'Zoom niveau 3\'|@translate}</option> |
|---|
| 281 | <option value="4">{\'Zoom niveau 4\'|@translate}</option> |
|---|
| 282 | <option value="5">{\'Zoom niveau 5\'|@translate}</option> |
|---|
| 283 | <option value="6">{\'Zoom niveau 6\'|@translate}</option> |
|---|
| 284 | <option value="7">{\'Zoom niveau 7\'|@translate}</option> |
|---|
| 285 | <option value="8">{\'Zoom niveau 8\'|@translate}</option> |
|---|
| 286 | <option value="9">{\'Zoom niveau 9\'|@translate}</option> |
|---|
| 287 | <option value="10">{\'Zoom niveau 10\'|@translate}</option> |
|---|
| 288 | <option value="11">{\'Zoom niveau 11\'|@translate}</option> |
|---|
| 289 | <option value="12">{\'Zoom niveau 12\'|@translate}</option> |
|---|
| 290 | <option value="13">{\'Zoom niveau 13\'|@translate}</option> |
|---|
| 291 | <option value="14">{\'Zoom niveau 14\'|@translate}</option> |
|---|
| 292 | <option value="15">{\'Zoom niveau 15\'|@translate}</option> |
|---|
| 293 | <option value="16">{\'Zoom niveau 16\'|@translate}</option> |
|---|
| 294 | <option value="17">{\'Zoom niveau 17\'|@translate}</option> |
|---|
| 295 | <option value="18">{\'Zoom niveau 18\'|@translate}</option> |
|---|
| 296 | <option value="19">{\'Zoom niveau 19\'|@translate}</option> |
|---|
| 297 | <option value="20">{\'Zoom niveau 20\'|@translate}</option> |
|---|
| 298 | </select> |
|---|
| 299 | </td> |
|---|
| 300 | <td style="text-align:left;"> |
|---|
| 301 | <button type="button" onclick="psli_SetAction();">{\'Set\'|@translate}</button> |
|---|
| 302 | </td> |
|---|
| 303 | <td> </td> |
|---|
| 304 | <td style="text-align:left;"> |
|---|
| 305 | <input name="pslibingmapssubmitremove" style="width:180px;" type="submit" value="{\'Supprimer la localisation\'|@translate}" {$TAG_INPUT_ENABLED} /> |
|---|
| 306 | <input type="checkbox" name="pslibingmapssubmitremovecheck">{\'Etes-vous sur ?\'|@translate}</input> |
|---|
| 307 | </td> |
|---|
| 308 | </tr> |
|---|
| 309 | <tr> |
|---|
| 310 | <td colspan="5" style="text-align:center;"> |
|---|
| 311 | <input id="pslibingmapsaction" type="hidden" name="pslibingmapsaction" value="{$PSLIBINGMAPSACTION}" /> |
|---|
| 312 | <input id="pslibingmapsname" type="hidden" name="pslibingmapsname" value="{$PSLIBINGMAPNAME}" /> |
|---|
| 313 | <input id="pslibingmapsentity" type="hidden" name="pslibingmapsentity" value="{$PSLIBINGMAPID}" /> |
|---|
| 314 | <input class="submit" name="pslibingmapssubmitcategory" type="submit" value="{\'Valider\'|@translate}" {$TAG_INPUT_ENABLED} /> |
|---|
| 315 | </td> |
|---|
| 316 | </tr> |
|---|
| 317 | </table> |
|---|
| 318 | <div id=\'pslibingmapsmap\' style="position:relative; text-align:center; height:439px; margin-bottom:15px; margin-right:15px; margin-left:15px; border:2px solid white"> |
|---|
| 319 | </div> |
|---|
| 320 | <script charset="UTF-8" type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script> |
|---|
| 321 | <script charset="UTF-8" type="text/javascript" src="./plugins/Psli-BingMaps/JS/Psli-BingMaps.js"></script> |
|---|
| 322 | <script> |
|---|
| 323 | psli_g_BingKey = "{$PSLIBINGMAPSKEY}"; |
|---|
| 324 | psli_InitCategoryMap(); |
|---|
| 325 | {$PSLIBINGMAPSVIEW} |
|---|
| 326 | </script> |
|---|
| 327 | </fieldset> |
|---|
| 328 | </form> |
|---|
| 329 | </div> |
|---|
| 330 | '; |
|---|
| 331 | |
|---|
| 332 | return preg_replace($search, $replacement, $content); |
|---|
| 333 | } |
|---|
| 334 | |
|---|
| 335 | /********************************************************************************************/ |
|---|
| 336 | // Add an entry to the 'Plugins' menu. |
|---|
| 337 | /********************************************************************************************/ |
|---|
| 338 | function PSLIBINGMAPS_admin_menu($menu) { |
|---|
| 339 | array_push( |
|---|
| 340 | $menu, |
|---|
| 341 | array( |
|---|
| 342 | 'NAME' => 'PSLI-BingMaps', |
|---|
| 343 | 'URL' => get_admin_plugin_menu_link(PSLI_BINGMAPS_DIRECTORY.'include/admin.php') |
|---|
| 344 | ) |
|---|
| 345 | ); |
|---|
| 346 | return $menu; |
|---|
| 347 | } |
|---|
| 348 | |
|---|
| 349 | ?> |
|---|