2 /************************************************************************
3 * MXChange v0.2.1 Start: 07/16/2004 *
4 * =============== Last change: 10/27/2004 *
6 * -------------------------------------------------------------------- *
7 * File : user_functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Special functions for user extension *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Spezielle Funktionen fuer die user-Erweiterung *
12 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40 // Add links for selecting some users
41 function alpha($sortby, $colspan, $return=false) {
43 if (empty($_GET['offset'])) $_GET['offset'] = 0;
44 $ADD = "&page=".SQL_ESCAPE($_GET['page'])."&offset=".SQL_ESCAPE($_GET['offset']);
45 if (!empty($_GET['mode'])) $ADD .= "&mode=".SQL_ESCAPE($_GET['mode']);
47 /* Creates the list of letters and makes them a link. */
48 $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);
49 $num = count($alphabet) - 1;
51 while (list($counter, $ltr) = each($alphabet)) {
52 if ($_GET['letter'] == $ltr) {
53 // Current letter is letter from URL
54 $OUT .= "<STRONG>".$ltr."</STRONG>";
56 // Output link to letter
57 $OUT .= "<A href=\"".URL."/modules.php?module=admin&what=".$GLOBALS['what'];
58 if (!empty($_GET['mode'])) $OUT .= "&mode=".SQL_ESCAPE($_GET['mode']);
59 $OUT .= "&letter=".$ltr."&sortby=".$sortby.$ADD."\">".$ltr."</A>";
62 if ((($counter / getConfig('user_alpha')) == round($counter / getConfig('user_alpha'))) && ($counter > 0)) {
63 $OUT .= " ]<br />[ ";
64 } elseif ( $counter != $num ) {
65 $OUT .= " | ";
69 define('__ALPHA_LIST', $OUT);
72 $OUT = LOAD_TEMPLATE("admin_list_user_alpha", true);
74 // Return generated code
77 // Output generated code
82 // Add links for sorting
83 function SortLinks($letter, $sortby, $colspan, $return=false) {
85 if (empty($_GET['offset'])) $_GET['offset'] = 0;
86 if (empty($_GET['page'])) $_GET['page'] = 0;
88 // Add page and offset
89 $ADD = "&page=".SQL_ESCAPE($_GET['page'])."&offset=".SQL_ESCAPE($_GET['offset']);
92 if (!empty($_GET['status'])) $ADD .= "&mode=".SQL_ESCAPE($_GET['status']);
93 elseif (!empty($_GET['mode'])) $ADD .= "&mode=".SQL_ESCAPE($_GET['mode']);
95 // Makes order by links..
96 if ($letter == "front") $letter = _ALL2;
98 // Prepare array with all possible sorters
101 'family' => FAMILY_NAME,
103 'REMOTE_ADDR' => REMOTE_IP
106 // Add nickname if extension is installed
107 if (EXT_IS_ACTIVE("nickname")) {
108 $list['nickname'] = NICKNAME;
111 foreach ($list as $sort => $title) {
112 if ($sortby == $sort) {
113 $OUT .= "<STRONG>".$title."</STRONG> | ";
115 $OUT .= "<A href=\"".URL."/modules.php?module=admin&what=list_user&letter=".$letter."&sortby=".$sort.$ADD."\">".$title."</a> | ";
119 define('__SORT_LIST', substr($OUT, 0, -13));
122 $OUT = LOAD_TEMPLATE("admin_list_user_sort", true);
132 // Add page navigation
133 function ADD_PAGENAV($PAGES, $offset, $show_form, $colspan,$return=false) {
136 define('__FORM_HEADER', "<TR><TD colspan=\"".$colspan."\" class=\"seperator\"> </TD></TR>");
138 // Load form for changing number of lines
139 define('__FORM_HEADER', LOAD_TEMPLATE("admin_list_user_sort_form", true));
143 // Add line with bottom border
144 define('__FORM_FOOTER', "<TR><TD colspan=\"".__COLSPAN2."\" class=\"seperator bottom2\"> </TD></TR>");
146 // Add line without bottom border
147 define('__FORM_FOOTER', "<TR><TD colspan=\"".__COLSPAN2."\" class=\"seperator bottom2\"> </TD></TR>");
151 for ($page = 1; $page <= $PAGES; $page++) {
152 if (($page == $_GET['page']) || ((empty($_GET['page'])) && ($page == "1"))) {
155 if (empty($_GET['letter'])) $_GET['letter'] = _ALL2;
156 if (empty($_GET['sortby'])) $_GET['sortby'] = "userid";
159 $OUT .= "<A href=\"".URL."/modules.php?module=admin&what=".$GLOBALS['what'];
161 // Add status or mode
162 if (!empty($_GET['status'])) $OUT .= "&mode=".SQL_ESCAPE($_GET['status']);
163 elseif (!empty($_GET['mode'])) $OUT .= "&mode=".SQL_ESCAPE($_GET['mode']);
166 $OUT .= "&letter=".SQL_ESCAPE($_GET['letter'])."&sortby=".SQL_ESCAPE($_GET['sortby'])."&page=".$page."&offset=".$offset."\">";
171 if (($page == $_GET['page']) || ((empty($_GET['page'])) && ($page == "1"))) {
172 $OUT .= "-</STRONG>";
177 if ($page < $PAGES) $OUT .= " | ";
180 define('__PAGENAV_LIST', $OUT);
183 $OUT = LOAD_TEMPLATE("admin_list_user_pagenav", true);
193 // Create email link to user's account
194 function USER_CREATE_EMAIL_LINK($email, $mod="admin") {
195 // Show contact link only if user is confirmed by default
196 $locked = " AND status='CONFIRMED'";
198 // But admins shall always see it
199 if (IS_ADMIN()) $locked = "";
201 $result = SQL_QUERY_ESC("SELECT userid
202 FROM "._MYSQL_PREFIX."_user_data
203 WHERE email='%s'".$locked." LIMIT 1",
204 array($email), __FILE__, __LINE__);
205 if (SQL_NUMROWS($result) == 1) {
207 list($uid) = SQL_FETCHROW($result);
209 // Rewrite email address to contact link
210 $email = URL."/modules.php?module=".$mod."&what=user_contct&u_id=".bigintval($uid);
214 SQL_FREERESULT($result);
216 // Return rewritten (?) email address
220 // Selects a random user id as the new referal id if they have at least X confirmed mails in this run
221 function SELECT_RANDOM_REFID () {
224 // Default is zero refid
227 // Is the extension version fine?
228 if (GET_EXT_VERSION("user") >= "0.3.4") {
230 $totalUsers = GET_TOTAL_DATA("CONFIRMED", "user_data", "userid", "status", true, " AND `rand_confirmed` >= ".getConfig('user_min_confirmed')."");
232 // Do we have at least one?
233 if ($totalUsers > 0) {
234 // Then choose random number
235 $randNum = mt_rand(0, ($totalUsers - 1));
237 // Look for random user
238 $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",
239 array(getConfig('user_min_confirmed'), $randNum), __FILE__, __LINE__);
241 // Do we have one entry there?
242 if (SQL_NUMROWS($result) == 1) {
243 // Use that userid as new referal id
244 list($refid) = SQL_FETCHROW($result);
246 // Reset this user's counter
247 SQL_QUERY_ESC("UPDATE `"._MYSQL_PREFIX."_user_data` SET `rand_confirmed`=0 WHERE userid=%s LIMIT 1",
248 array($refid), __FILE__, __LINE__);
252 SQL_FREERESULT($result);