Upload via GUI (258 Dateien)
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
require_once __DIR__ . '/common.php';
|
||||
|
||||
api_require_method('GET', 'POST');
|
||||
$staff = api_require_staff();
|
||||
api_require_admin_or_permission($staff, 'manage_priorities');
|
||||
$pdo = get_db();
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
$plans = $pdo->query(
|
||||
'SELECT p.*,
|
||||
(SELECT COUNT(*) FROM departments d WHERE d.sla_plan_id = p.id) AS dept_count,
|
||||
(SELECT COUNT(*) FROM help_topics h WHERE h.sla_plan_id = p.id) AS topic_count
|
||||
FROM sla_plans p ORDER BY p.name'
|
||||
)->fetchAll();
|
||||
api_json(['items' => array_map(fn(array $p) => [
|
||||
'id' => (int) $p['id'],
|
||||
'name' => $p['name'],
|
||||
'responseHours' => (int) $p['response_hours'],
|
||||
'resolutionHours' => (int) $p['resolution_hours'],
|
||||
'isActive' => (bool) $p['is_active'],
|
||||
'notes' => $p['notes'],
|
||||
'departmentCount' => (int) $p['dept_count'],
|
||||
'helpTopicCount' => (int) $p['topic_count'],
|
||||
'updatedAt' => $p['updated_at'],
|
||||
], $plans)]);
|
||||
}
|
||||
|
||||
$body = api_request_body();
|
||||
$action = $body['action'] ?? '';
|
||||
$id = (int) ($body['id'] ?? 0);
|
||||
|
||||
try {
|
||||
if ($action === 'save') {
|
||||
$in = ['name' => $body['name'] ?? '', 'response_hours' => $body['responseHours'] ?? 0, 'resolution_hours' => $body['resolutionHours'] ?? 0, 'notes' => $body['notes'] ?? ''];
|
||||
if (array_key_exists('isActive', $body)) $in['is_active'] = $body['isActive'];
|
||||
$newId = sla_plan_save($pdo, $id, $in);
|
||||
audit_log($staff['id'], ($id === 0 ? 'SLA-Plan erstellt: ' : 'SLA-Plan aktualisiert: ') . trim((string) ($body['name'] ?? '')) . ' (Mobile App)');
|
||||
api_json(['id' => $newId]);
|
||||
}
|
||||
if ($action === 'delete') {
|
||||
$deleted = sla_plan_delete($pdo, $id);
|
||||
audit_log($staff['id'], "SLA-Plan gelöscht: {$deleted} (Mobile App)");
|
||||
api_json(['ok' => true]);
|
||||
}
|
||||
} catch (AdminModelException $e) {
|
||||
api_error($e->httpStatus(), $e->errorCode(), $e->getMessage());
|
||||
}
|
||||
|
||||
api_error(422, 'INVALID_ACTION', 'Unbekannte Aktion.');
|
||||
Reference in New Issue
Block a user