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

Last change on this file since 10549 was 10549, checked in by LucMorizur, 13 years ago

Code cleaning

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