<?php

require_once("includes/initialize.php");
global $database;

// $message_output;
 $matricno=$_REQUEST['mat'];
 $mDetails = ONLINEPAY::get_name_by_mat1('transcript_tranzact',$matricno);
 $updateCert = ONLINEPAY::update_completed_certificate1('transcript_tranzact',$ptype,$matricno);

 $message_output='Your certificate is ready for collection at the Registrar'."'".'s office. While coming to collect the certificate, you will be required to come along with the following documents:
	           1.   Final Clearance (Original)
	           2.   Admission Letter
	           3.   Admission Clearance
	           4.   Certificate of Registration
	           5.   Verified O'."'".'Level Result'.'
	           6.   School ID Card
	           7.   All College official receipts (Evidence of fees paid)
	           8.   Red background passport photograph
	       
	       Best regards.';
foreach ($mDetails as $row)
{
    $matricno= $row->matricno;
    $fullname= $row->fullname;
    $dept= $row->department;
    $email= $row->email;
}


$response ="";
if(isset($_POST['submit']))
{
//    require '../includes/phpMailer/PHPMailer.php';
// 	require '../includes/phpMailer/PHPMailerAutoload.php';
    // require_once '../includes/phpMailer/SMTP.php';
    // require_once '../includes/phpMailer/Exception.php';
//   require_once '../includes/phpMailer/class.phpmailer.php';
//   require_once '../includes/phpMailer/class.smtp.php';
    $ptype = $_SESSION['ptype'];
	$name = $_POST['name'];
    $email = $_POST['email'];
    $subject = $_POST['subject'];
    $msg = $_POST['msg'];

/*	$mail = new PHPMailer;


	//SMTP Settings
    $mail->isSMTP();
// 	$mail->Host = 'mail.oscotechesaoke.edu.ng';
	$mail->Host = 'smtpout.oscotechesaoke.edu.ng';
	$mail->Port = 26 ;
	$mail->SMTPAuth= true;
	$mail->SMTPSecure='ssl';
	$mail->SMTPAutoTLS =false;
	$mail->Username = 'no.reply@oscotechesaoke.edu.ng';
// 	$mail->Password = 'academics_123';

	//Email Settings
    $mail->isHTML(true);
    $mail->setFrom('no.reply@oscotechesaoke.edu.ng', 'Osun State College of Technology, Esa Oke');
    $mail->addAddress("$email");
    $mail->Subject = $subject;
    $mail->Body = $body;
*/

	
	$to = $email;
// 	$subject="OSCOTECH Admission Registration Details!";
	$body="Dear ".$name.",";
	$body .= PHP_EOL;
	$body .= $msg;
	$body = stripslashes($body);
	$headers = "From: no.reply@oscotechesaoke.edu.ng";
	$headers .= PHP_EOL;
	$headers .= "Return-Path: no.reply@oscotechesaoke.edu.ng";
	$headers .= PHP_EOL;
	$headers .= "Reply-To: no.reply@oscotechesaoke.edu.ng";
	mail($to,$subject,$body,$headers);
	$updateCert = ONLINEPAY::update_completed_certificate($ptype,$matricno);
// 	mysql_close();
// 	header("location: type=certificate_tranzact");
// 	exit();



    if(mail)
    {
        // $status = "success";
       $response = "Email is sent!";
    }else{
        // $status = "failed";
       $response = "Something is wrong: <br>".$mail->ErrorInfo;
    }

	
}


?>

<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>Certificate Request Response</title>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css">
</head>

<!--<body class="bg-dark">-->
<body>
  <div class="container">
    <div class="row justify-content-center">
      <div class="col-md-4 mt-5 bg-light rounded">
        <h1 class="text-center font-weight-bold text-primary">OSCOTECH :: MAIL</h1>
        <hr class="bg-light">
        <h5 class="text-center text-success"><?echo $response?></h5>
        <form action="" method="post" id="form-box" class="p-2">
          <div class="form-group input-group">
            <div class="input-group-prepend">
              <span class="input-group-text"><i class="fas fa-user"></i></span>
            </div>
            <input type="text" name="name" class="form-control" value="<?php echo $fullname;?>"placeholder="Enter your name" readonly="readonly" required>
          </div>
          <div class="form-group input-group">
            <div class="input-group-prepend">
              <span class="input-group-text"><i class="fas fa-envelope"></i></span>
            </div>
            <input type="email" name="email" class="form-control" value="<?php echo $email;?>" placeholder="Enter your email" readonly="readonly" required>
          </div>
          <div class="form-group input-group">
            <div class="input-group-prepend">
              <span class="input-group-text"><i class="fas fa-at"></i></span>
            </div>
            <input type="text" name="subject" class="form-control" value="Certificate ready for collection" placeholder="Enter subject" readonly="readonly" required>
          </div>
          <div class="form-group input-group">
            <div class="input-group-prepend">
              <span class="input-group-text"><i class="fas fa-comment-alt"></i></span>
            </div>
            <textarea name="msg" id="msg" class="form-control"
            placeholder="Write your message" cols="40" rows="6" readonly="readonly" required> <? echo $message_output; ?></textarea>
          </div>
          <div class="form-group">
            <input type="submit" name="submit" id="submit" class="btn btn-primary btn-block" value="Send Message">
          </div>
          <div class="form-group">
            <a class="btn btn-primary btn-block" href="dashboard.php?type=certificate_tranzact"> Back </a>
          </div>
        </form>
        
      </div>
    </div>
  </div>
</body>

</html>