]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/user_functions.php
Long word shorted
[mailer.git] / inc / libs / user_functions.php
index cf44c26d78d3253107dbc67cbbc5be088769f77e..f00c096841e82d32954662a3293af96aef08a770 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;
-       if (empty($_GET['offset'])) $_GET['offset'] = "0";
-       $ADD = "&page=".$_GET['page']."&offset=".$_GET['offset'];
+       global $_CONFIG;
+       if (empty($_GET['offset'])) $_GET['offset'] = 0;
+       $ADD = "&page=".SQL_ESCAPE($_GET['page'])."&offset=".SQL_ESCAPE($_GET['offset']);
        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))
@@ -63,7 +63,7 @@ function alpha($sortby, $colspan, $return=false)
                        if (!empty($_GET['mode'])) $OUT .= "&mode=".SQL_ESCAPE($_GET['mode']);
                        $OUT .= "&amp;letter=".$ltr."&amp;sortby=".$sortby.$ADD."\">".$ltr."</A>";
                }
-               if ((($counter / $CONFIG['user_alpha']) == round($counter / $CONFIG['user_alpha'])) && ($counter > 0))
+               if ((($counter / $_CONFIG['user_alpha']) == round($counter / $_CONFIG['user_alpha'])) && ($counter > 0))
                {
                        $OUT .= "&nbsp;]<br />[&nbsp;";
                }
@@ -87,13 +87,20 @@ function alpha($sortby, $colspan, $return=false)
                OUTPUT_HTML($OUT);
        }
 }
-//
+
+// Add links for sorting
 function SortLinks($letter, $sortby, $colspan, $return=false)
 {
        $OUT = "";
-       if (empty($_GET['offset'])) $_GET['offset'] = "0";
-       $ADD = "&amp;page=".$_GET['page']."&amp;offset=".$_GET['offset'];
-       if (!empty($_GET['mode'])) $ADD .= "&amp;mode=".SQL_ESCAPE($_GET['mode']);
+       if (empty($_GET['offset'])) $_GET['offset'] = 0;
+       if (empty($_GET['page']))   $_GET['page'] = 0;
+
+       // Add page and offset
+       $ADD = "&amp;page=".SQL_ESCAPE($_GET['page'])."&amp;offset=".SQL_ESCAPE($_GET['offset']);
+
+       // Add status or mode
+       if (!empty($_GET['status'])) $ADD .= "&amp;mode=".SQL_ESCAPE($_GET['status']);
+        elseif (!empty($_GET['mode'])) $ADD .= "&amp;mode=".SQL_ESCAPE($_GET['mode']);
 
        // Makes order by links..
        if ($letter == "front") $letter = _ALL2;
@@ -111,7 +118,7 @@ function SortLinks($letter, $sortby, $colspan, $return=false)
                $list['nickname'] = NICKNAME;
        }
 
-       foreach ($list as $sort=>$title) {
+       foreach ($list as $sort => $title) {
                if ($sortby == $sort) {
                        $OUT .= "<STRONG>".$title."</STRONG>&nbsp;|&nbsp;";
                } else {
@@ -133,44 +140,43 @@ 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)
-       {
+       if (!$show_form) {
                // Empty row
                define('__FORM_HEADER', "<TR><TD colspan=\"".$colspan."\" class=\"seperator\">&nbsp;</TD></TR>");
-       }
-        else
-       {
+       } else {
                // Load form for changing number of lines
                define('__FORM_HEADER', LOAD_TEMPLATE("admin_list_user_sort_form", true));
        }
-       if (!$show_form)
-       {
+
+       if (!$show_form) {
                // Add line with bottom border
                define('__FORM_FOOTER', "<TR><TD colspan=\"".__COLSPAN2."\" class=\"seperator bottom2\">&nbsp;</TD></TR>");
-       }
-        else
-       {
+       } else {
                // Add line without bottom border
                define('__FORM_FOOTER', "<TR><TD colspan=\"".__COLSPAN2."\" class=\"seperator bottom2\">&nbsp;</TD></TR>");
        }
 
        $OUT = "";
-       for ($page = 1; $page <= $PAGES; $page++)
-       {
-               if (($page == $_GET['page']) || ((empty($_GET['page'])) && ($page == "1")))
-               {
+       for ($page = 1; $page <= $PAGES; $page++) {
+               if (($page == $_GET['page']) || ((empty($_GET['page'])) && ($page == "1"))) {
                        $OUT .= "<STRONG>-";
-               }
-                else
-               {
+               } else {
                        if (empty($_GET['letter'])) $_GET['letter'] = _ALL2;
                        if (empty($_GET['sortby'])) $_GET['sortby'] = "userid";
+
+                       // Base link
                        $OUT .= "<A href=\"".URL."/modules.php?module=admin&amp;what=".$GLOBALS['what'];
-                       if (!empty($_GET['mode'])) $OUT .= "&amp;mode=".SQL_ESCAPE($_GET['mode']);
-                       $OUT .= "&amp;letter=".$_GET['letter']."&amp;sortby=".$_GET['sortby']."&amp;page=".$page."&amp;offset=".$offset."\">";
+
+                       // Add status or mode
+                       if (!empty($_GET['status'])) $OUT .= "&amp;mode=".SQL_ESCAPE($_GET['status']);
+                        elseif (!empty($_GET['mode'])) $OUT .= "&amp;mode=".SQL_ESCAPE($_GET['mode']);
+
+                        // Letter and so on
+                       $OUT .= "&amp;letter=".SQL_ESCAPE($_GET['letter'])."&amp;sortby=".SQL_ESCAPE($_GET['sortby'])."&amp;page=".$page."&amp;offset=".$offset."\">";
                }
                $OUT .= $page;
                if (($page == $_GET['page']) || ((empty($_GET['page'])) && ($page == "1")))
@@ -198,6 +204,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 +229,46 @@ 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);
+
+                               // Reset this user's counter
+                               SQL_QUERY_ESC("UPDATE `"._MYSQL_PREFIX."_iser_data` SET `rand_confirmed`=0 WHERE userid=%s LIMIT 1",
+                                       array($refid), __FILE__, __LINE__);
+                       } // END - if
+
+                       // Free result
+                       SQL_FREERESULT($result);
+               } // END - if
+       } // END - if
+
+       // Return result
+       return $refid;
+}
+
+// [EOF]
 ?>