- // 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'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);
-
- // Free some memory
- SQL_FREERESULT($result);
-
- if ($status == 'CONFIRMED') {
- // Update last activity
- 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__);
-
- // Entry found?
- if (SQL_NUMROWS($result) == 1) {
- list($pay) = SQL_FETCHROW($result);
- $time = getPaymentPoints($pay, 'time');
- $payment = getPaymentPoints($pay, 'payment');
- $isValid = true;
- } // END - if
-
- // Free memory...
- SQL_FREERESULT($result);
- break;
-
- case 'BONUS':
- $result = SQL_QUERY_ESC("SELECT time, points FROM `{!_MYSQL_PREFIX!}_bonus` WHERE `id`=%s LIMIT 1",
- array(bigintval($pool)), __FILE__, __LINE__);
-
- // Entry found?
- if (SQL_NUMROWS($result) == 1) {
- list($time, $payment) = SQL_FETCHROW($result);
- $isValid = true;
- }
-
- // Free memory...
- SQL_FREERESULT($result);
- break;
- }
+ // Is an entry found?
+ if (SQL_NUMROWS($result_main) == 1) {
+ // Is the stats id valid?
+ $data = SQL_FETCHARRAY($result_main);
+
+ // Init result here with invalid to avoid possible missing variable
+ $result_mailid = FALSE;
+
+ // @TODO Rewrite this to a filter/function
+ switch ($data['link_type']) {
+ case 'NORMAL':
+ $result_mailid = SQL_QUERY_ESC("SELECT `pool_id`, `userid` AS `sender` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `id`=%s LIMIT 1",
+ array($urlId), __FILE__, __LINE__);
+ break;
+
+ case 'BONUS':
+ $result_mailid = SQL_QUERY_ESC("SELECT `id` AS `pool_id`, `is_notify` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
+ array($urlId), __FILE__, __LINE__);
+ break;
+
+ default: // Unknown type
+ reportBug(__FILE__, __LINE__, 'Unknown mail type ' . $data['link_type'] . ' detected.');
+ break;
+ } // END - switch
+
+ // Entry found?
+ if (SQL_NUMROWS($result_mailid) == 1) {
+ // Load data
+ $data = merge_array($data, SQL_FETCHARRAY($result_mailid));
+
+ // Correct notification switch in non-bonus mails
+ if ((!isset($data['is_notify'])) || (!in_array($data['is_notify'], array('Y', 'N')))) {
+ $data['is_notify'] = 'N';
+ } // END - if
+
+ // Set sender to 0 when we have a bonus mail
+ if ($data['link_type'] == 'BONUS') {
+ $data['sender'] = NULL;
+ } // END - if
+
+ // Is the user id valid?
+ if (fetchUserData($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 ($data['link_type']) {
+ case 'NORMAL':
+ $result = SQL_QUERY_ESC("SELECT `payment_id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
+ array(bigintval($data['pool_id'])), __FILE__, __LINE__);
+
+ // Entry found?
+ if (SQL_NUMROWS($result) == 1) {
+ list($paymentId) = SQL_FETCHROW($result);
+ $time = getPaymentData($paymentId, 'time');
+ $payment = getPaymentData($paymentId, 'payment');
+ $isValid = TRUE;
+ } // END - if
+
+ // Free memory...
+ SQL_FREERESULT($result);
+ break;
+
+ case 'BONUS':
+ $result = SQL_QUERY_ESC("SELECT `time`, `points` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
+ array(bigintval($data['pool_id'])), __FILE__, __LINE__);
+
+ // Entry found?
+ if (SQL_NUMROWS($result) == 1) {
+ list($time, $payment) = SQL_FETCHROW($result);
+ $isValid = TRUE;
+ } // END - if
+
+ // Free memory...
+ SQL_FREERESULT($result);
+ break;
+
+ default: // Unknown type
+ reportBug(__FILE__, __LINE__, 'Unknown mail type ' . $data['link_type'] . ' detected.');
+ break;
+ } // END - switch
+
+ // Is this entry valid?
+ if ($isValid === TRUE) {
+ // Run at least one second
+ if (($time == '0') && ($payment > 0)) $time = 1;
+
+ // Is time and payment set?
+ if (($time > 0) && ($payment > 0)) {
+ $realCode = '0';
+ if (!empty($code)) {
+ // Generate code (the user sees in the CAPTCHA)
+ $realCode = generateRandomCode(getCodeLength(), $code, $userId, $urlId);
+ } // END - if
+
+ // @TODO Rewrite this to a filter
+ switch ($do) {
+ case 'add':
+ // Init stats data
+ $stats_data = '0';
+
+ // Count clicks
+ // @TODO Rewrite this to a filter
+ switch ($data['link_type']) {
+ case 'NORMAL':
+ SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_stats` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
+ array($mailId), __FILE__, __LINE__);
+
+ // Update mediadata as well
+ if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
+ // Update database
+ updateMediadataEntry(array('total_clicks', 'normal_clicks'), 'add', 1);
+ } // END - if
+ $stats_data = $mailId;
+ break;