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

@ini_set("output_buffering", "off");
header('Content-Type: text/html; charset=utf8');


error_reporting (E_ALL);

date_default_timezone_set('Europe/Kiev');

$d = dir(".");
$title = "File viewer";

$delimeter = DIRECTORY_SEPARATOR;
$path_parts = pathinfo(__FILE__);
$path_array = explode($delimeter, $path_parts['dirname']);
$converter = str_replace('converter_', '', $path_array[count($path_array)-2]);

?>

<!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>
<script type="text/javascript">
function ctrlSelectMenu (elem, evt)
{
	if (!evt)
		evt = event;

	var target = evt.target || evt.srcElement;
	if (target.tagName == 'INPUT') {
		var checked = target.checked;
		var List = document.forms[0];
		for (var i = 0; i < List.length; i++){
			List[i].checked = checked;
		}
	}
}
</script>
</head>
<body style="font-family:Trebuchet MS; font-size: 10pt;" bgcolor="#f5f8fb">

<table width="100%" bgcolor="#416e98">
<tr valign="middle">
<td><span style="font-size:25px; color:#FFF; font-family:Trebuchet MS"></span></td>
<td align="right"><span style="font-size:15px; color:#FFF; font-family:Trebuchet MS"><?php echo $title; ?></span></td>
</tr>
</table>
<center>
<?php 
echo <<<HTML
<form method="post" enctype="multipart/form-data" name="excelform" autocomplete="off">
HTML;


if (isset($_POST['delete'])){
	foreach ($_POST['del_file'] as $file){
		unlink($file);
	}
}

$d = dir(".");

$log = array();

while (false !== ($entry = $d->read())) {
	if ($entry != ".")
		if ($entry != "..")
			if ($entry != "index.php")
				if ($entry != ".htaccess"){
					$log[] = $entry;
				}
}
$d->close();


echo '<form method="post" enctype="multipart/form-data" name="excelform" autocomplete="off">';

arsort($log);
echo '<table  border=1 bordercolor="#416e98" style="border-collapse : collapse; margin:5px;">';

	echo '<tr>';
	echo '<td align=center>Им\'я файла</td>';
	echo '<td align=center>Розмір, байт</td>';
	echo '<td align=center>Відмітити <br />для видалення<br /><input type=checkbox name="select_all" value="1" onclick="ctrlSelectMenu(this, event)" /></td>';
	echo '</tr>';
$i = 0;	
foreach ($log as $entry){
	echo '<tr>';
	echo '<td><a href="'.$entry.'" target="_blank">'.$entry.'</a></td>';
	echo '<td align=right>'.filesize($entry).'</td>';
	echo '<td align=center><input type=checkbox id="del_cb['.$i++.']" name="del_file[]" value="'.$entry.'" /> </td>';
	echo '</tr>';
}


	echo '<tr>';
	echo '<td align=center> </td>';
	echo '<td align=center> </td>';
	echo '<td align=center><input type=submit name=delete value="Видалити" /></td>';
	echo '</tr>';
	
echo '</table></form>';
	

?>
</center>
</body></html>