<?php
$must_login                    = true ;
$require_path                  = '../../../' ;
$require_sub                   = '../../' ;
require( $require_sub.'header.php' ) ;

if ( $boolean_login ){

    $status                    = '303' ;

    if ( $staff_info['staff_settings']['ishrmanager'] == 'yes' ){
        $status                = '300' ;

        if ( $array['update_status'] != '' && $array['comment_hr'] != '' ){
            $status            = '201' ;

            $query             = "SELECT formresignation_id, formresignation_so, staff_id, title, content, staff_id_manager, comment_manager, comment_hr, status_manager, staff_id_hr, status_hr, created_at, updated_at FROM formresignation
                                  WHERE deleted_at IS NULL AND branch_id = '".$array['branch_id']."' AND formresignation_id = '".$array['formresignation_id']."' AND status_manager = 'confirmed' AND status_hr = 'pending'" ;
            $mysqli_query      = $mysqli->query( $query . " LIMIT 1" ) ;

            if ( $mysqli_query->num_rows > 0 ){

                $row           = $mysqli_query->fetch_assoc() ;

                $status        = '308' ;

                $update_status = ( $array['update_status'] == 'confirmed' ? 'confirmed' : 'rejected' ) ;

                if ( $update_status != '' ){
                    $status    = '200' ;

                    $mysqli->query( "UPDATE formresignation SET
                                     staff_id_hr              = '".$staff_info['staff_id']."',
                                     status_hr                = '".$update_status."',
                                     comment_hr               = '".$array['comment_hr']."',
                                     date_hr                  = '".TODAYDATE."'
                                     WHERE formresignation_id = '".$array['formresignation_id']."'" ) ;

                    if ( $update_status == 'confirmed' ){
                        pushToUserCron( 'formresignation', $array['formresignation_id'], $row['staff_id'], 'Resignation', 'Resignation is confirmed by your HR Manager' ) ;
                    }else{
                        pushToUserCron( 'formresignation', $array['formresignation_id'], $row['staff_id'], 'Resignation', 'Resignation is rejected by your HR Manager' ) ;
                    }

                }

            }
        }
    }
}

require( $require_sub.'footer.php' ) ;
?>