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

    function 
image_voting($id)
    {
?>

<script type="text/javascript">
var user_id = <?= $GLOBALS['auth']['id'] > $GLOBALS['auth']['id'] : 'null' ?>;
function ajax_eval(script, value)
{
    if (user_id > 0)
    {
        doAjax('index.php?j=' + script + '&i=<?= $id ?>&v=' + value, function(AJAX) { eval(AJAX.responseText); });
    }
    else
    {
        alert("You must be logged-in in order to vote.");
    }
}
</script>

<?
        
echo '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td>';
        if (
$GLOBALS['auth']['id'])
        {
            echo 
'Rate Image: ';
            echo 
'<a href="javascript:ajax_eval(\'image_rate\', 1);"><span class="notice_good">Good</span></a> / ';
            echo 
'<a href="javascript:ajax_eval(\'image_rate\', 0);"><span class="notice_error">Bad</span></a>' "\r\n";
            echo 
' - <span id="vote_holder">';
            
$vote mysql_query("SELECT vote FROM images_rating WHERE user_id = '" $GLOBALS['auth']['id'] . "' AND image_id = '" $id "'");
            if (
$vote mysql_fetch_array($vote))
            {
                echo 
'You Voted: ';
                if (
$vote['vote'] == 1)
                {
                    echo 
'<span class="notice_good">Good</span>';
                }
                elseif (
$vote['vote'] == -1)
                {
                    echo 
'<span class="notice_error">Bad</span>';
                }
            }
            echo 
'</span> ';
        }    
        echo 
'Overall: <span id="v_rating">' image_overall_rating($id) . '</span>';
        echo 
'</td><td align="right">';
        if (
$GLOBALS['auth']['id'])
        {
            
$your_type mysql_query("SELECT category_id FROM images_categories_rating WHERE image_id = '" $id "' AND user_id = '" $GLOBALS['auth']['id'] . "'");
            
$type 0;
            if (
$your_type mysql_fetch_array($your_type))
            {
                
$type $your_type['category_id'];
            }
            echo 
'Vote Type: <form style="margin: 0px; display: inline;">';
            echo 
'<select id="section" name="section" class="input_select" style="font-size: 12px;" onChange="ajax_eval(\'image_typed\', document.getElementById(\'section\').value);">';
            echo 
'<option value="0"' . ($type == 'selected' '') . '></option>';
            
$gallery_sections mysql_query("SELECT name, id, worksafe FROM images_categories ORDER BY name");
            while (
$gallery_section mysql_fetch_array($gallery_sections))
            {
                echo 
'<option value="' $gallery_section['id'] . '" ' . ($type == $gallery_section['id'] ? 'selected ' '') . 'class="' . ($gallery_section['worksafe'] == 'notice_error' 'notice_good') . '">' $gallery_section['name'] . ($gallery_section['worksafe'] == '' ' - Not Worksafe') . '</option>';
            }
            echo 
'</select>';
            echo 
'</form>&nbsp;';
        }
        echo 
'Overall: <span id="v_type">' image_overall_type($id) . '</span>' "\r\n";
        echo 
'</td></tr></table>';
    }
?>