105 lines
2.4 KiB
PHP
105 lines
2.4 KiB
PHP
|
<?php
|
||
|
|
||
|
class Admin extends CI_Controller{
|
||
|
|
||
|
function __Construct()
|
||
|
{
|
||
|
parent ::__construct();
|
||
|
$this->load->model('M_admin');
|
||
|
}
|
||
|
|
||
|
function index()
|
||
|
{
|
||
|
if($this->auth->CI->session->userdata('is_log_in'))
|
||
|
{
|
||
|
$this->load->view('admin/template/header');
|
||
|
$this->load->view('admin/template/sidebar');
|
||
|
$this->load->view('admin/dashboard');
|
||
|
//echo $this->auth->CI->session->userdata('nama');
|
||
|
}else
|
||
|
{
|
||
|
$this->load->view('admin/login');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function login_auth()
|
||
|
{
|
||
|
$username = $this->input->post('username');
|
||
|
$password = $this->input->post('password');
|
||
|
$success = $this->auth->do_login($username,$password);
|
||
|
if($success)
|
||
|
{
|
||
|
// lemparkan ke halaman index user
|
||
|
redirect('admin');
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
$data['login_info'] = "Maaf, username dan password salah!";
|
||
|
$this->load->view('admin/login',$data);
|
||
|
}
|
||
|
}
|
||
|
function logout()
|
||
|
{
|
||
|
//$this->auth->CI->session->unset_userdata();
|
||
|
$this->auth->CI->session->sess_destroy();
|
||
|
redirect('admin');
|
||
|
}
|
||
|
|
||
|
//admin function
|
||
|
|
||
|
//add_post
|
||
|
function add_post()
|
||
|
{
|
||
|
$data['judul'] = 'Add Post';
|
||
|
$this->load->view('admin/template/header');
|
||
|
$this->load->view('admin/template/sidebar');
|
||
|
$this->load->view('admin/add_post',$data);
|
||
|
}
|
||
|
|
||
|
function save_post()
|
||
|
{
|
||
|
$this->M_admin->save_post();
|
||
|
redirect('admin/list_post','refresh');
|
||
|
}
|
||
|
|
||
|
//list all post
|
||
|
function list_post()
|
||
|
{
|
||
|
$data['judul'] = 'List Post';
|
||
|
$data['listpost'] = $this->M_admin->get_post_all();
|
||
|
$this->load->view('admin/template/header');
|
||
|
$this->load->view('admin/template/sidebar');
|
||
|
$this->load->view('admin/post',$data);
|
||
|
}
|
||
|
|
||
|
//edit post
|
||
|
function edit($id)
|
||
|
{
|
||
|
$data['judul']='Edit Page';
|
||
|
$data['edit']=$this->M_admin->edit_post($id);
|
||
|
$this->load->view('admin/template/header');
|
||
|
$this->load->view('admin/template/sidebar');
|
||
|
$this->load->view('admin/edit_post',$data);
|
||
|
}
|
||
|
function save_edit_post()
|
||
|
{
|
||
|
$id = $this->input->post('id');
|
||
|
$judul = $this->input->post('judul');
|
||
|
$isi = $this->input->post('isi');
|
||
|
|
||
|
$data['judul'] = 'Update Data Codeigniter';
|
||
|
$data['edit'] = $this->M_admin->save_edit_post($id, $judul, $isi);
|
||
|
echo ("<SCRIPT LANGUAGE='JavaScript'>
|
||
|
window.alert('Succesfully Updated')
|
||
|
</SCRIPT>");
|
||
|
redirect('admin/list_post','refresh');
|
||
|
}
|
||
|
|
||
|
//delete
|
||
|
function delete($id)
|
||
|
{
|
||
|
$id = $this->M_admin->delete_post($id);
|
||
|
|
||
|
redirect('admin/list_post');
|
||
|
}
|
||
|
}
|