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

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

    if (!$_display) {
        $_display = 'all';
    }
    elseif (!(ord($_display) >= 65 && ord($_display) <= 90) && !(ord($_display) >= 97 && ord($_display) <= 122))
    {
        $_display = 'all';
    }
    if ($_display == 'all')
    {
        $image_count = mysqli_fetch_array(mysqli_query_logged("SELECT COUNT(*) AS num FROM members"));
    }
    else
    {
        $image_count = mysqli_fetch_array(mysqli_query_logged("SELECT COUNT(*) AS num FROM members WHERE username LIKE '" . $_display . "%'"));
    }
    $page_count = ceil($image_count['num'] / 100);
    $pages = '<span class="pages">Page: ' . pages('?s=members' . ($_display ? '&d=' . $_display : ''), $_page, $page_count) . '</span>';
?>

<div class="header">Members<?php echo $image_count['num'] ? '<br />' . $pages : '' ?></div>
<div class="content">
<div class="header" style="margin-bottom: 0px;">
<?php
    echo '<a href="?s=members">All</a> : ';
    for ($i = 65; $i <= 90; $i++)
    {
        echo '<a href="?s=members&d=' . strtolower(chr($i)) . '">' . chr($i) . '</a> ';    
    }
?>
</div>
<?php
    if ($_display == 'all')
    {
        $members = mysqli_query_logged("SELECT id, main_image_id FROM members ORDER BY username LIMIT " . (($_page - 1) * 100) . ', ' . 100);
    }
    else
    {
        $members = mysqli_query_logged("SELECT id, main_image_id FROM members WHERE username LIKE '" . $_display . "%' ORDER BY username LIMIT " . (($_page - 1) * 100) . ', ' . 100);
    }
    if (mysqli_num_rows($members))
    {
        echo '<table width="100%" cellpaddin="0" cellspacing="0" border="0"><tr><td>';
        while ($user = mysqli_fetch_array($members))
        {
            $user_info = mysqli_fetch_array(mysqli_query_logged("SELECT * FROM members_extras WHERE user_id = '" . $user['id'] . "'"));
            echo box_image_top();
            echo '<table width="' . (THUMB_WIDTH / 1.3) . '" height="' . (THUMB_HEIGHT / 1.3) . '" border="0" cellpadding="0" cellspacing="0"><tr><td align="center" valign="top">';
            echo '<a href="?s=profile&u=' . get_username($user['id']) . '"><img src="?g=thumb&i=' . $user['main_image_id'] . '" width="' . (THUMB_WIDTH / 1.3) . '" height="' . (THUMB_HEIGHT / 1.3) . '" alt="" style="border: solid 0px black;"></a><br />'; 
            echo '<div style="padding: 5px 0px 0px 0px;"></div>';
            echo get_username($user['id']);
            echo '</td></tr></table>';
            echo box_image_bottom();
        }
        echo '</td></tr></table>';
    }
    else
    {
        echo '<div style="padding: 5px 0px 0px 0px;"></div>No members to show...';
    }    
?>
</div>
<?php
    if ($image_count['num'])
    {
        echo '<div class="header">' . $pages  . '</div>';
    }

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