<?php

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

// include the class
include 'requires/class_resize.php';

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

$active_main_menu  = 'setting' ;
$active_sub_menu   = 'setting-hr' ;
$active_menu       = 'setting-hr-working' ;

$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'];
    }
}

$working_group     = [];
$get_working_group = $mysqli->query("SELECT * FROM setting_working_group
								    		 WHERE deleted_at IS NULL");
if ($get_working_group->num_rows > 0) {
    while ($row_working_group = $get_working_group->fetch_assoc()) {
        $working_group[$row_working_group['group_id']] = $row_working_group['group_name'];
    }
}

switch ( $page_mode ) {
    case 'user' :
        if ( isset($_POST['submit']) && $_POST['submit'] == '1' && count($_POST['staffs']) > 0 && $_POST['timetable'] != '' ) {
            $staff_list = [];

            $check_group = $mysqli->query("SELECT * FROM staff
                                              WHERE deleted_at IS NULL AND staff_id IN (".implode("," , $_POST['staffs']).") ") ;


            if ( $check_group->num_rows > 0 ){
                while (  $row = $check_group->fetch_array(MYSQLI_ASSOC) ) {
                    if ( $row['group_id'] != $_POST['timetable'] ){
                        $old_staff_group[$row['staff_id']][0] = true;
                        $old_staff_group[$row['staff_id']][1] = [
                            "old" => $row['group_id'],
                            "new" => $_POST['group_id'],
                        ];
                    }
                }
            }
            
            foreach ( $_POST['staffs'] as $staff ) {
                $mysqli->query("UPDATE staff SET 
                                group_id = '".escapeString($_POST['timetable'])."'
                                WHERE staff_id = '".$staff."'");

                if ( $old_staff_group[$staff][0] && $old_staff_group[$staff][0] != '' ){
                    // log here
                }
            }
            

            header("Refresh: 0") ;
            exit ;
        }
    break ;
    case 'dep':
        if ( isset($_POST['submit']) && $_POST['submit'] == '1' && $_POST['department'] != '' && $_POST['timetable'] != '' ) {
            $department_list = [];
            $staff_list      = [];
            $departments = $mysqli->query("SELECT * FROM staff_department 
                                           WHERE deleted_at IS NULL AND department_id = '".escapeString($_POST['department'])."'") ;
            if ( $departments->num_rows > 0 ){
                while( $department = $departments->fetch_assoc() ) {
                    $department_list[] = $department;     
                    $staff_list[$department['staff_id']] = $department['staff_id'];       
                }
            }

            $check_group = $mysqli->query("SELECT * FROM staff
                                              WHERE deleted_at IS NULL AND staff_id IN (".implode("," , $staff_list).") ") ;

            if ( $check_group->num_rows > 0 ){
                while (  $row = $check_group->fetch_array(MYSQLI_ASSOC) ) {
                    if ( $row['group_id'] != $_POST['timetable'] ){
                        $old_staff_group[$row['staff_id']][0] = true;
                        $old_staff_group[$row['staff_id']][1] = [
                            "old" => $row['group_id'],
                            "new" => $_POST['group_id'],
                        ];
                    }
                }
            }       

            foreach ($department_list as $k => $v) {
                 $mysqli->query("UPDATE staff SET 
                                    group_id       = '".escapeString($_POST['timetable'])."'
                                    WHERE staff_id = '".escapeString($v['staff_id'])."'");
                 if ( $old_staff_group[$staff][0] && $old_staff_group[$staff][0] != '' ){
                    // log here
                }
            }
            header("Refresh: 0") ;
            exit ;
        }
    break ;
    case 'schedule' :
        if ( isset($_POST['submit']) && $_POST['submit'] == '1' && $_POST['staffs'] != '' && $_POST['timetable'] != '' ) {

            $staffs    = $_POST['staffs'] ;
            $timetable = escapeString($_POST['timetable']) ;
            $date_from = escapeString($_POST['date_from']) ;
            $date_to   = escapeString($_POST['date_to']) ;
            $date_to   = ( $date_to >= $date_from ? $date_to : $date_from ) ;
            $date_to   = date( 'Y-m-d', strtotime($date_to . ' + 1 day') ) ;

            $period    = new DatePeriod(
                 new DateTime($date_from),
                 new DateInterval('P1D'),
                 new DateTime($date_to)
            ) ;

            // get setting working
            $get_workings = $mysqli->query("SELECT working_day, group_id, working_on, working_next_day, working_if_flexi, working_if_include_rest, working_if_ot, working_direct_day, working_if_fixed_work, working_day_calculation, working_morning_start as working_period_from, working_morning_end as working_period_to, working_period_before, working_break_start as working_from, working_break_end as working_to, working_break_end_include_ot as working_to_include_ot, working_total_hours, working_total_rest_hours, working_rest_range_from, working_rest_range_to, working_rounding_ot, working_if_ot_morning, working_if_offduty, working_count_offduty, working_if_deduct_offduty, working_max_ot,working_total_rest_hours2,working_rest_range_from2,working_rest_range_to2 FROM setting_working
                                           WHERE deleted_at IS NULL AND group_id = '".$timetable."'") ;

            if ( $get_workings->num_rows > 0 ){

                $array_working   = [] ;
                while ( $get_working = $get_workings->fetch_assoc() ){
                    $array_working[$get_working['working_day']] = $get_working ;
                }

                foreach ( $staffs as $staff_id ){
                    foreach ( $period as $key => $value ) { 

                        $get_date = $value->format('Y-m-d') ;
                        $working  = $array_working[ date('N', strtotime($get_date)) ] ;

                        $mysqli->query( "UPDATE staff_attendance_working SET deleted_at = '".TODAYDATE."' 
                                         WHERE deleted_at IS NULL AND staff_id = '".$staff_id."' AND working_date = '".$get_date."'" ) ;

                        $mysqli->query("INSERT INTO staff_attendance_working
                                        (staff_id, working_group_id, working_date, working_on, working_next_day, working_if_flexi, working_if_include_rest, working_if_ot, working_direct_day, working_if_fixed_work, working_day_calculation, working_period_from, working_period_to, working_period_before, working_from, working_to, working_to_include_ot, working_total_hours, working_total_rest_hours, working_rest_range_from, working_rest_range_to, working_rounding_ot, working_if_ot_morning, working_if_offduty, working_count_offduty, working_if_deduct_offduty, working_max_ot, created_at, updated_at,working_total_rest_hours2,working_rest_range_from2,working_rest_range_to2) VALUES
                                        ('".$staff_id."', '".$working['group_id']."', '".$get_date."', '".$working['working_on']."', '".$working['working_next_day']."', '".$working['working_if_flexi']."', '".$working['working_if_include_rest']."', '".$working['working_if_ot']."', '".$working['working_direct_day']."', '".$working['working_if_fixed_work']."', '".$working['working_day_calculation']."', '".$working['working_period_from']."', '".$working['working_period_to']."', '".$working['working_period_before']."', '".$working['working_from']."', '".$working['working_to']."', '".$working['working_to_include_ot']."', '".$working['working_total_hours']."', '".$working['working_total_rest_hours']."', ".( $working['working_rest_range_from'] != '' ? "'".$working['working_rest_range_from']."'" : "NULL" ).", ".( $working['working_rest_range_to'] != '' ? "'".$working['working_rest_range_to']."'" : "NULL" ).", '".$working['working_rounding_ot']."', '".$working['working_if_ot_morning']."', '".$working['working_if_offduty']."', '".$working['working_count_offduty']."', '".$working['working_if_deduct_offduty']."', '".$working['working_max_ot']."', '".TODAYDATE."', '".TODAYDATE."','".$working['working_total_rest_hours2']."','".$working['working_rest_range_from2']."','".$working['working_rest_range_to2']."')") ;
                        

                    }
                }

            }

            header("Refresh: 0") ;
            exit ;
        }
    break ; 
}

include 'requires/page_header.php';
include 'requires/page_top.php';

switch ( $page_mode ) {

    case 'user' :
        ?>

        <!-- Header Ends -->
        <div class="warper container-fluid">
        <div class='container' style="background-color: white; border-radius: 10px;">
            <div class="page-header" style="margin: 30px 0px 0px 0px;padding: 0px;">
                <h1>Timetable <small>By User</small></h1>
            </div>

            <div class="panel panel-default" id="basic-table-title">
                <div class="panel-heading"></div>
                <div class="panel-body">
                    <form method="post" class="form-horizontal" >
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Staff</label>
                            <div class="col-sm-9" id='selectall'>
                                <select name="staffs[]" id="reprocessing_staff_id" class="chosen-select2 form-control tab_index ui-dropdown-select ui-search-input select2-basic-single" multiple required>
                                    <?php
                                    $mysqli_staff = $mysqli->query("SELECT staff_id, staff_name, staff_idno FROM staff
                                                                    WHERE deleted_at IS NULL AND ( staff_date_resigned IS NULL OR staff_date_resigned = '0000-00-00' ) ORDER BY (staff_idno+1) ASC") ;
                                    if ( $mysqli_staff->num_rows > 0 ){
                                        while ( $staff = $mysqli_staff->fetch_assoc() ){

                                            // default variable
                                            $id         = $staff['staff_id'] ;
                                            $staff_idno = ucwords($staff['staff_idno']) ;

                                            echo '<option value="'.$id.'">'.dataFilter($staff['staff_name']).' ('.$staff_idno.')'.'</option>' ;

                                        }
                                    }
                                    ?>
                                </select>
                                <button type="button" style="color:white;background-color: #5e5bd0;" class="chosen-toggle select btn btn-purple margin_top_7px">Select all</button>
                                <button type="button" style="color:white;background-color: #5e5bd0;" class="chosen-toggle deselect btn btn-purple margin_top_7px">Deselect all</button>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Timetable</label>
                            <div class="col-sm-9" id='selectall'>
                                <select name="timetable" id="reprocessing_staff_id" class="chosen-select2 form-control tab_index ui-dropdown-select ui-search-input select2-basic-single" required>
                                    <option value="">Select</option>
                                    <?php 
                                    foreach ($working_group as $k => $v) {
                                        echo '<option value="'.$k.'" '.( $row_page['group_id'] == $k ? 'selected' : '') .'>'.$v.'</option>' ;
                                    } 
                                    ?>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-11">
                                <input type="hidden" name="submit" value="1" />
                                <button type="submit" class="btn" style="color:white;background-color: #5e5bd0;float:right; margin-top: 5px;width: 100px;">Submit</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>

    <?php
    break;

    case 'dep':
        ?>
        <!-- Header Ends -->
        <div class="warper container-fluid">
        <div class='container' style="background-color: white; border-radius: 10px;">
            <div class="page-header" style="margin: 30px 0px 0px 0px;padding: 0px;">
                <h1>Timetable <small>By Department</small></h1>
            </div>
            <div class="panel panel-default" id="basic-table-title">
                <div class="panel-heading"></div>
                <div class="panel-body">
                    <form method="post" class="form-horizontal" >
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Department</label>
                            <div class="col-sm-9" id='selectall'>
                                <select name="department" id="reprocessing_staff_id" class="chosen-select2 form-control tab_index ui-dropdown-select ui-search-input select2-basic-single" required>
                                    <option value="">Select</option>
                                    <?php foreach ($department as $k => $v) { ?>
                                        <option value="<?php echo $k; ?>"><?php echo $v; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Timetable</label>
                            <div class="col-sm-9" id='selectall'>
                                <select name="timetable" id="reprocessing_staff_id" class="chosen-select2 form-control tab_index ui-dropdown-select ui-search-input select2-basic-single" required>
                                    <option value="">Select</option>
                                    <?php foreach ($working_group as $k => $v) { ?>
                                    <option value="<?= $k ?>" <?= ($row_page['group_id'] == $k ? 'selected' : '') ?>><?= $v ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-11">
                                <input type="hidden" name="submit" value="1" />
                                <button type="submit" class="btn" style="color:white;background-color: #5e5bd0;float:right; margin-top: 5px;width: 100px;">Submit</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        </div>
    <?php

    break ;

    case 'schedule' :

        // default parameter
        $search       = escapeString($_GET['search']) ;
        $search_name  = escapeString($_GET['search_name']) ;
        $search_idno  = escapeString($_GET['search_idno']) ;
        $search       = escapeString($_GET['search']) ;
        $lf_type      = escapeString($_GET['lf_type']) ;
        $lf_branch    = escapeString($_GET['lf_branch']) ;
        $sort_by      = escapeString($_GET['sort_by']) ;
        $sort_by      = ( $sort_by != '' ? $sort_by : 'staff_idno' ) ;
        $sort_by_type = escapeString($_GET['sort_by_type']) ;
        $sort_by_type = ( $sort_by_type != '' ? $sort_by_type : 'asc' ) ;
        $export       = escapeString($_GET['export']) ;

        $date_time    = escapeString($_GET['date_time']) ;
        $date_time    = ( $date_time != '' ? $date_time : date('Y-m', time()) ) ;
        $day_of_month = date("t", strtotime($date_time)) ;

        // query type
        $search_query = '' ;

        // add permission
        // if ( $_SESSION['system_permission'] != 'admin' ){
        //     if ( permissionCheck($row_user, 'local-only') && permissionCheck($row_user, 'foreign-only') ){
        //         // do nothing
        //     }elseif ( permissionCheck($row_user, 'local-only') ){
        //         $search_query .= " AND country_id  = '1'" ;
        //     }else{
        //         $search_query .= " AND country_id != '1'" ;
        //     }
        // }
        // search query
        if( $search != ''){
            $search_query .= " AND (staff_idno LIKE '%".$search."%' || staff_name LIKE '%".$search."%')" ;
        }
        if( $search_name != ''){
            $search_query .= " AND staff_name LIKE '%".$search_name."%'" ;
        }
        if( $search_idno != ''){
            $search_query .= " AND staff_idno LIKE '%".$search_idno."%'" ;
        }
        
        // pagination
        if (isset($page) && !empty($page)) { $product_page = $page ; } else { $product_page = 1 ; } // next and prev page (5 thing need to change)
        $start_from = ($product_page - 1) * LIMIT ; //end next and prev page
        
        // set search url
        $search_url = 'page_mode='.$page_mode.'&search_name='.$search_name.'&search_idno='.$search_idno.'&date_time='.$date_time.'&sort_by='.$sort_by.'&sort_by_type='.$sort_by_type ;

        // page query
        $mysqli_query = "SELECT staff_id, staff_name, staff_idno, group_id FROM staff
                         WHERE deleted_at IS NULL " . $search_query ;
        $mysqli_page = $mysqli->query($mysqli_query." ORDER BY (".$sort_by.' * 1) '.$sort_by_type.", ".$sort_by." ".$sort_by_type." LIMIT $start_from, " . LIMIT) ;

        // load pagination
        $page_pagination = nextPrevious($product_page, LIMIT, $search_url, $mysqli_query) ;

        // get all related staff
        $related_staffs  = [] ;
        $related_staffid = [] ;
        if( $mysqli_page->num_rows > 0 ){
            while ( $row_page = $mysqli_page->fetch_array(MYSQLI_ASSOC) ){
                $related_staffs[]  = $row_page ;
                $related_staffid[] = $row_page['staff_id'] ;
            }
        }

        // all selected staff working hours
        $group_working = [] ;
        $get_workings  = $mysqli->query( "SELECT staff_id, working_date, working_group_id FROM staff_attendance_working
                                          WHERE deleted_at IS NULL AND working_date LIKE '%".$date_time."%' AND staff_id IN (".implode(',', $related_staffid).")" ) ;
        if( $get_workings->num_rows > 0 ){
            while ( $get_working = $get_workings->fetch_array(MYSQLI_ASSOC) ){
                $group_working[$get_working['staff_id']][$get_working['working_date']] = $get_working['working_group_id'] ;
            }
        }
        ?>

        <!-- Header Ends -->
        <div class="warper container-fluid">
        <div class='container' style="background-color: white; border-radius: 10px;">
            <div class="page-header" style="margin: 30px 0px 0px 0px;padding: 0px;">
                <h1>Timetable <small>By Schedule</small></h1>
            </div>

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

                    <form method="post" class="form-horizontal" >
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Staff</label>
                            <div class="col-sm-9" id='selectall'>
                                <select name="staffs[]" id="reprocessing_staff_id" class="chosen-select2 form-control tab_index ui-dropdown-select ui-search-input select2-basic-single" multiple required>
                                    <?php
                                    $mysqli_staff = $mysqli->query("SELECT staff_id, staff_name, staff_idno FROM staff
                                                                    WHERE deleted_at IS NULL AND ( staff_date_resigned IS NULL OR staff_date_resigned = '0000-00-00' ) ORDER BY (staff_idno+1) ASC") ;
                                    if ( $mysqli_staff->num_rows > 0 ){
                                        while ( $staff = $mysqli_staff->fetch_assoc() ){

                                            // default variable
                                            $id         = $staff['staff_id'] ;
                                            $staff_idno = ucwords($staff['staff_idno']) ;

                                            echo '<option value="'.$id.'">'.dataFilter($staff['staff_name']).' ('.$staff_idno.')'.'</option>' ;

                                        }
                                    }
                                    ?>
                                </select>
                                <button type="button" style="color:white;background-color: #5e5bd0;" class="chosen-toggle select btn btn-purple margin_top_7px">Select all</button>
                                <button type="button" style="color:white;background-color: #5e5bd0;" class="chosen-toggle deselect btn btn-purple margin_top_7px">Deselect all</button>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Timetable</label>
                            <div class="col-sm-9" id='selectall'>
                                <select name="timetable" id="reprocessing_staff_id" class="chosen-select2 form-control tab_index ui-dropdown-select ui-search-input select2-basic-single" required>
                                    <option value="">Select</option>
                                    <?php 
                                    foreach ($working_group as $k => $v) {
                                        echo '<option value="'.$k.'" '.( $row_page['group_id'] == $k ? 'selected' : '') .'>'.$v.'</option>' ;
                                    } 
                                    ?>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?= $lang['Date From']?></label>
                            <div class="col-sm-9">
                                <input type="text" name="date_from" class="form-control tab_index datepicker" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?= $lang['Date To']?></label>
                            <div class="col-sm-9">
                                <input type="text" name="date_to" class="form-control tab_index datepicker" />
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-11">
                                <input type="hidden" name="submit" value="1" />
                                <button type="submit" class="btn" style="color:white;background-color: #5e5bd0;float:right; margin-top: 5px;width: 100px;">Submit</button>
                            </div>
                        </div>
                    </form>

                </div>
            </div>





            <div class="panel panel-default">
                <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 style="color:white;background-color: #5e5bd0;" href="?<?= $search_url ?>&date_time=<?= date('Y-m', strtotime($date_time.' -1 month')) ?>" class="btn btn-purple width_auto"><?= $lang['Prev Month']?></a>
                                <span style="margin-left:10px; margin-right:10px;"><?= $date_time ?></span>
                                <a style="color:white;background-color: #5e5bd0;" href="?<?= $search_url ?>&date_time=<?= date('Y-m', strtotime($date_time.' +1 month')) ?>" class="btn btn-purple width_auto"><?= $lang['Next Month']?></a>
                            </div>

                        </div>
                    </div>

                    <hr />

                    <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">
                            <div class="col-sm-11">
                                <input type="hidden" name="page_mode" value="<?= $page_mode ?>" />
                                <input type="hidden" name="search" value="<?= $search ?>" />
                                <input type="hidden" name="sort_by" value="<?= $sort_by ?>" />
                                <input type="hidden" name="sort_by_type" value="<?= $sort_by_type ?>" />
                                <input type="hidden" name="date_time" value="<?= $date_time ?>" />
                                <button type="submit" class="btn" style="color:white;background-color: #5e5bd0;float:right; margin-top: 5px;width: 100px;"><?= $lang['submit'] ?></button>
                            </div>
                        </div>
                    </form>
                    
                    <table class="ui-table table table-striped jambo_table bulk_action table-bordered stripe row-border order-column" id="basic-datatable-column">
                        <thead>
                            <tr>
                                <th><?= $lang['Action'] ?></th>
                                <th><div class="custom_dropdown_title">ID</div></th>
                                <th><div class="custom_dropdown_title"><?= $lang['Name'] ?></div></th>

                                <?php
                                for ( $a = 1 ; $a <= $day_of_month ; $a++ ){
                                    echo '<th class="column-title text-center">'.$a.'</th>' ;
                                }
                                ?>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            if( arrayCheck($related_staffs) ){
                                foreach ( $related_staffs as $kk => $row_page ){

                                    $id         = $row_page['staff_id'] ;
                                    $staff_idno = ucwords($row_page['staff_idno']) ;
    
                                    echo '
                                     <tr class="odd gradeX '.$last_4_class.'">
                                        <td class="align_center">
                                            <a title="'.$lang['Edit Current'].$lang['Staff'].'" href="hr-staff.php?page_mode=edit&page='.$id.'"><i class="fa fa-edit"></i></a>
                                            <span class="order_print_span">|</span>
                                            <a title="'.$lang['Check staff leave'].'" href="hr-staff-leave.php?staff_id='.$id.'" target="_blank"><i class="fa fa-sign-out" aria-hidden="true"></i></a>
                                        </td>
                                        <td class="align_center">'.$staff_idno.'</td>
                                        <td>'.dataFilter($row_page['staff_name']).'</td>' ;

                                        for ( $a = 1 ; $a <= $day_of_month ; $a++ ){
                                            
                                            $new_day  = $date_time.'-'.str_pad($a, 2, '0', STR_PAD_LEFT) ;
                                            $group_id = $group_working[$id][$new_day] ;

                                            echo '<td class="text-center">'.$working_group[$group_id].'</td>' ;
                                        }

                                    echo '
                                    </tr>' ;
                                }
                            }
                            ?>
                        </tbody>
                    </table>
                    <?= $page_pagination['page_pagination'] ?>
                </div>
            </div>
        </div>
        </div>

    <?php
    break;
}

?>

<script type="text/javascript">
$(document).ready(function(){
    // Select All Rules Product
    $('.chosen-toggle').each(function(index) {
        $(this).on('click', function(){
            $(this).parent().find('option').prop('selected', $(this).hasClass('select')).parent().trigger("change");
        });
    });
});
</script>

<?php

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