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

class Model_petugas extends CI_Model
{

    var $table = 'tbl_mst_petugas';


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


    public function get_all_petugas()
    {
        $query = $this->db->query("select * from tbl_mst_petugas");
        return $query->result();
    }

    public function get_all()
    {
        $query = $this->db->query("select md5(mst_petugas_email) from tbl_mst_petugas");
        return $query->result();
    }

    public function get_by_id($petugas_id)
    {
        $this->db->from($this->table);
        $this->db->where('mst_petugas_id', $petugas_id);
        $query = $this->db->get();

        return $query->row();
    }

    public function petugas_tambah($data)
    {
        $this->db->insert($this->table, $data);
        return $this->db->insert_id();
    }


    function data_edit($mst_petugas_id)
    {
        return $this->db->query("SELECT * FROM tbl_mst_petugas where mst_petugas_id='$mst_petugas_id'");
    }

    public function petugas_edit($where, $data)
    {
        $this->db->update($this->table, $data, $where);
        return $this->db->affected_rows();
    }

    public function delete_by_id($petugas_id)
    {
        $this->db->where('mst_petugas_id', $petugas_id);
        $this->db->delete($this->table);
    }
}
