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

    require_once(
'include/functions/comments.php');
    require_once(
'include/functions/horoscope.php');
    require_once(
'include/functions/pages.php');
    require_once(
'include/functions/tile_is_available.php');
    
    
$members mysql_query("SELECT * FROM members WHERE id = '" get_user_id($_user) . "'");
    if (
$members_row mysql_fetch_assoc($members))
    {
        
$members_extras_row mysql_fetch_assoc(mysql_query("SELECT * FROM members_extras WHERE user_id = '" get_user_id($_user) . "'"));
        
$members_laston_row mysql_fetch_assoc(mysql_query("SELECT * FROM members_laston WHERE user_id = '" get_user_id($_user) . "'"));
    }
    else
    {
        
header('Location: ./?s=members');
        die;
    }
    
    include(
'include/parts/header.php');
    
    if (
$GLOBALS['auth']['id'] && $GLOBALS['auth']['id'] != get_user_id($_user))
    {
?>
<script type="text/javascript">
    function make_friend()
    {                
        doAjax('index.php?j=friend&i=<?= get_user_id($_user?>&w=make', function(AJAX) { eval(AJAX.responseText); });
    }
    function remove_friend()
    {                
        doAjax('index.php?j=friend&i=<?= get_user_id($_user?>&w=remove', function(AJAX) { eval(AJAX.responseText); });
    }
--></script>
</script>
<?
    
}
?>

<script type="text/javascript">
    function tiles_completed(page)
    {
        doAjax('index.php?j=profile_tiles_completed&i=<?= get_user_id($_user?>&p=' + page, function(AJAX) { document.getElementById('tiles_completed').innerHTML = AJAX.responseText; });
    }
    function graphix_completed(page)
    {
        doAjax('index.php?j=profile_graphix_completed&i=<?= get_user_id($_user?>&p=' + page, function(AJAX) { document.getElementById('graphix_completed').innerHTML = AJAX.responseText; });
    }
--></script>
</script>

<div class="header"><a href="?s=members&d=<?= strtolower(substr($members_row['username'], 01)) ?>">Members</a> - User Information</div>
<div class="content">
<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td valign="top">
<table width="100%" border="0">
<?
    
echo '<tr><td width="150" style="text-align: right;">Username:</td><td>';
    echo 
$members_row['username'];
    if (
$members_extras_row['birthday'] && $members_extras_row['birthday'] != '0000-00-00 00:00:00')
    {
        
$age date('Y') - substr($members_extras_row['birthday'], 04);
        if (
substr($members_extras_row['birthday'], 52) >= date('m'))
        {
            
$age--;
            if (
substr($members_extras_row['birthday'], 52) == date('m') && substr($members_extras_row['birthday'], 82) <= date('d'))
            {
                
$age++;
            }
        }
        if (
$age 100)
        {
            echo 
', ' $age;
        }
    }
    if (
$members_extras_row['gender'])
    {
        echo 
$members_extras_row['gender'] == ', Male' ', Female';
    }
    if (
$members_extras_row['birthday'] && $members_extras_row['birthday'] != '0000-00-00')
    {    
        if (
$sign get_horoscope_sign($members_extras_row['birthday']))
        {
            echo 
' (' $sign ')';
        }
    }
    if (
$GLOBALS['auth']['id'])
    {
        echo 
' [ <a href="?s=messages&u=' $members_row['username'] . '">Send Message</a> ]';
        if (
$GLOBALS['auth']['id'] != get_user_id($_user))
        {
            
$friends mysql_query("SELECT * FROM friends WHERE user_id = '" $GLOBALS['auth']['id'] . "' AND friend_id = '" get_user_id($_user) . "'");
            if (
$friends_row mysql_fetch_assoc($friends))
            {
                echo 
' [ <span id="friend"><a href="javascript: remove_friend();">Remove Friend</a></span> ]';
            }
            else
            {
                echo 
' [ <span id="friend"><a href="javascript: make_friend();">Make Friend</a></span> ]';
            }
        }
    }
    echo 
'</td></tr>';
    if (
$members_extras_row['country'])
    {
        echo 
'<tr><td width="150" style="text-align: right;">Location:</td><td>';
        if (
$members_extras_row['country'])
        {
            echo 
$members_extras_row['country'];
        }
        if (
$members_extras_row['region'])
        {
            echo 
', ' $members_extras_row['region'];
        }
        if (
$members_extras_row['city'])
        {
            echo 
', ' $members_extras_row['city'];
        }
        echo 
'</td></tr>';
    }
    if (
$members_laston_row['laston'] && $members_laston_row['laston'] != '0000-00-00 00:00:00')
    {
        echo 
'<tr><td width="150" style="text-align: right;">Laston:</td><td>' nice_date($members_laston_row['laston']) . '</td></tr>';
    }
    if (
$members_extras_row['fullname'])
    {
        echo 
'<tr><td width="150" style="text-align: right;">Full Name:</td><td>' $members_extras_row['fullname'] . '</td></tr>';
    }
    if (
$members_extras_row['website'])
    {
        echo 
'<tr><td width="150" style="text-align: right;">Website:</td><td>';
        if (
strpos($members_extras_row['website'], 'http://') === false)
        {
            echo 
'<a href="http://' $members_extras_row['website'] . '">http://' $members_extras_row['website'] . '</a>';
        }
        else
        {
            echo 
'<a href="' $members_extras_row['website'] . '">' $members_extras_row['website'] . '</a>';
        }
        echo 
'</td></tr>';
    }
    if (
$members_extras_row['privacy'] == 0)
    {
        if (
$members_extras_row['aim'])
        {
            echo 
'<tr><td width="150" style="text-align: right;">AOL Messenger:</td><td>' $members_extras_row['aim'] . '</td></tr>';
        }
        if (
$members_extras_row['icq'])
        {
            echo 
'<tr><td width="150" style="text-align: right;">ICQ Messenger:</td><td>' $members_extras_row['icq'] . '</td></tr>';
        }
        if (
$members_extras_row['msn'])
        {
            echo 
'<tr><td width="150" style="text-align: right;">MSN Messenger:</td><td>' $members_extras_row['msn'] . '</td></tr>';
        }
        if (
$members_extras_row['yahoo'])
        {
            echo 
'<tr><td width="150" style="text-align: right;">Yahoo Messenger:</td><td>' $members_extras_row['yahoo'] . '</td></tr>';
        }
        if (
$members_extras_row['gtalk'])
        {
            echo 
'<tr><td width="150" style="text-align: right;">Google Talk:</td><td>' $members_extras_row['gtalk'] . '</td></tr>';
        }
    }
    
$tile_count_row mysql_fetch_assoc(mysql_query("SELECT COUNT(*) AS count FROM tiles WHERE user_id = '" get_user_id($_user) . "' AND deleted = '0' AND visibility >= '0'"));
    
$tile_count_seconds_row mysql_fetch_assoc(mysql_query("SELECT SUM(seconds) AS count FROM tiles WHERE user_id = '" get_user_id($_user) . "' AND deleted = '0' AND visibility >= '0'"));
    if (
$tile_count_row['count'])
    {
        echo 
'<tr><td width="150" style="text-align: right;">Average Checkin Time:</td><td>' round($tile_count_seconds_row['count'] / $tile_count_row['count'] / 602) . ' minutes</td></tr>';
    }
?>
</table>
</td><td valign="top" align="right">
<?
    
echo '<img src="?g=thumb&i=' get_main_image_id(get_user_id($_user)) . '" width="' THUMB_WIDTH '" height="' THUMB_HEIGHT '" alt="" style="border: solid 2px black;">';
?>
</td></tr></table>
<?
    
echo '</div>';
    
    
$tiles_pending 0;
    
$tiles_none 0;
    
$tiles mysql_query("SELECT * FROM tiles WHERE user_id = '" get_user_id($_user) . "' AND deleted = '0' AND cache_display = '1'");
    if (!
$tiles_count mysql_num_rows($tiles))
    {
        
$tiles mysql_query("SELECT * FROM tiles WHERE user_id = '" get_user_id($_user) . "' AND deleted = '0' AND cache_display = '0'");
        if (
mysql_num_rows($tiles))
        {
            
$tiles_pending 1;
        }
        else
        {
            
$tiles_none 1;
        }    
    }

    echo 
'<div id="tiles_completed">';
    echo 
'<div class="header">Tiles Completed<br /><span style="color: #cccccc; font-size: 10px;">Page: ' pages_ajax('javascript:tiles_completed(%%PAGE%%);'1ceil($tiles_count 25)) . '</span></div>';
    echo 
'<div class="content" style="padding: 0px 5px 5px 5px;">';

    if (
$tiles_none)
    {
        echo 
'<div style="padding: 5px 0px 0px 0px;"></div>This member has not completed any tiles...<br />';
    }
    elseif (
$tiles_pending)
    {
        echo 
'<div style="padding: 5px 0px 0px 0px;"></div>This member has completed some tiles but none of them are set to display...<br />';
    }
    else
    {
        echo 
'<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
        
$tiles mysql_query("SELECT * FROM tiles WHERE user_id = '" get_user_id($_user) . "' AND deleted = '0' AND cache_display = '1' ORDER BY tile_id DESC LIMIT 0, 25");
        while (
$tiles_row mysql_fetch_assoc($tiles))
        {
            
$quilts mysql_query("SELECT * FROM quilts WHERE id = '" $tiles_row['quilt_id'] . "'");
            if (
$quilts_row mysql_fetch_assoc($quilts))
            {
                if (
$quilts_row['tile_width'] > 100)
                {
                    
$new_width 100;
                    
$new_height $quilts_row['tile_height'] / ($quilts_row['tile_width'] / 100);
                    if (
$new_height 100)
                    {
                        
$new_width $quilts_row['tile_width'] / ($quilts_row['tile_height'] / 100);
                        
$new_height 100;
                    }
                }
                elseif (
$quilts_row['tile_height'] > 100)
                {
                    
$new_height 100;
                    
$new_width $quilts_row['tile_width'] / ($quilts_row['tile_height'] / 100);
                    if (
$new_height 100)
                    {
                        
$new_height $quilts_row['tile_height'] / ($quilts_row['tile_width'] / 100);
                        
$new_width 100;
                    }
                }
                else
                {
                    
$new_width $quilts_row['tile_width'];
                    
$new_height $quilts_row['tile_height'];
                }
                echo 
box_image_top();
                echo 
'<table width="100" height="100" cellpadding="0" cellspacing="0" border="0"><tr><td valign="top">';
                echo 
'<a href="?s=tile&i=' $tiles_row['tile_id'] . '"><img src="?g=tile&i=' $tiles_row['tile_id'] . '" width="' $new_width '" height="' $new_height '" title="' htmlspecialchars(get_username($tiles_row['user_id'])) . ': ' htmlspecialchars($tiles_row['comment']) . '" alt="" style="border: solid 0px black;"></a><br />';
                echo 
'</td></tr></table>';
                echo 
box_image_bottom();
            }
        }
        echo 
'</td></tr></table>';
    }
    echo 
'</div>';
    echo 
'</div>';

    
$gallery_images mysql_query("SELECT * FROM gallery_images WHERE user_id = '" get_user_id($_user) . "'");
    echo 
'<div id="graphix_completed">';
    echo 
'<div class="header">Graphix Completed<br /><span style="color: #cccccc; font-size: 10px;">Page: ' pages_ajax('javascript:graphix_completed(%%PAGE%%);'1ceil(mysql_num_rows($gallery_images) / 25)) . '</span></div>';
    echo 
'<div class="content" style="padding: 0px 5px 5px 5px;">';
    if (
mysql_num_rows($gallery_images))
    {
        echo 
'<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
        
$gallery_images mysql_query("SELECT * FROM gallery_images WHERE user_id = '" get_user_id($_user) . "' ORDER BY image_id DESC LIMIT 0, 25");
        while (
$gallery_images_row mysql_fetch_assoc($gallery_images))
        {
            
$comment_count mysql_fetch_array(mysql_query("SELECT COUNT(*) AS num FROM images_comments WHERE link_id = '" $gallery_images_row['image_id'] . "'"));
            echo 
box_image_top();
            echo 
'<table width="' THUMB_WIDTH '" height="' THUMB_HEIGHT '" border="0" cellpadding="0" cellspacing="0"><tr><td align="center" valign="top">';
            echo 
'<a href="?s=image&i=' $gallery_images_row['image_id'] . '"><img src="?g=thumb&i=' $gallery_images_row['image_id'] . '" width="' THUMB_WIDTH '" height="' THUMB_HEIGHT '" alt="" style="border: 0px;"></a><br />';
            echo 
'<div style="padding: 4px 0px 0px 0px;"></div>';
            echo 
'<b>' $comment_count['num'] . '</b> Comments<br />';
            echo 
'</td></tr></table>';
            echo 
box_image_bottom();
        }
        echo 
'</td></tr></table>';
    }
    else
    {
        echo 
'<div style="padding: 5px 0px 0px 0px;"></div>This member has not completed any graphix...';
    }
?>
</div>
</div>
<?
    comments
(get_user_id($_user), 'members');

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