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

Last change on this file since 647 was 647, checked in by plg, 19 years ago
  • bug fixed : in admin/cat_list, next_rank cant' be calculted and query to count sub-categories per sub-categories became false if no sub-categories
  • virtual association come back in admin/infos_images (not only in admin/picture_modify)
  • check_favorites function in admin section becomes check_user_favorites in public section : favorites are checked when user tries to display his favorites. Function was optimized.
  • in function update_category, wrap of long queries due to many categories to update at the same time
  • typo fixed in description of paginate_pages_around configuration parameter
  • bug fixed in new navigation bar : no separation pipe was displayed between next and last when the page displayed was the last
  • sessions.expiration changed of type from int to datetime (a lot easier to read)
  • sessions.ip removed : IP address is no longer used to verify session
  • typo fixed in language/en_UK.iso-8859-1/admin.lang.php on editcat_lock_info language item
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 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-2004 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-12-18 22:05:30 +0000 (Sat, 18 Dec 2004) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 647 $
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// retrieving user informations
29// $infos array is used to know the fields to retrieve in the table "users"
30// Each field becomes an information of the array $user.
31// Example :
32//            status --> $user['status']
33$infos = array('id','username','mail_address','nb_image_line','nb_line_page',
34               'status','language','maxwidth','maxheight','expand',
35               'show_nb_comments','recent_period','template',
36               'forbidden_categories');
37
38$query_user = 'SELECT * FROM '.USERS_TABLE;
39$query_done = false;
40$user['is_the_guest'] = false;
41
42if (isset($_COOKIE['id']))
43{
44  $session_id = $_COOKIE['id'];
45  $user['has_cookie'] = true;
46}
47else if (isset($_GET['id']))
48{
49  $session_id = $_GET['id'];
50  $user['has_cookie'] = false;
51}
52else
53{
54  $user['has_cookie'] = false;
55}
56
57if (isset($session_id)
58    and ereg("^[0-9a-zA-Z]{".$conf['session_id_size']."}$", $session_id))
59{
60  $page['session_id'] = $session_id;
61  $query = '
62SELECT user_id,expiration,NOW() AS now
63  FROM '.SESSIONS_TABLE.'
64  WHERE id = \''.$page['session_id'].'\'
65;';
66  $result = pwg_query($query);
67  if (mysql_num_rows($result) > 0)
68  {
69    $row = mysql_fetch_array($result);
70    if (strnatcmp($row['expiration'], $row['now']) < 0)
71    {
72      // deletion of the session from the database, because it is
73      // out-of-date
74      $delete_query = '
75DELETE FROM '.SESSIONS_TABLE.'
76  WHERE id = \''.$page['session_id'].'\'
77;';
78      pwg_query($delete_query);
79    }
80    else
81    {
82      $query_user .= ' WHERE id = '.$row['user_id'];
83      $query_done = true;
84    }
85  }
86}
87if (!$query_done)
88{
89  $query_user .= ' WHERE id = 2';
90  $user['is_the_guest'] = true;
91}
92$query_user .= ';';
93$row = mysql_fetch_array(pwg_query($query_user));
94
95// affectation of each value retrieved in the users table into a variable
96// of the array $user.
97foreach ($infos as $info) {
98  if (isset($row[$info]))
99  {
100    // If the field is true or false, the variable is transformed into a
101    // boolean value.
102    if ($row[$info] == 'true' or $row[$info] == 'false')
103      $user[$info] = get_boolean($row[$info]);
104    else
105      $user[$info] = $row[$info];   
106  }
107  else
108  {
109    $user[$info] = '';
110  }
111}
112
113// special for $user['restrictions'] array
114$user['restrictions'] = explode(',', $user['forbidden_categories']);
115if ($user['restrictions'][0] == '')
116{
117  $user['restrictions'] = array();
118}
119
120$isadmin = false;
121if ($user['status'] == 'admin')
122{
123  $isadmin =true;
124}
125// calculation of the number of picture to display per page
126$user['nb_image_page'] = $user['nb_image_line'] * $user['nb_line_page'];
127init_userprefs($user);
128?>
Note: See TracBrowser for help on using the repository browser.