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

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

    if ( $array['is_tick']    == 'yes' ){
    	$status   		       = '201' ;

    	$search_query          = '' ;
        $search_query         .= " AND announcement_id = '".$array['id']."'" ;

        $query                 = "SELECT announcement_id FROM announcement
                                  WHERE deleted_at IS NULL " . $search_query ;
        $mysqli_query          = $mysqli->query( $query ) ;

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

            $mysqli->query( "INSERT INTO staff_announcement
                             ( announcement_id, staff_id ) VALUES
                             ( '".$array['id']."', '".$staff_info['staff_id']."' ) " ) ;

            // update inbox as read
            $select_inbox      = $mysqli->query( "SELECT a.view_id FROM staff_inbox_view a
                                                  LEFT JOIN inbox b ON ( a.inbox_id = b.inbox_id ) 
                                                  WHERE a.deleted_at IS NULL AND a.staff_id = '".$staff_info['staff_id']."' AND a.is_read = '0' AND b.deleted_at IS NULL AND b.from_table = 'announcement' AND b.from_id = '".$array['id']."'" ) ;
            if ( $select_inbox->num_rows > 0 ){
                while ( $row_inbox = $select_inbox->fetch_assoc() ){
                    $mysqli->query( "UPDATE staff_inbox_view SET
                                     is_read        = '1' 
                                     WHERE view_id  = '".$row_inbox['view_id']."'" ) ;
                }
            }

        }
    }
}

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