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