More fixes, menus are no longer set visible if extension is deactivated, thanks to...
[mailer.git] / inc / extensions / ext-surfbar.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 08/28/2008 *
4  * ================                             Last change: 08/28/2008 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : ext-surfbar.php                                  *
8  * -------------------------------------------------------------------- *
9  * Short description : A surfbar for your members                       *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Eine Surfbar fuer Ihre Mitglieder                *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Version number
41 $EXT_VERSION = "0.0";
42
43 // Auto-set extension version
44 if (empty($EXT_VER)) $EXT_VER = $EXT_VERSION;
45
46 // Version history array (add more with , "0.1" and so on)
47 $EXT_VER_HISTORY = array("0.0");
48
49 switch ($EXT_LOAD_MODE)
50 {
51 case "register": // Do stuff when installation is running (modules.php?module=admin&action=login is called)
52         // SQL commands to run (surfbar URLs)
53         $SQLs[] = "DROP TABLE IF EXISTS `"._MYSQL_PREFIX."_surfbar_urls`";
54         $SQLs[] = "CREATE TABLE `"._MYSQL_PREFIX."_surfbar_urls` (
55 `id` BIGINT(20) UNSIGNED  NOT NULL AUTO_INCREMENT,
56 `userid` BIGINT(20) UNSIGNED  NOT NULL DEFAULT 0,
57 `url` VARCHAR(255) NOT NULL DEFAULT '',
58 `last_salt` VARCHAR(255) NOT NULL DEFAULT '',
59 `views_total` BIGINT(20) UNSIGNED  NOT NULL DEFAULT 0,
60 `views_max` BIGINT(20) UNSIGNED  NOT NULL DEFAULT 0,
61 `views_allowed` BIGINT(20) UNSIGNED  NOT NULL DEFAULT 0,
62 `status` ENUM('PENDING','ACTIVE','LOCKED','STOPPED','REJECTED','DELETED','MIGRATED','DEPLETED') NOT NULL DEFAULT 'PENDING',
63 `registered` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
64 `last_locked` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
65 `lock_reason` VARCHAR(255) NOT NULL DEFAULT '',
66 `reject_reason` VARCHAR(255) NOT NULL DEFAULT '',
67 `fixed_reload` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
68 PRIMARY KEY(`id`),
69 UNIQUE KEY `userid_url` (`userid`,`url`),
70 INDEX `status_userid` (`status`,`userid`)
71 ) TYPE=MyISAM COMMENT='Surfbar URLs'";
72
73         // Reload locks
74         $SQLs[] = "DROP TABLE IF EXISTS `"._MYSQL_PREFIX."_surfbar_locks`";
75         $SQLs[] = "CREATE TABLE `"._MYSQL_PREFIX."_surfbar_locks` (
76 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
77 `userid` BIGINT(20) UNSIGNED  NOT NULL DEFAULT 0,
78 `url_id` BIGINT(20) UNSIGNED  NOT NULL DEFAULT 0,
79 `last_surfed` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
80 PRIMARY KEY(`id`),
81 UNIQUE KEY `userid_url` (`userid`,`url_id`),
82 INDEX (`url_id`)
83 ) TYPE=MyISAM COMMENT='Surfbar reload locks'";
84
85         // Surfbar salts
86         $SQLs[] = "DROP TABLE IF EXISTS `"._MYSQL_PREFIX."_surfbar_salts`";
87         $SQLs[] = "CREATE TABLE `"._MYSQL_PREFIX."_surfbar_salts` (
88 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
89 `userid` BIGINT(20) UNSIGNED  NOT NULL DEFAULT 0,
90 `url_id` BIGINT(20) UNSIGNED  NOT NULL DEFAULT 0,
91 `last_salt` VARCHAR(255) NOT NULL DEFAULT '',
92 PRIMARY KEY(`id`),
93 UNIQUE KEY `userid_url` (`userid`,`url_id`),
94 INDEX (`url_id`)
95 ) TYPE=MyISAM COMMENT='Surfbar last used salts'";
96
97         // Statistics
98         $SQLs[] = "DROP TABLE IF EXISTS `"._MYSQL_PREFIX."_surfbar_stats`";
99         $SQLs[] = "CREATE TABLE `"._MYSQL_PREFIX."_surfbar_stats` (
100 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
101 `userid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
102 `url_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
103 `count` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
104 `last_online` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
105 PRIMARY KEY (`id`),
106 UNIQUE KEY `userid_url` (`userid`,`url_id`),
107 INDEX (`url_id`)
108 ) TYPE=MyISAM COMMENT='Surfbar Statistics'";
109
110         // Member actions pending on status
111         $SQLs[] = "DROP TABLE IF EXISTS `"._MYSQL_PREFIX."_surfbar_actions`";
112         $SQLs[] = "CREATE TABLE `"._MYSQL_PREFIX."_surfbar_actions` (
113 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
114 `status` ENUM('PENDING','ACTIVE','LOCKED','STOPPED','REJECTED','DELETED','MIGRATED','DEPLETED') NULL DEFAULT NULL,
115 `action` ENUM('EDIT','DELETE','PAUSE','UNPAUSE','FRAMETEST','RETREAT','RESUBMIT','BOOKNOW') NULL DEFAULT NULL,
116 `new_status` ENUM('PENDING','ACTIVE','LOCKED','STOPPED','REJECTED','DELETED','MIGRATED','DEPLETED') NULL DEFAULT NULL,
117 PRIMARY KEY (`id`),
118 UNIQUE KEY `status_action` (`status`,`action`)
119 ) TYPE=MyISAM COMMENT='Surfbar Member Actions'";
120
121         // Member actions
122         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES ('PENDING','RETREAT','DELETED')";
123         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES ('PENDING','FRAMETEST',NULL)";
124         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES ('PENDING','EDIT',NULL)";
125         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES ('ACTIVE','EDIT','PENDING')";
126         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES ('ACTIVE','DELETE','DELETED')";
127         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES ('ACTIVE','PAUSE','STOPPED')";
128         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES ('ACTIVE','FRAMETEST',NULL)";
129         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES ('LOCKED','DELETE','DELETED')";
130         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES ('LOCKED','FRAMETEST',NULL)";
131         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES ('LOCKED','RESUBMIT','PENDING')";
132         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES ('STOPPED','EDIT','PENDING')";
133         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES ('STOPPED','DELETE','DELETED')";
134         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES ('STOPPED','UNPAUSE','PENDING')";
135         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES ('DEPLETED','EDIT','PENDING')";
136         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES ('DEPLETED','DELETE','DELETED')";
137         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES ('REJECTED','EDIT','PENDING')";
138         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES ('REJECTED','DELETE','DELETED')";
139         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES ('REJECTED','FRAMETEST',NULL)";
140         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES ('REJECTED','RESUBMIT','PENDING')";
141         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES ('MIGRATED','EDIT','MIGRATED')";
142         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES ('MIGRATED','DELETE','DELETED')";
143         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES ('MIGRATED','FRAMETEST',NULL)";
144         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES ('MIGRATED','BOOKNOW','PENDING')";
145
146         // Config entries
147         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_pay_model` ENUM('STATIC','DYNAMIC') NOT NULL DEFAULT 'STATIC'";
148         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_static_reward` FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.25000";
149         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_static_costs` FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 1.00000";
150         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_static_time` SMALLINT(6) UNSIGNED NOT NULL DEFAULT 60";
151         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_static_lock` SMALLINT(6) UNSIGNED NOT NULL DEFAULT ".(60*5)."";
152         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_dynamic_percent` FLOAT(10,5) UNSIGNED NOT NULL DEFAULT 10.00000";
153         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_max_order` INT(7) UNSIGNED NOT NULL DEFAULT 10";
154         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_restart_time` BIGINT(20) UNSIGNED NOT NULL DEFAULT ".(60*6)."";
155         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_autostart` ENUM('Y','N') NOT NULL DEFAULT 'Y'";
156         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_migrate_urls` ENUM('Y','N') NOT NULL DEFAULT 'Y'";
157         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_total_counter` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0";
158         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_daily_counter` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0";
159         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_yester_counter` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0";
160         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_weekly_counter` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0";
161         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_monthly_counter` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0";
162         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_stats_reload` BIGINT(20) UNSIGNED NOT NULL DEFAULT 30";
163         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_purge_deleted` BIGINT(20) UNSIGNED NOT NULL DEFAULT ".($_CONFIG['one_day']*7)."";
164         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_purge_migrated` BIGINT(20) UNSIGNED NOT NULL DEFAULT ".($_CONFIG['one_day']*3)."";
165         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_pause_mode` ENUM('INTERNAL','EXERNAL') NOT NULL DEFAULT 'INTERNAL'";
166         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_pause_url` VARCHAR(255) NOT NULL DEFAULT ''";
167         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_notify_limits` ENUM('Y','N') NOT NULL DEFAULT 'Y'";
168         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_warn_low_points` BIGINT(20) UNSIGNED NOT NULL DEFAULT 100";
169         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_low_interval` BIGINT(20) UNSIGNED NOT NULL DEFAULT ".$_CONFIG['one_day']."";
170         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_migrate_order` ENUM('Y','N') NOT NULL DEFAULT 'Y'";
171         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_notification_mode` ENUM('INSTANT','RESET') NOT NULL DEFAULT 'INSTANT'";
172
173         // Extend user data
174         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_user_data` ADD `surfbar_low_notified` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00'";
175
176         // Member menus
177         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('surfbar',NULL,'Surfbar','Y','Y',4)";
178         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('surfbar','surfbar_start','Surfbar starten','Y','Y',1)";
179         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('surfbar','surfbar_book','URL buchen','Y','Y',2)";
180         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('surfbar','surfbar_list','URL-Verwaltung','Y','Y',3)";
181         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('surfbar','surfbar_stats','URL-Statistiken','Y','Y',4)";
182
183         // Admin menus
184         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('surfbar',NULL,'Surfbar','URLs in der Surfbar verwalten, Einstellungen &auml;ndern und vieles mehr.',7)";
185         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('surfbar','add_surfbar_url','URL hinzuf&uuml;gen','F&uuml;gen Sie URLs z.B. von Werbenetzwerken hinzu, oder Ihre eigenen Projekte. <strong>Vorsicht!</strong> Ihnen muss es auch gestattet sein, URLs aus dem Werbenetzwerk in die Surfbar einzuf&uuml;gen.',1)";
186         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('surfbar','list_surfbar_urls','URLs verwalten','Verwalten Sie hier alle in der Surfbar befindlichen URLs mit nur wenigen Klicks.',2)";
187         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('surfbar','unlock_surfbar_urls','Wartende URLs freigeben','Geben Sie hier nur direkt in der Surfbar gebuchte URLs frei.',3)";
188         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('surfbar','config_surfbar','Einstellungen','Einstellungen an der Surfbar &auml;ndern, wie Festverg&uuml;tung, prozentuale Ref-Verg&uuml;tung und vieles mehr.',4)";
189         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('surfbar','surfbar_stats','Statistiken','Detailierte Statistiken zu einer ausgew&auml;hlten URL anzeigen.',5)";
190         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('surfbar','list_surfbar_actions','Mitgliederaktionen','Listet alle Mitgliederaktionen auf.',6)";
191
192         // Load CSS?
193         $EXT_CSS = "Y";
194         break;
195
196 case "remove": // Do stuff when removing extension
197         // SQL commands to run
198         $SQLs[] = "DROP TABLE IF EXISTS `"._MYSQL_PREFIX."_surfbar_actions`";
199         $SQLs[] = "DROP TABLE IF EXISTS `"._MYSQL_PREFIX."_surfbar_locks`";
200         $SQLs[] = "DROP TABLE IF EXISTS `"._MYSQL_PREFIX."_surfbar_salts`";
201         $SQLs[] = "DROP TABLE IF EXISTS `"._MYSQL_PREFIX."_surfbar_stats`";
202         $SQLs[] = "DROP TABLE IF EXISTS `"._MYSQL_PREFIX."_surfbar_urls`";
203         $SQLs[] = "DELETE LOW_PRIORITY FROM `"._MYSQL_PREFIX."_member_menu` WHERE `action`='surfbar' LIMIT 5";
204         $SQLs[] = "DELETE LOW_PRIORITY FROM `"._MYSQL_PREFIX."_admin_menu` WHERE `action`='surfbar' LIMIT 7";
205         break;
206
207 case "activate": // Do stuff when admin activates this extension
208         // SQL commands to run
209         $SQLs[] = "UPDATE `"._MYSQL_PREFIX."_member_menu` SET `visible`='Y', `locked`='N' WHERE `action`='surfbar' LIMIT 5";
210         $SQLs[] = "UPDATE `"._MYSQL_PREFIX."_mod_reg` SET locked='N', hidden='N', admin_only='N', mem_only='Y' WHERE module='surfbar' LIMIT 1";
211         break;
212
213 case "deactivate": // Do stuff when admin deactivates this extension
214         // SQL commands to run
215         $SQLs[] = "UPDATE `"._MYSQL_PREFIX."_member_menu` SET visible='N', `locked`='Y' WHERE `action` = 'surfbar' LIMIT 5";
216         $SQLs[] = "UPDATE `"._MYSQL_PREFIX."_mod_reg` SET locked='Y' WHERE module='surfbar' LIMIT 1";
217         break;
218
219 case "update": // Update an extension
220         switch ($EXT_VER) {
221         case "0.0.1": // SQL queries for v0.0.1
222                 $SQLs[] = "";
223
224                 // Update notes (these will be set as task text!)
225                 $UPDATE_NOTES = "";
226                 break;
227         }
228         break;
229
230 default: // Do stuff when extension is loaded
231         // Set some constants we need???
232         define('edit', "edit");
233         break;
234 }
235
236 //
237 ?>