]> git.mxchange.org Git - mailer.git/blob - inc/pool-update.php
Fix for you-are-here navi
[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         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Don't run on daily reset
41 if (defined('__DAILY_RESET')) {
42         // Skip here
43         return false;
44 } // END - if
45
46 // Test html extensions once
47 $HTML_EXT = EXT_IS_ACTIVE("html_mail", true);
48
49 // Check for freed mail orders to send out
50 if ($HTML_EXT) {
51         //                                0     1        2      3       4          5            6      7        8          9       10
52         $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__);
53 } else {
54         //                                0     1        2      3       4          5            6      7        8          9    10
55         $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__);
56 }
57
58 // Reset variables
59 $cnt = 0; $cnt2 = 0; $LAST_SENT_ID = 0; $cnt_back = array("0"); $points_BACK = array("0");
60 if (SQL_NUMROWS($result_main) > 0)
61 {
62         while ($DATA = SQL_FETCHROW($result_main))
63         {
64                 // Check fetched data for HTML
65                 $HTML = $DATA[10]; if ($HTML == $DATA['id']) $HTML = "N";
66
67                 // Compile URL and subject line
68                 $DATA[7] = COMPILE_CODE($DATA[7]);
69
70                 // Set mail order as "active". That means it will be sent out
71                 $result_active = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET data_type='ACTIVE' WHERE id=%s AND data_type='NEW' LIMIT 1",
72                  array($DATA['id']), __FILE__, __LINE__);
73                 if (SQL_AFFECTEDROWS() == 1)
74                 {
75                         // "Explode" all receivers into an array
76                         if (ereg(";", $DATA[4]))
77                         {
78                                 // There's more than one receiver in the list...
79                                 $RECEIVERS = explode(";", $DATA[4]);
80                         }
81                          elseif (!empty($DATA[4]))
82                         {
83                                 // Only one user left
84                                 $RECEIVERS = array($DATA[4]);
85                         }
86                          else
87                         {
88                                 // No users left
89                                 $RECEIVERS = array("0");
90                         }
91                         $dummy = $RECEIVERS;
92
93                         // Now, if we are good little boys and girls Santa left us some user-ids.
94                         // We can now send mails to them...
95                         foreach ($RECEIVERS as $key => $uid)
96                         {
97                                 // Lookup user ID
98                                 $result_user = SQL_QUERY_ESC("SELECT gender, surname, family, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
99                                  array(bigintval($uid)), __FILE__, __LINE__);
100
101                                 // Is his data available?
102                                 //* DEBUG: */ echo "*L:".__LINE__."/".SQL_NUMROWS($result_user)."*<br />";
103                                 if (SQL_NUMROWS($result_user) == 1)
104                                 {
105                                         // The final receiver does exists so we can continue...
106                                         list($gender, $sname, $fname, $email) = SQL_FETCHROW($result_user);
107
108                                         // Free memory
109                                         SQL_FREERESULT($result_user);
110
111                                         // Do we have a stats entry?
112                                         $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",
113                                          array($DATA['id'], $DATA[1], $DATA[6]), __FILE__, __LINE__);
114
115                                         // If there's no stats entry add it!
116                                         //* DEBUG: */ echo "!L:".__LINE__."/".SQL_NUMROWS($result_stats)."!<br />";
117                                         if (SQL_NUMROWS($result_stats) == 0)
118                                         {
119                                                 // No entry was found, so we add him!
120                                                 $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())",
121                                                  array(bigintval($DATA['id']), bigintval($DATA[1]), bigintval($DATA[9]), bigintval($DATA[5]), $DATA[2], $DATA[7], $DATA[8], bigintval($DATA[6])), __FILE__, __LINE__);
122
123                                                 // Receive it's ID for the links table
124                                                 $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",
125                                                  array(bigintval($DATA['id']), bigintval($DATA[1]), bigintval($DATA[6])), __FILE__, __LINE__);
126                                         }
127
128                                         //* DEBUG: */ echo "!L:".__LINE__."/".SQL_NUMROWS($result_stats)."!<br />";
129                                         if (SQL_NUMROWS($result_stats) == 1)
130                                         {
131                                                 // We got one!
132                                                 list($stats_id) = SQL_FETCHROW($result_stats);
133                                                 SQL_FREERESULT($result_stats);
134
135                                                 // Mark this user as "spammed" ;-) And place a line for him...
136                                                 //* DEBUG: */ echo "?L:".__LINE__."/".$dummy."/".$key."/".$uid."(".$DATA[1].")/".$DATA['id']."/".$stats_id."?<br />";
137                                                 switch (REMOVE_RECEIVER($dummy, $key, bigintval($uid), bigintval($DATA['id']), bigintval($stats_id)))
138                                                 {
139                                                 case "done":
140                                                         // Prepare the mail
141                                                         $DATA[11] = bigintval($stats_id);
142                                                         $DATA[12] = $sname;
143                                                         $DATA[13] = $fname;
144                                                         $DATA[14] = TRANSLATE_GENDER($gender);
145
146                                                         // Replace text variables
147                                                         foreach ($REPLACER as $key => $value) {
148                                                                 if (isset($DATA[$key])) $DATA[3] = str_replace($value, $DATA[$key], $DATA[3]);
149                                                         } // END - if
150
151                                                         // Prepare content
152                                                         $content = array(
153                                                                 'id'         => $DATA[11],
154                                                                 'url'        => $DATA[3],
155                                                                 'sender_uid' => $DATA[1],
156                                                                 'category'   => GET_CATEGORY($DATA[9]),
157                                                                 'time'       => CREATE_FANCY_TIME(GET_PAY_POINTS($DATA[5], "time")),
158                                                                 'points'     => TRANSLATE_COMMA(GET_PAY_POINTS($DATA[5], "payment")),
159                                                                 'text'       => $DATA[3]
160                                                         );
161
162                                                         // Load message template
163                                                         $msg = LOAD_EMAIL_TEMPLATE("normal-mail", $content, bigintval($uid));
164
165                                                         // Send mail away
166                                                         SEND_EMAIL($email, $DATA[2], $msg, $HTML);
167
168                                                         // Count sent mails...
169                                                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET emails_sent=emails_sent+1 WHERE userid=%s LIMIT 1",
170                                                          array(bigintval($DATA[1])), __FILE__, __LINE__);
171
172                                                         if (GET_EXT_VERSION("user") >= "0.1.4") {
173                                                                 // Update mails received for receiver
174                                                                 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET emails_received=emails_received+1 WHERE userid=%s LIMIT 1",
175                                                                 array(bigintval($uid)), __FILE__, __LINE__);
176                                                         } // END - if
177
178                                                         // Update mediadata if version is 0.0.4 or higher
179                                                         if (GET_EXT_VERSION("mediadata") >= "0.0.4") {
180                                                                 // Update entry (or add missing)
181                                                                 //* DEBUG: */ echo "*MEDIA/L:".__LINE__."*<br />";
182                                                                 MEDIA_UPDATE_ENTRY(array("total_send", "normal_send"), "add", 1);
183                                                         } // END - if
184
185                                                         // And count up the mail
186                                                         $cnt++;
187                                                         //* DEBUG: */ echo"*EXIT/L:".__LINE__."/".$cnt."*<br />";
188                                                         break;
189
190                                                 case "already":
191                                                         // Entry already found, but we still count one up!
192                                                         $cnt++;
193                                                         //* DEBUG: */ echo"*EXIT/L:".__LINE__."/".$cnt."<br />";
194                                                         break;
195                                                 }
196                                         }
197
198                                         // Do we have reached the maximum to send mails? || ($_CONFIG['max_send'] >= $cnt)
199                                         //* DEBUG: */ echo "*L:".__LINE__."/".$cnt.">=".$DATA[8]."/".$_CONFIG['max_send'].">=".$cnt."/".$LAST_SENT_ID."!=".$DATA['id']."*<br />";
200                                         if ((($cnt >= $DATA[8])) && ($LAST_SENT_ID != $DATA['id'])) {
201                                                 // Prepare content
202                                                 $content = array(
203                                                         'sender_uid' => $DATA[1],
204                                                         'category'   => GET_CATEGORY($DATA[9])
205                                                 );
206
207                                                 // Yes we do, so we notify admin and sender about fully sent mail!
208                                                 SEND_ADMIN_NOTIFICATION(ADMIN_SUBJ_SEND_DONE, "done-admin", $content, $uid);
209
210                                                 // Get sender's data
211                                                 $result_sender = SQL_QUERY_ESC("SELECT surname, family, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
212                                                  array(bigintval($DATA[1])), __FILE__, __LINE__);
213                                                 if (SQL_NUMROWS($result_sender) == 1) {
214                                                         // Load data and prepare mail
215                                                         list($sname, $fname, $email) = SQL_FETCHROW($result_sender);
216                                                         SQL_FREERESULT($result_sender);
217
218                                                         // Load email template
219                                                         $msg = LOAD_EMAIL_TEMPLATE("done-member", $content, $DATA[1]);
220
221                                                         // Send it also waway
222                                                         SEND_EMAIL($email, MEMBER_SUBJ_SEND_DONE, $msg);
223                                                 }
224
225                                                 // Set status to SEND because we completely send it away
226                                                 $result_done = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET data_type='SEND', target_send='0', receivers='' WHERE id=%s LIMIT 1",
227                                                  array(bigintval($DATA['id'])), __FILE__, __LINE__);
228
229                                                 // Update send-completed-time
230                                                 $result_user = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_stats SET timestamp_send=UNIX_TIMESTAMP() WHERE pool_id=%s LIMIT 1",
231                                                  array(bigintval($DATA['id'])), __FILE__, __LINE__);
232
233                                                 $LAST_SENT_ID = $DATA['id']; $cnt = 0;
234                                                 $cnt2 += $cnt;
235
236                                                 // Update mediadata if version is 0.0.4 or higher
237                                                 if (GET_EXT_VERSION("mediadata") >= "0.0.4")
238                                                 {
239                                                         // Update entry (or add missing)
240                                                         //* DEBUG: */ echo "*MEDIA/L:".__LINE__."*<br />";
241                                                         MEDIA_UPDATE_ENTRY(array("total_orders", "normal_orders"), "add", 1);
242                                                 }
243
244                                                 //* DEBUG: */ echo"*EXIT/L:".__LINE__."/".$P."<br />";
245                                                 break;
246                                         }
247                                         // Do we have send maximum mails?
248                                          elseif (($cnt >= $_CONFIG['max_send']) || ($cnt2 >= $_CONFIG['max_send']))
249                                         {
250                                                 // There are some mails left to send for next round, so we reset the status back to NEW (=still not fully delivered)
251                                                 $ADD = "";
252                                                 if ($cnt <= $DATA[8]) $ADD = ", target_send=target_send-".$cnt;
253                                                 $result_queue = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET data_type='NEW', receivers='%s'".$ADD." WHERE id=%s LIMIT 1",
254                                                  array(implode(";", $dummy), bigintval($DATA['id'])), __FILE__, __LINE__);
255
256                                                 //* DEBUG: */ echo"*EXIT/L:".__LINE__."*<br />";
257                                                 break;
258                                         }
259                                 }
260                                  else
261                                 {
262                                         // User does not exists so we have add the sender's points back to sender's account
263                                         if (($RECEIVERS[0] == "0") || (empty($RECEIVERS[0])))
264                                         {
265                                                 // List was empty
266                                                 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET data_type='SEND' WHERE id=%s LIMIT 1",
267                                                  array(bigintval($DATA['id'])), __FILE__, __LINE__);
268                                         }
269                                          else
270                                         {
271                                                 if ($uid > 0)
272                                                 {
273                                                         // User does not exists, pay points back
274                                                         $points = GET_PAY_POINTS($DATA[5]);
275                                                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_points SET points=points+%s WHERE userid=%s AND ref_depth=0 LIMIT 1",
276                                                          array($points, bigintval($DATA[1])), __FILE__, __LINE__);
277
278                                                         // Update mediadata as well
279                                                         if (GET_EXT_VERSION("mediadata") >= "0.0.4")
280                                                         {
281                                                                 // Update database
282                                                                 //* DEBUG: */ echo "*MEDIA/L:".__LINE__."/".$points."*<br />";
283                                                                 MEDIA_UPDATE_ENTRY(array("total_points"), "add", $points);
284                                                         }
285
286                                                         // Add points together and remove user
287                                                         $points_BACK[$DATA[1]] += $points;
288                                                 }
289                                                 $cnt_back[$DATA[1]]++;
290                                         }
291                                         // Remove entry from list
292                                         unset($dummy[$key]);
293
294                                         // Update receivers
295                                         $result_queue = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET receivers='%s' WHERE id=%s LIMIT 1",
296                                          array(implode(";", $dummy), bigintval($DATA['id'])), __FILE__, __LINE__);
297                                 }
298                         }
299                 }
300         }
301         if ((sizeof($points_BACK) > 0) && (!empty($points_BACK[0]))) {
302                 foreach ($points_BACK as $uid => $PB) {
303                         // Add points only when we have points left to add and a valid user ID
304                         if (($PB > 0) && ($uid > 0)) {
305                                 // Prepare content
306                                 $content = array(
307                                         'points' => TRANSLATE_COMMA($DATA[10])
308                                 );
309
310                                 // We have to pay back some points to the sender (we add them directly :-P)
311                                 $result = SQL_QUERY_ESC("SELECT email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s AND status='CONFIRMED' LIMIT 1",
312                                         array(bigintval($uid)), __FILE__, __LINE__);
313                                 $DATA[10] = $PB; $DATA[11] = $cnt_back[$uid];
314                                 if (SQL_NUMROWS($result) == 1) {
315                                         list($email) = SQL_FETCHROW($result);
316                                         SQL_FREERESULT($result);
317
318                                         // User account does exists, so we can safely pay back!
319                                         $msg = LOAD_EMAIL_TEMPLATE("back-member", $content, bigintval($uid));
320
321                                         // Send mail out to member
322                                         SEND_EMAIL($email, MEMBER_BACK_JACKPOT." (".$uid.")", $msg);
323                                 } else {
324                                         // Add to jackpot
325                                         ADD_JACKPOT($PB);
326
327                                         // Send mail out to admin
328                                         SEND_ADMIN_NOTIFICATION(ADMIN_BACK_JACKPOT." (".$uid.")", "back-admin", $content, "admin");
329                                 }
330                         }
331                 }
332         }
333 }
334
335 // Free memory
336 SQL_FREERESULT($result_main);
337
338 // Only send bonus mail when bonus extension is active and maximum send-mails is not reached
339 if ((EXT_IS_ACTIVE("bonus") && ($cnt < $_CONFIG['max_send'])))
340 {
341         // Do we need to send out bonus mails?
342         if ($HTML_EXT) {
343                 //                                 0     1       2        3        4      5       6          7       8      9         10         11
344                 $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__);
345         } else {
346                 //                                 0     1       2        3        4      5       6          7       8      9         10
347                 $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__);
348         }
349
350         if (SQL_NUMROWS($result_bonus) > 0) {
351                 // Send these mails away...
352                 $cnt2 = "";
353                 while ($DATA = SQL_FETCHARRAY($result_bonus)) {
354                         // Compile URL
355                         $DATA['url'] = COMPILE_CODE($DATA['url']);
356
357                         // Message is active in queue
358                         $result_queue = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_bonus SET data_type='QUEUE' WHERE id=%s LIMIT 1",
359                          array(bigintval($DATA['id'])), __FILE__, __LINE__);
360
361                         // "Explode" all receivers into an array
362                         if (ereg(";", $DATA['receivers'])) {
363                                 // There's more than one receiver in the list...
364                                 $RECEIVERS = explode(";", $DATA['receivers']);
365                         } elseif (!empty($DATA['points'])) {
366                                 // Only one user left
367                                 $RECEIVERS = array($DATA['receivers']);
368                         } else {
369                                 // No users left
370                                 $RECEIVERS = array("0");
371                         }
372                         $dummy = $RECEIVERS;
373
374                         // Now, if we are good little boys and girls Santa left us some user-ids.
375                         // We can now send mails to them...
376                         foreach ($RECEIVERS as $key => $uid) {
377                                 // Load personal data
378                                 //* DEBUG: */ echo "*L:".__LINE__."/".$uid."*<br />";
379                                 $result_user = SQL_QUERY_ESC("SELECT surname, family, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
380                                  array(bigintval($uid)), __FILE__, __LINE__);
381
382                                 // Is his data available?
383                                 if (SQL_NUMROWS($result_user) == 1)
384                                 {
385                                         // The final receiver does exists so we can continue...
386                                         list($sname, $fname, $email) = SQL_FETCHROW($result_user);
387                                         //* DEBUG: */ echo "OK!/L:".__LINE__."<br />";
388
389                                         // Mark this user as "spammed" ;-) And place a line for him...
390                                         if (REMOVE_RECEIVER($dummy, $key, $uid, $DATA['id'], $DATA['id'], true) == "done")
391                                         {
392                                                 // Replace text variables
393                                                 foreach ($REPLACER as $key => $value) {
394                                                         if (isset($DATA[$key])) $DATA['text'] = str_replace($value, $DATA[$key], $DATA['text']);
395                                                 } // END - foreach
396
397                                                 // Prepare content
398                                                 $content = array(
399                                                         'id'       => $DATA['id'],
400                                                         'url'      => $DATA['url'],
401                                                         'time'     => CREATE_FANCY_TIME($DATA['time']),
402                                                         'points'   => TRANSLATE_COMMA($DATA['points']),
403                                                         'category' => GET_CATEGORY($DATA['cat_id']),
404                                                         'text'     => $DATA['text']
405                                                 );
406
407                                                 // Prepare the mail
408                                                 $msg = LOAD_EMAIL_TEMPLATE("bonus-mail", $content, $uid);
409
410                                                 // Send mail away
411                                                 if (isset($DATA['html_msg'])) {
412                                                         // Send HTML?
413                                                         SEND_EMAIL($email, $DATA['subject'], $msg, $DATA['html_msg']);
414                                                 } else {
415                                                         // No HTML mail!
416                                                         SEND_EMAIL($email, $DATA['subject'], $msg);
417                                                 }
418
419                                                 // Count one up and remove entry from dummy array
420                                                 $cnt++; unset($dummy[$key]);
421
422                                                 if (GET_EXT_VERSION("user") >= "0.1.4")
423                                                 {
424                                                         // Update mails received for receiver
425                                                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET emails_received=emails_received+1 WHERE userid=%s LIMIT 1",
426                                                          array(bigintval($uid)), __FILE__, __LINE__);
427                                                 }
428
429                                                 // Do we have send maximum mails?
430                                                 if (($cnt >= $_CONFIG['max_send']) || (SELECTION_COUNT($dummy) == 0))
431                                                 {
432                                                         // Yes, we have
433                                                         //* DEBUG: */ echo "*EXIT/L:".__LINE__."<br />";
434                                                         break;
435                                                 }
436                                         }
437                                 }
438
439                                 // Free some memory
440                                 SQL_FREERESULT($result_user);
441                         }
442
443                         // Update mediadata if version is 0.0.4 or higher
444                         if (GET_EXT_VERSION("mediadata") >= "0.0.4")
445                         {
446                                 // Update entry (or add missing
447                                 $P = $cnt;
448                                 if (!empty($cnt2) && empty($cnt)) $P = $cnt2;
449                                 //* DEBUG: */ echo "+MEDIA/L:".__LINE__."/".$P."+<br />";
450                                 MEDIA_UPDATE_ENTRY(array("total_send", "bonus_send"), "add", $P);
451                         }
452
453                         // Close sending system
454                         //* DEBUG: */ echo "-L:".__LINE__."/".SELECTION_COUNT($dummy)."-<br />";
455                         if (SELECTION_COUNT($dummy) == 0)
456                         {
457                                 // Queue reached!
458                                 $result_done = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_bonus SET data_type='SEND', target_send='0', receivers='' WHERE id=%s LIMIT 1",
459                                  array(bigintval($DATA['id'])), __FILE__, __LINE__);
460                                 //* DEBUG: */ echo "*L:".__LINE__."*<br />";
461
462                                 // Update mediadata if version is 0.0.4 or higher
463                                 if (GET_EXT_VERSION("mediadata") >= "0.0.4")
464                                 {
465                                         // Update entry (or add missing)
466                                         //* DEBUG: */ echo "*MEDIA/L:".__LINE__."*<br />";
467                                         MEDIA_UPDATE_ENTRY(array("total_orders", "bonus_orders"), "add", 1);
468                                 }
469                         }
470                          elseif ($cnt >= $_CONFIG['max_send'])
471                         {
472                                 // Update bonus pool
473                                 $result_done = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_bonus SET data_type='NEW', target_send=%s, receivers='%s' WHERE id=%s LIMIT 1",
474                                  array(SELECTION_COUNT($dummy), implode(";", $dummy), bigintval($DATA['id'])), __FILE__, __LINE__);
475                                 //* DEBUG: */ echo "*L:".__LINE__."<PRE>";
476                                 //* DEBUG: */ print_r($dummy);
477                                 //* DEBUG: */ echo "</PRE>\n!!!<br />";
478                                 break;
479                         }
480                 }
481         }
482
483         // Free memory
484         SQL_FREERESULT($result_bonus);
485 }
486
487 // Remove message (IMPORTANT!)
488 unset($msg);
489
490 //
491 ?>