Files
itflow/admin/post/ticket_template.php
johnnyq bbb2456f0b Projects modernization: projects list with Active/Mine/Overdue/Due soon/Stalled/Over budget/Ready to close/Completed/Archived/All views, ticket and task progress bars, time logged against budget with unbilled hours, due badges, manager changed in place, manager/client/created filters, bulk set manager, set due date, complete, reopen, archive, restore and delete, CSV/PDF export; project page with header actions, attention banners, tickets/tasks/time/due stat cards, Tickets/Tasks/Activity tabs, scope, details and team with hours; project quick look; New/Edit Project with client contact, start date, budget hours and template that can assign its tickets to the manager; Add tickets by picking or by number; add a project template's tickets to an existing project; template ticket subjects fill in [Client], [Project], [Month], [Quarter] and [Year]; project templates admin rework with ordered ticket templates, multi-add, duplicate, archive and restore; projects on the ticket page, client overview, dashboard, calendar, global search and client actions menu; New Ticket offers internal projects; tickets only join a project of their own client or an internal one; completing a project is checked on the server and completed projects can be reopened; deleting a project keeps its tickets; deleting a client deletes its projects; bulk ticket creation limits project choices to matching clients; project template reordering limited to admins; new manager notifications; new functions/project.php; removed project_link_closed_ticket.php; DB 2.8.6 adds project_start, project_budget_hours, project_contact_id and a ticket_project_id index, and cleans up orphaned projects, ticket project links and template links
2026-10-15 16:35:00 -04:00

121 lines
4.8 KiB
PHP

<?php
// Ticket Templates
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
// Import shared code from user-side tickets/tasks as we reuse functions
require_once '../agent/post/ticket.php';
require_once '../agent/post/task.php';
if (isset($_POST['add_ticket_template'])) {
validateCSRFToken();
$name = escapeSql($_POST['name']);
$description = escapeSql($_POST['description']);
$subject = escapeSql($_POST['subject']);
$details = mysqli_real_escape_string($mysqli, $_POST['details']);
$project_template_id = intval($_POST['project_template']);
mysqli_query($mysqli, "INSERT INTO ticket_templates SET ticket_template_name = '$name', ticket_template_description = '$description', ticket_template_subject = '$subject', ticket_template_details = '$details'");
$ticket_template_id = mysqli_insert_id($mysqli);
// At the end of the project template's tickets
if ($project_template_id && mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM project_templates WHERE project_template_id = $project_template_id"))) {
$order = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COALESCE(MAX(ticket_template_order), 0) + 1 FROM project_template_ticket_templates WHERE project_template_id = $project_template_id"))[0]);
mysqli_query($mysqli, "INSERT INTO project_template_ticket_templates SET project_template_id = $project_template_id, ticket_template_id = $ticket_template_id, ticket_template_order = $order");
}
logAudit("Ticket Template", "Create", "$session_name created ticket template $name", 0, $ticket_template_id);
flashAlert("Ticket Template <strong>$name</strong> created");
redirect();
}
if (isset($_POST['edit_ticket_template'])) {
validateCSRFToken();
$ticket_template_id = intval($_POST['ticket_template_id']);
$name = escapeSql($_POST['name']);
$description = escapeSql($_POST['description']);
$subject = escapeSql($_POST['subject']);
$details = mysqli_real_escape_string($mysqli, $_POST['details']);
mysqli_query($mysqli, "UPDATE ticket_templates SET ticket_template_name = '$name', ticket_template_description = '$description', ticket_template_subject = '$subject', ticket_template_details = '$details' WHERE ticket_template_id = $ticket_template_id");
logAudit("Ticket Template", "Edit", "$session_name edited ticket template $name", 0, $ticket_template_id);
flashAlert("Ticket Template <strong>$name</strong> edited");
redirect();
}
if (isset($_GET['delete_ticket_template'])) {
validateCSRFToken();
$ticket_template_id = intval($_GET['delete_ticket_template']);
$ticket_template_name = escapeSql(getFieldById('ticket_templates', $ticket_template_id, 'ticket_template_name'));
mysqli_query($mysqli, "DELETE FROM ticket_templates WHERE ticket_template_id = $ticket_template_id");
// Delete Associations
mysqli_query($mysqli, "DELETE FROM task_templates WHERE task_template_ticket_template_id = $ticket_template_id");
mysqli_query($mysqli, "DELETE FROM project_template_ticket_templates WHERE ticket_template_id = $ticket_template_id");
// Unlink from recurring tickets rather than deleting them - the schedule is still
// wanted, it just stops contributing tasks to the tickets it raises
mysqli_query($mysqli, "UPDATE recurring_tickets SET recurring_ticket_ticket_template_id = 0 WHERE recurring_ticket_ticket_template_id = $ticket_template_id");
logAudit("Ticket Template", "Delete", "$session_name deleted ticket template $ticket_template_name");
flashAlert("Ticket Template <strong>$ticket_template_name</strong> and its associated tasks deleted", 'error');
redirect();
}
if (isset($_POST['add_ticket_template_task'])) {
validateCSRFToken();
$ticket_template_id = intval($_POST['ticket_template_id']);
$task_name = escapeSql($_POST['task_name']);
mysqli_query($mysqli, "INSERT INTO task_templates SET task_template_name = '$task_name', task_template_ticket_template_id = $ticket_template_id");
$task_template_id = mysqli_insert_id($mysqli);
logAudit("Ticket Template", "Create", "$session_name created task $task_name for ticket template", 0, $ticket_template_id);
flashAlert("Added Task <strong>$task_name</strong>");
redirect();
}
if (isset($_GET['delete_task_template'])) {
validateCSRFToken();
$task_template_id = intval($_GET['delete_task_template']);
$task_template_name = escapeSql(getFieldById('task_templates', $task_template_id, 'task_template_name'));
mysqli_query($mysqli, "DELETE FROM task_templates WHERE task_template_id = $task_template_id");
logAudit("Ticket Template", "Edit", "$session_name deleted task $task_template_name from ticket template");
flashAlert("Task <strong>$task_template_name</strong> deleted", 'error');
redirect();
}