sub_design_seat_20211007204453.php 14.5 KB
<?php

    session_start();

	include "db_connect.php";

    $logUserid = mysqli_real_escape_string($con,$_POST['logUserid']);
    $train_id = mysqli_real_escape_string($con,$_POST['train_id']);
    $train_start_station = mysqli_real_escape_string($con,$_POST['train_start_station']);
    $seat_design = mysqli_real_escape_string($con,$_POST['seat_design']);

    $sql1 = "SELECT * FROM summarypredict WHERE logUserid = '$logUserid' ";
    $result1 = mysqli_query($con,$sql1) or die(mysqli_error($con));
    $row1 = mysqli_fetch_assoc($result1);

    $predict_line = $row1['seatlineno']; // Predicted value

    $sql2 = "SELECT * FROM train_info WHERE logUserId = '$logUserid' AND train_id = '$train_id' AND train_start_station = '$train_start_station' ";
    $result2 = mysqli_query($con,$sql2) or die(mysqli_error($con));
    $row2 = mysqli_fetch_assoc($result2);

    $train_arrival = $row2['train_arrival']; //Arrival Time
    $train_date = $row2['train_date']; // Train Date

	$sql5 = "SELECT * FROM seat_line_priority WHERE `line` = $predict_line ORDER BY priority";
	$result5 = mysqli_query($con,$sql5) or die(mysqli_error($con));
	$go_loop = 1;
	while($row5 = mysqli_fetch_array($result5)){
		$best_line = $row5['next_line'];

		for($i = 1; $i <= 4; $i++ ){
			$sql6 = "SELECT * FROM select_seat WHERE `train_id` = '$train_id' AND `date` = '$train_date' AND `arrival` = '$train_arrival' AND `row` = '$i' AND `seat` = '$best_line'";
			$result6 = mysqli_query($con,$sql6) or die(mysqli_error($con));
			$rowcount6 = mysqli_num_rows($result6);	

			if($rowcount6 == 0) {

				$sql8 = "SELECT * FROM select_seat_temp WHERE `logUserid` = '$logUserid' AND `train_id` = '$train_id' AND `train_start_station` = '$train_start_station' AND `date` = '$train_date' AND `arrival` = '$train_arrival' ";
				$result8 = mysqli_query($con,$sql8) or die(mysqli_error($con));
    			$rowcount8 = mysqli_num_rows($result8);

				if($rowcount8 == 1) {
					$sql9 = "DELETE FROM `best_seat` WHERE `logUserid` = '$logUserid' AND `train_id` = '$train_id' AND `train_start_station` = '$train_start_station' AND `date` = '$train_date' AND `arrival` = '$train_arrival' ";
					$result9 = mysqli_query($con,$sql9) or die(mysqli_error($con));
				} 
				
				$sql7 = "INSERT INTO `best_seat`(`logUserid`, `train_id`, `date`, `arrival`, `train_start_station`, `row`, `seat`) VALUES ('$logUserid', '$train_id', '$train_date', '$train_arrival', '$train_start_station', '$i', '$best_line')";
				$result7 = mysqli_query($con,$sql7) or die(mysqli_error($con));

				$go_loop = 0;
				break;
			}

		}

		if($go_loop == 0) {
			break;
		}

	}


    if($seat_design == 1) {
    ?>
        <div class="modal fade" id="<?php echo "train_".$train_id."_".$train_start_station ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
						<div class="modal-dialog modal-lg" role="document">
							<div class="modal-content">
							<div class="modal-header">
								<h5 class="modal-title" id="exampleModalLabel">Seat Plan </h5>
								<button type="button" class="close" data-dismiss="modal" aria-label="Close">
								<span aria-hidden="true">&times;</span>
								</button>
							</div>
							<?php  ?>
							<div class="modal-body">

							<!-- Start -->

							<div class="container-fluid" style="border: 1px solid rgb(223, 222, 222); border-radius: 10px; margin-bottom: 3%;">
											<div class="row" style="margin-bottom: 1%; margin-top: 3%;">
												<div class="col-sm-12 col-md-12 col-lg-12">
													<h6  style="text-align: center; font-size: 25px;" > Window Side </h6>
												</div>
											</div>
											<div class="row" style="margin-bottom: 3%;">
												<div class="col-xl-1 col-lg-1 col-md-1 col-sm-1 col-1" style="margin-top:1%;">
													<b style="font-size:13px;">E</b>
												</div>
                                            <?php
                                                $r = 1;
                                                for($i = 1; $i <= 10; $i++){

													$sql3 = "SELECT * FROM select_seat_temp WHERE `logUserid` = '$logUserid' AND `train_id` = '$train_id' AND `train_start_station` = '$train_start_station' AND `date` = '$train_date' AND `arrival` = '$train_arrival' AND `row` = '$r' AND `seat` = '$i'";
													$result3 = mysqli_query($con,$sql3) or die(mysqli_error($con));
													$rowcount3 = mysqli_num_rows($result3);
											?>
												<div class="col-xl-1 col-lg-1 col-md-1 col-sm-1 col-1" id="div_<?php echo $r?>_<?php echo $i ?>">
											<?php

													$sql4 = "SELECT * FROM select_seat WHERE `train_id` = '$train_id' AND `date` = '$train_date' AND `arrival` = '$train_arrival' AND `row` = '$r' AND `seat` = '$i'";
													$result4 = mysqli_query($con,$sql4) or die(mysqli_error($con));
													$rowcount4 = mysqli_num_rows($result4);													

													if($rowcount3 == 0) {

														if($rowcount4 == 0) {
											?>
													<button class="btn btn-primary" onclick="selectSeat('<?php echo $logUserid ?>','<?php echo $train_id ?>','<?php echo $train_start_station ?>','<?php echo $r?>','<?php echo $i ?>','no');" id="seatbtn_<?php echo $r?>_<?php echo $i ?>">1</button>

											<?php
														} else if($rowcount4 == 1) {
											?>

													<button class="btn btn-danger tooltip" id="seatbtn_<?php echo $r?>_<?php echo $i ?>" disabled>1 <span class="tooltiptext">Selected Seat</span></button>
													
											<?php
														}

													} else if($rowcount3 == 1) {
											?>
													<button class="btn btn-success" onclick="selectSeat('<?php echo $logUserid ?>','<?php echo $train_id ?>','<?php echo $train_start_station ?>','<?php echo $r?>','<?php echo $i ?>','yes');" id="seatbtn_<?php echo $r?>_<?php echo $i ?>">1</button>

											<?php

													}
                                            ?>
													
												</div>

                                            <?php
                                                }
                                            ?>
												<div class="col-xl-1 col-lg-1 col-md-1 col-sm-1 col-1" style="margin-top:1%;">
													<b style="font-size:13px;">E</b>
												</div>
											</div>
											
											<div class="row" style="margin-bottom: 3%;">
												<div class="col-xl-1 col-lg-1 col-md-1 col-sm-1 col-1" style="margin-top:1%;">
													<b style="font-size:13px;">E</b>
												</div>
												<?php
                                                $r = 2;
                                                for($i = 1; $i <= 10; $i++){

													$sql3 = "SELECT * FROM select_seat_temp WHERE `logUserid` = '$logUserid' AND `train_id` = '$train_id' AND `train_start_station` = '$train_start_station' AND `date` = '$train_date' AND `arrival` = '$train_arrival' AND `row` = '$r' AND `seat` = '$i'";
													$result3 = mysqli_query($con,$sql3) or die(mysqli_error($con));
													$rowcount3 = mysqli_num_rows($result3);
											?>
												<div class="col-xl-1 col-lg-1 col-md-1 col-sm-1 col-1" id="div_<?php echo $r?>_<?php echo $i ?>">
											<?php

													$sql4 = "SELECT * FROM select_seat WHERE `train_id` = '$train_id' AND `date` = '$train_date' AND `arrival` = '$train_arrival' AND `row` = '$r' AND `seat` = '$i'";
													$result4 = mysqli_query($con,$sql4) or die(mysqli_error($con));
													$rowcount4 = mysqli_num_rows($result4);													

													if($rowcount3 == 0) {

														if($rowcount4 == 0) {
											?>
													<button class="btn btn-primary" onclick="selectSeat('<?php echo $logUserid ?>','<?php echo $train_id ?>','<?php echo $train_start_station ?>','<?php echo $r?>','<?php echo $i ?>','no');" id="seatbtn_<?php echo $r?>_<?php echo $i ?>">1</button>

											<?php
														} else if($rowcount4 == 1) {
											?>

													<button class="btn btn-danger tooltip" id="seatbtn_<?php echo $r?>_<?php echo $i ?>" disabled>1 <span class="tooltiptext">Selected Seat</span></button>
													
											<?php
														}

													} else if($rowcount3 == 1) {
											?>
													<button class="btn btn-success" onclick="selectSeat('<?php echo $logUserid ?>','<?php echo $train_id ?>','<?php echo $train_start_station ?>','<?php echo $r?>','<?php echo $i ?>','yes');" id="seatbtn_<?php echo $r?>_<?php echo $i ?>">1</button>

											<?php

													}
                                            ?>
													
												</div>

                                            <?php
                                                }
                                            ?>
												<div class="col-xl-1 col-lg-1 col-md-1 col-sm-1 col-1" style="margin-top:1%;">
													<b style="font-size:13px;">E</b>
												</div>
											</div>

											<div class="row" style="margin-top: 4%; margin-bottom: 4%;">
												<div class="col-sm-12 col-md-12 col-lg-12">
													<h6 style="text-align: center; font-size: 25px;"> Aisle Side </h6>
												</div>
											</div>

											<div class="row" style="margin-bottom: 3%;">
												<div class="col-xl-1 col-lg-1 col-md-1 col-sm-1 col-1" style="margin-top:1%;">
													<b style="font-size:13px;">E</b>
												</div>
												<?php
                                                $r = 3;
                                                for($i = 1; $i <= 10; $i++){

													$sql3 = "SELECT * FROM select_seat_temp WHERE `logUserid` = '$logUserid' AND `train_id` = '$train_id' AND `train_start_station` = '$train_start_station' AND `date` = '$train_date' AND `arrival` = '$train_arrival' AND `row` = '$r' AND `seat` = '$i'";
													$result3 = mysqli_query($con,$sql3) or die(mysqli_error($con));
													$rowcount3 = mysqli_num_rows($result3);
											?>
												<div class="col-xl-1 col-lg-1 col-md-1 col-sm-1 col-1" id="div_<?php echo $r?>_<?php echo $i ?>">
											<?php

													$sql4 = "SELECT * FROM select_seat WHERE `train_id` = '$train_id' AND `date` = '$train_date' AND `arrival` = '$train_arrival' AND `row` = '$r' AND `seat` = '$i'";
													$result4 = mysqli_query($con,$sql4) or die(mysqli_error($con));
													$rowcount4 = mysqli_num_rows($result4);													

													if($rowcount3 == 0) {

														if($rowcount4 == 0) {
											?>
													<button class="btn btn-primary" onclick="selectSeat('<?php echo $logUserid ?>','<?php echo $train_id ?>','<?php echo $train_start_station ?>','<?php echo $r?>','<?php echo $i ?>','no');" id="seatbtn_<?php echo $r?>_<?php echo $i ?>">1</button>

											<?php
														} else if($rowcount4 == 1) {
											?>

													<button class="btn btn-danger tooltip" id="seatbtn_<?php echo $r?>_<?php echo $i ?>" disabled>1 <span class="tooltiptext">Selected Seat</span></button>
													
											<?php
														}

													} else if($rowcount3 == 1) {
											?>
													<button class="btn btn-success" onclick="selectSeat('<?php echo $logUserid ?>','<?php echo $train_id ?>','<?php echo $train_start_station ?>','<?php echo $r?>','<?php echo $i ?>','yes');" id="seatbtn_<?php echo $r?>_<?php echo $i ?>">1</button>

											<?php

													}
                                            ?>
													
												</div>

                                            <?php
                                                }
                                            ?>
												<div class="col-xl-1 col-lg-1 col-md-1 col-sm-1 col-1" style="margin-top:1%;">
													<b style="font-size:13px;">E</b>
												</div>
											</div>

											<div class="row" >
												<div class="col-xl-1 col-lg-1 col-md-1 col-sm-1 col-1" style="margin-top:1%;">
													<b style="font-size:13px;">E</b>
												</div>
												<?php
                                                $r = 4;
                                                for($i = 1; $i <= 10; $i++){

													$sql3 = "SELECT * FROM select_seat_temp WHERE `logUserid` = '$logUserid' AND `train_id` = '$train_id' AND `train_start_station` = '$train_start_station' AND `date` = '$train_date' AND `arrival` = '$train_arrival' AND `row` = '$r' AND `seat` = '$i'";
													$result3 = mysqli_query($con,$sql3) or die(mysqli_error($con));
													$rowcount3 = mysqli_num_rows($result3);
											?>
												<div class="col-xl-1 col-lg-1 col-md-1 col-sm-1 col-1" id="div_<?php echo $r?>_<?php echo $i ?>">
											<?php

													$sql4 = "SELECT * FROM select_seat WHERE `train_id` = '$train_id' AND `date` = '$train_date' AND `arrival` = '$train_arrival' AND `row` = '$r' AND `seat` = '$i'";
													$result4 = mysqli_query($con,$sql4) or die(mysqli_error($con));
													$rowcount4 = mysqli_num_rows($result4);													

													if($rowcount3 == 0) {

														if($rowcount4 == 0) {
											?>
													<button class="btn btn-primary" onclick="selectSeat('<?php echo $logUserid ?>','<?php echo $train_id ?>','<?php echo $train_start_station ?>','<?php echo $r?>','<?php echo $i ?>','no');" id="seatbtn_<?php echo $r?>_<?php echo $i ?>">1</button>

											<?php
														} else if($rowcount4 == 1) {
											?>

													<button class="btn btn-danger tooltip" id="seatbtn_<?php echo $r?>_<?php echo $i ?>" disabled>1 <span class="tooltiptext">Selected Seat</span></button>
													
											<?php
														}

													} else if($rowcount3 == 1) {
											?>
													<button class="btn btn-success" onclick="selectSeat('<?php echo $logUserid ?>','<?php echo $train_id ?>','<?php echo $train_start_station ?>','<?php echo $r?>','<?php echo $i ?>','yes');" id="seatbtn_<?php echo $r?>_<?php echo $i ?>">1</button>

											<?php

													}
                                            ?>
													
												</div>

                                            <?php
                                                }
                                            ?>
												<div class="col-xl-1 col-lg-1 col-md-1 col-sm-1 col-1" style="margin-top:1%;">
													<b style="font-size:13px;">E</b>
												</div>
											</div>
											<div class="row" style="margin-bottom: 3%; margin-top: 1%;;">
												<div class="col-sm-12 col-md-12 col-lg-12">
													<h6  style="text-align: center; font-size: 25px;"> Window Side </h6>
												</div>
											</div>
										</div>


							<!-- End -->

							</div>
							<div class="modal-footer">
								<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
							</div>
							</div>
						</div>
					</div>
    <?php

    } 

	?>