Create rappel systeme

This commit is contained in:
Tutur33
2023-12-01 14:51:33 +01:00
parent 450cef915a
commit 0416825f1d
3 changed files with 103 additions and 3 deletions
+38 -3
View File
@@ -72,7 +72,25 @@ $monthName = $months[$month];
echo("<td></td>");
}
for ($i=6-$day; $i <7 ; $i++) {
echo("<td>$nbr</td>");
$today = (date("j") == $nbr and date("n") == $month and date("Y") == $year) ? "class='today'" : "";
echo("<td $today>$nbr");
foreach ($_COOKIE as $nom_cookie => $valeur_cookie) {
$cut = explode("-", $nom_cookie);
if (count($cut) >= 3) {
$rappelday = $cut[0];
$rappelmonth = $cut[1];
$rappelyear = $cut[2];
$rappel = ($rappelday == $nbr and $rappelmonth == $month and $rappelyear == $year) ? "<br>$valeur_cookie" : "";
} else {
$rappel = "error rappel";
}
echo($rappel);
}
echo("</td>");
$nbr++;
}
@@ -84,8 +102,24 @@ $monthName = $months[$month];
}
$today = (date("j") == $nbr and date("n") == $month and date("Y") == $year) ? "class='today'" : "";
echo("<td $today>$nbr</td>");
echo("<td $today>$nbr");
foreach ($_COOKIE as $nom_cookie => $valeur_cookie) {
$cut = explode("-", $nom_cookie);
if (count($cut) >= 3) {
$rappelday = $cut[0];
$rappelmonth = $cut[1];
$rappelyear = $cut[2];
$rappel = ($rappelday == $nbr and $rappelmonth == $month and $rappelyear == $year) ? "<br>$valeur_cookie" : "";
} else {
$rappel = "error rappel";
}
echo($rappel);
}
echo("</td>");
$nbr++;
}
echo("</tr>");
@@ -94,5 +128,6 @@ $monthName = $months[$month];
</tr>
</table>
</main>
<a href="index.php">back -></a>
</body>
</html>
+27
View File
@@ -0,0 +1,27 @@
<?php
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
// Génère une chaîne aléatoire de la longueur spécifiée
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[mt_rand(0, strlen($characters) - 1)];
}
return $randomString;
}
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$rappel = $_POST['rappel'];
$id = generateRandomString();
$name = urlencode("$day-$month-$year-$id");
setcookie("$name", "$rappel", time() + 315360000, "/");
header("Location: index.php");
exit;
?>
+38
View File
@@ -63,5 +63,43 @@
<p>The calendar generated will display the days of the week as well as the dates for the selected month and year.</p>
</section>
</main>
<main>
<h2>Add a rappel :</h2>
<form method="post" action="create_rappel.php">
<label for="">Day :</label>
<select name="day">
<?php
for ($j = 1; $j <= 31; $j++) {
$selected = ($j == date("d")) ? 'selected' : '';
echo "<option value='$j' $selected>$j</option>";
}
?>
</select>
<label for="">Month :</label>
<select name="month">
<?php
foreach ($months as $value => $label) {
$selected = ($value == date("n")) ? 'selected' : '';
echo "<option value='$value' $selected>$label</option>";
}
?>
</select>
<label for="">Year :</label>
<select name="year">
<?php
for ($i = date("Y")-100; $i <= date("Y")+100; $i++) {
$selected = ($i == date("Y")) ? 'selected' : '';
echo "<option value='$i' $selected>$i</option>";
}
?>
</select>
<label for="rappel">Rappel :</label>
<input type="text" name="rappel" required>
<button type="submit">Validate</button>
</form>
</main>
</body>
</html>