<?php include('accesscheck2.php'); 
require_once('Connections/courier.php');

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_courier, $courier);


$query_rsodest_officer = "SELECT * FROM users where (security='MEDICAL OFFICER' or security='OPTICIAN' or security='DENTIST') order by title, surname, firstnames";	     
$rsodest_officer = mysql_query($query_rsodest_officer, $courier) or die(mysql_error());
//$row_rsodest_officer=mysql_fetch_assoc($rsodest_officer);
$totalRows_rsodest_officer = mysql_num_rows($rsodest_officer);

$rooms = mysql_query("Select * from consultation_rooms");


 $day = date('w');
$week_start = date('Y-m-d', strtotime('-'.$day.' days'));
 //echo "$week_start\n";
 $week_end = date('Y-m-d', strtotime('+'.(6-$day).' days'));

$roster = ("SELECT * FROM duty_roster left outer join users on duty_roster.staff_no = users.id where (duty_roster.duty_date >= '$week_start' AND duty_roster.duty_date <= '$week_end') order by duty_date ASC");
$roster;
$rsodest_roster = mysql_query($roster)or die (mysql_error());
$row_rsodest_roster = mysql_fetch_assoc($rsodest_roster);
$trows = mysql_num_rows($rsodest_roster);
                       
?>


<link href="css/new.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="../assets/css/themes/light.css">
<link rel="stylesheet" type="text/css" href="../assets/plugins/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="../assets/bootstrap/css/datepicker.css">

<form name="form" id="form" method="post" onsubmit="return false;">
<div class="content_area">
<div class="tab_content">
<div id="member_info">
<div class="list-group" style="padding: 0px">                        
          <div style="background-color: #428bca" class="portlet box">
            <div class="portlet-title">
                      <div class="caption"><i style="color: #FFF" class="icon-globe"></i><span class="sectionTitle2">DOCTOR'S SCHEDULES</span>
                        
                      </div>
                     <div class="tools">
                        <a href="javascript:;" class="collapse"></a>
                        <a href="#portlet-config" data-toggle="modal" class="config"></a>
                        
                     </div>
            </div>
            
            <div class="portlet-body" style="padding:0px;">
            <table>
      			<tr>
            	<td height="23" width="20%" style="text-align: left;padding-left: 10px; font-size:14px;font-weight:bold;">Date </td>
            	<td><input name="dateofbirth" type="text" id="dateofbirth" class="form-control-mine" style="width:50%;" ><label for="dateofbirth">&nbsp;<i class="icon-calendar" style="cursor: pointer;font-size: 20px"></i></label></td>
                <td><span style="padding:0px;">
                  <input type="button" class="btn green" name="loadform" value="Load Form" onclick="loadform2();"/>
                  </span></td>
                  </tr>
                  </table>
            <div class="table-responsive" style="display:none" id="roster">
              <table width="100%" cellspacing="0" cellpadding="2" border="0">
       <tbody>
          <tr>                 
            <td width="90%"  valign="top"><table width="100%" cellspacing="0" cellpadding="0" border="0" align="center">
              <tbody>
                <tr>
                  <td width="" valign="top"><table width="100%" height="60" cellspacing="0" cellpadding="0" border="0" class="nav_tbl">
                    <tbody>
                      <tr>
                        <td valign="top" height="30" class="areacontop"><table width="100%" cellspacing="1" cellpadding="1" border="0" class="sectionText1">
                          <tbody>
                            <tr>
                              <td valign="top" height="20" bgcolor="#FFFFFF">
                              <table width="100%" border="0" cellpadding="1" cellspacing="1" class="sectionText1" id="membershipinfo">
                                <tbody>
                                  <tr class="baseborder">
                                    <td height="30" align="right" style="text-align: left;padding-left: 10px;">
                                   
                	<tr>
                    	<td width="35%"><select name="specialist" style="width:250px;">
                                          <option value="">--Select Medical Officer--</option>
                                          <?php
                                    do {  
?>
                                          <option value="<?php echo $row_rsodest_officer['id']; ?>"><?php echo $row_rsodest_officer['firstnames'].' '.$row_rsodest_officer['surname']?></option>
                                          <?php
} while ($row_rsodest_officer = mysql_fetch_assoc($rsodest_officer));

?>
                                        </select></td>
                        <td width="25%"><label for="textfield2">From</label>
                          <select name="from_hr" style="width:50px;">
              <?php
			  $h= date('H');
              	for ($i = 0; $i <=23 ; $i++) {
					if(strlen($i)<2)
					{
						$i= '0'.$i;
		 ?>
              <option value="<?php echo $i; ?>" <?php if($h==$i){?>selected="selected"<?php }?>><?php echo $i; ?></option>
              <?php } else { ?> <option value="<?php echo $i; ?>" <?php if($h==$i){?>selected="selected"<?php }?>><?php echo $i; }?></option>
           
	<?php 
	 }
	?>
              </select><select name="from_min" style="width:50px;">
              	<?php
				$m= date('i');
              	for ($i = 0; $i <=59 ; $i++) {
					if(strlen($i)<2)
					{
						$i= '0'.$i;
		 ?>
              <option value="<?php echo $i; ?>" <?php if($m==$i){?>selected="selected"<?php }?>><?php echo $i; ?></option>
              <?php } else {?> <option value="<?php echo $i; ?>" <?php if($m==$i){?>selected="selected"<?php }?>><?php echo $i; }?></option>
           
	<?php 
	 }
				?>
              </select>
              </td>
                        <td width="22%"><label for="textfield3">To</label>
                         <select name="to_hr" style="width:50px;">
              <?php
			  $h= date('H');
              	for ($i = 0; $i <=23 ; $i++) {
					if(strlen($i)<2)
					{
						$i= '0'.$i;
		 ?>
              <option value="<?php echo $i; ?>" <?php if($h==$i){?>selected="selected"<?php }?>><?php echo $i; ?></option>
              <?php } else { ?> <option value="<?php echo $i; ?>" <?php if($h==$i){?>selected="selected"<?php }?>><?php echo $i; }?></option>
           
	<?php 
	 }
	?>
              </select><select name="to_min" style="width:50px;">
              	<?php
				$m= date('i');
              	for ($i = 0; $i <=59 ; $i++) {
					if(strlen($i)<2)
					{
						$i= '0'.$i;
		 ?>
              <option value="<?php echo $i; ?>" <?php if($m==$i){?>selected="selected"<?php }?>><?php echo $i; ?></option>
              <?php } else {?> <option value="<?php echo $i; ?>" <?php if($m==$i){?>selected="selected"<?php }?>><?php echo $i; }?></option>
           
	<?php 
	 }
				?>
              </select></td>
                        <td width="18%">
                        
                        <label for="textfield4">Room</label>
                          <select name="room" style="width:100px">
                          <?php while($rs_rooms=mysql_fetch_assoc($rooms)){?>
                          	<option value="<?php echo $rs_rooms['id'];?>"><?php echo $rs_rooms['room_no'];?></option>
						  	
						  <?php } ?>
                          </select>
                          </td>
                    </tr>
                	<tr>
                	  <td>
                      <?php 
					  
$list_doctors = mysql_query("SELECT * FROM users where (security='DENTIST' OR security='MEDICAL OFFICER' OR security='OPTICIAN')")or die(mysql_error());
$query_rs = mysql_fetch_assoc($list_doctors);
$trows = mysql_num_rows($list_doctors);
					  ?>
                      <select name="specialist1" style="width:250px;">
                                          <option value="">--Select Medical Officer--</option>
                                          <?php
										  
                                    do {  
?>
                                          <option value="<?php echo $query_rs['id']; ?>"><?php echo $query_rs['firstnames'].' '.$query_rs['surname']?></option>
                                          <?php
} while ($query_rs = mysql_fetch_assoc($list_doctors));
?>
                                        </select></td>
                	  <td><label for="textfield2">From</label>
                	     <select name="from_hr1" style="width:50px;">
              <?php
			  $h= date('H');
              	for ($i = 0; $i <=23 ; $i++) {
					if(strlen($i)<2)
					{
						$i= '0'.$i;
		 ?>
              <option value="<?php echo $i; ?>" <?php if($h==$i){?>selected="selected"<?php }?>><?php echo $i; ?></option>
              <?php } else { ?> <option value="<?php echo $i; ?>" <?php if($h==$i){?>selected="selected"<?php }?>><?php echo $i; }?></option>
           
	<?php 
	 }
	?>
              </select><select name="from_min1" style="width:50px;">
              	<?php
				$m= date('i');
              	for ($i = 0; $i <=59 ; $i++) {
					if(strlen($i)<2)
					{
						$i= '0'.$i;
		 ?>
              <option value="<?php echo $i; ?>" <?php if($m==$i){?>selected="selected"<?php }?>><?php echo $i; ?></option>
              <?php } else {?> <option value="<?php echo $i; ?>" <?php if($m==$i){?>selected="selected"<?php }?>><?php echo $i; }?></option>
           
	<?php 
	 }
				?>
              </select></td>
                	  <td><label for="textfield3">To</label>
                	    <select name="to_hr1" style="width:50px;">
              <?php
			  $h= date('H');
              	for ($i = 0; $i <=23 ; $i++) {
					if(strlen($i)<2)
					{
						$i= '0'.$i;
		 ?>
              <option value="<?php echo $i; ?>" <?php if($h==$i){?>selected="selected"<?php }?>><?php echo $i; ?></option>
              <?php } else { ?> <option value="<?php echo $i; ?>" <?php if($h==$i){?>selected="selected"<?php }?>><?php echo $i; }?></option>
           
	<?php 
	 }
	?>
              </select><select name="to_min1" style="width:50px;">
              	<?php
				$m= date('i');
              	for ($i = 0; $i <=59 ; $i++) {
					if(strlen($i)<2)
					{
						$i= '0'.$i;
		 ?>
              <option value="<?php echo $i; ?>" <?php if($m==$i){?>selected="selected"<?php }?>><?php echo $i; ?></option>
              <?php } else {?> <option value="<?php echo $i; ?>" <?php if($m==$i){?>selected="selected"<?php }?>><?php echo $i; }?></option>
           
	<?php 
	 }
				?>
              </select></td>
                	  <td><label for="textfield4">Room</label>
                      <?php $query_rooms = mysql_query("Select * from consultation_rooms"); ?>
                	    <select name="room1" style="width:100px">
                          <?php while($rsodest_rooms=mysql_fetch_assoc($query_rooms)){?>
                          	<option value="<?php echo $rsodest_rooms['id'];?>"><?php echo $rsodest_rooms['room_no'];?></option>
						  	
						  <?php } ?>
                          </select></td>
              	  </tr>
                	<tr>
                	  <td><?php 
					  
$list_doctors1 = mysql_query("SELECT * FROM users where (security='DENTIST' OR security='MEDICAL OFFICER' OR security='OPTICIAN')")or die(mysql_error());
$query_rs1 = mysql_fetch_assoc($list_doctors1);
$trows = mysql_num_rows($list_doctors1);
					  ?>
                      <select name="specialist2" style="width:250px;">
                                          <option value="">--Select Medical Officer--</option>
                                          <?php
										  
                                    do {  
?>
                                          <option value="<?php echo $query_rs1['id']; ?>"><?php echo $query_rs1['firstnames'].' '.$query_rs1['surname']?></option>
                                          <?php
} while ($query_rs1 = mysql_fetch_assoc($list_doctors1));
?>
                                        </select></td>
                	  <td><label for="textfield2">From</label>
                	     <select name="from_hr2" style="width:50px;">
              <?php
			  $h= date('H');
              	for ($i = 0; $i <=23 ; $i++) {
					if(strlen($i)<2)
					{
						$i= '0'.$i;
		 ?>
              <option value="<?php echo $i; ?>" <?php if($h==$i){?>selected="selected"<?php }?>><?php echo $i; ?></option>
              <?php } else { ?> <option value="<?php echo $i; ?>" <?php if($h==$i){?>selected="selected"<?php }?>><?php echo $i; }?></option>
           
	<?php 
	 }
	?>
              </select><select name="from_min2" style="width:50px;">
              	<?php
				$m= date('i');
              	for ($i = 0; $i <=59 ; $i++) {
					if(strlen($i)<2)
					{
						$i= '0'.$i;
		 ?>
              <option value="<?php echo $i; ?>" <?php if($m==$i){?>selected="selected"<?php }?>><?php echo $i; ?></option>
              <?php } else {?> <option value="<?php echo $i; ?>" <?php if($m==$i){?>selected="selected"<?php }?>><?php echo $i; }?></option>
           
	<?php 
	 }
				?>
              </select></td>
                	  <td><label for="textfield3">To</label>
                	     <select name="to_hr2" style="width:50px;">
              <?php
			  $h= date('H');
              	for ($i = 0; $i <=23 ; $i++) {
					if(strlen($i)<2)
					{
						$i= '0'.$i;
		 ?>
              <option value="<?php echo $i; ?>" <?php if($h==$i){?>selected="selected"<?php }?>><?php echo $i; ?></option>
              <?php } else { ?> <option value="<?php echo $i; ?>" <?php if($h==$i){?>selected="selected"<?php }?>><?php echo $i; }?></option>
           
	<?php 
	 }
	?>
              </select><select name="to_min2" style="width:50px;">
              	<?php
				$m= date('i');
              	for ($i = 0; $i <=59 ; $i++) {
					if(strlen($i)<2)
					{
						$i= '0'.$i;
		 ?>
              <option value="<?php echo $i; ?>" <?php if($m==$i){?>selected="selected"<?php }?>><?php echo $i; ?></option>
              <?php } else {?> <option value="<?php echo $i; ?>" <?php if($m==$i){?>selected="selected"<?php }?>><?php echo $i; }?></option>
           
	<?php 
	 }
				?>
              </select></td>
                	  <td><label for="textfield4">Room</label>
                	   <?php $query_rooms2 = mysql_query("Select * from consultation_rooms"); ?>
                	    <select name="room2" style="width:100px">
                          <?php while($rsodest_rooms2=mysql_fetch_assoc($query_rooms2)){?>
                          	<option value="<?php echo $rsodest_rooms2['id'];?>"><?php echo $rsodest_rooms2['room_no'];?></option>
						  	
						  <?php } ?>
                          </select></td>
              	  </tr>
                	<tr>
                	  <td>
                	    <?php 
					  
$list_doctors2 = mysql_query("SELECT * FROM users where (security='DENTIST' OR security='MEDICAL OFFICER' OR security='OPTICIAN')")or die(mysql_error());
$query_rs2 = mysql_fetch_assoc($list_doctors2);
$trows = mysql_num_rows($list_doctors2);
					  ?>
                      <select name="specialist3" style="width:250px;">
                                          <option value="">--Select Medical Officer--</option>
                                          <?php
										  
                                    do {  
?>
                                          <option value="<?php echo $query_rs2['id']; ?>"><?php echo $query_rs2['firstnames'].' '.$query_rs2['surname']?></option>
                                          <?php
} while ($query_rs2 = mysql_fetch_assoc($list_doctors2));
?>
                                        </select></td>
                	  <td><label for="textfield2">From</label>
                	     <select name="from_hr3" style="width:50px;">
              <?php
			  $h= date('H');
              	for ($i = 0; $i <=23 ; $i++) {
					if(strlen($i)<2)
					{
						$i= '0'.$i;
		 ?>
              <option value="<?php echo $i; ?>" <?php if($h==$i){?>selected="selected"<?php }?>><?php echo $i; ?></option>
              <?php } else { ?> <option value="<?php echo $i; ?>" <?php if($h==$i){?>selected="selected"<?php }?>><?php echo $i; }?></option>
           
	<?php 
	 }
	?>
              </select><select name="from_min3" style="width:50px;">
              	<?php
				$m= date('i');
              	for ($i = 0; $i <=59 ; $i++) {
					if(strlen($i)<2)
					{
						$i= '0'.$i;
		 ?>
              <option value="<?php echo $i; ?>" <?php if($m==$i){?>selected="selected"<?php }?>><?php echo $i; ?></option>
              <?php } else {?> <option value="<?php echo $i; ?>" <?php if($m==$i){?>selected="selected"<?php }?>><?php echo $i; }?></option>
           
	<?php 
	 }
				?>
              </select></td>
                	  <td><label for="textfield3">To</label>
                	    <select name="to_hr3" style="width:50px;">
              <?php
			  $h= date('H');
              	for ($i = 0; $i <=23 ; $i++) {
					if(strlen($i)<2)
					{
						$i= '0'.$i;
		 ?>
              <option value="<?php echo $i; ?>" <?php if($h==$i){?>selected="selected"<?php }?>><?php echo $i; ?></option>
              <?php } else { ?> <option value="<?php echo $i; ?>" <?php if($h==$i){?>selected="selected"<?php }?>><?php echo $i; }?></option>
           
	<?php 
	 }
	?>
              </select><select name="to_min3" style="width:50px;">
              	<?php
				$m= date('i');
              	for ($i = 0; $i <=59 ; $i++) {
					if(strlen($i)<2)
					{
						$i= '0'.$i;
		 ?>
              <option value="<?php echo $i; ?>" <?php if($m==$i){?>selected="selected"<?php }?>><?php echo $i; ?></option>
              <?php } else {?> <option value="<?php echo $i; ?>" <?php if($m==$i){?>selected="selected"<?php }?>><?php echo $i; }?></option>
           
	<?php 
	 }
				?>
              </select></td>
                	  <td><label for="textfield4">Room</label>
                	    <?php $query_rooms3 = mysql_query("Select * from consultation_rooms"); ?>
                	    <select name="room3" style="width:100px">
                          <?php while($rsodest_rooms3=mysql_fetch_assoc($query_rooms3)){?>
                          	<option value="<?php echo $rsodest_rooms3['id'];?>"><?php echo $rsodest_rooms3['room_no'];?></option>
						  	
						  <?php } ?>
                          </select></td>
              	  </tr>
                	<tr>
                    	<td colspan="4" style="float:right;"><button class="btn green" onclick="getstep('save_roster');" name="save">Save &nbsp;<i class="icon-save"></i></button></td>
                    </tr>
                      </table></td>
                                  </tr>
                                </tbody>
                              </table>
                              </td>
                            </tr>
                          </tbody>
                        </table></td>
                      </tr>
                    </tbody>
                  </table></td>
                </tr>
              </tbody>
            </table></td>
            </tr>
          <tr>
            <td colspan="2" valign="top">&nbsp;</td>
            </tr>
   
    <tr>
      <td valign="top" colspan="2">
        </td>
    </tr>
  </tbody></table>
  
</div>
 			</div>
            
            
          </div>
            
</div>
  </div>
</div>
<div class="portlet box green">
	<div class="portlet-title">
                      <div class="caption"><i style="color: #FFF" class="icon-globe"></i><span class="sectionTitle2">Weekly Overview</span>
                        
                      </div>
                     <div class="tools">
                        <a href="javascript:;" class="collapse"></a>
                        <a href="#portlet-config" data-toggle="modal" class="config"></a>
                        
                     </div>
            </div>
	
    <div class="portlet-body">
    	<div class="table-responsive">
    	<table class="table table-striped table-bordered" cellpadding="1" cellspacing="1" width="100%">
        	<tr>
                <td width='5%' height="23" align="right" nowrap="nowrap" style="background-color: #428bca;color: #000;text-align: left;padding-left: 10px;font-weight: bold"></td>
                <td width='30%' height="23" align="right" nowrap="nowrap" style="background-color: #428bca;color: #000;text-align: left;padding-left: 10px;font-weight: bold">Date</td>
                <td width='30%' height="23" align="right" nowrap="nowrap" style="background-color: #428bca;color: #000;text-align: left;padding-left: 10px;font-weight: bold">Doctor on Duty</td>
                <td width='60%' align="left" nowrap="nowrap" style="background-color: #428bca;color: #000;text-align: left;padding-left: 10px;font-weight: bold;text-align: center">Start Time</td>
                  <td width='60%' align="left" nowrap="nowrap" style="background-color: #428bca;color: #000;text-align: left;padding-left: 10px;font-weight: bold;text-align: center">End Time</td>
                    <td width='60%' align="left" nowrap="nowrap" style="background-color: #428bca;color: #000;text-align: left;padding-left: 10px;font-weight: bold;text-align: center">Consulting Room</td>
              </tr>
                <?php  if($trows > 0)
			  		  {
						  $i=1; do{ ?>
       						<tr>
                  <td height="23" align="right" style="font-weight: normal"><?php echo $i;?></td>
                  <td height="23" align="right" style="font-weight: normal"><?php echo $row_rsodest_roster['duty_date']."(".(date('D',$row_rsodest_roster['duty_date'])).")";?></td>
                  <td height="23" align="right" style="font-weight: normal"><?php echo strtoupper($row_rsodest_roster['title'].' '.$row_rsodest_roster['firstnames'].' '.$row_rsodest_roster['surname']);?></td>
                  <td height="23" align="right" style="font-weight: normal"><?php echo $row_rsodest_roster['start_time'];?></td> <td height="23" align="right" style="font-weight: normal"><?php echo $row_rsodest_roster['end_time'];?></td>
                   <td height="23" align="right" style="font-weight: normal"><?php echo $row_rsodest_roster['room_id'];?></td>
                  <!--td height="23" style="text-align: center"><a data-target="#basic1" data-toggle="modal" style="text-align: center;cursor: pointer"  onclick="ViewDoctorSchedule('view_doctor_schedule','<?php //echo $query_rs['id'];?>')">View Schedule</a></td>-->
              </tr>  <?php $i++;}while($row_rsodest_roster = mysql_fetch_assoc($rsodest_roster));}else{
                                                    ?>
                                            <tr <?php
                                                        if (fmod($start_row, 2) > 0) {
                                                            echo 'class="odd"';
                                                        } else {
                                                            echo 'style="background: linen"';
                                                        }
                  ?>>
										      <td height="23" colspan="4" valign="top" class="count">Sorry,No Medical Officer Found.</td>
									        </tr>
                                            
                                            <?php }?>
        
        
        
     	</table></div>
    
    </div>
</div>
</div>
 
</form>