mirror of
https://github.com/itflow-org/itflow
synced 2026-02-28 10:54:52 +00:00
Add task approval system
This commit is contained in:
140
agent/modals/ticket/ticket_task_approver_add.php
Normal file
140
agent/modals/ticket/ticket_task_approver_add.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
|
||||
$task_id = intval($_GET['id']);
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM tasks
|
||||
WHERE task_id = $task_id
|
||||
LIMIT 1"
|
||||
);
|
||||
|
||||
$row = mysqli_fetch_array($sql);
|
||||
$task_name = nullable_htmlentities($row['task_name']);
|
||||
|
||||
// Generate the HTML form content using output buffering.
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-shield-alt mr-2"></i>New approver for task <?=$task_name?></h5>
|
||||
<button type="button" class="close text-white" data-dismiss="modal">
|
||||
<span>×</span>
|
||||
</button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="task_id" value="<?php echo $task_id; ?>">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="form-group">
|
||||
<label>Approval scope <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-layer-group"></i></span>
|
||||
</div>
|
||||
<select class="form-control" name="approval_scope" id="approval_scope" required>
|
||||
<option value="">Select scope...</option>
|
||||
<option value="internal">Internal</option>
|
||||
<option value="client">Client</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group d-none" id="approval_type_wrapper">
|
||||
<label>Who can approve? <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-user-check"></i></span>
|
||||
</div>
|
||||
<select class="form-control" name="approval_type" id="approval_type" required>
|
||||
<!-- JS -->
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group d-none" id="specific_user_wrapper">
|
||||
<label>Select specific internal approver <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-user-circle"></i></span>
|
||||
</div>
|
||||
<select class="form-control select2" name="approval_required_user_id" id="specific_user_select">
|
||||
<option value="">Select user...</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="add_ticket_task_approver" class="btn btn-primary text-bold"><i class="fa fa-check mr-2"></i>Save</button>
|
||||
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fa fa-times mr-2"></i>Cancel</button>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
|
||||
<!-- JS to make the correct boxes appear depending on if internal/client approval) -->
|
||||
<script>
|
||||
$('#approval_scope').on('change', function() {
|
||||
const scope = $(this).val();
|
||||
const typeSelect = $('#approval_type');
|
||||
const wrapper = $('#approval_type_wrapper');
|
||||
|
||||
typeSelect.empty();
|
||||
$('#specific_user_wrapper').addClass('d-none');
|
||||
|
||||
if (!scope) {
|
||||
wrapper.addClass('d-none');
|
||||
return;
|
||||
}
|
||||
|
||||
wrapper.removeClass('d-none');
|
||||
|
||||
if (scope === 'internal') {
|
||||
typeSelect.append('<option value="">Select...</option>');
|
||||
typeSelect.append('<option value="any">Any internal reviewer</option>');
|
||||
typeSelect.append('<option value="specific">Specific agent</option>');
|
||||
}
|
||||
|
||||
if (scope === 'client') {
|
||||
typeSelect.append('<option value="">Select...</option>');
|
||||
typeSelect.append('<option value="any">Ticket contact</option>');
|
||||
typeSelect.append('<option value="technical">Technical contacts</option>');
|
||||
typeSelect.append('<option value="billing">Billing contacts</option>');
|
||||
}
|
||||
});
|
||||
|
||||
// Specific user (internal only for now)
|
||||
$('#approval_type').on('change', function() {
|
||||
const type = $(this).val();
|
||||
const scope = $('#approval_scope').val();
|
||||
const userSelect = $('#specific_user_select');
|
||||
|
||||
if (type !== 'specific' || scope !== 'internal') {
|
||||
$('#specific_user_wrapper').addClass('d-none');
|
||||
return;
|
||||
}
|
||||
|
||||
$('#specific_user_wrapper').removeClass('d-none');
|
||||
userSelect.empty().append('<option value="">Loading...</option>');
|
||||
|
||||
$.getJSON('ajax.php?get_internal_users=true', function(data) {
|
||||
userSelect.empty().append('<option value="">Select user...</option>');
|
||||
data.users.forEach(function(u) {
|
||||
userSelect.append(`<option value="${u.user_id}">${u.user_name}</option>`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<?php
|
||||
|
||||
require_once '../../../includes/modal_footer.php';
|
||||
@@ -14,6 +14,14 @@ $task_name = nullable_htmlentities($row['task_name']);
|
||||
$task_completion_estimate = intval($row['task_completion_estimate']);
|
||||
$task_completed_at = nullable_htmlentities($row['task_completed_at']);
|
||||
|
||||
// Approvals
|
||||
$sql_task_approvals = mysqli_query($mysqli, "
|
||||
SELECT user_name, approval_id, approval_scope, approval_type, approval_required_user_id, approval_status, approval_created_by, approval_approved_by FROM task_approvals
|
||||
LEFT JOIN users ON user_id = approval_required_user_id
|
||||
WHERE approval_task_id = $task_id
|
||||
ORDER BY approval_approved_by"
|
||||
);
|
||||
|
||||
// Generate the HTML form content using output buffering.
|
||||
ob_start();
|
||||
|
||||
@@ -27,7 +35,7 @@ ob_start();
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="task_id" value="<?php echo $task_id; ?>">
|
||||
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="form-group">
|
||||
@@ -49,7 +57,53 @@ ob_start();
|
||||
<input type="number" class="form-control" name="completion_estimate" placeholder="Estimated time to complete task in mins" value="<?php echo $task_completion_estimate; ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<?php if (mysqli_num_rows($sql_task_approvals) > 0) { ?>
|
||||
<hr>
|
||||
<div class="form-group">
|
||||
<b>Task Approvals</b>
|
||||
|
||||
<table class="table table-sm table-bordered" style="margin-top:10px;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Scope</th>
|
||||
<th>Type</th>
|
||||
<th>Status</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php while ($row = mysqli_fetch_array($sql_task_approvals)) {
|
||||
$approval_id = intval($row['approval_id']);
|
||||
$approval_scope = nullable_htmlentities($row['approval_scope']);
|
||||
$approval_type = nullable_htmlentities($row['approval_type']);
|
||||
$approval_user_name = nullable_htmlentities($row['user_name']);
|
||||
$approval_status = nullable_htmlentities($row['approval_status']);
|
||||
$approval_created_by = intval($row['approval_created_by']);
|
||||
$approval_approved_by = nullable_htmlentities($row['approval_approved_by']);
|
||||
?>
|
||||
<tr>
|
||||
<td><?= ucfirst($approval_scope) ?></td>
|
||||
<td><?= ucfirst($approval_type) ?> <?php if (!empty($approval_user_name)) { echo " - $approval_user_name"; } ?></td>
|
||||
<td><?= ucfirst($approval_status) ?></td>
|
||||
<td>
|
||||
<?php if ($approval_status !== 'approved') { ?>
|
||||
<a class="text-danger"
|
||||
onclick="return confirm('Delete this approval request?');"
|
||||
href="post.php?delete_ticket_task_approver=<?= $approval_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-trash-alt"></i>Delete
|
||||
</a>
|
||||
<!-- confirm-link won't work -->
|
||||
<?php } ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
|
||||
Reference in New Issue
Block a user