Advertisement
Guest User

Untitled

a guest
Jun 16th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.58 KB | None | 0 0
  1. <?php
  2.  
  3. class Rdv
  4. {
  5.     private $_idRdv;
  6.     private $_startRdv;
  7.     private $_endRdv;
  8.  
  9.     function __construct($idRdv, $startRdv, $endRdv)
  10.     {
  11.         if($idRdv != null && $startRdv != null && $endRdv != null){
  12.             $this->_idRdv = $idRdv;
  13.             $this->_startRdv = $startRdv;
  14.             $this->_endRdv = $endRdv;
  15.         }
  16.     }
  17.  
  18.     public function IdRdv()
  19. {
  20.     return $this->_idRdv;
  21. }
  22.  
  23. public function StartRdv()
  24. {
  25.     return $this->_startRdv;
  26. }
  27.  
  28. public function EndRdv()
  29. {
  30.     return $this->_endRdv;
  31. }
  32.  
  33.  
  34. }
  35.  
  36.  
  37.  
  38.  
  39. function connectDb(){
  40.     //CONNECTION BDD
  41.     $user = 'root';
  42.     $pass = '';
  43.     try {
  44.         $conn = new PDO('mysql:host=localhost;dbname=dbRDV', $user, $pass);
  45.         $conn->exec("SET CHARACTER SET utf8");
  46.  
  47.     } catch (PDOException $e) {
  48.         print "Erreur !: " . $e->getMessage() . "<br/>";
  49.         die();
  50.     }
  51.     return $conn;
  52.  
  53. }
  54.  
  55. //FORMULAIRE
  56.  
  57. function getDaysOfWeek($thisWeek)
  58. {
  59.     if ($thisWeek) {
  60.         if (date("w",time()) == 1) {
  61.             $mondayD = date("Y-m-d",time());
  62.             $monday = time();
  63.         }
  64.         else{
  65.             $mondayD = date("Y-m-d",strtotime( "last monday" ));
  66.             $monday = strtotime( "last monday" );
  67.         }
  68.     }
  69.     else{
  70.  
  71.     }
  72.     $tuesday = strtotime($mondayD. ' + 1 days');
  73.     $wednesay = strtotime($mondayD. ' + 2 days');
  74.     $thursday = strtotime($mondayD. ' + 3 days');
  75.     $friday = strtotime($mondayD. ' + 4 days');
  76.     $saturday = strtotime($mondayD. ' + 5 days');
  77.     $sunday = strtotime($mondayD. ' + 6 days');
  78.     $daysOfWeek = array($monday,$tuesday,$wednesay,$thursday,$friday,$saturday);
  79.     return array($daysOfWeek,$sunday);
  80. }
  81.  
  82. function setRdv($conn){
  83.  
  84.     if (!empty($_POST['firstname']) && !empty($_POST['lastname']) && !empty($_POST['date']) && !empty($_POST['time']) && !empty($_POST['coupe']) && (!empty($_POST['mail']) || !empty($_POST['sms']))) {
  85.  
  86.         if (isset($_POST['firstname']) && isset($_POST['lastname']) && isset($_POST['date']) && isset($_POST['time']) && isset($_POST['coupe']) && (isset($_POST['mail']) || isset($_POST['sms']))) {
  87.        
  88.             //get data from form
  89.             $idCoiffure = $_POST['coupe'];
  90.             $prenomClient = $_POST['firstname'];
  91.             $nomClient = $_POST['lastname'];
  92.             $dateChamp = $_POST['date'];
  93.             $dateChamp = date_parse_from_format("Y-m-d", $dateChamp);
  94.             $timeChamp = $_POST['time'];
  95.             $timeChamp = date_parse_from_format("H:i", $timeChamp);
  96.             $startRdv = date('c', mktime($timeChamp['hour'], $timeChamp['minute'], $timeChamp['second'],$dateChamp['month'], $dateChamp['day'], $dateChamp['year']));
  97.  
  98.  
  99.             $gTempsC = $conn->prepare("SELECT tempsCoiffure FROM tCoiffures WHERE idCoiffure = :idCoiffure");
  100.             $gTempsC->bindValue('idCoiffure', $idCoiffure, PDO::PARAM_STR);
  101.             $gTempsC->execute();
  102.             foreach ($gTempsC->fetchAll() as $row) {
  103.                 $tempsCoiffure = $row[tempsCoiffure];
  104.             };
  105.             $endRdv = date('c', strtotime('+'.$tempsCoiffure.' minutes', strtotime($startRdv)));
  106.  
  107.            
  108.             $smsRdv = $_POST['tel'];
  109.             $mailRdv = $_POST['email'];
  110.            
  111.            
  112.  
  113.  
  114.             //set data on db
  115.             $rPostRDV = $conn->prepare("INSERT INTO tRdvs(prenomClient, nomClient, startRdv, endRdv, smsRdv, mailRdv, idCoiffure) VALUES(?,?,?,?,?,?,?)");
  116.             $rPostRDV->execute(array($prenomClient,$nomClient,$startRdv,$endRdv,$smsRdv,$mailRdv,$idCoiffure));
  117.             $message = 'Vous avez bel et bien pris rendez-vous!';
  118.         }
  119.  
  120.     }
  121.     else{
  122.         $error='Veuillez remplir tout les champs du formulaire!';
  123.  
  124.     }
  125. return array($error,$message);
  126. }
  127.  
  128. function getRdvs($conn,$lundi,$dimanche){
  129.  
  130.  
  131.  
  132.  
  133.     $rGetRdvs = $conn->prepare("SELECT tRdvs.*, tCoiffures.tempsCoiffure  FROM tRdvs, tCoiffures WHERE UNIX_TIMESTAMP(startRdv) BETWEEN ? AND ?");
  134.     $rGetRdvs->execute(array($lundi,$dimanche));
  135.     $result = $rGetRdvs->fetchAll();
  136.     return $result;
  137. }
  138. echo json_encode(getRdvs($conn,$daysOfWeek[0],$sunday));
  139.  
  140. function getHours($conn){
  141.     $rGetHours = $conn->prepare("SELECT hour FROM tHoursWork");
  142.     $rGetHours->execute();
  143.     $result = $rGetHours->fetchAll();
  144.     return $result;
  145. }
  146.    
  147.     $conn = connectDb();
  148.     $returnDOW = getDaysOfWeek(true);
  149.     $daysOfWeek = $returnDOW[0];
  150.     $sunday = $returnDOW[1];
  151.     $msgs = setRdv($conn);
  152.     $getRdvs = getRdvs($conn,$daysOfWeek[0],$sunday);
  153.     $getHours = getHours($conn);
  154.    
  155.  
  156.  
  157.  
  158. //Calendar
  159.     $hours = array('08:00','09:00','10:00','11:00','12:00','13:00','14:00','15:00','16:00','17:00','18:00');
  160.  
  161. ?>
  162.  
  163.  
  164.  
  165. <!DOCTYPE html>
  166. <html>
  167. <head>
  168.  
  169.     <link rel="shortcut icon" href="img/logo_simple.png">
  170.     <link rel="icon" href="img/logo_simple.png">
  171.  
  172.     <title>Idée Coiffure</title>
  173.  
  174.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  175.  
  176.  
  177.  
  178.     <!--MY CSS-->
  179.     <link rel="stylesheet" type="text/css" href="css/css.css">
  180.  
  181.     <!--jQuery-->
  182.     <script
  183.   src="https://code.jquery.com/jquery-3.1.1.min.js"
  184.   integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
  185.   crossorigin="anonymous"></script>
  186.  
  187.     <link rel="shortcut icon" href="img/logo_simple.png">
  188.     <link rel="icon" href="img/logo_simple.png">
  189.  
  190.     <title>Idée Coiffure</title>
  191.  
  192.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  193.  
  194.     <!-- JS CALENDRIER-->
  195.     <script src="scripts/calendrier.js"></script>
  196.  
  197.     <!--MY CSS-->
  198.     <link rel="stylesheet" type="text/css" href="css/css.css">
  199.  
  200.    
  201.     <!--My JavaScript-->
  202.     <script type="text/javascript" src="scripts/script.js"></script>
  203.  
  204. </head>
  205. <body>
  206.  
  207.     <a href="/functions/getRdvs.php">getRdvs.php</a>
  208.  
  209.     <div id="wrap">
  210.         <?php include 'header.php'; ?>
  211.         <div id="main">
  212.             <div id="content_rdv">
  213.                 <table border="1px" class="tableprinc_calendrier">
  214.                     <tr>
  215.                         <td></td>
  216.                        
  217.                         <?php foreach ( $daysOfWeek as $day){ ?>
  218.                             <td><?php echo date("l",$day). ' ' .date('d-m-Y', $day);//echo date('Y-m-d', $day); ?></td>
  219.                         <?php } ?>
  220.                     </tr>
  221.  
  222.                     <?php foreach ($getHours as $hour){ ?>
  223.                     <tr>
  224.                     <td><?php print_r(date('H:i', strtotime($hour[hour]))); ?></td>
  225.                     <?php foreach ( $daysOfWeek as $day){ ?>
  226.                     <td id="<?php echo date("l",$day) . '_' . date('H', strtotime($hour[hour])); ?>" class="calendrier_td"></td>
  227.                     <?php } ?>
  228.  
  229.                     </tr>
  230.                     <?php } ?>
  231.                 </table>
  232.                 <input type="submit" id="sub_addRdv" value="Ajouter un rendez-vous">
  233.                 <div id="content_addRdv" >
  234.                     <table>
  235.                         <tr>
  236.                             <td>
  237.                                 <form method="POST" action="rdv.php">
  238.                                     <p>Prénom: <input type="text" name="firstname"> Nom: <input type="text" name="lastname"></p>
  239.                                     <p>Date: <input type="date" name="date"> Heure: <input type="time" name="time"></p>
  240.                                     <p>Choix de la coiffure: <select name="coupe">
  241.                                         <?php
  242.                                             foreach($conn->query('SELECT * from tCoiffures') as $row) {
  243.                                         $idCoiffure = $row[idCoiffure];
  244.                                         $nomCoiffure = $row[nomCoiffure];
  245.                                         $descriptionCoiffure = $row[descriptionCoiffure];
  246.                                         $tempsCoiffure = $row[tempsCoiffure];
  247.                                         ?><option value="<?php echo $idCoiffure; ?>"> <?php echo $nomCoiffure; ?></option>
  248.                                     <?php } ?>
  249.                                     </select>
  250.                                     </p>
  251.                                     Confirmation par:
  252.                                     <input id="chk_mail" class="chk_mailorsms" type="checkbox" value="mail" name="mail">MAIL
  253.                                     <input id="chk_sms" class="chk_mailorsms" type="checkbox" value="sms" name="sms">SMS
  254.                                     <br>
  255.                                     <div id="div_mailorsms"></div>
  256.                                     <br>
  257.                                     <input id="submit_rdv" type="submit" name="submit" onclick=" <?php $submit='true'; ?> ">
  258.                                     <span style="color:red"><?php echo $msgs[0]; ?></span><span style="color:green"><?php echo $msgs[1]; ?></span>
  259.                                     <input type="hidden" id="tempsCoiffure" value="<?php echo $tempsCoiffure; ?>">
  260.                                 </form>
  261.                             </td>
  262.                         </tr>
  263.                     </table>
  264.                 </div>
  265.             </div>
  266.         </div>
  267.         <?php include 'footer.php'; ?>
  268.     </div>
  269.    
  270. </body>
  271. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement