<?php include 'inc_classes.php'; 
include "admin_authentication.php";
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Apply Leave</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <!-- Bootstrap 3.3.7 -->
  <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
  <!-- daterange picker -->
  <link rel="stylesheet" href="bower_components/bootstrap-daterangepicker/daterangepicker.css">
  <!-- bootstrap datepicker -->
  <link rel="stylesheet" href="bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
  <!-- iCheck for checkboxes and radio inputs -->
  <link rel="stylesheet" href="plugins/iCheck/all.css">
  <!-- Bootstrap Color Picker -->
  <link rel="stylesheet" href="bower_components/bootstrap-colorpicker/dist/css/bootstrap-colorpicker.min.css">
  <!-- Bootstrap time Picker -->
  <link rel="stylesheet" href="plugins/timepicker/bootstrap-timepicker.min.css">
  <!-- Select2 -->
  <link rel="stylesheet" href="bower_components/select2/dist/css/select2.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
  <!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
  <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->
  <!-- Google Font -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>

 
  <!-- <script src="https://code.jquery.com/jquery-migrate-3.4.1.min.js"></script>  -->
<script>
  //  var from = null,start = 0; url='inc_classes.php';
  // $(document).ready(function(){
  //   from = prompt("please enter your name");
  //   $(from).submit(function(e){
  //     $.post(url,{
  //       message:$('#message').val(),
  //       from:from
  //     });
  //     $('#message').val('');
  //     return false;
  //   })
    

  // });
  // function load(){
  //   $.get(url + '?start=' + start,function(result){
  //     if(result.items){
  //       result.items.forEach(item=>{
  //         start = item.id;
  //         $('#message').append(renderMessage(item));
  //       })
  //     };
  //     load();
  //   })
  // }
  // function renderMessage(item){
  //   let time=new date(item.created);
  //   time=`${time.getHours()}:${time.getMinutes()<10?'0':''}${time.getMinutes()}`;
  //   return`<div class="msg"><p>${item.form}</p>${item.message}<span>${time}</span></div>`;

  //  } 

</script>

<?php
   if(isset($_POST['approved']))
 
   {
     
     $status= "Approved";
   $comment=$_POST['comment'];
      $leave_id=$_POST['leave_id'];
 
      $insert_salary="UPDATE `pr_apply_leave` set `status`= '$status',`comment`='$comment' where `leave_id`=' $leave_id'";
     $ptr_ins=mysql_query($insert_salary);
   }
    if(isset($_POST['rejected']))
    {
     
      $status= 'Rejected';
      $comment=$_POST['comment'];
      $leave_id=$_POST['leave_id'];
 
       $insert_salary="UPDATE `pr_apply_leave` set `status`= '$status',`comment`='$comment' where `leave_id`=' $leave_id'";
       $ptr_ins=mysql_query($insert_salary);
    }
    ?>   

 <?php 
//  function dataupload(){
 $result=array();
 if (isset($_REQUEST["plus"])){
 $message=$_POST['message'];
  $from = $_POST['from']; 

//if(!empty($message) && !empty($from)){
 echo $sql = "insert into pr_comment_box(`message`,`from`) value('".$message."','".$from."')";
      $ptr_query=mysql_query($sql);
  //$result['send_status'] = $db->query($sql);
  // $sel_app="select * from pr_comment_box where 1 and cm_id='".$_SESSION['cm_id']."' and admin_id='".$_SESSION['admin_id']."'";
  // $ptr_app=mysql_query($sel_app);
 }
 //$start = isset($_GET['start'])? interval($_GET['start']) :0;
 /* $items = $db->query("SELECT * FROM `pr_comment_box` WHERE `id` > ".$start);
 while($row = $items->fetch_assoc()){
   $result['items'][]=$row; */

  //  $start="select name from site_setting where 1 and admin_id='".$data_app['status_updated_by']."'";
  //  $items=mysql_query($start);
  //  $result=mysql_fetch_array($items);
//  }


//$db->close();

/* header('Access-Control-Allow-Origin:*');
header('Content-Type:application/json');
echo json_encode($result); */

?>



<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
  <?php include "include/header-main.php"; ?>
  <!-- Left side column. contains the logo and sidebar -->
  <?php include "include/menu_left.php"; ?>
  <!-- Content Wrapper. Contains page content -->
    <!-- Left side column. contains the logo and sidebar -->
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
       <h1>
        Leave Details
        <!--<small>Version 2.0</small>-->
       </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">Dashboard</li>
      </ol>
    </section>
  

            <!-- /.box-header -->
            <div class="box-body">
              <div class="table-responsive">
                <table class="table no-margin">
                  
                        <?php
                        $id='';
                        $where_leave_id='';
                        if($_REQUEST['id'])
                        {
                            $leave_id=$_GET['id'];    
                            $where_staff_id="and leave_id='".$leave_id."'";
                        }
                        


                        $sel_app="select * from pr_apply_leave where 1 ".$where_staff_id." ";
                        $ptr_app=mysql_query($sel_app);
                        $t=1;
                    
                        while($data_app=mysql_fetch_array($ptr_app))
                        {
                            $sel_staff="select name from site_setting where 1 and admin_id='".$data_app['admin_id']."'";
                            $ptr_staff=mysql_query($sel_staff);
                            $data_staff=mysql_fetch_array($ptr_staff);
                            ?>


                            
                            <tr>
                            
                                 <td><b>Staff Name -</td><td><?php echo $data_staff['name']; ?></td>
                                <input type="hidden" name="admin_id" id="admin_id" value="<?php echo $_SESSION[admin_id]; ?>" >
                                
                                <td><b>Reason -</td><td><?php echo $data_app['reason']; ?></td>
                                
                            </tr>
                       
                            <tr>
                            
                                <td><b> Leave From -</td><td><?php echo $data_app['from_date']; ?></td>

                                <td><b>Leave To -</td><td><?php echo $data_app['to_date']; ?></td>

                            </tr>
                            <tr>
                                <td><b>Status -</td><td>
                        <?php 
                        if($data_app['status'] =='Approved' ){
                          ?>
                          <span class="label label-success"><?php echo $data_app['status'] ?> </span>
                          <?php
                        }
                         
                        if($data_app['status'] =='Rejected' ){
                          ?>
                          <span class="label label-danger"><?php echo $data_app['status'] ?> </span>
                          <?php
                        }
                        
                        if($data_app['status'] =='Pending' ){
                          ?>
                          <span class="label label-warning"><?php echo $data_app['status'] ?> </span>
                          <?php
                        }
                        // else if($data_app['status'] =='pending' )
                        // {
                        //   $status= 'warning';
                        // }
                        // else if($data_app['status'] =='Rejected' )
                        // {
                        //   $status= 'danger';
                        // }
                        ?>
                        </td>
                         <td><span class="label label-<?php echo $status; ?>">
                          
                      </td>
                            
                                <td><b>Approved by -</td><td><?php echo $data_app['approved_by']; ?></td>
                            </tr>
                       
                            <?php
					        $t++;
				        }
				        ?>
                
                  </tbody>
                </table>
              </div>


              <!-- Chat box -->
            <div class="box box-success">
              <div class="box-header">
                <i class="fa fa-comments-o"></i>

                <h3 class="box-title">Chat</h3>

                <div class="box-tools pull-right" data-toggle="tooltip" title="Status">
                  <div class="btn-group" data-toggle="btn-toggle">
                    <button type="button" class="btn btn-default btn-sm active"><i class="fa fa-square text-green"></i></button>
                    <button type="button" class="btn btn-default btn-sm"><i class="fa fa-square text-red"></i></button>
                  </div>
                </div>
              </div>
              
           

            <div class="box-body chat" id="chat-box">
              <!-- chat item -->
              <!-- <div class="item">
                <img src="dist/img/user4-128x128.jpg" alt="user image" class="online">

                <p class="message">
                  <a href="#" class="name">
                    <small class="text-muted pull-right"><i class="fa fa-clock-o"></i> 2:15</small>
                    Mike Doe
                  </a>
                  I would like to meet you to discuss the latest news about
                  the arrival of the new theme. They say it is going to be one the
                  best themes on the market
                </p>
                <div class="attachment">
                  <h4>Attachments:</h4>

                  <p class="filename">
                    Theme-thumbnail-image.jpg
                  </p>


                   <div class="pull-right">
                    <button type="button" class="btn btn-primary btn-sm btn-flat">Open</button>
                  </div>
                </div> 
              </div>   -->
              <!-- /.item -->
              <!-- chat item -->
                
              <!-- /.item -->
              
            <div id="comment_data">
              
              <!-- coment by admin -->
              <!-- <div class="item">
                <img src="dist/img/user2-160x160.jpg" alt="user image" class="offline">

                <p class="message">
                  <a href="#" class="name">
                      <small class="text-muted pull-right"><i class="fa fa-clock-o"></i> 5:30</small>
                      Susan Doe
                  </a>
                      I would like to meet you to discuss the latest news about
                      the arrival of the new theme. They say it is going to be one the
                      best themes on the market
                </p>
              </div> -->
              <!-- coment by user -->
              <!-- <div class="item" style="display: inline-flex;" id="comment_user">
                <p class="message" style="margin-right: 20px; !important; margin-top:0px !important">
                  <a href="#" class="name" style="text-align: right; margin-right:20px !important">
                    <small class="text-muted pull-left"><i class="fa fa-clock-o"></i> 5:30</small>
                    Susan Doe
                  </a>
                  I would like to meet you to discuss the latest news about
                  the arrival of the new theme. They say it is going to be one the
                  best themes on the market
                </p>
                  <img src="dist/img/user2-160x160.jpg" alt="user image" class="offline">
              </div> -->
              <!-- /.item -->
            </div>
          </div> 
              <form name="chat" method="Post">
                <div class="box-body chat" id="uploaddata" style="text-align: right; margin-right:20px !important"></div>
                <div class="box-footer">
                  <div class="input-group">
                    <input type="text" class="form-control" id="sneha" name="comment_text" placeholder="Type message...">

                    <div class="input-group-btn">
                      
                      
                      <button type="button" class="btn btn-success" onclick="add_comment();"><i class="fa fa-plus"></i></button>
                    </div>
                  </div>
                </div> 
                <button type="button" name="approved" value="Submit" class="btn btn-block btn-primary" onclick="Approved();">Approved</button>
                <button type="button" name="rejected" value="Submit" class="btn btn-block btn-danger" onclick="Reject();">Reject</button>
                  <!-- /.table-responsive -->
              </form>   
            </div>
            <!-- /.box-body -->
            <div class="box-footer clearfix">
              <!--<a href="javascript:void(0)" class="btn btn-sm btn-info btn-flat pull-left">Place New Order</a>
              <a href="javascript:void(0)" class="btn btn-sm btn-default btn-flat pull-right">View All Orders</a>-->
            </div>
            <!-- /.box-footer -->
          </div>
          <!-- /.box -->
        </div>
        <!-- /.col -->
	  </div>
      <!-- /.box -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  <?php include "include/footer-main.php"; ?>
</div>

<!-- jQuery 3 -->
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- Select2 -->
<script src="bower_components/select2/dist/js/select2.full.min.js"></script>
<!-- InputMask -->
<script src="plugins/input-mask/jquery.inputmask.js"></script>
<script src="plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
<script src="plugins/input-mask/jquery.inputmask.extensions.js"></script>
<!-- date-range-picker -->
<script src="bower_components/moment/min/moment.min.js"></script>
<script src="bower_components/bootstrap-daterangepicker/daterangepicker.js"></script>
<!-- bootstrap datepicker -->
<script src="bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
<!-- bootstrap color picker -->
<script src="bower_components/bootstrap-colorpicker/dist/js/bootstrap-colorpicker.min.js"></script>
<!-- bootstrap time picker -->
<script src="plugins/timepicker/bootstrap-timepicker.min.js"></script>
<!-- SlimScroll -->
<script src="bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
<!-- iCheck 1.0.1 -->
<script src="plugins/iCheck/icheck.min.js"></script>
<!-- FastClick -->
<script src="bower_components/fastclick/lib/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="dist/js/demo.js"></script>
<!-- Page script -->
<script>
  $(function () {
    //Initialize Select2 Elements
    $('.select2').select2()

    //Datemask dd/mm/yyyy
    /*$('#datemask').inputmask('dd/mm/yyyy', { 'placeholder': 'dd/mm/yyyy' })
    //Datemask2 mm/dd/yyyy
    $('#datemask2').inputmask('mm/dd/yyyy', { 'placeholder': 'mm/dd/yyyy' })
    //Money Euro
    $('[data-mask]').inputmask()

    //Date range picker
    $('#reservation').daterangepicker()
    //Date range picker with time picker
    $('#reservationtime').daterangepicker({ timePicker: true, timePickerIncrement: 30, format: 'MM/DD/YYYY h:mm A' })
    //Date range as a button
    $('#daterange-btn').daterangepicker(
      {
        ranges   : {
          'Today'       : [moment(), moment()],
          'Yesterday'   : [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
          'Last 7 Days' : [moment().subtract(6, 'days'), moment()],
          'Last 30 Days': [moment().subtract(29, 'days'), moment()],
          'This Month'  : [moment().startOf('month'), moment().endOf('month')],
          'Last Month'  : [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
        },
        startDate: moment().subtract(29, 'days'),
        endDate  : moment()
      },
      function (start, end) {
        $('#daterange-btn span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'))
      }
    )*/

    //Date picker
    $('#datepicker').datepicker({
      autoclose: true,
	  format: 'dd/mm/yyyy',
	  startDate: '-1d',
	  Default: true,
	  todayHighlight: true
    })
	$('#datepicker1').datepicker({
      autoclose: true,
	  format: 'dd/mm/yyyy',
	  Default: true,
	  todayHighlight: true
    })

    //iCheck for checkbox and radio inputs
    $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
      checkboxClass: 'icheckbox_minimal-blue',
      radioClass   : 'iradio_minimal-blue'
    })
    //Red color scheme for iCheck
    $('input[type="checkbox"].minimal-red, input[type="radio"].minimal-red').iCheck({
      checkboxClass: 'icheckbox_minimal-red',
      radioClass   : 'iradio_minimal-red'
    })
    //Flat red color scheme for iCheck
    $('input[type="checkbox"].flat-red, input[type="radio"].flat-red').iCheck({
      checkboxClass: 'icheckbox_flat-green',
      radioClass   : 'iradio_flat-green'
    })

    //Colorpicker
    $('.my-colorpicker1').colorpicker()
    //color picker with addon
    $('.my-colorpicker2').colorpicker()

    //Timepicker
    $('.timepicker').timepicker({
      showInputs: false
    })
  })
</script>

<script>
 function myvalidation(){
  var chat_box = document.forms["chat"]["chat-box"].value;
}

function add_comment(){
    var commentText= encodeURIComponent(document.getElementById("sneha").value);
    var staff_id= document.getElementById("admin_id").value;
    var leave_id='<?php echo $_REQUEST['id']; ?>';
    var comment_data="action=add_leave_comments&staff_id="+staff_id+"&leave_id="+leave_id+"&comment="+commentText;
    //alert(comment_data);
    $.ajax({
    url: "ajax_leave.php",type:"post", data: comment_data,cache: false,
    success: function(retcomment)
    {
        //alert(retcomment);
        document.getElementById("comment_data").innerHTML=retcomment;
        setTimeout(show_comment(leave_id),200);
    }
    });

}

function show_comment(leave_id){
    //leave_id='<?php echo $_REQUEST['id']; ?>';
    var comment_data="action=show_leave_comments&leave_id="+leave_id;
    //alert(comment_data);
    $.ajax({
    url: "ajax_leave.php",type:"post", data: comment_data,cache: false,
    success: function(retcomment)
    {
        //alert(retcomment);
        document.getElementById("comment_data").innerHTML=retcomment;
    }
    });
}
 
$(function () {
  show_comment(<?php echo $_REQUEST['id']; ?>);
})

function Approved(leave_id){
    leave_id='<?php echo $_REQUEST['id']; ?>';
    var comment_data="action=Approved&leave_id="+leave_id;
    //alert(comment_data);
    $.ajax({
    url: "ajax_leave.php",type:"post", data: comment_data,cache: false,
    success: function(retcomment)
    {
        // alert(retcomment);
        //document.getElementById("comment_data").innerHTML=retcomment;
    }
    });
}
 
$(function () {
  Approved(<?php echo $_REQUEST['id']; ?>);
})

function Reject(leave_id){
    leave_id='<?php echo $_REQUEST['id']; ?>';
    var comment_data="action=Reject&leave_id="+leave_id;
    //alert(comment_data);
    $.ajax({
    url: "ajax_leave.php",type:"post", data: comment_data,cache: false,
    success: function(retcomment)
    {
        //alert(retcomment);
        // document.getElementById("comment_data").innerHTML=retcomment;
    }
    });
}
 
$(function () {
  Reject(<?php echo $_REQUEST['id']; ?>);
})

</script> 
</body>
</html>