Parser error fixed...
[mailer.git] / inc / extensions / ext-rallye.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         die();
42 }
43
44 // Version number
45 setThisExtensionVersion('0.3.5');
46
47 // Version history array (add more with , '0.1.0' and so on)
48 setExtensionVersionHistory(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
50 switch (getExtensionMode()) {
51         case 'register': // Do stuff when installation is running (modules.php?module=admin is called)
52                 // SQL commands to run
53                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_rallye_data`");
54                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_rallye_prices`");
55                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_rallye_users`");
56                 addExtensionSql("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 LONGTEXT 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={?_TABLE_TYPE?}");
71                 addExtensionSql("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 LONGTEXT NOT NULL,
77 KEY (rallye_id),
78 PRIMARY KEY (id)
79 ) TYPE={?_TABLE_TYPE?}");
80                 addExtensionSql("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={?_TABLE_TYPE?}");
89
90                 // Admin menu
91                 addAdminMenuSql('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                 addAdminMenuSql('rallye','add_rallye','Neue Rallye hinzuf&uuml;gen','Neue Ref-Rallye hinzuf&uuml;gen.',1);
93                 // @TODO Fix config_rallye_prices to list_rallye_prices
94                 addAdminMenuSql('rallye','config_rallye_prices','Preise einrichten','Richten Sie Preise zu den Rallyes ein.',2);
95                 addAdminMenuSql('rallye','list_rallyes','Rallyes verwalten','Alle bestehenden Ref-Rallyes auflisten, bearbeiten, stoppen, l&ouml;schen usw.',3);
96
97                 // Guest menu
98                 addGuestMenuSql('main','rallyes','Ref-Rallyes','N','Y',9);
99
100                 // Member menu
101                 addMemberMenuSql('main','rallyes','Ref-Rallyes','N','Y',9);
102                 break;
103
104         case 'remove': // Do stuff when removing extension
105                 // Drop tables
106                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_rallye_data`");
107                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_rallye_prices`");
108                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_rallye_users`");
109
110                 // Remove menus
111                 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='rallye'");
112                 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE `what`='rallyes'");
113                 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `what`='rallyes'");
114
115                 // Unregister filter
116                 unregisterFilter('extra_autopurge', 'RALLYE_EXTRA_AUTOPURGE', true, getExtensionDryRun());
117                 break;
118
119         case 'activate': // Do stuff when admin activates this extension
120                 // SQL commands to run
121                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `visible`='Y', `locked`='N' WHERE `what`='rallyes' LIMIT 1");
122                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='Y', `locked`='N' WHERE `what`='rallyes' LIMIT 1");
123                 break;
124
125         case 'deactivate': // Do stuff when admin deactivates this extension
126                 // SQL commands to run
127                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `visible`='N', `locked`='Y' WHERE `what`='rallyes' LIMIT 1");
128                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='N', `locked`='Y' WHERE `what`='rallyes' LIMIT 1");
129                 break;
130
131         case 'update': // Update an extension
132                 switch (getCurrentExtensionVersion()) {
133                         case '0.0.1': // SQL queries for v0.0.1
134                                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_rallye_data` ADD expired ENUM('Y','N') NOT NULL DEFAULT 'N'");
135
136                                 // Update notes (these will be set as task text!)
137                                 setExtensionUpdateNotes("Ablaufen der Rallyes intergriert.");
138                                 break;
139
140                         case '0.0.2': // SQL queries for v0.0.2
141                                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_rallye_users` ADD curr_points FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.00000");
142
143                                 // Update notes (these will be set as task text!)
144                                 setExtensionUpdateNotes("Aktueller {?POINTS?}-Stand wird beachtet.");
145                                 break;
146
147                         case '0.0.6': // SQL queries for v0.0.6
148                                 // Update notes (these will be set as task text!)
149                                 setExtensionUpdateNotes("Fehler <em>Unknown column 'd.useid' in 'on clause'</em> behoben.");
150                                 break;
151
152                         case '0.0.7': // SQL queries for v0.0.7
153                                 // Update notes (these will be set as task text!)
154                                 setExtensionUpdateNotes("Fehlende Abfrage im Mitlieder-Modul, on Erweiterung auch aktiviert ist.");
155                                 break;
156
157                         case '0.0.8': // SQL queries for v0.0.8
158                                 // Update notes (these will be set as task text!)
159                                 setExtensionUpdateNotes("Fehler <u>Template nicht gefunden</u> behoben und Admin-Formulare ausgelagert");
160                                 break;
161
162                         case '0.0.9': // SQL queries for v0.0.9
163                                 // Update notes (these will be set as task text!)
164                                 setExtensionUpdateNotes("Fehler beseitigt, wenn error_reporting=E_ALL gesetzt ist. Und der vorherige Fehler <u>Template nicht gefunden</u> ist endlich beseitigt.");
165                                 break;
166
167                         case '0.1.0': // SQL queries for v0.2.1
168                                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_rallye_users` CHANGE curr_points curr_points FLOAT(23,5) UNSIGNED NOT NULL DEFAULT 0.00000");
169
170                                 // Update notes (these will be set as task text!)
171                                 setExtensionUpdateNotes("5 Nachkommastellen implementiert.");
172                                 break;
173
174                         case '0.1.1': // SQL queries for v0.1.1
175                                 // Update notes (these will be set as task text!)
176                                 setExtensionUpdateNotes("Fehler beseitigt, wenn error_reporting=E_ALL gesetzt ist.");
177                                 break;
178
179                         case '0.1.2': // SQL queries for v0.1.2
180                                 // Update notes (these will be set as task text!)
181                                 setExtensionUpdateNotes("Problem mit Speicherung der Einstellungen beseitigt.");
182                                 break;
183
184                         case '0.1.3': // SQL queries for v0.1.3
185                                 // Update notes (these will be set as task text!)
186                                 setExtensionUpdateNotes("Anzeigefehler im Gast-/Mitgliedsbereich behoben.");
187                                 break;
188
189                         case '0.1.4': // SQL queries for v0.1.4
190                                 // Update notes (these will be set as task text!)
191                                 setExtensionUpdateNotes("Admin-Mails korregiert.");
192                                 break;
193
194                         case '0.1.5': // SQL queries for v0.1.5
195                                 // Update notes (these will be set as task text!)
196                                 setExtensionUpdateNotes("Men&uuml;punkte im Gast-/Mitgliedsbereich k&ouml;nnen nicht mehr aufgerufen werden, wenn die Erweiterung deaktiviert ist.");
197                                 break;
198
199                         case '0.1.6': // SQL queries for v0.1.6
200                                 // Update notes (these will be set as task text!)
201                                 setExtensionUpdateNotes("Seit <strong>Patch 340</strong> &uuml;berfl&uuml;ssige HTML-Tags entfernt.");
202                                 break;
203
204                         case '0.1.7': // SQL queries for v0.1.7
205                                 // Update notes (these will be set as task text!)
206                                 setExtensionUpdateNotes("Aktivierte bzw. abgelaufene Rallyes werden nur ausserhalb des CSS-Modus geladen (wenn also nicht css.php aufgerufen wurde)");
207                                 break;
208
209                         case '0.1.8': // SQL queries for v0.1.8
210                                 // Update notes (these will be set as task text!)
211                                 setExtensionUpdateNotes("Weitere Templates vom Admin-Bereich ausgelagert und Referal-Anazahl in der Mail zur Rallye-Ank&uuml;ndigung repariert.");
212                                 break;
213
214                         case '0.1.9': // SQL queries for v0.1.9
215                                 // Update notes (these will be set as task text!)
216                                 setExtensionUpdateNotes("Funktion <u>generateUserProfileLink()</u> mit Verlinkung auf Referal-Liste implementiert.");
217                                 break;
218
219                         case '0.2.0': // SQL queries for v0.2.0
220                                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_rallye_data` ADD min_users BIGINT(20) UNSIGNED NOT NULL DEFAULT 0");
221                                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_rallye_data` ADD min_prices BIGINT(20) UNSIGNED NOT NULL DEFAULT 3");
222
223                                 // Update notes (these will be set as task text!)
224                                 setExtensionUpdateNotes("Ablaufen der Rallyes intergriert. Bauen Sie in Ihr Template <strong>templates/de/emails/member/member_rallye_notify.tpl</strong> folgende zwei Zeilen ein:<br />
225 <ul>
226   <li>&#36;DATA&#91;min_users&#93;</li>
227   <li>&#36;DATA&#91;min_prices&#93;</li>
228 </ul>
229 Zudem sollten Sie mindestens folgende Templates (in <strong>templates/".getLanguage()."/html/guest/</strong> !) aktualisieren:<br />
230 <ul>
231   <li><strong>guest_rallye_footer.tpl</strong></li>
232   <li><strong>guest_rallye_header.tpl</strong></li>
233 </ul>");
234                                 break;
235
236                         case '0.2.1': // SQL queries for v0.2.1
237                                 // Update notes (these will be set as task text!)
238                                 setExtensionUpdateNotes("W&ouml;rter <strong>{?mt_word?}</strong>, <strong>{?mt_word2?}</strong> und <strong>{?mt_word3?}</strong> sind austauschbar.");
239                                 break;
240
241                         case '0.2.2': // SQL queries for v0.2.2
242                                 // Update notes (these will be set as task text!)
243                                 setExtensionUpdateNotes("Links wegen <strong>what=admins_contct</strong> ge&auml;ndert.");
244                                 break;
245
246                         case '0.2.3': // SQL queries for v0.2.3
247                                 // Update notes (these will be set as task text!)
248                                 setExtensionUpdateNotes("HTML-Code ausgelagert in Templates und SQL-Anweisungen abgesichert.");
249                                 break;
250
251                         case '0.2.4': // SQL queries for v0.2.4
252                                 // Update notes (these will be set as task text!)
253                                 setExtensionUpdateNotes("Abspeichern von Einstellungen repariert.");
254                                 break;
255
256                         case '0.2.5': // SQL queries for v0.2.5
257                                 // Update notes (these will be set as task text!)
258                                 setExtensionUpdateNotes("Men&uuml;punkt &quot;Rallyes verwalten&quot; repariert.");
259                                 break;
260
261                         case '0.2.6': // SQL queries for v0.2.6
262                                 // Update notes (these will be set as task text!)
263                                 setExtensionUpdateNotes("Automatisches Starten von Referal-Rallyes repariert.");
264                                 break;
265
266                         case '0.2.7': // SQL queries for v0.2.7
267                                 // Update notes (these will be set as task text!)
268                                 setExtensionUpdateNotes("Fatalen Fehler beseitigt.");
269                                 break;
270
271                         case '0.2.8': // SQL queries for v0.2.8
272                                 // Update notes (these will be set as task text!)
273
274                                 setExtensionUpdateNotes("Vorbereitung auf die neue Mediendaten v0.0.4.");
275                                 break;
276
277                         case '0.2.9': // SQL queries for v0.2.9
278                                 // Update notes (these will be set as task text!)
279                                 setExtensionUpdateNotes("Sicherheitsupdate f&uuml;r die Include-Befehle.");
280                                 break;
281
282                         case '0.3.0': // SQL queries for v0.3.0
283                                 // Update notes (these will be set as task text!)
284                                 setExtensionUpdateNotes("if-Anweisungen auf Funktion <strong>empty()</strong> umgestellt.");
285                                 break;
286
287                         case '0.3.1': // SQL queries for v0.3.1
288                                 // Update notes (these will be set as task text!)
289                                 setExtensionUpdateNotes("Erweiterung f&uuml;r automatisch generierte Admin-Kontaktlinks ge&auml;ndert.");
290                                 break;
291
292                         case '0.3.2': // SQL queries for v0.3.2
293                                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `action`='rals', `sort`=1, `title`='Referal-Rallye' WHERE `what`='rallyes' LIMIT 1");
294
295                                 // Update notes (these will be set as task text!)
296                                 setExtensionUpdateNotes("Mitgliedsmen&uuml; komplett umgebaut.");
297                                 break;
298
299                         case '0.3.3': // SQL queries for v0.3.3
300                                 // Update notes (these will be set as task text!)
301                                 setExtensionUpdateNotes("Rallyes werden nun nur dann automatisch beseitigt, wenn die Erweiterung <strong>autopurge</strong> installiert und aktiviert ist.");
302                                 break;
303
304                         case '0.3.4': // SQL queries for v0.3.4
305                                 // Update notes (these will be set as task text!)
306                                 setExtensionUpdateNotes("Fehlerhinweis bei deaktivierter Erweiterung verbessert.");
307                                 break;
308
309                         case '0.3.5': // SQL queries for 0.3.5
310                                 // This update depends on sql_patches
311                                 addExtensionUpdateDependency('sql_patches');
312
313                                 // Register filter
314                                 registerFilter('extra_autopurge', 'RALLYE_EXTRA_AUTOPURGE', false, true, getExtensionDryRun());
315
316                                 // Update notes (these will be set as task text!)
317                                 setExtensionUpdateNotes("Filter hinzugef&uuml;gt und ist von <strong>sql_patches</strong> abh&auml;ngig.");
318                                 break;
319                 }
320                 break;
321
322         case 'modify': // When the extension got modified
323                 break;
324
325         case 'test': // For testing purposes. For details see file inc/modules/admin/what-extensions.php, arround line 305.
326                 break;
327
328         case 'init': // Do stuff when extension is initialized
329                 // Do stuff only when not in CSS mode
330                 // @TODO Move this code into rallye_functions.php
331                 if (getOutputMode() != 1) {
332                         // Get total member count
333                         $total = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true);
334
335                         // Add more data on higher versions
336                         $ADD1 = ''; $ADD2 = ''; $OR = '';
337                         if (getExtensionVersion('rallye') >= '0.2.0') {
338                                 $ADD1 = ", `min_users`, `min_prices`";
339                                 $ADD2 = ", d.min_users, d.min_prices";
340                                 $OR   = " OR (d.min_users <= ".$total." AND d.min_users > 0)";
341                         } // END  - if
342
343                         // Check for new started but not notified rallyes
344                         $result = SQL_QUERY("SELECT SQL_SMALL_RESULT
345         `id`, `title`, `start_time`, `end_time`, `send_notify`".$ADD1."
346 FROM
347         `{?_MYSQL_PREFIX?}_rallye_data`
348 WHERE
349         `is_active`='Y' AND
350         `notified`='N' AND
351         `expired`='N' AND
352         `start_time` <= UNIX_TIMESTAMP() AND
353         `end_time` > UNIX_TIMESTAMP()
354 LIMIT 1", __FILE__, __LINE__);
355                         if (SQL_NUMROWS($result) == 1) {
356                                 // Start rallye
357                                 autostartReferalRallyes($result);
358                         } // END - if
359
360                         // Free memory
361                         SQL_FREERESULT($result);
362
363                         // Check for expired rallyes
364                         $result = SQL_QUERY("SELECT SQL_SMALL_RESULT
365         d.id, d.title, d.start_time, d.end_time, d.send_notify".$ADD2."
366 FROM
367         `{?_MYSQL_PREFIX?}_rallye_data` AS d
368 WHERE
369         d.is_active='Y' AND
370         d.notified='Y' AND
371         d.expired='N' AND
372         (d.end_time <= UNIX_TIMESTAMP()".$OR.")
373 LIMIT 1", __FILE__, __LINE__);
374                         if ((SQL_NUMROWS($result) == 1) && (isExtensionActive('autopurge'))) {
375                                 // End rallye here...
376                                 markReferalRallyesAsExpired($result);
377                         } // END - if
378
379                         // Free memory
380                         SQL_FREERESULT($result);
381                 } // END - if
382                 break;
383
384         default: // Unknown extension mode
385                 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown extension mode %s detected.", getExtensionMode()));
386                 break;
387 } // END - switch
388
389 // [EOF]
390 ?>