source: extensions/LCAS/trunk/admin/LCAS_admin.php @ 9474

Last change on this file since 9474 was 9474, checked in by Eric, 13 years ago

bug 2208 re-fixed : Duplicate user control improvement on username update will work fine on this way (hopefully !)

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