-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajouter_vacances.php
62 lines (57 loc) · 1.86 KB
/
ajouter_vacances.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
session_start();
if (isset($_SESSION['privilege']) && $_SESSION['privilege']==1)
{
if ((!isset($_POST['debut']))||(!isset($_POST['fin']))||(!isset($_POST['description'])))
{
$_SESSION['erreur']="Tous les champs sont obligatoires.";
}
else
{
$_POST['debut'] = str_replace('/', '-', $_POST['debut']);
$_POST['debut']= date('Y-m-d', strtotime($_POST['debut']));
$_POST['fin'] = str_replace('/', '-', $_POST['fin']);
$_POST['fin']= date('Y-m-d', strtotime($_POST['fin']));
if ($_POST['debut']>$_POST['fin'])
{
$_SESSION['erreur']="La date de début des vacances doit être inférieure à la date de leur fin.";
}
else
{
require_once 'config.php';
$bdd->query('SET NAMES UTF8');
$debut=$_POST['debut'];
$fin=$_POST['fin'];
$vacances=$bdd->prepare('SELECT * from dates_vacances WHERE ((?>=debut) AND (?<=fin)) OR ((?<=debut) AND (?<=fin) AND (?>=debut)) OR ((?>=debut) AND (?>=fin) AND (?<=fin)) OR ((?<=debut) AND (?>=fin))');
$vacances->execute(array($debut, $fin, $debut, $fin, $fin, $debut, $fin, $debut, $debut, $fin));
$resultat=$vacances->fetch();
if ($resultat!=NULL)
{
$_SESSION['erreur']="Cet intervalle de date (ou en partie) conïncide avec une période de vacances déjà existantes, veuillez le modifier";
}
else
{
$requete=$bdd->prepare('INSERT INTO dates_vacances (debut, fin, description) VALUES (:debut, :fin, :description)');
$requete->execute(array(
'debut'=>$_POST['debut'],
'fin'=>$_POST['fin'],
'description'=>$_POST['description']
));
$_SESSION['erreur']='ok';
}
}
}
header("Location: gerer_vacances.php");
}
else
{
if (!isset($_SESSION['privilege']))
{
$_SESSION['lien']=$_SERVER['REQUEST_URI'];
header("Location: connexion.php");
exit;
}
header("Location: interface.php");
exit;
}
?>