Huge script change, see http://forum.mxchange.org/topic-458.html for details:
[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  * $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                 addExtensionSql("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                 addExtensionSql("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                 addExtensionSql("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                 addExtensionSql("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
96                 // Guest menu
97                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('main','rallyes','Ref-Rallyes','Y','Y','9')");
98
99                 // Member menu
100                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('main','rallyes','Ref-Rallyes','Y','Y','9')");
101                 break;
102
103         case 'remove': // Do stuff when removing extension
104                 // Drop tables
105                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_rallye_data`");
106                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_rallye_prices`");
107                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_rallye_users`");
108
109                 // Remove menus
110                 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='rallye'");
111                 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE `what`='rallyes'");
112                 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `what`='rallyes'");
113
114                 // Unregister filter
115                 unregisterFilter('extra_autopurge', 'RALLYE_EXTRA_AUTOPURGE', true, getExtensionDryRun());
116                 break;
117
118         case 'activate': // Do stuff when admin activates this extension
119                 // SQL commands to run
120                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `visible`='Y', `locked`='N' WHERE `what`='rallyes' LIMIT 1");
121                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='Y', `locked`='N' WHERE `what`='rallyes' LIMIT 1");
122                 break;
123
124         case 'deactivate': // Do stuff when admin deactivates this extension
125                 // SQL commands to run
126                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_guest_menu` SET `visible`='N', `locked`='Y' WHERE `what`='rallyes' LIMIT 1");
127                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='N', `locked`='Y' WHERE `what`='rallyes' LIMIT 1");
128                 break;
129
130         case 'update': // Update an extension
131                 switch (getCurrentExtensionVersion()) {
132                         case '0.0.1': // SQL queries for v0.0.1
133                                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_rallye_data` ADD expired ENUM('Y','N') NOT NULL DEFAULT 'N'");
134
135                                 // Update notes (these will be set as task text!)
136                                 setExtensionUpdateNotes("Ablaufen der Rallyes intergriert.");
137                                 break;
138
139                         case '0.0.2': // SQL queries for v0.0.2
140                                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_rallye_users` ADD curr_points FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.00000");
141
142                                 // Update notes (these will be set as task text!)
143                                 setExtensionUpdateNotes("Aktueller {?POINTS?}-Stand wird beachtet.");
144                                 break;
145
146                         case '0.0.6': // SQL queries for v0.0.6
147                                 // Update notes (these will be set as task text!)
148                                 setExtensionUpdateNotes("Fehler <em>Unknown column 'd.useid' in 'on clause'</em> behoben.");
149                                 break;
150
151                         case '0.0.7': // SQL queries for v0.0.7
152                                 // Update notes (these will be set as task text!)
153                                 setExtensionUpdateNotes("Fehlende Abfrage im Mitlieder-Modul, on Erweiterung auch aktiviert ist.");
154                                 break;
155
156                         case '0.0.8': // SQL queries for v0.0.8
157                                 // Update notes (these will be set as task text!)
158                                 setExtensionUpdateNotes("Fehler <u>Template nicht gefunden</u> behoben und Admin-Formulare ausgelagert");
159                                 break;
160
161                         case '0.0.9': // SQL queries for v0.0.9
162                                 // Update notes (these will be set as task text!)
163                                 setExtensionUpdateNotes("Fehler beseitigt, wenn error_reporting=E_ALL gesetzt ist. Und der vorherige Fehler <u>Template nicht gefunden</u> ist endlich beseitigt.");
164                                 break;
165
166                         case '0.1.0': // SQL queries for v0.2.1
167                                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_rallye_users` CHANGE curr_points curr_points FLOAT(23,5) UNSIGNED NOT NULL DEFAULT 0.00000");
168
169                                 // Update notes (these will be set as task text!)
170                                 setExtensionUpdateNotes("5 Nachkommastellen implementiert.");
171                                 break;
172
173                         case '0.1.1': // SQL queries for v0.1.1
174                                 // Update notes (these will be set as task text!)
175                                 setExtensionUpdateNotes("Fehler beseitigt, wenn error_reporting=E_ALL gesetzt ist.");
176                                 break;
177
178                         case '0.1.2': // SQL queries for v0.1.2
179                                 // Update notes (these will be set as task text!)
180                                 setExtensionUpdateNotes("Problem mit Speicherung der Einstellungen beseitigt.");
181                                 break;
182
183                         case '0.1.3': // SQL queries for v0.1.3
184                                 // Update notes (these will be set as task text!)
185                                 setExtensionUpdateNotes("Anzeigefehler im Gast-/Mitgliedsbereich behoben.");
186                                 break;
187
188                         case '0.1.4': // SQL queries for v0.1.4
189                                 // Update notes (these will be set as task text!)
190                                 setExtensionUpdateNotes("Admin-Mails korregiert.");
191                                 break;
192
193                         case '0.1.5': // SQL queries for v0.1.5
194                                 // Update notes (these will be set as task text!)
195                                 setExtensionUpdateNotes("Men&uuml;punkte im Gast-/Mitgliedsbereich k&ouml;nnen nicht mehr aufgerufen werden, wenn die Erweiterung deaktiviert ist.");
196                                 break;
197
198                         case '0.1.6': // SQL queries for v0.1.6
199                                 // Update notes (these will be set as task text!)
200                                 setExtensionUpdateNotes("Seit <strong>Patch 340</strong> &uuml;berfl&uuml;ssige HTML-Tags entfernt.");
201                                 break;
202
203                         case '0.1.7': // SQL queries for v0.1.7
204                                 // Update notes (these will be set as task text!)
205                                 setExtensionUpdateNotes("Aktivierte bzw. abgelaufene Rallyes werden nur ausserhalb des CSS-Modus geladen (wenn also nicht css.php aufgerufen wurde)");
206                                 break;
207
208                         case '0.1.8': // SQL queries for v0.1.8
209                                 // Update notes (these will be set as task text!)
210                                 setExtensionUpdateNotes("Weitere Templates vom Admin-Bereich ausgelagert und Referal-Anazahl in der Mail zur Rallye-Ank&uuml;ndigung repariert.");
211                                 break;
212
213                         case '0.1.9': // SQL queries for v0.1.9
214                                 // Update notes (these will be set as task text!)
215                                 setExtensionUpdateNotes("Funktion <u>generateUserProfileLink()</u> mit Verlinkung auf Referal-Liste implementiert.");
216                                 break;
217
218                         case '0.2.0': // SQL queries for v0.2.0
219                                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_rallye_data` ADD min_users BIGINT(20) UNSIGNED NOT NULL DEFAULT 0");
220                                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_rallye_data` ADD min_prices BIGINT(20) UNSIGNED NOT NULL DEFAULT '3'");
221
222                                 // Update notes (these will be set as task text!)
223                                 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 />
224 <ul>
225   <li>&#36;DATA&#91;min_users&#93;</li>
226   <li>&#36;DATA&#91;min_prices&#93;</li>
227 </ul>
228 Zudem sollten Sie mindestens folgende Templates (in <strong>templates/".getLanguage()."/html/guest/</strong> !) aktualisieren:<br />
229 <ul>
230   <li><strong>guest_rallye_footer.tpl</strong></li>
231   <li><strong>guest_rallye_header.tpl</strong></li>
232 </ul>");
233                                 break;
234
235                         case '0.2.1': // SQL queries for v0.2.1
236                                 // Update notes (these will be set as task text!)
237                                 setExtensionUpdateNotes("W&ouml;rter <strong>Mailtausch</strong>, <strong>Mailtausches</strong> und <strong>Mailtauscher</strong> sind austauschbar.");
238                                 break;
239
240                         case '0.2.2': // SQL queries for v0.2.2
241                                 // Update notes (these will be set as task text!)
242                                 setExtensionUpdateNotes("Links wegen <strong>what=admins_contct</strong> ge&auml;ndert.");
243                                 break;
244
245                         case '0.2.3': // SQL queries for v0.2.3
246                                 // Update notes (these will be set as task text!)
247                                 setExtensionUpdateNotes("HTML-Code ausgelagert in Templates und SQL-Anweisungen abgesichert.");
248                                 break;
249
250                         case '0.2.4': // SQL queries for v0.2.4
251                                 // Update notes (these will be set as task text!)
252                                 setExtensionUpdateNotes("Abspeichern von Einstellungen repariert.");
253                                 break;
254
255                         case '0.2.5': // SQL queries for v0.2.5
256                                 // Update notes (these will be set as task text!)
257                                 setExtensionUpdateNotes("Men&uuml;punkt &quot;Rallyes verwalten&quot; repariert.");
258                                 break;
259
260                         case '0.2.6': // SQL queries for v0.2.6
261                                 // Update notes (these will be set as task text!)
262                                 setExtensionUpdateNotes("Automatisches Starten von Referal-Rallyes repariert.");
263                                 break;
264
265                         case '0.2.7': // SQL queries for v0.2.7
266                                 // Update notes (these will be set as task text!)
267                                 setExtensionUpdateNotes("Fatalen Fehler beseitigt.");
268                                 break;
269
270                         case '0.2.8': // SQL queries for v0.2.8
271                                 // Update notes (these will be set as task text!)
272
273                                 setExtensionUpdateNotes("Vorbereitung auf die neue Mediendaten v0.0.4.");
274                                 break;
275
276                         case '0.2.9': // SQL queries for v0.2.9
277                                 // Update notes (these will be set as task text!)
278                                 setExtensionUpdateNotes("Sicherheitsupdate f&uuml;r die Include-Befehle.");
279                                 break;
280
281                         case '0.3.0': // SQL queries for v0.3.0
282                                 // Update notes (these will be set as task text!)
283                                 setExtensionUpdateNotes("if-Anweisungen auf Funktion <strong>empty()</strong> umgestellt.");
284                                 break;
285
286                         case '0.3.1': // SQL queries for v0.3.1
287                                 // Update notes (these will be set as task text!)
288                                 setExtensionUpdateNotes("Erweiterung f&uuml;r automatisch generierte Admin-Kontaktlinks ge&auml;ndert.");
289                                 break;
290
291                         case '0.3.2': // SQL queries for v0.3.2
292                                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `action`='rals', `sort`='1', `title`='Referal-Rallye' WHERE `what`='rallyes' LIMIT 1");
293
294                                 // Update notes (these will be set as task text!)
295                                 setExtensionUpdateNotes("Mitgliedsmen&uuml; komplett umgebaut.");
296                                 break;
297
298                         case '0.3.3': // SQL queries for v0.3.3
299                                 // Update notes (these will be set as task text!)
300                                 setExtensionUpdateNotes("Rallyes werden nun nur dann automatisch beseitigt, wenn die Erweiterung <strong>autopurge</strong> installiert und aktiviert ist.");
301                                 break;
302
303                         case '0.3.4': // SQL queries for v0.3.4
304                                 // Update notes (these will be set as task text!)
305                                 setExtensionUpdateNotes("Fehlerhinweis bei deaktivierter Erweiterung verbessert.");
306                                 break;
307
308                         case '0.3.5': // SQL queries for 0.3.5
309                                 // This update depends on sql_patches
310                                 addExtensionUpdateDependency('sql_patches');
311
312                                 // Register filter
313                                 registerFilter('extra_autopurge', 'RALLYE_EXTRA_AUTOPURGE', false, true, getExtensionDryRun());
314
315                                 // Update notes (these will be set as task text!)
316                                 setExtensionUpdateNotes("Filter hinzugef&uuml;gt und ist von <strong>sql_patches</strong> abh&auml;ngig.");
317                                 break;
318                 }
319                 break;
320
321         case 'modify': // When the extension got modified
322                 break;
323
324         case 'test': // For testing purposes. For details see file inc/modules/admin/what-extensions.php, arround line 305.
325                 break;
326
327         case 'init': // Do stuff when extension is initialized
328                 // Do stuff only when not in CSS mode
329                 // @TODO Move this code into rallye_functions.php
330                 if (getOutputMode() != '1') {
331                         // Get total member count
332                         $total = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true);
333
334                         // Add more data on higher versions
335                         $ADD1 = ''; $ADD2 = ''; $OR = '';
336                         if (getExtensionVersion('rallye') >= '0.2.0') {
337                                 $ADD1 = ", `min_users`, `min_prices`";
338                                 $ADD2 = ", d.min_users, d.min_prices";
339                                 $OR   = " OR (d.min_users <= ".$total." AND d.min_users > 0)";
340                         } // END  - if
341
342                         // Check for new started but not notified rallyes
343                         $result = SQL_QUERY("SELECT SQL_SMALL_RESULT
344         `id`, `t`itle`, `start_time`, `end_time`, `send_notify`".$ADD1."
345 FROM
346         `{?_MYSQL_PREFIX?}_rallye_data`
347 WHERE
348         `is_active`='Y' AND
349         `notified`='N' AND
350         `expired`='N' AND
351         `start_time` <= UNIX_TIMESTAMP() AND
352         `end_time` > UNIX_TIMESTAMP()
353 LIMIT 1", __FILE__, __LINE__);
354                         if (SQL_NUMROWS($result) == 1) {
355                                 // Start rallye
356                                 autostartReferalRallyes($result);
357                         } // END - if
358
359                         // Free memory
360                         SQL_FREERESULT($result);
361
362                         // Check for expired rallyes
363                         $result = SQL_QUERY("SELECT SQL_SMALL_RESULT
364         d.id, d.title, d.start_time, d.end_time, d.send_notify".$ADD2."
365 FROM
366         `{?_MYSQL_PREFIX?}_rallye_data` AS d
367 WHERE
368         d.is_active='Y' AND
369         d.notified='Y' AND
370         d.expired='N' AND
371         (d.end_time <= UNIX_TIMESTAMP()".$OR.")
372 LIMIT 1", __FILE__, __LINE__);
373                         if ((SQL_NUMROWS($result) == 1) && (isExtensionActive('autopurge'))) {
374                                 // End rallye here...
375                                 markReferalRallyesAsExpired($result);
376                         } // END - if
377
378                         // Free memory
379                         SQL_FREERESULT($result);
380                 } // END - if
381                 break;
382
383         default: // Unknown extension mode
384                 DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown extension mode %s detected.", getExtensionMode()));
385                 break;
386 } // END - switch
387
388 // [EOF]
389 ?>