2 /************************************************************************
3 * MXChange v0.2.1 Start: 06/19/2004 *
4 * ================ Last change: 12/26/2004 *
6 * -------------------------------------------------------------------- *
7 * File : ext-rallye.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Referal rallye *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Ref-Rallyes starten *
12 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
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. *
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. *
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, *
32 ************************************************************************/
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
41 $EXT_VERSION = "0.3.5";
43 // Auto-set extension version
44 if (empty($EXT_VER)) $EXT_VER = $EXT_VERSION;
46 // Version history array (add more with , "0.1" and so on)
47 $EXT_VER_HISTORY = array("0.0", "0.0.1", "0.0.2", "0.0.3", "0.0.4", "0.0.5", "0.0.6", "0.0.7", "0.0.8", "0.0.9", "0.1.0", "0.1.1", "0.1.2", "0.1.3", "0.1.4", "0.1.5", "0.1.6", "0.1.7", "0.1.8", "0.1.9", "0.2.0", "0.2.1", "0.2.2", "0.2.3", "0.2.4", "0.2.5", "0.2.6", "0.2.7", "0.2.8", "0.2.9", "0.3.0", "0.3.1", "0.3.2", "0.3.3", "0.3.4", "0.3.5");
49 switch ($EXT_LOAD_MODE)
51 case "register": // Do stuff when installation is running (modules.php?module=admin&action=login is called)
52 // SQL commands to run
53 $SQLs[] = "DROP TABLE IF EXISTS `{!_MYSQL_PREFIX!}_rallye_data`";
54 $SQLs[] = "DROP TABLE IF EXISTS `{!_MYSQL_PREFIX!}_rallye_prices`";
55 $SQLs[] = "DROP TABLE IF EXISTS `{!_MYSQL_PREFIX!}_rallye_users`";
56 $SQLs[] = "CREATE TABLE `{!_MYSQL_PREFIX!}_rallye_data` (
57 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
58 admin_id BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
59 title VARCHAR(255) NOT NULL DEFAULT '',
60 descr LONGBLOB NOT NULL,
61 template VARCHAR(255) NOT NULL DEFAULT '',
62 start_time VARCHAR(10) NOT NULL DEFAULT 0,
63 end_time VARCHAR(10) NOT NULL DEFAULT 0,
64 auto_add_new_user ENUM('Y','N') NOT NULL DEFAULT 'Y',
65 is_active ENUM('Y','N') NOT NULL DEFAULT 'N',
66 send_notify ENUM('Y','N') NOT NULL DEFAULT 'Y',
67 notified ENUM('Y','N') NOT NULL DEFAULT 'N',
71 $SQLs[] = "CREATE TABLE `{!_MYSQL_PREFIX!}_rallye_prices` (
72 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
73 rallye_id BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
74 price_level BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
75 points BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
76 info LONGBLOB NOT NULL,
80 $SQLs[] = "CREATE TABLE `{!_MYSQL_PREFIX!}_rallye_users` (
81 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
82 rallye_id BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
83 userid BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
84 refs BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
91 $SQLs[] = "INSERT INTO `{!_MYSQL_PREFIX!}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('rallye', NULL, 'Rallye-Management','Richten Sie neue Ref-Rallyes ein, die zeitgesteuert anfangen und aufhöhren. Dabei wird alles weitere automatisch geregelt.','9')";
92 $SQLs[] = "INSERT INTO `{!_MYSQL_PREFIX!}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('rallye','add_rallye','Neue Rallye hinzufügen','Neue Ref-Rallye hinzufügen.','1')";
93 $SQLs[] = "INSERT INTO `{!_MYSQL_PREFIX!}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('rallye','config_rallye_prices','Preise einrichten','Richten Sie Preise zu den Rallyes ein.','2')";
94 $SQLs[] = "INSERT INTO `{!_MYSQL_PREFIX!}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('rallye','list_rallyes','Rallyes verwalten','Alle bestehenden Ref-Rallyes auflisten, bearbeiten, stoppen, löschen usw.','3')";
97 $SQLs[] = "INSERT INTO `{!_MYSQL_PREFIX!}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('main','rallyes','Ref-Rallyes','Y','Y','9')";
100 $SQLs[] = "INSERT INTO `{!_MYSQL_PREFIX!}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('main','rallyes','Ref-Rallyes','Y','Y','9')";
103 case "remove": // Do stuff when removing extension
105 $SQLs[] = "DROP TABLE IF EXISTS `{!_MYSQL_PREFIX!}_rallye_data`";
106 $SQLs[] = "DROP TABLE IF EXISTS `{!_MYSQL_PREFIX!}_rallye_prices`";
107 $SQLs[] = "DROP TABLE IF EXISTS `{!_MYSQL_PREFIX!}_rallye_users`";
110 $SQLs[] = "DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE action='rallye' LIMIT 4";
111 $SQLs[] = "DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_guest_menu` WHERE what='rallyes' LIMIT 1";
112 $SQLs[] = "DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE what='rallyes' LIMIT 1";
115 UNREGISTER_FILTER('extra_autopurge', 'RALLYE_EXTRA_AUTOPURGE', true, $dry_run);
118 case "activate": // Do stuff when admin activates this extension
119 // SQL commands to run
120 $SQLs[] = "UPDATE `{!_MYSQL_PREFIX!}_guest_menu` SET `visible`='Y', `locked`='N' WHERE what='rallyes' LIMIT 1";
121 $SQLs[] = "UPDATE `{!_MYSQL_PREFIX!}_member_menu` SET `visible`='Y', `locked`='N' WHERE what='rallyes' LIMIT 1";
124 case "deactivate": // Do stuff when admin deactivates this extension
125 // SQL commands to run
126 $SQLs[] = "UPDATE `{!_MYSQL_PREFIX!}_guest_menu` SET `visible`='N', `locked`='Y' WHERE what='rallyes' LIMIT 1";
127 $SQLs[] = "UPDATE `{!_MYSQL_PREFIX!}_member_menu` SET `visible`='N', `locked`='Y' WHERE what='rallyes' LIMIT 1";
130 case "update": // Update an extension
133 case "0.0.1": // SQL queries for v0.0.1
134 $SQLs[] = "ALTER TABLE `{!_MYSQL_PREFIX!}_rallye_data` ADD expired ENUM('Y','N') NOT NULL DEFAULT 'N'";
136 // Update notes (these will be set as task text!)
137 $UPDATE_NOTES = "Ablaufen der Rallyes intergriert.";
140 case "0.0.2": // SQL queries for v0.0.2
141 $SQLs[] = "ALTER TABLE `{!_MYSQL_PREFIX!}_rallye_users` ADD curr_points FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.00000";
143 // Update notes (these will be set as task text!)
144 $UPDATE_NOTES = "Aktueller {!POINTS!}-Stand wird beachtet.";
147 case "0.0.6": // SQL queries for v0.0.6
148 // Update notes (these will be set as task text!)
149 $UPDATE_NOTES = "Fehler <em>Unknown column 'd.useid' in 'on clause'</em> behoben.";
152 case "0.0.7": // SQL queries for v0.0.7
153 // Update notes (these will be set as task text!)
154 $UPDATE_NOTES = "Fehlende Abfrage im Mitlieder-Modul, on Erweiterung auch aktiviert ist.";
157 case "0.0.8": // SQL queries for v0.0.8
158 // Update notes (these will be set as task text!)
159 $UPDATE_NOTES = "Fehler <u>Template nicht gefunden</u> behoben und Admin-Formulare ausgelagert";
162 case "0.0.9": // SQL queries for v0.0.9
163 // Update notes (these will be set as task text!)
164 $UPDATE_NOTES = "Fehler beseitigt, wenn error_reporting=E_ALL gesetzt ist. Und der vorherige Fehler <u>Template nicht gefunden</u> ist endlich beseitigt.";
167 case "0.1.0": // SQL queries for v0.2.1
168 $SQLs[] = "ALTER TABLE `{!_MYSQL_PREFIX!}_rallye_users` CHANGE curr_points curr_points FLOAT(23,5) UNSIGNED NOT NULL DEFAULT 0.00000";
170 // Update notes (these will be set as task text!)
171 $UPDATE_NOTES = "5 Nachkommastellen implementiert.";
174 case "0.1.1": // SQL queries for v0.1.1
175 // Update notes (these will be set as task text!)
176 $UPDATE_NOTES = "Fehler beseitigt, wenn error_reporting=E_ALL gesetzt ist.";
179 case "0.1.2": // SQL queries for v0.1.2
180 // Update notes (these will be set as task text!)
181 $UPDATE_NOTES = "Problem mit Speicherung der Einstellungen beseitigt.";
184 case "0.1.3": // SQL queries for v0.1.3
185 // Update notes (these will be set as task text!)
186 $UPDATE_NOTES = "Anzeigefehler im Gast-/Mitgliedsbereich behoben.";
189 case "0.1.4": // SQL queries for v0.1.4
190 // Update notes (these will be set as task text!)
191 $UPDATE_NOTES = "Admin-Mails korregiert.";
194 case "0.1.5": // SQL queries for v0.1.5
195 // Update notes (these will be set as task text!)
196 $UPDATE_NOTES = "Menüpunkte im Gast-/Mitgliedsbereich können nicht mehr aufgerufen werden, wenn die Erweiterung deaktiviert ist.";
199 case "0.1.6": // SQL queries for v0.1.6
200 // Update notes (these will be set as task text!)
201 $UPDATE_NOTES = "Seit <a href=\"#\">Patch 340</a> überflüssige HTML-Tags entfernt.";
204 case "0.1.7": // SQL queries for v0.1.7
205 // Update notes (these will be set as task text!)
206 $UPDATE_NOTES = "Aktivierte bzw. abgelaufene Rallyes werden nur ausserhalb des CSS-Modus geladen (wenn also nicht css.php aufgerufen wurde)";
209 case "0.1.8": // SQL queries for v0.1.8
210 // Update notes (these will be set as task text!)
211 $UPDATE_NOTES = "Weitere Templates vom Admin-Bereich ausgelagert und Referal-Anazahl in der Mail zur Rallye-Ankündigung repariert.";
214 case "0.1.9": // SQL queries for v0.1.9
215 // Update notes (these will be set as task text!)
216 $UPDATE_NOTES = "Funktion ADMIN_USER_PROFILE_LINK() mit Verlinkung auf Referal-Liste implementiert.";
219 case "0.2.0": // SQL queries for v0.2.0
220 $SQLs[] = "ALTER TABLE `{!_MYSQL_PREFIX!}_rallye_data` ADD min_users BIGINT(20) UNSIGNED NOT NULL DEFAULT 0";
221 $SQLs[] = "ALTER TABLE `{!_MYSQL_PREFIX!}_rallye_data` ADD min_prices BIGINT(20) UNSIGNED NOT NULL DEFAULT '3'";
223 // Update notes (these will be set as task text!)
224 $UPDATE_NOTES = "Ablaufen der Rallyes intergriert. Bauen Sie in Ihr Template <strong>templates/de/emails/member/member_rallye_notify.tpl</strong> folgende zwei Zeilen ein:<br />
226 <li>$DATA[min_users]</li>
227 <li>$DATA[min_prices]</li>
229 Zudem sollten Sie mindestens folgende Templates (in <strong>templates/".GET_LANGUAGE()."/html/guest/</strong> !) aktualisieren:<br />
231 <li><strong>guest_rallye_footer.tpl</strong></li>
232 <li><strong>guest_rallye_header.tpl</strong></li>
236 case "0.2.1": // SQL queries for v0.2.1
237 // Update notes (these will be set as task text!)
238 $UPDATE_NOTES = "Wörter <strong>Mailtausch</strong>, <strong>Mailtausches</strong> und <strong>Mailtauscher</strong> sind austauschbar.";
241 case "0.2.2": // SQL queries for v0.2.2
242 // Update notes (these will be set as task text!)
243 $UPDATE_NOTES = "Links wegen <strong>what=admins_contct</strong> geändert.";
246 case "0.2.3": // SQL queries for v0.2.3
247 // Update notes (these will be set as task text!)
248 $UPDATE_NOTES = "HTML-Code ausgelagert in Templates und SQL-Anweisungen abgesichert.";
251 case "0.2.4": // SQL queries for v0.2.4
252 // Update notes (these will be set as task text!)
253 $UPDATE_NOTES = "Abspeichern von Einstellungen repariert.";
256 case "0.2.5": // SQL queries for v0.2.5
257 // Update notes (these will be set as task text!)
258 $UPDATE_NOTES = "Menüpunkt "Rallyes verwalten" repariert.";
261 case "0.2.6": // SQL queries for v0.2.6
262 // Update notes (these will be set as task text!)
263 $UPDATE_NOTES = "Automatisches Starten von Referal-Rallyes repariert.";
266 case "0.2.7": // SQL queries for v0.2.7
267 // Update notes (these will be set as task text!)
268 $UPDATE_NOTES = "Fatalen Fehler beseitigt.";
271 case "0.2.8": // SQL queries for v0.2.8
272 // Update notes (these will be set as task text!)
274 $UPDATE_NOTES = "Vorbereitung auf die neue Mediendaten v0.0.4.";
277 case "0.2.9": // SQL queries for v0.2.9
278 // Update notes (these will be set as task text!)
279 $UPDATE_NOTES = "Sicherheitsupdate für die Include-Befehle.";
282 case "0.3.0": // SQL queries for v0.3.0
283 // Update notes (these will be set as task text!)
284 $UPDATE_NOTES = "if-Anweisungen auf Funktion <strong>empty()</strong> umgestellt.";
287 case "0.3.1": // SQL queries for v0.3.1
288 // Update notes (these will be set as task text!)
289 $UPDATE_NOTES = "Erweiterung für automatisch generierte Admin-Kontaktlinks geändert.";
292 case "0.3.2": // SQL queries for v0.3.2
293 $SQLs[] = "UPDATE `{!_MYSQL_PREFIX!}_member_menu` SET action='rals', sort='1', title='Referal-Rallye' WHERE what='rallyes' LIMIT 1";
295 // Update notes (these will be set as task text!)
296 $UPDATE_NOTES = "Mitgliedsmenü komplett umgebaut.";
299 case "0.3.3": // SQL queries for v0.3.3
300 // Update notes (these will be set as task text!)
301 $UPDATE_NOTES = "Rallyes werden nun nur dann automatisch beseitigt, wenn die Erweiterung <strong>autopurge</strong> installiert und aktiviert ist.";
304 case "0.3.4": // SQL queries for v0.3.4
305 // Update notes (these will be set as task text!)
306 $UPDATE_NOTES = "Fehlerhinweis bei deaktivierter Erweiterung verbessert.";
309 case "0.3.5": // SQL queries for 0.3.5
310 // This update depends on sql_patches
311 $EXT_UPDATE_DEPENDS = "sql_patches";
314 REGISTER_FILTER('extra_autopurge', 'RALLYE_EXTRA_AUTOPURGE', false, true, $dry_run);
316 // Update notes (these will be set as task text!)
317 $UPDATE_NOTES = "Filter hinzugefügt und ist von <strong>sql_patches</strong> abhängig.";
322 case "test": // For testing purposes. For details see file inc/modules/admin/what-extensions.php, arround line 305.
325 default: // Do stuff when extension is loaded
326 // Do stuff only when not in CSS mode
327 if (($CSS != "1") && ($CSS != "-1") && ($cacheMode != "init")) {
328 // Get total member count
329 $TOTAL = GET_TOTAL_DATA("CONFIRMED", "user_data", "userid", "status", true);
331 // Add more data on higher versions
332 $ADD1 = ""; $ADD2 = ""; $OR = "";
333 if (GET_EXT_VERSION("rallye") >= "0.2.0") {
334 $ADD1 = ", min_users, min_prices";
335 $ADD2 = ", d.min_users, d.min_prices";
336 $OR = " OR (d.min_users <= ".$TOTAL." AND d.min_users > 0)";
339 // Check for new started but not notified rallyes
340 $result = SQL_QUERY("SELECT SQL_SMALL_RESULT id, title, start_time, end_time, send_notify".$ADD1."
341 FROM `{!_MYSQL_PREFIX!}_rallye_data`
342 WHERE is_active='Y' AND notified='N' AND expired='N' AND start_time <= UNIX_TIMESTAMP() AND end_time > UNIX_TIMESTAMP()
343 LIMIT 1", __FILE__, __LINE__);
344 if (SQL_NUMROWS($result) == 1) {
346 RALLYE_AUTOSTART_RALLYES($result);
350 SQL_FREERESULT($result);
352 // Check for expired rallyes
353 $result = SQL_QUERY("SELECT SQL_SMALL_RESULT d.id, d.title, d.start_time, d.end_time, d.send_notify".$ADD2."
354 FROM `{!_MYSQL_PREFIX!}_rallye_data` AS d
355 WHERE d.is_active='Y' AND d.notified='Y' AND d.expired='N' AND (d.end_time <= UNIX_TIMESTAMP()".$OR.")
356 LIMIT 1", __FILE__, __LINE__);
357 if ((SQL_NUMROWS($result) == 1) && (EXT_IS_ACTIVE("autopurge"))) {
358 // End rallye here...
359 RALLYE_EXPIRE_RALLYES($result);
363 SQL_FREERESULT($result);