<?php 
include_once('../header_emp.php');
if(!check_login()){
	header("Location: " . WEB_URL . "logout.php");
	die();
}
?>
<?php
include_once(ROOT_PATH.'language/'.$lang_code_global.'/lang_leave_request.php');
$delinfo = 'none';
$addinfo = 'none';
$msg = "";
if(isset($_GET['id']) && $_GET['id'] != '' && $_GET['id'] > 0){
	$sqlx= "DELETE FROM `tbl_employee_leave_request` WHERE leave_id = ".$_GET['id'];
	mysqli_query($link,$sqlx); 
	$delinfo = 'block';
}
if(isset($_GET['m']) && $_GET['m'] == 'add'){
	$addinfo = 'block';
	$msg = $_data['text_8'];
}
if(isset($_GET['m']) && $_GET['m'] == 'up'){
	$addinfo = 'block';
	$msg = $_data['text_9'];
}
?>
<!-- Content Header (Page header) -->

<section class="content-header">
  <h1><?= $_data['t_text_1'];?></h1>
  <ol class="breadcrumb">
    <li><a href="<?= WEB_URL?>dashboard.php"><i class="fa fa-dashboard"></i><?= $_data['home_breadcam'];?></a></li>
    <li class="active"><?= $_data['text_2'];?></li>
    <li class="active"><?= $_data['text_1'];?></li>
  </ol>
</section>
<!-- Main content -->
<section class="content">
<!-- Full Width boxes (Stat box) -->
<div class="row">
  <div class="col-xs-12">
    <div id="me" class="alert alert-danger alert-dismissable" style="display:<?= $delinfo; ?>">
      <button aria-hidden="true" data-dismiss="alert" class="close" type="button"><i class="fa fa-close"></i></button>
      <h4><i class="icon fa fa-ban"></i> <?= $_data['delete_text'];?> !</h4>
      <?= $_data['text_10'];?> </div>
    <div id="you" class="alert alert-success alert-dismissable" style="display:<?= $addinfo; ?>">
      <button aria-hidden="true" data-dismiss="alert" class="close" type="button"><i class="fa fa-close"></i></button>
      <h4><i class="icon fa fa-check"></i> <?= $_data['success'];?> !</h4>
      <?= $msg; ?> </div>
    <div align="right" style="margin-bottom:1%;"> <a class="btn btn-success" data-toggle="tooltip" href="<?= WEB_URL; ?>e_dashboard/add_leave_request.php" data-original-title="<?= $_data['text_3'];?>"><i class="fa fa-plus"></i></a> <a class="btn btn-success" data-toggle="tooltip" href="<?= WEB_URL; ?>e_dashboard.php" data-original-title="<?= $_data['home_breadcam'];?>"><i class="fa fa-dashboard"></i></a> </div>
    <div class="box box-success">
      <div class="box-header">
        <h3 class="box-title"><?= $_data['text_1'];?></h3>
      </div>
      <!-- /.box-header -->
      <div class="box-body">
        <table class="table sakotable table-bordered table-striped dt-responsive">
          <thead>
            <tr>
              <th><?= $_data['requested_date']; ?></th>
			  <th><?= $_data['leave_from']; ?></th>
			  <th><?= $_data['leave_to']; ?></th>
			  <th><?= $_data['leave_days']; ?></th>
			  <th><?= $_data['leave_status']; ?></th>
              <th><?= $_data['action_text'];?></th>
            </tr>
          </thead>
          <tbody>
            <?php
				$result = mysqli_query($link,"Select * from tbl_employee_leave_request r inner join tbl_add_employee e on e.eid = r.employee_id inner join tbl_add_member_type m on m.member_id = e.e_designation where r.branch_id = '" . (int)$_SESSION['objLogin']['branch_id'] . "' and r.employee_id = '" . (int)$_SESSION['objLogin']['eid'] . "' order by r.request_date ASC");
				while($row = mysqli_fetch_array($result)){?>
            <tr>
              <td><?= date('d/m/Y', strtotime($row['request_date'])); ?></td>
			  <td><?= $ams_helper->mySqlToDatePicker($row['from']); ?></td>
			  <td><?= $ams_helper->mySqlToDatePicker($row['to']); ?></td>
			  <td><label class="label label-success ams_label"><?= $ams_helper->daysBetween($row['from'], $row['to']);?></label></td>
			  <td><label class="label label-<?php if($row['request_status']=='Accepted'){echo 'success';} elseif($row['request_status']=='Rejected'){echo 'danger';}else{echo 'warning';}?> ams_label"><?= $row['request_status']; ?></label></td>
              <td><a class="btn btn-success ams_btn_special" data-toggle="tooltip" href="javascript:;" onClick="$('#nurse_view_<?= $row['leave_id']; ?>').modal('show');" data-original-title="<?= $_data['view_text'];?>"><i class="fa fa-eye"></i></a> <a class="btn btn-warning ams_btn_special" data-toggle="tooltip" href="<?= WEB_URL;?>e_dashboard/add_leave_request.php?id=<?= $row['leave_id']; ?>" data-original-title="<?= $_data['edit_text'];?>"><i class="fa fa-pencil"></i></a> <a class="btn btn-danger ams_btn_special" data-toggle="tooltip" onClick="deleteLeaveData(<?= $row['leave_id']; ?>);" href="javascript:;" data-original-title="<?= $_data['delete_text'];?>"><i class="fa fa-trash-o"></i></a>
                <div id="nurse_view_<?= $row['leave_id']; ?>" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                  <div class="modal-dialog">
                    <div class="modal-content">
                      <div class="modal-header green_header">
                        <button aria-label="Close" data-dismiss="modal" class="close" type="button"><span aria-hidden="true"><i class="fa fa-close"></i></span></button>
                        <h3 class="modal-title"><?= $_data['text_1_1_1'];?></h3>
                      </div>
                      <div class="modal-body">
                        <h3 style="text-decoration:underline;"><?= $_data['details_information'];?></h3>
                        <div class="row">
                          <div class="col-xs-6"> <b><?= $_data['requested_date']; ?> :</b> <?= date('d/m/Y', strtotime($row['request_date'])); ?><br/>
						  	<b><?= $_data['leave_from']; ?> :</b> <?= $ams_helper->mySqlToDatePicker($row['from']); ?><br/>
                            <b><?= $_data['leave_to'];?> :</b> <?= $ams_helper->mySqlToDatePicker($row['to']); ?><br/>
                            <b><?= $_data['leave_days'];?> :</b> <?= $ams_helper->daysBetween($row['from'], $row['to']); ?><br/>
                            <b><?= $_data['leave_status'];?> :</b> <?= $row['request_status']; ?><br/></div>
							<div class="col-xs-6">
							<b><?= $_data['leave_description'];?> :</b> <?= $row['leave_text']; ?><br/>
                          </div>
                        </div>
                      </div>
                    </div>
                    <!-- /.modal-content -->
                  </div>
                </div></td>
            </tr>
            <?php } mysqli_close($link);$link = NULL; ?>
          </tbody>
        </table>
      </div>
      <!-- /.box-body -->
    </div>
    <!-- /.box -->
  </div>
  <!-- /.col -->
</div>
<!-- /.row -->
<script type="text/javascript">
function deleteLeaveData(Id){
  	var iAnswer = confirm("<?= $_data['text_100']; ?>");
	if(iAnswer){
		window.location = '<?= WEB_URL; ?>e_dashboard/leave_request_list.php?id=' + Id;
	}
  }
  $( document ).ready(function() {
	setTimeout(function() {
		$("#me").hide(300);
		$("#you").hide(300);
	}, 3000);
});
</script>
<?php include_once('../footer.php'); ?>
