1 | <?php |
---|
2 | // Keeps file coded in UTF-8 without BOM: é |
---|
3 | |
---|
4 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
5 | |
---|
6 | global $template, $conf, $page; |
---|
7 | |
---|
8 | $conf_LCAS = unserialize($conf['LoginCaseAccentsSensitivity']); |
---|
9 | |
---|
10 | /** |
---|
11 | * Add users and manage users list according to LCAS plugin |
---|
12 | * ( http://piwigo.org/ext/extension_view.php?eid=513 ) |
---|
13 | */ |
---|
14 | |
---|
15 | // +-----------------------------------------------------------------------+ |
---|
16 | // | functions | |
---|
17 | // +-----------------------------------------------------------------------+ |
---|
18 | |
---|
19 | /** |
---|
20 | * returns a list of users depending on page filters (in $_GET) |
---|
21 | * |
---|
22 | * Each user comes with his related informations : id, username, mail |
---|
23 | * address, list of groups. |
---|
24 | * |
---|
25 | * @return array |
---|
26 | */ |
---|
27 | function LCAS_get_filtered_user_list() |
---|
28 | { |
---|
29 | global $conf, $page, $conf_LCAS; |
---|
30 | |
---|
31 | $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']); |
---|
32 | |
---|
33 | $users = array(); |
---|
34 | $users_t1 = array(); |
---|
35 | |
---|
36 | // filter |
---|
37 | $filter = array(); |
---|
38 | |
---|
39 | // Build a PHP regex both complying to user's request, and to LCAS current |
---|
40 | // rule |
---|
41 | $username= preg_replace(array('/^\*/', '/\*$/'), '%', $_GET['username']); |
---|
42 | if (preg_match('/%$/', $username)) |
---|
43 | $username = preg_replace('/%$/', '/', $username); |
---|
44 | else |
---|
45 | $username.= '$/'; |
---|
46 | if (preg_match('/^%/', $username)) |
---|
47 | $username = preg_replace('/^%/', '/', $username); |
---|
48 | else |
---|
49 | $username = '/^'.$username; |
---|
50 | $filter['username'] = |
---|
51 | pwg_db_real_escape_string(LCAS_change_case($username, $conf_LCAS[0])); |
---|
52 | |
---|
53 | if (isset($_GET['group']) |
---|
54 | and -1 != $_GET['group'] |
---|
55 | and is_numeric($_GET['group'])) |
---|
56 | { |
---|
57 | $filter['group'] = $_GET['group']; |
---|
58 | } |
---|
59 | |
---|
60 | if (isset($_GET['status']) |
---|
61 | and in_array($_GET['status'], get_enums(USER_INFOS_TABLE, 'status'))) |
---|
62 | { |
---|
63 | $filter['status'] = $_GET['status']; |
---|
64 | } |
---|
65 | |
---|
66 | // how to order the list? |
---|
67 | $order_by = 'id'; |
---|
68 | if (isset($_GET['order_by']) |
---|
69 | and in_array($_GET['order_by'], array_keys($page['order_by_items']))) |
---|
70 | { |
---|
71 | $order_by = $_GET['order_by']; |
---|
72 | } |
---|
73 | |
---|
74 | $direction = 'ASC'; |
---|
75 | if (isset($_GET['direction']) |
---|
76 | and in_array($_GET['direction'], array_keys($page['direction_items']))) |
---|
77 | { |
---|
78 | $direction = strtoupper($_GET['direction']); |
---|
79 | } |
---|
80 | |
---|
81 | // search users depending on filters and order |
---|
82 | $query = ' |
---|
83 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
84 | u.'.$conf['user_fields']['username'].' AS username, |
---|
85 | u.'.$conf['user_fields']['email'].' AS email, |
---|
86 | ui.status, |
---|
87 | ui.enabled_high, |
---|
88 | ui.level |
---|
89 | FROM '.USERS_TABLE.' AS u |
---|
90 | INNER JOIN '.USER_INFOS_TABLE.' AS ui |
---|
91 | ON u.'.$conf['user_fields']['id'].' = ui.user_id |
---|
92 | LEFT JOIN '.USER_GROUP_TABLE.' AS ug |
---|
93 | ON u.'.$conf['user_fields']['id'].' = ug.user_id |
---|
94 | WHERE u.'.$conf['user_fields']['id'].' > 0'; |
---|
95 | |
---|
96 | if (isset($filter['group'])) |
---|
97 | { |
---|
98 | $query.= ' |
---|
99 | AND ug.group_id = '.$filter['group']; |
---|
100 | } |
---|
101 | if (isset($filter['status'])) |
---|
102 | { |
---|
103 | $query.= ' |
---|
104 | AND ui.status = \''.$filter['status']."'"; |
---|
105 | } |
---|
106 | $query.= ' |
---|
107 | ORDER BY '.$order_by.' '.$direction.' |
---|
108 | ;'; |
---|
109 | |
---|
110 | $result = pwg_query($query); |
---|
111 | while ($row = pwg_db_fetch_assoc($result)) |
---|
112 | { |
---|
113 | $user = $row; |
---|
114 | $user['groups'] = array(); |
---|
115 | |
---|
116 | array_push($users, $user); |
---|
117 | } |
---|
118 | |
---|
119 | // add group lists |
---|
120 | $user_ids = array(); |
---|
121 | foreach ($users as $i => $user) |
---|
122 | { |
---|
123 | $user_ids[$i] = $user['id']; |
---|
124 | } |
---|
125 | $user_nums = array_flip($user_ids); |
---|
126 | |
---|
127 | if (count($user_ids) > 0) |
---|
128 | { |
---|
129 | $query = ' |
---|
130 | SELECT user_id, group_id |
---|
131 | FROM '.USER_GROUP_TABLE.' |
---|
132 | WHERE user_id IN ('.implode(',', $user_ids).') |
---|
133 | ;'; |
---|
134 | $result = pwg_query($query); |
---|
135 | while ($row = pwg_db_fetch_assoc($result)) |
---|
136 | { |
---|
137 | array_push( |
---|
138 | $users[$user_nums[$row['user_id']]]['groups'], |
---|
139 | $row['group_id'] |
---|
140 | ); |
---|
141 | } |
---|
142 | } |
---|
143 | |
---|
144 | // $users is now all usernames matching all filters but the username |
---|
145 | // filter |
---|
146 | // Username filter applied now: convert all found usernames with current |
---|
147 | // LCAS rule, and compare to LCAS-converted filter on username |
---|
148 | foreach ($users as $user) if (preg_match( |
---|
149 | $filter['username'], LCAS_change_case($user['username'], $conf_LCAS[0]) |
---|
150 | )) $users_t1[] = $user; |
---|
151 | |
---|
152 | return $users_t1; |
---|
153 | } |
---|
154 | |
---|
155 | // +-----------------------------------------------------------------------+ |
---|
156 | // | initialization | |
---|
157 | // +-----------------------------------------------------------------------+ |
---|
158 | |
---|
159 | if (!defined('PHPWG_ROOT_PATH')) |
---|
160 | { |
---|
161 | die('Hacking attempt!'); |
---|
162 | } |
---|
163 | |
---|
164 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
165 | |
---|
166 | // +-----------------------------------------------------------------------+ |
---|
167 | // | user list | |
---|
168 | // +-----------------------------------------------------------------------+ |
---|
169 | |
---|
170 | $page['filtered_users'] = LCAS_get_filtered_user_list(); |
---|
171 | |
---|
172 | // +-----------------------------------------------------------------------+ |
---|
173 | // | groups list | |
---|
174 | // +-----------------------------------------------------------------------+ |
---|
175 | |
---|
176 | $groups[-1] = '------------'; |
---|
177 | |
---|
178 | $query = ' |
---|
179 | SELECT id, name |
---|
180 | FROM '.GROUPS_TABLE.' |
---|
181 | ORDER BY name ASC |
---|
182 | ;'; |
---|
183 | $result = pwg_query($query); |
---|
184 | |
---|
185 | while ($row = pwg_db_fetch_assoc($result)) |
---|
186 | { |
---|
187 | $groups[$row['id']] = $row['name']; |
---|
188 | } |
---|
189 | |
---|
190 | // +-----------------------------------------------------------------------+ |
---|
191 | // | template init | |
---|
192 | // +-----------------------------------------------------------------------+ |
---|
193 | |
---|
194 | $base_url = PHPWG_ROOT_PATH.'admin.php?page=user_list'; |
---|
195 | |
---|
196 | if (isset($_GET['start']) and is_numeric($_GET['start'])) |
---|
197 | { |
---|
198 | $start = $_GET['start']; |
---|
199 | } |
---|
200 | else |
---|
201 | { |
---|
202 | $start = 0; |
---|
203 | } |
---|
204 | |
---|
205 | $template->assign( |
---|
206 | 'F_USERNAME', @htmlentities($_GET['username'], ENT_COMPAT, 'UTF-8') |
---|
207 | ); |
---|
208 | |
---|
209 | $profile_url = get_root_url().'admin.php?page=profile&user_id='; |
---|
210 | $perm_url = get_root_url().'admin.php?page=user_perm&user_id='; |
---|
211 | |
---|
212 | $visible_user_list = array(); |
---|
213 | foreach ($page['filtered_users'] as $num => $local_user) |
---|
214 | { |
---|
215 | // simulate LIMIT $start, $conf['users_page'] |
---|
216 | if ($num < $start) |
---|
217 | { |
---|
218 | continue; |
---|
219 | } |
---|
220 | if ($num >= $start + $conf['users_page']) |
---|
221 | { |
---|
222 | break; |
---|
223 | } |
---|
224 | |
---|
225 | $visible_user_list[] = $local_user; |
---|
226 | } |
---|
227 | |
---|
228 | |
---|
229 | $template->append('footer_elements', '<p>lskskjsleektjtj1</p>'); |
---|
230 | $template->append('footer_elements', '<p>str_from_var2($visible_user_list) (1): '.str_from_var2($visible_user_list).'</p>'); |
---|
231 | |
---|
232 | |
---|
233 | |
---|
234 | // Reset TPL variables |
---|
235 | $template->smarty->_tpl_vars['users'] = array(); |
---|
236 | $template->smarty->_tpl_vars['plugin_columns'] = array(); |
---|
237 | $template->smarty->_tpl_vars['plugin_actions'] = array(); |
---|
238 | |
---|
239 | // allow plugins to fill template var plugin_user_list_column_titles and |
---|
240 | // plugin_columns/plugin_actions for each user in the list |
---|
241 | $visible_user_list = trigger_event('loc_visible_user_list', $visible_user_list); |
---|
242 | |
---|
243 | $template->append('footer_elements', '<p>str_from_var2($visible_user_list) (2): '.str_from_var2($visible_user_list).'</p>'); |
---|
244 | |
---|
245 | |
---|
246 | foreach ($visible_user_list as $local_user) |
---|
247 | { |
---|
248 | $groups_string = preg_replace( |
---|
249 | '/(\d+)/e', |
---|
250 | "\$groups['$1']", |
---|
251 | implode( |
---|
252 | ', ', |
---|
253 | $local_user['groups'] |
---|
254 | ) |
---|
255 | ); |
---|
256 | |
---|
257 | if (isset($_POST['pref_submit']) |
---|
258 | and isset($_POST['selection']) |
---|
259 | and in_array($local_user['id'], $_POST['selection'])) |
---|
260 | { |
---|
261 | $checked = 'checked="checked"'; |
---|
262 | } |
---|
263 | else |
---|
264 | { |
---|
265 | $checked = ''; |
---|
266 | } |
---|
267 | |
---|
268 | $properties = array(); |
---|
269 | if ( $local_user['level'] != 0 ) |
---|
270 | { |
---|
271 | $properties[] = l10n( sprintf('Level %d', $local_user['level']) ); |
---|
272 | } |
---|
273 | $properties[] = |
---|
274 | (isset($local_user['enabled_high']) and ($local_user['enabled_high'] == 'true')) |
---|
275 | ? l10n('High definition') : l10n(''); |
---|
276 | |
---|
277 | $template->append( |
---|
278 | 'users', |
---|
279 | array( |
---|
280 | 'ID' => $local_user['id'], |
---|
281 | 'CHECKED' => $checked, |
---|
282 | 'U_PROFILE' => $profile_url.$local_user['id'], |
---|
283 | 'U_PERM' => $perm_url.$local_user['id'], |
---|
284 | 'USERNAME' => stripslashes($local_user['username']) |
---|
285 | .($local_user['id'] == $conf['guest_id'] |
---|
286 | ? '<br>['.l10n('guest').']' : '') |
---|
287 | .($local_user['id'] == $conf['default_user_id'] |
---|
288 | ? '<br>['.l10n('default values').']' : ''), |
---|
289 | 'STATUS' => l10n('user_status_'.$local_user['status']), |
---|
290 | 'EMAIL' => get_email_address_as_display_text($local_user['email']), |
---|
291 | 'GROUPS' => $groups_string, |
---|
292 | 'PROPERTIES' => implode( ', ', $properties), |
---|
293 | 'plugin_columns' => isset($local_user['plugin_columns']) ? $local_user['plugin_columns'] : array(), |
---|
294 | 'plugin_actions' => isset($local_user['plugin_actions']) ? $local_user['plugin_actions'] : array(), |
---|
295 | ) |
---|
296 | ); |
---|
297 | } |
---|
298 | |
---|
299 | $template->append('footer_elements', '<p>str_from_var2($template->smarty->_tpl_vars[users] : '.str_from_var2($template->smarty->_tpl_vars['users']).'</p>'); |
---|
300 | |
---|
301 | |
---|
302 | $template->append('footer_elements', '<p>lskskjsleektjtj2</p><p>lskskjsleektjtj2</p><p>lskskjsleektjtj2</p><p>lskskjsleektjtj2</p>'); |
---|
303 | |
---|
304 | |
---|
305 | // +-----------------------------------------------------------------------+ |
---|
306 | // | html code display | |
---|
307 | // +-----------------------------------------------------------------------+ |
---|
308 | |
---|
309 | $template->assign_var_from_handle('ADMIN_CONTENT', 'user_list'); |
---|
310 | ?> |
---|