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