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

Last change on this file since 3683 was 3681, checked in by grum, 15 years ago

Add plugin Advanced Menu Manager 2.1.0

  • Property svn:executable set to *
File size: 30.9 KB
Line 
1<?php
2/* -----------------------------------------------------------------------------
3  Plugin     : Advanced Menu Manager
4  Author     : Grum
5    email    : grum@grum.dnsalias.com
6    website  : http://photos.grum.dnsalias.com
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.'admin/include/tabsheet.class.php');
20include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/ajax.class.inc.php');
21include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/genericjs.class.inc.php');
22include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/translate.class.inc.php');
23
24class AMM_AIP extends AMM_root
25{
26  protected $google_translate;
27  protected $tabsheet;
28  protected $ajax;
29
30  protected $urls_modes=array(0 => 'new_window', 1 => 'current_window');
31
32  function AMM_AIP($prefixeTable, $filelocation)
33  {
34    parent::__construct($prefixeTable, $filelocation);
35
36    $this->load_config();
37    $this->init_events();
38
39    $this->tabsheet = new tabsheet();
40    $this->tabsheet->add('setmenu',
41                          l10n('g002_setmenu'),
42                          $this->page_link.'&amp;fAMM_tabsheet=setmenu');
43    $this->tabsheet->add('links',
44                          l10n('g002_addlinks'),
45                          $this->page_link.'&amp;fAMM_tabsheet=links');
46    $this->tabsheet->add('randompict',
47                          l10n('g002_randompict'),
48                          $this->page_link.'&amp;fAMM_tabsheet=randompict');
49    $this->tabsheet->add('personnalblock',
50                          l10n('g002_personnalblock'),
51                          $this->page_link.'&amp;fAMM_tabsheet=personnalblock');
52    $this->css = new css(dirname($this->filelocation).'/'.$this->plugin_name_files.".css");
53    $this->ajax = new Ajax();
54    $this->google_translate = new translate();
55  }
56
57
58  /* ---------------------------------------------------------------------------
59  Public classe functions
60  --------------------------------------------------------------------------- */
61
62  /*
63    manage plugin integration into piwigo's admin interface
64  */
65  public function manage()
66  {
67    global $template;
68
69global $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_list_page($_REQUEST['action']);
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        case 'setmenu_modmenu_sections_list':
224          $result=$this->ajax_amm_setmenu_mod_section_list('amm_sections_modmenu');
225          break;
226        case 'setmenu_modmenu_sections_showhide':
227          $result=$this->ajax_amm_setmenu_mod_section_showhide('amm_sections_modmenu', $_REQUEST['fItem']);
228          break;
229
230        case 'setmenu_modspecial_sections_list':
231          $result=$this->ajax_amm_setmenu_mod_section_list('amm_sections_modspecials');
232          break;
233        case 'setmenu_modspecial_sections_showhide':
234          $result=$this->ajax_amm_setmenu_mod_section_showhide('amm_sections_modspecials', $_REQUEST['fItem']);
235          break;
236
237        case 'personalised_list':
238          $result=$this->ajax_amm_personalised_list();
239          break;
240        case 'personalised_delete':
241          $result=$this->ajax_amm_personalised_delete($_REQUEST['fItem']);
242          break;
243      }
244      //$template->
245      $this->ajax->return_result($result);
246    }
247  }
248
249  /*
250    if empty, initialize $_request
251  */
252  private function init_request()
253  {
254    //initialise $REQUEST values if not defined
255    if(!array_key_exists('fAMM_tabsheet', $_REQUEST))
256    {
257      $_REQUEST['fAMM_tabsheet']='setmenu';
258    }
259
260    if((($_REQUEST['fAMM_tabsheet']=='links') or
261        ($_REQUEST['fAMM_tabsheet']=='personnalblock')) and !isset($_REQUEST['action']))
262    {
263      $_REQUEST['action']='list';
264    }
265    elseif((($_REQUEST['fAMM_tabsheet']=='setmenu')) and !isset($_REQUEST['action']))
266    {
267      $_REQUEST['action']='modmenu';
268    }
269
270
271
272  } //init_request
273
274
275  /*
276    manage display for urls table page
277  */
278  private function display_links_list_page()
279  {
280    global $template, $user;
281    $template->set_filename('body_page',
282                            dirname($this->filelocation).'/admin/amm_linkslist.tpl');
283
284    $tmp=$this->get_count_url();
285    if($tmp==0)
286    {
287      $tmp=l10n("g002_nolinks");
288    }
289    elseif($tmp==1)
290    {
291      $tmp="1 ".l10n("g002_link");
292    }
293    else
294    {
295      $tmp=$tmp." ".l10n("g002_links");
296    }
297
298
299    $template_datas=array(
300      'lnk_create' => $this->page_link.'&amp;fAMM_tabsheet=links&amp;action=create',
301      'lnk_config' => $this->page_link.'&amp;fAMM_tabsheet=links&amp;action=config',
302      'AMM_AJAX_URL_LIST' => $this->page_link."&ajaxfct=",
303      'nburl' => $tmp
304    );
305
306    $template->assign("datas", $template_datas);
307    $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page');
308  }
309
310  /*
311    manage display for urls config page
312  */
313  private function display_links_config_page()
314  {
315    global $template, $user;
316    $template->set_filename('body_page',
317                            dirname($this->filelocation).'/admin/amm_linksconfig.tpl');
318
319    $template_datas=array(
320      'lnk_list' => $this->page_link.'&amp;fAMM_tabsheet=links',
321      'AMM_AJAX_URL_LIST' => $this->page_link."&ajaxfct=",
322      'show_icons_selected' => $this->my_config['amm_links_show_icons'],
323      'lang_selected' => $user['language'],
324      'fromlang' => substr($user['language'],0,2)
325    );
326
327    $template_datas['language_list'] = array();
328    foreach($this->my_config['amm_links_title'] as $key => $val)
329    {
330      $template_datas['language_list'][] = array(
331        'LANG' => $key,
332        'MENUBARTIT' => base64_decode($val)
333      );
334    }
335
336
337
338    $lang=get_languages();
339    foreach($lang as $key => $val)
340    {
341      $template_datas['language_list_values'][] = $key;
342      $template_datas['language_list_labels'][] = $val;
343    }
344
345
346    $template_datas['yesno_values'] = array('y','n');
347    $template_datas['yesno_labels'][] = l10n('g002_yesno_y');
348    $template_datas['yesno_labels'][] = l10n('g002_yesno_n');
349
350
351    $template->assign("datas", $template_datas);
352    $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page');
353  }
354
355  /*
356    manage display for urls create/modify page
357  */
358  private function display_links_manage_page($modeedit = 'create', $urlid=0)
359  {
360    global $template, $user;
361    $template->set_filename('body_page',
362                            dirname($this->filelocation).'/admin/amm_linkslist_edit.tpl');
363
364    $extensions_list=array('jpg'=>0,'jpeg'=>0,'gif'=>0,'png'=>0);
365    $template_icons_list=array();
366    $directory=dir(dirname($this->filelocation).'/links_pictures/');
367    while($file=$directory->read())
368    {
369      if(isset($extensions_list[get_extension(strtolower($file))]))
370      {
371        $template_icons_list[]=$file;
372      }
373    }
374
375
376    if($modeedit=='modify')
377    {
378      $url=$this->get_url($urlid);
379
380      $template_datas=array(
381        'id' => $urlid,
382        'modeedit' => 'modify',
383        'label' => htmlentities($url['label'], ENT_QUOTES, 'UTF-8'),
384        'url' => $url['url'],
385        'icons_selected' => $url['icon'],
386        'mode_selected' => $url['mode'],
387        'visible_selected' => $url['visible']
388      );
389    }
390    else
391    {
392      $template_datas=array(
393        'id' => '',
394        'modeedit' => 'create',
395        'label' => '',
396        'url' => '',
397        'icons_selected' => $template_icons_list[0],
398        'mode_selected' => 0,
399        'visible_selected' => 'y'
400      );
401    }
402
403    $template_datas['lnk_list'] = $this->page_link.'&amp;fAMM_tabsheet=links';
404    $template_datas['icons_img'] = AMM_PATH."links_pictures/".$template_datas['icons_selected'];
405    $template_datas['icons_values'] = array();
406    foreach($template_icons_list as $key => $val)
407    {
408      $template_datas['icons_values'][] = array(
409        'img' => AMM_PATH."links_pictures/".$val,
410        'value' => $val,
411        'label' => $val
412      );
413    }
414    $template_datas['mode_values'] = array(0,1);
415    $template_datas['mode_labels'][] = l10n("g002_mode_".$this->urls_modes[0]);
416    $template_datas['mode_labels'][] = l10n("g002_mode_".$this->urls_modes[1]);
417    $template_datas['visible_values'] = array('y','n');
418    $template_datas['visible_labels'][] = l10n('g002_yesno_y');
419    $template_datas['visible_labels'][] = l10n('g002_yesno_n');
420
421    $template->assign("datas", $template_datas);
422    $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page');
423  }
424
425  /*
426    manage create/modify url into database and display result
427  */
428  protected function action_create_modify_url()
429  {
430    $datas=array(
431      'id' => $_POST['famm_id'],
432      'label' => $_POST['famm_label'],
433      'url' => $_POST['famm_url'],
434      'mode' => $_POST['famm_mode'],
435      'icon' => $_POST['famm_icon'],
436      'position' => 0,
437      'visible' => $_POST['famm_visible']
438    );
439
440    switch($_POST['famm_modeedit'])
441    {
442      case 'create':
443        $this->add_url($datas);
444        break;
445      case 'modify':
446        $this->modify_url($datas);
447    }
448  }
449
450  /*
451    manage urls config save into database
452  */
453  protected function action_links_modify_config()
454  {
455    $this->my_config['amm_links_show_icons']=$_POST['famm_links_show_icons'];
456    $languages=get_languages();
457    foreach($languages as $key => $val)
458    {
459      $this->my_config['amm_links_title'][$key]=base64_encode($_POST['famm_links_title_'.$key]);
460    }
461    $this->save_config();
462  }
463
464  /*
465    manage randompic config save into database
466  */
467  protected function action_randompic_modify_config()
468  {
469    $this->my_config['amm_randompicture_periodicchange']=$_POST['famm_randompicture_periodicchange'];
470    $this->my_config['amm_randompicture_showname']=$_POST['famm_randompicture_showname'];
471    $this->my_config['amm_randompicture_showcomment']=$_POST['famm_randompicture_showcomment'];
472    $languages=get_languages();
473    foreach($languages as $key => $val)
474    {
475      $this->my_config['amm_randompicture_title'][$key]=base64_encode(stripslashes($_POST['famm_randompicture_title_'.$key]));
476    }
477    $this->save_config();
478  }
479
480
481
482  /*
483    manage display for sections table page
484  */
485  private function display_sections_list_page($action)
486  {
487    global $template, $user;
488    $template->set_filename('body_page',
489                            dirname($this->filelocation).'/admin/amm_sections.tpl');
490
491    switch($action)
492    {
493      case 'modmenu':
494        $tmp_list=array(
495          array('separator' => '', 'link' => '', 'label' => 'g002_modmenu'),
496          array('separator' => ' / ', 'link' => $this->page_link.'&amp;fAMM_tabsheet=setmenu&amp;action=modspecial', 'label' => 'g002_modspecial')
497        );
498        break;
499      case 'modspecial':
500        $tmp_list=array(
501          array('separator' => '', 'link' => $this->page_link.'&amp;fAMM_tabsheet=setmenu&amp;action=modmenu', 'label' => 'g002_modmenu'),
502          array('separator' => ' / ', 'link' => '', 'label' => 'g002_modspecial')
503        );
504        break;
505    }
506
507    $template_datas=array(
508      'AMM_AJAX_URL_LIST' => $this->page_link."&ajaxfct=setmenu_".$action."_",
509      'LIST' => $tmp_list
510    );
511
512    $template->assign("datas", $template_datas);
513    $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page');
514  }
515
516
517  /*
518    manage display for randompic config page
519  */
520  private function display_randompic_config_page()
521  {
522    global $template, $user;
523    $template->set_filename('body_page',
524                            dirname($this->filelocation).'/admin/amm_randompicconfig.tpl');
525
526    $template_datas=array(
527      'lnk_list' => $this->page_link.'&amp;fAMM_tabsheet=links',
528      'showname_selected' => $this->my_config['amm_randompicture_showname'],
529      'showcomment_selected' => $this->my_config['amm_randompicture_showcomment'],
530      'periodic_change' => $this->my_config['amm_randompicture_periodicchange'],
531      'lang_selected' => $user['language'],
532      'fromlang' => substr($user['language'],0,2)
533    );
534
535    $template_datas['language_list'] = array();
536    foreach($this->my_config['amm_randompicture_title'] as $key => $val)
537    {
538      $template_datas['language_list'][] = array(
539        'LANG' => $key,
540        'MENUBARTIT' => htmlentities(base64_decode($val), ENT_QUOTES, 'UTF-8')
541      );
542    }
543
544
545
546    $lang=get_languages();
547    foreach($lang as $key => $val)
548    {
549      $template_datas['language_list_values'][] = $key;
550      $template_datas['language_list_labels'][] = $val;
551    }
552
553
554    $template_datas['yesno_values'] = array('y','n');
555    $template_datas['yesno_labels'][] = l10n('g002_yesno_y');
556    $template_datas['yesno_labels'][] = l10n('g002_yesno_n');
557
558    $template_datas['show_values'] = array('n', 'o', 'u');
559    $template_datas['show_labels'][] = l10n('g002_show_n');
560    $template_datas['show_labels'][] = l10n('g002_show_o');
561    $template_datas['show_labels'][] = l10n('g002_show_u');
562
563
564    $template->assign("datas", $template_datas);
565    $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page');
566  }
567
568
569
570
571
572
573
574  /*
575    manage display for personalised sections list page
576  */
577  private function display_personalised_list_page()
578  {
579    global $template, $user;
580    $template->set_filename('body_page',
581                            dirname($this->filelocation).'/admin/amm_personalisedlist.tpl');
582
583    $sql="SELECT COUNT(DISTINCT ID) as countid FROM ".$this->tables['personalised'];
584    $result=pwg_query($sql);
585    if($result)
586    {
587      $tmp=mysql_fetch_row($result);
588      $tmp=$tmp[0];
589    }
590    else
591    {
592      $tmp=0;
593    }
594
595    if($tmp==0)
596    {
597      $tmp=l10n("g002_nosections");
598    }
599    elseif($tmp==1)
600    {
601      $tmp="1 ".l10n("g002_section");
602    }
603    else
604    {
605      $tmp=$tmp." ".l10n("g002_sections");
606    }
607
608
609    $template_datas=array(
610      'lnk_create' => $this->page_link.'&amp;fAMM_tabsheet=personnalblock&amp;action=create',
611      'AMM_AJAX_URL_LIST' => $this->page_link."&ajaxfct=",
612      'nbsections' => $tmp
613    );
614
615    $template->assign("datas", $template_datas);
616    $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page');
617  }
618
619
620
621  /*
622    manage display for personalised sections create/modify page
623  */
624  private function display_personalised_manage_page($modeedit = 'create', $sectionid=0)
625  {
626    global $template, $user;
627    $template->set_filename('body_page',
628                            dirname($this->filelocation).'/admin/amm_personalisedlist_edit.tpl');
629
630    $template_datas=array();
631
632    $lang=get_languages();
633    $lang['all']=l10n('g002_all_languages');
634    foreach($lang as $key => $val)
635    {
636      $template_datas['language_list_values'][] = $key;
637      $template_datas['language_list_labels'][] = $val;
638      $template_datas['language_list'][$key]=array(
639        'LANG' => $key,
640        'MENUBARTIT' => '',
641        'MENUBARCONTENT' => ''
642      );
643    }
644
645
646    if($modeedit=='modify')
647    {
648      $sections=$this->get_personalised($sectionid);
649
650      $template_datas['id'] = $sectionid;
651      $template_datas['modeedit'] = 'modify';
652      $template_datas['visible_selected'] = $sections[0]['visible'];
653      $template_datas['nfo'] = htmlentities($sections[0]['nfo'], ENT_QUOTES, 'UTF-8');
654
655      foreach($sections as $key => $val)
656      {
657        $lang=($val['lang']=='*')?'all':$val['lang'];
658        $template_datas['language_list'][$lang] = array(
659          'LANG' => $lang,
660          'MENUBARTIT' => htmlentities($val['title'], ENT_QUOTES, 'UTF-8'),
661          'MENUBARCONTENT' => htmlentities($val['content'], ENT_QUOTES, 'UTF-8'),
662        );
663      }
664    }
665    else
666    {
667      $template_datas['nfo'] = '';
668      $template_datas['id'] = '';
669      $template_datas['modeedit'] = 'create';
670      $template_datas['visible_selected'] = 'y';
671    }
672
673    $template_datas['lang_selected'] = $user['language'];
674
675    $template_datas['personalised_list'] = $this->page_link.'&amp;fAMM_tabsheet=personnalblock';
676    $template_datas['yesno_values'] = array('y','n');
677    $template_datas['yesno_labels'][] = l10n('g002_yesno_y');
678    $template_datas['yesno_labels'][] = l10n('g002_yesno_n');
679
680    $template->assign("datas", $template_datas);
681    $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page');
682  }
683
684  /*
685    manage create/modify pesonalised sections into database and display result
686  */
687  protected function action_create_modify_personalised()
688  {
689    global $user;
690
691    if($_POST['famm_modeedit']=='create')
692    {
693      $id=$this->get_personalised_id();
694    }
695    else
696    {
697      $id=$_POST['famm_id'];
698    }
699    $languages=get_languages();
700    $languages['all']='*';
701    foreach($languages as $key => $val)
702    {
703      $datas=array(
704        'id' => $id,
705        'lang' => ($key=='all')?'*':$key,
706        'visible' => $_POST['famm_personalised_visible'],
707        'nfo' => ($_POST['famm_personalised_nfo']=='')?$_POST['famm_personalised_title_'.$user['language']]:$_POST['famm_personalised_nfo'],
708        'title' => $_POST['famm_personalised_title_'.$key],
709        'content' => $_POST['famm_personalised_content_'.$key]
710      );
711      switch($_POST['famm_modeedit'])
712      {
713        case 'create':
714          $this->add_personalised($datas);
715          break;
716        case 'modify':
717          $this->modify_personalised($datas);
718      }
719    }
720  }
721
722
723
724
725
726  /*
727    manage adviser profile
728      return true if user is adviser
729  */
730  protected function adviser_abort()
731  {
732    if(is_adviser())
733    {
734      $this->display_result(l10n("g002_adviser_not_allowed"), false);
735      return(true);
736    }
737    return(false);
738  }
739
740  /* ---------------------------------------------------------------------------
741    functions to manage urls tables
742  --------------------------------------------------------------------------- */
743  // protected function get_urls()
744  // protected function get_count_url()
745  // => defined in root class
746
747  // return properties of an given url
748  private function get_url($url_id)
749  {
750    $returned=array();
751    $sql="SELECT * FROM ".$this->tables['urls']." WHERE id = '".$url_id."'";
752    $result=pwg_query($sql);
753    if($result)
754    {
755      $returned=mysql_fetch_array($result);
756      //$returned['label']=stripslashes($returned['label']);
757    }
758    return($returned);
759  }
760
761  // permut position of two 2 urls
762  private function permut_url($url_id, $url_permut)
763  {
764    $sql="SELECT id, position FROM ".$this->tables['urls']." WHERE id IN ('".$url_id."','".$url_permut."')";
765    $result=pwg_query($sql);
766    if($result)
767    {
768      $tmp=array();
769      while($row=mysql_fetch_array($result))
770      {
771        $tmp[$row['id']]=$row['position'];
772      }
773      $sql="UPDATE ".$this->tables['urls']." SET position = ".$tmp[$url_id]." WHERE id = '".$url_permut."'";
774      pwg_query($sql);
775      $sql="UPDATE ".$this->tables['urls']." SET position = ".$tmp[$url_permut]." WHERE id = '".$url_id."'";
776      pwg_query($sql);
777    }
778  }
779
780  // delete an url
781  private function delete_url($url_id)
782  {
783    $sql="DELETE FROM ".$this->tables['urls']." WHERE id = '".$url_id."' ";
784    return(pwg_query($sql));
785  }
786
787  // add an url
788  private function add_url($datas)
789  {
790    $numurl=$this->get_count_url();
791    $sql="INSERT INTO ".$this->tables['urls']." (label, url, mode, icon, position, visible)
792          VALUES ('".$datas['label']."', '".$datas['url']."', '".$datas['mode']."',
793                  '".$datas['icon']."', '".$numurl."', '".$datas['visible']."')";
794    return(pwg_query($sql));
795  }
796
797  // modify an url
798  private function modify_url($datas)
799  {
800    $sql="UPDATE ".$this->tables['urls']." SET label = '".$datas['label']."',
801          url = '".$datas['url']."', mode = '".$datas['mode']."', icon = '".$datas['icon']."',
802          visible = '".$datas['visible']."'
803          WHERE id = '".$datas['id']."'";
804    return(pwg_query($sql));
805  }
806
807  // just modify url visibility
808  private function set_url_visibility($urlid, $visible)
809  {
810    $sql="UPDATE ".$this->tables['urls']." SET visible = '".$visible."'
811          WHERE id = '".$urlid."'";
812    return(pwg_query($sql));
813  }
814
815  /* ---------------------------------------------------------------------------
816    functions to manage sections tables
817  --------------------------------------------------------------------------- */
818  // protected function get_sections($only_visible=false, $lang="")
819  // => defined in root class
820
821  // return properties of a given section (return each languages)
822  private function get_personalised($section_id)
823  {
824    $returned=array();
825    $sql="SELECT * FROM ".$this->tables['personalised']." WHERE id = '".$section_id."'";
826    $result=pwg_query($sql);
827    if($result)
828    {
829      while($returned[]=mysql_fetch_array($result));
830    }
831    return($returned);
832  }
833
834  // delete a section
835  private function delete_personalised($section_id)
836  {
837    $sql="DELETE FROM ".$this->tables['personalised']." WHERE id = '".$section_id."' ";
838    return(pwg_query($sql));
839  }
840
841  // add a section
842  private function add_personalised($datas)
843  {
844    $sql="INSERT INTO ".$this->tables['personalised']." (id, lang, title, content, visible, nfo)
845          VALUES ('".$datas['id']."', '".$datas['lang']."', '".$datas['title']."', '".$datas['content']."', '".$datas['visible']."', '".$datas['nfo']."')";
846    return(pwg_query($sql));
847  }
848
849  // modify a section
850  private function modify_personalised($datas)
851  {
852    $sql="UPDATE ".$this->tables['personalised']." SET title = '".$datas['title']."',
853          content = '".$datas['content']."',  visible = '".$datas['visible']."',
854          nfo = '".$datas['nfo']."'
855          WHERE id = '".$datas['id']."'
856          AND lang = '".$datas['lang']."'";
857    return(pwg_query($sql));
858  }
859
860  // return the next personalised id
861  private function get_personalised_id()
862  {
863    $sql='SELECT MAX(ID) FROM '.$this->tables['personalised'];
864    $result=pwg_query($sql);
865    if($result)
866    {
867      $row=mysql_fetch_row($result);
868      if(is_array($row))
869      {
870        return($row[0]+1);
871      }
872    }
873    return(0);
874  }
875
876
877  /* ---------------------------------------------------------------------------
878    ajax functions
879  --------------------------------------------------------------------------- */
880
881  // return a html formatted list of urls
882  private function ajax_amm_links_list()
883  {
884    global $template, $user;
885    $local_tpl = new Template(AMM_PATH."admin/", "");
886    $local_tpl->set_filename('body_page',
887                  dirname($this->filelocation).'/admin/amm_linkslist_detail.tpl');
888
889    $template_datas['urls']=array();
890    $urls=$this->get_urls();
891    for($i=0;$i<count($urls);$i++)
892    {
893      $template_datas['urls'][]=array(
894        'img' => AMM_PATH."links_pictures/".$urls[$i]['icon'],
895        'label' => $urls[$i]['label'],
896        'url' => $urls[$i]['url'],
897        'mode' => l10n("g002_mode_".$this->urls_modes[$urls[$i]['mode']]),
898        'up' =>  ($i==0)?false:true,
899        'down' =>  ($i<(count($urls)-1))?true:false,
900        'edit' => $this->page_link.'&amp;fAMM_tabsheet=links&amp;action=modify&amp;fItem='.$urls[$i]['id'],
901        'ID' => $urls[$i]['id'],
902        'IDPREV' => ($i==0)?0:$urls[$i-1]['id'],
903        'IDNEXT' => ($i<(count($urls)-1))?$urls[$i+1]['id']:0,
904        'visible' => l10n('g002_yesno_'.$urls[$i]['visible'])
905      );
906    }
907
908    $themeconf=array(
909      'icon_dir' => $template->get_themeconf('icon_dir')
910    );
911
912    $local_tpl->assign('themeconf', $themeconf);
913    $local_tpl->assign('datas', $template_datas);
914    $local_tpl->assign('plugin', array('PATH' => AMM_PATH));
915
916    return($local_tpl->parse('body_page', true));
917  }
918
919  // permut position of 2 urls and returns a html formatted list of urls
920  private function ajax_amm_links_permut($urlid, $urlpermut)
921  {
922    $this->permut_url($urlid, $urlpermut);
923    return($this->ajax_amm_links_list());
924  }
925
926  // delete an url and returns a html formatted list of urls
927  private function ajax_amm_links_delete($urlid)
928  {
929    if(!$this->adviser_abort())
930    {
931      $this->delete_url($urlid);
932    }
933    return($this->ajax_amm_links_list());
934  }
935
936
937
938
939
940  // return a html formatted list of personalised sections
941  private function ajax_amm_personalised_list()
942  {
943    global $template, $user;
944    $local_tpl = new Template(AMM_PATH."admin/", "");
945    $local_tpl->set_filename('body_page',
946                  dirname($this->filelocation).'/admin/amm_personalisedlist_detail.tpl');
947
948    $template_datas['sections']=array();
949
950    $sections=$this->get_sections(false, '', false);
951    $is_done=array();
952    foreach($sections as $key => $val)
953    {
954      if(!isset($is_done[$val['id']]))
955      {
956        $template_datas['sections'][]=array(
957          'title' => ($val['title']!='')?$val['title']:l10n('g002_notitle'),
958          'edit' => $this->page_link.'&amp;fAMM_tabsheet=personnalblock&amp;action=modify&amp;fItem='.$val['id'],
959          'ID' => $val['id'],
960          'visible' => l10n('g002_yesno_'.$val['visible']),
961          'nfo' => $val['nfo']
962        );
963        $is_done[$val['id']]='';
964      }
965    }
966
967    $themeconf=array(
968      'icon_dir' => $template->get_themeconf('icon_dir')
969    );
970
971    $local_tpl->assign('themeconf', $themeconf);
972    $local_tpl->assign('datas', $template_datas);
973    $local_tpl->assign('plugin', array('PATH' => AMM_PATH));
974
975    return($local_tpl->parse('body_page', true));
976  }
977
978  // delete a section and returns a html formatted list
979  private function ajax_amm_personalised_delete($sectionid)
980  {
981    if(!$this->adviser_abort())
982    {
983      $this->delete_personalised($sectionid);
984    }
985    return($this->ajax_amm_personalised_list());
986  }
987
988
989
990
991  // return a html formatted list of special menu sections items
992  private function ajax_amm_setmenu_mod_section_list($menuname)
993  {
994    $labels=array(
995      'amm_sections_modspecials' => array(
996          'favorites' => 'favorite_cat',
997          'most_visited' => 'most_visited_cat',
998          'best_rated' => 'best_rated_cat',
999          'random' => 'random_cat',
1000          'recent_pics' => 'recent_pics_cat',
1001          'recent_cats' => 'recent_cats_cat',
1002          'calendar' => 'calendar'        ),
1003      'amm_sections_modmenu' => array(
1004          'qsearch' => 'qsearch',
1005          'tags' => 'Tags',
1006          'search' => 'Search',
1007          'comments' => 'comments',
1008          'about' => 'About',
1009          'rss' => 'Notification'
1010        )
1011    );
1012
1013
1014    $local_tpl = new Template(AMM_PATH."admin/", "");
1015    $local_tpl->set_filename('body_page',
1016                  dirname($this->filelocation).'/admin/amm_sectionsmod_detail.tpl');
1017
1018    $template_datas = array('LIST' => array());
1019    foreach($this->my_config[$menuname] as $key => $val)
1020    {
1021      $template_datas['LIST'][] = array(
1022        'ID' => base64_encode($key),
1023        'LABEL' => $labels[$menuname][$key],
1024        'VISIBLE' => 'g002_yesno_'.$val
1025      );
1026    }
1027
1028    $local_tpl->assign('datas', $template_datas);
1029    $local_tpl->assign('plugin', array('PATH' => AMM_PATH));
1030
1031    return($local_tpl->parse('body_page', true));
1032  }
1033
1034
1035  // move item to the specified position
1036  private function ajax_amm_setmenu_mod_section_showhide($menuname, $urlid)
1037  {
1038    $switchvisible=array('y'=>'n', 'n'=>'y');
1039
1040    $this->my_config[$menuname][base64_decode($urlid)]=$switchvisible[$this->my_config[$menuname][base64_decode($urlid)]];
1041    $this->save_config();
1042
1043    return($this->ajax_amm_setmenu_mod_section_list($menuname));
1044  }
1045
1046} // AMM_AIP class
1047
1048
1049?>
Note: See TracBrowser for help on using the repository browser.