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

class Lulustes extends CI_Controller {

	//load model
	public function __construct()
	{
		parent::__construct();
		$this->load->model('lulustes_model');
		$this->simple_login->check_login();
	}

	public function index()
	{
		$lulustes = $this->lulustes_model->lulus();
		$total = $this->lulustes_model->total();

		$data = array(	 'title'		=> 'Data Pendaftar LULUS TES [ '.$total->total.' ]',
						 'lulustes'			=> $lulustes,
						 'content' 			=> 'lulustes/index'						 					 
						);
		$this->load->view('layout/wrapper', $data, FALSE);	
	}

  //Edit pengumuman
	public function edit($no_pendaftaran)
	{
		//panggil data user yang akan diedit
		$lulustes = $this->lulustes_model->detail($no_pendaftaran);
		

		//validasi input
		$valid = $this->form_validation;
		//check nama
		$valid->set_rules('status','Data Pengumuman Kelulusan','required',
			array( 'required'		=> '%s Harus Diisi'));
		
		//jika sudah dicek dan error
		if($valid->run()===FALSE) {
		//end validasi

			$data= array(	'title'		=> 'Edit Data Hasil Tes No. Pend : '.$lulustes->no_pendaftaran,
							'lulustes'	=> $lulustes,
						  	'content' 	=> 'lulustes/edit'
						);
			$this->load->view('layout/wrapper', $data, FALSE);	
		//jika validasi oke, masuk database
		}else{
			$inp  = $this->input;
			$data = array(	'no_pendaftaran'		=> $no_pendaftaran,
              				'status'	          	=> $inp->post('status'),
							'tanggal_pengumuman'	=> date('Y-m-d H:i:s')
						);
			//proses oleh model
			$this->lulustes_model->edit($data);
			//notifikasi dan redirect
			$this->session->set_flashdata('sukses', 'Data Pengumuman Kelulusan No. Pend : '.$lulustes->no_pendaftaran.' Telah Diedit.');
			redirect(base_url('lulustes'),'refresh');
		}
		//end masuk database
	}	

	//Delete pengumuman
	public function delete($no_pendaftaran)
	{
		$data = array('no_pendaftaran' => $no_pendaftaran);
    	$data2 = array('userid' => $no_pendaftaran);
		//proses hapus
		$this->lulustes_model->delete($data);
    	$this->lulustes_model->delete2($data2);
		//notifikasi
		$this->session->set_flashdata('sukses', 'Satu Data Pengumuman Telah Dihapus..!');
		redirect(base_url('lulustes'),'refresh');
	}
}
