source: extensions/AMenuManager/amm_aip.class.inc.php @ 4382

Last change on this file since 4382 was 4382, checked in by grum, 14 years ago

<html><head><meta name="qrichtext" content="1" /></head><body style="font-size:9pt;font-family:Sans Serif">
<p>[AMM] allow to group and reorder menu items (mantis 1132,1133)</p>
</body></html>

  • Property svn:executable set to *
File size: 30.8 KB
Line 
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  --------------------------------------------------------------------------- */
16if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); }
17
18include_once(PHPWG_PLUGINS_PATH.'AMenuManager/amm_root.class.inc.php');
19include_once(PHPWG_ROOT_PATH.'include/block.class.php');
20include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
21include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/ajax.class.inc.php');
22include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/genericjs.class.inc.php');
23include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/translate.class.inc.php');
24
25class AMM_AIP extends AMM_root
26{
27  protected $google_translate;
28  protected $tabsheet;
29  protected $ajax;
30  protected $sectionsId=array('menu', 'special');
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.'&amp;fAMM_tabsheet=setmenu');
45    $this->tabsheet->add('links',
46                          l10n('g002_addlinks'),
47                          $this->page_link.'&amp;fAMM_tabsheet=links');
48    $this->tabsheet->add('randompict',
49                          l10n('g002_randompict'),
50                          $this->page_link.'&amp;fAMM_tabsheet=randompict');
51    $this->tabsheet->add('personnalblock',
52                          l10n('g002_personnalblock'),
53                          $this->page_link.'&amp;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.'&amp;fAMM_tabsheet=links&amp;action=create',
303      'lnk_config' => $this->page_link.'&amp;fAMM_tabsheet=links&amp;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.'&amp;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.'&amp;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        $this->my_config['amm_sections_items'][$properties[0]]['container']=$properties[1];
505        $this->my_config['amm_sections_items'][$properties[0]]['order']=$properties[2];
506        $this->my_config['amm_sections_items'][$properties[0]]['visibility']=$properties[3];
507      }
508      $this->sortSectionsItems();
509      if($this->save_config())
510      {
511        array_push($page['infos'], l10n('AMM_config_saved'));
512      }
513      else
514      {
515        array_push($page['errors'], l10n('AMM_adviser_not_authorized'));
516      }
517    }
518
519    $template->assign("sections", $this->sectionsId);
520    $template->assign("defaultValues", $this->defaultMenus);
521    $template->assign("items", $this->my_config['amm_sections_items']);
522    $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page');
523  }
524
525
526  /*
527    manage display for randompic config page
528  */
529  private function display_randompic_config_page()
530  {
531    global $template, $user;
532    $template->set_filename('body_page',
533                            dirname($this->filelocation).'/admin/amm_randompicconfig.tpl');
534
535    $template_datas=array(
536      'lnk_list' => $this->page_link.'&amp;fAMM_tabsheet=links',
537      'showname_selected' => $this->my_config['amm_randompicture_showname'],
538      'showcomment_selected' => $this->my_config['amm_randompicture_showcomment'],
539      'periodic_change' => $this->my_config['amm_randompicture_periodicchange'],
540      'height' => $this->my_config['amm_randompicture_height'],
541      'lang_selected' => $user['language'],
542      'fromlang' => substr($user['language'],0,2)
543    );
544
545    $template_datas['language_list'] = array();
546    foreach($this->my_config['amm_randompicture_title'] as $key => $val)
547    {
548      $template_datas['language_list'][] = array(
549        'LANG' => $key,
550        'MENUBARTIT' => htmlentities(base64_decode($val), ENT_QUOTES, 'UTF-8')
551      );
552    }
553
554
555
556    $lang=get_languages();
557    foreach($lang as $key => $val)
558    {
559      $template_datas['language_list_values'][] = $key;
560      $template_datas['language_list_labels'][] = $val;
561    }
562
563
564    $template_datas['yesno_values'] = array('y','n');
565    $template_datas['yesno_labels'][] = l10n('g002_yesno_y');
566    $template_datas['yesno_labels'][] = l10n('g002_yesno_n');
567
568    $template_datas['show_values'] = array('n', 'o', 'u');
569    $template_datas['show_labels'][] = l10n('g002_show_n');
570    $template_datas['show_labels'][] = l10n('g002_show_o');
571    $template_datas['show_labels'][] = l10n('g002_show_u');
572
573
574    $template->assign("datas", $template_datas);
575    $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page');
576  }
577
578
579
580
581
582
583
584  /*
585    manage display for personalised sections list page
586  */
587  private function display_personalised_list_page()
588  {
589    global $template, $user;
590    $template->set_filename('body_page',
591                            dirname($this->filelocation).'/admin/amm_personalisedlist.tpl');
592
593    $sql="SELECT COUNT(DISTINCT ID) as countid FROM ".$this->tables['personalised'];
594    $result=pwg_query($sql);
595    if($result)
596    {
597      $tmp=mysql_fetch_row($result);
598      $tmp=$tmp[0];
599    }
600    else
601    {
602      $tmp=0;
603    }
604
605    if($tmp==0)
606    {
607      $tmp=l10n("g002_nosections");
608    }
609    elseif($tmp==1)
610    {
611      $tmp="1 ".l10n("g002_section");
612    }
613    else
614    {
615      $tmp=$tmp." ".l10n("g002_sections");
616    }
617
618
619    $template_datas=array(
620      'lnk_create' => $this->page_link.'&amp;fAMM_tabsheet=personnalblock&amp;action=create',
621      'AMM_AJAX_URL_LIST' => $this->page_link."&ajaxfct=",
622      'nbsections' => $tmp
623    );
624
625    $template->assign("datas", $template_datas);
626    $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page');
627  }
628
629
630
631  /*
632    manage display for personalised sections create/modify page
633  */
634  private function display_personalised_manage_page($modeedit = 'create', $sectionid=0)
635  {
636    global $template, $user;
637    $template->set_filename('body_page',
638                            dirname($this->filelocation).'/admin/amm_personalisedlist_edit.tpl');
639
640    $template_datas=array();
641
642    $lang=get_languages();
643    $lang['all']=l10n('g002_all_languages');
644    foreach($lang as $key => $val)
645    {
646      $template_datas['language_list_values'][] = $key;
647      $template_datas['language_list_labels'][] = $val;
648      $template_datas['language_list'][$key]=array(
649        'LANG' => $key,
650        'MENUBARTIT' => '',
651        'MENUBARCONTENT' => ''
652      );
653    }
654
655
656    if($modeedit=='modify')
657    {
658      $sections=$this->get_personalised($sectionid);
659
660      $template_datas['id'] = $sectionid;
661      $template_datas['modeedit'] = 'modify';
662      $template_datas['visible_selected'] = $sections[0]['visible'];
663      $template_datas['nfo'] = htmlentities($sections[0]['nfo'], ENT_QUOTES, 'UTF-8');
664
665      foreach($sections as $key => $val)
666      {
667        $lang=($val['lang']=='*')?'all':$val['lang'];
668        $template_datas['language_list'][$lang] = array(
669          'LANG' => $lang,
670          'MENUBARTIT' => htmlentities($val['title'], ENT_QUOTES, 'UTF-8'),
671          'MENUBARCONTENT' => htmlentities($val['content'], ENT_QUOTES, 'UTF-8'),
672        );
673      }
674    }
675    else
676    {
677      $template_datas['nfo'] = '';
678      $template_datas['id'] = '';
679      $template_datas['modeedit'] = 'create';
680      $template_datas['visible_selected'] = 'y';
681    }
682
683    $template_datas['lang_selected'] = $user['language'];
684
685    $template_datas['personalised_list'] = $this->page_link.'&amp;fAMM_tabsheet=personnalblock';
686    $template_datas['yesno_values'] = array('y','n');
687    $template_datas['yesno_labels'][] = l10n('g002_yesno_y');
688    $template_datas['yesno_labels'][] = l10n('g002_yesno_n');
689
690    $template->assign("datas", $template_datas);
691    $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page');
692  }
693
694  /*
695    manage create/modify pesonalised sections into database and display result
696  */
697  protected function action_create_modify_personalised()
698  {
699    global $user;
700
701    if($_POST['famm_modeedit']=='create')
702    {
703      $id=$this->get_personalised_id();
704    }
705    else
706    {
707      $id=$_POST['famm_id'];
708    }
709    $languages=get_languages();
710    $languages['all']='*';
711    foreach($languages as $key => $val)
712    {
713      $datas=array(
714        'id' => $id,
715        'lang' => ($key=='all')?'*':$key,
716        'visible' => $_POST['famm_personalised_visible'],
717        'nfo' => ($_POST['famm_personalised_nfo']=='')?$_POST['famm_personalised_title_'.$user['language']]:$_POST['famm_personalised_nfo'],
718        'title' => $_POST['famm_personalised_title_'.$key],
719        'content' => $_POST['famm_personalised_content_'.$key]
720      );
721      switch($_POST['famm_modeedit'])
722      {
723        case 'create':
724          $this->add_personalised($datas);
725          break;
726        case 'modify':
727          $this->modify_personalised($datas);
728      }
729    }
730  }
731
732
733
734
735
736  /*
737    manage adviser profile
738      return true if user is adviser
739  */
740  protected function adviser_abort()
741  {
742    if(is_adviser())
743    {
744      $this->display_result(l10n("g002_adviser_not_allowed"), false);
745      return(true);
746    }
747    return(false);
748  }
749
750  /* ---------------------------------------------------------------------------
751    functions to manage urls tables
752  --------------------------------------------------------------------------- */
753  // protected function get_urls()
754  // protected function get_count_url()
755  // => defined in root class
756
757  // return properties of an given url
758  private function get_url($url_id)
759  {
760    $returned=array();
761    $sql="SELECT * FROM ".$this->tables['urls']." WHERE id = '".$url_id."'";
762    $result=pwg_query($sql);
763    if($result)
764    {
765      $returned=mysql_fetch_array($result);
766      //$returned['label']=stripslashes($returned['label']);
767    }
768    return($returned);
769  }
770
771  // permut position of two 2 urls
772  private function permut_url($url_id, $url_permut)
773  {
774    $sql="SELECT id, position FROM ".$this->tables['urls']." WHERE id IN ('".$url_id."','".$url_permut."')";
775    $result=pwg_query($sql);
776    if($result)
777    {
778      $tmp=array();
779      while($row=mysql_fetch_array($result))
780      {
781        $tmp[$row['id']]=$row['position'];
782      }
783      $sql="UPDATE ".$this->tables['urls']." SET position = ".$tmp[$url_id]." WHERE id = '".$url_permut."'";
784      pwg_query($sql);
785      $sql="UPDATE ".$this->tables['urls']." SET position = ".$tmp[$url_permut]." WHERE id = '".$url_id."'";
786      pwg_query($sql);
787    }
788  }
789
790  // delete an url
791  private function delete_url($url_id)
792  {
793    $sql="DELETE FROM ".$this->tables['urls']." WHERE id = '".$url_id."' ";
794    return(pwg_query($sql));
795  }
796
797  // add an url
798  private function add_url($datas)
799  {
800    $numurl=$this->get_count_url();
801    $sql="INSERT INTO ".$this->tables['urls']." (label, url, mode, icon, position, visible)
802          VALUES ('".$datas['label']."', '".$datas['url']."', '".$datas['mode']."',
803                  '".$datas['icon']."', '".$numurl."', '".$datas['visible']."')";
804    return(pwg_query($sql));
805  }
806
807  // modify an url
808  private function modify_url($datas)
809  {
810    $sql="UPDATE ".$this->tables['urls']." SET label = '".$datas['label']."',
811          url = '".$datas['url']."', mode = '".$datas['mode']."', icon = '".$datas['icon']."',
812          visible = '".$datas['visible']."'
813          WHERE id = '".$datas['id']."'";
814    return(pwg_query($sql));
815  }
816
817  // just modify url visibility
818  private function set_url_visibility($urlid, $visible)
819  {
820    $sql="UPDATE ".$this->tables['urls']." SET visible = '".$visible."'
821          WHERE id = '".$urlid."'";
822    return(pwg_query($sql));
823  }
824
825  /* ---------------------------------------------------------------------------
826    functions to manage sections tables
827  --------------------------------------------------------------------------- */
828  // protected function get_sections($only_visible=false, $lang="")
829  // => defined in root class
830
831  // return properties of a given section (return each languages)
832  private function get_personalised($section_id)
833  {
834    $returned=array();
835    $sql="SELECT * FROM ".$this->tables['personalised']." WHERE id = '".$section_id."'";
836    $result=pwg_query($sql);
837    if($result)
838    {
839      while($returned[]=mysql_fetch_array($result));
840    }
841    return($returned);
842  }
843
844  // delete a section
845  private function delete_personalised($section_id)
846  {
847    $sql="DELETE FROM ".$this->tables['personalised']." WHERE id = '".$section_id."' ";
848    return(pwg_query($sql));
849  }
850
851  // add a section
852  private function add_personalised($datas)
853  {
854    $sql="INSERT INTO ".$this->tables['personalised']." (id, lang, title, content, visible, nfo)
855          VALUES ('".$datas['id']."', '".$datas['lang']."', '".$datas['title']."', '".$datas['content']."', '".$datas['visible']."', '".$datas['nfo']."')";
856    return(pwg_query($sql));
857  }
858
859  // modify a section
860  private function modify_personalised($datas)
861  {
862    $sql="UPDATE ".$this->tables['personalised']." SET title = '".$datas['title']."',
863          content = '".$datas['content']."',  visible = '".$datas['visible']."',
864          nfo = '".$datas['nfo']."'
865          WHERE id = '".$datas['id']."'
866          AND lang = '".$datas['lang']."'";
867    return(pwg_query($sql));
868  }
869
870  // return the next personalised id
871  private function get_personalised_id()
872  {
873    $sql='SELECT MAX(ID) FROM '.$this->tables['personalised'];
874    $result=pwg_query($sql);
875    if($result)
876    {
877      $row=mysql_fetch_row($result);
878      if(is_array($row))
879      {
880        return($row[0]+1);
881      }
882    }
883    return(0);
884  }
885
886
887  /* ---------------------------------------------------------------------------
888    ajax functions
889  --------------------------------------------------------------------------- */
890
891  // return a html formatted list of urls
892  private function ajax_amm_links_list()
893  {
894    global $template, $user;
895    $local_tpl = new Template(AMM_PATH."admin/", "");
896    $local_tpl->set_filename('body_page',
897                  dirname($this->filelocation).'/admin/amm_linkslist_detail.tpl');
898
899    $template_datas['urls']=array();
900    $urls=$this->get_urls();
901    for($i=0;$i<count($urls);$i++)
902    {
903      $template_datas['urls'][]=array(
904        'img' => AMM_PATH."links_pictures/".$urls[$i]['icon'],
905        'label' => $urls[$i]['label'],
906        'url' => $urls[$i]['url'],
907        'mode' => l10n("g002_mode_".$this->urls_modes[$urls[$i]['mode']]),
908        'up' =>  ($i==0)?false:true,
909        'down' =>  ($i<(count($urls)-1))?true:false,
910        'edit' => $this->page_link.'&amp;fAMM_tabsheet=links&amp;action=modify&amp;fItem='.$urls[$i]['id'],
911        'ID' => $urls[$i]['id'],
912        'IDPREV' => ($i==0)?0:$urls[$i-1]['id'],
913        'IDNEXT' => ($i<(count($urls)-1))?$urls[$i+1]['id']:0,
914        'visible' => l10n('g002_yesno_'.$urls[$i]['visible'])
915      );
916    }
917
918    $themeconf=array(
919      'icon_dir' => $template->get_themeconf('icon_dir')
920    );
921
922    $local_tpl->assign('themeconf', $themeconf);
923    $local_tpl->assign('datas', $template_datas);
924    $local_tpl->assign('plugin', array('PATH' => AMM_PATH));
925
926    return($local_tpl->parse('body_page', true));
927  }
928
929  // permut position of 2 urls and returns a html formatted list of urls
930  private function ajax_amm_links_permut($urlid, $urlpermut)
931  {
932    $this->permut_url($urlid, $urlpermut);
933    return($this->ajax_amm_links_list());
934  }
935
936  // delete an url and returns a html formatted list of urls
937  private function ajax_amm_links_delete($urlid)
938  {
939    if(!$this->adviser_abort())
940    {
941      $this->delete_url($urlid);
942    }
943    return($this->ajax_amm_links_list());
944  }
945
946
947
948
949
950  // return a html formatted list of personalised sections
951  private function ajax_amm_personalised_list()
952  {
953    global $template, $user;
954    $local_tpl = new Template(AMM_PATH."admin/", "");
955    $local_tpl->set_filename('body_page',
956                  dirname($this->filelocation).'/admin/amm_personalisedlist_detail.tpl');
957
958    $template_datas['sections']=array();
959
960    $sections=$this->get_sections(false, '', false);
961    $is_done=array();
962    foreach($sections as $key => $val)
963    {
964      if(!isset($is_done[$val['id']]))
965      {
966        $template_datas['sections'][]=array(
967          'title' => ($val['title']!='')?$val['title']:l10n('g002_notitle'),
968          'edit' => $this->page_link.'&amp;fAMM_tabsheet=personnalblock&amp;action=modify&amp;fItem='.$val['id'],
969          'ID' => $val['id'],
970          'visible' => l10n('g002_yesno_'.$val['visible']),
971          'nfo' => $val['nfo']
972        );
973        $is_done[$val['id']]='';
974      }
975    }
976
977    $themeconf=array(
978      'icon_dir' => $template->get_themeconf('icon_dir')
979    );
980
981    $local_tpl->assign('themeconf', $themeconf);
982    $local_tpl->assign('datas', $template_datas);
983    $local_tpl->assign('plugin', array('PATH' => AMM_PATH));
984
985    return($local_tpl->parse('body_page', true));
986  }
987
988  // delete a section and returns a html formatted list
989  private function ajax_amm_personalised_delete($sectionid)
990  {
991    if(!$this->adviser_abort())
992    {
993      $this->delete_personalised($sectionid);
994    }
995    return($this->ajax_amm_personalised_list());
996  }
997
998
999
1000/*
1001 *
1002  // return a html formatted list of special menu sections items
1003  private function ajax_amm_setmenu_mod_section_list($menuname)
1004  {
1005
1006
1007
1008    $local_tpl = new Template(AMM_PATH."admin/", "");
1009    $local_tpl->set_filename('body_page',
1010                  dirname($this->filelocation).'/admin/amm_sectionsmod_detail.tpl');
1011
1012    $template_datas = array('LIST' => array());
1013    foreach($this->my_config[$menuname] as $key => $val)
1014    {
1015      $template_datas['LIST'][] = array(
1016        'ID' => base64_encode($key),
1017        'LABEL' => $labels[$menuname][$key],
1018        'VISIBLE' => 'g002_yesno_'.$val
1019      );
1020    }
1021
1022    $local_tpl->assign('datas', $template_datas);
1023    $local_tpl->assign('plugin', array('PATH' => AMM_PATH));
1024
1025    return($local_tpl->parse('body_page', true));
1026  }
1027
1028
1029  // move item to the specified position
1030  private function ajax_amm_setmenu_mod_section_showhide($menuname, $urlid)
1031  {
1032    $switchvisible=array('y'=>'n', 'n'=>'y');
1033
1034    $this->my_config[$menuname][base64_decode($urlid)]=$switchvisible[$this->my_config[$menuname][base64_decode($urlid)]];
1035    $this->save_config();
1036
1037    return($this->ajax_amm_setmenu_mod_section_list($menuname));
1038  }
1039  * */
1040
1041
1042} // AMM_AIP class
1043
1044
1045?>
Note: See TracBrowser for help on using the repository browser.