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

Last change on this file since 367 was 367, checked in by gweltas, 21 years ago

Migration of installation procedure

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 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-02-20 19:07:43 +0000 (Fri, 20 Feb 2004) $
10// | last modifier : $Author: gweltas $
11// | revision      : $Revision: 367 $
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', 'short_period',
36                'long_period', 'template', 'forbidden_categories' );
37
38$query_user = 'SELECT '.implode( ',', $infos );
39$query_user.= ' FROM '.USERS_TABLE;
40$query_done = false;
41$user['is_the_guest'] = false;
42
43// cookie deletion if administrator don't authorize them anymore
44if ( !$conf['authorize_cookies'] and isset( $_COOKIE['id'] ) )
45{
46  setcookie( 'id', '', 0, cookie_path() );
47  $url = 'category.php';
48  header( 'Request-URI: '.$url ); 
49  header( 'Content-Location: '.$url ); 
50  header( 'Location: '.$url );
51  exit();
52}
53
54$user['has_cookie'] = false;
55if     ( isset( $_GET['id']    ) ) $session_id = $_GET['id'];
56elseif ( isset( $_COOKIE['id'] ) )
57{
58  $session_id = $_COOKIE['id'];
59  $user['has_cookie'] = true;
60}
61
62if ( isset( $session_id )
63     and ereg( "^[0-9a-zA-Z]{".$conf['session_id_size']."}$", $session_id ) )
64{
65  $page['session_id'] = $session_id;
66  $query = 'SELECT user_id,expiration,ip';
67  $query.= ' FROM '.SESSIONS_TABLE;
68  $query.= " WHERE id = '".$page['session_id']."'";
69  $query.= ';';
70  $result = mysql_query( $query );
71  if ( mysql_num_rows( $result ) > 0 )
72  {
73    $row = mysql_fetch_array( $result );
74    if ( !$user['has_cookie'] )
75    {
76      if ( $row['expiration'] < time() )
77      {
78        // deletion of the session from the database,
79        // because it is out-of-date
80        $delete_query = 'DELETE FROM '.SESSIONS_TABLE;
81        $delete_query.= " WHERE id = '".$page['session_id']."'";
82        $delete_query.= ';';
83        mysql_query( $delete_query );
84      }
85      else if ( $_SERVER['REMOTE_ADDR'] == $row['ip'] )
86      {
87        $query_user .= ' WHERE id = '.$row['user_id'];
88        $query_done = true;
89      }
90    }
91    else
92    {
93      $query_user .= ' WHERE id = '.$row['user_id'];
94      $query_done = true;
95    }
96  }
97}
98if ( !$query_done )
99{
100  $query_user .= ' WHERE id = 2';
101  $user['is_the_guest'] = true;
102}
103$query_user .= ';';
104$row = mysql_fetch_array( mysql_query( $query_user ) );
105
106// affectation of each value retrieved in the users table into a variable
107// of the array $user.
108foreach ( $infos as $info ) {
109  if ( isset( $row[$info] ) )
110  {
111    // If the field is true or false, the variable is transformed into a
112    // boolean value.
113    if ( $row[$info] == 'true' or $row[$info] == 'false' )
114      $user[$info] = get_boolean( $row[$info] );
115    else
116      $user[$info] = $row[$info];   
117  }
118  else
119  {
120    $user[$info] = '';
121  }
122}
123
124// special for $user['restrictions'] array
125$user['restrictions'] = explode( ',', $user['forbidden_categories'] );
126if ( $user['restrictions'][0] == '' ) $user['restrictions'] = array();
127$isadmin = false;
128if ($user['status'] == 'admin') $isadmin =true;
129// calculation of the number of picture to display per page
130$user['nb_image_page'] = $user['nb_image_line'] * $user['nb_line_page'];
131init_userprefs($user);
132$user['lien_expanded']='./template/'.$user['template'].'/theme/expanded..gif';
133$user['lien_collapsed']='./template/'.$user['template'].'/theme/collapsed.gif';
134?>
Note: See TracBrowser for help on using the repository browser.