Changeset 1084 for trunk/picture.php
- Timestamp:
- Mar 16, 2006, 11:34:45 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/picture.php
r1082 r1084 28 28 define('PHPWG_ROOT_PATH','./'); 29 29 include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); 30 include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php'); 30 31 include(PHPWG_ROOT_PATH.'include/section_init.inc.php'); 31 32 … … 195 196 case 'rate' : 196 197 { 197 if (isset($_GET['rate']) 198 and $conf['rate'] 199 and (!$user['is_the_guest'] or $conf['rate_anonymous']) 200 and in_array($_GET['rate'], $rate_items)) 201 { 202 if ($user['is_the_guest']) 203 { 204 $ip_components = explode('.', $_SERVER["REMOTE_ADDR"]); 205 if (count($ip_components) > 3) 206 { 207 array_pop($ip_components); 208 } 209 $anonymous_id = implode ('.', $ip_components); 210 211 if (isset($_COOKIE['pwg_anonymous_rater'])) 212 { 213 if ($anonymous_id != $_COOKIE['pwg_anonymous_rater']) 214 { // client has changed his IP adress or he's trying to fool us 215 $query = ' 216 SELECT element_id FROM '. RATE_TABLE . ' 217 WHERE user_id=' . $user['id'] . ' 218 AND anonymous_id=\'' . $anonymous_id . '\''; 219 $result = pwg_query($query); 220 $already_there = array(); 221 while ($row = mysql_fetch_array($result)) 222 { 223 array_push($already_there, $row['element_id']); 224 } 225 226 if (count($already_there) > 0) 227 { 228 $query = ' 229 DELETE 230 FROM '.RATE_TABLE.' 231 WHERE user_id = '.$user['id'].' 232 AND anonymous_id = \''.$_COOKIE['pwg_anonymous_rater'].'\' 233 AND element_id NOT IN ('.implode(',', $already_there).') 234 ;'; 235 pwg_query($query); 236 } 237 238 $query = ' 239 UPDATE 240 '.RATE_TABLE.' 241 SET anonymous_id = \'' .$anonymous_id.'\' 242 WHERE user_id = '.$user['id'].' 243 AND anonymous_id = \'' . $_COOKIE['pwg_anonymous_rater'].'\' 244 ;'; 245 pwg_query($query); 246 247 setcookie( 248 'pwg_anonymous_rater', 249 $anonymous_id, 250 strtotime('+10 years'), 251 cookie_path() 252 ); 253 } 254 } 255 else 256 { 257 setcookie( 258 'pwg_anonymous_rater', 259 $anonymous_id, 260 strtotime('+10 years'), 261 cookie_path() 262 ); 263 } 264 } 265 266 $query = ' 267 DELETE 268 FROM '.RATE_TABLE.' 269 WHERE element_id = '.$page['image_id'] . ' 270 AND user_id = '.$user['id'].' 271 '; 272 if (isset($anonymous_id)) 273 { 274 $query.= ' AND anonymous_id = \''.$anonymous_id.'\''; 275 } 276 pwg_query($query); 277 $query = ' 278 INSERT 279 INTO '.RATE_TABLE.' 280 (user_id,anonymous_id,element_id,rate,date) 281 VALUES 282 (' 283 .$user['id'].',' 284 .(isset($anonymous_id) ? '\''.$anonymous_id.'\'' : "''").',' 285 .$page['image_id'].',' 286 .$_GET['rate'] 287 .',NOW()) 288 ;'; 289 pwg_query($query); 290 291 // update of images.average_rate field 292 $query = ' 293 SELECT ROUND(AVG(rate),2) AS average_rate 294 FROM '.RATE_TABLE.' 295 WHERE element_id = '.$page['image_id'].' 296 ;'; 297 $row = mysql_fetch_array(pwg_query($query)); 298 $query = ' 299 UPDATE '.IMAGES_TABLE.' 300 SET average_rate = '.$row['average_rate'].' 301 WHERE id = '.$page['image_id'].' 302 ;'; 303 pwg_query($query); 304 } 305 198 rate_picture($user['id'], $page['image_id'], $_GET['rate']); 306 199 redirect($url_self); 307 200 }
Note: See TracChangeset
for help on using the changeset viewer.