1 | <?php |
---|
2 | /* ----------------------------------------------------------------------------- |
---|
3 | Plugin : LMT |
---|
4 | Author : Grum |
---|
5 | email : grum@piwigo.org |
---|
6 | website : http://photos.grum.fr |
---|
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.'GrumPluginClasses/classes/GPCTranslate.class.inc.php'); |
---|
18 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTables.class.inc.php'); |
---|
19 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCRequestBuilder.class.inc.php'); |
---|
20 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/genericjs.class.inc.php'); |
---|
21 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCPagesNavigation.class.inc.php'); |
---|
22 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
23 | |
---|
24 | class LMT_AIP extends LMT_root |
---|
25 | { |
---|
26 | protected $tabsheet; |
---|
27 | |
---|
28 | public function __construct($prefixeTable, $filelocation) |
---|
29 | { |
---|
30 | parent::__construct($prefixeTable, $filelocation); |
---|
31 | $this->loadConfig(); |
---|
32 | $this->initEvents(); |
---|
33 | |
---|
34 | $this->tabsheet = new tabsheet(); |
---|
35 | $this->tabsheet->add('list', |
---|
36 | l10n('lmt_list'), |
---|
37 | $this->getAdminLink()."&f_tabsheet=list"); |
---|
38 | $this->tabsheet->add('manage', |
---|
39 | l10n('lmt_manage'), |
---|
40 | $this->getAdminLink()."&f_tabsheet=manage"); |
---|
41 | $this->tabsheet->add('manageaut', |
---|
42 | l10n('lmt_manageaut'), |
---|
43 | $this->getAdminLink()."&f_tabsheet=manageaut"); |
---|
44 | $this->tabsheet->add('search', |
---|
45 | l10n('lmt_search'), |
---|
46 | $this->getAdminLink()."&f_tabsheet=search"); |
---|
47 | $this->tabsheet->add('config', |
---|
48 | l10n('lmt_config'), |
---|
49 | $this->getAdminLink()."&f_tabsheet=config"); |
---|
50 | $this->tabsheet->add('help', |
---|
51 | l10n('lmt_help'), |
---|
52 | $this->getAdminLink()."&f_tabsheet=help"); |
---|
53 | } |
---|
54 | |
---|
55 | public function __destruct() |
---|
56 | { |
---|
57 | unset($this->tabsheet); |
---|
58 | parent::__destruct(); |
---|
59 | } |
---|
60 | |
---|
61 | /* |
---|
62 | initialize events call for the plugin |
---|
63 | */ |
---|
64 | public function initEvents() |
---|
65 | { |
---|
66 | parent::initEvents(); |
---|
67 | |
---|
68 | if(isset($_REQUEST['f_tabsheet']) and $_REQUEST['f_tabsheet']=='search') |
---|
69 | { |
---|
70 | // load request builder JS only on the search page |
---|
71 | GPCRequestBuilder::loadJSandCSS(); |
---|
72 | } |
---|
73 | |
---|
74 | add_event_handler('loc_end_page_header', array(&$this->css, 'applyCSS')); |
---|
75 | add_event_handler('loc_end_page_header', array(&$this->css_icn, 'applyCSS')); |
---|
76 | |
---|
77 | GPCCss::applyGpcCss(); |
---|
78 | } |
---|
79 | |
---|
80 | /* |
---|
81 | display administration page |
---|
82 | */ |
---|
83 | public function manage() |
---|
84 | { |
---|
85 | global $template; |
---|
86 | |
---|
87 | $template->set_filename('plugin_admin_content', dirname(__FILE__)."/admin/lmt_admin.tpl"); |
---|
88 | |
---|
89 | if(!isset($_REQUEST['f_tabsheet'])) |
---|
90 | { |
---|
91 | $_REQUEST['f_tabsheet']='list'; |
---|
92 | } |
---|
93 | |
---|
94 | switch($_REQUEST['f_tabsheet']) |
---|
95 | { |
---|
96 | case 'list': |
---|
97 | $this->display_list_page(); |
---|
98 | break; |
---|
99 | case 'manage': |
---|
100 | $this->display_manage_page(); |
---|
101 | break; |
---|
102 | case 'manageaut': |
---|
103 | $this->display_manageaut_page(); |
---|
104 | break; |
---|
105 | case 'managedoc': |
---|
106 | $this->display_managedoc_page(); |
---|
107 | break; |
---|
108 | case 'search': |
---|
109 | $this->displaySearch(); |
---|
110 | break; |
---|
111 | case 'help': |
---|
112 | $this->display_help_page(); |
---|
113 | break; |
---|
114 | case 'config': |
---|
115 | $this->display_config_page(); |
---|
116 | break; |
---|
117 | } |
---|
118 | |
---|
119 | $this->tabsheet->select($_REQUEST['f_tabsheet']); |
---|
120 | $this->tabsheet->assign(); |
---|
121 | $selected_tab=$this->tabsheet->get_selected(); |
---|
122 | $template->assign($this->tabsheet->get_titlename(), "[".$selected_tab['caption']."]"); |
---|
123 | |
---|
124 | $template_plugin["LMT_VERSION"] = "<i>".$this->getPluginName()."</i> ".l10n('lmt_release').LMT_VERSION; |
---|
125 | $template_plugin["LMT_PAGE"] = $_REQUEST['f_tabsheet']; |
---|
126 | $template_plugin["LMT_TITLE"] = ""; |
---|
127 | |
---|
128 | $template->assign('plugin', $template_plugin); |
---|
129 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
130 | } |
---|
131 | |
---|
132 | |
---|
133 | /* |
---|
134 | manage display of config page & save config |
---|
135 | */ |
---|
136 | protected function display_config_page() |
---|
137 | { |
---|
138 | $languages=get_languages(); |
---|
139 | if(!$this->adviser_abort()) |
---|
140 | { |
---|
141 | |
---|
142 | if(isset($_POST['submit_save_config'])) |
---|
143 | { |
---|
144 | foreach($this->config as $key => $val) |
---|
145 | { |
---|
146 | if(is_array($val)) |
---|
147 | { |
---|
148 | foreach($languages as $key2 => $val2) |
---|
149 | { |
---|
150 | if(isset($_REQUEST[str2url('f_'.$key.'_'.$key2)])) |
---|
151 | { |
---|
152 | $this->config[$key][$key2] = htmlspecialchars(stripslashes($_REQUEST[str2url('f_'.$key.'_'.$key2)]), ENT_QUOTES); |
---|
153 | } |
---|
154 | } |
---|
155 | } |
---|
156 | else |
---|
157 | { |
---|
158 | if(isset($_REQUEST['f_'.$key])) |
---|
159 | { |
---|
160 | $this->config[$key] = $_REQUEST['f_'.$key]; |
---|
161 | } |
---|
162 | } |
---|
163 | |
---|
164 | } |
---|
165 | $this->displayResult(l10n('lmt_save_config'), $this->saveConfig()); |
---|
166 | } |
---|
167 | } |
---|
168 | $this->display_config(); |
---|
169 | } |
---|
170 | |
---|
171 | |
---|
172 | /* |
---|
173 | |
---|
174 | */ |
---|
175 | protected function display_help_page() |
---|
176 | { |
---|
177 | global $template; |
---|
178 | |
---|
179 | $template->set_filename('body_page', |
---|
180 | dirname($this->getFileLocation()).'/admin/plugin_admin_help.tpl'); |
---|
181 | |
---|
182 | $template->assign('imgdir', LMT_PATH."img/"); |
---|
183 | |
---|
184 | $template->assign_var_from_handle('LMT_BODY_PAGE', 'body_page'); |
---|
185 | } |
---|
186 | |
---|
187 | /* |
---|
188 | */ |
---|
189 | protected function display_list_page() |
---|
190 | { |
---|
191 | global $template, $conf, $user; |
---|
192 | |
---|
193 | $template->set_filename('body_page', |
---|
194 | dirname($this->getFileLocation()).'/admin/plugin_admin_list.tpl'); |
---|
195 | |
---|
196 | if(!isset($_REQUEST['filter']) || |
---|
197 | !($_REQUEST['filter']=="BY" || |
---|
198 | $_REQUEST['filter']=="BY-SA" || |
---|
199 | $_REQUEST['filter']=="BY-ND" || |
---|
200 | $_REQUEST['filter']=="BY-NC-ND" || |
---|
201 | $_REQUEST['filter']=="BY-NC-SA" || |
---|
202 | $_REQUEST['filter']=="BY-NC" || |
---|
203 | $_REQUEST['filter']=="CRIGHT" || |
---|
204 | $_REQUEST['filter']=="CLEFT" || |
---|
205 | $_REQUEST['filter']=="CC0" || |
---|
206 | $_REQUEST['filter']=="PD" |
---|
207 | )) |
---|
208 | { |
---|
209 | $_REQUEST['filter']=''; |
---|
210 | } |
---|
211 | |
---|
212 | $datas=array( |
---|
213 | "LMT_AJAX_URL_LIST" => $this->getAdminLink('ajax') |
---|
214 | ); |
---|
215 | |
---|
216 | $filter_list_selected = ''; |
---|
217 | $filter_list_values = array_slice(LMT_root::$licences,0,count(LMT_root::$licences)-1); |
---|
218 | $filter_list_labels = array(); |
---|
219 | foreach($filter_list_values as $key=>$val) |
---|
220 | { |
---|
221 | $filter_list_labels[] = "[".l10n("lmt_lbl_cc_s-".strtolower($val))."] ".l10n("lmt_lbl_cc-".strtolower($val)); |
---|
222 | if($val==$_REQUEST['filter']) |
---|
223 | { |
---|
224 | $filter_list_selected = $val; |
---|
225 | } |
---|
226 | } |
---|
227 | |
---|
228 | $filter_list_values = array_merge(array(''), $filter_list_values); |
---|
229 | $filter_list_labels = array_merge(array(l10n('lmt_nofilter')), $filter_list_labels); |
---|
230 | $default_licence = l10n("lmt_lbl_cc-".strtolower($this->config['lmt_licence_default'])); |
---|
231 | $default_licence_img =LMT_PATH."img/".strtolower($this->config['lmt_licence_default'])."_80x15.png"; |
---|
232 | |
---|
233 | $results=true; |
---|
234 | if(isset($_POST["submit_replace_caddie"])) |
---|
235 | { |
---|
236 | $sql="DELETE FROM ".CADDIE_TABLE." WHERE user_id='".$user['id']."'"; |
---|
237 | $result=pwg_query($sql); |
---|
238 | ($result)?$results=true:$results=false; |
---|
239 | } |
---|
240 | |
---|
241 | if(isset($_POST["submit_add_to_caddie"]) || isset($_POST["submit_replace_caddie"])) |
---|
242 | { |
---|
243 | |
---|
244 | $sql="REPLACE INTO ".CADDIE_TABLE." |
---|
245 | SELECT '".$user['id']."', it.id FROM ".IMAGES_TABLE." it, ".$this->tables["images"]." lmti |
---|
246 | WHERE it.id = lmti.image_id"; |
---|
247 | if($_REQUEST['filter']!="") |
---|
248 | { |
---|
249 | $sql.=" AND lmti.licence_type='".$_REQUEST['filter']."'"; |
---|
250 | } |
---|
251 | |
---|
252 | $result=pwg_query($sql); |
---|
253 | if((!$results)||(!$result)) |
---|
254 | { |
---|
255 | $this->displayResult(l10n("lmt_caddie_not_updated"), false); |
---|
256 | } |
---|
257 | else |
---|
258 | { |
---|
259 | $this->displayResult(l10n("lmt_caddie_updated"), true); |
---|
260 | } |
---|
261 | } |
---|
262 | |
---|
263 | $template->assign('datas', $datas); |
---|
264 | $template->assign('default_licence', $default_licence); |
---|
265 | $template->assign('default_licence_img', $default_licence_img); |
---|
266 | $template->assign('filter_list_values', $filter_list_values); |
---|
267 | $template->assign('filter_list_labels', $filter_list_labels); |
---|
268 | $template->assign('filter_list_selected', $filter_list_selected); |
---|
269 | $template->assign_var_from_handle('LMT_BODY_PAGE', 'body_page'); |
---|
270 | } |
---|
271 | |
---|
272 | |
---|
273 | /* |
---|
274 | */ |
---|
275 | protected function display_manage_page() |
---|
276 | { |
---|
277 | global $template, $conf, $user; |
---|
278 | |
---|
279 | /* |
---|
280 | apply licence |
---|
281 | */ |
---|
282 | if(isset($_POST['submit_apply_licence'])) |
---|
283 | { |
---|
284 | $results=array("", ""); |
---|
285 | $lst=array(); |
---|
286 | foreach($_POST as $key => $val) |
---|
287 | { |
---|
288 | if((substr($key,0,2)=="fn")&&($val=="1")) $lst[]=substr($key,2); |
---|
289 | } |
---|
290 | |
---|
291 | if(count($lst)>0) |
---|
292 | { |
---|
293 | if($_POST['manage_caddie']!="napp_clear_selected") |
---|
294 | { |
---|
295 | if($_POST['licence']=='DEFAULT') |
---|
296 | { |
---|
297 | $sql="DELETE FROM ".$this->tables['images']." |
---|
298 | WHERE image_id IN (".implode(",", $lst).")"; |
---|
299 | } |
---|
300 | else |
---|
301 | { |
---|
302 | $sql="REPLACE INTO ".$this->tables['images']." |
---|
303 | SELECT id, '".$_POST['licence']."', '".$_POST['author']."' |
---|
304 | FROM ".IMAGES_TABLE." |
---|
305 | WHERE id IN (".implode(",", $lst).")"; |
---|
306 | } |
---|
307 | $result=pwg_query($sql); |
---|
308 | ($result)?$results[0].=l10n("lmt_add_licence_ok")."<br/>":$results[1].=l10n("lmt_add_licence_ko")."<br/>"; |
---|
309 | } |
---|
310 | |
---|
311 | switch($_POST['manage_caddie']) |
---|
312 | { |
---|
313 | case 'app_clear': |
---|
314 | $sql="DELETE FROM ".CADDIE_TABLE." WHERE user_id = '".$user['id']."'"; |
---|
315 | $result=pwg_query($sql); |
---|
316 | ($result)?$results[0].=l10n("lmt_clear_caddie_ok")."<br/>":$results[1].=l10n("lmt_clear_caddie_ko")."<br/>"; |
---|
317 | break; |
---|
318 | case 'app_clear_selected': |
---|
319 | case 'napp_clear_selected': |
---|
320 | $sql="DELETE FROM ".CADDIE_TABLE." |
---|
321 | WHERE user_id = '".$user['id']."' |
---|
322 | AND element_id IN (".implode(",", $lst).")"; |
---|
323 | $result=pwg_query($sql); |
---|
324 | ($result)?$results[0].=l10n("lmt_clear_si_caddie_ok")."<br/>":$results[1].=l10n("lmt_clear_si_caddie_ko")."<br/>"; |
---|
325 | break; |
---|
326 | } |
---|
327 | |
---|
328 | if($results[0]!="") |
---|
329 | { |
---|
330 | $this->displayResult($results[0], true); |
---|
331 | } |
---|
332 | |
---|
333 | if($results[1]!="") |
---|
334 | { |
---|
335 | $this->displayResult($results[1], false); |
---|
336 | } |
---|
337 | } |
---|
338 | else |
---|
339 | { |
---|
340 | $this->displayResult(l10n("lmt_no_element_selected"), false); |
---|
341 | } |
---|
342 | } |
---|
343 | |
---|
344 | |
---|
345 | $template->set_filename('body_page', |
---|
346 | dirname($this->getFileLocation()).'/admin/plugin_admin_manage.tpl'); |
---|
347 | |
---|
348 | $datas=array( |
---|
349 | "LMT_AJAX_URL_LIST" => $this->getAdminLink('ajax') |
---|
350 | ); |
---|
351 | |
---|
352 | if(!isset($_REQUEST['select'])) |
---|
353 | { |
---|
354 | $_REQUEST['select']="caddie"; |
---|
355 | } |
---|
356 | |
---|
357 | $sql="SELECT count(element_id) FROM ".CADDIE_TABLE." WHERE user_id = '".$user['id']."'"; |
---|
358 | $result=pwg_query($sql); |
---|
359 | $nbphotos=pwg_db_fetch_row($result); |
---|
360 | |
---|
361 | $author_list_values = array(0); |
---|
362 | $author_list_labels = array(l10n("lmt_no_author")); |
---|
363 | $sql="SELECT * FROM ".$this->tables["licence_author"]." ORDER BY id"; |
---|
364 | $result=pwg_query($sql); |
---|
365 | if($result) |
---|
366 | { |
---|
367 | while($row=pwg_db_fetch_assoc($result)) |
---|
368 | { |
---|
369 | $author_list_values[]=$row['id']; |
---|
370 | $author_list_labels[]=$row['text1']." ".$row['text2']; |
---|
371 | } |
---|
372 | } |
---|
373 | |
---|
374 | $licences_list_values = array(); |
---|
375 | $licences_list_values = self::$licences; |
---|
376 | $licences_list_labels = array(); |
---|
377 | foreach($licences_list_values as $key=>$val) |
---|
378 | { |
---|
379 | $licences_list_labels[] = "[".l10n("lmt_lbl_cc_s-".strtolower($val))."] ".l10n("lmt_lbl_cc-".strtolower($val)); |
---|
380 | } |
---|
381 | |
---|
382 | /* $licences_list_values = array_merge(array('DEFAULT'), $licences_list_values); |
---|
383 | $licences_list_labels = array_merge(array(l10n('lmt_bydefault')), $licences_list_labels);*/ |
---|
384 | |
---|
385 | $selectlist_list_values=array("-", "all", "none", "invert"); |
---|
386 | $selectlist_list_values=array_merge($selectlist_list_values, $licences_list_values); |
---|
387 | |
---|
388 | $selectlist_list_labels=array( |
---|
389 | l10n("lmt_choose_select"), |
---|
390 | l10n("lmt_select_all"), |
---|
391 | l10n("lmt_select_none"), |
---|
392 | l10n("lmt_select_invert") |
---|
393 | ); |
---|
394 | $selectlist_list_labels=array_merge($selectlist_list_labels, $licences_list_labels); |
---|
395 | |
---|
396 | $template->assign('datas', $datas); |
---|
397 | $template->assign('nbphotos', $nbphotos[0]); |
---|
398 | $template->assign('selectlist_list_values', $selectlist_list_values); |
---|
399 | $template->assign('selectlist_list_labels', $selectlist_list_labels); |
---|
400 | $template->assign('filter_list_selected', ""); |
---|
401 | $template->assign('licences_list_values', $licences_list_values); |
---|
402 | $template->assign('licences_list_labels', $licences_list_labels); |
---|
403 | $template->assign('licences_list_selected', ""); |
---|
404 | $template->assign('author_list_values', $author_list_values); |
---|
405 | $template->assign('author_list_labels', $author_list_labels); |
---|
406 | $template->assign_var_from_handle('LMT_BODY_PAGE', 'body_page'); |
---|
407 | } |
---|
408 | |
---|
409 | |
---|
410 | /* |
---|
411 | display config page |
---|
412 | */ |
---|
413 | protected function display_config() |
---|
414 | { |
---|
415 | global $template, $lang; |
---|
416 | |
---|
417 | $template->set_filename('body_page', |
---|
418 | dirname($this->getFileLocation()).'/admin/plugin_admin_config.tpl'); |
---|
419 | |
---|
420 | |
---|
421 | $datas=array( |
---|
422 | "img_directory" => LMT_PATH."img/" |
---|
423 | ); |
---|
424 | foreach($this->config as $key => $val) |
---|
425 | { |
---|
426 | if(!is_array($val)) |
---|
427 | { |
---|
428 | $datas[$key]=$val; |
---|
429 | } |
---|
430 | } |
---|
431 | |
---|
432 | $lmt_yesno_values=array("y", "n"); |
---|
433 | $lmt_yesno_labels=array(l10n("lmt_yesno_y"), l10n("lmt_yesno_n")); |
---|
434 | |
---|
435 | $lmt_licence_logo_values=array("80x15", "88x31", "text"); |
---|
436 | $lmt_licence_logo_labels=array(l10n("lmt_icon_80x15"), l10n("lmt_icon_88x31"), l10n("lmt_icon_text")); |
---|
437 | |
---|
438 | $datas['lmt_redirect_urls']=array(); |
---|
439 | $lmt_licence_default_values = array_slice(self::$licences,0,count(self::$licences)-1); |
---|
440 | $lmt_licence_default_labels = array(); |
---|
441 | |
---|
442 | $tmp=array(); |
---|
443 | foreach($lmt_licence_default_values as $key=>$val) |
---|
444 | { |
---|
445 | $lmt_licence_default_labels[] = "[".l10n("lmt_lbl_cc_s-".strtolower($val))."] ".l10n("lmt_lbl_cc-".strtolower($val)); |
---|
446 | |
---|
447 | $tmp[]="'".str2url("ilmt_redirect_url-".strToLower($val))."'"; |
---|
448 | $datas['lmt_redirect_urls'][str2url('lmt_redirect_url-'.strToLower($val))]=array( |
---|
449 | 'text' => l10n("lmt_lbl_cc_s-".strToLower($val)), |
---|
450 | 'langs' => array() |
---|
451 | ); |
---|
452 | } |
---|
453 | $datas['objnames2'] = implode(",", $tmp); |
---|
454 | |
---|
455 | |
---|
456 | //langs list & texts |
---|
457 | $datas['lmt_warning_texts']=array(); |
---|
458 | |
---|
459 | $lmt_language_list=array(); |
---|
460 | $lmt_language_list_values=array(); |
---|
461 | $lmt_language_list_labels=array(); |
---|
462 | $lmt_language_selected=str2url(get_default_language()); |
---|
463 | $languages=get_languages(); |
---|
464 | |
---|
465 | foreach($languages as $key => $val) |
---|
466 | { |
---|
467 | $lmt_language_list_values[]=str2url($key); |
---|
468 | $lmt_language_list_labels[]=$val; |
---|
469 | |
---|
470 | $datas['lmt_warning_texts'][]=array( |
---|
471 | 'lang' => str2url($key), |
---|
472 | 'text' => $this->config['lmt_warning_texts'][$key] |
---|
473 | ); |
---|
474 | |
---|
475 | foreach($lmt_licence_default_values as $key2 => $val2) |
---|
476 | { |
---|
477 | $datas['lmt_redirect_urls'][str2url('lmt_redirect_url-'.strToLower($val2))]['langs'][str2url($key)]= |
---|
478 | $this->config['lmt_redirect_url-'.strToLower($val2)][$key]; |
---|
479 | } |
---|
480 | } |
---|
481 | |
---|
482 | $datas['help']=array(); |
---|
483 | foreach($lang["lmt_help_config"] as $key => $val) |
---|
484 | { |
---|
485 | $datas['help']['hlp'.$key]=addslashes($val); |
---|
486 | } |
---|
487 | |
---|
488 | $lmt_licence_default_author_values=array(0); |
---|
489 | $lmt_licence_default_author_labels=array(l10n("lmt_no_author")); |
---|
490 | $sql="SELECT * FROM ".$this->tables['licence_author']." ORDER BY id"; |
---|
491 | $result=pwg_query($sql); |
---|
492 | if($result) |
---|
493 | { |
---|
494 | while($row=pwg_db_fetch_assoc($result)) |
---|
495 | { |
---|
496 | $lmt_licence_default_author_values[]=$row['id']; |
---|
497 | $lmt_licence_default_author_labels[]=$row['text1']." ".$row['text2']; |
---|
498 | } |
---|
499 | } |
---|
500 | |
---|
501 | $template->assign('datas', $datas); |
---|
502 | $template->assign('extended_code', $this->generate_js_licence_author()); |
---|
503 | $template->assign('lmt_yesno_values', $lmt_yesno_values); |
---|
504 | $template->assign('lmt_yesno_labels', $lmt_yesno_labels); |
---|
505 | $template->assign('lmt_licence_logo_values', $lmt_licence_logo_values); |
---|
506 | $template->assign('lmt_licence_logo_labels', $lmt_licence_logo_labels); |
---|
507 | $template->assign('lmt_licence_default_values', $lmt_licence_default_values); |
---|
508 | $template->assign('lmt_licence_default_labels', $lmt_licence_default_labels); |
---|
509 | $template->assign('lmt_licence_default_author_values', $lmt_licence_default_author_values); |
---|
510 | $template->assign('lmt_licence_default_author_labels', $lmt_licence_default_author_labels); |
---|
511 | $template->assign('lmt_language_list_values', $lmt_language_list_values); |
---|
512 | $template->assign('lmt_language_list_labels', $lmt_language_list_labels); |
---|
513 | $template->assign('lmt_language_selected', $lmt_language_selected); |
---|
514 | $template->assign_var_from_handle('LMT_BODY_PAGE', 'body_page'); |
---|
515 | |
---|
516 | } //display_config |
---|
517 | |
---|
518 | |
---|
519 | |
---|
520 | /** |
---|
521 | * display the search page |
---|
522 | * |
---|
523 | */ |
---|
524 | protected function displaySearch() |
---|
525 | { |
---|
526 | global $template; |
---|
527 | |
---|
528 | $template->set_filename('body_page', |
---|
529 | dirname($this->getFileLocation()).'/admin/lmt_search.tpl'); |
---|
530 | |
---|
531 | $template->assign('lmt_search_page', GPCRequestBuilder::displaySearchPage($this->getPluginName())); |
---|
532 | |
---|
533 | $template->assign_var_from_handle('LMT_BODY_PAGE', 'body_page'); |
---|
534 | } |
---|
535 | |
---|
536 | |
---|
537 | |
---|
538 | /* |
---|
539 | */ |
---|
540 | protected function display_manageaut_page() |
---|
541 | { |
---|
542 | global $template, $conf, $user; |
---|
543 | |
---|
544 | if(!isset($_REQUEST['action'])) |
---|
545 | { |
---|
546 | $_REQUEST['action']="list"; |
---|
547 | } |
---|
548 | if(!isset($_REQUEST['id'])) |
---|
549 | { |
---|
550 | $_REQUEST['id']=""; |
---|
551 | } |
---|
552 | |
---|
553 | |
---|
554 | /* ------------------------------------------------------------------------ |
---|
555 | * Add an author |
---|
556 | * ---------------------------------------------------------------------- */ |
---|
557 | if(isset($_POST['submit_add_author'])) |
---|
558 | { |
---|
559 | if($_POST["text1"]!="") |
---|
560 | { |
---|
561 | $sql="INSERT INTO ".$this->tables["licence_author"]." VALUES('', '". htmlspecialchars($_POST["text1"], ENT_QUOTES)."', '".htmlspecialchars($_POST["text2"], ENT_QUOTES)."')"; |
---|
562 | $result=pwg_query($sql); |
---|
563 | if($result) |
---|
564 | { |
---|
565 | $this->displayResult(l10n("lmt_author_added"), true); |
---|
566 | $_REQUEST['action']="list"; |
---|
567 | } |
---|
568 | else |
---|
569 | { |
---|
570 | $this->displayResult(l10n("lmt_cannot_add_author"), false); |
---|
571 | } |
---|
572 | } |
---|
573 | else |
---|
574 | { |
---|
575 | $this->displayResult(l10n("lmt_no_text"), false); |
---|
576 | } |
---|
577 | } |
---|
578 | |
---|
579 | /* ------------------------------------------------------------------------ |
---|
580 | * Modify an author |
---|
581 | * ---------------------------------------------------------------------- */ |
---|
582 | if(isset($_POST['submit_modify_author'])) |
---|
583 | { |
---|
584 | if($_POST["text1"]!="") |
---|
585 | { |
---|
586 | $sql="UPDATE ".$this->tables["licence_author"]." |
---|
587 | SET text1 = '". htmlspecialchars($_POST["text1"], ENT_QUOTES)."', |
---|
588 | text2 = '".htmlspecialchars($_POST["text2"], ENT_QUOTES)."' |
---|
589 | WHERE id = '".$_POST["id"]."'"; |
---|
590 | $result=pwg_query($sql); |
---|
591 | if($result) |
---|
592 | { |
---|
593 | $this->displayResult(l10n("lmt_author_modified"), true); |
---|
594 | $_REQUEST['action']="list"; |
---|
595 | } |
---|
596 | else |
---|
597 | { |
---|
598 | $this->displayResult(l10n("lmt_cannot_modify_author"), false); |
---|
599 | } |
---|
600 | } |
---|
601 | else |
---|
602 | { |
---|
603 | $this->displayResult(l10n("lmt_no_text"), false); |
---|
604 | } |
---|
605 | } |
---|
606 | |
---|
607 | /* ------------------------------------------------------------------------ |
---|
608 | * delete an author |
---|
609 | * ---------------------------------------------------------------------- */ |
---|
610 | if($_REQUEST['action']=="delete") |
---|
611 | { |
---|
612 | $sql="DELETE FROM ".$this->tables['licence_author']." WHERE id = '".$_REQUEST['id']."'"; |
---|
613 | $result=pwg_query($sql); |
---|
614 | if($result) |
---|
615 | { |
---|
616 | if(pwg_db_changes($result)==1) |
---|
617 | { |
---|
618 | $this->displayResult(l10n("lmt_author_deleted"), true); |
---|
619 | |
---|
620 | $sql="UPDATE ".$this->tables["images"]." SET author_id = NULL |
---|
621 | WHERE author_id = '".$_REQUEST['id']."'"; |
---|
622 | $result=pwg_query($sql); |
---|
623 | if($result) |
---|
624 | { |
---|
625 | $nbimages=pwg_db_changes($result); |
---|
626 | if($nbimages>0) |
---|
627 | { |
---|
628 | $this->displayResult($nbimages." ".l10n("lmt_author_nb_images_updated"), true); |
---|
629 | } |
---|
630 | } |
---|
631 | else |
---|
632 | { |
---|
633 | $this->displayResult(l10n("lmt_cannot_delete_author"), false); |
---|
634 | } |
---|
635 | } |
---|
636 | else |
---|
637 | { |
---|
638 | $this->displayResult(l10n("lmt_cannot_delete_author"), false); |
---|
639 | } |
---|
640 | } |
---|
641 | else |
---|
642 | { |
---|
643 | $this->displayResult(l10n("lmt_cannot_delete_author"), false); |
---|
644 | } |
---|
645 | $this->display_manageaut_page_list(); |
---|
646 | } |
---|
647 | elseif($_REQUEST['action']=="add") |
---|
648 | { |
---|
649 | $this->display_manageaut_page_add_modify("add"); |
---|
650 | } |
---|
651 | elseif($_REQUEST['action']=="edit") |
---|
652 | { |
---|
653 | $this->display_manageaut_page_add_modify("edit"); |
---|
654 | } |
---|
655 | else |
---|
656 | { |
---|
657 | // list |
---|
658 | $this->display_manageaut_page_list(); |
---|
659 | } |
---|
660 | } //display_manageaut |
---|
661 | |
---|
662 | protected function display_manageaut_page_list() |
---|
663 | { |
---|
664 | global $template; |
---|
665 | |
---|
666 | $template->set_filename('body_page', |
---|
667 | dirname($this->getFileLocation()).'/admin/plugin_admin_manageaut.tpl'); |
---|
668 | |
---|
669 | $datas=array( |
---|
670 | "author_list" => array(), |
---|
671 | "img_directory" => LMT_PATH."img/", |
---|
672 | "default_licencepublished" => l10n("lmt_lbl_under-".strToLower($this->config['lmt_licence_default'])), |
---|
673 | "default_licenceL" => strToLower($this->config['lmt_licence_default']), |
---|
674 | "default_licenceU" => l10n("lmt_lbl_cc_s-".strToLower($this->config['lmt_licence_default'])), |
---|
675 | "lmt_licence_logo" => $this->config['lmt_licence_logo'], |
---|
676 | "nbauthor" => 0, |
---|
677 | "add_link" => $this->getAdminLink().'&f_tabsheet=manageaut&action=add' |
---|
678 | ); |
---|
679 | |
---|
680 | $sql="SELECT * FROM ".$this->tables['licence_author']." ORDER BY id"; |
---|
681 | $result=pwg_query($sql); |
---|
682 | if($result) |
---|
683 | { |
---|
684 | while($row=pwg_db_fetch_assoc($result)) |
---|
685 | { |
---|
686 | $datas["author_list"][]=array( |
---|
687 | "id" => $row['id'], |
---|
688 | "text1" => $row['text1'], |
---|
689 | "text2" => $row['text2'], |
---|
690 | "lnk_delete" => $this->getAdminLink().'&f_tabsheet=manageaut&action=delete&id='.$row['id'], |
---|
691 | "lnk_edit" => $this->getAdminLink().'&f_tabsheet=manageaut&action=edit&id='.$row['id'] |
---|
692 | ); |
---|
693 | } |
---|
694 | $datas["nbauthor"] = count($datas["author_list"]); |
---|
695 | } |
---|
696 | |
---|
697 | $template->assign('datas', $datas); |
---|
698 | //$template->assign('extended_code', $this->generate_js_licence_author()); |
---|
699 | $template->assign_var_from_handle('LMT_BODY_PAGE', 'body_page'); |
---|
700 | } |
---|
701 | |
---|
702 | protected function display_manageaut_page_add_modify() |
---|
703 | { |
---|
704 | global $template; |
---|
705 | |
---|
706 | $template->set_filename('body_page', |
---|
707 | dirname($this->getFileLocation()).'/admin/plugin_admin_manageaut_edit.tpl'); |
---|
708 | |
---|
709 | if($_REQUEST["action"]=="edit") |
---|
710 | { |
---|
711 | $sql="SELECT * FROM ".$this->tables['licence_author']." WHERE id = '".$_REQUEST['id']."'"; |
---|
712 | $result = pwg_query($sql); |
---|
713 | if($result) |
---|
714 | { |
---|
715 | while($row=pwg_db_fetch_assoc($result)) |
---|
716 | { |
---|
717 | $datas=array( |
---|
718 | "action" => "modify", |
---|
719 | "id" => $_REQUEST['id'], |
---|
720 | "text1" => $row["text1"], |
---|
721 | "text2" => $row["text2"] |
---|
722 | ); |
---|
723 | } |
---|
724 | } |
---|
725 | else |
---|
726 | { |
---|
727 | $datas=array( |
---|
728 | "action" => "add", |
---|
729 | "id" => "", |
---|
730 | "text1" => "", |
---|
731 | "text2" => "", |
---|
732 | ); |
---|
733 | } |
---|
734 | } |
---|
735 | else |
---|
736 | { |
---|
737 | $datas=array( |
---|
738 | "action" => "add", |
---|
739 | "id" => "", |
---|
740 | "text1" => "", |
---|
741 | "text2" => "", |
---|
742 | ); |
---|
743 | } |
---|
744 | |
---|
745 | $datas["urllist"] = $this->getAdminLink().'&f_tabsheet=manageaut'; |
---|
746 | |
---|
747 | $template->assign('datas', $datas); |
---|
748 | //$template->assign('extended_code', $this->generate_js_licence_author()); |
---|
749 | $template->assign_var_from_handle('LMT_BODY_PAGE', 'body_page'); |
---|
750 | } |
---|
751 | |
---|
752 | |
---|
753 | /* |
---|
754 | manage adviser profile |
---|
755 | return true if user is adviser |
---|
756 | */ |
---|
757 | protected function adviser_abort() |
---|
758 | { |
---|
759 | if(is_adviser()) |
---|
760 | { |
---|
761 | $this->displayResult(l10n("lmt_adviser_not_allowed"), false); |
---|
762 | return(true); |
---|
763 | } |
---|
764 | return(false); |
---|
765 | } |
---|
766 | |
---|
767 | |
---|
768 | /* |
---|
769 | this function return a js to manage licence text |
---|
770 | */ |
---|
771 | protected function generate_js_licence_author() |
---|
772 | { |
---|
773 | $local_tpl = new Template(LMT_PATH."admin/", ""); |
---|
774 | $local_tpl->set_filename('body_page', |
---|
775 | dirname($this->getFileLocation()).'/admin/lmt_js.tpl'); |
---|
776 | |
---|
777 | $lmt_licence_default_values=array_slice(self::$licences,0,count(self::$licences)-1); |
---|
778 | $datas['shortlicencetext']=array(); |
---|
779 | foreach($lmt_licence_default_values as $key=>$val) |
---|
780 | { |
---|
781 | $datas['shortlicencetext'][$val] = array( |
---|
782 | "txt" => l10n("lmt_lbl_cc_s-".strtolower($val)), |
---|
783 | "published" => l10n("lmt_lbl_under-".strtolower($val)) |
---|
784 | ); |
---|
785 | } |
---|
786 | |
---|
787 | $local_tpl->assign("datas",$datas); |
---|
788 | |
---|
789 | return($local_tpl->parse('body_page', true)); |
---|
790 | } |
---|
791 | |
---|
792 | |
---|
793 | /* --------------------------------------------------------------------------- |
---|
794 | function to manage database manipulation |
---|
795 | --------------------------------------------------------------------------- */ |
---|
796 | |
---|
797 | } //class |
---|
798 | |
---|
799 | |
---|
800 | ?> |
---|