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