1 | <?php |
---|
2 | /* ----------------------------------------------------------------------------- |
---|
3 | Plugin : GMaps |
---|
4 | Author : Grum |
---|
5 | email : grum@piwigo.org |
---|
6 | website : http://photos.grum.fr |
---|
7 | |
---|
8 | << May the Little SpaceFrog be with you ! >> |
---|
9 | ------------------------------------------------------------------------------ |
---|
10 | See main.inc.php for release information |
---|
11 | |
---|
12 | GMaps_AIP : classe to manage plugin admin pages |
---|
13 | |
---|
14 | --------------------------------------------------------------------------- */ |
---|
15 | |
---|
16 | include_once('gmaps_root.class.inc.php'); |
---|
17 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTables.class.inc.php'); |
---|
18 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTabSheet.class.inc.php'); |
---|
19 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
20 | |
---|
21 | class GMaps_AIP extends GMaps_root |
---|
22 | { |
---|
23 | protected $tabsheet; |
---|
24 | protected $amdState; |
---|
25 | |
---|
26 | public function __construct($prefixeTable, $filelocation) |
---|
27 | { |
---|
28 | parent::__construct($prefixeTable, $filelocation); |
---|
29 | $this->loadConfig(); |
---|
30 | $this->configForTemplate(); |
---|
31 | |
---|
32 | $this->amdState=GMaps_root::checkAMDActivated(); |
---|
33 | |
---|
34 | $this->initRequest(); |
---|
35 | $this->initEvents(); |
---|
36 | |
---|
37 | $this->tabsheet = new tabsheet(); |
---|
38 | |
---|
39 | |
---|
40 | if($this->amdState!='advanced') |
---|
41 | { |
---|
42 | $this->tabsheet->add('amd_warning', |
---|
43 | l10n('gmaps_warning'), |
---|
44 | $this->getAdminLink()."&fGMaps_tabsheet=amd_warning"); |
---|
45 | } |
---|
46 | $this->tabsheet->add('maps', |
---|
47 | l10n('gmaps_maps'), |
---|
48 | $this->getAdminLink()."&fGMaps_tabsheet=maps"); |
---|
49 | $this->tabsheet->add('category_maps', |
---|
50 | l10n('gmaps_associate_category_maps'), |
---|
51 | $this->getAdminLink()."&fGMaps_tabsheet=category_maps"); |
---|
52 | $this->tabsheet->add('kml_files', |
---|
53 | l10n('gmaps_kml_files_management'), |
---|
54 | $this->getAdminLink()."&fGMaps_tabsheet=kml_files"); |
---|
55 | $this->tabsheet->add('search', |
---|
56 | l10n('gmaps_search'), |
---|
57 | $this->getAdminLink()."&fGMaps_tabsheet=search"); |
---|
58 | /* $this->tabsheet->add('help', |
---|
59 | l10n('gmaps_help'), |
---|
60 | $this->getAdminLink()."&fGMaps_tabsheet=help"); |
---|
61 | */ |
---|
62 | } |
---|
63 | |
---|
64 | public function __destruct() |
---|
65 | { |
---|
66 | unset($this->tabsheet); |
---|
67 | parent::__destruct(); |
---|
68 | } |
---|
69 | |
---|
70 | /** |
---|
71 | * initialize events call for the plugin |
---|
72 | */ |
---|
73 | public function initEvents() |
---|
74 | { |
---|
75 | parent::initEvents(); |
---|
76 | |
---|
77 | if($_REQUEST['fGMaps_tabsheet']=='search') |
---|
78 | { |
---|
79 | // load request builder JS only on the search page |
---|
80 | GPCRequestBuilder::loadJSandCSS(); |
---|
81 | } |
---|
82 | add_event_handler('loc_end_page_header', array(&$this->css, 'applyCSS')); |
---|
83 | GPCCss::applyGpcCss(); |
---|
84 | } |
---|
85 | |
---|
86 | /** |
---|
87 | * display the administration page |
---|
88 | */ |
---|
89 | public function manage() |
---|
90 | { |
---|
91 | global $template; |
---|
92 | |
---|
93 | $this->initRequest(); |
---|
94 | |
---|
95 | $template->set_filename('plugin_admin_content', dirname(__FILE__)."/admin/gmaps_admin.tpl"); |
---|
96 | |
---|
97 | switch($_REQUEST['fGMaps_tabsheet']) |
---|
98 | { |
---|
99 | case 'amd_warning': |
---|
100 | $this->displayAmdWarning(); |
---|
101 | break; |
---|
102 | case 'maps': |
---|
103 | $this->displayMaps(); |
---|
104 | break; |
---|
105 | case 'category_maps': |
---|
106 | $this->displayCategoryMaps(); |
---|
107 | break; |
---|
108 | case 'kml_files': |
---|
109 | $this->displayKmlFiles(); |
---|
110 | break; |
---|
111 | case 'search': |
---|
112 | $this->displaySearch(); |
---|
113 | break; |
---|
114 | case 'help': |
---|
115 | $this->displayHelp(); |
---|
116 | break; |
---|
117 | } |
---|
118 | |
---|
119 | $this->tabsheet->select($_REQUEST['fGMaps_tabsheet']); |
---|
120 | $this->tabsheet->assign(); |
---|
121 | $selected_tab=$this->tabsheet->get_selected(); |
---|
122 | $template->assign($this->tabsheet->get_titlename(), "[".$selected_tab['caption']."]"); |
---|
123 | |
---|
124 | $template_plugin["GMAPS_VERSION"] = "<i>".$this->getPluginName()."</i> ".l10n('gmaps_release').GMAPS_VERSION; |
---|
125 | $template_plugin["GMAPS_PAGE"] = $_REQUEST['fGMaps_tabsheet']; |
---|
126 | $template_plugin["GMAPS_TITLE"] = ""; |
---|
127 | |
---|
128 | $template->assign('plugin', $template_plugin); |
---|
129 | |
---|
130 | if($_REQUEST['errcode']!='') |
---|
131 | { |
---|
132 | $template->assign('errcode', l10n('gmaps_error_code_'.$_REQUEST['errcode'])); |
---|
133 | } |
---|
134 | |
---|
135 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
136 | |
---|
137 | } |
---|
138 | |
---|
139 | |
---|
140 | |
---|
141 | |
---|
142 | /** |
---|
143 | * if empty, initialize the $_REQUEST var |
---|
144 | * |
---|
145 | * if not empty, check validity for the request values |
---|
146 | * |
---|
147 | */ |
---|
148 | private function initRequest() |
---|
149 | { |
---|
150 | //initialise $REQUEST values if not defined |
---|
151 | |
---|
152 | if(!isset($_REQUEST['errcode'])) $_REQUEST['errcode']=''; |
---|
153 | |
---|
154 | if(!isset($_REQUEST['fGMaps_tabsheet'])) |
---|
155 | { |
---|
156 | $_REQUEST['fGMaps_tabsheet']="maps"; |
---|
157 | } |
---|
158 | |
---|
159 | if(!($_REQUEST['fGMaps_tabsheet']!="maps" or |
---|
160 | $_REQUEST['fGMaps_tabsheet']!="category_maps" or |
---|
161 | $_REQUEST['fGMaps_tabsheet']!="amd_warning" |
---|
162 | //$_REQUEST['fGMaps_tabsheet']!="kml_files" or |
---|
163 | //$_REQUEST['fGMaps_tabsheet']!="search" or |
---|
164 | //$_REQUEST['fGMaps_tabsheet']!="help" |
---|
165 | )) $_REQUEST['fGMaps_tabsheet']="maps"; |
---|
166 | |
---|
167 | if($_REQUEST['fGMaps_tabsheet']=="amd_warning" and $this->amdState=='advanced') $_REQUEST['fGMaps_tabsheet']="maps"; |
---|
168 | } |
---|
169 | |
---|
170 | |
---|
171 | |
---|
172 | |
---|
173 | |
---|
174 | /** |
---|
175 | * display de maps page |
---|
176 | * |
---|
177 | */ |
---|
178 | protected function displayMaps() |
---|
179 | { |
---|
180 | global $template; |
---|
181 | |
---|
182 | $template->set_filename('body_page', |
---|
183 | dirname($this->getFileLocation()).'/admin/gmaps_maps.tpl'); |
---|
184 | |
---|
185 | $mapTabsheet = new GPCTabSheet('mapTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itab2'); |
---|
186 | $mapTabsheet->add('general', |
---|
187 | l10n('gmaps_properties_general'), |
---|
188 | '', true, "udm.displayTab('general');"); |
---|
189 | $mapTabsheet->add('dimensions', |
---|
190 | l10n('gmaps_dimensions'), |
---|
191 | '', false, "udm.displayTab('dimensions');"); |
---|
192 | $mapTabsheet->add('mapType', |
---|
193 | l10n('gmaps_properties_mapType'), |
---|
194 | '', false, "udm.displayTab('mapType');"); |
---|
195 | $mapTabsheet->add('zoomLevel', |
---|
196 | l10n('gmaps_properties_zoomLevel'), |
---|
197 | '', false, "udm.displayTab('zoomLevel');"); |
---|
198 | $mapTabsheet->assign(); |
---|
199 | |
---|
200 | |
---|
201 | $datas=Array( |
---|
202 | 'urlRequest' => $this->getAdminLink('ajax') |
---|
203 | ); |
---|
204 | $template->assign('datas', $datas); |
---|
205 | |
---|
206 | $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page'); |
---|
207 | } |
---|
208 | |
---|
209 | |
---|
210 | /** |
---|
211 | * display the category_maps page |
---|
212 | * |
---|
213 | */ |
---|
214 | protected function displayCategoryMaps() |
---|
215 | { |
---|
216 | global $template; |
---|
217 | |
---|
218 | $template->set_filename('body_page', |
---|
219 | dirname($this->getFileLocation()).'/admin/gmaps_category_maps.tpl'); |
---|
220 | |
---|
221 | $mapTabsheet = new GPCTabSheet('mapTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itab2'); |
---|
222 | $mapTabsheet->add('assoc', |
---|
223 | l10n('gmaps_map_assoc'), |
---|
224 | '', false, "am.displayTab('assoc');"); |
---|
225 | $mapTabsheet->add('integration', |
---|
226 | l10n('gmaps_map_integration'), |
---|
227 | '', true, "am.displayTab('integration');"); |
---|
228 | $mapTabsheet->assign(); |
---|
229 | |
---|
230 | |
---|
231 | $datas=Array( |
---|
232 | 'urlRequest' => $this->getAdminLink('ajax'), |
---|
233 | 'cats' => $this->makeCategoriesTree(), |
---|
234 | 'maps' => $this->makeMapsList(), |
---|
235 | 'icons' => $this->makeIconsList(), |
---|
236 | 'kmlFiles' => $this->makeKmlFilesList() |
---|
237 | ); |
---|
238 | $template->assign('datas', $datas); |
---|
239 | |
---|
240 | $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page'); |
---|
241 | } |
---|
242 | |
---|
243 | |
---|
244 | /** |
---|
245 | * display the kml file management page |
---|
246 | * |
---|
247 | */ |
---|
248 | protected function displayKmlFiles() |
---|
249 | { |
---|
250 | global $template; |
---|
251 | |
---|
252 | $template->set_filename('body_page', |
---|
253 | dirname($this->getFileLocation()).'/admin/gmaps_kmlfiles.tpl'); |
---|
254 | |
---|
255 | $datas=Array( |
---|
256 | 'urlRequest' => $this->getAdminLink('ajax'), |
---|
257 | ); |
---|
258 | $template->assign('datas', $datas); |
---|
259 | |
---|
260 | $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page'); |
---|
261 | } |
---|
262 | |
---|
263 | |
---|
264 | |
---|
265 | /** |
---|
266 | * display the search page |
---|
267 | * |
---|
268 | */ |
---|
269 | protected function displaySearch() |
---|
270 | { |
---|
271 | global $template; |
---|
272 | |
---|
273 | $template->set_filename('body_page', |
---|
274 | dirname($this->getFileLocation()).'/admin/gmaps_search.tpl'); |
---|
275 | |
---|
276 | $template->assign('gmaps_search_page', GPCRequestBuilder::displaySearchPage($this->getPluginName())); |
---|
277 | |
---|
278 | $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page'); |
---|
279 | } |
---|
280 | |
---|
281 | |
---|
282 | /** |
---|
283 | * display the help page |
---|
284 | * |
---|
285 | */ |
---|
286 | protected function displayHelp() |
---|
287 | { |
---|
288 | global $template; |
---|
289 | |
---|
290 | /*$template->set_filename('body_page', |
---|
291 | dirname($this->getFileLocation()).'/admin/plugin_admin_maps.tpl'); |
---|
292 | |
---|
293 | |
---|
294 | $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page');*/ |
---|
295 | } |
---|
296 | |
---|
297 | |
---|
298 | |
---|
299 | /** |
---|
300 | * display a warning page if AMD is not installed |
---|
301 | * |
---|
302 | */ |
---|
303 | protected function displayAmdWarning() |
---|
304 | { |
---|
305 | global $template; |
---|
306 | |
---|
307 | $template->set_filename('body_page', |
---|
308 | dirname($this->getFileLocation()).'/admin/gmaps_amd_warning.tpl'); |
---|
309 | |
---|
310 | switch(GMaps_root::checkAMDActivated()) |
---|
311 | { |
---|
312 | case 'none': |
---|
313 | case 'inactive': |
---|
314 | $template->assign('gmaps_amd_warning_inactive', sprintf(l10n('gmaps_amd_warning_inactive'), GMAPS_AMD_NEEDED)); |
---|
315 | break; |
---|
316 | case 'basic': |
---|
317 | $template->assign('gmaps_amd_warning_basic', l10n('gmaps_amd_warning_basic')); |
---|
318 | break; |
---|
319 | } |
---|
320 | $template->assign_var_from_handle('GMAPS_BODY_PAGE', 'body_page'); |
---|
321 | } |
---|
322 | |
---|
323 | |
---|
324 | /** |
---|
325 | * build the categories tree |
---|
326 | * @return Array : an array, ready to use in the template |
---|
327 | */ |
---|
328 | private function makeCategoriesTree() |
---|
329 | { |
---|
330 | $returned=array( |
---|
331 | array( |
---|
332 | 'id' => 0, |
---|
333 | 'name' => '-- '.l10n('gmaps_applyForAllTheGallery').' --' |
---|
334 | ) |
---|
335 | ); |
---|
336 | |
---|
337 | $sql="SELECT id, name, global_rank |
---|
338 | FROM ".CATEGORIES_TABLE." |
---|
339 | ORDER BY global_rank"; |
---|
340 | $result = pwg_query($sql); |
---|
341 | if($result) |
---|
342 | { |
---|
343 | while ($row = pwg_db_fetch_assoc($result)) |
---|
344 | { |
---|
345 | $returned[]=array( |
---|
346 | 'id' => $row['id'], |
---|
347 | 'name' => str_repeat(' ', substr_count($row['global_rank'], '.')).$row['name'] |
---|
348 | ); |
---|
349 | } |
---|
350 | } |
---|
351 | |
---|
352 | return($returned); |
---|
353 | } //makeCategoriesTree |
---|
354 | |
---|
355 | |
---|
356 | /** |
---|
357 | * build a maps list |
---|
358 | * @return Array : an array, ready to use in the template |
---|
359 | */ |
---|
360 | private function makeMapsList() |
---|
361 | { |
---|
362 | $returned=array( |
---|
363 | 'IC' => array(), |
---|
364 | 'IP' => array(), |
---|
365 | 'MP' => array() |
---|
366 | ); |
---|
367 | |
---|
368 | $sql="SELECT id, name, displayType |
---|
369 | FROM ".$this->tables['maps']." |
---|
370 | ORDER BY displayType, name"; |
---|
371 | $result = pwg_query($sql); |
---|
372 | if($result) |
---|
373 | { |
---|
374 | while($row = pwg_db_fetch_assoc($result)) |
---|
375 | { |
---|
376 | $returned[$row['displayType']][]=array( |
---|
377 | 'id' => $row['id'], |
---|
378 | 'name' => $row['name'] |
---|
379 | ); |
---|
380 | } |
---|
381 | } |
---|
382 | |
---|
383 | return($returned); |
---|
384 | } //makeMapsList |
---|
385 | |
---|
386 | |
---|
387 | /** |
---|
388 | * build THE ICON LIST |
---|
389 | * @return Array : an array, ready to use in the template |
---|
390 | */ |
---|
391 | private function makeIconsList() |
---|
392 | { |
---|
393 | $returned=array(); |
---|
394 | |
---|
395 | $directory=scandir(GMAPS_PATH.'img/'); |
---|
396 | foreach($directory as $file) |
---|
397 | { |
---|
398 | $ext=(pathinfo($file, PATHINFO_EXTENSION)); |
---|
399 | if(preg_match('/^i.*(?:jpg|jpeg|png|gif)$/i', $file)) |
---|
400 | { |
---|
401 | $returned[]=array( |
---|
402 | 'type' => (strtolower(substr($file,0,1))=='i')?'img':'other', |
---|
403 | 'file' => $file |
---|
404 | ); |
---|
405 | } |
---|
406 | } |
---|
407 | |
---|
408 | return($returned); |
---|
409 | } //makeIconsList |
---|
410 | |
---|
411 | |
---|
412 | /** |
---|
413 | * build the kml files list |
---|
414 | * @return Array : an array, ready to use in the template |
---|
415 | */ |
---|
416 | private function makeKmlFilesList() |
---|
417 | { |
---|
418 | $returned=array(); |
---|
419 | |
---|
420 | $sql="SELECT id, name |
---|
421 | FROM ".$this->tables['kmlfiles']." |
---|
422 | ORDER BY name, id"; |
---|
423 | $result = pwg_query($sql); |
---|
424 | if($result) |
---|
425 | { |
---|
426 | while($row = pwg_db_fetch_assoc($result)) |
---|
427 | { |
---|
428 | $returned[]=$row; |
---|
429 | } |
---|
430 | } |
---|
431 | |
---|
432 | return($returned); |
---|
433 | } //makeCategoriesTree |
---|
434 | |
---|
435 | } //class |
---|
436 | |
---|
437 | |
---|
438 | ?> |
---|