<?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 DISTINCT semester_num, session 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 !='' order by session desc, semester_num desc");
	
	echo '<div class="row"> <div class="s_error"></div>';
	if(mysqli_num_rows($mc)>0){
	while($al=mysqli_fetch_assoc($mc)){

		$fae=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 !='' AND semester_num='".$al['semester_num']."' AND session='".$al['session']."' order by session desc, semester_num desc");
		$ala=mysqli_fetch_assoc($fae);

	$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';
						}
			
			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>';

	}

	}

}



if(isset($_POST['update_hod'])){
	
	$biv=mysqli_query($con,"select * from head where dep_id ='".$_POST['update_hod']."' AND (email='".$_POST['hod_email']."' OR pfn='".$_POST['hod_pfn']."')");
	$ccc=mysqli_fetch_assoc($biv);
	
	$ser=mysqli_query($con,"update head set lastname='".$_POST['hod_lastname']."', othernames='".$_POST['hod_othernames']."', email='".$_POST['hod_email']."', pfn='".$_POST['hod_pfn']."', password='".sha1('inspireweb-00')."' where id='".$ccc['id']."' ");
	
if($ser && mysqli_num_rows($biv)>0){
		
$mailto=$_POST['hod_email'];
$message = '<html><body>';
$message .= '<div align="center" style="padding:10px;">
<img src="https://'.$lasu_link.'img/logo.png" style="width:230px;" alt=""></div>';
$message .= '<div style="border:1px solid #0033cc; padding:15px;"><h1 style="color:#0040ff; text-align:center;">Dear Sir/Ma,</h1>';
$message .= '<p style="font-size:17px; color:black;">Your Course Registration Account has been created successfully. Your login details are stated below.</p>';

$message .= '<p style="color:black; font-size:17px; font-weight:600;text-decoration:underline;">Login Details</p>';

$message .= '<p style="color:black; font-size:19px;"><b>Email : </b>'.ucwords($_POST['hod_email']).'</p>';
$message .= '<p style="color:black; font-size:19px;"><b>Default Password : </b>inspireweb-00</p>';
$message .= '<p style="color:black; font-size:19px;"><b>URL : </b><a style="padding:7px 10px; color:#fff;background-color:#337ab7;border-color:#2e6da4; text-decoration:none;" href="https://'.$lasu_link.'head">Login Page</a></p>';
$message .= '<br><small style="color:#4d4d4d;float:right;"> Inspire Polytechnic</small><div style="clear:both;"></div>';
$message .= '</div></body></html>';

require "../PHPMailer/PHPMailerAutoload.php";
		 $mail = new PHPMailer(true);
            $mail->SMTPDebug = 0;                      
            $mail->isSMTP();                                            
            $mail->Host       = $site_host;                     
            $mail->SMTPAuth   = true;                                   
            $mail->Username   = $site_username;                     
            $mail->Password   = $site_password;                               
            
            $mail->Port = 587;                                    
            
            $mail->setFrom($site_email, 'Inspire Polytechnic Course Reg. Portal');
            $mail->addAddress($mailto, '');     
            
            $mail->isHTML(true);                                  
            $mail->Subject = 'Inspire Polytechnic Course Reg. Account';
            $mail->Body    = $message;
            
			$mail->send();
			
	
	echo '<script>
	alert("HOD Details Updated!")
	location.href="department.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 check request and try again.</p>
											<div class="clearfix"></div>
										</div>';
	}
	
	
}


if(isset($_POST['add_hod'])){
	
	$biv=mysqli_query($con,"select * from head where dep_id ='".$_POST['a_depid']."' AND (email='".$_POST['a_email']."' OR pfn='".$_POST['a_pfn']."')");
	if(mysqli_num_rows($biv)==0){

		$ser=mysqli_query($con,"insert into head(dep_id,lastname,othernames,email,pfn,password) values('".$_POST['a_depid']."','".$_POST['a_lastname']."','".$_POST['a_othernames']."','".$_POST['a_email']."','".$_POST['a_pfn']."','".sha1('inspireweb-00')."')");
		
	if($ser){
		
$mailto=$_POST['a_email'];
$message = '<html><body>';
$message .= '<div align="center" style="padding:10px;">
<img src="https://'.$lasu_link.'img/logo.png" style="width:230px;" alt=""></div>';
$message .= '<div style="border:1px solid #0033cc; padding:15px;"><h1 style="color:#0040ff; text-align:center;">Dear Sir/Ma,</h1>';
$message .= '<p style="font-size:17px; color:black;">Your Course Registration Account has been created successfully. Your login details are stated below.</p>';

$message .= '<p style="color:black; font-size:17px; font-weight:600;text-decoration:underline;">Login Details</p>';

$message .= '<p style="color:black; font-size:19px;"><b>Email : </b>'.ucwords($_POST['a_email']).'</p>';
$message .= '<p style="color:black; font-size:19px;"><b>Default Password : </b>inspireweb-00</p>';
$message .= '<p style="color:black; font-size:19px;"><b>URL : </b><a style="padding:7px 10px; color:#fff;background-color:#337ab7;border-color:#2e6da4; text-decoration:none;" href="https://'.$lasu_link.'head">Login Page</a></p>';
$message .= '<br><small style="color:#4d4d4d;float:right;"> Inspire Polytechnic</small><div style="clear:both;"></div>';
$message .= '</div></body></html>';

require "../PHPMailer/PHPMailerAutoload.php";
		 $mail = new PHPMailer(true);
            $mail->SMTPDebug = 0;                      
            $mail->isSMTP();                                            
$mail->Host       = $site_host;                     
            $mail->SMTPAuth   = true;                                   
            $mail->Username   = $site_username;                     
            $mail->Password   = $site_password;                               
            
            $mail->Port = 587;                                    
            
            $mail->setFrom($site_email, 'Inspire Polytechnic Course Reg. Portal');
            $mail->addAddress($mailto, '');     
            
            $mail->isHTML(true);                                  
            $mail->Subject = 'Course Reg. Account';
            $mail->Body    = $message;
            
			$mail->send(); 
			
	echo '<script>
	alert("HOD Added!")
	location.href="department.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>';
	}
	
}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! User is already the head/coordinator of this department</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>



