Start repository

This commit is contained in:
tips-of-mine
2025-05-31 10:26:04 +02:00
commit 486d93a4f0
30 changed files with 5788 additions and 0 deletions

102
front/timeline.ajax.php Normal file
View File

@ -0,0 +1,102 @@
<?php
include ("../../../inc/includes.php");
// Check for AJAX request
header("Content-Type: application/json; charset=UTF-8");
// Check if plugin is activated
if (!Plugin::isPluginActive("soc")) {
http_response_code(404);
die(json_encode(['error' => 'Plugin not active']));
}
Session::checkLoginUser();
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
http_response_code(400);
die(json_encode(['error' => 'Invalid ID']));
}
$case_id = intval($_GET['id']);
// Check permission
if (!Session::haveRight("plugin_soc_case", READ)) {
http_response_code(403);
die(json_encode(['error' => 'Permission denied']));
}
$case = new PluginSocCase();
if (!$case->getFromDB($case_id)) {
http_response_code(404);
die(json_encode(['error' => 'Case not found']));
}
// Get timeline events
$timeline = [];
// Get case creation
$timeline[] = [
'date' => $case->fields['date_creation'],
'type' => 'creation',
'content' => __('Case created', 'soc')
];
// Get case updates from history
$log = new Log();
$logs = $log->getHistoryData($case, 0, 0, ['date_mod' => 'DESC']);
foreach ($logs as $entry) {
$timeline[] = [
'date' => $entry['date_mod'],
'type' => 'update',
'content' => sprintf(
__('%s updated %s from %s to %s', 'soc'),
$entry['user_name'],
$entry['field'],
$entry['old_value'],
$entry['new_value']
)
];
}
// Get related tickets
$case_ticket = new PluginSocCaseTicket();
$tickets = PluginSocCaseTicket::getTicketsForCase($case_id);
foreach ($tickets as $ticket_data) {
$timeline[] = [
'date' => $ticket_data['date_creation'],
'type' => 'ticket',
'content' => sprintf(
__('Ticket %s created: %s', 'soc'),
$ticket_data['id'],
$ticket_data['name']
),
'ticket_id' => $ticket_data['id']
];
}
// Get related changes
$case_change = new PluginSocCaseChange();
$changes = PluginSocCaseChange::getChangesForCase($case_id);
foreach ($changes as $change_data) {
$timeline[] = [
'date' => $change_data['date_creation'],
'type' => 'change',
'content' => sprintf(
__('Change %s created: %s', 'soc'),
$change_data['id'],
$change_data['name']
),
'change_id' => $change_data['id']
];
}
// Sort timeline by date (newest first)
usort($timeline, function($a, $b) {
return strtotime($b['date']) - strtotime($a['date']);
});
echo json_encode(['timeline' => $timeline]);