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

class User_model extends CI_Model {

		public function __construct()
		{
			parent::__construct();
			$this->load->database();
		}	

		//ambil data user
		public function listing()
		{

			$this->db->select('*');
			$this->db->from('user2');
			$this->db->order_by('id','desc');
			$query = $this->db->get();
			return $query->result();			
		}

		//ambil detail data user
		public function detail($id)
		{

			$this->db->select('*');
			$this->db->from('user2');
			//where
			$this->db->where('id', $id);
			$this->db->order_by('id','desc');
			$query = $this->db->get();
			return $query->row();			
		}

		//Login user
		public function login($userid,$password)
		{

			$this->db->select('*');
			$this->db->from('user2');
			//where
			$this->db->where(array(  'userid'		=> $userid,
							   		  'password'	=> MD5($password)));
			$this->db->order_by('id','desc');
			$query = $this->db->get();
			return $query->row();			
		}


		//hitung total user
		public function total()
		{

			$this->db->select('COUNT(*) AS total');
			$this->db->from('user2');
			$this->db->order_by('id','desc');
			$query = $this->db->get();
			return $query->row();			
		}

		//fungsi delete
		public function delete($data)
		{
			$this->db->where('id', $data['id']);
			$this->db->delete('user2', $data);
		}

		//fungsi edit
		public function edit($data)
		{
			$this->db->where('id', $data['id']);
			$this->db->update('user2', $data);
		}

		//tambah user
		public function tambah($data)
		{
			$this->db->insert('user2', $data);
		}

		public function menu_psswd()
		{
			$this->db->select('*');
			$this->db->from('pengaturan');
			//where
			$this->db->where('pengaturan_slug','menu_edit_psswd');
			$this->db->order_by('pengaturan_slug','desc');
			$query = $this->db->get();
			return $query->row();		
		}

		public function menu_pengumuman()
		{
			$this->db->select('*');
			$this->db->from('pengaturan');
			//where
			$this->db->where('pengaturan_slug','menu_pengumuman');
			$this->db->order_by('pengaturan_slug','desc');
			$query = $this->db->get();
			return $query->row();		
		}
}

/* End of file User_model.php */
/* Location: ./application/models/User_model.php */