<?php $this->load->view('admin/common/header'); ?>

<div class="dashborder-content">

<div class="container-fluid">
<div class="row">
<?php $this->load->view('admin/common/sidebar'); ?>

  <div class="col-md-10">


<div class="row">

<div class="col-md-12">
<div class="panel panel-bd lobidrag lobipanel lobipanel-sortable" data-inner-id="6lbDiPQUBj" data-index="0">
<div class="panel-heading ui-sortable-handle">
<div class="panel-title" style="max-width: calc(100% - 180px);">


<div class="row">

<div class="col-md-6" style="padding-top: 4px;"><h4>  My Positions
</h4></div>
<div class="col-md-6" style="text-align:right;">
<form class="form-inline" action="<?= base_url('admin/position')?>">


<div class="input-group" style="width:100% !important;">

<input type="text" class="form-control" placeholder="Search Here" name="search" style="font-size:12px;">
<div class="input-group-addon btn"><i class="fa fa-search"></i>
</div>
</div>


</form>

</div>

</div>
</div>
</div>
<div class="panel-body">

<div class="table-responsive">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>S.no.</th>
<th>Job. Id</th>
<th>Position</th>
<th>No. of positions</th>
<th>Location</th>
<th>Exp.</th>
<th>CTC</th>
<th>TAT</th>
<th>JD</th><th>Admin Status</th>
<th>Status</th>
<th></th>
</tr>
</thead>
<tbody>
  <?php $i=1; foreach($position as $p){?>
<tr>
<td><?= $i; ?></td>
<td><?= $p['job_id']?></td>
<td ondblclick="editfield(this,'position',<?= $p['id']?>)"><?= $p['position']?></td>
<td ondblclick="editfield(this,'position_no',<?= $p['id']?>)"><?= $p['position_no']?></td>
<td ondblclick="editfield(this,'location',<?= $p['id']?>)"><?= $p['location']?></td>
<td ondblclick="editfield(this,'exp',<?= $p['id']?>)"><?= $p['exp']?></td>
<td ondblclick="editfield(this,'ctc',<?= $p['id']?>)"><?= $p['ctc']?></td>
<td ondblclick="editfield(this,'tat',<?= $p['id']?>)"><?= $p['tat']?></td>
<td><a target="_blank" href="<?= base_url('uploads/position/'.$p['jd'])?>">View JD</a></td><td><form action="<?= base_url('Admin/admin_status_position')?>" method="post"><input type="hidden" name="id" value="<?=$p['id']?>"><select name="admin_status" class="form-control" onchange="this.form.submit()"><option value="Active" <?php if($p['admin_status']=='Active'){ echo 'selected';}?>>Active</option><option value="Inactive" <?php if($p['admin_status']=='Inactive'){ echo 'selected';}?>>Inactive</option></select></form></td>
<td><form action="<?= base_url('admin/change_position_status')?>" method="post">
  <input type="hidden" name="id"  value="<?= $p['id']?>">
  <select class="form-control" name="status" onchange="if(confirm('Are You Sure Want To change Status')){ this.form.submit() }">
  <option <?php if($p['status']=='Open'){ echo 'selected';}?>>Open</option>
  <option <?php if($p['status']=='Hold'){ echo 'selected';}?>>Hold</option>
  <option <?php if($p['status']=='Closed'){ echo 'selected';}?>>Closed</option>

</select></form></td>
<td id="update_but<?= $p['id']?>"  style="display: none;">
  <button type="button" onclick="get_text(this)" class="btn btn-success">Update</button>
</td>
</tr>
<?php $i++; }?>

</tbody>
</table>
<?= $links; ?>
</div>
</div>
</div>
</div>



</div>


</div>

</div>
</div>

</div>



<?php $this->load->view('admin/common/footer'); ?>
<script type="text/javascript">
  function editfield(e,n,id)
  {
      var v=$(e).text();
      $(e).empty();
      $(e).append('<input name="'+n+'" type="text" value="'+v+'" class="form-control" required>');
      $('#update_but'+id).css('display', 'block');
  }

  function get_text(e)
  {
    var array = [];
    //console.log($(e).parent().parent().find('input'));
    $(e).parent().parent().find('input').each(function(){
      $(this).attr('name');
      array.push({
        nam : $(this).attr("name"),
          vall : $(this).val()
         
    });
    });
      $.ajax({
      url: "<?= base_url('company/position_update')?>",
      data: { form_val : array },
      type: 'post',
      dataType: "json",
      success: function(data) {
        if(data==1)
        {
          
          alert("Successfully updated");
          //window.location.href="<?= base_url('company/position')?>";
        }
        else if(data==0)
        {
          alert("Please try After Some Time");
          //window.location.href="<?= base_url('company/position')?>";
        }
        else
        {
          alert("data");
          $('#error_panel').empty();
          $('#error_panel').append(data.error);
        }
      }
    });
  }

</script>