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

Last change on this file since 31810 was 28815, checked in by Youp3, 10 years ago

Advanced Meta Data : prise en compte de la modification l10n / translate + sprintf

  • Property svn:executable set to *
File size: 23.9 KB
RevLine 
[4905]1<?php
2/*
3 * -----------------------------------------------------------------------------
4 * Plugin Name: Advanced MetaData
5 * -----------------------------------------------------------------------------
6 * Author     : Grum
7 *   email    : grum@piwigo.org
8 *   website  : http://photos.grum.fr
9 *   PWG user : http://forum.piwigo.org/profile.php?id=3706
10 *
11 *   << May the Little SpaceFrog be with you ! >>
12 *
13 * -----------------------------------------------------------------------------
14 *
15 * See main.inc.php for release information
16 *
17 * AIP classe => manage integration in administration interface
18 *
19 * -----------------------------------------------------------------------------
20 */
21
22if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); }
23
24include_once('amd_root.class.inc.php');
[5935]25include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTabSheet.class.inc.php');
26include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/genericjs.class.inc.php');
[4905]27
28
29class AMD_AIP extends AMD_root
30{
31  protected $tabsheet;
32
33  /**
34   *
35   * constructor needs the prefix of piwigo's tables and the location of plugin
36   *
37   * @param String $prefixeTable
38   * @param String $filelocation
39   */
[5183]40  public function __construct($prefixeTable, $filelocation)
[4905]41  {
42    parent::__construct($prefixeTable, $filelocation);
43
[5935]44    $this->loadConfig();
[6729]45    $this->configForTemplate();
[5935]46    $this->initEvents();
[4905]47
48    $this->tabsheet = new tabsheet();
[6919]49
[6950]50    if($this->config['amd_InterfaceMode']=='basic')
[6919]51    {
52      $this->tabsheet->add('metadata',
53                            l10n('g003_metadata'),
[15343]54                            $this->getAdminLink().'-metadata');
[6919]55      $this->tabsheet->add('help',
56                            l10n('g003_help'),
[15343]57                            $this->getAdminLink().'-help');
[6919]58    }
59    else
60    {
61      $this->tabsheet->add('database',
62                            l10n('g003_database'),
[15343]63                            $this->getAdminLink().'-database');
[6919]64      $this->tabsheet->add('metadata',
65                            l10n('g003_metadata'),
[15343]66                            $this->getAdminLink().'-metadata');
[6919]67      $this->tabsheet->add('search',
68                            l10n('g003_search'),
[15343]69                            $this->getAdminLink().'-search');
[6950]70      $this->tabsheet->add('tags',
71                            l10n('g003_tags'),
[15343]72                            $this->getAdminLink().'-tags');
[6919]73      $this->tabsheet->add('help',
74                            l10n('g003_help'),
[15343]75                            $this->getAdminLink().'-help');
[6919]76    }
[4905]77  }
78
[5183]79  public function __destruct()
[4905]80  {
81    unset($this->tabsheet);
[5183]82    parent::__destruct();
[4905]83  }
84
85
86  /*
87   * ---------------------------------------------------------------------------
88   * Public classe functions
89   * ---------------------------------------------------------------------------
90   */
91
92
93  /**
94   * manage the plugin integration into piwigo's admin interface
95   */
96  public function manage()
97  {
98    global $template, $page;
99
100    $this->initRequest();
101
[6722]102    $template->set_filename('plugin_admin_content', dirname(__FILE__)."/admin/amd_admin.tpl");
[4905]103
[15343]104    $this->tabsheet->select($_GET['tab']);
[4905]105    $this->tabsheet->assign();
106    $selected_tab=$this->tabsheet->get_selected();
107    $template->assign($this->tabsheet->get_titlename(), "[".$selected_tab['caption']."]");
108
[6722]109    $pluginInfo=array(
110      'AMD_VERSION' => "<i>".$this->getPluginName()."</i> ".l10n('g003_version').AMD_VERSION,
[15343]111      'AMD_PAGE' => $_GET['tab'],
[6722]112      'PATH' => AMD_PATH
113    );
[4905]114
[6722]115    $template->assign('plugin', $pluginInfo);
[16007]116    GPCCore::setTemplateToken();
[4905]117
[15343]118    switch($_GET['tab'])
[4905]119    {
[6722]120      case 'help':
121        $this->displayHelp();
122        break;
123      case 'database':
[15343]124        $this->displayDatabase($_REQUEST['t']);
[6722]125        break;
126      case 'metadata':
[15343]127        $this->displayMetaData($_REQUEST['t']);
[6722]128        break;
129      case 'search':
[15343]130        $this->displaySearch($_REQUEST['t']);
[6722]131        break;
[6950]132      case 'tags':
133        $this->displayTags();
134        break;
[4905]135    }
136
137    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
138  }
139
140  /**
141   * initialize events call for the plugin
[5935]142   *
143   * don't inherits from its parent => it's normal
[4905]144   */
[5935]145  public function initEvents()
[4905]146  {
[16007]147    parent::initEvents();
148
[15343]149    if(isset($_GET['tab']) and $_GET['tab']=='search')
[6891]150    {
151      // load request builder JS only on the search page
152      GPCRequestBuilder::loadJSandCSS();
153    }
[4905]154  }
155
[16007]156
[4905]157  /**
158   * ---------------------------------------------------------------------------
159   * Private & protected functions
160   * ---------------------------------------------------------------------------
161   */
162
163  /**
164   * if empty, initialize the $_REQUEST var
165   *
166   * if not empty, check validity for the request values
167   *
168   */
169  private function initRequest()
170  {
171    //initialise $REQUEST values if not defined
172
[15343]173    if(!isset($_GET['tab']))
[4905]174    {
[6950]175      if($this->getNumOfPictures()==0 and $this->config['amd_InterfaceMode']=='advanced')
[6722]176      {
[15343]177        $_GET['tab']="database";
178        $_REQUEST['t']="state";
[6722]179      }
180      else
181      {
[15343]182        $_GET['tab']="metadata";
183        $_REQUEST['t']="select";
[6722]184      }
[4905]185    }
186
[15343]187    $tmp=explode('/', $_GET['tab'].'/');
188    $_GET['tab']=$tmp[0];
189    $_REQUEST['t']=$tmp[1];
190
191
192    if(!($_GET['tab']=="metadata" or
193         $_GET['tab']=="help" or
194         $_GET['tab']=="database" or
195         $_GET['tab']=="search" or
196         $_GET['tab']=="tags")
[6919]197         or
[6950]198         $this->config['amd_InterfaceMode']=='basic' and
[6919]199         (
[15343]200           $_GET['tab']=="database" or
201           $_GET['tab']=="search" or
202           $_GET['tab']=="tags"
[6919]203         )
204      )
[4905]205    {
[15343]206      $_GET['tab']="metadata";
[4905]207    }
208
[6722]209    /*
210     * metadata tabsheet
211     */
[15343]212    if($_GET['tab']=="metadata")
[4905]213    {
[15343]214      if(!isset($_REQUEST['t']))
[6919]215      {
[6950]216        if($this->config['amd_InterfaceMode']=='basic')
[6919]217        {
[15343]218          $_REQUEST['t']="display";
[6919]219        }
220        else
221        {
[15343]222          $_REQUEST['t']="select";
[6919]223        }
224      }
[6722]225
[15343]226      if(!($_REQUEST['t']=="personnal" or
227           $_REQUEST['t']=="select" or
228           $_REQUEST['t']=="display")
[6919]229           or
[6950]230           $this->config['amd_InterfaceMode']=='basic' and
[6919]231           (
[15343]232             $_REQUEST['t']=="select"
[6919]233           )
234        )
235      {
[6950]236        if($this->config['amd_InterfaceMode']=='basic')
[6919]237        {
[15343]238          $_REQUEST['t']="display";
[6919]239        }
240        else
241        {
[15343]242          $_REQUEST['t']="select";
[6919]243        }
244      }
[4905]245    }
246
[6722]247    /*
248     * help tabsheet
249     */
[15343]250    if($_GET['tab']=="help")
[4905]251    {
[15343]252      if(!isset($_REQUEST['t'])) $_REQUEST['t']="exif";
[6722]253
[15343]254      if(!($_REQUEST['t']=="exif" or
255           $_REQUEST['t']=="iptc" or
256           $_REQUEST['t']=="xmp" or
257           $_REQUEST['t']=="magic")) $_REQUEST['t']="exif";
[4905]258    }
259
[6722]260    /*
261     * search tabsheet
262     */
[15343]263    if($_GET['tab']=="search")
[5191]264    {
[15343]265      if(!isset($_REQUEST['t'])) $_REQUEST['t']="search";
[5191]266
[15343]267      if(!($_REQUEST['t']=="config" or
268           $_REQUEST['t']=="search")) $_REQUEST['t']="search";
[5191]269    }
270
[4905]271    /*
[6722]272     * database tabsheet
[4905]273     */
[15343]274    if($_GET['tab']=="database")
[4905]275    {
[15343]276      if(!isset($_REQUEST['t'])) $_REQUEST['t']="state";
[4905]277
[15343]278      if(!($_REQUEST['t']=="state" or
279           $_REQUEST['t']=="update")) $_REQUEST['t']="state";
[6722]280    }
[4905]281
[6950]282
[4905]283  } //init_request
284
285
286  /**
287   * manage adviser profile
288   *
289   * @return Boolean : true if user is adviser, otherwise false (and push a
290   *                   message in the error list)
291   */
292  protected function adviser_abort()
293  {
294    if(is_adviser())
295    {
296      $this->display_result(l10n("g003_adviser_not_allowed"), false);
297      return(true);
298    }
299    return(false);
300  }
301
302
[6891]303
304
[4905]305  /**
[6891]306   * display and manage the search page
307   */
308  protected function displaySearch()
309  {
310    global $template, $lang;
311
312    $template->set_filename('body_page',
313                dirname($this->getFileLocation()).'/admin/amd_metadata_search.tpl');
314
[7564]315    $template->assign('amd_search_page', GPCRequestBuilder::displaySearchPage('AMetaData'));
[6891]316
317    $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page');
318  }
319
320
321
322
323  /**
[4905]324   * display and manage the metadata page
[5191]325   * the page have three tabsheet :
[6722]326   *  - personnal tag management, to build personnal tags
[4905]327   *  - select tag management, to manage tags to be selected on the galerie
328   *  - display tag management, to choose how the tags are displayed
329   *
330   * @param String $tab : the selected tab on the stat page
331   */
332  protected function displayMetaData($tab)
333  {
334    global $template, $user;
335    $template->set_filename('body_page', dirname(__FILE__).'/admin/amd_metadata.tpl');
336
[5935]337    $statTabsheet = new GPCTabSheet('statTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itab2');
[4905]338    $statTabsheet->select($tab);
[6722]339    $statTabsheet->add('personnal',
340                          l10n('g003_personnal'),
[15343]341                          $this->getAdminLink().'-metadata/personnal');
[6950]342    if($this->config['amd_InterfaceMode']=='advanced')
[6919]343    {
344      $statTabsheet->add('select',
345                            l10n('g003_select'),
[15343]346                            $this->getAdminLink().'-metadata/select');
[6919]347    }
[4905]348    $statTabsheet->add('display',
349                          l10n('g003_display'),
[15343]350                          $this->getAdminLink().'-metadata/display');
[4905]351    $statTabsheet->assign();
352
[6722]353    switch($tab)
354    {
355      case 'select':
356        $template->assign('sheetContent', $this->displayMetaDataSelect());
357        break;
358      case 'display':
359        $template->assign('sheetContent', $this->displayMetaDataDisplay());
360        break;
361      case 'personnal':
362        $template->assign('sheetContent', $this->displayMetaDataPersonnal());
363        break;
364    }
[4905]365
[6722]366    $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page');
367  }
[4905]368
[6722]369
370  /**
371   * display and manage the metadata page allowing to build user defined tags
372   *
373   * @return String : the content of the page
374   */
375  protected function displayMetaDataPersonnal()
376  {
[6950]377    global $template, $theme, $themes, $themeconf, $lang;
[6722]378
379    $template->set_filename('sheet_page',
380                  dirname($this->getFileLocation()).'/admin/amd_metadata_personnal.tpl');
381
382    $datas=array(
383      'urlRequest' => $this->getAdminLink('ajax'),
384      'tagList' => array(),
385    );
386
387    /*
388     * build tagList
389     */
390    $sql="SELECT ut.name, ut.numId, ut.tagId
391          FROM ".$this->tables['used_tags']." ut
392            JOIN ".$this->tables['selected_tags']." st ON st.tagId = ut.tagId
393          ORDER BY tagId";
394    $result=pwg_query($sql);
395    if($result)
[4905]396    {
[6722]397      while($row=pwg_db_fetch_assoc($result))
398      {
399        $datas['tagList'][]=Array(
400          'tagId' => $row['tagId'],
401          'name'  => L10n::get($row['name']),
402          'numId' => $row['numId']
403        );
404      }
[4905]405    }
406
[6950]407    $lang['g003_personnal_page_help']=GPCCore::BBtoHTML($lang['g003_personnal_page_help']);
408
[6722]409    $template->assign('datas', $datas);
410    return($template->parse('sheet_page', true));
[4905]411  }
412
[6722]413
[4905]414  /**
415   * display and manage the metadata page allowing to make tags selection
416   *
417   * @return String : the content of the page
418   */
419  protected function displayMetaDataSelect()
420  {
[6950]421    global $template, $theme, $themes, $themeconf, $lang;
[4905]422
423    $template->set_filename('sheet_page',
[5935]424                  dirname($this->getFileLocation()).'/admin/amd_metadata_select.tpl');
[4905]425
426    $datas=array(
[6722]427      'urlRequest' => $this->getAdminLink('ajax'),
[5935]428      'config_GetListTags_OrderType' => $this->config['amd_GetListTags_OrderType'],
429      'config_GetListTags_FilterType' => $this->config['amd_GetListTags_FilterType'],
430      'config_GetListTags_ExcludeUnusedTag' => $this->config['amd_GetListTags_ExcludeUnusedTag'],
431      'config_GetListTags_SelectedTagOnly' => $this->config['amd_GetListTags_SelectedTagOnly'],
432      'config_GetListImages_OrderType' => $this->config['amd_GetListImages_OrderType']
[4905]433    );
434
[6950]435    $lang['g003_select_page_help']=GPCCore::BBtoHTML($lang['g003_select_page_help']);
436
[4905]437    $template->assign('datas', $datas);
438    return($template->parse('sheet_page', true));
439  }
440
441
442  /**
443   * display and manage the metadata page allowing to choose tags order
444   *
445   * @return String : the content of the page
446   */
447  protected function displayMetaDataDisplay()
448  {
[6950]449    global $user, $template, $lang;
[4905]450
451    //$local_tpl = new Template(AMD_PATH."admin/", "");
452    $template->set_filename('sheet_page',
[5935]453                  dirname($this->getFileLocation()).'/admin/amd_metadata_display.tpl');
[4905]454
455    $datas=array(
[6722]456      'urlRequest' => $this->getAdminLink('ajax'),
[4905]457      'selectedTags' => Array(),
458      'groups' => Array(),
459      'tagByGroup' => Array(),
460    );
461
462    $sql="SELECT st.tagId, st.order, st.groupId, ut.numId
463          FROM ".$this->tables['selected_tags']." st
464            LEFT JOIN ".$this->tables['used_tags']." ut
465              ON ut.tagId = st.tagId
466          ORDER BY st.groupId ASC, st.order ASC, st.tagId ASC";
467    $result=pwg_query($sql);
468    if($result)
469    {
[5959]470      while($row=pwg_db_fetch_assoc($result))
[4905]471      {
472        if($row['groupId']==-1)
473        {
474          $datas['selectedTags'][]=Array(
475            'numId' => $row['numId'],
476            'tagId' => $row['tagId']
477          );
478        }
479        else
480        {
481          $datas['tagByGroup'][]=Array(
482            'numId' => $row['numId'],
483            'tagId' => $row['tagId'],
484            'group' => $row['groupId'],
485            'order' => $row['order']
486          );
487        }
488      }
489    }
490
491    $sql="SELECT g.groupId, gn.name
492          FROM ".$this->tables['groups']." g
493            LEFT JOIN ".$this->tables['groups_names']." gn
494              ON g.groupId = gn.groupId
495          WHERE gn.lang = '".$user['language']."'
496          ORDER BY g.order;";
497    $result=pwg_query($sql);
498    if($result)
499    {
[5959]500      while($row=pwg_db_fetch_assoc($result))
[4905]501      {
502        $datas['groups'][]=Array(
503          'id' => $row['groupId'],
504          'name' => $row['name']
505        );
506      }
507    }
508
[6950]509    $lang['g003_display_page_help']=GPCCore::BBtoHTML($lang['g003_display_page_help']);
[4905]510    $template->assign('datas', $datas);
511    return($template->parse('sheet_page', true));
512  }
513
514
[5080]515  /**
516   * display and manage the database page
[6722]517   * the page have two tabsheet :
518   *  - state, to have general information about the database
519   *  - update, to manage database fill-in
[5080]520   *
[6722]521   * @param String $tab : the selected tab on the stat page
522   */
523  protected function displayDatabase($tab)
524  {
525    global $template, $user;
526    $template->set_filename('body_page', dirname(__FILE__).'/admin/amd_metadata.tpl');
527
528    $statTabsheet = new GPCTabSheet('statTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itab2');
529    $statTabsheet->select($tab);
530    $statTabsheet->add('state',
531                          l10n('g003_state'),
[15343]532                          $this->getAdminLink().'-database/state');
[6722]533    $statTabsheet->add('update',
534                          l10n('g003_update'),
[15343]535                          $this->getAdminLink().'-database/update');
[6722]536    $statTabsheet->assign();
537
538    switch($tab)
539    {
540      case 'state':
[6729]541        $template->assign('sheetContent', $this->displayDatabaseStatus());
[6722]542        break;
543      case 'update':
544        $template->assign('sheetContent', $this->displayDatabaseDatabase());
545        break;
546    }
547
548    $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page');
549  }
550
551
[6729]552
[6722]553  /**
[6729]554   * display the database status
555   *
556   * @return String : the content of the page
557   */
558  private function displayDatabaseStatus()
559  {
560    global $template, $page;
561
562    $template->set_filename('sheet_page', dirname(__FILE__).'/admin/amd_metadata_database_status.tpl');
563
[7519]564    $warning2='';
565    $sql="SELECT tagId
566          FROM ".$this->tables['used_tags']."
567          WHERE newFromLastUpdate='y'";
568    $result=pwg_query($sql);
569    if($result)
570    {
571      $tmp=array();
572      $tagSchema='';
573      while($row=pwg_db_fetch_assoc($result))
574      {
575        if(preg_match('/^([a-z0-9]*)\..*/i', $row['tagId'], $tagSchema))
576        {
577          if(!in_array($tagSchema[1],$this->config['amd_FillDataBaseIgnoreSchemas'])) $tmp[]=$row['tagId'];
578        }
579      }
580      if(count($tmp)>0)
581      {
582        $ul='';
583        foreach($tmp as $val)
584        {
585          $ul.='<li>'.$val.'</li>';
586        }
587        if(count($tmp)>1)
588        {
589          $warning2=sprintf(GPCCore::BBtoHTML(l10n('g003_databaseWarning2_n')),$ul);
590        }
591        else
592        {
593          $warning2=sprintf(GPCCore::BBtoHTML(l10n('g003_databaseWarning2_1')),$ul);
594        }
595      }
596    }
597
598
[6729]599    $datas=array(
600      'urlRequest' => $this->getAdminLink('ajax'),
[7519]601      'warning2' => $warning2,
[6729]602      'warning1' => GPCCore::BBtoHTML(l10n('g003_databaseWarning1')),
603      'nfoMetadata' => Array(
604          'exif' => 0,
605          'iptc' => 0,
606          'magic' => 0,
607          'xmp' => 0,
[7519]608          'com' => 0,
[6729]609          'userDefined' => 0,
610          'numOfPictures' => 0,
611          'numOfNotAnalyzedPictures' => 0,
612          'numOfPicturesWithoutTag' => 0,
613          'nfoSize' => 0,
614          'nfoRows' => 0,
615          'nfoSizeAndRows' => '',
616        )
617    );
618
619    $sql="SELECT SUM(numOfImg) AS nb, 'exif' AS `type`
620          FROM ".$this->tables['used_tags']."
621          WHERE tagId LIKE 'exif.%'
622          UNION
623          SELECT SUM(numOfImg), 'iptc'
624          FROM ".$this->tables['used_tags']."
625          WHERE tagId LIKE 'iptc.%'
626          UNION
627          SELECT SUM(numOfImg), 'magic'
628          FROM ".$this->tables['used_tags']."
629          WHERE tagId LIKE 'magic.%'
630          UNION
631          SELECT SUM(numOfImg), 'xmp'
632          FROM ".$this->tables['used_tags']."
633          WHERE tagId LIKE 'xmp.%'
634          UNION
[7519]635          SELECT SUM(numOfImg), 'com'
636          FROM ".$this->tables['used_tags']."
637          WHERE tagId LIKE 'com.%'
638          UNION
[6729]639          SELECT SUM(numOfImg), 'userDefined'
640          FROM ".$this->tables['used_tags']."
641          WHERE tagId LIKE 'userDefined.%'
642          UNION
643          SELECT COUNT(imageId), 'numOfPictures'
644          FROM ".$this->tables['images']."
645          WHERE analyzed='y'
646          UNION
647          SELECT COUNT(imageId), 'numOfNotAnalyzedPictures'
648          FROM ".$this->tables['images']."
649          WHERE analyzed='n'
650          UNION
651          SELECT COUNT(imageId), 'numOfPicturesWithoutTag'
652          FROM ".$this->tables['images']."
653          WHERE nbTags=0";
654    $result=pwg_query($sql);
655    if($result)
656    {
657      while($row=pwg_db_fetch_assoc($result))
658      {
659        if(!is_null($row['nb']))
660        {
661          $datas['nfoMetadata'][$row['type']]=$row['nb'];
662          if($row['type']=='exif' or
663             $row['type']=='iptc' or
664             $row['type']=='magic' or
665             $row['type']=='xmp' or
[7519]666             $row['type']=='com' or
[6729]667             $row['type']=='userDefined') $datas['nfoMetadata']['nfoRows']+=$row['nb'];
668        }
669      }
670    }
671
672    $sql="SHOW TABLE STATUS WHERE name LIKE '".$this->tables['images_tags']."'";
673    $result=pwg_query($sql);
674    if($result)
675    {
676      while($row=pwg_db_fetch_assoc($result))
677      {
678        $datas['nfoMetadata']['nfoSize']=$row['Data_length']+$row['Index_length'];
679      }
680    }
681
682    if($datas['nfoMetadata']['nfoSize']<1048576)
683    {
684      $datas['nfoMetadata']['nfoSize']=sprintf('%.2fKio', $datas['nfoMetadata']['nfoSize']/1024);
685    }
686    else
687    {
688      $datas['nfoMetadata']['nfoSize']=sprintf('%.2fMio', $datas['nfoMetadata']['nfoSize']/1048576);
689    }
[28815]690    $datas['nfoMetadata']['nfoSizeAndRows']=l10n('g003_sizeAndRows', $datas['nfoMetadata']['nfoSize'], $datas['nfoMetadata']['nfoRows']);
691    $datas['nfoMetadata']['numOfPictures']=l10n('g003_numberOfAnalyzedPictures', $datas['nfoMetadata']['numOfPictures']);
692    $datas['nfoMetadata']['numOfNotAnalyzedPictures']=l10n('g003_numberOfNotAnalyzedPictures', $datas['nfoMetadata']['numOfNotAnalyzedPictures']);
693    $datas['nfoMetadata']['numOfPicturesWithoutTag']=l10n('g003_numberOfPicturesWithoutTags', $datas['nfoMetadata']['numOfPicturesWithoutTag']);
[6729]694
695    $template->assign("datas", $datas);
696
697    return($template->parse('sheet_page', true));
698  } // displayDatabaseStatus
699
700
701
702
703  /**
[6722]704   * display and manage the database page
705   *
[5080]706   * the function automatically update the AMD tables :
707   *  - add new pictures in the AMD image table (assuming image is not analyzed
708   *    yet)
709   *  - remove deleted pictures in the AMD image & image_tags table
710   *
711   * @return String : the content of the page
712   */
[6722]713  private function displayDatabaseDatabase()
[5080]714  {
[7447]715    global $template, $page, $user;
[4905]716
[5080]717    /*
718     * insert new image (from piwigo images table) in the AMD images table, with
719     * statut 'not analyzed'
720     */
721    $sql="INSERT INTO ".$this->tables['images']."
722            SELECT id, 'n', 0
723              FROM ".IMAGES_TABLE."
724              WHERE id NOT IN (SELECT imageId FROM ".$this->tables['images'].")";
725    pwg_query($sql);
726
727
728    /*
729     * delete image who are in the AMD images table and not in the piwigo image
730     * table
731     */
732    $sql="DELETE FROM ".$this->tables['images']."
733            WHERE imageId NOT IN (SELECT id FROM ".IMAGES_TABLE.")";
734    pwg_query($sql);
735
736
737    /*
[6729]738     * delete metadata for images that are not in the AMD image table
[5080]739     */
[6729]740    $sql="DELETE ait
741          FROM ".$this->tables['images_tags']." ait
742            JOIN (SELECT DISTINCT imageId FROM ".$this->tables['images_tags']." ) aitd
743              ON ait.imageId=aitd.imageId
744          WHERE aitd.imageId NOT IN (SELECT id FROM ".IMAGES_TABLE.") ";
[5080]745    pwg_query($sql);
746
747
[7447]748    $caddieNbPictures=0;
749    $sql="SELECT COUNT(element_id) AS nbPictures
750          FROM ".CADDIE_TABLE."
751          WHERE user_id='".$user['id']."';";
752    $result=pwg_query($sql);
753    if($result)
754    {
755      while($row=pwg_db_fetch_assoc($result))
756      {
757        $caddieNbPictures=$row['nbPictures'];
758      }
759    }
[5080]760
[6729]761
762    $template->set_filename('sheet_page', dirname(__FILE__).'/admin/amd_metadata_database_database.tpl');
763
[5080]764    $datas=array(
[6722]765      'urlRequest' => $this->getAdminLink('ajax'),
[5935]766      'NumberOfItemsPerRequest' => $this->config['amd_NumberOfItemsPerRequest'],
[28815]767      'caddieNbPictures' => ($caddieNbPictures==1)?l10n('g003_1_picture_in_caddie'):l10n('g003_n_pictures_in_caddie', $caddieNbPictures)
[5080]768    );
769
770    $template->assign("datas", $datas);
771
772    return($template->parse('sheet_page', true));
773  } // displayDatabase
774
775
776
777
[4905]778
[5191]779  /**
780   * display and manage the help page
781   *
782   * @param String $tab : the selected tab on the help page
783   */
[6173]784  protected function displayHelp()
[5191]785  {
786    global $template, $user, $lang;
787    $template->set_filename('body_page', dirname(__FILE__).'/admin/amd_help.tpl');
[4905]788
[5935]789    $statTabsheet = new GPCTabSheet('statTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder', 'itab2');
[5191]790    $statTabsheet->add('exif',
791                          l10n('g003_help_tab_exif'),
[6173]792                          '', true, "displayHelp('exif');");
[5191]793    $statTabsheet->add('iptc',
794                          l10n('g003_help_tab_iptc'),
[6173]795                          '', false, "displayHelp('iptc');");
[5191]796    $statTabsheet->add('xmp',
797                          l10n('g003_help_tab_xmp'),
[6173]798                          '', false, "displayHelp('xmp');");
[5191]799    $statTabsheet->add('magic',
800                          l10n('g003_help_tab_magic'),
[6173]801                          '', false, "displayHelp('magic');");
[5191]802    $statTabsheet->assign();
803
804    $data=Array(
[6173]805      'sheetContent_exif' => GPCCore::BBtoHTML($lang['g003_help_exif']),
806      'sheetContent_xmp' => GPCCore::BBtoHTML($lang['g003_help_xmp']),
807      'sheetContent_iptc' => GPCCore::BBtoHTML($lang['g003_help_iptc']),
808      'sheetContent_magic' => GPCCore::BBtoHTML($lang['g003_help_magic']),
809      'title_exif' => l10n('g003_help_tab_exif'),
810      'title_xmp' => l10n('g003_help_tab_xmp'),
811      'title_iptc' => l10n('g003_help_tab_iptc'),
812      'title_magic' => l10n('g003_help_tab_magic')
[5191]813    );
814
815    $template->assign('data', $data);
816
817    $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page');
818  }
819
[6950]820
821  /**
822   * display and manage the tags page
823   *
824   */
825  protected function displayTags()
826  {
827    global $template, $user, $lang;
828    $template->set_filename('body_page', dirname(__FILE__).'/admin/amd_metadata_tags.tpl');
829
830    $datas=array(
831      'urlRequest' => $this->getAdminLink('ajax')
832    );
833
834    $lang['g003_tags_page_help']=GPCCore::BBtoHTML($lang['g003_tags_page_help']);
835
836    $template->assign('datas', $datas);
837
838    $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page');
839  }
840
841
[4905]842} // AMD_AIP class
843
844
845?>
Note: See TracBrowser for help on using the repository browser.