<?php
require_once __DIR__ . '/../includes/app.php';

require_admin();

$current = $_GET['dir'] ?? '';
$current = sanitize_dir($current);

$items = list_directory_contents($current);
?>
<!doctype html>
<html lang="tr">
<head>
<meta charset="utf-8">
<title>FTP Explorer</title>

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.13.1/font/bootstrap-icons.css" rel="stylesheet">

<style>

body{
    background:#f6f8fb;
}

.table td{
    vertical-align:middle;
}

.folder{
    font-weight:bold;
}

.actions{
    width:120px;
}

.pathbar{
    background:#fff;
    border-radius:8px;
    padding:10px;
    margin-bottom:15px;
}

.info{
    font-size:13px;
    color:#777;
}

</style>

</head>

<body>

<div class="container-fluid mt-4">

<h3 class="mb-4">

<i class="bi bi-folder2-open"></i>

FTP Explorer

</h3>

<div class="pathbar">

<strong>Dizin :</strong>

/

<?=e($current)?>

</div>

<table class="table table-hover table-bordered bg-white">

<thead>

<tr>

<th>Ad</th>

<th>Boyut</th>

<th>Tarih</th>

<th>İndirme</th>

<th class="actions"></th>

</tr>

</thead>

<tbody>

<?php

if($current!='')
{

$parent=dirname($current);

if($parent=='.')
$parent='';

?>

<tr>

<td colspan="5">

<a class="btn btn-sm btn-secondary"

href="?dir=<?=urlencode($parent)?>">

<i class="bi bi-arrow-left"></i>

Üst Dizin

</a>

</td>

</tr>

<?php

}

?>

<?php foreach($items as $item): ?>

<tr>

<td>

<?php

if($item['is_dir'])
{

?>

<i class="<?=e($item['icon'])?>"

style="color:<?=e($item['color'])?>"></i>

<a class="folder"

href="?dir=<?=urlencode($item['path'])?>">

<?=e($item['name'])?>

</a>

<?php

}
else

{

?>

<i class="<?=e($item['icon'])?>"

style="color:<?=e($item['color'])?>"></i>

<?=e($item['name'])?>

<div class="info">

<?=e($item['ext'])?>

</div>

<?php

}

?>

</td>

<td>

<?=

$item['is_dir']

?

'-'

:

format_size($item['size'])

?>

</td>

<td>

<?=date('d.m.Y H:i',$item['mtime'])?>

</td>

<td>

<?=$item['downloads']?>

</td>

<td>

<?php

if(!$item['is_dir'])

{

?>

<a

href="file-info.php?file=<?=urlencode($item['path'])?>"

class="btn btn-primary btn-sm">

Bilgi

</a>

<?php

}

?>

</td>

</tr>

<?php endforeach; ?>

</tbody>

</table>

</div>

</body>

</html>