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

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

[Event Cats] Adaptation for PEM

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