<?php
include 'connect/cms-config.php' ;
include 'requires/function.php' ;
include 'requires/session.php' ;

// check permission
if ( !permissionCheck($row_user, 'attendance-list-view') ){
    header('Location: index.php') ;
    exit ;
}

// keep parameter in value
$edit           = escapeString($_GET['edit']) ;
$page 	   	    = escapeString($_GET['page']) ;
$page_mode 	    = escapeString($_GET['page_mode']) ;
$type 	   	    = escapeString($_GET['type']) ;


// get all branch
$branch     = [] ;
$get_branch = $mysqli->query("SELECT * FROM branch
                              WHERE deleted_at IS NULL".$user_branch_permission_sql) ;
if ( $get_branch->num_rows > 0 ){
    while ( $row_branch = $get_branch->fetch_assoc() ){
        $branch[$row_branch['branch_id']] = $row_branch['branch_name'] ;
    }
}
include 'HR/hr-attendance-format-2-update.php' ;
include 'HR/hr-attendance-format-2-data.php' ;

$boolean_role = false ;
$boolean_edit = false ;
if ( permissionCheck($row_user,"attendance-list-edit") ){
    $boolean_role = true ;
    if ( $edit == 'yes' ){
        $boolean_edit = true ;
    }
}

// active page
$active_main_menu = 'hr' ;
$active_sub_menu  = 'hr-attendance' ;
$active_menu 	  = 'hr-attendance-list' ;	

// start header here
include 'requires/page_header.php' ;
include 'requires/page_top.php' ;

// reset sort by type
$sort_by_type = ( $sort_by_type == 'DESC' ? 'ASC' : 'DESC' ) ;

// get all attendance list
$array_list     = [] ;
$get_attendaces = $mysqli->query("SELECT list_id, list_work_day, list_ot_day, list_late, list_early_out, list_time_off, list_type_remark, staff_id, list_date, list_attendance_remark FROM staff_attendance_list
                          WHERE deleted_at IS NULL AND list_date LIKE '".$date_time."%'") ;
if ( $get_attendaces->num_rows > 0 ){
    while ( $row_list = $get_attendaces->fetch_assoc() ){
        $array_list[$row_list['staff_id']][$row_list['list_date']] = $row_list ;
    }
}

// get all requires 
$tier_list         = [] ;
$mysqli_tier       = $mysqli->query("SELECT a.tier_id, b.title FROM profile_tier a
                                     LEFT JOIN profile_tier_translation b ON ( a.tier_id = b.tier_id )
                                     WHERE a.deleted_at IS NULL AND b.lang = 'en' ORDER BY a.sortable ASC") ;
if ( $mysqli_tier->num_rows > 0 ){
    while ( $row_tier = $mysqli_tier->fetch_assoc() ){
        $tier_list[]  = $row_tier ;
    }
}

?>

<style>
.check_in_out_warning{
    background:#f7a6a6;
}
.select_datepicker{
    text-align: center;
}
.datepicker_box{
    display: inline-block;
}
.datepicker_submit{
    border: 0;
    padding: 7px;
}
</style>

<!-- Header Ends -->
<div class="warper container-fluid">   	
	<div class="page-header">
        <h1><?= $lang['attendance']?> <small><?= $lang['list']?></small></h1>
        <div class="clearfix">
            <div style="float: right;">
                <?php if ( permissionCheck($row_user, 'attendance-attendance-reprocessing') ){ ?>
                    [ <a href="hr-attendance.php?page_mode=reprocessing" target="_blank"><?= $lang['Reprocessing'] ?></a> ]
                    <br />
                <?php } ?>
                [ <a href="<?= ( PATHEXPORT != 'PATHEXPORT' ? PATHEXPORT : '' ) ?>hr-attendance-format-2.php?<?= $search_url ?>&export=yes" target="_blank"><?= $lang['export_as']?> Excel</a> ]
            </div>
        </div>
    </div>

    <?php
    if ( $boolean_role ){
        if ( $edit == 'yes' ){
            echo '<a href="?'.$search_url.'&edit=" class="btn btn-purple" style="margin-bottom:10px;">'.$lang['Normal Mode'].'</a>' ;
        }else{
            echo '<a href="?'.$search_url.'&edit=yes" class="btn btn-purple" style="margin-bottom:10px;">'.$lang['Edit Mode'].'</a>' ;
        }
    }
    ?>

    <?php
    if ($_SESSION['system_result'] != ''){
        echo $_SESSION['system_result'] ;
        unset($_SESSION['system_result']) ;
    }
    ?>

    <div class="panel panel-default" id="basic-table-title">
        <div class="panel-heading"></div>
        <div class="panel-body">
            <form method="get" class="form-horizontal" style="max-width:600px;">
                <div class="form-group">
                    <label class="col-sm-2 control-label"><?= $lang['Name']?></label>
                    <div class="col-sm-9">
                        <input type="text" name="search_name" value="<?= $search_name ?>" class="form-control" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label"><?= $lang['ID No']?></label>
                    <div class="col-sm-9">
                        <input type="text" name="search_idno" value="<?= $search_idno ?>" class="form-control" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label"><?= $lang['Mobile'] ?></label>
                    <div class="col-sm-9">
                        <input type="text" name="search_mobile" value="<?= $search_mobile ?>" class="form-control" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label"><?= $lang['email'] ?></label>
                    <div class="col-sm-9">
                        <input type="text" name="search_mail" value="<?= $search_mail ?>" class="form-control" />
                    </div>
                </div>
                <div class="form-group" style="display: none;">
                    <label class="col-sm-2 control-label"><?= $lang['Tier'] ?></label>
                    <div class="col-sm-9">
                        <select name="search_tier" class="form-control">
                            <option value=""><?= $lang['All'] ?></option>
                            <?php foreach( $tier_list as $k => $v ){ ?>
                                <option value="<?= $v['tier_id'] ?>" <?= ( $search_tier == $v['tier_id'] ? 'selected' : '' ) ?> ><?= $v['title'] ?></option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                <div class="form-group" style="display: none;">
                    <label class="col-sm-2 control-label"><?= $lang['Department']?></label>
                    <div class="col-sm-9">
                        <select name="search_department[]" class="chosen-select select2-basic-single form-control" multiple >
                            <?php
                            // department check list
                            $department     = [] ;
                            $get_department = $mysqli->query("SELECT a.department_id, b.department_desc FROM setting_department a
                                                              LEFT JOIN setting_department_translation b ON ( a.department_id = b.department_id )
                                                              WHERE a.deleted_at IS NULL AND b.lang = 'en'") ;
                            if ( $get_department->num_rows > 0 ){
                                while ( $row_department = $get_department->fetch_assoc() ){
                                    
                                    $department[$row_department['department_id']] = $row_department['department_desc'] ;
                                }
                            }

                            foreach ( $department as $kk => $vv ){
                                $selected = '';
                                
                                if(arrayCheck($_GET['search_department'])){
                                    if(in_array("$kk", $_GET['search_department'], TRUE)){
                                         $selected = 'selected';
                                    }
                                }
                                echo '<option value="'.$kk.'" '.$selected.'>'.$vv.'</option>' ;
                            }
                            ?>
                        </select>
                    </div>
                </div>
                <div class="form-group" style="display: none;">
                    <label class="col-sm-2 control-label"><?= $lang['L_F']?></label>
                    <div class="col-sm-9">
                        <select name="search_country" class="form-control">
                            <option value=""><?= $lang['All']?></option>
                            <option value="local" <?= $search_country == 'local' ? 'selected' : '' ?> ><?= $lang['Local']?></option>
                            <option value="foreigner" <?= $search_country == 'foreigner' ? 'selected' : '' ?> ><?= $lang['Foreigner']?></option>
                        </select>
                    </div>
                </div>
                <div class="form-group" style="display: none;">
                    <label class="col-sm-2 control-label"><?= $lang['branch']?></label>
                    <div class="col-sm-9">
                        <select name="search_branch" class="form-control">
                            <option value=""><?= $lang['All']?></option>
                            <?php
                            foreach ( $branch as $kk => $vv ){
                                echo '<option value="'.$kk.'" '.( $search_branch == $kk ? 'selected' : '' ).' >'.$vv.'</option>' ;
                            }
                            ?>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label"><?= $lang['Day From'] ?></label>
                    <div class="col-sm-9">
                        <select class="form-control" name="search_day_from">
                            <option value="">Select</option>
                            <?php
                                for ($i=1; $i < date("t", strtotime($date_time)) ; $i++) { 
                                   echo ' <option value="'.$i.'" '.($search_day_from == $i ? "selected" : '').'>'.$i.'</option>';
                                }
                            ?>
                        </select>
                        
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 control-label"><?= $lang['Day To'] ?></label>
                    <div class="col-sm-9">
                        <select class="form-control" name="search_day_to">
                            <option value="">Select</option>
                            <?php
                                for ($i=1; $i < date("t", strtotime($date_time)) ; $i++) { 
                                   echo ' <option value="'.$i.'" '.($search_day_to == $i ? "selected" : '').'>'.$i.'</option>';
                                }
                            ?>
                        </select>
                    </div>
                </div>
               <!--  <div class="form-group">
                    <label class="col-sm-2 control-label"><?= $lang['Date Resigned'] ?></label>
                    <div class="col-sm-9">
                        <input class="form-control" name="search_resigned" type="date" value="<?= ($search_resigned!= '' ? $search_resigned : date('Y-m-d',time()) ) ?>" placeholder="Date Resigned">
                    </div>
                </div> -->
                <div class="form-group">
                    <label class="col-sm-2 control-label"><?= $lang['Resign List'] ?></label>
                    <div class="col-sm-9">
                        <input  name="search_resigned" type="checkbox" value="1" <?= ($search_resigned!= '' ? "checked" : "") ?> placeholder="Resign List">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">View Type</label>
                    <div class="col-sm-9">
                        <select name="export" class="form-control">
                            <option value="">Search</option>
                            <option value="yes">View as Excel </option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-11">
                        <input type="hidden" name="page_mode" value="<?= $page_mode ?>" />
                        <input type="hidden" name="edit" value="<?= $edit ?>" />
                        <input type="hidden" name="date_time" value="<?= $date_time ?>" />
                        <input type="hidden" name="sort_by" value="<?= $sort_by ?>" />
                        <input type="hidden" name="sort_by_type" value="<?= $sort_by_type ?>" />
                        <button type="submit" class="btn btn-purple" style="float:right"><?= $lang['submit']?></button>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <div class="panel panel-default" id="basic-table-title">
        <div class="panel-heading"></div>
        <div class="panel-body">

        	<div class="form-group">
                <div class="col-sm-12">

                	<div class="box-tools col-sm-12 col-md-12 col-lg-12" style="text-align: center; margin: 20px;">
    		            <a href="?<?= $search_url ?>&page=1&date_time=<?= date('Y-m', strtotime($date_time.' -1 month')) ?>" class="width_auto"><?= $lang['Prev Month']?></a>

    		            <div class="datepicker_box">
    		            	<span style="margin-left:10px; margin-right:10px;">
    		            		<input type="text" readonly name="date_time" class="select_datepicker" value="<?= $date_time ?>">
    		            	</span>
    		            </div>

    		            <?php
    		            if ( $date_time >= date('Y-m', strtotime(TODAYDAY)) ){}else{
    		            	?>
    		            	<a href="?<?= $search_url ?>&page=1&date_time=<?= date('Y-m', strtotime($date_time.' +1 month')) ?>" class="width_auto"><?= $lang['Next Month']?></a>
    		            	<?php
    		            }
    		            ?>
    				</div>

                </div>
        	</div>

        	<div class="form-group">
                <div class="col-sm-12">

                	<table class="ui-table table table-striped jambo_table bulk_action table-bordered stripe row-border order-column" id="basic-datatable-column">
    					<thead>
    						<tr class="headings">
                                <th class="column-title text-center" width="8%">
                                    <div class="custom_dropdown_title">
                                        <div class="dataTable_width_image"><?= $lang['Image']?></div>
                                    </div>
                                </th>
                                <th class="column-title text-center" width="8%">
                                    <div class="custom_dropdown_title">
                                        <div class="dataTable_width_id">
                                            <a href="?<?= $search_url ?>&sort_by=staff_idno&sort_by_type=<?= ($sort_by == 'staff_idno' ? $sort_by_type : 'ASC') ?>">
                                            ID<?= ( $sort_by == 'staff_idno' ? '<i class="fa fa-sort-alpha-'.( $sort_by_type == 'DESC' ? 'asc' : 'desc' ).'"></i>' : '' ) ?>
                                            </a>
                                        </div>
                                    </div>
                                </th>
                                <th class="custom_dropdown_th" >
                                    <div class="custom_dropdown_title">
                                        <a href="?<?= $search_url ?>&sort_by=staff_name&sort_by_type=<?= ($sort_by == 'staff_name' ? $sort_by_type : 'ASC') ?>">
                                        <?= $lang['Name']?><?= ( $sort_by == 'staff_name' ? '<i class="fa fa-sort-alpha-'.( $sort_by_type == 'DESC' ? 'desc' : 'asc' ).'"></i>' : '' ) ?>
                                        </a>
                                    </div>
                                </th>
                                <th>
                                    <div class="custom_dropdown_title">
                                        <a href="?<?= $search_url ?>&sort_by=department_desc&sort_by_type=<?= ($sort_by == 'department_desc' ? $sort_by_type : 'ASC') ?>">
                                        <?= $lang['Department']?><?= ( $sort_by == 'department_desc' ? '<i class="fa fa-sort-alpha-'.( $sort_by_type == 'DESC' ? 'desc' : 'asc' ).'"></i>' : '' ) ?>
                                        </a>
                                    </div>
                                </th>
                                <th>
                                    <div class="custom_dropdown_title">
                                        <a href="?<?= $search_url ?>&sort_by=job_position_id&sort_by_type=<?= ($sort_by == 'job_position_id' ? $sort_by_type : 'ASC') ?>">
                                        <?= $lang['Designation']?><?= ( $sort_by == 'job_position_id' ? '<i class="fa fa-sort-alpha-'.( $sort_by_type == 'DESC' ? 'desc' : 'asc' ).'"></i>' : '' ) ?>
                                        </a>
                                    </div>
                                </th>

                                <?php
                                for ( $a = $start_day ; $a <= $day_of_month ; $a++ ){
                                    echo '<th class="column-title text-center"><div class="dataTable_width" style="margin: auto;">'.$a.'</div></th>' ;
                                }
                                ?>
    						</tr>
    					</thead>
    					<tbody>

    						<?php
                            if ( count($attendances) > 0 ){
                                foreach ( $attendances as $k_staff => $v_staff ){

                                    $date_group  = $v_staff['group'] ;
                                    $staff_id    = $v_staff['staff_id'] ;
                                    $staff_idno  = ucwords($v_staff['staff_idno']) ;
                                    $staff_tier  = $v_staff['staff_tier'] ;
                                    $departments = explode( ',', $v_staff['staff_department'] ) ;

                                    $check_permission         = false ;
                                    if ( $get_user_tier['check'] ){
                                        if ( in_array( $staff_tier, $get_user_tier['tiers'] ) ){
                                            $check_permission = true ;
                                        }
                                    }else{
                                        $check_permission     = true ;
                                    }

                                    echo '
                                    <tr staff_id="'.$v_staff['staff_id'].'">
                                        <td class="text-center">
                                            <div class="dataTable_width_image"><image src="'.$v_staff['staff_image'].'" /></div>
                                        </td>
                                        <td class="text-center" title="'.$v_staff['staff_idno'].'">
                                            <div class="dataTable_width_id">'.$staff_idno.' </div>
                                        </td>
                                        <td class="text-center">
                                            <div class="dataTable_width_name"><a href="hr-attendance.php?page_mode=reprocessing-list&date_time='.$date_time.'&staff_id='.$v_staff['staff_id'].'" target="_blank">'.ucwords($v_staff['staff_name']).'</div>
                                        </td>
                                        <td>'.implode( '<br />', $departments ).'</td>
                                        <td class="text-center">'.ucwords($v_staff['staff_positionname']).'</td>' ;
                                        for ( $a = $start_day ; $a <= $day_of_month ; $a++ ){
                                            
                                            $new_day       = $date_time.'-'.str_pad($a, 2, '0', STR_PAD_LEFT) ;
                                            $list_date     = $new_day ;
                                            $row_report    = $array_list[$v_staff['staff_id']][$list_date] ;
                                            $report_day    = 0 ;
                                            $report_min    = '00:00:00' ;
                                            $report_ot     = 0 ;
                                            $report_wt     = '' ;
                                            $report_remark = '' ;
                                            $report_health = ( $array_health[$staff_id][$list_date] != '' ? $array_health[$staff_id][$list_date] : '' ) ;
                                            if ( $row_report != undefined && arrayCheck($row_report) ){
                                                $report_day     = ( $row_report['list_work_day'] != '00:00:00' ? $row_report['list_work_day'] : 0 ) ;
                                                $report_ot      = ( $row_report['list_ot_day'] != '00:00:00' ? $row_report['list_ot_day'] : 0 ) ;
                                                $list_late      = ( $row_report['list_late'] != '00:00:00' ? $row_report['list_late'] : 0 ) ;
                                                $list_early_out = ( $row_report['list_early_out'] != '00:00:00' ? $row_report['list_early_out'] : 0 ) ;

                                                if ( $row_report['list_late'] != '00:00:00' ){
                                                    $report_min = commonAddTime($row_report['list_late'], '00:00:01') ;
                                                }
                                                if ( $row_report['list_early_out'] != '00:00:00' ){
                                                    $report_min = commonAddTime($row_report['list_early_out'], $report_min) ;
                                                }
                                                if ( $row_report['list_time_off'] != '00:00:00' && $row_report['list_time_off'] != '' ){
                                                    $report_min = commonAddTime($row_report['list_time_off'], $report_min) ;
                                                }

                                                // $report_min = ( $row_report['list_late'] != '00:00:00' ? $row_report['list_late'] : '00:00' ) ;
                                                $report_wt = ( $row_report['list_type_remark'] != '' ? $row_report['list_type_remark'] : '' ) ;
                                                $report_remark = ( $row_report['list_attendance_remark'] != '' ? $row_report['list_attendance_remark'] : '' ) ;
                                            }
                                            $report_min  = substr($report_min, 0, -3) ;

                                            $array_group = [] ;
                                            if ( !empty($date_group[$new_day]) ){
                                                $get_group   = $date_group[$new_day] ;
                                                foreach ( $get_group as $k_group => $v_group ){

                                                    $coordinates     = '' ;
                                                    if ( $v_group['latitude'] != '' && $v_group['longitude'] != '' ){
                                                        $coordinates = '<a target="_blank" href="https://maps.google.com/?q='.$v_group['latitude'].','.$v_group['longitude'].'" style="margin-left:5px;"><i class="fa fa-location-arrow"></i></a>' ;
                                                    }

                                                    $array_group[]   = ( $v_group['created_at'] != $v_group['updated_at'] ? '<span>*</span>' : '' ) . '<span '.( $v_group['abnormal'] == 'yes' ? 'class="red"' : '' ).' title="'.ucwords($v_group['record_from']).( $v_group['code'] != '' ? ' : ' . $v_group['code'] : '' ).'" >'.date('H:i:s', strtotime($v_group['created_at'])).'</span>' . $coordinates ;
                                                }
                                            }

                                            echo '
                                            <td class="text-center">
                                                <div class="dataTable_width2">
                                                    <table>
                                                        <tr>
                                                            <td>
                                                                <div class="dataTable_width_time">' ;
                                                                    if ( $boolean_edit && $new_day <= TODAYDAY ){
                                                                        if ( $check_permission ){
                                                                            echo '<a data-toggle="tooltip" title="Edit" data-staffid="'.$staff_id.'" data-check_group="'.$new_day.'" class="allinfodata attendance_format2_edit"><i class="fa fa-edit"></i></a><br />' ; 
                                                                        }
                                                                    }
                                                                    echo implode('<br />', $array_group) ;
                                                                    if(arrayCheck($array_group)){
                                                                        
                                                                    }else{
                                                                        echo '--:--:--:--';
                                                                    }
                                                                    echo '
                                                                </div>
                                                            </td>';
                                                            if (EXCELDETAIL == "YES"){ 
                                                                echo '
                                                                <td style="border-left: 1px solid #ddd; vertical-align: top;">
                                                                ';   
                                                                
                                                                    if ( $boolean_edit && $new_day <= TODAYDAY ){
                                                                        $list_id = $row_report['list_id'] ;
                                                                        echo '
                                                                        <form method="post" class="dataTable_form_edit">
                                                                            <div class="dataTable_form_edit_title">Work Day : </div>
                                                                            <input type="text" name="list_work_day" class="list_work_day" value="'.$report_day.'" /><br />
                                                                            <div class="dataTable_form_edit_title">OT Day : </div>
                                                                            <input type="text" name="list_ot_day" class="list_ot_day" value="'.$report_ot.'" /><br />

                                                                            <div class="dataTable_form_edit_title">Min : </div>
                                                                            <input type="text" name="list_min" class="list_min" value="'.$report_min.'" /><br />
                                                                            <div class="dataTable_form_edit_title">Working Type : </div>
                                                                            <select name="list_wt" class="list_wt">
                                                                                <option value="">-- CHOOSE --</option>
                                                                                <option value="WD" '.($report_wt == 'WD' ? 'selected' : '').'>WORK DAY</option>
                                                                                <option value="AL" '.($report_wt == 'AL' ? 'selected' : '').'>ANNUAL LEAVE</option>
                                                                                <option value="UL" '.($report_wt == 'UL' ? 'selected' : '').'>UNPAID LEAVE</option>
                                                                                <option value="MC" '.($report_wt == 'MC' ? 'selected' : '').'>SICK LEAVE</option>
                                                                                <option value="AS" '.($report_wt == 'AS' ? 'selected' : '').'>ABSENT</option>
                                                                                <option value="HL" '.($report_wt == 'HL' ? 'selected' : '').'>HOLIDAY LIST</option>
                                                                                <option value="OD" '.($report_wt == 'OD' ? 'selected' : '').'>OFF DAY</option>
                                                                                <option value="CL" '.($report_wt == 'CL' ? 'selected' : '').'>COMPANY LEAVE</option>
                                                                                <option value="SP" '.($report_wt == 'SP' ? 'selected' : '').'>SUSPEND LEAVE</option>
                                                                            </select><br />
                                                                            <div class="dataTable_form_edit_title">Remark : </div>
                                                                            <input type="text" class="list_remark" value="'.$report_remark.'" /><br />
                                                                          
                                                                           <input type="hidden" name="list_id" class="list_id" value="'.$list_id.'" />
                                                                            '.( $list_id != '' ? '<button type="submit"><i class="fa fa-pencil"></i></button>' : '' ).'
                                                                        </form>
                                                                            
                                                                        '.( arrayCheck($array_group) ? '
                                                                        <form method="post" class="dataTable_form_edit_health">
                                                                            <div class="dataTable_form_edit_title">Health : </div>
                                                                            <input type="text" class="list_health" class="list_health" value="'.$report_health.'" />
                                                                          
                                                                           <input type="hidden" name="list_staff_id" class="list_staff_id" value="'.$staff_id.'" />
                                                                           <input type="hidden" name="list_date" class="list_date" value="'.$list_date.'" />
                                                                            <button type="submit"><i class="fa fa-pencil"></i></button>
                                                                        </form>' : '' ) ;
                                                                    }else{
                                                                        echo '
                                                                        <div>
                                                                            
                                                                            W : '.$report_day.'<br />
                                                                            O : '.( $report_ot != 0 ? $report_ot : '-' ).'<br />
                                                                            Min : '.( $report_min != '00:00' ? numberFormat(convertMinutes($report_min))  : '-' ).'<br />'.'
                                                                            WT : ';
                                                                            switch ($report_wt) {
                                                                                case 'WD': echo 'WORK DAY'; break;
                                                                                case 'AL': echo 'ANNUAL LEAVE'; break;
                                                                                case 'UL': echo 'UNPAID LEAVE'; break;
                                                                                case 'MC': echo 'SICK LEAVE'; break;
                                                                                case 'AS': echo 'ABSENT'; break;
                                                                                case 'HL': echo 'HOLIDAY LIST'; break;
                                                                                case 'OD': echo 'OFF DAY'; break;
                                                                                case 'CL': echo 'COMPANY LEAVE'; break;                                   
                                                                                case 'SP': echo 'SUSPEND LEAVE'; break;
                                                                            }
                                                                            echo '<br/>
                                                                            RK : '.( $report_remark != '' ? $report_remark : '-' ).'<br />
                                                                            HL : '.$report_health.'
                                                                        </div>' ;
                                                                    }
                                                               

                                                            echo '
                                                            </td>';
                                                             }
                                                             echo '
                                                            
                                                        </tr>
                                                    </table>
                                                </div>
                                            </td>' ;
                                        }
                                        echo '
                                    </tr>' ;
                                }
                            }
                            ?>

    					</tbody>
    				</table>
                    <?= $page_pagination['page_pagination'] ?>

                </div>
        	</div>
    		
        </div>
    </div>

</div>





<script type="text/javascript">

    $('.allinfodata').live('click', function(){

        $('.modaldata').val('');
        $('.modal2title').empty();
        $('.modal2title').append('Update');
        var staffid     = $(this).data('staffid');
        var check_group = $(this).data('check_group');
        $('#modal_staff_id').val(staffid);
        $('#modal_check_group').val(check_group);

        // if ( confirm('Confirm update attendance?') ) {

            $.ajax({
                url : 'hr-attendance.php?page_mode=admend-format-2&staff_id='+staffid+'&check_group='+check_group,
                type: 'get',
                dataType: 'json',
                success:function(data) {

                    if ( data['result'] == 'success' ){

                        var content = '' ;

                        // loop all date time
                        $.each( data['data'], function(k, v) {

                            content += '<div class="form-group clearfix">' ;
                                content += '<label class="control-label col-md-2 col-sm-2 col-xs-12">Time ( '+(k+1)+' )</label>' ;
                                content += '<div class="col-md-10 col-sm-10 col-xs-12">' ;
                                    content += '<div class="form-group">' ;
                                        content += '<div class="col-md-4 col-sm-4 col-xs-4">' ;
                                             content += '<input type="hidden" class="form-control modaldata" name="attendance_id_'+k+'" value="'+v['id']+'" placeholder="<?= $lang['attendance'] ?> ID">' ;
                                            content += '<input type="hidden" class="form-control modaldata" name="attendance_date_'+k+'" value="'+v['date']+'" placeholder="<?= $lang['date'] ?>">' ;
                                            content += '<input type="time" class="form-control modaldata" name="attendance_time_'+k+'" value="'+v['time']+'" placeholder="<?= $lang['Time'] ?>">' ;
                                        content += '</div>' ;
                                        content += '<div class="col-md-8 col-sm-8 col-xs-8">' ;
                                            content += '<input type="text" class="form-control modaldata" style="padding: 8px; font-size: 13px;" name="attendance_remark_'+k+'" value="'+v['remark']+'" placeholder="<?= $lang['remark'] ?>">' ;
                                        content += '</div>' ;
                                    content += '</div>' ;
                                content += '</div>' ;                   
                            content += '</div>' ;

                        }) ;

                        // show_all_datetime
                        $(".show_all_datetime").html( content ) ;

                    }else{
                        alert("Failed to get attendance") ;
                        location.reload() ;
                    }

                }
            });
            $('#modal-2').modal('show');

        // }

    });

</script>

<div class="modal modal-default fade" id="modal-2">
    <div class="modal-dialog">
        <div class="modal-content">

            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title modal2title"></h4>
            </div>

            <form method="post" action="?<?= $search_url ?>"> 

                <input type="hidden" name="modal_staff_id" id="modal_staff_id" class="modaldata" />
                <input type="hidden" name="modal_check_group" id="modal_check_group" class="modaldata" />
                <div class="modal-body">
                    <div class="show_all_datetime clearfix"></div>
                </div>                  
                
                <div class="modal-footer">
                    <div class="form-group clearfix">
                        <div class="col-md-12 col-sm-12 col-xs-12">
                            <div class="form-group">
                                <div class="col-md-12 col-sm-12 col-xs-12">
                                    <button type="submit" class="btn btn-purple addbtn2"><i class="fa fa-check-circle"></i> <?= $lang['Save']?></button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            
            </form>

        </div>
    </div>
</div> 

<?php
// footer
include 'requires/page_footer.php' ;
?>