source: extensions/event_cats/maintain.inc.php @ 4080

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

[Event Cats] Form submit beginning, "forced problem" improvement

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