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

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

database stay empty after analyze : bug fixed

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