Skip to content

Commit

Permalink
added unselect seat and it's working
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedtourab committed Jun 7, 2019
1 parent c83205b commit a27aaa8
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 30 deletions.
56 changes: 31 additions & 25 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 18 additions & 3 deletions Controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,29 @@ function checkSelectedSeat(){


}

function cancelSeatReservation(){
session_start();
global $myModel;
$timeDuration = 120; //in seconds
if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY']) > $timeDuration) {
$_SESSION=array();
session_destroy();
return 'timeout';
}
if(isset($_POST['row']) && isset($_POST['column']) && isset($_SESSION['CURRENT_USER_NAME']) ){
$row = $_POST['row'];
$column = $_POST['column'];
$reservingUser = null;
$myModel->updateSeatState('free',$reservingUser,$row,$column);
$_SESSION['LAST_ACTIVITY'] = time();
}
}
function reserveSeat(){

session_start();
global $myModel;
$timeDuration = 120; //in seconds
if (isset($_SESSION['LAST_ACTIVITY']) &&
(time() - $_SESSION['LAST_ACTIVITY']) > $timeDuration) {
if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY']) > $timeDuration) {
$_SESSION=array();
session_destroy();
return 'timeout';
Expand Down
6 changes: 6 additions & 0 deletions Controller/controllerHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
exit();
}

if(isset($_POST['cancelSeatReservation'])){
$result = $myController->cancelSeatReservation();
unset($_POST);
echo $result;
exit();
}

if(isset($_POST['purchaseSeatRequest'])){
$result = $myController->purchaseSeat();
Expand Down
25 changes: 23 additions & 2 deletions View/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ function selectSeat(seat) {

} else if (response.toString() === 'already_selected'){//selected by me that's mean that I want to unselect the seat because I pressed twice
seat.checked=false;
cancelSeatReservation(seat);
indexOfElementToRemove = selectedSeats.indexOf(seatID);
if (indexOfElementToRemove > -1) {
selectedSeats.splice(indexOfElementToRemove, 1);
Expand All @@ -113,11 +114,31 @@ function selectSeat(seat) {
}
});
}
function cancelSeatReservation(seat) {
let seatID = seat.id;
let regexStr = seatID.match(/[a-z]+|[^a-z]+/gi);
let seatRow = Number(regexStr[0]);
let seatColumn = regexStr[1];

$.ajax({
url: "../Controller/controllerHandler.php",
type: "POST", //send it through post method
data: {cancelSeatReservation: 'yes',row:seatRow,column:seatColumn},
dataType:"text",
success: function (response) {

},
error: function (xhr) {

//Do Something to handle error
}
});
}
function reserveSeatRequest(seat) {
let seatID = seat.id;
let seatRow = Number(seatID.charAt(0));
let seatColumn = seatID.charAt(1);
let regexStr = seatID.match(/[a-z]+|[^a-z]+/gi);
let seatRow = Number(regexStr[0]);
let seatColumn = regexStr[1];

$.ajax({
url: "../Controller/controllerHandler.php",
Expand Down

0 comments on commit a27aaa8

Please sign in to comment.