1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Psli-BingMaps |
---|
4 | Author: psli |
---|
5 | */ |
---|
6 | |
---|
7 | // Chech whether we are indeed included by Piwigo. |
---|
8 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
9 | |
---|
10 | //******* Fetch global data ******* |
---|
11 | global $template, $conf, $page, $debug; |
---|
12 | |
---|
13 | $add_js = ""; |
---|
14 | |
---|
15 | // Include class files for map, pin and zone |
---|
16 | include_once(PSLI_BINGMAPS_CLASS_ZONE_PHP); |
---|
17 | |
---|
18 | //******* Get Bing Map Key ******* |
---|
19 | $query = ' |
---|
20 | SELECT value |
---|
21 | FROM '.CONFIG_TABLE.' |
---|
22 | WHERE param = "'.PSLI_CONF_KEY.'";'; |
---|
23 | $result = pwg_query($query); |
---|
24 | $row = pwg_db_fetch_assoc($result); |
---|
25 | $bing_map_key = $row['value']; |
---|
26 | |
---|
27 | //******* Select entity to display ******* |
---|
28 | $class_zone = new Psli_Zone(); |
---|
29 | if (isset($_POST['open'])) |
---|
30 | { |
---|
31 | if ((isset($_POST['zoneSelected'])) && ($_POST['zoneSelected'] != 0)) |
---|
32 | $class_zone->open($_POST['zoneSelected']); |
---|
33 | else |
---|
34 | array_push($page['errors'], l10n('You need to select a zone')); |
---|
35 | } |
---|
36 | else |
---|
37 | { |
---|
38 | if ((isset($_POST['hiddenzone'])) && ($_POST['hiddenzone'] != "")) |
---|
39 | $class_zone->open($_POST['hiddenzone']); |
---|
40 | } |
---|
41 | if ($class_zone->isOpened()) |
---|
42 | $display = 'block'; |
---|
43 | else |
---|
44 | $display = 'none'; |
---|
45 | |
---|
46 | |
---|
47 | /************************************************************************************/ |
---|
48 | /* Submit - Delete zone **************************************************************/ |
---|
49 | if (isset($_POST['delete'])) |
---|
50 | { |
---|
51 | if (isset($_POST['deleteCheck'])) |
---|
52 | { |
---|
53 | if ((isset($_POST['zoneSelected'])) && ($_POST['zoneSelected'] != 0)) |
---|
54 | { |
---|
55 | $class_zone->delete(); |
---|
56 | $class_zone = new Psli_Zone(); |
---|
57 | $display = 'none'; |
---|
58 | array_push($page['infos'], l10n('Information data registered in database')); |
---|
59 | } |
---|
60 | else |
---|
61 | array_push($page['errors'], l10n('You need to select a zone')); |
---|
62 | } |
---|
63 | else |
---|
64 | array_push($page['errors'], l10n('You need to confirm deletion')); |
---|
65 | } |
---|
66 | /************************************************************************************/ |
---|
67 | |
---|
68 | /************************************************************************************/ |
---|
69 | /* Submit - Update a zone ************************************************************/ |
---|
70 | if (isset($_POST['save'])) |
---|
71 | { |
---|
72 | $class_zone->setTitle($_POST['title']); |
---|
73 | $class_zone->setZoomMin($_POST['zoommin']); |
---|
74 | $class_zone->setZoomMax($_POST['zoommax']); |
---|
75 | $class_zone->setLatitude($_POST['hiddencenterlat']); |
---|
76 | $class_zone->setLongitude($_POST['hiddencenterlon']); |
---|
77 | |
---|
78 | $class_zone->clearZone(); |
---|
79 | $points = explode("#", $_POST['hiddenpoints']); |
---|
80 | for ($i = 0; $i < (sizeof($points) - 1); $i++) |
---|
81 | { |
---|
82 | $coordonnee = explode(";", $points[$i]); |
---|
83 | $class_zone->addPoint($coordonnee[0], $coordonnee[1]); |
---|
84 | } |
---|
85 | |
---|
86 | $class_zone->clearMaps(); |
---|
87 | if (isset ($_POST['associatedmap'])) |
---|
88 | for ($i = 0; $i < count($_POST['associatedmap']); $i++) |
---|
89 | $class_zone->addMap($_POST['associatedmap'][$i]); |
---|
90 | |
---|
91 | switch ($_POST['actionselect']) |
---|
92 | { |
---|
93 | case 1: |
---|
94 | $class_zone->setAction(1, $_POST['actionzoomselect']); |
---|
95 | break; |
---|
96 | case 2: |
---|
97 | $class_zone->setAction(2, $_POST['actionalbumselect']); |
---|
98 | break; |
---|
99 | case 3: |
---|
100 | $class_zone->setAction(3, $_POST['actionpictureid']); |
---|
101 | break; |
---|
102 | } |
---|
103 | $class_zone->save(); |
---|
104 | $display = 'block'; |
---|
105 | array_push($page['infos'], l10n('Information data registered in database')); |
---|
106 | } |
---|
107 | /************************************************************************************/ |
---|
108 | |
---|
109 | /************************************************************************************/ |
---|
110 | /* Submit - Create a new zone ********************************************************/ |
---|
111 | if (isset($_POST['create'])) |
---|
112 | { |
---|
113 | $class_zone = new Psli_Zone(); |
---|
114 | $class_zone->create(); |
---|
115 | $display = 'block'; |
---|
116 | array_push($page['infos'], l10n('Information data registered in database')); |
---|
117 | } |
---|
118 | /************************************************************************************/ |
---|
119 | |
---|
120 | //******* Draw zone ******* |
---|
121 | if ($class_zone->isOpened()) |
---|
122 | { |
---|
123 | foreach ($class_zone->getPoints() as $point) |
---|
124 | { |
---|
125 | $add_js .= "\n".'psli_g_VerticeInitial.push(new Microsoft.Maps.Location('.$point['lat'].','.$point['lon'].'));'; |
---|
126 | } |
---|
127 | $add_js .= ' |
---|
128 | psli_CopyInitial(); |
---|
129 | var psli_l_Pin = new Microsoft.Maps.Polygon(psli_g_Vertice,{fillColor: psli_g_PolygonColor, strokeColor: psli_g_PolygonColor}); |
---|
130 | psli_g_Map.entities.clear(); |
---|
131 | psli_g_Map.entities.push(psli_l_Pin); |
---|
132 | psli_g_ZoneDraw = true; |
---|
133 | '."\n"; |
---|
134 | } |
---|
135 | |
---|
136 | //******* Get zone selected data ******* |
---|
137 | if ($class_zone->isOpened()) |
---|
138 | { |
---|
139 | switch ($class_zone->getAction()) |
---|
140 | { |
---|
141 | case 1: |
---|
142 | $add_js .= "\ndocument.getElementById(\"actionzoomselect\").selectedIndex = ".($class_zone->getActionId() - 1).";"; |
---|
143 | $add_js .= "\ndocument.getElementById(\"ActionAlbum\").style.display = 'none';"; |
---|
144 | $add_js .= "\ndocument.getElementById(\"ActionPicture\").style.display = 'none';"; |
---|
145 | break; |
---|
146 | case 2: |
---|
147 | $add_js .= "\ndocument.getElementById(\"actionselect\").selectedIndex = 1;"; |
---|
148 | $add_js .= "\ndocument.getElementById(\"actionalbumselect\").selectedItem = ".($class_zone->getActionId()).";"; |
---|
149 | $add_js .= "\ndocument.getElementById(\"ActionAlbum\").style.display = 'block';"; |
---|
150 | $add_js .= "\ndocument.getElementById(\"ActionZoom\").style.display = 'none';"; |
---|
151 | $add_js .= "\ndocument.getElementById(\"ActionPicture\").style.display = 'none';"; |
---|
152 | break; |
---|
153 | case 3: |
---|
154 | $add_js .= "\ndocument.getElementById(\"actionselect\").selectedIndex = 2;"; |
---|
155 | $add_js .= "\ndocument.getElementById(\"ActionAlbum\").style.display = 'none';"; |
---|
156 | $add_js .= "\ndocument.getElementById(\"ActionZoom\").style.display = 'none';"; |
---|
157 | $add_js .= "\ndocument.getElementById(\"ActionPicture\").style.display = 'block';"; |
---|
158 | break; |
---|
159 | } |
---|
160 | } |
---|
161 | |
---|
162 | //******* Generate map list ******* |
---|
163 | $query = " |
---|
164 | SELECT id, title |
---|
165 | FROM ".PSLI_MAPS_TABLE." |
---|
166 | ORDER BY title;"; |
---|
167 | $result = pwg_query($query); |
---|
168 | $associatedmap = ""; |
---|
169 | while ($row = pwg_db_fetch_assoc($result)) |
---|
170 | { |
---|
171 | $status = ""; |
---|
172 | if ($class_zone->isMapAssociated($row['id'])) |
---|
173 | $status = "CHECKED"; |
---|
174 | $associatedmap .= '<tr><td><input type="checkbox" name="associatedmap[]" value="'.$row['id'].'" style="margin-right:10px;" '.$status.' />'.$row['title'].'</td></tr>'; |
---|
175 | } |
---|
176 | |
---|
177 | //******* Generate category list for pin action ******* |
---|
178 | $query = ' |
---|
179 | SELECT id,name,uppercats,global_rank |
---|
180 | FROM '.CATEGORIES_TABLE.' |
---|
181 | ;'; |
---|
182 | $result = pwg_query($query); |
---|
183 | $actionalbum = array(); |
---|
184 | $actionalbum_selecteds = array(); |
---|
185 | if (pwg_db_num_rows($result) > 0) |
---|
186 | { |
---|
187 | while ($row = pwg_db_fetch_assoc($result)) |
---|
188 | { |
---|
189 | if (($class_zone->getAction() == 2) && ($row['id'] == $class_zone->getActionId())) |
---|
190 | { |
---|
191 | $option = strip_tags( |
---|
192 | get_cat_display_name_cache( |
---|
193 | $row['uppercats'], |
---|
194 | null, |
---|
195 | false |
---|
196 | ) |
---|
197 | ); |
---|
198 | $actionalbum_selecteds[$row['id']] = $option; |
---|
199 | array_push($actionalbum, $row); |
---|
200 | } |
---|
201 | else |
---|
202 | { |
---|
203 | array_push($actionalbum, $row); |
---|
204 | } |
---|
205 | } |
---|
206 | } |
---|
207 | $actionalbum_selecteds[0] = l10n('Not assign to a category'); |
---|
208 | usort($actionalbum, 'global_rank_compare'); |
---|
209 | display_select_categories($actionalbum, $actionalbum_selecteds, 'actionalbum_select', true); |
---|
210 | |
---|
211 | //******* Send configuration data to template ******* |
---|
212 | $class_zone->assignData($template, "HIDDENCENTERLAT", "HIDDENCENTERLON", "ZOOMMIN", "ZOOMMAX", "TITLE", "ACTIONPICTURE", "HIDDENZONE"); |
---|
213 | $class_zone->generateZoneList($template, "zone_select"); |
---|
214 | |
---|
215 | //******* Assign data to template ******* |
---|
216 | $template->assign( |
---|
217 | array( |
---|
218 | 'KEY' => $bing_map_key, |
---|
219 | 'JSPATH' => PSLI_BINGMAPS_JS_ZONE, |
---|
220 | 'DISPLAY' => $display, |
---|
221 | 'ADDJS' => $add_js, |
---|
222 | 'ASSOCIATEDMAP' => $associatedmap, |
---|
223 | 'ACTIONPICTURE' => $class_zone->getActionId() |
---|
224 | ) |
---|
225 | ); |
---|
226 | |
---|
227 | //******* Assign the template contents to ADMIN_CONTENT ******* |
---|
228 | $template->set_filenames(array('plugin_admin_content' => PSLI_BINGMAPS_ADMIN_ZONE_TPL)); |
---|
229 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
230 | ?> |
---|