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

$status                       = '300' ;
 
$qrocde                       = $array['qrcode'] ;
 
if ( $qrocde                 != '' ){
    $status                   = '303' ;

    if ( $staff_info['staff_settings']['checkvisitation'] == 'yes' ){
        $status               = '201' ;

        $select               = $mysqli->query( "SELECT * FROM visitor 
                                                WHERE deleted_at IS NULL AND visitor_id = '".$qrocde."' LIMIT 1" ) ;
        if ( $select->num_rows > 0 ){

            $status           = '200' ;

            $row_visitor      = $select->fetch_assoc() ;

            // get branch name
            $branch_name      = '' ;
            $mysqli_query     = "SELECT branch_id, branch_name FROM branch
                                 WHERE branch_id = '".$row_visitor['branch']."' LIMIT 1" ;
            $mysqli_branch    = $mysqli->query($mysqli_query) ;
            if ( $mysqli_branch->num_rows > 0 ){
                $row_branch   = $mysqli_branch->fetch_assoc() ;
                $branch_name  = $row_branch['branch_name'] ;
            }

            $is_showbutton    = 'no' ;
            $visited_at       = date( 'Y-m-d', strtotime( $row_visitor['visited_at'] ) ) ;
            $visited_at_to    = date( 'Y-m-d', strtotime( $row_visitor['visited_at_to'] ) ) ;
            if ( $visited_at <= TODAYDAY && $visited_at_to >= TODAYDAY ){
                $is_showbutton = 'yes' ;
            }

            $data = [
                'visitor_id'          => dataFilter( $row_visitor['visitor_id'] ),
                'appointment_date'    => date( 'Y-m-d H:iA', strtotime( $row_visitor['visited_at'] ) ) . ' ~ ' . date( 'Y-m-d H:iA', strtotime( $row_visitor['visited_at_to'] ) ),
                'branch_name'         => dataFilter( $branch_name ),
                'visitor_category'    => ucwords( dataFilter( $row_visitor['category'] ) ),
                'visitor_name'        => dataFilter( $row_visitor['name'] ),
                'contact_number'      => dataFilter( $row_visitor['mobile'] ),
                'email'               => dataFilter( $row_visitor['email'] ),
                'nric_passport'       => dataFilter( $row_visitor['identity'] ),
                'nationality'         => dataFilter( $row_visitor['nationality'] ),
                'visitor_company'     => ucwords( dataFilter( $row_visitor['visitor_company'] ) ),
                'car_plate'           => dataFilter( $row_visitor['car_plate'] ),
                'reason_to_visit'     => dataFilter( $row_visitor['reason'] ),
                'contact_person'      => dataFilter( $row_visitor['contact_person'] ),
                'status'              => dataFilter( $row_visitor['status'] ),
                'is_showbutton'       => $is_showbutton
            ] ;

        }

    }
    
}

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