mirror of
https://github.com/itflow-org/itflow
synced 2026-12-02 00:59:03 +00:00
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
This commit is contained in:
27
admin/database_updates/2.8.6.php
Normal file
27
admin/database_updates/2.8.6.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* ITFlow - Database update to version 2.8.6 (from 2.8.5)
|
||||
* Included by admin/database_updates.php - do not access directly
|
||||
*/
|
||||
|
||||
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
|
||||
|
||||
// Projects: when the work starts, the hours sold for it, and who signs it off at the client
|
||||
mysqli_query($mysqli, "ALTER TABLE `projects` ADD COLUMN `project_start` date DEFAULT NULL AFTER `project_description`");
|
||||
mysqli_query($mysqli, "ALTER TABLE `projects` ADD COLUMN `project_budget_hours` decimal(8,2) DEFAULT NULL AFTER `project_due`");
|
||||
mysqli_query($mysqli, "ALTER TABLE `projects` ADD COLUMN `project_contact_id` int(11) NOT NULL DEFAULT 0 AFTER `project_manager`");
|
||||
|
||||
// A project's tickets are looked up by project on every projects page
|
||||
mysqli_query($mysqli, "ALTER TABLE `tickets` ADD INDEX `ticket_project_id` (`ticket_project_id`)");
|
||||
|
||||
// Deleting a client left its projects behind, and deleting a project left
|
||||
// its tickets pointing at it - clear out both
|
||||
mysqli_query($mysqli, "DELETE `projects` FROM `projects` LEFT JOIN `clients` ON `client_id` = `project_client_id` WHERE `project_client_id` > 0 AND `client_id` IS NULL");
|
||||
mysqli_query($mysqli, "UPDATE `tickets` LEFT JOIN `projects` ON `project_id` = `ticket_project_id` SET `ticket_project_id` = 0 WHERE `ticket_project_id` > 0 AND `project_id` IS NULL");
|
||||
|
||||
// A project template's ticket templates whose template is gone
|
||||
mysqli_query($mysqli, "DELETE `project_template_ticket_templates` FROM `project_template_ticket_templates`
|
||||
LEFT JOIN `project_templates` ON `project_templates`.`project_template_id` = `project_template_ticket_templates`.`project_template_id`
|
||||
LEFT JOIN `ticket_templates` ON `ticket_templates`.`ticket_template_id` = `project_template_ticket_templates`.`ticket_template_id`
|
||||
WHERE `project_templates`.`project_template_id` IS NULL OR `ticket_templates`.`ticket_template_id` IS NULL");
|
||||
@@ -6,7 +6,7 @@ ob_start();
|
||||
|
||||
?>
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fas fa-fw fa-project-diagram me-2"></i>Creating Project Template</h5>
|
||||
<h5 class="modal-title"><i class="fas fa-fw fa-cubes me-2"></i>New Project Template</h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
@@ -14,21 +14,15 @@ ob_start();
|
||||
|
||||
<div class="modal-body">
|
||||
<div class="mb-3">
|
||||
<label>Project Template Name <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-project-diagram"></i></span>
|
||||
<input type="text" class="form-control" name="name" placeholder="Project Template Name" maxlength="255" required autofocus>
|
||||
</div>
|
||||
<label class="form-label">Name <strong class="text-danger">*</strong></label>
|
||||
<input type="text" class="form-control" name="name" placeholder="Client onboarding, server refresh, office move..." maxlength="200" required autofocus>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Description</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-angle-right"></i></span>
|
||||
<input type="text" class="form-control" name="description" placeholder="Description">
|
||||
</div>
|
||||
<div class="mb-0">
|
||||
<label class="form-label">Description</label>
|
||||
<textarea class="form-control" name="description" rows="3" placeholder="When to use it"></textarea>
|
||||
<div class="form-text">Next, add its ticket templates - one per step of the work.</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="add_project_template" class="btn btn-primary text-bold"><i class="fas fa-check me-2"></i>Create</button>
|
||||
|
||||
@@ -2,19 +2,20 @@
|
||||
|
||||
require_once '../../includes/modal_header.php';
|
||||
|
||||
$project_template_id = intval($_GET['project_template_id']);
|
||||
$project_template_id = intval($_GET['project_template_id'] ?? 0);
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT project_template_description, project_template_name FROM project_templates WHERE project_template_id = $project_template_id LIMIT 1");
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$project_template_name = escapeHtml($row['project_template_name']);
|
||||
$project_template_description = escapeHtml($row['project_template_description']);
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT project_template_description, project_template_name FROM project_templates WHERE project_template_id = $project_template_id LIMIT 1"));
|
||||
if (!$row) {
|
||||
echo json_encode(['error' => 'That project template no longer exists.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fas fa-fw fa-project-diagram me-2"></i>Editing Project Template: <strong><?= $project_template_name ?></strong></h5>
|
||||
<h5 class="modal-title text-truncate"><i class="fas fa-fw fa-cubes me-2"></i>Edit Project Template <small class="ms-1 opacity-75"><?= escapeHtml($row['project_template_name']) ?></small></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
@@ -23,21 +24,14 @@ ob_start();
|
||||
|
||||
<div class="modal-body">
|
||||
<div class="mb-3">
|
||||
<label>Project Template Name <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-project-diagram"></i></span>
|
||||
<input type="text" class="form-control" name="name" placeholder="Project Template Name" maxlength="255" value="<?= $project_template_name ?>" required autofocus>
|
||||
</div>
|
||||
<label class="form-label">Name <strong class="text-danger">*</strong></label>
|
||||
<input type="text" class="form-control" name="name" maxlength="200" value="<?= escapeHtml($row['project_template_name']) ?>" required autofocus>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Description</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-angle-right"></i></span>
|
||||
<input type="text" class="form-control" name="description" placeholder="Description" value="<?= $project_template_description ?>">
|
||||
</div>
|
||||
<div class="mb-0">
|
||||
<label class="form-label">Description</label>
|
||||
<textarea class="form-control" name="description" rows="3" placeholder="When to use it"><?= escapeHtml($row['project_template_description']) ?></textarea>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
|
||||
@@ -1,15 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Add ticket templates to a project template - any number at once, at the
|
||||
* end of its list in the order picked.
|
||||
*/
|
||||
|
||||
require_once '../../includes/modal_header.php';
|
||||
|
||||
$project_template_id = intval($_GET['project_template_id']);
|
||||
$project_template_id = intval($_GET['project_template_id'] ?? 0);
|
||||
$name = getFieldById('project_templates', $project_template_id, 'project_template_name');
|
||||
if ($name === null || $name === '') {
|
||||
echo json_encode(['error' => 'That project template no longer exists.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT ticket_template_id, ticket_template_name, ticket_template_subject,
|
||||
(SELECT COUNT(*) FROM task_templates WHERE task_template_ticket_template_id = ticket_template_id) AS task_count
|
||||
FROM ticket_templates
|
||||
WHERE ticket_template_id NOT IN (SELECT ticket_template_id FROM project_template_ticket_templates WHERE project_template_id = $project_template_id)
|
||||
AND ticket_template_archived_at IS NULL
|
||||
ORDER BY ticket_template_name ASC");
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fas fa-fw fa-life-ring me-2"></i>Adding Ticket Template</h5>
|
||||
<h5 class="modal-title text-truncate"><i class="fas fa-fw fa-life-ring me-2"></i>Add ticket templates <small class="ms-1 opacity-75"><?= escapeHtml($name) ?></small></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
@@ -17,44 +34,19 @@ ob_start();
|
||||
<input type="hidden" name="project_template_id" value="<?= $project_template_id ?>">
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Ticket Template <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-life-ring"></i></span>
|
||||
<select class="form-select select2" name="ticket_template_id" required>
|
||||
<option value="">- Select a Ticket Template -</option>
|
||||
<?php
|
||||
|
||||
$sql_ticket_templates_select = mysqli_query($mysqli, "SELECT ticket_template_id, ticket_template_name FROM ticket_templates
|
||||
WHERE ticket_template_id NOT IN (
|
||||
SELECT ticket_template_id FROM project_template_ticket_templates
|
||||
WHERE project_template_id = $project_template_id
|
||||
)
|
||||
AND ticket_template_archived_at IS NULL
|
||||
ORDER BY ticket_template_name ASC"
|
||||
);
|
||||
while ($row = mysqli_fetch_assoc($sql_ticket_templates_select)) {
|
||||
$ticket_template_id_select = intval($row['ticket_template_id']);
|
||||
$ticket_template_name_select = escapeHtml($row['ticket_template_name']);
|
||||
?>
|
||||
<option value="<?= $ticket_template_id_select ?>"><?= $ticket_template_name_select ?></option>
|
||||
<?php
|
||||
}
|
||||
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Order</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-sort-numeric-down"></i></span>
|
||||
<input type="text" class="form-control" name="order" value="1">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (mysqli_num_rows($sql)) { ?>
|
||||
<label class="form-label">Ticket templates <strong class="text-danger">*</strong></label>
|
||||
<select class="form-select select2" name="ticket_template_ids[]" multiple required data-placeholder="Pick ticket templates...">
|
||||
<?php while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$task_count = intval($row['task_count']); ?>
|
||||
<option value="<?= intval($row['ticket_template_id']) ?>" data-icon="fas fa-life-ring"
|
||||
data-description="<?= escapeHtml(trim(($task_count ? "$task_count task" . ($task_count === 1 ? '' : 's') : 'No tasks') . ($row['ticket_template_subject'] ? ' - ' . $row['ticket_template_subject'] : ''))) ?>"><?= escapeHtml($row['ticket_template_name']) ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
<div class="form-text">They go at the end, in the order picked - drag them about on the template afterwards.</div>
|
||||
<?php } else { ?>
|
||||
<div class="text-body-secondary">Every ticket template is in it already. Make more under <a href="ticket_templates.php">Ticket Templates</a>.</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
|
||||
@@ -1529,7 +1529,7 @@ function demoBuildClient($mysqli, $profile, $index, $context, &$counts) {
|
||||
}
|
||||
|
||||
// Support and billing
|
||||
$projects = demoBuildProjects($mysqli, $profile, $index, $client_id, $months, $counts);
|
||||
$projects = demoBuildProjects($mysqli, $profile, $index, $client_id, $months, $counts, $primary_contact_id);
|
||||
demoBuildTickets($mysqli, $profile, $index, $client_id, $contact_ids, $assets, $primary_location_id, $projects, $vendor_ids, $months, $context, $counts);
|
||||
demoBuildBilling($mysqli, $profile, $index, $client_id, $primary_vendor_id, $months, $context, $counts);
|
||||
|
||||
@@ -2048,7 +2048,7 @@ function demoBuildNetworkIps($mysqli, $profile, $assets, $network_ids, &$counts)
|
||||
// actually arrives at an MSP, and it is what the per asset onboarding tickets
|
||||
// hang off. A refresh project sits behind them, and some have work running now.
|
||||
// ------------------------------
|
||||
function demoBuildProjects($mysqli, $profile, $index, $client_id, $months, &$counts) {
|
||||
function demoBuildProjects($mysqli, $profile, $index, $client_id, $months, &$counts, $contact_id = 0) {
|
||||
|
||||
global $config_project_prefix;
|
||||
|
||||
@@ -2062,8 +2062,11 @@ function demoBuildProjects($mysqli, $profile, $index, $client_id, $months, &$cou
|
||||
'project_number' => demoNextNumber($mysqli, 'config_project_next_number'),
|
||||
'project_name' => 'Onboarding - ' . $profile['name'],
|
||||
'project_description' => 'Take on ' . $profile['name'] . ': document the environment, deploy monitoring and backup, capture credentials, standardise the endpoint build and hand over to the service desk.',
|
||||
'project_start' => demoMonthDate($months, 3),
|
||||
'project_due' => demoMonthDate(max(0, $months - 1), 28),
|
||||
'project_budget_hours' => 16 + ($index % 3) * 8,
|
||||
'project_manager' => $user_id,
|
||||
'project_contact_id' => intval($contact_id),
|
||||
'project_client_id' => $client_id,
|
||||
'project_created_at' => demoMonthDateTime($months, 3, 9, 30),
|
||||
'project_completed_at' => demoMonthDateTime(max(0, $months - 1), 26, 16, 0),
|
||||
@@ -2077,8 +2080,11 @@ function demoBuildProjects($mysqli, $profile, $index, $client_id, $months, &$cou
|
||||
'project_number' => demoNextNumber($mysqli, 'config_project_next_number'),
|
||||
'project_name' => 'Server and network refresh',
|
||||
'project_description' => 'Replaced end of life server hardware, rebuilt the switching and brought the site onto the standard build.',
|
||||
'project_start' => demoMonthDate(15, 4),
|
||||
'project_due' => demoMonthDate(13, 20),
|
||||
'project_budget_hours' => 40,
|
||||
'project_manager' => $user_id,
|
||||
'project_contact_id' => intval($contact_id),
|
||||
'project_client_id' => $client_id,
|
||||
'project_created_at' => demoMonthDateTime(15, 4, 9, 30),
|
||||
'project_completed_at' => demoMonthDateTime(13, 18, 16, 45),
|
||||
@@ -2086,15 +2092,25 @@ function demoBuildProjects($mysqli, $profile, $index, $client_id, $months, &$cou
|
||||
$counts['projects']++;
|
||||
}
|
||||
|
||||
// And whatever is running now
|
||||
// And whatever is running now - one running late, one due soon, one not
|
||||
// started yet and one with time in hand, so the projects list has some of each
|
||||
if (!empty($profile['project'])) {
|
||||
$timing = [
|
||||
['start' => date('Y-m-d', strtotime('-45 days')), 'due' => date('Y-m-d', strtotime('-6 days'))],
|
||||
['start' => date('Y-m-d', strtotime('-30 days')), 'due' => date('Y-m-d', strtotime('+9 days'))],
|
||||
['start' => date('Y-m-d', strtotime('+14 days')), 'due' => date('Y-m-d', strtotime('+75 days'))],
|
||||
['start' => demoMonthDate(1, 8), 'due' => demoMonthDate(-2, 15)],
|
||||
][$index % 4];
|
||||
$projects['active'] = starterInsert($mysqli, 'projects', [
|
||||
'project_prefix' => $prefix,
|
||||
'project_number' => demoNextNumber($mysqli, 'config_project_next_number'),
|
||||
'project_name' => $profile['project'][0],
|
||||
'project_description' => $profile['project'][1],
|
||||
'project_due' => demoMonthDate(-2, 15),
|
||||
'project_start' => $timing['start'],
|
||||
'project_due' => $timing['due'],
|
||||
'project_budget_hours' => [12, 24, 32, 40][$index % 4],
|
||||
'project_manager' => $user_id,
|
||||
'project_contact_id' => intval($contact_id),
|
||||
'project_client_id' => $client_id,
|
||||
'project_created_at' => demoMonthDateTime(1, 8, 10, 0),
|
||||
]);
|
||||
|
||||
@@ -1,13 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* ITFlow - admin handlers for project templates: an ordered set of ticket
|
||||
* templates a new project can raise (functions/project.php,
|
||||
* projectApplyTemplate()).
|
||||
*/
|
||||
|
||||
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
|
||||
|
||||
/** A project template by id - its name, or back with an error when it is gone. */
|
||||
function projectTemplateName($project_template_id) {
|
||||
$name = getFieldById('project_templates', intval($project_template_id), 'project_template_name');
|
||||
if ($name === null || $name === '') {
|
||||
flashAlert('That project template no longer exists.', 'error');
|
||||
redirect('project_templates.php');
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
|
||||
if (isset($_POST['add_project_template'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$name = escapeSql($_POST['name']);
|
||||
$description = escapeSql($_POST['description']);
|
||||
$name_input = trim((string) ($_POST['name'] ?? ''));
|
||||
if ($name_input === '') {
|
||||
flashAlert('A project template needs a name.', 'error');
|
||||
redirect();
|
||||
}
|
||||
$name = escapeSql(mb_substr($name_input, 0, 200));
|
||||
$description = escapeSql(trim((string) ($_POST['description'] ?? '')));
|
||||
|
||||
mysqli_query($mysqli, "INSERT INTO project_templates SET project_template_name = '$name', project_template_description = '$description'");
|
||||
|
||||
@@ -15,9 +36,9 @@ if (isset($_POST['add_project_template'])) {
|
||||
|
||||
logAudit("Project Template", "Create", "$session_name created project template $name", 0, $project_template_id);
|
||||
|
||||
flashAlert("Project Template <strong>$name</strong> created");
|
||||
flashAlert("Project template <strong>" . escapeHtml($name_input) . "</strong> created - now add its ticket templates");
|
||||
|
||||
redirect();
|
||||
redirect("project_template.php?project_template_id=$project_template_id");
|
||||
|
||||
}
|
||||
|
||||
@@ -25,15 +46,22 @@ if (isset($_POST['edit_project_template'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$project_template_id = intval($_POST['project_template_id']);
|
||||
$name = escapeSql($_POST['name']);
|
||||
$description = escapeSql($_POST['description']);
|
||||
$project_template_id = intval($_POST['project_template_id'] ?? 0);
|
||||
projectTemplateName($project_template_id);
|
||||
|
||||
$name_input = trim((string) ($_POST['name'] ?? ''));
|
||||
if ($name_input === '') {
|
||||
flashAlert('A project template needs a name.', 'error');
|
||||
redirect();
|
||||
}
|
||||
$name = escapeSql(mb_substr($name_input, 0, 200));
|
||||
$description = escapeSql(trim((string) ($_POST['description'] ?? '')));
|
||||
|
||||
mysqli_query($mysqli, "UPDATE project_templates SET project_template_name = '$name', project_template_description = '$description' WHERE project_template_id = $project_template_id");
|
||||
|
||||
logAudit("Project Template", "Edit", "$session_name edited project template $name", 0, $project_template_id);
|
||||
|
||||
flashAlert("Project Template <strong>$name</strong> edited");
|
||||
flashAlert("Project template <strong>" . escapeHtml($name_input) . "</strong> saved");
|
||||
|
||||
redirect();
|
||||
|
||||
@@ -53,19 +81,34 @@ if (isset($_POST['edit_ticket_template_order'])) {
|
||||
|
||||
}
|
||||
|
||||
/** Ticket templates into a project template - at the end, in the order picked. */
|
||||
if (isset($_POST['add_ticket_template_to_project_template'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$project_template_id = intval($_POST['project_template_id']);
|
||||
$ticket_template_id = intval($_POST['ticket_template_id']);
|
||||
$order = intval($_POST['order']);
|
||||
$project_template_id = intval($_POST['project_template_id'] ?? 0);
|
||||
$name = escapeSql(projectTemplateName($project_template_id));
|
||||
|
||||
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");
|
||||
// ticket_template_id is what the single-pick form posted
|
||||
$ids = array_map('intval', (array) ($_POST['ticket_template_ids'] ?? []));
|
||||
if (isset($_POST['ticket_template_id'])) {
|
||||
$ids[] = intval($_POST['ticket_template_id']);
|
||||
}
|
||||
|
||||
logAudit("Project Template", "Edit", "$session_name added ticket template to project_template", 0, $project_template_id);
|
||||
$order = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COALESCE(MAX(ticket_template_order), 0) FROM project_template_ticket_templates WHERE project_template_id = $project_template_id"))[0]);
|
||||
$added = 0;
|
||||
foreach (array_unique(array_filter($ids)) as $ticket_template_id) {
|
||||
if (!mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM ticket_templates WHERE ticket_template_id = $ticket_template_id"))) {
|
||||
continue;
|
||||
}
|
||||
$order++;
|
||||
mysqli_query($mysqli, "INSERT IGNORE INTO project_template_ticket_templates SET project_template_id = $project_template_id, ticket_template_id = $ticket_template_id, ticket_template_order = $order");
|
||||
$added += mysqli_affected_rows($mysqli) > 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
flashAlert("Ticket template added");
|
||||
logAudit("Project Template", "Edit", "$session_name added $added ticket template" . ($added === 1 ? '' : 's') . " to project template $name", 0, $project_template_id);
|
||||
|
||||
flashAlert("<strong>$added</strong> ticket template" . ($added === 1 ? '' : 's') . " added");
|
||||
|
||||
redirect();
|
||||
|
||||
@@ -75,36 +118,76 @@ if (isset($_POST['remove_ticket_template_from_project_template'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$ticket_template_id = intval($_POST['ticket_template_id']);
|
||||
$project_template_id = intval($_POST['project_template_id']);
|
||||
$ticket_template_id = intval($_POST['ticket_template_id'] ?? 0);
|
||||
$project_template_id = intval($_POST['project_template_id'] ?? 0);
|
||||
$name = escapeSql(projectTemplateName($project_template_id));
|
||||
|
||||
mysqli_query($mysqli, "DELETE FROM project_template_ticket_templates WHERE project_template_id = $project_template_id AND ticket_template_id = $ticket_template_id");
|
||||
|
||||
logAudit("Project Template", "Edit", "$session_name removed ticket template from project template", 0, $project_template_id);
|
||||
logAudit("Project Template", "Edit", "$session_name removed a ticket template from project template $name", 0, $project_template_id);
|
||||
|
||||
flashAlert("Ticket template removed", 'error');
|
||||
flashAlert("Ticket template taken out of the project template", 'error');
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_GET['archive_project_template']) || isset($_GET['restore_project_template'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$archive = isset($_GET['archive_project_template']);
|
||||
$project_template_id = intval($archive ? $_GET['archive_project_template'] : $_GET['restore_project_template']);
|
||||
$name = projectTemplateName($project_template_id);
|
||||
|
||||
mysqli_query($mysqli, "UPDATE project_templates SET project_template_archived_at = " . ($archive ? 'NOW()' : 'NULL') . " WHERE project_template_id = $project_template_id");
|
||||
|
||||
logAudit("Project Template", $archive ? "Archive" : "Restore", "$session_name " . ($archive ? 'archived' : 'restored') . " project template " . escapeSql($name), 0, $project_template_id);
|
||||
|
||||
flashAlert("Project template <strong>" . escapeHtml($name) . "</strong> " . ($archive ? 'archived - it is no longer offered on New Project' : 'restored'), $archive ? 'error' : 'success');
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
/** A copy, with the same ticket templates in the same order - for a variation on a plan. */
|
||||
if (isset($_GET['duplicate_project_template'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$project_template_id = intval($_GET['duplicate_project_template']);
|
||||
$name = projectTemplateName($project_template_id);
|
||||
$copy_name = escapeSql(mb_substr("$name (copy)", 0, 200));
|
||||
|
||||
mysqli_query($mysqli, "INSERT INTO project_templates (project_template_name, project_template_description)
|
||||
SELECT '$copy_name', project_template_description FROM project_templates WHERE project_template_id = $project_template_id");
|
||||
$copy_id = mysqli_insert_id($mysqli);
|
||||
mysqli_query($mysqli, "INSERT INTO project_template_ticket_templates (project_template_id, ticket_template_id, ticket_template_order)
|
||||
SELECT $copy_id, ticket_template_id, ticket_template_order FROM project_template_ticket_templates WHERE project_template_id = $project_template_id");
|
||||
|
||||
logAudit("Project Template", "Create", "$session_name duplicated project template " . escapeSql($name), 0, $copy_id);
|
||||
|
||||
flashAlert("Project template <strong>" . escapeHtml($name) . "</strong> duplicated");
|
||||
|
||||
redirect("project_template.php?project_template_id=$copy_id");
|
||||
|
||||
}
|
||||
|
||||
if (isset($_GET['delete_project_template'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$project_template_id = intval($_GET['delete_project_template']);
|
||||
|
||||
$project_template_name = escapeSql(getFieldById('project_templates', $project_template_id, 'project_template_name'));
|
||||
$name = projectTemplateName($project_template_id);
|
||||
|
||||
mysqli_query($mysqli, "DELETE FROM project_templates WHERE project_template_id = $project_template_id");
|
||||
|
||||
// Remove Associated Ticket Templates
|
||||
mysqli_query($mysqli, "DELETE FROM project_template_ticket_templates WHERE project_template_id = $project_template_id");
|
||||
|
||||
logAudit("Project Template", "Delete", "$session_name deleted project template $project_template_name and its associated ticket templates and tasks");
|
||||
logAudit("Project Template", "Delete", "$session_name deleted project template " . escapeSql($name), 0, $project_template_id);
|
||||
|
||||
flashAlert("Project Template <strong>$project_template_name</strong> and its associated ticket templates and tasks deleted", 'error');
|
||||
flashAlert("Project template <strong>" . escapeHtml($name) . "</strong> deleted - its ticket templates stay", 'error');
|
||||
|
||||
redirect();
|
||||
// Its own page is gone
|
||||
redirect(strpos((string) ($_SERVER['HTTP_REFERER'] ?? ''), 'project_template.php') !== false ? 'project_templates.php' : null);
|
||||
|
||||
}
|
||||
|
||||
@@ -22,8 +22,10 @@ if (isset($_POST['add_ticket_template'])) {
|
||||
|
||||
$ticket_template_id = mysqli_insert_id($mysqli);
|
||||
|
||||
if($project_template_id) {
|
||||
mysqli_query($mysqli, "INSERT INTO project_template_ticket_templates SET project_template_id = $project_template_id, ticket_template_id = $ticket_template_id");
|
||||
// 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);
|
||||
|
||||
@@ -1,248 +1,191 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* A project template - its ticket templates in the order a new project
|
||||
* raises them (drag to change it), each with its tasks.
|
||||
*/
|
||||
|
||||
require_once "includes/inc_all_admin.php";
|
||||
|
||||
$project_template_id = intval($_GET['project_template_id'] ?? 0);
|
||||
|
||||
if (isset($_GET['project_template_id'])) {
|
||||
$project_template_id = intval($_GET['project_template_id']);
|
||||
$template = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT project_template_name, project_template_description, project_template_created_at,
|
||||
project_template_updated_at, project_template_archived_at FROM project_templates
|
||||
WHERE project_template_id = $project_template_id LIMIT 1"));
|
||||
|
||||
$sql_project_templates = mysqli_query(
|
||||
$mysqli,
|
||||
"SELECT project_template_created_at, project_template_description, project_template_name,
|
||||
project_template_updated_at FROM project_templates
|
||||
WHERE project_template_id = $project_template_id LIMIT 1"
|
||||
);
|
||||
if (!$template) { ?>
|
||||
<div class="text-center mt-5">
|
||||
<h1 class="h3 text-secondary">Nothing to see here</h1>
|
||||
<a class="btn btn-secondary mt-3" href="project_templates.php"><i class="fa fa-fw fa-arrow-left me-2"></i>Project templates</a>
|
||||
</div>
|
||||
<?php
|
||||
require_once "../includes/footer.php";
|
||||
exit;
|
||||
}
|
||||
|
||||
if (mysqli_num_rows($sql_project_templates) == 0) {
|
||||
echo "<center><h1 class='text-secondary mt-5'>Nothing to see here</h1><a class='btn btn-lg btn-secondary mt-3' href='javascript:history.back()'><i class='fa fa-fw fa-arrow-left'></i> Go Back</a></center>";
|
||||
|
||||
require_once "../includes/footer.php";
|
||||
exit;
|
||||
// Its ticket templates in order, then all their tasks in one go
|
||||
$sql = mysqli_query($mysqli, "SELECT ticket_templates.ticket_template_id, ticket_template_name, ticket_template_subject, ticket_template_description, ticket_template_order
|
||||
FROM project_template_ticket_templates
|
||||
JOIN ticket_templates ON ticket_templates.ticket_template_id = project_template_ticket_templates.ticket_template_id
|
||||
WHERE project_template_id = $project_template_id
|
||||
ORDER BY ticket_template_order ASC, ticket_template_name ASC");
|
||||
$ticket_templates = [];
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$ticket_templates[intval($row['ticket_template_id'])] = $row + ['tasks' => []];
|
||||
}
|
||||
if ($ticket_templates) {
|
||||
$sql = mysqli_query($mysqli, "SELECT task_template_ticket_template_id, task_template_name FROM task_templates
|
||||
WHERE task_template_ticket_template_id IN (" . implode(',', array_keys($ticket_templates)) . ")
|
||||
ORDER BY task_template_order ASC, task_template_id ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$ticket_templates[intval($row['task_template_ticket_template_id'])]['tasks'][] = $row['task_template_name'];
|
||||
}
|
||||
|
||||
$row = mysqli_fetch_assoc($sql_project_templates);
|
||||
|
||||
$project_template_name = escapeHtml($row['project_template_name']);
|
||||
$project_template_description = escapeHtml($row['project_template_description']);
|
||||
$project_template_created_at = date("Y-m-d", strtotime($row['project_template_created_at']));
|
||||
$project_template_updated_at = escapeHtml($row['project_template_updated_at']);
|
||||
|
||||
// Get Associated Ticket Templates
|
||||
$sql_ticket_templates = mysqli_query($mysqli, "SELECT ticket_template_created_at, ticket_template_description,
|
||||
project_template_ticket_templates.ticket_template_id, ticket_template_name,
|
||||
ticket_template_order, ticket_template_subject, ticket_template_updated_at FROM ticket_templates, project_template_ticket_templates
|
||||
WHERE ticket_templates.ticket_template_id = project_template_ticket_templates.ticket_template_id
|
||||
AND project_template_ticket_templates.project_template_id = $project_template_id
|
||||
ORDER BY ticket_template_order ASC, ticket_template_name ASC");
|
||||
$ticket_template_count = mysqli_num_rows($sql_ticket_templates);
|
||||
|
||||
// Get All Task Templates
|
||||
$sql_task_templates = mysqli_query($mysqli,
|
||||
"SELECT task_template_id, task_template_name FROM ticket_templates, task_templates, project_template_ticket_templates
|
||||
WHERE ticket_templates.ticket_template_id = project_template_ticket_templates.ticket_template_id
|
||||
AND project_template_ticket_templates.project_template_id = $project_template_id
|
||||
AND ticket_templates.ticket_template_id = task_template_ticket_template_id
|
||||
ORDER BY task_template_created_at ASC"
|
||||
);
|
||||
$task_template_count = mysqli_num_rows($sql_task_templates);
|
||||
}
|
||||
$task_count = array_sum(array_map(function ($t) { return count($t['tasks']); }, $ticket_templates));
|
||||
$archived = !empty($template['project_template_archived_at']);
|
||||
|
||||
?>
|
||||
|
||||
<!-- Breadcrumbs-->
|
||||
<ol class="breadcrumb d-print-none">
|
||||
<li class="breadcrumb-item">
|
||||
<a href="admin_user.php">Admin</a>
|
||||
</li>
|
||||
<li class="breadcrumb-item">
|
||||
<a href="project_templates.php">Project Templates</a>
|
||||
</li>
|
||||
<li class="breadcrumb-item active">Project Template Details</li>
|
||||
<li class="breadcrumb-item"><a href="users.php">Admin</a></li>
|
||||
<li class="breadcrumb-item"><a href="project_templates.php">Project Templates</a></li>
|
||||
<li class="breadcrumb-item active"><?= escapeHtml($template['project_template_name']) ?></li>
|
||||
</ol>
|
||||
|
||||
<!-- Project Header -->
|
||||
<div class="card card-body mb-3">
|
||||
<div class="row">
|
||||
<div class="col-sm-4">
|
||||
<div class="d-flex">
|
||||
<i class="fa fa-fw fa-2x fa-project-diagram text-secondary me-3"></i>
|
||||
<div class="flex-grow-1">
|
||||
<h3 class="mb-0"><?= $project_template_name ?><span class='badge rounded-pill bg-info ms-2'>Template</span></h3>
|
||||
<div><small class="text-secondary"><?= $project_template_description ?></small></div>
|
||||
</div>
|
||||
<div class="card mb-3">
|
||||
<div class="card-body d-flex flex-wrap align-items-center gap-3">
|
||||
<span class="itflow-asset-icon itflow-asset-icon-lg itflow-project-icon" aria-hidden="true"><i class="fas fa-fw fa-cubes"></i></span>
|
||||
<div class="flex-grow-1 min-w-0">
|
||||
<h1 class="h4 fw-semibold mb-1 d-flex flex-wrap align-items-center gap-2">
|
||||
<span><?= escapeHtml($template['project_template_name']) ?></span>
|
||||
<span class="badge rounded-pill text-bg-info fw-normal fs-6">Template</span>
|
||||
<?php if ($archived) { ?><span class="badge rounded-pill text-bg-secondary fw-normal fs-6">Archived</span><?php } ?>
|
||||
</h1>
|
||||
<div class="text-body-secondary small d-flex flex-wrap column-gap-3 row-gap-1">
|
||||
<span><i class="fas fa-fw fa-life-ring me-1"></i><?= count($ticket_templates) ?> ticket<?= count($ticket_templates) === 1 ? '' : 's' ?></span>
|
||||
<span><i class="fas fa-fw fa-tasks me-1"></i><?= $task_count ?> task<?= $task_count === 1 ? '' : 's' ?></span>
|
||||
<?php if ($template['project_template_description']) { ?><span><?= escapeHtml($template['project_template_description']) ?></span><?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-3">
|
||||
<div class="d-flex">
|
||||
<i class="fa fa-fw fa-2x fa-life-ring text-secondary me-3"></i>
|
||||
<div class="flex-grow-1">
|
||||
<div>Ticket Templates</div>
|
||||
<h3 class="mb-0"><?= $ticket_template_count ?></h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-3">
|
||||
<div class="d-flex">
|
||||
<i class="fa fa-fw fa-2x fa-tasks text-secondary me-3"></i>
|
||||
<div class="flex-grow-1">
|
||||
<div>Task Templates</div>
|
||||
<h3 class="mb-0"><?= $task_template_count ?></h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-2">
|
||||
<div class="btn-group float-end">
|
||||
<button type="button" class="btn btn-primary btn-sm ajax-modal" href="#" data-modal-url="modals/project_template/project_template_ticket_template_add.php?project_template_id=<?= $project_template_id ?>">
|
||||
<i class="fas fa-fw fa-plus me-2"></i>Add Ticket Template
|
||||
</button>
|
||||
<div class="dropdown dropstart text-center ms-3">
|
||||
<button class="btn btn-secondary btn-sm" title="More actions" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown">
|
||||
<i class="fas fa-fw fa-ellipsis-v"></i>
|
||||
</button>
|
||||
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/project_template/project_template_edit.php?project_template_id=<?= $project_template_id ?>">
|
||||
<i class="fas fa-fw fa-edit me-2"></i>Edit Template
|
||||
<div class="d-flex flex-wrap gap-2 d-print-none">
|
||||
<button type="button" class="btn btn-primary ajax-modal" data-modal-url="modals/project_template/project_template_ticket_template_add.php?project_template_id=<?= $project_template_id ?>">
|
||||
<i class="fas fa-plus me-2"></i>Add ticket templates
|
||||
</button>
|
||||
<button type="button" class="btn btn-outline-secondary ajax-modal" data-modal-url="modals/project_template/project_template_edit.php?project_template_id=<?= $project_template_id ?>">
|
||||
<i class="fas fa-edit me-2"></i>Edit
|
||||
</button>
|
||||
<div class="dropdown dropstart">
|
||||
<button class="btn btn-outline-secondary" title="More actions" type="button" data-bs-toggle="dropdown"><i class="fas fa-fw fa-ellipsis-v"></i></button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item" href="post.php?duplicate_project_template=<?= $project_template_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-copy text-secondary me-2"></i>Duplicate
|
||||
</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<?php if ($archived) { ?>
|
||||
<a class="dropdown-item" href="post.php?restore_project_template=<?= $project_template_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-box-open text-secondary me-2"></i>Restore
|
||||
</a>
|
||||
<?php if ($session_user_role == 3) { ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?archive_project_template=<?= $project_template_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-archive me-2"></i>Archive (not yet implemented)
|
||||
</a>
|
||||
<?php } ?>
|
||||
<?php if ($session_user_role == 3) { ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item text-danger confirm-link" href="post.php?delete_project_template=<?= $project_template_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-trash me-2"></i>Delete
|
||||
</a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<a class="dropdown-item text-danger" href="post.php?archive_project_template=<?= $project_template_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-archive me-2"></i>Archive
|
||||
</a>
|
||||
<?php } ?>
|
||||
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?delete_project_template=<?= $project_template_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>"
|
||||
data-confirm-text="The template goes for good. Its ticket templates stay, and so do projects started from it.">
|
||||
<i class="fas fa-fw fa-trash me-2"></i>Delete
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
|
||||
<!-- Tickets card -->
|
||||
<?php if (mysqli_num_rows($sql_ticket_templates) > 0) { ?>
|
||||
<div class="card card-body card-outline card-dark mb-3">
|
||||
|
||||
<h5 class="text-secondary"><i class="fa fa-fw fa-life-ring me-2"></i>Project Ticket Templates</h5>
|
||||
<div class="table-responsive-sm">
|
||||
<table class="table table-striped table-borderless table-hover" id="ticket_templates">
|
||||
<thead class="text-dark">
|
||||
<tr>
|
||||
<th>Template Name</th>
|
||||
<th>Description</th>
|
||||
<th>Ticket Subject</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
|
||||
while ($row = mysqli_fetch_assoc($sql_ticket_templates)) {
|
||||
$ticket_template_id = intval($row['ticket_template_id']);
|
||||
$ticket_template_order = intval($row['ticket_template_order']);
|
||||
$ticket_template_name = escapeHtml($row['ticket_template_name']);
|
||||
$ticket_template_description = escapeHtml($row['ticket_template_description']);
|
||||
$ticket_template_subject = escapeHtml($row['ticket_template_subject']);
|
||||
$ticket_template_created_at = escapeHtml($row['ticket_template_created_at']);
|
||||
$ticket_template_updated_at = escapeHtml($row['ticket_template_updated_at']);
|
||||
|
||||
?>
|
||||
|
||||
<tr data-task-id="<?= $ticket_template_id ?>">
|
||||
<td>
|
||||
<a href="#" class="drag-handle"><i class="fas fa-bars text-muted me-2"></i></a>
|
||||
<a href="ticket_template.php?ticket_template_id=<?= $ticket_template_id ?>">
|
||||
<?= $ticket_template_name ?>
|
||||
</a>
|
||||
</td>
|
||||
<td><?= $ticket_template_description ?></td>
|
||||
<td><?= $ticket_template_subject ?></td>
|
||||
<td>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="project_template_id" value="<?= $project_template_id ?>">
|
||||
<input type="hidden" name="ticket_template_id" value="<?= $ticket_template_id ?>">
|
||||
<button type="submit" class="btn btn-default btn-sm confirm-link" title="Remove ticket template"
|
||||
name="remove_ticket_template_from_project_template">
|
||||
<i class="fa fa-fw fa-times"></i>
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="row g-3">
|
||||
<div class="col-xl-8">
|
||||
<div class="card mb-3">
|
||||
<div class="card-header d-flex align-items-center">
|
||||
<h3 class="card-title mb-0 me-auto"><i class="fas fa-fw fa-list-ol text-secondary me-2"></i>Tickets it raises</h3>
|
||||
<?php if (count($ticket_templates) > 1) { ?><span class="small text-body-secondary">Drag to change the order</span><?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
|
||||
<!-- Task Templates Card -->
|
||||
<?php if (mysqli_num_rows($sql_task_templates) > 0) { ?>
|
||||
<div class="card card-body card-outline card-dark">
|
||||
<h5 class="text-secondary"><i class="fas fa-fw fa-tasks me-2"></i>Project Task Templates</h5>
|
||||
<table class="table">
|
||||
<?php
|
||||
while($row = mysqli_fetch_assoc($sql_task_templates)){
|
||||
$task_template_id = intval($row['task_template_id']);
|
||||
$task_template_name = escapeHtml($row['task_template_name']);
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<i class="far fa-fw fa-check-square text-primary me-3"></i>
|
||||
<?= $task_template_name ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</table>
|
||||
<?php if ($ticket_templates) { ?>
|
||||
<ol class="list-group list-group-flush list-group-numbered" id="projectTemplateTickets">
|
||||
<?php foreach ($ticket_templates as $ticket_template_id => $row) { ?>
|
||||
<li class="list-group-item d-flex align-items-start gap-2" data-ticket-template-id="<?= $ticket_template_id ?>">
|
||||
<div class="flex-grow-1 min-w-0 ms-1">
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
<a class="fw-semibold" href="ticket_template.php?ticket_template_id=<?= $ticket_template_id ?>"><?= escapeHtml($row['ticket_template_name']) ?></a>
|
||||
<?php if ($row['tasks']) { ?>
|
||||
<a class="small text-body-secondary text-decoration-none" data-bs-toggle="collapse" href="#ptTasks<?= $ticket_template_id ?>" role="button"><i class="fas fa-tasks me-1"></i><?= count($row['tasks']) ?> task<?= count($row['tasks']) === 1 ? '' : 's' ?> <i class="fas fa-caret-down"></i></a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php if ($row['ticket_template_subject'] && $row['ticket_template_subject'] !== $row['ticket_template_name']) { ?>
|
||||
<div class="small text-body-secondary">Raised as "<?= escapeHtml($row['ticket_template_subject']) ?>"</div>
|
||||
<?php } ?>
|
||||
<?php if ($row['tasks']) { ?>
|
||||
<ul class="collapse small text-body-secondary mt-1 mb-0 ps-3" id="ptTasks<?= $ticket_template_id ?>">
|
||||
<?php foreach ($row['tasks'] as $task_name) { ?><li><?= escapeHtml($task_name) ?></li><?php } ?>
|
||||
</ul>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<span class="drag-handle text-body-secondary px-1" title="Drag to move" role="button"><i class="fas fa-grip-vertical"></i></span>
|
||||
<form action="post.php" method="post" class="m-0">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="project_template_id" value="<?= $project_template_id ?>">
|
||||
<input type="hidden" name="ticket_template_id" value="<?= $ticket_template_id ?>">
|
||||
<button type="submit" class="btn btn-sm btn-light confirm-link" title="Take it out of this template" name="remove_ticket_template_from_project_template"
|
||||
data-confirm-text="The ticket template stays - it just won't be raised by this project template.">
|
||||
<i class="fas fa-fw fa-times"></i>
|
||||
</button>
|
||||
</form>
|
||||
</li>
|
||||
<?php } ?>
|
||||
</ol>
|
||||
<?php } else { ?>
|
||||
<div class="itflow-asset-empty">
|
||||
<i class="fas fa-life-ring fa-2x mb-2 opacity-50"></i>
|
||||
<div>No ticket templates in it yet. Add one per step of the work - each brings its own task checklist.</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<!-- End Task TemplatesCard -->
|
||||
|
||||
</div> <!-- End col-3 -->
|
||||
|
||||
</div> <!-- End row -->
|
||||
</div>
|
||||
<div class="col-xl-4">
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title mb-0"><i class="fas fa-fw fa-info-circle text-secondary me-2"></i>How it is used</h3>
|
||||
</div>
|
||||
<div class="card-body small">
|
||||
<p>Pick it on <strong>New Project</strong>, or <strong>Add tickets > From a project template</strong> on a project, and these tickets are raised on the project in this order, each with its tasks.</p>
|
||||
<p class="text-body-secondary">They go to the project's client contact, and to its manager when asked. The client isn't emailed - it's planned work.</p>
|
||||
<p class="mb-0 text-body-secondary"><code>[Client]</code>, <code>[Project]</code>, <code>[Month]</code>, <code>[Quarter]</code> and <code>[Year]</code> in a ticket template's subject are filled in. Anything else in brackets is left for the agent.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="../libs/SortableJS/Sortable.min.js"></script>
|
||||
<script>
|
||||
new Sortable(document.querySelector('table#ticket_templates tbody'), {
|
||||
handle: '.drag-handle',
|
||||
animation: 150,
|
||||
onEnd: function (evt) {
|
||||
const rows = document.querySelectorAll('table#ticket_templates tbody tr');
|
||||
const positions = Array.from(rows).map((row, index) => ({
|
||||
id: row.dataset.taskId,
|
||||
order: index
|
||||
}));
|
||||
|
||||
itflowPostForm('/agent/ajax.php', {
|
||||
update_project_template_ticket_order: true,
|
||||
csrf_token: '<?= $_SESSION['csrf_token'] ?>',
|
||||
project_template_id: <?= $project_template_id ?>,
|
||||
positions: positions
|
||||
(function () {
|
||||
var list = document.getElementById('projectTemplateTickets');
|
||||
if (!list) {
|
||||
return;
|
||||
}
|
||||
new Sortable(list, {
|
||||
handle: '.drag-handle',
|
||||
animation: 150,
|
||||
onEnd: function () {
|
||||
var positions = Array.prototype.map.call(list.querySelectorAll('[data-ticket-template-id]'), function (row, index) {
|
||||
return {id: row.dataset.ticketTemplateId, order: index};
|
||||
});
|
||||
itflowPostForm('/agent/ajax.php', {
|
||||
update_project_template_ticket_order: true,
|
||||
csrf_token: '<?= $_SESSION['csrf_token'] ?>',
|
||||
project_template_id: <?= $project_template_id ?>,
|
||||
positions: positions
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
require_once "../includes/footer.php";
|
||||
|
||||
?>
|
||||
|
||||
<script src="../js/pretty_content.js"></script>
|
||||
|
||||
@@ -1,136 +1,148 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Project templates - the plans a new project can start from: onboarding a
|
||||
* client, a server refresh, an office move. Each is an ordered set of ticket
|
||||
* templates, and each of those brings its tasks. Picking one on New Project
|
||||
* raises those tickets on the project.
|
||||
*/
|
||||
|
||||
// Default Column Sortby Filter
|
||||
$sort = "project_template_name";
|
||||
$order = "ASC";
|
||||
|
||||
require_once "includes/inc_all_admin.php";
|
||||
|
||||
$sql = mysqli_query(
|
||||
$mysqli,
|
||||
"SELECT SQL_CALC_FOUND_ROWS project_template_created_at, project_template_description, project_template_id,
|
||||
project_template_name FROM project_templates
|
||||
WHERE (project_template_name LIKE '%$q%' OR project_template_description LIKE '%$q%')
|
||||
AND project_template_archived_at IS NULL
|
||||
ORDER BY $sort $order LIMIT $record_from, $record_to"
|
||||
);
|
||||
$show_archived = ($_GET['show'] ?? '') === 'archived';
|
||||
|
||||
// Only these sort - an unknown column would take the page down
|
||||
$sortable_columns = [
|
||||
'project_template_name' => "project_template_name $order",
|
||||
'ticket_count' => "ticket_count $order, project_template_name ASC",
|
||||
'task_count' => "task_count $order, project_template_name ASC",
|
||||
'project_template_updated_at' => "COALESCE(project_template_updated_at, project_template_created_at) $order",
|
||||
];
|
||||
if (!isset($sortable_columns[$sort])) {
|
||||
$sort = 'project_template_name';
|
||||
}
|
||||
|
||||
$search = "(project_template_name LIKE '%$q%' OR project_template_description LIKE '%$q%')";
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS project_templates.project_template_id, project_template_name, project_template_description,
|
||||
project_template_created_at, project_template_updated_at, project_template_archived_at,
|
||||
COUNT(DISTINCT ptt.ticket_template_id) AS ticket_count, COUNT(task_template_id) AS task_count
|
||||
FROM project_templates
|
||||
LEFT JOIN project_template_ticket_templates ptt ON ptt.project_template_id = project_templates.project_template_id
|
||||
LEFT JOIN task_templates ON task_template_ticket_template_id = ptt.ticket_template_id
|
||||
WHERE $search AND project_template_archived_at IS " . ($show_archived ? 'NOT NULL' : 'NULL') . "
|
||||
GROUP BY project_templates.project_template_id
|
||||
ORDER BY {$sortable_columns[$sort]}
|
||||
LIMIT $record_from, $record_to");
|
||||
|
||||
$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
|
||||
$counts = mysqli_fetch_row(mysqli_query($mysqli, "SELECT COALESCE(SUM(project_template_archived_at IS NULL), 0), COALESCE(SUM(project_template_archived_at IS NOT NULL), 0) FROM project_templates WHERE $search"));
|
||||
|
||||
$sort_link = function ($column, $label) use ($url_query_strings_sort, $sort, $disp, $order_icon) {
|
||||
return '<a class="text-reset text-decoration-none" href="?' . escapeHtml($url_query_strings_sort) . '&sort=' . $column . '&order=' . $disp . '">'
|
||||
. $label . ($sort === $column ? " $order_icon" : '') . '</a>';
|
||||
};
|
||||
|
||||
?>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header bg-dark py-2">
|
||||
<h3 class="card-title mt-2"><i class="fas fa-fw fa-project-diagram me-2"></i>Project Templates</h3>
|
||||
<h3 class="card-title mt-2"><i class="fas fa-fw fa-cubes me-2"></i>Project Templates</h3>
|
||||
<div class="card-tools">
|
||||
<button type="button" class="btn btn-primary ajax-modal" data-modal-url="modals/project_template/project_template_add.php"><i class="fas fa-plus me-2"></i>New Project Template</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-header py-3">
|
||||
<form autocomplete="off">
|
||||
<?php if ($show_archived) { ?><input type="hidden" name="show" value="archived"><?php } ?>
|
||||
<div class="row g-2 align-items-center">
|
||||
|
||||
<div class="col-md-4">
|
||||
<div class="col-md-5">
|
||||
<div class="input-group">
|
||||
<input type="search" class="form-control" name="q" value="<?php if(isset($q)){ echo stripslashes(escapeHtml($q)); } ?>" placeholder="Search Project Templates">
|
||||
<button class="btn btn-dark" title="Search"><i class="fa fa-search"></i></button>
|
||||
<input type="search" class="form-control" name="q" value="<?php if (isset($q)) { echo stripslashes(escapeHtml($q)); } ?>" placeholder="Search project templates...">
|
||||
<button class="btn btn-dark" title="Search"><i class="fa fa-search"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-8">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</form>
|
||||
<nav class="nav nav-pills itflow-asset-tabs mt-2">
|
||||
<a class="nav-link <?= $show_archived ? '' : 'active' ?>" href="?<?= escapeHtml(http_build_query(array_filter(['q' => $_GET['q'] ?? '']))) ?>"><i class="fas fa-fw fa-cubes me-1"></i>Active <span class="badge rounded-pill ms-1"><?= intval($counts[0]) ?></span></a>
|
||||
<a class="nav-link <?= $show_archived ? 'active' : '' ?>" href="?<?= escapeHtml(http_build_query(array_filter(['q' => $_GET['q'] ?? '', 'show' => 'archived']))) ?>"><i class="fas fa-fw fa-archive me-1"></i>Archived <span class="badge rounded-pill ms-1"><?= intval($counts[1]) ?></span></a>
|
||||
</nav>
|
||||
</div>
|
||||
<div class="table-responsive-sm">
|
||||
<table class="table table-striped table-borderless table-hover mb-0">
|
||||
<thead class="text-dark <?php if($num_rows[0] == 0){ echo "d-none"; } ?>">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle mb-0">
|
||||
<thead class="table-light text-nowrap <?php if ($num_rows[0] == 0) { echo "d-none"; } ?>">
|
||||
<tr>
|
||||
<th class="ps-3">
|
||||
<a class="text-secondary" href="?<?= $url_query_strings_sort ?>&sort=project_template_name&order=<?= $disp ?>">
|
||||
Template <?php if ($sort == 'project_template_name') { echo $order_icon; } ?>
|
||||
</a>
|
||||
</th>
|
||||
<th>Tickets</th>
|
||||
<th>Tasks</th>
|
||||
<th class="text-center">Action</th>
|
||||
<th class="ps-3"><?= $sort_link('project_template_name', 'Template') ?></th>
|
||||
<th class="text-center"><?= $sort_link('ticket_count', 'Tickets') ?></th>
|
||||
<th class="text-center"><?= $sort_link('task_count', 'Tasks') ?></th>
|
||||
<th><?= $sort_link('project_template_updated_at', 'Updated') ?></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
|
||||
while($row = mysqli_fetch_assoc($sql)){
|
||||
<?php while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$project_template_id = intval($row['project_template_id']);
|
||||
$project_template_name = escapeHtml($row['project_template_name']);
|
||||
$project_template_description = escapeHtml($row['project_template_description']);
|
||||
$project_template_created_at = escapeHtml($row['project_template_created_at']);
|
||||
|
||||
// Get Ticket Template Count
|
||||
$sql_ticket_templates = mysqli_query($mysqli, "SELECT 1 FROM ticket_templates, project_template_ticket_templates
|
||||
WHERE ticket_templates.ticket_template_id = project_template_ticket_templates.ticket_template_id
|
||||
AND project_template_ticket_templates.project_template_id = $project_template_id
|
||||
ORDER BY ticket_template_order ASC, ticket_template_name ASC");
|
||||
$ticket_template_count = mysqli_num_rows($sql_ticket_templates);
|
||||
|
||||
// Get Tasks Template Count
|
||||
$sql_task_templates = mysqli_query($mysqli,
|
||||
"SELECT 1 FROM ticket_templates, task_templates, project_template_ticket_templates
|
||||
WHERE ticket_templates.ticket_template_id = project_template_ticket_templates.ticket_template_id
|
||||
AND project_template_ticket_templates.project_template_id = $project_template_id
|
||||
AND ticket_templates.ticket_template_id = task_template_ticket_template_id
|
||||
ORDER BY task_template_created_at ASC"
|
||||
);
|
||||
$task_template_count = mysqli_num_rows($sql_task_templates);
|
||||
|
||||
$updated = $row['project_template_updated_at'] ?: $row['project_template_created_at'];
|
||||
?>
|
||||
<tr>
|
||||
<td class="ps-3">
|
||||
<a class="text-dark" href="project_template.php?project_template_id=<?= $project_template_id ?>">
|
||||
<div class="d-flex">
|
||||
<i class="fa fa-fw fa-2x fa-project-diagram me-3"></i>
|
||||
<div class="flex-grow-1">
|
||||
<div>
|
||||
<?= $project_template_name ?>
|
||||
</div>
|
||||
<div>
|
||||
<small class="text-secondary"><?= $project_template_description ?></small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</td>
|
||||
<td><?= $ticket_template_count ?></td>
|
||||
<td><?= $task_template_count ?></td>
|
||||
<td>
|
||||
<div class="dropdown dropstart text-center">
|
||||
<button class="btn btn-secondary btn-sm" title="More actions" data-bs-toggle="dropdown">
|
||||
<i class="fas fa-ellipsis-h"></i>
|
||||
</button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/project_template/project_template_edit.php?project_template_id=<?= $project_template_id ?>">
|
||||
<i class="fas fa-fw fa-edit me-2"></i>Edit
|
||||
</a>
|
||||
<?php if($session_user_role == 3) { ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?delete_project_template=<?= $project_template_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-trash me-2"></i>Delete
|
||||
</a>
|
||||
<div class="d-flex align-items-center gap-3">
|
||||
<span class="itflow-asset-icon itflow-project-icon" aria-hidden="true"><i class="fas fa-fw fa-cubes"></i></span>
|
||||
<div class="min-w-0">
|
||||
<a class="fw-semibold text-body" href="project_template.php?project_template_id=<?= $project_template_id ?>"><?= escapeHtml($row['project_template_name']) ?></a>
|
||||
<?php if ($row['project_template_description']) { ?>
|
||||
<div class="small text-body-secondary text-truncate" style="max-width: 36rem"><?= escapeHtml($row['project_template_description']) ?></div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="text-center"><?= intval($row['ticket_count']) ?: '<span class="text-body-secondary">-</span>' ?></td>
|
||||
<td class="text-center"><?= intval($row['task_count']) ?: '<span class="text-body-secondary">-</span>' ?></td>
|
||||
<td class="small text-body-secondary text-nowrap" title="<?= escapeHtml($updated) ?>"><?= timeAgo($updated) ?></td>
|
||||
<td class="text-end">
|
||||
<div class="dropdown dropstart">
|
||||
<button class="btn btn-sm btn-light" title="More actions" type="button" data-bs-toggle="dropdown"><i class="fas fa-fw fa-ellipsis-v"></i></button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/project_template/project_template_edit.php?project_template_id=<?= $project_template_id ?>">
|
||||
<i class="fas fa-fw fa-edit text-secondary me-2"></i>Edit
|
||||
</a>
|
||||
<a class="dropdown-item" href="post.php?duplicate_project_template=<?= $project_template_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-copy text-secondary me-2"></i>Duplicate
|
||||
</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<?php if ($row['project_template_archived_at']) { ?>
|
||||
<a class="dropdown-item" href="post.php?restore_project_template=<?= $project_template_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-box-open text-secondary me-2"></i>Restore
|
||||
</a>
|
||||
<?php } else { ?>
|
||||
<a class="dropdown-item text-danger" href="post.php?archive_project_template=<?= $project_template_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-archive me-2"></i>Archive
|
||||
</a>
|
||||
<?php } ?>
|
||||
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?delete_project_template=<?= $project_template_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>"
|
||||
data-confirm-text="The template goes for good. Its ticket templates stay, and so do projects started from it.">
|
||||
<i class="fas fa-fw fa-trash me-2"></i>Delete
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php if ($num_rows[0] == 0) { ?>
|
||||
<div class="itflow-asset-empty">
|
||||
<i class="fas fa-cubes fa-2x mb-2 opacity-50"></i>
|
||||
<div><?= $q !== '' ? 'No project templates match.' : ($show_archived ? 'No archived project templates.' : 'No project templates yet - a client onboarding plan is a good first one: one ticket template per step, each with its checklist of tasks.') ?></div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php require_once "../includes/filter_footer.php"; ?>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user