<?php
$t = "Смайлы";
if (isset($_GET["id"])){
	if ($id == -1 || $db->Count("smiles","WHERE `id` = '".$id."'") == 0){
		include_once 'core/head.php';
		echo '<div class="error">Смайл не найден</div>';
		include_once 'core/foot.php';
		die();
	}
	$s = $db->getObject("SELECT * FROM `smiles` WHERE `id` = '".$id."'");
	$path = ROOT.("/media/images/smiles/".$s->path);
	if (!file_exists($path)){
		include_once 'core/head.php';
		echo '<div class="error">Смайл не найден</div>';
		include_once 'core/foot.php';
		die();
	}
	$line = @file_get_contents($path);
	$core->setHeaderFile("gif",$path);
	echo $line;
	die();
}
include_once 'core/head.php';
echo '<div class="title">Смайлы</div>';
$max = 10;
$k_post = $db->Count("smiles");
$k_page = $core->k_page($k_post,$max);
$page = $core->page($k_page);
$start = $max*$page-$max;

$gb = $db->Query("SELECT * FROM `smiles` ORDER BY `id` ASC LIMIT $start, $max"); 
while ($g = mysqli_fetch_assoc($gb)){
	$explode = explode(",",$g["code"]);
	$implode = implode(" ",$explode);
	echo '<div class="text"><img src="/smiles.lm?id='.$g["id"].'" alt="'.$explode[0].'"> - '.$implode.'</div>';
	
}
if($k_page>1) echo $core->str("?back=".$back."&",$k_page,$page);

echo ($back?linkGen($back,"Вернуться назад",["data-id"=>"link-back"]):null);
echo linkGen("/","На главную",["data-id"=>"link-home"]);
include_once 'core/foot.php';
?>