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