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