<?php
	if(isset($_GET['page'])) {
		if($_GET['page'] == 'status'){ require ("includes/profile.status.php"); } // Статус
		if($_GET['page'] == 'cover'){ require ("includes/profile.cover.php"); }  // Обложка профиля
	}
	$id = intval($_GET['id']);
	$data = profile :: getUser($id);
	$title = "Просмотр профиля";

	$link = profile :: getLink($data); // Ссылка на профиль в title 

	if(isset($data['id']) && $data['block_unlock'] == 0) { require ("includes/profile.block.php"); } // Вывод сообщения о блокировке.

	$bday_m = array(
	1=>	"января",
	"февраля",
	"марта",
	"апреля",
	"мая",
	"июня",
	"июля",
	"августа",
	"сентября",
	"октября",
	"ноября",
	"декабря"
	);

	$status = true;

// Добавление в друзья.
	if(isset($_GET['act']) && $_GET['act'] == 'friends') {
		require (MODULE."friends/.inc/add.php");
	}


	require (CORE."head.php"); #Шапка
// Эмоции	
$Emotions = [];
$Emotions['Радость'] = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30];
$Emotions['Любовь'] = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21];
$Emotions['Грусть'] = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29];
$Emotions['Страх'] = [1,2,3,4,5,6,7,8,9,10,11,12];
$Emotions['Гнев'] = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17];
$Emotions['Персонажи'] =[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16];

// The end///

//Системная страница с id 45
	if(isset($data['id'])) {
		if($data['id'] != $config['SYS_ID']) {
		?>
	<div class="app-block">


<?
    require (MODULE."admin/.inc/apnews.php"); //Вывод новостей

?>
		<div class="list _l-padd-n cover-page--on" style="position: relative;overflow: visible;">
		<div class="_oh">
			<div class="cover-page--cont">
				<div class="cover-page--element" style="<?=($data['cover'] != NULL ? "background-image: url(".FILES_SERVER."covers/res/{$data['cover']}?{$user['info_cover']});" : '')?>">
					<div class="cover-page--floating">
						<?=($data['id'] == $user['id'] ? "<a href=\"{$link}?page=cover\" class=\"app-btn-white\">Изменить</a>" : '' )?>
					</div>
				</div>
			</div>

			<div class="_l-padd">

			<div style="padding-top: 5px;margin-right: 10px;" class="_fl-l cover-page--avatar emotion-show" data-emotions="<?= system::textOut($data['emotions']) ?>">
				<?=($data['avatar'] != 0 ? "<a href=\"".profile :: getLinkAvatar($data)."\">".profile :: userAvatar($data, 1)."</a>" : profile :: userAvatar($data, 1) )?>
			</div>

 			<div class="_fl-" style="margin-top: 10px;">
  				<div>

  				<b style="font-size: 1.2em;font-weight: normal;"><span class="_name size--big"><?=profile :: getFullName($data, false)?> <?=profile :: ver($data)?></span></b>
  				<div class="_gray"><?=(profile :: getOnline($data) ? "на сайте" : "был" . ($data['info_sex'] == 0 ? "а" : "") . " на сайте ".system :: times($data['last_time']) )?></div>
				</div>
  			</div>
  			</div>
			</div>
            <?php
            if (isset($user['id']) && $user['id'] == $data['id'])
            {?>
                <div class="emoji_field_wrap">
                    <span id="emotions" class="_fl-r emotions" title="Выбор настроения"><i class="fa fa-smile-o fa-0px" style="font-size: 24px;color: #528ecb;"></i></span>
                    <div class="emoji_tt_wrap emoji_no_tabs emoji_expanded tt_up ">
                        <div class="emoji_cat_title_fix">
                            <div class="emoji_cat_title_helper">
                                <div class="emoji_cat_title">Текущая эмоция</div>
                            </div>

                            <div class="emoji_smiles_row">
                                <div class="emoji_smile_cont emotion-show" data-emotions="0_0" onclick="return Emotions.selected(this)"></div>
                                <div class="emoji_smile_cont emotion-show" data-current data-emotions="<?= system::textOut($data['emotions']) ?>"></div>
                            </div>
                        </div>
                        <div class="emoji_block_cont">
                            <div class="emoji_list_cont">
                                <div class="emoji_list_scroll">
                                <?php foreach(array_keys($Emotions) as $key => $item) { ?>
                                    <div class="emoji_cat_title_helper">
                                        <div class="emoji_cat_title"><?= $item ?></div>
                                    </div>
                                    <?php if(is_array($Emotions[$item])) {
                                        ?><div class="emoji_smiles_row"><?
                                        foreach($Emotions[$item] as $_item) {
                                            ?>
                                            <div class="emoji_smile_cont emotion-show" data-emotions="<?= $key ?>_<?= $_item ?>" onclick="return Emotions.selected(this)"></div>
                                            <?
                                        }
                                        ?></div><?
                                    }?>
                                <?php } ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            <?}
            $lMusici = DB::$pdo->queryFetch("SELECT * FROM `listen_music` WHERE `id_user` = '". $data['id'] ."' AND `time` > '".time()."' LIMIT 1");
            if($lMusici !== false) {
                ?>
                <div class="p-status _l-padd listen-music" style="padding-top: 0px;padding-bottom: 0px;position: relative;">
                        <div class="ai_play">
                            <img src="/template/emoji/1f3b6_x1.png">
                        </div>
                        <div class="ai_body">
                            <div class="ai_label">
                                <span class="ai_artist"><?= $lMusici['artist'] ?></span>
                                <span class="dividers"> – </span>
                                <span class="ai_title"><?= $lMusici['title'] ?></span>
                            </div>
                        </div>
                </div>
                <?
                unset($lMusici);
            } else {

                ?>

                <?= (($data['status'] != NULL || (isset($user['id']) && $user['id'] == $data['id'])) ? '
			
				' . ($data['id'] == $user['id'] ? '
					<div class="p-status _l-padd" style="padding-top: 0px;padding-bottom: 0px;position: relative;"><a id="status-click" onclick="UI.status.Toggle($(this), event);" href="' . $link . '?page=status">
						<span id="data-emoji" style="display:none">' . emoji:: Decode($data['status']) . '</span>
						<span class="curr_status_fake">
							<span class="curr_status" style="display: inline;">
								' . ($data['status'] == "" ? "изменить статус" : emoji:: Text($data['status'])) . '
							</span>
						</span>
					</a></div>
					<div class="app-dropdown" style="display: none;" data-role="status-out"><div id="emojistatus" class="_l-padd"><span  data-role="status-edition"><input class="main-input _w-100" maxlength="300" onkeypress="if(event.keyCode==13)UI.status.Save();" type="text" value="" name="status" id="status-input" data-id="emoji-block_1"><div class="_padd-top"><button class="main-btn" type="button" onclick="UI.status.Save();">Сохранить</button>' . emoji:: Smiles("emoji-block_1", "status-input") . '</div></span></div></div>
				' : '<div class="p-status _l-padd _gray" style="padding-bottom: 0px;"><span>' . emoji:: Text($data['status']) . '</span></div>') . '
			
				' : '') ?>

                <?php
            }
			if(profile :: getFriend($user['id'], $data['id']) == true) {
				$friend = true;
			} 

			$mutualFriends = (isset($user['id']) && $user['id'] != $data['id'] ? DB :: $pdo -> querySingle("SELECT COUNT(*) FROM `friends` WHERE `id_friend` IN (SELECT `id_user` FROM `friends` WHERE `id_friend` = ?) AND `id_user` = ?;", [$user['id'], $data['id']]) : 0 );
			if($data['id'] != $user['id']) { ?>
			<div class="_oh _lh-n _l-padd">
			<a href="/gifts?id=<?=$data['id']?>&amp;cat=1" class="main-btn _fl-r _dbl _center" style="margin-left: 5px;"><?=system :: icon("gift-white")?></a>
			<div style="width: 40%;" class="_fl-r">
				<?php
				if($friend == false){
					if(profile :: getFriend($data['id'], $user['id'], true) == true) {
				"<a href=\"/friends?id={$user['id']}&amp;add={$data['id']}&amp;access=".ACCESS."\" class=\"action-btn _dbl _center _oh\">Отписаться</a>";
				} else {
				echo "<a href=\"/friends?id={$user['id']}&amp;add={$data['id']}&amp;access=".ACCESS."\" class=\"main-btn _dbl _center _oh\" >Добавить в друзья</a>";
				if(profile :: getFriend($user['id'],$data['id'],true)){$requestYou = true;}
				}
				} else {
				echo "<a href=\"/friends?id={$user['id']}&amp;add={$data['id']}&amp;access=".ACCESS."\" class=\"action-btn _dbl _center _oh\">Удалить из друзей</a>";
				}
				?>
			</div>
			<div style="width: 45%;"><a href="/mail?act=show&peer=<?=$data['id']?>" class="main-btn _center _dbl _oh">Написать</a></div>
			<div style="margin-top: 5px;">
				<?=(isset($requestYou) ? "<div class=\"_center _gray\" style=\"margin-top: 8px;\"><span class=\"_bold\">".profile :: getName($data, false)."</span> подписан".( $data['info_sex'] == 0 ? "а" : '' )." на Вас</div>" : '')?>
			</div>
			</div>
			<?php } else if(isset($user['id']) && $data['id'] == $user['id']) {?>
			<div class="_lh-n _l-padd _btn-up" style="padding-top: 0px;">
				<a href="/anketa/?act=anketa/edit" class="action-btn _dbl _center">Редактировать</a>
			</div>
			<?php } ?>



		</div>

		<div><a href="/anketa?id=<?=$data['id']?>" class="app-toggler app-toggler-white _center" data-id="user--info" data-class="app-toggler-open" onclick="App.toggle(this,event);return false;"><?=language::text('info', $language,'profile');?> <?=profile :: getFullName($data)?><i class="fa fa-chevron-down" style="float:right;"></i></a></div>
			<!-- inform. block -->

		<div id="user--info" class="list" style="display: none;">
		

			<?php

			$a = array(
					1=>array(
							array('в активном поиске',''),
							array('в активном поиске','')
						),
					array(
							array('не замужем',''),
							array('не женат','')
						),
					array(
							array('встречается', 'с'),
							array('встречается', 'с')
						),
					array(
							array('помолвлена', 'с'),
							array('помолвлен', 'с'),
						),
					array(
							array('замужем','за'),
							array('женат','на')
						),
					array(
							array('влюблена','в'),
							array('влюблён','в')
						),
					array(
							array('всё сложно', 'с'),
							array('всё сложно', 'с')
						)
				);

			if($data['info_rs'] > 0) {
				$pr = profile :: getUser($data['info_partner'], NULL, false);
				?>
			<div>
				<span class="_gray"><?=language::text('sm', $language,'profile');?>:</span> <?=$a[$data['info_rs']][$data['info_sex']][0]." ".(isset($pr['id']) && $data['info_partner'] != 0 && ($pr['info_partner'] == $data['id'] || $data['info_rs'] == 6) ? $a[$data['info_rs']][$data['info_sex']][1]." ".profile :: goPage($pr, false) : '' )?>
			</div>
			<?php }?>

			<div>
				<span class="_gray"><?=language::text('sex', $language,'profile');?>:</span> <?=profile :: getSex($data);?>
			</div>
			<?php if($data['info_hometown'] != "") {?>
			<div>
				<span class="_gray"><?=language::text('city', $language,'profile');?>:</span> <?=$data['info_hometown']?>
			</div>
			<?php }?>
			<?php if($data['info_b_hide'] == 1 && $data['info_b_d'] > 0 && $data['info_b_m'] > 0 && $data['info_b_y'] > 0) {?>
			<div>
				<span class="_gray">День рождения:</span> <?=($data['info_b_d'])." ".$bday_m[$data['info_b_m']]." ".$data['info_b_y']?>
			</div>
			<?php }?>
			<div>
				<span class="_gray">Время на сайте:</span> <?=profile :: onlineTime($data['online_time']);?>
			</div>

			<?php if(admin :: getAccess($user,  array('a'=>3))) { ?>
			<div class="_line"></div>
			<div class="_btn-up">
				<span class="_gray">Последнее посещение:</span> <?=system :: times($data['last_time']);?>
			</div>
			<div>
				<span class="_gray">IP:</span> <?=$data['adm_ip'];?>
			</div>
			<div>
				<span class="_gray">UA:</span> <?=$data['adm_ua']?>
			</div>
			<div class="_lh-n _btn-up">
				<a href="/admin/?act=user/info&amp;id=<?=$data['id']?>" class="action-btn _dbl _center">Админ-информация</a>
			</div>
			<?php } ?>
		</div>
		</div>



   <?if (isset($user['id']) && $user['id'] == $data['id'] && DB::$pdo -> querySingle("SELECT COUNT(*) FROM `bag_tracker_users` WHERE `id_user` = '".$user['id']."' AND `aut` = '0'") > 0)
        {?>
            <div class="app-block">
                <div class="touch" style="padding: 15px 18px; text-align: center; font-size: 15px;">
                    Вам предложено вступить в команду Баг-Треккера!<br />
                    <a style="font-size: 13px;" href="/bag_tracker/?my_invite">
                        Подробнее...
                    </a>
                </div>
            </div>
        <?}?>

<!-- Табло -->
<div class="app-container">
    <table class="table--wrap" cellpadding="0">
        <tbody><tr>
     <td>
            <a class="app-user--speedmenu" href="/anketa?id=<?=$data['id']?>" title="<?=language::text('anketa', $language,'profile')?>">
              <i class="fa fa-address-book fa-0px" style="margin: 0 4px -2px 0;"></i>
                <span class="u-speedmenu-text"><?=language::text('anketa', $language,'profile')?></span>
            </a>
          </td>
           
           <td>
            <a class="app-user--speedmenu" href="/blog?id=<?=$data['id']?>" title="<?=language::text('anketa', $language,'profile')?>">
              <i class="fa fa-book fa-0px" style="margin: 0 4px -2px 0;"></i>
                <span class="u-speedmenu-text">Блоги</span>
            </a>
          </td>
          
          <td>
            <a class="app-user--speedmenu" href="/friends?id=<?=$data['id']?>" title="<?=language::text('friend', $language,'profile')?>">
             <i class="fa fa-users fa-0px" style="margin: 0 4px -2px 0;"></i>
                <span class="u-speedmenu-text"><?=language::text('friend', $language,'profile')?></span>
            </a>
          </td>
          <td>
            <a class="app-user--speedmenu" href="/photos<?=$data['id']?>" title="<?=language::text('photo', $language,'profile')?>">
             <i class="fa fa-camera fa-0px" style="margin: 0 4px -2px 0;"></i>
                <span class="u-speedmenu-text"><?=language::text('photo', $language,'profile')?></span>
            </a>
          </td>
          <td>
            <a class="app-user--speedmenu" href="/gifts?id=<?=$data['id']?>" title="<?=language::text('gifts', $language,'profile')?>">
            <i class="fa fa-gift fa-01px" style="margin: 0 4px -2px 0;"></i>
                <span class="u-speedmenu-text"><?=language::text('gifts', $language,'profile')?></span>
            </a>
          </td>
        </tr>
      </tbody></table></div>
<!-- Конец табла -->

	<?if ($data['count_friends'] > 0) {?>
<div class="app-container">
      <div class="app-user--sections" id="ufriends">
        <div class="app-user--sections--name">
          <a href="/friends?id=<?=$data['id']?>" title="Друзья"><?=language::text('friend', $language,'profile')?> <?=$mutualFriends > 0 ? " / Общие {$mutualFriends}" : ''?>
            <span class="app-sections--counter"><?=$data['count_friends']?></span>
          </a>
        </div>

        <div class="app-user--sections--main">
<?php

    $Friends = DB :: $pdo -> query("SELECT * FROM `friends` WHERE `id_user` = '".$id."' ORDER BY `id` DESC LIMIT 8"); 
	$i = 0;
	while($r = $Friends -> fetch()) {
		++$i;
    $da = profile :: getUser($r['id_friend']);
?>
          <div class="app-user--sections--item">
            <a href="<?=profile :: getLink($da);?>">
              <div class="post-l app-user--sections--avatar emotion-show " data-emotions="<?=system::textOut($da['emotions'])?>">
                 <?=profile :: userAvatar($da, 0)?>
              </div>
              <div class="app-user--sections--username">
               <?=profile :: getFullName($da, true)?>
              </div>
            </a>
          </div>

     <?}?>   
        </div></div>
       <!--  <a class="app-user--sections--show" href="#show-all">
      Показать всех друзей
        </a>-->
        </div>
<?}?>



	<?if ($data['count_photos'] > 0) {?>
	<div class="app-container">
      <div class="app-user--sections" id="uphoto">
        <div class="app-user--sections--name">
          <a href="/photos<?=$data['id']?>" title="Фотографии"><?=language::text('photo', $language,'profile')?>
            <span class="app-sections--counter"><?=$data['count_photos']?></span>
          </a>
        </div>

        <div class="app-user--sections--main">
            <?$pho = DB :: $pdo -> query("SELECT * FROM `photos` WHERE `id_user` = ?  ORDER by `time` DESC LIMIT 8", array($data['id'])); #Переменная фото
                $i = 0;
		        $in = 0;
	    	while($r = $pho -> fetch()) {
			++$i;
            ?>
        <div class="app-user--sections--item">
            <a href="/photos<?="{$data['id']}/view{$r['id']}"?>">
              <img class="app--sections--photo" src="<?=FILES_SERVER.system :: photosGetView($r['hash'],1)?>">
            </a>
          </div>
<?}?>
       

      </div>
    </div>
    <!--<a class="app-user--sections--show" href="#show-all">
        Показать все фотографии
        </a>-->
    </div>
	<?}?>
	
	
	
	
	
		<?
			$lo= DB :: $pdo -> querySingle("SELECT COUNT(*) FROM `groups_users` WHERE `id_user` = '".$data['id']."'");
		if ($lo > 0) {
	
		?>
<div class="app-container">
      <div class="app-user--sections" id="ufriends">
        <div class="app-user--sections--name">
          <a href="" title="Группы">Группы 
            <span class="app-sections--counter"><?=$lo?></span>
          </a>
        </div>

        <div class="app-user--sections--main">
            <?
            $query = DB :: $pdo -> query("SELECT * FROM `groups_users` WHERE `id_user` = '".$data['id']."' ORDER BY `id` DESC LIMIT 8");
    while($gpp = $query -> fetch())
    {
    $group = DB :: $pdo -> queryFetch("SELECT * FROM `groups` WHERE `id` = ? LIMIT 1;", array($gpp['id_group']));
  
   ?>

    
          <div class="app-user--sections--item">
            <a href="/groups/?group=<?echo $group['id'];?>">
              <div class="post-l app-user--sections--avatar">
                 <?=group :: Avatar($group,0)?>
              </div>
              
            </a>
          </div>
<?}?>

        </div></div>
       <!--  <a class="app-user--sections--show" href="#show-all">
      Показать всех друзей
        </a>-->
        </div>
<?}?>

	
	
	
	
	<?if ($data['count_gifts'] > 0) {?>
	<div class="app-container">
      <div class="app-user--sections" id="ufriends">
        <div class="app-user--sections--name">
          <a href="/gifts?id=<?=$data['id']?>" title="Подарки"><?=language::text('gifts', $language,'profile') ?>
            <span class="app-sections--counter"><?=$data['count_gifts']?></span>
          </a>
        </div>

        <div class="app-user--sections--main">

 <?php
         	if ($data['count_gifts'] > 0)
		    {
		       
		        $query_gifts = DB :: $pdo -> query("SELECT * FROM `user_gifts` WHERE `id_ank` = '".$data['id']."' ORDER BY `id` DESC LIMIT 8");
		        while($r_gifts = $query_gifts -> fetch())
		        {
		        ?>
		          
          <div class="app-user--sections--item">
            
              <div class="app-user--sections--avatar">
                <img class="app--sections--photo" src="<?=FILES_SERVER?>/gifts/<?=$r_gifts['id_gift']?>.jpg" width="64px" height="64px">
              </div>
         
          </div>
		        <?
		        }
		        
		    }
         ?>
          
         </div> </div></div>
         <?}?>

  
      <? if (isset($data['id']) && $data['id'] == $user['id'])
        { ?>

        <div class="app-container-NsTYLE">
      <a class="app-upage-link-button" style="width: 50%;" href="/blog?id=<?=$data['id']?>" title="Написать в блог"> Написать в блог</a>
    </div>
 <?}?> 
 <?
 $total = DB :: $pdo -> querySingle("SELECT COUNT(*) FROM `blog` WHERE `id_user` = '".$data['id']."'");
if ($total == 0)
{
?>
 
<?
} else {
    if ($total > 10)
    {
        $p = (($_GET['p']) ? intval($_GET['p']) : 1);
        $pagination = new pagination(10, $total, $p);
        $total_lin = $pagination -> limit;
    } else {
        $total_lin = '';
    }
    $query = DB :: $pdo -> query("SELECT * FROM `blog` WHERE `id_user` = '".$data['id']."' ORDER BY `id` DESC ".$total_lin."");
    while($gpp = $query -> fetch())
    {
    $post_cc = DB :: $pdo -> querySingle("SELECT COUNT(*) FROM `blog_comments` WHERE `id_note` = '".$gpp['id']."'");
    
				?>
			
             

				
				
				
				
				
				
    
 
 
 
 <div class="app-container">
     
     <div class="app-user--block">
           <?  if (isset($data['id']) && $data['id'] == $user['id'])
                        {?>     <div>
        <a class="toggle-menu-act" onclick="UI.toggleMenu(this);"><span></span></a>
                            <div class="toggle-menu">
                            <div class="toggle-menu-arrow"><span></span></div>
                            <ul class="toggle-menu-block">
                        
                    <a href="/blog/?note=<?echo $gpp['id'];?>&edit">Редактировать</a>
                      
                       <a href="/blog/?note=<?echo $gpp['id'];?>&dell">Удалить</a> 
                       
        </ul>
        </div>
        </div>
        <?}?>
          <div class="app-user-b_top">
          <div class="app-user-b_uavatar">
            <span class="circle-photo"> <?=profile::userAvatar($data, 4)?> </span>
          </div>

          <div class="app-user-b_lef">
            <div class="app-user-b_username">
              <?=profile::ico($data).profile::getFullName($data)?>
            </div>
            <div class="app-user-b_date"><?=system::times($gpp['time'])?></div>
          </div>
        </div>

        <div class="app-user-b_content">
       <?= Emoji :: Text($gpp['text']); ?>
	   <?
	    if (DB :: $pdo -> querySingle("SELECT COUNT(*) FROM `blog_files` WHERE `id_blog` = '".$gpp['id']."'") > 0)
                {
                ?>
                    <div class="list_blog39">
                        <?
                        $query_f = DB :: $pdo -> query("SELECT * FROM `blog_files` WHERE `id_blog` = '".$gpp['id']."' ORDER BY `id` DESC");
                        while($r_f = $query_f -> fetch())
                        {
                        ?>
                            <div class="llq_pdq--291">
                               
                                <img class="liq-pdq--891" src="<?echo "".FILES_SERVER."/blog_files/".$r_f['id']."_m.jpg";?>" alt="*" />
                                
                            </div>
                        <?
                        }
                        ?>
                    </div>
                <?
                }
	   ?>
	   
        </div>
      </div>
      <div class="app-user-b_bot">
        <a class="app-link_spo" href="/blog/?note=<?=$gpp['id']?>&" title="Комментировать">Комментировать</a> <span style="color: #666b7b;padding: 5px;background: #e2e2e2;text-align: center;border-radius: 3px;"><?=$post_cc?></span>

        
      </div>
    </div>
 <?
 }

}
?>
 
 
 
 
 
 
 
 
 
 
 
     
<?php
		} else if($data['id'] == $config['SYS_ID']) {
		?>
		<div class="list">
			<?=profile :: getName($data)?>
			<div class="_line"></div>
			<div class="_center _gray" style="font-size: 14px;">
				Официальная страница поддержки.
			</div>
		</div>
		<?php
		}
	} else {
		?>
		<div class="app-block">
		<div class="list">
		<div class="_center _gray" style="font-size: 14px;">
		<img src="/template/icons/att.png" /><br />
		Страница удалена или же еще не создана.
		</div>
		</div>
		</div>
		<?php
	}

	require (CORE."foot.php");