Advertisement
Guest User

Untitled

a guest
Mar 8th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.09 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Krist
  5. * Date: 08-Mar-18
  6. * Time: 10:38
  7. */
  8. $servername = "localhost";
  9. $username = "root";
  10. $password = "123456789";
  11. $dbname = "havnarbio";
  12.  
  13. $conn = new mysqli($servername, $username, $password, $dbname);
  14.  
  15. if($conn->connect_error){
  16. die("Connection failed: " .$conn->connect_error);
  17. }
  18. $sql = "SELECT * FROM ticket";
  19. $result = $conn->query($sql);
  20. $tickets = array();
  21.  
  22. $index = 0;
  23. while($row = mysqli_fetch_assoc($result)){ // loop to store the data in an associative array.
  24. $tickets[$index] = $row;
  25. $index++;
  26. }
  27.  
  28. ?>
  29.  
  30. <!DOCTYPE html>
  31. <html>
  32. <head>
  33. <meta charset="UTF-8">
  34. <title>Cinema Seating Plan Canvas</title>
  35. <script src="jquery-3.2.1.min.js"></script>
  36. <link rel="stylesheet" href="css/normalize.css" />
  37. <link rel="stylesheet" href="css/foundation.min.css" />
  38. <link rel="stylesheet" href="css/main.css" />
  39.  
  40. </head>
  41. <body>
  42. <canvas id="canvas1" width="500" height="390"></canvas>
  43. <script>
  44. var tickets = <?php echo json_encode($tickets); ?>;
  45.  
  46.  
  47.  
  48.  
  49. const STATE_GREEN = "rgb(13,114,0)";
  50. const STATE_BLUE = "rgb(0,0,255)";
  51. const STATE_WHITE = "rgb(255,255,255)"
  52. const SEAT_WIDTH = 22;
  53. const SEAT_HEIGHT = 22;
  54. var seats = [ ];
  55. var infoSeats = [ ];
  56. var canvas = document.getElementById("canvas1");
  57. var ctx = canvas.getContext("2d");
  58.  
  59. function createSeats() {
  60. //Creating the seats
  61. var seatId = 1;
  62. for (var i = 1; i < 320; i += 40) {
  63. for (var j = 1; j < 300; j += 30) {
  64. seats.push({pos: [j, i], state: STATE_GREEN, id: seatId, available: 0});
  65. seatId++;
  66. }
  67. }
  68.  
  69. infoSeats.push({pos:[340, 1], state: STATE_GREEN});
  70. infoSeats.push({pos:[340,30], state: STATE_WHITE});
  71. infoSeats.push({pos:[340,60], state: STATE_BLUE});
  72.  
  73.  
  74. addMovieTitle();
  75. draw();
  76. canvas.addEventListener('click', function (e) {
  77. var seatMinX;
  78. var seatMaxX;
  79. var seatMinY;
  80. var seatMaxY;
  81. for(var i = 0; i < seats.length; i++) {
  82. seatMinX = seats[i].pos[0];
  83. seatMaxX = seats[i].pos[0] + 30;
  84. seatMinY = seats[i].pos[1];
  85. seatMaxY = seats[i].pos[1] + 30;
  86.  
  87. if(seatMinX < e.pageX && e.pageX < seatMaxX) {
  88. if(seatMinY < e.pageY && e.pageY < seatMaxY) {
  89. if(seats[i].state !== STATE_WHITE && seats[i].state === STATE_BLUE){
  90. seats[i].state = STATE_GREEN
  91. }
  92. else if(seats[i].state !== STATE_WHITE && seats[i].state === STATE_GREEN){
  93. seats[i].state = STATE_BLUE;
  94. }
  95. draw();
  96. addPrice();
  97. }
  98. }
  99. }
  100. }, false);
  101. }
  102. function draw() {
  103. ctx.clearRect(0,0,canvas.width, canvas.height); //Clearing the canvas for redrawing
  104.  
  105. seats.forEach(function(x) {
  106. ctx.fillStyle = x.state;
  107. ctx.strokeRect(x.pos[0], x.pos[1], SEAT_WIDTH, SEAT_HEIGHT);
  108. ctx.fillRect(x.pos[0], x.pos[1], SEAT_WIDTH, SEAT_HEIGHT);
  109. });
  110. infoSeats.forEach(function(x) {
  111. ctx.fillStyle = x.state;
  112. ctx.strokeRect(x.pos[0], x.pos[1], SEAT_WIDTH, SEAT_HEIGHT);
  113. ctx.fillRect(x.pos[0], x.pos[1], SEAT_WIDTH, SEAT_HEIGHT);
  114. });
  115.  
  116. ctx.strokeRect(5,359,280,25);
  117. ctx.fillStyle = "black";
  118. ctx.font = ("20px Arial");
  119. ctx.fillText("Screen", 108,378);
  120. ctx.fillText("Available", 370, 20);
  121. ctx.fillText("Sold", 370, 49);
  122. ctx.fillText("Selected", 370, 79);
  123.  
  124. }
  125. function submitSeats() {
  126. for (var i = 0; i < seats.length; i++) {
  127. if (seats[i].state === STATE_BLUE) {
  128. seats[i].state = STATE_WHITE;
  129. seats[i].available = 1;
  130. //Send id og available to server
  131. draw();
  132. addPrice();
  133.  
  134.  
  135.  
  136. }
  137. }
  138. alert("Tín bílegging er skrásett");
  139. goBack();
  140. }
  141. function addPrice() {
  142. var tempPrice = 0;
  143. for (var i = 0; i < seats.length; i++) {
  144. if (seats[i].state === STATE_BLUE) {
  145. tempPrice += 90;
  146. }
  147. }
  148. var text = "Tín samlaði prísur er: ";
  149. var price = text.concat(tempPrice.toString());
  150.  
  151. $("#totalPrice").text(price);
  152. }
  153. function goBack() {
  154. window.history.back();
  155. }
  156. function addMovieTitle() {
  157. var title; //Get movie title from database
  158. $("#movieTitle").text(title);
  159. }
  160.  
  161.  
  162. window.addEventListener("load",createSeats, false);
  163.  
  164.  
  165. </script>
  166.  
  167. <form action="sendSeats.php" method="post">
  168. <button id="submit" onclick="submitSeats()">Keyp</button>
  169. </form>
  170. <button id="goBack" onclick="goBack()">Aftur</button>
  171. <p id="totalPrice"></p>
  172. <h1 id="movieTitle"></h1>
  173.  
  174. </div>
  175. </body>
  176. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement