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

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

[Event Cats] Improve configuration parameters management

File size: 5.2 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
25global $ec_conf, $page, $ec_conf_index;
26
27// $ec_conf initalization
28
29$ec_conf_default = array( // PLUGIN CONFIGURATION ($ec_conf) :
30                          // ---------------------------------
31  'activated'             // plugin activated
32    => '0',               //
33                          //
34  'dup_allow'             // duplication allowance :
35    => '0',               //   0 : no account ;
36                          //   1 : all accounts ;
37                          //   2 : specified by group and user ids ;
38                          //
39  'auto_code_dg_nb'       // number of digits when creating a new code
40    => '10',              // automatically
41                          //
42  'reg_display'           // the way the "register" link is displayed,
43    => '0',               // together with the original $lang value for this
44                          // label
45                          //
46  'howto'                 // whether the small aknowledgement message has
47    => '0',               // already been displayed
48                          //
49  'unknown_code'          // what to do in case an unknown code is used with
50    => '1',               // "autolog" parameter :
51                          //   0 : nothing (display home page, index.php (not
52                          //       logged in of course)) ;
53                          //   1 : display "access denied" page ;
54                          //   2 : display an Additional Page precised below.
55                          //
56  'unknown_code_ap_id'    // the id of the Additional Page which must be used
57    => '0',               // in case of usage of an unknow code.
58);
59
60$ec_conf_index = array_flip(array_keys($ec_conf_default));
61
62$t = array(); $u = '0'; $v = false;
63if ($v = (
64  ($t = mysql_fetch_row(pwg_query("
65    SELECT `value`
66    FROM `".CONFIG_TABLE."`
67    WHERE `param` = 'event_cats';
68  "))) !== false)
69) {
70  $v = (count($ec_conf = explode(',', $t[0])) == count($ec_conf_index));
71  $u = $ec_conf[0];
72}
73// $v is false
74//   _ if the entry in the table doesn't exist ;
75//   _ if the entry in the table exists, but its number of parameters is
76//     different than the number of default parameters.
77// $u is '0' if the plugin has not yet been activated, '1' if it has been.
78if (!$v) {
79  $ec_conf = array_values($ec_conf_default);
80  change_ec_conf('activated', $u);
81}
82// now :
83//   _ the number of parameters is the same in the DB as the number of
84//     default parameters ;
85//   _ the parameters have the default values if needed ;
86//   _ the plugin shows it is active if it is the case.
87unset($t, $u, $v);
88
89/*
90 * change_ec_conf($c, $v)
91 * updates Event Cats configuration values in the database as well as in
92 * $ec_conf.
93 *
94 * @param
95 *   $c : conf value to update ;
96 *   $v : value to give to $ec_conf[$c].
97 * @return
98 *   true or false whether the change was OK or not
99 */
100function change_ec_conf($c, $v) {
101  global $ec_conf, $page, $ec_conf_index;
102  if (array_key_exists($c, $ec_conf_index)) {
103    $ec_conf[$ec_conf_index[$c]] = $v;
104    return (pwg_query("
105      UPDATE `".CONFIG_TABLE."`
106      SET `value` = \"".implode(',', $ec_conf)."\"
107      WHERE `param` = 'event_cats';
108    ") !== false);
109  }
110  else {
111    $page['errors'][] = 'Bad change_ec_conf argument';
112    return false;
113  }
114}
115
116/*
117 * read_ec_conf($c)
118 * returns the value in $ec_conf using string keys.
119 *
120 * @param
121 *   $c : conf value to update ;
122 * @return
123 *   $ec_conf value
124 */
125function read_ec_conf($c) {
126  global $ec_conf, $page, $ec_conf_index;
127  if (array_key_exists($c, $ec_conf_index))
128   return $ec_conf[$ec_conf_index[$c]];
129  else {
130    $page['errors'][] = 'Bad read_ec_conf argument';
131    return false;
132  }
133}
134
135?>
Note: See TracBrowser for help on using the repository browser.