Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Rdv
- {
- private $_idRdv;
- private $_startRdv;
- private $_endRdv;
- function __construct($idRdv, $startRdv, $endRdv)
- {
- if($idRdv != null && $startRdv != null && $endRdv != null){
- $this->_idRdv = $idRdv;
- $this->_startRdv = $startRdv;
- $this->_endRdv = $endRdv;
- }
- }
- public function IdRdv()
- {
- return $this->_idRdv;
- }
- public function StartRdv()
- {
- return $this->_startRdv;
- }
- public function EndRdv()
- {
- return $this->_endRdv;
- }
- }
- function connectDb(){
- //CONNECTION BDD
- $user = 'root';
- $pass = '';
- try {
- $conn = new PDO('mysql:host=localhost;dbname=dbRDV', $user, $pass);
- $conn->exec("SET CHARACTER SET utf8");
- } catch (PDOException $e) {
- print "Erreur !: " . $e->getMessage() . "<br/>";
- die();
- }
- return $conn;
- }
- //FORMULAIRE
- function getDaysOfWeek($thisWeek)
- {
- if ($thisWeek) {
- if (date("w",time()) == 1) {
- $mondayD = date("Y-m-d",time());
- $monday = time();
- }
- else{
- $mondayD = date("Y-m-d",strtotime( "last monday" ));
- $monday = strtotime( "last monday" );
- }
- }
- else{
- }
- $tuesday = strtotime($mondayD. ' + 1 days');
- $wednesay = strtotime($mondayD. ' + 2 days');
- $thursday = strtotime($mondayD. ' + 3 days');
- $friday = strtotime($mondayD. ' + 4 days');
- $saturday = strtotime($mondayD. ' + 5 days');
- $sunday = strtotime($mondayD. ' + 6 days');
- $daysOfWeek = array($monday,$tuesday,$wednesay,$thursday,$friday,$saturday);
- return array($daysOfWeek,$sunday);
- }
- function setRdv($conn){
- if (!empty($_POST['firstname']) && !empty($_POST['lastname']) && !empty($_POST['date']) && !empty($_POST['time']) && !empty($_POST['coupe']) && (!empty($_POST['mail']) || !empty($_POST['sms']))) {
- if (isset($_POST['firstname']) && isset($_POST['lastname']) && isset($_POST['date']) && isset($_POST['time']) && isset($_POST['coupe']) && (isset($_POST['mail']) || isset($_POST['sms']))) {
- //get data from form
- $idCoiffure = $_POST['coupe'];
- $prenomClient = $_POST['firstname'];
- $nomClient = $_POST['lastname'];
- $dateChamp = $_POST['date'];
- $dateChamp = date_parse_from_format("Y-m-d", $dateChamp);
- $timeChamp = $_POST['time'];
- $timeChamp = date_parse_from_format("H:i", $timeChamp);
- $startRdv = date('c', mktime($timeChamp['hour'], $timeChamp['minute'], $timeChamp['second'],$dateChamp['month'], $dateChamp['day'], $dateChamp['year']));
- $gTempsC = $conn->prepare("SELECT tempsCoiffure FROM tCoiffures WHERE idCoiffure = :idCoiffure");
- $gTempsC->bindValue('idCoiffure', $idCoiffure, PDO::PARAM_STR);
- $gTempsC->execute();
- foreach ($gTempsC->fetchAll() as $row) {
- $tempsCoiffure = $row[tempsCoiffure];
- };
- $endRdv = date('c', strtotime('+'.$tempsCoiffure.' minutes', strtotime($startRdv)));
- $smsRdv = $_POST['tel'];
- $mailRdv = $_POST['email'];
- //set data on db
- $rPostRDV = $conn->prepare("INSERT INTO tRdvs(prenomClient, nomClient, startRdv, endRdv, smsRdv, mailRdv, idCoiffure) VALUES(?,?,?,?,?,?,?)");
- $rPostRDV->execute(array($prenomClient,$nomClient,$startRdv,$endRdv,$smsRdv,$mailRdv,$idCoiffure));
- $message = 'Vous avez bel et bien pris rendez-vous!';
- }
- }
- else{
- $error='Veuillez remplir tout les champs du formulaire!';
- }
- return array($error,$message);
- }
- function getRdvs($conn,$lundi,$dimanche){
- $rGetRdvs = $conn->prepare("SELECT tRdvs.*, tCoiffures.tempsCoiffure FROM tRdvs, tCoiffures WHERE UNIX_TIMESTAMP(startRdv) BETWEEN ? AND ?");
- $rGetRdvs->execute(array($lundi,$dimanche));
- $result = $rGetRdvs->fetchAll();
- return $result;
- }
- echo json_encode(getRdvs($conn,$daysOfWeek[0],$sunday));
- function getHours($conn){
- $rGetHours = $conn->prepare("SELECT hour FROM tHoursWork");
- $rGetHours->execute();
- $result = $rGetHours->fetchAll();
- return $result;
- }
- $conn = connectDb();
- $returnDOW = getDaysOfWeek(true);
- $daysOfWeek = $returnDOW[0];
- $sunday = $returnDOW[1];
- $msgs = setRdv($conn);
- $getRdvs = getRdvs($conn,$daysOfWeek[0],$sunday);
- $getHours = getHours($conn);
- //Calendar
- $hours = array('08:00','09:00','10:00','11:00','12:00','13:00','14:00','15:00','16:00','17:00','18:00');
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <link rel="shortcut icon" href="img/logo_simple.png">
- <link rel="icon" href="img/logo_simple.png">
- <title>Idée Coiffure</title>
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <!--MY CSS-->
- <link rel="stylesheet" type="text/css" href="css/css.css">
- <!--jQuery-->
- <script
- src="https://code.jquery.com/jquery-3.1.1.min.js"
- integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
- crossorigin="anonymous"></script>
- <link rel="shortcut icon" href="img/logo_simple.png">
- <link rel="icon" href="img/logo_simple.png">
- <title>Idée Coiffure</title>
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <!-- JS CALENDRIER-->
- <script src="scripts/calendrier.js"></script>
- <!--MY CSS-->
- <link rel="stylesheet" type="text/css" href="css/css.css">
- <!--My JavaScript-->
- <script type="text/javascript" src="scripts/script.js"></script>
- </head>
- <body>
- <a href="/functions/getRdvs.php">getRdvs.php</a>
- <div id="wrap">
- <?php include 'header.php'; ?>
- <div id="main">
- <div id="content_rdv">
- <table border="1px" class="tableprinc_calendrier">
- <tr>
- <td></td>
- <?php foreach ( $daysOfWeek as $day){ ?>
- <td><?php echo date("l",$day). ' ' .date('d-m-Y', $day);//echo date('Y-m-d', $day); ?></td>
- <?php } ?>
- </tr>
- <?php foreach ($getHours as $hour){ ?>
- <tr>
- <td><?php print_r(date('H:i', strtotime($hour[hour]))); ?></td>
- <?php foreach ( $daysOfWeek as $day){ ?>
- <td id="<?php echo date("l",$day) . '_' . date('H', strtotime($hour[hour])); ?>" class="calendrier_td"></td>
- <?php } ?>
- </tr>
- <?php } ?>
- </table>
- <input type="submit" id="sub_addRdv" value="Ajouter un rendez-vous">
- <div id="content_addRdv" >
- <table>
- <tr>
- <td>
- <form method="POST" action="rdv.php">
- <p>Prénom: <input type="text" name="firstname"> Nom: <input type="text" name="lastname"></p>
- <p>Date: <input type="date" name="date"> Heure: <input type="time" name="time"></p>
- <p>Choix de la coiffure: <select name="coupe">
- <?php
- foreach($conn->query('SELECT * from tCoiffures') as $row) {
- $idCoiffure = $row[idCoiffure];
- $nomCoiffure = $row[nomCoiffure];
- $descriptionCoiffure = $row[descriptionCoiffure];
- $tempsCoiffure = $row[tempsCoiffure];
- ?><option value="<?php echo $idCoiffure; ?>"> <?php echo $nomCoiffure; ?></option>
- <?php } ?>
- </select>
- </p>
- Confirmation par:
- <input id="chk_mail" class="chk_mailorsms" type="checkbox" value="mail" name="mail">MAIL
- <input id="chk_sms" class="chk_mailorsms" type="checkbox" value="sms" name="sms">SMS
- <br>
- <div id="div_mailorsms"></div>
- <br>
- <input id="submit_rdv" type="submit" name="submit" onclick=" <?php $submit='true'; ?> ">
- <span style="color:red"><?php echo $msgs[0]; ?></span><span style="color:green"><?php echo $msgs[1]; ?></span>
- <input type="hidden" id="tempsCoiffure" value="<?php echo $tempsCoiffure; ?>">
- </form>
- </td>
- </tr>
- </table>
- </div>
- </div>
- </div>
- <?php include 'footer.php'; ?>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement