🚧 Did some stuff, don't remember exactly what

Signed-off-by: Luke Tainton <luke@tainton.uk>
This commit is contained in:
2020-08-04 21:20:57 +01:00
parent 68b0e4a565
commit eb3caf6a41
185 changed files with 21061 additions and 163 deletions

View File

@@ -9,11 +9,6 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#563d7c">
<?php
if (!is_signed_in()) {
echo("<meta http-equiv='refresh' content='0; url=" . $_ENV['APP_URL'] . "/login' />");
}
?>
<title><?php echo( $PAGE_TITLE ); ?></title>
<!-- Bootstrap core CSS -->

View File

@@ -2,28 +2,30 @@
$PAGE_NAME = "Home";
require_once __DIR__ . "/../includes/header.php";
// Get user's own tickets
try {
$user_tickets_stmt = "SELECT uuid, id, title, description, status FROM tickets WHERE created_by=:uuid";
$user_tickets_sql = $db->prepare($user_tickets_stmt);
$user_tickets_sql->bindParam(':uuid', $_SESSION['uuid']);
$user_tickets_sql->execute();
$user_tickets_sql->setFetchMode(PDO::FETCH_ASSOC);
$user_tickets_result = $user_tickets_sql->fetchAll();
} catch (PDOException $e) {
echo("Error: " . $e->getMessage());
}
if (is_signed_in()) {
// Get user's own tickets
try {
$user_tickets_stmt = "SELECT uuid, id, title, description, status FROM tickets WHERE created_by=:uuid";
$user_tickets_sql = $db->prepare($user_tickets_stmt);
$user_tickets_sql->bindParam(':uuid', $_SESSION['uuid']);
$user_tickets_sql->execute();
$user_tickets_sql->setFetchMode(PDO::FETCH_ASSOC);
$user_tickets_result = $user_tickets_sql->fetchAll();
} catch (PDOException $e) {
echo("Error: " . $e->getMessage());
}
// Get tickets user has subscribed to
try {
$sub_tickets_stmt = "SELECT ticket_uuid FROM ticket_subscribers WHERE user_uuid=:uuid";
$sub_tickets_sql = $db->prepare($sub_tickets_stmt);
$sub_tickets_sql->bindParam(':uuid', $_SESSION['uuid']);
$sub_tickets_sql->execute();
$sub_tickets_sql->setFetchMode(PDO::FETCH_ASSOC);
$sub_tickets_result = $sub_tickets_sql->fetchAll();
} catch (PDOException $e) {
echo("Error: " . $e->getMessage());
// Get tickets user has subscribed to
try {
$sub_tickets_stmt = "SELECT ticket_uuid FROM ticket_subscribers WHERE user_uuid=:uuid";
$sub_tickets_sql = $db->prepare($sub_tickets_stmt);
$sub_tickets_sql->bindParam(':uuid', $_SESSION['uuid']);
$sub_tickets_sql->execute();
$sub_tickets_sql->setFetchMode(PDO::FETCH_ASSOC);
$sub_tickets_result = $sub_tickets_sql->fetchAll();
} catch (PDOException $e) {
echo("Error: " . $e->getMessage());
}
}
function get_sub_ticket($db, $ticket_uuid) {
@@ -71,74 +73,80 @@
?>
is the one-stop shop for all of your IT-related needs. Let us know how we can help you by opening a request.
</p>
<p>
<a href='/new' class='btn btn-primary my-2'>Create a request</a>
<a href='/open' class='btn btn-secondary my-2'>View existing requests</a>
</p>
<?php if (is_signed_in()) { ?>
<p>
<a href='/new' class='btn btn-primary my-2'>Create a request</a>
<a href='/open' class='btn btn-secondary my-2'>View existing requests</a>
</p>
<?php } else { ?>
<p><b>Please log in to create or view requests.</b></p>
<?php } ?>
</div>
</section>
<section>
<div class="card mx-auto" style="width: 80%;">
<div class="card-header">
<span class="mdi mdi-ticket-outline"></span> My Open Requests
</div>
<ul class="list-group list-group-flush">
<?php
if (count($user_tickets_result) == 0) {
echo("<center><b>No open tickets</b></center>");
} else {
foreach($user_tickets_result as $tkt) {
?>
<li class="list-group-item">
<div class="container">
<div class="row">
<div class="col-10">
<span style="display: inline;" class="text-muted">#<?php echo(sprintf("%'.05d\n", $tkt["id"])); ?> </span><span><b><?php echo($tkt['title']); ?></b></span>
<p class="m-0"><?php echo($tkt['description']); ?></p>
</div>
<div class="col-2">
<a class="btn btn-success float-right" href="view?rid=<?php echo($tkt["uuid"]); ?>" role="button">Go</a>
<?php if (is_signed_in()) { ?>
<section>
<div class="card mx-auto" style="width: 80%;">
<div class="card-header">
<span class="mdi mdi-ticket-outline"></span> My Open Requests
</div>
<ul class="list-group list-group-flush">
<?php
if (count($user_tickets_result) == 0) {
echo("<center><b>No open tickets</b></center>");
} else {
foreach($user_tickets_result as $tkt) {
?>
<li class="list-group-item">
<div class="container">
<div class="row">
<div class="col-10">
<span style="display: inline;" class="text-muted">#<?php echo(sprintf("%'.05d\n", $tkt["id"])); ?> </span><span><b><?php echo($tkt['title']); ?></b></span>
<p class="m-0"><?php echo($tkt['description']); ?></p>
</div>
<div class="col-2">
<a class="btn btn-success float-right" href="view?rid=<?php echo($tkt["uuid"]); ?>" role="button">Go</a>
</div>
</div>
</div>
</div>
</li>
<?php } } ?>
</ul>
</div>
</section>
</li>
<?php } } ?>
</ul>
</div>
</section>
<section style="margin-top: 1%;">
<div class="card mx-auto" style="width: 80%;">
<div class="card-header">
<span class="mdi mdi-rss"></span> My Subscribed Requests
</div>
<ul class="list-group list-group-flush">
<?php
if (count($sub_tickets_result) == 0) {
echo("<center><b>No subscribed tickets</b></center>");
} else {
foreach($sub_tickets_result as $sub) {
$tkt = get_sub_ticket($db, $sub['ticket_uuid']);
$tkt_creator = get_user_name($db, $tkt['created_by']);
?>
<li class="list-group-item">
<div class="container">
<div class="row">
<div class="col-10">
<span style="display: inline;" class="text-muted">#<?php echo sprintf("%'.05d\n", $tkt["id"]); ?> </span><span><b><?php echo($tkt['title']); ?></b></span> <span style="display: inline;" class="text-muted"><?php echo("(Creator: " . $tkt_creator . ")"); ?></span>
<p class="m-0"><?php echo($tkt['description']); ?></p>
</div>
<div class="col-2">
<a class="btn btn-success float-right" href="view?rid=<?php echo($tkt["uuid"]); ?>" role="button">Go</a>
<section style="margin-top: 1%;">
<div class="card mx-auto" style="width: 80%;">
<div class="card-header">
<span class="mdi mdi-rss"></span> My Subscribed Requests
</div>
<ul class="list-group list-group-flush">
<?php
if (count($sub_tickets_result) == 0) {
echo("<center><b>No subscribed tickets</b></center>");
} else {
foreach($sub_tickets_result as $sub) {
$tkt = get_sub_ticket($db, $sub['ticket_uuid']);
$tkt_creator = get_user_name($db, $tkt['created_by']);
?>
<li class="list-group-item">
<div class="container">
<div class="row">
<div class="col-10">
<span style="display: inline;" class="text-muted">#<?php echo sprintf("%'.05d\n", $tkt["id"]); ?> </span><span><b><?php echo($tkt['title']); ?></b></span> <span style="display: inline;" class="text-muted"><?php echo("(Creator: " . $tkt_creator . ")"); ?></span>
<p class="m-0"><?php echo($tkt['description']); ?></p>
</div>
<div class="col-2">
<a class="btn btn-success float-right" href="view?rid=<?php echo($tkt["uuid"]); ?>" role="button">Go</a>
</div>
</div>
</div>
</div>
</li>
<?php } } ?>
</ul>
</div>
</section>
</li>
<?php } } ?>
</ul>
</div>
</section>
<?php } ?>
</main>

View File

@@ -1,60 +1,52 @@
<?php
$PAGE_NAME = "New request";
require_once __DIR__ . "/../includes/header.php";
use Ramsey\Uuid\Uuid;
// If form submitted, save to database
if($_SERVER['REQUEST_METHOD'] == 'POST') {
try {
// Process ticket data
$stmt = "INSERT INTO tickets (title, description, created_by) VALUES (:title, :description, :user)";
$tkt_uuid = Uuid::uuid4()->toString();
$stmt = "INSERT INTO tickets (uuid, title, description, created_by) VALUES (:tktuuid, :title, :description, :user)";
$sql = $db->prepare($stmt);
$sql->bindParam(':tktuuid', $tkt_uuid);
$sql->bindParam(':title', $_POST['title']);
$sql->bindParam(':description', $_POST['description']);
$sql->bindParam(':user', $_SESSION['uuid']);
$sql->execute();
} catch (PDOException $e) {
// echo("Error: <br>" . $e->getMessage() . "<br>");
$new_ticket_alert = array("danger", "SQL Error: " . $e->getMessage());
$new_ticket_alert = array("danger", "Failed to save request: " . $e->getMessage());
}
// Get ticket UUID
// If file is uploaded, process that
if(isset($_FILES['file']) && $_FILES['file']['name'] != "") {
try {
$tkt_stmt = "SELECT uuid FROM tickets WHERE created_by=:uuid AND created_on > date_sub(now(), interval 1 minute)";
$tkt_sql = $db->prepare($tkt_stmt);
$tkt_sql->bindParam(':uuid', $_SESSION['uuid']);
$tkt_sql->execute();
$tkt_sql->setFetchMode(PDO::FETCH_ASSOC);
$tkt_result = $tkt_sql->fetchAll()[0];
$tkt_uuid = $tkt_result['uuid'];
$file_name = $_FILES['file']['name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$file_tmp = $_FILES['file']['tmp_name'];
move_uploaded_file($file_tmp,"/srv/attachments/".$file_name);
$stmt = "INSERT INTO ticket_uploads (ticket, user, filename) VALUES (:ticket, :user, :name)";
$sql = $db->prepare($stmt);
$sql->bindParam(':ticket', $tkt_uuid);
$sql->bindParam(':user', $_SESSION['uuid']);
$sql->bindParam(':name', $file_name);
$sql->execute();
} catch (PDOException $e) {
// echo("Error: <br>" . $e->getMessage() . "<br>");
$new_ticket_alert = array("danger", "SQL Error: " . $e->getMessage());
$new_ticket_alert = array("danger", "Failed to upload file: " . $e->getMessage());
}
// If file is uploaded, process that
if(isset($_FILES['file'])) {
try {
$file_name = $_FILES['file']['name'];
$file_size =$_FILES['file']['size'];
$file_type=$_FILES['file']['type'];
$file_tmp =$_FILES['file']['tmp_name'];
move_uploaded_file($file_tmp,"/srv/attachments/".$file_name);
$stmt = "INSERT INTO ticket_uploads (ticket, user, path) VALUES (:ticket, :user, :filepath)";
$sql = $db->prepare($stmt);
$sql->bindParam(':ticket', $tkt_uuid);
$sql->bindParam(':user', $_SESSION['uuid']);
$sql->bindParam(':filepath', "/srv/attachments/".$file_name);
$sql->execute();
} catch (PDOException $e) {
// echo("Error: <br>" . $e->getMessage() . "<br>");
$new_ticket_alert = array("danger", "SQL Error: " . $e->getMessage());
}
}
}
header_remove("Location");
header('Location: /view?rid=' . $tkt_uuid);
}
if (!is_signed_in()) {
$new_ticket_alert = array("danger", "You need to log in to access this page.");
}
?>
@@ -66,21 +58,29 @@
<?php
if(isset($new_ticket_alert)) {
echo("
<div class='alert alert-" . $new_ticket_alert[0] . "' role='alert'>
" . $new_ticket_alert[1] . "
</div>
"); }
<section>
<div class='alert alert-" . $new_ticket_alert[0] . " alert-dismissible fade show' role='alert'>
" . $new_ticket_alert[1] . "
<button type='button' class='close' data-dismiss='alert' aria-label='Close'>
<span aria-hidden='true'>&times;</span>
</button>
</div>
</section>
");
unset($new_ticket_alert);
}
?>
</section>
<section class="jumbotron text-center">
<div class="container">
<h1>Create a new request</h1>
<p class="lead text-muted">
Fill in the form below to create a new request. We'll respond to it as soon as we can.
</p>
</div>
</section>
<?php if (is_signed_in()) { ?>
<section class="jumbotron text-center">
<div class="container">
<h1>Create a new request</h1>
<p class="lead text-muted">
Fill in the form below to create a new request. We'll respond to it as soon as we can.
</p>
</div>
</section>
<section>
<div class="card mx-auto" style="width: 50%;">
@@ -101,6 +101,7 @@
</form>
</div>
</section>
<?php } ?>
</main>

View File

@@ -8,19 +8,30 @@
<!-- Begin page content -->
<main role="main" class="flex-shrink-0">
<section class="jumbotron text-center">
<div class="container">
<h1>Open requests</h1>
<p class="lead text-muted">
Here you can find all of your requests, and other requests that you are subscribed to.
</p>
</div>
</section>
<section>
<p>This page is currently under construction.</p>
<?php if (is_signed_in()) { ?>
<section class="jumbotron text-center">
<div class="container">
<h1>Open requests</h1>
<p class="lead text-muted">
Here you can find all of your requests, and other requests that you are subscribed to.
</p>
</div>
</section>
<section>
<p>This page is currently under construction.</p>
</section>
<?php } else { ?>
<section>
<div class='alert alert-danger alert-dismissible fade show' role='alert'>
You need to log in to access this page.
<button type='button' class='close' data-dismiss='alert' aria-label='Close'>
<span aria-hidden='true'>&times;</span>
</button>
</div>
</section>
<?php } ?>
</main>
<?php

View File

@@ -32,7 +32,7 @@
array_push($authorised_users, $user['user_uuid']);
}
if (in_array($_SESSION['uuid'], $authorised_users)) {
if (in_array($_SESSION['uuid'], $authorised_users) || $_SESSION['uuid'] == $request['created_by']) {
$is_authorised = true;
} else {
$is_authorised = false;
@@ -45,29 +45,71 @@
<!-- Begin page content -->
<main role="main" class="flex-shrink-0">
<?php if ($is_authorised == true) { ?>
<section class="jumbotron text-center">
<div class="container">
<h1><?php echo($request['title']); ?></h1>
<p style="color: gray; font-style: italic;"><?php echo("#" . sprintf("%'.05d\n", $request["id"])); ?></p>
<p class="lead text-muted">
<?php echo($request['description']); ?>
</p>
<p>
<?php print_r($request); ?>
</p>
<p>
<?php print_r($users_result) ?>
</p>
<?php if (!is_signed_in()) { ?>
<section>
<div class='alert alert-danger alert-dismissible fade show' role='alert'>
You need to log in to access this page.
<button type='button' class='close' data-dismiss='alert' aria-label='Close'>
<span aria-hidden='true'>&times;</span>
</button>
</div>
</section>
<?php } else if ($is_authorised == false) { ?>
<section class="jumbotron text-center">
<div class="container">
<h1>You are not authorised to see this page.</h1>
</div>
</section>
<?php } ?>
<?php } else {
if ($is_authorised == true) { ?>
<section class="jumbotron text-center">
<div class="container">
<h1><?php echo($request['title']); ?></h1>
<p style="color: gray; font-style: italic;"><?php echo("#" . sprintf("%'.05d\n", $request["id"])); ?></p>
<p class="lead text-muted"><?php echo($request['description']); ?></p>
<div class="container">
<div class="row">
<div class="col-sm">
<div class="card mx-auto">
<div class="card-header"><span class="mdi mdi-information-outline"></span> Information</div>
<ul class="list-group list-group-flush">
<li class="list-group-item">
<div class="container">
<div class="row">
<span style="display: inline;"><b>Status:</b> <?php echo($request['status']); ?></span>
</div>
</div>
</li>
</ul>
</div>
</div>
<div class="col-sm">
<div class="card mx-auto">
<div class="card-header"><span class="mdi mdi-update"></span> Updates</div>
<ul class="list-group list-group-flush">
<li class="list-group-item">
<div class="container">
<div class="row">
<div class="col-10">
<span style="display: inline;" class="text-muted">#<?php echo(sprintf("%'.05d\n", $tkt["id"])); ?> </span><span><b><?php echo($tkt['title']); ?></b></span>
<p class="m-0"><?php echo($tkt['description']); ?></p>
</div>
<div class="col-2">
<a class="btn btn-success float-right" href="view?rid=<?php echo($tkt["uuid"]); ?>" role="button">Go</a>
</div>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
<p><?php print_r($request); ?></p>
</div>
</section>
<?php } else if ($is_authorised == false) { ?>
<section class="jumbotron text-center">
<div class="container">
<h1>You are not authorised to see this page.</h1>
</div>
</section>
<?php } } ?>
</main>