source: trunk/include/user.inc.php @ 787

Last change on this file since 787 was 787, checked in by plg, 19 years ago
  • user list : links to profile page and permissions page are represented by icons (more compact)
  • user list : ability to associate to a group or to dissociate from a group a list of selected users
  • user list : ability to set user properties in "batch" mode (a selection of users at once)
  • user list : alternate background color for each line
  • (not in ChangeLog) temporary commented code to update current user language if $_POSTlanguage is set (see include/user.inc.php for details)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2005-05-09 22:34:21 +0000 (Mon, 09 May 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 787 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28// Dynamic change of language with database persistency
29//
30// FIXME : ce bout de code fait planter l'assignation d'un language a
31// plusieurs users simultanement dans la nouvelle page admin/user_list.php
32//
33// if (isset($_POST['language']))
34// {
35//   $query = "UPDATE ".USERS_TABLE." SET language = '";
36//   $query.= $_POST['language'];
37//   $query.= "' WHERE id = ".$_POST['userid'].";";
38//   pwg_query($query);
39// }
40
41
42// retrieving connected user informations
43if (isset($_COOKIE['id']))
44{
45  $session_id = $_COOKIE['id'];
46  $user['has_cookie'] = true;
47}
48else if (isset($_GET['id']))
49{
50  $session_id = $_GET['id'];
51  $user['has_cookie'] = false;
52}
53else
54{
55  $user['has_cookie'] = false;
56}
57
58if (isset($session_id)
59    and ereg("^[0-9a-zA-Z]{".$conf['session_id_size']."}$", $session_id))
60{
61  $page['session_id'] = $session_id;
62  $query = '
63SELECT user_id,expiration,NOW() AS now
64  FROM '.SESSIONS_TABLE.'
65  WHERE id = \''.$page['session_id'].'\'
66;';
67  $result = pwg_query($query);
68  if (mysql_num_rows($result) > 0)
69  {
70    $row = mysql_fetch_array($result);
71    if (strnatcmp($row['expiration'], $row['now']) < 0)
72    {
73      // deletion of the session from the database, because it is
74      // out-of-date
75      $delete_query = '
76DELETE FROM '.SESSIONS_TABLE.'
77  WHERE id = \''.$page['session_id'].'\'
78;';
79      pwg_query($delete_query);
80    }
81    else
82    {
83      $user['id'] = $row['user_id'];
84      $user['is_the_guest'] = false;
85    }
86  }
87}
88if (!isset($user['id']))
89{
90  $user['id'] = 2;
91  $user['is_the_guest'] = true;
92}
93
94$query = '
95SELECT u.*, uf.*
96  FROM '.USERS_TABLE.' AS u LEFT JOIN '.USER_FORBIDDEN_TABLE.' AS uf
97    ON id = user_id
98  WHERE u.id = '.$user['id'].'
99;';
100$row = mysql_fetch_array(pwg_query($query));
101
102// affectation of each value retrieved in the users table into a variable of
103// the array $user.
104foreach ($row as $key => $value)
105{
106  if (!is_numeric($key))
107  {
108    // If the field is true or false, the variable is transformed into a
109    // boolean value.
110    if ($value == 'true' or $value == 'false')
111    {
112      $user[$key] = get_boolean($value);
113    }
114    else
115    {
116      $user[$key] = $value;
117    }
118  }
119}
120
121// properties of user guest are found in the configuration
122if ($user['is_the_guest'])
123{
124  $user['template'] = $conf['default_template'];
125  $user['nb_image_line'] = $conf['nb_image_line'];
126  $user['nb_line_page'] = $conf['nb_line_page'];
127  $user['language'] = $conf['default_language'];
128  $user['maxwidth'] = $conf['default_maxwidth'];
129  $user['maxheight'] = $conf['default_maxheight'];
130  $user['recent_period'] = $conf['recent_period'];
131  $user['expand'] = $conf['auto_expand'];
132  $user['show_nb_comments'] = $conf['show_nb_comments'];
133}
134
135// if no information were found about user in user_forbidden table OR the
136// forbidden categories must be updated : only if current user is in public
137// part
138if (!defined('IN_ADMIN') or !IN_ADMIN)
139{
140  if (!isset($user['need_update'])
141      or !is_bool($user['need_update'])
142      or $user['need_update'] == true)
143  {
144    $user['forbidden_categories'] = calculate_permissions($user['id'],
145                                                          $user['status']);
146  }
147}
148
149// forbidden_categories is a must be empty, at least
150if (!isset($user['forbidden_categories']))
151{
152  $user['forbidden_categories'] = '';
153}
154
155// special for $user['restrictions'] array
156$user['restrictions'] = explode(',', $user['forbidden_categories']);
157if ($user['restrictions'][0] == '')
158{
159  $user['restrictions'] = array();
160}
161
162// calculation of the number of picture to display per page
163$user['nb_image_page'] = $user['nb_image_line'] * $user['nb_line_page'];
164
165if (empty($user['language'])
166    or !file_exists(PHPWG_ROOT_PATH.'language/'.
167                    $user['language'].'/common.lang.php'))
168{
169  $user['language'] = $conf['default_language'];
170}
171include_once(PHPWG_ROOT_PATH.'language/'.$user['language'].'/common.lang.php');
172
173// displaying the username in the language of the connected user, instead of
174// "guest" as you can find in the database
175if ($user['is_the_guest'])
176{
177  $user['username'] = $lang['guest'];
178}
179
180// only if we are in the administration section
181if (defined('IN_ADMIN') and IN_ADMIN)
182{
183  $langdir = PHPWG_ROOT_PATH.'language/'.$user['language'];
184  if (!file_exists($langdir.'/admin.lang.php'))
185  {
186    $langdir = PHPWG_ROOT_PATH.'language/'.$conf['default_language'];
187  }
188  include_once($langdir.'/admin.lang.php');
189  include_once($langdir.'/faq.lang.php');
190}
191
192if (empty($user['template']))
193{
194  $user['template'] = $conf['default_template'];
195}
196$template = setup_style($user['template']);
197?>
Note: See TracBrowser for help on using the repository browser.