1 | <?php |
---|
2 | /* ----------------------------------------------------------------------------- |
---|
3 | Plugin : LMT |
---|
4 | Author : Grum |
---|
5 | email : grum@piwigo.org |
---|
6 | website : http://photos.grum.dnsalias.com |
---|
7 | |
---|
8 | << May the Little SpaceFrog be with you ! >> |
---|
9 | ------------------------------------------------------------------------------ |
---|
10 | See main.inc.php for release information |
---|
11 | |
---|
12 | LMT_AIP : classe to manage plugin admin pages |
---|
13 | |
---|
14 | --------------------------------------------------------------------------- */ |
---|
15 | |
---|
16 | include_once('lmt_root.class.inc.php'); |
---|
17 | include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/translate.class.inc.php'); |
---|
18 | include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/tables.class.inc.php'); |
---|
19 | include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/genericjs.class.inc.php'); |
---|
20 | include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/pages_navigation.class.inc.php'); |
---|
21 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
22 | |
---|
23 | class LMT_AIP extends LMT_root |
---|
24 | { |
---|
25 | protected $google_translate; |
---|
26 | protected $tabsheet; |
---|
27 | |
---|
28 | public function LMT_AIP($prefixeTable, $filelocation) |
---|
29 | { |
---|
30 | parent::__construct($prefixeTable, $filelocation); |
---|
31 | $this->load_config(); |
---|
32 | $this->init_events(); |
---|
33 | |
---|
34 | $this->tabsheet = new tabsheet(); |
---|
35 | $this->tabsheet->add('list', |
---|
36 | l10n('lmt_list'), |
---|
37 | $this->page_link."&f_tabsheet=list"); |
---|
38 | $this->tabsheet->add('manage', |
---|
39 | l10n('lmt_manage'), |
---|
40 | $this->page_link."&f_tabsheet=manage"); |
---|
41 | $this->tabsheet->add('manageaut', |
---|
42 | l10n('lmt_manageaut'), |
---|
43 | $this->page_link."&f_tabsheet=manageaut"); |
---|
44 | $this->tabsheet->add('config', |
---|
45 | l10n('lmt_config'), |
---|
46 | $this->page_link."&f_tabsheet=config"); |
---|
47 | $this->tabsheet->add('help', |
---|
48 | l10n('lmt_help'), |
---|
49 | $this->page_link."&f_tabsheet=help"); |
---|
50 | |
---|
51 | // don't create this object inside root classe otherwise header is modified |
---|
52 | // everywhere in admin pages |
---|
53 | $this->ajax = new Ajax(); |
---|
54 | |
---|
55 | // don't create the google_translate object everytime, otherwise google's js |
---|
56 | // code is always included in the header even if translation functionalities |
---|
57 | // aren't needed |
---|
58 | // translation is needed only if we are in a ajax request |
---|
59 | /*if((isset($_POST['fmypolls_gomodify_translation'])||isset($_POST['fmypolls_goadd_translation']))) |
---|
60 | { |
---|
61 | $this->google_translate = new translate(); |
---|
62 | } |
---|
63 | */ |
---|
64 | } |
---|
65 | |
---|
66 | /* |
---|
67 | initialize events call for the plugin |
---|
68 | */ |
---|
69 | public function init_events() |
---|
70 | { |
---|
71 | parent::init_events(); |
---|
72 | add_event_handler('loc_end_page_header', array(&$this->css, 'apply_CSS')); |
---|
73 | add_event_handler('loc_end_page_header', array(&$this->css_icn, 'apply_CSS')); |
---|
74 | } |
---|
75 | |
---|
76 | /* |
---|
77 | display administration page |
---|
78 | */ |
---|
79 | public function manage() |
---|
80 | { |
---|
81 | global $template; |
---|
82 | |
---|
83 | $this->return_ajax_content(); |
---|
84 | |
---|
85 | $template->set_filename('plugin_admin_content', dirname(__FILE__)."/admin/lmt_admin.tpl"); |
---|
86 | |
---|
87 | if(!isset($_REQUEST['f_tabsheet'])) |
---|
88 | { |
---|
89 | $_REQUEST['f_tabsheet']='list'; |
---|
90 | } |
---|
91 | |
---|
92 | switch($_REQUEST['f_tabsheet']) |
---|
93 | { |
---|
94 | case 'list': |
---|
95 | $this->display_list_page(); |
---|
96 | break; |
---|
97 | case 'manage': |
---|
98 | $this->display_manage_page(); |
---|
99 | break; |
---|
100 | case 'manageaut': |
---|
101 | $this->display_manageaut_page(); |
---|
102 | break; |
---|
103 | case 'managedoc': |
---|
104 | $this->display_managedoc_page(); |
---|
105 | break; |
---|
106 | case 'help': |
---|
107 | $this->display_help_page(); |
---|
108 | break; |
---|
109 | case 'config': |
---|
110 | $this->display_config_page(); |
---|
111 | break; |
---|
112 | } |
---|
113 | |
---|
114 | $this->tabsheet->select($_REQUEST['f_tabsheet']); |
---|
115 | $this->tabsheet->assign(); |
---|
116 | $selected_tab=$this->tabsheet->get_selected(); |
---|
117 | $template->assign($this->tabsheet->get_titlename(), "[".$selected_tab['caption']."]"); |
---|
118 | |
---|
119 | $template_plugin["LMT_VERSION"] = "<i>".$this->plugin_name."</i> ".l10n('lmt_release').LMT_VERSION; |
---|
120 | $template_plugin["LMT_PAGE"] = $_REQUEST['f_tabsheet']; |
---|
121 | $template_plugin["LMT_TITLE"] = ""; |
---|
122 | |
---|
123 | $template->assign('plugin', $template_plugin); |
---|
124 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
125 | } |
---|
126 | |
---|
127 | |
---|
128 | /* |
---|
129 | return ajax content |
---|
130 | */ |
---|
131 | protected function return_ajax_content() |
---|
132 | { |
---|
133 | global $ajax, $template; |
---|
134 | |
---|
135 | if(isset($_REQUEST['ajaxfct'])) |
---|
136 | { |
---|
137 | //$this->debug("AJAXFCT:".$_REQUEST['ajaxfct']); |
---|
138 | $result="<p class='errors'>An error has occured</p>"; |
---|
139 | switch($_REQUEST['ajaxfct']) |
---|
140 | { |
---|
141 | case 'img_list': |
---|
142 | $result=$this->ajax_img_list($_REQUEST['numpage']); |
---|
143 | break; |
---|
144 | case 'manage_list': |
---|
145 | $result=$this->ajax_manage_list($_REQUEST['numpage']); |
---|
146 | break; |
---|
147 | } |
---|
148 | //$template-> |
---|
149 | $this->ajax->return_result($result); |
---|
150 | } |
---|
151 | } |
---|
152 | |
---|
153 | |
---|
154 | /* |
---|
155 | manage display of config page & save config |
---|
156 | */ |
---|
157 | protected function display_config_page() |
---|
158 | { |
---|
159 | $languages=get_languages(); |
---|
160 | if(!$this->adviser_abort()) |
---|
161 | { |
---|
162 | |
---|
163 | if(isset($_POST['submit_save_config'])) |
---|
164 | { |
---|
165 | foreach($this->my_config as $key => $val) |
---|
166 | { |
---|
167 | if(is_array($val)) |
---|
168 | { |
---|
169 | foreach($languages as $key2 => $val2) |
---|
170 | { |
---|
171 | if(isset($_REQUEST[str2url('f_'.$key.'_'.$key2)])) |
---|
172 | { |
---|
173 | $this->my_config[$key][$key2] = htmlspecialchars(stripslashes($_REQUEST[str2url('f_'.$key.'_'.$key2)]), ENT_QUOTES); |
---|
174 | } |
---|
175 | } |
---|
176 | } |
---|
177 | else |
---|
178 | { |
---|
179 | if(isset($_REQUEST['f_'.$key])) |
---|
180 | { |
---|
181 | $this->my_config[$key] = $_REQUEST['f_'.$key]; |
---|
182 | } |
---|
183 | } |
---|
184 | |
---|
185 | } |
---|
186 | $this->display_result(l10n('lmt_save_config'), $this->save_config()); |
---|
187 | } |
---|
188 | } |
---|
189 | $this->display_config(); |
---|
190 | } |
---|
191 | |
---|
192 | |
---|
193 | /* |
---|
194 | |
---|
195 | */ |
---|
196 | protected function display_help_page() |
---|
197 | { |
---|
198 | global $template; |
---|
199 | |
---|
200 | $template->set_filename('body_page', |
---|
201 | dirname($this->filelocation).'/admin/plugin_admin_help.tpl'); |
---|
202 | |
---|
203 | $template->assign('imgdir', LMT_PATH."img/"); |
---|
204 | |
---|
205 | $template->assign_var_from_handle('LMT_BODY_PAGE', 'body_page'); |
---|
206 | } |
---|
207 | |
---|
208 | /* |
---|
209 | */ |
---|
210 | protected function display_list_page() |
---|
211 | { |
---|
212 | global $template, $conf, $user; |
---|
213 | |
---|
214 | $template->set_filename('body_page', |
---|
215 | dirname($this->filelocation).'/admin/plugin_admin_list.tpl'); |
---|
216 | |
---|
217 | if(!isset($_REQUEST['filter']) || |
---|
218 | !($_REQUEST['filter']=="BY" || |
---|
219 | $_REQUEST['filter']=="BY-SA" || |
---|
220 | $_REQUEST['filter']=="BY-ND" || |
---|
221 | $_REQUEST['filter']=="BY-NC-ND" || |
---|
222 | $_REQUEST['filter']=="BY-NC-SA" || |
---|
223 | $_REQUEST['filter']=="BY-NC" || |
---|
224 | $_REQUEST['filter']=="CRIGHT" || |
---|
225 | $_REQUEST['filter']=="CLEFT" |
---|
226 | )) |
---|
227 | { |
---|
228 | $_REQUEST['filter']=''; |
---|
229 | } |
---|
230 | |
---|
231 | $datas=array( |
---|
232 | "LMT_AJAX_URL_LIST" => $this->page_link.'&ajaxfct=img_list&numpage=' |
---|
233 | ); |
---|
234 | |
---|
235 | $filter_list_selected = ''; |
---|
236 | $filter_list_values = array_slice($this->licences,0,count($this->licences)-1); |
---|
237 | $filter_list_labels = array(); |
---|
238 | foreach($filter_list_values as $key=>$val) |
---|
239 | { |
---|
240 | $filter_list_labels[] = "[".l10n("lmt_lbl_cc_s-".strtolower($val))."] ".l10n("lmt_lbl_cc-".strtolower($val)); |
---|
241 | if($val==$_REQUEST['filter']) |
---|
242 | { |
---|
243 | $filter_list_selected = $val; |
---|
244 | } |
---|
245 | } |
---|
246 | |
---|
247 | $filter_list_values = array_merge(array(''), $filter_list_values); |
---|
248 | $filter_list_labels = array_merge(array(l10n('lmt_nofilter')), $filter_list_labels); |
---|
249 | $default_licence = l10n("lmt_lbl_cc-".strtolower($this->my_config['lmt_licence_default'])); |
---|
250 | $default_licence_img =LMT_PATH."img/".strtolower($this->my_config['lmt_licence_default'])."_80x15.png"; |
---|
251 | |
---|
252 | $results=true; |
---|
253 | if(isset($_POST["submit_replace_caddie"])) |
---|
254 | { |
---|
255 | $sql="DELETE FROM ".CADDIE_TABLE." WHERE user_id='".$user['id']."'"; |
---|
256 | $result=pwg_query($sql); |
---|
257 | ($result)?$results=true:$results=false; |
---|
258 | } |
---|
259 | |
---|
260 | if(isset($_POST["submit_add_to_caddie"]) || isset($_POST["submit_replace_caddie"])) |
---|
261 | { |
---|
262 | $sql="REPLACE INTO ".CADDIE_TABLE." SELECT '".$user['id']."', id FROM ".IMAGES_TABLE." WHERE id IN (".implode(",", $img_ids).");"; |
---|
263 | $result=pwg_query($sql); |
---|
264 | if((!$results)||(!$result)) |
---|
265 | { |
---|
266 | $this->display_result(l10n("lmt_caddie_not_updated"), false); |
---|
267 | } |
---|
268 | else |
---|
269 | { |
---|
270 | $this->display_result(l10n("lmt_caddie_updated"), true); |
---|
271 | } |
---|
272 | } |
---|
273 | |
---|
274 | $template->assign('datas', $datas); |
---|
275 | $template->assign('default_licence', $default_licence); |
---|
276 | $template->assign('default_licence_img', $default_licence_img); |
---|
277 | $template->assign('filter_list_values', $filter_list_values); |
---|
278 | $template->assign('filter_list_labels', $filter_list_labels); |
---|
279 | $template->assign('filter_list_selected', $filter_list_selected); |
---|
280 | $template->assign_var_from_handle('LMT_BODY_PAGE', 'body_page'); |
---|
281 | } |
---|
282 | |
---|
283 | |
---|
284 | /* |
---|
285 | */ |
---|
286 | protected function display_manage_page() |
---|
287 | { |
---|
288 | global $template, $conf, $user; |
---|
289 | |
---|
290 | /* |
---|
291 | apply licence |
---|
292 | */ |
---|
293 | if(isset($_POST['submit_apply_licence'])) |
---|
294 | { |
---|
295 | $results=array("", ""); |
---|
296 | $lst=array(); |
---|
297 | foreach($_POST as $key => $val) |
---|
298 | { |
---|
299 | if((substr($key,0,2)=="fn")&&($val=="1")) $lst[]=substr($key,2); |
---|
300 | } |
---|
301 | |
---|
302 | if(count($lst)>0) |
---|
303 | { |
---|
304 | if($_POST['manage_caddie']!="napp_clear_selected") |
---|
305 | { |
---|
306 | if($_POST['licence']=='DEFAULT') |
---|
307 | { |
---|
308 | $sql="DELETE FROM ".$this->tables['images']." |
---|
309 | WHERE image_id IN (".implode(",", $lst).")"; |
---|
310 | } |
---|
311 | else |
---|
312 | { |
---|
313 | $sql="REPLACE INTO ".$this->tables['images']." |
---|
314 | SELECT id, '".$_POST['licence']."', '".$_POST['author']."' |
---|
315 | FROM ".IMAGES_TABLE." |
---|
316 | WHERE id IN (".implode(",", $lst).")"; |
---|
317 | } |
---|
318 | $result=pwg_query($sql); |
---|
319 | ($result)?$results[0].=l10n("lmt_add_licence_ok")."<br/>":$results[1].=l10n("lmt_add_licence_ko")."<br/>"; |
---|
320 | } |
---|
321 | |
---|
322 | switch($_POST['manage_caddie']) |
---|
323 | { |
---|
324 | case 'app_clear': |
---|
325 | $sql="DELETE FROM ".CADDIE_TABLE." WHERE user_id = '".$user['id']."'"; |
---|
326 | $result=pwg_query($sql); |
---|
327 | ($result)?$results[0].=l10n("lmt_clear_caddie_ok")."<br/>":$results[1].=l10n("lmt_clear_caddie_ko")."<br/>"; |
---|
328 | break; |
---|
329 | case 'app_clear_selected': |
---|
330 | case 'napp_clear_selected': |
---|
331 | $sql="DELETE FROM ".CADDIE_TABLE." |
---|
332 | WHERE user_id = '".$user['id']."' |
---|
333 | AND element_id IN (".implode(",", $lst).")"; |
---|
334 | $result=pwg_query($sql); |
---|
335 | ($result)?$results[0].=l10n("lmt_clear_si_caddie_ok")."<br/>":$results[1].=l10n("lmt_clear_si_caddie_ko")."<br/>"; |
---|
336 | break; |
---|
337 | } |
---|
338 | |
---|
339 | if($results[0]!="") |
---|
340 | { |
---|
341 | $this->display_result($results[0], true); |
---|
342 | } |
---|
343 | |
---|
344 | if($results[1]!="") |
---|
345 | { |
---|
346 | $this->display_result($results[1], false); |
---|
347 | } |
---|
348 | } |
---|
349 | else |
---|
350 | { |
---|
351 | $this->display_result(l10n("lmt_no_element_selected"), false); |
---|
352 | } |
---|
353 | } |
---|
354 | |
---|
355 | |
---|
356 | $template->set_filename('body_page', |
---|
357 | dirname($this->filelocation).'/admin/plugin_admin_manage.tpl'); |
---|
358 | |
---|
359 | $datas=array( |
---|
360 | "LMT_AJAX_URL_LIST" => $this->page_link.'&ajaxfct=manage_list&numpage=' |
---|
361 | ); |
---|
362 | |
---|
363 | if(!isset($_REQUEST['select'])) |
---|
364 | { |
---|
365 | $_REQUEST['select']="caddie"; |
---|
366 | } |
---|
367 | |
---|
368 | $sql="SELECT count(element_id) FROM ".CADDIE_TABLE." WHERE user_id = '".$user['id']."'"; |
---|
369 | $result=pwg_query($sql); |
---|
370 | $nbphotos=mysql_fetch_array($result); |
---|
371 | |
---|
372 | $author_list_values = array(0); |
---|
373 | $author_list_labels = array(l10n("lmt_no_author")); |
---|
374 | $sql="SELECT * FROM ".$this->tables["licence_author"]." ORDER BY id"; |
---|
375 | $result=pwg_query($sql); |
---|
376 | if($result) |
---|
377 | { |
---|
378 | while($row=mysql_fetch_array($result)) |
---|
379 | { |
---|
380 | $author_list_values[]=$row['id']; |
---|
381 | $author_list_labels[]=$row['text1']." ".$row['text2']; |
---|
382 | } |
---|
383 | } |
---|
384 | |
---|
385 | $licences_list_values = array(); |
---|
386 | $licences_list_values = $this->licences; |
---|
387 | $licences_list_labels = array(); |
---|
388 | foreach($licences_list_values as $key=>$val) |
---|
389 | { |
---|
390 | $licences_list_labels[] = "[".l10n("lmt_lbl_cc_s-".strtolower($val))."] ".l10n("lmt_lbl_cc-".strtolower($val)); |
---|
391 | } |
---|
392 | |
---|
393 | /* $licences_list_values = array_merge(array('DEFAULT'), $licences_list_values); |
---|
394 | $licences_list_labels = array_merge(array(l10n('lmt_bydefault')), $licences_list_labels);*/ |
---|
395 | |
---|
396 | $selectlist_list_values=array("-", "all", "none", "invert"); |
---|
397 | $selectlist_list_values=array_merge($selectlist_list_values, $licences_list_values); |
---|
398 | |
---|
399 | $selectlist_list_labels=array( |
---|
400 | l10n("lmt_choose_select"), |
---|
401 | l10n("lmt_select_all"), |
---|
402 | l10n("lmt_select_none"), |
---|
403 | l10n("lmt_select_invert") |
---|
404 | ); |
---|
405 | $selectlist_list_labels=array_merge($selectlist_list_labels, $licences_list_labels); |
---|
406 | |
---|
407 | $template->assign('datas', $datas); |
---|
408 | $template->assign('nbphotos', $nbphotos[0]); |
---|
409 | $template->assign('selectlist_list_values', $selectlist_list_values); |
---|
410 | $template->assign('selectlist_list_labels', $selectlist_list_labels); |
---|
411 | $template->assign('filter_list_selected', ""); |
---|
412 | $template->assign('licences_list_values', $licences_list_values); |
---|
413 | $template->assign('licences_list_labels', $licences_list_labels); |
---|
414 | $template->assign('licences_list_selected', ""); |
---|
415 | $template->assign('author_list_values', $author_list_values); |
---|
416 | $template->assign('author_list_labels', $author_list_labels); |
---|
417 | $template->assign_var_from_handle('LMT_BODY_PAGE', 'body_page'); |
---|
418 | } |
---|
419 | |
---|
420 | |
---|
421 | /* |
---|
422 | display config page |
---|
423 | */ |
---|
424 | protected function display_config() |
---|
425 | { |
---|
426 | global $template, $lang; |
---|
427 | |
---|
428 | $template->set_filename('body_page', |
---|
429 | dirname($this->filelocation).'/admin/plugin_admin_config.tpl'); |
---|
430 | |
---|
431 | |
---|
432 | $datas=array( |
---|
433 | "img_directory" => LMT_PATH."img/" |
---|
434 | ); |
---|
435 | foreach($this->my_config as $key => $val) |
---|
436 | { |
---|
437 | if(!is_array($val)) |
---|
438 | { |
---|
439 | $datas[$key]=$val; |
---|
440 | } |
---|
441 | } |
---|
442 | |
---|
443 | $lmt_yesno_values=array("y", "n"); |
---|
444 | $lmt_yesno_labels=array(l10n("lmt_yesno_y"), l10n("lmt_yesno_n")); |
---|
445 | |
---|
446 | $lmt_licence_logo_values=array("80x15", "88x31", "text"); |
---|
447 | $lmt_licence_logo_labels=array(l10n("lmt_icon_80x15"), l10n("lmt_icon_88x31"), l10n("lmt_icon_text")); |
---|
448 | |
---|
449 | $datas['lmt_redirect_urls']=array(); |
---|
450 | $lmt_licence_default_values = array_slice($this->licences,0,count($this->licences)-1); |
---|
451 | $lmt_licence_default_labels = array(); |
---|
452 | |
---|
453 | $tmp=array(); |
---|
454 | foreach($lmt_licence_default_values as $key=>$val) |
---|
455 | { |
---|
456 | $lmt_licence_default_labels[] = "[".l10n("lmt_lbl_cc_s-".strtolower($val))."] ".l10n("lmt_lbl_cc-".strtolower($val)); |
---|
457 | |
---|
458 | $tmp[]="'".str2url("ilmt_redirect_url-".strToLower($val))."'"; |
---|
459 | $datas['lmt_redirect_urls'][str2url('lmt_redirect_url-'.strToLower($val))]=array( |
---|
460 | 'text' => l10n("lmt_lbl_cc_s-".strToLower($val)), |
---|
461 | 'langs' => array() |
---|
462 | ); |
---|
463 | } |
---|
464 | $datas['objnames2'] = implode(",", $tmp); |
---|
465 | |
---|
466 | |
---|
467 | //langs list & texts |
---|
468 | $datas['lmt_warning_texts']=array(); |
---|
469 | |
---|
470 | $lmt_language_list=array(); |
---|
471 | $lmt_language_list_values=array(); |
---|
472 | $lmt_language_list_labels=array(); |
---|
473 | $lmt_language_selected=str2url(get_default_language()); |
---|
474 | $languages=get_languages(); |
---|
475 | |
---|
476 | foreach($languages as $key => $val) |
---|
477 | { |
---|
478 | $lmt_language_list_values[]=str2url($key); |
---|
479 | $lmt_language_list_labels[]=$val; |
---|
480 | |
---|
481 | $datas['lmt_warning_texts'][]=array( |
---|
482 | 'lang' => str2url($key), |
---|
483 | 'text' => $this->my_config['lmt_warning_texts'][$key] |
---|
484 | ); |
---|
485 | |
---|
486 | foreach($lmt_licence_default_values as $key2 => $val2) |
---|
487 | { |
---|
488 | $datas['lmt_redirect_urls'][str2url('lmt_redirect_url-'.strToLower($val2))]['langs'][str2url($key)]= |
---|
489 | $this->my_config['lmt_redirect_url-'.strToLower($val2)][$key]; |
---|
490 | } |
---|
491 | } |
---|
492 | |
---|
493 | $datas['help']=array(); |
---|
494 | foreach($lang["lmt_help_config"] as $key => $val) |
---|
495 | { |
---|
496 | $datas['help']['hlp'.$key]=addslashes($val); |
---|
497 | } |
---|
498 | |
---|
499 | $lmt_licence_default_author_values=array(0); |
---|
500 | $lmt_licence_default_author_labels=array(l10n("lmt_no_author")); |
---|
501 | $sql="SELECT * FROM ".$this->tables['licence_author']." ORDER BY id"; |
---|
502 | $result=pwg_query($sql); |
---|
503 | if($result) |
---|
504 | { |
---|
505 | while($row=mysql_fetch_array($result)) |
---|
506 | { |
---|
507 | $lmt_licence_default_author_values[]=$row['id']; |
---|
508 | $lmt_licence_default_author_labels[]=$row['text1']." ".$row['text2']; |
---|
509 | } |
---|
510 | } |
---|
511 | |
---|
512 | $template->assign('datas', $datas); |
---|
513 | $template->assign('extended_code', $this->generate_js_licence_author()); |
---|
514 | $template->assign('lmt_yesno_values', $lmt_yesno_values); |
---|
515 | $template->assign('lmt_yesno_labels', $lmt_yesno_labels); |
---|
516 | $template->assign('lmt_licence_logo_values', $lmt_licence_logo_values); |
---|
517 | $template->assign('lmt_licence_logo_labels', $lmt_licence_logo_labels); |
---|
518 | $template->assign('lmt_licence_default_values', $lmt_licence_default_values); |
---|
519 | $template->assign('lmt_licence_default_labels', $lmt_licence_default_labels); |
---|
520 | $template->assign('lmt_licence_default_author_values', $lmt_licence_default_author_values); |
---|
521 | $template->assign('lmt_licence_default_author_labels', $lmt_licence_default_author_labels); |
---|
522 | $template->assign('lmt_language_list_values', $lmt_language_list_values); |
---|
523 | $template->assign('lmt_language_list_labels', $lmt_language_list_labels); |
---|
524 | $template->assign('lmt_language_selected', $lmt_language_selected); |
---|
525 | $template->assign_var_from_handle('LMT_BODY_PAGE', 'body_page'); |
---|
526 | |
---|
527 | } //display_config |
---|
528 | |
---|
529 | |
---|
530 | |
---|
531 | |
---|
532 | /* |
---|
533 | */ |
---|
534 | protected function display_manageaut_page() |
---|
535 | { |
---|
536 | global $template, $conf, $user; |
---|
537 | |
---|
538 | if(!isset($_REQUEST['action'])) |
---|
539 | { |
---|
540 | $_REQUEST['action']="list"; |
---|
541 | } |
---|
542 | if(!isset($_REQUEST['id'])) |
---|
543 | { |
---|
544 | $_REQUEST['id']=""; |
---|
545 | } |
---|
546 | |
---|
547 | |
---|
548 | /* ------------------------------------------------------------------------ |
---|
549 | * Add an author |
---|
550 | * ---------------------------------------------------------------------- */ |
---|
551 | if(isset($_POST['submit_add_author'])) |
---|
552 | { |
---|
553 | if($_POST["text1"]!="") |
---|
554 | { |
---|
555 | $sql="INSERT INTO ".$this->tables["licence_author"]." VALUES('', '". addslashes($_POST["text1"])."', '".addslashes($_POST["text2"])."')"; |
---|
556 | $result=pwg_query($sql); |
---|
557 | if($result) |
---|
558 | { |
---|
559 | $this->display_result(l10n("lmt_author_added"), true); |
---|
560 | $_REQUEST['action']="list"; |
---|
561 | } |
---|
562 | else |
---|
563 | { |
---|
564 | $this->display_result(l10n("lmt_cannot_add_author"), false); |
---|
565 | } |
---|
566 | } |
---|
567 | else |
---|
568 | { |
---|
569 | $this->display_result(l10n("lmt_no_text"), false); |
---|
570 | } |
---|
571 | } |
---|
572 | |
---|
573 | /* ------------------------------------------------------------------------ |
---|
574 | * Modify an author |
---|
575 | * ---------------------------------------------------------------------- */ |
---|
576 | if(isset($_POST['submit_modify_author'])) |
---|
577 | { |
---|
578 | if($_POST["text1"]!="") |
---|
579 | { |
---|
580 | $sql="UPDATE ".$this->tables["licence_author"]." |
---|
581 | SET text1 = '". addslashes($_POST["text1"])."', |
---|
582 | text2 = '".addslashes($_POST["text2"])."' |
---|
583 | WHERE id = '".$_POST["id"]."'"; |
---|
584 | $result=pwg_query($sql); |
---|
585 | if($result) |
---|
586 | { |
---|
587 | $this->display_result(l10n("lmt_author_modified"), true); |
---|
588 | $_REQUEST['action']="list"; |
---|
589 | } |
---|
590 | else |
---|
591 | { |
---|
592 | $this->display_result(l10n("lmt_cannot_modify_author"), false); |
---|
593 | } |
---|
594 | } |
---|
595 | else |
---|
596 | { |
---|
597 | $this->display_result(l10n("lmt_no_text"), false); |
---|
598 | } |
---|
599 | } |
---|
600 | |
---|
601 | /* ------------------------------------------------------------------------ |
---|
602 | * delete an author |
---|
603 | * ---------------------------------------------------------------------- */ |
---|
604 | if($_REQUEST['action']=="delete") |
---|
605 | { |
---|
606 | $sql="DELETE FROM ".$this->tables['licence_author']." WHERE id = '".$_REQUEST['id']."'"; |
---|
607 | $result=pwg_query($sql); |
---|
608 | if($result) |
---|
609 | { |
---|
610 | if(mysql_affected_rows()==1) |
---|
611 | { |
---|
612 | $this->display_result(l10n("lmt_author_deleted"), true); |
---|
613 | |
---|
614 | $sql="UPDATE ".$this->tables["images"]." SET author_id = NULL |
---|
615 | WHERE author_id = '".$_REQUEST['id']."'"; |
---|
616 | $result=pwg_query($sql); |
---|
617 | if($result) |
---|
618 | { |
---|
619 | $nbimages=mysql_affected_rows(); |
---|
620 | if($nbimages>0) |
---|
621 | { |
---|
622 | $this->display_result($nbimages." ".l10n("lmt_author_nb_images_updated"), true); |
---|
623 | } |
---|
624 | } |
---|
625 | else |
---|
626 | { |
---|
627 | $this->display_result(l10n("lmt_cannot_delete_author"), false); |
---|
628 | } |
---|
629 | } |
---|
630 | else |
---|
631 | { |
---|
632 | $this->display_result(l10n("lmt_cannot_delete_author"), false); |
---|
633 | } |
---|
634 | } |
---|
635 | else |
---|
636 | { |
---|
637 | $this->display_result(l10n("lmt_cannot_delete_author"), false); |
---|
638 | } |
---|
639 | $this->display_manageaut_page_list(); |
---|
640 | } |
---|
641 | elseif($_REQUEST['action']=="add") |
---|
642 | { |
---|
643 | $this->display_manageaut_page_add_modify("add"); |
---|
644 | } |
---|
645 | elseif($_REQUEST['action']=="edit") |
---|
646 | { |
---|
647 | $this->display_manageaut_page_add_modify("edit"); |
---|
648 | } |
---|
649 | else |
---|
650 | { |
---|
651 | // list |
---|
652 | $this->display_manageaut_page_list(); |
---|
653 | } |
---|
654 | } //display_manageaut |
---|
655 | |
---|
656 | protected function display_manageaut_page_list() |
---|
657 | { |
---|
658 | global $template; |
---|
659 | |
---|
660 | $template->set_filename('body_page', |
---|
661 | dirname($this->filelocation).'/admin/plugin_admin_manageaut.tpl'); |
---|
662 | |
---|
663 | $datas=array( |
---|
664 | "author_list" => array(), |
---|
665 | "img_directory" => LMT_PATH."img/", |
---|
666 | "default_licencepublished" => l10n("lmt_lbl_under-".strToLower($this->my_config['lmt_licence_default'])), |
---|
667 | "default_licenceL" => strToLower($this->my_config['lmt_licence_default']), |
---|
668 | "default_licenceU" => l10n("lmt_lbl_cc_s-".strToLower($this->my_config['lmt_licence_default'])), |
---|
669 | "lmt_licence_logo" => $this->my_config['lmt_licence_logo'], |
---|
670 | "nbauthor" => 0, |
---|
671 | "add_link" => $this->page_link.'&f_tabsheet=manageaut&action=add' |
---|
672 | ); |
---|
673 | |
---|
674 | $sql="SELECT * FROM ".$this->tables['licence_author']." ORDER BY id"; |
---|
675 | $result=pwg_query($sql); |
---|
676 | if($result) |
---|
677 | { |
---|
678 | while($row=mysql_fetch_array($result)) |
---|
679 | { |
---|
680 | $datas["author_list"][]=array( |
---|
681 | "id" => $row['id'], |
---|
682 | "text1" => $row['text1'], |
---|
683 | "text2" => $row['text2'], |
---|
684 | "lnk_delete" => $this->page_link.'&f_tabsheet=manageaut&action=delete&id='.$row['id'], |
---|
685 | "lnk_edit" => $this->page_link.'&f_tabsheet=manageaut&action=edit&id='.$row['id'] |
---|
686 | ); |
---|
687 | } |
---|
688 | $datas["nbauthor"] = count($datas["author_list"]); |
---|
689 | } |
---|
690 | |
---|
691 | $template->assign('datas', $datas); |
---|
692 | //$template->assign('extended_code', $this->generate_js_licence_author()); |
---|
693 | $template->assign_var_from_handle('LMT_BODY_PAGE', 'body_page'); |
---|
694 | } |
---|
695 | |
---|
696 | protected function display_manageaut_page_add_modify() |
---|
697 | { |
---|
698 | global $template; |
---|
699 | |
---|
700 | $template->set_filename('body_page', |
---|
701 | dirname($this->filelocation).'/admin/plugin_admin_manageaut_edit.tpl'); |
---|
702 | |
---|
703 | if($_REQUEST["action"]=="edit") |
---|
704 | { |
---|
705 | $sql="SELECT * FROM ".$this->tables['licence_author']." WHERE id = '".$_REQUEST['id']."'"; |
---|
706 | $result = pwg_query($sql); |
---|
707 | if($result) |
---|
708 | { |
---|
709 | while($row=mysql_fetch_array($result)) |
---|
710 | { |
---|
711 | $datas=array( |
---|
712 | "action" => "modify", |
---|
713 | "id" => $_REQUEST['id'], |
---|
714 | "text1" => $row["text1"], |
---|
715 | "text2" => $row["text2"] |
---|
716 | ); |
---|
717 | } |
---|
718 | } |
---|
719 | else |
---|
720 | { |
---|
721 | $datas=array( |
---|
722 | "action" => "add", |
---|
723 | "id" => "", |
---|
724 | "text1" => "", |
---|
725 | "text2" => "", |
---|
726 | ); |
---|
727 | } |
---|
728 | } |
---|
729 | else |
---|
730 | { |
---|
731 | $datas=array( |
---|
732 | "action" => "add", |
---|
733 | "id" => "", |
---|
734 | "text1" => "", |
---|
735 | "text2" => "", |
---|
736 | ); |
---|
737 | } |
---|
738 | |
---|
739 | $datas["urllist"] = $this->page_link.'&f_tabsheet=manageaut'; |
---|
740 | |
---|
741 | $template->assign('datas', $datas); |
---|
742 | //$template->assign('extended_code', $this->generate_js_licence_author()); |
---|
743 | $template->assign_var_from_handle('LMT_BODY_PAGE', 'body_page'); |
---|
744 | } |
---|
745 | |
---|
746 | |
---|
747 | /* |
---|
748 | manage adviser profile |
---|
749 | return true if user is adviser |
---|
750 | */ |
---|
751 | protected function adviser_abort() |
---|
752 | { |
---|
753 | if(is_adviser()) |
---|
754 | { |
---|
755 | $this->display_result(l10n("lmt_adviser_not_allowed"), false); |
---|
756 | return(true); |
---|
757 | } |
---|
758 | return(false); |
---|
759 | } |
---|
760 | |
---|
761 | |
---|
762 | /* |
---|
763 | this function return a js to manage licence text |
---|
764 | */ |
---|
765 | protected function generate_js_licence_author() |
---|
766 | { |
---|
767 | $local_tpl = new Template(LMT_PATH."admin/", ""); |
---|
768 | $local_tpl->set_filename('body_page', |
---|
769 | dirname($this->filelocation).'/admin/lmt_js.tpl'); |
---|
770 | |
---|
771 | $lmt_licence_default_values=array_slice($this->licences,0,count($this->licences)-1); |
---|
772 | $datas['shortlicencetext']=array(); |
---|
773 | foreach($lmt_licence_default_values as $key=>$val) |
---|
774 | { |
---|
775 | $datas['shortlicencetext'][$val] = array( |
---|
776 | "txt" => l10n("lmt_lbl_cc_s-".strtolower($val)), |
---|
777 | "published" => l10n("lmt_lbl_under-".strtolower($val)) |
---|
778 | ); |
---|
779 | } |
---|
780 | |
---|
781 | $local_tpl->assign("datas",$datas); |
---|
782 | |
---|
783 | return($local_tpl->parse('body_page', true)); |
---|
784 | } |
---|
785 | |
---|
786 | |
---|
787 | /* --------------------------------------------------------------------------- |
---|
788 | function to manage database manipulation |
---|
789 | --------------------------------------------------------------------------- */ |
---|
790 | |
---|
791 | |
---|
792 | |
---|
793 | |
---|
794 | |
---|
795 | /* --------------------------------------------------------------------------- |
---|
796 | ajax functions |
---|
797 | --------------------------------------------------------------------------- */ |
---|
798 | |
---|
799 | protected function ajax_img_list($pagenum) |
---|
800 | { |
---|
801 | global $conf; |
---|
802 | |
---|
803 | $local_tpl = new Template(LMT_PATH."admin/", ""); |
---|
804 | $local_tpl->set_filename('body_page', |
---|
805 | dirname($this->filelocation).'/admin/plugin_admin_listitems.tpl'); |
---|
806 | |
---|
807 | if(!isset($_REQUEST['filter']) || |
---|
808 | !($_REQUEST['filter']=="BY" || |
---|
809 | $_REQUEST['filter']=="BY-SA" || |
---|
810 | $_REQUEST['filter']=="BY-ND" || |
---|
811 | $_REQUEST['filter']=="BY-NC-ND" || |
---|
812 | $_REQUEST['filter']=="BY-NC-SA" || |
---|
813 | $_REQUEST['filter']=="BY-NC" || |
---|
814 | $_REQUEST['filter']=="CRIGHT" || |
---|
815 | $_REQUEST['filter']=="CLEFT" |
---|
816 | )) |
---|
817 | { |
---|
818 | $_REQUEST['filter']=''; |
---|
819 | } |
---|
820 | |
---|
821 | $img_ids=array(); |
---|
822 | $img_liste = array(); |
---|
823 | $sql="SELECT SQL_CALC_FOUND_ROWS lmti.*, img.file, img.path, img.tn_ext, cat.id as catid, cat.name as catname, cat.permalink, lmtla.text1, lmtla.text2 |
---|
824 | FROM ".$this->tables["images"]." lmti LEFT OUTER JOIN ".$this->tables["licence_author"]." lmtla ON lmtla.id = lmti.author_id, |
---|
825 | ".IMAGES_TABLE." img LEFT OUTER JOIN ".CATEGORIES_TABLE." cat ON img.storage_category_id = cat.id |
---|
826 | WHERE lmti.image_id = img.id "; |
---|
827 | if($_REQUEST['filter']!="") |
---|
828 | { |
---|
829 | $sql.=" AND lmti.licence_type='".$_REQUEST['filter']."'"; |
---|
830 | } |
---|
831 | |
---|
832 | $sql.=" ORDER BY cat.id, img.id "; |
---|
833 | |
---|
834 | if($this->my_config['lmt_list_maxitems']>0) |
---|
835 | { |
---|
836 | $refdbt = ($pagenum-1)*$this->my_config['lmt_list_maxitems']; |
---|
837 | $sql.=" LIMIT ".$refdbt.", ".$this->my_config['lmt_list_maxitems']; |
---|
838 | } |
---|
839 | |
---|
840 | $result=pwg_query($sql); |
---|
841 | if($result) |
---|
842 | { |
---|
843 | while($row = mysql_fetch_array($result)) |
---|
844 | { |
---|
845 | $filenfo = pathinfo($row['path']); |
---|
846 | preg_match("/(.*)\./i", $filenfo["basename"], $tmp); |
---|
847 | $filenfo['filename'] = $tmp[1]; |
---|
848 | |
---|
849 | $img_ids[]=$row['image_id']; |
---|
850 | $img_liste[]=array( |
---|
851 | 'id' => $row['image_id'], |
---|
852 | 'licence' => ($row['licence_type']=="CRIGHT")?l10n("lmt_lbl_cc_s-".strtolower($row['licence_type'])):"", |
---|
853 | 'licencei' => LMT_PATH."img/".strtolower($row['licence_type'])."_80x15.png", |
---|
854 | 'aut_text1' => $row['text1'], |
---|
855 | 'aut_text2' => $row['text2'], |
---|
856 | 'file' => $row['file'], |
---|
857 | 'catname' => $row['catname'], |
---|
858 | 'catlink' => make_index_url( |
---|
859 | array( |
---|
860 | 'category' => array( |
---|
861 | 'id' => $row['catid'], |
---|
862 | 'name' => $row['catname'], |
---|
863 | 'permalink' => $row['permalink']) |
---|
864 | ) |
---|
865 | ), |
---|
866 | 'imglink' => make_picture_url( |
---|
867 | array( |
---|
868 | 'image_id' => $row['image_id'], |
---|
869 | 'category' => array( |
---|
870 | 'id' => $row['catid'], |
---|
871 | 'name' => $row['catname'], |
---|
872 | 'permalink' => $row['permalink']) |
---|
873 | ) |
---|
874 | ), |
---|
875 | 'thumb' => $filenfo["dirname"]."/thumbnail/".$conf["prefix_thumbnail"].$filenfo["filename"].".".$row["tn_ext"] |
---|
876 | ); |
---|
877 | } |
---|
878 | } |
---|
879 | |
---|
880 | $sql="select FOUND_ROWS()"; |
---|
881 | $result=pwg_query($sql); |
---|
882 | $nb=mysql_fetch_array($result); |
---|
883 | |
---|
884 | $pages_navigation = new pages_navigation(); |
---|
885 | $pages_navigation->set_nb_items($nb[0]); |
---|
886 | $pages_navigation->set_nb_items_per_page($this->my_config['lmt_list_maxitems']); |
---|
887 | $pages_navigation->set_current_page($pagenum); |
---|
888 | $pages_navigation->set_options(array( |
---|
889 | "text_prev" => l10n("lmt_nav_prev"), |
---|
890 | "text_next" => l10n("lmt_nav_next"), |
---|
891 | "text_first" => l10n("lmt_nav_first"), |
---|
892 | "text_last" => l10n("lmt_nav_last") |
---|
893 | )); |
---|
894 | $navbar=$pages_navigation->make_navigation("loadpage"); |
---|
895 | if($navbar!="") |
---|
896 | { |
---|
897 | $navbar=", ".$navbar; |
---|
898 | } |
---|
899 | |
---|
900 | $local_tpl->assign('imgliste', $img_liste); |
---|
901 | return($nb[0]." ".l10n("lmt_lst_nb_photos").$navbar."#".$local_tpl->parse('body_page', true)); |
---|
902 | } |
---|
903 | |
---|
904 | protected function ajax_manage_list($pagenum) |
---|
905 | { |
---|
906 | global $conf, $user; |
---|
907 | |
---|
908 | $local_tpl = new Template(LMT_PATH."admin/", ""); |
---|
909 | $local_tpl->set_filename('body_page', |
---|
910 | dirname($this->filelocation).'/admin/plugin_admin_manageitems.tpl'); |
---|
911 | |
---|
912 | if(!isset($_REQUEST['select'])) |
---|
913 | { |
---|
914 | $_REQUEST['select']="caddie"; |
---|
915 | } |
---|
916 | |
---|
917 | $img_liste = array(); |
---|
918 | $sql="SELECT SQL_CALC_FOUND_ROWS img.id as image_id, img.file, img.path, img.tn_ext, cat.id as catid, cat.name as catname, cat.permalink, |
---|
919 | lmti.licence_type, lmtla.text1, lmtla.text2 |
---|
920 | FROM ".CADDIE_TABLE." caddie, (".IMAGES_TABLE." img |
---|
921 | LEFT OUTER JOIN ".CATEGORIES_TABLE." cat ON img.storage_category_id = cat.id) |
---|
922 | LEFT OUTER JOIN ".$this->tables["images"]." AS lmti |
---|
923 | ON img.id = lmti.image_id |
---|
924 | LEFT OUTER JOIN ".$this->tables["licence_author"]." lmtla |
---|
925 | ON lmtla.id = lmti.author_id |
---|
926 | WHERE img.id = caddie.element_id |
---|
927 | AND caddie.user_id = '".$user['id']."' |
---|
928 | ORDER BY cat.id, img.id "; |
---|
929 | |
---|
930 | if($this->my_config['lmt_list_maxitems']>0) |
---|
931 | { |
---|
932 | $refdbt = ($pagenum-1)*$this->my_config['lmt_list_maxitems']; |
---|
933 | $sql.=" LIMIT ".$refdbt.", ".$this->my_config['lmt_list_maxitems']; |
---|
934 | } |
---|
935 | |
---|
936 | $result=pwg_query($sql); |
---|
937 | |
---|
938 | if($result) |
---|
939 | { |
---|
940 | while($row = mysql_fetch_array($result)) |
---|
941 | { |
---|
942 | $filenfo = pathinfo($row['path']); |
---|
943 | preg_match("/(.*)\./i", $filenfo["basename"], $tmp); |
---|
944 | $filenfo['filename'] = $tmp[1]; |
---|
945 | |
---|
946 | $img_liste[]=array( |
---|
947 | 'id' => $row['image_id'], |
---|
948 | 'licence' => ($row['licence_type']=="")?"DEFAULT":$row['licence_type'], |
---|
949 | 'licencei' => ($row['licence_type']=="")?"":LMT_PATH."img/".strtolower($row['licence_type'])."_80x15.png", |
---|
950 | 'aut_text1' => $row['text1'], |
---|
951 | 'aut_text2' => $row['text2'], |
---|
952 | 'file' => $row['file'], |
---|
953 | 'catname' => $row['catname'], |
---|
954 | 'catlink' => make_index_url( |
---|
955 | array( |
---|
956 | 'category' => array( |
---|
957 | 'id' => $row['catid'], |
---|
958 | 'name' => $row['catname'], |
---|
959 | 'permalink' => $row['permalink']) |
---|
960 | ) |
---|
961 | ), |
---|
962 | 'imglink' => make_picture_url( |
---|
963 | array('image_id' => $row['image_id']) |
---|
964 | ), |
---|
965 | 'thumb' => $filenfo["dirname"]."/thumbnail/".$conf["prefix_thumbnail"].$filenfo["filename"].".".$row["tn_ext"] |
---|
966 | ); |
---|
967 | } |
---|
968 | } |
---|
969 | |
---|
970 | $sql="select FOUND_ROWS()"; |
---|
971 | $result=pwg_query($sql); |
---|
972 | $nb=mysql_fetch_array($result); |
---|
973 | |
---|
974 | $pages_navigation = new pages_navigation(); |
---|
975 | $pages_navigation->set_nb_items($nb[0]); |
---|
976 | $pages_navigation->set_nb_items_per_page($this->my_config['lmt_list_maxitems']); |
---|
977 | $pages_navigation->set_current_page($pagenum); |
---|
978 | $pages_navigation->set_options(array( |
---|
979 | "text_prev" => l10n("lmt_nav_prev"), |
---|
980 | "text_next" => l10n("lmt_nav_next"), |
---|
981 | "text_first" => l10n("lmt_nav_first"), |
---|
982 | "text_last" => l10n("lmt_nav_last") |
---|
983 | )); |
---|
984 | $navbar=$pages_navigation->make_navigation("loadpage"); |
---|
985 | if($navbar!="") |
---|
986 | { |
---|
987 | $navbar=", ".$navbar; |
---|
988 | } |
---|
989 | |
---|
990 | $local_tpl->assign('imgliste', $img_liste); |
---|
991 | return($nb[0]." ".l10n("lmt_lst_nb_photos").$navbar."#".$local_tpl->parse('body_page', true)); |
---|
992 | } |
---|
993 | |
---|
994 | } //class |
---|
995 | |
---|
996 | ?> |
---|