From 7319816b7c712cd16d6e83bcd617c95943b79be6 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Thu, 29 Apr 2021 20:43:35 +0300 Subject: CRUD reports --- report/delete.php | 28 ++++++++++++++++++++++++++++ report/edit.php | 43 +++++++++++++++++++++++++++++++++++++++++++ report/update.php | 28 ++++++++++++++++++++++++++++ report/view.php | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 131 insertions(+) create mode 100644 report/delete.php create mode 100644 report/edit.php create mode 100644 report/update.php create mode 100644 report/view.php (limited to 'report') diff --git a/report/delete.php b/report/delete.php new file mode 100644 index 0000000..1e43244 --- /dev/null +++ b/report/delete.php @@ -0,0 +1,28 @@ +prepare("DELETE FROM reports WHERE id=:report_id"); +$query->bindParam(':report_id', $_GET['id']); +if($query->execute()) { + echo "

report deleted

"; +} else { + echo "

report failed to delete

"; +} + +redirect: header("Refresh: 2; URL=$_SERVER[HTTP_REFERER]"); +footer: require_once(TEMPLATES_PATH . "/footer.php"); +?> diff --git a/report/edit.php b/report/edit.php new file mode 100644 index 0000000..ef289bd --- /dev/null +++ b/report/edit.php @@ -0,0 +1,43 @@ +prepare("SELECT title, description, users.username AS submitter FROM reports + JOIN users ON reports.author=users.id + WHERE reports.id=:report_id"); + $query->bindParam(':report_id', $id); + $query->execute(); + + $result = $query->fetch(); + $title = $result['title']; + $submitter = $result['submitter']; + $description = $result['description']; +} + +?> + +
+ +

Title:

+

Submitted by:

+

Description:

+ +
+ + diff --git a/report/update.php b/report/update.php new file mode 100644 index 0000000..0fadb53 --- /dev/null +++ b/report/update.php @@ -0,0 +1,28 @@ +prepare("INSERT INTO reports (author, title, description) VALUES (:user_id, :title, :description)") + : $conn->prepare("UPDATE reports SET title=:title, description=:description WHERE id=:report_id"); + if($_POST['id'] == "") { + $query->bindParam(':user_id', $_SESSION['user_id']); + } else { + $query->bindParam(':report_id', $_POST['id']); + } + $query->bindParam(':title', $_POST['title']); + $query->bindParam(':description', $_POST['description']); + if($query->execute()) { + echo "

report submitted

"; + } else { + echo "

report failed to submit

"; + } +} + +header("Refresh: 2; URL=$_SERVER[HTTP_REFERER]"); +footer: require_once(TEMPLATES_PATH . "/footer.php"); +?> diff --git a/report/view.php b/report/view.php new file mode 100644 index 0000000..479f90e --- /dev/null +++ b/report/view.php @@ -0,0 +1,32 @@ +No report selected, redirecting to index..."; + header("Refresh: 2; URL=$_SERVER[HTTP_REFERER]"); + goto footer; +} + +$conn = new PDO($config['db']['dsn'], $config['db']['username'], $config['db']['password']); +$query = $conn->prepare("SELECT title, description, users.username AS submitter FROM reports + JOIN users ON reports.author = users.id WHERE reports.id=:report_id"); +$query->bindParam(':report_id', $_GET['id']); +$query->execute(); +$result = $query->fetch(); + +$markdown = new Parsedown(); + +echo "

$result[title]

"; +echo "

Submitted by $result[submitter]

"; +echo '

' . $markdown->text($result['description']) . '

'; + +if(session_set()) { + echo "

Edit | Delete

"; +} + +footer: require_once(TEMPLATES_PATH . "/footer.php"); +?> -- cgit v1.2.1