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' => 'title_menu', 'special' => 'special_categories'); |
---|
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 | $users=new users(""); |
---|
527 | $groups=new groups(""); |
---|
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->my_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->filelocation).'/admin/amm_randompicconfig.tpl'); |
---|
546 | |
---|
547 | $template_datas=array( |
---|
548 | 'lnk_list' => $this->page_link.'&fAMM_tabsheet=links', |
---|
549 | 'showname_selected' => $this->my_config['amm_randompicture_showname'], |
---|
550 | 'showcomment_selected' => $this->my_config['amm_randompicture_showcomment'], |
---|
551 | 'periodic_change' => $this->my_config['amm_randompicture_periodicchange'], |
---|
552 | 'height' => $this->my_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->my_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->filelocation).'/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=mysql_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->page_link.'&fAMM_tabsheet=personnalblock&action=create', |
---|
633 | 'AMM_AJAX_URL_LIST' => $this->page_link."&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->filelocation).'/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->page_link.'&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->filelocation).'/admin/amm_sections_visibility.tpl'); |
---|
755 | |
---|
756 | |
---|
757 | $parameters=explode("/", $visibility); |
---|
758 | |
---|
759 | $users=new users(str_replace(",", "/", $parameters[0])); |
---|
760 | $users->set_allowed('admin', true); |
---|
761 | $groups=new groups(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->display_result(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=mysql_fetch_array($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=mysql_fetch_array($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[]=mysql_fetch_array($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=mysql_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->filelocation).'/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->page_link.'&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->filelocation).'/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->page_link.'&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 | ?> |
---|