Created
November 21, 2023 11:02
-
-
Save cladjidane/0d1697449af8dc20510c99269776e040 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function checkTaskDeadline($task) { | |
$currentDate = new DateTime(); | |
$taskDate = DateTime::createFromFormat('Y-m-d', $task['date']); | |
$dateFormatted = $taskDate->format('d-m-Y'); | |
if ($taskDate < $currentDate) { | |
$daysPassed = $currentDate->diff($taskDate)->format('%a'); | |
$daysLimits = ['1' => 1, '2' => 3, '3' => 7]; | |
if ($daysPassed > $daysLimits[$task['priority']]) { | |
return "<span><span class=\"late\"></span>$dateFormatted ($daysPassed jour" . ($daysPassed > 1 ? 's' : '') . ")</span>"; | |
} | |
} | |
return "<span><span class=\"on-time\"></span>$dateFormatted</span>"; | |
} | |
function controllerTask(){ | |
$notice = ''; | |
$request_mode = $_REQUEST['mode'] ?? null; | |
if($request_mode) { | |
switch ($request_mode) { | |
case 'add': | |
$notice = addTask($_REQUEST); | |
break; | |
case 'update': | |
if($_REQUEST['id']) $notice = updateTask($_REQUEST['id']); | |
break; | |
case 'delete': | |
if($_REQUEST['id']) $notice = deleteTask($_REQUEST['id']); | |
break; | |
} | |
if($notice == '') $notice = 'Un problème est survenu'; | |
} | |
return $notice; | |
} | |
function addTask($data) { | |
$taskName = !empty($data['field-task']) ? $data['field-task'] : ($data['select-task'] ?? ''); | |
$taskPriority = $data['priority']; | |
$taskDate = $data['date']; | |
if (empty($taskName)) { | |
redirect_to('Veuillez saisir une tâche'); | |
} | |
$taskId = uniqid(); | |
$_SESSION['tasks'][$taskId] = ['task' => $taskName, 'id' => $taskId, 'status' => 'wip', 'priority' => $taskPriority, 'date' => $taskDate]; | |
redirect_to('La tâche a bien été ajoutée'); | |
} | |
function deleteTask($taskId) { | |
unset($_SESSION['tasks'][$taskId]); | |
redirect_to('La tâche a bien été supprimée'); | |
} | |
function updateTask($taskId) { | |
$_SESSION['tasks'][$taskId]['status'] = $_SESSION['tasks'][$taskId]['status'] === 'wip' ? 'finish' : 'wip'; | |
redirect_to('La tâche a bien été modifiée'); | |
} | |
function redirect_to($message){ | |
header('Location: /?notice='.$message); | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
/*
Organisation
1-Positionnement
2-Dimensions
3-Texte
4-Bordures et fonds
5-Propriétés CSS3 ou spécifiques navigateurs
*/
*,
::before,
::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
min-height: 100vh;
font-family: Arial, Helvetica, sans-serif;
background: radial-gradient(rgb(233, 233, 233), rgb(187, 187, 187));
padding-bottom: 100px;
}
h1 {
margin: 30px 0;
text-align: center;
font-size: 30px;
}
h2 {
text-align: center;
font-size: 20px;
}
h3 {
margin-bottom: 50px;
text-align: center;
font-size: 12px;
}
.notice {
padding: 20px;
width: 70%;
max-width: 1200px;
min-width: 320px;
margin: 20px auto 0;
border: 1px solid black;
border-radius: 10px;
background: rgb(178, 233, 177);
}
.list-todo {
width: 70%;
max-width: 1200px;
min-width: 320px;
margin: 20px auto 0;
list-style-type: none;
}
.list-todo li {
display: flex;
align-items: center;
width: 100%;
margin: 5px 0;
padding: 10px;
color: #333;
font-size: 15px;
background: #f1f1f1;
border-radius: 10px;
}
.list-todo li input {
width: 20px;
height: 20px;
margin-left: 10px;
pointer-events: none;
}
.list-todo li .btdelete {
height: 20px;
width: 20px;
margin-left: auto;
padding: 0;
background: transparent;
background-image: url('./ressources/fermer.svg');
border: none;
cursor: pointer;
}
.list-todo li .btdelete:hover {
opacity: .5;
}
.list-todo li > span {
margin-left: 10px;
font-size: 15px;
display: flex;
align-items: center;
gap: 10px;
}
.list-todo li > span > span {
padding: 5px 10px; background: black;
color: white;
font-size: 10px;
border-radius: 10px;
display: flex;
align-items: center;
}
.list-todo li .on-time {
display: inline-block;
width: 10px;
height: 10px;
margin-right: 5px;
pointer-events: none;
background-color: green;
border-radius: 10px;
}
.list-todo li .late {
display: inline-block;
width: 10px;
height: 10px;
margin-right: 5px;
pointer-events: none;
background-color: red;
border-radius: 10px;
}
.list-todo li.ok span {
text-decoration: line-through;
}
.form-add {
display: block;
max-width: 1200px;
min-width: 320px;
width: 70%;
margin: 0 auto;
padding: 20px;
background: white;
border-radius: 10px;
}
.form-add .fields {
display: flex;
align-items: center;
gap: 20px;
}
.form-add label {
display: block;
color: black;
font-size: 15px;
font-weight: bold;
}
.form-add select {
width: 50%;
margin: 10px 0;
padding: 12px 10px;
font-size: 15px;
}
.form-add input {
width: 50%;
margin: 10px 0;
padding: 10px;
font-size: 15px;
}
.form-add button {
padding: 10px;
font-size: 15px;
}
.form-checked {
display: flex;
align-items: center;
gap: 5px;
}
.form-checked button {
border: none;
background: silver;
font-size: 10px;
padding: 4px 3px;
}