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

Revision 4263, 5.3 KB checked in by LucMorizur, 10 years ago (diff)

[Event Cats] Continue duplication management

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  'duplic_gen'            // whether Generic accounts allow to be duplicated
43    => '0',               //
44                          //
45  'duplic_type'           // the kind of account type (Contacts, Friends,
46    => '0',               // Family) allowed to duplicate account
47                          //
48  'howto'                 // whether the small aknowledgement message has
49    => '0',               // already been displayed
50                          //
51  'unknown_code'          // what to do in case an unknown code is used with
52    => '1',               // "autolog" parameter :
53                          //   0 : nothing (display home page, index.php (not
54                          //       logged in of course)) ;
55                          //   1 : display "access denied" page ;
56                          //   2 : display an Additional Page precised below.
57                          //
58  'unknown_code_ap_id'    // the id of the Additional Page which must be used
59    => '0',               // in case of usage of an unknow code.
60);
61
62$ec_conf_index = array_flip(array_keys($ec_conf_default));
63
64$t = array(); $u = '0'; $v = false;
65if ($v = (
66  ($t = mysql_fetch_row(pwg_query("
67    SELECT `value`
68    FROM `".CONFIG_TABLE."`
69    WHERE `param` = 'event_cats';
70  "))) !== false)
71) {
72  $v = (count($ec_conf = explode(',', $t[0])) == count($ec_conf_index));
73  $u = $ec_conf[0];
74}
75// $v is false
76//   _ if the entry in the table doesn't exist ;
77//   _ if the entry in the table exists, but its number of parameters is
78//     different than the number of default parameters.
79// $u is '0' if the plugin has not yet been activated, '1' if it has been.
80if (!$v) {
81  $ec_conf = array_values($ec_conf_default);
82  change_ec_conf('activated', $u); // writes in the DB
83}
84// now :
85//   _ the number of parameters is the same in the DB as the number of
86//     default parameters ;
87//   _ the parameters have the default values if needed ;
88//   _ the plugin shows it is active if it is the case.
89unset($t, $u, $v);
90
91/*
92 * change_ec_conf($c, $v)
93 * updates Event Cats configuration values in the database as well as in
94 * $ec_conf.
95 *
96 * @param
97 *   $c : conf value to update ;
98 *   $v : value to give to $ec_conf[$c].
99 * @return
100 *   true or false whether the change was OK or not
101 */
102function change_ec_conf($c, $v) {
103  global $ec_conf, $page, $ec_conf_index;
104  if (array_key_exists($c, $ec_conf_index)) {
105    $ec_conf[$ec_conf_index[$c]] = $v;
106    return (pwg_query("
107      UPDATE `".CONFIG_TABLE."`
108      SET `value` = \"".implode(',', $ec_conf)."\"
109      WHERE `param` = 'event_cats';
110    ") !== false);
111  }
112  else {
113    $page['errors'][] = 'Bad change_ec_conf argument';
114    return false;
115  }
116}
117
118/*
119 * read_ec_conf($c)
120 * returns the value in $ec_conf using string keys.
121 *
122 * @param
123 *   $c : conf value to update ;
124 * @return
125 *   $ec_conf value
126 */
127function read_ec_conf($c) {
128  global $ec_conf, $page, $ec_conf_index;
129  if (array_key_exists($c, $ec_conf_index))
130   return $ec_conf[$ec_conf_index[$c]];
131  else {
132    $page['errors'][] = 'Bad read_ec_conf argument';
133    return false;
134  }
135}
136
137?>
Note: See TracBrowser for help on using the repository browser.