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

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

[event cats] First commit, with files this time

File size: 14.0 KB
RevLine 
[3956]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   = (strpos($ec_entry['action'], 'ec_ok') !== false);
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_forced_pb' :
225      $page['errors'][$ec_entry['code']] = l10n('ec_forced_pb');
226    case 'ec_ok' :
227    case 'ec_ok_img_pb' :
228      $a = 0;
229      if (!empty($ec_entry['arg1'])) $a++;
230      if (!empty($ec_entry['arg2'])) $a+= 2;
231      switch ($a) {
232        case 0: // Home
233          $dspl = l10n('ec_dspl_ok_home');
234        break;
235        case 1: // Category
236        case 3: // Image
237          $url_end = '&cat='.$arg1;
238          $dspl =
239           l10n('ec_dspl_ok_cat_pre').
240           $arg1.
241           l10n('ec_dspl_ok_cat_mid').
242           $ec_lists['categories'][$arg1_int].
243           l10n('ec_dspl_ok_cat_end')
244          ;
245          if ($ec_entry['action'] == 'ec_ok_img_pb') {
246            $url_end.= '&img='.$arg2;
247            $page['errors'][] = l10n('ec_image_miss');
248            $dspl.=
249             '<br>'.$span_err_pre.
250             l10n('ec_dspl_nok_img2_pre').
251             $arg2.
252             l10n('ec_dspl_nok_img2_mid').
253             $arg1.
254             l10n('ec_dspl_nok_img2_end').
255             $span_err_end
256            ;
257          }
258          elseif ($a == 3) { // Image
259            $url_end.= '&img='.$arg2;
260            $t = mysql_fetch_row(pwg_query('
261             SELECT `name`, `file`
262             FROM `'.IMAGES_TABLE.'`
263             WHERE `id` = "'.$arg2.'"
264            '));
265            $dspl.=
266             '<br>'.
267             l10n('ec_dspl_ok_img2_pre').
268             $arg2.
269             l10n('ec_dspl_ok_img2_mid1').
270             $t[0].
271             l10n('ec_dspl_ok_img2_mid2').
272             $t[1].
273             l10n('ec_dspl_ok_img2_end')
274            ;
275          }
276        break;
277        case 2: // Additional Page
278          $url_end = '&ap='.$arg2;
279          $dspl = ($ec_ap_ok) ?
280           l10n('ec_dspl_ok_ap_pre').
281           $arg2.
282           l10n('ec_dspl_ok_ap_mid').
283           $ec_lists['add_pages'][$arg2_int].
284           l10n('ec_dspl_ok_ap_end')
285          :
286           l10n('ec_dspl_ok_home')
287          ;
288        break;
289      }
290    break;
291   
292    case 'ec_nok' :
293      if (empty($ec_entry['arg2'])) {
294        $dspl = l10n('ec_dspl_ok_acc_denied');
295      }
296      else {
297        $url_end = '&ap='.$arg2;
298        $dspl = ($ec_ap_ok) ?
299         l10n('ec_dspl_ok_ap_pre').
300         $arg2.
301         l10n('ec_dspl_ok_ap_mid').
302         $ec_lists['add_pages'][$arg2_int].
303         l10n('ec_dspl_ok_ap_end')
304        :
305         l10n('ec_dspl_ok_acc_denied')
306        ;
307      }
308    break;
309   
310    case 'ec_nok_ap_pb' : // No need to check here if Additional Pages is
311    case 'ec_ok_ap_pb' :  // active : we can arrive here only when it is.
312      $url_end = '&ap='.$arg2;
313      $page['errors'][] = l10n('ec_add_page_miss');
314      $dspl = ($ec_entry['action'] == 'ec_ok_ap_pb') ?
315       l10n('ec_dspl_ok_home') : l10n('ec_dspl_nok_acc_denied');
316      $dspl.=
317       $span_err_pre.
318       l10n('ec_dspl_nok_ap_pre').
319       $arg2.
320       l10n('ec_dspl_nok_ap_end').
321       $span_err_end
322      ;
323    break;
324   
325    case 'ec_ok_cat_pb' :
326      $url_end = '&cat='.$arg1;
327      $page['errors'][] = l10n('ec_category_miss');
328      $dspl =
329       l10n('ec_dspl_nok_home').
330       $span_err_pre.
331       l10n('ec_dspl_nok_img1_pre').
332       $arg1.
333       l10n('ec_dspl_nok_img1_end').
334       $span_err_end
335      ;
336    break;
337   
338    case 'ec_nok_action_pb' :
339      $page['errors'][$ec_entry['code']] = l10n('ec_action_pb');
340      $username =
341       $span_err_pre.
342       l10n('ec_dspl_nok_actn').
343       $span_err_end
344      ;
345      $dspl = l10n('ec_dspl_ok_home');
346    break;
347   
348    case 'ec_nok_userid_pb' :
349      $page['errors'][$ec_entry['code']] = l10n('ec_username_pb');
350      $username =
351       $span_err_pre.
352       l10n('ec_dspl_usr_pb').
353       $span_err_end
354      ;
355      $dspl = l10n('ec_dspl_ok_home');
356    break;
357   
358    case 'ec_nok_userid_miss' :
359      $page['errors'][$ec_entry['code']] = l10n('ec_username_miss');
360      $username =
361       $span_err_pre.
362       l10n('ec_dspl_nok_usr_pre').
363       $ec_entry['user_id'].
364       l10n('ec_dspl_nok_usr_end').
365       $span_err_end
366      ;
367      $dspl = l10n('ec_dspl_ok_home');
368    break;
369  }
370 
371  // construction of $code_URL
372  $code_URL =
373   ROOT_URL.
374   'index.php?autolog='.
375   $ec_entry['code'].
376   $url_end
377  ;
378 
379  $code_list[$i] = array(
380   'id'       => $i,
381   'Code'     => $ec_entry['code'],
382   'Username' => $username,
383   'Action'   => $ec_entry['action'],
384   'Arg1'     => $dspl,
385   'Forced'   => $ec_entry['forced'],
386   'code_URL' => $code_URL,
387   'log_OK'   => $log_OK,
388  );
389}
390
391/*
392print '<pre>';
393//print_r('ROOT_URL : '.ROOT_URL.'<br>EVNTCATS_PATH : '.EVNTCATS_PATH);
394print('ROOT_URL : '.ROOT_URL.'<br>EVNTCATS_PATH : '.EVNTCATS_PATH);
395print '</pre>';
396*/
397
398$template->assign('ec_howto', (count($page['errors']) == 0 and count($page['infos']) == 0));
399
400$template->assign('ec_ap_ok',$ec_ap_ok);
401$template->assign('code_list',$code_list);
402$template->assign('ec_lists',$ec_lists);
403$template->assign('EVNTCATS_PATH',EVNTCATS_PATH);
404$template->assign('RACINE_URL',ROOT_URL);
405
406// $template->assign('test0tpl',str_from_var($ec_lists['ec_codes']));
407$template->assign('test1tpl',str_from_var($ec_lists));
408$template->assign('test2tpl',str_from_var($page['errors']));
409$template->assign('test3tpl',str_from_var($code_list));
410
411/* C'est quoi, ça ?...
412if ( isset($_POST['submit']) )
413  {
414    if (isset($_POST['account']) and isset($_POST['code']))
415      {
416        $conf['auto_log'][$_POST['code']] = $_POST['account'];
417      }
418    else
419      {
420        $page['errors']='arg_missing';
421      }
422
423    if (isset($_POST['duplication']))
424      {
425        $conf['allow_user_registration'] = ($_POST['duplication'] == '1');
426      }
427  }
428*/
429
430$template->set_filenames(array('evntcats_admin_content' => dirname(__FILE__).'/evntcats_admin.tpl'));
431$template->assign_var_from_handle('ADMIN_CONTENT','evntcats_admin_content');
432?>
Note: See TracBrowser for help on using the repository browser.