1 | <?php |
---|
2 | /* ----------------------------------------------------------------------------- |
---|
3 | Plugin : Advanced Menu Manager |
---|
4 | Author : Grum |
---|
5 | email : grum@grum.dnsalias.com |
---|
6 | website : http://photos.grum.fr |
---|
7 | PWG user : http://forum.phpwebgallery.net/profile.php?id=3706 |
---|
8 | |
---|
9 | << May the Little SpaceFrog be with you ! >> |
---|
10 | ------------------------------------------------------------------------------ |
---|
11 | See main.inc.php for release information |
---|
12 | |
---|
13 | AIP classe => manage integration in administration interface |
---|
14 | |
---|
15 | --------------------------------------------------------------------------- */ |
---|
16 | if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); } |
---|
17 | |
---|
18 | include_once(PHPWG_PLUGINS_PATH.'AMenuManager/amm_root.class.inc.php'); |
---|
19 | include_once(PHPWG_ROOT_PATH.'include/block.class.php'); |
---|
20 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
21 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCAjax.class.inc.php'); |
---|
22 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/genericjs.class.inc.php'); |
---|
23 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTranslate.class.inc.php'); |
---|
24 | |
---|
25 | class AMM_AIP extends AMM_root |
---|
26 | { |
---|
27 | protected $google_translate; |
---|
28 | protected $tabsheet; |
---|
29 | protected $sectionsId=array('menu' => 'Menu', 'special' => 'Specials'); |
---|
30 | |
---|
31 | protected $urls_modes=array(0 => 'new_window', 1 => 'current_window'); |
---|
32 | |
---|
33 | function AMM_AIP($prefixeTable, $filelocation) |
---|
34 | { |
---|
35 | parent::__construct($prefixeTable, $filelocation); |
---|
36 | |
---|
37 | $this->loadConfig(); |
---|
38 | $this->initEvents(); |
---|
39 | |
---|
40 | $this->tabsheet = new tabsheet(); |
---|
41 | $this->tabsheet->add('setmenu', |
---|
42 | l10n('g002_setmenu'), |
---|
43 | $this->getAdminLink().'&fAMM_tabsheet=setmenu'); |
---|
44 | $this->tabsheet->add('links', |
---|
45 | l10n('g002_addlinks'), |
---|
46 | $this->getAdminLink().'&fAMM_tabsheet=links'); |
---|
47 | $this->tabsheet->add('randompict', |
---|
48 | l10n('g002_randompict'), |
---|
49 | $this->getAdminLink().'&fAMM_tabsheet=randompict'); |
---|
50 | $this->tabsheet->add('personnalblock', |
---|
51 | l10n('g002_personnalblock'), |
---|
52 | $this->getAdminLink().'&fAMM_tabsheet=personnalblock'); |
---|
53 | $this->css = new GPCCss(dirname($this->getFileLocation()).'/'.$this->getPluginNameFiles().".css"); |
---|
54 | $this->google_translate = new GPCTranslate(); |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | /* --------------------------------------------------------------------------- |
---|
59 | Public classe functions |
---|
60 | --------------------------------------------------------------------------- */ |
---|
61 | |
---|
62 | /* |
---|
63 | manage plugin integration into piwigo's admin interface |
---|
64 | */ |
---|
65 | public function manage() |
---|
66 | { |
---|
67 | global $template, $page; |
---|
68 | |
---|
69 | $template->set_filename('plugin_admin_content', dirname(__FILE__)."/admin/amm_admin.tpl"); |
---|
70 | |
---|
71 | $this->return_ajax_content(); |
---|
72 | |
---|
73 | $this->init_request(); |
---|
74 | |
---|
75 | $this->tabsheet->select($_REQUEST['fAMM_tabsheet']); |
---|
76 | $this->tabsheet->assign(); |
---|
77 | $selected_tab=$this->tabsheet->get_selected(); |
---|
78 | $template->assign($this->tabsheet->get_titlename(), "[".$selected_tab['caption']."]"); |
---|
79 | |
---|
80 | $template_plugin["AMM_VERSION"] = "<i>".$this->getPluginName()."</i> ".l10n('g002_version').AMM_VERSION; |
---|
81 | $template_plugin["AMM_PAGE"] = $_REQUEST['fAMM_tabsheet']; |
---|
82 | $template_plugin["PATH"] = AMM_PATH; |
---|
83 | |
---|
84 | $template->assign('plugin', $template_plugin); |
---|
85 | |
---|
86 | |
---|
87 | if(isset($_POST['famm_modeedit'])) |
---|
88 | { |
---|
89 | $post_action=$_POST['famm_modeedit']; |
---|
90 | } |
---|
91 | else |
---|
92 | { |
---|
93 | $post_action=""; |
---|
94 | } |
---|
95 | |
---|
96 | $page_nfo=""; |
---|
97 | if($_REQUEST['fAMM_tabsheet']=='links') |
---|
98 | { |
---|
99 | $page_nfo=l10n('g002_addlinks_nfo'); |
---|
100 | |
---|
101 | switch($_REQUEST['action']) |
---|
102 | { |
---|
103 | case 'list': |
---|
104 | $this->display_links_list_page(); |
---|
105 | break; |
---|
106 | case 'create': |
---|
107 | case 'modify': |
---|
108 | if($post_action==$_REQUEST['action']) |
---|
109 | { |
---|
110 | if(!$this->adviser_abort()) |
---|
111 | { |
---|
112 | $this->action_create_modify_url(); |
---|
113 | } |
---|
114 | $this->display_links_list_page(); |
---|
115 | } |
---|
116 | else |
---|
117 | { |
---|
118 | ($_REQUEST['action']=='modify')?$urlid=$_REQUEST['fItem']:$urlid=0; |
---|
119 | $this->display_links_manage_page($_REQUEST['action'], $urlid); |
---|
120 | } |
---|
121 | break; |
---|
122 | case 'config': |
---|
123 | if($post_action==$_REQUEST['action']) |
---|
124 | { |
---|
125 | if(!$this->adviser_abort()) |
---|
126 | { |
---|
127 | $this->action_links_modify_config(); |
---|
128 | } |
---|
129 | } |
---|
130 | $this->display_links_config_page(); |
---|
131 | break; |
---|
132 | } |
---|
133 | } |
---|
134 | elseif($_REQUEST['fAMM_tabsheet']=='randompict') |
---|
135 | { |
---|
136 | $page_nfo=l10n('g002_randompict_nfo'); |
---|
137 | if($post_action=='config') |
---|
138 | { |
---|
139 | if(!$this->adviser_abort()) |
---|
140 | { |
---|
141 | $this->action_randompic_modify_config(); |
---|
142 | } |
---|
143 | } |
---|
144 | $this->display_randompic_config_page(); |
---|
145 | } |
---|
146 | elseif($_REQUEST['fAMM_tabsheet']=='personnalblock') |
---|
147 | { |
---|
148 | $page_nfo=l10n('g002_personnalblock_nfo'); |
---|
149 | |
---|
150 | switch($_REQUEST['action']) |
---|
151 | { |
---|
152 | case 'list': |
---|
153 | $this->display_personalised_list_page(); |
---|
154 | break; |
---|
155 | case 'create': |
---|
156 | case 'modify': |
---|
157 | if($post_action==$_REQUEST['action']) |
---|
158 | { |
---|
159 | if(!$this->adviser_abort()) |
---|
160 | { |
---|
161 | $this->action_create_modify_personalised(); |
---|
162 | } |
---|
163 | $this->display_personalised_list_page(); |
---|
164 | } |
---|
165 | else |
---|
166 | { |
---|
167 | ($_REQUEST['action']=='modify')?$sectionid=$_REQUEST['fItem']:$sectionid=0; |
---|
168 | $this->display_personalised_manage_page($_REQUEST['action'], $sectionid); |
---|
169 | } |
---|
170 | break; |
---|
171 | } |
---|
172 | } |
---|
173 | elseif($_REQUEST['fAMM_tabsheet']=='setmenu') |
---|
174 | { |
---|
175 | $page_nfo=l10n('g002_setmenu_nfo'); |
---|
176 | $this->display_sections_page(); |
---|
177 | } |
---|
178 | |
---|
179 | $template->assign('page_nfo', $page_nfo); |
---|
180 | |
---|
181 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
182 | |
---|
183 | |
---|
184 | } |
---|
185 | |
---|
186 | /* |
---|
187 | initialize events call for the plugin |
---|
188 | */ |
---|
189 | public function initEvents() |
---|
190 | { |
---|
191 | add_event_handler('loc_end_page_header', array(&$this->css, 'applyCSS')); |
---|
192 | } |
---|
193 | |
---|
194 | /* --------------------------------------------------------------------------- |
---|
195 | Private classe functions |
---|
196 | --------------------------------------------------------------------------- */ |
---|
197 | |
---|
198 | /* |
---|
199 | return ajax content |
---|
200 | */ |
---|
201 | protected function return_ajax_content() |
---|
202 | { |
---|
203 | global $ajax, $template; |
---|
204 | |
---|
205 | if(isset($_REQUEST['ajaxfct'])) |
---|
206 | { |
---|
207 | //$this->debug("AJAXFCT:".$_REQUEST['ajaxfct']); |
---|
208 | $result="<p class='errors'>".l10n('g002_error_invalid_ajax_call')."</p>"; |
---|
209 | switch($_REQUEST['ajaxfct']) |
---|
210 | { |
---|
211 | case 'links_list': |
---|
212 | $result=$this->ajax_amm_links_list(); |
---|
213 | break; |
---|
214 | case 'links_permut': |
---|
215 | $result=$this->ajax_amm_links_permut($_REQUEST['fItem'], $_REQUEST['fPermut']); |
---|
216 | break; |
---|
217 | case 'links_delete': |
---|
218 | $result=$this->ajax_amm_links_delete($_REQUEST['fItem']); |
---|
219 | break; |
---|
220 | |
---|
221 | /* |
---|
222 | case 'setmenu_modmenu_sections_list': |
---|
223 | $result=$this->ajax_amm_setmenu_mod_section_list('amm_sections_modmenu'); |
---|
224 | break; |
---|
225 | case 'setmenu_modmenu_sections_showhide': |
---|
226 | $result=$this->ajax_amm_setmenu_mod_section_showhide('amm_sections_modmenu', $_REQUEST['fItem']); |
---|
227 | break; |
---|
228 | |
---|
229 | case 'setmenu_modspecial_sections_list': |
---|
230 | $result=$this->ajax_amm_setmenu_mod_section_list('amm_sections_modspecials'); |
---|
231 | break; |
---|
232 | case 'setmenu_modspecial_sections_showhide': |
---|
233 | $result=$this->ajax_amm_setmenu_mod_section_showhide('amm_sections_modspecials', $_REQUEST['fItem']); |
---|
234 | break; |
---|
235 | */ |
---|
236 | |
---|
237 | case 'personalised_list': |
---|
238 | $result=$this->ajax_amm_personalised_list(); |
---|
239 | break; |
---|
240 | case 'personalised_delete': |
---|
241 | $result=$this->ajax_amm_personalised_delete($_REQUEST['fItem']); |
---|
242 | break; |
---|
243 | } |
---|
244 | |
---|
245 | GPCAjax::returnResult($result); |
---|
246 | } |
---|
247 | } |
---|
248 | |
---|
249 | /* |
---|
250 | if empty, initialize $_request |
---|
251 | */ |
---|
252 | private function init_request() |
---|
253 | { |
---|
254 | //initialise $REQUEST values if not defined |
---|
255 | if(!array_key_exists('fAMM_tabsheet', $_REQUEST)) |
---|
256 | { |
---|
257 | $_REQUEST['fAMM_tabsheet']='setmenu'; |
---|
258 | } |
---|
259 | |
---|
260 | if((($_REQUEST['fAMM_tabsheet']=='links') or |
---|
261 | ($_REQUEST['fAMM_tabsheet']=='personnalblock')) and !isset($_REQUEST['action'])) |
---|
262 | { |
---|
263 | $_REQUEST['action']='list'; |
---|
264 | } |
---|
265 | elseif((($_REQUEST['fAMM_tabsheet']=='setmenu')) and !isset($_REQUEST['action'])) |
---|
266 | { |
---|
267 | $_REQUEST['action']='modmenu'; |
---|
268 | } |
---|
269 | |
---|
270 | |
---|
271 | |
---|
272 | } //init_request |
---|
273 | |
---|
274 | |
---|
275 | /* |
---|
276 | manage display for urls table page |
---|
277 | */ |
---|
278 | private function display_links_list_page() |
---|
279 | { |
---|
280 | global $template, $user; |
---|
281 | $template->set_filename('body_page', |
---|
282 | dirname($this->getFileLocation()).'/admin/amm_linkslist.tpl'); |
---|
283 | |
---|
284 | $tmp=$this->get_count_url(); |
---|
285 | if($tmp==0) |
---|
286 | { |
---|
287 | $tmp=l10n("g002_nolinks"); |
---|
288 | } |
---|
289 | elseif($tmp==1) |
---|
290 | { |
---|
291 | $tmp="1 ".l10n("g002_link"); |
---|
292 | } |
---|
293 | else |
---|
294 | { |
---|
295 | $tmp=$tmp." ".l10n("g002_links"); |
---|
296 | } |
---|
297 | |
---|
298 | |
---|
299 | $template_datas=array( |
---|
300 | 'lnk_create' => $this->getAdminLink().'&fAMM_tabsheet=links&action=create', |
---|
301 | 'lnk_config' => $this->getAdminLink().'&fAMM_tabsheet=links&action=config', |
---|
302 | 'AMM_AJAX_URL_LIST' => $this->getAdminLink()."&ajaxfct=", |
---|
303 | 'nburl' => $tmp |
---|
304 | ); |
---|
305 | |
---|
306 | $template->assign("datas", $template_datas); |
---|
307 | $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page'); |
---|
308 | } |
---|
309 | |
---|
310 | /* |
---|
311 | manage display for urls config page |
---|
312 | */ |
---|
313 | private function display_links_config_page() |
---|
314 | { |
---|
315 | global $template, $user; |
---|
316 | $template->set_filename('body_page', |
---|
317 | dirname($this->getFileLocation()).'/admin/amm_linksconfig.tpl'); |
---|
318 | |
---|
319 | $template_datas=array( |
---|
320 | 'lnk_list' => $this->getAdminLink().'&fAMM_tabsheet=links', |
---|
321 | 'AMM_AJAX_URL_LIST' => $this->getAdminLink()."&ajaxfct=", |
---|
322 | 'show_icons_selected' => $this->config['amm_links_show_icons'], |
---|
323 | 'lang_selected' => $user['language'], |
---|
324 | 'fromlang' => substr($user['language'],0,2) |
---|
325 | ); |
---|
326 | |
---|
327 | $template_datas['language_list'] = array(); |
---|
328 | foreach($this->config['amm_links_title'] as $key => $val) |
---|
329 | { |
---|
330 | $template_datas['language_list'][] = array( |
---|
331 | 'LANG' => $key, |
---|
332 | 'MENUBARTIT' => base64_decode($val) |
---|
333 | ); |
---|
334 | } |
---|
335 | |
---|
336 | |
---|
337 | |
---|
338 | $lang=get_languages(); |
---|
339 | foreach($lang as $key => $val) |
---|
340 | { |
---|
341 | $template_datas['language_list_values'][] = $key; |
---|
342 | $template_datas['language_list_labels'][] = $val; |
---|
343 | } |
---|
344 | |
---|
345 | |
---|
346 | $template_datas['yesno_values'] = array('y','n'); |
---|
347 | $template_datas['yesno_labels'][] = l10n('g002_yesno_y'); |
---|
348 | $template_datas['yesno_labels'][] = l10n('g002_yesno_n'); |
---|
349 | |
---|
350 | |
---|
351 | $template->assign("datas", $template_datas); |
---|
352 | $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page'); |
---|
353 | } |
---|
354 | |
---|
355 | /* |
---|
356 | manage display for urls create/modify page |
---|
357 | */ |
---|
358 | private function display_links_manage_page($modeedit = 'create', $urlid=0) |
---|
359 | { |
---|
360 | global $template, $user; |
---|
361 | $template->set_filename('body_page', |
---|
362 | dirname($this->getFileLocation()).'/admin/amm_linkslist_edit.tpl'); |
---|
363 | |
---|
364 | $extensions_list=array('jpg'=>0,'jpeg'=>0,'gif'=>0,'png'=>0); |
---|
365 | $template_icons_list=array(); |
---|
366 | $directory=dir(dirname($this->getFileLocation()).'/links_pictures/'); |
---|
367 | while($file=$directory->read()) |
---|
368 | { |
---|
369 | if(isset($extensions_list[get_extension(strtolower($file))])) |
---|
370 | { |
---|
371 | $template_icons_list[]=$file; |
---|
372 | } |
---|
373 | } |
---|
374 | |
---|
375 | |
---|
376 | if($modeedit=='modify') |
---|
377 | { |
---|
378 | $url=$this->get_url($urlid); |
---|
379 | |
---|
380 | $template_datas=array( |
---|
381 | 'id' => $urlid, |
---|
382 | 'modeedit' => 'modify', |
---|
383 | 'label' => htmlentities($url['label'], ENT_QUOTES, 'UTF-8'), |
---|
384 | 'url' => $url['url'], |
---|
385 | 'icons_selected' => $url['icon'], |
---|
386 | 'mode_selected' => $url['mode'], |
---|
387 | 'visible_selected' => $url['visible'] |
---|
388 | ); |
---|
389 | } |
---|
390 | else |
---|
391 | { |
---|
392 | $template_datas=array( |
---|
393 | 'id' => '', |
---|
394 | 'modeedit' => 'create', |
---|
395 | 'label' => '', |
---|
396 | 'url' => '', |
---|
397 | 'icons_selected' => $template_icons_list[0], |
---|
398 | 'mode_selected' => 0, |
---|
399 | 'visible_selected' => 'y' |
---|
400 | ); |
---|
401 | } |
---|
402 | |
---|
403 | $template_datas['lnk_list'] = $this->getAdminLink().'&fAMM_tabsheet=links'; |
---|
404 | $template_datas['icons_img'] = AMM_PATH."links_pictures/".$template_datas['icons_selected']; |
---|
405 | $template_datas['icons_values'] = array(); |
---|
406 | foreach($template_icons_list as $key => $val) |
---|
407 | { |
---|
408 | $template_datas['icons_values'][] = array( |
---|
409 | 'img' => AMM_PATH."links_pictures/".$val, |
---|
410 | 'value' => $val, |
---|
411 | 'label' => $val |
---|
412 | ); |
---|
413 | } |
---|
414 | $template_datas['mode_values'] = array(0,1); |
---|
415 | $template_datas['mode_labels'][] = l10n("g002_mode_".$this->urls_modes[0]); |
---|
416 | $template_datas['mode_labels'][] = l10n("g002_mode_".$this->urls_modes[1]); |
---|
417 | $template_datas['visible_values'] = array('y','n'); |
---|
418 | $template_datas['visible_labels'][] = l10n('g002_yesno_y'); |
---|
419 | $template_datas['visible_labels'][] = l10n('g002_yesno_n'); |
---|
420 | |
---|
421 | $template->assign("datas", $template_datas); |
---|
422 | $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page'); |
---|
423 | } |
---|
424 | |
---|
425 | /* |
---|
426 | manage create/modify url into database and display result |
---|
427 | */ |
---|
428 | protected function action_create_modify_url() |
---|
429 | { |
---|
430 | $datas=array( |
---|
431 | 'id' => $_POST['famm_id'], |
---|
432 | 'label' => $_POST['famm_label'], |
---|
433 | 'url' => $_POST['famm_url'], |
---|
434 | 'mode' => $_POST['famm_mode'], |
---|
435 | 'icon' => $_POST['famm_icon'], |
---|
436 | 'position' => 0, |
---|
437 | 'visible' => $_POST['famm_visible'] |
---|
438 | ); |
---|
439 | |
---|
440 | switch($_POST['famm_modeedit']) |
---|
441 | { |
---|
442 | case 'create': |
---|
443 | $this->add_url($datas); |
---|
444 | break; |
---|
445 | case 'modify': |
---|
446 | $this->modify_url($datas); |
---|
447 | } |
---|
448 | } |
---|
449 | |
---|
450 | /* |
---|
451 | manage urls config save into database |
---|
452 | */ |
---|
453 | protected function action_links_modify_config() |
---|
454 | { |
---|
455 | $this->config['amm_links_show_icons']=$_POST['famm_links_show_icons']; |
---|
456 | $languages=get_languages(); |
---|
457 | foreach($languages as $key => $val) |
---|
458 | { |
---|
459 | $this->config['amm_links_title'][$key]=base64_encode($_POST['famm_links_title_'.$key]); |
---|
460 | } |
---|
461 | $this->saveConfig(); |
---|
462 | } |
---|
463 | |
---|
464 | /* |
---|
465 | manage randompic config save into database |
---|
466 | */ |
---|
467 | protected function action_randompic_modify_config() |
---|
468 | { |
---|
469 | $this->config['amm_randompicture_height']=$_POST['famm_randompicture_height']; |
---|
470 | $this->config['amm_randompicture_periodicchange']=$_POST['famm_randompicture_periodicchange']; |
---|
471 | $this->config['amm_randompicture_showname']=$_POST['famm_randompicture_showname']; |
---|
472 | $this->config['amm_randompicture_showcomment']=$_POST['famm_randompicture_showcomment']; |
---|
473 | $languages=get_languages(); |
---|
474 | foreach($languages as $key => $val) |
---|
475 | { |
---|
476 | $this->config['amm_randompicture_title'][$key]=base64_encode(stripslashes($_POST['famm_randompicture_title_'.$key])); |
---|
477 | } |
---|
478 | $this->saveConfig(); |
---|
479 | } |
---|
480 | |
---|
481 | |
---|
482 | |
---|
483 | /* |
---|
484 | manage display for sections table page |
---|
485 | */ |
---|
486 | private function display_sections_page() |
---|
487 | { |
---|
488 | global $template, $user, $page; |
---|
489 | $template->set_filename('body_page', dirname($this->getFileLocation()).'/admin/amm_sections.tpl'); |
---|
490 | |
---|
491 | if(isset($_POST['fList']) && !$this->adviser_abort()) |
---|
492 | { |
---|
493 | /* the returned information in the fList form element are |
---|
494 | * a list of ecah item, separate with a ";" |
---|
495 | * each item have properties separated by a "," |
---|
496 | * id, container, order, visibility |
---|
497 | */ |
---|
498 | $items=explode(";",$_POST['fList']); |
---|
499 | for($i=0;$i<count($items)-1;$i++) |
---|
500 | { |
---|
501 | $properties=explode("#", $items[$i]); |
---|
502 | $properties[0]=explode(",", $properties[0]); |
---|
503 | $this->config['amm_sections_items'][$properties[0][0]]['container']=$properties[0][1]; |
---|
504 | $this->config['amm_sections_items'][$properties[0][0]]['order']=$properties[0][2]; |
---|
505 | $this->config['amm_sections_items'][$properties[0][0]]['visibility']=$properties[1]; |
---|
506 | } |
---|
507 | $this->sortSectionsItems(); |
---|
508 | if($this->saveConfig()) |
---|
509 | { |
---|
510 | array_push($page['infos'], l10n('g002_config_saved')); |
---|
511 | } |
---|
512 | else |
---|
513 | { |
---|
514 | array_push($page['errors'], l10n('g002_adviser_not_allowed')); |
---|
515 | } |
---|
516 | } |
---|
517 | |
---|
518 | foreach($this->config['amm_sections_items'] as $key=>$val) |
---|
519 | { |
---|
520 | $this->config['amm_sections_items'][$key]['visibilityForm'] = $this->makeVisibility($val['visibility'], $key); |
---|
521 | $this->defaultMenus[$key]['visibilityForm'] = $this->makeVisibility("guest,generic,normal,webmaster,admin/", $key); |
---|
522 | } |
---|
523 | |
---|
524 | $this->sortSectionsItems(); |
---|
525 | |
---|
526 | $users=new GPCUsers(""); |
---|
527 | $groups=new GPCGroups(""); |
---|
528 | |
---|
529 | |
---|
530 | $template->assign("visibility", Array('users' => $users->access_list, 'groups' => $groups->access_list)); |
---|
531 | $template->assign("sections", $this->sectionsId); |
---|
532 | $template->assign("defaultValues", $this->defaultMenus); |
---|
533 | $template->assign("items", $this->config['amm_sections_items']); |
---|
534 | $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page'); |
---|
535 | } |
---|
536 | |
---|
537 | |
---|
538 | /* |
---|
539 | manage display for randompic config page |
---|
540 | */ |
---|
541 | private function display_randompic_config_page() |
---|
542 | { |
---|
543 | global $template, $user; |
---|
544 | $template->set_filename('body_page', |
---|
545 | dirname($this->getFileLocation()).'/admin/amm_randompicconfig.tpl'); |
---|
546 | |
---|
547 | $template_datas=array( |
---|
548 | 'lnk_list' => $this->getAdminLink().'&fAMM_tabsheet=links', |
---|
549 | 'showname_selected' => $this->config['amm_randompicture_showname'], |
---|
550 | 'showcomment_selected' => $this->config['amm_randompicture_showcomment'], |
---|
551 | 'periodic_change' => $this->config['amm_randompicture_periodicchange'], |
---|
552 | 'height' => $this->config['amm_randompicture_height'], |
---|
553 | 'lang_selected' => $user['language'], |
---|
554 | 'fromlang' => substr($user['language'],0,2) |
---|
555 | ); |
---|
556 | |
---|
557 | $template_datas['language_list'] = array(); |
---|
558 | foreach($this->config['amm_randompicture_title'] as $key => $val) |
---|
559 | { |
---|
560 | $template_datas['language_list'][] = array( |
---|
561 | 'LANG' => $key, |
---|
562 | 'MENUBARTIT' => htmlentities(base64_decode($val), ENT_QUOTES, 'UTF-8') |
---|
563 | ); |
---|
564 | } |
---|
565 | |
---|
566 | |
---|
567 | |
---|
568 | $lang=get_languages(); |
---|
569 | foreach($lang as $key => $val) |
---|
570 | { |
---|
571 | $template_datas['language_list_values'][] = $key; |
---|
572 | $template_datas['language_list_labels'][] = $val; |
---|
573 | } |
---|
574 | |
---|
575 | |
---|
576 | $template_datas['yesno_values'] = array('y','n'); |
---|
577 | $template_datas['yesno_labels'][] = l10n('g002_yesno_y'); |
---|
578 | $template_datas['yesno_labels'][] = l10n('g002_yesno_n'); |
---|
579 | |
---|
580 | $template_datas['show_values'] = array('n', 'o', 'u'); |
---|
581 | $template_datas['show_labels'][] = l10n('g002_show_n'); |
---|
582 | $template_datas['show_labels'][] = l10n('g002_show_o'); |
---|
583 | $template_datas['show_labels'][] = l10n('g002_show_u'); |
---|
584 | |
---|
585 | |
---|
586 | $template->assign("datas", $template_datas); |
---|
587 | $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page'); |
---|
588 | } |
---|
589 | |
---|
590 | |
---|
591 | |
---|
592 | |
---|
593 | |
---|
594 | |
---|
595 | |
---|
596 | /* |
---|
597 | manage display for personalised sections list page |
---|
598 | */ |
---|
599 | private function display_personalised_list_page() |
---|
600 | { |
---|
601 | global $template, $user; |
---|
602 | $template->set_filename('body_page', |
---|
603 | dirname($this->getFileLocation()).'/admin/amm_personalisedlist.tpl'); |
---|
604 | |
---|
605 | $sql="SELECT COUNT(DISTINCT ID) as countid FROM ".$this->tables['personalised']; |
---|
606 | $result=pwg_query($sql); |
---|
607 | if($result) |
---|
608 | { |
---|
609 | $tmp=pwg_db_fetch_row($result); |
---|
610 | $tmp=$tmp[0]; |
---|
611 | } |
---|
612 | else |
---|
613 | { |
---|
614 | $tmp=0; |
---|
615 | } |
---|
616 | |
---|
617 | if($tmp==0) |
---|
618 | { |
---|
619 | $tmp=l10n("g002_nosections"); |
---|
620 | } |
---|
621 | elseif($tmp==1) |
---|
622 | { |
---|
623 | $tmp="1 ".l10n("g002_section"); |
---|
624 | } |
---|
625 | else |
---|
626 | { |
---|
627 | $tmp=$tmp." ".l10n("g002_sections"); |
---|
628 | } |
---|
629 | |
---|
630 | |
---|
631 | $template_datas=array( |
---|
632 | 'lnk_create' => $this->getAdminLink().'&fAMM_tabsheet=personnalblock&action=create', |
---|
633 | 'AMM_AJAX_URL_LIST' => $this->getAdminLink()."&ajaxfct=", |
---|
634 | 'nbsections' => $tmp |
---|
635 | ); |
---|
636 | |
---|
637 | $template->assign("datas", $template_datas); |
---|
638 | $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page'); |
---|
639 | } |
---|
640 | |
---|
641 | |
---|
642 | |
---|
643 | /* |
---|
644 | manage display for personalised sections create/modify page |
---|
645 | */ |
---|
646 | private function display_personalised_manage_page($modeedit = 'create', $sectionid=0) |
---|
647 | { |
---|
648 | global $template, $user; |
---|
649 | $template->set_filename('body_page', |
---|
650 | dirname($this->getFileLocation()).'/admin/amm_personalisedlist_edit.tpl'); |
---|
651 | |
---|
652 | $template_datas=array(); |
---|
653 | |
---|
654 | $lang=get_languages(); |
---|
655 | $lang['all']=l10n('g002_all_languages'); |
---|
656 | foreach($lang as $key => $val) |
---|
657 | { |
---|
658 | $template_datas['language_list_values'][] = $key; |
---|
659 | $template_datas['language_list_labels'][] = $val; |
---|
660 | $template_datas['language_list'][$key]=array( |
---|
661 | 'LANG' => $key, |
---|
662 | 'MENUBARTIT' => '', |
---|
663 | 'MENUBARCONTENT' => '' |
---|
664 | ); |
---|
665 | } |
---|
666 | |
---|
667 | |
---|
668 | if($modeedit=='modify') |
---|
669 | { |
---|
670 | $sections=$this->get_personalised($sectionid); |
---|
671 | |
---|
672 | $template_datas['id'] = $sectionid; |
---|
673 | $template_datas['modeedit'] = 'modify'; |
---|
674 | $template_datas['visible_selected'] = $sections[0]['visible']; |
---|
675 | $template_datas['nfo'] = htmlentities($sections[0]['nfo'], ENT_QUOTES, 'UTF-8'); |
---|
676 | |
---|
677 | foreach($sections as $key => $val) |
---|
678 | { |
---|
679 | $lang=($val['lang']=='*')?'all':$val['lang']; |
---|
680 | $template_datas['language_list'][$lang] = array( |
---|
681 | 'LANG' => $lang, |
---|
682 | 'MENUBARTIT' => htmlentities($val['title'], ENT_QUOTES, 'UTF-8'), |
---|
683 | 'MENUBARCONTENT' => htmlentities($val['content'], ENT_QUOTES, 'UTF-8'), |
---|
684 | ); |
---|
685 | } |
---|
686 | } |
---|
687 | else |
---|
688 | { |
---|
689 | $template_datas['nfo'] = ''; |
---|
690 | $template_datas['id'] = ''; |
---|
691 | $template_datas['modeedit'] = 'create'; |
---|
692 | $template_datas['visible_selected'] = 'y'; |
---|
693 | } |
---|
694 | |
---|
695 | $template_datas['lang_selected'] = $user['language']; |
---|
696 | |
---|
697 | $template_datas['personalised_list'] = $this->getAdminLink().'&fAMM_tabsheet=personnalblock'; |
---|
698 | $template_datas['yesno_values'] = array('y','n'); |
---|
699 | $template_datas['yesno_labels'][] = l10n('g002_yesno_y'); |
---|
700 | $template_datas['yesno_labels'][] = l10n('g002_yesno_n'); |
---|
701 | |
---|
702 | $template->assign("datas", $template_datas); |
---|
703 | $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page'); |
---|
704 | } |
---|
705 | |
---|
706 | /* |
---|
707 | manage create/modify pesonalised sections into database and display result |
---|
708 | */ |
---|
709 | protected function action_create_modify_personalised() |
---|
710 | { |
---|
711 | global $user; |
---|
712 | |
---|
713 | if($_POST['famm_modeedit']=='create') |
---|
714 | { |
---|
715 | $id=$this->get_personalised_id(); |
---|
716 | } |
---|
717 | else |
---|
718 | { |
---|
719 | $id=$_POST['famm_id']; |
---|
720 | } |
---|
721 | $languages=get_languages(); |
---|
722 | $languages['all']='*'; |
---|
723 | foreach($languages as $key => $val) |
---|
724 | { |
---|
725 | $datas=array( |
---|
726 | 'id' => $id, |
---|
727 | 'lang' => ($key=='all')?'*':$key, |
---|
728 | 'visible' => $_POST['famm_personalised_visible'], |
---|
729 | 'nfo' => ($_POST['famm_personalised_nfo']=='')?$_POST['famm_personalised_title_'.$user['language']]:$_POST['famm_personalised_nfo'], |
---|
730 | 'title' => $_POST['famm_personalised_title_'.$key], |
---|
731 | 'content' => $_POST['famm_personalised_content_'.$key] |
---|
732 | ); |
---|
733 | switch($_POST['famm_modeedit']) |
---|
734 | { |
---|
735 | case 'create': |
---|
736 | $this->add_personalised($datas); |
---|
737 | break; |
---|
738 | case 'modify': |
---|
739 | $this->modify_personalised($datas); |
---|
740 | } |
---|
741 | } |
---|
742 | } |
---|
743 | |
---|
744 | |
---|
745 | |
---|
746 | /* this function returns an HTML FORM to use with each menu items |
---|
747 | * $visibility is a formatted string looking this : |
---|
748 | * users type1(,users typeX)/(groupId0)(,groupIdX)) |
---|
749 | */ |
---|
750 | private function makeVisibility($visibility, $id) |
---|
751 | { |
---|
752 | $local_tpl = new Template(AMM_PATH."admin/", ""); |
---|
753 | $local_tpl->set_filename('body_page', |
---|
754 | dirname($this->getFileLocation()).'/admin/amm_sections_visibility.tpl'); |
---|
755 | |
---|
756 | |
---|
757 | $parameters=explode("/", $visibility); |
---|
758 | |
---|
759 | $users=new GPCUsers(str_replace(",", "/", $parameters[0])); |
---|
760 | $users->setAllowed('admin', true); |
---|
761 | $groups=new GPCGroups(str_replace(",", "/", $parameters[1])); |
---|
762 | |
---|
763 | $local_tpl->assign('name', $id); |
---|
764 | $local_tpl->assign('users', $users->access_list); |
---|
765 | $local_tpl->assign('groups', $groups->access_list); |
---|
766 | |
---|
767 | return($local_tpl->parse('body_page', true)); |
---|
768 | } |
---|
769 | |
---|
770 | |
---|
771 | |
---|
772 | /* |
---|
773 | manage adviser profile |
---|
774 | return true if user is adviser |
---|
775 | */ |
---|
776 | protected function adviser_abort() |
---|
777 | { |
---|
778 | if(is_adviser()) |
---|
779 | { |
---|
780 | $this->displayResult(l10n("g002_adviser_not_allowed"), false); |
---|
781 | return(true); |
---|
782 | } |
---|
783 | return(false); |
---|
784 | } |
---|
785 | |
---|
786 | |
---|
787 | |
---|
788 | /* --------------------------------------------------------------------------- |
---|
789 | functions to manage urls tables |
---|
790 | --------------------------------------------------------------------------- */ |
---|
791 | // protected function get_urls() |
---|
792 | // protected function get_count_url() |
---|
793 | // => defined in root class |
---|
794 | |
---|
795 | // return properties of an given url |
---|
796 | private function get_url($url_id) |
---|
797 | { |
---|
798 | $returned=array(); |
---|
799 | $sql="SELECT * FROM ".$this->tables['urls']." WHERE id = '".$url_id."'"; |
---|
800 | $result=pwg_query($sql); |
---|
801 | if($result) |
---|
802 | { |
---|
803 | $returned=pwg_db_fetch_assoc($result); |
---|
804 | //$returned['label']=stripslashes($returned['label']); |
---|
805 | } |
---|
806 | return($returned); |
---|
807 | } |
---|
808 | |
---|
809 | // permut position of two 2 urls |
---|
810 | private function permut_url($url_id, $url_permut) |
---|
811 | { |
---|
812 | $sql="SELECT id, position FROM ".$this->tables['urls']." WHERE id IN ('".$url_id."','".$url_permut."')"; |
---|
813 | $result=pwg_query($sql); |
---|
814 | if($result) |
---|
815 | { |
---|
816 | $tmp=array(); |
---|
817 | while($row=pwg_db_fetch_assoc($result)) |
---|
818 | { |
---|
819 | $tmp[$row['id']]=$row['position']; |
---|
820 | } |
---|
821 | $sql="UPDATE ".$this->tables['urls']." SET position = ".$tmp[$url_id]." WHERE id = '".$url_permut."'"; |
---|
822 | pwg_query($sql); |
---|
823 | $sql="UPDATE ".$this->tables['urls']." SET position = ".$tmp[$url_permut]." WHERE id = '".$url_id."'"; |
---|
824 | pwg_query($sql); |
---|
825 | } |
---|
826 | } |
---|
827 | |
---|
828 | // delete an url |
---|
829 | private function delete_url($url_id) |
---|
830 | { |
---|
831 | $sql="DELETE FROM ".$this->tables['urls']." WHERE id = '".$url_id."' "; |
---|
832 | return(pwg_query($sql)); |
---|
833 | } |
---|
834 | |
---|
835 | // add an url |
---|
836 | private function add_url($datas) |
---|
837 | { |
---|
838 | $numurl=$this->get_count_url(); |
---|
839 | $sql="INSERT INTO ".$this->tables['urls']." (label, url, mode, icon, position, visible) |
---|
840 | VALUES ('".$datas['label']."', '".$datas['url']."', '".$datas['mode']."', |
---|
841 | '".$datas['icon']."', '".$numurl."', '".$datas['visible']."')"; |
---|
842 | return(pwg_query($sql)); |
---|
843 | } |
---|
844 | |
---|
845 | // modify an url |
---|
846 | private function modify_url($datas) |
---|
847 | { |
---|
848 | $sql="UPDATE ".$this->tables['urls']." SET label = '".$datas['label']."', |
---|
849 | url = '".$datas['url']."', mode = '".$datas['mode']."', icon = '".$datas['icon']."', |
---|
850 | visible = '".$datas['visible']."' |
---|
851 | WHERE id = '".$datas['id']."'"; |
---|
852 | return(pwg_query($sql)); |
---|
853 | } |
---|
854 | |
---|
855 | // just modify url visibility |
---|
856 | private function set_url_visibility($urlid, $visible) |
---|
857 | { |
---|
858 | $sql="UPDATE ".$this->tables['urls']." SET visible = '".$visible."' |
---|
859 | WHERE id = '".$urlid."'"; |
---|
860 | return(pwg_query($sql)); |
---|
861 | } |
---|
862 | |
---|
863 | |
---|
864 | |
---|
865 | /* --------------------------------------------------------------------------- |
---|
866 | functions to manage sections tables |
---|
867 | --------------------------------------------------------------------------- */ |
---|
868 | // protected function get_sections($only_visible=false, $lang="") |
---|
869 | // => defined in root class |
---|
870 | |
---|
871 | // return properties of a given section (return each languages) |
---|
872 | private function get_personalised($section_id) |
---|
873 | { |
---|
874 | $returned=array(); |
---|
875 | $sql="SELECT * FROM ".$this->tables['personalised']." WHERE id = '".$section_id."'"; |
---|
876 | $result=pwg_query($sql); |
---|
877 | if($result) |
---|
878 | { |
---|
879 | while($returned[]=pwg_db_fetch_assoc($result)); |
---|
880 | } |
---|
881 | return($returned); |
---|
882 | } |
---|
883 | |
---|
884 | // delete a section |
---|
885 | private function delete_personalised($section_id) |
---|
886 | { |
---|
887 | $sql="DELETE FROM ".$this->tables['personalised']." WHERE id = '".$section_id."' "; |
---|
888 | return(pwg_query($sql)); |
---|
889 | } |
---|
890 | |
---|
891 | // add a section |
---|
892 | private function add_personalised($datas) |
---|
893 | { |
---|
894 | $sql="INSERT INTO ".$this->tables['personalised']." (id, lang, title, content, visible, nfo) |
---|
895 | VALUES ('".$datas['id']."', '".$datas['lang']."', '".$datas['title']."', '".$datas['content']."', '".$datas['visible']."', '".$datas['nfo']."')"; |
---|
896 | return(pwg_query($sql)); |
---|
897 | } |
---|
898 | |
---|
899 | // modify a section |
---|
900 | private function modify_personalised($datas) |
---|
901 | { |
---|
902 | $sql="UPDATE ".$this->tables['personalised']." SET title = '".$datas['title']."', |
---|
903 | content = '".$datas['content']."', visible = '".$datas['visible']."', |
---|
904 | nfo = '".$datas['nfo']."' |
---|
905 | WHERE id = '".$datas['id']."' |
---|
906 | AND lang = '".$datas['lang']."'"; |
---|
907 | return(pwg_query($sql)); |
---|
908 | } |
---|
909 | |
---|
910 | // return the next personalised id |
---|
911 | private function get_personalised_id() |
---|
912 | { |
---|
913 | $sql='SELECT MAX(ID) FROM '.$this->tables['personalised']; |
---|
914 | $result=pwg_query($sql); |
---|
915 | if($result) |
---|
916 | { |
---|
917 | $row=pwg_db_fetch_row($result); |
---|
918 | if(is_array($row)) |
---|
919 | { |
---|
920 | return($row[0]+1); |
---|
921 | } |
---|
922 | } |
---|
923 | return(0); |
---|
924 | } |
---|
925 | |
---|
926 | |
---|
927 | |
---|
928 | |
---|
929 | |
---|
930 | /* --------------------------------------------------------------------------- |
---|
931 | ajax functions |
---|
932 | --------------------------------------------------------------------------- */ |
---|
933 | |
---|
934 | // return a html formatted list of urls |
---|
935 | private function ajax_amm_links_list() |
---|
936 | { |
---|
937 | global $template, $user; |
---|
938 | $local_tpl = new Template(AMM_PATH."admin/", ""); |
---|
939 | $local_tpl->set_filename('body_page', |
---|
940 | dirname($this->getFileLocation()).'/admin/amm_linkslist_detail.tpl'); |
---|
941 | |
---|
942 | $template_datas['urls']=array(); |
---|
943 | $urls=$this->get_urls(); |
---|
944 | for($i=0;$i<count($urls);$i++) |
---|
945 | { |
---|
946 | $template_datas['urls'][]=array( |
---|
947 | 'img' => AMM_PATH."links_pictures/".$urls[$i]['icon'], |
---|
948 | 'label' => $urls[$i]['label'], |
---|
949 | 'url' => $urls[$i]['url'], |
---|
950 | 'mode' => l10n("g002_mode_".$this->urls_modes[$urls[$i]['mode']]), |
---|
951 | 'up' => ($i==0)?false:true, |
---|
952 | 'down' => ($i<(count($urls)-1))?true:false, |
---|
953 | 'edit' => $this->getAdminLink().'&fAMM_tabsheet=links&action=modify&fItem='.$urls[$i]['id'], |
---|
954 | 'ID' => $urls[$i]['id'], |
---|
955 | 'IDPREV' => ($i==0)?0:$urls[$i-1]['id'], |
---|
956 | 'IDNEXT' => ($i<(count($urls)-1))?$urls[$i+1]['id']:0, |
---|
957 | 'visible' => l10n('g002_yesno_'.$urls[$i]['visible']) |
---|
958 | ); |
---|
959 | } |
---|
960 | |
---|
961 | $themeconf=array( |
---|
962 | 'icon_dir' => $template->get_themeconf('icon_dir') |
---|
963 | ); |
---|
964 | |
---|
965 | $local_tpl->assign('themeconf', $themeconf); |
---|
966 | $local_tpl->assign('datas', $template_datas); |
---|
967 | $local_tpl->assign('plugin', array('PATH' => AMM_PATH)); |
---|
968 | |
---|
969 | return($local_tpl->parse('body_page', true)); |
---|
970 | } |
---|
971 | |
---|
972 | // permut position of 2 urls and returns a html formatted list of urls |
---|
973 | private function ajax_amm_links_permut($urlid, $urlpermut) |
---|
974 | { |
---|
975 | $this->permut_url($urlid, $urlpermut); |
---|
976 | return($this->ajax_amm_links_list()); |
---|
977 | } |
---|
978 | |
---|
979 | // delete an url and returns a html formatted list of urls |
---|
980 | private function ajax_amm_links_delete($urlid) |
---|
981 | { |
---|
982 | if(!$this->adviser_abort()) |
---|
983 | { |
---|
984 | $this->delete_url($urlid); |
---|
985 | } |
---|
986 | return($this->ajax_amm_links_list()); |
---|
987 | } |
---|
988 | |
---|
989 | |
---|
990 | |
---|
991 | |
---|
992 | |
---|
993 | // return a html formatted list of personalised sections |
---|
994 | private function ajax_amm_personalised_list() |
---|
995 | { |
---|
996 | global $template, $user; |
---|
997 | $local_tpl = new Template(AMM_PATH."admin/", ""); |
---|
998 | $local_tpl->set_filename('body_page', |
---|
999 | dirname($this->getFileLocation()).'/admin/amm_personalisedlist_detail.tpl'); |
---|
1000 | |
---|
1001 | $template_datas['sections']=array(); |
---|
1002 | |
---|
1003 | $sections=$this->get_sections(false, '', false); |
---|
1004 | $is_done=array(); |
---|
1005 | foreach($sections as $key => $val) |
---|
1006 | { |
---|
1007 | if(!isset($is_done[$val['id']])) |
---|
1008 | { |
---|
1009 | $template_datas['sections'][]=array( |
---|
1010 | 'title' => ($val['title']!='')?$val['title']:l10n('g002_notitle'), |
---|
1011 | 'edit' => $this->getAdminLink().'&fAMM_tabsheet=personnalblock&action=modify&fItem='.$val['id'], |
---|
1012 | 'ID' => $val['id'], |
---|
1013 | 'visible' => l10n('g002_yesno_'.$val['visible']), |
---|
1014 | 'nfo' => $val['nfo'] |
---|
1015 | ); |
---|
1016 | $is_done[$val['id']]=''; |
---|
1017 | } |
---|
1018 | } |
---|
1019 | |
---|
1020 | $themeconf=array( |
---|
1021 | 'icon_dir' => $template->get_themeconf('icon_dir') |
---|
1022 | ); |
---|
1023 | |
---|
1024 | $local_tpl->assign('themeconf', $themeconf); |
---|
1025 | $local_tpl->assign('datas', $template_datas); |
---|
1026 | $local_tpl->assign('plugin', array('PATH' => AMM_PATH)); |
---|
1027 | |
---|
1028 | return($local_tpl->parse('body_page', true)); |
---|
1029 | } |
---|
1030 | |
---|
1031 | // delete a section and returns a html formatted list |
---|
1032 | private function ajax_amm_personalised_delete($sectionid) |
---|
1033 | { |
---|
1034 | if(!$this->adviser_abort()) |
---|
1035 | { |
---|
1036 | $this->delete_personalised($sectionid); |
---|
1037 | } |
---|
1038 | return($this->ajax_amm_personalised_list()); |
---|
1039 | } |
---|
1040 | |
---|
1041 | |
---|
1042 | } // AMM_AIP class |
---|
1043 | |
---|
1044 | |
---|
1045 | ?> |
---|