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['LoginCaseAccentsSensitivity'] = serialize($newconf_LCAS); |
---|
49 | |
---|
50 | conf_update_param('LoginCaseAccentsSensitivity', |
---|
51 | pwg_db_real_escape_string($conf['LoginCaseAccentsSensitivity'])); |
---|
52 | |
---|
53 | array_push($page['infos'], l10n('LCAS_save_config')); |
---|
54 | } |
---|
55 | |
---|
56 | $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']); |
---|
57 | |
---|
58 | if (isset($conf_LCAS[0])) |
---|
59 | { |
---|
60 | $case_ins = ($conf_LCAS[0] == '1' or $conf_LCAS[0] == '3'); |
---|
61 | $acc_ins = ($conf_LCAS[0] == '2' or $conf_LCAS[0] == '3'); |
---|
62 | |
---|
63 | if ($case_ins or $acc_ins) |
---|
64 | { |
---|
65 | |
---|
66 | // +-----------------------------------------------------------------------+ |
---|
67 | // | user list | |
---|
68 | // +-----------------------------------------------------------------------+ |
---|
69 | |
---|
70 | $page['all_users'] = LCAS_get_user_list($conf_LCAS[0]); |
---|
71 | |
---|
72 | // +-----------------------------------------------------------------------+ |
---|
73 | // | initialization | |
---|
74 | // +-----------------------------------------------------------------------+ |
---|
75 | |
---|
76 | $lcas_UserToUpdate = -1; |
---|
77 | if ((isset($_POST['UserToUpdate'])) && ($_POST['UserToUpdate'] != -1)) { |
---|
78 | $lcas_UserToUpdate = $_POST['UserToUpdate']; |
---|
79 | |
---|
80 | if ((isset($_POST['user-'.$lcas_UserToUpdate])) && |
---|
81 | ($_POST['user-'.$lcas_UserToUpdate] != '')) { |
---|
82 | |
---|
83 | // Check if username already exists |
---|
84 | $lcas_previous_compare_user = |
---|
85 | LCAS_change_case($_POST['user-'.$lcas_UserToUpdate], $conf_LCAS[0]); |
---|
86 | |
---|
87 | $LCAS_users = array(); |
---|
88 | |
---|
89 | // This is a dirty request - Works fine for small number of users |
---|
90 | // but could be unoptimized for large number of users |
---|
91 | $query = ' |
---|
92 | SELECT '.$conf['user_fields']['username'].' AS username |
---|
93 | FROM '.USERS_TABLE.';'; |
---|
94 | |
---|
95 | $res = pwg_query($query); |
---|
96 | while ($r = pwg_db_fetch_assoc($res)) |
---|
97 | { |
---|
98 | $LCAS_users[$r['username']] = |
---|
99 | LCAS_change_case($r['username'], $conf_LCAS[0]); |
---|
100 | } |
---|
101 | |
---|
102 | $users_found = array_keys($LCAS_users, $lcas_previous_compare_user); |
---|
103 | |
---|
104 | if (count($users_found) < 1) |
---|
105 | { |
---|
106 | // Get old username before update - |
---|
107 | // Useful for user notification if is set |
---|
108 | $query =' |
---|
109 | SELECT username |
---|
110 | FROM '.USERS_TABLE.' |
---|
111 | WHERE id = '.$lcas_UserToUpdate.' |
---|
112 | ;'; |
---|
113 | |
---|
114 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
115 | |
---|
116 | // Username update |
---|
117 | $query = ' |
---|
118 | UPDATE '.USERS_TABLE.' |
---|
119 | SET username="'.pwg_db_real_escape_string($_POST['user-'.$lcas_UserToUpdate]).'" |
---|
120 | WHERE id='.$lcas_UserToUpdate.' |
---|
121 | LIMIT 1 |
---|
122 | ;'; |
---|
123 | |
---|
124 | pwg_query($query); |
---|
125 | |
---|
126 | if (isset($conf_LCAS[1]) and $conf_LCAS[1] == 'true') |
---|
127 | { |
---|
128 | LCAS_SendMail($lcas_UserToUpdate, $data['username'], |
---|
129 | $_POST['user-'.$lcas_UserToUpdate]); |
---|
130 | } |
---|
131 | |
---|
132 | // Reloading conflict table content |
---|
133 | $page['all_users'] = LCAS_get_user_list($conf_LCAS[0]); |
---|
134 | array_push($page['infos'], |
---|
135 | l10n('LCAS_Info_userlist_username_renamed')); |
---|
136 | } |
---|
137 | else |
---|
138 | { |
---|
139 | // Username already exists |
---|
140 | array_push( |
---|
141 | $page['errors'], |
---|
142 | l10n('LCAS_Err_Userlist_New_Username_Exists'). |
---|
143 | '<br>"'.$lcas_previous_compare_user.'"' |
---|
144 | ); |
---|
145 | } |
---|
146 | } |
---|
147 | else { |
---|
148 | // Username is empty |
---|
149 | array_push($page['errors'], |
---|
150 | l10n('LCAS_Err_Userlist_Empty_New_Username')); |
---|
151 | } |
---|
152 | } |
---|
153 | |
---|
154 | // +-----------------------------------------------------------------------+ |
---|
155 | // | user list | |
---|
156 | // +-----------------------------------------------------------------------+ |
---|
157 | |
---|
158 | $lcas_previous_compare_user = ''; |
---|
159 | $visible_user_list = array(); |
---|
160 | foreach ($page['all_users'] as $local_user) |
---|
161 | { |
---|
162 | if ($lcas_previous_compare_user != $local_user['transformed']) { |
---|
163 | $display = 'orange'; |
---|
164 | $lcas_previous_compare_user = $local_user['transformed']; |
---|
165 | } |
---|
166 | else { |
---|
167 | $display = ''; |
---|
168 | } |
---|
169 | |
---|
170 | $template->append( |
---|
171 | 'users', |
---|
172 | array( |
---|
173 | 'ID' => $local_user['id'], |
---|
174 | 'USERNAME' => stripslashes($local_user['username']), |
---|
175 | 'COMPARE' => stripslashes($local_user['transformed']), |
---|
176 | 'EMAIL' => $local_user['email'], |
---|
177 | 'DISPLAY' => $display, |
---|
178 | ) |
---|
179 | ); |
---|
180 | } |
---|
181 | } |
---|
182 | } |
---|
183 | |
---|
184 | |
---|
185 | // +-----------------------------------------------------------------------+ |
---|
186 | // | templates init | |
---|
187 | // +-----------------------------------------------------------------------+ |
---|
188 | $template->assign( |
---|
189 | array( |
---|
190 | 'LCAS_VERSION' => $version, |
---|
191 | 'LCAS_PATH' => LCAS_PATH, |
---|
192 | 'LCAS_PATH_ABS' => LCAS_PATH_ABS, |
---|
193 | 'LCAS_Option' => $conf_LCAS[0], |
---|
194 | 'LCAS_MAIL_TRUE' => $conf_LCAS[1] == 'true' ? 'checked = "checked"' : '' , |
---|
195 | 'LCAS_MAIL_FALSE' => $conf_LCAS[1] == 'false' ? 'checked = "checked"' : '' , |
---|
196 | 'LCAS_MAILTEXT' => $conf_LCAS[2] |
---|
197 | ) |
---|
198 | ); |
---|
199 | |
---|
200 | |
---|
201 | // +-----------------------------------------------------------------------+ |
---|
202 | // | errors display | |
---|
203 | // +-----------------------------------------------------------------------+ |
---|
204 | if (isset ($errors) and count($errors) != 0) |
---|
205 | { |
---|
206 | $template->assign('errors',array()); |
---|
207 | foreach ($errors as $error) |
---|
208 | { |
---|
209 | array_push($page['errors'], $error); |
---|
210 | } |
---|
211 | } |
---|
212 | |
---|
213 | // +-----------------------------------------------------------------------+ |
---|
214 | // | templates display | |
---|
215 | // +-----------------------------------------------------------------------+ |
---|
216 | $template->set_filename('plugin_admin_content', |
---|
217 | dirname(__FILE__) . '/template/global.tpl'); |
---|
218 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
219 | |
---|
220 | ?> |
---|