<?php
/*------------------------------------------------
 * Photo viewer    
 * Copyright © FinBoss 2016
 * finboss.ua@gmail.com 
 *
 *
 * License: Commercial open source software (COSS) 
 *------------------------------------------------
 */

//ob_end_clean();
ob_implicit_flush(true);
@ini_set("output_buffering", "off");
header('Content-Type: text/html; charset=utf-8');

error_reporting (E_ALL);

if (isset($_GET['delete'])){
	if (is_file('files/'.$_GET['delete'])){
		unlink('files/'.$_GET['delete']);
	}
}

$d = dir("./files");
$title = "Просмотр фото";
$_file = "Файл:";
$_load = "Загрузить";
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" >
<title><?php echo $title; ?></title>
</head>
<body style="font-family:Trebuchet MS; font-size: 10pt;" bgcolor="#FEF4EB">

<table width="100%" bgcolor="#416e98">
<tr valign="middle">
<td><span style="font-size:25px; color:#FFF; font-family:Trebuchet MS"><?php echo $title; ?></span></td>
<td align="right"><span style="font-size:15px; color:#FFF; font-family:Trebuchet MS"></span></td>
</tr>
</table>
<?php 
echo "<br>";

$log = array();

while (false !== ($entry = $d->read())) {
	if ($entry != ".")
		if ($entry != "..")
			if ($entry != "index.php"){
				$log[$entry] = date("Y m d H i s", filectime("./files/".$entry));
			}
}
$d->close();

ksort($log);
echo '<a href="upload_photo.php">'."Закачать".'</a>';
echo '<br/><a href="translit_photo.php">'."Транслит".'</a>';
echo "<br/><br/>";
echo '<table border=1 bordercolor=white style="border-collapse : collapse" width="100%" height="80%">';
$i = 0;
echo '<tr><td valign=top align=left width=20%><div style="height:100%;overflow:scroll">';
$i = 1;
foreach ($log as $entry => $value){
	echo $i++.') <b><span style="cursor:hand;color:blue" onclick="document.getElementById(\'photo_name\').innerText=\''.$entry.'\';document.getElementById(\'photo\').src=\''."files/".$entry.'\';">'.$entry.'</span></b>
	<a href="view_photo.php?delete='.$entry.'" title="Удалить">X</a>
	<br/>';
}


foreach ($log as $entry => $value){
	echo "<td width='80%' valign='top'><center>";
	echo "<b><span style='color:red' id='photo_name'>$entry</span></b><br>";
	echo "<img id='photo' src='files/$entry' width=90%/>";
	echo "</td>";
	break;
}

echo '</div></td></tr>';
echo '</table>';
echo "Всего:".count($log);
echo '<br/>';



?>

</body></html>