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