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

if ( $boolean_login ){
    $status            = '201' ;

    $search_query      = '' ;
    $search_query     .= " AND a.redeem_id = '".$array['id']."'" ;
    $join_filter      .= ", b.status as redeem_status, b.remark as redeem_remark" ;
    $join_query       .= " LEFT JOIN staff_redeem b ON ( a.redeem_id = b.redeem_id )" ;
    $search_query     .= " AND b.view_id = '".$array['view_id']."' AND b.staff_id = '".$staff_info['staff_id']."'" ;

    $query             = "SELECT a.redeem_id, a.redeem_type, a.date_start, a.date_end, a.point, a.title, a.content, a.file, a.status, a.created_at ".$join_filter." FROM redeem a
                          ".$join_query."
                          WHERE a.deleted_at IS NULL " . $search_query ;
    $mysqli_query      = $mysqli->query( $query ) ;

    if ( $mysqli_query->num_rows > 0 ){
        $status        = '299' ;

        $row           = $mysqli_query->fetch_assoc() ; 

        if ( $row['redeem_status'] == 'awaiting-collection' ){

            $status    = '200' ;

            $mysqli->query( "UPDATE staff_redeem SET
                             status        = 'confirmed'
                             WHERE view_id = '".$array['view_id']."'" ) ;

        }
    }
}

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