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

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

bug 2207 fixed : Conflicts table content is reloaded after successful username update.

File size: 6.9 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            // Reloading conflict table content
119            $page['all_users'] = LCAS_get_user_list($conf_LCAS[0]);
120            array_push($page['infos'], l10n('LCAS_Info_userlist_username_renamed'));
121          }
122          else
123          {
124            // Username already exists
125            array_push($page['errors'], l10n('LCAS_Err_Userlist_New_Username_Exists').'<br>"'.$lcas_previous_compare_user.'"');
126          }
127        }
128        else {
129          // Username is empty
130          array_push($page['errors'], l10n('LCAS_Err_Userlist_Empty_New_Username'));
131        }
132      }
133
134// +-----------------------------------------------------------------------+
135// |                               user list                               |
136// +-----------------------------------------------------------------------+
137
138      $lcas_previous_compare_user = '';
139      $visible_user_list          = array();
140      foreach ($page['all_users'] as $local_user)
141      {
142        if ($lcas_previous_compare_user != $local_user['transformed']) {
143          $display = 'orange';
144          $lcas_previous_compare_user = $local_user['transformed'];
145        }
146        else {
147          $display = '';
148        }
149
150        $template->append(
151          'users',
152          array(
153            'ID'          => $local_user['id'],
154            'USERNAME'    => stripslashes($local_user['username']),
155            'COMPARE'     => stripslashes($local_user['transformed']),
156            'EMAIL'       => get_email_address_as_display_text($local_user['email']),
157            'DISPLAY'     => $display,
158          )
159        );
160      }
161     
162    }
163  }
164
165
166// +-----------------------------------------------------------------------+
167// |                           templates init                              |
168// +-----------------------------------------------------------------------+
169  $template->assign(
170    array(
171    'LCAS_VERSION'                  => $version,
172    'LCAS_PATH'                     => LCAS_PATH,
173                'LCAS_Option'                   => $conf_LCAS[0],
174                'LCAS_MAIL_TRUE'                => $conf_LCAS[1] == 'true'  ? 'checked = "checked"' : '' ,
175                'LCAS_MAIL_FALSE'               => $conf_LCAS[1] == 'false' ? 'checked = "checked"' : '' ,
176    'LCAS_MAILTEXT'                 => $conf_LCAS[2]
177    )
178  );
179
180
181// +-----------------------------------------------------------------------+
182// |                             errors display                            |
183// +-----------------------------------------------------------------------+
184  if (isset ($errors) and count($errors) != 0)
185  {
186          $template->assign('errors',array());
187          foreach ($errors as $error)
188          {
189                  array_push($page['errors'], $error);
190                }
191        } 
192
193// +-----------------------------------------------------------------------+
194// |                           templates display                           |
195// +-----------------------------------------------------------------------+
196  $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/global.tpl');
197  $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
198
199?>
Note: See TracBrowser for help on using the repository browser.