<?php 
include('../dbconnect.php');
if(isset($_POST['view'])){

    $empid = $_POST['empid'];

    if($_POST["view"] != ''){

        $update_query = "UPDATE notif SET status = 1 WHERE status='0' AND empid='$empid'";
        mysqli_query($conn, $update_query);
    }

    $query = "SELECT * FROM notif WHERE empid='$empid' ORDER BY id DESC LIMIT 5";
    $result = mysqli_query($conn, $query);
    $output = '';

    if(mysqli_num_rows($result) > 0)
    {
        while($row = mysqli_fetch_array($result)){

            $output .='<a class="dropdown-item" href="'.$row['dataid'].'">
            <strong>'.$row['title'].'</strong><br/>
            <small>'.$row['description'].'</small>
            <h6> <small>'.date('m/d/Y h:i A', strtotime($row['timestamp'])).'</small></h6> 

            </a>';

        }


    }else{

        $output .='<a class="dropdown-item" href="#">No Data Found</a>';
    }

    //get number of unseen notification

    $status_query = "SELECT * FROM notif WHERE status='0' AND empid='$empid'";
    $result_query = mysqli_query($conn, $status_query);
    $count = mysqli_num_rows($result_query);

    
    $data = array(
        'notification' => $output,
        'unseen_notification'  => $count
    );

    echo json_encode($data);




}
mysqli_close($conn);

?>