<?php

 
session_start();


//call the db
//require_once 'includes/configuration.php';

require_once('../db/configuration.php');


//call all the functions
//include '../includes/functions.php';

//authentication
include '../includes/course_auth.php';

$errors = array();
$info = array();
$info_success = array();



//uid
if(isset($_GET['u']))
{
	$get_uid = $_GET['uid'];
	
	$flu = $_GET['flu'];
}


//uid
if(isset($_POST['u']))
{
	$post_uid = $_POST['u'];
	
	$flu = $_POST['flu'];
}

$result = mysqli_query(dbc(),"SELECT * FROM users WHERE user_id = '{$_GET['musty']}'"); 
		$row = mysqli_fetch_assoc($result);
		$c_id = $row['course_id'];
		$d_id = $row['department_id'];
  




?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>School Of Health Technology Course Registeration Form</title>

    <!-- include all the css files, js files, database configuration and all other included stuffss -->
    <?php include '../includes/course_reg_includes.php'; ?>
    
    
    
    <!-- CSS code from Bootply.com editor -->
        
        <style type="text/css">
            body {
				padding-top:50px;
			}
			
			#masthead {
				min-height:250px;
			}
			
			#masthead h1 {
				font-size: 30px;
				line-height: 1;
				padding-top:20px;
			}
			
			#masthead .well {
				margin-top:8%;
			}
			
			@media screen and (min-width: 768px) {
				#masthead h1 {
					font-size: 50px;
				}
			}
			
			.navbar-bright {
				background-color:#111155;
				color:#fff;
			}
			
			.affix-top,.affix{
				position: static;
			}
			
			@media (min-width: 979px) {
			  #sidebar.affix-top {
				position: static;
				margin-top:30px;
				width:228px;
			  }
			  
			  #sidebar.affix {
				position: fixed;
				top:70px;
				width:228px;
			  }
			}
			
			#sidebar li.active {
				border:0 #eee solid;
				border-right-width:4px;
			}
			
					</style>
   
    
</head>

<body>

	<!-- header goes in here -->
    <?php include '../includes/course_header2.php'; ?>
    <!-- /header -->
   
   
    <!-- container -->
    <div class="container">
    	
       
            <div  style="height:20px">
              
            </div><!-- /alert info -->
            
            
           
          
            <div class="row">
             
         
               		  <div class="panel panel-info">
                      
       <?php
		$get1=mysqli_query(dbc(),"SELECT * FROM `registered_subjects` WHERE `department_id`='$d_id' AND `course_id`=$c_id AND `user_id`='{$_GET['musty']}'");
		?>
<?php
if(mysqli_num_rows($get1)>=1){
?>
<legend><b>All Courses You Have Registered..</b></legend><center>
<table width="95%" border="2" cellspacing="1">
	<tr class="thead">
        <td width="23%" height="24" align="center"><b>Course Code</b></td>
    <td width="34%"  align="center"><b>Course Title</b></td>
      <td width="14%" align="center"><b>Course Unit(s)</b></td>
      <td width="15%" align="center"><b>Semester</b></td>
      <td width="14%" align="center"><b>Status</b></td>
    </tr>
  <?php
 
  	while($l=mysqli_fetch_array($get1)){

	echo "<tr class= \"trodd\">";
	?>
    <td height="21"  align="center"><?php echo get_subject_code($l['subject_id']);?></td>
     <td><?php echo get_subject_name($l['subject_id']);?></td>
     <td align="center"><?php echo get_subject_unit($l['subject_id']);?></td>
     <td align="center"><?php echo get_subject_semester($l['subject_id']);?></td>     
 <td align="center"><b style="color:#F00;"><?php echo "Registered"; ?></b></td>
 </tr>
 
 <?php 

}

   }

	
?>  </table>                        
                      <br/>
                      
                      
               		    <?php
                        if(mysqli_num_rows($get1)<1){
//		echo "<p style='margin:30px 0 30px 0; text-align:center; border:1px solid #CCC;'>No Courses Have Been Registered</p>";
	
		$get=mysqli_query(dbc(),"SELECT * FROM `subject` WHERE `department_id`='$d_id' AND `course_id`='$c_id' ");
		
		if(mysqli_num_rows($get)<0){
		echo "<p style='margin:30px 0 30px 0; text-align:center; border:1px solid #CCC;'>No Courses Available</p>";
		}
		?>
<legend><b>All Courses To Be Offered </b><?php
if(mysqli_num_rows($get)>0){
?>
</legend><center><table width="83%" border="2" cellspacing="1">
	<tr class="thead">
        <td align="center"><b>Course Code</b></td>
    <td  align="center"><b>Course Title</b></td>
      <td align="center"><b>Course Unit(s)</b></td>
      <td align="center"><b>Semester</b></td>
    </tr>
  <?php
 
  	while($l=mysqli_fetch_array($get)){
		 $subid=$l['subject_id'];
		 $snit=$l['subject_unit'];
		 
	echo "<tr class= \"trodd\">";
	?>
    <td  align="center"><?php echo $l['subject_code'];?></td>
     <td><?php echo $l['subject_title'];?></td>
     <td align="center"><?php echo $l['subject_unit'];?></td>
     <td align="center"><?php echo $l['semester'];?></td>
     <td ><br/><form method="post">
     <input type="hidden" name="s_id" value="<?php echo $subid; ?>"/>
     <input type="hidden" name="dd_id" value="<?php echo $d_id; ?>"/>
      <input type="hidden" name="cc_id" value="<?php echo $c_id; ?>"/>
<!--      <input type="text" name="musas" value="<?php //echo $snit; ?>"/>-->
     
     </form><br/>
     
     </td>
 </tr>
 <tr><td>
 
 
 
 <?php 
if(isset($_POST['register'])){
$sss_id=mysql_real_escape_string($subid);
$cc_id=mysql_real_escape_string($c_id);
$dd_id=mysql_real_escape_string($d_id);
$ut=mysql_real_escape_string($snit);

$qry412="INSERT INTO `registered_subjects` (`department_id`, `course_id`, `subject_id`,`subject_unit` ,`year`,`user_id` ) VALUES ('$dd_id', '$cc_id', '$sss_id', '$ut',NOW(),'{$_GET['musty']}')";
					$rst412 =  mysqli_query($dbc,$qry412);

}

}

   }


?>
<tr><td>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
 <input type="submit" name="register" value="Register"/>
 </form>
 </td></tr>
</table>

<?php } ?>


</center>
                        <a href="javascript:doit()"> <img src="../images/print_big.png" border=0  class="pull-right" title="Print" height="30" width="45"> </a>
              </div>
                    </div><!-- /panel -->

                
                
                
                  
                </div><!-- /col-md-6 -->
               
                
                <div class="col-md-6">
                <!-- notification -->
                <?php   include '../includes/notifications.php'; //show notification  ?>
                
                 
               
            </div><!-- /col-md-8 -->
               
              
     	        
            
               
                
                
                <!-- sign up on social media -->
                <div class="row"></div>
                <!-- /row -->
        

				
              
    

	
	
	
	<!-- footer starts -->
	<?php include '../includes/footer.php';?>


    </div>
    <!-- /.container -->

    <!-- JavaScript -->
     <!-- call the jquery files, so as not to slow the web page -->
    <?php include '../js/jquery_plugins.php'; ?>
    

    
</body>

</html>
