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

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

Add Spanish translation (incomplete) + improve help page

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