- }
- if (SQL_NUMROWS($result_mailid) == 1)
- {
- list($pool, $sender, $notify) = SQL_FETCHROW($result_mailid);
-
- // Correct notification switch in non-bonus mails
- if (($notify != "Y") && ($notify != "N")) $notify = "N";
-
- // Free some memory
- SQL_FREERESULT($result_mailid);
-
- // Set sender to 0 when we have a bonus mail
- if ($ltype == "BONUS") $sender = 0;
-
- // Is the user's ID unlocked?
- $result = SQL_QUERY_ESC("SELECT status, gender, surname, family, ref_payout FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
- array($url_uid), __FILE__, __LINE__);
- if (SQL_NUMROWS($result) == 1)
- {
- // Load data
- list($status, $gender, $sname, $fname, $ref_pay) = SQL_FETCHROW($result);
- SQL_FREERESULT($result);
-
- if ($status == "CONFIRMED")
- {
- // Update last activity
- $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET last_online=UNIX_TIMESTAMP(), last_module='mailid_top' WHERE userid=%s LIMIT 1",
- array($url_uid), __FILE__, __LINE__);
-
- // User has confirmed his account so we can procede...
- switch ($ltype)
- {
- case "NORMAL":
- $result = SQL_QUERY_ESC("SELECT payment_id FROM "._MYSQL_PREFIX."_user_stats WHERE pool_id=%s LIMIT 1",
- array(bigintval($pool)), __FILE__, __LINE__);
- if (SQL_NUMROWS($result) == 1)
- {
+
+ default: // Unknown type
+ debug_report_bug('Unknown mail type ' . $ltype . ' detected.');
+ break;
+ }
+
+ // Entry found?
+ if (SQL_NUMROWS($result_mailid) == 1) {
+ // Load data
+ list($pool, $sender, $notify) = SQL_FETCHROW($result_mailid);
+
+ // Correct notification switch in non-bonus mails
+ if (($notify != 'Y') && ($notify != 'N')) $notify = 'N';
+
+ // Free some memory
+ SQL_FREERESULT($result_mailid);
+
+ // Set sender to 0 when we have a bonus mail
+ if ($ltype == 'BONUS') $sender = '0';
+
+ // Is the user id valid?
+ if (fetchUserData($url_userid) === true) {
+ // Is the user status CONFIRMED?
+ if (getUserData('status') == 'CONFIRMED') {
+ // User has confirmed his account so we can procede...
+ // @TODO Rewrite this to a filter
+ switch ($ltype) {
+ case 'NORMAL':
+ $result = SQL_QUERY_ESC("SELECT `payment_id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
+ array(bigintval($pool)), __FILE__, __LINE__);
+
+ // Entry found?
+ if (SQL_NUMROWS($result) == 1) {