added note detail view
This commit is contained in:
@@ -43,4 +43,22 @@ class NotesModel extends Database
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function getNoteById($noteId) {
|
||||
$pdo = $this->linkDB();
|
||||
if (!$pdo) return null;
|
||||
try {
|
||||
if ($_SESSION['role'] === 'admin') { // Admin can fetch any note
|
||||
$stmt = $pdo->prepare("SELECT n.*, u.username as owner_username FROM notes n JOIN users u ON n.user_id = u.id WHERE n.id = ?");
|
||||
$stmt->execute([$noteId]);
|
||||
} else { // Regular user can only fetch their own notes
|
||||
$stmt = $pdo->prepare("SELECT * FROM notes WHERE id = ? AND user_id = ?");
|
||||
$stmt->execute([$noteId, $_SESSION['user_id']]);
|
||||
}
|
||||
return $stmt->fetch();
|
||||
} catch (PDOException $e) {
|
||||
error_log("Get Note Error: " . $e->getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user