<?php
    $GLOBALS['highlight'] = 'tiles_pending';

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

    include('include/parts/header.php');
    
    $entries = mysqli_fetch_array(mysqli_query_logged("SELECT COUNT(*) AS num FROM tiles_pending WHERE user_id = '" . $GLOBALS['auth']['id'] . "'"));
    $page_count = ceil($entries['num'] / 1);
    $pages = '<span class="pages">Page: ' . pages('?s=tiles_pending', $_page, $page_count) . '</span><br />';
?>
    
<div class="header">Pending Tiles<?php echo $entries['num'] ? '<br />' . $pages : '' ?></div>

<div class="content" style="padding: 0px 5px 5px 5px;">
<?php
    $tiles_pending = mysqli_query_logged("SELECT * FROM tiles_pending WHERE user_id = '" . $GLOBALS['auth']['id'] . "' ORDER BY due_date DESC LIMIT " . (($_page - 1) * 1) . ", " . 1);
    if (mysqli_num_rows($tiles_pending))
    {
        while ($tiles_pending_row = mysqli_fetch_array($tiles_pending))
        {
             $quilts = mysqli_query_logged("SELECT * FROM quilts WHERE id = '" . $tiles_pending_row['quilt_id'] . "'");
            if ($quilts_row = mysqli_fetch_array($quilts))
            {
                echo '<table width="100%" border="0" cellpadding="0" cellspacing="0" style="padding-top: 3px;"><tr><td width="400" valign="top">';
                echo '<img src="?g=tile_sides&i=' . $tiles_pending_row['quilt_id'] . '&x=' . $tiles_pending_row['matrix_x'] . '&y=' . $tiles_pending_row['matrix_y'] . '&borders=' . $tiles_pending_row['borders'] . '" width="' . ($quilts_row['tile_width'] + $quilts_row['side_pixels'] * 2) . '" height="' . ($quilts_row['tile_height'] + $quilts_row['side_pixels'] * 2) . '" border="0"><br />';
                echo '<span style="font-size: 5px;"><br /></span>';
                echo '<form action="?a=tile_cancel&i=' . $tiles_pending_row['quilt_id'] . '&x=' . $tiles_pending_row['matrix_x'] . '&y=' . $tiles_pending_row['matrix_y'] . '" method="post" style="margin: 0px;">';
                echo '<input type="submit" value="Cancel Tile" style="border: solid 1px red; background: black; color: red;">';
                echo '</form>';
                echo '</td><td valign="top">';
                echo '<form action="?a=upload_tile&i=' . $tiles_pending_row['quilt_id'] . '&x=' . $tiles_pending_row['matrix_x'] . '&y=' . $tiles_pending_row['matrix_y'] . '" method="post" enctype="multipart/form-data" style="margin: 0px;">';
                echo '<table border="0" cellpadding="2" cellspacing="0">';
                echo '<tr><td style="width: 150px; text-align: right;">From Quilt:</td><td><a href="?s=quilt&i=' . $tiles_pending_row['quilt_id'] . '">' . $quilts_row['name'] . '</a></td></tr>';
                echo '<tr><td style="width: 150px; text-align: right;">Checkout Date:</td><td>' . nice_date($tiles_pending_row['started_on'], 'F j, Y @ g:ia') . '</td></tr>';
                echo '<tr><td style="width: 150px; text-align: right;">Due Date:</td><td>' . nice_date($tiles_pending_row['started_on'], 'F j, Y @ g:ia', $quilts_row['timelimit']) . '</td></tr>';
                echo '<tr><td style="width: 150px; text-align: right;">Checkin Tile:</td><td><input name="tile" type="file" style="border: solid 2px black; margin: 0px; padding: 3px;"></td></tr>';
                echo '<tr><td style="width: 150px; text-align: right;">Comment:</td><td><input name="comment" size="40" style="border: solid 2px black; margin: 0px; padding: 3px;"></td></tr>';
                echo '<tr><td style="width: 150px; text-align: right;"></td><td><input type="submit" value="Checkin This Tile" style="border: solid 1px green; background: black; color: green;"></td></tr>';
                echo '</table>';
                echo '</form>';
                echo '</td></tr></table>';
            }
        }
    }
    else
    {
        echo '<div style="padding: 5px 0px 0px 0px;"></div>You do not have any tiles pending.';
    }
?>
</div>

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

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