<?php
  
//Навигация
ECHO "<div class='navigation'>";
ECHO "<a href='/'>".ICONS('home', 25, 'fa-fw')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "".LG('Фотоальбомы')."</a>";
ECHO "</div>";

ECHO "<div class='tmenu_body'>";

IF (GET('get') == 'rating'){
  
  $sql = "ORDER BY `PHOTOS`.`RATING` DESC";
  $url = "&get=rating";
  
  ECHO "<a href='/modules/?path=photos' class='tmenu-33'>".LG('Новые')."</a>";
  ECHO "<a href='/modules/?path=photos&get=all' class='tmenu-33'>".LG('Все')."</a>";
  ECHO "<a href='/modules/?path=photos&get=rating' class='tmenu-33 tmenu-33-o'>".LG('По рейтингу')."</a>";
  
}ELSEIF (GET('get') == 'all'){
  
  $sql = NULL;
  $url = "&get=all";
  
  ECHO "<a href='/modules/?path=photos' class='tmenu-33'>".LG('Новые')."</a>";
  ECHO "<a href='/modules/?path=photos&get=all' class='tmenu-33 tmenu-33-o'>".LG('Все')."</a>";
  ECHO "<a href='/modules/?path=photos&get=rating' class='tmenu-33'>".LG('По рейтингу')."</a>";
  
}ELSE{
  
  $sql = "ORDER BY `PHOTOS`.`TIME` DESC";
  $url = NULL;
  
  ECHO "<a href='/modules/?path=photos' class='tmenu-33 tmenu-33-o'>".LG('Новые')."</a>";
  ECHO "<a href='/modules/?path=photos&get=all' class='tmenu-33'>".LG('Все')."</a>";
  ECHO "<a href='/modules/?path=photos&get=rating' class='tmenu-33'>".LG('По рейтингу')."</a>";
  
}

ECHO "</div>";

//Поиск
REQUIRE (ROOT.'/modules/search/plugins/form/photos.php');

$data2 = DB::GET_STRING_ALL("SELECT `PHOTOS`.`ID` FROM `PHOTOS` LEFT JOIN `PHOTOS_DIR` ON (`PHOTOS_DIR`.`ID` = `PHOTOS`.`ID_DIR` OR `PHOTOS_DIR`.`ID_DIR` = `PHOTOS`.`ID_DIR`) WHERE `PRIVATE` = '0' GROUP BY `PHOTOS`.`ID`");

$column = 0;

WHILE ($data2->FETCH())
{
  
  $column++;
  
}

$spage = SPAGE($column, $page_settings);
$page = PAGE($spage);
$limit = $page_settings * $page - $page_settings;

IF ($column == 0){ 
  
  HTML::EMPTY();
  
}ELSE{
  
  ECHO "<div class='list-body'>"; 
  ECHO "<ul class='photos-body'>";
  
}

$data = DB::GET_STRING_ALL("SELECT `PHOTOS`.`ID`,`PHOTOS`.`ID_DIR`,`PHOTOS`.`EXT`,`PHOTOS`.`NAME` FROM `PHOTOS` LEFT JOIN `PHOTOS_DIR` ON (`PHOTOS_DIR`.`ID` = `PHOTOS`.`ID_DIR` OR `PHOTOS_DIR`.`ID_DIR` = `PHOTOS`.`ID_DIR`) WHERE `PRIVATE` = '0' GROUP BY `PHOTOS`.`ID` ".$sql." LIMIT ".$limit.", ".$page_settings."");

WHILE ($list = $data->FETCH())
{
  
  ECHO "<li class='photos-wrapper'><a href='/modules/?path=photos&section=show&photo_id=".$list['ID']."' class='photos'>";
  
  ECHO "<img src='/photo/240x240/".$list['ID_DIR']."/".$list['ID']."/' style='max-width: 100%; position: absolute;'>";
  
  ECHO "<span class='photos-or-dir'>".ICONS('camera', 13, 'fa-fw')." ".$list['EXT']."</span>";
  
  $count_like = DB::GET_COLUMN("SELECT COUNT(`ID`) FROM `PHOTOS_LIKES` WHERE `PHOTO_ID` = '".$list['ID']."' LIMIT 1");
  
  ECHO "<span class='photos-like_'>".ICONS('heart', 13, 'fa-fw')." ".$count_like."</span>";
  
  ECHO "<span class='photos-or-dir-text'>".CROP_TEXT(TEXT_ABSOLUTE($list['NAME']), 0, 14)."</span>";
  
  ECHO "</a></li>";
  
}

IF ($column > 0){
  
  ECHO "</ul>";
  ECHO "</div>";
  
}

IF ($spage > 1){ ECHO STR_PAGE('/modules/?path=photos'.$url.'&', $spage, $page); }

IF (ISSET($user)){
  
  ECHO "<div class='list'>";
  ECHO "<a href='/modules/?path=photos&section=users&id=".$user['ID']."'>".ICONS('arrow-left', 15, 'fa-fw')." ".LG('К моим альбомам')."</a>";
  ECHO "</div>";
  
}

//Навигация
ECHO "<div class='navigation'>";
ECHO "<a href='/'>".ICONS('home', 25, 'fa-fw')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "".LG('Фотоальбомы')."</a>";
ECHO "</div>"; 
  
?>