1 | <?php |
---|
2 | /*************************************************************************** |
---|
3 | * user.inc.php * |
---|
4 | * ------------------ * |
---|
5 | * application : PhpWebGallery 1.3 * |
---|
6 | * author : Pierrick LE GALL <pierrick@z0rglub.com> * |
---|
7 | * * |
---|
8 | *************************************************************************** |
---|
9 | |
---|
10 | *************************************************************************** |
---|
11 | * * |
---|
12 | * This program is free software; you can redistribute it and/or modify * |
---|
13 | * it under the terms of the GNU General Public License as published by * |
---|
14 | * the Free Software Foundation; * |
---|
15 | * * |
---|
16 | ***************************************************************************/ |
---|
17 | // retrieving user informations |
---|
18 | // $infos array is used to know the fields to retrieve in the table "users" |
---|
19 | // Each field becomes an information of the array $user. |
---|
20 | // Example : |
---|
21 | // status --> $user['status'] |
---|
22 | $infos = array( 'id', 'username', 'mail_address', 'nb_image_line', |
---|
23 | 'nb_line_page', 'status', 'theme', 'language', 'maxwidth', |
---|
24 | 'maxheight', 'expand', 'show_nb_comments', 'short_period', |
---|
25 | 'long_period', 'template' ); |
---|
26 | |
---|
27 | $query_user = 'SELECT'; |
---|
28 | for ( $i = 0; $i < sizeof( $infos ); $i++ ) |
---|
29 | { |
---|
30 | if ( $i > 0 ) |
---|
31 | { |
---|
32 | $query_user.= ','; |
---|
33 | } |
---|
34 | else |
---|
35 | { |
---|
36 | $query_user.= ' '; |
---|
37 | } |
---|
38 | $query_user.= $infos[$i]; |
---|
39 | } |
---|
40 | $query_user.= ' FROM '.PREFIX_TABLE.'users'; |
---|
41 | $query_done = false; |
---|
42 | $user['is_the_guest'] = false; |
---|
43 | if ( isset( $_GET['id'] ) |
---|
44 | && ereg( "^[0-9a-zA-Z]{".$conf['session_id_size']."}$", $_GET['id'] ) ) |
---|
45 | { |
---|
46 | $page['session_id'] = $_GET['id']; |
---|
47 | $query = 'SELECT user_id,expiration,ip'; |
---|
48 | $query.= ' FROM '.PREFIX_TABLE.'sessions'; |
---|
49 | $query.= " WHERE id = '".$_GET['id']."'"; |
---|
50 | $query.= ';'; |
---|
51 | $result = mysql_query( $query ); |
---|
52 | if ( mysql_num_rows( $result ) > 0 ) |
---|
53 | { |
---|
54 | $row = mysql_fetch_array( $result ); |
---|
55 | if ( $row['expiration'] < time() ) |
---|
56 | { |
---|
57 | // deletion of the session from the database, |
---|
58 | // because it is out-of-date |
---|
59 | $delete_query = 'DELETE FROM '.PREFIX_TABLE.'sessions'; |
---|
60 | $delete_query.= " WHERE id = '".$page['session_id']."'"; |
---|
61 | $delete_query.= ';'; |
---|
62 | mysql_query( $delete_query ); |
---|
63 | } |
---|
64 | else |
---|
65 | { |
---|
66 | if ( $_SERVER['REMOTE_ADDR'] == $row['ip'] ) |
---|
67 | { |
---|
68 | $query_user .= ' WHERE id = '.$row['user_id']; |
---|
69 | $query_done = true; |
---|
70 | } |
---|
71 | } |
---|
72 | } |
---|
73 | } |
---|
74 | if ( !$query_done ) |
---|
75 | { |
---|
76 | $query_user .= ' WHERE id = 2'; |
---|
77 | $user['is_the_guest'] = true; |
---|
78 | } |
---|
79 | $query_user .= ';'; |
---|
80 | |
---|
81 | $row = mysql_fetch_array( mysql_query( $query_user ) ); |
---|
82 | |
---|
83 | // affectation of each value retrieved in the users table into a variable |
---|
84 | // of the array $user. |
---|
85 | foreach ( $infos as $info ) { |
---|
86 | $user[$info] = $row[$info]; |
---|
87 | // If the field is true or false, the variable is transformed into a |
---|
88 | // boolean value. |
---|
89 | if ( $row[$info] == 'true' or $row[$info] == 'false' ) |
---|
90 | { |
---|
91 | $user[$info] = get_boolean( $row[$info] ); |
---|
92 | } |
---|
93 | } |
---|
94 | ?> |
---|