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