Entire rewrite of mail part in app! Not kidding here...
[mailer.git] / inc / libs / user_functions.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 07/16/2004 *
4  * ===============                              Last change: 10/27/2004 *
5  *                                                                      *
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  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
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.                                  *
22  *                                                                      *
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.                         *
27  *                                                                      *
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,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 function alpha($sortby, $colspan, $return=false)
41 {
42         global $_CONFIG;
43         if (empty($_GET['offset'])) $_GET['offset'] = 0;
44         $ADD = "&amp;page=".$_GET['page']."&amp;offset=".$_GET['offset'];
45         if (!empty($_GET['mode'])) $ADD .= "&amp;mode=".SQL_ESCAPE($_GET['mode']);
46
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;
50         $OUT = "";
51         while (list($counter, $ltr) = each($alphabet))
52         {
53                 if ($_GET['letter'] == $ltr)
54                 {
55                         // Current letter is letter from URL
56                         $OUT .= "<STRONG>".$ltr."</STRONG>";
57                 }
58                  else
59                 {
60                         // Output link to letter
61                         $OUT .= "<A href=\"".URL."/modules.php?module=admin&amp;what=".$GLOBALS['what'];
62                         if (!empty($_GET['mode'])) $OUT .= "&amp;mode=".SQL_ESCAPE($_GET['mode']);
63                         $OUT .= "&amp;letter=".$ltr."&amp;sortby=".$sortby.$ADD."\">".$ltr."</A>";
64                 }
65                 if ((($counter / $_CONFIG['user_alpha']) == round($counter / $_CONFIG['user_alpha'])) && ($counter > 0))
66                 {
67                         $OUT .= "&nbsp;]<br />[&nbsp;";
68                 }
69                  elseif ( $counter != $num )
70                 {
71                         $OUT .= "&nbsp;|&nbsp;";
72                 }
73         }
74         define('__ALPHA_LIST', $OUT);
75
76         // Load template
77         $OUT = LOAD_TEMPLATE("admin_list_user_alpha", true);
78         if ($return)
79         {
80                 // Return generated code
81                 return $OUT;
82         }
83          else
84         {
85                 // Output generated code
86                 OUTPUT_HTML($OUT);
87         }
88 }
89 //
90 function SortLinks($letter, $sortby, $colspan, $return=false)
91 {
92         $OUT = "";
93         if (empty($_GET['offset'])) $_GET['offset'] = 0;
94         $ADD = "&amp;page=".$_GET['page']."&amp;offset=".$_GET['offset'];
95         if (!empty($_GET['mode'])) $ADD .= "&amp;mode=".SQL_ESCAPE($_GET['mode']);
96
97         // Makes order by links..
98         if ($letter == "front") $letter = _ALL2;
99
100         // Prepare array with all possible sorters
101         $list = array(
102                 'userid'                => _UID,
103                 'family'                => FAMILY_NAME,
104                 'email'         => ADDY,
105                 'REMOTE_ADDR'   => REMOTE_IP
106         );
107
108         // Add nickname if extension is installed
109         if (EXT_IS_ACTIVE("nickname")) {
110                 $list['nickname'] = NICKNAME;
111         }
112
113         foreach ($list as $sort => $title) {
114                 if ($sortby == $sort) {
115                         $OUT .= "<STRONG>".$title."</STRONG>&nbsp;|&nbsp;";
116                 } else {
117                         $OUT .= "<A href=\"".URL."/modules.php?module=admin&amp;what=list_user&amp;letter=".$letter."&amp;sortby=".$sort.$ADD."\">".$title."</a>&nbsp;|&nbsp;";
118                 }
119         }
120         define('__SORT_LIST', substr($OUT, 0, -13));
121
122         // Load template
123         $OUT = LOAD_TEMPLATE("admin_list_user_sort", true);
124         if ($return)
125         {
126                 // Return code
127                 return $OUT;
128         }
129          else
130         {
131                 // Output code
132                 OUTPUT_HTML($OUT);
133         }
134 }
135 //
136 function ADD_PAGENAV($PAGES, $offset, $show_form, $colspan,$return=false)
137 {
138         if (!$show_form)
139         {
140                 // Empty row
141                 define('__FORM_HEADER', "<TR><TD colspan=\"".$colspan."\" class=\"seperator\">&nbsp;</TD></TR>");
142         }
143          else
144         {
145                 // Load form for changing number of lines
146                 define('__FORM_HEADER', LOAD_TEMPLATE("admin_list_user_sort_form", true));
147         }
148         if (!$show_form)
149         {
150                 // Add line with bottom border
151                 define('__FORM_FOOTER', "<TR><TD colspan=\"".__COLSPAN2."\" class=\"seperator bottom2\">&nbsp;</TD></TR>");
152         }
153          else
154         {
155                 // Add line without bottom border
156                 define('__FORM_FOOTER', "<TR><TD colspan=\"".__COLSPAN2."\" class=\"seperator bottom2\">&nbsp;</TD></TR>");
157         }
158
159         $OUT = "";
160         for ($page = 1; $page <= $PAGES; $page++)
161         {
162                 if (($page == $_GET['page']) || ((empty($_GET['page'])) && ($page == "1")))
163                 {
164                         $OUT .= "<STRONG>-";
165                 }
166                  else
167                 {
168                         if (empty($_GET['letter'])) $_GET['letter'] = _ALL2;
169                         if (empty($_GET['sortby'])) $_GET['sortby'] = "userid";
170                         $OUT .= "<A href=\"".URL."/modules.php?module=admin&amp;what=".$GLOBALS['what'];
171                         if (!empty($_GET['mode'])) $OUT .= "&amp;mode=".SQL_ESCAPE($_GET['mode']);
172                         $OUT .= "&amp;letter=".$_GET['letter']."&amp;sortby=".$_GET['sortby']."&amp;page=".$page."&amp;offset=".$offset."\">";
173                 }
174                 $OUT .= $page;
175                 if (($page == $_GET['page']) || ((empty($_GET['page'])) && ($page == "1")))
176                 {
177                         $OUT .= "-</STRONG>";
178                 }
179                  else
180                 {
181                         $OUT .= "</A>";
182                 }
183                 if ($page < $PAGES) $OUT .= "&nbsp;|&nbsp;";
184         }
185         define('__PAGENAV_LIST', $OUT);
186
187         // Load template
188         $OUT = LOAD_TEMPLATE("admin_list_user_pagenav", true);
189         if ($return)
190         {
191                 // Return code
192                 return $OUT;
193         }
194          else
195         {
196                 // Output code
197                 OUTPUT_HTML($OUT);
198         }
199 }
200 // Create email link to user's account
201 function USER_CREATE_EMAIL_LINK($email, $mod="admin")
202 {
203         $locked = " AND status='CONFIRMED'";
204         if (IS_ADMIN()) $locked = "";
205         $result = SQL_QUERY_ESC("SELECT userid
206 FROM "._MYSQL_PREFIX."_user_data
207 WHERE email='%s'".$locked." LIMIT 1",
208          array($email), __FILE__, __LINE__);
209         if (SQL_NUMROWS($result) == 1)
210         {
211                 // Load userid
212                 list($uid) = SQL_FETCHROW($result);
213
214                 // Rewrite email address to contact link
215                 $email = URL."/modules.php?module=".$mod."&amp;what=user_contct&amp;u_id=".bigintval($uid);
216         }
217
218         // Free memory
219         SQL_FREERESULT($result);
220
221         // Return rewritten (?) email address
222         return $email;
223 }
224 //
225 ?>