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 | |
---|
27 | // *********************************************************************** |
---|
28 | // ** maintain.inc.php: Installation page for Piwigo plugin Event Cats ** |
---|
29 | // *********************************************************************** |
---|
30 | |
---|
31 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
32 | |
---|
33 | global $ec_conf; |
---|
34 | |
---|
35 | if (!defined('EVNTCATS_PATH')) |
---|
36 | define('EVNTCATS_PATH',PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)). '/'); |
---|
37 | |
---|
38 | include_once(EVNTCATS_PATH.'include/ec_conf.inc.php'); |
---|
39 | |
---|
40 | // *********************************************************************** |
---|
41 | function plugin_uninstall() { |
---|
42 | global $prefixeTable; |
---|
43 | |
---|
44 | pwg_query(" |
---|
45 | DELETE IGNORE FROM `".CONFIG_TABLE."` WHERE `param` = 'event_cats' LIMIT 1; |
---|
46 | "); |
---|
47 | return pwg_query('DROP TABLE IF EXISTS `'.$prefixeTable.'event_cats`;'); |
---|
48 | } |
---|
49 | |
---|
50 | // *********************************************************************** |
---|
51 | function plugin_install() { |
---|
52 | global $prefixeTable; |
---|
53 | |
---|
54 | plugin_uninstall(); |
---|
55 | |
---|
56 | // create table for plugin, if it doesn't exist yet |
---|
57 | $r = (pwg_query(" |
---|
58 | CREATE TABLE `".$prefixeTable."event_cats` ( |
---|
59 | `id` SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT , |
---|
60 | `code` VARCHAR(32) DEFAULT NULL , |
---|
61 | `user_id` SMALLINT(5) UNSIGNED DEFAULT NULL , |
---|
62 | `action` ENUM('ec_ok', 'ec_nok') DEFAULT NULL , |
---|
63 | `arg1` SMALLINT(5) UNSIGNED DEFAULT NULL , |
---|
64 | `arg2` SMALLINT(5) UNSIGNED DEFAULT NULL , |
---|
65 | `forced` ENUM('true', 'false') NOT NULL DEFAULT 'false' , |
---|
66 | `comment` VARCHAR(100) DEFAULT NULL , |
---|
67 | PRIMARY KEY (`id`), |
---|
68 | KEY `code` (`code`), |
---|
69 | KEY `user_id` (`user_id`) |
---|
70 | ) |
---|
71 | DEFAULT CHARACTER SET utf8 |
---|
72 | ENGINE=MyISAM; |
---|
73 | ") !== false); |
---|
74 | |
---|
75 | /* |
---|
76 | Explanations on table structure: |
---|
77 | |
---|
78 | code : the code used as "autolog" argument. If thie code provided by the |
---|
79 | visitor does not exist in the table, the administrator can choose |
---|
80 | whether the visitor is redirected to the home page (nothing |
---|
81 | happens) or to the "access denied" page; |
---|
82 | user_id: the account concerned in following values; |
---|
83 | action : the action to perform: |
---|
84 | ec_nok: code disabled: account not logged in, visitor (guest) redirected |
---|
85 | to an explaining Additional Page (arg2 field). If Additional Page |
---|
86 | plugin is not activated, redirection to the "access denied" page; |
---|
87 | ec_ok : code OK, account logged in. Redirection depends on arg1 and arg2 |
---|
88 | values. There are four cases: |
---|
89 | arg1 and arg2 are both NULL: home page; |
---|
90 | arg1 not NULL and arg2 NULL: category; |
---|
91 | arg1 NULL and arg2 not NULL: Additional Page; |
---|
92 | arg1 and arg2 both not NULL: Image page. |
---|
93 | If arg1 is a valid category id, and arg2 is not a valid image id, |
---|
94 | redirection to category. In all other cases where the arg1 or arg2 |
---|
95 | is not valid, redirection to home page. |
---|
96 | arg1 : (described above); |
---|
97 | arg2 : (described above); |
---|
98 | forced : allows the administrator to impose that, for certain codes, the |
---|
99 | settings specified in the database ("action", "arg1", "arg2") are |
---|
100 | applied, whatever can be the arguments given in the URL; |
---|
101 | comment: a reminder for the webmaster. |
---|
102 | |
---|
103 | * As a precision: |
---|
104 | in the PHP code, the "action" can also have the following values, so to |
---|
105 | display accurate messages in the admin page: |
---|
106 | ec_nok_action_pb : the same "code" is used in more than one entries in the |
---|
107 | DB (which is allowed) and is not always associated to |
---|
108 | the same action ('ec_ok' in one or more entries, and |
---|
109 | 'ec_nok' in one or more other entries). This is |
---|
110 | confusing and makes impossible to log in using this |
---|
111 | code; |
---|
112 | ec_nok_userid_pb : the same "code" is used in more than one entries in the |
---|
113 | DB (which is allowed) and is not always associated to |
---|
114 | the same user id. This is confusing and makes |
---|
115 | impossible to log in using this code; |
---|
116 | ec_nok_userid_miss: the user id associated to this code does not exist in |
---|
117 | the user ids table; |
---|
118 | ec_nok_ap_pb : not valid Additional Page id -> access denied; |
---|
119 | ec_ok_ap_pb : not valid Additional Page id -> home page; |
---|
120 | ec_ok_cat_pb : not valid category id -> home page; |
---|
121 | ec_ok_img_pb : not valid image id -> category page; |
---|
122 | |
---|
123 | _ the two main fields are "user_id" and "code", as the main purpose of the |
---|
124 | plugin, and thus of the table, is to establish a relationship between a |
---|
125 | code and an account on the gallery -- a user_id. "action" is an important |
---|
126 | field too, as it tells which action to perform. |
---|
127 | _ though, even if "action", "user_id" and "code" are important, all of them |
---|
128 | can be omitted (thus can be NULL), and both "user_id" and "code" can be |
---|
129 | repeated (thus are not UNIQUE). This because: |
---|
130 | _ the same code can automatically log in ("autolog") the same account |
---|
131 | following several ways, depending on "cat", "img", and "ap" arguments of |
---|
132 | the URL; and thus different ways can be stored in the DB; |
---|
133 | _ a "disabled" code (the user tries to "autolog", but (s)he's not allowed |
---|
134 | to) does not need a corresponding "user_id", thus "user_id" can be NULL; |
---|
135 | _ "user_id" field is used to store groups ids when "code" is NULL, to |
---|
136 | identify groups authorized to duplication; |
---|
137 | _ "code" does not have the MySQL UNIQUE attribute, but it has to be unique |
---|
138 | when the "forced" Event Cats parameter is true, which is the case when this |
---|
139 | code is disabled (outdated). |
---|
140 | |
---|
141 | */ |
---|
142 | |
---|
143 | if ($r) $r = (pwg_query(" |
---|
144 | INSERT INTO `".CONFIG_TABLE."` (`param`,`value`,`comment`) |
---|
145 | VALUES ('event_cats','0','Paramètres du plugin Event Cats'); |
---|
146 | ") !== false); |
---|
147 | |
---|
148 | if ($r) $r = (change_ec_conf('activated', '0')); |
---|
149 | |
---|
150 | if ($r) return true; |
---|
151 | else { |
---|
152 | plugin_uninstall(); |
---|
153 | return false; |
---|
154 | } |
---|
155 | } |
---|
156 | |
---|
157 | // *********************************************************************** |
---|
158 | function plugin_activate() { |
---|
159 | change_ec_conf('activated', '1'); |
---|
160 | } |
---|
161 | |
---|
162 | // *********************************************************************** |
---|
163 | function plugin_deactivate() { |
---|
164 | change_ec_conf('activated', '0'); |
---|
165 | } |
---|
166 | |
---|
167 | ?> |
---|