- if ($mailId > 0) {
- // Member mail
- $result_link = SQL_QUERY_ESC("SELECT `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s AND `userid`=%s LIMIT 1",
- array($mailId, $userId), __FILE__, __LINE__);
- $type = 'mailid';
- $urlId = $mailId;
- } elseif ($bonusId > 0) {
- // Bonus mail
- $result_link = SQL_QUERY_ESC("SELECT `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s AND `userid`=%s LIMIT 1",
- array($bonusId, $userId), __FILE__, __LINE__);
- $type = 'bonusid';
- $urlId = $bonusId;
- } else {
- // Problem: No id entered
- redirectToUrl('modules.php?module=index');
- }
-
- if (SQL_NUMROWS($result_link) == 1) {
- // Load the entry
- list($ltype) = SQL_FETCHROW($result_link);
-
- // @TODO Rewrite this to a filter
- switch ($ltype) {
+ switch ($data['type']) {
+ case 'normal':
+ $result_main = sqlQueryEscaped("SELECT `id` AS `link_id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s AND `userid`=%s LIMIT 1",
+ array($data['id'], $data['userid']), __FILE__, __LINE__);
+ break;
+
+ case 'bonus':
+ $result_main = sqlQueryEscaped("SELECT `id` AS `link_id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s AND `userid`=%s LIMIT 1",
+ array($data['id'], $data['userid']), __FILE__, __LINE__);
+ break;
+
+ default: // Not detected
+ reportBug(__FILE__, __LINE__, 'No valid type=' . $data['type'] . ' set.');
+ break;
+ } // END - switch
+
+ // Is an entry found?
+ if (sqlNumRows($result_main) == 1) {
+ // Is the stats id valid?
+ $data = merge_array($data, sqlFetchArray($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']) {