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

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

Check if username already exists (depending on the rule which is set)

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