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

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

	$search_query         = '' ;
	if ( $array['search']!= '' ){
        $search_query    .= " AND b.title LIKE '%".$array['search']."%'" ;
    }
    if ( $array['searchstatus'] != '' ){
        $get_status       = '' ;
        switch ( $array['searchstatus'] ){
            case 'unread' :
                $get_status = '0' ;
            break ;
            case 'read'   :
                $get_status = '1' ;
            break ;
        }
        $search_query    .= " AND a.is_read = '".$get_status."'" ;
    }

    $query                = "SELECT a.view_id, a.inbox_id, a.is_read, b.title, b.description, b.created_at FROM staff_inbox_view a
                             LEFT JOIN inbox b ON ( a.inbox_id = b.inbox_id ) 
                             WHERE a.deleted_at IS NULL AND b.deleted_at IS NULL AND a.staff_id = '".$staff_info['staff_id']."' " . $search_query ;
    $mysqli_query         = $mysqli->query( $query . " ORDER BY b.created_at DESC LIMIT " . getLimit( $current ) ) ;

    if ( $mysqli_query->num_rows > 0 ){

        $status           = '200' ;

        $list             = [] ;
        while ( $row      = $mysqli_query->fetch_assoc() ){
            $row['title']       = dataFilter( $row['title'] ) ;
            $row['description'] = dataFilter( $row['description'] ) ;
            $row['created_at']  = resetDateFormat( $row['created_at'] ) ;
            $list[]             = $row ;
        }

        $data['list']     = $list ;

    }


    // total inbox
    $mysqli_query         = $mysqli->query( "SELECT COUNT( a.view_id ) as total FROM staff_inbox_view a
                                             WHERE a.deleted_at IS NULL AND a.staff_id = '".$staff_info['staff_id']."' AND a.is_read = '0'" ) ;

    if ( $mysqli_query->num_rows > 0 ){
        $row              = $mysqli_query->fetch_assoc() ;
        $count_inbox      = $row['total'] ;
    }
    $data['count_inbox']  = $count_inbox ;


    // mark notification as 0
    $mysqli->query( "UPDATE staff_notification SET badge = '0' WHERE staff_id = '".$staff_info['staff_id']."'" ) ;
}

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