First Commit

This commit is contained in:
2026-08-19 17:26:06 +01:00
parent f782c6f531
commit 121f788c28
25 changed files with 5132 additions and 73 deletions
+231 -4
View File
@@ -1,6 +1,233 @@
<?php
require_login();
$user = current_user();
// Check landing page redirection if default blocknote is set and user is not requesting explicitly view=all
if (!isset($_GET['view']) && !empty($user['default_blocknote'])) {
$def_bn = get_blocknote_by_id($user['default_blocknote']);
if ($def_bn && can_access_blocknote($def_bn, $user['username'], is_admin())) {
header("Location: index.php?page=view_blocknote&id=" . urlencode($user['default_blocknote']));
exit;
}
}
$msg_success = "";
$msg_error = "";
// Handle Form Submissions
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = $_POST['action'] ?? '';
if ($action === 'create_blocknote') {
$res = create_blocknote($_POST['title'] ?? '', $user['username']);
if ($res['success']) {
$msg_success = $res['message'];
} else {
$msg_error = $res['message'];
}
} elseif ($action === 'rename_blocknote') {
$res = rename_blocknote($_POST['id'] ?? '', $_POST['title'] ?? '', $user['username'], is_admin());
if ($res['success']) {
$msg_success = $res['message'];
} else {
$msg_error = $res['message'];
}
} elseif ($action === 'delete_blocknote') {
$res = delete_blocknote($_POST['id'] ?? '', $user['username'], is_admin());
if ($res['success']) {
$msg_success = $res['message'];
} else {
$msg_error = $res['message'];
}
} elseif ($action === 'import_blocknote') {
$json_content = "";
if (!empty($_FILES['json_file']['tmp_name'])) {
$json_content = file_get_contents($_FILES['json_file']['tmp_name']);
} else {
$json_content = $_POST['json_text'] ?? '';
}
$res = import_blocknote_json($json_content, $user['username'], $_POST['title'] ?? '');
if ($res['success']) {
$msg_success = $res['message'];
} else {
$msg_error = $res['message'];
}
}
}
// Fetch blocknotes
$blocknotes = get_user_blocknotes($user['username'], is_admin());
?>
<main class="main-content">
<section>
<h1>Welcome to the Home Page</h1>
<p>This is the home page.</p>
</section>
<div class="page-header">
<div class="page-title-group">
<h1>📓 <?= is_admin() ? __('dashboard_title_admin') : __('dashboard_title_user') ?></h1>
<p><?= is_admin() ? __('dashboard_desc_admin') : __('dashboard_desc_user') ?></p>
</div>
<div style="display: flex; gap: 0.5rem; flex-wrap: wrap;">
<button class="btn btn-dark" data-modal-target="modal-import-blocknote">
<?= __('btn_import_json') ?>
</button>
<button class="btn btn-primary" data-modal-target="modal-create-blocknote">
<?= __('btn_new_blocknote') ?>
</button>
</div>
</div>
<?php if (!empty($msg_success)): ?>
<div class="alert alert-success">
✅ <?= htmlspecialchars($msg_success) ?>
</div>
<?php endif; ?>
<?php if (!empty($msg_error)): ?>
<div class="alert alert-danger">
⚠️ <?= htmlspecialchars($msg_error) ?>
</div>
<?php endif; ?>
<?php if (empty($blocknotes)): ?>
<div class="empty-state">
<div class="empty-state-icon">📋</div>
<h3><?= __('empty_blocknotes_title') ?></h3>
<p><?= is_admin() ? __('empty_blocknotes_desc_admin') : __('empty_blocknotes_desc_user') ?></p>
<button class="btn btn-primary" data-modal-target="modal-create-blocknote">
<?= __('btn_new_blocknote') ?>
</button>
</div>
<?php else: ?>
<div class="blocknotes-grid">
<?php foreach ($blocknotes as $bn): ?>
<?php
$note_count = count($bn['notes'] ?? []);
$is_owner = (strtolower($bn['username'] ?? '') === strtolower($user['username']));
?>
<div class="blocknote-card">
<div class="blocknote-card-header">
<h2 class="blocknote-title">
<a href="index.php?page=view_blocknote&id=<?= urlencode($bn['id']) ?>">
<?= htmlspecialchars($bn['title']) ?>
</a>
</h2>
<?php if (is_admin() || !$is_owner): ?>
<span class="blocknote-owner-tag">
👤 <?= htmlspecialchars($bn['username'] ?? __('label_unknown')) ?>
</span>
<?php endif; ?>
</div>
<div class="blocknote-card-body">
<div class="blocknote-meta">
<span>📄 <?= $note_count ?> <?= ($note_count === 1) ? __('note_single') : __('note_plural') ?></span>
<span>🕒 <?= date('d/m/Y H:i', strtotime($bn['updated_at'] ?? 'now')) ?></span>
</div>
</div>
<div class="blocknote-card-actions">
<a href="index.php?page=view_blocknote&id=<?= urlencode($bn['id']) ?>" class="btn btn-sm btn-secondary" style="flex:1; justify-content:center;">
<?= __('btn_open_edit') ?>
</a>
<a href="index.php?page=export_blocknote&id=<?= urlencode($bn['id']) ?>" class="btn btn-sm btn-dark" title="<?= __('btn_export_json') ?>">
💾
</a>
<button class="btn btn-sm btn-dark" title="<?= __('btn_rename') ?>" onclick="openRenameModal('<?= htmlspecialchars($bn['id']) ?>', '<?= htmlspecialchars(addslashes($bn['title'])) ?>')">
✏️
</button>
<form action="index.php?page=home&view=all" method="POST" onsubmit="return confirm('<?= htmlspecialchars(addslashes(__('confirm_delete_blocknote'))) ?>');" style="display:inline;">
<input type="hidden" name="action" value="delete_blocknote">
<input type="hidden" name="id" value="<?= htmlspecialchars($bn['id']) ?>">
<button type="submit" class="btn btn-sm btn-danger" title="<?= __('btn_delete') ?>">
🗑️
</button>
</form>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</main>
<!-- MODAL CREA BLOCKNOTE -->
<div class="modal-backdrop" id="modal-create-blocknote">
<div class="modal-card">
<div class="modal-header">
<h3><?= __('modal_create_title') ?></h3>
<button class="modal-close-btn">&times;</button>
</div>
<form action="index.php?page=home&view=all" method="POST">
<input type="hidden" name="action" value="create_blocknote">
<div class="form-group">
<label for="create_title"><?= __('label_title') ?></label>
<input type="text" name="title" id="create_title" class="form-control" required placeholder="<?= htmlspecialchars(__('placeholder_bn_title')) ?>">
</div>
<div style="display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 1.5rem;">
<button type="button" class="btn btn-dark modal-close-trigger"><?= __('btn_cancel') ?></button>
<button type="submit" class="btn btn-primary"><?= __('btn_create') ?></button>
</div>
</form>
</div>
</div>
<!-- MODAL RINOMINA BLOCKNOTE -->
<div class="modal-backdrop" id="modal-rename-blocknote">
<div class="modal-card">
<div class="modal-header">
<h3><?= __('modal_rename_title') ?></h3>
<button class="modal-close-btn">&times;</button>
</div>
<form action="index.php?page=home&view=all" method="POST">
<input type="hidden" name="action" value="rename_blocknote">
<input type="hidden" name="id" id="rename_id">
<div class="form-group">
<label for="rename_title"><?= __('label_title') ?></label>
<input type="text" name="title" id="rename_title" class="form-control" required placeholder="<?= htmlspecialchars(__('placeholder_rename_title')) ?>">
</div>
<div style="display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 1.5rem;">
<button type="button" class="btn btn-dark modal-close-trigger"><?= __('btn_cancel') ?></button>
<button type="submit" class="btn btn-secondary"><?= __('btn_save') ?></button>
</div>
</form>
</div>
</div>
<!-- MODAL IMPORTA BLOCKNOTE -->
<div class="modal-backdrop" id="modal-import-blocknote">
<div class="modal-card">
<div class="modal-header">
<h3><?= __('modal_import_title') ?></h3>
<button class="modal-close-btn">&times;</button>
</div>
<form action="index.php?page=home&view=all" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="import_blocknote">
<div class="form-group">
<label for="import_title"><?= __('label_title') ?></label>
<input type="text" name="title" id="import_title" class="form-control" placeholder="<?= htmlspecialchars(__('placeholder_import_title')) ?>">
</div>
<div class="form-group">
<label for="json_file"><?= __('label_file_json') ?></label>
<input type="file" name="json_file" id="json_file" class="form-control" accept=".json">
</div>
<div class="form-group">
<label for="json_text"><?= __('label_paste_json') ?></label>
<textarea name="json_text" id="json_text" class="form-control" style="font-family: monospace; min-height: 120px;" placeholder="<?= htmlspecialchars(__('placeholder_paste_json')) ?>"></textarea>
</div>
<div style="display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 1.5rem;">
<button type="button" class="btn btn-dark modal-close-trigger"><?= __('btn_cancel') ?></button>
<button type="submit" class="btn btn-primary"><?= __('btn_import') ?></button>
</div>
</form>
</div>
</div>
<script>
function openRenameModal(id, currentTitle) {
document.getElementById('rename_id').value = id;
document.getElementById('rename_title').value = currentTitle;
document.getElementById('modal-rename-blocknote').classList.add('active');
}
</script>