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

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

[Event Cats] Improve configuration parameters management

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