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

Last change on this file since 3970 was 3970, checked in by LucMorizur, 15 years ago

[Event Cats] All files converted in UTF-8 without BOM

File size: 7.6 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, $conf, $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_forced_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
122_ the two main fields are "user_id" and "code", as the main purpose of the
123  plugin, and thus of the table, is to establish a relationship between a
124  code and an account on the gallery -- a user_id. "action" is an important
125  field too, as it tells which action to perform.
126_ though, even if "action", "user_id" and "code" are important, all of them
127  can be omitted (thus can be NULL), and both "user_id" and "code" can be
128  repeated (thus are not UNIQUE). This because :
129  _ the same code can automatically log in ("autolog") the same account
130    following several ways, depending on "cat", "img", and "ap" arguments of
131    the URL ; and thus different ways can be stored in the DB ;
132  _ a "disabled" code (the user tries to "autolog", but (s)he's not allowed
133    to) does not need a corresponding "user_id", thus "user_id" can be NULL ;
134  _ "user_id" field is used to store groups ids when "code" is NULL, to
135    identify groups authorized to duplication ;
136_ "code" does not have the MySQL UNIQUE attribute, but it has to be unique
137  when the "forced" Event Cats parameter is true, which is the case when this
138  code is disabled (outdated).
139
140*/
141  pwg_query('
142   INSERT INTO '.CONFIG_TABLE.' (param,value,comment)
143   VALUES ("event_cats","0,1,0,0","Paramètres du plugin Event Cats");
144  ');
145  change_ec_conf('activated', 0);
146  return $q;
147}
148
149function plugin_activate() {
150  change_ec_conf('activated', 1);
151}
152
153function plugin_deactivate() {
154  change_ec_conf('activated', 0);
155}
156
157?>
Note: See TracBrowser for help on using the repository browser.