

  <?php
  session_start();
  $_SESSION['message']=""; 
  $_SESSION['message1']=""; 
  require 'PHPMailer\PHPMailerAutoload.php';
  require'database_connection.php';

if(isset($_POST['submit'])){
$username=$_POST['username'];
$phonenumber=$_POST['phonenumber'];
$business=$_POST['business'];
$comment1=$_POST['comment1'];
$comment2=$_POST['comment2'];
$comment3=$_POST['comment3'];

$mail = new PHPMailer;

//$mail->SMTPDebug = 4;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username ='rajabuhamisi30@gmail.com';                // SMTP username
$mail->Password = 'asha2003';                           // SMTP password
$mail->SMTPSecure = 'tls';    
//$mail->SMTPSecure ='PHPMailer::ENCRYPTION_STARTTLS';                         // Enable TLS encryption, `ssl` also accepted
$mail->Port = 25;                                    // TCP port to connect to

$mail->setFrom('rajabuhamisi30@gmail.com', 'baas associatives');
$mail->addAddress($_POST['mail']);     // Add a recipient
//$mail->addAddress('ellen@example.com');               // Name is optional
$mail->addReplyTo('rajabuhamisi30@gmail.com');


//$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'BAAS ASSOCIATES';
$mail->Body    = '<div><h1 align="center">welcome:'.$_POST['username'].'baas associates</h1>
<h2>For this time we test our email system to our client and we say for any incovenience causes by this</h1>
<p>welcome baas associates for better services</p></div>';
//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
   // echo 'Message could not be sent.';
  $_SESSION['message1']=' <div class="alert alert-danger alert-dismissible fade show ml-3 mr-3 mt-2 mb-2" role="alert" style="color:red;width:26rem"><strong>Please check your connection and try again!!</strong>
        <button class="close" data-dismiss="alert" arial-label="close">
          <span arial-hidden="true">&times;</span></button>
      </div>';
   // echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
  $mail=$_POST['mail'];

 $sql="insert into booking(book_id,book_username,book_phone,book_email,book_comment1,book_select,book_comment2,book_comment3)values";
 $sql.="(null,'$username','$phonenumber','$mail','$comment1','$business','$comment2','$comment3')";
 $query=mysqli_query($conn,$sql);

    
     $_SESSION['message1']=' <div class="alert alert-success alert-dismissible fade show ml-3 mr-3 mt-2 mb-2" role="alert" style="color:green;width:26rem"><strong>Thanks for book with us!please check your email!</strong>
        <button class="close" data-dismiss="alert" arial-label="close">
          <span arial-hidden="true">&times;</span></button>
      </div>';
}




}
session_destroy();
?>
<!DOCTYPE html>
<html>
<head>
  <title>Booking</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="rajabu/w3.css">
     <link rel="stylesheet" href="rajabu/book.css">
      <link rel="stylesheet" href="css/font.css">
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css" media="screen" >
    <link rel="stylesheet" href="fontawesome-free-5.8.2-web/css/all.min.css">
    <script type="text/javascript" src="js/jquery-1.11.3-jquery.min.js"></script>
    
</head>


<body>
  <div class="container-fluid mt-3">
    <form class="needs-validation" method="POST" novalidate>
  <div class="card">
    <div class="card-header text-center display-lg">BOOK AN AUDIT</div>
       <?=$_SESSION['message1']; ?>
    <div class="card-body row">
      <div class="col">
    <div class="form-group">
      <label for="username">Name</label>
      <input class="form-control" type="text" name="username" id="validationCustom01" required style="width:25rem" pattern="^[a-z A-z]{2,}$">
        <div class="invalid-feedback">please add your name</div>
       
      </div>
    </div>
    <div class="col">
      <div class="form-group">
      <label for="phonenumber">phonenumber</label>
    <input type="tel" class="form-control" name="phonenumber" id="validationCustom02" style="width:25rem" placeholder='+255677177075' required pattern='^[+255]{4}[?=6-7]{1}[0-9]{8}$'>
    <div class="invalid-feedback">add your phonenumber</div>
  </div>
</div>
</div>
<div class="row card-body">
<div class="col">
      <div class="form-group">
      <label for="email">Email</label>
    <input type="email" class="form-control" name="mail" id="validationCustom03" style="width:25rem" placeholder='ashura@gmail.com' required pattern="^[A-Za-z0-9._]{3,}@[a-z]{3,}[.]{1}[a-z.]{2,6}$">
    <div class="invalid-feedback">add valid email</div>
  </div>
</div>
<div class="col">
 <div class="form-group">
 <p><label>How long have you been in business?</label></p>
  <textarea rows="4" cols="50" class="form-control" placeholder="comment is optional" name="comment1" style="width:25rem"></textarea>
   
</div>

  </div>
</div>
<div class="row card-body">
<div class="col">
  <div class="form-group">
<label for="select">What firm of business are you?</label>
    <select class='form-control' name="business" id="validationCustom04" style="width:25rem" required>
    <option value="partner" disabled selected>Are you ?</option>
    <option value="Proprietor">Proprietor</option>
    <option value="partnership">partnership</option>
    <option value="company">company</option>
    </select>
 <div class="invalid-feedback">Choose your firm</div>
  </div>
</div>
<div class="col">
  <div class="form-group">
  <label>How did you find out about us?</label>
  <textarea rows="5" cols="40" class="form-control" placeholder="comment is optional" name="comment2" style="width:25rem"></textarea>
   </div>  
</div>

  </div>
  <div class="row card-body">
   <div class="col">
    <div class="form-group">
  <label for="comment">How did you find out about us?</label>
  <textarea rows="5" cols="40" class="form-control" placeholder="comment is optional" name="comment2" style="width:25rem"></textarea>
   </div>  
   </div>
   <div class="col">
    <div class="form-group">
   <label for="comment">At what time do you need the audit report?</label>
  <textarea rows="5" cols="40" class="form-control" placeholder="comment is optional" name="comment3" style="width:25rem"></textarea>
</div>

    
   </div>

  </div>
  <div class="row">
    <div class="col">
  <button type="submit" class="btn btn-danger ml-3 mb-3" name="submit">save book info</button>
</div>
</div>
  
   
    <div class="card-footer text-center">Bass associates</div>
</div>

</form>
  </div>

    <script src="bootstrap/js/jquery-3.5.1.min.js"></script>
    <script src="bootstrap/js/bootstrap.bundle.js"></script>
    <script src="bootstrap/js/bootstrap.bundle.min.js"></script>

</body>
</html>






  <script type="text/javascript">
    (function() {
  'use strict';
  window.addEventListener('load', function() {
    // Fetch all the forms we want to apply custom Bootstrap validation styles to
    var forms = document.getElementsByClassName('needs-validation');
    // Loop over them and prevent submission
    var validation = Array.prototype.filter.call(forms, function(form) {
      form.addEventListener('submit', function(event) {
        if (form.checkValidity() === false) {
          event.preventDefault();
          event.stopPropagation();
        }
        form.classList.add('was-validated');
      }, false);
    });
  }, false);







})();
  </script>
<!--<script type="text/javascript">
  /***collect data from the form****/
 var username=document.forms['book']['username'];
 var phonenumber=document.forms['book']['phonenumber'];
 var mail=document.forms['book']['mail'];
 var business=document.forms['book']['business'];

 /****add error message*****/
 var username_error=document.getElementById("username_error");
  var phonenumber_error=document.getElementById("phonenumber_error");
   var mail_error=document.getElementById("mail_error");
    var business_error=document.getElementById("business_error");

 /**add event listener*******/
 username.addEventListener("blur",verifyuserName,true);
 phonenumber.addEventListener("blur",verifyphoneNumber,true);
 mail.addEventListener("blur",verifyMail,true);
 business.addEventListener("blur",verifyBusiness,true);
/**mail validation*********/
 var pattern =/^[A-Za-z0-9._]{3,}@[a-z]{3,}[.]{1}[a-z.]{2,6}$/;
var pattern1=/^[+255]{4}[?=6-7]{1}[0-9]{8}$/;

 function validate()
 {
 if(username.value == ""){
  username_error.textContent="please add username";
  username_error.style.color="red";
  return false;
 }
 if(phonenumber.value == ""){
  phonenumber_error.textContent="please add phonenumber";
  phonenumber_error.style.color="red";
  return false;
 }
  if(!phonenumber.value.match(pattern1)){
  phonenumber_error.textContent="please add valid phonenumber";
  phonenumber_error.style.color="red";
  return false;
 }
if(mail.value == ""){
  mail_error.textContent="please add valid email";
  mail_error.style.color="red";
  return false;
}
if(!mail.value.match(pattern)){
  mail_error.textContent="please correct your email";
  mail_error.style.color="red";
  return false;
}

if(business.value == "partner"){
  business_error.textContent="please choose your firm";
  business_error.style.color="red";
  return false;
}
}
function verifyuserName(){
  if(username.value != ""){
    username_error.innerHTML="";
    return true;
  }
}
function verifyphoneNumber(){
  if(phonenumber.value != ""){
    phonenumber_error.innerHTML="";
    return true;
  }
}
function verifyMail(){
  if(mail.value != ""){
    mail_error.innerHTML="";
    return true;
  }
}
function verifyBusiness(){
  if(business.value != ""){
    business_error.innerHTML="";
    return true;
  }
}


</script>-->

