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

Last change on this file since 4421 was 4421, checked in by LucMorizur, 14 years ago

[Event Cats] Add character "é" in all files so to keep them coded in UTF-8 w/o BOM

File size: 13.7 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
38// Keeps file coded in UTF-8 without BOM : é
39
40if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
41
42global $template, $conf, $lang, $prefixeTable,
43       $ec_conf, $page, $ec_debug, $ec_lists;
44
45load_language('plugin.lang', EVNTCATS_PATH);
46
47include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
48include_once(PHPWG_ROOT_PATH.'include/functions.inc.php');
49include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
50include_once(PHPWG_ROOT_PATH.'include/functions_url.inc.php');
51include_once(EVNTCATS_PATH.'include/evntcats_main_funcs.inc.php');
52include_once(EVNTCATS_PATH.'include/evntcats_admin_funcs.inc.php');
53$my_base_url = get_admin_plugin_menu_link(__FILE__);
54
55$template->assign('EVNTCATS_VERSION', EVNTCATS_INFO_VERSION);
56$me = get_plugin_data($plugin_id);
57$template->clear_assign('ec_infos');
58$template->append('head_elements',
59  '<link rel="stylesheet" type="text/css" href="'.
60  EVNTCATS_PATH.'admin/evntcats_theme.css">'
61);
62if (!isset($ec_debug)) $ec_debug = array();
63
64// +-----------------------------------------------------------------------+
65// | $_POST analysis, to determine which tab to display (tabsheet prep.)
66// +-----------------------------------------------------------------------+
67
68// If needed, stores in the DB the new value of the number of digits of
69// automatically created codes
70if (
71  isset($_POST['ec_in_up_auto_code_length']) and
72  $_POST['ec_in_up_auto_code_length'] != read_ec_conf('auto_code_dg_nb')
73) change_ec_conf('auto_code_dg_nb', $_POST['ec_in_up_auto_code_length']);
74
75
76// If needed, stores in the DB that acknowledgement message has been displayed
77if ($ec_howto = (read_ec_conf('howto') == '0')) change_ec_conf('howto', '1');
78
79build_ec_lists(); // in evntcats_main_funcs.php
80
81$dup_types_exist = false;
82$dup_entries_exist = false;
83$ec_exist_entries = false;
84function check_DB() {
85  global $dup_types_exist, $dup_entries_exist, $ec_exist_entries, $ec_lists;
86 
87  $dup_types_exist = build_dup_groups(); // build_dup_groups() returns
88  // true if an entry exists for duplication management for types
89 
90  // both arrays below are built when executing build_dup_groups() function
91  $dup_entries_exist = (
92    $dup_types_exist or
93    count($ec_lists['groups_granted_ids']) > 0 or
94    count($ec_lists['users_granted_direct_ids']) > 0
95  );
96 
97  $ec_exist_entries = (mysql_num_rows(pwg_query("
98    SELECT * FROM `".EVNTCATS_TABLE."`
99    WHERE `code` IS NOT NULL ;
100  ")) != 0);
101}
102
103check_DB();
104
105// If no entry exist, default tab is 'autolog_new'.
106$page['tab'] = (!$ec_exist_entries) ? 'autolog_new' : 'autolog_entries';
107
108// If no entry exist, but some duplication management entries exist, and
109// duplication setting is "managed per groups", default tab is 'duplication'
110if (
111  !$ec_exist_entries and
112  read_ec_conf('dup_allow') == '2' and
113  $dup_entries_exist
114) $page['tab'] = 'duplication';
115
116// If a modification of duplication management has been posted, default tab
117// is 'duplication'.
118if (
119  count($_POST) > 0 and
120  count(array_intersect(array(
121    'ec_duplic_conf_submit',
122    'deny_groups_submit',
123    'grant_groups_submit',
124    'deny_types_submit',
125    'grant_types_submit',
126    'deny_users_submit',
127    'grant_users_submit',
128  ),
129  array_keys($_POST))) > 0
130) $page['tab'] = 'duplication';
131
132if (isset($_POST['ec_conf_submit'])) {
133  if (isset($_POST['ec_dup_conf']))
134   if (!change_ec_conf('dup_allow', $_POST['ec_dup_conf']))
135    ec_end2(7);
136  if (isset($_POST['ec_dup_disp']))
137   if (!change_ec_conf('duplic_display', $_POST['ec_dup_disp']))
138    ec_end2(8);
139  if (isset($_POST['ec_unknown']))
140   if (!change_ec_conf('unknown_code', $_POST['ec_unknown']))
141    ec_end2(9);
142  if (isset($_POST['ec_in_up_aps']))
143   if (!change_ec_conf('unknown_code_ap_id', $_POST['ec_in_up_aps']))
144    ec_end2(10);
145  if (isset($_POST['ec_comments']))
146   if (!change_ec_conf('comment_display', $_POST['ec_comments']))
147    ec_end2(11);
148  $page['tab'] = 'config';
149  $page['infos'][] = l10n('ec_config_saved');
150}
151elseif (isset($_POST['ec_duplic_conf_submit'])) {
152  if (isset($_POST['ec_dup_conf'])) {
153    if (
154      read_ec_conf('dup_allow') == '2' and
155      $_POST['ec_dup_conf'] != '2'
156    ) $page['tab'] = 'config';
157    if (!change_ec_conf('dup_allow', $_POST['ec_dup_conf']))
158     ec_end2(5);
159  }
160  if (isset($_POST['ec_dup_disp']))
161   if (!change_ec_conf('duplic_display', $_POST['ec_dup_disp']))
162    ec_end2(6);
163  $page['infos'][] = l10n('ec_config_saved');
164}
165elseif (
166  isset($_POST['deny_groups_submit']) and
167  isset($_POST['deny_groups']) and
168  count($_POST['deny_groups']) > 0
169) {
170  if (pwg_query("
171    DELETE
172    FROM `".EVNTCATS_TABLE."`
173    WHERE `arg1` = 1
174      AND `arg2` IN (".implode(',', $_POST['deny_groups']).");
175  ") === false) ec_end2(1);
176  else $page['infos'][] = l10n('ec_config_saved');
177}
178elseif (
179  isset($_POST['grant_groups_submit']) and
180  isset($_POST['grant_groups']) and
181  count($_POST['grant_groups']) > 0
182) {
183  $inserts = array();
184  foreach ($_POST['grant_groups'] as $v) $inserts[] = array(
185    'arg1' => 1,
186    'arg2' => intval($v)
187  );
188  mass_inserts(EVNTCATS_TABLE, array('arg1', 'arg2'), $inserts);
189  $page['infos'][] = l10n('ec_config_saved');
190}
191elseif (
192  isset($_POST['deny_types_submit']) and (
193    isset($_POST['deny_types']) and
194    count($_POST['deny_types']) > 0 or
195    isset($_POST['deny_generic'])
196  )
197) {
198  $c = $ec_lists['types_granted'];
199  if (isset($_POST['deny_types']))
200   foreach ($_POST['deny_types'] as $v) $c = $c & ~$v;
201  if (isset($_POST['deny_generic'])) $c = $c & 7;
202  $q = ($dup_types_exist) ? "
203    UPDATE `".EVNTCATS_TABLE."`
204    SET `arg2` = $c
205    WHERE `arg1` = 3
206    LIMIT 1 ;
207  " : "
208    INSERT INTO `".EVNTCATS_TABLE."`
209    (`arg1`, `arg2`)
210    VALUES (3, $c);
211  ";
212  if (pwg_query($q) === false) ec_end2(3);
213  else $page['infos'][] = l10n('ec_config_saved');
214}
215elseif (
216  isset($_POST['grant_types_submit']) and (
217    isset($_POST['grant_types']) and
218    count($_POST['grant_types']) > 0 or
219    isset($_POST['grant_generic'])
220  )
221) {
222  $c = $ec_lists['types_granted'];
223  if (isset($_POST['grant_types']))
224   foreach ($_POST['grant_types'] as $v) $c = $c | $v;
225  if (isset($_POST['grant_generic'])) $c = $c | 8;
226  $q = ($dup_types_exist) ? "
227    UPDATE `".EVNTCATS_TABLE."`
228    SET `arg2` = $c
229    WHERE `arg1` = 3
230    LIMIT 1 ;
231  " : "
232    INSERT INTO `".EVNTCATS_TABLE."`
233    (`arg1`, `arg2`)
234    VALUES (3, $c);
235  ";
236  if (pwg_query($q) === false) ec_end2(4);
237  else $page['infos'][] = l10n('ec_config_saved');
238}
239elseif (
240  isset($_POST['deny_users_submit']) and
241  isset($_POST['deny_users']) and
242  count($_POST['deny_users']) > 0
243) {
244  if (pwg_query("
245    DELETE
246    FROM `".EVNTCATS_TABLE."`
247    WHERE `arg1` = 2
248      AND `arg2` IN (".implode(',', $_POST['deny_users']).");
249  ") === false) ec_end2(2);
250  else $page['infos'][] = l10n('ec_config_saved');
251}
252elseif (
253  isset($_POST['grant_users_submit']) and
254  isset($_POST['grant_users']) and
255  count($_POST['grant_users']) > 0
256) {
257  $inserts = array();
258  foreach ($_POST['grant_users'] as $v) $inserts[] = array(
259    'arg1' => 2,
260    'arg2' => intval($v)
261  );
262  mass_inserts(EVNTCATS_TABLE, array('arg1', 'arg2'), $inserts);
263  $page['infos'][] = l10n('ec_config_saved');
264}
265elseif (isset($_POST['ec_act1'])) {
266  if (
267    $_POST['ec_act1'] == 'disable' and
268    count($ec_lists['add_pages']) == 0
269  ) {
270    $_POST['ec_act1'] = 'modify_entry_submit';
271    $_POST['ec_input_action'] = 'refused';
272  }
273  if (
274    $_POST['ec_act1'] == 'duplicate_entry_ask' or
275    $_POST['ec_act1'] == 'create_ask'
276  )
277   $page['tab'] = 'autolog_new';
278  elseif (
279    $_POST['ec_act1'] == 'disable' or
280    $_POST['ec_act1'] == 'modify_entry_ask'
281  )
282   $page['tab'] = 'autolog_modif';
283  elseif ($_POST['ec_act1'] == 'create')
284   $page['tab'] = (ec_create_modify_entry_OK()) ?
285    'autolog_entries' : 'autolog_new';
286  elseif (
287    isset($_POST['ec_entry_sel']) and
288    is_numeric($_POST['ec_entry_sel'])
289  ) {
290    if ($_POST['ec_act1'] == 'duplicate_entry_submit') $page['tab'] =
291     (ec_create_modify_entry_OK()) ? 'autolog_entries' : 'autolog_new';
292    elseif ($_POST['ec_act1'] == 'modify_entry_submit') $page['tab'] =
293     (ec_create_modify_entry_OK()) ? 'autolog_entries' : 'autolog_modif';
294    else {
295      $page['tab'] = 'autolog_entries';
296      if ($_POST['ec_act1'] == 'delete') {
297        if (isset($_POST['ec_entry_sel'])) {
298          ec_delete_entry_OK($_POST['ec_entry_sel']);
299          build_ec_table();
300        }
301        else ec_end1('ec_entry_sel', 'Bad argument : ');
302      }
303      else if ($_POST['ec_act1'] == 'toggle_forced')
304       ec_create_modify_entry_OK();
305    }
306  }
307}
308else {
309  if (isset($_GET['tab'])) switch ($_GET['tab']) {
310    case 'autolog_modif':
311      if ($ec_exist_entries) $page['tab'] = $_GET['tab'];
312    break;
313    case 'duplication':
314      if (read_ec_conf('dup_allow') == '2') $page['tab'] = $_GET['tab'];
315    break;
316    case 'autolog_new':
317    case 'config':
318      $page['tab'] = $_GET['tab'];
319    break;
320  }
321}
322
323// +-----------------------------------------------------------------------+
324// |                            Tabsheet
325// +-----------------------------------------------------------------------+
326
327check_DB();
328 
329if (
330  $page['tab'] == 'duplication' and
331  read_ec_conf('dup_allow') != '2'
332) $page['tab'] = 'config';
333
334$tabsheet = new tabsheet();
335if ($ec_exist_entries) {
336  $tabsheet->add('autolog_entries',
337                 l10n('ec_tab_autoid_entries'),
338                 $my_base_url.'&amp;tab=autolog_entries');
339  $tabsheet->add('autolog_modif',
340                 l10n('ec_tab_autoid_modif'),
341                 $my_base_url.'&amp;tab=autolog_modif');
342}
343$tabsheet->add('autolog_new',
344               l10n('ec_tab_autoid_new'),
345               $my_base_url.'&amp;tab=autolog_new');
346if (read_ec_conf('dup_allow') == '2') $tabsheet->add('duplication',
347               l10n('ec_tab_duplication'),
348               $my_base_url.'&amp;tab=duplication');
349$tabsheet->add('config',
350               l10n('ec_tab_config'),
351               $my_base_url.'&amp;tab=config');
352
353$template->assign('EVNTCATS_URLS', array(
354 'ROOT'     => EVNTCATS_PATH,
355));
356
357/****************************************************************************/
358
359$ec_file = ($page['tab'] == 'autolog_modif') ? 'autolog_new' : $page['tab'];
360
361include(EVNTCATS_PATH.'admin/'.$ec_file.'.inc.php');
362
363$tabsheet->select($page['tab']);
364$tabsheet->assign();
365
366/*
367print '<pre>';
368//print_r('ROOT_URL : '.ROOT_URL.'<br>EVNTCATS_PATH : '.EVNTCATS_PATH);
369print('ROOT_URL : '.ROOT_URL.'<br>EVNTCATS_PATH : '.EVNTCATS_PATH);
370print '</pre>';
371*/
372
373$template->assign('ec_howto',
374 ($ec_howto and (count($page['errors']) ==0 and count($page['infos']) == 0)));
375
376$template->assign('EVNTCATS_PATH',EVNTCATS_PATH);
377$template->assign('RACINE_URL',ROOT_URL);
378$template->assign('U_HELP', get_root_url().'popuphelp.php?page=help');
379
380if (isset($conf['ec_debug1'])) $template->assign('ec_debug1', array(
381  'POST'      => str_from_var($_POST),
382  'ec_debug'  => (isset($ec_debug)) ? str_from_var($ec_debug) : '(unset)',
383  'GET'       => str_from_var($_GET),
384  'page'      => str_from_var($page),
385  'ec_conf'   => str_from_var($ec_conf),
386  'ec_lists'  => (isset($ec_lists)) ? str_from_var($ec_lists) : '(unset)',
387  'code_list' => (isset($code_list)) ? str_from_var($code_list) : '(unset)',
388));
389
390$template->set_filenames(array(
391 'evntcats_admin_content' => dirname(__FILE__).'/template/'.$ec_file.'.tpl'
392));
393$template->assign_var_from_handle('ADMIN_CONTENT','evntcats_admin_content');
394?>
Note: See TracBrowser for help on using the repository browser.