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

Last change on this file since 15869 was 15343, checked in by grum, 12 years ago

feature:2637 - Compatibility with Piwigo 2.4

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