<!DOCTYPE html>
<?php

include('buiapp/partials/header.php');
include ('buiapp/phpClasses/functions.php');
if (isset($_SESSION['staff_session'])) {
    $username = $_SESSION['staff_session'];
	$csession =  currentSession();
		$role = getrole($username, $csession);
	

} else {
    header('Location: index.php');
    exit();
}
$csession =  currentSession();
				$role = getrole($username, $csession);
				
if($role[0] == '1' || $role[0] == '2'){
	
	
}else{
	header('Location: index.php');
   exit();
}
include('header.php');
?>
<style type="text/css">
table.table-bordered{
    border:1px solid black;
    margin-top:20px;
  }
table.table-bordered > thead > tr > th{
    border:1px solid black;
	background-color: black;
	color: white;
}
table.table-bordered > tbody > tr > td{
    border:1px solid black;
}
table.table-bordered > tfoot > tr > td{
    border:1px solid black;
}
</style>


  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
         <?php
	  $curs = currentSession();
	  $rid = getrole($username, $curs);
		$rdt = getroledetails($rid[0]);
		if($rid[0] == 1){
		echo $rid[3]." ".$rdt."'s Dashboard";
		}else{
		    echo $rid[2]." ".$rdt."'s Dashboard";
		}
	  ?>
        <small>Bowen University Iwo</small>
      </h1>
      <ol class="breadcrumb">
        	 <?php  $url = htmlspecialchars($_SERVER['HTTP_REFERER']); echo " <li><a href='$url'><i class='fa fa-arrow'></i>Back</a></li>";?>
        <li class="active">Dashboard</li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content container-fluid" style="background-image: url('images/logo2.png'); background-repeat: no-repeat; background-attachment: fixed; background-position: center; ">
		 			<?php 
		 			if(isset($_SESSION['working_lecid'])){
		 			    $stid =	$_SESSION['working_lecid']; 
						 $dept =  $_SESSION['working_lecdept']; 
						   $fac = $_SESSION['working_lecfac'];
		 			}
		 			
						if(isset($_POST['id'])){
							$stid = $_POST['id'];
							$dept = $_POST['dept'];
							$fac = $_POST['fac'];
							
							$_SESSION['working_lecid'] = $stid;
						    $_SESSION['working_lecdept'] = $dept;
						    $_SESSION['working_lecfac'] = $fac;
							
						}
						
						if(isset($_POST['delete'])){
							$stid = $_POST['id'];
							$dept = $_POST['dept'];
							$fac = $_POST['fac'];
							
							$cid = $_POST['cid'];
							deletecourse($cid, $stid);
							//header("Refresh:0");
							
						}
						
						if(isset($_POST['leveladviser'])){
			$level = $_POST['leveladviser'];
			leveladviser($stid, $level, $dept, $fac);
			$stid = $_POST['id'];
							$dept = $_POST['dept'];
							$fac = $_POST['fac'];
		}
		
		 if(isset($_POST['lreccou'])){
			$cour = $_POST['lreccou'];
			foreach($cour as $sel){
			
			echo assigncourse($stid, $sel);
			}
			 $stid = $_POST['id'];
							$dept = $_POST['dept'];
					$fac = $_POST['fac'];
			//header("Refresh:0");
		}
					?>
                
				
					<div class="box box-info box-solid">
            <div class="box-header with-border">
              <h3 class="box-title">Bio Data</h3>
					
              <div class="box-tools pull-right">
			  
                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                </button>
              </div>
			 
			  
			  
	</div>
	 <div class="box-body">
	           <div class="box">
            <div class="box-header">
              <h3 class="box-title">Bio Data</h3>
            </div>
            <!-- /.box-header -->
			  <?php 
					$bio =  aboutstaff($stid);
					$srole = getrole($stid, $csession);
				
					
					?>
            <div class="box-body no-padding">
              <table class="table table-striped">
               
                <tr>
                  <td>Name</td>
                  <td><?php echo "$bio[0] $bio[1] $bio[3] $bio[2]";?></td>
                </tr>
                <tr>
                  <td>Staff Level</td>
                  <td><?php echo $bio[9];?></td>
                  
                </tr> <tr>
                  <td>Programme</td>
                  <td><?php echo $bio[10];?></td>
                  
                </tr> <tr>
                  <td>Role</td>
                  <td><?php
				  echo getroledetails($srole[0]);
					if($srole[0] == 1){
						echo " - $srole[3]";
					}else if($srole[0] == 2){
						echo " - $srole[2]";
					}else if($srole[0] == 3){
						echo " - $srole[1]";
					};?></td>
                  
                </tr>
				<tr>
                  <td>Phonenumber</td>
                  <td><?php echo $bio[7];?></td>
                  
                </tr> 
				<tr>
                  <td>Email</td>
                  <td><?php echo $bio[8];?></td>
                  
                </tr> 
				<tr>
                  <td>Send Mail</td>
                  
                  
                </tr> 
				 
              </table>
            </div>
            <!-- /.box-body -->
          </div>
			
					 
			</div>
			</div>
			<?php
			if($role[0] == 2){
				$list = getallsessions();
				$curs = currentSession();
				
				
				foreach($list as $dat){
					
					echo '
					
					
					<div class="box box-info box-solid">
            <div class="box-header with-border">
              <h3 class="box-title">'.$dat.' Academic Session</h3>

              <div class="box-tools pull-right">
                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                </button>
              </div>
			 
			  
			  
	</div>
	 <div class="box-body" style="padding-left: 3%; padding-right: 3%;">';
	
		if($dat == $curs){
		    
		    
		     $qg = "SELECT levels FROM departments WHERE DepartmentCode='$dept'";
	$dbc = connect();
	$runqg = mysqli_query($dbc, $qg);
	$rowqg = mysqli_fetch_row($runqg);
	
	$qgt = $rowqg[0];
	
	
	$letl = 100;
		    
		    
	
			echo "<form action='lecturerprofile.php' method='POST'<div class='row'>";
				
		echo '    
<input type="hidden" name="id" value="'.$stid.'">
							<input type="hidden" name="dept" value="'.$dept.'">
							<input type="hidden" name="fac" value="'.$fac.'">';
		
		for($k = 1; $k <= $qgt; $k++){
	echo '	<div class="row">';
		$courses = numberofcoursesassign($dept, "$k");
	
        echo '<div class="col-md-12">
          <div class="box">
            <div class="box-header with-border">
              <h3 class="box-title">'.$letl.' Level</h3>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
              <table class="table table-striped">
                <tr>
                  <th style="width: 10px">Course Code</th>
                  <th>Course Title</th>
                  <th>Course Credit</th>
				  <th>Select</th>
                 
                </tr>';
				
				foreach($courses as $tet){
				echo "
				
				
				<tr>
				
				<td>$tet[7]</td> 
				<td>".getcoursetitleandunit($tet[7])[0]."</td>
				<td>".getcoursetitleandunit($tet[7])[2]."</td>
				<td>";
				$check = checkifcourseisassigned($tet[7], $stid);
				if($check == 0){
					//if it is not registered
					echo " <input type='checkbox' value='$tet[7]' name='lreccou[]'>";
				}else{
					// if it is registered
					echo " <input type='checkbox'  value='$tet[7]' name='lreccou[]' checked = 'checked' readonly >";
				}
				
				echo "
				
				</td>
					</tr>
				";
				
			}
				echo '
              </table>
            </div>
          </div>
	</div>'; 
	echo '</div>';
	$letl += 100;
	}
	
	 
	


		
			
			
			echo "
			<br>
		<br>
		<br>";
		echo '
		<input type="hidden" name="id" value="'.$stid.'">
							<input type="hidden" name="dept" value="'.$dept.'">
							<input type="hidden" name="fac" value="'.$fac.'">';
							echo "
			<button type='submit' class='btn btn btn-success btn-flat'>Assign Courses to Lecturer</button>
			</form>";
			
			
		
		
	
		
		echo '<form action="lecturerprofile.php" method="POST">
		 <div class="form-group">
                  <label>Assign Lecturer to Level as Adviser</label>
                  <select class="form-control" name="leveladviser">
                    <option>100</option>
                    <option>200</option>
                    <option>300</option>
                    <option>400</option>
                    <option>500</option>
                    <option>600</option>
                  </select>
                </div>
		
		
							
							<input type="hidden" name="id" value="'.$stid.'">
							<input type="hidden" name="dept" value="'.$dept.'">
							<input type="hidden" name="fac" value="'.$fac.'">
		
		<button type="submit" class="btn btn-success btn-flat">Submit</button>
		
		
		
		
		</form>
		<br>
		
		';
		
		
		}
		
		
		
		
		
		
		
		
		
		
		
	 
			  $cous = mycoursespersession($stid, $dat);
			echo '  <div class="table-responsive">
              <table id="example1" class="table table-bordered ">
                <thead >
                <tr>
					<th>S/N</th>
               
                                    <th>Course Code</th>
                                    <th>Course Title</th>
                                    <th>Course Description</th>
                                    <th>Course Credit</th>
									<th>Enrolled Students</th>
									
									
									<th>Action</th>
									<th>Delete Course</th>
									
									
                
             
                </tr>
                </thead>
                <tbody>';
				$x = 0;
				foreach($cous as $dt){
					echo '<tr>
					<td>'. ++$x.'</td>
					<td>'. $dt.'</td>
					<td>'. getcoursetitleandunit($dt)[0].'</td>
					<td>'. getcoursetitleandunit($dt)[1].'</td>
					<td>'. getcoursetitleandunit($dt)[2].'</td>
				
					<td>'. count (studcoursesession(getcourselevelid($dt), $dat)).'</td>
					 <td><form action ="courseexam.php" method="POST"> <input type="hidden" value="'.getcourselevelid($dt).'" name="id"> <input type="hidden" value="'.$dat.'" name="sess"> <button type="submit" class="btn btn-info btn-sm"> More </button></form></td>
					
					
					<td>
					 <div class="modal modal-danger fade" id="modal-danger'.$x.'">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">Danger Modal</h4>
              </div>
              <div class="modal-body">
                <p>Are you sure you want to delete '.$dt.' from '.$stid.'?</p>
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-outline pull-left" data-dismiss="modal">Close</button>
				<form action="lecturerprofile.php" method="post">
				<input type="hidden" name="cid" value="'.$dt.'">
				<input type="hidden" name="id" value="'.$stid.'">
							<input type="hidden" name="dept" value="'.$dept.'">
							<input type="hidden" name="fac" value="'.$fac.'">
				
                <button type="submit" name="delete" class="btn btn-outline">Delete</button>
				</form>
              </div>
            </div>
            <!-- /.modal-content -->
          </div>
          <!-- /.modal-dialog -->
        </div>
					
					
					
					
					
					<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#modal-danger'.$x.'">
                Delete
              </button>
					</td>
					
					
					</tr>';
				}
				
					 echo '
					 </tbody>
					 </table>
			</div>
			</div>
			</div>
			
					
					
					
					
					
			
					
					
					
					
					
					';
				}
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			}
			
			?>
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->

  <!-- Main Footer -->
  <footer class="main-footer">
    <!-- To the right -->
    <div class="pull-right hidden-xs">
      
    </div>
    <!-- Default to the left -->
    <strong>Copyright &copy; 2019 <a href="#">Bowen University</a>.</strong> All rights reserved.
  </footer>


  <!-- /.control-sidebar -->
  <!-- Add the sidebar's background. This div must be placed
  immediately after the control sidebar -->
  <div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->

<!-- REQUIRED JS SCRIPTS -->

<!-- jQuery 3 -->
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<!-- Bootstrap 3.3.7 -->
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
<script src="bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<script src="bower_components/jquery-ui/jquery-ui.min.js"></script>
<!-- Slimscroll -->
<script src="bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="bower_components/fastclick/lib/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="dist/js/demo.js"></script>
<!-- fullCalendar -->
<script src="bower_components/moment/moment.js"></script>
<script src="bower_components/fullcalendar/dist/fullcalendar.min.js"></script>
<!-- Page specific script -->
<!-- Page specific script -->
<script>
  $(function () {
    $('#example1').DataTable()
	$('#example3').DataTable()
    $('#example2').DataTable({
      'paging'      : true,
      'lengthChange': false,
      'searching'   : false,
      'ordering'    : true,
      'info'        : true,
      'autoWidth'   : false
    })
  })
</script>

</body>
</html>