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

Last change on this file since 8164 was 8164, checked in by Whiler, 13 years ago

Usernames can be renamed (check for already existing is missing ; BTW, it works)

File size: 9.7 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__)).'/');
12
13//ini_set('error_reporting', E_ALL);
14//ini_set('display_errors', true);
15
16include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
17include_once (PHPWG_ROOT_PATH.'/include/constants.php');
18$my_base_url = get_admin_plugin_menu_link(__FILE__);
19
20load_language('plugin.lang', LCAS_PATH);
21load_language('help/plugin.lang', LCAS_PATH);
22
23$page['global'] = array();
24$error = array();
25$pattern = '/;/';
26$replacement = '.';
27
28$LCAS_Password_Test_Score = 0;
29$LCAS_Exclusionlist_Error = false;
30
31// +-----------------------------------------------------------------------+
32// |                            Tabssheet                                  |
33// +-----------------------------------------------------------------------+
34if (!isset($_GET['tab']))
35        $page['tab'] = 'global';
36else
37  $page['tab'] = $_GET['tab'];
38
39$tabsheet = new tabsheet();
40$tabsheet->add('global',
41               l10n('LCAS_Tab_Global'),
42               $my_base_url.'&amp;tab=global');
43  $tabsheet->add('userlist',
44                 l10n('LCAS_Tab_UserList'),
45                 $my_base_url.'&amp;tab=userlist');
46$tabsheet->select($page['tab']);
47$tabsheet->assign();
48
49
50// +-----------------------------------------------------------------------+
51// |                      Getting plugin version                           |
52// +-----------------------------------------------------------------------+
53$plugin =  LCAS_PluginInfos(LCAS_PATH);
54$version = $plugin['version'];
55
56// +-----------------------------------------------------------------------+
57// |                            Tabssheet select                           |
58// +-----------------------------------------------------------------------+
59
60switch ($page['tab'])
61{
62// *************************************************************************
63// +-----------------------------------------------------------------------+
64// |                           Global Config                               |
65// +-----------------------------------------------------------------------+
66// *************************************************************************
67  case 'global':
68
69        if (isset($_POST['submit']) and !is_adviser() and isset($_POST['LCAS_Case_Sensitive']) and isset($_POST['LCAS_Accent_Sensitive']) )
70  {
71
72/* General configuration settings */
73
74/* Check if CR-LF exist at begining and end of mail exclusion list - If yes, removes them */
75                $newconf_LCAS= array(
76      $_POST['LCAS_Case_Sensitive'],
77      $_POST['LCAS_Accent_Sensitive']);
78
79    $conf['LoginCaseAccentsSensitivity'] = serialize($newconf_LCAS);
80
81                $query = '
82                UPDATE '.CONFIG_TABLE.'
83                SET value="'.addslashes($conf['LoginCaseAccentsSensitivity']).'"
84                WHERE param="LoginCaseAccentsSensitivity"
85                LIMIT 1
86                ;';
87               
88                pwg_query($query);
89
90                array_push($page['infos'], l10n('LCAS_save_config'));
91  }
92
93
94  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
95
96
97/* Save last opened paragraph in configuration tab */
98  $nb_para=(isset($_POST["nb_para"])) ? $_POST["nb_para"]:"";
99  $nb_para2=(isset($_POST["nb_para2"])) ? $_POST["nb_para2"]:"";
100
101  $template->assign(
102    array(
103    'nb_para'                        => $nb_para,
104    'nb_para2'                       => $nb_para2,
105    'LCAS_VERSION'                   => $version,
106    'LCAS_PATH'                      => LCAS_PATH,
107    'PWG_insensitive_case_logon'     => $conf['insensitive_case_logon']? 'true'              : 'false',
108                'LCAS_Case_Sensitive_TRUE'       => $conf_LCAS[0]=='true'          ? 'checked="checked"' : '' ,
109                'LCAS_Case_Sensitive_FALSE'      => $conf_LCAS[0]=='false'         ? 'checked="checked"' : '' ,
110                'LCAS_Accent_Sensitive_TRUE'     => $conf_LCAS[1]=='true'          ? 'checked="checked"' : '' ,
111                'LCAS_Accent_Sensitive_FALSE'    => $conf_LCAS[1]=='false'         ? 'checked="checked"' : ''
112    )
113  );
114
115
116// +-----------------------------------------------------------------------+
117// |                             errors display                            |
118// +-----------------------------------------------------------------------+
119  if (isset ($errors) and count($errors) != 0)
120  {
121          $template->assign('errors',array());
122          foreach ($errors as $error)
123          {
124                  array_push($page['errors'], $error);
125                }
126        } 
127
128// +-----------------------------------------------------------------------+
129// |                           templates display                           |
130// +-----------------------------------------------------------------------+
131  $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/global.tpl');
132  $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
133
134  break;
135
136
137// *************************************************************************
138// +-----------------------------------------------------------------------+
139// |                           Users list page                             |
140// +-----------------------------------------------------------------------+
141// *************************************************************************
142  case 'userlist':
143 
144  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
145 
146  if ((isset($conf_LCAS[0]) and $conf_LCAS[0]=='true') || (isset($conf_LCAS[1]) and $conf_LCAS[1]=='true'))
147  {
148// +-----------------------------------------------------------------------+
149// |                           initialization                              |
150// +-----------------------------------------------------------------------+
151
152                if (!defined('PHPWG_ROOT_PATH'))
153    {
154        die('Hacking attempt!');
155    }
156         
157    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
158
159// +-----------------------------------------------------------------------+
160// | Check Access and exit when user status is not ok                      |
161// +-----------------------------------------------------------------------+
162                check_status(ACCESS_ADMINISTRATOR);
163
164    $lcas_UserToUpdate = -1;
165    if ((isset($_POST['UserToUpdate'])) && ($_POST['UserToUpdate'] != -1)) {
166        $lcas_UserToUpdate = $_POST['UserToUpdate'];
167       
168        if ((isset($_POST['user-'.$lcas_UserToUpdate])) && ($_POST['user-'.$lcas_UserToUpdate] != '')) {
169                // Vérifier si le nom n'est pas déjà pris
170               
171               
172               
173                // Mise à jour du nom
174                                $query = '
175                                UPDATE '.USERS_TABLE.'
176                                SET username="'.addslashes($_POST['user-'.$lcas_UserToUpdate]).'"
177                                WHERE id='.$lcas_UserToUpdate.'
178                                LIMIT 1
179                                ;';
180
181                                pwg_query($query);
182               
183                                array_push($page['infos'], l10n('LCAS_Info_userlist_username_renamed'));
184        }
185        else {
186                // User is empty
187                                array_push($page['errors'], l10n('LCAS_Err_Userlist_Empty_New_Username'));
188        }
189    }
190
191
192
193// +-----------------------------------------------------------------------+
194// |                               user list                               |
195// +-----------------------------------------------------------------------+
196
197                if ($conf_LCAS[0]=='true' && $conf_LCAS[1]=='true')
198                        $lcas_rule = 2;
199                else if ($conf_LCAS[0]=='true')
200                        $lcas_rule = 1;
201                else if ($conf_LCAS[1]=='true')
202                        $lcas_rule = 3;
203                else
204                        $lcas_rule = 0;
205               
206                $page['all_users'] = LCAS_get_user_list($lcas_rule);
207
208// +-----------------------------------------------------------------------+
209// |                               user list                               |
210// +-----------------------------------------------------------------------+
211
212                $lcas_previous_compare_user = '';
213    $visible_user_list          = array();
214    foreach ($page['all_users'] as $local_user)
215    {
216      if ($lcas_previous_compare_user != $local_user['transformed']) {
217        $display = 'orange';
218        $lcas_previous_compare_user = $local_user['transformed'];
219      }
220      else {
221        $display = '';
222      }
223
224                $template->append(
225                'users',
226        array(
227                'ID'          => $local_user['id'],
228                'USERNAME'    => stripslashes($local_user['username']),
229                'COMPARE'     => stripslashes($local_user['transformed']),
230                                        'EMAIL'       => get_email_address_as_display_text($local_user['email']),
231          'DISPLAY'     => $display,
232                                )
233                        );
234                }
235    /* Plugin version inserted */
236    $template->assign(
237      array(
238        'LCAS_VERSION'  => $version,
239        'LCAS_PATH'     => LCAS_PATH,
240      )
241    );   
242
243   
244// +-----------------------------------------------------------------------+
245// |                             errors display                            |
246// +-----------------------------------------------------------------------+
247                if ( isset ($errors) and count($errors) != 0)
248                {
249                $template->assign('errors',array());
250                        foreach ($errors as $error)
251                {
252                                array_push($page['errors'], $error);
253                }
254                } 
255
256// +-----------------------------------------------------------------------+
257// |                           templates display                           |
258// +-----------------------------------------------------------------------+
259                $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/userlist.tpl');
260    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');         
261  }
262  else
263  {
264                array_push($page['errors'], l10n('LCAS_Err_Userlist_Settings'));
265  }
266  break;
267
268}
269?>
Note: See TracBrowser for help on using the repository browser.