]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/user_functions.php
Bad things are now 'classified' as bad (CSS class 'bad' is being used instead of...
[mailer.git] / inc / libs / user_functions.php
index 8e1eea9389e1432b67110480085ae5bb04883d66..71b180ee8fccc6c64bfa791f0f6178a5b493ceca 100644 (file)
@@ -17,7 +17,7 @@
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
  * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
- * For more information visit: http://www.mxchange.org                  *
+ * 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 *
@@ -41,24 +41,25 @@ if (!defined('__SECURITY')) {
 } // END - if
 
 // Add links for selecting some users
-function alpha ($sortby, $colspan, $return=false) {
-       if (!isGetRequestParameterSet('offset')) setGetRequestParameter('offset', 0);
-       $add = '&page='.getRequestParameter('page').'&offset='.getRequestParameter('offset');
-       if (isGetRequestParameterSet('mode')) $add .= '&mode='.getRequestParameter('mode');
+function alpha ($sortby) {
+       $add = '';
+       foreach (array('page','offset','mode','status') as $param) {
+               if (isGetRequestElementSet($param)) {
+                       $add .= '&' . $param . '=' . getRequestElement($param);
+               } // END - if
+       } // END - foreach
 
        /* Creates the list of letters and makes them a link. */
        $alphabet = explode(',', 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,');
        $num = count($alphabet) - 1;
        $OUT = '';
        while (list($counter, $ltr) = each($alphabet)) {
-               if (getRequestParameter('letter') == $ltr) {
+               if (getRequestElement('letter') == $ltr) {
                        // Current letter is letter from URL
                        $OUT .= '<strong>' . $ltr . '</strong>';
                } else {
                        // Output link to letter
-                       $OUT .= '<a href="{%url=modules.php?module=admin&amp;what=' . getWhat();
-                       if (isGetRequestParameterSet('mode')) $OUT .= '&amp;mode=' . getRequestParameter('mode');
-                       $OUT .= '&amp;letter=' . $ltr . '&amp;sortby=' . $sortby . $add . '%}">' . $ltr . '</a>';
+                       $OUT .= '<a href="{%url=modules.php?module=admin&amp;what=' . getWhat() . '&amp;letter=' . $ltr . '&amp;sortby=' . $sortby . $add . '%}">' . $ltr . '</a>';
                }
 
                if ((($counter / getConfig('user_alpha')) == round($counter / getConfig('user_alpha'))) && ($counter > 0)) {
@@ -70,36 +71,36 @@ function alpha ($sortby, $colspan, $return=false) {
 
        // Prepare content
        $content = array (
-               'colspan2'        => $colspan,
                'alpha_selection' => $OUT
        );
 
        // Load template
        $OUT = loadTemplate('admin_list_user_alpha', true, $content);
-       if ($return === true) {
-               // Return generated code
-               return $OUT;
-       } else {
-               // Output generated code
-               outputHtml($OUT);
-       }
+
+       // Return generated code
+       return $OUT;
 }
 
 // Add links for sorting
-function addSortLinks ($letter, $sortby, $colspan, $return=false) {
+function addSortLinks ($letter, $sortby) {
        $OUT = '';
-       if (!isGetRequestParameterSet('offset')) setGetRequestParameter('offset', 0);
-       if (!isGetRequestParameterSet('page'))   setGetRequestParameter('page'  , 0);
+       if (!isGetRequestElementSet('offset')) setGetRequestElement('offset', 0);
+       if (!isGetRequestElementSet('page'))   setGetRequestElement('page'  , 0);
 
        // Add page and offset
-       $add = '&amp;page=' . getRequestParameter('page') . '&amp;offset=' . getRequestParameter('offset');
+       $add = '&amp;page=' . getRequestElement('page') . '&amp;offset=' . getRequestElement('offset');
 
-       // Add status or mode
-       if (isGetRequestParameterSet('status'))   $add .= '&amp;mode=' . getRequestParameter('status');
-       elseif (isGetRequestParameterSet('mode')) $add .= '&amp;mode=' . getRequestParameter('mode');
+       // Add status/ mode
+       foreach (array('mode','status') as $param) {
+               if (isGetRequestElementSet($param)) {
+                       $add .= '&amp;' . $param . '=' . getRequestElement($param);
+               } // END - if
+       } // END - foreach
 
        // Makes order by links..
-       if ($letter == 'front') $letter = '';
+       if ($letter == 'front') {
+               $letter = '';
+       } // END - if
 
        // Prepare array with all possible sorters
        $list = array(
@@ -122,79 +123,67 @@ function addSortLinks ($letter, $sortby, $colspan, $return=false) {
                }
        } // END - foreach
 
-       // Add list and colspan
+       // Add output
        $content['list'] = substr($OUT, 0, -1);
-       $content['colspan2'] = $colspan;
 
        // Load template
        $OUT = loadTemplate('admin_list_user_sort', true, $content);
 
-       // Should we return or output?
-       if ($return === true) {
-               // Return code
-               return $OUT;
-       } else {
-               // Output code
-               outputHtml($OUT);
-       }
+       // Return code
+       return $OUT;
 }
 
 // Add page navigation
-function addPageNavigation ($numPages, $offset, $showForm, $colspan, $return=false) {
-       // @TODO These two constants are no longer used, maybe we reactivate this code?
-       //if ($showForm === true) {
-       //      // Load form for changing number of lines
-       //      define('__FORM_HEADER', loadTemplate('admin_list_user_sort_form', true));
-       //      define('__FORM_FOOTER', '<tr><td colspan="'.$colspan.'" class="seperator bottom">&nbsp;</td></tr>');
-       //} else {
-       //      // Empty row
-       //      define('__FORM_HEADER', '<tr><td colspan="' . $colspan . '" class="seperator">&nbsp;</td></tr>');
-       //      define('__FORM_FOOTER', '<tr><td colspan="' . $colspan . '" class="seperator bottom">&nbsp;</td></tr>');
-       //}
-
+function addPageNavigation ($numPages) {
+       // Start with empty content
        $OUT = '';
-       for ($page = 1; $page <= $numPages; $page++) {
-               if (($page == getRequestParameter('page')) || ((!isGetRequestParameterSet('page')) && ($page == 1))) {
-                       $OUT .= '<strong>-';
-               } else {
-                       if (!isGetRequestParameterSet('letter')) setGetRequestParameter('letter', '');
-                       if (!isGetRequestParameterSet('sortby')) setGetRequestParameter('sortby', 'userid');
 
-                       // Base link
-                       $OUT .= '<a href="{%url=modules.php?module=admin&amp;what=' . getWhat();
+       // Create only the navigation if page count > 1
+       if ($numPages > 1) {
+               // Create navigation links for every page
+               for ($page = 1; $page <= $numPages; $page++) {
+                       if (($page == getRequestElement('page')) || ((!isGetRequestElementSet('page')) && ($page == 1))) {
+                               $OUT .= '<strong>-';
+                       } else {
+                               if (!isGetRequestElementSet('letter')) setGetRequestElement('letter', '');
+                               if (!isGetRequestElementSet('sortby')) setGetRequestElement('sortby', 'userid');
 
-                       // Add status or mode
-                       if (isGetRequestParameterSet('status'))    $OUT .= '&amp;mode=' . getRequestParameter('status');
-                        elseif (isGetRequestParameterSet('mode')) $OUT .= '&amp;mode=' . getRequestParameter('mode');
+                               // Base link
+                               $OUT .= '<a href="{%url=modules.php?module=admin&amp;what=' . getWhat();
 
-                       // Letter and so on
-                       $OUT .= '&amp;letter=' . getRequestParameter('letter') . '&amp;sortby=' . getRequestParameter('sortby') . '&amp;page=' . $page . '&amp;offset=' . $offset . '%}">';
-               }
+                               // Add status/mode
+                               foreach (array('mode','status') as $param) {
+                                       if (isGetRequestElementSet($param)) {
+                                               $OUT .= '&amp;' . $param . '=' . getRequestElement($param);
+                                       } // END - if
+                               } // END - foreach
 
-               $OUT .= $page;
+                               // Letter and so on
+                               $OUT .= '&amp;letter=' . getRequestElement('letter') . '&amp;sortby=' . getRequestElement('sortby') . '&amp;page=' . $page . '&amp;offset=' . getConfig('user_limit') . '%}">';
+                       }
 
-               if (($page == getRequestParameter('page')) || ((!isGetRequestParameterSet('page')) && ($page == 1))) {
-                       $OUT .= '-</strong>';
-               } else  {
-                       $OUT .= '</a>';
-               }
+                       $OUT .= $page;
 
-               if ($page < $numPages) $OUT .= '|';
-       } // END - for
+                       if (($page == getRequestElement('page')) || ((!isGetRequestElementSet('page')) && ($page == 1))) {
+                               $OUT .= '-</strong>';
+                       } else  {
+                               $OUT .= '</a>';
+                       }
 
-       // Remember the list and colspan
-       $content['list']     = $OUT;
-       $content['colspan2'] = $colspan;
+                       if ($page < $numPages) {
+                               $OUT .= '|';
+                       } // END - if
+               } // END - for
 
-       // Load template
-       $OUT = loadTemplate('admin_list_user_pagenav', true, $content);
-       if ($return === true) {
-               // Return code
-               return $OUT;
-       } else {
-               // Output code
-               outputHtml($OUT);
-       }
+               // Add list output
+               $content['list'] = $OUT;
+
+               // Load template
+               $OUT = loadTemplate('admin_list_user_pagenav', true, $content);
+       } // END - if
+
+       // Return code
+       return $OUT;
 }
 
 // Create email link to user's account
@@ -203,16 +192,22 @@ function generateUserEmailLink ($email, $mod = 'admin') {
        $locked = " AND `status`='CONFIRMED'";
 
        // But admins shall always see it
-       if (isAdmin()) $locked = '';
+       if (isAdmin()) {
+               $locked = '';
+       } // END - if
 
+       // Search for the email address
        $result = SQL_QUERY_ESC("SELECT
        `userid`
 FROM
        `{?_MYSQL_PREFIX?}_user_data`
 WHERE
-       `email`='%s'" . $locked."
+       '%s' REGEXP `email`
+       " . $locked . "
 LIMIT 1",
                array($email), __FUNCTION__, __LINE__);
+
+       // Do we have an entry?
        if (SQL_NUMROWS($result) == 1) {
                // Load userid
                list($userid) = SQL_FETCHROW($result);
@@ -228,11 +223,11 @@ LIMIT 1",
        return $email;
 }
 
-// Selects a random user id as the new referal id if they have at least X confirmed mails in this run
+// Selects a random user id as the new referral id if they have at least X confirmed mails in this run
 // @TODO Double-check configuration entry here
-function determineRandomReferalId () {
+function determineRandomReferralId () {
        // Default is zero refid
-       $refid = null;
+       $refid = NULL;
 
        // Is the extension version fine?
        if (isExtensionInstalledAndNewer('user', '0.3.4')) {
@@ -250,12 +245,8 @@ function determineRandomReferalId () {
 
                        // Do we have one entry there?
                        if (SQL_NUMROWS($result) == 1) {
-                               // Use that userid as new referal id
+                               // Use that userid as new referral id
                                list($refid) = SQL_FETCHROW($result);
-
-                               // Reset all users, this makes this random referal id more challenging
-                               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `rand_confirmed`=0",
-                                       array($refid), __FUNCTION__, __LINE__);
                        } // END - if
 
                        // Free result
@@ -343,12 +334,12 @@ function doUserLogin ($userid, $passwd, $successUrl = '', $errorUrl = 'modules.p
                                // Is the timeout reached?
                                if ($probe >= getConfig('login_timeout')) {
                                        // Add login bonus to user's account
-                                       $add = ', `login_bonus`=`login_bonus`+{?login_bonus?}';
+                                       $add = ',`login_bonus`=`login_bonus`+{?login_bonus?}';
                                        $GLOBALS['bonus_payed'] = true;
 
                                        // Subtract login bonus from userid's account or jackpot
                                        if ((isExtensionInstalledAndNewer('bonus', '0.3.5')) && (getBonusMode() != 'ADD')) {
-                                               handleBonusPoints('login_bonus');
+                                               handleBonusPoints('login_bonus', $userid);
                                        } // END - if
                                } // END - if
                        } // END - if
@@ -477,8 +468,8 @@ function doNewUserPassword ($email, $userid) {
                        redirectToUrl('modules.php?module=index&amp;what=login&amp;login=' . $errorCode);
                }
        } else {
-               // id or email is wrong
-               displayMessage('<span class="notice">{--GUEST_WRONG_ID_EMAIL--}</span>');
+               // Id or email is wrong
+               displayMessage('<span class="bad">{--GUEST_WRONG_ID_EMAIL--}</span>');
        }
 
        // Return the error code
@@ -487,12 +478,12 @@ function doNewUserPassword ($email, $userid) {
 }
 
 // Get timestamp for given stats type and data
-function getEpocheTimeFromUserStats ($statsType, $statsData, $userid = '0') {
+function getEpocheTimeFromUserStats ($statsType, $statsData, $userid = NULL) {
        // Default timestamp is zero
        $data['inserted'] = '0';
 
        // User id set?
-       if ((isMemberIdSet()) && ($userid == '0')) {
+       if ((isMemberIdSet()) && (is_null($userid))) {
                $userid = getMemberId();
        } // END - if
 
@@ -539,6 +530,9 @@ function insertUserStatsRecord ($userid, $statsType, $statsData) {
                return false;
        } // END - if
 
+       // Default is not working
+       $return = false;
+
        // Does it exist?
        if ((!getEpocheTimeFromUserStats($statsType, $statsData, $userid)) && (!is_array($statsData))) {
                // Then insert it!
@@ -548,10 +542,16 @@ function insertUserStatsRecord ($userid, $statsType, $statsData) {
                                $statsType,
                                $statsData
                        ), __FUNCTION__, __LINE__);
+
+               // Does it have worked?
+               $return = (!SQL_HASZEROAFFECTED());
        } elseif (is_array($statsData)) {
                // Invalid data!
                logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',type=' . $statsType . ',data=' . gettype($statsData) . ': Invalid statistics data type!');
        }
+
+       // Return status
+       return $return;
 }
 
 // Confirms a user account
@@ -563,10 +563,10 @@ function doConfirmUserAccount ($hash) {
        );
 
        // Initialize the user id
-       $userid = '0';
+       $userid = NULL;
 
        // Search for an unconfirmed or confirmed account
-       $result = SQL_QUERY_ESC("SELECT `userid`, `refid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `user_hash`='%s' AND (`status`='UNCONFIRMED' OR `status`='CONFIRMED') LIMIT 1",
+       $result = SQL_QUERY_ESC("SELECT `userid`,`refid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `user_hash`='%s' AND (`status`='UNCONFIRMED' OR `status`='CONFIRMED') LIMIT 1",
                array($hash), __FILE__, __LINE__);
        if (SQL_NUMROWS($result) == 1) {
                // Ok, he want's to confirm now so we load some data
@@ -586,7 +586,6 @@ function doConfirmUserAccount ($hash) {
        `{?_MYSQL_PREFIX?}_user_data`
 SET
        `status`='CONFIRMED',
-       `ref_payout`={?ref_payout?},
        `user_hash`=NULL
 WHERE
        `user_hash`='%s' AND
@@ -602,12 +601,12 @@ LIMIT 1",
                        // And send him right away the confirmation mail
                        sendEmail($userid, '{--GUEST_THANX_CONFIRM--}', $message);
 
-                       // Maybe he got "referaled"?
-                       if (($refid > 0) && ($refid != $userid)) {
-                               // Select the referal userid
+                       // Maybe he got "referraled"?
+                       if ((isValidUserId($refid)) && ($refid != $userid)) {
+                               // Select the referral userid
                                if (fetchUserData($refid)) {
                                        // Update ref counter...
-                                       updateReferalCounter($refid);
+                                       updateReferralCounter($refid);
 
                                        // If version matches add ref bonus to refid's account
                                        if ((isExtensionInstalledAndNewer('bonus', '0.4.4')) && (isBonusRallyeActive())) {
@@ -616,19 +615,18 @@ LIMIT 1",
                                                        array(bigintval($refid)), __FILE__, __LINE__);
 
                                                // Subtract points from system
-                                               handleBonusPoints(getConfig('bonus_ref'));
+                                               handleBonusPoints(getConfig('bonus_ref'), $refid);
                                        } // END - if
 
-                                       // Add one-time referal bonus over referal system or directly
-                                       // @TODO Try to rewrite the following unset()
-                                       unset($GLOBALS['ref_level']);
-                                       addPointsThroughReferalSystem('referal_bonus', $refid, getPointsRef(), true, bigintval($userid), getConfig('reg_points_mode'));
+                                       // Add one-time referral bonus over referral system or directly
+                                       initReferralSystem();
+                                       addPointsThroughReferralSystem('referral_bonus', $refid, getPointsRef(), bigintval($userid));
                                } // END - if
                        } // END - if
 
                        if (isExtensionActive('rallye')) {
                                // Add user to rallye (or not?)
-                               addUserToReferalRallye(bigintval($userid));
+                               addUserToReferralRallye(bigintval($userid));
                        } // END - if
 
                        // Account confirmed!
@@ -726,11 +724,17 @@ function doExpressionUser ($data) {
        // User-related data, so is there a userid?
        if (!empty($data['matches'][4][$data['key']])) {
                // Do we have a userid or $userid?
-               if ($data['matches'][4][$data['key']] == '$userid') {
+               if (substr($data['matches'][4][$data['key']], 0, 1) == '$') {
                        // Use dynamic call
-                       $functionName = "getFetchedUserData('userid', \$userid, '" . $data['callback'] . "')";
+                       $functionName = "getFetchedUserData('userid', " . $data['matches'][4][$data['key']] . ", '" . $data['callback'] . "')";
                } elseif (!empty($data['matches'][4][$data['key']])) {
-                       // User data found
+                       // Do we have a number or a dollar sign in front of it?
+                       if (preg_replace('/[^0123456789]/', '', $data['matches'][4][$data['key']]) != $data['matches'][4][$data['key']]) {
+                               // Possible database column, so get it again
+                               $data['matches'][4][$data['key']] = "getFetchedUserData('userid', getMemberId(), '" . $data['matches'][4][$data['key']] . "')";
+                       } // END - if
+
+                       // Fix all together
                        $functionName = "getFetchedUserData('userid', " . $data['matches'][4][$data['key']] . ", '" . $data['callback'] . "')";
                }
        } elseif ((!empty($data['callback'])) && (isUserDataValid())) {
@@ -743,6 +747,7 @@ function doExpressionUser ($data) {
                // Surround the original function call with it
                $functionName = $data['extra_func'] . '(' . $functionName . ')';
        } // END - if
+       //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'functionName=' . $functionName);
 
        // Generate replacer
        $replacer = '{DQUOTE} . ' . $functionName . ' . {DQUOTE}';
@@ -755,17 +760,17 @@ function doExpressionUser ($data) {
 }
 
 // Template call-back function for list_user admin function
-function doTemplateAdminListUserTitle ($template, $dummy = false) {
+function doTemplateAdminListUserTitle ($template, $clear = false) {
        // Init title with "all accounts"
        $code = '{--ADMIN_LIST_ALL_ACCOUNTS--}';
 
        // Do we have a 'status' or 'mode' set?
-       if (isGetRequestParameterSet('status')) {
+       if (isGetRequestElementSet('status')) {
                // Set title according to the 'status'
-               $code = sprintf("{--ADMIN_LIST_STATUS_%s_ACCOUNTS--}", strtoupper(getRequestParameter('status')));
-       } elseif (isGetRequestParameterSet('mode')) {
+               $code = sprintf("{--ADMIN_LIST_STATUS_%s_ACCOUNTS--}", strtoupper(getRequestElement('status')));
+       } elseif (isGetRequestElementSet('mode')) {
                // Set title according to the "mode"
-               $code = sprintf("{--ADMIN_LIST_MODE_%s_ACCOUNTS--}", strtoupper(getRequestParameter('mode')));
+               $code = sprintf("{--ADMIN_LIST_MODE_%s_ACCOUNTS--}", strtoupper(getRequestElement('mode')));
        }
 
        // Return the code