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:
johnnyq
2026-10-15 16:35:00 -04:00
parent 64d938db7f
commit bbb2456f0b
44 changed files with 3617 additions and 1550 deletions

View File

@@ -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 &gt; 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>