Hotfix
[mailer.git] / mailid_top.php
index cf0ec430c2162794333a642b0241cdcb3bc7e759..282cb6fd19f34b45d4d390453d11c51f7be17deb 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 11/14/2003 *
- * ===============                              Last change: 11/13/2004 *
+ * Mailer v0.2.1-FINAL                                Start: 11/14/2003 *
+ * ===================                          Last change: 11/13/2004 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : mailid_top.php                                   *
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Bestaetigung von Mails                           *
  * -------------------------------------------------------------------- *
- *                                                                      *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author::                                                          $ *
+ * -------------------------------------------------------------------- *
+ * @TODO Merge this script with mailid.php                              *
  * -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder                           *
- * For more information visit: http://www.mxchange.org                  *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
+ * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
  * it under the terms of the GNU General Public License as published by *
  * MA  02110-1301  USA                                                  *
  ************************************************************************/
 
-// Load security stuff here (Oh, I hope this is not unsecure? Am I paranoia??? ;-) )
-require("inc/libs/security_functions.php");
+// Load security stuff here
+require('inc/libs/security_functions.php');
 
-// Init "action" and "what"
-global $what, $action;
-$GLOBALS['what'] = ""; $GLOBALS['action'] = "";
+// Init start time
+$GLOBALS['startTime'] = microtime(true);
 
 // Tell everyone we are in this module
-$GLOBALS['module'] = "mailid";  $CSS = 0;
+$GLOBALS['module'] = 'mailid';
+$GLOBALS['output_mode'] = -1;
 
 // Load the required file(s)
-require("inc/config.php");
+require('inc/config-global.php');
+
+// Set content type and HTTP status
+setContentType('text/html');
+setHttpStatus('404 NOT FOUND');
+
+// Is the extension mailid active?
+redirectOnUninstalledExtension('mailid');
+
+// Is the extension other active?
+redirectOnUninstalledExtension('other');
+
+// Init variables
+$userId = '0';
+$bonusId = '0';
+$mailId = '0';
+$code = '0';
+$do = '';
+
+// Secure all data
+if (isGetRequestElementSet('userid'))  $userId  = bigintval(getRequestElement('userid'));
+if (isGetRequestElementSet('mailid'))  $mailId  = bigintval(getRequestElement('mailid'));
+if (isGetRequestElementSet('bonusid')) $bonusId = bigintval(getRequestElement('bonusid'));
+if (isGetRequestElementSet('code'))    $code    = bigintval(getRequestElement('code'));
+if (isGetRequestElementSet('do'))      $do      = getRequestElement('do');
+
+// 01             2       21    12           2    2            21    1                      2210
+if ((isValidUserId($userId)) && (($mailId > 0) || ($bonusId > 0)) && (!ifFatalErrorsDetected())) {
+       // No image?
+       if ($do != 'img') {
+               // ... then output header
+               loadIncludeOnce('inc/header.php');
+       } // END - fi
+
+       // Maybe he wants to confirm an email?
+       if ($mailId > 0) {
+               $result_main = SQL_QUERY_ESC("SELECT `id`,`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) {
+               $result_main = SQL_QUERY_ESC("SELECT `id`,`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;
+       }
 
-if (isBooleanConstantAndTrue('mxchange_installed')) {
-       // Is the extension active
-       if (!EXT_IS_ACTIVE("mailid", true)) {
-               // Is not activated/installed yet!
-               addFatalMessage(sprintf(EXTENSION_PROBLEM_NOT_INSTALLED, "mailid"));
-       } // END - if
+       if (SQL_NUMROWS($result_main) == 1) {
+               // Is the stats id valid?
+               list($lid, $ltype) = SQL_FETCHROW($result_main);
 
-       // Secure all data
-       $url_uid = 0; $url_bid = 0; $url_mid = 0; $code = 0; $mode = "";
-       if (!empty($_GET['uid']))     $url_uid = bigintval($_GET['uid']);
-       if (!empty($_GET['mailid']))  $url_mid = bigintval($_GET['mailid']);
-       if (!empty($_GET['bonusid'])) $url_bid = bigintval($_GET['bonusid']);
-       if (!empty($_GET['code']))    $code    = bigintval($_GET['code']);
-       if (!empty($_GET['mode']))    $mode    = $_GET['mode'];
-
-       // 01        1        12            2    2            21    1                   22     10
-       if (($url_uid) > 0 && (($url_mid > 0) || ($url_bid > 0)) && (getTotalFatalErrors() == 0)) {
-               // No image? Then output header
-               if ($mode != "img") LOAD_INC_ONCE("inc/header.php");
-
-               // Maybe he wants to confirm an email?
-               if ($url_mid > 0) {
-                       $result = SQL_QUERY_ESC("SELECT id, link_type FROM `{!_MYSQL_PREFIX!}_user_links` WHERE stats_id=%s AND userid=%s LIMIT 1",
-                        array($url_mid, $url_uid), __FILE__, __LINE__);
-                       $type = "mailid"; $DATA = $url_mid;
-               } elseif ($url_bid > 0)         {
-                       $result = SQL_QUERY_ESC("SELECT id, link_type FROM `{!_MYSQL_PREFIX!}_user_links` WHERE bonus_id=%s AND userid=%s LIMIT 1",
-                        array($url_bid, $url_uid), __FILE__, __LINE__);
-                       $type = "bonusid"; $DATA = $url_bid;
-               }
+               // Init result here with invalid to avoid possible missing variable
+               $result_mailid = false;
 
-               if (SQL_NUMROWS($result) == 1) {
-                       // Is the stats ID valid?
-                       list($lid, $ltype) = SQL_FETCHROW($result);
-                       SQL_FREERESULT($result);
-                       switch ($ltype)
-                       {
-                       case "NORMAL":
-                               $result_mailid = SQL_QUERY_ESC("SELECT pool_id, userid, id FROM `{!_MYSQL_PREFIX!}_user_stats` WHERE id=%s LIMIT 1",
-                                       array($url_mid), __FILE__, __LINE__);
+               // @TODO Rewrite this to a filter
+               switch ($ltype) {
+                       case 'NORMAL':
+                               $result_mailid = SQL_QUERY_ESC("SELECT `pool_id`,`userid`,`id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `id`=%s LIMIT 1",
+                                       array($mailId), __FILE__, __LINE__);
                                break;
 
-                       case "BONUS":
-                               $result_mailid = SQL_QUERY_ESC("SELECT id, id, is_notify FROM `{!_MYSQL_PREFIX!}_bonus` WHERE id=%s LIMIT 1",
-                                       array($url_bid), __FILE__, __LINE__);
+                       case 'BONUS':
+                               $result_mailid = SQL_QUERY_ESC("SELECT `id`,`id`,`is_notify` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
+                                       array($bonusId), __FILE__, __LINE__);
                                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'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__);
+                       default: // Unknown type
+                               debug_report_bug(__FILE__, __LINE__, 'Unknown mail type ' . $ltype . ' detected.');
+                               break;
+               }
 
-                                               // 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",
+               // 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';
+                       } // END - if
+
+                       // Set sender to 0 when we have a bonus mail
+                       if ($ltype == 'BONUS') {
+                               $sender = '0';
+                       } // 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 ($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      = GET_PAY_POINTS($pay, "time");
-                                                               $payment   = GET_PAY_POINTS($pay, "payment");
-                                                               $VALID     = true;
+                                                               $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",
+                                               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);
-                                                               $VALID = true;
-                                                       }
+                                                               $isValid = true;
+                                                       } // END - if
 
                                                        // Free memory...
                                                        SQL_FREERESULT($result);
                                                        break;
-                                               }
 
-                                               // Is this entry valid?
-                                               if ($VALID) {
-                                                       if (($time == "0") && ($payment > 0)) $time = "1";
-                                                       if (($time > 0) && ($payment > 0)) {
-                                                               if (!empty($code)) {
-                                                                       // Generate code
-                                                                       $img_code = GEN_RANDOM_CODE(getConfig('code_length'), $code, $url_uid, $DATA);
-                                                               } // END - if
-
-                                                               switch ($mode) {
-                                                               case "add":
+                                               default: // Unknown type
+                                                       debug_report_bug(__FILE__, __LINE__, 'Unknown mail type ' . $ltype . ' detected.');
+                                                       break;
+                                       }
+
+                                       // Is this entry valid?
+                                       if ($isValid === true) {
+                                               if (($time == '0') && ($payment > 0)) $time = 1;
+                                               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;
+                                                                       $stats_data = '0';
 
                                                                        // Count clicks
-                                                                       switch ($ltype)
-                                                                       {
-                                                                       case "NORMAL":
-                                                                               SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_stats` SET clicks=clicks + 1 WHERE id=%s LIMIT 1",
-                                                                                       array($url_mid), __FILE__, __LINE__);
-
-                                                                               // Update mediadata as well
-                                                                               if (GET_EXT_VERSION("mediadata") >= "0.0.4") {
-                                                                                       // Update database
-                                                                                       MEDIA_UPDATE_ENTRY(array("total_clicks", "normal_clicks"), "add", 1);
-                                                                               }
-                                                                               $stats_data = $url_mid;
-                                                                               break;
+                                                                       // @TODO Rewrite this to a filter
+                                                                       switch ($ltype) {
+                                                                               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;
 
-                                                                       case "BONUS":
-                                                                               SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_bonus` SET clicks=clicks + 1 WHERE id=%s LIMIT 1",
-                                                                                       array($url_bid), __FILE__, __LINE__);
+                                                                               case 'BONUS':
+                                                                                       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
+                                                                                               array($bonusId), __FILE__, __LINE__);
 
-                                                                               // Update mediadata as well
-                                                                               if (GET_EXT_VERSION("mediadata") >= "0.0.4") {
-                                                                                       // Update database
-                                                                                       MEDIA_UPDATE_ENTRY(array("total_clicks", "bonus_clicks"), "add", 1);
-                                                                               }
-                                                                               $stats_data = $url_bid;
-                                                                               break;
-                                                                       }
+                                                                                       // Update mediadata as well
+                                                                                       if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
+                                                                                               // Update database
+                                                                                               updateMediadataEntry(array('total_clicks', 'bonus_clicks'), 'add', 1);
+                                                                                       } // END - if
+                                                                                       $stats_data = $bonusId;
+                                                                                       break;
+
+                                                                               default: // Unknown type
+                                                                                       debug_report_bug(__FILE__, __LINE__, 'Unknown mail type ' . $ltype . ' detected.');
+                                                                                       break;
+                                                                       } // END - switch
 
                                                                        // Export data into constants for the template
-                                                                       define('_POINTS_VALUE'   , TRANSLATE_COMMA($payment));
-                                                                       define('_TEMPLATE_BANNER', LOAD_TEMPLATE("mailid_banner", true));
+                                                                       $content['banner'] = loadTemplate('mailid_banner', true);
 
                                                                        // Only when user extension = v0.1.2: Update mails-confirmed counter
-                                                                       if (GET_EXT_VERSION("user") >= "0.1.2") {
+                                                                       // @TODO Rewrite these blocks to filter
+                                                                       if (isExtensionInstalledAndNewer('user', '0.1.2')) {
                                                                                // Update counter
-                                                                               SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET mails_confirmed=mails_confirmed + 1 WHERE userid=%s LIMIT 1",
-                                                                                       array($url_uid), __FILE__, __LINE__);
+                                                                               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `mails_confirmed`=`mails_confirmed`+1 WHERE `userid`=%s LIMIT 1",
+                                                                                       array($userId), __FILE__, __LINE__);
 
                                                                                // Update random confirmed as well?
-                                                                               if (GET_EXT_VERSION("user") >= "0.3.4") {
+                                                                               if ((isExtensionInstalledAndNewer('user', '0.3.4')) && (isRandomReferralIdEnabled())) {
                                                                                        // Update second counter
-                                                                                       SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET rand_confirmed=rand_confirmed + 1 WHERE userid=%s LIMIT 1",
-                                                                                               array($url_uid), __FILE__, __LINE__);
+                                                                                       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `rand_confirmed`=`rand_confirmed` + 1 WHERE `userid`=%s LIMIT 1",
+                                                                                               array($userId), __FILE__, __LINE__);
                                                                                } // END - if
                                                                        } // END - if
 
                                                                        // Insert stats record
-                                                                       USER_STATS_INSERT_RECORD($url_uid, $type, $stats_data);
+                                                                       insertUserStatsRecord($userId, $type, $stats_data);
 
                                                                        // Right code entered?
-                                                                       if (bigintval($_POST['gfx_check']) == $img_code) {
-                                                                               // Add points over referal system is the default
-                                                                               $locked = false;
-                                                                               $template = "mailid_points_done";
+                                                                       if (bigintval(postRequestElement('gfx_check')) == $realCode) {
+                                                                               // Set HTTP status to okay
+                                                                               setHttpStatus('200 OK');
+
+                                                                               // Add points over referral system is the default
+                                                                               $template = 'mailid_points_done';
 
                                                                                // Right code entered add points and remove entry
-                                                                               if (($ref_pay > 0) && (getConfig('allow_direct_pay') == "N")) {
-                                                                                       // Don't add points over the referal system
-                                                                                       $locked = true;
-                                                                                       $template = "mailid_points_locked";
+                                                                               if (ifUserPointsLocked($userId)) {
+                                                                                       // Don't add points over the referral system
+                                                                                       $template = 'mailid_points_locked';
                                                                                } // END - if
 
                                                                                // Count down ref_payout value
-                                                                               SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET ref_payout=ref_payout-1 WHERE userid=%s AND ref_payout > 0 LIMIT 1",
-                                                                                       array($url_uid), __FILE__, __LINE__);
+                                                                               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_payout`=`ref_payout`-1 WHERE `userid`=%s AND `ref_payout` > 0 LIMIT 1",
+                                                                                       array($userId), __FILE__, __LINE__);
 
                                                                                // Add points
-                                                                               unset($GLOBALS['ref_level']);
-                                                                               ADD_POINTS_REFSYSTEM("mailid_okay", $url_uid, $payment, false, "0", $locked);
+                                                                               initReferralSystem();
+                                                                               addPointsThroughReferralSystem('mailid_okay', $userId, $payment);
 
                                                                                // Shall I add bonus points for "turbo clickers" ?
-                                                                               if (GET_EXT_VERSION("bonus") >= "0.2.2") {
+                                                                               if (isExtensionInstalledAndNewer('bonus', '0.2.2')) {
                                                                                        // Is an active-rallye running and this is not a notification mail?
-                                                                                       if ((getConfig('bonus_active') == "Y") && ($notify == "N")) {
+                                                                                       if ((isBonusRallyeActive()) && ($notify != 'Y')) {
                                                                                                // Shall I exclude the webmaster's own userid from the active-rallye?
-                                                                                               if ((((getConfig('bonus_uid') == $url_uid) && (getConfig('bonus_include_own') == "Y")) || (getConfig('bonus_uid') != $url_uid)) && (getConfig('def_refid') != $url_uid)) {
+                                                                                               if ((((getBonusUserid() == $userId) && (getConfig('bonus_include_own') == 'Y')) || (getBonusUserid() != $userId)) && (getDefRefid() != $userId)) {
                                                                                                        // Add points and remember ranking are done in this function....
-                                                                                                       BONUS_ADD_TURBO_POINTS($DATA, $url_uid, $type);
+                                                                                                       addTurboBonus($urlId, $userId, $type);
 
                                                                                                        // Set template to mailid_points_done2 which contains a link to the ranking list
-                                                                                                       $template = "mailid_points_done2";
-                                                                                                       if ($locked) $template = "mailid_points_locked2";
-                                                                                                       define('_UID_VALUE' , $url_uid);
-                                                                                                       define('_TYPE_VALUE', $type);
-                                                                                                       define('_DATA_VALUE', TRANSLATE_COMMA($DATA));
+                                                                                                       $template = 'mailid_points_done2';
+
+                                                                                                       // Different template if user has some mails to confirm
+                                                                                                       if (ifUserPointsLocked($userId)) {
+                                                                                                               $template = 'mailid_points_locked2';
+                                                                                                       } // END - if
+
+                                                                                                       // Assign more data for the template
+                                                                                                       $content['userid']  = $userId;
+                                                                                                       $content['type']    = $type;
+                                                                                                       $content['data']    = $urlId;
                                                                                                } // END - if
                                                                                        } // END - if
                                                                                } // END - if
 
                                                                                // Load total points
-                                                                               define('__TOTAL_POINTS', TRANSLATE_COMMA(
-                                                                                       GET_TOTAL_DATA($url_uid, "user_points", "points") -
-                                                                                       GET_TOTAL_DATA($url_uid, "user_data", "used_points"))
-                                                                               );
+                                                                               $content['total_points']  = getTotalPoints($userId);
+
+                                                                               // Add payment points
+                                                                               $content['points'] = $payment;
 
                                                                                // Load template
-                                                                               LOAD_TEMPLATE($template);
-                                                                       } else {
+                                                                               loadTemplate($template, false, $content);
+                                                                       } elseif (isValidUserId($sender)) {
                                                                                // Wrong image code! So add points to sender's account
-                                                                               unset($GLOBALS['ref_level']);
-                                                                               ADD_POINTS_REFSYSTEM("mailid_payback", $sender, $payment, false, 0, false, "direct");
+                                                                               initReferralSystem();
+                                                                               addPointsThroughReferralSystem('mailid_payback', $sender, $payment);
+
+                                                                               // Add payment points
+                                                                               $content['points'] = $payment;
 
                                                                                // Load template
-                                                                               LOAD_TEMPLATE("mailid_points_failed");
+                                                                               loadTemplate('mailid_points_failed', false, $content);
+                                                                       } else {
+                                                                               // Add payment points (again)
+                                                                               $content['points'] = $payment;
+
+                                                                               // Load template
+                                                                               loadTemplate('mailid_points_failed2', false, $content);
                                                                        }
 
                                                                        // Remove link from table
-                                                                       SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_links` WHERE id=%s LIMIT 1",
+                                                                       SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `id`=%s LIMIT 1",
                                                                                array(bigintval($lid)), __FILE__, __LINE__);
                                                                        break;
 
-                                                               case "img":
-                                                                       GENERATE_IMAGE($img_code);
+                                                               case 'img':
+                                                                       generateImageOrCode($realCode);
                                                                        break;
 
-                                                               case "confirm":
-                                                                       if ($code > 0)
-                                                                       {
+                                                               case 'confirm':
+                                                                       if ($code > 0) {
                                                                                // Export data into constants for the template
-                                                                               define('_CODE_VALUE', $code);
-                                                                               define('_UID_VALUE' , $url_uid );
-                                                                               define('_TYPE_VALUE', $type);
-                                                                               define('_DATA_VALUE', $DATA);
-                                                                               define('_TEMPLATE_BANNER', LOAD_TEMPLATE("mailid_banner", true));
-                                                                               if (getConfig('code_length') > 0)
-                                                                               {
+                                                                               $content['code']   = $code;
+                                                                               $content['userid'] = $userId;
+                                                                               $content['type']   = $type;
+                                                                               $content['data']   = $urlId;
+                                                                               $content['banner'] = loadTemplate('mailid_banner', true);
+                                                                               if (getCodeLength() > 0) {
                                                                                        // Generate Code
-                                                                                       define('_IMAGE_CODE', IMG_CODE($code, $type, $DATA, $url_uid));
-                                                                                       $templ = "mailid_enter_code";
-                                                                               }
-                                                                                else
-                                                                               {
+                                                                                       $content['image'] = generateCaptchaCode($realCode, $type, $urlId, $userId);
+                                                                                       $templ = 'mailid_enter_code';
+                                                                               } else {
                                                                                        // Disabled code
-                                                                                       define('__GFX_CODE', $img_code);
-                                                                                       $templ = "mailid_confirm_buttom";
+                                                                                       $content['gfx'] = $realCode;
+                                                                                       $templ = 'mailid_confirm_buttom';
                                                                                }
 
                                                                                // Load template
-                                                                               LOAD_TEMPLATE($templ);
+                                                                               loadTemplate($templ, false, $content);
+                                                                       } else {
+                                                                               // Cannot confirm!
+                                                                               debug_report_bug(__FILE__, __LINE__, 'No code given.');
                                                                        }
                                                                        break;
 
-                                                               case "":
+                                                               case '':
                                                                        // Ok, all data is valid and loaded. Finally let's output the timer... :-)
                                                                        // Export data into constants for the template
-                                                                       define('_TIME_VALUE', $time);
-                                                                       define('_TIM2_VALUE', strlen($time));
-                                                                       define('_UID_VALUE' , $url_uid );
-                                                                       define('_TYPE_VALUE', $type);
-                                                                       define('_DATA_VALUE', $DATA);
-                                                                       define('_RAND_VALUE', mt_rand(0, 99999));
-                                                                       define('_TEMPLATE_BANNER', LOAD_TEMPLATE("mailid_banner", true));
+                                                                       $content['time']   = $time;
+                                                                       $content['tim2']   = strlen($time);
+                                                                       $content['userid'] = $userId;
+                                                                       $content['type']   = $type;
+                                                                       $content['data']   = $urlId;
+                                                                       $content['rand']   = mt_rand(0, 99999);
+                                                                       $content['banner'] = loadTemplate('mailid_banner', true);
 
                                                                        // Load template
-                                                                       LOAD_TEMPLATE("mailid_timer");
+                                                                       loadTemplate('mailid_timer', false, $content);
                                                                        break;
-                                                               }
-                                                       }
-                                                        else LOAD_TEMPLATE("admin_settings_saved", false, "<div class=\"member_failed\">".MAIL_ALREADY_CONFIRMED." (6)</div>");
+
+                                                               default: // Unknown mode
+                                                                       debug_report_bug(__FILE__, __LINE__, 'Unknown mode ' . $do . ' detected.');
+                                                                       break;
+                                                       } // END - switch
+                                               } else {
+                                                       loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (6)');
+                                                       $do = 'failed';
                                                }
-                                                else LOAD_TEMPLATE("admin_settings_saved", false, "<div class=\"member_failed\">".MAIL_ALREADY_CONFIRMED." (5)</div>");
+                                       } else {
+                                               loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (5)');
+                                               $do = 'failed';
                                        }
-                                        else LOAD_TEMPLATE("admin_settings_saved", false, "<div class=\"member_failed\">".MAIL_ALREADY_CONFIRMED." (4)</div>");
                                } else {
-                                       SQL_FREERESULT($result);
-                                       LOAD_TEMPLATE("admin_settings_saved", false, "<div class=\"member_failed\">".MAIL_ALREADY_CONFIRMED." (3)</div>");
+                                       loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (4)');
+                                       $do = 'failed';
                                }
                        } else {
-                               SQL_FREERESULT($result);
-                               LOAD_TEMPLATE("admin_settings_saved", false, "<div class=\"member_failed\">".MAIL_ALREADY_CONFIRMED." (2)</div>");
+                               loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (3)');
+                               $do = 'failed';
                        }
                } else {
-                       SQL_FREERESULT($result);
-                       LOAD_TEMPLATE("admin_settings_saved", false, "<div class=\"member_failed\">".MAIL_ALREADY_CONFIRMED." (1)</div>");
+                       loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (2)');
+                       $do = 'failed';
                }
 
-               // Insert footer if no image
-               if ($mode != "img") {
-                       // Write footer
-                       LOAD_INC_ONCE("inc/footer.php");
-               } // END - if
+               // Free result
+               SQL_FREERESULT($result_mailid);
+       } else {
+               loadTemplate('admin_settings_unsaved', false, '{--MAIL_ALREADY_CONFIRMED--} (1)');
+               $do = 'failed';
        }
-} elseif ($mode != "img") {
-       // You have to install first!
-       LOAD_URL("install.php");
+
+       // Free result
+       SQL_FREERESULT($result_main);
+
+       // Insert footer if no image
+       if ($do != 'img') {
+               // Write footer
+               loadIncludeOnce('inc/footer.php');
+       } // END - if
 }
 
 // Really all done here... ;-)
+shutdown();
+
+// [EOF]
 ?>