<?php session_start();
include("../connect.php");

if(isset($_SESSION['lasuadmincoursereg_id'])){
$ddd=mysqli_query($con,"select * from admin where id='".$_SESSION['lasuadmincoursereg_id']."'");
$adm=mysqli_fetch_assoc($ddd);

}

if(isset($_POST['update_programme'])){
	$qry=mysqli_query($con,"update programme set name='".$_POST['upd_name']."', description='".$_POST['upd_description']."' where id='".$_POST['update_programme']."'");
	if($qry){
		echo '<script>
		alert("Programme Update!")
		location.href="dashboard.php"
		</script>';
	}else{
		echo '<div class="alert alert-danger alert-dismissable">
											<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
											<i class="zmdi zmdi-block pr-15 pull-left"></i><p class="pull-left">OPPS! Unable to complete operation, please try again later.</p>
											<div class="clearfix"></div>
										</div>';
	}
	
	
}


if(isset($_POST['update_course'])){
	$qry=mysqli_query($con,"update course set course_code='".strtolower(trim($_POST['upd_course_code']))."', description='".strtolower(trim($_POST['upd_description']))."', status='".strtolower(trim($_POST['upd_status']))."', unit='".trim($_POST['upd_unit'])."', level='".$_POST['upd_level']."' where id='".$_POST['update_course']."'");
	
	if($qry){
		echo '<script>
		alert("Course Updated!")
		location.href="course_bank.php"
		</script>';
	}else{
		echo '<div class="alert alert-danger alert-dismissable">
											<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
											<i class="zmdi zmdi-block pr-15 pull-left"></i><p class="pull-left">OPPS! Unable to complete operation, please try again later.</p>
											<div class="clearfix"></div>
										</div>';
	}
}

if(isset($_POST['check_student'])){
	$sl=0;
	$dad=mysqli_query($con,"select * from student where id='".$_POST['check_student']."'");
	$mad=mysqli_fetch_assoc($dad);
	
	$mc=mysqli_query($con,"select sid,semester_num,session,semester_description from reg_course where sid='".$mad['id']."' AND  matric_no='".$mad['matric_no']."' AND programme_id='".$mad['programme_id']."' AND dep_id='".$mad['dept_id']."' AND session !='' GROUP BY semester_num, session order by session desc, semester_num desc");
	
	echo '<div class="row"> <div class="s_error"></div>';
	if(mysqli_num_rows($mc)>0){
	while($ala=mysqli_fetch_assoc($mc)){

	$sl=$sl+1;
	
						$rand=rand(1,6);
						if($rand==1){
							$color='#ffb31a';
						}else if($rand==2){
							$color='#0066ff';
						}else if($rand==3){
							$color='#e60000';
						}else if($rand==4){
							$color='#00994d';
						}else if($rand==5){
							$color='#ffb31a';
						}else if($rand==6){
							$color='#cc0066';
						}else{
							$color='#00b2b3';
						}
			// sid, semester_num, session
			echo '<div class="col-md-6"> 
						<a href="javascript:void(0)" class="see_student_course" id="'.$ala['sid'].'_'.$ala['semester_num'].'_'.$ala['session'].'" data-toggle="tooltip" data-placement="top" title="See Registered Courses">
						
						<div class="panel panel-default card-view pa-0" style="margin:10px;">
							<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 class="col-xs-6 text-center pl-0 pr-0 data-wrap-left">
							<span class="txt-dark block counter">'.$ala['session'].'</span>
						<span class="weight-500 uppercase-font block" style="margin-top:5px;color:#a6a6a6;">'.ucwords(strtolower($ala['semester_description'])).'</span>
												</div>
												<div class="col-xs-6 text-center  pl-0 pr-0 data-wrap-right">
													<i class="icon-layers data-right-rep-icon txt-light-grey"></i>
												</div>
											</div>	
										</div>
									</div>
								</div>
							</div>
						</div>
						</a></div>';
	
	
	}
	}else{
		$sl=$sl+0;
	}
	
	if($sl==0){
		echo '<div class="alert" align="center">
			<i class="fa fa-exclamation-triangle txt-warning" style="font-size:74px;"></i>
			<p style="color:#cc5200; font-size:24px; margin-top:30px;"><span style="font-weight:bold;">OPPS!</span> No course registration record found.</p>
			</div>';
	}
	echo '</div>';
	
}

if(isset($_POST['update_exam_slip'])){
	if($_POST['exam_slip_switch']==1 && $_POST['exam_slip_password']==''){
		echo '<div class="alert alert-danger alert-dismissable">
											<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
											<i class="zmdi zmdi-block pr-15 pull-left"></i><p class="pull-left">OPPS! You forgot to enter Invigilators verification password.</p>
											<div class="clearfix"></div>
										</div>';
	}else{
		
	$mig=mysqli_query($con,"select * from semester where id='".$_POST['exam_slip_semester']."' AND programme_id='".$_POST['exam_slip_programme']."'");
	$sig=mysqli_fetch_assoc($mig);
	if($_POST['exam_slip_switch']==1){
		$pass=$_POST['exam_slip_password'];
		mysqli_query($con,"update semester set exam_slip=0 where programme_id='".$_POST['exam_slip_programme']."'");
	}else{
		$pass=$sig['exam_slip_password'];
	}
	
	$mag=mysqli_query($con,"update semester set exam_slip='".$_POST['exam_slip_switch']."', exam_slip_password='$pass' where id='".$_POST['exam_slip_semester']."' AND programme_id='".$_POST['exam_slip_programme']."'");
	if($mag){
		echo '<script>
		alert("Settings Updated!")
		location.href="exam_slip.php"
		</script>';
	}else{
		echo '<div class="alert alert-danger alert-dismissable">
											<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
											<i class="zmdi zmdi-block pr-15 pull-left"></i><p class="pull-left">OPPS! Unable to complete operation, please try again later.</p>
											<div class="clearfix"></div>
										</div>';
	}
	}
}


?>


 <script src="../vendors/bower_components/jquery/dist/jquery.min.js"></script>
 
 <script>
	jQuery().ready(function(){
	$("a.see_student_course").click(function(){
			var see_student_course = $(this).attr("id");
			$.ajax({
						type: "POST",
                        url: "operation.php",
                        data: ({see_student_course:see_student_course}),
                        cache: false,
                        success: function(data){
						$("div.s_error").html(data);
						 } 
 });	
		});
		});
 </script>

