<?php
    $GLOBALS['highlight'] = 'friends';
    
    require_once('include/functions/pages.php');
    
    $_page = isset($_GET['p']) ? intval($_GET['p']) : 1;

    include('include/parts/header.php');
    
    $entries = mysqli_fetch_array(mysqli_query_logged("SELECT COUNT(*) AS num FROM friends"));
    $page_count = ceil($entries['num'] / 100);
    $pages = '<span class="pages">Page: ' . pages('?s=friends', $_page, $page_count) . '</span>';
?>

<div class="header">Friends</div>
<div class="content" style="padding: 0px 5px 5px 5px;">
<?php
    $friends = mysqli_query_logged("SELECT friend_id FROM friends WHERE user_id = '" . $GLOBALS['auth']['id'] . "' ORDER BY friend_id LIMIT " . (($_page - 1) * 100) . ', ' . 100);
    if (mysqli_num_rows($friends))
    {
        echo '<table width="100%" cellpaddin="0" cellspacing="0" border="0"><tr><td>';
        while ($friends_row = mysqli_fetch_array($friends))
        {
            echo box_image_top();
            echo '<table width="' . (THUMB_WIDTH / 1.3) . '" height="' . (THUMB_HEIGHT / 1.3) . '" cellpadding="0" cellspacing="0" border="0"><tr><td align="center" valign="top">';
            echo '<a href="?s=profile&u=' . get_username($friends_row['friend_id']) . '"><img src="?g=thumb&i=' . get_main_image_id($friends_row['friend_id']) . '" width="' . (THUMB_WIDTH / 1.3) . '" height="' . (THUMB_HEIGHT / 1.3) . '" alt="" style="border: 0px;"></a><br />'; 
            echo '<div style="padding: 5px 0px 0px 0px;"></div>';
            echo get_username($friends_row['friend_id']) . '<br />';
            echo '</td></tr></table>';
            echo box_image_bottom();
        }
        echo '</td></tr></table>';
    }
    else
    {
        echo '<div style="padding: 5px 0px 0px 0px;"></div>You don\'t have any friends...';
    }    
?>
</div>

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