<?
    $GLOBALS
['highlight'] = 'upload_image';

    require_once(
'include/functions/pages.php');
            
    include(
'include/parts/header.php');

    
$entries mysql_fetch_array(mysql_query("SELECT COUNT(image_id) AS num FROM gallery_images WHERE user_id = '" $GLOBALS['auth']['id'] . "'"));
    
$page_count ceil($entries['num'] / IMAGES_PER_PAGE);
    
$pages '<span style="color: #cccccc; font-size: 10px;">Page: ' pages('?s=image_upload'$_page$page_count) . '</span><br />';
?>

<div class="header">Graphix Image Upload</div>

<div class="content">
<?
    
if ($_notice)
    {
        echo 
'<span style="color: red;">' $_notice '</span><br />';
        echo 
'<div style="padding: 10px 0px 0px 0px;"></div>';
    }
?>
    Upload a new image. <?= (MAX_PICTURE_UPLOAD_SIZE 1000000?>MB maximum filesize.<br />
    Accepted formats are: JPEG, GIF, PNG.<br /><br />
    
    <form action="?a=upload_image" method="post" enctype="multipart/form-data" style="margin: 0px;">
    <table width="100%" border="0">
    <tr><td width="150" style="text-align: right;">File:</td><td><input type="file" name="picture" style="border: solid 2px black; margin: 0px; padding: 3px;"></td></tr>
    <tr><td width="150" style="text-align: right;"></td><td><input type="submit" value="Upload Image" style="border: solid 1px green; background: black; color: green;"></td></tr>
    </table>
    </form>
</div>

<div class="header">My Gallery Images<?= $entries['num'] ? '<br />' $pages '' ?></div>

<div class="content" style="padding: 0px 5px 5px 5px;">
<?
    $main_image 
mysql_fetch_array(mysql_query("SELECT main_image_id AS id FROM members WHERE id = '" $GLOBALS['auth']['id'] . "'"));
    
$images mysql_query("SELECT image_id FROM gallery_images WHERE user_id = '" $GLOBALS['auth']['id'] . "' ORDER BY posted_on DESC LIMIT " . (($_page 1) * IMAGES_PER_PAGE) . ", " IMAGES_PER_PAGE);
    if (
mysql_num_rows($images))
    {
        echo 
'<table width="100%" cellpaddin="0" cellspacing="0" border="0"><tr><td>';
        while (
$image mysql_fetch_array($images))
        {        
            echo 
box_image_top();
            echo 
'<table width="300" border="0" cellpadding="0" cellspacing="0"><tr><td align="center" valign="top">';
            echo 
'<a href="?s=image&i=' $image['image_id'] . '"><img src="?g=thumb&i=' $image['image_id'] . '" width="' THUMB_WIDTH '" height="' THUMB_HEIGHT '" style="border: 0px;"></a>';
            echo 
'</td><td valign="top" width="170" style="padding-left: 5px;">';
            if (
$main_image['id'] == $image['image_id'])
            {
                echo 
'<div style="border: solid 1px orange; background: black; color: orange; padding: 2px 2px 2px 2px; text-align: center; margin-bottom: 4px;">';
                echo 
'<a href="?a=image_remove_main&p=' $_page '">Unset Main</a>';
                echo 
'</div>';                    
            }
            else
            {
                echo 
'<div style="border: solid 1px green; background: black; color: green; padding: 2px 2px 2px 2px; text-align: center; margin-bottom: 4px;">';
                echo 
'<a href="?a=image_set_main&i=' $image['image_id'].'&p=' $_page '" style="color: green;">Make Main</a>';
                echo 
'</div>';
            }
            if (
$main_image['id'] != $image['image_id'])
            {
                echo 
'<div style="border: solid 1px red; background: black; color: red; padding: 2px 2px 2px 2px; text-align: center; margin-bottom: 4px;">';
                echo 
'<a href="?a=image_remove&i=' $image['image_id'].'&p=' $_page '" style="color: red;">Delete</a>';
                echo 
'</div>';
            }
            echo 
'<div style="border: solid 1px grey; background: black; color: grey; padding: 2px 2px 2px 2px; text-align: center;">';
            echo 
'[' $image['image_id'] . ']';
            echo 
'</div>';
            echo 
'</td></tr></table> ';
            echo 
box_image_bottom();
        }
        echo 
'</td></tr></table> ';
    }
    else
    {
        echo 
'<div style="padding: 5px 0px 0px 0px;"></div>You have no graphix in the database.';
    }
?>
</div>

<?
    
if ($entries['num'])
    {
        echo 
'<div class="header">' $pages '</div>';
    }

    include(
'include/parts/footer.php');
?>