<?
    
require_once('include/functions/image_upload.php');
    
    
$_vote = isset($_POST['type_vote']) ? intval($_POST['type_vote']) : '';

    if (
$GLOBALS['auth']['id'])
    {
        list(
$new$dupe$notice) = process_uploads();
        if (
$new)
        {
            
mysql_query("REPLACE INTO gallery_images SET image_id = '" $new "', user_id = '" $GLOBALS['auth']['id'] . "'");
            if (
$_vote)
            {
                
vote_image($new$_vote);
            }
        }
        elseif (
$dupe)
        {
            
$promoters_images mysql_query("SELECT * FROM gallery_images WHERE image_id = '" $dupe "' AND user_id = '" $GLOBALS['auth']['id'] . "'");
            if (!
mysql_num_rows($promoters_images))
            {
                
mysql_query("REPLACE INTO gallery_images SET image_id = '" $dupe "', user_id = '" $GLOBALS['auth']['id'] . "'");
                if (
$_vote)
                {
                    
vote_image($dupe$_vote);
                }
            }
            else
            {
                
$notice 'Duplicate Image';
            }
        }
        
make_cookie('notice'$notice);
        
header('Location: ./?s=upload_image');
        die;
    }
    else
    {
        
header('Location: ./');
        die;
    }
    
    function 
vote_image($id$the_vote)
    {
        
$vote mysql_query("SELECT name FROM images_categories WHERE id = '" $the_vote "'");
        if (
$vote mysql_fetch_array($vote))
        {
            
mysql_query("REPLACE INTO images_categories_rating SET image_id = '" $id "', category_id = '" $the_vote "', user_id = '" $GLOBALS['auth']['id'] . "', posted_on = NOW()");
        }        
    }
?>