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