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