]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/user_functions.php
Admin user details extended, DEBUG_LOG() rewritten, random userid on refid=0 added
[mailer.git] / inc / libs / user_functions.php
index 9c42fb28a2b8f6b6b072b4deb35d2db5aa9d284a..75cf35e9972a3bfa42064ed2895e5c0b9b651523 100644 (file)
  ************************************************************************/
 
 // Some security stuff...
-if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
-{
+if (!defined('__SECURITY')) {
        $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
        require($INC);
 }
 
+// Add links for selecting some users
 function alpha($sortby, $colspan, $return=false)
 {
        global $_CONFIG;
@@ -46,7 +46,7 @@ function alpha($sortby, $colspan, $return=false)
        if (!empty($_GET['mode'])) $ADD .= "&mode=".SQL_ESCAPE($_GET['mode']);
 
        /* Creates the list of letters and makes them a link. */
-       $alphabet = array(_ALL2, "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", _OTHERS);
+       $alphabet = array(_ALL2,"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",_OTHERS);
        $num = count($alphabet) - 1;
        $OUT = "";
        while (list($counter, $ltr) = each($alphabet))
@@ -87,7 +87,8 @@ function alpha($sortby, $colspan, $return=false)
                OUTPUT_HTML($OUT);
        }
 }
-//
+
+// Add links for sorting
 function SortLinks($letter, $sortby, $colspan, $return=false)
 {
        $OUT = "";
@@ -133,7 +134,8 @@ function SortLinks($letter, $sortby, $colspan, $return=false)
                OUTPUT_HTML($OUT);
        }
 }
-//
+
+// Add page navigation
 function ADD_PAGENAV($PAGES, $offset, $show_form, $colspan,$return=false)
 {
        if (!$show_form)
@@ -198,6 +200,7 @@ function ADD_PAGENAV($PAGES, $offset, $show_form, $colspan,$return=false)
                OUTPUT_HTML($OUT);
        }
 }
+
 // Create email link to user's account
 function USER_CREATE_EMAIL_LINK($email, $mod="admin")
 {
@@ -222,5 +225,42 @@ WHERE email='%s'".$locked." LIMIT 1",
        // Return rewritten (?) email address
        return $email;
 }
-//
+
+// Selects a random user id as the new referal id if they have at least X confirmed mails in this run
+function SELECT_RANDOM_REFID () {
+       global $_CONFIG;
+
+       // Default is zero refid
+       $refid = 0;
+
+       // Is the extension version fine?
+       if (GET_EXT_VERSION("user") >= "0.3.4") {
+               // Get all user ids
+               $totalUsers = GET_TOTAL_DATA("CONFIRMED", "user_data", "userid", "status", true, " AND `rand_confirmed` >= ".$_CONFIG['user_min_confirmed']."");
+
+               // Do we have at least one?
+               if ($totalUsers > 0) {
+                       // Then choose random number
+                       $randNum = mt_rand(0, ($totalUsers - 1));
+
+                       // Look for random user
+                       $result = SQL_QUERY_ESC("SELECT `userid` FROM `"._MYSQL_PREFIX."_user_data` WHERE `status`='CONFIRMED' AND `rand_confirmed` >= %s ORDER BY `rand_confirmed` DESC LIMIT %s, 1",
+                               array($_CONFIG['user_min_confirmed'], $randNum), __FILE__, __LINE__);
+
+                       // Do we have one entry there?
+                       if (SQL_NUMROWS($result) == 1) {
+                               // Use that userid as new referal id
+                               list($refid) = SQL_FETCHROW($result);
+                       } // END - if
+
+                       // Free result
+                       SQL_FREERESULT($result);
+               } // END - if
+       } // END - if
+
+       // Return result
+       return $refid;
+}
+
+// [EOF]
 ?>