AJAX installation is 'basicly finished' :) Plus I threw in a small christmas present...
[mailer.git] / inc / extensions / ext-surfbar.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 08/28/2008 *
4  * ===================                          Last change: 08/28/2008 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : ext-surfbar.php                                  *
8  * -------------------------------------------------------------------- *
9  * Short description : A visitor add-on for your members                *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Ein Besuchertausch fuer Ihre Mitglieder          *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } // END - if
42
43 // Version number
44 setThisExtensionVersion('0.0.0');
45
46 // Version history array (add more with , '0.0.1' and so on)
47 setExtensionVersionHistory(array('0.0.0'));
48
49 // This extension is in development (non-productive)
50 enableExtensionProductive(FALSE);
51
52 switch (getExtensionMode()) {
53         case 'register': // Do stuff when installation is running
54                 // SQL commands to run (surfbar URLs)
55                 addDropTableSql('surfbar_urls');
56                 addCreateTableSql('surfbar_urls', "
57 `url_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
58 `url_userid` BIGINT(20) UNSIGNED NULL DEFAULT NULL,
59 `url_package_id` BIGINT(20) UNSIGNED NULL DEFAULT NULL,
60 `url` VARCHAR(255) NOT NULL DEFAULT '',
61 `url_last_salt` VARCHAR(255) NOT NULL DEFAULT '',
62 `url_views_total` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
63 `url_views_max` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
64 `url_views_allowed` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
65 `url_status` ENUM('PENDING', 'ACTIVE', 'LOCKED', 'STOPPED', 'REJECTED', 'DELETED', 'MIGRATED', 'DEPLETED') NOT NULL DEFAULT 'PENDING',
66 `url_registered` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
67 `url_last_locked` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
68 `url_lock_reason` VARCHAR(255) NOT NULL DEFAULT '',
69 `url_reject_reason` VARCHAR(255) NOT NULL DEFAULT '',
70 `url_fixed_reload` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
71 `url_fixed_waiting` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
72 PRIMARY KEY (`url_id`),
73 UNIQUE INDEX `userid_url` (`url_userid`, `url`),
74 INDEX `status_userid` (`url_status`, `url_userid`),
75 INDEX (`url_package_id`)",
76                         'Visitor add-on URLs');
77
78                 // Booking packages for members
79                 addDropTableSql('surfbar_packages');
80                 addCreateTableSql('surfbar_packages', "
81 `package_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
82 `package_reload` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
83 `package_waiting` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
84 `package_points_costs` FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.00000,
85 `package_points_reward` FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.00000,
86 PRIMARY KEY (`package_id`),
87 UNIQUE INDEX `package` (`package_reload`, `package_waiting`)",
88                         'Booking packages');
89
90                 // Reload locks
91                 addDropTableSql('surfbar_locks');
92                 addCreateTableSql('surfbar_locks', "
93 `locks_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
94 `locks_userid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
95 `locks_url_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
96 `locks_last_surfed` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
97 PRIMARY KEY (`locks_id`),
98 UNIQUE INDEX `userid_url` (`locks_userid`, `locks_url_id`),
99 INDEX (`locks_url_id`)",
100                         'Vistor-addon reload locks');
101
102                 // Visitor add-on salts
103                 addDropTableSql('surfbar_salts');
104                 addCreateTableSql('surfbar_salts', "
105 `salts_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
106 `salts_userid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
107 `salts_url_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
108 `salts_last_salt` VARCHAR(255) NOT NULL DEFAULT '',
109 PRIMARY KEY (`salts_id`),
110 UNIQUE INDEX `salts_userid_url` (`salts_userid`, `salts_url_id`),
111 INDEX (`salts_url_id`)",
112                         'Visitor add-on last used salts');
113
114                 // Statistics
115                 addDropTableSql('surfbar_stats');
116                 addCreateTableSql('surfbar_stats', "
117 `stats_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
118 `stats_userid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
119 `stats_url_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
120 `stats_count` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
121 `stats_last_surfed` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
122 PRIMARY KEY (`stats_id`),
123 UNIQUE INDEX `userid_url` (`stats_userid`, `stats_url_id`),
124 INDEX (`stats_url_id`)",
125                         'Visitor add-on Statistics');
126
127                 // Member actions pending on status
128                 addDropTableSql('surfbar_actions');
129                 addCreateTableSql('surfbar_actions', "
130 `actions_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
131 `actions_status` ENUM('PENDING', 'ACTIVE', 'LOCKED', 'STOPPED', 'REJECTED', 'DELETED', 'MIGRATED', 'DEPLETED') NULL DEFAULT NULL,
132 `actions_action` ENUM('EDIT', 'DELETE', 'PAUSE', 'UNPAUSE', 'FRAMETEST', 'RETREAT', 'RESUBMIT', 'BOOKNOW') NULL DEFAULT NULL,
133 `actions_new_status` ENUM('PENDING', 'ACTIVE', 'LOCKED', 'STOPPED', 'REJECTED', 'DELETED', 'MIGRATED', 'DEPLETED') NULL DEFAULT NULL,
134 PRIMARY KEY (`actions_id`),
135 UNIQUE INDEX `status_action` (`actions_status`, `actions_action`)",
136                         'Visitor add-on Member Actions');
137
138                 // Member actions
139                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('PENDING', 'RETREAT', 'DELETED')");
140                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('PENDING', 'FRAMETEST',NULL)");
141                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('PENDING', 'EDIT',NULL)");
142                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('ACTIVE', 'EDIT', 'PENDING')");
143                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('ACTIVE', 'DELETE', 'DELETED')");
144                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('ACTIVE', 'PAUSE', 'STOPPED')");
145                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('ACTIVE', 'FRAMETEST',NULL)");
146                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('LOCKED', 'DELETE', 'DELETED')");
147                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('LOCKED', 'FRAMETEST',NULL)");
148                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('LOCKED', 'RESUBMIT', 'PENDING')");
149                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('STOPPED', 'EDIT', 'PENDING')");
150                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('STOPPED', 'DELETE', 'DELETED')");
151                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('STOPPED', 'UNPAUSE', 'PENDING')");
152                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('DEPLETED', 'EDIT', 'PENDING')");
153                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('DEPLETED', 'DELETE', 'DELETED')");
154                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('REJECTED', 'EDIT', 'PENDING')");
155                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('REJECTED', 'DELETE', 'DELETED')");
156                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('REJECTED', 'FRAMETEST',NULL)");
157                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('REJECTED', 'RESUBMIT', 'PENDING')");
158                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('MIGRATED', 'EDIT', 'MIGRATED')");
159                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('MIGRATED', 'DELETE', 'DELETED')");
160                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('MIGRATED', 'FRAMETEST',NULL)");
161                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('MIGRATED', 'BOOKNOW', 'PENDING')");
162
163                 // Config entries
164                 addConfigAddSql('surfbar_payment_model', "ENUM('STATIC', 'DYNAMIC') NOT NULL DEFAULT 'STATIC'");
165                 addConfigAddSql('surfbar_static_reward', 'FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.25000');
166                 addConfigAddSql('surfbar_static_costs', 'FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 1.00000');
167                 addConfigAddSql('surfbar_static_time', 'SMALLINT(6) UNSIGNED NOT NULL DEFAULT 60');
168                 addConfigAddSql('surfbar_static_lock', 'SMALLINT(6) UNSIGNED NOT NULL DEFAULT ' . (60 * 5));
169                 addConfigAddSql('surfbar_dynamic_percent', 'FLOAT(10,5) UNSIGNED NOT NULL DEFAULT 10.00000');
170                 addConfigAddSql('surfbar_max_order', 'INT(7) UNSIGNED NOT NULL DEFAULT 10');
171                 addConfigAddSql('surfbar_restart_time', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT ' . (60 * 6));
172                 addConfigAddSql('surfbar_auto_start', "ENUM('Y', 'N') NOT NULL DEFAULT 'Y'");
173                 addConfigAddSql('surfbar_migrate_urls', "ENUM('Y', 'N') NOT NULL DEFAULT 'Y'");
174                 addConfigAddSql('surfbar_total_counter', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
175                 addConfigAddSql('surfbar_daily_counter', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
176                 addConfigAddSql('surfbar_yester_counter', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
177                 addConfigAddSql('surfbar_weekly_counter', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
178                 addConfigAddSql('surfbar_monthly_counter', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
179                 addConfigAddSql('surfbar_stats_reload', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 30');
180                 addConfigAddSql('surfbar_purge_deleted', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT ' . (getOneDay() * 7));
181                 addConfigAddSql('surfbar_purge_migrated', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT ' . (getOneDay() * 3));
182                 addConfigAddSql('surfbar_pause_mode', "ENUM('INTERNAL', 'EXERNAL') NOT NULL DEFAULT 'INTERNAL'");
183                 addConfigAddSql('surfbar_pause_url', "VARCHAR(255) NOT NULL DEFAULT ''");
184                 addConfigAddSql('surfbar_notify_limits', "ENUM('Y', 'N') NOT NULL DEFAULT 'Y'");
185                 addConfigAddSql('surfbar_notify_admin_unlock', "ENUM('Y', 'N') NOT NULL DEFAULT 'Y'");
186                 addConfigAddSql('surfbar_warn_low_points', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 100');
187                 addConfigAddSql('surfbar_low_interval', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT {?ONE_DAY?}');
188                 addConfigAddSql('surfbar_migrate_order', "ENUM('Y', 'N') NOT NULL DEFAULT 'Y'");
189                 addConfigAddSql('surfbar_notification_mode', "ENUM('INSTANT', 'RESET') NOT NULL DEFAULT 'INSTANT'");
190                 addConfigAddSql('surfbar_guest_login_form', "ENUM('Y', 'N') NOT NULL DEFAULT 'Y'");
191
192                 // Extend user data
193                 addExtensionAddTableColumnSql('user_data', 'surfbar_low_notified', "TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00'");
194
195                 // Member menus
196                 addMemberMenuSql('surfbar', NULL, 'Besuchertausch', 4);
197                 addMemberMenuSql('surfbar', 'start_surfbar', 'Besuchertausch starten', 1);
198                 addMemberMenuSql('surfbar', 'book_surfbar', 'Seite buchen', 2);
199                 addMemberMenuSql('surfbar', 'list_surfbar', 'Seiten-Management', 3);
200                 addMemberMenuSql('surfbar', 'stats_surfbar', 'Seiten-Statistik', 4);
201
202                 // Admin menus
203                 addAdminMenuSql('surfbar', NULL, 'Besuchertausch', 'URLs im Besuchertausch verwalten, Einstellungen &auml;ndern und vieles mehr.', 7);
204                 addAdminMenuSql('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 im Besuchertausch einzuf&uuml;gen.', 1);
205                 addAdminMenuSql('surfbar', 'list_surfbar_urls', 'URLs verwalten', 'Verwalten Sie hier alle im Besuchertausch befindlichen URLs mit nur wenigen Klicks.', 2);
206                 addAdminMenuSql('surfbar', 'unlock_surfbar_urls', 'Wartende URLs freigeben', 'Geben Sie hier f&uuml;r den Besuchertausch gebuchte URLs frei.', 3);
207                 addAdminMenuSql('surfbar', 'list_surfbar_packages', 'Buchungspakete verwalten', '&quot;Buchungspakete&quot; erlauben dem Mitglied nur von Ihnen definierte Reloadzeiten und Mindestauffenthalte.', 4);
208                 addAdminMenuSql('surfbar', 'config_surfbar', 'Einstellungen', 'Einstellungen am Besuchertausch &auml;ndern, wie Festverg&uuml;tung, prozentuale Ref-Verg&uuml;tung und vieles mehr.', 5);
209                 addAdminMenuSql('surfbar', 'surfbar_stats', 'Statistiken', 'Detailierte Statistiken zu einer ausgew&auml;hlten URL anzeigen.', 6);
210                 addAdminMenuSql('surfbar', 'list_surfbar_actions', 'Mitglieder-Aktionen', 'Listet alle Mitglieder-Aktionen auf.', 7);
211
212                 // Register module
213                 addModuleSql('surfbar', '{OPEN_TEMPLATE}MODULE_SURFBAR_TITLE{CLOSE_TEMPLATE}', 'Y', 'Y', 'N', 'N');
214
215                 // Insert data for points accounts
216                 registerExtensionPointsData('monthly_surfbar', 'points', 'LOCKED', 'DIRECT');
217
218                 // Register filters
219                 registerFilter(__FILE__, __LINE__, 'post_change_surfbar_url_status', 'SURFBAR_CHANGE_URL_STATUS', FALSE, TRUE, isExtensionDryRun());
220                 registerFilter(__FILE__, __LINE__, 'pre_change_surfbar_url_status', 'SURFBAR_CHANGE_URL_VALIDATE_DATA', FALSE, TRUE, isExtensionDryRun());
221                 break;
222
223         case 'remove': // Do stuff when removing extension
224                 // SQL commands to run
225                 addDropTableSql('surfbar_actions');
226                 addDropTableSql('surfbar_locks');
227                 addDropTableSql('surfbar_salts');
228                 addDropTableSql('surfbar_stats');
229                 addDropTableSql('surfbar_packages');
230                 addDropTableSql('surfbar_urls');
231                 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `action`='surfbar'");
232                 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='surfbar'");
233
234                 // Unregister module
235                 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_mod_reg` WHERE `module`='surfbar' LIMIT 1");
236
237                 // Unregister points data
238                 unregisterExtensionPointsData('monthly_surfbar');
239
240                 // Unregister filter
241                 unregisterFilter(__FILE__, __LINE__, 'post_change_surfbar_url_status', 'SURFBAR_CHANGE_URL_STATUS', TRUE, isExtensionDryRun());
242                 unregisterFilter(__FILE__, __LINE__, 'pre_change_surfbar_url_status', 'SURFBAR_CHANGE_URL_VALIDATE_DATA', TRUE, isExtensionDryRun());
243                 break;
244
245         case 'activate': // Do stuff when admin activates this extension
246                 // SQL commands to run
247                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='Y',`locked`='N' WHERE `action`='surfbar' LIMIT 5");
248                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_mod_reg` SET `locked`='N',`hidden`='N',`admin_only`='N',`mem_only`='Y' WHERE `module`='surfbar' LIMIT 1");
249                 break;
250
251         case 'deactivate': // Do stuff when admin deactivates this extension
252                 // SQL commands to run
253                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='N',`locked`='Y' WHERE `action` = 'surfbar' LIMIT 5");
254                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_mod_reg` SET `locked`='Y' WHERE `module`='surfbar' LIMIT 1");
255                 break;
256
257         case 'update': // Update an extension
258                 switch (getCurrentExtensionVersion()) {
259                         case '0.0.1': // SQL queries for v0.0.1
260                                 addExtensionSql('');
261
262                                 // Update notes (these will be set as task text!)
263                                 setExtensionUpdateNotes('');
264                                 break;
265                 } // END - switch
266                 break;
267
268         case 'modify': // When the extension got modified
269                 break;
270
271         case 'test': // For testing purposes
272                 break;
273
274         case 'init': // Do stuff when extension is initialized
275                 break;
276
277         default: // Unknown extension mode
278                 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown extension mode %s in extension %s detected.", getExtensionMode(), getCurrentExtensionName()));
279                 break;
280 } // END - switch
281
282 // [EOF]
283 ?>