aboutsummaryrefslogtreecommitdiffstats
path: root/include/functions_rate.inc.php
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2007-09-20 04:33:10 +0000
committerrvelices <rv-github@modusoptimus.com>2007-09-20 04:33:10 +0000
commitc5970aba221881d9788197115fd17ab863d72269 (patch)
tree34d81fe1348499e13797328189e03112f26ebdfb /include/functions_rate.inc.php
parent11567fb57b1f36dc7e1387b88ab01d5fa2073c45 (diff)
merge -r 2099 from branch-1_7 to trunk + fix typo (replace get_cookie_var with set_cookie_var)
- fix very rare sql error (duplicate key) for rating git-svn-id: http://piwigo.org/svn/trunk@2100 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--include/functions_rate.inc.php47
1 files changed, 23 insertions, 24 deletions
diff --git a/include/functions_rate.inc.php b/include/functions_rate.inc.php
index a0486bd55..800caca42 100644
--- a/include/functions_rate.inc.php
+++ b/include/functions_rate.inc.php
@@ -49,24 +49,24 @@ function rate_picture($image_id, $rate)
return;
}
- if ($user_anonymous)
+ $ip_components = explode('.', $_SERVER["REMOTE_ADDR"]);
+ if (count($ip_components) > 3)
{
- $ip_components = explode('.', $_SERVER["REMOTE_ADDR"]);
- if (count($ip_components) > 3)
- {
- array_pop($ip_components);
- }
- $anonymous_id = implode ('.', $ip_components);
+ array_pop($ip_components);
+ }
+ $anonymous_id = implode ('.', $ip_components);
+ if ($user_anonymous)
+ {
$save_anonymous_id = pwg_get_cookie_var('anonymous_rater', $anonymous_id);
if ($anonymous_id != $save_anonymous_id)
{ // client has changed his IP adress or he's trying to fool us
$query = '
SELECT element_id
-FROM '.RATE_TABLE.'
-WHERE user_id = '.$user['id'].'
- AND anonymous_id = \''.$anonymous_id.'\'
+ FROM '.RATE_TABLE.'
+ WHERE user_id = '.$user['id'].'
+ AND anonymous_id = \''.$anonymous_id.'\'
;';
$already_there = array_from_query($query, 'element_id');
@@ -74,34 +74,33 @@ WHERE user_id = '.$user['id'].'
{
$query = '
DELETE
-FROM '.RATE_TABLE.'
-WHERE user_id = '.$user['id'].'
- AND anonymous_id = \''.$save_anonymous_id.'\'
- AND element_id NOT IN ('.implode(',', $already_there).')
+ FROM '.RATE_TABLE.'
+ WHERE user_id = '.$user['id'].'
+ AND anonymous_id = \''.$save_anonymous_id.'\'
+ AND element_id IN ('.implode(',', $already_there).')
;';
pwg_query($query);
}
$query = '
-UPDATE
-'.RATE_TABLE.'
-SET anonymous_id = \'' .$anonymous_id.'\'
-WHERE user_id = '.$user['id'].'
- AND anonymous_id = \'' . $save_anonymous_id.'\'
+UPDATE '.RATE_TABLE.'
+ SET anonymous_id = \'' .$anonymous_id.'\'
+ WHERE user_id = '.$user['id'].'
+ AND anonymous_id = \'' . $save_anonymous_id.'\'
;';
pwg_query($query);
} // end client changed ip
- pwg_get_cookie_var('anonymous_rater', $anonymous_id);
+ pwg_set_cookie_var('anonymous_rater', $anonymous_id);
} // end anonymous user
$query = '
DELETE
FROM '.RATE_TABLE.'
WHERE element_id = '.$image_id.'
- AND user_id = '.$user['id'].'
+ AND user_id = '.$user['id'].'
';
- if (isset($anonymous_id))
+ if (isset($user_anonymous))
{
$query.= ' AND anonymous_id = \''.$anonymous_id.'\'';
}
@@ -113,7 +112,7 @@ INSERT
VALUES
('
.$user['id'].','
- .(isset($anonymous_id) ? '\''.$anonymous_id.'\'' : "''").','
+ .'\''.$anonymous_id.'\','
.$image_id.','
.$rate
.',NOW())
@@ -135,4 +134,4 @@ UPDATE '.IMAGES_TABLE.'
pwg_query($query);
}
-?>
+?> \ No newline at end of file