149 lines
3.1 KiB
PHP
149 lines
3.1 KiB
PHP
<?php
|
|
class User extends CI_Controller{
|
|
|
|
function __Construct()
|
|
{
|
|
parent ::__construct();
|
|
$this->load->model('M_form');
|
|
}
|
|
|
|
function index()
|
|
{
|
|
if($this->auth->CI->session->userdata('is_log_in'))
|
|
{
|
|
if($this->auth->CI->session->userdata('role')=='Admin')
|
|
{
|
|
$this->load->view('vAdmin');
|
|
}
|
|
else
|
|
{
|
|
redirect('form');
|
|
}
|
|
}else
|
|
{
|
|
//load halaman login
|
|
$this->load->view('vLogin');
|
|
}
|
|
$array_items = array('status' => '', 'tipe' => '', 'message' => '');
|
|
$this->session->unset_userdata($array_items);
|
|
}
|
|
|
|
function loadform()
|
|
{
|
|
if ($this->cekLogin())
|
|
{
|
|
$data['form_saved'] = $this->M_form->getFormSaved();
|
|
$data['form_pending'] = $this->M_form->getFormPending();
|
|
$this->load->view('vAdminForm',$data);
|
|
}
|
|
else
|
|
{
|
|
//$this->load->view('vLogin');
|
|
}
|
|
}
|
|
|
|
function loadstaff()
|
|
{
|
|
$data['user'] = $this->M_form->getUser();
|
|
$this->load->view('vAdminStaff',$data);
|
|
}
|
|
|
|
function loadsellingout()
|
|
{
|
|
$data['sellout'] = $this->M_form->getSellout();
|
|
$this->load->view('vAdminSellingout',$data);
|
|
}
|
|
|
|
function loadvolume()
|
|
{
|
|
$data['volume'] = $this->M_form->getVolume();
|
|
$this->load->view('vAdminVolume',$data);
|
|
}
|
|
|
|
function login_auth()
|
|
{
|
|
$username = $this->input->post('username');
|
|
$password = $this->input->post('password');
|
|
$success = $this->auth->do_login($username,$password);
|
|
if($success)
|
|
{
|
|
$notif = array(
|
|
'status' => '1',
|
|
'tipe' => 'alert-info',
|
|
'message' => '<strong>Welcome back </strong>'.$this->auth->CI->session->userdata('nama')
|
|
);
|
|
$this->session->set_userdata($notif);
|
|
redirect('user');
|
|
}
|
|
else
|
|
{
|
|
//wrong log in
|
|
$data['login_info'] = "Maaf, username dan password salah!";
|
|
$this->load->view('vLogin',$data);
|
|
}
|
|
}
|
|
|
|
function logout()
|
|
{
|
|
//$this->auth->CI->session->unset_userdata();
|
|
$this->auth->CI->session->sess_destroy();
|
|
redirect('user');
|
|
}
|
|
|
|
function insert_user()
|
|
{
|
|
$datauser = array (
|
|
'nama' => $this->input->post('nama'),
|
|
'username' => $this->input->post('username'),
|
|
'password' => md5($this->input->post('password')),
|
|
'role' => $this->input->post('role')
|
|
);
|
|
$cek = $this->M_form->newuser($datauser);
|
|
if ($cek)
|
|
{
|
|
$notif = array(
|
|
'status' => '1',
|
|
'tipe' => 'alert-success',
|
|
'message' => '<strong>Well Done</strong> | Sales baru berhasil diinput'
|
|
);
|
|
$this->session->set_userdata($notif);
|
|
redirect('user');
|
|
}
|
|
else
|
|
{
|
|
$notif = array(
|
|
'status' => '1',
|
|
'tipe' => 'alert-error',
|
|
'message' => '<strong>Well Done</strong> | Sales baru berhasil diinput'
|
|
);
|
|
$this->session->set_userdata($notif);
|
|
redirect('user');
|
|
}
|
|
}
|
|
|
|
function delete_user($id)
|
|
{
|
|
$id = $this->M_form->delete_user($id);
|
|
|
|
redirect('user');
|
|
}
|
|
|
|
function cekLogin()
|
|
{
|
|
if($this->auth->CI->session->userdata('is_log_in'))
|
|
{
|
|
if($this->auth->CI->session->userdata('role')=='Admin')
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
redirect('Form');
|
|
}
|
|
}else
|
|
{
|
|
//load halaman login
|
|
return false;
|
|
}
|
|
}
|
|
} |