Typo 'referral'->'referal' fixed, more 'empty version' fixed
[mailer.git] / inc / modules / guest / what-confirm.php
index aa8d40d..f6fbe74 100644 (file)
@@ -17,7 +17,7 @@
  * Needs to be in all Files and every File needs "svn propset           *
  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder                           *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
 
 // Some security stuff...
 if (!defined('__SECURITY')) {
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
-       require($INC);
-}
+       die();
+} // END - if
 
 // Add description as navigation point
-ADD_DESCR('guest', __FILE__);
+addMenuDescription('guest', __FILE__);
+
+// Init content
+$content = array(
+       'message' => getMessage('GUEST_CONFIRMED_FAILED'),
+       'userid'  => 0,
+);
 
-if (REQUEST_ISSET_GET(('hash'))) {
-       // Initialize the user ID
-       $uid = 0;
+if (isGetRequestElementSet('hash')) {
+       // Initialize the user id
+       $userid = 0;
 
        // Search for an unconfirmed or confirmed account
-       $result = SQL_QUERY_ESC("SELECT userid, email, refid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE user_hash='%s' AND (`status`='UNCONFIRMED' OR `status`='CONFIRMED') LIMIT 1",
-               array(REQUEST_GET('hash')), __FILE__, __LINE__);
+       $result = SQL_QUERY_ESC("SELECT `userid`, `email`, `refid`,`gender` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `user_hash`='%s' AND (`status`='UNCONFIRMED' OR `status`='CONFIRMED') LIMIT 1",
+               array(getRequestElement('hash')), __FILE__, __LINE__);
        if (SQL_NUMROWS($result) == 1) {
                // Ok, he want's to confirm now so we load some data
-               list ($uid, $email, $rid) = SQL_FETCHROW($result);
+               list($userid, $email, $rid, $gender) = SQL_FETCHROW($result);
+
+               // Fetch user data
+               if (!fetchUserData($userid)) {
+                       // Not found, should not happen
+                       debug_report_bug('User account ' . $userid . ' not found.');
+               } // END - if
+
+               // Load all data and add points
+               $content = getUserDataArray();
+               $content['gender'] = translateGender($content['gender']);
+               $content['points'] = getConfig('points_register');
 
                // Unlock his account (but only when it is on UNCONFIRMED!)
-               SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET `status`='CONFIRMED', ref_payout=%s, user_hash=NULL WHERE user_hash='%s' AND `status`='UNCONFIRMED' LIMIT 1",
-                       array(getConfig('ref_payout'), REQUEST_GET('hash')), __FILE__, __LINE__);
+               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `status`='CONFIRMED', ref_payout={?ref_payout?}, `user_hash`=NULL WHERE `user_hash`='%s' AND `status`='UNCONFIRMED' LIMIT 1",
+                       array(getRequestElement('hash')), __FILE__, __LINE__);
                if (SQL_AFFECTEDROWS() == 1) {
-                       $msg = LOAD_EMAIL_TEMPLATE("confirm-member", array('points' => getConfig('points_register')), bigintval($uid));
+                       // Send email if updated
+                       $message = loadEmailTemplate('confirm-member', $content, bigintval($userid));
 
                        // And send him right away the confirmation mail
-                       sendEmail($email, getMessage('GUEST_THANX_CONFIRM'), $msg);
+                       sendEmail($email, getMessage('GUEST_THANX_CONFIRM'), $message);
 
                        // Maybe he got "referaled"?
-                       if (($rid > 0) && ($rid != $uid)) {
+                       if (($rid > 0) && ($rid != $userid)) {
                                // Select the referal userid
-                               $result = SQL_QUERY_ESC("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
-                                       array(bigintval($rid)), __FILE__, __LINE__);
-                               if (SQL_NUMROWS($result) == 1) {
+                               if (fetchUserData($rid)) {
                                        // Update ref counter...
                                        updateReferalCounter($rid);
 
-                                       // Ok, write the ref-points to this user and his parent-ref
-                                       unset($GLOBALS['ref_level']);
-
-                                       // Shall I "pay" the referal points imidiately?
-                                       if (getConfig('ref_payout') == '0') {
-                                               // Yes, "pay" it now
+                                       // Shall I 'pay' the referal points imidiately?
+                                       if (getConfig('ref_payout') == 0) {
+                                               // Yes, 'pay' it now
                                                $locked = false;
                                        } else {
-                                               // No, "pay" it later
+                                               // No, 'pay' it later
                                                $locked = true;
                                        }
 
                                        // If version matches add ref bonus to refid's account
-                                       if ((GET_EXT_VERSION('bonus') >= '0.4.4') && (getConfig('bonus_active') == 'Y')) {
+                                       if ((getExtensionVersion('bonus') >= '0.4.4') && (getConfig('bonus_active') == 'Y')) {
                                                // Add points (directly only!)
-                                               SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET bonus_ref=bonus_ref+%s WHERE userid=%s LIMIT 1",
-                                                       array(getConfig('bonus_ref'), bigintval($rid)), __FILE__, __LINE__);
+                                               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `bonus_ref`=`bonus_ref`+{?bonus_ref?} WHERE `userid`=%s LIMIT 1",
+                                                       array(bigintval($rid)), __FILE__, __LINE__);
 
                                                // Subtract points from system
-                                               BONUS_POINTS_HANDLER(getConfig('bonus_ref'));
+                                               handleBonusPoints(getConfig('bonus_ref'));
                                        } // END - if
 
                                        // Add one-time referal bonus over referal system or directly
+                                       // @TODO Try to rewrite the following unset()
                                        unset($GLOBALS['ref_level']);
-                                       ADD_POINTS_REFSYSTEM("referal_bonus", $rid, getConfig('points_ref'), true, bigintval($uid), $locked, getConfig('reg_points_mode'));
+                                       addPointsThroughReferalSystem('referal_bonus', $rid, getConfig('points_ref'), true, bigintval($userid), $locked, getConfig('reg_points_mode'));
                                } // END - if
                        } // END - if
 
-                       if (EXT_IS_ACTIVE('rallye')) {
+                       if (isExtensionActive('rallye')) {
                                // Add user to rallye (or not?)
-                               RALLYE_AUTOADD_USER(bigintval($uid));
+                               addUserToReferalRallye(bigintval($userid));
                        } // END - if
 
                        // Account confirmed!
-                       if (defined('LEAD_CODE_ENABLED') && defined('LEAD_EXPIRY_TIME')) {
+                       if (isExtensionActive('lead')) {
                                // Set special lead cookie
-                               setSession('lead_uid', bigintval($uid));
+                               setSession('lead_userid', bigintval($userid));
 
                                // Lead-Code mode enabled
-                               redirectToUrl("lead-confirm.php");
+                               redirectToUrl('lead-confirm.php');
                        } else {
-                               define('__CONFIRM_MSG', getMessage('GUEST_CONFIRMED_DONE'));
-                               define('__UID', bigintval($uid));
-                               LOAD_TEMPLATE("guest_confirm_table");
+                               $content['message'] = getMessage('GUEST_CONFIRMED_DONE');
+                               $content['userid']  = bigintval($userid);
                        }
-               } elseif (defined('LEAD_CODE_ENABLED') && defined('LEAD_EXPIRY_TIME')) {
+               } elseif (isExtensionActive('lead')) {
                        // Set special lead cookie
-                       setSession('lead_uid', bigintval($uid));
+                       setSession('lead_userid', bigintval($userid));
 
                        // Lead-Code mode enabled
-                       redirectToUrl("lead-confirm.php");
+                       redirectToUrl('lead-confirm.php');
                } else {
                        // Nobody was found unter this hash key... or our new member want's to confirm twice?
-                       define('__CONFIRM_MSG', getMessage('GUEST_CONFIRMED_TWICE'));
-                       define('__UID', '0');
-                       LOAD_TEMPLATE("guest_confirm_table");
+                       $content['message'] = getMessage('GUEST_CONFIRMED_TWICE');
                }
        } else {
                // Nobody was found unter this hash key... or our new member want's to confirm twice?
-               define('__CONFIRM_MSG', getMessage('GUEST_CONFIRMED_TWICE'));
-               define('__UID', '0');
-               LOAD_TEMPLATE("guest_confirm_table");
+               $content['message'] = getMessage('GUEST_CONFIRMED_TWICE');
        }
-} elseif ((IS_FORM_SENT()) && (REQUEST_ISSET_POST(('email')))) {
-       // Confirmation link requested      0     1         2
-       $result = SQL_QUERY_ESC("SELECT userid, status, user_hash FROM `{!_MYSQL_PREFIX!}_user_data` WHERE email='%s' LIMIT 1",
-               array(REQUEST_POST('email')), __FILE__, __LINE__);
-       if (SQL_NUMROWS($result) == 1) {
+
+       // Load template
+       loadTemplate('admin_settings_saved', false, $content['message']);
+} elseif ((isFormSent()) && (isPostRequestElementSet('email'))) {
+       // Confirmation link requested      0         1          2
+       if (fetchUserData(postRequestElement('email'), 'email')) {
                // Email address found
-               $DATA = SQL_FETCHROW($result);
-               switch ($DATA[1])
-               {
-               case "UNCONFIRMED": // Account not confirmed
-                       $msg = LOAD_EMAIL_TEMPLATE("guest_request_confirm", array('hash' => $DATA[2]), $DATA[0]);
-                       sendEmail(REQUEST_POST('email'), getMessage('REQUEST_CONFIRM_LINK_SUBJ'), $msg);
-                       $content = getMessage('CONFIRM_LINK_SENT');
-                       break;
-
-               case 'CONFIRMED': // Account already confirmed
-                       $content = getMessage('LOGIN_ID_CONFIRMED');
-                       break;
-
-               case "LOCKED": // Account is locked
-                       $content = getMessage('LOGIN_ID_LOCKED');
-                       break;
-               }
+               $content = getUserDataArray();
+
+               // Detect status
+               switch ($content['status']) {
+                       case 'UNCONFIRMED': // Account not confirmed
+                               // Load email template
+                               $message = loadEmailTemplate('guest_request_confirm', array('hash' => $content['user_hash']), $content['userid']);
+
+                               // Send email
+                               sendEmail(postRequestElement('email'), getMessage('REQUEST_CONFIRM_LINK_SUBJ'), $message);
+
+                               // And set message
+                               $content['message'] = getMessage('CONFIRM_LINK_SENT');
+                               break;
+
+                       case 'CONFIRMED': // Account already confirmed
+                               $content['message'] = getMessage('LOGIN_ID_CONFIRMED');
+                               break;
+
+                       case 'LOCKED': // Account is locked
+                               $content['message'] = getMessage('LOGIN_ID_LOCKED');
+                               break;
+               } // END - switch
        } else {
                // Email address not registered
-               $content = getMessage('EMAIL_ADDY_404');
+               $content['message'] = getMessage('EMAIL_ADDRESS_404');
        }
 
-       define('__CONFIRM_MSG', $content);
-       LOAD_TEMPLATE("guest_confirm_table");
+       // Load template
+       loadTemplate('admin_settings_saved', false, $content['message']);
 } else {
        // No hash found, the guest may want to enter his email address to re-get his confirmation link?
-       LOAD_TEMPLATE("guest_confirm_link");
+       loadTemplate('guest_confirm_link');
 }
 
-//
+// [EOF]
 ?>