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

$msg='';
if(isset($_REQUEST['submit_head'])){
	$emp=explode("***",$_POST['hod_department']);
	$far=mysqli_query($con,"select * from head where email='".trim($_POST['hod_email'])."' OR pfn='".trim($_POST['hod_pfn'])."' OR dep_id='".$emp[0]."'");
	if(mysqli_num_rows($far)==0){
	
	$qry=mysqli_query($con,"insert into head(dep_id,lastname,othernames,email,pfn,password) values('".$emp[0]."', '".trim($_POST['hod_lastname'])."', '".trim($_POST['hod_othernames'])."', '".trim($_POST['hod_email'])."', '".trim($_POST['hod_pfn'])."', '".sha1('lasuweb22')."')");
	
	$fr=mysqli_query($con,"select id,email,pfn,dep_id from head where email='".trim($_POST['hod_email'])."' AND pfn='".trim($_POST['hod_pfn'])."' AND dep_id='".$emp[0]."'");
	$me=mysqli_fetch_assoc($fr);
	
	mysqli_query($con,"insert into head_access(head_id,course_upload,login_access) values('".$me['id']."', 1, 1)");
	
	//$qry=mysqli_query($con,"insert into head_enrol(pfn,lastname,othernames,email,dep_id,department,sent_email) values('".trim($_POST['hod_pfn'])."', '".trim($_POST['hod_lastname'])."', '".trim($_POST['hod_othernames'])."', '".trim($_POST['hod_email'])."', '".$emp[0]."', '".$emp[1]."','no')");
	
	
$mailto=trim($_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="font-size:18px; color:#0040ff;">Dear '.$_POST['hod_lastname'].',</h1>';
$message .= '<p style="font-size:17px; color:black;">Your Course Registration Account has been created successfully. You have been enrolled as the Head/Coordinator, Department of '.$emp[1].'. 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:17px;"><b>Email : </b>'.trim($_POST['hod_email']).'</p>';
$message .= '<p style="color:black; font-size:17px;"><b>Default Password : </b>inspireweb-00</p>';
$message .= '<p style="color:black; font-size:17px;"><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;                      //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($mailto, '');     //Add a recipient
            //Content
            $mail->isHTML(true);                                  //Set email format to HTML
            $mail->Subject = 'Course Reg. Account';
            $mail->Body    = $message;
            //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
			$mail->send(); // to send the composed mail 
	
	$msg= '<div class="alert alert-dismissible alert-success">
				<strong>SUCCESS: </strong> Enrollment Successful. Kindly Check mail for your login details
              </div>';
	
	}else{
		$msg= '<div class="alert alert-dismissible alert-danger">
				<strong>SORRY: </strong> Head with the Supplied Details Already Enrolled
              </div>';
	}
	
	
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Course Reg - Heads Enrollment  :: Inspire Polytechnic</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="assets/css/themify-icons.css" rel="stylesheet">
    <link href="assets/css/flaticon.css" rel="stylesheet">
    <link href="assets/css/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/animate.css" rel="stylesheet">
    <link href="assets/css/owl.carousel.css" rel="stylesheet">
    <link href="assets/css/owl.theme.css" rel="stylesheet">
    <link href="assets/css/slick.css" rel="stylesheet">
    <link href="assets/css/slick-theme.css" rel="stylesheet">
    <link href="assets/css/swiper.min.css" rel="stylesheet">
    <link href="assets/css/owl.transitions.css" rel="stylesheet">
    <link href="assets/css/jquery.fancybox.css" rel="stylesheet">
    <link href="assets/css/odometer-theme-default.css" rel="stylesheet">
    <link href="assets/css/style.css" rel="stylesheet">

<style>
div#programme_box{
	-webkit-transition: width 2s, height 2s, -webkit-transform 2s; /* Safari */
    transition: width 2s, height 2s, transform 2s;
}
div#programme_box:hover{
    -webkit-transform: rotate(20deg); /* Safari */
    transform: rotate(20deg);
}
</style>

</head>

<body>

    <!-- start page-wrapper -->
    <div class="page-wrapper">

        <!-- start preloader -->
        <div class="preloader">
            <div class="angular-shape">
                <div></div>
                <div></div>
                <div></div>
            </div>
            <div class="spinner">
              <div class="double-bounce1"></div>
              <div class="double-bounce2"></div>
            </div>
        </div>
        <!-- end preloader -->


<section class="page-title">
            <div class="angular-shape">
                <div></div>
                <div></div>
                <div></div>
            </div>            
            <div class="container">
                <div class="row">
                    <div class="col col-xs-12">
					<div align="center"><img src="img/logo_white.png" style="width:;" class="img-responsive"></div>
                        <h2>Heads Enrollment</h2>
                    </div>
                </div> <!-- end row -->
            </div> <!-- end container -->
        </section> 

        <!-- start features-section -->
		
        <section class="features-section" id="login" style="margin-top:;">
            <div class="container">
                <!--<div class="row">
                    <div class="col col-lg-6 col-lg-offset-3">
                        <div class="section-title-s3">
                            <span>Account Registration Portal</span>
                            <h2>Sign Up</h2>
                        </div>
                    </div>
                </div>-->
				
                <div class="row">
				
                    <div class="col col-md-3"></div>
                    <div class="col col-md-6">		
					
						<div class="error"><?php echo $msg;?></div>
						<div class="login_container" style="padding:30px; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);">
						<form method="post" id="form_submi">
							<p style="margin-bottom:7px;">Complete the form below </p><hr>
						<input type="hidden" name="enrol_head" value="true">
						
									
									<div class="row">
									<div class="col-md-12 form-group">
									<label class="control-label mb-5" for="email_de">Department</label>
						<select class="form-control" name="hod_department" style="height:46px; border-radius:0;" required >
						<option value="">Select</option>
						<?php
						$dar=mysqli_query($con,"select * from department order by department asc");
						while($row=mysqli_fetch_assoc($dar)){
							echo '<option value="'.$row['id'].'***'.$row['department'].'">'.$row['department'].'</option>';
						}
						?>
						</select>
									</div>
									</div>
									
									<div class="row">
									<div class="col-md-6 form-group">
									<label class="control-label mb-5" for="email_de">PF No.</label>
						<input class="form-control" style="height:46px; border-radius:0;" name="hod_pfn" type="text" required >
									</div>
									<div class="col-md-6 form-group">
									<label class="control-label mb-5" for="email_de">Lastname</label>
						<input class="form-control" style="height:46px; border-radius:0;" name="hod_lastname" type="text" required >
									</div>
									</div>
									
									<div class="row">
									<div class="col-md-6 form-group">
									<label class="control-label mb-5" for="email_de">Othernames</label>
						<input class="form-control" style="height:46px; border-radius:0;" name="hod_othernames" type="text" required >
									</div>
									<div class="col-md-6 form-group">
									<label class="control-label mb-5" for="email_de">Email</label>
									<input class="form-control" style="height:46px; border-radius:0;" name="hod_email" type="email" required >
									</div> 
									</div>
												
												<div class="error3"></div>
													<div class="form-group">
													<button style="border-radius:0;" class="btn btn-primary btn-lg mb-5 pull-right" name="submit_head" value="true" type="submit">Submit</button>
													<div class="clearfix"></div>
												</div>
									</form>
						
                        </div>
						
						
                    </div>
					
					<div class="col col-md-3"></div>
					
                </div>
            </div> <!-- end container -->
        </section>
        <!-- end features-section -->
		


       <p style="font-size:12px;text-align:center;" class="copyright">Copyright &copy; <?php echo date("Y");?> Inspire Polytechnic. All rights reserved.</p>




    </div>
    <!-- end of page-wrapper -->



    <!-- All JavaScript files
    ================================================== -->
    <script src="assets/js/jquery.min.js"></script>
	<script>
	jQuery().ready(function(){
		
		$("input.see_matric_no").bind('copy paste cut', function(e){
				e.preventDefault(); 
				return false;
		});
		
		$("input.see_matric_no").keyup(function(){
			var see_matric_no = $(this).val();
			if(see_matric_no.length>9){
		$("div.msg").html("");
		$("div.result").html('<br><div align="center"><img src="img/loader-fotd.gif" class="img-responsive" style="width:50px;"></div>');		
				$.ajax({
						type: "POST",
                        url: "operation_check.php",
                        data: ({see_matric_no:see_matric_no}),
                        cache: false,
                        success: function(data){ 
							$("div.result").html(data);
						 } 
 });
				
			}else{
				$("div.result").html("");
			}
		});
		
				$("form#form_submit").on('submit',(function(e){
					e.preventDefault();
			$("div.msg").html("<div align='center' style='color:#202060; font-weight:600; padding:5px;'><img src='img/loader-fotd.gif' class='img-responsive' style='width:30px;'> Authenticating Student Data ...</div>");
	
				$.ajax({
						type: "POST",
                        url: "operation.php",
                        data: new FormData(this),
						contentType:false,
						processData:false,
                        cache: false,
                        success: function(data){ 
						$("div.msg").html(data);
						}
    });			
	
	
		}));
		
		
	});
	</script>
	
    <script src="assets/js/bootstrap.min.js"></script>

    <!-- Plugins for this template -->
    <script src="assets/js/jquery-plugin-collection.js"></script>

    <!-- Custom script for this template -->
    <script src="assets/js/script.js"></script>
</body>
</html>
