<?

//$name описание действий объекта 
if ($type == 'album' && $post['avtor'] != $user['id']){
$name = '';
}

//Вывод блока с содержимым 
if ($type  ==  'album'){
$gallery = mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery` WHERE `id` = '".$post['id_file']."' LIMIT 1"));
if ($post['count'] > 5){
$kol = '10';
$kol2 = $post['count'] - 5;
}else{
$kol = $post['count'];
}

# -----------------------
# Ставим лайк
if (isset($_GET['like'])){
$stena=mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery_foto` WHERE `id` = '".intval($_GET['like'])."' LIMIT 11"));
$ank3=get_user($stena['id_user']);
$l=mysql_result(mysql_query("SELECT COUNT(*) FROM `photo_like` WHERE `id_photo` = '$stena[id]'"),0);
if (isset($_GET['like']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `photo_like` WHERE `id_photo` = '$stena[id]' AND `id_user` = '$user[id]' LIMIT 1"),0)==0){
mysql_query("INSERT INTO `photo_like` (`id_user`, `id_photo`) values('$user[id]', '$stena[id]')");

# Отправляем уведомление автору что ему поставили лайк
mysql_query("INSERT INTO `notification` (`avtor`, `id_user`, `id_object`, `all_type`, `type`, `time`) VALUES ('$user[id]', '$avtor[id]', '$stena[id]', '$gallery[id]', 'like', '$time')");
}
}

# Убрать лайк
if (isset($_GET['dlike'])){
$stena=mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery_foto` WHERE `id` = '".intval($_GET['dlike'])."'"));
$ank3=get_user($stena['id_user']);
$l=mysql_result(mysql_query("SELECT COUNT(*) FROM `photo_like` WHERE `id_photo` = '$stena[id]'"),0);
mysql_query("DELETE FROM `photo_like` WHERE `id_user` = '$user[id]' AND `id_photo` = '$stena[id]'");
}

# Закладки
# Добавляем в закладки
if (isset($_GET['fav'])){
$stena=mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery_foto` WHERE `id` = '".intval($_GET['fav'])."' LIMIT 1"));
$ank3=get_user($stena['id_user']);
$l=mysql_result(mysql_query("SELECT COUNT(*) FROM `bookmarks` WHERE `id_object` = '$stena[id]'"),0);
if (isset($_GET['fav']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `bookmarks` WHERE `id_object` = '$stena[id]' AND `id_user` = '$user[id]' LIMIT 1"),0)==0){
mysql_query("INSERT INTO `bookmarks` (`type`, `id_user`, `id_object`, `time`) values('foto', '$user[id]', '$stena[id]', '$time')");
}
}
# Убираем из закладок
if (isset($_GET['dfav'])){
$stena=mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery_foto` WHERE `id` = '".intval($_GET['dfav'])."'"));
$ank3=get_user($stena['id_user']);
$l=mysql_result(mysql_query("SELECT COUNT(*) FROM `bookmarks` WHERE `id_object` = '$stena[id]'"),0);
mysql_query("DELETE FROM `bookmarks` WHERE `id_user` = '$user[id]' AND `id_object` = '$stena[id]'");
}
# Закладки end

# -----------------------

if ($gallery['id']){

$as = mysql_query("SELECT * FROM `gallery_foto` WHERE `id_gallery` = '$gallery[id]' ORDER BY `id` DESC LIMIT $kol");
while ($xx = mysql_fetch_assoc($as)){

echo '<table class="block2">';
echo '<td class="block_avatar">';
echo ''.avatar($avtor['id']).' <span class="avatar_icon">'.online($avtor['id']).'</span>';
echo '</td>';
echo '<td style="vertical-align: middle;" class="block_info">';
//Дополнительное меню
echo '<a class="toggle-menu-act" onclick="UI.toggleMenu(this);"><span></span></a>';
echo '<div class="toggle-menu">';
echo '<div class="toggle-menu-arrow"><span></span></div>';
echo '<ul class="toggle-menu-block">';
echo '<a href="/id'.$avtor[id].'">Профиль</a>';
echo '<a href="/modules/photo/' . $gallery['id_user'] . '/' . $gallery['id'] . '/' . $xx['id'] . '/">Фото</a> ';
echo '</ul>';
echo '</div>';
echo '<span class="nick">'.user::nick($avtor['id']).'</span>';
echo '</td>';
echo '</table>';
echo '<div class="">';
echo '<a href="/modules/photo/' . $gallery['id_user'] . '/' . $gallery['id'] . '/' . $xx['id'] . '/"><img style="width: 100%; height: 250px; object-fit: cover;" src="/modules/photo/foto/' . $xx['id'] . '.' . $xx['ras'] . '"></a>';
echo '</div>';
echo '<div class="block3">';
if ($xx['opis'] != null)
echo output_text($xx['opis']);
echo '</div>';
echo '<div class="block2">';
# Счетчики
$count_kom = mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery_komm` WHERE `id_foto` = '".$xx[id]."' "),0);
$count_like = mysql_result(mysql_query("SELECT COUNT(*) FROM `photo_like` WHERE `id_photo` = '$xx[id]'"),0);
# Лайки + комментарии
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `photo_like` WHERE `id_user` = '".$user['id']."' AND `id_photo` = '".$xx['id']."' LIMIT 1"),0)==0){
echo '<a href="?like='.$xx['id'].'"><img src="/img/like.png"> <font color="#1f1f1f">'.$count_like.'</font></a>';
}else{
echo '<a href="?dlike='.$xx['id'].'"><img src="/img/like_ok.png"> <font color="#1f1f1f">'.$count_like.'</font></a>';
}
echo '<span style="margin: 0 15px;"><a href="/modules/photo/' . $gallery['id_user'] . '/' . $gallery['id'] . '/' . $xx['id'] . '/"><img src="/img/kom.png"> <font color="#1f1f1f">'.$count_kom.'</font></span></a>';

# Закладки
echo '<span style="float:right;">';
if (mysql_result(query("SELECT COUNT(*) FROM `bookmarks` WHERE `id_user` = '".$user['id']."' AND `id_object` = '" . $xx['id'] . "' AND `type`='foto' LIMIT 1"),0) == 0){
echo '<a href="?fav='.$xx['id'].'"><img src="/img/fav.png"></a>';
}else{
echo '<a href="?dfav='.$xx['id'].'"><img src="/img/fav_ok.png"></a>';
}
echo '</span>';
# Закладки end

echo '</div>';
}

}
}

?>