Changeset 1092 for trunk/include/functions_rate.inc.php
- Timestamp:
- Mar 22, 2006, 2:01:47 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/functions_rate.inc.php
-
Property
svn:eol-style
set to
native
-
Property
svn:keywords
set to
Author Date Id Revision
r1084 r1092 7 7 // | branch : BSF (Best So Far) 8 8 // | file : $RCSfile$ 9 // | last update : $Date: 2006-03-15 03:26:25 +0100 (mer, 15 mar 2006) $ 10 // | last modifier : $Author: rvelices $ 11 // | revision : $Revision: 1081 $ 12 // | revision : $Revision: 1081 $ 9 // | last update : $Date$ 10 // | last modifier : $Author$ 11 // | revision : $Revision$ 13 12 // +-----------------------------------------------------------------------+ 14 13 // | This program is free software; you can redistribute it and/or modify | … … 30 29 * rate a picture by a user 31 30 * 32 * @param int user identifier33 31 * @param int image identifier 34 32 * @param int rate 35 33 * @return void 36 34 */ 37 function rate_picture($ user_id, $image_id, $rate)35 function rate_picture($image_id, $rate) 38 36 { 39 global $conf ;37 global $conf, $user; 40 38 41 $query = '42 SELECT status 43 FROM '.USER_INFOS_TABLE.'44 WHERE user_id = '.$user_id.'45 ;';46 list($user_status) = mysql_fetch_array(pwg_query($query));39 if (!isset($rate) 40 or !$conf['rate'] 41 or !in_array($rate, $conf['rate_items'])) 42 { 43 return; 44 } 47 45 48 if ('guest' == $user_status 49 or 'generic' == $user_status) 46 $user_anonymous = is_autorize_status(ACCESS_CLASSIC) ? false : true; 47 48 if ($user_anonymous and !$conf['rate_anonymous']) 50 49 { 51 $user_anonymous = true;50 return; 52 51 } 53 else 52 53 if ($user_anonymous) 54 54 { 55 $user_anonymous = false; 56 } 57 58 if (isset($rate) 59 and $conf['rate'] 60 and (!$user_anonymous or $conf['rate_anonymous']) 61 and in_array($rate, $conf['rate_items'])) 62 { 63 if ($user_anonymous) 55 $ip_components = explode('.', $_SERVER["REMOTE_ADDR"]); 56 if (count($ip_components) > 3) 64 57 { 65 $ip_components = explode('.', $_SERVER["REMOTE_ADDR"]); 66 if (count($ip_components) > 3) 67 { 68 array_pop($ip_components); 69 } 70 $anonymous_id = implode ('.', $ip_components); 71 72 if (isset($_COOKIE['pwg_anonymous_rater'])) 73 { 74 if ($anonymous_id != $_COOKIE['pwg_anonymous_rater']) 75 { // client has changed his IP adress or he's trying to fool us 76 $query = ' 58 array_pop($ip_components); 59 } 60 $anonymous_id = implode ('.', $ip_components); 61 62 if (isset($_COOKIE['pwg_anonymous_rater'])) 63 { 64 if ($anonymous_id != $_COOKIE['pwg_anonymous_rater']) 65 { // client has changed his IP adress or he's trying to fool us 66 $query = ' 77 67 SELECT element_id 78 68 FROM '.RATE_TABLE.' … … 80 70 AND anonymous_id = \''.$anonymous_id.'\' 81 71 ;'; 82 83 84 85 86 72 $already_there = array_from_query($query, 'element_id'); 73 74 if (count($already_there) > 0) 75 { 76 $query = ' 87 77 DELETE 88 78 FROM '.RATE_TABLE.' … … 91 81 AND element_id NOT IN ('.implode(',', $already_there).') 92 82 ;'; 93 94 83 pwg_query($query); 84 } 95 85 96 86 $query = ' 97 87 UPDATE 98 88 '.RATE_TABLE.' … … 101 91 AND anonymous_id = \'' . $_COOKIE['pwg_anonymous_rater'].'\' 102 92 ;'; 103 93 pwg_query($query); 104 94 105 95 setcookie( 106 96 'pwg_anonymous_rater', 107 97 $anonymous_id, 108 98 strtotime('+10 years'), 109 99 cookie_path() 110 111 }112 }113 114 115 100 ); 101 } // end client changed ip 102 } // end client has cookie 103 else 104 { 105 setcookie( 116 106 'pwg_anonymous_rater', 117 107 $anonymous_id, … … 119 109 cookie_path() 120 110 ); 121 }122 111 } 123 124 112 } // end anonymous user 113 $query = ' 125 114 DELETE 126 115 FROM '.RATE_TABLE.' 127 116 WHERE element_id = '.$image_id.' 128 AND user_id = '.$user _id.'117 AND user_id = '.$user['id'].' 129 118 '; 130 131 132 133 134 135 119 if (isset($anonymous_id)) 120 { 121 $query.= ' AND anonymous_id = \''.$anonymous_id.'\''; 122 } 123 pwg_query($query); 124 $query = ' 136 125 INSERT 137 126 INTO '.RATE_TABLE.' … … 139 128 VALUES 140 129 (' 141 .$user_id.','142 143 144 145 130 .$user['id'].',' 131 .(isset($anonymous_id) ? '\''.$anonymous_id.'\'' : "''").',' 132 .$image_id.',' 133 .$rate 134 .',NOW()) 146 135 ;'; 147 148 149 150 136 pwg_query($query); 137 138 // update of images.average_rate field 139 $query = ' 151 140 SELECT ROUND(AVG(rate),2) AS average_rate 152 141 FROM '.RATE_TABLE.' 153 142 WHERE element_id = '.$image_id.' 154 143 ;'; 155 156 144 $row = mysql_fetch_array(pwg_query($query)); 145 $query = ' 157 146 UPDATE '.IMAGES_TABLE.' 158 147 SET average_rate = '.$row['average_rate'].' 159 148 WHERE id = '.$image_id.' 160 149 ;'; 161 pwg_query($query); 162 } 150 pwg_query($query); 163 151 } 164 152 -
Property
svn:eol-style
set to
Note: See TracChangeset
for help on using the changeset viewer.