- Daily/weekly/monthly reset completely rewritten
[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 ((ereg(basename(__FILE__), $_SERVER['PHP_SELF']))) {
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 `last_salt` VARCHAR( 255 ) NOT NULL DEFAULT '',
59 `reward` FLOAT(10,5) UNSIGNED  NOT NULL DEFAULT '0.00000',
60 `costs` FLOAT(10,5) UNSIGNED  NOT NULL DEFAULT '0.00000',
61 `payment_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
62 `views_total` BIGINT(20) UNSIGNED  NOT NULL DEFAULT '0',
63 `status` ENUM('PENDING','CONFIRMED', 'LOCKED') NOT NULL DEFAULT 'CONFIRMED',
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 PRIMARY KEY(`id`),
68 UNIQUE KEY `userid_url` (`userid`, `url`)
69 ) TYPE=MyISAM COMMENT='Surfbar URLs'";
70
71         // Reload locks
72         $SQLs[] = "DROP TABLE IF EXISTS `"._MYSQL_PREFIX."_surfbar_locks`";
73         $SQLs[] = "CREATE TABLE `"._MYSQL_PREFIX."_surfbar_locks` (
74 `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
75 `userid` BIGINT(20) UNSIGNED  NOT NULL DEFAULT '0',
76 `url_id` BIGINT(20) UNSIGNED  NOT NULL DEFAULT '0',
77 `last_surfed` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
78 PRIMARY KEY(`id`),
79 INDEX (`userid`),
80 INDEX (`url_id`)
81 ) TYPE=MyISAM COMMENT='Surfbar reload locks'";
82
83         // Surfbar salts
84         $SQLs[] = "DROP TABLE IF EXISTS `"._MYSQL_PREFIX."_surfbar_salts`";
85         $SQLs[] = "CREATE TABLE `"._MYSQL_PREFIX."_surfbar_salts` (
86 `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
87 `userid` BIGINT(20) UNSIGNED  NOT NULL DEFAULT '0',
88 `url_id` BIGINT(20) UNSIGNED  NOT NULL DEFAULT '0',
89 `last_salt` VARCHAR(255) NOT NULL DEFAULT '',
90 PRIMARY KEY(`id`),
91 INDEX (`userid`),
92 INDEX (`url_id`)
93 ) TYPE=MyISAM COMMENT='Surfbar last used salts'";
94
95         // Reload locks
96         $SQLs[] = "DROP TABLE IF EXISTS `"._MYSQL_PREFIX."_surfbar_reflevels`";
97         $SQLs[] = "CREATE TABLE `"._MYSQL_PREFIX."_surfbar_reflevels` (
98 `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
99 `level` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',
100 `percent` FLOAT(10,5) UNSIGNED NOT NULL DEFAULT '0.00000',
101 PRIMARY KEY(`id`)
102 ) TYPE=MyISAM COMMENT='Surfbar referal levels'";
103
104         // Statistics
105         $SQLs[] = "DROP TABLE IF EXISTS `"._MYSQL_PREFIX."_surfbar_stats`";
106         $SQLs[] = "CREATE TABLE `"._MYSQL_PREFIX."_surfbar_stats` (
107 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
108 `userid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
109 `url_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
110 `count` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
111 `last_online` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
112 PRIMARY KEY (`id`),
113 INDEX (`userid`,`url_id`)
114 ) TYPE=MyISAM COMMENT='Surfbar Statistics'";
115
116         // Add default referal level 0 with 100%
117         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_surfbar_reflevels` (`level`, `percent`) VALUES (0, 100)";
118
119         // Config entries
120         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_pay_model` ENUM('STATIC','DYNAMIC') NOT NULL DEFAULT 'STATIC'";
121         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_static_reward` FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.25000";
122         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_static_costs` FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 1.00000";
123         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_static_time` SMALLINT(6) UNSIGNED NOT NULL DEFAULT 60";
124         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_static_lock` SMALLINT(6) UNSIGNED NOT NULL DEFAULT ".(60*5)."";
125         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_notify_admin_unlock` ENUM('N','Y') NOT NULL DEFAULT 'N'";
126         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_dynamic_percent` FLOAT(10,5) UNSIGNED NOT NULL DEFAULT 10.00000";
127         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_max_order` INT(7) UNSIGNED NOT NULL DEFAULT 10";
128         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_restart_time` BIGINT(20) UNSIGNED NOT NULL DEFAULT ".(60*6)."";
129         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_autostart` ENUM('Y','N') NOT NULL DEFAULT 'Y'";
130         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_total_counter` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0";
131         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_daily_counter` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0";
132         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_weekly_counter` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0";
133         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_monthly_counter` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0";
134         $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD `surfbar_stats_reload` BIGINT(20) UNSIGNED NOT NULL DEFAULT 30";
135
136         // Member menus
137         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('surfbar',NULL,'Surfbar','Y','Y',4)";
138         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('surfbar','surfbar_start','Surfbar starten','Y','Y',1)";
139         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('surfbar','surfbar_book','URL buchen','Y','Y',2)";
140         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('surfbar','surfbar_stats','URL-Statistiken','Y','Y',3)";
141
142         // Admin menus
143         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('surfbar','','Surfbar','URLs in der Surfbar verwalten, Einstellungen &auml;ndern und vieles mehr.',7)";
144         $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.',1)";
145         $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.',2)";
146         $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('surfbar','list_surfbar_reflvl','Referal-Ebenen einstellen','Stellen Sie hier die prozentuale Verg&uuml;tung f&uuml;r Refs ein. Es wird nur die Basisverg&uuml;tung zur Rechengrundlage der Referalverg&uuml;tung verwendet.',3)";
147         $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)";
148
149         // Load CSS?
150         $EXT_CSS = "Y";
151         break;
152
153 case "remove": // Do stuff when removing extension
154         // SQL commands to run
155         $SQLs[] = "DROP TABLE IF EXISTS `"._MYSQL_PREFIX."_surfbar_urls`";
156         $SQLs[] = "DROP TABLE IF EXISTS `"._MYSQL_PREFIX."_surfbar_locks`";
157         $SQLs[] = "DROP TABLE IF EXISTS `"._MYSQL_PREFIX."_surfbar_reflevels`";
158         $SQLs[] = "DROP TABLE IF EXISTS `"._MYSQL_PREFIX."_surfbar_salts`";
159         $SQLs[] = "DROP TABLE IF EXISTS `"._MYSQL_PREFIX."_surfbar_stats`";
160         $SQLs[] = "DELETE LOW_PRIORITY FROM `"._MYSQL_PREFIX."_member_menu` WHERE `action`='surfbar' LIMIT 3";
161         $SQLs[] = "DELETE LOW_PRIORITY FROM `"._MYSQL_PREFIX."_admin_menu` WHERE action='surfbar' LIMIT 5";
162         break;
163
164 case "activate": // Do stuff when admin activates this extension
165         // SQL commands to run
166         $SQLs[] = "UPDATE `"._MYSQL_PREFIX."_member_menu` SET `visible`='Y', `locked`='N' WHERE `action`='surfbar' LIMIT 3";
167         break;
168
169 case "deactivate": // Do stuff when admin deactivates this extension
170         // SQL commands to run
171         $SQLs[] = "UPDATE `"._MYSQL_PREFIX."_member_menu` SET `locked`='Y' WHERE `action` = 'surfbar' LIMIT 3";
172         break;
173
174 case "update": // Update an extension
175         switch ($EXT_VER)
176         {
177         case "0.0.1": // SQL queries for v0.0.1
178                 $SQLs[] = "";
179
180                 // Update notes (these will be set as task text!)
181                 $UPDATE_NOTES = "";
182                 break;
183         }
184         break;
185
186 default: // Do stuff when extension is loaded
187         $dummy = LOAD_CONFIG();
188         $_CONFIG = merge_array($_CONFIG, $dummy);
189         unset($dummy);
190         break;
191 }
192
193 // Language file prefix
194 $EXT_LANG_PREFIX = "surfbar";
195
196 // Extension is always active?
197 $EXT_ALWAYS_ACTIVE = "N";
198
199 //
200 ?>