<?php session_start();
include("connect.php");
if(!isset($_SESSION['stureg_id'])){
	header("location:index.php");
}else{
	$ddd=mysqli_query($con,"select * from student where id='".$_SESSION['stureg_id']."'");
	$me=mysqli_fetch_assoc($ddd);
	
	$bam=mysqli_query($con,"select * from `programme` where id='".$me['programme_id']."'");
	$pro=mysqli_fetch_assoc($bam);
	
	$bxm=mysqli_query($con,"select * from `department` where id='".$me['dept_id']."'");
	$dep=mysqli_fetch_assoc($bxm);
	
	$bm=mysqli_query($con,"select * from `faculty` where id='".$dep['fac_id']."'");
	$fac=mysqli_fetch_assoc($bm);
	
	$bc=mysqli_query($con,"select * from `semester` where programme_id='".$me['programme_id']."' AND session !='' AND current_semester=1 order by id desc");
	$sem=mysqli_fetch_assoc($bc);
	
	if($me['dept_id']==0 || $me['dept_id']==''){
		header("location:dashboard.php");
	}
	
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
	 <title>Add and Delete Course :: Inspire Polytechnic, Course Registration Portal</title>
   <meta name="description" content="Inspire Polytechnic, Course Registration Portal" />
	<meta name="keyword" content="Inspire Polytechnic, Course Registration, Portal, Studies, Education" />
	<meta name="author" content="Dosumu Ololade"/>
    <link rel="icon" href="img/lasu_logo.png">
	<link href="vendors/bower_components/datatables/media/css/jquery.dataTables.min.css" rel="stylesheet" type="text/css"/>
	<link href="dist/css/style.css" rel="stylesheet" type="text/css">
	
	
	
</head>

<body>
	<!--Preloader-->
	<div class="preloader-it">
		<div class="la-anim-1"></div>
	</div>
	<!--/Preloader-->
    <div class="wrapper theme-6-active pimary-color-green">
		<!-- Top Menu Items -->
		<nav class="navbar navbar-inverse navbar-fixed-top">
			<div class="mobile-only-brand pull-left">
				<div class="nav-header pull-left">
					<div class="logo-wrap">
						<a href="dashboard.php">
							<img class="brand-img" style="width:30px;" src="img/lasu_logo.png" alt="brand"/>
							
						</a>
					</div>
				</div>	
				<a id="toggle_nav_btn" class="toggle-left-nav-btn inline-block ml-20 pull-left" href="javascript:void(0);"><i class="zmdi zmdi-menu"></i></a>
				
			</div>
			<div id="mobile_only_nav" class="mobile-only-nav pull-right">
				<ul class="nav navbar-right top-nav pull-right">
					<li class="dropdown auth-drp">
						<a href="#" class="dropdown-toggle pr-0" data-toggle="dropdown"> <?php echo ucwords($me['sname']); ?> <img src="img/avatar.png" alt="user_auth" class="user-auth-img img-circle"/><span class="user-online-status"></span></a>
						<ul class="dropdown-menu user-auth-dropdown" data-dropdown-in="flipInX" data-dropdown-out="flipOutX">
							<li>
								<a href="logout.php"><i class="zmdi zmdi-power"></i><span>Log Out</span></a>
							</li>
						</ul>
					</li>
				</ul>
			</div>	
		</nav>
		<!-- /Top Menu Items -->
		
		<!-- Left Sidebar Menu -->
		<div class="fixed-sidebar-left">
			<ul class="nav navbar-nav side-nav nicescroll-bar">
				<li class="navigation-header">
					<span><?php echo $me['matric_no']?></span> 
					<i class="zmdi zmdi-more"></i>
				</li>
				
				<li>
					<a href="index.php"><div class="pull-left"><i class="fa fa-home mr-20"></i><span class="right-nav-text">Home</span></div>
					<div class="clearfix"></div></a>
				</li>
				
				<li>
					<a href="dashboard.php"><div class="pull-left"><i class="fa fa-dashboard mr-20"></i><span class="right-nav-text">Dashboard</span></div>
					<div class="clearfix"></div></a>
				</li>
				
				<li>
					<a href="registration.php"><div class="pull-left"><i class="fa fa-language mr-20"></i><span class="right-nav-text">Course Registration</span></div>
					<div class="clearfix"></div></a>
				</li>
				<li>
					<a href="add_delete.php" class="active"><div class="pull-left"><i class="fa fa-edit mr-20"></i><span class="right-nav-text">Add & Delete Course</span></div>
					<div class="clearfix"></div></a>
				</li>
				<li>
			<a href="course_form.php"><div class="pull-left"><i class="fa fa-print mr-20"></i><span class="right-nav-text">Print Course Form</span></div>
					<div class="clearfix"></div></a>
				</li>
				<li>
			<a href="exam_slip.php"><div class="pull-left"><i class="icon icon-notebook mr-20"></i><span class="right-nav-text"> Exam Slip</span></div>
					<div class="clearfix"></div></a>
				</li>
				<li>
			<a href="logout.php"><div class="pull-left"><i class="fa fa-power-off mr-20"></i><span class="right-nav-text">Logout</span></div>
					<div class="clearfix"></div></a>
				</li>
			</ul>
		</div>
		<!-- /Left Sidebar Menu -->
		
		
		
		
		<!-- Right Sidebar Backdrop -->
		<div class="right-sidebar-backdrop"></div>
		<!-- /Right Sidebar Backdrop -->

        <!-- Main Content -->
		<div class="page-wrapper">
            <div class="container-fluid pt-25">
					
					<div class="row">
					
					<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
						<div class="panel panel-success card-view pa-0">
							<div class="panel-wrapper collapse in">
								<div class="panel-body pa-0">
						<div align="center"><img src="img/logo.png" style="width:250px; padding:20px 5px;" class="img-responsive"></div>
									
								</div>
							</div>
						</div>
					</div>
					
					<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
						<div class="panel panel-default card-view ">
							<div class="panel-wrapper collapse in">
								<div class="panel-body pa-0">
									<div class="sm-data-box">
										<div class="container-fluid">
											<div class="row">
												<div style="margin-top:-12px;margin-bottom:-12px;" class="col-md-12 text-center pl-0 pr-0 data-wrap-left">
													<span class="txt-dark block counter" style="font-weight:600;">
													<i class="fa fa-edit"></i> ADD & DELETE COURSE</span>
												</div>
											</div>	
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
					
				</div>
					
				<!-- Row -->
					
				
				<div class="row">
				
					<div class="col-md-4">
					<div class="panel panel-default card-view pa-0">
							<div class="panel-wrapper collapse in">
								<div class="panel-body pa-0" style="padding-left:;">
									<div class="sm-data-box">
										<div class="container-fluid">
											<div class="row">
												<div class="col-xs-6 text-center pl-0 pr-0 data-wrap-left">
													<span class="txt-dark block counter" style="font-size:18px; padding-left:14px;">
													<?php echo $pro['name']; ?></span>
													<span class="weight-500 uppercase-font block font-12 pt-10">Programme</span>
												</div>
												<div class="col-xs-6 text-center  pl-0 pr-0 data-wrap-right">
													<i class="fa fa-certificate data-right-rep-icon txt-light-grey"></i>
												</div>
											</div>	
										</div>
									</div>
								</div>
							</div>
						</div>
						</div>
						
						<div class="col-md-4">
						<div class="panel panel-default card-view pa-0">
							<div class="panel-wrapper collapse in">
								<div class="panel-body pa-0" style="padding-left:;">
									<div class="sm-data-box">
										<div class="container-fluid">
											<div class="row">
												<div class="col-xs-6 text-center pl-0 pr-0 data-wrap-left">
													<span class="txt-dark block counter" style="font-size:18px; padding-left:14px;">
													<?php echo $dep['department'];	?></span>
													<span class="weight-500 uppercase-font block font-12 pt-10">Department</span>
												</div>
												<div class="col-xs-6 text-center  pl-0 pr-0 data-wrap-right">
													<i class="fa fa-graduation-cap data-right-rep-icon txt-light-grey"></i>
												</div>
											</div>	
										</div>
									</div>
								</div>
							</div>
						</div>
						</div>
						
						<div class="col-md-4">
						<div class="panel panel-default card-view pa-0">
							<div class="panel-wrapper collapse in">
								<div class="panel-body pa-0" style="padding-left:;">
									<div class="sm-data-box">
										<div class="container-fluid">
											<div class="row">
												<div class="col-xs-6 text-center pl-0 pr-0 data-wrap-left">
													<span class="txt-dark block counter" style="font-size:18px; padding-left:14px;">
													<?php 
													if(mysqli_num_rows($bc)==0){
														echo 'Not Defined!';
													}else if($sem['session']!=''){
														echo $sem['session'];	
													}else{
														echo 'Not Defined!';	
													}
													?></span>
													<span class="weight-500 uppercase-font block font-12 pt-10">Current Academic Session</span>
												</div>
												<div class="col-xs-6 text-center  pl-0 pr-0 data-wrap-right">
													<i class="fa fa-calendar data-right-rep-icon txt-light-grey"></i>
												</div>
											</div>	
										</div>
									</div>
								</div>
							</div>
						</div>
						</div>
						
					
					</div>
					</div>
					
					<div class="row">
					<div class="col-md-5">
					<?php
	$bp=mysqli_query($con,"select * from `semester` where programme_id='".$me['programme_id']."' AND add_delete_control=1 AND session !='' order by id desc");
	
	$mama=mysqli_query($con,"select dep_id,id,sid,matric_no,semester_num,session,programme_id,programme from reg_course where sid='".$me['id']."' AND matric_no='".$me['matric_no']."' AND dep_id='".$me['dept_id']."' AND programme_id='".$me['programme_id']."' AND programme='".$pro['name']."' AND session='".$sem['session']."' AND semester_num='".$sem['semester']."'");
	
	if(mysqli_num_rows($bp)==0){
		echo '<div class="alert alert-warning alert-dismissable" style="font-size:18px;">
											<i class="fa fa-exclamation-circle" style="font-size:25px;"></i>
											<span style="color:;">SORRY! Add and delete course period has expired or yet to be opened...</span>
										</div>
										<div class="panel panel-default card-view pa-0">
							<div class="panel-wrapper collapse in">
								<div class="panel-body pa-0" style="padding-left:;">
									<img src="img/banner3.png" class="img-responsive">
								</div>
							</div>
						</div>';
	}else if(mysqli_num_rows($mama)==0){
		echo '<div class="alert alert-danger alert-dismissable" style="font-size:16px;">
											<i class="fa fa-ban" style="font-size:25px;"></i>
					<span style="color:;">SORRY! You are not eligible to use the add and delete course module because you did not register for any course in this current semester...</span>
										</div>
										<div class="panel panel-default card-view pa-0">
							<div class="panel-wrapper collapse in">
								<div class="panel-body pa-0" style="padding-left:;">
									<img src="img/banner3.png" class="img-responsive">
								</div>
							</div>
						</div>';
	}else{
							
			///////////////////////////////// payment
				
				
				/////////// to verify student tution fee
			$ssm=mysqli_query($con,"select * from semester where programme_id='".$me['programme_id']."' AND add_delete_control=1 AND session !=''");
			if(mysqli_num_rows($ssm)>0){
				
			$ckk=mysqli_fetch_assoc($ssm);
			
			$cax=mysqli_query($con,"select * from semester where programme_id='".$me['programme_id']."'");
			$fal=mysqli_fetch_assoc($cax);
			
			$cav=mysqli_query($con,"select SUM(fraction) as fraction from payment where matric_no='".trim($me['matric_no'])."' AND session='".trim($ckk['session'])."'");
			$pdp=mysqli_fetch_assoc($cav);
			$pay_sum=$pdp['fraction'];
			
			if($pay_sum==0 || $pay_sum==''){
				
				echo '<div class="panel-body pa-10 hidden-xs hidden-sm" style="padding-left:;">
			<img src="img/banner1.png" style="width:360px;" class="img-responsive">
								</div>';
								
			}else{
				$pay_sum=$pay_sum;
			
				if(mysqli_num_rows($cax)==1 && $pay_sum<1.0){ //if programme is only one semester and yet to complete payment
				echo '<div class="panel-body pa-10 hidden-xs hidden-sm" style="padding-left:;">
			<img src="img/banner1.png" style="width:360px;" class="img-responsive">
								</div>';	
				}else if($ckk['semester']==1 && $pay_sum<0.7){ // if in the 1st semester and student is yet to pay up to 70%
					echo '<div class="panel-body pa-10 hidden-xs hidden-sm" style="padding-left:;">
			<img src="img/banner1.png" style="width:360px;" class="img-responsive">
								</div>';
				}else if($ckk['semester']>1 && $pay_sum<1.0){ // if in the 2nd or 3rd semester and student is yet to pay up
					echo '<div class="panel-body pa-10 hidden-xs hidden-sm" style="padding-left:;">
			<img src="img/banner1.png" style="width:360px;" class="img-responsive">
								</div>';
				}else{ ///////////////// IF STUDENT TUTION HAS BEEN PAID UP TO THE CURRENT SEMESTER
				
				
				
				///////////////////////////////// payment
							
							
							
							echo '<div class="panel  panel-primary card-view">
					<div class="panel-heading">
									<div class="pull-left">
										<h6 class="panel-title" style="color:white; font-weight:bold; font-size:15px; margin-top:-10px; margin-bottom:-10px;">REGISTERED COURSE</h6>
									</div>
									</div>
									<div class="panel-body">
									
									<div class="table-wrap mt-20">
										<div class="table-responsive">
										  <table class="table table-hover table-bordered mb-0">
											<thead>
											  <tr>
												<th style="font-weight:bold;padding:6px;">COURSE CODE</th>
												<th style="font-weight:bold;padding:6px;">COURSE TITLE</th>
												<th style="font-weight:bold;padding:6px;">STATUS</th>
												<th style="font-weight:bold;padding:6px;">UNITS</th>
												<th style="padding:6px;"></th>
											  </tr>
											</thead>
											<tbody>';
			$bo=mysqli_query($con,"select * from `semester` where programme_id='".$me['programme_id']."' AND add_delete_control=1 AND session !='' order by id desc");
			$sek=mysqli_fetch_assoc($bo);
			
			$mac=mysqli_query($con,"select * from reg_course where sid='".$_SESSION['stureg_id']."' AND  matric_no='".$me['matric_no']."' AND programme_id='".$me['programme_id']."' AND semester_num='".$sek['semester']."' AND dep_id='".$me['dept_id']."' AND session='".$sek['session']."' order by course_code asc");
	
	$sum_unit=0;		
	if(mysqli_num_rows($mac)>0){
	$ms=0;
	while($cos=mysqli_fetch_assoc($mac)){
		$sum_unit +=$cos['unit'];
		$ms=$ms+1;
		echo '<tr id="'.$cos['id'].'">
		<td align="center" style="padding:5px; font-size:13px;">'.strtoupper($cos['course_code']).'</td>
		<td style="padding:5px; font-size:13px;">'.strtoupper($cos['description']).'</td>
		<td align="center" style="padding:5px; font-size:13px;">'.strtoupper($cos['status']).'</td>
		<td align="center" style="padding:5px; font-size:13px;">'.$cos['unit'].'</td>
		<td align="center" style="padding:5px; font-size:15px;"><a title="Remove '.strtoupper($cos['course_code']).'" href="javascript:void(0)" class="remove_course" id="'.$cos['id'].'"><i class="fa fa-trash text-danger"></i></a></td>
		</tr>';
	}
	}else{
		$sum_unit =0;
		$ms=0;
		echo '<tr class="no_course_found"><td colspan="5" align="center">No course registered, you can use the add course module below!</td></tr>';
	}
			
							echo '</tbody></table></div></div>
		
		<input type="hidden" name="execute_add_delete" value="true">
		
		<div class="row">
		
		<div class="col-md-4" style="color:black; margin-top:9px; font-size:15px; text-align:center;">Min. TNU: <span style="font-weight:600;font-size:18px; color:#ff9900;">'.$sek['min_tnu'].'</span></div>
		
		<div class="col-md-4" style="color:black; margin-top:9px; font-size:15px; text-align:center;">Reg. TNU: <span style="font-weight:600;font-size:18px; color:#0066ff;" class="text_tnu">'.$sum_unit.'</span></div>
		
		<div class="col-md-4" style="color:black; margin-top:9px; font-size:15px; text-align:center;">Max. TNU: <span style="font-weight:600;font-size:18px; color:#00cc99;">'.$sek['max_tnu'].'</span></div>
		
		</div>
		<div class="error1"></div>
		
							</div></div>';
			

////////////////// payment	
} 
				
			}
			}

/////////////////  payment


			
						}
					
					?>
					
					
					</div>
					
					<div class="col-md-7">
					<?php
	$bz=mysqli_query($con,"select * from `semester` where programme_id='".$me['programme_id']."' AND add_delete_control=1 AND session !='' order by id desc");
	if(mysqli_num_rows($bz)==0 || mysqli_num_rows($mama)==0){
		echo '<div class="panel-body pa-10" style="padding-left:;">
			<img src="img/banner5.png" class="img-responsive">
								</div>';
						}else{
							
							
					///////////////////////////////// payment
				
				
				/////////// to verify student tution fee
			$ssm1=mysqli_query($con,"select * from semester where programme_id='".$me['programme_id']."' AND add_delete_control=1 AND session !=''");
			if(mysqli_num_rows($ssm1)>0){
				
			$ckk1=mysqli_fetch_assoc($ssm1);
			
			$cax1=mysqli_query($con,"select * from semester where programme_id='".$me['programme_id']."'");
			$fal1=mysqli_fetch_assoc($cax1);
			
			$cav1=mysqli_query($con,"select SUM(fraction) as fraction from payment where matric_no='".trim($me['matric_no'])."' AND session='".trim($ckk1['session'])."'");
			$pdp1=mysqli_fetch_assoc($cav1);
			$pay_sum1=$pdp1['fraction'];
			
			if($pay_sum1==0 || $pay_sum1==''){
				echo '<div class="alert alert-danger" style="font-size:19px;">
											<i class=" fa fa-exclamation-circle " style="font-size:30px;"></i>&nbsp;
											<span>You are yet to pay your tution fee for '.$ckk1['session'].' academic session</span>
										</div>';
			}else{
				$pay_sum1=$pay_sum1;
			
				if(mysqli_num_rows($cax1)==1 && $pay_sum1<1.0){ //if programme is only one semester and yet to complete payment
				echo '<div class="alert alert-danger" style="font-size:19px;">
											<i class=" fa fa-exclamation-circle " style="font-size:30px;"></i>&nbsp;
											<span>You are yet to complete your tution fee for '.$ckk1['session'].' academic session</span>
										</div>';	
				}else if($ckk1['semester']==1 && $pay_sum1<0.7){ // if in the 1st semester and student is yet to pay up to 70%
					echo '<div class="alert alert-danger" style="font-size:19px;">
											<i class=" fa fa-exclamation-circle " style="font-size:30px;"></i>&nbsp;
											<span>You are yet to complete your tution fee for '.$ckk1['session'].' academic session</span>
										</div>';
				}else if($ckk1['semester']>1 && $pay_sum1<1.0){ // if in the 2nd or 3rd semester and student is yet to pay up
					echo '<div class="alert alert-danger" style="font-size:19px;">
											<i class=" fa fa-exclamation-circle " style="font-size:30px;"></i>&nbsp;
											<span>You are yet to complete your tution fee for '.$ckk1['session'].' academic session</span>
										</div>';
				}else{ ///////////////// IF STUDENT TUTION HAS BEEN PAID UP TO THE CURRENT SEMESTER
				
				
				
				///////////////////////////////// payment	
							
							
							
							echo '
							<form method="post" id="form_submit">		
			<input type="hidden" name="execute_add_delete" value="true">
		<input type="hidden" value="'.$sum_unit.'" name="sum_tnu" class="sum_tnu">
							
							<div class="panel  panel-primary card-view">
					<div class="panel-heading">
									<div class="pull-left">
										<h6 class="panel-title" style="color:white; font-weight:bold; font-size:15px; margin-top:-10px; margin-bottom:-10px;">SELECT COURSE TO ADD</h6>
									</div>
									</div>
									<div class="panel-body">
								
<div style="margin-bottom:30px;" align="center">
<div class="form-group" align="center" style="margin-top:5px; margin-bottom:5px; border:1px solid #00e6ad; padding:12px;">
<label for="extra_year" style="color:#008060;"> 
<input type="checkbox" id="extra_year" value="extra_year" name="extra_year" /> Click to indicate that you are an extra year student!</label>
</div>

									</div>


								
									<div class="table-wrap" style="max-height:500px; overflow-x:hidden;">
										  <table id="example" style="border:1px solid lavender;" class="table table-hover table-bordered mb-0">
											<thead>
											  <tr>
												<th style="padding:6px;"></th>
												<th style="font-weight:bold;padding:6px;">COURSE CODE</th>
												<th style="font-weight:bold;padding:6px;">COURSE TITLE</th>
												<th style="font-weight:bold;padding:6px;">DEPT</th>
												<th style="font-weight:bold;padding:6px;">STATUS</th>
												<th style="font-weight:bold;padding:6px;">UNITS</th>
											  </tr>
											</thead>
											<tbody>';
	$ba=mysqli_query($con,"select * from `semester` where programme_id='".$me['programme_id']."' AND add_delete_control=1 AND session !='' order by id desc");
	$sam=mysqli_fetch_assoc($ba);
	
	$mic=mysqli_query($con,"select level from reg_course where sid='".$_SESSION['stureg_id']."' AND  matric_no='".$me['matric_no']."' AND programme_id='".$me['programme_id']."' AND semester_num='".$sam['semester']."' AND dep_id='".$me['dept_id']."' AND session='".$sam['session']."' order by level desc limit 1");
	$sic=mysqli_fetch_assoc($mic);
	
	if(mysqli_num_rows($mic)>0){
		echo '<div style="text-decoration:underline; font-size:18px;">Level: <input type="text" name="s_level" value="'.$sic['level'].'" readonly style="font-weight:600; color:gray; cursor:default; border:0; background:transparent; box-shadow:0;">
		<div class="hidden-xs hidden-sm" style="margin-bottom:-30px;"></div>
		</div>';
		$ll=$sic['level'];
		$level_query= "AND level<='$ll'";
		//$level_query= "AND (t1.level<'$ll' OR t1.level='$ll')";
	}else{
		
		echo '<div class="form-group col-md-4">
			<label class="control-label mb-5" for="email_de">Select Level</label>
			<select class="form-control" name="s_level" required>
			<option value="">Select</option>';
				for($y=1; $y<=9; $y++){
				echo '<option>'.$y.'00</option>';
									}
												
					echo '</select>
					<div class="hidden-xs hidden-sm" style="margin-bottom:-25px;"></div>
					</div>';
		$ll='';
		$level_query= "";
	}
	
	//$mec=mysqli_query($con,"select * from course where programme_id='".$me['programme_id']."' AND semester_id='".$sam['id']."' $level_query AND `course_code` NOT IN (select course_code from reg_course where programme_id='".$me['programme_id']."' AND semester_num='".$sam['semester']."' AND dep_id='".$me['dept_id']."' AND session='".$sam['session']."' AND sid='".$_SESSION['stureg_id']."' AND  matric_no='".$me['matric_no']."') order by course_code asc ");
	
	//$mec=mysqli_query($con,"select dep_id,id,course_code,description,unit,status,level from course where programme_id='".$me['programme_id']."' AND semester_id='".$sam['id']."' $level_query  order by course_code asc");
	
/* $mec=mysqli_query($con,"SELECT t1.course_code,t1.dep_id,t1.description,t1.unit,t1.status,t1.level,t1.id, t1.programme_id, t1.semester_id
FROM course t1
INNER JOIN
(
    SELECT status,unit,course_code, MAX(id) AS latest_id
    FROM course
    GROUP BY course_code,status,unit
) t2
    ON t1.course_code = t2.course_code AND t1.id = t2.latest_id

	where t1.programme_id='".$me['programme_id']."' AND t1.semester_id='".$sam['id']."' $level_query ORDER BY t1.course_code asc"); */

$mec=mysqli_query($con,"select * from course where programme_id='".$me['programme_id']."' AND semester_id='".$sam['id']."' $level_query AND `course_code` NOT IN (select course_code from reg_course where programme_id='".$me['programme_id']."' AND semester_num='".$sam['semester']."' AND dep_id='".$me['dept_id']."' AND session='".$sam['session']."' AND sid='".$_SESSION['stureg_id']."' AND  matric_no='".$me['matric_no']."') order by course_code asc ");	
	
	$mmm=0;
	
	while($ele=mysqli_fetch_assoc($mec)){
	$mmm=$mmm+1;
	
		$das=mysqli_query($con,"select * from department where id='".$ele['dep_id']."'");
		$dept=mysqli_fetch_assoc($das);
	
		echo '<tr id="'.$ele['id'].'">
		<td align="center" style="padding:5px;">
		<input type="checkbox" class="checker" name="cid[]" value="'.$ele['id'].'" />
		</td>
		<td align="center" style="padding:5px; font-size:13px;">'.strtoupper($ele['course_code']).'</td>
		<td style="padding:5px; font-size:13px;">'.strtoupper($ele['description']).'</td>
		<td style="padding:5px; font-size:12px;">'.strtoupper($dept['department']).'</td>
		<td align="center" style="padding:5px; font-size:13px;">'.strtoupper($ele['status']).'</td>
		<td align="center" style="padding:5px; font-size:13px;">'.$ele['unit'].'</td>
		</tr>';
	}
							echo '</tbody>
							
							</table></div>
<hr>
<div class="error"></div>

<a href="add_delete.php" class="pull-left btn btn-default">Refresh <i class="fa fa-refresh"></i></a>
<button type="submit" class="pull-right btn btn-success">Add Course</button>
									<div class="clearfix"></div>
		
		
		
		
					
					
					
							</div></div></form>';
						
						
						////////////////// payment	
} 
				
			}
			}

/////////////////  payment
						
						
						
						}
					
					?>
					
					
					</div>
					
					
				
					
				</div>
				<!-- /Row -->
			<footer class="footer container-fluid pl-30 pt-50 pr-30">
				<div class="row" style="background:white;">
					<div class="col-sm-12">
						<p style="text-align:center;"> &copy; Copyright <?php echo date("Y");?> Inspire Polytechnic. All rights reserved</p>
					</div>
				</div>
			</footer>
			</div>
			<!-- Footer -->
			
			<!-- /Footer -->
			
		</div>
        <!-- /Main Content -->

   
    <!-- /#wrapper -->
	
	<!-- JavaScript -->
	
    <!-- jQuery -->
    <script src="vendors/bower_components/jquery/dist/jquery.min.js"></script>
	
	<script>
	jQuery().ready(function(){
		
			$("a.remove_course").click(function(){
		if(confirm("Are you sure you want to delete course?"))
		  {
		var remove_course=$(this).attr("id");
		var s_tnu =$("input.sum_tnu").val();
		$.ajax({
						type: "POST",
                        url: "add_exe.php",
                        data: ({remove_course:remove_course,s_tnu:s_tnu}),
                        cache: false,
                        success: function(data){ 
						
						if(data.indexOf("minimum reached!")> -1){
							
							$("div.error1").html('').fadeIn();
							$("div.error1").html('<br><div class="alert alert-dismissible alert-danger">\
				<strong>SORRY!</strong> Course cannot be removed, Min TNU attained.</div>').delay(6000).fadeOut();
				
						}else{
							$("div.error1").html("");
						$("tr#"+remove_course).animate({ backgroundColor: "#fbc7c7" }, "fast").animate({ opacity: "hide" }, "slow");
						$("input.sum_tnu").val(parseInt(data));
						$("span.text_tnu").text(data);
						}
						
						 } 
 });
	
		}
return false;
		});
		
		
$('#example').DataTable( {
		dom: 'Bfrtip',
		buttons: [
			'copy', 'csv', 'excel', 'pdf', 'print'
		],
		"ordering": false,
		"info": false,
		"paging": false,
		"pageLength": <?php echo mysqli_num_rows($mec)?>,
		"fnDrawCallback": function(oSettings){
			
			
		/* $("input.checker").click(function(){
			if($(this).is(":checked")){
				var signal = 'add';
				var course_id = $(this).val();
			}else{
				var course_id =$(this).val();
				var signal='delete';
			}
			var added_tnu= parseInt($("input.add_new_tnu").val());
			$.ajax({
						type: "POST",
                        url: "add_exe.php",
                        data: ({signal:signal,course_id:course_id,tnu:added_tnu}),
                        cache: false,
                        success: function(data){
						$("input.add_new_tnu").val(parseInt(data));
						 } 
 });	
		}); */
		
		
		}
	} );
		
		
	$("form#form_submit").on('submit',(function(e){
	e.preventDefault();
	if(confirm("Are you sure you want to submit?"))
		  {
	$("div.error").html("<p class='text-primary' style='padding:5px; text-align:center;'><i class='fa fa-spin fa-spinner'></i> Processing Request...</p>");
	$('#example').DataTable().search('').draw();
				$.ajax({
						type: "POST",
                        url: "add_exe.php",
                        data: new FormData(this),
						contentType:false,
						processData:false,
                        cache: false,
                        success: function(data){ 
						$("div.error").html(data);
						}
    });		
	}
return false;	
		}));
		
		
	});
	</script>
	

    <!-- Bootstrap Core JavaScript -->
    <script src="vendors/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
	<script src="vendors/bower_components/switchery/dist/switchery.min.js"></script>
	<script src="vendors/bower_components/select2/dist/js/select2.full.min.js"></script>
	<script src="vendors/bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
	<script src="dist/js/jquery.slimscroll.js"></script>
	<script src="dist/js/dropdown-bootstrap-extended.js"></script>
	<script src="vendors/bower_components/switchery/dist/switchery.min.js"></script>
	<script src="dist/js/init.js"></script>
	<script src="dist/js/form-advance-data.js"></script>
	<script src="dist/js/dashboard-data.js"></script>

</body>

</html>
