<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Fetch extends CI_Controller {

	function __construct() {
		parent::__construct();
		$this->load->model('My_model');
	}

	public function index()
	{
		if(!$username=$this->session->userdata('logged_in')) redirect(base_url().'login');
		$user_id = $this->session->userdata('user_id');

		if(isset($_POST["view"])){
			if($_POST["view"] != ''){
				$this->My_model->update('claim_alert',array('admin_id'=>$user_id),array('status'=>'1'));	
			}
			$get_alerts = $this->My_model->get_rows('claim_alert',array('admin_id'=>$user_id),'alert_id DESC','10');

			$output = '';

			if($get_alerts){
				foreach($get_alerts as $alert){
					$output .= '
					<li>
					<a href="#">
					<strong>'.$alert->message.'</strong><br />
					<small><em>'.$alert->alert_date.'</em></small>
					</a>
					</li>
					<li class="divider"></li>
					';
					// 	 <small><em>'.$row["comment_text"].'</em></small>
				}
			}else{
				$output .= '<li><a href="#" class="text-bold text-italic">No Notification Found</a></li>';
			}

			$get_unread = $this->My_model->get_rows('claim_alert',array('admin_id'=>$user_id,'status'=>'0'));

			if($get_unread) $count = sizeof($get_unread);
			else $count = 0;

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