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