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

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

Add compatibility for Piwigo 2.1 and 2.2 - LCAS can be used on both Piwigo version without changing Smarty's header (that's for Lucmorizur ;-))

File size: 7.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__)).'/');
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          // Check if username already exists
93                $count = 0;
94                $lcas_previous_compare_user = LCAS_change_case($_POST['user-'.$lcas_UserToUpdate], $conf_LCAS[0]);
95                      foreach ($page['all_users'] as $local_user)
96                      {
97                        if ($lcas_previous_compare_user == $local_user['transformed']) {
98                                $count = 1;
99                                break;
100                        }
101                      }
102
103          $query = '
104                 SELECT username
105                 FROM '.USERS_TABLE.'
106                 WHERE username="'.addslashes($_POST['user-'.$lcas_UserToUpdate]).'"
107          ;';
108       
109          $count = pwg_db_num_rows(pwg_query($query));
110
111          if ($count < 1)
112          {
113            // Get old username befor update - Usefull 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'], $_POST['user-'.$lcas_UserToUpdate]);
135            }
136
137            // Reloading conflict table content
138            $page['all_users'] = LCAS_get_user_list($conf_LCAS[0]);
139            array_push($page['infos'], l10n('LCAS_Info_userlist_username_renamed'));
140          }
141          else
142          {
143            // Username already exists
144            array_push($page['errors'], l10n('LCAS_Err_Userlist_New_Username_Exists').'<br>"'.$lcas_previous_compare_user.'"');
145          }
146        }
147        else {
148          // Username is empty
149          array_push($page['errors'], l10n('LCAS_Err_Userlist_Empty_New_Username'));
150        }
151      }
152
153// +-----------------------------------------------------------------------+
154// |                               user list                               |
155// +-----------------------------------------------------------------------+
156
157      $lcas_previous_compare_user = '';
158      $visible_user_list          = array();
159      foreach ($page['all_users'] as $local_user)
160      {
161        if ($lcas_previous_compare_user != $local_user['transformed']) {
162          $display = 'orange';
163          $lcas_previous_compare_user = $local_user['transformed'];
164        }
165        else {
166          $display = '';
167        }
168
169        $template->append(
170          'users',
171          array(
172            'ID'          => $local_user['id'],
173            'USERNAME'    => stripslashes($local_user['username']),
174            'COMPARE'     => stripslashes($local_user['transformed']),
175            'EMAIL'       => get_email_address_as_display_text($local_user['email']),
176            'DISPLAY'     => $display,
177          )
178        );
179      }
180     
181    }
182  }
183
184
185// +-----------------------------------------------------------------------+
186// |                           templates init                              |
187// +-----------------------------------------------------------------------+
188  $template->assign(
189    array(
190    'LCAS_VERSION'                  => $version,
191    'LCAS_PATH'                     => LCAS_PATH,
192    'PHPWG_VERSION'                 => PHPWG_VERSION,
193    'LCAS_PATH_ABS'                 => LCAS_PATH_ABS,
194                'LCAS_Option'                   => $conf_LCAS[0],
195                'LCAS_MAIL_TRUE'                => $conf_LCAS[1] == 'true'  ? 'checked = "checked"' : '' ,
196                'LCAS_MAIL_FALSE'               => $conf_LCAS[1] == 'false' ? 'checked = "checked"' : '' ,
197    'LCAS_MAILTEXT'                 => $conf_LCAS[2]
198    )
199  );
200
201
202// +-----------------------------------------------------------------------+
203// |                             errors display                            |
204// +-----------------------------------------------------------------------+
205  if (isset ($errors) and count($errors) != 0)
206  {
207          $template->assign('errors',array());
208          foreach ($errors as $error)
209          {
210                  array_push($page['errors'], $error);
211                }
212        } 
213
214// +-----------------------------------------------------------------------+
215// |                           templates display                           |
216// +-----------------------------------------------------------------------+
217  $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/global.tpl');
218  $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
219
220?>
Note: See TracBrowser for help on using the repository browser.