Implement update functionality

Signed-off-by: Luke Tainton <luke@tainton.uk>
This commit is contained in:
2020-08-09 13:56:31 +01:00
parent cdf2bcc73c
commit 383b33d58e

View File

@@ -2,6 +2,22 @@
$PAGE_NAME = "Update Request"; $PAGE_NAME = "Update Request";
require_once __DIR__ . "/../includes/header.php"; require_once __DIR__ . "/../includes/header.php";
// If form submitted, save to database
if($_SERVER['REQUEST_METHOD'] == 'POST') {
try {
// Process ticket data
$stmt = "INSERT INTO ticket_updates (ticket, user, msg) VALUES (:tktuuid, :user, :msg)";
$sql = $db->prepare($stmt);
$sql->bindParam(':tktuuid', $_POST['rid']);
$sql->bindParam(':user', $_SESSION['uuid']);
$sql->bindParam(':msg', $_POST['msg']);
$sql->execute();
} catch (PDOException $e) {
// echo("Error: <br>" . $e->getMessage() . "<br>");
$new_ticket_alert = array("danger", "Failed to save update: " . $e->getMessage());
}
header('Location: /view?rid=' . $_POST['rid'], true);
} else { // Form not yet submitted
// Get ticket // Get ticket
try { try {
$ticket_stmt = "SELECT * FROM tickets WHERE uuid=:uuid"; $ticket_stmt = "SELECT * FROM tickets WHERE uuid=:uuid";
@@ -12,7 +28,7 @@
$ticket_result = $ticket_sql->fetchAll(); $ticket_result = $ticket_sql->fetchAll();
$request = $ticket_result[0]; $request = $ticket_result[0];
} catch (PDOException $e) { } catch (PDOException $e) {
echo("Error: " . $e->getMessage()); $new_ticket_alert = array("danger", "Failed to get request: " . $e->getMessage());
} }
// Get ticket updates // Get ticket updates
@@ -24,7 +40,7 @@
$updates_sql->setFetchMode(PDO::FETCH_ASSOC); $updates_sql->setFetchMode(PDO::FETCH_ASSOC);
$updates_result = $updates_sql->fetchAll(); $updates_result = $updates_sql->fetchAll();
} catch (PDOException $e) { } catch (PDOException $e) {
echo("Error: " . $e->getMessage()); $new_ticket_alert = array("danger", "Failed to get updates: " . $e->getMessage());
} }
// Get authorised subscribers // Get authorised subscribers
@@ -36,8 +52,10 @@
$users_sql->setFetchMode(PDO::FETCH_ASSOC); $users_sql->setFetchMode(PDO::FETCH_ASSOC);
$users_result = $users_sql->fetchAll(); $users_result = $users_sql->fetchAll();
} catch (PDOException $e) { } catch (PDOException $e) {
echo("Error: " . $e->getMessage()); $new_ticket_alert = array("danger", "Failed to get subscribers: " . $e->getMessage());
} }
}
$authorised_users = array(); $authorised_users = array();
foreach($users_result as $user) { foreach($users_result as $user) {
@@ -167,10 +185,13 @@
</section> </section>
<section> <section>
<div class="card mx-auto" style="width: 50%;margin-bottom: 50px;"> <div class="card mx-auto" style="width: 50%;margin-bottom: 50px;">
<form style="padding: 2%" action="/new" method="post" enctype="multipart/form-data"> <form style="padding: 2%" action="/update" method="post" enctype="multipart/form-data">
<div class="form-group"> <div class="form-group">
<label for="description">Update: </label> <input type="hidden" id="rid" name="rid" value="<?php echo($_GET['rid']); ?>">
<textarea type="text" class="form-control" id="description" name="description" rows="3"></textarea> </div>
<div class="form-group">
<label for="msg">Update: </label>
<textarea type="text" class="form-control" id="msg" name="msg" rows="3"></textarea>
</div> </div>
<button type="submit" class="btn btn-primary">Submit</button> <button type="submit" class="btn btn-primary">Submit</button>
</form> </form>