Fix for INSERT INTO query
[mailer.git] / birthday_confirm.php
index b65d5e1b0ad23ed425a9589ba2b3d1644c3c5fb9..69530f99f06390558687a38c93831ba015030da6 100644 (file)
@@ -37,75 +37,74 @@ require_once("inc/libs/security_functions.php");
 // Init "action" and "what"
 global $what, $action;
 $GLOBALS['what'] = ""; $GLOBALS['action'] = "";
-if (!empty($_GET['action'])) $GLOBALS['action'] = secureString($_GET['action']);
-if (!empty($_GET['what'])) $GLOBALS['what'] = secureString($_GET['what']);
 
 // Set module
 $GLOBALS['module'] = "birthday_confirm"; $CSS = -1;
 
 // Load the required file(s)
-require ("inc/config.php");
+require("inc/config.php");
 
-if (defined('mxchange_installed') && (mxchange_installed))
-{
+// Is the "birthday" extension active?
+if (!EXT_IS_ACTIVE("birthday")) {
+       // Redirect to index
+       LOAD_URL("modules.php?module=index&msg=".CODE_EXTENSION_PROBLEM."&ext=birthday");
+} // END - if
+
+// Is the script installed?
+if (isBooleanConstantAndTrue('mxchange_installed')) {
        // Script is installed so let's check for his confirmation link...
-       $uid = strip_tags(bigintval($_GET['uid']));
+       $uid = bigintval($_GET['uid']);
 
        // Only allow numbers here...
-       $chk = strip_tags(bigintval($_GET['check']));
-
-       // .. only first 32 numbers
-       $chk = substr($chk, 0, 32);
+       $chk = bigintval($_GET['check'], false);
 
        // Check if link is not clicked so far
-       $result = SQL_QUERY_ESC("SELECT DISTINCT b.points, d.sex, d.surname, d.family, d.status
+       $result = SQL_QUERY_ESC("SELECT b.points, d.gender, d.surname, d.family, d.status, d.ref_payout
 FROM "._MYSQL_PREFIX."_user_birthday AS b
-LEFT JOIN "._MYSQL_PREFIX."_user_data AS d
+INNER JOIN `"._MYSQL_PREFIX."_user_data` AS d
 ON b.userid=d.userid
-WHERE b.userid=%d AND b.chk_value='%s' LIMIT 1",
+WHERE b.userid=%s AND b.chk_value='%s' LIMIT 1",
  array($uid, $chk), __FILE__, __LINE__);
+       //* DEBUG: */ echo "uid=".$uid.",chk=".$chk." (".strlen($chk)."/".strlen($_GET['check'])."/".SQL_NUMROWS($result).")<br />\n";
 
-       if (SQL_NUMROWS($result) == 1)
-       {
+       // Is an entry there?
+       if (SQL_NUMROWS($result) == 1) {
                // Ok, congratulation again! Here's your gift from us...
-               list($GIFT, $salut, $sname, $fname, $status) = SQL_FETCHROW($result);
-               if ($status == "CONFIRMED")
-               {
+               $data = SQL_FETCHARRAY($result, false);
+
+               // Is the account confirmed?
+               if ($data['status'] == "CONFIRMED") {
                        // Set mode depending on how many mails the member has to confirm
                        $locked = false;
-                       if (($ref_payout > 0) && ($CONFIG['allow_direct_pay'] == 'N')) $locked = true;
+                       if (($data['ref_payout'] > 0) && (getConfig('allow_direct_pay') == "N")) $locked = true;
 
                        // Add points to account
-                       ADD_POINTS_REFSYSTEM($uid, $GIFT, false, "0", $locked, strtolower($CONFIG['birthday_mode']));
+                       unset($GLOBALS['ref_level']);
+                       ADD_POINTS_REFSYSTEM("birthday_confirm", $uid, $data['points'], false, "0", $locked, strtolower(getConfig('birthday_mode')));
 
                        // Remove entry from table
-                       $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_birthday WHERE userid=%d LIMIT 1",
-                        array($uid), __FILE__, __LINE__);
+                       $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_birthday WHERE userid=%s AND chk_value='%s' LIMIT 1",
+                               array($uid, $chk), __FILE__, __LINE__);
 
                        // Update mediadata if version is 0.0.4 or newer
-                       if (GET_EXT_VERSION("mediadata") >= "0.0.4")
-                       {
+                       if (GET_EXT_VERSION("mediadata") >= "0.0.4") {
                                // Update database
-                               MEDIA_UPDATE_ENTRY(array("total_points"), "add", $GIFT);
+                               MEDIA_UPDATE_ENTRY(array("total_points"), "add", $data['points']);
                        }
 
                        // Transfer data to constants for the template
-                       define('__SALUT', TRANSLATE_SEX($salut));
-                       define('__SNAME', $sname);
-                       define('__FNAME', $fname);
-                       define('__GIFT' , $GIFT);
+                       define('__GENDER', TRANSLATE_GENDER($data['gender']));
+                       define('__SNAME', $data['surname']);
+                       define('__FNAME', $data['family']);
+                       define('__GIFT' , $data['points']);
 
                        // Load message from template
                        define('__MSG', LOAD_TEMPLATE("birthday_msg", true));
-               }
-                else
-               {
+               } else {
                        // Unconfirmed / locked accounts cannot get points
-                       define('__MSG', BIRTHDAY_CANNOT_STATUS_1.TRANSLATE_STATUS($status).BIRTHDAY_CANNOT_STATUS_2);
+                       define('__MSG', BIRTHDAY_CANNOT_STATUS_1.TRANSLATE_STATUS($data['status']).BIRTHDAY_CANNOT_STATUS_2);
                }
-       }
-        else
-       {
+       } else {
                // Cannot load data!
                define('__MSG', BIRTHDAY_CANNOT_LOAD_DATA);
        }
@@ -130,11 +129,9 @@ WHERE b.userid=%d AND b.chk_value='%s' LIMIT 1",
 
        // Include footer
        include(PATH."inc/footer.php");
-}
- else
-{
+} else {
        // You have to configure first!
-       LOAD_URL(URL."/install.php");
+       LOAD_URL("install.php");
 }
 // Really all done here... ;-)
 ?>