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

Last change on this file since 4371 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: 6.9 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
25if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
26
27global $ec_conf, $page, $ec_conf_index, $ec_conf_default,
28       $ec_conf_possible_values;
29
30// $ec_conf initalization
31
32// $ec_conf has numeric indexes (instead of string keys like 'activated',
33// 'howto'...) because of its first reading, done with the "explode" function.
34// It would be  very easy to build a string keys indexed array, thanks to
35// following instructions :
36/*
37$t = mysql_fetch_row(pwg_query("
38  SELECT `value`
39  FROM `".CONFIG_TABLE."`
40  WHERE `param` = 'event_cats';
41"));
42$ec_conf_temp = explode(',', $t[0]);
43$ec_conf = array(); $i = 0;
44foreach ($ec_conf_default as $k => $v) $ec_conf[$k] = ec_conf_temp[$i++];
45*/
46// Though, I prefer to keep $ec_conf with numeric indexes, so to be compelled
47// to go through function change_ec_conf() to modify ec_conf, and thus update
48// the DB at the same time.
49
50$ec_conf_default = array( // PLUGIN CONFIGURATION ($ec_conf) :
51                          // ---------------------------------
52  'activated'             // plugin activated, 0 or 1
53    => '0',               //
54                          //
55  'howto'                 // whether the small aknowledgement message has
56    => '0',               // already been displayed, 0 or 1
57                          //
58  'dup_allow'             // duplication allowance :
59    => '2',               //   0 : no account ;
60                          //   1 : all accounts ;
61                          //   2 : specified by group and user ids ;
62                          //
63  'duplic_display'        // duplication link display in the menubar :
64    => '2',               //   0 : "Register" for everybody ;
65                          //   1 : "Duplicate" for everybody ;
66                          //   2 : "Register" only for generic accounts,
67                          //       "Duplicate" for all other accounts ;
68                          //
69  'auto_code_dg_nb'       // number of digits when creating a new code
70    => '10',              // automatically, several values
71                          //
72  'unknown_code'          // what to do in case an unknown code is used with
73    => '1',               // "autolog" parameter :
74                          //   0 : nothing (display home page, index.php (not
75                          //       logged in of course)) ;
76                          //   1 : display "access denied" page ;
77                          //   2 : display an Additional Page precised below.
78                          //
79  'unknown_code_ap_id'    // the id of the Additional Page which must be used
80    => '0',               // in case of usage of an unknow code, several vals.
81);
82
83$ec_conf_possible_values = array(
84  'activated'          => array('0', '1'),
85  'howto'              => array('0', '1'),
86  'dup_allow'          => array('0', '1', '2'),
87  'duplic_display'     => array('0', '1', '2'),
88  'auto_code_dg_nb'    => array( '4',  '5',  '8', '10', '12', '15',
89                                '16', '20', '24', '25', '30', '32'),
90  'unknown_code'       => array('0', '1', '2'),
91  'unknown_code_ap_id' => array()
92);
93
94$ec_conf_index = array_flip(array_keys($ec_conf_default));
95
96$t = array(); $u = '0'; $v = false;
97if ($v = (
98  ($t = mysql_fetch_row(pwg_query("
99    SELECT `value`
100    FROM `".CONFIG_TABLE."`
101    WHERE `param` = 'event_cats';
102  "))) !== false)
103) {
104  $v = (count($ec_conf = explode(',', $t[0])) == count($ec_conf_index));
105  $u = $ec_conf[0];
106}
107// $v is false
108//   _ if the entry in the table doesn't exist ;
109//   _ if the entry in the table exists, but its number of parameters is
110//     different than the number of default parameters.
111// $u is '0' if the plugin has not yet been activated, '1' if it has been.
112if (!$v) {
113  $ec_conf = array_values($ec_conf_default);
114  change_ec_conf('activated', $u); // writes in the DB
115}
116// now :
117//   _ the number of parameters is the same in the DB as the number of
118//     default parameters ;
119//   _ the parameters have the default values if needed ;
120//   _ the plugin shows it is active if it is the case.
121unset($t, $u, $v);
122
123/*
124 * change_ec_conf($c, $v)
125 * updates Event Cats configuration values in the database as well as in
126 * $ec_conf.
127 *
128 * @param
129 *   $c : conf value to update ;
130 *   $v : value to give to $ec_conf[$c].
131 * @return
132 *   true or false whether the change was OK or not
133 */
134function change_ec_conf($c, $v) {
135  global $ec_conf, $page, $ec_conf_index, $ec_conf_possible_values;
136  if (array_key_exists($c, $ec_conf_index)) {
137    if (
138      count($ec_conf_possible_values[$c]) == 0 or
139      in_array($v, $ec_conf_possible_values[$c])
140    ) {
141      $ec_conf[$ec_conf_index[$c]] = $v;
142      return (pwg_query("
143        UPDATE `".CONFIG_TABLE."`
144        SET `value` = \"".implode(',', $ec_conf)."\"
145        WHERE `param` = 'event_cats';
146      ") !== false);
147    }
148    else {
149      $page['errors'][] = 'Bad change_ec_conf value';
150      return false;
151    }
152  }
153  else {
154    $page['errors'][] = 'Bad change_ec_conf index';
155    return false;
156  }
157}
158
159/*
160 * read_ec_conf($c)
161 * returns the value in $ec_conf using string keys.
162 *
163 * @param
164 *   $c : conf value to update ;
165 * @return
166 *   $ec_conf value
167 */
168function read_ec_conf($c) {
169  global $ec_conf, $page, $ec_conf_index;
170  if (array_key_exists($c, $ec_conf_index))
171   return $ec_conf[$ec_conf_index[$c]];
172  else {
173    $page['errors'][] = 'Bad read_ec_conf index';
174    return false;
175  }
176}
177
178?>
Note: See TracBrowser for help on using the repository browser.