
<div class="page-content">
    <!-- Page Breadcrumb -->
    <div class="page-breadcrumbs">
        <ul class="breadcrumb">
            <li>
                <i class="fa fa-home"></i>
                <a href="#">Employee</a>
            </li>
            <li class="active">Leave</li>
        </ul>
    </div>
    <!-- /Page Breadcrumb -->

    <!-- Page Header -->
    <div class="page-header position-relative">
        <div class="header-title">
            <h1>
                Leave (New)
            </h1>
        </div>
        <!--Header Buttons-->
        <div class="header-buttons">
            <a class="sidebar-toggler" href="#">
                <i class="fa fa-arrows-h"></i>
            </a>
            <a class="refresh" id="refresh-toggler" href="">
                <i class="glyphicon glyphicon-refresh"></i>
            </a>
            <a class="fullscreen" id="fullscreen-toggler" href="#">
                <i class="glyphicon glyphicon-fullscreen"></i>
            </a>
        </div>
        <!--Header Buttons End-->
    </div>
    <!-- /Page Header -->
    <!-- Page Body -->
    



    
    <!-- End Page Body -->
                

    <div class="page-body">
        <div class="row">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div class="row">
                    <div class="col-xs-12 col-md-12">
                        <div class="widget">
                            <div class="widget-header ">
                                <span class="widget-caption">Leave</span>
                                <div class="widget-buttons">
                                    <a href="#" data-toggle="maximize">
                                        <i class="fa fa-expand"></i>
                                    </a>
                                    <a href="#" data-toggle="collapse">
                                        <i class="fa fa-minus"></i>
                                    </a>
                                    <a href="#" data-toggle="dispose">
                                        <i class="fa fa-times"></i>
                                    </a>
                                </div>
                            </div>
                            <div class="widget-body">
                                <div class="table-toolbar">
                                    
                                    <a id="close" href="<?php echo site_url('leaves')?>" class="btn btn-danger">
                                        <span class="fa fa-arrow-left"></span>
                                    </a>
                                    <div class="btn-group pull-right">
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-lg-12 col-sm-12 col-xs-12">
                                        <div class="well bordered-left bordered-themeprimary">
                                            <h3>Overview</h3>
                                            <p>vBizz Let you manage and track yearly leaves for your company.</p>
                                        </div>
                                    </div>
                                </div>
                                <div class = "row center">
                                    <div class="col-lg-10 col-sm-6 col-xs-12">
                                        <div class="widget center">
                                            <div class="widget-header bordered-bottom bordered-lightred">
                                                <span class="widget-caption">Add New Record</span>
                                            </div>
                                            <div class="widget-body">
                                                <div id="horizontal-form">
                                                    <form id="form_leave" class="form-horizontal" role="form" method="POST" action="<?php echo site_url('add_leave')?>">
                                                        <input type="hidden"  name="id" value="<?php echo !empty($leave)?$leave->id:''?>">
                                                        <div class="form-group">
                                                            <label for="inputEmail3" class="col-sm-2 control-label no-padding-right">Leave Type</label>
                                                            <div class="col-sm-10">
                                                                <input type="text" class="form-control" name="leave_type" placeholder="Leave Type" required
                                                                    value="<?php echo !empty($leave)?$leave->leave_type:''?>"
                                                                >
                                                            </div>
                                                        </div>
                                                        <div class="form-group">
                                                            <label for="inputEmail3" class="col-sm-2 control-label no-padding-right">Number of Leaves</label>
                                                            <div class="col-sm-10">
                                                                <input type="number" class="form-control" name="leave_number" placeholder="Number of Leaves" 
                                                                    value="<?php echo !empty($leave)?$leave->leave_number:''?>"
                                                                >
                                                            </div>
                                                        </div>
                                                        <div class="form-group">
                                                            <label for="" class="col-sm-2 control-label no-padding-right">Description</label>
                                                            <div class="col-sm-10">
                                                                    <textarea name="description" class="form-control" rows="3" placeholder="Description"><?php if(empty($leave)){echo $leave->description;}?></textarea>
                                                            </div>
                                                        </div>
                                                        <div class="form-group">
                                                            <label for="inputPassword3" class="col-sm-2 control-label no-padding-right">Paid Leave</label>
                                                            <div class="col-sm-10">
                                                                <div class="checkbox">
                                                                    <label>
                                                                        <input type="checkbox" class="colored-success" name="paid" 
                                                                        <?php
                                                                        if (!empty($leave)){
                                                                            if ($leave->paid==1) {
                                                                                echo 'checked';
                                                                            } else {   
                                                                                echo '';
                                                                            }
                                                                            
                                                                        } 
                                                                    ?>
                                                                        >
                                                                        <span class="text"></span>
                                                                    </label>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="form-group">
                                                            <label for="published" class="col-sm-2 control-label no-padding-right" >Leaves Carried to Next Year ?</label>
                                                            <div class="col-sm-10">
                                                                <label>
                                                                    <input id="published" name="carry_leave" class="checkbox-slider slider-icon colored-blue yesno" type="checkbox" 
                                                                    <?php
                                                                        if (!empty($leave)){
                                                                            if ($leave->carry_leave==1) {
                                                                                echo 'checked';
                                                                            } else {   
                                                                                echo '';
                                                                            }
                                                                            
                                                                        } 
                                                                    ?>
                                                                    >
                                                                    <span class="text" style="margin-top:6px"></span>
                                                                </label>
                                                            </div>
                                                        </div>
                                                        <div class="form-group">
                                                            <label for="inputEmail3" class="col-sm-2 control-label no-padding-right">
                                                                <input type="button"  class="btn btn-primary" id="add_params" onclick="" data-count="0" value="Add Params">
                                                            </label>
                                                            <?php 
                                                                if(!empty($leave)){
                                                                        if($leave->leave_params!==''&&$leave->leave_params!=null){
                                                                            $leave_params = json_decode($leave->leave_params);
                                                            ?>
                                                            <input type="hidden" id="input_count" name="1" value="<?php echo count($leave_params);?>">
                                                            <?php
                                                                    }else{
                                                            ?>
                                                                        <input type="hidden" id="input_count" name="2" value="">
                                                            <?php
                                                                }
                                                            }
                                                            ?>
                                                            <div class="col-sm-10">

                                                                <table id="tbl_params">
                                                                    <?php
                                                                    if(!empty($leave)){
                                                                        if($leave->leave_params!==''&&$leave->leave_params!=null){
                                                                            $leave_params = json_decode($leave->leave_params);
                                                                            // var_dump($leave_params);
                                                                            $count = 1;
                                                                            foreach ($leave_params as $row){
                                                                    ?>
                                                                            <tr id="tr<?php echo $count?>">
                                                                                <td><label for="">Title</label><input type="hidden" name="param_id[]" value="<?php echo $count?>"><input class="form-control" type="" name="title<?php echo $count?>" value="<?php echo $row->title?>" required></td>
                                                                                <td><label for="">Start Date</label><input class="form-control date-picker" data-date-format="yyyy-mm-dd" type="" name="start_date<?php echo $count?>" value="<?php echo $row->start_date?>" required></td>
                                                                                <td><label for="">End Date</label><input class="form-control date-picker" data-date-format="yyyy-mm-dd" type="" name="end_date<?php echo $count?>" value="<?php echo $row->end_date?>" required></td>
                                                                                <td><label for="">Optional</label><label style="display:block"> <input id="optional" name="optional<?php echo $count?>"  class="checkbox-slider slider-icon colored-blue yesno" type="checkbox"
                                                                                <?php

                                                                                 if ($row->optional==1) {
                                                                                        echo 'checked';
                                                                                    } else {   
                                                                                        echo '';
                                                                                    }
                                                                                ?>
                                                                                ><span class="text" style="margin-top:6px"></span></label></td>
                                                                                <td><a class="btn btn-danger remove_param" onclick="remove('tr<?php echo $count?>')"><span class="fa fa-remove"></span></a></td>
                                                                            </tr>
                                                                    <?php         
                                                                            ++$count;                                                               
                                                                            }
                                                                        }
                                                                    }

                                                                    ?>
                                                                </table>
                                                            </div>
                                                        </div>
                                                        <div class="form-group">
                                                            <div class="col-sm-offset-2 col-sm-10">
                                                                <button class="btn btn-success" type="submit" >
                                                                <span class="fa fa-check"></span>
                                                                Save</button>
                                                                <a id="close" href="<?php echo site_url('leaves')?>" class="btn btn-danger">
                                                                    <span class="fa fa-close"></span>
                                                                    Close
                                                                </a>
                                                            </div>
                                                        </div>
                                                    </form>
                                                </div>
                                            </div>
                                        </div>
                                    </div> 
                                    
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- End Page Content -->
<script>
    $(document).ready(function(){
        $('.date-picker').datepicker();
    });
    $('#add_params').click(function(){
            var str_count = $('#input_count').val();
            var table = $('#tbl_params');
            if (str_count==''){
                count = 0;
            }else{
                count = parseInt(str_count);
            }
            count = count+1;
            $('#input_count').val(count);
            console.log(count);


            $('<tr id="tr'+count+'">'+
                '<td><label for="">Title</label><input type="hidden" name="param_id[]" value="'+count+'"><input class="form-control" type="" name="title'+count+'" value="" required></td>'+
                '<td><label for="">Start Date</label><input class="form-control date-picker" data-date-format="yyyy-mm-dd" type="" name="start_date'+count+'" value="" required></td>'+
                '<td><label for="">End Date</label><input class="form-control date-picker" data-date-format="yyyy-mm-dd" type="" name="end_date'+count+'" value="" required></td>'+
                '<td><label for="">Optional</label><label style="display:block"> <input id="optional" name="optional'+count+'"  class="checkbox-slider slider-icon colored-blue yesno" type="checkbox"><span class="text" style="margin-top:6px"></span></label></td>'+
                '<td><a class="btn btn-danger remove_param" onclick="remove(\'tr'+count+'\')"><span class="fa fa-remove"></span></a></td>'+
            '</tr>').appendTo('#tbl_params');

            $('#tr'+count+' .date-picker').datepicker();

        });
   
    function remove(id){
        var row = $('tr[id='+id+']');
        var table = $('#tbl_params');
        document.getElementById("tbl_params").deleteRow(row[0].rowIndex);
        console.log("row", table);
    }

    function submit_leave(){
        document.getElementById('form_leave').submit();

    }

</script>