<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class ttd extends CI_Controller {
	function __construct(){
		parent::__construct();	
			$this->load->library('session');
			$this->load->library('form_validation');
			//$this->load->model('m_ttd');
			$this->load->model('m_ttd');
			if($this->session->userdata('username') =='' OR $this->session->userdata('token') !=md5('100%Madiun'.date('Ymd')) ){
				redirect(base_url("login"));
			}			
	}
	public function index()
	{
	$data['ttd'] = $this->m_ttd->tampil();
	$this->load->view('admin/ttd', $data);			
	}
	public function add()
	{
	$data['cek']='';
	$data['ttd'] = $this->m_ttd->tampil();
	$this->load->view('admin/ttd-add', $data);				
	}	
	public function save()
	{
		if(isset($_POST['button'])){
		$act = $this->security->xss_clean($this->input->post('act'));			
		$idttd = $this->security->xss_clean($this->input->post('idttd'));			
		$headerttd = $this->security->xss_clean($this->input->post('headerttd'));		
		$sebagai = $this->security->xss_clean($this->input->post('sebagai'));		
		$nama = $this->security->xss_clean($this->input->post('nama'));		
		$nip = $this->security->xss_clean($this->input->post('nip'));		
		$status = $this->security->xss_clean($this->input->post('status'));		
		if($act =='save'){			
		$data_save = array(
								'headerttd' => $headerttd,
								'sebagai' => $sebagai,
								'nama' => $nama,
								'nip' => $nip,
								'status' => $status
						);	
		$this->m_ttd->in($data_save,'ttd');
		$data['ttd'] = $this->m_ttd->tampil();		
		$data['alert'] = 'success';
		$data['pesan'] = 'Berhasil disimpan';		
		$this->load->view('admin/ttd', $data);				
		}else if($act=='edit'){
		$data_save = array(
								'headerttd' => $headerttd,
								'sebagai' => $sebagai,
								'nama' => $nama,
								'nip' => $nip,
								'status' => $status
						);			
		$where = array(
						'idttd' => $idttd
				);
		$this->m_ttd->update($where,$data_save,'ttd');		
		$data['ttd'] = $this->m_ttd->tampil();		
		$data['alert'] = 'success';
		$data['pesan'] = 'Berhasil diperbarui';		
		$this->load->view('admin/ttd', $data);		
		}
		}
		if(isset($_POST['kembali'])){
		$data['alert'] = '';
		$data['pesan'] = '';				
		$data['ttd'] = $this->m_ttd->tampil();
		$this->load->view('admin/ttd', $data);			
		}		
	}	
	public function edit()
	{
	if(isset($_POST['edit'])){
		$id=$this->security->xss_clean($this->input->post('id'));	
		$data['cek'] ='edit';
		$data['ttd'] = $this->m_ttd->tampil();		
		$data['edit'] = $this->m_ttd->edit($id);
		$this->load->view('admin/ttd-add', $data);					
	}else if(isset($_POST['hapus'])){
		$id=$this->security->xss_clean($this->input->post('id'));	
		$where = array(
						'idttd' => $id
				);
		$this->m_ttd->hapus($where,'ttd');
		$data['ttd'] = $this->m_ttd->tampil();		
		$data['alert'] = 'success';
		$data['pesan'] = 'Data berhasil dihapus';			
		$this->load->view('admin/ttd', $data);				
	}else{
		
		$data['ttd'] = $this->m_ttd->tampil();
		$this->load->view('admin/ttd', $data);		
		}	
	}
}