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-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | branch : BSF (Best So Far) |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2008-04-25 23:39:06 +0000 (Fri, 25 Apr 2008) $ |
---|
10 | // | last modifier : $Author: rvelices $ |
---|
11 | // | revision : $Revision: 2310 $ |
---|
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 | /** |
---|
29 | * This file is included by the picture page to manage rates |
---|
30 | * |
---|
31 | */ |
---|
32 | |
---|
33 | if ($conf['rate']) |
---|
34 | { |
---|
35 | if ( NULL != $picture['current']['average_rate'] ) |
---|
36 | { |
---|
37 | $query = ' |
---|
38 | SELECT COUNT(rate) AS count |
---|
39 | , ROUND(AVG(rate),2) AS average |
---|
40 | , ROUND(STD(rate),2) AS STD |
---|
41 | FROM '.RATE_TABLE.' |
---|
42 | WHERE element_id = '.$picture['current']['id'].' |
---|
43 | ;'; |
---|
44 | $row = mysql_fetch_array(pwg_query($query)); |
---|
45 | } |
---|
46 | else |
---|
47 | { // avg rate null -> no rate -> no need to query db |
---|
48 | $row = array( 'count'=>0, 'average'=>NULL, 'std'=>NULL ); |
---|
49 | } |
---|
50 | |
---|
51 | if ($row['count'] == 0) |
---|
52 | { |
---|
53 | $value = l10n('no_rate'); |
---|
54 | } |
---|
55 | else |
---|
56 | { |
---|
57 | $value = sprintf( |
---|
58 | l10n('%.2f (rated %d times, standard deviation = %.2f)'), |
---|
59 | $row['average'], |
---|
60 | $row['count'], |
---|
61 | $row['STD'] |
---|
62 | ); |
---|
63 | } |
---|
64 | |
---|
65 | $user_rate = null; |
---|
66 | if ($conf['rate_anonymous'] or is_autorize_status(ACCESS_CLASSIC) ) |
---|
67 | { |
---|
68 | if ($row['count']>0) |
---|
69 | { |
---|
70 | $query = 'SELECT rate |
---|
71 | FROM '.RATE_TABLE.' |
---|
72 | WHERE element_id = '.$page['image_id'] . ' |
---|
73 | AND user_id = '.$user['id'] ; |
---|
74 | |
---|
75 | if ( !is_autorize_status(ACCESS_CLASSIC) ) |
---|
76 | { |
---|
77 | $ip_components = explode('.', $_SERVER['REMOTE_ADDR']); |
---|
78 | if ( count($ip_components)>3 ) |
---|
79 | { |
---|
80 | array_pop($ip_components); |
---|
81 | } |
---|
82 | $anonymous_id = implode ('.', $ip_components); |
---|
83 | $query .= ' AND anonymous_id = \''.$anonymous_id . '\''; |
---|
84 | } |
---|
85 | |
---|
86 | $result = pwg_query($query); |
---|
87 | if (mysql_num_rows($result) > 0) |
---|
88 | { |
---|
89 | $row = mysql_fetch_array($result); |
---|
90 | $user_rate = $row['rate']; |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | $template->assign_block_vars( |
---|
95 | 'rate', |
---|
96 | array( |
---|
97 | 'SENTENCE' =>isset($user_rate) ? l10n('update_rate') : l10n('new_rate'), |
---|
98 | 'F_ACTION' => add_url_params( |
---|
99 | $url_self, |
---|
100 | array('action'=>'rate') |
---|
101 | ) |
---|
102 | ) |
---|
103 | ); |
---|
104 | |
---|
105 | $template->assign_block_vars('info_rate', array('CONTENT' => $value)); |
---|
106 | |
---|
107 | foreach ($conf['rate_items'] as $num => $mark) |
---|
108 | { |
---|
109 | $template->assign_block_vars( |
---|
110 | 'rate.rate_option', |
---|
111 | array( |
---|
112 | 'OPTION' => $mark, |
---|
113 | 'SEPARATOR' => ($num > 0 ? '|' : ''), |
---|
114 | ) |
---|
115 | ); |
---|
116 | if (isset($user_rate) and $user_rate==$mark) |
---|
117 | { |
---|
118 | $template->assign_block_vars('rate.rate_option.my_rate', array() ); |
---|
119 | } |
---|
120 | else |
---|
121 | { |
---|
122 | $template->assign_block_vars('rate.rate_option.not_my_rate', array() ); |
---|
123 | } |
---|
124 | } |
---|
125 | } |
---|
126 | } |
---|
127 | |
---|
128 | ?> |
---|