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