<?php
  
//Навигация
ECHO "<div class='navigation'>";
ECHO "<a href='/'>".ICONS('home', 25, 'fa-fw')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "<a href='/modules/?path=search'>".LG('Поиск по сайту')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO LG('Фото');
ECHO "</div>";

IF (POST('ok')){
  
  $_SESSION['search'] = ADSL(POST('search'));
  
}

IF (ISSET($_SESSION['search'])){
  
  $search = STRIPSLASHES(HTMLSPECIALCHARS($_SESSION['search']));
  
}ELSE{
  
  $search = NULL;
  
}

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

ECHO "<form method='post' action='/modules/?path=search&type=photos' class='panel-bottom-comments-js' style='position: relative;'>";

ECHO "<input type='text' name='search' class='form-control-100' placeholder='".LG('Что ищем?')."' value='".$search."'>";

ECHO "<button type='submit' id='ajax-comments-button' class='search-button' value='go'>".ICONS('search', 16, 'fa-fw')."</button>";

IF (CONFIG('CSRF') == 1){
  
  ECHO '<input type="hidden" name="'.$token_id.'" value="'.$token_value.'">';

}

ECHO '<input type="hidden" value="go" name="ok">';

ECHO "</form>";

ECHO "</div>";

$sql = "SELECT `PHOTOS`.`ID`,`PHOTOS`.`NAME`,`PHOTOS`.`ID_DIR` FROM `PHOTOS` LEFT JOIN `PHOTOS_DIR` ON (`PHOTOS_DIR`.`ID` = `PHOTOS`.`ID_DIR` OR `PHOTOS_DIR`.`ID_DIR` = `PHOTOS`.`ID_DIR`) WHERE `PRIVATE` = '0' AND (`PHOTOS`.`NAME` LIKE '%".$search."%' OR `PHOTOS`.`MESSAGE` LIKE '%".$search."%') GROUP BY `PHOTOS`.`ID`";

$photos = DB::GET_STRING_ALL($sql);

$column = 0;

WHILE ($photos->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'>";
  
}

$s = 0;

$data = DB::GET_STRING_ALL($sql." ORDER BY `PHOTOS`.`TIME` DESC 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=search&type=photos&', $spage, $page); }

//Навигация
ECHO "<div class='navigation'>";
ECHO "<a href='/'>".ICONS('home', 25, 'fa-fw')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "<a href='/modules/?path=search'>".LG('Поиск по сайту')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO LG('Фото');
ECHO "</div>";

REQUIRE (ROOT.'/system/connections/footer.php');
EXIT;
  
?>