Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.67 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. require("databaseconnection.php");
  5. if (isset($_SESSION['admin'])) {
  6.     $SQL = "select isAdmin from users where login = '".$_SESSION['loggedlogin']."';";
  7.     $baza = new Database();
  8.     $baza->connect();
  9.     if($dane = $baza->query($SQL)){
  10.         if($dane->num_rows == 0){
  11.         }else{
  12.             while($row = $dane->fetch_assoc()){
  13.                 if($row['isAdmin']<1){
  14.                     header("location: index.php");
  15.                 }else{
  16.                     $status = $row['isAdmin'];
  17.                 }
  18.             }
  19.         }
  20.     }else{
  21.       header("location: index.php");
  22.     }
  23.   }
  24. require("HourModel.php");
  25.  
  26. $placeName = "Kort I";
  27.  
  28. $connection = new Database();
  29. if(isset($_GET['date'])){
  30.     $checkDate = $_GET['date'];
  31. }else{
  32. $checkDate = date("Y-m-d");
  33. }
  34. //echo("&date = ".date("Y-m-d"));
  35. $connection->connect();
  36. $sql = "Select * from objects order by name;";
  37. $dataQuery = $connection->query($sql);
  38.  
  39.  
  40. $tommorow = date('Y-m-d', strtotime("+1 days",strtotime($checkDate)));
  41. $yesterday = date('Y-m-d', strtotime("-1 days",strtotime($checkDate)));
  42. echo('
  43. <head>
  44.  
  45. <meta charset="utf-8" />
  46. <link rel="stylesheet" type="text/css" href="css/bootstrap-theme.min.css" />
  47. <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
  48. <link rel="stylesheet" type="text/css" href="style.css" />
  49. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
  50. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
  51.  
  52. <style>
  53.    .tab{
  54.        display:inline-block;
  55.    }
  56.  
  57.  
  58. </style>
  59. </head>
  60. ');
  61.  
  62. echo("<button class='btn orange wielkosc6' onclick='location.reload();'>Odśwież</button>");
  63.  
  64. echo("<h1>Sprawdzam dzien:".$checkDate."</h1>");
  65.  
  66. echo("<b><h3><div style='display:inline-block; margin-right: 7px;' onclick='before();'> <- </div>");
  67. echo("<div style='display:inline-block;' onclick='after();'> -> </div></h3></b>");
  68.  
  69. if($dataQuery->num_rows<1){
  70.     exit();
  71. }
  72. echo("
  73. <script>
  74. function after(){
  75. window.location.replace('/tabela.php?date=".$tommorow."');
  76. }
  77. function before(){
  78.    window.location.replace('/tabela.php?date=".$yesterday."');
  79.    }
  80. </script>
  81.  
  82.  
  83. ");
  84.     echo("<div class='row'>");
  85. echo("<div class='center-block alert alert-primary  '  style='margin-top:60px;' >");
  86. while($r = $dataQuery->fetch_assoc()){
  87.     $placeName = $r['name'];
  88.     $placeAddress = $r['address'];
  89.     $placeId = $r['object_id'];
  90.     $category = $r['category'];
  91.  
  92.  
  93. $testModel = getTestHourModel();
  94.  echo("<div class='center-block marginek3 marginek4'>");
  95.     echo("<div class=' row ' style='width: 200px; display: inline-block; margin:15px;'>");
  96.     echo("<h2>".$placeName."</h2>");
  97.     $actualDate = date("Y-m-d");
  98.     $actualHour = date("H");
  99.  
  100. foreach($testModel as $model){
  101.     $arr = array($placeName,$placeAddress,$model->fromHour,$model->toHour,$checkDate,$placeId);
  102.     $json = json_encode($arr);
  103.     $jsondecoded = json_decode($json);
  104.     $dw = date( "w", strtotime($_GET['date']));
  105.  
  106.  
  107.     if(checkHourIsReserved($placeId,$jsondecoded[2],$checkDate)){
  108.      
  109.             echo("<div class='blue wolne marginek5' style='border: 1px solid white; margin: 0 0 0 0;font-weight: bold;text-align: center; '>".$jsondecoded[2].":00 - ".$jsondecoded[3].":00<br>".' WOLNE </div>');
  110.  
  111.         }else{
  112.             $SQL = "select * from staticReservations where dayOfWeek=".$dw." and hour_from=".$jsondecoded[2]." and object_id=".$placeId.";";
  113.             if($datax = $connection->query($SQL)){
  114.                
  115.                  while($roww = $datax->fetch_assoc()){
  116.                      echo("<div  class='zajete marginek5'   style='border: 1px solid white; font-weight: bold;text-align: center; background-color: rgba(224,0,0,0.4);'>".$jsondecoded[2].":00 - ".$jsondecoded[3].":00<br><b>".' ('.$roww['teamName'].')</b></div>');              
  117.                  }
  118.              }            
  119.             $SQL = "select * from unregister_reservations where hour_from = ".$jsondecoded[2]." AND DATE = '".$checkDate."' and object_id=".$placeId." ;";
  120.      
  121.        
  122.             if($datax = $connection->query($SQL)){
  123.                
  124.                 while($roww = $datax->fetch_assoc()){
  125.                     echo("<div  class='zajete marginek5'   style='border: 1px solid white; font-weight: bold;text-align: center; background-color: rgba(224,0,0,0.4);'>".$jsondecoded[2].":00 - ".$jsondecoded[3].":00<br>".' ('.$roww['nickname'].') - niezarej</div>');              
  126.                 }
  127.             }
  128.             $SQL = "SELECT *
  129.                    FROM
  130.                        reservation_details
  131.                    INNER JOIN
  132.                        reservations ON reservation_details.hour_from = ".$jsondecoded[2]."
  133.                    AND DATE =  
  134.                        '".$checkDate."'
  135.                    AND
  136.                        reservation_details.detail_id = reservations.detail_id
  137.                    INNER JOIN
  138.                        users ON users.user_id = reservations.client_id
  139.                    LIMIT 1;";
  140.                  
  141.             if($data = $connection->query($SQL)){
  142.                 if($data->num_rows==1){
  143.                 while($row = $data->fetch_assoc()){
  144.                     echo("<div class='zajete marginek5'  style='border: 1px solid white; font-weight: bold;text-align: center; background-color: rgba(224,0,0,0.4);'>".$jsondecoded[2].":00 - ".$jsondecoded[3].":00 <br>".' ('.$row['login'].')'.$row['name'].' '.$row['surname'].' </div>');      
  145.                    // echo($SQL);
  146.                 }
  147.             }
  148.         }
  149.  
  150.                      
  151.            
  152.  
  153.         }
  154.     }
  155.         echo("</div>");  
  156.     echo("</div>");
  157.  
  158. }
  159. echo("</div></div>");
  160. function checkHourIsReserved($objectId,$hourFrom,$data){
  161.     $SQL = 'SELECT * FROM reservation_details where object_id = '.$objectId.' AND hour_From = '.$hourFrom.' AND date = "'.$data.'";';
  162.     $connection = new Database();
  163.     $connection->connect();
  164.     $dataQueryy = $connection->query($SQL);
  165.     if($dataQueryy->num_rows>0){
  166.             return false;
  167.     }else{
  168.         $SQL = 'SELECT * FROM unregister_reservations where object_id = '.$objectId.' AND hour_From = '.$hourFrom.' AND date = "'.$data.'";';
  169.         $dataQueryy = $connection->query($SQL);
  170.         if($dataQueryy->num_rows>0){
  171.             return false;
  172.         }
  173.         else{
  174.  
  175.             $dw = date( "w", strtotime($data));
  176.             $SQL = "select * from staticReservations where dayOfWeek=".$dw." and hour_from=".$hourFrom." and object_id=".$objectId.";";
  177.        
  178.             $dataQueryy = $connection->query($SQL);
  179.             if($dataQueryy->num_rows>0){
  180.                
  181.                 return false;
  182.             }else{
  183.                 $SQL = "";
  184.                
  185.                 return true;
  186.             }
  187.  
  188.         }
  189.     }
  190. }
  191.  
  192. function getTestHourModel(){
  193.     $hourModel = array();
  194.     for($i = 7 ;$i<22;$i++){
  195.     $hourModel[] = new HourModel($i,$i+1);
  196.     }
  197.  
  198.     return $hourModel;
  199. }
  200. echo('          <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"
  201. integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous">
  202. </script>
  203. <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"
  204. integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous">
  205. </script>
  206. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"
  207. integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous">
  208. </script>');
  209. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement