1 | <?php |
---|
2 | |
---|
3 | global $user, $lang, $conf, $errors; |
---|
4 | |
---|
5 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | Check Access and exit when user status is not ok | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | check_status(ACCESS_ADMINISTRATOR); |
---|
10 | |
---|
11 | if (!defined('LCAS_PATH')) |
---|
12 | define('LCAS_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
13 | if (!defined('LCAS_PATH_ABS')) |
---|
14 | define('LCAS_PATH_ABS' , dirname(__FILE__).'/'); |
---|
15 | |
---|
16 | //ini_set('error_reporting', E_ALL); |
---|
17 | //ini_set('display_errors', true); |
---|
18 | |
---|
19 | include_once(PHPWG_ROOT_PATH.'include/constants.php'); |
---|
20 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
21 | $my_base_url = get_admin_plugin_menu_link(__FILE__); |
---|
22 | |
---|
23 | load_language('plugin.lang', LCAS_PATH); |
---|
24 | load_language('help.lang', LCAS_PATH); |
---|
25 | |
---|
26 | $error = array(); |
---|
27 | |
---|
28 | // +-----------------------------------------------------------------------+ |
---|
29 | // | Getting plugin version | |
---|
30 | // +-----------------------------------------------------------------------+ |
---|
31 | $plugin = LCAS_PluginInfos(LCAS_PATH); |
---|
32 | $version = $plugin['version']; |
---|
33 | |
---|
34 | if (isset($_POST['submit']) |
---|
35 | and isset($_POST['LCAS_Option']) |
---|
36 | and isset($_POST['LCAS_Mail'])) |
---|
37 | { |
---|
38 | |
---|
39 | /* General configuration settings */ |
---|
40 | $_POST['LCAS_MailText'] = str_replace('\"', '"', str_replace("\'", "'", |
---|
41 | str_replace("\\\\", "\\", $_POST['LCAS_MailText']))); |
---|
42 | |
---|
43 | $newconf_LCAS= array( |
---|
44 | $_POST['LCAS_Option'], |
---|
45 | $_POST['LCAS_Mail'], |
---|
46 | $_POST['LCAS_MailText']); |
---|
47 | |
---|
48 | conf_update_param('LoginCaseAccentsSensitivity', pwg_db_real_escape_string(serialize($newconf_LCAS))); |
---|
49 | |
---|
50 | array_push($page['infos'], l10n('LCAS_save_config')); |
---|
51 | } |
---|
52 | |
---|
53 | $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']); |
---|
54 | |
---|
55 | if (isset($conf_LCAS[0])) |
---|
56 | { |
---|
57 | $case_ins = ($conf_LCAS[0] == '1' or $conf_LCAS[0] == '3'); |
---|
58 | $acc_ins = ($conf_LCAS[0] == '2' or $conf_LCAS[0] == '3'); |
---|
59 | |
---|
60 | if ($case_ins or $acc_ins) |
---|
61 | { |
---|
62 | |
---|
63 | // +-----------------------------------------------------------------------+ |
---|
64 | // | user list | |
---|
65 | // +-----------------------------------------------------------------------+ |
---|
66 | |
---|
67 | $page['all_users'] = LCAS_get_user_list($conf_LCAS[0]); |
---|
68 | |
---|
69 | // +-----------------------------------------------------------------------+ |
---|
70 | // | initialization | |
---|
71 | // +-----------------------------------------------------------------------+ |
---|
72 | |
---|
73 | $lcas_UserToUpdate = -1; |
---|
74 | if ((isset($_POST['UserToUpdate'])) && ($_POST['UserToUpdate'] != -1)) { |
---|
75 | $lcas_UserToUpdate = $_POST['UserToUpdate']; |
---|
76 | |
---|
77 | if ((isset($_POST['user-'.$lcas_UserToUpdate])) && |
---|
78 | ($_POST['user-'.$lcas_UserToUpdate] != '')) { |
---|
79 | |
---|
80 | // Check if username already exists |
---|
81 | $lcas_previous_compare_user = |
---|
82 | LCAS_change_case($_POST['user-'.$lcas_UserToUpdate], $conf_LCAS[0]); |
---|
83 | |
---|
84 | $LCAS_users = array(); |
---|
85 | |
---|
86 | // This is a dirty request - Works fine for small number of users |
---|
87 | // but could be unoptimized for large number of users |
---|
88 | $query = ' |
---|
89 | SELECT '.$conf['user_fields']['username'].' AS username |
---|
90 | FROM '.USERS_TABLE.';'; |
---|
91 | |
---|
92 | $res = pwg_query($query); |
---|
93 | while ($r = pwg_db_fetch_assoc($res)) |
---|
94 | { |
---|
95 | $LCAS_users[$r['username']] = |
---|
96 | LCAS_change_case($r['username'], $conf_LCAS[0]); |
---|
97 | } |
---|
98 | |
---|
99 | $users_found = array_keys($LCAS_users, $lcas_previous_compare_user); |
---|
100 | |
---|
101 | if (count($users_found) < 1) |
---|
102 | { |
---|
103 | // Get old username before update - |
---|
104 | // Useful for user notification if is set |
---|
105 | $query =' |
---|
106 | SELECT username |
---|
107 | FROM '.USERS_TABLE.' |
---|
108 | WHERE id = '.$lcas_UserToUpdate.' |
---|
109 | ;'; |
---|
110 | |
---|
111 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
112 | |
---|
113 | // Username update |
---|
114 | $query = ' |
---|
115 | UPDATE '.USERS_TABLE.' |
---|
116 | SET username="'.pwg_db_real_escape_string($_POST['user-'.$lcas_UserToUpdate]).'" |
---|
117 | WHERE id='.$lcas_UserToUpdate.' |
---|
118 | LIMIT 1 |
---|
119 | ;'; |
---|
120 | |
---|
121 | pwg_query($query); |
---|
122 | |
---|
123 | if (isset($conf_LCAS[1]) and $conf_LCAS[1] == 'true') |
---|
124 | { |
---|
125 | LCAS_SendMail($lcas_UserToUpdate, $data['username'], |
---|
126 | $_POST['user-'.$lcas_UserToUpdate]); |
---|
127 | } |
---|
128 | |
---|
129 | // Reloading conflict table content |
---|
130 | $page['all_users'] = LCAS_get_user_list($conf_LCAS[0]); |
---|
131 | array_push($page['infos'], |
---|
132 | l10n('LCAS_Info_userlist_username_renamed')); |
---|
133 | } |
---|
134 | else |
---|
135 | { |
---|
136 | // Username already exists |
---|
137 | array_push( |
---|
138 | $page['errors'], |
---|
139 | l10n('LCAS_Err_Userlist_New_Username_Exists'). |
---|
140 | '<br>"'.$lcas_previous_compare_user.'"' |
---|
141 | ); |
---|
142 | } |
---|
143 | } |
---|
144 | else { |
---|
145 | // Username is empty |
---|
146 | array_push($page['errors'], |
---|
147 | l10n('LCAS_Err_Userlist_Empty_New_Username')); |
---|
148 | } |
---|
149 | } |
---|
150 | |
---|
151 | // +-----------------------------------------------------------------------+ |
---|
152 | // | user list | |
---|
153 | // +-----------------------------------------------------------------------+ |
---|
154 | |
---|
155 | $lcas_previous_compare_user = ''; |
---|
156 | $visible_user_list = array(); |
---|
157 | foreach ($page['all_users'] as $local_user) |
---|
158 | { |
---|
159 | if ($lcas_previous_compare_user != $local_user['transformed']) { |
---|
160 | $display = 'orange'; |
---|
161 | $lcas_previous_compare_user = $local_user['transformed']; |
---|
162 | } |
---|
163 | else { |
---|
164 | $display = ''; |
---|
165 | } |
---|
166 | |
---|
167 | $template->append( |
---|
168 | 'users', |
---|
169 | array( |
---|
170 | 'ID' => $local_user['id'], |
---|
171 | 'USERNAME' => stripslashes($local_user['username']), |
---|
172 | 'COMPARE' => stripslashes($local_user['transformed']), |
---|
173 | 'EMAIL' => |
---|
174 | get_email_address_as_display_text($local_user['email']), |
---|
175 | 'DISPLAY' => $display, |
---|
176 | ) |
---|
177 | ); |
---|
178 | } |
---|
179 | } |
---|
180 | } |
---|
181 | |
---|
182 | |
---|
183 | // +-----------------------------------------------------------------------+ |
---|
184 | // | templates init | |
---|
185 | // +-----------------------------------------------------------------------+ |
---|
186 | $template->assign( |
---|
187 | array( |
---|
188 | 'LCAS_VERSION' => $version, |
---|
189 | 'LCAS_PATH' => LCAS_PATH, |
---|
190 | 'PHPWG_VERSION' => PHPWG_VERSION, |
---|
191 | 'LCAS_PATH_ABS' => LCAS_PATH_ABS, |
---|
192 | 'LCAS_Option' => $conf_LCAS[0], |
---|
193 | 'LCAS_MAIL_TRUE' => $conf_LCAS[1] == 'true' ? 'checked = "checked"' : '' , |
---|
194 | 'LCAS_MAIL_FALSE' => $conf_LCAS[1] == 'false' ? 'checked = "checked"' : '' , |
---|
195 | 'LCAS_MAILTEXT' => $conf_LCAS[2] |
---|
196 | ) |
---|
197 | ); |
---|
198 | |
---|
199 | |
---|
200 | // +-----------------------------------------------------------------------+ |
---|
201 | // | errors display | |
---|
202 | // +-----------------------------------------------------------------------+ |
---|
203 | if (isset ($errors) and count($errors) != 0) |
---|
204 | { |
---|
205 | $template->assign('errors',array()); |
---|
206 | foreach ($errors as $error) |
---|
207 | { |
---|
208 | array_push($page['errors'], $error); |
---|
209 | } |
---|
210 | } |
---|
211 | |
---|
212 | // +-----------------------------------------------------------------------+ |
---|
213 | // | templates display | |
---|
214 | // +-----------------------------------------------------------------------+ |
---|
215 | $template->set_filename('plugin_admin_content', |
---|
216 | dirname(__FILE__) . '/template/global.tpl'); |
---|
217 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
218 | |
---|
219 | ?> |
---|