prefix("xcgal_pictures")." AS p, ".$xoopsDB->prefix("xcgal_albums")." AS a ". "WHERE p.aid = a.aid AND pid = '$pic' LIMIT 1"; $result = $xoopsDB->query($sql); if (!$xoopsDB->getRowsNum($result)) redirect_header('index.php',2,_MD_NON_EXIST_AP); $row = $xoopsDB->fetchArray($result); $xoopsDB->freeRecordSet($result); if (!USER_CAN_RATE_PICTURES || $row['votes_allowed'] == 'NO') redirect_header($location,2,_MD_PERM_DENIED); // Clean votes older votes $curr_time = time(); if ($xoopsModuleConfig['keep_votes_time'] > 0){ $clean_before = $curr_time - $xoopsModuleConfig['keep_votes_time'] * 86400; $sql = "DELETE ". "FROM ".$xoopsDB->prefix("xcgal_votes")." ". "WHERE vote_time < $clean_before"; $result = $xoopsDB->queryf($sql); } // Check if user already rated this picture if (is_object($xoopsUser)){ $vid = $xoopsUser->uid(); $sql = "SELECT * ". "FROM ".$xoopsDB->prefix("xcgal_votes")." ". "WHERE pic_id = '$pic' AND v_uid = '$vid'"; } else { $vid = 0; $sql = "SELECT * ". "FROM ".$xoopsDB->prefix("xcgal_votes")." ". "WHERE pic_id = '$pic' AND vote_time > '".(time()-86400)."' AND ip='".$HTTP_SERVER_VARS['REMOTE_ADDR']."'"; } $result = $xoopsDB->query($sql); if ($xoopsDB->getRowsNum($result)) redirect_header($location,2,_MD_RATE_ALREADY); // Update picture rating $new_rating = round(($row['votes'] * $row['pic_rating'] + $rate * 2000)/($row['votes']+1)); $sql = "UPDATE ".$xoopsDB->prefix("xcgal_pictures")." ". "SET pic_rating = '$new_rating', votes = votes + 1 ". "WHERE pid = '$pic' LIMIT 1"; $result = $xoopsDB->queryf($sql); // Update the votes table $sql = "INSERT INTO ".$xoopsDB->prefix("xcgal_votes")." ". "VALUES ('$pic', '".$HTTP_SERVER_VARS['REMOTE_ADDR']."', '$curr_time', '$vid')"; $result = $xoopsDB->queryf($sql); redirect_header($location,2,_MD_RATE_OK); ?>