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

Last change on this file since 532 was 532, checked in by gweltas, 20 years ago
  • Delivery of french translation in order to test i18n
  • Deletion of collapsed & expanded gifs (obsoletes)
  • Creation of faq language file for further writing of a end user-oriented FAQ
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// |                             user.inc.php                              |
4// +-----------------------------------------------------------------------+
5// | application   : PhpWebGallery <http://phpwebgallery.net>              |
6// | branch        : BSF (Best So Far)                                     |
7// +-----------------------------------------------------------------------+
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-09-23 17:09:06 +0000 (Thu, 23 Sep 2004) $
10// | last modifier : $Author: gweltas $
11// | revision      : $Revision: 532 $
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',
34                'nb_line_page', 'status', 'language', 'maxwidth',
35                'maxheight', 'expand', 'show_nb_comments', 'recent_period',
36                'template', 'forbidden_categories' );
37
38$query_user = 'SELECT * FROM '.USERS_TABLE;
39$query_done = false;
40$user['is_the_guest'] = false;
41
42// cookie deletion if administrator don't authorize them anymore
43if ( !$conf['authorize_cookies'] and isset( $_COOKIE['id'] ) )
44{
45  setcookie( 'id', '', 0, cookie_path() );
46  $url = 'category.php';
47  redirect( $url );
48}
49
50$user['has_cookie'] = false;
51if     ( isset( $_GET['id']    ) ) $session_id = $_GET['id'];
52elseif ( isset( $_COOKIE['id'] ) )
53{
54  $session_id = $_COOKIE['id'];
55  $user['has_cookie'] = true;
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 = 'SELECT user_id,expiration,ip';
63  $query.= ' FROM '.SESSIONS_TABLE;
64  $query.= " WHERE id = '".$page['session_id']."'";
65  $query.= ';';
66  $result = mysql_query( $query );
67  if ( mysql_num_rows( $result ) > 0 )
68  {
69    $row = mysql_fetch_array( $result );
70    if ( !$user['has_cookie'] )
71    {
72      if ( $row['expiration'] < time() )
73      {
74        // deletion of the session from the database,
75        // because it is out-of-date
76        $delete_query = 'DELETE FROM '.SESSIONS_TABLE;
77        $delete_query.= " WHERE id = '".$page['session_id']."'";
78        $delete_query.= ';';
79        mysql_query( $delete_query );
80      }
81      else if ( $_SERVER['REMOTE_ADDR'] == $row['ip'] )
82      {
83        $query_user .= ' WHERE id = '.$row['user_id'];
84        $query_done = true;
85      }
86    }
87    else
88    {
89      $query_user .= ' WHERE id = '.$row['user_id'];
90      $query_done = true;
91    }
92  }
93}
94if ( !$query_done )
95{
96  $query_user .= ' WHERE id = 2';
97  $user['is_the_guest'] = true;
98}
99$query_user .= ';';
100$row = mysql_fetch_array( mysql_query( $query_user ) );
101
102// affectation of each value retrieved in the users table into a variable
103// of the array $user.
104foreach ( $infos as $info ) {
105  if ( isset( $row[$info] ) )
106  {
107    // If the field is true or false, the variable is transformed into a
108    // boolean value.
109    if ( $row[$info] == 'true' or $row[$info] == 'false' )
110      $user[$info] = get_boolean( $row[$info] );
111    else
112      $user[$info] = $row[$info];   
113  }
114  else
115  {
116    $user[$info] = '';
117  }
118}
119
120// special for $user['restrictions'] array
121$user['restrictions'] = explode( ',', $user['forbidden_categories'] );
122if ( $user['restrictions'][0] == '' )
123{
124  $user['restrictions'] = array();
125}
126
127$isadmin = false;
128if ( $user['status'] == 'admin' )
129{
130  $isadmin =true;
131}
132// calculation of the number of picture to display per page
133$user['nb_image_page'] = $user['nb_image_line'] * $user['nb_line_page'];
134init_userprefs($user);
135?>
Note: See TracBrowser for help on using the repository browser.