<?php
include $_SERVER['DOCUMENT_ROOT'].'/inc/config.php';
include $_SERVER['DOCUMENT_ROOT'].'/inc/login.php';
if (isset($_GET['id'])) { $uid = $_GET['id']; } else { $uid = $my_id; }
$uid = addslashes($uid);
$uid = htmlspecialchars($uid);

include $_SERVER['DOCUMENT_ROOT'].'/inc/sql_social.php';

$z_user_info = mysql_query("SELECT * FROM users WHERE id='$uid'");
$o_user_info = mysql_fetch_array($z_user_info);
$live_user = $o_user_info['id'];

if ($live_user) {

$info_firstname = $o_user_info['firstname'];
$info_lastname = $o_user_info['lastname'];
$info_sex = $o_user_info['sex'];


$z_count_photos = mysql_query("SELECT photo_id FROM photo_to_users WHERE user_id='$uid' and photo_type='1' and live='1'");
$count_photos = mysql_num_rows($z_count_photos);

$photo_slide = '';
$photo_modal = '';
$arr_photo = '';
$photo_id = 0;
$result = mysql_query("SELECT * FROM photo_to_users WHERE user_id='$uid' and photo_type='1' and live='1' ORDER BY photo_id DESC"); 
while ( $myrow = mysql_fetch_array($result) )
{
$photo_slide = $photo_slide.'
<div style="padding:calc(100% / 10 - 1px); background-image:url(/photo/m_'.$myrow['photo_name'].'.jpg); margin-right:2px; margin-bottom:2px; background-size:cover; background-position:top; float:left; cursor:pointer;" onClick="photo_id='.$photo_id.'; start_photo=true; photo_show();"></div>
';


$uid = $myrow['user_id'];
$z_user_info = mysql_query("SELECT * FROM users WHERE id='$uid'");
$o_user_info = mysql_fetch_array($z_user_info);
$info_firstname = $o_user_info['firstname'];
$info_lastname = $o_user_info['lastname'];
$rand = rand(10000, 99999);
$date = date("d.m.Y H:i", $myrow['date']);
$object_id = $myrow['photo_id'];

$z_count_likes = mysql_query("SELECT likes_id FROM likes WHERE object_id='$object_id' and object_type='1'");
$count_likes = mysql_num_rows($z_count_likes);

if ($count_likes>0) {
    $likes_count = '<span style="color:#2B587A; font-size:13px;"><b id="like_count_1_'.$myrow['photo_id'].'">'.$count_likes.'</b></span>';
    $display_likes = 'block';
} else {
    $likes_count = '<span style="color:#2B587A; font-size:13px;"><b id="like_count_1_'.$myrow['photo_id'].'"></b></span>';
    $display_likes = 'none';
}

$z_heart_likes = mysql_query("SELECT likes_id FROM likes WHERE object_id='$object_id' and object_type='1' and user_id='$my_id'");
$heart_likes = mysql_num_rows($z_heart_likes);

if ($heart_likes>0) {
    $likes_heart = '<span id="like_heart_1_'.$myrow['photo_id'].'" class="icon-heart" style="color:#5085ad; font-size:13px;"></span>';
} else {
    $likes_heart = '<span id="like_heart_1_'.$myrow['photo_id'].'" class="icon-heart" style="color:#b4cee2; font-size:13px;"></span>';
}


$i = 0;
$likes_body = '';
$result_like = mysql_query("SELECT * FROM likes WHERE object_id='$object_id' and object_type='1' ORDER BY likes_id DESC, likes_id LIMIT 0, 5"); 
while ( $myrow_like = mysql_fetch_array($result_like) )
{
    $rand = rand(10000, 99999);
    $user_ava_id = $myrow_like['user_id'];
    $z_user_avatar = mysql_query("SELECT * FROM users WHERE id='$user_ava_id'");
    $o_user_avatar = mysql_fetch_array($z_user_avatar);
    $user_avatar = $o_user_avatar['avatar'];
    $user_sex = $o_user_avatar['sex'];
    if ($user_avatar==0) {
        if ($user_sex==1) { $avatar = '/img/no_photo/girl.png?r='.$rand; }
        if ($user_sex==2) { $avatar = '/img/no_photo/boy.png?r='.$rand; }
    } else {
        $avatar = '/avatar/'.$user_ava_id.'.jpg?r='.$rand;
    }

    if ($i==0) {
        $likes_body = '<img width=\'30\' height=\'30\' src=\''.$avatar.'\' style=\'border-radius:100px; margin:5px 0px 5px 0px;\' />'.$likes_body;
    } else {
        $likes_body = '<img width=\'30\' height=\'30\' src=\''.$avatar.'\' style=\'border-radius:100px; float:left; margin:5px 5px 5px 0px;\' />'.$likes_body;
    }
    $i++;
}

$rand = rand(10000, 99999);
$user_ava_id = $myrow['user_id'];
$z_user_avatar = mysql_query("SELECT * FROM users WHERE id='$user_ava_id'");
$o_user_avatar = mysql_fetch_array($z_user_avatar);
$user_avatar = $o_user_avatar['avatar'];
$user_sex = $o_user_avatar['sex'];
if ($user_avatar==0) {
    if ($user_sex==1) { $avatar = '/img/no_photo/girl.png?r='.$rand; }
    if ($user_sex==2) { $avatar = '/img/no_photo/boy.png?r='.$rand; }
} else {
    $avatar = '/avatar/'.$user_ava_id.'.jpg?r='.$rand;
}

$uid_online = $myrow['user_id'];
$z_user_online = mysql_query("SELECT time FROM users_to_online WHERE user_id='$uid_online'");
$o_user_online = mysql_fetch_array($z_user_online);
$user_online = $o_user_online['time'];
$this_date = date('U');
if ($user_online>($this_date-60)) {
    $user_online = ' <span class="icon-lamp" style="color:#46af48; font-size:10px;"></span>';
} else {
    $user_online = '';
}

$photo_modal = $photo_modal.'
<div>
<img id="photo_'.$myrow['photo_id'].'" width="100%" src="/photo/'.$myrow['photo_name'].'.jpg" />
<div style="padding:15px; height:60px; background:#f5f5f5; border-bottom:1px solid #e1e1e8;">
    <div style="width:50%; float:left;">
        <div style="float:left;">
            <a href="/id'.$myrow['user_id'].'"><img id="id_top_avatar" width="30" height="30" src="'.$avatar.'" style="border-radius:100px;"></a>
        </div>
        <div style="float:left; padding-left:10px;">
            <a href="/id1">'.$info_firstname.$user_online.'</a>
            <br>
            <span style="font-size:11px; color:#777;">'.$date.'</span>
        </div>
    </div>
    <div style="width:50%; float:left; cursor:pointer;" onselectstart="return false" onmousedown="return false">
        <div style="float:right; cursor:pointer;" onClick="object_id='.$myrow['photo_id'].'; object_type=1; token=\''.md5($my_id.'_'.$myrow['photo_id'].'_1_like_'.$secret).'\'; like();">
            '.$likes_heart.'
            <span style="color:#2B587A; margin-left:5px;">Нравится</span>
            '.$likes_count.'
        </div>
        <span id="popover_1_'.$myrow['photo_id'].'" data-toggle="tooltip" data-placement="top" data-html="true" title="'.$likes_body.'" onclick="object_id='.$myrow['photo_id'].'; object_type=1; more=false; page=1; like_peoples();" onmouseover="$(\'#popover_1_'.$myrow['photo_id'].'\').tooltip(\'show\');" onmouseout="$(\'#popover_1_'.$myrow['photo_id'].'\').tooltip(\'hide\');" style="float:right; font-size:12px; color:#b4cee2; margin-right:10px; cursor:pointer; display:'.$display_likes.';">&bull;&bull;&bull;</span>
    </div>
</div>
</div>
';
if ($arr_photo=='') { $arr_photo = $arr_photo.$myrow['photo_id']; } else { $arr_photo = $arr_photo.','.$myrow['photo_id']; }
$photo_id++;

}

if ($count_photos==0) {
    if ($uid==$my_id) {
        $photo_slide = '<p style="padding:15px; background:#f5f5f5; border-radius:4px; text-align:center; margin-bottom:0px;">На вашей странице нет фотографий, добавьте первые фото.</p>';
    } else {
        $photo_slide = '<p style="padding:15px; background:#f5f5f5; border-radius:4px; text-align:center; margin-bottom:0px;">У пользователя <b>'.$info_firstname.' '.$info_lastname.'</b> нет ни одной фотографии.</p>';

    }
}

}

$z_count_otvety = mysql_query("SELECT * FROM news WHERE user_to='$my_id'");
$count_otvety = mysql_num_rows($z_count_otvety);

mysql_close($msconnect);

$global_rand = rand(100000, 999999);
$title = $lang[436];
?>
<?php
include $_SERVER['DOCUMENT_ROOT'].'/functions/top_search.php';
include $_SERVER['DOCUMENT_ROOT'].'/functions/login.php';
include $_SERVER['DOCUMENT_ROOT'].'/functions/load_comments.php';
include $_SERVER['DOCUMENT_ROOT'].'/functions/send_comment.php';
include $_SERVER['DOCUMENT_ROOT'].'/functions/del_comment.php';
include $_SERVER['DOCUMENT_ROOT'].'/functions/like_users.php';
include $_SERVER['DOCUMENT_ROOT'].'/functions/like_peoples.php';
include $_SERVER['DOCUMENT_ROOT'].'/functions/load_photo.php';
include $_SERVER['DOCUMENT_ROOT'].'/functions/send_wall.php';
include $_SERVER['DOCUMENT_ROOT'].'/functions/del_photo.php';
include $_SERVER['DOCUMENT_ROOT'].'/functions/save_photo.php';
include $_SERVER['DOCUMENT_ROOT'].'/functions/ping_online.php';
include $_SERVER['DOCUMENT_ROOT'].'/functions/visits.php';
include $_SERVER['DOCUMENT_ROOT'].'/functions/otvety.php';



include $_SERVER['DOCUMENT_ROOT']."/inc/agent.php";
$agent->init();
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="">
        <meta name="author" content="">
        <title><?php echo $title; ?></title>
        <link href="/img/favicon.png" rel="shortcut icon" type="image/x-icon" />        
        <link rel="stylesheet" type="text/css" href="/css/bootstrap.css?r=<?php echo $global_rand; ?>" />
        <link rel="stylesheet" type="text/css" href="/css/jcrop.css?r=<?php echo $global_rand; ?>" />
        <link rel="stylesheet" type="text/css" href="/slick/slick.css?r=<?php echo $global_rand; ?>">
        <link rel="stylesheet" type="text/css" href="/slick/slick-theme.css?r=<?php echo $global_rand; ?>">
        <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Lobster" />
        <link rel="stylesheet" type="text/css" href="/icon/style.css?r=<?php echo $global_rand; ?>" />
        <script>
        var my_id = <?php if ($my_id) { echo $my_id; } else { echo 0; } ?>;
        var show_photo = true;
        var count_photos = <?php echo $count_photos; ?>;
        var uid = <?php echo $uid; ?>;
        var live_uploads = <?php if ($uid==$my_id) { echo 'true'; } else { echo 'false'; } ?>;
        var tokens = ['<?php echo md5($my_id.'_main_'.$secret); ?>', '<?php echo md5($my_id.'_contacts_'.$secret); ?>', '<?php echo md5($my_id.'_interests_'.$secret); ?>', '<?php echo md5($my_id.'_education_'.$secret); ?>', '<?php echo md5($my_id.'_work_'.$secret); ?>', '<?php echo md5($my_id.'_work_'.$secret); ?>'];
        var page = 1;
        var more = false;
        <?php if ($arr_photo!==''):?>var photo_ids = [<?php echo $arr_photo; ?>];<?php endif;?>
        <?php if ($my_id):?>var otvety_count = <?php echo $count_otvety; ?>;<?php endif;?>
        <?php if ($my_id):?>var tokens = ['<?php echo md5($my_id.'_'.$uid.'_sendwall_'.$secret); ?>', '<?php echo md5($my_id.'_photo_'.$secret);?>', '<?php echo md5($my_id.'_'.$uid.'_sendcomment_'.$secret); ?>', '<?php echo md5($my_id.'_comment_'.$secret);?>'];<?php endif;?>
        </script>
    </head>
    <body role="document">
        <?php include $_SERVER['DOCUMENT_ROOT'].'/templates/header_user.tpl'; ?>
        <div class="container" style="margin-top:70px; margin-bottom:20px;">
            <div class="row">
                <div class="col-md-2" style="padding-bottom:15px;">
                <?php include $_SERVER['DOCUMENT_ROOT'].'/templates/user_left_menu.tpl'; ?>
                </div>    
                <?php if ($live_user):?>
                <div class="col-md-10">
                    <div style="padding:0px; background-color:#ffffff; border:1px solid #e1e1e8; border-radius:4px; margin-bottom:20px;"> 
                        <div class="header-title-bg" style="margin-top:0px; margin-left:0px;">
                        <?php if ($uid==$my_id):?>
                            <?php echo $lang[437]; ?> <b><?php echo $count_photos; ?></b>
                        <?php endif;?>
                        <?php if ($uid!==$my_id):?>
                            <?php echo $lang[438]; ?> <b><?php echo $info_firstname; ?> <?php echo $info_lastname; ?></b>
                        <?php endif;?>
                        </div>
                        <div style="margin-top:47px; padding:20px;"><?php echo $photo_slide; ?></div>
                        <div class="row"></div>
                        <?php if ($uid==$my_id):?>
                        <div style="margin-top:20px; background:#f5f5f5; padding:5px 20px 5px 20px; border-radius:0px 0px 5px 5px; border-top:1px solid #e1e1e8;">
                            <div id="upload_photoslide" class="row" style="margin:0px; margin-top:12px; display:none;">
                                <div id="id_upload_foto_status" style="width:25%; float:left;"></div>
                            </div>
                        </div>
                        <?php endif;?>
                        <?php if ($uid!==$my_id):?>
                        <div style="height:20px;"></div>
                        <?php endif;?>
                    </div>
                </div>
                <?php endif;?>
                <?php if (!$live_user):?>
                <div class="col-md-10">
                    <div style="padding:20px; background-color:#ffffff; border:1px solid #e1e1e8; border-radius:4px; margin-bottom:20px;"> 
                        <p style="padding:15px; background:#f5f5f5; border-radius:4px; margin-bottom:0px; text-align:center;"><?php echo $lang[439]; ?></p>
                    </div>
                </div>
                <?php endif;?>
            </div>                        
        </div>            
        <?php if ($uid==$my_id) { include $_SERVER['DOCUMENT_ROOT'].'/modal/avatar.php'; } ?>
        <?php include $_SERVER['DOCUMENT_ROOT'].'/modal/photo.php'; ?>
        <?php include $_SERVER['DOCUMENT_ROOT'].'/modal/likes.php'; ?>
        <?php include $_SERVER['DOCUMENT_ROOT'].'/modal/load_photo.php'; ?>
        <?php include $_SERVER['DOCUMENT_ROOT'].'/modal/visits.php'; ?>
        <?php include $_SERVER['DOCUMENT_ROOT'].'/modal/otvety.php'; ?>
        
        
        <div class="talker">
        <div class="talker_message"></div>
        </div>            
        <?php include $_SERVER['DOCUMENT_ROOT'].'/templates/footer.tpl'; ?>    
        <script src="/uploadify/jquery.uploadifive.min.js?r=<?php echo $global_rand; ?>" type="text/javascript"></script>
        <script src="/js/jcrop.js?r=<?php echo $global_rand; ?>"></script>
        <script src="/slick/slick.js?r=<?php echo $global_rand; ?>" type="text/javascript" charset="utf-8"></script>
        <script type="text/javascript">
        <?php if ($my_id):?>
        onload = function() {
            ping_online();
        }
        <?php endif;?>
        </script>
        <script src="/js/system/<?php echo $js_lang; ?>/photos.js?r=<?php echo $global_rand; ?>" type="text/javascript"></script>
    </body>
</html>