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 --- dbinit.sql | 13 +++- managetickets.php | 213 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ openticket.php | 189 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 414 insertions(+), 1 deletion(-) create mode 100644 managetickets.php create mode 100644 openticket.php diff --git a/dbinit.sql b/dbinit.sql index b505dbc..017f60a 100644 --- a/dbinit.sql +++ b/dbinit.sql @@ -28,7 +28,18 @@ CREATE TABLE `arfnet2`.`orders` ( `client` INT NOT NULL , `billing` VARCHAR(255) NOT NULL , `date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP , - `status` ENUM('setting up','active','inactive') NOT NULL , + `status` ENUM('setting up','active','inactive') NOT NULL DEFAULT 'setting up' , `comments` TEXT NOT NULL , PRIMARY KEY (`id`) ); + +CREATE TABLE `arfnet2`.`tickets` ( + `id` INT NOT NULL AUTO_INCREMENT , + `order` INT NOT NULL , + `subject` VARCHAR(255) NOT NULL , + `body` TEXT NOT NULL , + `date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP , + `status` ENUM('open','closed') NOT NULL DEFAULT 'open' , + `asignee` INT NOT NULL , + PRIMARY KEY (`id`) +); 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
+ +
+ +
+
+ + + diff --git a/openticket.php b/openticket.php new file mode 100644 index 0000000..4448f7b --- /dev/null +++ b/openticket.php @@ -0,0 +1,189 @@ +fetch_all(MYSQLI_ASSOC); + +// POST actions +if ($_SERVER["REQUEST_METHOD"] == "POST") { + // add entry + $sql = "INSERT INTO orders (service, name, client, billing, comments) VALUES (?, ?, ?, ?, ?)"; + $stmt = mysqli_prepare($link, $sql); + mysqli_stmt_bind_param($stmt, "sssss", $param_service, $param_name, $param_client, $param_billing, $param_comments); + $param_service = $_POST["service"]; + $param_name = $_POST["name"]; + $param_client = $clientid; + $param_billing = $_POST["billing"]; + $param_comments = $_POST["comments"]; + + if (!mysqli_stmt_execute($stmt) || (mysqli_stmt_affected_rows($stmt) != 1)) { + echo "SQL error."; + } else { + // send admin mail + // Get admin mails + $sql = "SELECT email FROM users WHERE type = 'admin'"; + $stmt = mysqli_prepare($link, $sql); + mysqli_stmt_execute($stmt); + $result = mysqli_stmt_get_result($stmt); + $admins = $result->fetch_all(MYSQLI_ASSOC); + + foreach ($admins as $admin) { + $mailer->addAddress($admin["email"]); + } + + $mailer->Subject = "New service order request"; + $mailer->Body = "Admins,\n\nUser $username requested service ".getservicebyid($_POST["service"])["name"]."\n\n" + ."Instance name: ".$_POST["name"]."\n" + ."Calculated billing: ".$_POST["billing"]."\n" + ."Comments:\n" + .$_POST["comments"] + ."\n\n--\nARFNET Client, Service, Ticket and Invoice Management System\nhttps://arf20.com"; + if (!$mailer->send()) { + echo 'Mailer Error [ask arf20]: ' . $mailer->ErrorInfo; + } else header("location: ".$_SERVER['SCRIPT_NAME']); + } +} + +function getservicebyid($id) { + global $services; + foreach ($services as $service) { + if ($service["id"] == $id) { + return $service; + } + } +} + +function genoption($id, $name) { + return "" + ."
\n"; +} + +?> + + + + + + + ARFNET CSTIMS + + + +
+ ARFNET +
+
+
+
+
+

ARFNET Client Service Ticket and Invoice Management System

+

panel

+
+

Order a new service

+
+
+
+
+
+
+
+
+
+
+
+
+

+                            
+
+

+
+
+

+
+
+ + +
+
+
+
+ +
+
+ + -- cgit v1.2.3