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

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

[Event Cats] Remove bug types could not be granted to duplication when from blank

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