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