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