<?php
require_once($_SERVER['DOCUMENT_ROOT']."/hrm/config/config.php");
require_once($_SERVER['DOCUMENT_ROOT']."/hrm/base/recruit.php");
require_once($_SERVER['DOCUMENT_ROOT']."/hrm/config/tsms.php");
require_once($_SERVER['DOCUMENT_ROOT']."/hrm/config/mail.php");
//require_once($_SERVER['DOCUMENT_ROOT']."/coms/stat.php");
if(isset($_REQUEST['applicantID'])){
  $candidate = getCanditateById($_REQUEST['applicantID']);
  $name = $candidate['fullname'];
  $email = $candidate['email'];
  $tell = $candidate['tell'];
  $idNo = $candidate['idNo'];
  $nationality = $candidate['nationality'];
  $county = $candidate['county'];
  $disabilty = $candidate['disability'];
  $gender = $candidate['gender'];
  $dob = $candidate['dob'];
  $division = $candidate['division'];
    $location = $candidate['location'];
    $subLocation = $candidate['subLocation'];
    $village = $candidate['village'];
    $drivingLicence = $candidate['drivingLicence'];

  $application = getApplicationByUserId($_REQUEST['applicantID']);
  $application = mysqli_fetch_array($application);
  $coverLeter = $application['cletter'];
  $salary = $application['salary'];
  $availability = $application['availability'];
  $attachments = $application['attachments'];
}
if(isset($_POST['shortlist'])){
  $application = getApplicationByUserId($_REQUEST['applicantID']);
  $application = mysqli_fetch_array($application);
  // $jobID = $application['jobID'];
  $jobID = $_REQUEST['jobID'];
  shortlist($jobID, $_REQUEST['applicantID']);
  updateStatus("shortlisted",$_REQUEST['applicantID'],$jobID);
  header('location: applicants?jobID='.$jobID);
}
if(isset($_POST['rejected'])){
  $application = getApplicationByUserId($_REQUEST['applicantID']);
  $application = mysqli_fetch_array($application);
  $jobID = $_REQUEST['jobID'];
  updateStatus("rejected",$_REQUEST['applicantID'],$jobID);
  header('location: applicants?jobID='.$jobID);
}


if(isset($_REQUEST['jobID'])){
    $applicants = getApplicationByJobId($_REQUEST['jobID']);
    $job = getJobById($_REQUEST['jobID']);
}

if(isset($_POST['send'])){
  $jobID = $_REQUEST['jobID'];
  updateStatus("contacted",$_REQUEST['applicantID'],$jobID);
    if($_POST['channel']=='sms'){
      send("Dear candidate", $_POST['sms'],$tell);
    }
    if($_POST['channel']=='email'){
      @send_mail_by_PHPMailer($email, "JOB APPLICATION STATUS", $_POST['email']);
    }
}


?>
<!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, shrink-to-fit=no">
  <meta name="description" content="">
  <meta name="author" content="">
  <link href="logo.png" rel="icon">
  <title>HRM - applicants</title>
  <link href="/hrm/views/vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
  <link href="/hrm/views/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css">
  <link href="/hrm/views/css/ruang-admin.min.css" rel="stylesheet">
</head>

<body id="page-top">
  <div id="wrapper">
    <!-- Sidebar -->
    <?php
      include( $_SERVER['DOCUMENT_ROOT'].'/hrm/views/admin/sidebar.php');
    ?>
    <!-- Sidebar -->
    <div id="content-wrapper" class="d-flex flex-column">
      <div id="content">
        <!-- TopBar -->
        <?php
          include($_SERVER['DOCUMENT_ROOT'].'/hrm/views/admin/topbar.php');
        ?>
        <!-- Topbar -->

        <!-- Container Fluid-->
        <div class="container-fluid" id="container-wrapper">
          <div class="d-sm-flex align-items-center justify-content-between mb-4">
            <h4 class=" mb-0 text-primary">APPLICANTS PROFILE</h4>
            <ol class="breadcrumb">
              <li class="breadcrumb-item"><a href="./">Home</a></li>
              <li class="breadcrumb-item active" aria-current="page">Dashboard</li>
            </ol>
          </div>

          <?php
            errorsP($errors);
            success($succcess);

          ?>

          <div class="row mb-3">
            <!-- top card -->
           
          <!-- end of top card -->
          <!-- beginig of printables -->
          <div id="printable">
          <div class="card col-xl-12 col-lg-12 col-md-12 mb-4 p-3" id="bio">
        <h4>bio Infomation</h4> 
          <hr>
               <form action="" method="POST" class = "row">
                <!-- <div style="display: flex;"> -->
                    <div class="form-group col-lg-4 mb-4">
                      <label>Full Name</label>
                      <input type="text" class="form-control" id="exampleInputLastName"
                       placeholder="" name="name" value="<?php echo $name; ?>">
                    </div>
                    
                   
                    <div class="form-group col-lg-4 mb-4">
                      <label>Email</label>
                      <input type="text" class="form-control" id="exampleInputEmail" aria-describedby="emailHelp"
                        placeholder="" name = "email" value="<?php echo $email; ?>">
                    </div>

                    <div class="form-group col-lg-4 mb-4">
                      <label>Telephone</label>
                      <input type="text" class="form-control" id="exampleInputEmail" aria-describedby="emailHelp"
                        placeholder="" name = "tell" value="<?php echo $tell; ?>">
                    </div>
                    
                    <div class="form-group col-lg-4 mb-4">
                      <label>Date of bith</label>
                      <input type="date" class="form-control" id="exampleInputEmail" aria-describedby="emailHelp"
                        placeholder="" name = "dob" value="<?php echo $dob; ?>">
                    </div>

                    <div class="form-group col-lg-4 mb-4">
                      <label>Nationality</label>
                      <input type="text" class="form-control" id="su" aria-describedby="emailHelp"
                        placeholder=""  name = "nationality" value="<?php echo $nationality; ?>" required>
                    </div>

                    <div class="form-group col-lg-4 mb-4">
                      <label>County Of Origin</label>
                      <input type="text" class="form-control" id="su" aria-describedby="emailHelp"
                        placeholder=""  name = "county" value="<?php echo $county; ?>" required>
                    </div>

                    <div class="form-group col-lg-3 mb-4">
                      <label>Division</label>
                      <input type="text" class="form-control" id="su" aria-describedby="emailHelp"
                        placeholder=""  name = "division" value="<?php echo $division; ?>" required>
                    </div>

                    <div class="form-group col-lg-3 mb-4">
                      <label>Location</label>
                      <input type="text" class="form-control" id="su" aria-describedby="emailHelp"
                        placeholder=""  name = "location" value="<?php echo $location; ?>" required>
                    </div>

                    <div class="form-group col-lg-3 mb-4">
                      <label>Sublocation</label>
                      <input type="text" class="form-control" id="su" aria-describedby="emailHelp"
                        placeholder=""  name = "sublocation" value="<?php echo $subLocation; ?>" required>
                    </div>

                    <div class="form-group col-lg-3 mb-4">
                      <label>Village</label>
                      <input type="text" class="form-control" id="su" aria-describedby="emailHelp"
                        placeholder=""  name = "village" value="<?php echo $village; ?>" required>
                    </div>


                    <div class="form-group col-lg-3 mb-4">
                      <label>Gender</label>
                      <select name="gender" class="form-control" id="channel" >
                          <?php
                            if(isset($gender)){
                              echo  '<option value="'.$gender.'">'.$gender.'</option>';
                            }
                          ?>
                         <option value="male">Male</option>
                          <option value="female">Female</option>
                        </select>
                    </div>
                    <div class="form-group col-lg-3 mb-4">
                      <label>Are You Living With Disability?</label>
                      <select name="disabilty" class="form-control" id="channel" >
                      <?php
                            if(isset($disabilty)){
                              echo  '<option value="'.$disabilty.'">'.$disabilty.'</option>';
                            }
                          ?>
                        <option value="no">No</option>
                         <option value="yes">Yes</option>
                         
                        </select>
                    </div>

                    <div class="form-group col-lg-3">
                      <label>ID/Passport No.</label>
                      <input type="text" class="form-control" id="exampleInputEmail" aria-describedby="emailHelp"
                        placeholder="" name = "idNo" value="<?php echo $idNo; ?>" required>
                    </div>

                    <div class="form-group col-lg-3">
                      <label>Driving License Number</label>
                      <select name="licence" class="form-control" id="channel" >
                      <?php
                            if(isset($disabilty)){
                              echo  '<option value="'.$disabilty.'">'.$disabilty.'</option>';
                            }
                          ?>
                        <option value="no">No</option>
                         <option value="yes">Yes</option>
                         
                        </select>
                    </div>
                    <!-- </div> -->

                    
                    
                    <!-- <div class="form-group col-lg-4" >
                      <button type="submit" class="btn btn-primary btn-block" name="bio" style="margin-top: 25px">SAVE</button>
                    </div>
                     -->

                    <hr> 
                </form>
                </div>

                <!-- tab 2 -->
            <div  style="display: block;" id="accademic" class="col-lg-12">

                 <!-- Datatables -->
              <div class="col-lg-12">
              <div class="card col-xl-12 col-md-12 mb-4 p-3">
                <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
                  <h6 class="m-0 font-weight-bold text-primary">Accademic</h6>
                </div>

                <!-- inputs -->

               
                <!-- inputs -->
                <div class="table-responsive p-3">
                  <table class="table align-items-center table-flush" id="dataTable">
                    <thead class="thead-dark tfoot-dark">
                      <tr>
                        <th>#</th>
                        <th>INSTITUTION</th>
                        <th>LEVEL</th>
                        <th>PROGRAM</th>
                        <th>FROM</th>
                        <th>TO</th>
                        <th>SCORE</th>
                        
                      </tr>
                    </thead>
                    <tfoot>
                      <tr>
                      <th>#</th>
                        <th>INSTITUTION</th>
                        <th>LEVEL</th>
                        <th>PROGRAM</th>
                        <th>FROM</th>
                        <th>TO</th>
                        <th>SCORE</th>
                      </tr>
                    </tfoot>
                    <tbody>
                         <?php
                            $vacancies = getAccademicById($_REQUEST['applicantID']);
                              foreach($vacancies as $row){
                                                      
                                print " <tr> ";
                                print "<td>" . $row['id'] . "</td>";
                                print "<td>" . $row['institution']. "</td>";
                                print "<td>" . $row['level']. "</td>";
                                print "<td>" . $row['program']. "</td>";
                                print "<td>" . $row['start']. "</td>";
                                print "<td>" . $row['end']. "</td>";
                                print "<td>" . $row['score']. "</td>";
                                
                            }
                        ?>

                     
                    </tbody>
                  </table>
                </div>
              </div>
            </div>
            </div>

            <!-- experience -->

            <div  style="display: block;" id="experience" class="col-lg-12">

                    <!-- Datatables -->
                    <div class="col-lg-12">
                    <div class="card col-xl-12 col-md-12 mb-4 p-3">
                    <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
                    <h6 class="m-0 font-weight-bold text-primary">Experience</h6>
                    </div>

                    <!-- inputs -->

                   
                    <!-- inputs -->
                    <div class="table-responsive p-3">
                    <table class="table align-items-center table-flush" id="dataTable">
                    <thead class="thead-dark tfoot-dark">
                        <tr>
                        <th>#</th>
                        <th>EMPLOYER</th>
                        <th>POSITION</th>
                        <th>ROLE</th>
                        <th>FROM</th>
                        <th>TO</th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                        <th>#</th>
                        <th>EMPLOYER</th>
                        <th>POSITION</th>
                        <th>ROLE</th>
                        <th>FROM</th>
                        <th>TO</th>
                        </tr>
                    </tfoot>
                    <tbody>
                            <?php
                            $vacancies = getExpById($_REQUEST['applicantID']);
                                foreach($vacancies as $row){
                                                        
                                print " <tr> ";
                                print "<td>" . $row['id'] . "</td>";
                                print "<td>" . $row['employer']. "</td>";
                                print "<td>" . $row['position']. "</td>";
                                print "<td>" . $row['roles']. "</td>";
                                print "<td>" . $row['start']. "</td>";
                                print "<td>" . $row['end']. "</td>";
                                
                            }
                        ?>

                        
                    </tbody>
                    </table>
                    </div>
                    </div>
                    </div>
             </div>

            <!-- experience -->

            <!-- referrees -->

            <!-- referrees -->
              <div class="col-lg-12">
                    <div class="card col-xl-12 col-md-12 mb-4 p-3">
                    <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
                    <h6 class="m-0 font-weight-bold text-primary">Refferees</h6>
                    </div>
            <div class="table-responsive p-3">
                  <table class="table align-items-center table-flush" id="dataTable">
                  <thead class="thead-dark tfoot-dark">
                      <tr>
                      <th>#</th>
                      <th>FULLNAME</th>
                      <th>EMAIL</th>
                      <th>TELLEPHONE</th>
                      <th>ORGANISATION</th>
                      
                      </tr>
                  </thead>
                  <tfoot>
                      <tr>
                      <th>#</th>
                      <th>FULLNAME</th>
                      <th>EMAIL</th>
                      <th>TELLEPHONE</th>
                      <th>ORGANISATION</th>
                      </tr>
                  </tfoot>
                  <tbody>
                          <?php
                          $vacancies = getReferee($_REQUEST['applicantID']);
                              foreach($vacancies as $row){
                                                      
                              print " <tr> ";
                              print "<td>" . $row['id'] . "</td>";
                              print "<td>" . $row['fullname']. "</td>";
                              print "<td>" . $row['email']. "</td>";
                              print "<td>" . $row['tell']. "</td>";
                              print "<td>" . $row['organisation']. "</td>";
                             
                              
                          }
                      ?>

                      
                  </tbody>
                  </table>
                  </div>
                  </div>
                  </div>
            <!-- final -->

            <!-- end of printable -->
            </div>
           
             <!-- final -->
             <div  style="display: block;" id="final">

                <!-- Datatables -->
                <div class="col-lg-12">
                <div class="card col-xl-10 col-md-12 mb-4 p-3">
                

                <!-- inputs -->

                <form action="" method="POST" class = "row" enctype="multipart/form-data">
                <!-- <div style="display: flex;"> -->
                <div class="form-group col-lg-12 mb-4">
                <h6 class="m-0 font-weight-bold text-primary">COVER LETTER</h6>
                    <?php echo $coverLeter; ?>
                </div>


                <div class="form-group col-lg-4 mb-4">
                    <label>Expected Salary</label>
                    <input type="text" class="form-control" id="exampleInputLastName"
                    placeholder="" name="salary" value="<?php echo $salary; ?>">
                </div>

                <div class="form-group col-lg-4 mb-4">
                    <label>Posible Available Date</label>
                    <input type="date" class="form-control" id="exampleInputEmail" aria-describedby="emailHelp"
                    placeholder="" name = "availability" value="<?php echo $availability; ?>">
                </div>

                <div class="form-group col-lg-4 mb-4">
                    <label>Passport Photo</label>
                    <img src="<?php echo $attachments ;?>" style="width:30%; height:fit-content"/>
                </div>
                
                

                <div class="form-group col-lg-3" >
                    <button type="submit" class="btn btn-success btn-block" name="shortlist" style="margin-top: 25px">SHORTLIST</button>
                </div>

                <div class="form-group col-lg-3" >
                    <button type="submit" class="btn btn-danger btn-block" name="rejected" style="margin-top: 25px">REGRET</button>
                </div>

                <div class="form-group col-lg-3" >
                    <button type="button" class="btn btn-info btn-block" name="com" style="margin-top: 25px" onclick="coms()">COMMUNICATE</button>
                </div>

                <div class="form-group col-lg-3" >
                    <button type="submit" class="btn btn-primary btn-block" name="print" style="margin-top: 25px" onclick="printcv('printable')">PRINT</button>
                </div>


                <hr> 
                </form>
                <!-- inputs -->

                </div>
                </div>
                <!-- final -->



                           <!-- coms -->
             <div  style="display: none;" id="coms">

                <!-- Datatables -->
                <div class="col-lg-12">
                <div class="card col-xl-10 col-md-12 mb-4 p-3">


                <!-- inputs -->

                <form action="" method="POST" class = "row" enctype="multipart/form-data">
                <!-- <div style="display: flex;"> -->
                <div class="form-group col-lg-12 mb-4">
                <h6 class="m-0 font-weight-bold text-primary">SEND MASSAGE OR EMAIL</h6>
                </div>


                <div class="form-group col-lg-12 mb-4">
                    <label>CHANNEL</label>
                    <select name="channel" class="form-control" id="channel" >
                        <option value="sms">SMS</option>
                         <option value="email">EMAIL</option>
                         <option value="all">SMS/EMAIL</option>
                        </select>
                </div>

                <div class="form-group col-lg-12 mb-4">
                    <label>SMS</label>
                    <textarea type="text" class="form-control" id="exampleInputEmail" aria-describedby="emailHelp"
                    placeholder="" name="sms" value="" rows="3" autocomplete></textarea>
                </div>

                <div class="form-group col-lg-12 mb-4">
                    <label>EMAIL</label>
                    <textarea type="text" class="form-control" id="exampleInputEmail" aria-describedby="emailHelp"
                    placeholder="" name="email" value="" rows="8" autocomplete></textarea>
                </div>

                <div class="form-group col-lg-3" >
                    <button type="submit" class="btn btn-success btn-block" name="send" style="margin-top: 25px">SEND</button>
                </div>

                <hr> 
                </form>
                <!-- inputs -->

                </div>
                </div>
                <!-- coms -->



                      

              
                </div>



          <!-- <div class="row">
            <div class="col-lg-12 text-center">
              <p>Do you like this template ? you can download from <a href="https://github.com/indrijunanda/RuangAdmin"
                  class="btn btn-primary btn-sm" target="_blank"><i class="fab fa-fw fa-github"></i>&nbsp;GitHub</a></p>
            </div>
          </div> -->

          <!-- Modal Logout -->
          <div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabelLogout"
            aria-hidden="true">
            <div class="modal-dialog" role="document">
              <div class="modal-content">
                <div class="modal-header">
                  <h5 class="modal-title" id="exampleModalLabelLogout">Ohh No!</h5>
                  <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                  </button>
                </div>
                <div class="modal-body">
                  <p>Are you sure you want to logout?</p>
                </div>
                <div class="modal-footer">
                  <button type="button" class="btn btn-outline-primary" data-dismiss="modal">Cancel</button>
                  <a href="login.html" class="btn btn-primary">Logout</a>
                </div>
              </div>
            </div>
          </div>

        </div>
        <!---Container Fluid-->
      </div>
      <!-- Footer -->
      <footer class="sticky-footer bg-white">
        <div class="container my-auto">
          <div class="copyright text-center my-auto">
            <span>copyright &copy; <script> document.write(new Date().getFullYear()); </script> - developed by
              <b><a href="https://wintec.co.ke" target="_blank">wintec</a></b>
            </span>
          </div>
        </div>
      </footer>
      <!-- Footer -->
    </div>
  </div>

  <!-- Scroll to top -->
  <a class="scroll-to-top rounded" href="#page-top">
    <i class="fas fa-angle-up"></i>
  </a>

  <script src="/hrm/views/vendor/jquery/jquery.min.js"></script>
  <script src="/hrm/views/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
  <script src="/hrm/views/vendor/jquery-easing/jquery.easing.min.js"></script>
  <script src="/hrm/views/js/ruang-admin.min.js"></script>
  <script src="/hrm/views/vendor/chart.js/Chart.min.js"></script>
  <script src="/hrm/views/js/demo/chart-area-demo.js"></script>  
  <script type="text/javascript" src="/hrm/views/ckeditor/ckeditor.js"></script>

  <script>
    $(document).ready(function () {
      $('#dataTable').DataTable(); // ID From dataTable 
      $('#dataTableHover').DataTable(); // ID From dataTable with Hover
    });

    function sSustomer(){
      var target = document.getElementById('target').value;
      if( target == "specify"){
        document.getElementById("customer").style.display = "block";
        //alert("nimefikiwa");
      }else{
        document.getElementById("customer").style.display = "none";
      }
    }

    function tab(){
      document.getElementById("create").style.display = "none";
      document.getElementById("publish").style.display = "";
    }
    function coms(){
      document.getElementById("coms").style.display = "";
    }

    function tab1(){
      document.getElementById("create").style.display = "";
      document.getElementById("publish").style.display = "none";
    }

    function printcv(doc) {
            const printContents = document.getElementById(doc).innerHTML;
            const originalContents = document.body.innerHTML;
            document.body.innerHTML = printContents;
            window.print();
            document.body.innerHTML = originalContents;
        }

    CKEDITOR.replace( 'superA' );
    CKEDITOR.replace( 'superB' );
    CKEDITOR.replace( 'superC' );

    

    
  </script>
</body>

</html>