source: tags/release-1_3_3/include/user.inc.php @ 27538

Last change on this file since 27538 was 297, checked in by z0rglub, 20 years ago

Simplifying concatenation of $infos variables to select in the database

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1<?php
2/***************************************************************************
3 *                               user.inc.php                              *
4 *                            ------------------                           *
5 *   application   : PhpWebGallery 1.3 <http://phpwebgallery.net>          *
6 *   author        : Pierrick LE GALL <pierrick@z0rglub.com>               *
7 *                                                                         *
8 *   $Id: user.inc.php 297 2004-01-18 22:06:34Z z0rglub $
9 *                                                                         *
10 ***************************************************************************
11
12 ***************************************************************************
13 *                                                                         *
14 *   This program is free software; you can redistribute it and/or modify  *
15 *   it under the terms of the GNU General Public License as published by  *
16 *   the Free Software Foundation;                                         *
17 *                                                                         *
18 ***************************************************************************/
19
20// retrieving user informations
21// $infos array is used to know the fields to retrieve in the table "users"
22// Each field becomes an information of the array $user.
23// Example :
24//            status --> $user['status']
25$infos = array( 'id', 'username', 'mail_address', 'nb_image_line',
26                'nb_line_page', 'status', 'language', 'maxwidth',
27                'maxheight', 'expand', 'show_nb_comments', 'short_period',
28                'long_period', 'template', 'forbidden_categories' );
29
30$query_user = 'SELECT '.implode( ',', $infos );
31$query_user.= ' FROM '.PREFIX_TABLE.'users';
32$query_done = false;
33$user['is_the_guest'] = false;
34
35// cookie deletion if administrator don't authorize them anymore
36if ( !$conf['authorize_cookies'] and isset( $_COOKIE['id'] ) )
37{
38  setcookie( 'id', '', 0, cookie_path() );
39  $url = 'category.php';
40  header( 'Request-URI: '.$url ); 
41  header( 'Content-Location: '.$url ); 
42  header( 'Location: '.$url );
43  exit();
44}
45
46$user['has_cookie'] = false;
47if     ( isset( $_GET['id']    ) ) $session_id = $_GET['id'];
48elseif ( isset( $_COOKIE['id'] ) )
49{
50  $session_id = $_COOKIE['id'];
51  $user['has_cookie'] = true;
52}
53
54if ( isset( $session_id )
55     and ereg( "^[0-9a-zA-Z]{".$conf['session_id_size']."}$", $session_id ) )
56{
57  $page['session_id'] = $session_id;
58  $query = 'SELECT user_id,expiration,ip';
59  $query.= ' FROM '.PREFIX_TABLE.'sessions';
60  $query.= " WHERE id = '".$page['session_id']."'";
61  $query.= ';';
62  $result = mysql_query( $query );
63  if ( mysql_num_rows( $result ) > 0 )
64  {
65    $row = mysql_fetch_array( $result );
66    if ( !$user['has_cookie'] )
67    {
68      if ( $row['expiration'] < time() )
69      {
70        // deletion of the session from the database,
71        // because it is out-of-date
72        $delete_query = 'DELETE FROM '.PREFIX_TABLE.'sessions';
73        $delete_query.= " WHERE id = '".$page['session_id']."'";
74        $delete_query.= ';';
75        mysql_query( $delete_query );
76      }
77      else if ( $_SERVER['REMOTE_ADDR'] == $row['ip'] )
78      {
79        $query_user .= ' WHERE id = '.$row['user_id'];
80        $query_done = true;
81      }
82    }
83    else
84    {
85      $query_user .= ' WHERE id = '.$row['user_id'];
86      $query_done = true;
87    }
88  }
89}
90if ( !$query_done )
91{
92  $query_user .= ' WHERE id = 2';
93  $user['is_the_guest'] = true;
94}
95$query_user .= ';';
96$row = mysql_fetch_array( mysql_query( $query_user ) );
97
98// affectation of each value retrieved in the users table into a variable
99// of the array $user.
100foreach ( $infos as $info ) {
101  if ( isset( $row[$info] ) )
102  {
103    // If the field is true or false, the variable is transformed into a
104    // boolean value.
105    if ( $row[$info] == 'true' or $row[$info] == 'false' )
106      $user[$info] = get_boolean( $row[$info] );
107    else
108      $user[$info] = $row[$info];   
109  }
110  else
111  {
112    $user[$info] = '';
113  }
114}
115
116// special for $user['restrictions'] array
117$user['restrictions'] = explode( ',', $user['forbidden_categories'] );
118if ( $user['restrictions'][0] == '' ) $user['restrictions'] = array();
119?>
Note: See TracBrowser for help on using the repository browser.