source: extensions/AMetaData/amd_ajax.php @ 6729

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

feature:1777

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