source: extensions/event_cats/include/ec_conf.inc.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: 7.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$ec_conf_default = array( // PLUGIN CONFIGURATION ($ec_conf) :
53                          // ---------------------------------
54  'activated'             // plugin activated, 0 or 1
55    => '0',               //
56                          //
57  'howto'                 // whether the small aknowledgement message has
58    => '0',               // already been displayed, 0 or 1
59                          //
60  'dup_allow'             // duplication allowance :
61    => '2',               //   0 : no account ;
62                          //   1 : all accounts ;
63                          //   2 : specified by group and user ids ;
64                          //
65  'duplic_display'        // duplication link display in the menubar :
66    => '2',               //   0 : "Register" for everybody ;
67                          //   1 : "Duplicate" for everybody ;
68                          //   2 : "Register" only for generic accounts,
69                          //       "Duplicate" for all other accounts ;
70                          //
71  'auto_code_dg_nb'       // number of digits when creating a new code
72    => '10',              // automatically, several values
73                          //
74  'unknown_code'          // what to do in case an unknown code is used with
75    => '1',               // "autolog" parameter :
76                          //   0 : nothing (display home page, index.php (not
77                          //       logged in of course)) ;
78                          //   1 : display "access denied" page ;
79                          //   2 : display an Additional Page precised below.
80                          //
81  'unknown_code_ap_id'    // the id of the Additional Page which must be used
82    => '0',               // in case of usage of an unknow code, several vals.
83                          //
84  'comment_display'       // the way the comment is displayed in "entries"
85    => '0',               // tab : 0, as tooltip ; 1, on a line under code
86);
87
88$ec_conf_possible_values = array(
89  'activated'          => array('0', '1'),
90  'howto'              => array('0', '1'),
91  'dup_allow'          => array('0', '1', '2'),
92  'duplic_display'     => array('0', '1', '2'),
93  'auto_code_dg_nb'    => array( '4',  '5',  '8', '10', '12', '15',
94                                '16', '20', '24', '25', '30', '32'),
95  'unknown_code'       => array('0', '1', '2'),
96  'unknown_code_ap_id' => array(),
97  'comment_display'    => array('0', '1')
98);
99
100$ec_conf_index = array_flip(array_keys($ec_conf_default));
101
102$t = array(); $u = '0'; $v = false;
103if ($v = (
104  ($t = mysql_fetch_row(pwg_query("
105    SELECT `value`
106    FROM `".CONFIG_TABLE."`
107    WHERE `param` = 'event_cats';
108  "))) !== false)
109) {
110  $v = (count($ec_conf = explode(',', $t[0])) == count($ec_conf_index));
111  $u = $ec_conf[0];
112}
113// $v is false
114//   _ if the entry in the table doesn't exist ;
115//   _ if the entry in the table exists, but its number of parameters is
116//     different than the number of default parameters.
117// $u is '0' if the plugin has not yet been activated, '1' if it has been.
118if (!$v) {
119  $ec_conf = array_values($ec_conf_default);
120  change_ec_conf('activated', $u); // writes in the DB
121}
122// now :
123//   _ the number of parameters is the same in the DB as the number of
124//     default parameters ;
125//   _ the parameters have the default values if needed ;
126//   _ the plugin shows it is active if it is the case.
127unset($t, $u, $v);
128
129/*
130 * change_ec_conf($c, $v)
131 * updates Event Cats configuration values in the database as well as in
132 * $ec_conf.
133 *
134 * @param
135 *   $c : conf value to update ;
136 *   $v : value to give to $ec_conf[$c].
137 * @return
138 *   true or false whether the change was OK or not
139 */
140function change_ec_conf($c, $v) {
141  global $ec_conf, $page, $ec_conf_index, $ec_conf_possible_values;
142  if (array_key_exists($c, $ec_conf_index)) {
143    if (
144      count($ec_conf_possible_values[$c]) == 0 or
145      in_array($v, $ec_conf_possible_values[$c])
146    ) {
147      $ec_conf[$ec_conf_index[$c]] = $v;
148      return (pwg_query("
149        UPDATE `".CONFIG_TABLE."`
150        SET `value` = \"".implode(',', $ec_conf)."\"
151        WHERE `param` = 'event_cats';
152      ") !== false);
153    }
154    else {
155      $page['errors'][] = 'Bad change_ec_conf value';
156      return false;
157    }
158  }
159  else {
160    $page['errors'][] = 'Bad change_ec_conf index';
161    return false;
162  }
163}
164
165/*
166 * read_ec_conf($c)
167 * returns the value in $ec_conf using string keys.
168 *
169 * @param
170 *   $c : conf value to update ;
171 * @return
172 *   $ec_conf value
173 */
174function read_ec_conf($c) {
175  global $ec_conf, $page, $ec_conf_index;
176  if (array_key_exists($c, $ec_conf_index))
177   return $ec_conf[$ec_conf_index[$c]];
178  else {
179    $page['errors'][] = 'Bad read_ec_conf index';
180    return false;
181  }
182}
183
184?>
Note: See TracBrowser for help on using the repository browser.