- Surfbar further extended, currently broken!
[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 installtion 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 `payment_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
59 `last_salt` VARCHAR(255) NOT NULL DEFAULT '',
60 `views_total` BIGINT(20) UNSIGNED  NOT NULL DEFAULT '0',
61 `views_max` BIGINT(20) UNSIGNED  NOT NULL DEFAULT '0',
62 `views_allowed` BIGINT(20) UNSIGNED  NOT NULL DEFAULT '0',
63 `status` ENUM('PENDING','ACTIVE','LOCKED','STOPPED','REJECTED','DELETED','MIGRATED') NOT NULL DEFAULT 'PENDING',
64 `registered` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
65 `last_locked` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
66 `lock_reason` VARCHAR(255) NOT NULL DEFAULT '',
67 `reject_reason` VARCHAR(255) NOT NULL DEFAULT '',
68 PRIMARY KEY(`id`),
69 UNIQUE KEY `userid_url` (`userid`,`url`),
70 INDEX (`payment_id`)
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 INDEX (`userid`),
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 INDEX (`userid`),
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 INDEX (`userid`,`url_id`)
107 ) TYPE=MyISAM COMMENT='Surfbar Statistics'";
108
109         // Member actions pending on status
110         $SQLs[] = "DROP TABLE IF EXISTS `"._MYSQL_PREFIX."_surfbar_actions`";
111         $SQLs[] = "CREATE TABLE `"._MYSQL_PREFIX."_surfbar_actions` (
112 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
113 `status` ENUM('PENDING','ACTIVE','LOCKED','STOPPED','REJECTED','DELETED','MIGRATED') NOT NULL DEFAULT 'PENDING',
114 `action` ENUM('EDIT','DELETE','PAUSE','UNPAUSE','FRAMETEST','RETREAT','RESUBMIT','BOOKNOW') NULL DEFAULT NULL,
115 `new_status` ENUM('PENDING','ACTIVE','LOCKED','STOPPED','REJECTED','DELETED','MIGRATED') NULL DEFAULT NULL,
116 PRIMARY KEY (`id`),
117 INDEX (`status`)
118 ) TYPE=MyISAM COMMENT='Surfbar Member Actions'";
119
120         // Member actions
121         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES('PENDING','RETREAT','DELETED')";
122         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES('PENDING','FRAMETEST',NULL)";
123         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES('ACTIVE','EDIT','PENDING')";
124         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES('ACTIVE','DELETE','DELETED')";
125         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES('ACTIVE','PAUSE','STOPPED')";
126         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES('ACTIVE','FRAMETEST',NULL)";
127         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES('LOCKED','DELETE','DELETED')";
128         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES('LOCKED','FRAMETEST',NULL)";
129         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES('LOCKED','RESUBMIT','PENDING')";
130         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES('STOPPED','EDIT','PENDING')";
131         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES('STOPPED','DELETE','DELETED')";
132         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES('STOPPED','UNPAUSE','PENDING')";
133         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES('REJECTED','EDIT','PENDING')";
134         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES('REJECTED','DELETE','DELETED')";
135         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES('REJECTED','FRAMETEST',NULL)";
136         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES('REJECTED','RESUBMIT','PENDING')";
137         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES('MIGRATED','EDIT','PENDING')";
138         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES('MIGRATED','DELETE','DELETED')";
139         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES('MIGRATED','FRAMETEST',NULL)";
140         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_actions` (`status`,`action`,`new_status`) VALUES('MIGRATED','BOOKNOW','PENDING')";
141
142         // Config entries
143         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_pay_model` ENUM('STATIC','DYNAMIC') NOT NULL DEFAULT 'STATIC'";
144         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_static_reward` FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.25000";
145         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_static_costs` FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 1.00000";
146         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_static_time` SMALLINT(6) UNSIGNED NOT NULL DEFAULT 60";
147         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_static_lock` SMALLINT(6) UNSIGNED NOT NULL DEFAULT ".(60*5)."";
148         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_dynamic_percent` FLOAT(10,5) UNSIGNED NOT NULL DEFAULT 10.00000";
149         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_max_order` INT(7) UNSIGNED NOT NULL DEFAULT 10";
150         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_restart_time` BIGINT(20) UNSIGNED NOT NULL DEFAULT ".(60*6)."";
151         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_autostart` ENUM('Y','N') NOT NULL DEFAULT 'Y'";
152         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_migrate_urls` ENUM('Y','N') NOT NULL DEFAULT 'Y'";
153         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_total_counter` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0";
154         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_daily_counter` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0";
155         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_yester_counter` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0";
156         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_weekly_counter` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0";
157         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_monthly_counter` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0";
158         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_stats_reload` BIGINT(20) UNSIGNED NOT NULL DEFAULT 30";
159         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_purge_deleted` BIGINT(20) UNSIGNED NOT NULL DEFAULT ".($_CONFIG['one_day']*7)."";
160         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_purge_migrated` BIGINT(20) UNSIGNED NOT NULL DEFAULT ".($_CONFIG['one_day']*3)."";
161         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_pause_mode` ENUM('INTERNAL','EXERNAL') NOT NULL DEFAULT 'INTERNAL'";
162         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_pause_url` VARCHAR(255) NOT NULL DEFAULT ''";
163         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_notify_limits` ENUM('Y','N') NOT NULL DEFAULT 'Y'";
164         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_warn_low_points` BIGINT(20) NOT NULL DEFAULT 100";
165         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_migrate_order` ENUM('Y','N') NOT NULL DEFAULT 'Y'";
166
167         // Extend user data
168         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_user_data` ADD `surfbar_low_notified` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00'";
169
170         // Member menus
171         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('surfbar',NULL,'Surfbar','Y','Y',4)";
172         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('surfbar','surfbar_start','Surfbar starten','Y','Y',1)";
173         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('surfbar','surfbar_book','URL buchen','Y','Y',2)";
174         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('surfbar','surfbar_list','URL-Verwaltung','Y','Y',3)";
175         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('surfbar','surfbar_stats','URL-Statistiken','Y','Y',4)";
176
177         // Admin menus
178         $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)";
179         $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)";
180         $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)";
181         $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)";
182         $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)";
183         $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)";
184         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('surfbar','surfbar_actions','Mitgliederaktionen','Listet alle Mitgliederaktionen auf.',6)";
185
186         // Load CSS?
187         $EXT_CSS = "Y";
188         break;
189
190 case "remove": // Do stuff when removing extension
191         // SQL commands to run
192         $SQLs[] = "DROP TABLE IF EXISTS `"._MYSQL_PREFIX."_surfbar_actions`";
193         $SQLs[] = "DROP TABLE IF EXISTS `"._MYSQL_PREFIX."_surfbar_locks`";
194         $SQLs[] = "DROP TABLE IF EXISTS `"._MYSQL_PREFIX."_surfbar_salts`";
195         $SQLs[] = "DROP TABLE IF EXISTS `"._MYSQL_PREFIX."_surfbar_stats`";
196         $SQLs[] = "DROP TABLE IF EXISTS `"._MYSQL_PREFIX."_surfbar_urls`";
197         $SQLs[] = "DELETE LOW_PRIORITY FROM `"._MYSQL_PREFIX."_member_menu` WHERE `action`='surfbar' LIMIT 5";
198         $SQLs[] = "DELETE LOW_PRIORITY FROM `"._MYSQL_PREFIX."_admin_menu` WHERE `action`='surfbar' LIMIT 7";
199         break;
200
201 case "activate": // Do stuff when admin activates this extension
202         // SQL commands to run
203         $SQLs[] = "UPDATE `"._MYSQL_PREFIX."_member_menu` SET `visible`='Y', `locked`='N' WHERE `action`='surfbar' LIMIT 5";
204         break;
205
206 case "deactivate": // Do stuff when admin deactivates this extension
207         // SQL commands to run
208         $SQLs[] = "UPDATE `"._MYSQL_PREFIX."_member_menu` SET `locked`='Y' WHERE `action` = 'surfbar' LIMIT 5";
209         break;
210
211 case "update": // Update an extension
212         switch ($EXT_VER)
213         {
214         case "0.0.1": // SQL queries for v0.0.1
215                 $SQLs[] = "";
216
217                 // Update notes (these will be set as task text!)
218                 $UPDATE_NOTES = "";
219                 break;
220         }
221         break;
222
223 default: // Do stuff when extension is loaded
224         break;
225 }
226
227 // Language file prefix
228 $EXT_LANG_PREFIX = "surfbar";
229
230 // Extension is always active?
231 $EXT_ALWAYS_ACTIVE = "N";
232
233 //
234 ?>