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-20 12:30:36 +0000 (Mon, 20 Dec 2004) $ |
---|
10 | // | last modifier : $Author: plg $ |
---|
11 | // | revision : $Revision: 648 $ |
---|
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 connected user informations |
---|
29 | |
---|
30 | if (isset($_COOKIE['id'])) |
---|
31 | { |
---|
32 | $session_id = $_COOKIE['id']; |
---|
33 | $user['has_cookie'] = true; |
---|
34 | } |
---|
35 | else if (isset($_GET['id'])) |
---|
36 | { |
---|
37 | $session_id = $_GET['id']; |
---|
38 | $user['has_cookie'] = false; |
---|
39 | } |
---|
40 | else |
---|
41 | { |
---|
42 | $user['has_cookie'] = false; |
---|
43 | } |
---|
44 | |
---|
45 | if (isset($session_id) |
---|
46 | and ereg("^[0-9a-zA-Z]{".$conf['session_id_size']."}$", $session_id)) |
---|
47 | { |
---|
48 | $page['session_id'] = $session_id; |
---|
49 | $query = ' |
---|
50 | SELECT user_id,expiration,NOW() AS now |
---|
51 | FROM '.SESSIONS_TABLE.' |
---|
52 | WHERE id = \''.$page['session_id'].'\' |
---|
53 | ;'; |
---|
54 | $result = pwg_query($query); |
---|
55 | if (mysql_num_rows($result) > 0) |
---|
56 | { |
---|
57 | $row = mysql_fetch_array($result); |
---|
58 | if (strnatcmp($row['expiration'], $row['now']) < 0) |
---|
59 | { |
---|
60 | // deletion of the session from the database, because it is |
---|
61 | // out-of-date |
---|
62 | $delete_query = ' |
---|
63 | DELETE FROM '.SESSIONS_TABLE.' |
---|
64 | WHERE id = \''.$page['session_id'].'\' |
---|
65 | ;'; |
---|
66 | pwg_query($delete_query); |
---|
67 | } |
---|
68 | else |
---|
69 | { |
---|
70 | $user['id'] = $row['user_id']; |
---|
71 | $user['is_the_guest'] = false; |
---|
72 | } |
---|
73 | } |
---|
74 | } |
---|
75 | if (!isset($user['id'])) |
---|
76 | { |
---|
77 | $user['id'] = 2; |
---|
78 | $user['is_the_guest'] = true; |
---|
79 | } |
---|
80 | |
---|
81 | $query = ' |
---|
82 | SELECT u.*, uf.* |
---|
83 | FROM '.USERS_TABLE.' AS u LEFT JOIN '.USER_FORBIDDEN_TABLE.' AS uf |
---|
84 | ON id = user_id |
---|
85 | WHERE u.id = '.$user['id'].' |
---|
86 | ;'; |
---|
87 | $row = mysql_fetch_array(pwg_query($query)); |
---|
88 | |
---|
89 | // affectation of each value retrieved in the users table into a variable of |
---|
90 | // the array $user. |
---|
91 | foreach ($row as $key => $value) |
---|
92 | { |
---|
93 | if (!is_numeric($key)) |
---|
94 | { |
---|
95 | // If the field is true or false, the variable is transformed into a |
---|
96 | // boolean value. |
---|
97 | if ($value == 'true' or $value == 'false') |
---|
98 | { |
---|
99 | $user[$key] = get_boolean($value); |
---|
100 | } |
---|
101 | else |
---|
102 | { |
---|
103 | $user[$key] = $value; |
---|
104 | } |
---|
105 | } |
---|
106 | } |
---|
107 | |
---|
108 | // if no information were found about user in user_forbidden table OR the |
---|
109 | // forbidden categories must be updated |
---|
110 | if (!isset($user['need_update']) |
---|
111 | or !is_bool($user['need_update']) |
---|
112 | or $user['need_update'] == true) |
---|
113 | { |
---|
114 | $user['forbidden_categories'] = calculate_permissions($user['id']); |
---|
115 | } |
---|
116 | |
---|
117 | // forbidden_categories is a must be empty, at least |
---|
118 | if (!isset($user['forbidden_categories'])) |
---|
119 | { |
---|
120 | $user['forbidden_categories'] = ''; |
---|
121 | } |
---|
122 | |
---|
123 | // special for $user['restrictions'] array |
---|
124 | $user['restrictions'] = explode(',', $user['forbidden_categories']); |
---|
125 | if ($user['restrictions'][0] == '') |
---|
126 | { |
---|
127 | $user['restrictions'] = array(); |
---|
128 | } |
---|
129 | |
---|
130 | $isadmin = false; |
---|
131 | if ($user['status'] == 'admin') |
---|
132 | { |
---|
133 | $isadmin = true; |
---|
134 | } |
---|
135 | // calculation of the number of picture to display per page |
---|
136 | $user['nb_image_page'] = $user['nb_image_line'] * $user['nb_line_page']; |
---|
137 | |
---|
138 | init_userprefs($user); |
---|
139 | ?> |
---|