1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based photo gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org | |
---|
6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | This program is free software; you can redistribute it and/or modify | |
---|
10 | // | it under the terms of the GNU General Public License as published by | |
---|
11 | // | the Free Software Foundation | |
---|
12 | // | | |
---|
13 | // | This program is distributed in the hope that it will be useful, but | |
---|
14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
16 | // | General Public License for more details. | |
---|
17 | // | | |
---|
18 | // | You should have received a copy of the GNU General Public License | |
---|
19 | // | along with this program; if not, write to the Free Software | |
---|
20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
21 | // | USA. | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | /** |
---|
25 | * This file is included by the picture page to manage rates |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | if ($conf['rate']) |
---|
30 | { |
---|
31 | if ( NULL != $picture['current']['average_rate'] ) |
---|
32 | { |
---|
33 | $query = ' |
---|
34 | SELECT COUNT(rate) AS count |
---|
35 | , ROUND(AVG(rate),2) AS average |
---|
36 | FROM '.RATE_TABLE.' |
---|
37 | WHERE element_id = '.$picture['current']['id'].' |
---|
38 | ;'; |
---|
39 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
40 | } |
---|
41 | else |
---|
42 | { // avg rate null -> no rate -> no need to query db |
---|
43 | $row = array( 'count'=>0, 'average'=>NULL ); |
---|
44 | } |
---|
45 | $template->assign('rate_summary', $row); |
---|
46 | |
---|
47 | $user_rate = null; |
---|
48 | if ($conf['rate_anonymous'] or is_autorize_status(ACCESS_CLASSIC) ) |
---|
49 | { |
---|
50 | if ($row['count']>0) |
---|
51 | { |
---|
52 | $query = 'SELECT rate |
---|
53 | FROM '.RATE_TABLE.' |
---|
54 | WHERE element_id = '.$page['image_id'] . ' |
---|
55 | AND user_id = '.$user['id'] ; |
---|
56 | |
---|
57 | if ( !is_autorize_status(ACCESS_CLASSIC) ) |
---|
58 | { |
---|
59 | $ip_components = explode('.', $_SERVER['REMOTE_ADDR']); |
---|
60 | if ( count($ip_components)>3 ) |
---|
61 | { |
---|
62 | array_pop($ip_components); |
---|
63 | } |
---|
64 | $anonymous_id = implode ('.', $ip_components); |
---|
65 | $query .= ' AND anonymous_id = \''.$anonymous_id . '\''; |
---|
66 | } |
---|
67 | |
---|
68 | $result = pwg_query($query); |
---|
69 | if (pwg_db_num_rows($result) > 0) |
---|
70 | { |
---|
71 | $row = pwg_db_fetch_assoc($result); |
---|
72 | $user_rate = $row['rate']; |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | $template->assign( |
---|
77 | 'rating', |
---|
78 | array( |
---|
79 | 'F_ACTION' => add_url_params( |
---|
80 | $url_self, |
---|
81 | array('action'=>'rate') |
---|
82 | ), |
---|
83 | 'USER_RATE'=> $user_rate, |
---|
84 | 'marks' => $conf['rate_items'] |
---|
85 | ) |
---|
86 | ); |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | ?> |
---|