<?php
session_start();
if(!isset($_SESSION['username']) || !isset($_SESSION['password'])){
 header("Location: index.php");
} 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PMS Member's Only</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="http://fonts.googleapis.com/css?family=Open+Sans+Condensed:300" rel="stylesheet" type="text/css" />
<link href="default.css" rel="stylesheet" type="text/css" media="all" />
<script type="text/ecmascript">
function printdiv(printpage)
{
var headstr = "<html><head><title></title></head><body>";
var footstr = "</body>";
var newstr = document.all.item(printpage).innerHTML;
var oldstr = document.body.innerHTML;
document.body.innerHTML = headstr+newstr+footstr;
window.print();
document.body.innerHTML = oldstr;
return false;
}

    function visitPage(){
        window.location='select.php';
    }

</script>
 <script type = "text/javascript" >
    history.pushState(null, null, 'selected.php');
    window.addEventListener('popstate', function(event) {
    history.pushState(null, null, 'selected.php');
    });
</script>
<script type="text/javascript">
    function warning()
    {
        return "Please print the page before leaving"; //U can write any custom message here.
    }
    window.onbeforeunload = warning;
</script>
</head>
<body>
<div id="header" class="container">
	<div id="logo">
		<h1>PMS - Porter's Management System</h1>
	</div>
</div>

<div id="page" class="container">
	<div id="sidebar1">
		<div id="box1"><ul class="style1">
				<li class="first"><a href="select.php" class="link-style">SELECT PORTERS</a></li>
				<li><a href="addporters.php" class="link-style">ADD RECORDS</a></li>
                <li><a href="editall.php" class="link-style">Edit RECORDS</a></li>
				<li><a href="deleteporter.php" class="link-style">DELETE PORTER</a></li>
				<li><a href="#" class="link-style">UPDATE STATUS</a></li>
                               <li><a href="logout.php" class="link-style">Logout</a></li>
			</ul>
            </div>
	</div>
	<div id="content" align="center">
    <div class="tokeo"><div class="row1"><h4>Trek DMC kilimanjaro</h4></div>
    <div class="row1"><div class="rowl">Climb Start Date:<strong><?php print $_POST['datepicker']; ?></strong></div><div class="rowr">Climb Descend Date:<strong><?php print $_POST['datepicker2']; ?></strong></div></div>
    <div class="row1"><div class="rowl">Climb Route:<strong><?php print $_POST['climbroute']; ?></strong></div><div class="rowr">Meeting area:<strong><?php print $_POST['meetingarea']; ?></strong> Time:<strong><?php print $_POST['time']; ?></strong></div></div>
    </div>
<table style="width:800px">
  <tr>
    <td align="center">
      <table border="1" style="width:750px">
      <tr>
      <td>S/N</td>
        <td>Account Number</td>
        <td>Full Name</td>
        <td>Phone Number</td>

 </tr>
<?php
$con=mysqli_connect("localhost", "comeadve_glory1", "Safari#@2027$", "comeadve_tdmc");
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  
$lmt=$_POST['NumberOfPorters'];	
	
$order = "SELECT * FROM employees WHERE (Status =0) ORDER BY Id LIMIT $lmt";	
$result=mysqli_query($con,$order)
  or die("Sorry, The page has been reloaded and no data were selected from the database!");	  
$num_rows = mysqli_num_rows($result);
echo "$num_rows Porters Selected.\n";	

if($lmt ==0){
	
	echo "";
	}
  
elseif(mysqli_num_rows($result)== 0){
	
	    $sql1 = "UPDATE employees
        SET Status='0'
        WHERE (Status =1)";
		$rest=mysqli_query($con, $sql1);
		if($rest){
	   echo "Repeat the selection for porters,they have been reset for new rotation";
		}
}
else{
   while($data = mysqli_fetch_array($result)) {

   echo("<tr><td>$data[0]</td><td>$data[1]</td><td>$data[2]</td><td>$data[3]</td></tr>");
   }
   //update status;
   $sqlu = "UPDATE employees
        SET Status='1'
        WHERE (Status =0) ORDER BY Id LIMIT $lmt";
        mysqli_query($con,$sqlu);
   }
	
mysqli_close($con);
?>

<table style="width:800px">
  <tr>
    <td align="center">
      <table border="1" style="width:750px">
      <tr>
      <td>S/N</td>
        <td>Account Number</td>
        <td>Full Name</td>
        <td>Phone Number</td>
 </tr>
<?php
$conn=mysqli_connect("localhost", "comeadve_glory1", "Safari#@2027$", "comeadve_tdmc");
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
$lmt1=$_POST['Waiters'];	
	
$order1 = "SELECT * FROM waiters WHERE (Status =0) ORDER BY Id LIMIT $lmt1";	
$result1=mysqli_query($conn,$order1);	
$num_rows = mysqli_num_rows($result1);
echo "$num_rows Waiters Selected.\n";

if($lmt1 ==0){
	
	echo "";
	}	
  
elseif(mysqli_num_rows($result1)== 0){
	
		$sqlw = "UPDATE waiters
        SET Status='0'
        WHERE (Status =1)";
		$restw=mysqli_query($conn, $sqlw);
		if($restw){
	   echo "Repeat the selection for waiters,they have been reset for new rotation";
		}
}
else{
   while($data1 = mysqli_fetch_array($result1)) {

   echo("<tr><td>$data1[0]</td><td>$data1[1]</td><td>$data1[2]</td><td>$data1[3]</td></tr>");
       //header("Location: selected.php");
   }
   	   $sqll = "UPDATE waiters
        SET Status='1'
        WHERE (Status =0) ORDER BY Id LIMIT $lmt1";
        mysqli_query($conn,$sqll);
}
mysqli_close($conn);
?>
</table>
</td>
</tr>
</table>
</table>
</td>
</tr>
</table>

<table style="width:800px">
  <tr>
    <td align="center">
      <table border="1" style="width:750px">
      <tr>
      <td>S/N</td>
        <td>Account Number</td>
        <td>Full Name</td>
        <td>Phone Number</td>
      
 </tr>
<?php
$conm=mysqli_connect("localhost", "comeadve_glory1", "Safari#@2027$", "comeadve_tdmc");
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
$lmttc=$_POST['Tentcrew'];	
	
$ordertc = "SELECT * FROM tentcrew WHERE (Status =0) ORDER BY Id LIMIT $lmttc";	
$resulttc=mysqli_query($conm,$ordertc);	
$num_rows = mysqli_num_rows($resulttc);
echo "$num_rows Tent Crew Selected.\n";

if($lmttc ==0){
	
	echo "";
	}
  
elseif(mysqli_num_rows($resulttc)== 0){
	
	$sqlt = "UPDATE tentcrew
        SET Status='0'
        WHERE (Status =1)";
		$resttc=mysqli_query($conm, $sqlt);
		if($resttc){
	   echo "Repeat the selection for tent crew,they have been reset for new rotation";
		}
}
else{
   while($datatc = mysqli_fetch_array($resulttc)) {

   echo("<tr><td>$datatc[0]</td><td>$datatc[1]</td><td>$datatc[2]</td><td>$datatc[3]</td></tr>");
     //header("Location: selected.php");
   }
   $sqltc = "UPDATE tentcrew
        SET Status='1'
        WHERE (Status =0) ORDER BY Id LIMIT $lmttc";
mysqli_query($conm,$sqltc);	
}
mysqli_close($conm);
?>
</table>
</td>
</tr>
</table>

<table style="width:800px">
  <tr>
    <td align="center">
      <table border="1" style="width:750px">
      <tr>
      <td>S/N</td>
        <td>Account Number</td>
        <td>Full Name</td>
        <td>Phone Number</td>
      
 </tr>
<?php
$conb=mysqli_connect("localhost", "comeadve_glory1", "Safari#@2027$", "comeadve_tdmc");
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
$lmttb=$_POST['Toiletboy'];	
	
$ordertb = "SELECT * FROM toiletboy WHERE (Status =0) ORDER BY Id LIMIT $lmttb";	
$resulttb=mysqli_query($conb,$ordertb);	  
$num_rows = mysqli_num_rows($resulttb);
echo "$num_rows Toilet boy Selected.\n";

if($lmttb ==0){
	
	echo "";
	}	
  
elseif(mysqli_num_rows($resulttb)== 0){
	
		$sqlb = "UPDATE toiletboy
        SET Status='0'
        WHERE (Status =1)";
		$restb=mysqli_query($conb, $sqlb);
		if($restb){
	    echo "Repeat the selection for toilet boy,they have been reset for new rotation";
		}
}
else{
   while($datatb = mysqli_fetch_array($resulttb)) {

   echo("<tr><td>$datatb[0]</td><td>$datatb[1]</td><td>$datatb[2]</td><td>$datatb[3]</td></tr>");
    //header("Location: selected.php");
   }
   $sqltb = "UPDATE toiletboy
        SET Status='1'
        WHERE (Status =0) ORDER BY Id LIMIT $lmttb";
        mysqli_query($conb,$sqltb);
}
mysqli_close($conb);
?>
</table>
</td>
</tr>
</table>

<table style="width:800px">
  <tr>
    <td align="center">
      <table border="1" style="width:750px">
      <tr>
      <td>S/N</td>
        <td>Account Number</td>
        <td>Full Name</td>
        <td>Phone Number</td>
 </tr>
<?php
$conbw=mysqli_connect("localhost", "comeadve_glory1", "Safari#@2027$", "comeadve_tdmc");
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
$lmtdw=$_POST['Dishwasher'];	
	
$orderdw = "SELECT * FROM dishwasher WHERE (Status =0) ORDER BY Id LIMIT $lmtdw";	
$resultdw=mysqli_query($conbw,$orderdw);	  
$num_rows = mysqli_num_rows($resultdw);
echo "$num_rows Dishwashers Selected.\n";

if($lmtdw ==0){
	
	echo "";
	}	
  
elseif(mysqli_num_rows($resultdw)== 0){
	
		$sqldw = "UPDATE dishwasher
        SET Status='0'
        WHERE (Status =1)";
		$restdw=mysqli_query($conbw, $sqldw);
		if($restdw){
	    echo "Repeat the selection for dishwashers,they have been reset for new rotation";
		}
}
else{
   while($datadw = mysqli_fetch_array($resultdw)) {

   echo("<tr><td>$datadw[0]</td><td>$datadw[1]</td><td>$datadw[2]</td><td>$datadw[3]</td></tr>");
    //header("Location: selected.php");
   }
   $sqldw = "UPDATE dishwasher
        SET Status='1'
        WHERE (Status =0) ORDER BY Id LIMIT $lmtdw";
        mysqli_query($conbw,$sqldw);
}
mysqli_close($conbw);
?>
</table>
</td>
</tr>
</table>


	</div>
	<div class="print" align="center"><br /><br /><input name="b_print" type="button" class="ipt"   onClick="printdiv('content');" value="&nbsp;&nbsp;Print List & Save(pdf) file&nbsp;&nbsp;"> 
	  &nbsp;&nbsp;<button onclick="visitPage();">&nbsp;New Selection&nbsp;</button></div>
</div>
<div id="footer">
	<p>&copy; Trek DMC kilimanjaro. All rights reserved. Design by <a href="www.technohosttz.com">Technohost Tanzania</a></p>
</div>
</body>
</html>
