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

class Announcement_Model extends CI_Model {


	public function fetch_data()
	{
	 
	 	$this->db->select('announcement.*,mst_office.name as o_name');
	 	$this->db->where('announcement.deleted_DT',NULL);
		$this->db->from('announcement');
		$this->db->join('mst_office','mst_office.id=announcement.a_office','left');
		$this->db->order_by("announcement.a_id","desc");
		return $query=$this->db->get()->result();

	}

	public function display_recordsById($id)
	{
		//$query=$this->db->query("select a_id,office_name,guard_name from tr_assign_duty where a_id='".$id."'");
		$query=$this->db->query("select * from announcement where a_id='".$id."'");

		return $query->result();
	}

	public function update($id)
	{
						$data=array(
						    "type"=>$_POST['type'],
						"a_office"=>$_POST['office_name'],
					   "a_title"=>$_POST['title'],
					   "a_desc"=>$_POST['description'],
					   "modify_SI"=>$this->session->userdata('id'),
                   	 "modify_BY"=>$this->session->userdata('username'),
                    "modify_DT"=>date('Y-m-d H:i:s'));
       				 $c=$this->db->where('a_id',$id)->update('announcement',$data); 

	}

public function fetch_office_name()
	{
		$query=$this->db->query("select name,id as officeid from mst_office");
		return $query->result();
		//return $this->db->last_query();

	}

	public function fetch_guard_name()
	{
		$query=$this->db->query("select name,id from mst_guard");
		return $query->result();
		//return $this->db->last_query();

	}
	
}
