+
+ // Calculcate target sent
+ $target = countSelection(explode(';', $receiverList));
+
+ // Receiver is zero?
+ if ($receiver == 0) {
+ // Then auto-fix it
+ $receiver = $target;
+ } // END - if
+
+ // HTML extension active?
+ if (EXT_IS_ACTIVE('html_mail')) {
+ // No HTML by default
+ $HTML = 'N';
+
+ // HTML mode?
+ if ($mode == 'html') $HTML = 'Y';
+
+ // Add HTML mail
+ SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_bonus`
+(subject, text, receivers, points, time, data_type, timestamp, url, cat_id, target_send, mails_sent, html_msg)
+VALUES ('%s','%s','%s','%s','%s','NEW', UNIX_TIMESTAMP(),'%s','%s','%s','%s','%s')",
+ array(
+ $subject,
+ $text,
+ $receiverList,
+ $points,
+ $seconds,
+ $url,
+ $cat,
+ $target,
+ bigintval($receiver),
+ $HTML
+ ), __FUNCTION__, __LINE__);
+ } else {
+ // Add regular mail
+ SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_bonus`
+(subject, text, receivers, points, time, data_type, timestamp, url, cat_id, target_send, mails_sent)
+VALUES ('%s','%s','%s','%s','%s','NEW', UNIX_TIMESTAMP(),'%s','%s','%s','%s')",
+ array(
+ $subject,
+ $text,
+ $receiverList,
+ $points,
+ $seconds,
+ $url,
+ $cat,
+ $target,
+ bigintval($receiver),
+ ), __FUNCTION__, __LINE__);
+ }
+}
+
+// Generate a receiver list for given category and maximum receivers
+function generateReceiverList ($cat, $receiver, $mode = '') {
+ // Init variables
+ $CAT_TABS = "%s";
+ $CAT_WHERE = '';
+ $receiverList = '';
+ $result = false;
+
+ // Secure data
+ $cat = bigintval($cat);
+ $receiver = bigintval($receiver);
+
+ // Is the receiver zero and mode set?
+ if (($receiver == 0) && (!empty($mode))) {
+ // Auto-fix receiver maximum
+ $receiver = getTotalReceivers($mode);
+ } // END - if
+
+ // Category given?
+ if ($cat > 0) {
+ // Select category
+ $CAT_TABS = "LEFT JOIN `{!_MYSQL_PREFIX!}_user_cats` AS c ON d.userid=c.userid";
+ $CAT_WHERE = " AND c.cat_id=%s";
+ } // END - if
+
+ // Exclude users in holiday?
+ if (GET_EXT_VERSION('holiday') >= '0.1.3') {
+ // Add something for the holiday extension
+ $CAT_WHERE .= " AND d.`holiday_active`='N'";
+ } // END - if
+
+ if ((EXT_IS_ACTIVE('html_mail')) && ($mode == 'html')) {
+ // Only include HTML receivers
+ $result = SQL_QUERY_ESC("SELECT d.userid FROM `{!_MYSQL_PREFIX!}_user_data` AS d ".$CAT_TABS." WHERE d.`status`='CONFIRMED' AND d.`html`='Y'".$CAT_WHERE." ORDER BY d.%s %s LIMIT %s",
+ array($cat, getConfig('order_select'), getConfig('order_mode'), $receiver), __FUNCTION__, __LINE__);
+ } else {
+ // Include all
+ $result = SQL_QUERY_ESC("SELECT d.userid FROM `{!_MYSQL_PREFIX!}_user_data` AS d ".$CAT_TABS." WHERE d.`status`='CONFIRMED'".$CAT_WHERE." ORDER BY d.%s %s LIMIT %s",
+ array($cat, getConfig('order_select'), getConfig('order_mode'), $receiver), __FUNCTION__, __LINE__);
+ }
+
+ // Entries found?
+ if ((SQL_NUMROWS($result) >= $receiver) && ($receiver > 0)) {
+ // Load all entries
+ while ($content = SQL_FETCHARRAY($result)) {
+ // Add receiver when not empty
+ if (!empty($content['userid'])) $receiverList .= $content['userid'] . ';';
+ } // END - while