[1082] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[2297] | 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
[3049] | 5 | // | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org | |
---|
[2297] | 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 | // +-----------------------------------------------------------------------+ |
---|
[1082] | 23 | |
---|
| 24 | /** |
---|
| 25 | * This file is included by the picture page to manage rates |
---|
[1090] | 26 | * |
---|
[1082] | 27 | */ |
---|
| 28 | |
---|
| 29 | if ($conf['rate']) |
---|
| 30 | { |
---|
[2309] | 31 | if ( NULL != $picture['current']['average_rate'] ) |
---|
| 32 | { |
---|
| 33 | $query = ' |
---|
[1082] | 34 | SELECT COUNT(rate) AS count |
---|
| 35 | , ROUND(AVG(rate),2) AS average |
---|
[2227] | 36 | , ROUND(STD(rate),2) AS std |
---|
[1082] | 37 | FROM '.RATE_TABLE.' |
---|
| 38 | WHERE element_id = '.$picture['current']['id'].' |
---|
| 39 | ;'; |
---|
[2309] | 40 | $row = mysql_fetch_array(pwg_query($query)); |
---|
| 41 | } |
---|
| 42 | else |
---|
| 43 | { // avg rate null -> no rate -> no need to query db |
---|
| 44 | $row = array( 'count'=>0, 'average'=>NULL, 'std'=>NULL ); |
---|
| 45 | } |
---|
[2227] | 46 | $template->assign('rate_summary', $row); |
---|
[1082] | 47 | |
---|
[1286] | 48 | $user_rate = null; |
---|
[1092] | 49 | if ($conf['rate_anonymous'] or is_autorize_status(ACCESS_CLASSIC) ) |
---|
[1082] | 50 | { |
---|
| 51 | if ($row['count']>0) |
---|
| 52 | { |
---|
| 53 | $query = 'SELECT rate |
---|
| 54 | FROM '.RATE_TABLE.' |
---|
| 55 | WHERE element_id = '.$page['image_id'] . ' |
---|
| 56 | AND user_id = '.$user['id'] ; |
---|
| 57 | |
---|
[1092] | 58 | if ( !is_autorize_status(ACCESS_CLASSIC) ) |
---|
[1082] | 59 | { |
---|
| 60 | $ip_components = explode('.', $_SERVER['REMOTE_ADDR']); |
---|
| 61 | if ( count($ip_components)>3 ) |
---|
| 62 | { |
---|
| 63 | array_pop($ip_components); |
---|
| 64 | } |
---|
| 65 | $anonymous_id = implode ('.', $ip_components); |
---|
| 66 | $query .= ' AND anonymous_id = \''.$anonymous_id . '\''; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | $result = pwg_query($query); |
---|
| 70 | if (mysql_num_rows($result) > 0) |
---|
| 71 | { |
---|
| 72 | $row = mysql_fetch_array($result); |
---|
[1286] | 73 | $user_rate = $row['rate']; |
---|
[1082] | 74 | } |
---|
| 75 | } |
---|
[1286] | 76 | |
---|
[2227] | 77 | $template->assign( |
---|
| 78 | 'rating', |
---|
| 79 | array( |
---|
| 80 | 'F_ACTION' => add_url_params( |
---|
[1286] | 81 | $url_self, |
---|
| 82 | array('action'=>'rate') |
---|
[2227] | 83 | ), |
---|
| 84 | 'USER_RATE'=> $user_rate, |
---|
| 85 | 'marks' => $conf['rate_items'] |
---|
[1082] | 86 | ) |
---|
| 87 | ); |
---|
| 88 | } |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | ?> |
---|