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