source: extensions/event_cats/admin/evntcats_admin.php @ 3985

Last change on this file since 3985 was 3985, checked in by LucMorizur, 15 years ago

[Event Cats] Form submit beginning, "forced problem" improvement

File size: 14.4 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Plugin Name : Event Cats                                              |
4// | Plugin Version : 1.0                                                  |
5// | File Version : 1.0                                                    |
6// | Plugin Version author : LucMorizur                                    |
7// | Plugin description : (plugin for Piwigo, http://piwigo.org )          |
8// | This plugin allows an account to be automatically logged in ; and to  |
9// | let users duplicate the account they are logged with, to get benefits |
10// | of the groups of the previous account, immediately on their new acc.  |
11// | Ce plugin permet d'identifier automatiquement un compte ; et permet à |
12// | un utilisateur de dupliquer un compte, pour que le nouveau compte     |
13// | bénéficie immédiatement de l'affectation aux groupes de l'ancien cpte |
14// +-----------------------------------------------------------------------+
15
16// +-----------------------------------------------------------------------+
17// | Piwigo - a PHP based picture gallery                                  |
18// +-----------------------------------------------------------------------+
19// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
20// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
21// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
22// +-----------------------------------------------------------------------+
23// | This program is free software; you can redistribute it and/or modify  |
24// | it under the terms of the GNU General Public License as published by  |
25// | the Free Software Foundation                                          |
26// |                                                                       |
27// | This program is distributed in the hope that it will be useful, but   |
28// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
29// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
30// | General Public License for more details.                              |
31// |                                                                       |
32// | You should have received a copy of the GNU General Public License     |
33// | along with this program; if not, write to the Free Software           |
34// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
35// | USA.                                                                  |
36// +-----------------------------------------------------------------------+
37
38if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
39
40global $template, $conf, $lang, $test1, $prefixeTable, $ec_err, $page,
41 $ec_lists,   // array of following arrays :
42              //   $ec_lists['ec_table'] :
43              //     Event Cats table, in function of each entry id
44              //   $ec_lists['ec_codes'] : // Used ?
45              //     array of useful data, in function of entries codes
46              //   $ec_lists['add_pages'] :
47              //     array of Add. Pages names in function of their id
48              //   $ec_lists['categories'] :
49              //     array of category names in function of their id
50              //   $ec_lists['user_ids'] :
51              //     array of usernames in function of their id
52 $ec_ap_ok;   // whether Additional Pages is installed and activated
53
54load_language('plugin.lang', EVNTCATS_PATH);
55
56include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
57include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
58include_once(PHPWG_ROOT_PATH.'include/functions_url.inc.php');
59include_once(EVNTCATS_PATH.'include/evntcats_funcs.inc.php');
60$my_base_url = get_admin_plugin_menu_link(__FILE__);
61
62$template->assign( 'EVNTCATS_VERSION' , EVNTCATS_INFO_VERSION);
63$me = get_plugin_data($plugin_id);
64$template->clear_assign('ec_infos');
65$template->append('head_elements',
66  '<link rel="stylesheet" type="text/css" href="'.
67  EVNTCATS_PATH.'admin/evntcats_theme.css">'
68);
69
70// +-----------------------------------------------------------------------+
71// |                            Tabsheet
72// +-----------------------------------------------------------------------+
73if (!isset($_GET['tab']))
74    $page['tab'] = 'autolog';
75else
76    $page['tab'] = $_GET['tab'];
77
78$tabsheet = new tabsheet();
79$tabsheet->add('autolog',
80               l10n('ec_tab_autoid'),
81               $my_base_url.'&amp;tab=autolog');
82$tabsheet->add('config',
83               l10n('ec_tab_config'),
84               $my_base_url.'&amp;tab=config');
85$tabsheet->select($page['tab']);
86$tabsheet->assign();
87
88$template->assign(
89 array('U_HELP' => get_root_url().'popuphelp.php?page=event_cats'));
90
91$template->assign('EVNTCATS_URLS', array (
92 'ROOT'     => EVNTCATS_PATH,
93 'DISABLE'  => PHPWG_ROOT_PATH.
94  'admin.php?page=plugin&section=event_cats%2Fadmin%2Fevntcats_admin.php&disable=',
95 'DELETE'   => PHPWG_ROOT_PATH.
96  'admin.php?page=plugin&section=event_cats%2Fadmin%2Fevntcats_admin.php&delete='
97));
98
99/****************************************************************************/
100
101$code_list = array();
102build_ec_lists(); // in evntcats_funcs.php
103
104if (isset($_GET['delete'])) {
105  if (array_key_exists($_GET['delete'],$ec_lists['ec_table'])) {
106    $t = $ec_lists['ec_table'][$_GET['delete']]['code'];
107    $q = pwg_query('
108     DELETE FROM '.EVNTCATS_TABLE.'
109     WHERE id = '.$_GET['delete']
110    );
111    if ($q = 1) {
112      $page['infos']['infos'] = l10n('ec_entry_del_ok_pre').$t.
113       l10n('ec_entry_del_ok_end');
114    }
115    else {
116      $page['errors'][] = l10n('ec_entry_del_nok_pre').$t.
117       l10n('ec_entry_del_nok_end');
118    }
119    build_ec_table();
120  }
121}
122
123if (isset($_GET['disable'])) {
124  if (array_key_exists($_GET['disable'],$ec_lists['ec_table'])) {
125    $t = $ec_lists['ec_table'][$_GET['disable']]['code'];
126    $q = pwg_query('
127     UPDATE '.EVNTCATS_TABLE.'
128     SET action = \'ec_outdated\'
129     WHERE id = '.$_GET['disable']
130    );
131    if ($q = 1) {
132      $page['infos']['infos'] = l10n('ec_entry_dis_ok_pre1').$t.
133       l10n('ec_entry_dis_ok_end1');
134      if (isset($_GET['add_p'])) {
135        if (array_key_exists($_GET['add_p'],$ec_lists['add_pages'])) {
136          $q = pwg_query('
137           UPDATE '.EVNTCATS_TABLE.'
138           SET arg1 = '.$_GET['add_p'].'
139           WHERE id = '.$_GET['disable']
140          );
141          if ($q = 1) {
142            $page['infos']['infos'].=
143             l10n('ec_entry_dis_ok_pre2').
144             $_GET['add_p'].
145             l10n('ec_entry_dis_ok_mid2').
146             $ec_lists['add_pages'][$_GET['add_p']].
147             l10n('ec_entry_dis_ok_end2');
148          }
149          else {
150            $page['errors'][] =
151             l10n('ec_entry_dis_nok_pre2').
152             $t.
153             l10n('ec_entry_dis_nok_mid2').
154             $_GET['add_p'].
155             l10n('ec_entry_dis_nok_end2');
156          }
157        }
158      }
159      else {
160        $q = pwg_query('
161         UPDATE '.EVNTCATS_TABLE.'
162         SET arg1 = NULL
163         WHERE id = '.$_GET['disable']
164        );
165        if ($q != 1) {
166          $page['errors'][] =
167           l10n('ec_entry_dis_nok_pre3').
168           $t.
169           l10n('ec_entry_dis_nok_end3');
170        }
171      }
172    }
173    else {
174      $page['errors'][] = l10n('ec_entry_dis_nok_pre1').$t.
175       l10n('ec_entry_dis_nok_end1');
176    }
177    build_ec_table();
178  }
179}
180
181if (isset($_GET[''])) {
182}
183
184if (isset($_GET[''])) {
185}
186
187if (isset($_GET[''])) {
188}
189
190if (isset($_GET[''])) {
191}
192
193/****************************************************************
194* Construction of array var to be transmitted to tpl file,      *
195* containing all infos to be displayed in the code array table. *
196****************************************************************/
197
198$span_err_pre = '<span style = "color: red; font-weight: bold;">';
199$span_err_end = '</span>';
200
201foreach ($ec_lists['ec_table'] as $ec_entry) {
202   
203  $a = NULL;
204  $dspl     = '';
205  $url_end  = '';
206  $i        = intval($ec_entry['id']);
207  $arg1     = $ec_entry['arg1'];
208  $arg1_int = intval($arg1);
209  $arg2     = $ec_entry['arg2'];
210  $arg2_int = intval($arg2);
211  $log_OK   = is_in($ec_entry['action'], 'ec_ok');
212 
213  // No specific need for "code" displaying
214 
215  // "username" displaying
216  $username = ($log_OK) ?
217   $ec_lists['user_ids'][intval($ec_entry['user_id'])] : '';
218 
219  // No specific need for "action" displaying
220 
221  // "displayed page" : # of the AP, or of the category...
222  switch ($ec_entry['action']) {
223   
224    case 'ec_ok_f_pb' :
225    case 'ec_ok_f_pb_img_pb' :
226      $page['errors'][$ec_entry['code']] =
227       $ec_entry['code'].' : '.l10n('ec_forced_pb');
228    case 'ec_ok' :
229    case 'ec_ok_img_pb' :
230      $a = 0;
231      if (!empty($ec_entry['arg1'])) $a++;
232      if (!empty($ec_entry['arg2'])) $a+= 2;
233      switch ($a) {
234        case 0: // Home
235          $dspl = l10n('ec_dspl_ok_home');
236        break;
237        case 1: // Category
238        case 3: // Image
239          $url_end = '&cat='.$arg1;
240          $dspl =
241           l10n('ec_dspl_ok_cat_pre').
242           $arg1.
243           l10n('ec_dspl_ok_cat_mid').
244           $ec_lists['categories'][$arg1_int].
245           l10n('ec_dspl_ok_cat_end')
246          ;
247          if (is_in($ec_entry['action'], '_img_pb')) {
248            $url_end.= '&img='.$arg2;
249            $page['errors'][] = 
250             $ec_entry['code'].' : '.l10n('ec_image_miss');
251            $dspl.=
252             '<br>'.$span_err_pre.
253             l10n('ec_dspl_nok_img2_pre').
254             $arg2.
255             l10n('ec_dspl_nok_img2_mid').
256             $arg1.
257             l10n('ec_dspl_nok_img2_end').
258             $span_err_end
259            ;
260          }
261          elseif ($a == 3) { // Image
262            $url_end.= '&img='.$arg2;
263            $t = mysql_fetch_row(pwg_query('
264             SELECT `name`, `file`
265             FROM `'.IMAGES_TABLE.'`
266             WHERE `id` = "'.$arg2.'"
267            '));
268            $dspl.=
269             '<br>'.
270             l10n('ec_dspl_ok_img2_pre').
271             $arg2.
272             l10n('ec_dspl_ok_img2_mid1').
273             $t[0].
274             l10n('ec_dspl_ok_img2_mid2').
275             $t[1].
276             l10n('ec_dspl_ok_img2_end')
277            ;
278          }
279        break;
280        case 2: // Additional Page
281          $url_end = '&ap='.$arg2;
282          $dspl = ($ec_ap_ok) ?
283           l10n('ec_dspl_ok_ap_pre').
284           $arg2.
285           l10n('ec_dspl_ok_ap_mid').
286           $ec_lists['add_pages'][$arg2_int].
287           l10n('ec_dspl_ok_ap_end')
288          :
289           l10n('ec_dspl_ok_home')
290          ;
291        break;
292      }
293    break;
294   
295    case 'ec_nok' :
296      if (empty($ec_entry['arg2'])) {
297        $dspl = l10n('ec_dspl_nok_acc_denied');
298      }
299      else {
300        $dspl = ($ec_ap_ok) ?
301         l10n('ec_dspl_ok_ap_pre').
302         $arg2.
303         l10n('ec_dspl_ok_ap_mid').
304         $ec_lists['add_pages'][$arg2_int].
305         l10n('ec_dspl_ok_ap_end')
306        :
307         l10n('ec_dspl_nok_acc_denied')
308        ;
309      }
310    break;
311   
312    case 'ec_ok_f_pb_ap_pb' :
313      $page['errors'][$ec_entry['code']] =
314       $ec_entry['code'].' : '.l10n('ec_forced_pb');
315    case 'ec_nok_ap_pb' : // No need to check here if Additional Pages is
316    case 'ec_ok_ap_pb' :  // active : we can arrive here only when it is.
317      $page['errors'][] = 
318       $ec_entry['code'].' : '.l10n('ec_add_page_miss');
319      if (is_in($ec_entry['action'], 'ec_ok')) {
320        $url_end = '&ap='.$arg2;
321        $dspl = l10n('ec_dspl_ok_home');
322      }
323      else {
324        $dspl = l10n('ec_dspl_nok_acc_denied');
325      }
326      $dspl.=
327       $span_err_pre.
328       l10n('ec_dspl_nok_ap_pre').
329       $arg2.
330       l10n('ec_dspl_nok_ap_end').
331       $span_err_end
332      ;
333    break;
334   
335    case 'ec_ok_f_pb_cat_pb' :
336      $page['errors'][$ec_entry['code']] =
337       $ec_entry['code'].' : '.l10n('ec_forced_pb');
338    case 'ec_ok_cat_pb' :
339      $url_end = '&cat='.$arg1;
340      $page['errors'][] = 
341       $ec_entry['code'].' : '.l10n('ec_category_miss');
342      $dspl =
343       l10n('ec_dspl_nok_home').
344       $span_err_pre.
345       l10n('ec_dspl_nok_img1_pre').
346       $arg1.
347       l10n('ec_dspl_nok_img1_end').
348       $span_err_end
349      ;
350    break;
351   
352    case 'ec_nok_action_pb' :
353      $page['errors'][$ec_entry['code']] = 
354       $ec_entry['code'].' : '.l10n('ec_action_pb');
355      $username =
356       $span_err_pre.
357       l10n('ec_dspl_nok_actn').
358       $span_err_end
359      ;
360      $dspl = l10n('ec_dspl_ok_home');
361    break;
362   
363    case 'ec_nok_userid_pb' :
364      $page['errors'][$ec_entry['code']] = 
365       $ec_entry['code'].' : '.l10n('ec_username_pb');
366      $username =
367       $span_err_pre.
368       l10n('ec_dspl_usr_pb').
369       $span_err_end
370      ;
371      $dspl = l10n('ec_dspl_ok_home');
372    break;
373   
374    case 'ec_nok_userid_miss' :
375      $page['errors'][$ec_entry['code']] = 
376       $ec_entry['code'].' : '.l10n('ec_username_miss');
377      $username =
378       $span_err_pre.
379       l10n('ec_dspl_nok_usr_pre').
380       $ec_entry['user_id'].
381       l10n('ec_dspl_nok_usr_end').
382       $span_err_end
383      ;
384      $dspl = l10n('ec_dspl_ok_home');
385    break;
386  }
387 
388  // construction of $code_URL
389  $code_URL =
390   ROOT_URL.
391   'index.php?autolog='.
392   $ec_entry['code'].
393   $url_end
394  ;
395 
396  $code_list[$i] = array(
397   'id'       => $i,
398   'Code'     => (isset($page['errors'][$ec_entry['code']])) ?
399    $span_err_pre.$ec_entry['code'].$span_err_end : $ec_entry['code'],
400   'Username' => $username,
401   'Action'   => (is_in($ec_entry['action'], 'ec_nok_')) ?
402    $span_err_pre.$ec_entry['action'].$span_err_end : $ec_entry['action'],
403   'Arg1'     => $dspl,
404   'Forced'   => $ec_entry['forced'],
405   'code_URL' => $code_URL,
406   'log_OK'   => $log_OK,
407   'f_pb'     => is_in($ec_entry['action'], '_f_pb'),
408  );
409}
410
411/*
412print '<pre>';
413//print_r('ROOT_URL : '.ROOT_URL.'<br>EVNTCATS_PATH : '.EVNTCATS_PATH);
414print('ROOT_URL : '.ROOT_URL.'<br>EVNTCATS_PATH : '.EVNTCATS_PATH);
415print '</pre>';
416*/
417
418$template->assign('ec_howto', (count($page['errors']) == 0 and count($page['infos']) == 0));
419
420$template->assign('ec_ap_ok',$ec_ap_ok);
421$template->assign('code_list',$code_list);
422$template->assign('ec_lists',$ec_lists);
423$template->assign('EVNTCATS_PATH',EVNTCATS_PATH);
424$template->assign('RACINE_URL',ROOT_URL);
425
426$template->assign('GET',str_from_var($_GET));
427$template->assign('POST',str_from_var($_POST));
428$template->assign('test1tpl',str_from_var($ec_lists));
429$template->assign('test2tpl',str_from_var($page['errors']));
430$template->assign('test3tpl',str_from_var($code_list));
431
432$template->set_filenames(array('evntcats_admin_content' => dirname(__FILE__).'/evntcats_admin.tpl'));
433$template->assign_var_from_handle('ADMIN_CONTENT','evntcats_admin_content');
434?>
Note: See TracBrowser for help on using the repository browser.