<?
php
class Home extends CI_Controller {
public function __construct()
parent::__construct();
$this->load->library('session');
$this->load->model('Home_model');
public function index ()
// $query = $this->Home_model->getJumlah();
// $data['home'] = $query->result_array();
// print_r($data);
$data['jumlah_sm'] = count($this->Home_model->getSuratmasuk()->
result_array());
$data['jumlah_sk'] = count($this->Home_model->getSuratkeluar()-
>result_array());
$this->load->view('home', $data);
public function agendamasuk(){
$query = $this->Home_model->getSuratmasuk();
$data['suratmasuks'] = $query->result_array();
$this->load->view('agendamasuk',$data);
}
public function agendakeluar(){
$query = $this->Home_model->getSuratkeluar();
$data['suratkeluars'] = $query->result_array();
$this->load->view('agendakeluar',$data);
public function datasuratmasuk(){
$query = $this->Home_model->getSuratmasuk();
$data['suratmasuks'] = $query->result_array();
$this->load->view('datasuratmasuk',$data);
public function datasuratkeluar(){
$query = $this->Home_model->getSuratkeluar();
$data['suratkeluars'] = $query->result_array();
$this->load->view('datasuratkeluar',$data);
public function add(){
if($this->input->post()){
$data['isi'] = $this->input->post('isi');
$data['asal'] = $this->input->post('asal');
$data['no_surat'] = $this->input->post('no_surat');
$data['penerima_surat'] = $this->input->post('penerima_surat');
$id = $this->Home_model->insertsurat($data);
if($id){
echo "data berhasil disimpan";
else{
echo "data tidak berhasil disimpan";
$this->load->view('form_add');
public function add_sk(){
if($this->input->post()){
$data['isi_surat'] = $this->input->post('isi_surat');
$data['asal_surat'] = $this->input->post('asal_surat');
$data['no_surat'] = $this->input->post('no_surat');
$id = $this->Home_model->insert_sk($data);
if($id){
echo "data berhasil disimpan";
else{
echo "data tidak berhasil disimpan";
$this->load->view('form_add_sk');
public function edit_sm($id){
$query = $this->Home_model->detail_sm($id);
$data['suratmasuk'] = $query->row_array();
if($this->input->post()){
$post['isi'] = $this->input->post('isi');
$post['asal'] = $this->input->post('asal');
$post['no_surat'] = $this->input->post('no_surat');
$post['penerima_surat'] = $this->input->post('penerima_sura
t');
$id = $this->Home_model->edit_sm($id, $post);
if($id){
echo "data berhasil disimpan";
else{
echo "data tidak berhasil disimpan";
$this->load->view('edit_sm',$data);
}
public function detail_sm($id){
$query = $this->Home_model->detail_sm($id);
$data['suratmasuk'] = $query->row_array();
$this->load->view('detail_sm',$data);
public function detail_sk($id){
$query = $this->Home_model->detail_sk($id);
$data['suratkeluar'] = $query->row_array();
$this->load->view('detail_sk',$data);
public function login()
if($this->input->post())
$username = $this->input->post('username');
$password = $this->input->post('password');
if($username == 'admin' && $password == 'admin')
$_SESSION['username'] = 'admin';
redirect('/');
else {
$this->session->set_flashdata('message', '<div class="a
lert alert-warning">Username/password tidak valid.</div>');
redirect('Home/login');
$this->load->view('login');
public function logout()
$this->session->sess_destroy();
redirect('/');