1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based photo gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2012 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 | $rate_summary = array( 'count'=>0, 'score'=>$picture['current']['rating_score'], 'average'=>null ); |
---|
32 | if ( NULL != $rate_summary['score'] ) |
---|
33 | { |
---|
34 | $query = ' |
---|
35 | SELECT COUNT(rate) AS count |
---|
36 | , ROUND(AVG(rate),2) AS average |
---|
37 | FROM '.RATE_TABLE.' |
---|
38 | WHERE element_id = '.$picture['current']['id'].' |
---|
39 | ;'; |
---|
40 | list($rate_summary['count'], $rate_summary['average']) = pwg_db_fetch_row(pwg_query($query)); |
---|
41 | } |
---|
42 | $template->assign('rate_summary', $rate_summary); |
---|
43 | |
---|
44 | $user_rate = null; |
---|
45 | if ($conf['rate_anonymous'] or is_autorize_status(ACCESS_CLASSIC) ) |
---|
46 | { |
---|
47 | if ($rate_summary['count']>0) |
---|
48 | { |
---|
49 | $query = 'SELECT rate |
---|
50 | FROM '.RATE_TABLE.' |
---|
51 | WHERE element_id = '.$page['image_id'] . ' |
---|
52 | AND user_id = '.$user['id'] ; |
---|
53 | |
---|
54 | if ( !is_autorize_status(ACCESS_CLASSIC) ) |
---|
55 | { |
---|
56 | $ip_components = explode('.', $_SERVER['REMOTE_ADDR']); |
---|
57 | if ( count($ip_components)>3 ) |
---|
58 | { |
---|
59 | array_pop($ip_components); |
---|
60 | } |
---|
61 | $anonymous_id = implode ('.', $ip_components); |
---|
62 | $query .= ' AND anonymous_id = \''.$anonymous_id . '\''; |
---|
63 | } |
---|
64 | |
---|
65 | $result = pwg_query($query); |
---|
66 | if (pwg_db_num_rows($result) > 0) |
---|
67 | { |
---|
68 | $row = pwg_db_fetch_assoc($result); |
---|
69 | $user_rate = $row['rate']; |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | $template->assign( |
---|
74 | 'rating', |
---|
75 | array( |
---|
76 | 'F_ACTION' => add_url_params( |
---|
77 | $url_self, |
---|
78 | array('action'=>'rate') |
---|
79 | ), |
---|
80 | 'USER_RATE'=> $user_rate, |
---|
81 | 'marks' => $conf['rate_items'] |
---|
82 | ) |
---|
83 | ); |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | ?> |
---|