aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2021-04-29 20:43:35 +0300
committerAqua-sama <aqua@iserlohn-fortress.net>2021-04-29 20:43:35 +0300
commit7319816b7c712cd16d6e83bcd617c95943b79be6 (patch)
treeae5de7c1e2a4387c50ee1df53b24b0021be5c591
parentFinish user management (diff)
downloadbugtracker-7319816b7c712cd16d6e83bcd617c95943b79be6.tar.xz
CRUD reports
-rw-r--r--bug/delete.php0
-rw-r--r--bug/edit.php (renamed from edit.php)0
-rw-r--r--bug/update.php (renamed from update.php)0
-rw-r--r--bug/view.php (renamed from view.php)0
-rw-r--r--etc/readme.md25
-rw-r--r--index.php6
-rw-r--r--readme.md28
-rw-r--r--report/delete.php28
-rw-r--r--report/edit.php43
-rw-r--r--report/update.php28
-rw-r--r--report/view.php32
-rw-r--r--usage.md19
12 files changed, 173 insertions, 36 deletions
diff --git a/bug/delete.php b/bug/delete.php
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/bug/delete.php
diff --git a/edit.php b/bug/edit.php
index 7eba339..7eba339 100644
--- a/edit.php
+++ b/bug/edit.php
diff --git a/update.php b/bug/update.php
index f27cdd4..f27cdd4 100644
--- a/update.php
+++ b/bug/update.php
diff --git a/view.php b/bug/view.php
index 2468abb..2468abb 100644
--- a/view.php
+++ b/bug/view.php
diff --git a/etc/readme.md b/etc/readme.md
new file mode 100644
index 0000000..2d01f05
--- /dev/null
+++ b/etc/readme.md
@@ -0,0 +1,25 @@
+## How to run the services manually
+
+### php-fpm
+```sh
+php-fpm --fpm-config php/php-fpm.conf
+```
+
+### nginx
+```sh
+nginx -p nginx/ -c nginx.conf
+```
+
+### postgresql
+```sh
+# setup
+initdb -D /path/to/postgres.d
+createdb -h localhost -p 5432 -U $(whoami) bugtracker
+
+# starting
+pg_ctl -D postgres/ -l logfile start
+
+# connecting
+psql -h localhost bugtracker
+```
+
diff --git a/index.php b/index.php
index f63f3af..02ad53a 100644
--- a/index.php
+++ b/index.php
@@ -39,11 +39,11 @@ foreach ($bugs_r as $row) {
<?php
if(session_set()) {
- echo "<p><a href='{$config['urls']['base']}/reports/edit.php'>Create</a></p>\n";
+ echo "<p><a href='{$config['urls']['base']}/report/edit.php'>Create</a></p>\n";
}
# reports query
-$reports_q = 'SELECT title, description, author FROM reports WHERE bug IS NULL';
+$reports_q = 'SELECT reports.id AS id, title, description, users.username AS user FROM reports JOIN users ON reports.author=users.id WHERE bug IS NULL ORDER BY id';
$reports_r = $conn->query($reports_q);
if($reports_r->rowCount() > 0) {
@@ -53,7 +53,7 @@ if($reports_r->rowCount() > 0) {
<tr><th>Title</th><th>Description</th><th>Submitted by</th></tr>
<?php
foreach ($reports_r as $row) {
- echo "<tr><td><a href=view.php?id=$row[id]>$row[title]</a></td> <td>" . truncate($row['description']) . "</td> <td>$row[submitter]</td></tr>\n";
+ echo "<tr><td><a href=report/view.php?id=$row[id]>$row[title]</a></td> <td>" . truncate($row['description']) . "</td> <td>$row[user]</td></tr>\n";
}
?>
</table>
diff --git a/readme.md b/readme.md
index 1da26fc..455dd6b 100644
--- a/readme.md
+++ b/readme.md
@@ -20,18 +20,18 @@ A simple bugtracker written in php.
login | user/login.php
logout | user/logout.php
-## bugs
-
-### create
-### read
-### update
-### delete
-
-## reports
-
-### create
-### read
-### update
-### delete
+### reports
+ action |
+--------|--------
+ create | report/edit.php
+ read | report/view.php
+ update | report/update.php
+ delete | report/delete.php
-## index page
+### bugs
+ action |
+--------|--------
+ create | bug/edit.php
+ read | bug/view.php
+ update | bug/update.php
+ delete | bug/delete.php
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 @@
+<?php
+require '../config.php';
+require_once(TEMPLATES_PATH . "/header.php");
+require_once(TEMPLATES_PATH . "/panel.php");
+require_once(LIBRARY_PATH . "/functions.php");
+
+if(!session_set()) {
+ echo "You need to be logged in";
+ goto redirect;
+}
+
+if($_GET['id'] == "") {
+ echo "No report to delete";
+ goto redirect;
+}
+
+$conn = new PDO($config['db']['dsn'], $config['db']['username'], $config['db']['password']);
+$query = $conn->prepare("DELETE FROM reports WHERE id=:report_id");
+$query->bindParam(':report_id', $_GET['id']);
+if($query->execute()) {
+ echo "<h2>report deleted</h2>";
+} else {
+ echo "<h2>report failed to delete</h2>";
+}
+
+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 @@
+<?php
+require '../config.php';
+require_once(TEMPLATES_PATH . "/header.php");
+require_once(TEMPLATES_PATH . "/panel.php");
+require_once(LIBRARY_PATH . "/functions.php");
+
+if(!session_set()) {
+ header("Refresh: 2; URL={$config['urls']['base']}");
+ goto footer;
+}
+
+$id = isset($_GET['id']) ? $_GET['id'] : "";
+$title = "";
+$submitter = $_SESSION['user_name'];
+$description = "";
+
+if($id != "") {
+ $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', $id);
+ $query->execute();
+
+ $result = $query->fetch();
+ $title = $result['title'];
+ $submitter = $result['submitter'];
+ $description = $result['description'];
+}
+
+?>
+
+<form action="update.php?id=<?php echo $id; ?>" method="post">
+<input name="id" type="hidden" value="<?php echo $id; ?>">
+<p>Title: <input name="title" type="text" value="<?php echo $title; ?>"></p>
+<p>Submitted by: <?php echo $submitter; ?></p>
+<p>Description: <br><textarea name="description" rows=25 cols=80><?php echo $description; ?></textarea></p>
+<input type="submit" value="submit" >
+</form>
+
+<?php
+footer: require_once(TEMPLATES_PATH . "/footer.php");
+?>
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 @@
+<?php
+require '../config.php';
+require_once(TEMPLATES_PATH . "/header.php");
+require_once(TEMPLATES_PATH . "/panel.php");
+require_once(LIBRARY_PATH . "/functions.php");
+
+if(session_set()) {
+ $conn = new PDO($config['db']['dsn'], $config['db']['username'], $config['db']['password']);
+ $query = $_POST['id'] == "" ?
+ $conn->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 "<h2>report submitted</h2>";
+ } else {
+ echo "<h2>report failed to submit</h2>";
+ }
+}
+
+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 @@
+<?php
+require '../config.php';
+require_once(TEMPLATES_PATH . "/header.php");
+require_once(TEMPLATES_PATH . "/panel.php");
+require_once(LIBRARY_PATH . "/functions.php");
+require_once(LIBRARY_PATH . "/parsedown.php");
+
+if(!isset($_GET['id']) || $_GET['id'] == "") {
+ echo "<div id='error'>No report selected, redirecting to index...</div>";
+ 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 "<p><b>$result[title]</b></p>";
+echo "<p>Submitted by $result[submitter]</p>";
+echo '<p>' . $markdown->text($result['description']) . '</p>';
+
+if(session_set()) {
+ echo "<p><a href=edit.php?id=$_GET[id]>Edit</a> | <a href=delete.php?id=$_GET[id]>Delete</a></p>";
+}
+
+footer: require_once(TEMPLATES_PATH . "/footer.php");
+?>
diff --git a/usage.md b/usage.md
deleted file mode 100644
index 1d25ff9..0000000
--- a/usage.md
+++ /dev/null
@@ -1,19 +0,0 @@
-## Starting services
-
-```sh
-php-fpm --fpm-config php/php-fpm.conf
-nginx -p nginx/ -c nginx.conf
-```
-
-## postgresql
-### setup
-```sh
-$ initdb -D /path/to/postgres.d
-$ createdb -h localhost -p 5432 -U red bugtracker
-
-# starting
-pg_ctl -D /home/red/etc/postgres/ -l logfile start
-
-# connecting
-psql -h localhost bugtracker
-```