source: extensions/event_cats/include/ec_conf.inc.php @ 4470

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

[Event Cats] Help benner improvement

File size: 8.1 KB
Line 
1<?php
2
3// +-----------------------------------------------------------------------+
4// | Piwigo - a PHP based picture gallery                                  |
5// +-----------------------------------------------------------------------+
6// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
7// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
8// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
9// +-----------------------------------------------------------------------+
10// | This program is free software; you can redistribute it and/or modify  |
11// | it under the terms of the GNU General Public License as published by  |
12// | the Free Software Foundation                                          |
13// |                                                                       |
14// | This program is distributed in the hope that it will be useful, but   |
15// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
16// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
17// | General Public License for more details.                              |
18// |                                                                       |
19// | You should have received a copy of the GNU General Public License     |
20// | along with this program; if not, write to the Free Software           |
21// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
22// | USA.                                                                  |
23// +-----------------------------------------------------------------------+
24
25// Keeps file coded in UTF-8 without BOM : é
26
27if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
28
29global $ec_conf, $page, $ec_conf_index, $ec_conf_default,
30       $ec_conf_possible_values;
31
32// $ec_conf initalization
33
34// $ec_conf has numeric indexes (instead of string keys like 'activated',
35// 'howto'...) because of its first reading, done with the "explode" function.
36// It would be  very easy to build a string keys indexed array, thanks to
37// following instructions :
38/*
39$t = mysql_fetch_row(pwg_query("
40  SELECT `value`
41  FROM `".CONFIG_TABLE."`
42  WHERE `param` = 'event_cats';
43"));
44$ec_conf_temp = explode(',', $t[0]);
45$ec_conf = array(); $i = 0;
46foreach ($ec_conf_default as $k => $v) $ec_conf[$k] = ec_conf_temp[$i++];
47*/
48// Though, I prefer to keep $ec_conf with numeric indexes, so to be compelled
49// to go through function change_ec_conf() to modify ec_conf, and thus update
50// the DB at the same time.
51
52//----------------------------------------------------------------------------
53// The following lines allow to change the number of configuration items, the
54// default values they can have, and also their possible other values, very
55// quickly.
56
57// Gives configuration items names and default values. Only strings.
58$ec_conf_default = array( // PLUGIN CONFIGURATION ($ec_conf) :
59                          // ---------------------------------
60  'activated'             // plugin activated, 0 or 1
61    => '0',               //
62                          //
63  'howto'                 // whether the small aknowledgement message has
64    => '0',               // already been displayed, 0 or 1
65                          //
66  'dup_allow'             // duplication allowance :
67    => '2',               //   0 : no account ;
68                          //   1 : all accounts ;
69                          //   2 : specified by group and user ids ;
70                          //
71  'duplic_display'        // duplication link display in the menubar :
72    => '2',               //   0 : "Register" for everybody ;
73                          //   1 : "Duplicate" for everybody ;
74                          //   2 : "Register" only for generic accounts,
75                          //       "Duplicate" for all other accounts ;
76                          //
77  'auto_code_dg_nb'       // number of digits when creating a new code
78    => '10',              // automatically, several values
79                          //
80  'unknown_code'          // what to do in case an unknown code is used with
81    => '1',               // "autolog" parameter :
82                          //   0 : nothing (display home page, index.php (not
83                          //       logged in of course)) ;
84                          //   1 : display "access denied" page ;
85                          //   2 : display an Additional Page precised below.
86                          //
87  'unknown_code_ap_id'    // the id of the Additional Page which must be used
88    => '0',               // in case of usage of an unknow code, several vals.
89                          //
90  'comment_display'       // the way the comment is displayed in "entries"
91    => '1',               // tab : 0, as tooltip ; 1, on a line under code
92                          //
93  'in_help_display'       // whether the help banner is displayed.
94    => '1',               // 0: not displayed ; 1 : displayed (surprising !)
95);
96
97// Gives possible values. In case values cannot be predicted, just provide an
98// empty array : array() .
99$ec_conf_possible_values = array(
100  'activated'          => array('0', '1'),
101  'howto'              => array('0', '1'),
102  'dup_allow'          => array('0', '1', '2'),
103  'duplic_display'     => array('0', '1', '2'),
104  'auto_code_dg_nb'    => array( '4',  '5',  '8', '10', '12', '15',
105                                '16', '20', '24', '25', '30', '32'),
106  'unknown_code'       => array('0', '1', '2'),
107  'unknown_code_ap_id' => array(),
108  'comment_display'    => array('0', '1'),
109  'in_help_display'    => array('0', '1'),
110);
111
112// Once these lines have been updated, you don't need to change anything
113// else. Everything is managed by the code ; the only effect being that
114// existing configuration values in the DB are reset to their default
115// values -- normally not a harmful effect.
116//----------------------------------------------------------------------------
117
118$ec_conf_index = array_flip(array_keys($ec_conf_default));
119
120$t = array(); $u = '0'; $v = false;
121if ($v = (
122  ($t = mysql_fetch_row(pwg_query("
123    SELECT `value`
124    FROM `".CONFIG_TABLE."`
125    WHERE `param` = 'event_cats';
126  "))) !== false)
127) {
128  $v = (count($ec_conf = explode(',', $t[0])) == count($ec_conf_index));
129  $u = $ec_conf[0];
130}
131// $v is false
132//   _ if the entry in the table doesn't exist ;
133//   _ if the entry in the table exists, but its number of parameters is
134//     different than the number of default parameters.
135// $u is '0' if the plugin has not yet been activated, '1' if it has been.
136if (!$v) {
137  $ec_conf = array_values($ec_conf_default);
138  change_ec_conf('activated', $u); // writes in the DB
139}
140// now :
141//   _ the number of parameters is the same in the DB as the number of
142//     default parameters ;
143//   _ the parameters have the default values if needed ;
144//   _ the plugin shows it is active if it is the case.
145unset($t, $u, $v);
146
147/*
148 * change_ec_conf($c, $v)
149 * updates Event Cats configuration values in the database as well as in
150 * $ec_conf.
151 *
152 * @param
153 *   $c : conf value to update ;
154 *   $v : value to give to $ec_conf[$c].
155 * @return
156 *   true or false whether the change was OK or not
157 */
158function change_ec_conf($c, $v) {
159  global $ec_conf, $page, $ec_conf_index, $ec_conf_possible_values;
160  if (array_key_exists($c, $ec_conf_index)) {
161    if (
162      count($ec_conf_possible_values[$c]) == 0 or
163      in_array($v, $ec_conf_possible_values[$c])
164    ) {
165      $ec_conf[$ec_conf_index[$c]] = $v;
166      return (pwg_query("
167        UPDATE `".CONFIG_TABLE."`
168        SET `value` = \"".implode(',', $ec_conf)."\"
169        WHERE `param` = 'event_cats';
170      ") !== false);
171    }
172    else {
173      $page['errors'][] = 'Bad change_ec_conf value';
174      return false;
175    }
176  }
177  else {
178    $page['errors'][] = 'Bad change_ec_conf index';
179    return false;
180  }
181}
182
183/*
184 * read_ec_conf($c)
185 * returns the value in $ec_conf using string keys.
186 *
187 * @param
188 *   $c : conf value to update ;
189 * @return
190 *   $ec_conf value
191 */
192function read_ec_conf($c) {
193  global $ec_conf, $page, $ec_conf_index;
194  if (array_key_exists($c, $ec_conf_index))
195   return $ec_conf[$ec_conf_index[$c]];
196  else {
197    $page['errors'][] = 'Bad read_ec_conf index';
198    return false;
199  }
200}
201
202?>
Note: See TracBrowser for help on using the repository browser.