/
propose.php
127 lines (105 loc) · 3.94 KB
/
propose.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
require_once 'modele/Membre.php';
require_once 'modele/SessionSurf.php';
require_once 'template.php';
//session_start();
class Propose_Form{
function __construct($details){
$this->response_status = 1;
$this->response_html = '';
$this->response_JeChercheSection = '';
$this->proposition = array();
$this->proposition = $details;
}
private function validateFields(){
if(!$this->proposition)
{
$this->response_html .= '<p style="color:red">Proposition Unset</p>';
$this->response_status = 0;
}
if (!isset($this->proposition['nomSpot']))
{
$this->response_html .= '<p style="color:red">Manque le Spot - Bizarre</p>';
$this->response_status = 0;
}
if (strlen($this->proposition['lieuDep'])==0)
{
$this->response_html .= '<p style="color:red">Saisir le lieu de départ.</p>';
$this->response_status = 0;
}
if (!isset($this->proposition['dateAller']))
{
$this->response_html .= '<p style="color:red">Saisir date aller.</p>';
$this->response_status = 0;
}else if (!isset($this->proposition['heureAller']))
{
$this->response_html .= '<p style="color:red">Saisir heure aller.</p>';
$this->response_status = 0;
}else
{
$this->proposition['dateAller'] = date('Y-m-d G:i:s',strtotime($this->proposition['dateAller'].' '.$this->proposition['heureAller']));
$dateAtester = new DateTime($this->proposition['dateAller']);
if ($dateAtester<=date_add(date_create(), new DateInterval('P1D'))) {
$this->response_status = 0;
$this->response_html .= '<p style="color:red">Saisir une date posterieure à la date du jour</p>';
}
}
if (!isset($this->proposition['dateRetour']) )
{
$this->response_html .= '<p style="color:red">Saisir date retour</p>';
$this->response_status = 0;
} else
{
$this->proposition['dateRetour'] = date('Y-m-d G:i:s',strtotime($this->proposition['dateRetour']));
if (isset($this->proposition['dateAller'])) {
$dateAllerObj = new DateTime($this->proposition['dateAller']);
$dateRetourObj = new DateTime($this->proposition['dateRetour']);
if ($dateAllerObj>$dateRetourObj) {
$this->response_html .= '<p style="color:red">Saisir date retour postérieure à la date de départ</p>';
$this->response_status = 0;
}
}
}
if ($this->proposition['noVeh']>-1) {
if ($this->proposition['nbrPlacesDispo']<=0) {
$this->response_html .= '<p style="color:red">Saisir nombre de places dispo supérieur à 0</p>';
$this->response_status = 0;
}
if ($this->proposition['nbrPlanchesDispo']<=0) {
$this->response_html .= '<p style="color:red">Saisir nombre de places pour les planches dispo supérieur à 0</p>';
$this->response_status = 0;
}
}
}
private function enregistrerSession(){
require_once 'modele/SessionSurf.php';
require_once 'modele/Membre.php';
$sessionSurf = new SessionSurf($this->proposition);
$sessionSurf->setOrganisateur($_SESSION['Membre']);
$manager = new SessionSurfsManager(null);
$manager->ajoutSession($sessionSurf,$this->proposition['nomSpot'],$this->proposition['noVeh'],$this->proposition['nbrPlacesDispo'],$this->proposition['nbrPlanchesDispo']);
$this->response_status = 1;
$this->response_html = '<p>Ok, Proposition enregistrée! Go to surf !!! Recharges la page pour voir apparaitre dans la section je cherche ta proposition</p>' ;
$sessionSurfEnBase = $manager->loadComplet($sessionSurf->noSes());
require_once 'template.php';
ob_start();
ecrireJeChercheSection();
$this->response_JeChercheSection = ob_get_contents();
ob_end_clean();
}
function sendRequest(){
$this->validateFields();
if($this->response_status)
{
$this->enregistrerSession();
}
$response = array();
$response['status'] = $this->response_status;
$response['html'] = $this->response_html;
$response['JeChercheSection'] = $this->response_JeChercheSection;
echo json_encode($response);
}
}
//$propose_form = new Propose_Form($_REQUEST);
//$propose_form->sendRequest();
?>