source: extensions/AMetaData/amd_aip.class.inc.php @ 5191

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

add metadata help

  • Property svn:executable set to *
File size: 42.6 KB
RevLine 
[4905]1<?php
2/*
3 * -----------------------------------------------------------------------------
4 * Plugin Name: Advanced MetaData
5 * -----------------------------------------------------------------------------
6 * Author     : Grum
7 *   email    : grum@piwigo.org
8 *   website  : http://photos.grum.fr
9 *   PWG user : http://forum.piwigo.org/profile.php?id=3706
10 *
11 *   << May the Little SpaceFrog be with you ! >>
12 *
13 * -----------------------------------------------------------------------------
14 *
15 * See main.inc.php for release information
16 *
17 * AIP classe => manage integration in administration interface
18 *
19 * -----------------------------------------------------------------------------
20 */
21
22if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); }
23
24include_once('amd_root.class.inc.php');
25include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
26include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/ajax.class.inc.php');
27include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/genericjs.class.inc.php');
28
29
30
31class AMD_AIP extends AMD_root
32{
33  protected $tabsheet;
34  protected $ajax;
35
36  /**
37   *
38   * constructor needs the prefix of piwigo's tables and the location of plugin
39   *
40   * @param String $prefixeTable
41   * @param String $filelocation
42   */
[5183]43  public function __construct($prefixeTable, $filelocation)
[4905]44  {
45    parent::__construct($prefixeTable, $filelocation);
46
47    $this->load_config();
48    $this->init_events();
49
50    $this->tabsheet = new tabsheet();
51    $this->tabsheet->add('metadata',
52                          l10n('g003_metadata'),
53                          $this->page_link.'&amp;fAMD_tabsheet=metadata');
[5080]54    $this->tabsheet->add('help',
55                          l10n('g003_help'),
56                          $this->page_link.'&amp;fAMD_tabsheet=help');
[4905]57    $this->ajax = new Ajax();
58  }
59
[5183]60  public function __destruct()
[4905]61  {
62    unset($this->tabsheet);
63    unset($this->ajax);
[5183]64    parent::__destruct();
[4905]65  }
66
67
68  /*
69   * ---------------------------------------------------------------------------
70   * Public classe functions
71   * ---------------------------------------------------------------------------
72   */
73
74
75  /**
76   * manage the plugin integration into piwigo's admin interface
77   */
78  public function manage()
79  {
80    global $template, $page;
81
82    $template->set_filename('plugin_admin_content', dirname(__FILE__)."/admin/amd_admin.tpl");
83
84    $this->initRequest();
85
86    $this->returnAjaxContent();
87
88    $this->tabsheet->select($_REQUEST['fAMD_tabsheet']);
89    $this->tabsheet->assign();
90    $selected_tab=$this->tabsheet->get_selected();
91    $template->assign($this->tabsheet->get_titlename(), "[".$selected_tab['caption']."]");
92
93    $template_plugin["AMD_VERSION"] = "<i>".$this->plugin_name."</i> ".l10n('g003_version').AMD_VERSION;
94    $template_plugin["AMD_PAGE"] = $_REQUEST['fAMD_tabsheet'];
95    $template_plugin["PATH"] = AMD_PATH;
96
97    $template->assign('plugin', $template_plugin);
98
[5080]99    if($_REQUEST['fAMD_tabsheet']=='help')
[4905]100    {
[5191]101      $this->displayHelp($_REQUEST['fAMD_page']);
[4905]102    }
103    elseif($_REQUEST['fAMD_tabsheet']=='metadata')
104    {
105      $this->displayMetaData($_REQUEST['fAMD_page']);
106    }
107
108    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
109  }
110
111  /**
112   * initialize events call for the plugin
113   */
114  public function init_events()
115  {
116    add_event_handler('loc_end_page_header', array(&$this->css, 'apply_CSS'));
117  }
118
119  /**
120   * ---------------------------------------------------------------------------
121   * Private & protected functions
122   * ---------------------------------------------------------------------------
123   */
124
125  /**
126   * manage the ajax requests
127   * this function function determine if there is an ajax call, manage the
128   * request and returns the content of the request
129   *
130   * no params are given, the function works with the "$_REQUEST" var
131   *
132   * @return String
133   */
134  protected function returnAjaxContent()
135  {
136    global $ajax, $template;
137
138    if(isset($_REQUEST['ajaxfct']))
139    {
140      //$this->debug("AJAXFCT:".$_REQUEST['ajaxfct']);
141      $result="<p class='errors'>".l10n('g002_error_invalid_ajax_call')."</p>";
142      switch($_REQUEST['ajaxfct'])
143      {
144        case 'makeStatsGetList':
145          $result=$this->ajax_amd_makeStatsGetList($_REQUEST['selectMode'], $_REQUEST['numOfItems']);
146          break;
147        case 'makeStatsDoAnalyze':
148          $result=$this->ajax_amd_makeStatsDoAnalyze($_REQUEST['imagesList']);
149          break;
[4917]150        case 'makeStatsConsolidation':
151          $result=$this->ajax_amd_makeStatsConsolidation();
152          break;
[4905]153        case 'makeStatsGetStatus':
154          $result=$this->ajax_amd_makeStatsGetStatus();
155          break;
156        case 'showStatsGetListTags':
157          $result=$this->ajax_amd_showStatsGetListTags($_REQUEST['orderType'], $_REQUEST['filterType'], $_REQUEST['excludeUnusedTag'], $_REQUEST['selectedTagOnly']);
158          break;
159        case 'showStatsGetListImages':
160          $result=$this->ajax_amd_showStatsGetListImages($_REQUEST['tagId'], $_REQUEST['orderType']);
161          break;
162        case 'updateTagSelect':
163          $result=$this->ajax_amd_updateTagSelect($_REQUEST['numId'], $_REQUEST['tagSelected']);
164          break;
165        case 'groupGetList':
166          $result=$this->ajax_amd_groupGetList();
167          break;
168        case 'groupDelete':
169          $result=$this->ajax_amd_groupDelete($_REQUEST['id']);
170          break;
171        case 'groupGetNames':
172          $result=$this->ajax_amd_groupGetNames($_REQUEST['id']);
173          break;
174        case 'groupSetNames':
175          $result=$this->ajax_amd_groupSetNames($_REQUEST['id'], $_REQUEST['listNames']);
176          break;
177        case 'groupSetOrder':
178          $result=$this->ajax_amd_groupSetOrder($_REQUEST['listGroup']);
179          break;
180        case 'groupGetTagList':
181          $result=$this->ajax_amd_groupGetTagList($_REQUEST['id']);
182          break;
183        case 'groupSetTagList':
184          $result=$this->ajax_amd_groupSetTagList($_REQUEST['id'], $_REQUEST['listTag']);
185          break;
186        case 'groupGetOrderedTagList':
187          $result=$this->ajax_amd_groupGetOrderedTagList($_REQUEST['id']);
188          break;
189        case 'groupSetOrderedTagList':
190          $result=$this->ajax_amd_groupSetOrderedTagList($_REQUEST['id'], $_REQUEST['listTag']);
191          break;
192      }
193      $this->ajax->return_result($result);
194    }
195  }
196
197
198  /**
199   * if empty, initialize the $_REQUEST var
200   *
201   * if not empty, check validity for the request values
202   *
203   */
204  private function initRequest()
205  {
206    //initialise $REQUEST values if not defined
207    if($this->getNumOfPictures()==0)
208    {
209      $defautTabsheet="database";
210    }
211    else
212    {
[5080]213      $defautTabsheet="select";
[4905]214    }
215
216    if(!isset($_REQUEST['fAMD_tabsheet']))
217    {
218      $_REQUEST['fAMD_tabsheet']=$defautTabsheet;
219    }
220
221    if($_REQUEST['fAMD_tabsheet']!="metadata" and
[5080]222       $_REQUEST['fAMD_tabsheet']!="help")
[4905]223    {
[5080]224      $_REQUEST['fAMD_tabsheet']="metadata";
[4905]225    }
226
227    if($_REQUEST['fAMD_tabsheet']=="metadata" and !isset($_REQUEST['fAMD_page']))
228    {
[5080]229      $_REQUEST['fAMD_page']=$defautTabsheet;
[4905]230    }
231
232    if($_REQUEST['fAMD_tabsheet']=="metadata" and
233       !($_REQUEST['fAMD_page']=="select" or
[5080]234         $_REQUEST['fAMD_page']=="database" or
[4905]235         $_REQUEST['fAMD_page']=="display"))
236    {
[5080]237      $_REQUEST['fAMD_page']=$defautTabsheet;
[4905]238    }
239
[5191]240
241    if($_REQUEST['fAMD_tabsheet']=="help" and !isset($_REQUEST['fAMD_page']))
242    {
243      $_REQUEST['fAMD_page']="exif";
244    }
245
246    if($_REQUEST['fAMD_tabsheet']=="help" and
247       !($_REQUEST['fAMD_page']=="exif" or
248         $_REQUEST['fAMD_page']=="iptc" or
249         $_REQUEST['fAMD_page']=="xmp" or
250         $_REQUEST['fAMD_page']=="magic"))
251    {
252      $_REQUEST['fAMD_page']="exif";
253    }
254
255
[4905]256    /*
257     * check ajax
258     */
259    if(isset($_REQUEST['ajaxfct']))
260    {
261      /*
262       * check makeStatsGetList values
263       */
264      if($_REQUEST['ajaxfct']=="makeStatsGetList" and !isset($_REQUEST['selectMode']))
265      {
[5080]266        $_REQUEST['selectMode']="caddieAdd";
[4905]267      }
268
269      if($_REQUEST['ajaxfct']=="makeStatsGetList" and
270         !($_REQUEST['selectMode']=="notAnalyzed" or
[5080]271           $_REQUEST['selectMode']=="caddieAdd" or
272           $_REQUEST['selectMode']=="caddieReplace" or
[4905]273           $_REQUEST['selectMode']=="all"))
274      {
[5080]275        $_REQUEST['selectMode']="caddieAdd";
[4905]276      }
277
278      if($_REQUEST['ajaxfct']=="makeStatsGetList" and !isset($_REQUEST['numOfItems']))
279      {
280        $_REQUEST['numOfItems']=25;
281      }
282
283      /*
284       * check makeStatsDoAnalyze values
285       */
286      if($_REQUEST['ajaxfct']=="makeStatsDoAnalyze" and !isset($_REQUEST['imagesList']))
287      {
288        $_REQUEST['imagesList']="";
289      }
290
291      /*
292       * check makeStatsConsolidate values
293       */
294      if($_REQUEST['ajaxfct']=="makeStatsConsolidate" and !isset($_REQUEST['step']))
295      {
296        $_REQUEST['step']="*";
297      }
298
299      /*
300       * check showStatsGetListTags values
301       */
302      if($_REQUEST['ajaxfct']=="showStatsGetListTags" and !isset($_REQUEST['orderType']))
303      {
304        $_REQUEST['orderType']="tag";
305      }
306
307      if($_REQUEST['ajaxfct']=="showStatsGetListTags" and
308         !($_REQUEST['orderType']=="tag" or
309           $_REQUEST['orderType']=="num"))
310      {
311        $_REQUEST['orderType']="tag";
312      }
313
314      if($_REQUEST['ajaxfct']=="showStatsGetListTags" and !isset($_REQUEST['filterType']))
315      {
316        $_REQUEST['filterType']="";
317      }
318
319      if($_REQUEST['ajaxfct']=="showStatsGetListTags" and
320         !($_REQUEST['filterType']=="" or
[4999]321           $_REQUEST['filterType']=="magic" or
[4905]322           $_REQUEST['filterType']=="exif" or
323           $_REQUEST['filterType']=="xmp" or
324           $_REQUEST['filterType']=="iptc"))
325      {
326        $_REQUEST['filterType']="";
327      }
328
329      if($_REQUEST['ajaxfct']=="showStatsGetListTags" and !isset($_REQUEST['excludeUnusedTag']))
330      {
331        $_REQUEST['excludeUnusedTag']="n";
332      }
333
334      if($_REQUEST['ajaxfct']=="showStatsGetListTags" and
335         !($_REQUEST['excludeUnusedTag']=="y" or
336           $_REQUEST['excludeUnusedTag']=="n" ))
337      {
338        $_REQUEST['excludeUnusedTag']="n";
339      }
340
341      if($_REQUEST['ajaxfct']=="showStatsGetListTags" and !isset($_REQUEST['selectedTagOnly']))
342      {
343        $_REQUEST['selectedTagOnly']="n";
344      }
345
346      if($_REQUEST['ajaxfct']=="showStatsGetListTags" and
347         !($_REQUEST['selectedTagOnly']=="y" or
348           $_REQUEST['selectedTagOnly']=="n" ))
349      {
350        $_REQUEST['selectedTagOnly']="n";
351      }
352
353
354      /*
355       * check showStatsGetListImagess values
356       */
357      if($_REQUEST['ajaxfct']=="showStatsGetListImages" and !isset($_REQUEST['orderType']))
358      {
359        $_REQUEST['orderType']="num";
360      }
361
362      if($_REQUEST['ajaxfct']=="showStatsGetListImages" and
363         !($_REQUEST['orderType']=="value" or
364           $_REQUEST['orderType']=="num"))
365      {
366        $_REQUEST['orderType']="num";
367      }
368
369      if($_REQUEST['ajaxfct']=="showStatsGetListImages" and !isset($_REQUEST['tagId']))
370      {
371        $_REQUEST['tagId']="*";
372      }
373
374
375      /*
376       * check showStatsGetListImagess values
377       */
378      if($_REQUEST['ajaxfct']=="updateTagSelect" and !isset($_REQUEST['numId']))
379      {
380        $_REQUEST['numId']="";
381      }
382
383      if($_REQUEST['ajaxfct']=="updateTagSelect" and !isset($_REQUEST['tagSelected']))
384      {
385        $_REQUEST['tagSelected']="";
386      }
387
388
389
390
391      /*
392       * check groupDelete values
393       */
394      if($_REQUEST['ajaxfct']=="groupDelete" and !isset($_REQUEST['id']))
395      {
396        $_REQUEST['id']="";
397      }
398
399
400
401      /*
402       * check groupSetOrder values
403       */
404      if($_REQUEST['ajaxfct']=="groupSetOrder" and !isset($_REQUEST['listGroup']))
405      {
406        $_REQUEST['listGroup']="";
407      }
408
409      /*
410       * check groupGetNames values
411       */
412      if($_REQUEST['ajaxfct']=="groupGetNames" and !isset($_REQUEST['id']))
413      {
414        $_REQUEST['id']="";
415      }
416
417      /*
418       * check groupSetNames values
419       */
420      if($_REQUEST['ajaxfct']=="groupSetNames" and !isset($_REQUEST['listNames']))
421      {
422        $_REQUEST['listNames']="";
423      }
424
425      if($_REQUEST['ajaxfct']=="groupSetNames" and !isset($_REQUEST['id']))
426      {
427        $_REQUEST['id']="";
428      }
429
430
431      /*
432       * check groupGetTagList values
433       */
434      if($_REQUEST['ajaxfct']=="groupGetTagList" and !isset($_REQUEST['id']))
435      {
436        $_REQUEST['id']="";
437      }
438
439      /*
440       * check groupSetTagList values
441       */
442      if($_REQUEST['ajaxfct']=="groupSetTagList" and !isset($_REQUEST['id']))
443      {
444        $_REQUEST['id']="";
445      }
446
447      if($_REQUEST['ajaxfct']=="groupSetTagList" and !isset($_REQUEST['listTag']))
448      {
449        $_REQUEST['listTag']="";
450      }
451
452
453      /*
454       * check groupGetOrderedTagList values
455       */
456      if($_REQUEST['ajaxfct']=="groupGetOrderedTagList" and !isset($_REQUEST['id']))
457      {
458        $_REQUEST['id']="";
459      }
460
461      /*
462       * check groupSetOrderedTagList values
463       */
464      if($_REQUEST['ajaxfct']=="groupSetOrderedTagList" and !isset($_REQUEST['id']))
465      {
466        $_REQUEST['id']="";
467      }
468
469      if($_REQUEST['ajaxfct']=="groupSetOrderedTagList" and !isset($_REQUEST['listTag']))
470      {
471        $_REQUEST['listTag']="";
472      }
473
474    }
475  } //init_request
476
477
478  /**
479   * manage adviser profile
480   *
481   * @return Boolean : true if user is adviser, otherwise false (and push a
482   *                   message in the error list)
483   */
484  protected function adviser_abort()
485  {
486    if(is_adviser())
487    {
488      $this->display_result(l10n("g003_adviser_not_allowed"), false);
489      return(true);
490    }
491    return(false);
492  }
493
494
495  /**
496   * display and manage the metadata page
[5191]497   * the page have three tabsheet :
[4905]498   *  - select tag management, to manage tags to be selected on the galerie
499   *  - display tag management, to choose how the tags are displayed
[5191]500   *  - manage database
[4905]501   *
502   * @param String $tab : the selected tab on the stat page
503   */
504  protected function displayMetaData($tab)
505  {
506    global $template, $user;
507    $template->set_filename('body_page', dirname(__FILE__).'/admin/amd_metadata.tpl');
508
509    $statTabsheet = new tabsheet('statTabsheet', $this->tabsheet->get_titlename());
510    $statTabsheet->select($tab);
[5080]511    $statTabsheet->add('database',
512                          l10n('g003_database'),
513                          $this->page_link.'&amp;fAMD_tabsheet=metadata&amp;fAMD_page=database');
[4905]514    $statTabsheet->add('select',
515                          l10n('g003_select'),
[4916]516                          $this->page_link.'&amp;fAMD_tabsheet=metadata&amp;fAMD_page=select');
[4905]517    $statTabsheet->add('display',
518                          l10n('g003_display'),
[4916]519                          $this->page_link.'&amp;fAMD_tabsheet=metadata&amp;fAMD_page=display');
[4905]520    $statTabsheet->assign();
521
522
523
524    if($tab=="select")
525    {
526      $template->assign('sheetContent', $this->displayMetaDataSelect());
527    }
[5080]528    elseif($tab=="display")
[4905]529    {
530      $template->assign('sheetContent', $this->displayMetaDataDisplay());
531    }
[5080]532    else
533    {
[5191]534      $template->assign('sheetContent', $this->displayMetaDataDatabase());
[5080]535    }
[4905]536
537    $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page');
538  }
539
540  /**
541   * display and manage the metadata page allowing to make tags selection
542   *
543   * @return String : the content of the page
544   */
545  protected function displayMetaDataSelect()
546  {
547    global $template;
548
549    $template->set_filename('sheet_page',
550                  dirname($this->filelocation).'/admin/amd_metadata_select.tpl');
551
552    $datas=array(
553      'urlRequest' => $this->page_link,
554      'config_GetListTags_OrderType' => $this->my_config['amd_GetListTags_OrderType'],
555      'config_GetListTags_FilterType' => $this->my_config['amd_GetListTags_FilterType'],
556      'config_GetListTags_ExcludeUnusedTag' => $this->my_config['amd_GetListTags_ExcludeUnusedTag'],
557      'config_GetListTags_SelectedTagOnly' => $this->my_config['amd_GetListTags_SelectedTagOnly'],
558      'config_GetListImages_OrderType' => $this->my_config['amd_GetListImages_OrderType']
559    );
560
561
562    $template->assign('datas', $datas);
563
564    return($template->parse('sheet_page', true));
565  }
566
567
568  /**
569   * display and manage the metadata page allowing to choose tags order
570   *
571   * @return String : the content of the page
572   */
573  protected function displayMetaDataDisplay()
574  {
575    global $user, $template;
576
577    //$local_tpl = new Template(AMD_PATH."admin/", "");
578    $template->set_filename('sheet_page',
579                  dirname($this->filelocation).'/admin/amd_metadata_display.tpl');
580
581
582    $datas=array(
583      'urlRequest' => $this->page_link,
584      'selectedTags' => Array(),
585      'groups' => Array(),
586      'tagByGroup' => Array(),
587    );
588
589    $sql="SELECT st.tagId, st.order, st.groupId, ut.numId
590          FROM ".$this->tables['selected_tags']." st
591            LEFT JOIN ".$this->tables['used_tags']." ut
592              ON ut.tagId = st.tagId
593          ORDER BY st.groupId ASC, st.order ASC, st.tagId ASC";
594    $result=pwg_query($sql);
595    if($result)
596    {
597      while($row=mysql_fetch_assoc($result))
598      {
599        if($row['groupId']==-1)
600        {
601          $datas['selectedTags'][]=Array(
602            'numId' => $row['numId'],
603            'tagId' => $row['tagId']
604          );
605        }
606        else
607        {
608          $datas['tagByGroup'][]=Array(
609            'numId' => $row['numId'],
610            'tagId' => $row['tagId'],
611            'group' => $row['groupId'],
612            'order' => $row['order']
613          );
614        }
615      }
616    }
617
618    $sql="SELECT g.groupId, gn.name
619          FROM ".$this->tables['groups']." g
620            LEFT JOIN ".$this->tables['groups_names']." gn
621              ON g.groupId = gn.groupId
622          WHERE gn.lang = '".$user['language']."'
623          ORDER BY g.order;";
624    $result=pwg_query($sql);
625    if($result)
626    {
627      while($row=mysql_fetch_assoc($result))
628      {
629        $datas['groups'][]=Array(
630          'id' => $row['groupId'],
631          'name' => $row['name']
632        );
633      }
634    }
635
636    $template->assign('datas', $datas);
637    return($template->parse('sheet_page', true));
638  }
639
640
[5080]641  /**
642   * display and manage the database page
643   *
644   * the function automatically update the AMD tables :
645   *  - add new pictures in the AMD image table (assuming image is not analyzed
646   *    yet)
647   *  - remove deleted pictures in the AMD image & image_tags table
648   *
649   * @return String : the content of the page
650   */
[5191]651  private function displayMetaDataDatabase()
[5080]652  {
653    global $template, $page;
[4905]654
[5080]655    /*
656     * insert new image (from piwigo images table) in the AMD images table, with
657     * statut 'not analyzed'
658     */
659    $sql="INSERT INTO ".$this->tables['images']."
660            SELECT id, 'n', 0
661              FROM ".IMAGES_TABLE."
662              WHERE id NOT IN (SELECT imageId FROM ".$this->tables['images'].")";
663    pwg_query($sql);
664
665
666    /*
667     * delete image who are in the AMD images table and not in the piwigo image
668     * table
669     */
670    $sql="DELETE FROM ".$this->tables['images']."
671            WHERE imageId NOT IN (SELECT id FROM ".IMAGES_TABLE.")";
672    pwg_query($sql);
673
674
675    /*
676     * delete metdata for images that are not in the AMD image table
677     */
678    $sql="DELETE FROM ".$this->tables['images_tags']."
679            WHERE imageId NOT IN (SELECT imageId FROM ".$this->tables['images'].")";
680    pwg_query($sql);
681
682
683    $template->set_filename('sheet_page', dirname(__FILE__).'/admin/amd_metadata_database.tpl');
684
685    $datas=array(
686      'urlRequest' => $this->page_link,
687      'NumberOfItemsPerRequest' => $this->my_config['amd_NumberOfItemsPerRequest'],
688    );
689
690    $template->assign("datas", $datas);
691
692    return($template->parse('sheet_page', true));
693  } // displayDatabase
694
695
696
697
[4905]698
[5191]699  /**
700   * display and manage the help page
701   *
702   * @param String $tab : the selected tab on the help page
703   */
704  protected function displayHelp($tab)
705  {
706    global $template, $user, $lang;
707    $template->set_filename('body_page', dirname(__FILE__).'/admin/amd_help.tpl');
[4905]708
[5191]709    $statTabsheet = new tabsheet('statTabsheet', $this->tabsheet->get_titlename());
710    $statTabsheet->select($tab);
711    $statTabsheet->add('exif',
712                          l10n('g003_help_tab_exif'),
713                          $this->page_link.'&amp;fAMD_tabsheet=help&amp;fAMD_page=exif');
714    $statTabsheet->add('iptc',
715                          l10n('g003_help_tab_iptc'),
716                          $this->page_link.'&amp;fAMD_tabsheet=help&amp;fAMD_page=iptc');
717    $statTabsheet->add('xmp',
718                          l10n('g003_help_tab_xmp'),
719                          $this->page_link.'&amp;fAMD_tabsheet=help&amp;fAMD_page=xmp');
720    $statTabsheet->add('magic',
721                          l10n('g003_help_tab_magic'),
722                          $this->page_link.'&amp;fAMD_tabsheet=help&amp;fAMD_page=magic');
723    $statTabsheet->assign();
724
725    $data=Array(
726      'sheetContent' => $this->BBtoHTML($lang['g003_help_'.$tab]),
727      'title' => l10n('g003_help_tab_'.$tab),
728    );
729
730    $template->assign('data', $data);
731
732    $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page');
733  }
734
735
736
737  /**
738   * convert (light) BB tag to HTML tag
739   *
740   * all BB codes are not recognized, only :
741   *  - [ul] [/ul]
742   *  - [li] [/li]
743   *  - [b] [/b]
744   *  - [i] [/i]
745   *  - [url] [/url]
746   *  - carriage return is replaced by a <br>
747   *
748   * @param String $text : text to convert
749   * @return String : BB to HTML text
750   */
751  protected function BBtoHTML($text)
752  {
753    $patterns = Array(
754      '/\[li\](.*?)\[\/li\]\n*/im',
755      '/\[b\](.*?)\[\/b\]/ism',
756      '/\[i\](.*?)\[\/i\]/ism',
757      '/\[url\]([\w]+?:\/\/[^ \"\n\r\t<]*?)\[\/url\]/ism',
758      '/\[url=([\w]+?:\/\/[^ \"\n\r\t<]*?)\](.*?)\[\/url\]/ism',
759      '/\n{0,1}\[ul\]\n{0,1}/im',
760      '/\n{0,1}\[\/ul\]\n{0,1}/im',
761      '/\n/im',
762    );
763    $replacements = Array(
764      '<li>\1</li>',
765      '<b>\1</b>',
766      '<i>\1</i>',
767      '<a href="\1">\1</a>',
768      '<a href="\1">\2</a>',
769      '<ul>',
770      '</ul>',
771      '<br>',
772    );
773
774    return(preg_replace($patterns, $replacements, $text));
775  }
776
777
[4905]778  /*
779   * ---------------------------------------------------------------------------
780   * ajax functions
781   * ---------------------------------------------------------------------------
782   */
783
784  /**
785   * return a list of picture Id
786   *
787   * picture id are separated with a space " "
788   * picture id are grouped in blocks of 'amd_NumberOfItemsPerRequest' items and
789   * are separated with a semi-colon ";"
790   *
791   * client side just have to split blocks, and transmit it to the server
792   *
793   * There is two mode to determine the pictures being analyzed :
794   *  - "all"         : analyze all the images
795   *  - "notAnalyzed" : analyze only the images not yet analyzed
796   *
797   * @param String $mode
798   * @param Integer $nbOfItems : number of items per request
799   * @return String : list of image id to be analyzed, separated with a space
800   *                      "23 78 4523 5670"
801   */
802  private function ajax_amd_makeStatsGetList($mode, $nbOfItems)
803  {
[5080]804    global $user;
805
[4905]806    $returned="";
807    $this->my_config['amd_NumberOfItemsPerRequest']=$nbOfItems;
808    $this->save_config();
809
[5080]810    $sql="SELECT ait.imageId FROM ".$this->tables['images']." ait";
[4905]811    if($mode=="notAnalyzed")
812    {
[5080]813      $sql.=" WHERE ait.analyzed='n'";
[4905]814    }
[5080]815    elseif($mode=="caddieAdd" or $mode=="caddieReplace")
[4905]816    {
[5080]817
818      $sql.=" LEFT JOIN ".CADDIE_TABLE." ct ON ait.imageId = ct.element_id
819            WHERE ct.user_id = ".$user['id'].";";
820    }
821
822    if($mode=="all" or $mode=="caddieReplace")
823    {
[4905]824      pwg_query("UPDATE ".$this->tables['images']." SET analyzed='n', nbTags=0");
825      pwg_query("UPDATE ".$this->tables['used_tags']." SET numOfImg=0");
826      pwg_query("DELETE FROM ".$this->tables['images_tags']);
827    }
828
829    $result=pwg_query($sql);
830    if($result)
831    {
832      $i=0;
833      while($row=mysql_fetch_row($result))
834      {
835        $returned.=$row[0];
836        $i++;
837        if($i>=$nbOfItems)
838        {
839          $returned.=";";
840          $i=0;
841        }
842        else
843        {
844          $returned.=" ";
845        }
846      }
847    }
848    return(trim($returned).";");
849  }
850
851
852  /**
853   * extract metadata from images
854   *
855   * @param String $imageList : list of image id to be analyzed, separated with
856   *                            a space
857   *                                "23 78 4523 5670"
858   * @return String : list of the analyzed pictures, with number of tags found
859   *                  for each picture
860   *                    "23=0;78=66;4523=33;5670=91;"
861   */
862  private function ajax_amd_makeStatsDoAnalyze($imagesList)
863  {
864    $list=explode(" ", trim($imagesList));
865
866    $returned="";
867
868    if(count($list)>0)
869    {
870      // $path = path of piwigo's on the server filesystem
871      $path=dirname(dirname(dirname(__FILE__)));
872
873      $sql="SELECT id, path FROM ".IMAGES_TABLE." WHERE id IN (".implode(", ", $list).")";
874      $result=pwg_query($sql);
875      if($result)
876      {
877        while($row=mysql_fetch_assoc($result))
878        {
879          /*
880           * in some case (in a combination of some pictures), when there is too
881           * much pictures to analyze in the same request, a fatal error occurs
882           * with the message : "Allowed memory size of XXXXX bytes exhausted"
883           *
884           *
885           * tracking memory leak is not easy... :-(
886           *
887           */
888          //echo "analyzing:".$row['id']."\n";
889          //$mem1=memory_get_usage();
890          //echo "memory before analyze:".$mem1."\n";
891          $returned.=$this->analyzeImageFile($path."/".$row['path'], $row['id']);
892          //echo $returned."\n";
893          //$mem2=memory_get_usage();
894          //echo "memory after analyze:".$mem2." (".($mem2-$mem1).")\n";
895        }
896      }
897    }
898    return($returned);
899  }
900
901  /**
[4917]902   * do some consolidation on database to optimize other requests
903   *
904   */
905  private function ajax_amd_makeStatsConsolidation()
906  {
[5183]907    $this->makeStatsConsolidation();
[4917]908  }
909
910  /**
[4905]911   * returns a list of formated string, separated with a semi-colon :
912   *  - number of current analyzed pictures + number of current analyzed tags
913   *    for the analyzed pictures
914   *  - number of pictures not analyzed
915   *  - number of pictures without tag
916   *
917   * @return String
918   */
919  private function ajax_amd_makeStatsGetStatus()
920  {
921    $numOfMetaData=0;
922    $numOfPictures=0;
923    $numOfPicturesNotAnalyzed=0;
924
925    $sql="SELECT COUNT(imageId), SUM(nbTags) FROM ".$this->tables['images']."
926            WHERE analyzed='y';";
927    $result=pwg_query($sql);
928    if($result)
929    {
930      while($row=mysql_fetch_row($result))
931      {
932        $numOfPictures=$row[0];
933        $numOfMetaData=$row[1];
934      }
935    }
936
937
938    $sql="SELECT COUNT(imageId) FROM ".$this->tables['images']."
939            WHERE analyzed='n';";
940    $result=pwg_query($sql);
941    if($result)
942    {
943      while($row=mysql_fetch_row($result))
944      {
945        $numOfPicturesNotAnalyzed=$row[0];
946      }
947    }
948
949    $sql="SELECT COUNT(imageId) FROM ".$this->tables['images']."
950            WHERE nbTags=0;";
951    $result=pwg_query($sql);
952    if($result)
953    {
954      while($row=mysql_fetch_row($result))
955      {
956        $numOfPicturesWithoutTags=$row[0];
957      }
958    }
959
960    return(sprintf(l10n("g003_numberOfAnalyzedPictures"), $numOfPictures, $numOfMetaData).";".
961              sprintf(l10n("g003_numberOfNotAnalyzedPictures"), $numOfPicturesNotAnalyzed).";".
962              sprintf(l10n("g003_numberOfPicturesWithoutTags"), $numOfPicturesWithoutTags));
963  }
964
965
966  /**
967   * return a formatted <table> (using the template "amd_stat_show_iListTags")
968   * of used tag with, for each tag, the number and the percentage of pictures
969   * where the tag was found
970   *
971   * @param String $orderType : order for the list (by tag 'tag' or by number of
972   *                            pictures 'num')
973   * @param String $filterType : filter for the list ('exif', 'xmp', 'iptc' or '')
974   * @return String
975   */
976  private function ajax_amd_showStatsGetListTags($orderType, $filterType, $excludeUnusedTag, $selectedTagOnly)
977  {
978    $this->my_config['amd_GetListTags_OrderType'] = $orderType;
979    $this->my_config['amd_GetListTags_FilterType'] = $filterType;
980    $this->my_config['amd_GetListTags_ExcludeUnusedTag'] = $excludeUnusedTag;
981    $this->my_config['amd_GetListTags_SelectedTagOnly'] = $selectedTagOnly;
982    $this->save_config();
983
984    $local_tpl = new Template(AMD_PATH."admin/", "");
985    $local_tpl->set_filename('body_page',
986                  dirname($this->filelocation).'/admin/amd_metadata_select_iListTags.tpl');
987
988    $numOfPictures=$this->getNumOfPictures();
989
990    $datas=array();
991    $sql="SELECT ut.numId, ut.tagId, ut.translatable, ut.name, ut.numOfImg, if(st.tagId IS NULL, 'n', 'y') as checked
992            FROM ".$this->tables['used_tags']." ut
993              LEFT JOIN ".$this->tables['selected_tags']." st
994                ON st.tagId = ut.tagId ";
995    $where="";
996
997    if($filterType!='')
998    {
999      $where.=" WHERE ut.tagId LIKE '".$filterType.".%' ";
1000    }
1001
1002    if($excludeUnusedTag=='y')
1003    {
1004      ($where=="")?$where=" WHERE ":$where.=" AND ";
1005      $where.=" ut.numOfImg > 0 ";
1006    }
1007
1008    if($selectedTagOnly=='y')
1009    {
1010      ($where=="")?$where=" WHERE ":$where.=" AND ";
1011      $where.=" st.tagId IS NOT NULL ";
1012    }
1013
1014    $sql.=$where;
1015
1016    switch($orderType)
1017    {
1018      case 'tag':
1019        $sql.=" ORDER BY tagId ASC";
1020        break;
1021      case 'num':
1022        $sql.=" ORDER BY numOfImg DESC, tagId ASC";
1023        break;
1024    }
1025
1026    $result=pwg_query($sql);
1027    if($result)
1028    {
1029      while($row=mysql_fetch_assoc($result))
1030      {
1031        $datas[]=array(
1032          "numId" => $row['numId'],
1033          "tagId" => $row['tagId'],
1034          "label" => L10n::get($row['name']),
1035          "nb"    => $row['numOfImg'],
[5040]1036          "pct"   => ($numOfPictures!=0)?sprintf("%.2f", 100*$row['numOfImg']/$numOfPictures):"0",
[4905]1037          "tagChecked" => ($row['checked']=='y')?"checked":""
1038        );
1039      }
1040    }
1041
1042    $local_tpl->assign('datas', $datas);
1043
1044    return($local_tpl->parse('body_page', true));
1045  }
1046
1047
1048  /*
1049   *
1050   *
1051   */
1052  private function ajax_amd_showStatsGetListImages($tagId, $orderType)
1053  {
1054    $this->my_config['amd_GetListImages_OrderType'] = $orderType;
1055    $this->save_config();
1056
1057    $local_tpl = new Template(AMD_PATH."admin/", "");
1058    $local_tpl->set_filename('body_page',
1059                  dirname($this->filelocation).'/admin/amd_metadata_select_iListImages.tpl');
1060
1061
1062
1063    $datas=array();
1064    $sql="SELECT ut.translatable, ut.numOfImg, COUNT(it.imageId) AS Nb, it.value
1065            FROM ".$this->tables['used_tags']." ut
1066              LEFT JOIN ".$this->tables['images_tags']." it
1067              ON ut.numId = it.numId
1068            WHERE ut.tagId = '".$tagId."'
1069              AND it.value IS NOT NULL
1070            GROUP BY it.value
1071            ORDER BY ";
1072    switch($orderType)
1073    {
1074      case 'value':
1075        $sql.="it.value ASC";
1076        break;
1077      case 'num':
1078        $sql.="Nb DESC";
1079        break;
1080    }
1081
1082    $result=pwg_query($sql);
1083    if($result)
1084    {
1085      while($row=mysql_fetch_assoc($result))
1086      {
1087        $datas[]=array(
1088          "value" => ($row['translatable']=='y')?L10n::get($row['value']):$row['value'],
1089          "nb"    => $row['Nb'],
1090          "pct"   => ($row['numOfImg']!=0)?sprintf("%.2f", 100*$row['Nb']/$row['numOfImg']):"-"
1091        );
1092      }
1093    }
1094
1095    if(count($datas)>0)
1096    {
1097      $local_tpl->assign('datas', $datas);
1098      return($local_tpl->parse('body_page', true));
1099    }
1100    else
1101    {
1102      return("<div style='width:100%;text-align:center;padding-top:20px;'>".l10n('g003_selected_tag_isnot_linked_with_any_picture')."</div>");
1103    }
1104  }
1105
1106
1107  /*
1108   *
1109   *
1110   */
1111  private function ajax_amd_updateTagSelect($numId, $selected)
1112  {
1113    if($selected=='y')
1114    {
1115      $sql="SELECT ut.tagId FROM ".$this->tables['selected_tags']." st
1116              LEFT JOIN ".$this->tables['used_tags']." ut
1117                ON ut.tagID = st.tagId
1118              WHERE ut.numId = $numId;";
1119      $result=pwg_query($sql);
1120      if($result)
1121      {
1122        if(mysql_num_rows($result)==0)
1123        {
1124          $sql="INSERT INTO ".$this->tables['selected_tags']."
1125                  SELECT ut.tagId, 0, -1
1126                  FROM ".$this->tables['used_tags']." ut
1127                    LEFT JOIN ".$this->tables['selected_tags']." st
1128                      ON ut.tagID = st.tagId
1129                  WHERE ut.numId = $numId;";
1130          pwg_query($sql);
1131        }
1132      }
1133    }
1134    elseif($selected=='n')
1135    {
1136      $sql="DELETE FROM ".$this->tables['selected_tags']." st
1137              USING phpwebgallery_amd_used_tags ut
1138                LEFT JOIN phpwebgallery_amd_selected_tags st
1139                  ON ut.tagID = st.tagId
1140              WHERE ut.numId = $numId;";
1141      pwg_query($sql);
1142    }
1143
1144  }
1145
1146
1147  /**
1148   * this function return the list of tags :
1149   *  - associated with the group
1150   *  - not associated with a group
1151   * the list is used to make tags selection
1152   *
1153   * @param String $id      : Id of the current group
1154   * @return String : an HTML formatted list with checkbox
1155   */
1156  private function ajax_amd_groupGetTagList($id)
1157  {
1158    if($id!="")
1159    {
1160      $sql="SELECT st.tagId, st.groupId, ut.name, ut.numId
1161            FROM ".$this->tables['selected_tags']." st
1162              LEFT JOIN ".$this->tables['used_tags']." ut
1163                ON st.tagId = ut.tagId
1164            ORDER BY tagId";
1165      $result=pwg_query($sql);
1166      if($result)
1167      {
1168        $datas=Array();
1169        while($row=mysql_fetch_assoc($result))
1170        {
1171          if($row['groupId']==$id)
1172          {
1173            $state="checked";
1174          }
1175          elseif($row['groupId']==-1)
1176          {
1177            $state="";
1178          }
1179          else
1180          {
1181            $state="n/a";
1182          }
1183
1184          if($state!="n/a")
1185            $datas[]=Array(
1186              'tagId' => $row['tagId'],
1187              'name'  => L10n::get($row['name']),
1188              'state' => $state,
1189              'numId' => $row['numId']
1190            );
1191        }
1192
1193        if(count($datas)>0)
1194        {
1195          $local_tpl = new Template(AMD_PATH."admin/", "");
1196          $local_tpl->set_filename('body_page',
1197                        dirname($this->filelocation).'/admin/amd_metadata_display_groupListTagSelect.tpl');
1198          $local_tpl->assign('datas', $datas);
1199          return($local_tpl->parse('body_page', true));
1200        }
1201        else
1202        {
1203          return(l10n("g003_no_tag_can_be_selected"));
1204        }
1205      }
1206    }
1207    else
1208    {
1209      return(l10n("g003_invalid_group_id"));
1210    }
1211  }
1212
1213
1214  /**
1215   * this function associate tags to a group
1216   *
1217   * @param String $id      : Id of group
1218   * @param String $listTag : list of selected tags, items are separated by a
1219   *                          semi-colon ";" char
1220   */
1221  private function ajax_amd_groupSetTagList($id, $listTag)
1222  {
1223    if($id!="")
1224    {
1225      $sql="UPDATE ".$this->tables['selected_tags']."
1226            SET groupId = -1
1227            WHERE groupId = $id;";
1228      pwg_query($sql);
1229
1230      if($listTag!="")
1231      {
1232        $sql="UPDATE ".$this->tables['selected_tags']." st, ".$this->tables['used_tags']." ut
1233              SET st.groupId = $id
1234              WHERE st.tagId = ut.tagId
1235                AND ut.numId IN ($listTag);";
1236        pwg_query($sql);
1237      }
1238    }
1239    else
1240    {
1241      return("KO");
1242    }
1243  }
1244
1245
1246  /**
1247   * this function returns an ordered list of tags associated with a group
1248   *
1249   * @param String $id        : the group Id
1250   * @return String : an HTML formatted list
1251   */
1252  private function ajax_amd_groupGetOrderedTagList($id)
1253  {
1254    global $template;
1255    if($id!="")
1256    {
1257      $numOfPictures=$this->getNumOfPictures();
1258
1259      $sql="SELECT st.tagId, ut.name, ut.numId, ut.numOfImg
1260            FROM ".$this->tables['selected_tags']." st
1261              LEFT JOIN ".$this->tables['used_tags']." ut
1262                ON st.tagId = ut.tagId
1263            WHERE st.groupId = $id
1264            ORDER BY st.order ASC, st.tagId ASC";
1265      $result=pwg_query($sql);
1266      if($result)
1267      {
1268        $datas=Array();
1269        while($row=mysql_fetch_assoc($result))
1270        {
1271          $datas[]=Array(
1272            'tagId' => $row['tagId'],
1273            'name'  => L10n::get($row['name']),
1274            'numId' => $row['numId'],
1275            'nbItems' => $row['numOfImg'],
[5040]1276            'pct'   => ($numOfPictures==0)?"0":sprintf("%.2f", 100*$row['numOfImg']/$numOfPictures)
[4905]1277          );
1278        }
1279
1280        if(count($datas)>0)
1281        {
1282          $template->set_filename('list_page',
1283                        dirname($this->filelocation).'/admin/amd_metadata_display_groupListTagOrder.tpl');
1284          $template->assign('datas', $datas);
1285          $template->assign('group', $id);
1286          return($template->parse('list_page', true));
1287        }
1288        else
1289        {
1290          return(l10n("g003_no_tag_can_be_selected"));
1291        }
1292      }
1293    }
1294    else
1295    {
1296      return(l10n("g003_invalid_group_id"));
1297    }
1298  }
1299
1300
1301  /**
1302   * this function update the tags order inside a group
1303   *
1304   * @param String $id        : the group Id
1305   * @param String $listGroup : the ordered list of tags, items are separated
1306   *                            by a semi-colon ";" char
1307   */
1308  private function ajax_amd_groupSetOrderedTagList($id, $listTag)
1309  {
1310    $tags=explode(';', $listTag);
1311    if($id!="" and count($tags)>0)
1312    {
1313      /*
1314       * by default, all items are set with order equals -1 (if list is not
1315       * complete, forgotten items are sorted in head)
1316       */
1317      pwg_query("UPDATE ".$this->tables['selected_tags']." st
1318                  SET st.order = -1
1319                  WHERE st.groupId = $id;");
1320
1321      foreach($tags as $key=>$val)
1322      {
1323        $sql="UPDATE ".$this->tables['selected_tags']." st, ".$this->tables['used_tags']." ut
1324              SET st.order = $key
1325              WHERE st.groupId = $id
1326                AND st.tagId = ut.tagId
1327                AND ut.numId = $val;";
1328        $result=pwg_query($sql);
1329      }
1330    }
1331  }
1332
1333
1334
1335  /**
1336   * this function update the groups order
1337   *
1338   * @param String $listGroup : the ordered list of groups, items are separated
1339   *                            by a semi-colon ";" char
1340   */
1341  private function ajax_amd_groupSetOrder($listGroup)
1342  {
1343    $groups=explode(";",$listGroup);
1344    if(count($groups)>0)
1345    {
1346      /*
1347       * by default, all items are set with order equals -1 (if list is not
1348       * complete, forgotten items are sorted in head)
1349       */
1350      pwg_query("UPDATE ".$this->tables['groups']." g SET g.order = -1;");
1351
1352      foreach($groups as $key=>$val)
1353      {
1354        $sql="UPDATE ".$this->tables['groups']." g
1355              SET g.order = $key
1356              WHERE g.groupId = $val;";
1357        $result=pwg_query($sql);
1358      }
1359    }
1360  }
1361
1362  /**
1363   * this function is used to create a new group ($groupId = "") or update the
1364   * group name (names are given in all langs in a list)
1365   *
1366   * @param String $groupId : the groupId to update, or "" to create a new groupId
1367   * @param String $listNames : name of the group, in all language given as a
1368   *                            list ; each lang is separated by a carraige
1369   *                            return "\n" char, each items is defined as
1370   *                            lang=value
1371   *                              en_UK=the name group
1372   *                              fr_FR=le nom du groupe
1373   */
1374  private function ajax_amd_groupSetNames($groupId, $listNames)
1375  {
1376    $names=explode("\n", $listNames);
1377    if($groupId=="" and count($names)>0)
1378    {
1379      $sql="INSERT INTO ".$this->tables['groups']." VALUES('', 9999)";
1380      $result=pwg_query($sql);
1381      $groupId=mysql_insert_id();
1382    }
1383
1384    if(is_numeric($groupId) and count($names)>0)
1385    {
1386      $sql="DELETE FROM ".$this->tables['groups_names']."
1387            WHERE groupId = $groupId;";
1388      pwg_query($sql);
1389
1390
1391      $sql="";
1392      foreach($names as $val)
1393      {
1394        $tmp=explode("=", $val);
1395        if($sql!="") $sql.=", ";
1396        $sql.=" ($groupId, '".$tmp[0]."', '".$tmp[1]."')";
1397      }
1398      $sql="INSERT INTO ".$this->tables['groups_names']." VALUES ".$sql;
1399      pwg_query($sql);
1400    }
1401  }
1402
1403  /**
1404   * this function returns an html form, allowing to manage the group
1405   *
1406   * @param String $groupId : the groupId to manage, or "" to return a creation
1407   *                          form
1408   * @return String : the form
1409   */
1410  private function ajax_amd_groupGetNames($groupId)
1411  {
1412    global $user;
1413
1414    $local_tpl = new Template(AMD_PATH."admin/", "");
1415    $local_tpl->set_filename('body_page',
1416                  dirname($this->filelocation).'/admin/amd_metadata_display_groupEdit.tpl');
1417
1418    $datasLang=array(
1419      'language_list' => Array(),
1420      'lang_selected' => $user['language'],
1421      'fromlang' => substr($user['language'],0,2),
1422      'default' => ''
1423    );
1424
1425    $langs=get_languages();
1426    foreach($langs as $key => $val)
1427    {
1428      $datasLang['language_list'][$key] = Array(
1429        'langName' => str_replace("\n", "", $val),
1430        'name' => ""
1431      );
1432    }
1433
1434    if($groupId!="")
1435    {
1436      $sql="SELECT lang, name FROM ".$this->tables['groups_names']."
1437            WHERE groupId = $groupId;";
1438      $result=pwg_query($sql);
1439      if($result)
1440      {
1441        while($row=mysql_fetch_assoc($result))
1442        {
1443          if(array_key_exists($row['lang'], $datasLang['language_list']))
1444          {
1445            $datasLang['language_list'][$row['lang']]['name']=htmlentities($row['name'], ENT_QUOTES, 'UTF-8');
1446            if($user['language']==$row['lang'])
1447            {
1448              $datasLang['default']=$datasLang['language_list'][$row['lang']]['name'];
1449            }
1450          }
1451        }
1452      }
1453    }
1454
1455    $local_tpl->assign('datasLang', $datasLang);
1456
1457    return($local_tpl->parse('body_page', true));
1458  }
1459
1460
1461  /**
1462   * this function returns an html form, allowing to manage the group
1463   *
1464   * @param String $groupId : the groupId to manage, or "" to return a creation
1465   *                          form
1466   * @return String : the form
1467   */
1468  private function ajax_amd_groupGetList()
1469  {
1470    global $user, $template;
1471
1472    //$local_tpl = new Template(AMD_PATH."admin/", "");
1473    $template->set_filename('group_list',
1474                  dirname($this->filelocation).'/admin/amd_metadata_display_groupList.tpl');
1475
1476
1477    $datas=array(
1478      'groups' => Array(),
1479    );
1480
1481    $sql="SELECT g.groupId, gn.name
1482          FROM ".$this->tables['groups']." g
1483            LEFT JOIN ".$this->tables['groups_names']." gn
1484              ON g.groupId = gn.groupId
1485          WHERE gn.lang = '".$user['language']."'
1486          ORDER BY g.order;";
1487    $result=pwg_query($sql);
1488    if($result)
1489    {
1490      while($row=mysql_fetch_assoc($result))
1491      {
1492        $datas['groups'][]=Array(
1493          'id' => $row['groupId'],
1494          'name' => htmlentities($row['name'], ENT_QUOTES, "UTF-8")
1495        );
1496      }
1497    }
1498
1499    $template->assign('datas', $datas);
1500    return($template->parse('group_list', true));
1501  }
1502
1503
1504  /**
1505   * delete the group
1506   * associated tag returns in the available tag list
1507   *
1508   * @param String $groupId : the groupId to delete
1509   */
1510  private function ajax_amd_groupDelete($groupId)
1511  {
1512    if($groupId!="")
1513    {
1514      $sql="DELETE FROM ".$this->tables['groups']."
1515            WHERE groupId = $groupId;";
1516      pwg_query($sql);
1517
1518      $sql="DELETE FROM ".$this->tables['groups_names']."
1519            WHERE groupId = $groupId;";
1520      pwg_query($sql);
1521
1522      $sql="UPDATE ".$this->tables['selected_tags']."
1523            SET groupId = -1
1524            WHERE groupId = $groupId;";
1525      pwg_query($sql);
1526    }
1527  }
1528
1529} // AMD_AIP class
1530
1531
1532?>
Note: See TracBrowser for help on using the repository browser.