format('Y-m-d') . ' ' . $params['heure'] . ':00', $params['duree'], $params['id_patient'], $params['id_medecin']) !== FALSE) { if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){ $response = new Response(); $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=creation"); $response->send(); }else{ Response::quickResponse(200, json_encode([ 'status' => 'success', 'title' => 'Création effectuée!', 'message' => 'La consultation du '.$params['date']->format('d/m/Y').' à '.$params['heure'].' a bien été créée.' ])); } }else{ if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){ $response = new Response(); $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=error"); $response->send(); }else{ Response::quickResponse(200, json_encode([ 'status' => 'error', 'title' => 'Erreur de création!' ])); } } }else{ if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){ $response = new Response(); $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=error"); $response->send(); }else{ Response::quickResponse(200, json_encode([ 'status' => 'error', 'title' => 'Erreur de paramètre', 'message' => 'Date incorrecte' ])); } } } public function delete($params){ if(RDVRepo::delete($params['id_consultation']) !==FALSE){ if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){ $response = new Response(); $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=supression"); $response->send(); }else{ Response::quickResponse(200, json_encode([ 'status' => 'success', 'title' => 'Supression effectuée!', 'message' => 'La consultation a bien été supprimée.' ])); } }else{ if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){ $response = new Response(); $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=error"); $response->send(); }else{ Response::quickResponse(200, json_encode([ 'status' => 'error', 'title' => 'Erreur lors de la supression!' ])); } } } public function update($params){ if(StaticRepo::checkParam($params['date_naissance'],'Date')) { $params['date'] = DateTime::createFromFormat('d/m/Y', $params['date']); if (RDVRepo::updateDateTime($params['id_consultation'], $params['date']->format('Y-m-d') . ' ' . $params['heure'] . ':00') !== FALSE) { if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){ $response = new Response(); $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=maj"); $response->send(); }else{ Response::quickResponse(200, json_encode([ 'status' => 'success', 'title' => 'Modification effectuée!', 'message' => 'La consultation du '.$params['date']->format('d/m/Y').' à '.$params['heure'].'a bien été mis àjour.' ])); } }else{ if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){ $response = new Response(); $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=error"); $response->send(); }else{ Response::quickResponse(200, json_encode([ 'status' => 'error', 'title' => 'Erreur de mise a jour!' ])); } } }else{ if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){ $response = new Response(); $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=error"); $response->send(); }else{ Response::quickResponse(200, json_encode([ 'status' => 'error', 'title' => 'Erreur de paramètre', 'message' => 'Date incorrecte' ])); } } } public function getSVG($params){ $days = ['Mon'=>0,'Tue'=>1,'Wed'=>2,'Thu'=>3,'Fri'=>4,'Sat'=>5,'Sun'=>6]; $svgCalendar = " image/svg+xml Calendar "; $current = strtotime($params['mois']); //on range les rendez-vous dans un tableau avec leur jour comme clé $RDVTemp = RDVRepo::getByMonth($params['mois'].'-01'); $RDVs = []; foreach($RDVTemp as $rdv){ if(!isset($RDVs[date('j',strtotime($rdv['DateRDV']))])){ $RDVs[date('j',strtotime($rdv['DateRDV']))] = []; } array_push($RDVs[date('j',strtotime($rdv['DateRDV']))],$rdv); } foreach(range(1,date('t',strtotime($params['mois']))) as $day) { //génération du SVG de la journée //selon si on a une date sur un ou deux chiffres, on adapte $date = strftime("%B %Y", $current); if ($day >= 10) { $xDate = 1500; } else { $xDate = 1000; } //fond général + affichage de la date $svgCalendar .= ' ' . $day . ' ' . $date . ' '; //on défini le tableau si jamais if (!isset($RDVs[$day])) { $RDVs[$day] = []; } //on parcours les consultations du jour pour les afficher foreach ($RDVs[$day] as $key => $rdv) { $patient = PatientRepo::getById(intval($rdv['Patient_Id'])); $medecin = MedecinRepo::getById(intval($rdv['Medecin_id'])); //couleur suivant le nombre de consultation if ($key % 2 == 0) { $color = 'f9f9f9'; } else { $color = 'ececec'; } //du svg blablabla $yConsult = 1500 + 700 * $key; $svgCalendar .= ' ' . date('G:i', strtotime($rdv['DateRDV'])) . ' ' . $rdv['Minute'] . 'mn ' . $medecin['Prenom'] . ' ' . $medecin['Nom'] . ' ' . $patient['Prenom'] . ' ' . $patient['Nom'] . ' '; } $svgCalendar .= ''; } //on met u fond (sinon on voit les consultation en arrière plan) $svgCalendar .= ''; $svgCalendar.=''; //position x;y de base des jours du calendrier $x=1100*$days[date('D',$current)]; $y=0; //initialisation de variables $cal = []; $week=[]; //obligé de séparer la génération des consultation et du calendrier pour organiser le svg foreach(range(1,date('t',strtotime($params['mois']))) as $day){ //génération du svg du calendrier $day = date('D',$current); $day_nbr = date('d',$current); $week[$days[$day]] = date('d',$current); $current = strtotime("+1 day",$current); if($y/1100 % 2 == 0){ if($days[$day] % 2 == 0){$color='f0f0f0';}else{$color='fff';} $svgCalendar.=''; }else{ if($days[$day] % 2 != 0){$color='f0f0f0';}else{$color='fff';} $svgCalendar.=''; } $svgCalendar.=''.$day_nbr.''; $x+=1100; if($days[$day] == 6){ $i=0; array_push($cal,$week); $week = []; $y+=1100; $x=0; } } $svgCalendar .= ''; return $svgCalendar; } }