new changes

This commit is contained in:
Hugo Sampaio 2025-01-31 11:50:06 -03:00
parent f4eaba4384
commit e3ae8df4d8
8 changed files with 107 additions and 72 deletions

View File

@ -529,3 +529,80 @@ if (isset($_GET['get_totp_token_via_id'])) {
if (isset($_GET['get_readable_pass'])) { if (isset($_GET['get_readable_pass'])) {
echo json_encode(GenerateReadablePassword(4)); echo json_encode(GenerateReadablePassword(4));
} }
/*
* ITFlow - POST request handler for client tickets
*/
if (isset($_POST['update_kanban_status_position'])) {
// Update multiple ticket status kanban orders
enforceUserPermission('module_support', 2);
$positions = $_POST['positions'];
foreach ($positions as $position) {
$status_id = intval($position['status_id']);
$kanban = intval($position['status_kanban']);
mysqli_query($mysqli, "UPDATE ticket_statuses SET ticket_status_order = $kanban WHERE ticket_status_id = $status_id");
}
// return a response
echo json_encode(['status' => 'success']);
exit;
}
if (isset($_POST['update_kanban_ticket'])) {
// Update ticket kanban order and status
enforceUserPermission('module_support', 2);
// have to do new logic, to update only one dragged ticket
$positions = $_POST['positions']; //old and new position
// old logic that updated all tickets on the column
$positions = $_POST['positions'];
foreach ($positions as $position) {
$ticket_id = intval($position['ticket_id']);
$kanban = intval($position['ticket_kanban']); // ticket kanban position
$status = intval($position['ticket_status']); // ticket statuses
$oldStatus = intval($position['ticket_oldStatus']); // ticket old status if moved
$statuses['Closed'] = 5;
$statuses['Resolved'] = 4;
// Continue if status is null / Closed
if ($status === null || $status === $statuses['Closed']) {
continue;
}
if ($oldStatus === false) {
// if ticket was not moved, just uptdate the order on kanban
mysqli_query($mysqli, "UPDATE tickets SET ticket_kanban = $kanban WHERE ticket_id = $ticket_id");
customAction('ticket_update', $ticket_id);
} else {
// If the ticket was moved from a resolved status to another status, we need to update ticket_resolved_at
if ($oldStatus === $statuses['Resolved']) {
mysqli_query($mysqli, "UPDATE tickets SET ticket_kanban = $kanban, ticket_status = $status, ticket_resolved_at = NULL WHERE ticket_id = $ticket_id");
customAction('ticket_update', $ticket_id);
} elseif ($status === $statuses['Resolved']) {
// If the ticket was moved to a resolved status, we need to update ticket_resolved_at
mysqli_query($mysqli, "UPDATE tickets SET ticket_kanban = $kanban, ticket_status = $status, ticket_resolved_at = NOW() WHERE ticket_id = $ticket_id");
customAction('ticket_update', $ticket_id);
} else {
// If the ticket was moved from any status to another status
mysqli_query($mysqli, "UPDATE tickets SET ticket_kanban = $kanban, ticket_status = $status WHERE ticket_id = $ticket_id");
customAction('ticket_update', $ticket_id);
}
}
}
// return a response
echo json_encode(['status' => 'success','payload' => $positions]);
exit;
}

View File

@ -2472,7 +2472,7 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) {
if (CURRENT_DATABASE_VERSION == '1.8.0') { if (CURRENT_DATABASE_VERSION == '1.8.0') {
mysqli_query($mysqli, "ALTER TABLE `ticket_statuses` ADD `ticket_status_kanban` int(11)"); mysqli_query($mysqli, "ALTER TABLE `ticket_statuses` ADD `ticket_status_order` int(11)");
mysqli_query($mysqli, "ALTER TABLE `tickets` ADD `ticket_kanban` int(11);"); mysqli_query($mysqli, "ALTER TABLE `tickets` ADD `ticket_kanban` int(11);");

2
db.sql
View File

@ -2019,7 +2019,7 @@ CREATE TABLE `ticket_statuses` (
`ticket_status_name` varchar(200) NOT NULL, `ticket_status_name` varchar(200) NOT NULL,
`ticket_status_color` varchar(200) NOT NULL, `ticket_status_color` varchar(200) NOT NULL,
`ticket_status_active` tinyint(1) NOT NULL DEFAULT 1, `ticket_status_active` tinyint(1) NOT NULL DEFAULT 1,
`ticket_status_kanban` int(11), `ticket_status_order` int(11),
PRIMARY KEY (`ticket_status_id`) PRIMARY KEY (`ticket_status_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;

1
plugins/dragula/dragula.min.css vendored Normal file
View File

@ -0,0 +1 @@
.gu-mirror{position:fixed!important;margin:0!important;z-index:9999!important;opacity:.8}.gu-hide{display:none!important}.gu-unselectable{-webkit-user-select:none!important;-moz-user-select:none!important;-ms-user-select:none!important;user-select:none!important}.gu-transit{opacity:.2}

1
plugins/dragula/dragula.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,50 +0,0 @@
<?php
/*
* ITFlow - GET/POST request handler for client tickets
*/
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
if (isset($_POST['update_kanban_status_position'])) {
// Update multiple ticket status kanban orders
enforceUserPermission('module_support', 2);
$positions = $_POST['positions'];
foreach ($positions as $position) {
$status_id = intval($position['status_id']);
$kanban = intval($position['status_kanban']);
mysqli_query($mysqli, "UPDATE ticket_statuses SET ticket_status_kanban = $kanban WHERE ticket_status_id = $status_id");
}
// return a response
echo json_encode(['status' => 'success']);
exit;
}
if (isset($_POST['update_kanban_ticket'])) {
// Update ticket kanban order and status
enforceUserPermission('module_support', 2);
$positions = $_POST['positions'];
foreach ($positions as $position) {
$ticket_id = intval($position['ticket_id']);
$kanban = intval($position['ticket_kanban']); // ticket kanban position
$status = intval($position['ticket_status']); // ticket statuses
// Continue if status is null
if ($status === null) {
continue;
}
mysqli_query($mysqli, "UPDATE tickets SET ticket_kanban = $kanban, ticket_status = $status WHERE ticket_id = $ticket_id");
customAction('ticket_update', $ticket_id);
}
// return a response
echo json_encode(['status' => 'success','payload' => $positions]);
exit;
}

View File

@ -41,10 +41,12 @@ if (isset($_GET['category'])) {
if ($category == 'empty') { if ($category == 'empty') {
$category_snippet = "AND ticket_category = 0 "; $category_snippet = "AND ticket_category = 0 ";
} elseif ($category == 'all') { } elseif ($category == 'all') {
$category_snippet = ""; $category_snippet = '';
} else { } else {
$category_snippet = "AND ticket_category = " . $category; $category_snippet = "AND ticket_category = " . $category;
} }
} else {
$category_snippet = '';
} }
@ -166,8 +168,10 @@ $sql_categories = mysqli_query(
<a class="dropdown-item " href="<?=htmlspecialchars('?' . http_build_query(array_merge($_GET, ['view' => 'list']))); ?>">List</a> <a class="dropdown-item " href="<?=htmlspecialchars('?' . http_build_query(array_merge($_GET, ['view' => 'list']))); ?>">List</a>
<div class="dropdown-divider"></div> <div class="dropdown-divider"></div>
<a class="dropdown-item " href="<?=htmlspecialchars('?' . http_build_query(array_merge($_GET, ['view' => 'compact']))); ?>">Compact List</a> <a class="dropdown-item " href="<?=htmlspecialchars('?' . http_build_query(array_merge($_GET, ['view' => 'compact']))); ?>">Compact List</a>
<?php if ($status !== 'Closed') {?>
<div class="dropdown-divider"></div> <div class="dropdown-divider"></div>
<a class="dropdown-item " href="<?=htmlspecialchars('?' . http_build_query(array_merge($_GET, ['view' => 'kanban']))); ?>">Kanban</a> <a class="dropdown-item " href="<?=htmlspecialchars('?' . http_build_query(array_merge($_GET, ['view' => 'kanban']))); ?>">Kanban</a>
<?php } ?>
</div> </div>
</div> </div>
<div class="btn-group"> <div class="btn-group">
@ -353,9 +357,9 @@ $sql_categories = mysqli_query(
</div> </div>
</div> </div>
<?php <?php
if ($_GET["view"]) { if (isset($_GET["view"])) {
if ($_GET["view"] == "list") { if ($_GET["view"] == "list") {
require_once "tickets_list.php"; require_once "tickets_list.php";
} elseif ($_GET["view"] == "compact") { } elseif ($_GET["view"] == "compact") {

View File

@ -1,4 +1,4 @@
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/dragula/3.7.3/dragula.min.css"> <link rel="stylesheet" href="/plugins/dragula/dragula.min.css">
<style> <style>
.popover { .popover {
max-width: 600px; max-width: 600px;
@ -43,12 +43,12 @@ $kanban = [];
// Fetch all statuses // Fetch all statuses
$status_sql = mysqli_query($mysqli, "SELECT * FROM ticket_statuses"); $status_sql = mysqli_query($mysqli, "SELECT * FROM ticket_statuses where ticket_status_active = 1 AND ticket_status_id != 5 ORDER BY ticket_status_order");
$statuses = []; $statuses = [];
while ($status_row = mysqli_fetch_array($status_sql)) { while ($status_row = mysqli_fetch_array($status_sql)) {
$id = $status_row['ticket_status_id']; $id = $status_row['ticket_status_id'];
$name = $status_row['ticket_status_name']; $name = $status_row['ticket_status_name'];
$kanban_order = $status_row['ticket_status_kanban']; $kanban_order = $status_row['ticket_status_order'];
$statuses[$id] = new stdClass(); $statuses[$id] = new stdClass();
$statuses[$id]->id = $id; $statuses[$id]->id = $id;
@ -192,7 +192,7 @@ $kanban = $ordered_kanban;
<script src="https://cdnjs.cloudflare.com/ajax/libs/dragula/3.7.3/dragula.min.js"></script> <script src="/plugins/dragula/dragula.min.js"></script>
<script> <script>
$(document).ready(function() { $(document).ready(function() {
@ -227,7 +227,7 @@ $kanban = $ordered_kanban;
// Send AJAX request to update all column positions // Send AJAX request to update all column positions
$.ajax({ $.ajax({
url: 'post.php', url: 'ajax.php',
type: 'POST', type: 'POST',
data: { data: {
update_kanban_status_position: true, update_kanban_status_position: true,
@ -265,10 +265,18 @@ $kanban = $ordered_kanban;
//id of current status / column //id of current status / column
var columnId = $(target).data('status-id'); var columnId = $(target).data('status-id');
var movedTicketId = $(el).data('ticket-id');
var movedTicketStatusId = $(el).data('ticket-status-id');
cards.each(function(index, card) { cards.each(function(index, card) {
ticketId = $(card).data('ticket-id'); let ticketId = $(card).data('ticket-id');
statusId = $(card).data('ticket-status-id'); let statusId = $(card).data('ticket-status-id');
oldStatus = false;
if (ticketId == movedTicketId) {
oldStatus = movedTicketStatusId;
}
//update the status id of the card if needed //update the status id of the card if needed
if (statusId != columnId) { if (statusId != columnId) {
@ -278,6 +286,7 @@ $kanban = $ordered_kanban;
positions.push({ positions.push({
ticket_id: ticketId, ticket_id: ticketId,
ticket_kanban: index, ticket_kanban: index,
ticket_oldStatus: oldStatus,
ticket_status: statusId ?? null// Get the new status ID from the target column ticket_status: statusId ?? null// Get the new status ID from the target column
}); });
}); });
@ -285,7 +294,7 @@ $kanban = $ordered_kanban;
//console.log(positions); //console.log(positions);
// Send AJAX request to update all ticket kanban orders and statuses // Send AJAX request to update all ticket kanban orders and statuses
$.ajax({ $.ajax({
url: 'post.php', url: 'ajax.php',
type: 'POST', type: 'POST',
data: { data: {
update_kanban_ticket: true, update_kanban_ticket: true,
@ -300,11 +309,4 @@ $kanban = $ordered_kanban;
}); });
}); });
}); });
</script> </script>