[1082] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[2297] | 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
[5196] | 5 | // | Copyright(C) 2008-2010 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 |
---|
| 36 | FROM '.RATE_TABLE.' |
---|
| 37 | WHERE element_id = '.$picture['current']['id'].' |
---|
| 38 | ;'; |
---|
[4325] | 39 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
[2309] | 40 | } |
---|
| 41 | else |
---|
| 42 | { // avg rate null -> no rate -> no need to query db |
---|
[5500] | 43 | $row = array( 'count'=>0, 'average'=>NULL ); |
---|
[2309] | 44 | } |
---|
[2227] | 45 | $template->assign('rate_summary', $row); |
---|
[1082] | 46 | |
---|
[1286] | 47 | $user_rate = null; |
---|
[1092] | 48 | if ($conf['rate_anonymous'] or is_autorize_status(ACCESS_CLASSIC) ) |
---|
[1082] | 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 | |
---|
[1092] | 57 | if ( !is_autorize_status(ACCESS_CLASSIC) ) |
---|
[1082] | 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); |
---|
[4325] | 69 | if (pwg_db_num_rows($result) > 0) |
---|
[1082] | 70 | { |
---|
[4325] | 71 | $row = pwg_db_fetch_assoc($result); |
---|
[1286] | 72 | $user_rate = $row['rate']; |
---|
[1082] | 73 | } |
---|
| 74 | } |
---|
[1286] | 75 | |
---|
[2227] | 76 | $template->assign( |
---|
| 77 | 'rating', |
---|
| 78 | array( |
---|
| 79 | 'F_ACTION' => add_url_params( |
---|
[1286] | 80 | $url_self, |
---|
| 81 | array('action'=>'rate') |
---|
[2227] | 82 | ), |
---|
| 83 | 'USER_RATE'=> $user_rate, |
---|
| 84 | 'marks' => $conf['rate_items'] |
---|
[1082] | 85 | ) |
---|
| 86 | ); |
---|
| 87 | } |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | ?> |
---|