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