- Major change in LOAD_EMAIL_TEMPLATE(). The deprecated switch() block has
[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['id']) $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=%s AND data_type='NEW' LIMIT 1",
70                  array($DATA['id']), __FILE__, __LINE__);
71                 if (SQL_AFFECTEDROWS() == 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 gender, surname, family, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s 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($gender, $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=%s AND userid=%s AND timestamp_ordered='%s' LIMIT 1",
111                                          array($DATA['id'], $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['id']), 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=%s AND userid=%s AND timestamp_ordered='%s' LIMIT 1",
123                                                  array(bigintval($DATA['id']), 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['id']."/".$stats_id."?<br />";
135                                                 switch (REMOVE_RECEIVER($dummy, $key, bigintval($uid), bigintval($DATA['id']), 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_GENDER($gender);
143
144                                                         // Replace text variables
145                                                         foreach ($REPLACER as $key => $value) {
146                                                                 if (isset($DATA[$key])) $DATA[3] = str_replace($value, $DATA[$key], $DATA[3]);
147                                                         } // END - if
148
149                                                         // Prepare content
150                                                         $content = array(
151                                                                 'id'         => $DATA[11],
152                                                                 'url'        => $DATA[3],
153                                                                 'sender_uid' => $DATA[1],
154                                                                 'category'   => GET_CATEGORY($DATA[9]),
155                                                                 'time'       => CREATE_FANCY_TIME(GET_PAY_POINTS($DATA[5], "time")),
156                                                                 'points'     => TRANSLATE_COMMA(GET_PAY_POINTS($DATA[5], "payment")),
157                                                                 'text'       => $DATA[3]
158                                                         );
159
160                                                         // Load message template
161                                                         $msg = LOAD_EMAIL_TEMPLATE("normal-mail", $content, bigintval($uid));
162
163                                                         // Send mail away
164                                                         SEND_EMAIL($email, $DATA[2], $msg, $HTML);
165
166                                                         // Count sent mails...
167                                                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET emails_sent=emails_sent+1 WHERE userid=%s LIMIT 1",
168                                                          array(bigintval($DATA[1])), __FILE__, __LINE__);
169
170                                                         if (GET_EXT_VERSION("user") >= "0.1.4") {
171                                                                 // Update mails received for receiver
172                                                                 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET emails_received=emails_received+1 WHERE userid=%s LIMIT 1",
173                                                                 array(bigintval($uid)), __FILE__, __LINE__);
174                                                         } // END - if
175
176                                                         // Update mediadata if version is 0.0.4 or higher
177                                                         if (GET_EXT_VERSION("mediadata") >= "0.0.4") {
178                                                                 // Update entry (or add missing)
179                                                                 //* DEBUG: */ echo "*MEDIA/L:".__LINE__."*<br />";
180                                                                 MEDIA_UPDATE_ENTRY(array("total_send", "normal_send"), "add", 1);
181                                                         } // END - if
182
183                                                         // And count up the mail
184                                                         $cnt++;
185                                                         //* DEBUG: */ echo"*EXIT/L:".__LINE__."/".$cnt."*<br />";
186                                                         break;
187
188                                                 case "already":
189                                                         // Entry already found, but we still count one up!
190                                                         $cnt++;
191                                                         //* DEBUG: */ echo"*EXIT/L:".__LINE__."/".$cnt."<br />";
192                                                         break;
193                                                 }
194                                         }
195
196                                         // Do we have reached the maximum to send mails? || ($_CONFIG['max_send'] >= $cnt)
197                                         //* DEBUG: */ echo "*L:".__LINE__."/".$cnt.">=".$DATA[8]."/".$_CONFIG['max_send'].">=".$cnt."/".$LAST_SENT_ID."!=".$DATA['id']."*<br />";
198                                         if ((($cnt >= $DATA[8])) && ($LAST_SENT_ID != $DATA['id'])) {
199                                                 // Prepare content
200                                                 $content = array(
201                                                         'sender_uid' => $DATA[1],
202                                                         'category'   => GET_CATEGORY($DATA[9])
203                                                 );
204
205                                                 // Yes we do, so we notify admin and sender about fully sent mail!
206                                                 SEND_ADMIN_NOTIFICATION(ADMIN_SUBJ_SEND_DONE, "done-admin", $content, $uid);
207
208                                                 // Get sender's data
209                                                 $result_sender = SQL_QUERY_ESC("SELECT surname, family, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
210                                                  array(bigintval($DATA[1])), __FILE__, __LINE__);
211                                                 if (SQL_NUMROWS($result_sender) == 1) {
212                                                         // Load data and prepare mail
213                                                         list($sname, $fname, $email) = SQL_FETCHROW($result_sender);
214                                                         SQL_FREERESULT($result_sender);
215
216                                                         // Load email template
217                                                         $msg = LOAD_EMAIL_TEMPLATE("done-member", $content, $DATA[1]);
218
219                                                         // Send it also waway
220                                                         SEND_EMAIL($email, MEMBER_SUBJ_SEND_DONE, $msg);
221                                                 }
222
223                                                 // Set status to SEND because we completely send it away
224                                                 $result_done = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET data_type='SEND', target_send='0', receivers='' WHERE id=%s LIMIT 1",
225                                                  array(bigintval($DATA['id'])), __FILE__, __LINE__);
226
227                                                 // Update send-completed-time
228                                                 $result_user = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_stats SET timestamp_send=UNIX_TIMESTAMP() WHERE pool_id=%s LIMIT 1",
229                                                  array(bigintval($DATA['id'])), __FILE__, __LINE__);
230
231                                                 $LAST_SENT_ID = $DATA['id']; $cnt = 0;
232                                                 $cnt2 += $cnt;
233
234                                                 // Update mediadata if version is 0.0.4 or higher
235                                                 if (GET_EXT_VERSION("mediadata") >= "0.0.4")
236                                                 {
237                                                         // Update entry (or add missing)
238                                                         //* DEBUG: */ echo "*MEDIA/L:".__LINE__."*<br />";
239                                                         MEDIA_UPDATE_ENTRY(array("total_orders", "normal_orders"), "add", 1);
240                                                 }
241
242                                                 //* DEBUG: */ echo"*EXIT/L:".__LINE__."/".$P."<br />";
243                                                 break;
244                                         }
245                                         // Do we have send maximum mails?
246                                          elseif (($cnt >= $_CONFIG['max_send']) || ($cnt2 >= $_CONFIG['max_send']))
247                                         {
248                                                 // There are some mails left to send for next round, so we reset the status back to NEW (=still not fully delivered)
249                                                 $ADD = "";
250                                                 if ($cnt <= $DATA[8]) $ADD = ", target_send=target_send-".$cnt;
251                                                 $result_queue = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET data_type='NEW', receivers='%s'".$ADD." WHERE id=%s LIMIT 1",
252                                                  array(implode(";", $dummy), bigintval($DATA['id'])), __FILE__, __LINE__);
253
254                                                 //* DEBUG: */ echo"*EXIT/L:".__LINE__."*<br />";
255                                                 break;
256                                         }
257                                 }
258                                  else
259                                 {
260                                         // User does not exists so we have add the sender's points back to sender's account
261                                         if (($RECEIVERS[0] == "0") || (empty($RECEIVERS[0])))
262                                         {
263                                                 // List was empty
264                                                 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET data_type='SEND' WHERE id=%s LIMIT 1",
265                                                  array(bigintval($DATA['id'])), __FILE__, __LINE__);
266                                         }
267                                          else
268                                         {
269                                                 if ($uid > 0)
270                                                 {
271                                                         // User does not exists, pay points back
272                                                         $points = GET_PAY_POINTS($DATA[5]);
273                                                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_points SET points=points+%s WHERE userid=%s AND ref_depth=0 LIMIT 1",
274                                                          array($points, bigintval($DATA[1])), __FILE__, __LINE__);
275
276                                                         // Update mediadata as well
277                                                         if (GET_EXT_VERSION("mediadata") >= "0.0.4")
278                                                         {
279                                                                 // Update database
280                                                                 //* DEBUG: */ echo "*MEDIA/L:".__LINE__."/".$points."*<br />";
281                                                                 MEDIA_UPDATE_ENTRY(array("total_points"), "add", $points);
282                                                         }
283
284                                                         // Add points together and remove user
285                                                         $points_BACK[$DATA[1]] += $points;
286                                                 }
287                                                 $cnt_back[$DATA[1]]++;
288                                         }
289                                         // Remove entry from list
290                                         unset($dummy[$key]);
291
292                                         // Update receivers
293                                         $result_queue = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET receivers='%s' WHERE id=%s LIMIT 1",
294                                          array(implode(";", $dummy), bigintval($DATA['id'])), __FILE__, __LINE__);
295                                 }
296                         }
297                 }
298         }
299         if ((sizeof($points_BACK) > 0) && (!empty($points_BACK[0]))) {
300                 foreach ($points_BACK as $uid => $PB) {
301                         // Add points only when we have points left to add and a valid user ID
302                         if (($PB > 0) && ($uid > 0)) {
303                                 // Prepare content
304                                 $content = array(
305                                         'points' => TRANSLATE_COMMA($DATA[10])
306                                 );
307
308                                 // We have to pay back some points to the sender (we add them directly :-P)
309                                 $result = SQL_QUERY_ESC("SELECT email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s AND status='CONFIRMED' LIMIT 1",
310                                         array(bigintval($uid)), __FILE__, __LINE__);
311                                 $DATA[10] = $PB; $DATA[11] = $cnt_back[$uid];
312                                 if (SQL_NUMROWS($result) == 1) {
313                                         list($email) = SQL_FETCHROW($result);
314                                         SQL_FREERESULT($result);
315
316                                         // User account does exists, so we can safely pay back!
317                                         $msg = LOAD_EMAIL_TEMPLATE("back-member", $content, bigintval($uid));
318
319                                         // Send mail out to member
320                                         SEND_EMAIL($email, MEMBER_BACK_JACKPOT." (".$uid.")", $msg);
321                                 } else {
322                                         // Add to jackpot
323                                         ADD_JACKPOT($PB);
324
325                                         // Send mail out to admin
326                                         SEND_ADMIN_NOTIFICATION(ADMIN_BACK_JACKPOT." (".$uid.")", "back-admin", $content, "admin");
327                                 }
328                         }
329                 }
330         }
331 }
332
333 // Free memory
334 SQL_FREERESULT($result_main);
335
336 // Only send bonus mail when bonus extension is active and maximum send-mails is not reached
337 if ((EXT_IS_ACTIVE("bonus") && ($cnt < $_CONFIG['max_send'])))
338 {
339         // Do we need to send out bonus mails?
340         if ($HTML_EXT) {
341                 //                                 0     1       2        3        4      5       6          7       8      9         10         11
342                 $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__);
343         } else {
344                 //                                 0     1       2        3        4      5       6          7       8      9         10
345                 $result_bonus = SQL_QUERY("SELECT id, subject, text, receivers, points, time, data_type, timestamp, url, cat_id, target_send FROM "._MYSQL_PREFIX."_bonus WHERE data_type='NEW' ORDER BY timestamp DESC", __FILE__, __LINE__);
346         }
347
348         if (SQL_NUMROWS($result_bonus) > 0) {
349                 // Send these mails away...
350                 $cnt2 = "";
351                 while ($DATA = SQL_FETCHARRAY($result_bonus)) {
352                         // Compile URL
353                         $DATA['url'] = COMPILE_CODE($DATA['url']);
354
355                         // Message is active in queue
356                         $result_queue = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_bonus SET data_type='QUEUE' WHERE id=%s LIMIT 1",
357                          array(bigintval($DATA['id'])), __FILE__, __LINE__);
358
359                         // "Explode" all receivers into an array
360                         if (ereg(";", $DATA['receivers'])) {
361                                 // There's more than one receiver in the list...
362                                 $RECEIVERS = explode(";", $DATA['receivers']);
363                         } elseif (!empty($DATA['points'])) {
364                                 // Only one user left
365                                 $RECEIVERS = array($DATA['receivers']);
366                         } else {
367                                 // No users left
368                                 $RECEIVERS = array("0");
369                         }
370                         $dummy = $RECEIVERS;
371
372                         // Now, if we are good little boys and girls Santa left us some user-ids.
373                         // We can now send mails to them...
374                         foreach ($RECEIVERS as $key => $uid) {
375                                 // Load personal data
376                                 //* DEBUG: */ echo "*L:".__LINE__."/".$uid."*<br />";
377                                 $result_user = SQL_QUERY_ESC("SELECT surname, family, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
378                                  array(bigintval($uid)), __FILE__, __LINE__);
379
380                                 // Is his data available?
381                                 if (SQL_NUMROWS($result_user) == 1)
382                                 {
383                                         // The final receiver does exists so we can continue...
384                                         list($sname, $fname, $email) = SQL_FETCHROW($result_user);
385                                         //* DEBUG: */ echo "OK!/L:".__LINE__."<br />";
386
387                                         // Mark this user as "spammed" ;-) And place a line for him...
388                                         if (REMOVE_RECEIVER($dummy, $key, $uid, $DATA['id'], $DATA['id'], true) == "done")
389                                         {
390                                                 // Replace text variables
391                                                 foreach ($REPLACER as $key => $value) {
392                                                         if (isset($DATA[$key])) $DATA['text'] = str_replace($value, $DATA[$key], $DATA['text']);
393                                                 } // END - foreach
394
395                                                 // Prepare content
396                                                 $content = array(
397                                                         'id'       => $DATA['id'],
398                                                         'url'      => $DATA['url'],
399                                                         'time'     => CREATE_FANCY_TIME($DATA['time']),
400                                                         'points'   => TRANSLATE_COMMA($DATA['points']),
401                                                         'category' => GET_CATEGORY($DATA['cat_id']),
402                                                         'text'     => $DATA['text']
403                                                 );
404
405                                                 // Prepare the mail
406                                                 $msg = LOAD_EMAIL_TEMPLATE("bonus-mail", $content, $uid);
407
408                                                 // Send mail away
409                                                 if (isset($DATA['html_msg'])) {
410                                                         // Send HTML?
411                                                         SEND_EMAIL($email, $DATA['subject'], $msg, $DATA['html_msg']);
412                                                 } else {
413                                                         // No HTML mail!
414                                                         SEND_EMAIL($email, $DATA['subject'], $msg);
415                                                 }
416
417                                                 // Count one up and remove entry from dummy array
418                                                 $cnt++; unset($dummy[$key]);
419
420                                                 if (GET_EXT_VERSION("user") >= "0.1.4")
421                                                 {
422                                                         // Update mails received for receiver
423                                                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET emails_received=emails_received+1 WHERE userid=%s LIMIT 1",
424                                                          array(bigintval($uid)), __FILE__, __LINE__);
425                                                 }
426
427                                                 // Do we have send maximum mails?
428                                                 if (($cnt >= $_CONFIG['max_send']) || (SELECTION_COUNT($dummy) == 0))
429                                                 {
430                                                         // Yes, we have
431                                                         //* DEBUG: */ echo "*EXIT/L:".__LINE__."<br />";
432                                                         break;
433                                                 }
434                                         }
435                                 }
436
437                                 // Free some memory
438                                 SQL_FREERESULT($result_user);
439                         }
440
441                         // Update mediadata if version is 0.0.4 or higher
442                         if (GET_EXT_VERSION("mediadata") >= "0.0.4")
443                         {
444                                 // Update entry (or add missing
445                                 $P = $cnt;
446                                 if (!empty($cnt2) && empty($cnt)) $P = $cnt2;
447                                 //* DEBUG: */ echo "+MEDIA/L:".__LINE__."/".$P."+<br />";
448                                 MEDIA_UPDATE_ENTRY(array("total_send", "bonus_send"), "add", $P);
449                         }
450
451                         // Close sending system
452                         //* DEBUG: */ echo "-L:".__LINE__."/".SELECTION_COUNT($dummy)."-<br />";
453                         if (SELECTION_COUNT($dummy) == 0)
454                         {
455                                 // Queue reached!
456                                 $result_done = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_bonus SET data_type='SEND', target_send='0', receivers='' WHERE id=%s LIMIT 1",
457                                  array(bigintval($DATA['id'])), __FILE__, __LINE__);
458                                 //* DEBUG: */ echo "*L:".__LINE__."*<br />";
459
460                                 // Update mediadata if version is 0.0.4 or higher
461                                 if (GET_EXT_VERSION("mediadata") >= "0.0.4")
462                                 {
463                                         // Update entry (or add missing)
464                                         //* DEBUG: */ echo "*MEDIA/L:".__LINE__."*<br />";
465                                         MEDIA_UPDATE_ENTRY(array("total_orders", "bonus_orders"), "add", 1);
466                                 }
467                         }
468                          elseif ($cnt >= $_CONFIG['max_send'])
469                         {
470                                 // Update bonus pool
471                                 $result_done = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_bonus SET data_type='NEW', target_send=%s, receivers='%s' WHERE id=%s LIMIT 1",
472                                  array(SELECTION_COUNT($dummy), implode(";", $dummy), bigintval($DATA['id'])), __FILE__, __LINE__);
473                                 //* DEBUG: */ echo "*L:".__LINE__."<PRE>";
474                                 //* DEBUG: */ print_r($dummy);
475                                 //* DEBUG: */ echo "</PRE>\n!!!<br />";
476                                 break;
477                         }
478                 }
479         }
480
481         // Free memory
482         SQL_FREERESULT($result_bonus);
483 }
484
485 // Remove message (IMPORTANT!)
486 unset($msg);
487
488 //
489 ?>