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

Last change on this file since 4080 was 3690, checked in by grum, 15 years ago

Update AMM 2.1.1 - bug resolved + improvement
See main.inc.php file for details

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