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

if ( $boolean_login ){

    $status                = '303' ;

    if ( $staff_info['staff_settings']['checkrecruitment'] == 'yes' ){

        $status            = '201' ;


        // position
        $positions         = [] ;
        $mysqli_position = $mysqli->query( "SELECT a.job_position_id, b.job_position_desc FROM setting_job_position a
                                             LEFT JOIN setting_job_position_translation b ON ( a.job_position_id = b.job_position_id )
                                             WHERE a.deleted_at IS NULL AND b.lang = '".$array['lang']."'" ) ;
        if ( $mysqli_position->num_rows > 0 ){
            while( $row_position = $mysqli_position->fetch_assoc() ){
                $positions[$row_position['job_position_id']] = $row_position['job_position_desc'] ;
            }
        }



        $search_query      = '' ;
        if ( $array['search'] != '' ){
            $search_query .= " AND ( employment_name LIKE '%".$array['search']."%' OR employment_nric LIKE '%".$array['search']."%' OR employment_mobile LIKE '%".$array['search']."%' OR employment_email LIKE '%".$array['search']."%' )" ;
        }
        
        $searchstatus      = 'Processing' ;
        if ( $array['searchstatus'] != '' ){
            switch ( $array['searchstatus'] ){
                case 'pending'     :
                    $searchstatus  = 'Processing' ;
                break ;
                case 'shortlisted' :
                    $searchstatus  = 'Processing Confirmed' ;
                break ;
                case 'rejected'    :
                    $searchstatus  = 'Processing Rejected' ;
                break ;
            }
        }
        if ( $searchstatus != '' ){
            $search_query .= " AND employment_status = '".$searchstatus."'" ;
        }

        $query             = "SELECT employment_id, employment_name, employment_nric, employment_mobile, employment_email, employment_sex, employment_position, employment_resume, employment_status, employment_date FROM staff_employment
                              WHERE employment_trash = '0' AND employment_branch = '".$array['branch_id']."' AND employment_incharge_staff_id = '".$staff_info['staff_id']."' " . $search_query ;
        $mysqli_query      = $mysqli->query( $query . " ORDER BY employment_modified DESC LIMIT " . getLimit( $current ) ) ;

        if ( $mysqli_query->num_rows > 0 ){

            $status        = '200' ;

            



            $list          = [] ;
            while ( $row   = $mysqli_query->fetch_assoc() ){
                $row['employment_id']       = dataFilter( $row['employment_id'] ) ;
                $row['employment_name']     = dataFilter( $row['employment_name'] ) ;
                $row['employment_nric']     = dataFilter( $row['employment_nric'] ) ;
                $row['employment_mobile']   = dataFilter( $row['employment_mobile'] ) ;
                $row['employment_email']    = dataFilter( $row['employment_email'] ) ;
                $row['employment_sex']      = dataFilter( $row['employment_sex'] ) ;
                $row['employment_date']     = resetDateFormat( $row['employment_date'] ) ;
                $row['employment_position'] = $positions[$row['employment_position']] ;
                $row['employment_resume']   = ( $row['employment_resume'] != '' ? PATH.'/uploads/Employment_Resume/'.$row['employment_resume'] : '' ) ;
                $list[]    = $row ;
            }

            $data['list']  = $list ;

        }

    }
}

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