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

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

[Event Cats] Implement help banner

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