<?php
function load_photo($photo_name) {
    include $_SERVER['DOCUMENT_ROOT'].'/inc/config.php';
    $photo_name = addslashes($photo_name);
    $photo_name = htmlspecialchars($photo_name);
    include $_SERVER['DOCUMENT_ROOT'].'/inc/login.php';
    include $_SERVER['DOCUMENT_ROOT'].'/inc/sql_social.php';
    
    $z_photo_info = mysql_query("SELECT * FROM photo_to_users WHERE photo_name='$photo_name'");
    $o_photo_info = mysql_fetch_array($z_photo_info);
    $object_id = $o_photo_info['photo_id'];
    $uid = $o_photo_info['user_id'];
    $date = date("d.m.Y H:i", $o_photo_info['date']);
    
    $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'];
    $rand = rand(10000, 99999);

    $z_count_likes = mysql_query("SELECT likes_id FROM likes WHERE object_id='$object_id' and object_type='5'");
    $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_5_'.$object_id.'">'.$count_likes.'</b></span>';
        $display_likes = 'block';
    } else {
        $likes_count = '<span style="color:#2B587A; font-size:13px;"><b id="like_count_5_'.$object_id.'"></b></span>';
        $display_likes = 'none';
    }

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

    if ($heart_likes>0) {
        $likes_heart = '<span id="like_heart_5_'.$object_id.'" class="icon-heart" style="color:#5085ad; font-size:13px;"></span>';
    } else {
        $likes_heart = '<span id="like_heart_5_'.$object_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='5' 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);
    $z_user_avatar = mysql_query("SELECT * FROM users WHERE id='$uid'");
    $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/'.$uid.'.jpg?r='.$rand;
    }
    
    $uid_online = $uid;
    $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 = '';
    }

    if ($my_id) {
        $photo_modal = $photo_modal.'
        <div>
        <img id="photo_'.$object_id.'" width="100%" src="/photo/'.$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'.$uid.'"><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="/id'.$uid.'">'.$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='.$object_id.'; object_type=5; token=\''.md5($my_id.'_'.$object_id.'_5_like_'.$secret).'\'; like();">
                    '.$likes_heart.'
                    <span style="color:#2B587A; margin-left:5px;">'.$lang[559].'</span>
                    '.$likes_count.'
                </div>
                <span id="popover_5_'.$object_id.'" data-toggle="tooltip" data-placement="top" data-html="true" title="'.$likes_body.'" onclick="object_id='.$object_id.'; object_type=5; more=false; page=1; $(\'#id_comment_photo\').modal(\'hide\'); $(\'#id_modal_photos\').modal(\'hide\'); like_peoples();" onmouseover="$(\'#popover_5_'.$object_id.'\').tooltip(\'show\');" onmouseout="$(\'#popover_5_'.$object_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>
        ';
    } else {
        $photo_modal = $photo_modal.'
        <div>
        <img id="photo_'.$object_id.'" width="100%" src="/photo/'.$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'.$uid.'"><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="/id'.$uid.'">'.$info_firstname.$user_online.'</a>
                    <br>
                    <span style="font-size:11px; color:#777;">'.$date.'</span>
                </div>
            </div>
            <div style="width:50%; float:left;" onselectstart="return false" onmousedown="return false">
                <div style="float:right;">
                    '.$likes_heart.'
                    <span style="color:#2B587A; margin-left:5px;">'.$lang[560].'</span>
                    '.$likes_count.'
                </div>
                <span id="popover_5_'.$object_id.'" data-toggle="tooltip" data-placement="top" data-html="true" title="'.$likes_body.'" onclick="object_id='.$object_id.'; object_type=5; more=false; page=1; $(\'#id_comment_photo\').modal(\'hide\'); $(\'#id_modal_photos\').modal(\'hide\'); like_peoples();" onmouseover="$(\'#popover_5_'.$object_id.'\').tooltip(\'show\');" onmouseout="$(\'#popover_5_'.$object_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>
        ';
    }
    
    mysql_close($msconnect);
    return $photo_modal;
}
?>