<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ include file="dbconfig.jsp" %>

<%
HttpSession ses = request.getSession();
String id = ses.getAttribute("userID").toString(); 

String bgcolor = null;
String btncolor = null;
String member_type = null;

Statement stmt = con.createStatement();
String sql = "select member_type from member where ID = '" +id+ "'";

ResultSet res = stmt.executeQuery(sql);
   
   if (res.next()) {
	   member_type = res.getString("member_type");
	   ses.setAttribute("member_type", member_type);
	   
	   if (member_type.equals("Gold")){
		   bgcolor = "bg-warning";
	   		btncolor = "btn-warning";}
	   else if (member_type.equals("Silver")){
		   bgcolor = "bg-light";
		   btncolor = "btn-light";}
	   else if (member_type.equals("Platinum")){
		   bgcolor = "bg-secondary";
		   btncolor = "btn-secondary";}
	   else if (member_type.equals("Bronze")){
		   bgcolor = "bg-danger";
		   btncolor = "btn-danger";}
   }%>

<!DOCTYPE html>
<html lang="en">
<head>
	<title>TITLE</title>
	<meta charset="UTF-8">
	 <!-- Defining a description for the web page -->
	<meta name="description" content="Web tutorials">
	<!-- Defining keywords for search engines -->
	<meta name="keywords" content="HTML,CSS,XML,JavaScript">
	<!-- Defining the author of a page -->
	<meta name="author" content="HTML">
	<!-- Setting the viewport to make the webpage compatible on all devices -->
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<!-- STYLE SHEETS -->
	<!-- Bootstrap 3.3.7 -->
	<!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> -->
	<!-- Bootstrap 4.0 -->
	<link rel="stylesheet" href="css/bootstrap.css">
	<link rel="stylesheet" href="css/bootstrap.min.css">
	<!-- END OF STYLE SHEETS -->

	<style type="text/css">
	
		.nav a{
			color: black;
			text-decoration: none;
			font-size: 15px;
			font-weight: 500;
		}

		.desktop {
			    display: none;
			  }
		/*Medium devices (tablets, 768px and up)*/
		@media (min-width: 768px) {
			.desktop {
			    display: block;
			  }
		 }

	</style>
	<script type="text/javascript">
	function radioValidate() {
		var radio = document.forms["radioForm"]["yesno"].value;
	
		if (radio == null || radio == "")  {
			alert("select yes or no!!");
			return false;
		}
		
	}
</script>
</head>
<body>


	<div class="desktop">
	<!-- All the content below is defined under a main col-12 class [main-column] -->
	<div class="col-12">

		<!-- All the page content is defined under a main row class [main-row]-->
		<div class="row">

			<!-- left side nav bar -->
			<div class="col-md-2 bg-dark fixed-top" style="height: 100vh;">

				<div class="row nav">

					<a class="col-md-12 py-4 text-left rounded-0 border-right-0 border-left-0 border-top-0 border-bottom border-dark btn btn-info" href="Profile.jsp">HOME</a>

					<div class="bg-dark col-md-12 py-5"></div>

					<a class="col-md-12 py-4 text-left rounded-0 border-right-0 border-left-0 border-top-0 border-bottom border-dark btn btn-info" href="SelectSportsOrGym.jsp">MAKE SCHEDULE</a>
					<a class="col-md-12 py-4 text-left rounded-0 border-right-0 border-left-0 border-top-0 border-bottom border-dark btn btn-info" href="viewSportsBooking.jsp">VIEW SPORTS BOOKINGS</a>
					<a class="col-md-12 py-4 text-left rounded-0 border-right-0 border-left-0 border-top-0 border-bottom border-dark btn btn-info" href="viewBooking.jsp">VIEW GYM BOOKINGS</a>
					<a class="col-md-12 py-4 text-left rounded-0 border-right-0 border-left-0 border-top-0 border-bottom border-dark btn btn-info" href="search.jsp">SEARCH BOOKINGS</a>
					<a class="col-md-12 py-4 text-left rounded-0 border-right-0 border-left-0 border-top-0 border-bottom border-dark btn btn-info" href="/Fire_Fitness/Payment">CONFIRM BOOKINGS</a>

				</div>

			</div> <!-- End of left side nav bar -->



			<!-- Middle content -->
			<div class="col-8 offset-2 px-0">

				<% String trainer_name = request.getParameter("trainer_name");
	   String workout_name = request.getParameter("workout_name");
	   Date d = Date.valueOf(request.getParameter("Date"));
	   Time start_time = Time.valueOf(request.getParameter("start_time"));
	   Time end_time = Time.valueOf(request.getParameter("end_time"));
	   String member_ID = null;
	   String schedule_ID = null;
	   String trainer_ID = null;
	   
	   Statement st1 = con.createStatement();
	   Statement st2 = con.createStatement();
	   Statement st3 = con.createStatement();
	   String query1 = "select schedule_ID from schedule where start_time = '" +start_time+ "' AND end_time = '" +end_time+ "'";
	   String query2 = "select trainer_ID from trainer where Name = '" +trainer_name+ "'";
	   
	   ResultSet rs1 = st1.executeQuery(query1);
	   ResultSet rs2 = st2.executeQuery(query2);
	   
	   if (rs1.next())
		   schedule_ID = rs1.getString("schedule_ID");
	   
	   if (rs2.next()) 
		   trainer_ID = rs2.getString("trainer_ID");
	   
	   String query3 = "select member_ID from trainer_booking where trainer_ID = '" +trainer_ID+ "' AND Date = '" +d+ "' AND schedule_ID = '" +schedule_ID+ "'";	  
	   
	   ResultSet rs3 = st3.executeQuery(query3);
	   
	   if (rs3.next())
		   member_ID = rs3.getString("member_ID"); %>
		   
		<form action="DeleteServlet" method="post" name="radioForm" onsubmit="return radioValidate()">
			<table>
				<caption>Trainer Booking Details</caption>
	   			<tr>
					<th>Trainer Name</th>
					<th>Workout</th>
					<th>Date</th>
					<th>start time</th>
					<th>end time</th>
	   			</tr>
	   			<tr>
	   				<td><%=trainer_name %></td>
	   				<td><%=workout_name %></td>
	   				<td><%=d %></td>
	   				<td><%=start_time %></td>
	   				<td><%=end_time %></td>
	   			</tr>
	   			<tr>
	   				<td>cancel your booking?</td>
	   				<td><input type="radio" name="yesno" value="yes">Yes</td>
	   				<td><input type="radio" name="yesno" value="no">No</td>
	   				<td><button type="submit" name="yes">delete</button></td>
	   			</tr>
	   			<input type="hidden" name="member_ID" value="<%=member_ID %>">
	   			<input type="hidden" name="trainer_ID" value="<%=trainer_ID %>">
	   			<input type="hidden" name="Date" value="<%=d %>">
	   			<input type="hidden" name="schedule_ID" value="<%=schedule_ID %>">
			</table>
		</form>
	       
	       
	       
			</div> <!-- End of middle content -->




			<!-- Right side nav bar -->
			<div class="col-md-2 offset-10 <%=bgcolor %> fixed-top" style="height: 100vh">

				<div class="row nav">

					<div class="<%=bgcolor %> col-md-12 py-4"></div>

					<div class="pl-5">
					<img src="avatar.jpeg" class="img-fluid rounded-circle" style="height: 250px">
				</div>

					<div class="<%=bgcolor %> col-md-12 py-3"></div>

					<div class="<%=bgcolor %> col-md-12 py-0 text-center pl-5"><span style=" font-weight: 500">MEMBER ID :  ${userID}</span></div>


					<div class="<%=bgcolor %> col-md-12 py-0 text-center pl-5"><span style="font-weight: 500">WELCOME</span></div>

					<% HttpSession s = request.getSession();
					   Object userID = (s.getAttribute("userID"));
					   String ID = userID.toString();
					   //out.println(id);
					   //int i = Integer.parseInt(id);
					   Statement st = con.createStatement();
					   ResultSet r = st.executeQuery("select fName from member where ID = '" + ID + "'");
					   
					   while (r.next()) {
					   s.setAttribute("name", r.getString("fName")); %>
					<div class="<%=bgcolor %> col-md-12 pb-4 text-center pl-5"><span style="font-weight: 500"><%=r.getString("fName") %></span></div>
					<% } %>
					
					<a class="col-md-12 py-4 text-left rounded-0 border-right-0 border-left-1 border-top-0 border-bottom-0 border-dark btn <%=btncolor %>" href="Update.jsp?edit=<%=id %>">UPDATE PROFILE</a>
					<a class="col-md-12 py-4 text-left rounded-0 border-right-0 border-left-1 border-top-0 border-bottom-0 border-dark btn <%=btncolor %>" href="logoutProcess.jsp">LOGOUT</a>
					
					

				</div>

			</div> <!-- End of right-side nav bar -->


		</div> <!-- End of [main-row] -->

	</div> <!-- End of [main-column] -->
</div>








	<!-- SCRIPTS -->
	<!-- jQuery Library -->
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
	<!-- Bootstrap 3.3.7 javascript -->
	<!-- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> -->
	<!-- popper Library -->
	<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
	<!-- Bootstrap 4.0 javascript -->
	<script src="js/bootstrap.bundle.js"></script>
	<script src="js/bootstrap.bundle.min.js"></script>
	<!-- END OF SCRIPTS -->
</body>
</html>