b764392c67ce8863574b0cb2e1f8e19ee85716ec
[mailer.git] / inc / pool-update.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 11/08/2003 *
4  * ===============                              Last change: 07/01/2005 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : pool-update.php                                  *
8  * -------------------------------------------------------------------- *
9  * Short description : Sends queued mails from the pool                 *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Sendet freigegebene Mails aus den Pool           *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
36 {
37         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38         require($INC);
39 }
40
41 // Test html extensions once
42 $HTML_EXT = EXT_IS_ACTIVE("html_mail", true);
43
44 // Check for freed mail orders to send out
45 if ($HTML_EXT)
46 {
47         //                                0     1        2      3       4          5            6      7        8          9       10
48         $result_main = SQL_QUERY("SELECT id, sender, subject, text, receivers, payment_id, timestamp, url, target_send, cat_id, html_msg FROM "._MYSQL_PREFIX."_pool WHERE data_type='NEW' ORDER BY timestamp DESC", __FILE__, __LINE__);
49 }
50  else
51 {
52         //                                0     1        2      3       4          5            6      7        8          9    10
53         $result_main = SQL_QUERY("SELECT id, sender, subject, text, receivers, payment_id, timestamp, url, target_send, cat_id, id FROM "._MYSQL_PREFIX."_pool WHERE data_type='NEW' ORDER BY timestamp DESC", __FILE__, __LINE__);
54 }
55
56 // Reset variables
57 $cnt = "0"; $cnt2 = "0"; $LAST_SENT_ID = "0"; $cnt_back = array("0"); $POINTS_BACK = array("0");
58 if (SQL_NUMROWS($result_main) > 0)
59 {
60         while ($DATA = SQL_FETCHROW($result_main))
61         {
62                 // Check fetched data for HTML
63                 $HTML = $DATA[10]; if ($HTML == $DATA[0]) $HTML = 'N';
64
65                 // Compile URL and subject line
66                 $DATA[7] = COMPILE_CODE($DATA[7]);
67
68                 // Set mail order as "active". That means it will be sent out
69                 $result_active = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET data_type='ACTIVE' WHERE id=%d AND data_type='NEW' LIMIT 1",
70                  array($DATA[0]), __FILE__, __LINE__);
71                 if (SQL_AFFECTEDROWS($result_active) == 1)
72                 {
73                         // "Explode" all receivers into an array
74                         if (ereg(";", $DATA[4]))
75                         {
76                                 // There's more than one receiver in the list...
77                                 $RECEIVERS = explode(";", $DATA[4]);
78                         }
79                          elseif (!empty($DATA[4]))
80                         {
81                                 // Only one user left
82                                 $RECEIVERS = array($DATA[4]);
83                         }
84                          else
85                         {
86                                 // No users left
87                                 $RECEIVERS = array("0");
88                         }
89                         $DUMMY = $RECEIVERS;
90
91                         // Now, if we are good little boys and girls Santa left us some user-ids.
92                         // We can now send mails to them...
93                         foreach ($RECEIVERS as $key=>$uid)
94                         {
95                                 // Lookup user ID
96                                 $result_user = SQL_QUERY_ESC("SELECT sex, surname, family, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d LIMIT 1",
97                                  array(bigintval($uid)), __FILE__, __LINE__);
98
99                                 // Is his data available?
100                                 //* DEBUG: */ echo "*L:".__LINE__."/".SQL_NUMROWS($result_user)."*<BR>";
101                                 if (SQL_NUMROWS($result_user) == 1)
102                                 {
103                                         // The final receiver does exists so we can continue...
104                                         list($salut, $sname, $fname, $email) = SQL_FETCHROW($result_user);
105
106                                         // Free memory
107                                         SQL_FREERESULT($result_user);
108
109                                         // Do we have a stats entry?
110                                         $result_stats = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_user_stats WHERE pool_id=%d AND userid=%d AND timestamp_ordered='%s' LIMIT 1",
111                                          array($DATA[0], $DATA[1], $DATA[6]), __FILE__, __LINE__);
112
113                                         // If there's no stats entry add it!
114                                         //* DEBUG: */ echo "!L:".__LINE__."/".SQL_NUMROWS($result_stats)."!<BR>";
115                                         if (SQL_NUMROWS($result_stats) == 0)
116                                         {
117                                                 // No entry was found, so we add him!
118                                                 $result_stats = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_stats (pool_id , userid, cat_id, payment_id, subject, url , max_rec , timestamp_ordered, timestamp_sstart) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' , UNIX_TIMESTAMP())",
119                                                  array(bigintval($DATA[0]), bigintval($DATA[1]), bigintval($DATA[9]), bigintval($DATA[5]), $DATA[2], $DATA[7], $DATA[8], bigintval($DATA[6])), __FILE__, __LINE__);
120
121                                                 // Receive it's ID for the links table
122                                                 $result_stats = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_user_stats WHERE pool_id=%d AND userid=%d AND timestamp_ordered='%s' LIMIT 1",
123                                                  array(bigintval($DATA[0]), bigintval($DATA[1]), bigintval($DATA[6])), __FILE__, __LINE__);
124                                         }
125
126                                         //* DEBUG: */ echo "!L:".__LINE__."/".SQL_NUMROWS($result_stats)."!<BR>";
127                                         if (SQL_NUMROWS($result_stats) == 1)
128                                         {
129                                                 // We got one!
130                                                 list($stats_id) = SQL_FETCHROW($result_stats);
131                                                 SQL_FREERESULT($result_stats);
132
133                                                 // Mark this user as "spammed" ;-) And place a line for him...
134                                                 //* DEBUG: */ echo "?L:".__LINE__."/".$DUMMY."/".$key."/".$uid."(".$DATA[1].")/".$DATA[0]."/".$stats_id."?<BR>";
135                                                 switch (REMOVE_RECEIVER($DUMMY, $key, bigintval($uid), bigintval($DATA[0]), bigintval($stats_id)))
136                                                 {
137                                                 case "done":
138                                                         // Prepare the mail
139                                                         $DATA[11] = bigintval($stats_id);
140                                                         $DATA[12] = $sname;
141                                                         $DATA[13] = $fname;
142                                                         $DATA[14] = TRANSLATE_SEX($salut);
143
144                                                         // Load message template
145                                                         $msg = LOAD_EMAIL_TEMPLATE("normal-mail", $DATA[3], bigintval($uid));
146
147                                                         // Send mail away
148                                                         SEND_EMAIL($email, $DATA[2], $msg, $HTML);
149
150                                                         // Count sent mails...
151                                                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET emails_sent=emails_sent+1 WHERE userid=%d LIMIT 1",
152                                                          array(bigintval($DATA[1])), __FILE__, __LINE__);
153
154                                                         if (GET_EXT_VERSION("user") >= "0.1.4")
155                                                         {
156                                                                 // Update mails received for receiver
157                                                                 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET emails_received=emails_received+1 WHERE userid=%d LIMIT 1",
158                                                                 array(bigintval($uid)), __FILE__, __LINE__);
159                                                         }
160
161                                                         // Update mediadata if version is 0.0.4 or higher
162                                                         if (GET_EXT_VERSION("mediadata") >= "0.0.4")
163                                                         {
164                                                                 // Update entry (or add missing)
165                                                                 //* DEBUG: */ echo "*MEDIA/L:".__LINE__."*<BR>";
166                                                                 MEDIA_UPDATE_ENTRY(array("total_send", "normal_send"), "add", 1);
167                                                         }
168
169                                                         // And count up the mail
170                                                         $cnt++;
171                                                         //* DEBUG: */ echo"*EXIT/L:".__LINE__."/".$cnt."*<BR>";
172                                                         break;
173
174                                                 case "already":
175                                                         // Entry already found, but we still count one up!
176                                                         $cnt++;
177                                                         //* DEBUG: */ echo"*EXIT/L:".__LINE__."/".$cnt."<BR>";
178                                                         break;
179                                                 }
180                                         }
181
182                                         // Do we have reached the maximum to send mails? || ($CONFIG['max_send'] >= $cnt)
183                                         //* DEBUG: */ echo "*L:".__LINE__."/".$cnt.">=".$DATA[8]."/".$CONFIG['max_send'].">=".$cnt."/".$LAST_SENT_ID."!=".$DATA[0]."*<BR>";
184                                         if ((($cnt >= $DATA[8])) && ($LAST_SENT_ID != $DATA[0]))
185                                         {
186                                                 // Yes we do, so we notify admin and sender about fully sent mail!
187                                                 if (GET_EXT_VERSION("admins") >= "0.4.1")
188                                                 {
189                                                         // New method
190                                                         SEND_ADMIN_EMAILS_PRO(ADMIN_SUBJ_SEND_DONE, "done-admin", $DATA[3], $uid);
191                                                 }
192                                                  else
193                                                 {
194                                                         // Old method
195                                                         SEND_ADMIN_EMAILS(ADMIN_SUBJ_SEND_DONE, LOAD_EMAIL_TEMPLATE("done-admin", $DATA[3], $uid));
196                                                 }
197
198                                                 // Get sender's data
199                                                 $result_sender = SQL_QUERY_ESC("SELECT surname, family, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d LIMIT 1",
200                                                  array(bigintval($DATA[1])), __FILE__, __LINE__);
201                                                 if (SQL_NUMROWS($result_sender) == 1)
202                                                 {
203                                                         // Load data and prepare mail
204                                                         list($sname, $fname, $email) = SQL_FETCHROW($result_sender);
205                                                         SQL_FREERESULT($result_sender);
206                                                         $msg = LOAD_EMAIL_TEMPLATE("done-member", $DATA[3], $DATA[1]);
207
208                                                         // Send it also waway
209                                                         SEND_EMAIL($email, MEMBER_SUBJ_SEND_DONE, $msg);
210                                                 }
211
212                                                 // Set status to SEND because we completely send it away
213                                                 $result_done = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET data_type='SEND', target_send='0', receivers='' WHERE id=%d LIMIT 1",
214                                                  array(bigintval($DATA[0])), __FILE__, __LINE__);
215
216                                                 // Update send-completed-time
217                                                 $result_user = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_stats SET timestamp_send=UNIX_TIMESTAMP() WHERE pool_id=%d LIMIT 1",
218                                                  array(bigintval($DATA[0])), __FILE__, __LINE__);
219
220                                                 $LAST_SENT_ID = $DATA[0]; $cnt = "0";
221                                                 $cnt2 += $cnt;
222
223                                                 // Update mediadata if version is 0.0.4 or higher
224                                                 if (GET_EXT_VERSION("mediadata") >= "0.0.4")
225                                                 {
226                                                         // Update entry (or add missing)
227                                                         //* DEBUG: */ echo "*MEDIA/L:".__LINE__."*<BR>";
228                                                         MEDIA_UPDATE_ENTRY(array("total_orders", "normal_orders"), "add", 1);
229                                                 }
230
231                                                 //* DEBUG: */ echo"*EXIT/L:".__LINE__."/".$P."<BR>";
232                                                 break;
233                                         }
234                                         // Do we have send maximum mails?
235                                          elseif (($cnt >= $CONFIG['max_send']) || ($cnt2 >= $CONFIG['max_send']))
236                                         {
237                                                 // There are some mails left to send for next round, so we reset the status back to NEW (=still not fully delivered)
238                                                 $ADD = "";
239                                                 if ($cnt <= $DATA[8]) $ADD = ", target_send=target_send-".$cnt;
240                                                 $result_queue = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET data_type='NEW', receivers='%s'".$ADD." WHERE id=%d LIMIT 1",
241                                                  array(implode(";", $DUMMY), bigintval($DATA[0])), __FILE__, __LINE__);
242
243                                                 //* DEBUG: */ echo"*EXIT/L:".__LINE__."*<BR>";
244                                                 break;
245                                         }
246                                 }
247                                  else
248                                 {
249                                         // User does not exists so we have add the sender's points back to sender's account
250                                         if (($RECEIVERS[0] == "0") || (empty($RECEIVERS[0])))
251                                         {
252                                                 // List was empty
253                                                 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET data_type='SEND' WHERE id=%d LIMIT 1",
254                                                  array(bigintval($DATA[0])), __FILE__, __LINE__);
255                                         }
256                                          else
257                                         {
258                                                 if ($uid > 0)
259                                                 {
260                                                         // User does not exists, pay points back
261                                                         $POINTS = GET_PAY_POINTS($DATA[5]);
262                                                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_points SET points=points+%s WHERE userid=%d AND ref_depth='0' LIMIT 1",
263                                                          array($POINTS, bigintval($DATA[1])), __FILE__, __LINE__);
264
265                                                         // Update mediadata as well
266                                                         if (GET_EXT_VERSION("mediadata") >= "0.0.4")
267                                                         {
268                                                                 // Update database
269                                                                 //* DEBUG: */ echo "*MEDIA/L:".__LINE__."/".$POINTS."*<BR>";
270                                                                 MEDIA_UPDATE_ENTRY(array("total_points"), "add", $POINTS);
271                                                         }
272
273                                                         // Add points together and remove user
274                                                         $POINTS_BACK[$DATA[1]] += $POINTS;
275                                                 }
276                                                 $cnt_back[$DATA[1]]++;
277                                         }
278                                         // Remove entry from list
279                                         unset($DUMMY[$key]);
280
281                                         // Update receivers
282                                         $result_queue = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET receivers='%s' WHERE id=%d LIMIT 1",
283                                          array(implode(";", $DUMMY), bigintval($DATA[0])), __FILE__, __LINE__);
284                                 }
285                         }
286                 }
287         }
288         if ((sizeof($POINTS_BACK) > 0) && (!empty($POINTS_BACK[0])))
289         {
290                 foreach ($POINTS_BACK as $uid=>$PB)
291                 {
292                         // Add points only when we have points left to add and a valid user ID
293                         if (($PB > 0) && ($uid > 0))
294                         {
295                                 // We have to pay back some points to the sender (we add them directly :-P)
296                                 $result = SQL_QUERY_ESC("SELECT email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d AND status='CONFIRMED' LIMIT 1",
297                                  array(bigintval($uid)), __FILE__, __LINE__);
298                                 $DATA[10] = $PB; $DATA[11] = $cnt_back[$uid];
299                                 if (SQL_NUMROWS($result) == 1)
300                                 {
301                                         list($email) = SQL_FETCHROW($result);
302                                         SQL_FREERESULT($result);
303
304                                         // User account does exists, so we can safely pay back!
305                                         $msg = LOAD_EMAIL_TEMPLATE("back-member", "", bigintval($uid));
306
307                                         // Send mail out to member
308                                         SEND_EMAIL($email, MEMBER_BACK_JACKPOT." (".$uid.")", $msg);
309                                 }
310                                  else
311                                 {
312                                         // Add to jackpot
313                                         ADD_JACKPOT($PB);
314
315                                         // Send mail out to admin
316                                         if (GET_EXT_VERSION("admins") >= "0.4.1")
317                                         {
318                                                 SEND_ADMIN_EMAILS_PRO(ADMIN_BACK_JACKPOT." (".$uid.")", "back-admin", "", "admin");
319                                         }
320                                          else
321                                         {
322                                                 SEND_ADMIN_EMAILS(ADMIN_BACK_JACKPOT." (".$uid.")", LOAD_TEMPLATE("back-admin", "", "admin"));
323                                         }
324                                 }
325                         }
326                 }
327         }
328 }
329
330 // Free memory
331 SQL_FREERESULT($result_main);
332
333 // Only send bonus mail when bonus extension is active and maximum send-mails is not reached
334 if ((EXT_IS_ACTIVE("bonus") && ($cnt < $CONFIG['max_send'])))
335 {
336         // Do we need to send out bonus mails?
337         if ($HTML_EXT)
338         {
339                 //                                 0     1       2        3        4      5       6          7       8      9         10         11
340                 $result_bonus = SQL_QUERY("SELECT id, subject, text, receivers, points, time, data_type, timestamp, url, cat_id, target_send, html_msg FROM "._MYSQL_PREFIX."_bonus WHERE data_type='NEW' ORDER BY timestamp DESC", __FILE__, __LINE__);
341         }
342          else
343         {
344                 //                                 0     1       2        3        4      5       6          7       8      9         10      11
345                 $result_bonus = SQL_QUERY("SELECT id, subject, text, receivers, points, time, data_type, timestamp, url, cat_id, target_send, 'N' FROM "._MYSQL_PREFIX."_bonus WHERE data_type='NEW' ORDER BY timestamp DESC", __FILE__, __LINE__);
346         }
347
348         if (SQL_NUMROWS($result_bonus) > 0)
349         {
350                 // Send these mails away...
351                 $cnt2 = "";
352                 while ($DATA = SQL_FETCHROW($result_bonus))
353                 {
354                         // Compile URL
355                         $DATA[8] = COMPILE_CODE($DATA[8]);
356
357                         // Message is active in queue
358                         $result_queue = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_bonus SET data_type='QUEUE' WHERE id=%d LIMIT 1",
359                          array(bigintval($DATA[0])), __FILE__, __LINE__);
360
361                         // "Explode" all receivers into an array
362                         if (ereg(";", $DATA[3]))
363                         {
364                                 // There's more than one receiver in the list...
365                                 $RECEIVERS = explode(";", $DATA[3]);
366                         }
367                          elseif (!empty($DATA[4]))
368                         {
369                                 // Only one user left
370                                 $RECEIVERS = array($DATA[3]);
371                         }
372                          else
373                         {
374                                 // No users left
375                                 $RECEIVERS = array("0");
376                         }
377                         $DUMMY = $RECEIVERS;
378
379                         // Now, if we are good little boys and girls Santa left us some user-ids.
380                         // We can now send mails to them...
381                         foreach ($RECEIVERS as $key=>$uid)
382                         {
383                                 // Load personal data
384                                 //* DEBUG: */ echo "*L:".__LINE__."/".$uid."*<BR>";
385                                 $result_user = SQL_QUERY_ESC("SELECT surname, family, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d LIMIT 1",
386                                  array(bigintval($uid)), __FILE__, __LINE__);
387
388                                 // Is his data available?
389                                 if (SQL_NUMROWS($result_user) == 1)
390                                 {
391                                         // The final receiver does exists so we can continue...
392                                         list($sname, $fname, $email) = SQL_FETCHROW($result_user);
393                                         //* DEBUG: */ echo "OK!/L:".__LINE__."<BR>";
394
395                                         // Mark this user as "spammed" ;-) And place a line for him...
396                                         if (REMOVE_RECEIVER($DUMMY, $key, $uid, $DATA[0], $DATA[0], true) == "done")
397                                         {
398                                                 // Prepare the mail
399                                                 $msg = LOAD_EMAIL_TEMPLATE("bonus-mail", $DATA[2], $uid);
400
401                                                 // Send mail away
402                                                 SEND_EMAIL($email, $DATA[1], $msg, $DATA[11]);
403
404                                                 // Count one up and remove entry from dummy array
405                                                 $cnt++; unset($DUMMY[$key]);
406
407                                                 if (GET_EXT_VERSION("user") >= "0.1.4")
408                                                 {
409                                                         // Update mails received for receiver
410                                                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET emails_received=emails_received+1 WHERE userid=%d LIMIT 1",
411                                                          array(bigintval($uid)), __FILE__, __LINE__);
412                                                 }
413
414                                                 // Do we have send maximum mails?
415                                                 if (($cnt >= $CONFIG['max_send']) || (SELECTION_COUNT($DUMMY) == 0))
416                                                 {
417                                                         // Yes, we have
418                                                         //* DEBUG: */ echo "*EXIT/L:".__LINE__."<BR>";
419                                                         break;
420                                                 }
421                                         }
422                                 }
423
424                                 // Free some memory
425                                 SQL_FREERESULT($result_user);
426                         }
427
428                         // Update mediadata if version is 0.0.4 or higher
429                         if (GET_EXT_VERSION("mediadata") >= "0.0.4")
430                         {
431                                 // Update entry (or add missing
432                                 $P = $cnt;
433                                 if (!empty($cnt2) && empty($cnt)) $P = $cnt2;
434                                 //* DEBUG: */ echo "+MEDIA/L:".__LINE__."/".$P."+<BR>";
435                                 MEDIA_UPDATE_ENTRY(array("total_send", "bonus_send"), "add", $P);
436                         }
437
438                         // Close sending system
439                         //* DEBUG: */ echo "-L:".__LINE__."/".SELECTION_COUNT($DUMMY)."-<BR>";
440                         if (SELECTION_COUNT($DUMMY) == 0)
441                         {
442                                 // Queue reached!
443                                 $result_done = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_bonus SET data_type='SEND', target_send='0', receivers='' WHERE id=%d LIMIT 1",
444                                  array(bigintval($DATA[0])), __FILE__, __LINE__);
445                                 //* DEBUG: */ echo "*L:".__LINE__."*<BR>";
446
447                                 // Update mediadata if version is 0.0.4 or higher
448                                 if (GET_EXT_VERSION("mediadata") >= "0.0.4")
449                                 {
450                                         // Update entry (or add missing)
451                                         //* DEBUG: */ echo "*MEDIA/L:".__LINE__."*<BR>";
452                                         MEDIA_UPDATE_ENTRY(array("total_orders", "bonus_orders"), "add", 1);
453                                 }
454                         }
455                          elseif ($cnt >= $CONFIG['max_send'])
456                         {
457                                 // Update bonus pool
458                                 $result_done = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_bonus SET data_type='NEW', target_send=%d, receivers='%s' WHERE id=%d LIMIT 1",
459                                  array(SELECTION_COUNT($DUMMY), implode(";", $DUMMY), bigintval($DATA[0])), __FILE__, __LINE__);
460                                 //* DEBUG: */ echo "*L:".__LINE__."<PRE>";
461                                 //* DEBUG: */ print_r($DUMMY);
462                                 //* DEBUG: */ echo "</PRE>\n!!!<BR>";
463                                 break;
464                         }
465                 }
466         }
467
468         // Free memory
469         SQL_FREERESULT($result_bonus);
470 }
471
472 // Remove message (IMPORTANT!)
473 unset($msg);
474
475 //
476 ?>