<?php
class Berita_m extends CI_Model {
    

    function __construct()
    {        
        parent::__construct();
    }
	
	public function tampil($id)
    {
		$this->d_pas = $this->load->database('default', TRUE);
		$query = $this->d_pas->query("SELECT * FROM at_berita where tipe='$id'");
        $b=$query->result();
		return $b;
    }
	
	public function hal($id)
    {
		$this->d_pas = $this->load->database('default', TRUE);
		$query = $this->d_pas->query("SELECT * FROM at_berita where tipe='$id'");
        $b=$query->num_rows();
		return $b;
    }
	
	public function berita_semua($cari, $tipe, $limit)
    {
		$this->d_pas = $this->load->database('default', TRUE);
        $query = $this->d_pas->query("SELECT * FROM at_berita where tipe='$tipe' order by urut asc, tanggal DESC $limit");
        return $query->result();
		
    }
	
	public function simpan($judul_ind, $judul_ing, $isi_ind, $isi_ing, $tanggal, $foto, $tipe, $oleh, $depan)
    {
		$data = array(
        'judul_ind' => $judul_ind, 
        'judul_ing' => $judul_ing,
        'isi_ind' => $isi_ind, 
        'isi_ing' => $isi_ing,
        'tanggal' => $tanggal, 
        'foto' => $foto,
		'oleh' => $oleh,
		'urut' => $depan,
        'tipe' => $tipe
        );
		$str = $this->db->insert_string('at_berita', $data);
        mysql_query($str);
    }
	
	public function editsimpan($a, $judul_ind, $judul_ing, $isi_ind, $isi_ing, $tanggal, $foto, $tipe, $oleh, $depan)
    {
		$data = array(
        'judul_ind' => $judul_ind, 
        'judul_ing' => $judul_ing,
        'isi_ind' =>  $isi_ind, 
        'isi_ing' => $isi_ing, 'tanggal' => $tanggal,
        'foto' => $foto,
		'oleh' => $oleh,
		'urut' => $depan,
        'tipe' => $tipe
        );

		$this->db->where('id', $a);
		$this->db->update('at_berita', $data); 
    }
    
    	
	public function hapus($a, $b)
    {
		$this->db->where('id', $a);
		$this->db->where('tipe', $b);
		$this->db->delete('at_berita'); 
    }

}