]> git.mxchange.org Git - mailer.git/blob - 0.2.1/inc/libs/admins_functions.php
Code rewritings, load base config improved and many minor fixes...
[mailer.git] / 0.2.1 / inc / libs / admins_functions.php
1 <?php\r
2 /************************************************************************\r
3  * MXChange v0.2.1                                    Start: 06/30/2003 *\r
4  * ===============                              Last change: 11/27/2004 *\r
5  *                                                                      *\r
6  * -------------------------------------------------------------------- *\r
7  * File              : admins_functions.php                             *\r
8  * -------------------------------------------------------------------- *\r
9  * Short description : Functions for the admins extension               *\r
10  * -------------------------------------------------------------------- *\r
11  * Kurzbeschreibung  : Funktionen fuer die admins-Erweiterung           *\r
12  * -------------------------------------------------------------------- *\r
13  *                                                                      *\r
14  * -------------------------------------------------------------------- *\r
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *\r
16  * For more information visit: http://www.mxchange.org                  *\r
17  *                                                                      *\r
18  * This program is free software; you can redistribute it and/or modify *\r
19  * it under the terms of the GNU General Public License as published by *\r
20  * the Free Software Foundation; either version 2 of the License, or    *\r
21  * (at your option) any later version.                                  *\r
22  *                                                                      *\r
23  * This program is distributed in the hope that it will be useful,      *\r
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *\r
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *\r
26  * GNU General Public License for more details.                         *\r
27  *                                                                      *\r
28  * You should have received a copy of the GNU General Public License    *\r
29  * along with this program; if not, write to the Free Software          *\r
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *\r
31  * MA  02110-1301  USA                                                  *\r
32  ************************************************************************/\r
33 \r
34 // Some security stuff...\r
35 if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))\r
36 {\r
37         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";\r
38         require($INC);\r
39 }\r
40 //\r
41 function ADMINS_CHECK_ACL($act, $wht)\r
42 {\r
43         global $_COOKIE, $ADMINS, $ADMINS_ACLS, $CONFIG;\r
44         // If action is login or logout allow allways!\r
45         if (($act == "login") || ($act == "logout")) return true;\r
46 \r
47         // Default is deny\r
48         $ret = false;\r
49 \r
50         // Get admin's defult access right\r
51         if (!empty($ADMINS['def_acl'][$_COOKIE['admin_login']]))\r
52         {\r
53                 // Load from cache\r
54                 $default = $ADMINS['def_acl'][$_COOKIE['admin_login']];\r
55 \r
56                 // Count cache hits\r
57                 $CONFIG['cache_hits']++;\r
58         }\r
59          else\r
60         {\r
61                 // Load from database\r
62                 $result = SQL_QUERY_ESC("SELECT default_acl FROM "._MYSQL_PREFIX."_admins WHERE login='%s' LIMIT 1",\r
63                  array($_COOKIE['admin_login']), __FILE__, __LINE__);\r
64                 list($default) = SQL_FETCHROW($result);\r
65                 SQL_FREERESULT($result);\r
66         }\r
67 \r
68         // Get admin's ID\r
69         $aid = GET_ADMIN_ID($_COOKIE['admin_login']);\r
70 \r
71         if (!empty($wht))\r
72         {\r
73                 // Check for parent menu:\r
74                 // First get it's action value\r
75                 $parent_action = GET_ACTION("admin", $wht);\r
76 \r
77                 // Check with this function...\r
78                 $parent = ADMINS_CHECK_ACL($parent_action, "");\r
79         }\r
80          else\r
81         {\r
82                 // Anything else is true!\r
83                 $parent = false;\r
84         }\r
85 \r
86         // Shall I test for a main or sub menu? (action or what?)\r
87         $lines = 0; $acl_mode = "failed";\r
88         if (GET_EXT_VERSION("cache") >= "0.1.2")\r
89         {\r
90                 // Load only from array when there are lines!\r
91                 if (count($ADMINS_ACLS) > 0)\r
92                 {\r
93                         // Load ACL from array\r
94                         foreach ($ADMINS_ACLS['admin_id'] as $id=>$aid_acls)\r
95                         {\r
96                                 if ($aid == $aid_acls)\r
97                                 {\r
98                                         // Okay, one line was found!\r
99                                         if ((!empty($act)) && ($ADMINS_ACLS['action_menu'][$id] == $act))\r
100                                         {\r
101                                                 // Main menu line found\r
102                                                 $acl_mode = $ADMINS_ACLS['access_mode'][$id];\r
103                                                 $lines = 1;\r
104                                         }\r
105                                          elseif ((!empty($wht)) && ($ADMINS_ACLS['what_menu'][$id] == $wht))\r
106                                         {\r
107                                                 // Check sub menu\r
108                                                 $acl_mode = $ADMINS_ACLS['access_mode'][$id];\r
109                                                 $lines = 1;\r
110                                         }\r
111                                         if ($lines == 1)\r
112                                         {\r
113                                                 // Count cache hits\r
114                                                 $CONFIG['cache_hits']++;\r
115                                                 break;\r
116                                         }\r
117                                 }\r
118                         }\r
119 \r
120                         // No ACL found?\r
121                         if ($acl_mode == "failed")\r
122                         {\r
123                                 $acl_mode = "";\r
124                                 $lines = 0;\r
125                         }\r
126                 }\r
127                  else\r
128                 {\r
129                         // No lines here\r
130                         $lines = 0;\r
131                 }\r
132         }\r
133          else\r
134         {\r
135                 // Old version, so load it from database\r
136                 if (!empty($act))\r
137                 {\r
138                         // Main menu\r
139                         $result = SQL_QUERY_ESC("SELECT access_mode FROM "._MYSQL_PREFIX."_admins_acls WHERE admin_id=%d AND action_menu='%s' LIMIT 1",\r
140                          array(bigintval($aid), $act), __FILE__, __LINE__);\r
141                 }\r
142                  elseif (!empty($wht))\r
143                 {\r
144                         // Sub menu\r
145                         $result = SQL_QUERY_ESC("SELECT access_mode FROM "._MYSQL_PREFIX."_admins_acls WHERE admin_id=%d AND what_menu='%s' LIMIT 1",\r
146                          array(bigintval($aid), $wht), __FILE__, __LINE__);\r
147                 }\r
148 \r
149                 // Get number of lines\r
150                 $lines = SQL_NUMROWS($result);\r
151 \r
152                 // Load ACL\r
153                 list($acl_mode) = SQL_FETCHROW($result);\r
154                 SQL_FREERESULT($result);\r
155         }\r
156 \r
157         // Check ACL and (maybe) allow\r
158         if ((($default == "allow") && ($lines == 0)) || (($default == "deny") && ($lines == "1") && ($acl_mode == "allow")) || (($lines == 0) && ($parent))) $ret = true;\r
159 \r
160         // Return value\r
161         return $ret;\r
162 }\r
163 // Create email link to admins's account\r
164 function ADMINS_CREATE_EMAIL_LINK($email, $mod="admin")\r
165 {\r
166         $locked = " AND status='CONFIRMED'";\r
167         if (IS_ADMIN()) $locked = "";\r
168         if (strpos("@", $email) > 0)\r
169         {\r
170                 // Create email link\r
171                 $result = SQL_QUERY_ESC("SELECT id\r
172 FROM "._MYSQL_PREFIX."_admins\r
173 WHERE email='%s'".$locked." LIMIT 1",\r
174  array($email), __FILE__, __LINE__);\r
175                 if (SQL_NUMROWS($result) == 1)\r
176                 {\r
177                         // Load userid\r
178                         list($uid) = SQL_FETCHROW($result);\r
179 \r
180                         // Rewrite email address to contact link\r
181                         $email = URL."/modules.php?module=".$mod."&amp;what=user_contct&amp;u_id=".bigintval($uid);\r
182                 }\r
183 \r
184                 // Free memory\r
185                 SQL_FREERESULT($result);\r
186         }\r
187          elseif (bigintval($email) > 0)\r
188         {\r
189                 // Direct ID given\r
190                 $email = URL."/modules.php?module=".$mod."&amp;what=admins_contct&amp;admin=".bigintval($email);\r
191         }\r
192 \r
193         // Return rewritten (?) email address\r
194         return $email;\r
195 }\r
196 //\r
197 ?>\r