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

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

Some changes on release 0.4b

  • Property svn:executable set to *
File size: 43.1 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($_REQUEST['fAMD_page']);
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($tab)
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->select($tab);
720    $statTabsheet->add('exif',
721                          l10n('g003_help_tab_exif'),
722                          $this->getAdminLink().'&amp;fAMD_tabsheet=help&amp;fAMD_page=exif');
723    $statTabsheet->add('iptc',
724                          l10n('g003_help_tab_iptc'),
725                          $this->getAdminLink().'&amp;fAMD_tabsheet=help&amp;fAMD_page=iptc');
726    $statTabsheet->add('xmp',
727                          l10n('g003_help_tab_xmp'),
728                          $this->getAdminLink().'&amp;fAMD_tabsheet=help&amp;fAMD_page=xmp');
729    $statTabsheet->add('magic',
730                          l10n('g003_help_tab_magic'),
731                          $this->getAdminLink().'&amp;fAMD_tabsheet=help&amp;fAMD_page=magic');
732    $statTabsheet->assign();
733
734    $data=Array(
735      'sheetContent' => GPCCore::BBtoHTML($lang['g003_help_'.$tab]),
736      'title' => l10n('g003_help_tab_'.$tab),
737    );
738
739    $template->assign('data', $data);
740
741    $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page');
742  }
743
744
745  /*
746   * ---------------------------------------------------------------------------
747   * ajax functions
748   * ---------------------------------------------------------------------------
749   */
750
751  /**
752   * return a list of picture Id
753   *
754   * picture id are separated with a space " "
755   * picture id are grouped in blocks of 'amd_NumberOfItemsPerRequest' items and
756   * are separated with a semi-colon ";"
757   *
758   * client side just have to split blocks, and transmit it to the server
759   *
760   * There is two mode to determine the pictures being analyzed :
761   *  - "all"         : analyze all the images
762   *  - "notAnalyzed" : analyze only the images not yet analyzed
763   *
764   * @param String $mode
765   * @param Integer $nbOfItems : number of items per request
766   * @return String : list of image id to be analyzed, separated with a space
767   *                      "23 78 4523 5670"
768   */
769  private function ajax_amd_makeStatsGetList($mode, $nbOfItems)
770  {
771    global $user;
772
773    $returned="";
774    $this->config['amd_NumberOfItemsPerRequest']=$nbOfItems;
775    $this->saveConfig();
776
777    $sql="SELECT ait.imageId FROM ".$this->tables['images']." ait";
778    if($mode=="notAnalyzed")
779    {
780      $sql.=" WHERE ait.analyzed='n'";
781    }
782    elseif($mode=="caddieAdd" or $mode=="caddieReplace")
783    {
784
785      $sql.=" LEFT JOIN ".CADDIE_TABLE." ct ON ait.imageId = ct.element_id
786            WHERE ct.user_id = ".$user['id']." ";
787
788      if($mode=="caddieAdd") $sql.=" AND ait.analyzed='n'";
789    }
790
791    if($mode=="all" or $mode=="caddieReplace")
792    {
793      pwg_query("UPDATE ".$this->tables['images']." SET analyzed='n', nbTags=0");
794      pwg_query("UPDATE ".$this->tables['used_tags']." SET numOfImg=0");
795      pwg_query("DELETE FROM ".$this->tables['images_tags']);
796    }
797
798    $result=pwg_query($sql);
799    if($result)
800    {
801      $i=0;
802      while($row=pwg_db_fetch_row($result))
803      {
804        $returned.=$row[0];
805        $i++;
806        if($i>=$nbOfItems)
807        {
808          $returned.=";";
809          $i=0;
810        }
811        else
812        {
813          $returned.=" ";
814        }
815      }
816    }
817    return(trim($returned).";");
818  }
819
820
821  /**
822   * extract metadata from images
823   *
824   * @param String $imageList : list of image id to be analyzed, separated with
825   *                            a space
826   *                                "23 78 4523 5670"
827   * @return String : list of the analyzed pictures, with number of tags found
828   *                  for each picture
829   *                    "23=0;78=66;4523=33;5670=91;"
830   */
831  private function ajax_amd_makeStatsDoAnalyze($imagesList)
832  {
833    $list=explode(" ", trim($imagesList));
834
835    $returned="";
836
837    if(count($list)>0 and trim($imagesList)!='')
838    {
839      // $path = path of piwigo's on the server filesystem
840      $path=dirname(dirname(dirname(__FILE__)));
841
842      $sql="SELECT id, path FROM ".IMAGES_TABLE." WHERE id IN (".implode(", ", $list).")";
843      $result=pwg_query($sql);
844      if($result)
845      {
846        while($row=pwg_db_fetch_assoc($result))
847        {
848          /*
849           * in some case (in a combination of some pictures), when there is too
850           * much pictures to analyze in the same request, a fatal error occurs
851           * with the message : "Allowed memory size of XXXXX bytes exhausted"
852           *
853           *
854           * tracking memory leak is not easy... :-(
855           *
856           */
857          //echo "analyzing:".$row['id']."\n";
858          //$mem1=memory_get_usage();
859          //echo "memory before analyze:".$mem1."\n";
860          $returned.=$this->analyzeImageFile($path."/".$row['path'], $row['id']);
861          //echo $returned."\n";
862          //$mem2=memory_get_usage();
863          //echo "memory after analyze:".$mem2." (".($mem2-$mem1).")\n";
864        }
865      }
866    }
867    return($returned);
868  }
869
870  /**
871   * do some consolidation on database to optimize other requests
872   *
873   */
874  private function ajax_amd_makeStatsConsolidation()
875  {
876    $this->makeStatsConsolidation();
877  }
878
879  /**
880   * returns a list of formated string, separated with a semi-colon :
881   *  - number of current analyzed pictures + number of current analyzed tags
882   *    for the analyzed pictures
883   *  - number of pictures not analyzed
884   *  - number of pictures without tag
885   *
886   * @return String
887   */
888  private function ajax_amd_makeStatsGetStatus()
889  {
890    $numOfMetaData=0;
891    $numOfPictures=0;
892    $numOfPicturesNotAnalyzed=0;
893
894    $sql="SELECT COUNT(imageId), SUM(nbTags) FROM ".$this->tables['images']."
895            WHERE analyzed='y';";
896    $result=pwg_query($sql);
897    if($result)
898    {
899      while($row=pwg_db_fetch_row($result))
900      {
901        $numOfPictures=$row[0];
902        $numOfMetaData=$row[1];
903      }
904    }
905
906
907    $sql="SELECT COUNT(imageId) FROM ".$this->tables['images']."
908            WHERE analyzed='n';";
909    $result=pwg_query($sql);
910    if($result)
911    {
912      while($row=pwg_db_fetch_row($result))
913      {
914        $numOfPicturesNotAnalyzed=$row[0];
915      }
916    }
917
918    $sql="SELECT COUNT(imageId) FROM ".$this->tables['images']."
919            WHERE nbTags=0;";
920    $result=pwg_query($sql);
921    if($result)
922    {
923      while($row=pwg_db_fetch_row($result))
924      {
925        $numOfPicturesWithoutTags=$row[0];
926      }
927    }
928
929    return(sprintf(l10n("g003_numberOfAnalyzedPictures"), $numOfPictures, $numOfMetaData).";".
930              sprintf(l10n("g003_numberOfNotAnalyzedPictures"), $numOfPicturesNotAnalyzed).";".
931              sprintf(l10n("g003_numberOfPicturesWithoutTags"), $numOfPicturesWithoutTags));
932  }
933
934
935  /**
936   * return a formatted <table> (using the template "amd_stat_show_iListTags")
937   * of used tag with, for each tag, the number and the percentage of pictures
938   * where the tag was found
939   *
940   * @param String $orderType : order for the list (by tag 'tag' or by number of
941   *                            pictures 'num')
942   * @param String $filterType : filter for the list ('exif', 'xmp', 'iptc' or '')
943   * @return String
944   */
945  private function ajax_amd_showStatsGetListTags($orderType, $filterType, $excludeUnusedTag, $selectedTagOnly)
946  {
947    global $template;
948
949    $this->config['amd_GetListTags_OrderType'] = $orderType;
950    $this->config['amd_GetListTags_FilterType'] = $filterType;
951    $this->config['amd_GetListTags_ExcludeUnusedTag'] = $excludeUnusedTag;
952    $this->config['amd_GetListTags_SelectedTagOnly'] = $selectedTagOnly;
953    $this->saveConfig();
954
955    $local_tpl = new Template(AMD_PATH."admin/", "");
956    $local_tpl->set_filename('body_page',
957                  dirname($this->getFileLocation()).'/admin/amd_metadata_select_iListTags.tpl');
958
959    $numOfPictures=$this->getNumOfPictures();
960
961    $datas=array();
962    $sql="SELECT ut.numId, ut.tagId, ut.translatable, ut.name, ut.numOfImg, if(st.tagId IS NULL, 'n', 'y') as checked, ut.translatedName
963            FROM ".$this->tables['used_tags']." ut
964              LEFT JOIN ".$this->tables['selected_tags']." st
965                ON st.tagId = ut.tagId ";
966    $where="";
967
968    if($filterType!='')
969    {
970      if($filterType=='exif')
971      {
972        $where.=" WHERE ut.tagId LIKE 'exif.tiff.%'
973                    OR ut.tagId LIKE 'exif.exif.%'
974                    OR ut.tagId LIKE 'exif.gps.%'  ";
975      }
976      else
977      {
978        $where.=" WHERE ut.tagId LIKE '".$filterType.".%' ";
979      }
980    }
981
982    if($excludeUnusedTag=='y')
983    {
984      ($where=="")?$where=" WHERE ":$where.=" AND ";
985      $where.=" ut.numOfImg > 0 ";
986    }
987
988    if($selectedTagOnly=='y')
989    {
990      ($where=="")?$where=" WHERE ":$where.=" AND ";
991      $where.=" st.tagId IS NOT NULL ";
992    }
993
994    $sql.=$where;
995
996    switch($orderType)
997    {
998      case 'tag':
999        $sql.=" ORDER BY tagId ASC";
1000        break;
1001      case 'num':
1002        $sql.=" ORDER BY numOfImg DESC, tagId ASC";
1003        break;
1004      case 'label':
1005        $sql.=" ORDER BY translatedName ASC, tagId ASC";
1006        break;
1007    }
1008
1009    $result=pwg_query($sql);
1010    if($result)
1011    {
1012      while($row=pwg_db_fetch_assoc($result))
1013      {
1014        $datas[]=array(
1015          "numId" => $row['numId'],
1016          "tagId" => $row['tagId'],
1017          "label" => L10n::get($row['name']),
1018          "nb"    => $row['numOfImg'],
1019          "pct"   => ($numOfPictures!=0)?sprintf("%.2f", 100*$row['numOfImg']/$numOfPictures):"0",
1020          "tagChecked" => ($row['checked']=='y')?"checked":""
1021        );
1022      }
1023    }
1024
1025    $local_tpl->assign('themeconf', Array('name' => $template->get_themeconf('name')));
1026    $local_tpl->assign('datas', $datas);
1027
1028    return($local_tpl->parse('body_page', true));
1029  }
1030
1031
1032  /*
1033   *
1034   *
1035   */
1036  private function ajax_amd_showStatsGetListImages($tagId, $orderType)
1037  {
1038    global $template;
1039
1040    $this->config['amd_GetListImages_OrderType'] = $orderType;
1041    $this->saveConfig();
1042
1043    $local_tpl = new Template(AMD_PATH."admin/", "");
1044    $local_tpl->set_filename('body_page',
1045                  dirname($this->getFileLocation()).'/admin/amd_metadata_select_iListImages.tpl');
1046
1047
1048
1049    $datas=array();
1050    $sql="SELECT ut.translatable, ut.numOfImg, COUNT(it.imageId) AS Nb, it.value
1051            FROM ".$this->tables['used_tags']." ut
1052              LEFT JOIN ".$this->tables['images_tags']." it
1053              ON ut.numId = it.numId
1054            WHERE ut.tagId = '".$tagId."'
1055              AND it.value IS NOT NULL
1056            GROUP BY it.value
1057            ORDER BY ";
1058    switch($orderType)
1059    {
1060      case 'value':
1061        $sql.="it.value ASC";
1062        break;
1063      case 'num':
1064        $sql.="Nb DESC";
1065        break;
1066    }
1067
1068    $result=pwg_query($sql);
1069    if($result)
1070    {
1071      while($row=pwg_db_fetch_assoc($result))
1072      {
1073        $datas[]=array(
1074          "value" => $this->prepareValueForDisplay($row['value'], ($row['translatable']=='y'), ", "),
1075          "nb"    => $row['Nb'],
1076          "pct"   => ($row['numOfImg']!=0)?sprintf("%.2f", 100*$row['Nb']/$row['numOfImg']):"-"
1077        );
1078      }
1079    }
1080
1081    if(count($datas)>0)
1082    {
1083      $local_tpl->assign('themeconf', Array('name' => $template->get_themeconf('name')));
1084      $local_tpl->assign('datas', $datas);
1085      return($local_tpl->parse('body_page', true));
1086    }
1087    else
1088    {
1089      return("<div style='width:100%;text-align:center;padding-top:20px;'>".l10n('g003_selected_tag_isnot_linked_with_any_picture')."</div>");
1090    }
1091  }
1092
1093
1094  /*
1095   *
1096   *
1097   */
1098  private function ajax_amd_updateTagSelect($numId, $selected)
1099  {
1100    if($selected=='y')
1101    {
1102      $sql="SELECT ut.tagId FROM ".$this->tables['selected_tags']." st
1103              LEFT JOIN ".$this->tables['used_tags']." ut
1104                ON ut.tagID = st.tagId
1105              WHERE ut.numId = $numId;";
1106      $result=pwg_query($sql);
1107      if($result)
1108      {
1109        if(pwg_db_num_rows($result)==0)
1110        {
1111          $sql="INSERT INTO ".$this->tables['selected_tags']."
1112                  SELECT ut.tagId, 0, -1
1113                  FROM ".$this->tables['used_tags']." ut
1114                    LEFT JOIN ".$this->tables['selected_tags']." st
1115                      ON ut.tagID = st.tagId
1116                  WHERE ut.numId = $numId;";
1117          pwg_query($sql);
1118        }
1119      }
1120    }
1121    elseif($selected=='n')
1122    {
1123      $sql="DELETE FROM ".$this->tables['selected_tags']." st
1124              USING ".$this->tables['used_tags']." ut
1125                LEFT JOIN ".$this->tables['selected_tags']." st
1126                  ON ut.tagID = st.tagId
1127              WHERE ut.numId = $numId;";
1128      pwg_query($sql);
1129    }
1130
1131  }
1132
1133
1134  /**
1135   * this function return the list of tags :
1136   *  - associated with the group
1137   *  - not associated with a group
1138   * the list is used to make tags selection
1139   *
1140   * @param String $id      : Id of the current group
1141   * @return String : an HTML formatted list with checkbox
1142   */
1143  private function ajax_amd_groupGetTagList($id)
1144  {
1145    global $template;
1146
1147    if($id!="")
1148    {
1149      $sql="SELECT st.tagId, st.groupId, ut.name, ut.numId
1150            FROM ".$this->tables['selected_tags']." st
1151              LEFT JOIN ".$this->tables['used_tags']." ut
1152                ON st.tagId = ut.tagId
1153            ORDER BY tagId";
1154      $result=pwg_query($sql);
1155      if($result)
1156      {
1157        $datas=Array();
1158        while($row=pwg_db_fetch_assoc($result))
1159        {
1160          if($row['groupId']==$id)
1161          {
1162            $state="checked";
1163          }
1164          elseif($row['groupId']==-1)
1165          {
1166            $state="";
1167          }
1168          else
1169          {
1170            $state="n/a";
1171          }
1172
1173          if($state!="n/a")
1174            $datas[]=Array(
1175              'tagId' => $row['tagId'],
1176              'name'  => L10n::get($row['name']),
1177              'state' => $state,
1178              'numId' => $row['numId']
1179            );
1180        }
1181
1182        if(count($datas)>0)
1183        {
1184          $local_tpl = new Template(AMD_PATH."admin/", "");
1185          $local_tpl->set_filename('body_page',
1186                        dirname($this->getFileLocation()).'/admin/amd_metadata_display_groupListTagSelect.tpl');
1187          $local_tpl->assign('themeconf', Array('name' => $template->get_themeconf('name')));
1188          $local_tpl->assign('datas', $datas);
1189          return($local_tpl->parse('body_page', true));
1190        }
1191        else
1192        {
1193          return(l10n("g003_no_tag_can_be_selected"));
1194        }
1195      }
1196    }
1197    else
1198    {
1199      return(l10n("g003_invalid_group_id"));
1200    }
1201  }
1202
1203
1204  /**
1205   * this function associate tags to a group
1206   *
1207   * @param String $id      : Id of group
1208   * @param String $listTag : list of selected tags, items are separated by a
1209   *                          semi-colon ";" char
1210   */
1211  private function ajax_amd_groupSetTagList($id, $listTag)
1212  {
1213    if($id!="")
1214    {
1215      $sql="UPDATE ".$this->tables['selected_tags']."
1216            SET groupId = -1
1217            WHERE groupId = $id;";
1218      pwg_query($sql);
1219
1220      if($listTag!="")
1221      {
1222        $sql="UPDATE ".$this->tables['selected_tags']." st, ".$this->tables['used_tags']." ut
1223              SET st.groupId = $id
1224              WHERE st.tagId = ut.tagId
1225                AND ut.numId IN ($listTag);";
1226        pwg_query($sql);
1227      }
1228    }
1229    else
1230    {
1231      return("KO");
1232    }
1233  }
1234
1235
1236  /**
1237   * this function returns an ordered list of tags associated with a group
1238   *
1239   * @param String $id        : the group Id
1240   * @return String : an HTML formatted list
1241   */
1242  private function ajax_amd_groupGetOrderedTagList($id)
1243  {
1244    global $template;
1245    if($id!="")
1246    {
1247      $numOfPictures=$this->getNumOfPictures();
1248
1249      $sql="SELECT st.tagId, ut.name, ut.numId, ut.numOfImg
1250            FROM ".$this->tables['selected_tags']." st
1251              LEFT JOIN ".$this->tables['used_tags']." ut
1252                ON st.tagId = ut.tagId
1253            WHERE st.groupId = $id
1254            ORDER BY st.order ASC, st.tagId ASC";
1255      $result=pwg_query($sql);
1256      if($result)
1257      {
1258        $datas=Array();
1259        while($row=pwg_db_fetch_assoc($result))
1260        {
1261          $datas[]=Array(
1262            'tagId' => $row['tagId'],
1263            'name'  => L10n::get($row['name']),
1264            'numId' => $row['numId'],
1265            'nbItems' => $row['numOfImg'],
1266            'pct'   => ($numOfPictures==0)?"0":sprintf("%.2f", 100*$row['numOfImg']/$numOfPictures)
1267          );
1268        }
1269
1270        if(count($datas)>0)
1271        {
1272          $template->set_filename('list_page',
1273                        dirname($this->getFileLocation()).'/admin/amd_metadata_display_groupListTagOrder.tpl');
1274          $template->assign('datas', $datas);
1275          $template->assign('group', $id);
1276          return($template->parse('list_page', true));
1277        }
1278        else
1279        {
1280          return(l10n("g003_no_tag_can_be_selected"));
1281        }
1282      }
1283    }
1284    else
1285    {
1286      return(l10n("g003_invalid_group_id"));
1287    }
1288  }
1289
1290
1291  /**
1292   * this function update the tags order inside a group
1293   *
1294   * @param String $id        : the group Id
1295   * @param String $listGroup : the ordered list of tags, items are separated
1296   *                            by a semi-colon ";" char
1297   */
1298  private function ajax_amd_groupSetOrderedTagList($id, $listTag)
1299  {
1300    $tags=explode(';', $listTag);
1301    if($id!="" and count($tags)>0)
1302    {
1303      /*
1304       * by default, all items are set with order equals -1 (if list is not
1305       * complete, forgotten items are sorted in head)
1306       */
1307      pwg_query("UPDATE ".$this->tables['selected_tags']." st
1308                  SET st.order = -1
1309                  WHERE st.groupId = $id;");
1310
1311      foreach($tags as $key=>$val)
1312      {
1313        $sql="UPDATE ".$this->tables['selected_tags']." st, ".$this->tables['used_tags']." ut
1314              SET st.order = $key
1315              WHERE st.groupId = $id
1316                AND st.tagId = ut.tagId
1317                AND ut.numId = $val;";
1318        $result=pwg_query($sql);
1319      }
1320    }
1321  }
1322
1323
1324
1325  /**
1326   * this function update the groups order
1327   *
1328   * @param String $listGroup : the ordered list of groups, items are separated
1329   *                            by a semi-colon ";" char
1330   */
1331  private function ajax_amd_groupSetOrder($listGroup)
1332  {
1333    $groups=explode(";",$listGroup);
1334    if(count($groups)>0)
1335    {
1336      /*
1337       * by default, all items are set with order equals -1 (if list is not
1338       * complete, forgotten items are sorted in head)
1339       */
1340      pwg_query("UPDATE ".$this->tables['groups']." g SET g.order = -1;");
1341
1342      foreach($groups as $key=>$val)
1343      {
1344        $sql="UPDATE ".$this->tables['groups']." g
1345              SET g.order = $key
1346              WHERE g.groupId = $val;";
1347        $result=pwg_query($sql);
1348      }
1349    }
1350  }
1351
1352  /**
1353   * this function is used to create a new group ($groupId = "") or update the
1354   * group name (names are given in all langs in a list)
1355   *
1356   * @param String $groupId : the groupId to update, or "" to create a new groupId
1357   * @param String $listNames : name of the group, in all language given as a
1358   *                            list ; each lang is separated by a carraige
1359   *                            return "\n" char, each items is defined as
1360   *                            lang=value
1361   *                              en_UK=the name group
1362   *                              fr_FR=le nom du groupe
1363   */
1364  private function ajax_amd_groupSetNames($groupId, $listNames)
1365  {
1366    $names=explode("\n", $listNames);
1367    if($groupId=="" and count($names)>0)
1368    {
1369      $sql="INSERT INTO ".$this->tables['groups']." VALUES('', 9999)";
1370      $result=pwg_query($sql);
1371      $groupId=pwg_db_insert_id();
1372    }
1373
1374    if(is_numeric($groupId) and count($names)>0)
1375    {
1376      $sql="DELETE FROM ".$this->tables['groups_names']."
1377            WHERE groupId = $groupId;";
1378      pwg_query($sql);
1379
1380
1381      $sql="";
1382      foreach($names as $val)
1383      {
1384        $tmp=explode("=", $val);
1385        if($sql!="") $sql.=", ";
1386        $sql.=" ($groupId, '".$tmp[0]."', '".$tmp[1]."')";
1387      }
1388      $sql="INSERT INTO ".$this->tables['groups_names']." VALUES ".$sql;
1389      pwg_query($sql);
1390    }
1391  }
1392
1393  /**
1394   * this function returns an html form, allowing to manage the group
1395   *
1396   * @param String $groupId : the groupId to manage, or "" to return a creation
1397   *                          form
1398   * @return String : the form
1399   */
1400  private function ajax_amd_groupGetNames($groupId)
1401  {
1402    global $user;
1403
1404    $local_tpl = new Template(AMD_PATH."admin/", "");
1405    $local_tpl->set_filename('body_page',
1406                  dirname($this->getFileLocation()).'/admin/amd_metadata_display_groupEdit.tpl');
1407
1408    $datasLang=array(
1409      'language_list' => Array(),
1410      'lang_selected' => $user['language'],
1411      'fromlang' => substr($user['language'],0,2),
1412      'default' => ''
1413    );
1414
1415    $langs=get_languages();
1416    foreach($langs as $key => $val)
1417    {
1418      $datasLang['language_list'][$key] = Array(
1419        'langName' => str_replace("\n", "", $val),
1420        'name' => ""
1421      );
1422    }
1423
1424    if($groupId!="")
1425    {
1426      $sql="SELECT lang, name FROM ".$this->tables['groups_names']."
1427            WHERE groupId = $groupId;";
1428      $result=pwg_query($sql);
1429      if($result)
1430      {
1431        while($row=pwg_db_fetch_assoc($result))
1432        {
1433          if(array_key_exists($row['lang'], $datasLang['language_list']))
1434          {
1435            $datasLang['language_list'][$row['lang']]['name']=htmlentities($row['name'], ENT_QUOTES, 'UTF-8');
1436            if($user['language']==$row['lang'])
1437            {
1438              $datasLang['default']=$datasLang['language_list'][$row['lang']]['name'];
1439            }
1440          }
1441        }
1442      }
1443    }
1444
1445    $local_tpl->assign('datasLang', $datasLang);
1446
1447    return($local_tpl->parse('body_page', true));
1448  }
1449
1450
1451  /**
1452   * this function returns an html form, allowing to manage the group
1453   *
1454   * @param String $groupId : the groupId to manage, or "" to return a creation
1455   *                          form
1456   * @return String : the form
1457   */
1458  private function ajax_amd_groupGetList()
1459  {
1460    global $user, $template;
1461
1462    //$local_tpl = new Template(AMD_PATH."admin/", "");
1463    $template->set_filename('group_list',
1464                  dirname($this->getFileLocation()).'/admin/amd_metadata_display_groupList.tpl');
1465
1466
1467    $datas=array(
1468      'groups' => Array(),
1469    );
1470
1471    $sql="SELECT g.groupId, gn.name
1472          FROM ".$this->tables['groups']." g
1473            LEFT JOIN ".$this->tables['groups_names']." gn
1474              ON g.groupId = gn.groupId
1475          WHERE gn.lang = '".$user['language']."'
1476          ORDER BY g.order;";
1477    $result=pwg_query($sql);
1478    if($result)
1479    {
1480      while($row=pwg_db_fetch_assoc($result))
1481      {
1482        $datas['groups'][]=Array(
1483          'id' => $row['groupId'],
1484          'name' => htmlentities($row['name'], ENT_QUOTES, "UTF-8")
1485        );
1486      }
1487    }
1488
1489    $template->assign('datas', $datas);
1490    return($template->parse('group_list', true));
1491  }
1492
1493
1494  /**
1495   * delete the group
1496   * associated tag returns in the available tag list
1497   *
1498   * @param String $groupId : the groupId to delete
1499   */
1500  private function ajax_amd_groupDelete($groupId)
1501  {
1502    if($groupId!="")
1503    {
1504      $sql="DELETE FROM ".$this->tables['groups']."
1505            WHERE groupId = $groupId;";
1506      pwg_query($sql);
1507
1508      $sql="DELETE FROM ".$this->tables['groups_names']."
1509            WHERE groupId = $groupId;";
1510      pwg_query($sql);
1511
1512      $sql="UPDATE ".$this->tables['selected_tags']."
1513            SET groupId = -1
1514            WHERE groupId = $groupId;";
1515      pwg_query($sql);
1516    }
1517  }
1518
1519} // AMD_AIP class
1520
1521
1522?>
Note: See TracBrowser for help on using the repository browser.