From 795940c0f278b7e2ff4ff7b0e328dca480662a1c Mon Sep 17 00:00:00 2001 From: arf20 Date: Wed, 20 Mar 2024 17:31:54 +0100 Subject: Add ticket and ticket management --- managetickets.php | 213 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 213 insertions(+) create mode 100644 managetickets.php (limited to 'managetickets.php') diff --git a/managetickets.php b/managetickets.php new file mode 100644 index 0000000..02c2871 --- /dev/null +++ b/managetickets.php @@ -0,0 +1,213 @@ +fetch_all(MYSQLI_ASSOC); + +// Get services +$sql = "SELECT id, name, type, billing, description FROM services"; +$stmt = mysqli_prepare($link, $sql); +mysqli_stmt_execute($stmt); +$result = mysqli_stmt_get_result($stmt); +$services = $result->fetch_all(MYSQLI_ASSOC); + +// Get orders +$sql = "SELECT id, service, name, client, date, billing, status, comments FROM orders"; +$stmt = mysqli_prepare($link, $sql); +mysqli_stmt_execute($stmt); +$result = mysqli_stmt_get_result($stmt); +$orders = $result->fetch_all(MYSQLI_ASSOC); + +// Get tickets +$sql = "SELECT id, `order`, subject, body, date, status, asignee FROM tickets"; +$stmt = mysqli_prepare($link, $sql); +mysqli_stmt_execute($stmt); +$result = mysqli_stmt_get_result($stmt); +$tickets = $result->fetch_all(MYSQLI_ASSOC); + +// GET actions +// delete entry +if (isset($_GET["del"])) { + $sql = "DELETE FROM tickets WHERE id = ?"; + $stmt = mysqli_prepare($link, $sql); + mysqli_stmt_bind_param($stmt, "s", $param_id); + $param_id = $_GET["del"]; + if (!mysqli_stmt_execute($stmt) || mysqli_stmt_affected_rows($stmt) != 1) { + echo "SQL error."; + } else header("location: ".$_SERVER['SCRIPT_NAME']); +} + +// POST actions +if ($_SERVER["REQUEST_METHOD"] == "POST") { + // add entry + if (isset($_POST["add"])) { + $sql = "INSERT INTO tickets (`order`, subject, body, status, asignee) VALUES (?, ?, ?, ?, ?)"; + $stmt = mysqli_prepare($link, $sql); + mysqli_stmt_bind_param($stmt, "sssss", $param_order, $param_subject, $param_body, $param_status, $param_asignee); + $param_order = $_POST["order"]; + $param_subject = $_POST["subject"]; + $param_body = $_POST["body"]; + $param_status = $_POST["status"]; + $param_asignee = $_POST["asignee"]; + + if (!mysqli_stmt_execute($stmt) || (mysqli_stmt_affected_rows($stmt) != 1)) { + echo "SQL error."; + } else header("location: ".$_SERVER['SCRIPT_NAME']); + } + + // edit entry + if (isset($_POST["save"])) { + $sql = "UPDATE tickets SET status = ?, asignee = ? WHERE id = ?"; + $stmt = mysqli_prepare($link, $sql); + mysqli_stmt_bind_param($stmt, "sss", $param_status, $param_asignee, $param_id); + $param_status = $_POST["status"]; + $param_asignee = $_POST["asignee"]; + $param_id = $_POST["id"]; + + if (!mysqli_stmt_execute($stmt) || (mysqli_stmt_affected_rows($stmt) != 1)) { + echo "SQL error."; + } else header("location: ".$_SERVER['SCRIPT_NAME']); + } +} + +function getticketbyid($id) { + global $tickets; + foreach ($tickets as $ticket) { + if ($ticket["id"] == $id) { + return $ticket; + } + } +} + +function getorderbyid($id) { + global $orders; + foreach ($orders as $order) { + if ($order["id"] == $id) { + return $order; + } + } +} + +function getservicebyid($id) { + global $services; + foreach ($services as $service) { + if ($service["id"] == $id) { + return $service; + } + } +} + +function getuserbyid($id) { + global $users; + foreach ($users as $user) { + if ($user["id"] == $id) { + return $user; + } + } +} + +?> + + + + + + + ARFNET CSTIMS + + +
+ ARFNET +
+
+
+
+
+

ARFNET Client Service Ticket and Invoice Management System

+

panel

+

Tickets

+ ".$user["username"].""; + echo "

Edit ticket ".$ticket["id"]."

\n" + ."

\n" + ."

\n" + ."

\n" + ."

\n" + ."
".$ticket["body"]."

\n" + ."

\n" + ."

\n" + ."" + ."
cancel" + ."
"; + } + + if (isset($_GET["add"])) { + $order_options = $asignee_options = ""; + foreach ($orders as $order) + $order_options .= ""; + foreach ($users as $user) + if ($user["type"] == "admin" || $user["type"] == "helpdesk") + $asignee_options .= ""; + echo "

Add ticket

\n" + ."

" + ."

\n" + ."

\n" + ."

\n" + ."

\n" + ."
cancel" + ."
"; + } + ?> + + add + + + " + ."" + ."" + ."" + ."" + ."" + ."" + ."" + ."\n"; + } + ?> +
idorderserviceclientsubjectbodystatusasigneeaction
".$ticket["id"]."".$order["name"]."".getservicebyid($order["service"])["name"]."".getuserbyid(getorderbyid($ticket["order"])["client"])["username"]."".$ticket["subject"]."
".$ticket["body"]."
".$ticket["status"]."".getuserbyid($ticket["asignee"])["username"]."del edit
+ +
+ +
+
+ + + -- cgit v1.2.3