Several fixes and and improvements:
[mailer.git] / inc / extensions / ext-rallye.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 06/19/2004 *
4  * ================                             Last change: 12/26/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : ext-rallye.php                                   *
8  * -------------------------------------------------------------------- *
9  * Short description : Referal rallye                                   *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Ref-Rallyes starten                              *
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.3.4";
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", "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");
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
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',
68 KEY (admin_id),
69 PRIMARY KEY (id)
70 ) TYPE=MyISAM";
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,
77 KEY (rallye_id),
78 PRIMARY KEY(id)
79 ) TYPE=MyISAM";
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',
85 KEY (rallye_id),
86 KEY (userid),
87 PRIMARY KEY(id)
88 ) TYPE=MyISAM";
89         // Admin menu
90         $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&ouml;hren. Dabei wird alles weitere automatisch geregelt.','9')";
91         $SQLs[] = "INSERT INTO "._MYSQL_PREFIX."_admin_menu (`action`,`what`,`title`,`descr`,`sort`) VALUES ('rallye','add_rallye','Neue Rallye hinzuf&uuml;gen','Neue Ref-Rallye hinzuf&uuml;gen.','1')";
92         $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')";
93         $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&ouml;schen usw.','3')";
94         // Guest menu
95         $SQLs[] = "INSERT INTO "._MYSQL_PREFIX."_guest_menu (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('main','rallyes','Ref-Rallyes','Y','Y','9')";
96         // Member menu
97         $SQLs[] = "INSERT INTO "._MYSQL_PREFIX."_member_menu (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('main','rallyes','Ref-Rallyes','Y','Y','9')";
98         break;
99
100 case "remove": // Do stuff when removing extension
101         // SQL commands to run
102         $SQLs[] = "DROP TABLE IF EXISTS "._MYSQL_PREFIX."_rallye_data";
103         $SQLs[] = "DROP TABLE IF EXISTS "._MYSQL_PREFIX."_rallye_prices";
104         $SQLs[] = "DROP TABLE IF EXISTS "._MYSQL_PREFIX."_rallye_users";
105         $SQLs[] = "DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_admin_menu WHERE action='rallye' LIMIT 4";
106         $SQLs[] = "DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_guest_menu WHERE what='rallyes' LIMIT 1";
107         $SQLs[] = "DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_member_menu WHERE what='rallyes' LIMIT 1";
108         break;
109
110 case "activate": // Do stuff when admin activates this extension
111         // SQL commands to run
112         $SQLs[] = "UPDATE "._MYSQL_PREFIX."_guest_menu SET visible='Y', locked='N' WHERE what='rallyes' LIMIT 1";
113         $SQLs[] = "UPDATE "._MYSQL_PREFIX."_member_menu SET visible='Y', locked='N' WHERE what='rallyes' LIMIT 1";
114         break;
115
116 case "deactivate": // Do stuff when admin deactivates this extension
117         // SQL commands to run
118         $SQLs[] = "UPDATE "._MYSQL_PREFIX."_guest_menu SET visible='Y', locked='Y' WHERE what='rallyes' LIMIT 1";
119         $SQLs[] = "UPDATE "._MYSQL_PREFIX."_member_menu SET visible='Y', locked='Y' WHERE what='rallyes' LIMIT 1";
120         break;
121
122 case "update": // Update an extension
123         switch ($EXT_VER)
124         {
125         case "0.0.1": // SQL queries for v0.0.1
126                 $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_rallye_data ADD expired ENUM('Y','N') NOT NULL DEFAULT 'N'";
127
128                 // Update notes (these will be set as task text!)
129                 $UPDATE_NOTES = "Ablaufen der Rallyes intergriert.";
130                 break;
131
132         case "0.0.2": // SQL queries for v0.0.2
133                 $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_rallye_users ADD curr_points DOUBLE(23,3) NOT NULL DEFAULT '0.000'";
134
135                 // Update notes (these will be set as task text!)
136                 $UPDATE_NOTES = "Aktueller {!POINTS!}-Stand wird beachtet.";
137                 break;
138
139         case "0.0.6": // SQL queries for v0.0.6
140                 // Update notes (these will be set as task text!)
141                 $UPDATE_NOTES = "Fehler <I>Unknown column 'd.useid' in 'on clause'</I> behoben.";
142                 break;
143
144         case "0.0.7": // SQL queries for v0.0.7
145                 // Update notes (these will be set as task text!)
146                 $UPDATE_NOTES = "Fehlende Abfrage im Mitlieder-Modul, on Erweiterung auch aktiviert ist.";
147                 break;
148
149         case "0.0.8": // SQL queries for v0.0.8
150                 // Update notes (these will be set as task text!)
151                 $UPDATE_NOTES = "Fehler <U>Template nicht gefunden</U> behoben und Admin-Formulare ausgelagert";
152                 break;
153
154         case "0.0.9": // SQL queries for v0.0.9
155                 // Update notes (these will be set as task text!)
156                 $UPDATE_NOTES = "Fehler beseitigt, wenn error_reporting=E_ALL gesetzt ist. Und der vorherige Fehler <U>Template nicht gefunden</U> ist endlich beseitigt.";
157                 break;
158
159         case "0.1.0": // SQL queries for v0.2.1
160                 $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_rallye_users CHANGE curr_points curr_points DOUBLE(23,5) NOT NULL DEFAULT '0.00000'";
161
162                 // Update notes (these will be set as task text!)
163                 $UPDATE_NOTES = "5 Nachkommastellen implementiert.";
164                 break;
165
166         case "0.1.1": // SQL queries for v0.1.1
167                 // Update notes (these will be set as task text!)
168                 $UPDATE_NOTES = "Fehler beseitigt, wenn error_reporting=E_ALL gesetzt ist.";
169                 break;
170
171         case "0.1.2": // SQL queries for v0.1.2
172                 // Update notes (these will be set as task text!)
173                 $UPDATE_NOTES = "Problem mit Speicherung der Einstellungen beseitigt.";
174                 break;
175
176         case "0.1.3": // SQL queries for v0.1.3
177                 // Update notes (these will be set as task text!)
178                 $UPDATE_NOTES = "Anzeigefehler im Gast-/Mitgliedsbereich behoben.";
179                 break;
180
181         case "0.1.4": // SQL queries for v0.1.4
182                 // Update notes (these will be set as task text!)
183                 $UPDATE_NOTES = "Admin-Mails korregiert.";
184                 break;
185
186         case "0.1.5": // SQL queries for v0.1.5
187                 // Update notes (these will be set as task text!)
188                 $UPDATE_NOTES = "Men&uuml;punkte im Gast-/Mitgliedsbereich k&ouml;nnen nicht mehr aufgerufen werden, wenn die Erweiterung deaktiviert ist.";
189                 break;
190
191         case "0.1.6": // SQL queries for v0.1.6
192                 // Update notes (these will be set as task text!)
193                 $UPDATE_NOTES = "Seit <A href=\"#\">Patch 340</A> &uuml;berfl&uuml;ssige HTML-Tags entfernt.";
194                 break;
195
196         case "0.1.7": // SQL queries for v0.1.7
197                 // Update notes (these will be set as task text!)
198                 $UPDATE_NOTES = "Aktivierte bzw. abgelaufene Rallyes werden nur ausserhalb des CSS-Modus geladen (wenn also nicht css.php aufgerufen wurde)";
199                 break;
200
201         case "0.1.8": // SQL queries for v0.1.8
202                 // Update notes (these will be set as task text!)
203                 $UPDATE_NOTES = "Weitere Templates vom Admin-Bereich ausgelagert und Referal-Anazahl in der Mail zur Rallye-Ank&uuml;ndigung repariert.";
204                 break;
205
206         case "0.1.9": // SQL queries for v0.1.9
207                 // Update notes (these will be set as task text!)
208                 $UPDATE_NOTES = "Funktion ADMIN_USER_PROFILE_LINK() mit Verlinkung auf Referal-Liste implementiert.";
209                 break;
210
211         case "0.2.0": // SQL queries for v0.2.0
212                 $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_rallye_data ADD min_users BIGINT(20) UNSIGNED NOT NULL DEFAULT '0'";
213                 $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_rallye_data ADD min_prices BIGINT(20) UNSIGNED NOT NULL DEFAULT '3'";
214
215                 // Update notes (these will be set as task text!)
216                 $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 />
217 <UL>
218   <LI>&#36;DATA&#91;min_users&#93;</LI>
219   <LI>&#36;DATA&#91;min_prices&#93;</LI>
220 </UL>
221 Zudem sollten Sie mindestens folgende Templates (in <STRONG>templates/".GET_LANGUAGE()."/html/guest/</STRONG> !) aktualisieren:<br />
222 <UL>
223   <LI><STRONG>guest_rallye_footer.tpl</STRONG></LI>
224   <LI><STRONG>guest_rallye_header.tpl</STRONG></LI>
225 </UL>";
226                 break;
227
228         case "0.2.1": // SQL queries for v0.2.1
229                 // Update notes (these will be set as task text!)
230                 $UPDATE_NOTES = "W&ouml;rter <STRONG>Mailtausch</STRONG>, <STRONG>Mailtausches</STRONG> und <STRONG>Mailtauscher</STRONG> sind austauschbar.";
231                 break;
232
233         case "0.2.2": // SQL queries for v0.2.2
234                 // Update notes (these will be set as task text!)
235                 $UPDATE_NOTES = "Links wegen <STRONG>what=admins_contct</STRONG> ge&auml;ndert.";
236                 break;
237
238         case "0.2.3": // SQL queries for v0.2.3
239                 // Update notes (these will be set as task text!)
240                 $UPDATE_NOTES = "HTML-Code ausgelagert in Templates und SQL-Anweisungen abgesichert.";
241                 break;
242
243         case "0.2.4": // SQL queries for v0.2.4
244                 // Update notes (these will be set as task text!)
245                 $UPDATE_NOTES = "Abspeichern von Einstellungen repariert.";
246                 break;
247
248         case "0.2.5": // SQL queries for v0.2.5
249                 // Update notes (these will be set as task text!)
250                 $UPDATE_NOTES = "Men&uuml;punkt &quot;Rallyes verwalten&quot; repariert.";
251                 break;
252
253         case "0.2.6": // SQL queries for v0.2.6
254                 // Update notes (these will be set as task text!)
255                 $UPDATE_NOTES = "Automatisches Starten von Referal-Rallyes repariert.";
256                 break;
257
258         case "0.2.7": // SQL queries for v0.2.7
259                 // Update notes (these will be set as task text!)
260                 $UPDATE_NOTES = "Fatalen Fehler beseitigt.";
261                 break;
262
263         case "0.2.8": // SQL queries for v0.2.8
264                 // Update notes (these will be set as task text!)
265
266                 $UPDATE_NOTES = "Vorbereitung auf die neue Mediendaten v0.0.4.";
267                 break;
268
269         case "0.2.9": // SQL queries for v0.2.9
270                 // Update notes (these will be set as task text!)
271                 $UPDATE_NOTES = "Sicherheitsupdate f&uuml;r die Include-Befehle.";
272                 break;
273
274         case "0.3.0": // SQL queries for v0.3.0
275                 // Update notes (these will be set as task text!)
276                 $UPDATE_NOTES = "if-Anweisungen auf Funktion <STRONG>empty()</STRONG> umgestellt.";
277                 break;
278
279         case "0.3.1": // SQL queries for v0.3.1
280                 // Update notes (these will be set as task text!)
281                 $UPDATE_NOTES = "Erweiterung f&uuml;r automatisch generierte Admin-Kontaktlinks ge&auml;ndert.";
282                 break;
283
284         case "0.3.2": // SQL queries for v0.3.2
285                 $SQLs[] = "UPDATE "._MYSQL_PREFIX."_member_menu SET action='rals', sort='1', title='Referal-Rallye' WHERE what='rallyes' LIMIT 1";
286
287                 // Update notes (these will be set as task text!)
288                 $UPDATE_NOTES = "Mitgliedsmen&uuml; komplett umgebaut.";
289                 break;
290
291         case "0.3.3": // SQL queries for v0.3.3
292                 // Update notes (these will be set as task text!)
293                 $UPDATE_NOTES = "Rallyes werden nun nur dann automatisch beseitigt, wenn die Erweiterung <strong>autopurge</strong> installiert und aktiviert ist.";
294                 break;
295
296         case "0.3.4": // SQL queries for v0.3.4
297                 // Update notes (these will be set as task text!)
298                 $UPDATE_NOTES = "Fehlerhinweis bei deaktivierter Erweiterung verbessert.";
299                 break;
300         }
301         break;
302
303 default: // Do stuff when extension is loaded
304         // Do stuff only when not in CSS mode
305         if (($CSS != "1") && ($CSS != "-1") && ($cacheMode != "init")) {
306                 // Get total member count
307                 $TOTAL = GET_TOTAL_DATA("CONFIRMED", "user_data", "userid", "status", true);
308
309                 // Add more data on higher versions
310                 $ADD1 = ""; $ADD2 = ""; $OR = "";
311                 if (GET_EXT_VERSION("rallye") >= "0.2.0") {
312                         $ADD1 = ", min_users, min_prices";
313                         $ADD2 = ", d.min_users, d.min_prices";
314                         $OR   = " OR (d.min_users <= ".$TOTAL." AND d.min_users > 0)";
315                 } // END  - if
316
317                 // Check for new started but not notified rallyes
318                 $result = SQL_QUERY("SELECT SQL_SMALL_RESULT id, title, start_time, end_time, send_notify".$ADD1."
319 FROM "._MYSQL_PREFIX."_rallye_data
320 WHERE is_active='Y' AND notified='N' AND expired='N' AND start_time <= UNIX_TIMESTAMP() AND end_time > UNIX_TIMESTAMP()
321 LIMIT 1", __FILE__, __LINE__);
322                 if (SQL_NUMROWS($result) == 1) {
323                         // Start rallye
324                         RALLYE_AUTOSTART_RALLYES($result);
325                 } // END - if
326
327                 // Free memory
328                 SQL_FREERESULT($result);
329
330                 // Check for expired rallyes
331                 $result = SQL_QUERY("SELECT SQL_SMALL_RESULT d.id, d.title, d.start_time, d.end_time, d.send_notify".$ADD2."
332 FROM "._MYSQL_PREFIX."_rallye_data AS d
333 WHERE d.is_active='Y' AND d.notified='Y' AND d.expired='N' AND (d.end_time <= UNIX_TIMESTAMP()".$OR.")
334 LIMIT 1", __FILE__, __LINE__);
335                 if ((SQL_NUMROWS($result) == 1) && (EXT_IS_ACTIVE("autopurge")))
336                 {
337                         // End rallye here...
338                         RALLYE_EXPIRE_RALLYES($result);
339                 }
340
341                 // Free memory
342                 SQL_FREERESULT($result);
343         }
344         break;
345 }
346
347 // Language file prefix
348 $EXT_LANG_PREFIX = "rallye";
349
350 //
351 ?>