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

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

[Event Cats] Adaptation for PEM

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
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  'comment_display'       // the way the comment is displayed in "entries"
83    => '0',               // tab : 0, as tooltip ; 1, on a line under code
84);
85
86$ec_conf_possible_values = array(
87  'activated'          => array('0', '1'),
88  'howto'              => array('0', '1'),
89  'dup_allow'          => array('0', '1', '2'),
90  'duplic_display'     => array('0', '1', '2'),
91  'auto_code_dg_nb'    => array( '4',  '5',  '8', '10', '12', '15',
92                                '16', '20', '24', '25', '30', '32'),
93  'unknown_code'       => array('0', '1', '2'),
94  'unknown_code_ap_id' => array(),
95  'comment_display'    => array('0', '1')
96);
97
98$ec_conf_index = array_flip(array_keys($ec_conf_default));
99
100$t = array(); $u = '0'; $v = false;
101if ($v = (
102  ($t = mysql_fetch_row(pwg_query("
103    SELECT `value`
104    FROM `".CONFIG_TABLE."`
105    WHERE `param` = 'event_cats';
106  "))) !== false)
107) {
108  $v = (count($ec_conf = explode(',', $t[0])) == count($ec_conf_index));
109  $u = $ec_conf[0];
110}
111// $v is false
112//   _ if the entry in the table doesn't exist ;
113//   _ if the entry in the table exists, but its number of parameters is
114//     different than the number of default parameters.
115// $u is '0' if the plugin has not yet been activated, '1' if it has been.
116if (!$v) {
117  $ec_conf = array_values($ec_conf_default);
118  change_ec_conf('activated', $u); // writes in the DB
119}
120// now :
121//   _ the number of parameters is the same in the DB as the number of
122//     default parameters ;
123//   _ the parameters have the default values if needed ;
124//   _ the plugin shows it is active if it is the case.
125unset($t, $u, $v);
126
127/*
128 * change_ec_conf($c, $v)
129 * updates Event Cats configuration values in the database as well as in
130 * $ec_conf.
131 *
132 * @param
133 *   $c : conf value to update ;
134 *   $v : value to give to $ec_conf[$c].
135 * @return
136 *   true or false whether the change was OK or not
137 */
138function change_ec_conf($c, $v) {
139  global $ec_conf, $page, $ec_conf_index, $ec_conf_possible_values;
140  if (array_key_exists($c, $ec_conf_index)) {
141    if (
142      count($ec_conf_possible_values[$c]) == 0 or
143      in_array($v, $ec_conf_possible_values[$c])
144    ) {
145      $ec_conf[$ec_conf_index[$c]] = $v;
146      return (pwg_query("
147        UPDATE `".CONFIG_TABLE."`
148        SET `value` = \"".implode(',', $ec_conf)."\"
149        WHERE `param` = 'event_cats';
150      ") !== false);
151    }
152    else {
153      $page['errors'][] = 'Bad change_ec_conf value';
154      return false;
155    }
156  }
157  else {
158    $page['errors'][] = 'Bad change_ec_conf index';
159    return false;
160  }
161}
162
163/*
164 * read_ec_conf($c)
165 * returns the value in $ec_conf using string keys.
166 *
167 * @param
168 *   $c : conf value to update ;
169 * @return
170 *   $ec_conf value
171 */
172function read_ec_conf($c) {
173  global $ec_conf, $page, $ec_conf_index;
174  if (array_key_exists($c, $ec_conf_index))
175   return $ec_conf[$ec_conf_index[$c]];
176  else {
177    $page['errors'][] = 'Bad read_ec_conf index';
178    return false;
179  }
180}
181
182?>
Note: See TracBrowser for help on using the repository browser.