<?
    
require_once('include/functions/community_thread_overall_rating.php');

    
$_id = (isset($_GET['i'])) ? trim($_GET['i']) : '';
    
$_vote = (isset($_GET['v'])) ? trim($_GET['v']) : '';
        
    
$community_threads mysql_query("SELECT thread_user_id FROM community_threads WHERE thread_id = '" $_id "'");
    if (
$community_threads_row mysql_fetch_array($community_threads))
    {
        if (
$community_threads_row['thread_user_id'] != $GLOBALS['auth']['id'])
        {
            
$community_threads_categories mysql_query("SELECT * FROM community_threads_categories WHERE id = '" $_vote "'");
            if (
$community_threads_categories_row mysql_fetch_array($community_threads_categories))
            {
                
mysql_query("REPLACE INTO community_threads_ratings SET thread_id = '" $_id "', category_id = '" $_vote "', user_id = '" $GLOBALS['auth']['id'] . "', posted_on = NOW()");
            }
            elseif (
$_vote == '0')
            {
                
mysql_query("DELETE FROM community_threads_ratings WHERE thread_id = '" $_id "' AND user_id = '" $GLOBALS['auth']['id'] . "'");
            }    
        }
        echo 
"document.getElementById('thread_ranking').innerHTML = '" thread_overall_rating($_id) . "';";
    }
?>