add uploaded files to edit, note details, welcome page

This commit is contained in:
Felix Ivo 2025-07-07 10:42:12 +02:00
parent 9db4d93ce3
commit 0799db48f0
5 changed files with 61 additions and 3 deletions

View File

@ -94,6 +94,11 @@ class NotesModel extends Database
$params = [trim($title), $content, $noteId, $userId]; $params = [trim($title), $content, $noteId, $userId];
} }
$stmt->execute($params); $stmt->execute($params);
$uploadResult = $this->uploadFiles($noteId);
if (!$uploadResult['success']) {
return $uploadResult;
}
if ($stmt->rowCount() > 0) { if ($stmt->rowCount() > 0) {
return ['success' => true, 'message' => 'Note updated successfully.']; return ['success' => true, 'message' => 'Note updated successfully.'];
@ -148,6 +153,19 @@ class NotesModel extends Database
} }
} }
function getFileCount() {
$pdo = $this->linkDB();
if (!$pdo) return 0;
try {
$stmt = $pdo->prepare("SELECT COUNT(*) FROM files");
$stmt->execute();
return $stmt->fetchColumn();
} catch (PDOException $e) {
error_log("Get Files Count Error: " . $e->getMessage());
return 0;
}
}
function getNoteCount() { function getNoteCount() {
$pdo = $this->linkDB(); $pdo = $this->linkDB();
if (!$pdo) return 0; if (!$pdo) return 0;

View File

@ -67,7 +67,6 @@ function sanitize($data, $flags = ENT_QUOTES, $encoding = 'UTF-8') {
<input type="file" id="attachments" name="attachments[]" multiple> <input type="file" id="attachments" name="attachments[]" multiple>
</div> </div>
<div class="form-actions"> <div class="form-actions">
<button type="submit" class="button">Create Note</button> <button type="submit" class="button">Create Note</button>
</div> </div>

View File

@ -15,6 +15,8 @@ if (!$note) {
echo "<a href='?controller=Notes&page=showNotes&do=showNotes' class='button secondary'>Back to Dashboard</a>"; echo "<a href='?controller=Notes&page=showNotes&do=showNotes' class='button secondary'>Back to Dashboard</a>";
} }
$files = $this->notesModel->getUploadedFiles($noteId);
function isLoggedIn() { function isLoggedIn() {
return isset($_SESSION['user_id']); return isset($_SESSION['user_id']);
} }
@ -37,7 +39,7 @@ function sanitize($data, $flags = ENT_QUOTES, $encoding = 'UTF-8') {
<div id="drop-zone">Drag & drop a .txt or .md file here, or fill manually.</div> <div id="drop-zone">Drag & drop a .txt or .md file here, or fill manually.</div>
<form id="note-form" method="POST"> <form id="note-form" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="update_note"> <input type="hidden" name="action" value="update_note">
<input type="hidden" name="note_id" value="<?php echo sanitize($note['id']); ?>"> <input type="hidden" name="note_id" value="<?php echo sanitize($note['id']); ?>">
<div class="form-group"> <div class="form-group">
@ -54,6 +56,22 @@ function sanitize($data, $flags = ENT_QUOTES, $encoding = 'UTF-8') {
<?php if($note && !empty($note['content'])) echo $parsedown->text(sanitize($note['content'])); else echo "Start typing or drop a file to see preview..."; ?> <?php if($note && !empty($note['content'])) echo $parsedown->text(sanitize($note['content'])); else echo "Start typing or drop a file to see preview..."; ?>
</div> </div>
</div> </div>
<div class="form-group">
<label for="attachments">Attach additional Files:</label>
<input type="file" id="attachments" name="attachments[]" multiple>
</div>
<?php if($files && count($files) > 0): ?>
<div class="form-group">
<label>Files currently attached:</label>
<ul>
<?php foreach($files as $file): ?>
<li>
<a href="<?php echo $file['path']; ?>" target="_blank"><?php echo htmlspecialchars($file['original_filename']); ?></a>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<div class="form-actions"> <div class="form-actions">
<button type="submit" class="button">Update Note</button> <button type="submit" class="button">Update Note</button>
</div> </div>

View File

@ -3,6 +3,9 @@
<?php <?php
$parsedown = new Parsedown(); $parsedown = new Parsedown();
$parsedown->setSafeMode(true); $parsedown->setSafeMode(true);
$this->notesModel = new \ppa\Model\NotesModel();
$files = $this->notesModel->getUploadedFiles($note['id']);
?> ?>
<div class="container"> <div class="container">
@ -24,6 +27,19 @@ $parsedown->setSafeMode(true);
<?php echo $parsedown->text($note['content'] ?? ''); ?> <?php echo $parsedown->text($note['content'] ?? ''); ?>
</div> </div>
<div class="note-files">
<?php if (isset($files) && count($files) > 0): ?>
<h3>Attached Files:</h3>
<ul>
<?php foreach ($files as $file): ?>
<li>
<a href="<?php echo $file['path']; ?>" target="_blank"><?php echo htmlspecialchars($file['original_filename']); ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
<div class="note-actions"> <div class="note-actions">
<a href="?controller=Notes&page=showNotes&do=showNotes" class="button">Back to Notes</a> <a href="?controller=Notes&page=showNotes&do=showNotes" class="button">Back to Notes</a>
<?php if (isset($note['id'])): ?> <?php if (isset($note['id'])): ?>

View File

@ -26,7 +26,14 @@ $this->userModel = new \ppa\Model\UserModel();
echo $this->userModel->getUserCount(); echo $this->userModel->getUserCount();
?> ?>
Users Users
</b> </b><br>
<b style="font-size: 20px; margin: 20px">
<?php
echo $this->notesModel->getFileCount();
?>
Files
</b><br>
<?php include dirname(__DIR__).'/footer.phtml'; ?> <?php include dirname(__DIR__).'/footer.phtml'; ?>