Wrapper function introduced, description for random refid rewritten:
authorRoland Häder <roland@mxchange.org>
Mon, 27 Sep 2010 13:16:45 +0000 (13:16 +0000)
committerRoland Häder <roland@mxchange.org>
Mon, 27 Sep 2010 13:16:45 +0000 (13:16 +0000)
- New wrapper function getDefRefid() introduced
- Description in admin area for random referal id rewritten, it now matches
  with the actual code logic and is now easier to understand
- TODOs.txt updated

15 files changed:
DOCS/TODOs.txt
inc/autopurge/purge-inact.php
inc/functions.php
inc/language/de.php
inc/libs/task_functions.php
inc/libs/user_functions.php
inc/modules/admin/what-config_refid.php
inc/modules/admin/what-list_autopurge.php
inc/wrapper-functions.php
mailid_top.php
ref.php
templates/de/html/admin/admin_config_order.tpl
templates/de/html/admin/admin_config_refid.tpl
templates/de/html/admin/admin_edit_user.tpl
templates/de/html/admin/admin_list_autopurge_row.tpl

index ef40780..caff153 100644 (file)
 ./inc/extensions-functions.php:434:// @TODO Change from ext_id to ext_name (not just even the variable! ;-) )
 ./inc/extensions-functions.php:564:            // @TODO Extension is loaded, what next?
 ./inc/functions.php:110:               // @TODO Extension 'msg' does not exist
-./inc/functions.php:1501:                      // @TODO Move this SQL code into a function, let's say 'getTimestampFromPoolId($id) ?
-./inc/functions.php:1589:                      // @TODO Are these convertions still required?
-./inc/functions.php:1607:// @TODO Rewrite this function to use readFromFile() and writeToFile()
+./inc/functions.php:1509:                      // @TODO Move this SQL code into a function, let's say 'getTimestampFromPoolId($id) ?
+./inc/functions.php:1597:                      // @TODO Are these convertions still required?
+./inc/functions.php:1615:// @TODO Rewrite this function to use readFromFile() and writeToFile()
 ./inc/functions.php:179:// @TODO Rewrite this to an extension 'smtp'
-./inc/functions.php:2265:      // @TODO This is still very static, rewrite it somehow
+./inc/functions.php:2273:      // @TODO This is still very static, rewrite it somehow
 ./inc/gen_sql_patches.php:94:// @TODO Rewrite this to a filter
 ./inc/install-functions.php:57:        // @TODO DEACTIVATED: changeDataInFile(getCachePath() . 'config-local.php', 'OUTPUT-MODE', "setConfigEntry('OUTPUT_MODE', '", "');", postRequestParameter('omode'), 0);
-./inc/language/de.php:1089:// @TODO Rewrite these two constants
-./inc/language/de.php:1104:// @TODO Rewrite these three constants
+./inc/language/de.php:1090:// @TODO Rewrite these two constants
+./inc/language/de.php:1105:// @TODO Rewrite these three constants
 ./inc/language/de.php:286:     // @TODO Following two are unused?
 ./inc/language/de.php:789:// @TODO Are these constants longer used?
 ./inc/language-functions.php:241:      // @TODO These are all valid languages, again hard-coded
index faa424f..3301af8 100644 (file)
@@ -54,7 +54,7 @@ if (getConfig('autopurge_inactive') == 'Y') {
        // Init exclusion list
        // @TODO Rewrite these if() blocks to a filter
        $EXCLUDE_LIST = '';
-       if (isValidUserId(getConfig('def_refid'))) $EXCLUDE_LIST .= ' AND `userid` != {?def_refid?}';
+       if (isValidUserId(getDefRefid())) $EXCLUDE_LIST .= ' AND `userid` != {?def_refid?}';
        // Check for more extensions
        if (isExtensionActive('beg'))     $EXCLUDE_LIST .= ' AND `userid` != {?beg_userid?}';
        if (isExtensionActive('bonus'))   $EXCLUDE_LIST .= ' AND `userid` != {?bonus_userid?}';
index 29151e8..7c34708 100644 (file)
@@ -661,16 +661,24 @@ function generateRandomCode ($length, $code, $userid, $DATA = '') {
 
        // Build key string
        $keys = getConfig('SITE_KEY') . getEncryptSeperator() . getConfig('DATE_KEY');
-       if (isConfigEntrySet('secret_key'))  $keys .= getEncryptSeperator().getSecretKey();
-       if (isConfigEntrySet('file_hash'))   $keys .= getEncryptSeperator().getFileHash();
+       if (isConfigEntrySet('secret_key')) {
+               $keys .= getEncryptSeperator().getSecretKey();
+       } // END - if
+       if (isConfigEntrySet('file_hash')) {
+               $keys .= getEncryptSeperator().getFileHash();
+       } // END - if
        $keys .= getEncryptSeperator() . getDateFromPatchTime();
-       if (isConfigEntrySet('master_salt')) $keys .= getEncryptSeperator().getMasterSalt();
+       if (isConfigEntrySet('master_salt')) {
+               $keys .= getEncryptSeperator().getMasterSalt();
+       } // END - if
 
        // Build string from misc data
        $data   = $code . getEncryptSeperator() . $userid . getEncryptSeperator() . $DATA;
 
        // Add more additional data
-       if (isSessionVariableSet('u_hash'))         $data .= getEncryptSeperator() . getSession('u_hash');
+       if (isSessionVariableSet('u_hash')) {
+               $data .= getEncryptSeperator() . getSession('u_hash');
+       } // END - if
 
        // Add referal id, language, theme and userid
        $data .= getEncryptSeperator() . determineReferalId();
@@ -1278,11 +1286,11 @@ function genScrambleString ($len) {
        // First we need to setup randomized numbers from 0 to 31
        for ($idx = 0; $idx < $len; $idx++) {
                // Generate number
-               $rand = mt_rand(0, ($len -1));
+               $rand = mt_rand(0, ($len - 1));
 
                // Check for it by creating more numbers
                while (array_key_exists($rand, $scrambleNumbers)) {
-                       $rand = mt_rand(0, ($len -1));
+                       $rand = mt_rand(0, ($len - 1));
                } // END - while
 
                // Add number
@@ -1926,34 +1934,34 @@ function determineReferalId () {
        // Check if refid is set
        if ((isset($GLOBALS['refid'])) && ($GLOBALS['refid'] > 0)) {
                // This is fine...
-       } elseif ((isGetRequestParameterSet('user')) && (basename($_SERVER['PHP_SELF']) == 'click.php')) {
-               // The variable user comes from the click-counter script click.php and we only accept this here
-               $GLOBALS['refid'] = bigintval(getRequestParameter('user'));
        } elseif (isPostRequestParameterSet('refid')) {
-               // Get referal id from variable refid (so I hope this makes my script more compatible to other scripts)
+               // Get referal id from POST element refid
                $GLOBALS['refid'] = secureString(postRequestParameter('refid'));
        } elseif (isGetRequestParameterSet('refid')) {
-               // Get referal id from variable refid (so I hope this makes my script more compatible to other scripts)
+               // Get referal id from GET parameter refid
                $GLOBALS['refid'] = secureString(getRequestParameter('refid'));
        } elseif (isGetRequestParameterSet('ref')) {
                // Set refid=ref (the referal link uses such variable)
                $GLOBALS['refid'] = secureString(getRequestParameter('ref'));
+       } elseif ((isGetRequestParameterSet('user')) && (basename($_SERVER['PHP_SELF']) == 'click.php')) {
+               // The variable user comes from  click.php
+               $GLOBALS['refid'] = bigintval(getRequestParameter('user'));
        } elseif ((isSessionVariableSet('refid')) && (isValidUserId(getSession('refid')))) {
                // Set session refid als global
                $GLOBALS['refid'] = bigintval(getSession('refid'));
-       } elseif ((isExtensionInstalledAndNewer('user', '0.3.4')) && (isRandomReferalIdEnabled())) {
+       } elseif (isRandomReferalIdEnabled()) {
                // Select a random user which has confirmed enougth mails
                $GLOBALS['refid'] = determineRandomReferalId();
-       } elseif ((isExtensionInstalledAndNewer('sql_patches', '0.1.2')) && (isValidUserId(getConfig('def_refid')))) {
+       } elseif ((isExtensionInstalledAndNewer('sql_patches', '0.1.2')) && (isValidUserId(getDefRefid()))) {
                // Set default refid as refid in URL
-               $GLOBALS['refid'] = getConfig('def_refid');
+               $GLOBALS['refid'] = getDefRefid();
        } else {
                // No default id when sql_patches is not installed or none set
                $GLOBALS['refid'] = null;
        }
 
        // Set cookie when default refid > 0
-       if (!isSessionVariableSet('refid') || (isValidUserId($GLOBALS['refid'])) || ((!isValidUserId(getSession('refid'))) && (isConfigEntrySet('def_refid')) && (isValidUserId(getConfig('def_refid'))))) {
+       if (!isSessionVariableSet('refid') || (isValidUserId($GLOBALS['refid'])) || ((!isValidUserId(getSession('refid'))) && (isExtensionInstalledAndNewer('sql_patches', '0.1.2')) && (isValidUserId(getDefRefid())))) {
                // Default is not found
                $found = false;
 
@@ -1961,15 +1969,15 @@ function determineReferalId () {
                if ((isExtensionActive('nickname')) && (isNicknameUsed($GLOBALS['refid']))) {
                        // Nickname in URL, so load the id
                        $found = fetchUserData($GLOBALS['refid'], 'nickname');
-               } elseif ($GLOBALS['refid'] > 0) {
+               } elseif (isValidUserId($GLOBALS['refid'])) {
                        // Direct userid entered
                        $found = fetchUserData($GLOBALS['refid']);
                }
 
                // Is the record valid?
-               if ((($found === false) || (!isUserDataValid())) && (isConfigEntrySet('def_refid'))) {
+               if ((($found === false) || (!isUserDataValid())) && (isExtensionInstalledAndNewer('sql_patches', '0.1.2'))) {
                        // No, then reset referal id
-                       $GLOBALS['refid'] = getConfig('def_refid');
+                       $GLOBALS['refid'] = getDefRefid();
                } // END - if
 
                // Set cookie
index 6c32c02..98cf72d 100644 (file)
@@ -1051,9 +1051,10 @@ addMessages(array(
        'EMAIL_DETAILS' => "Email-Details",
        'EMAIL_DETAILS_LINK' => "Details anzeigen",
        'ADMIN_CONFIG_REFID_TITLE' => "Einstellungen zum Referal-Link",
-       'ADMIN_RANDOM_ZERO_REFID' => "Soll per Zufall ein Mitglied nach folgenden Kriterien ausgew&auml;hlt werden, wenn keine Standart-Refid eingestellt ist?",
-       'ADMIN_RAND_REFID_ENABLED' => "Mitglieder per Zufall w&auml;hlen",
-       'ADMIN_RAND_REFID_DISABLED' => "Referal-Id 0 verwenden",
+       'ADMIN_RANDOM_ZERO_REFID' => "Soll per Zufall ein Mitglied werden oder soll die oben eingestellte Standart-Refid verwendet werden?",
+       'ADMIN_RANDOM_REFID_ENABLED' => "Mitglieder per Zufall w&auml;hlen",
+       'ADMIN_RANDOM_REFID_DISABLED' => "Voreingestellte Referal-Id setzen",
+       'ADMIN_CONFIG_RANDOM_REFID_TITLE' => "Kriterien wonach ein Mitglied als Zufallsreferal ausgew&auml;hlt wird:",
        'ADMIN_RANDOM_MIN_CONFIRMED' => "Wie viele best&auml;tigte Mails muss ein Mitglied mindestens haben, um per Zufall ausgew&auml;hlt zu werden?",
        'EMAILS_RECEIVED' => "Emails empfangen",
        'MAILS_CONFIRMED' => "Emails best&auml;tigt",
index b1a98ec..f067f2e 100644 (file)
@@ -237,7 +237,7 @@ function outputAdvancedOverview (&$result_main) {
 
                // Check for more extensions
                // @TODO These can be rewritten to filter
-               if (getConfig('def_refid') > 0)                $EXCLUDE_LIST .= ' AND d.`userid` != {?def_refid?}';
+               if (isValidUserId(getDefRefid()))              $EXCLUDE_LIST .= ' AND d.`userid` != {?def_refid?}';
                if (isExtensionActive('beg'))                  $EXCLUDE_LIST .= ' AND d.`userid` != {?beg_userid?}';
                if (isExtensionActive('bonus'))                $EXCLUDE_LIST .= ' AND d.`userid` != {?bonus_userid?}';
                if (isExtensionActive('doubler'))              $EXCLUDE_LIST .= ' AND d.`userid` != {?doubler_userid?}';
index fc9e433..1c7ae8a 100644 (file)
@@ -253,8 +253,8 @@ function determineRandomReferalId () {
                                // Use that userid as new referal id
                                list($refid) = SQL_FETCHROW($result);
 
-                               // Reset this user's counter
-                               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `rand_confirmed`=0 WHERE `userid`=%s LIMIT 1",
+                               // 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
 
index 9b4a3d5..7aad038 100644 (file)
@@ -48,7 +48,7 @@ if (isFormSent()) {
        adminSaveSettingsFromPostData();
 } else {
        // Prepare member selection
-       $content['form_selection'] = addMemberSelectionBox(getConfig('def_refid'), false, true, true, 'def_refid');
+       $content['form_selection'] = addMemberSelectionBox(getDefRefid(), false, true, true, 'def_refid');
 
        // Prepare contants for the template
        foreach (array('refid_target_index','refid_target_register','select_user_zero_refid_y','select_user_zero_refid_n') as $entry) {
index 69404cd..2835465 100644 (file)
@@ -46,25 +46,25 @@ addMenuDescription('admin', __FILE__);
 // Exclude default referal id if set
 // @TODO Rewrite those lines to filter
 $EXCLUDE_LIST = '';
-if (getConfig('def_refid') > 0)                $EXCLUDE_LIST .= ' AND d.userid != {?def_refid?}';
+if (isValidUserId(getDefRefid()))              $EXCLUDE_LIST .= ' AND d.userid != {?def_refid?}';
 if (isExtensionActive('beg'))                  $EXCLUDE_LIST .= ' AND d.userid != {?beg_userid?}';
 if (isExtensionActive('bonus'))                $EXCLUDE_LIST .= ' AND d.userid != {?bonus_userid?}';
 if (isExtensionActive('doubler'))              $EXCLUDE_LIST .= ' AND d.userid != {?doubler_userid?}';
-if (isExtensionInstalledAndNewer('holiday', '0.1.3')) $EXCLUDE_LIST .= " AND d.holiday_active='N'";
+if (isExtensionInstalledAndNewer('holiday', '0.1.3')) $EXCLUDE_LIST .= " AND d.`holiday_active`='N'";
 
 // Check for all accounts
 $result = SQL_QUERY("SELECT
-       d.userid, d.gender, d.surname, d.family, d.email, d.joined, d.last_online, d.ap_notified
+       d.`userid`, d.`gender`, d.`surname`, d.`family`, d.`email`, d.`joined`, d.`last_online`, d.`ap_notified`
 FROM
        `{?_MYSQL_PREFIX?}_user_data` AS d
 WHERE
        d.`status`='CONFIRMED' AND
-       d.joined < (UNIX_TIMESTAMP() - {?ap_inactive_since?}) AND
-       d.last_online < (UNIX_TIMESTAMP() - {?ap_inactive_since?}) AND
-       d.ap_notified < (UNIX_TIMESTAMP() - {?ap_inactive_since?})
+       d.`joined` < (UNIX_TIMESTAMP() - {?ap_inactive_since?}) AND
+       d.`last_online` < (UNIX_TIMESTAMP() - {?ap_inactive_since?}) AND
+       d.`ap_notified` < (UNIX_TIMESTAMP() - {?ap_inactive_since?})
        ".$EXCLUDE_LIST."
 ORDER BY
-       d.userid ASC", __FILE__, __LINE__);
+       d.`userid` ASC", __FILE__, __LINE__);
 
 if (!SQL_HASZERONUMS($result)) {
        // Ok, we have found some inactive accounts
@@ -79,7 +79,7 @@ if (!SQL_HASZERONUMS($result)) {
                        'email'       => '<a href="' . generateEmailLink($content['email'], 'user_data') . '">' . $content['email'] . '</a>',
                        'joined'      => generateDateTime($content['joined'], 2),
                        'last_online' => generateDateTime($content['last_online'], 2),
-                       'notified'    => generateDateTime($content['ap_notified'], 2),
+                       'ap_notified' => generateDateTime($content['ap_notified'], 2),
                );
 
                // Load row template
index b42874e..76ef4a0 100644 (file)
@@ -1317,7 +1317,7 @@ function isRandomReferalIdEnabled () {
        // Do we have cache?
        if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS[__FUNCTION__] = (getConfig('select_user_zero_refid') == 'Y');
+               $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y'));
        } // END - if
 
        // Return cache
@@ -1336,6 +1336,18 @@ function getDefaultLanguage () {
        return $GLOBALS[__FUNCTION__];
 }
 
+// "Getter" for default referal id
+function getDefRefid () {
+       // Do we have cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('def_refid');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
 // "Getter" for path
 function getPath () {
        // Do we have cache?
index d77d5eb..5fa5fb3 100644 (file)
@@ -260,7 +260,7 @@ if ((isValidUserId($userId)) && (($mailId > 0) || ($bonusId > 0)) && (!ifFatalEr
                                                                                        // Is an active-rallye running and this is not a notification mail?
                                                                                        if ((isBonusRallyeActive()) && ($notify != 'Y')) {
                                                                                                // Shall I exclude the webmaster's own userid from the active-rallye?
-                                                                                               if ((((getBonusUserId() == $userId) && (getConfig('bonus_include_own') == 'Y')) || (getBonusUserId() != $userId)) && (getConfig('def_refid') != $userId)) {
+                                                                                               if ((((getBonusUserId() == $userId) && (getConfig('bonus_include_own') == 'Y')) || (getBonusUserId() != $userId)) && (getDefRefid() != $userId)) {
                                                                                                        // Add points and remember ranking are done in this function....
                                                                                                        addTurboBonus($urlId, $userId, $type);
 
diff --git a/ref.php b/ref.php
index 59fe143..3b5fd80 100644 (file)
--- a/ref.php
+++ b/ref.php
@@ -68,7 +68,7 @@ if (isValidUserId(determineReferalId())) {
                        // Do we have an entry?
                        if (!isUserDataValid()) {
                                // No entry, so no referal id
-                               $GLOBALS['refid'] = getConfig('def_refid');
+                               $GLOBALS['refid'] = getDefRefid();
                        } // END - if
                }
        } // END - if
index ed24684..3d6c424 100644 (file)
                <td class="bottom" align="right">{--ADMIN_ORDER_SELECTION_MODE--}:</td>
                <td class="bottom" align="center">
                        <select name="order_mode" class="form_select" size="1">
-                               <option value="ASC"$content[order_mode_asc]">{--SORT_ASCENDING--}</option>
-                               <option value="DESC"$content[order_mode_desc]">{--SORT_DESCENDING--}</option>
+                               <option value="ASC"$content[order_mode_asc]>{--SORT_ASCENDING--}</option>
+                               <option value="DESC"$content[order_mode_desc]>{--SORT_DESCENDING--}</option>
                        </select>
                </td>
        </tr>
index 7378838..ba95377 100644 (file)
        </tr>
 
        <tr>
-               <td class="bottom" align="right" width="200" style="padding-right:5px">{--ADMIN_SELECT_REFID_TARGRT--}:</td>
-               <td class="bottom" align="center">
+               <td align="right" width="200" style="padding-right:5px">{--ADMIN_SELECT_REFID_TARGRT--}:</td>
+               <td align="center">
                        <select name="refid_target" size="1" class="form_select">
-                               <option value="register"$content[refid_target_register]">{--ADMIN_REFERAL_TARGET_REGISTER--}</option>
-                               <option value="index"$content[refid_target_index]">{--ADMIN_REFERAL_TARGET_INDEX--}</option>
+                               <option value="register"$content[refid_target_register]>{--ADMIN_REFERAL_TARGET_REGISTER--}</option>
+                               <option value="index"$content[refid_target_index]>{--ADMIN_REFERAL_TARGET_INDEX--}</option>
                        </select>
                </td>
        </tr>
 
        <tr>
-               <td align="right" width="200" style="padding-right:5px">{--ADMIN_RANDOM_ZERO_REFID--}</td>
-               <td align="center">
+               <td class="bottom" align="right" width="200" style="padding-right:5px">{--ADMIN_RANDOM_ZERO_REFID--}</td>
+               <td class="bottom" align="center">
                        <select name="select_user_zero_refid" size="1" class="form_select">
-                               <option value="Y"$content[select_user_zero_refid_y]">{--ADMIN_RAND_REFID_ENABLED--}</option>
-                               <option value="N"$content[select_user_zero_refid_n]">{--ADMIN_RAND_REFID_DISABLED--}</option>
+                               <option value="Y"$content[select_user_zero_refid_y]>{--ADMIN_RANDOM_REFID_ENABLED--}</option>
+                               <option value="N"$content[select_user_zero_refid_n]>{--ADMIN_RANDOM_REFID_DISABLED--}</option>
                        </select>
                </td>
        </tr>
 
        <tr>
+               <td class="table_header bottom" colspan="2" align="center">
+                       <strong>{--ADMIN_CONFIG_RANDOM_REFID_TITLE--}</strong>
+               </td>
+       </tr>
+
+       <tr>
                <td class="bottom" align="right" width="200" style="padding-right:5px">{--ADMIN_RANDOM_MIN_CONFIRMED--}</td>
                <td class="bottom" align="center">
                        <input type="text" class="form_field" name="user_min_confirmed" size="3" maxlength="3" value="{?user_min_confirmed?}" />
index 07e30cd..78fc892 100644 (file)
@@ -10,9 +10,9 @@
                <td width="195" align="right" height="21">{--GENDER--}:</td>
                <td width="195">
                        <select name="gender" class="form_select" size="1">
-                               <option value="M"$content[gender_m]">{--GENDER_M--}</option>
-                               <option value="F"$content[gender_f]">{--GENDER_F--}</option>
-                               <option value="C"$content[gender_c]">{--GENDER_C--}</option>
+                               <option value="M"$content[gender_m]>{--GENDER_M--}</option>
+                               <option value="F"$content[gender_f]>{--GENDER_F--}</option>
+                               <option value="C"$content[gender_c]>{--GENDER_C--}</option>
                        </select>
                </td>
        </tr>
index cf02eb6..5816470 100644 (file)
@@ -6,5 +6,5 @@
        <td align="center" class="{%template,ColorSwitch%} bottom right">$content[email]</td>
        <td align="center" class="{%template,ColorSwitch%} bottom right">$content[joined]</td>
        <td align="center" class="{%template,ColorSwitch%} bottom right">$content[last_online]</td>
-       <td align="center" class="{%template,ColorSwitch%} bottom">$content[notified]</td>
+       <td align="center" class="{%template,ColorSwitch%} bottom">$content[ap_notified]</td>
 </tr>