<?php 
session_start();
include_once 'config.php';
include_once 'auth.php';
$user_id = $_SESSION['Admin']['id'];
$MainPage="Job-Post";
$Page = "Post-Job";

?>
<!DOCTYPE html>
<html lang="en" class="default-style layout-fixed layout-navbar-fixed">
<head>
<title><?php echo $Proj_Title; ?> - Post Job</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
<meta name="description" content="">
<meta name="author" content="" />

<?php include_once 'header_script.php'; ?>
<script src="../ckeditor/ckeditor.js"></script>
</head>
<body>
<style type="text/css">
  .password-tog-info {
  display: inline-block;
cursor: pointer;
font-size: 12px;
font-weight: 600;
position: absolute;
right: 50px;
top: 30px;
text-transform: uppercase;
z-index: 2;
}


</style>
<div class="layout-wrapper layout-2">
<div class="layout-inner">

<?php include_once 'sidebar.php'; ?>


<div class="layout-container">

<?php include_once 'top_header.php'; ?>
<?php 
$id = $_GET['id'];
$sql7 = "SELECT * FROM tbl_post_jobs WHERE id='$id'";
$res7 = $conn->query($sql7);
$row7 = $res7->fetch_assoc();
$row7['SkillId'] = explode(",",$row7['SkillId']);
//$row7['JobType'] = explode(",",$row7['JobType']);
?>

<?php 
  if(isset($_POST['submit'])){
$CompId = $_POST['CompId'];
$CatId = $_POST['CatId'];
$SkillId = implode(",",$_POST['SkillId']);
//$JobType = implode(",",$_POST['JobType']);
$MinSalary = $_POST['MinSalary'];
$MaxSalary = $_POST['MaxSalary'];
$JobType = addslashes(trim($_POST['JobType']));
$Title = addslashes(trim($_POST['Title']));
$Details = addslashes(trim($_POST['Details']));
$FreshExp = addslashes(trim($_POST['FreshExp']));
$JobLocation = addslashes(trim($_POST['JobLocation'])); 
$Skills = addslashes(trim($_POST['Skills']));
$JobMap = addslashes(trim($_POST['JobMap']));
$Experience = addslashes(trim($_POST['Experience'])); 
$Vaccancy = addslashes(trim($_POST['Vaccancy']));
$Education = addslashes(trim($_POST['Education']));
$StateId = addslashes($_POST['StateId']);
$CityId = addslashes($_POST['CityId']);
$Status = $_POST['Status'];
$CreatedDate = date('Y-m-d');


if($_GET['id']==''){
    $qx = "INSERT INTO tbl_post_jobs SET CompId='$CompId',Title='$Title',CatId='$CatId',SkillId='$SkillId',FreshExp='$FreshExp',JobMap='$JobMap',MinSalary='$MinSalary',MaxSalary='$MaxSalary',Experience='$Experience',Vaccancy='$Vaccancy',Details='$Details',JobType='$JobType',JobLocation='$JobLocation',StateId='$StateId',CityId='$CityId',Status='$Status',Education='$Education',CreatedBy='$user_id',CreatedDate='$CreatedDate'";
  $conn->query($qx);
  echo "<script>alert('Post Job Added Successfully!');window.location.href='view-job-posts.php';</script>";
}
else{
     $query2 = "UPDATE tbl_post_jobs SET CompId='$CompId',Title='$Title',CatId='$CatId',SkillId='$SkillId',FreshExp='$FreshExp',JobMap='$JobMap',MinSalary='$MinSalary',MaxSalary='$MaxSalary',Experience='$Experience',Vaccancy='$Vaccancy',Details='$Details',JobType='$JobType',JobLocation='$JobLocation',StateId='$StateId',CityId='$CityId',Education='$Education',Status='$Status',ModifiedBy='$user_id',ModifiedDate='$ModifiedDate' WHERE id = '$id'";
  $conn->query($query2);
  echo "<script>alert('Post Job Updated Successfully!');window.location.href='view-job-posts.php';</script>";
}
    //header('Location:courses.php'); 

  }
 ?>

<div class="layout-content">

<div class="container-fluid flex-grow-1 container-p-y">
<h4 class="font-weight-bold py-3 mb-0">Post Job</h4>


<div class="card mb-4">
<div class="card-body">
<div id="alert_message"></div>
<form id="validation-form" method="post" enctype="multipart/form-data">
<div class="form-row">

<div class="form-group col-lg-12">
    <label class="form-label">Company Name <span class="text-danger">*</span></label>
    <select class="select2-demo form-control" name="CompId" id="CompId" required="">

 <?php 
      $q = "select id,CompName from tbl_users WHERE Status=1 AND Roll='3'";
      $r = getList($q);
      foreach($r as $rw)
      {
    ?>
      <option <?php if($row7['CompId']==$rw['id']) { ?> selected <?php } ?> value="<?php echo $rw['id']; ?>"><?php echo $rw['CompName']; ?></option>
    <?php } ?>
</select>
</div>

 <div class="form-group col-lg-12">
  <label for="example-value">Job Title <span class="text-danger">*</span></label>
  <input type="text" name="Title" class="form-control" value="<?php echo $row7['Title']; ?>" placeholder="Job Title" required="">
</div>

<div class="form-group col-lg-12">
<label class="form-label">Category <span class="text-danger">*</span></label>
    <select class="select2-demo form-control" name="CatId" id="CatId" required="">
    <option selected="" disabled="">Select Category</option>
    <?php 
      $q = "select * from tbl_category WHERE Status=1";
      $r = getList($q);
      foreach($r as $rw)
      {
    ?>
      <option <?php if($row7['CatId']==$rw['id']){ ?> selected <?php } ?> value="<?php echo $rw['id']; ?>"><?php echo $rw['Name']; ?></option>
    <?php } ?>
</select>
</div>

<div class="form-group col-lg-12">
    <label class="form-label">Skill Name <span class="text-danger">*</span></label>
    <select class="select2-demo form-control" name="SkillId[]" id="SkillId" multiple required="">

 <?php 
      $q = "select * from tbl_skills WHERE Status=1 AND CatId='".$row7['CatId']."'";
      $r = getList($q);
      foreach($r as $rw)
      {
    ?>
      <option <?php if(in_array($rw["id"],$row7['SkillId'])) { ?> selected <?php } ?> value="<?php echo $rw['id']; ?>"><?php echo $rw['Name']; ?></option>
    <?php } ?>
</select>
</div>

<div class="form-group col-md-6">
<label class="form-label">Fresher/Experience <span class="text-danger">*</span></label>
  <select class="form-control" id="FreshExp" name="FreshExp" required="">
<option selected="" disabled="" value="">Select </option>
<option value="1" <?php if($row7["FreshExp"]=='1') {?> selected <?php } ?>>Fresher</option>
<option value="2" <?php if($row7["FreshExp"]=='2') {?> selected <?php } ?>>Experience</option>
</select>
<div class="clearfix"></div>
</div>

<div class="form-group col-md-6">
<label class="form-label">Experience <span class="text-danger">*</span></label>
  <input type="text" name="Experience" class="form-control" value="<?php echo $row7['Experience']; ?>" placeholder="Job Experience" required="">
<div class="clearfix"></div>
</div>

<div class="form-group col-md-12">
<label class="form-label">Education <span class="text-danger">*</span></label>
  <input type="text" name="Education" class="form-control" value="<?php echo $row7['Education']; ?>" placeholder="e.g., B.E." required="">
<div class="clearfix"></div>
</div>



 <div class="form-group col-lg-12">
<label for="form-label">Job Type</label>
<select class="form-control" id="exampleFormControlSelect1" name="JobType">
<?php 
      $q = "select * from tbl_job_types WHERE Status=1";
      $r = getList($q);
      foreach($r as $rw)
      {
    ?>
      <option <?php if($row7['JobType']==$rw['id']){ ?> selected <?php } ?> value="<?php echo $rw['id']; ?>"><?php echo $rw['Name']; ?></option>
    <?php } ?>  

</select>
</div>    

<div class="form-group col-md-6">
    <label class="form-label">State <span class="text-danger">*</span></label>
<select class="form-control" id="StateId" name="StateId" required="">
<option selected="" disabled="">Select State</option>
 <?php 
        $CountryId = $row7['CountryId'];
        $q = "select * from tbl_state WHERE CountryId='1' ORDER BY Name ASC";
        $r = $conn->query($q);
        while($rw = $r->fetch_assoc())
    {
?>
                <option <?php if($row7['StateId']==$rw['id']){ ?> selected <?php } ?> value="<?php echo $rw['id']; ?>"><?php echo $rw['Name']; ?></option>
              <?php } ?>
</select>
  </div>
  <div class="form-group col-md-6">
      <label class="form-label">City/District </label>
<select class="form-control" id="CityId" name="CityId">
<option selected="" disabled="">Select City/District</option>
  <?php 
 $StateId = $row7['StateId'];
        $q = "select * from tbl_city WHERE StateId='$StateId' ORDER BY Name ASC";
        $r = $conn->query($q);
        while($rw = $r->fetch_assoc())
    {
?>
                <option <?php if($row7['CityId']==$rw['id']){ ?> selected <?php } ?> value="<?php echo $rw['id']; ?>"><?php echo $rw['Name']; ?></option>
              <?php } ?>
</select>
  </div>

 <div class="form-group col-lg-6">
                                <label for="form-label">Job Location <span class="text-danger">*</span></label>
                                <input type="text" name="JobLocation" class="form-control" value="<?php echo $row7['JobLocation']; ?>" placeholder="Job Location" required="">
                            </div>
                            <div class="form-group col-lg-6">
                                <label for="form-label">Job Vacancy <span class="text-danger">*</span></label>
                                <input type="text" name="Vaccancy" value="<?php echo $row7['Vaccancy']; ?>" class="form-control" value="" placeholder="Job Vacancy" required="">
                            </div>
                             <div class="form-group col-lg-6">
                                <label for="form-label">Min Salary<span class="text-danger">*</span></label>
                                <input type="text" placeholder="e.g. 10000" name="MinSalary" value="<?php echo $row7["MinSalary"]; ?>" required="" class="form-control" >
                            </div>
                             <div class="form-group col-lg-6">
                                <label for="form-label">Max Salary</label>
                                <input type="text" type="text" placeholder="e.g. 20000" name="MaxSalary" value="<?php echo $row7["MaxSalary"]; ?>" required="" class="form-control" >
                            </div>
                             <div class="form-group col-lg-12">
                                <label for="form-label">Job Description <span class="text-danger">*</span></label>
                                <textarea id="editor1" name="Details" class="form-control"><?php echo $row7['Details']; ?></textarea>
                            </div>

                            <!--   <div class="form-group col-lg-12">
                                <label for="example-value">Required Skills and Abilities </label>
                                <textarea id="editor2" name="Skills" class="form-control"><?php echo $row7["Skills"]; ?></textarea>
                            </div>
 -->
                                <div class="form-group col-lg-12">
                            <label for="form-label">Jobs Location Embedded Map Code </label>
                            <textarea class="form-control" name="JobMap"><?php echo $row7['JobMap']; ?></textarea>
                        </div>




<div class="form-group col-md-12">
<label class="form-label">Status <span class="text-danger">*</span></label>
  <select class="form-control" id="Status" name="Status" required="">
<option selected="" disabled="" value="">Select Status</option>
<option value="1" <?php if($row7["Status"]=='1') {?> selected <?php } ?>>Active</option>
<option value="0" <?php if($row7["Status"]=='0') {?> selected <?php } ?>>Inctive</option>
</select>
<div class="clearfix"></div>
</div>
</div>
<button type="submit" name="submit" class="btn btn-primary btn-finish">Submit</button>
</form>
</div>
</div>
</div>

<?php include_once 'footer.php'; ?>
</div>
</div>
</div>
<div class="layout-overlay layout-sidenav-toggle"></div>
</div>


<?php include_once 'footer_script.php'; ?>
 <script>
        CKEDITOR.replace( 'editor1');

$(document).ready(function(){
         $(document).on("change", "#CatId", function(event){
  var val = this.value;
   var action = "getSkills";
    $.ajax({
    url:"ajax_files/ajax_dropdown.php",
    method:"POST",
    data : {action:action,id:val}, 
    success:function(data)
    {
      $('#SkillId').html(data);
    }
    });

 });

          $(document).on("change", "#StateId", function(event){
  var val = this.value;
   var action = "getCity";
    $.ajax({
    url:"ajax_files/ajax_dropdown.php",
    method:"POST",
    data : {action:action,id:val},
    success:function(data)
    {
      $('#CityId').html(data);
    }
    });
 });
          });
</script>
</body>
</html>