include/functions.php
function update_image_rating($image_id, $rating) {
global $site_db, $user_info, $lang;
$sql = "SELECT cat_id, user_id, image_votes, image_rating
FROM ".IMAGES_TABLE."
WHERE image_id = $image_id";
$image_row = $site_db->query_firstrow($sql);
if ($user_info['user_level'] != ADMIN && $image_row['user_id'] == $user_info['user_id']) {
return "Du darfst Deine eigenen Bilder nicht bewerten";
}
if (check_permission("auth_vote", $image_row['cat_id'])) {
$old_votes = $image_row['image_votes'];
$old_rating = $image_row['image_rating'];
$new_rating = (($old_rating * $old_votes) + $rating) / ($old_votes + 1);
$new_rating = sprintf("%.2f", $new_rating);
$sql = "UPDATE ".IMAGES_TABLE."
SET image_votes = ($old_votes + 1), image_rating = '$new_rating'
WHERE image_id = $image_id";
$site_db->query($sql);
return $lang['voting_success'];
}
return $lang['voting_error'];
}
In includes/page_header.php
update_image_rating($id, $rating);
$msg = $lang['voting_success'];
ersetzen durch:
$msg = update_image_rating($id, $rating);