pep malade
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
[2026-01-06T14:39:28+01:00] RAW INPUT: []
|
||||
[2026-01-06T14:39:28+01:00] RAW INPUT: [{"date":"2025-09-08","type":"PEP_SICK","duration":1}]
|
||||
[2026-01-06T14:40:04+01:00] RAW INPUT: [{"date":"2025-09-30","type":"OFF_CAROLE","person":"Carole","duration":1}]
|
||||
[2026-01-06T14:40:04+01:00] RAW INPUT: []
|
||||
[2026-01-06T14:40:52+01:00] RAW INPUT: [{"date":"2025-09-08","type":"PEP_SICK","duration":1}]
|
||||
[2026-01-06T14:40:52+01:00] RAW INPUT: []
|
||||
[2026-01-06T14:46:35+01:00] RAW INPUT: [{"date":"2025-09-22","type":"PEP_SICK","duration":1}]
|
||||
[2026-01-06T14:47:20+01:00] RAW INPUT: [{"date":"2025-09-29","type":"PEP_SICK","duration":1}]
|
||||
[2026-01-06T14:48:43+01:00] RAW INPUT: [{"date":"2025-09-30","type":"PEP_SICK","duration":1}]
|
||||
[2026-01-06T15:00:55+01:00] RAW INPUT: [{"date":"2025-09-29","type":"PEP_SICK","duration":1}]
|
||||
[2026-01-06T15:04:46+01:00] RAW INPUT: [{"date":"2025-10-17","type":"PEP_SICK","duration":1}]
|
||||
[2026-01-06T15:10:42+01:00] RAW INPUT: [{"date":"2025-10-21","type":"PEP_SICK","duration":1}]
|
||||
[2026-01-06T15:11:00+01:00] RAW INPUT: [{"date":"2025-10-24","type":"PEP_SICK","duration":1}]
|
||||
[2026-01-06T15:11:10+01:00] RAW INPUT: [{"date":"2025-12-02","type":"PEP_SICK","duration":1}]
|
||||
[2026-01-06T15:11:57+01:00] RAW INPUT: [{"date":"2025-09-23","type":"PEP_SICK","duration":1}]
|
||||
[2026-01-06T15:17:03+01:00] RAW INPUT: [{"date":"2025-09-10","type":"CENTRE","duration":1}]
|
||||
[2026-01-06T15:26:35+01:00] RAW INPUT: [{"date":"2025-10-06","type":"PEP_SICK","duration":1},{"date":"2025-10-07","type":"PEP_SICK","duration":1},{"date":"2025-10-08","type":"PEP_SICK","duration":1}]
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
require __DIR__ . '/../../../../includes/db.php';
|
||||
|
||||
try {
|
||||
$stmt = $pdo->query("SELECT id, event_date AS date, event_type AS type, person_id, duration FROM pf_events ORDER BY event_date");
|
||||
$events = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'events' => $events,
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Erreur lors de la récupération des événements : ' . $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
// api/get-leaves.php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
require __DIR__ . '/../../../../includes/db.php';
|
||||
|
||||
try {
|
||||
$stmt = $pdo->query("
|
||||
SELECT
|
||||
l.id,
|
||||
l.person_id,
|
||||
p.name AS person_name,
|
||||
l.leave_type,
|
||||
l.leave_date,
|
||||
l.duration
|
||||
FROM pf_leaves l
|
||||
JOIN pf_people p ON p.id = l.person_id
|
||||
ORDER BY l.leave_date, l.person_id
|
||||
");
|
||||
|
||||
$leaves = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'leaves' => $leaves,
|
||||
]);
|
||||
|
||||
} catch (PDOException $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require __DIR__ . '/../../../../includes/db.php';
|
||||
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
if (!isset($input['action'])) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['status' => 'error', 'message' => 'Action manquante.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$action = $input['action'];
|
||||
|
||||
try {
|
||||
if ($action === 'delete') {
|
||||
// Suppression d'un seul événement
|
||||
if (!isset($input['event_id'])) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['status' => 'error', 'message' => 'ID manquant pour la suppression.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$eventId = (int)$input['event_id'];
|
||||
$stmt = $pdo->prepare("DELETE FROM pf_events WHERE id = ?");
|
||||
$stmt->execute([$eventId]);
|
||||
|
||||
echo json_encode(['status' => 'success', 'message' => 'Événement supprimé.']);
|
||||
|
||||
} elseif ($action === 'update') {
|
||||
// Mise à jour d'un seul événement
|
||||
if (!isset($input['event_id'], $input['new_type'])) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['status' => 'error', 'message' => 'ID ou nouveau type manquant pour la mise à jour.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$eventId = (int)$input['event_id'];
|
||||
$newType = $input['new_type'];
|
||||
|
||||
$stmt = $pdo->prepare("UPDATE pf_events SET event_type = ? WHERE id = ?");
|
||||
$stmt->execute([$newType, $eventId]);
|
||||
|
||||
echo json_encode(['status' => 'success', 'message' => 'Événement mis à jour.']);
|
||||
|
||||
} elseif ($action === 'bulk_delete') {
|
||||
// Suppression en masse
|
||||
if (empty($input['event_ids']) || !is_array($input['event_ids'])) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['status' => 'error', 'message' => 'Liste event_ids manquante pour bulk_delete.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$eventIds = array_map('intval', $input['event_ids']);
|
||||
$eventIds = array_filter($eventIds, fn($id) => $id > 0);
|
||||
|
||||
if (empty($eventIds)) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['status' => 'error', 'message' => 'Aucun ID valide pour bulk_delete.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$placeholders = implode(',', array_fill(0, count($eventIds), '?'));
|
||||
$stmt = $pdo->prepare("DELETE FROM pf_events WHERE id IN ($placeholders)");
|
||||
$stmt->execute($eventIds);
|
||||
|
||||
echo json_encode(['status' => 'success', 'message' => 'Événements supprimés en masse.']);
|
||||
|
||||
} elseif ($action === 'bulk_update') {
|
||||
// Mise à jour en masse
|
||||
if (empty($input['event_ids']) || !is_array($input['event_ids']) || !isset($input['new_type'])) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['status' => 'error', 'message' => 'event_ids ou new_type manquant pour bulk_update.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$eventIds = array_map('intval', $input['event_ids']);
|
||||
$eventIds = array_filter($eventIds, fn($id) => $id > 0);
|
||||
$newType = $input['new_type'];
|
||||
|
||||
if (empty($eventIds)) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['status' => 'error', 'message' => 'Aucun ID valide pour bulk_update.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$placeholders = implode(',', array_fill(0, count($eventIds), '?'));
|
||||
$params = array_merge([$newType], $eventIds);
|
||||
|
||||
$stmt = $pdo->prepare("UPDATE pf_events SET event_type = ? WHERE id IN ($placeholders)");
|
||||
$stmt->execute($params);
|
||||
|
||||
echo json_encode(['status' => 'success', 'message' => 'Événements mis à jour en masse.']);
|
||||
|
||||
} else {
|
||||
http_response_code(400);
|
||||
echo json_encode(['status' => 'error', 'message' => 'Action non valide.']);
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
// api/manage-leaf.php
|
||||
header('Content-Type: application/json');
|
||||
require __DIR__ . '/../../../../includes/db.php';
|
||||
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
if (!isset($input['action'])) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['status' => 'error', 'message' => 'Action manquante.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$action = $input['action'];
|
||||
|
||||
try {
|
||||
if ($action === 'delete_day') {
|
||||
if (empty($input['date'])) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['status' => 'error', 'message' => 'Date manquante pour delete_day.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$dateObj = date_create($input['date']);
|
||||
if (!$dateObj) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['status' => 'error', 'message' => 'Date invalide.']);
|
||||
exit;
|
||||
}
|
||||
$leaveDate = $dateObj->format('Y-m-d');
|
||||
|
||||
$stmt = $pdo->prepare("DELETE FROM pf_leaves WHERE leave_date = ?");
|
||||
$stmt->execute([$leaveDate]);
|
||||
|
||||
echo json_encode(['status' => 'success', 'message' => 'Congés supprimés pour ce jour.']);
|
||||
|
||||
} else {
|
||||
http_response_code(400);
|
||||
echo json_encode(['status' => 'error', 'message' => 'Action non valide.']);
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require __DIR__ . '/../../../../includes/db.php';
|
||||
|
||||
$eventsToSave = json_decode(file_get_contents('php://input'), true);
|
||||
$rawInput = file_get_contents('php://input');
|
||||
file_put_contents(
|
||||
__DIR__ . '/events-debug.log',
|
||||
"[" . date('c') . "] RAW INPUT: " . $rawInput . PHP_EOL,
|
||||
FILE_APPEND
|
||||
);
|
||||
|
||||
$eventsToSave = json_decode($rawInput, true);
|
||||
|
||||
|
||||
if (empty($eventsToSave) || !is_array($eventsToSave)) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['status' => 'error', 'message' => 'Aucune donnée d\'événement reçue.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$inserted = [];
|
||||
|
||||
try {
|
||||
$pdo->beginTransaction();
|
||||
|
||||
$sql = "INSERT INTO pf_events (event_date, event_type, person_id, duration)
|
||||
VALUES (:event_date, :event_type, :person_id, :duration)";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
|
||||
foreach ($eventsToSave as $event) {
|
||||
$person_id = null;
|
||||
|
||||
// Si un nom de personne est fourni
|
||||
if (!empty($event['person'])) {
|
||||
$personStmt = $pdo->prepare("SELECT id FROM pf_people WHERE name = ?");
|
||||
$personStmt->execute([$event['person']]);
|
||||
$personRow = $personStmt->fetch();
|
||||
if ($personRow) {
|
||||
$person_id = $personRow['id'];
|
||||
}
|
||||
}
|
||||
|
||||
$stmt->execute([
|
||||
':event_date' => $event['date'],
|
||||
':event_type' => $event['type'],
|
||||
':person_id' => $person_id,
|
||||
':duration' => $event['duration'] ?? 1.0,
|
||||
]);
|
||||
|
||||
$inserted[] = [
|
||||
'id' => $pdo->lastInsertId(),
|
||||
'date' => $event['date'],
|
||||
'type' => $event['type'],
|
||||
'duration' => $event['duration'] ?? 1.0,
|
||||
'person_id' => $person_id,
|
||||
];
|
||||
}
|
||||
|
||||
$pdo->commit();
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'inserted' => $inserted,
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
$pdo->rollBack();
|
||||
http_response_code(500);
|
||||
echo json_encode(['status' => 'error', 'message' => 'Erreur lors de la sauvegarde : ' . $e->getMessage()]);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
// api/save-leaves.php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
require __DIR__ . '/../../../../includes/db.php';
|
||||
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
if (!is_array($input) || empty($input)) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['status' => 'error', 'message' => 'Données invalides (attendu tableau JSON).']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Exemple d'élément attendu :
|
||||
// { date: '2025-09-01', person_id: 2, leave_type: 'CP', duration: 1.0 }
|
||||
|
||||
$validLeaveTypes = ['CP', 'JRA', 'JA'];
|
||||
|
||||
try {
|
||||
$pdo->beginTransaction();
|
||||
|
||||
$stmtInsert = $pdo->prepare("
|
||||
INSERT INTO pf_leaves (person_id, leave_type, leave_date, duration)
|
||||
VALUES (:person_id, :leave_type, :leave_date, :duration)
|
||||
");
|
||||
|
||||
foreach ($input as $item) {
|
||||
$date = $item['date'] ?? null;
|
||||
$personId = $item['person_id'] ?? null;
|
||||
$leaveType = $item['leave_type'] ?? null;
|
||||
$duration = isset($item['duration']) ? (float)$item['duration'] : 1.0;
|
||||
|
||||
if (!$date || !$personId || !$leaveType) {
|
||||
continue; // on ignore les lignes incomplètes
|
||||
}
|
||||
|
||||
if (!in_array($leaveType, $validLeaveTypes, true)) {
|
||||
continue; // leave_type invalide
|
||||
}
|
||||
|
||||
// Normalisation de la date
|
||||
$dateObj = date_create($date);
|
||||
if (!$dateObj) {
|
||||
continue;
|
||||
}
|
||||
$leaveDate = $dateObj->format('Y-m-d');
|
||||
|
||||
$stmtInsert->execute([
|
||||
':person_id' => (int)$personId,
|
||||
':leave_type' => $leaveType,
|
||||
':leave_date' => $leaveDate,
|
||||
':duration' => $duration,
|
||||
]);
|
||||
}
|
||||
|
||||
$pdo->commit();
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'message' => 'Congés enregistrés.',
|
||||
]);
|
||||
|
||||
} catch (PDOException $e) {
|
||||
$pdo->rollBack();
|
||||
http_response_code(500);
|
||||
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
|
||||
}
|
||||
Reference in New Issue
Block a user