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

class Pewawancara extends CI_Controller 
{
	public function __construct() 
	{
        parent::__construct();
		$this->load->model('M_admin');
		$this->load->model('M_daftar');
    }
	
	public function index()
	{
		if($this->session->userdata('admin'))
		{
			$data['act1']				= "";
			$data['act2']				= "active";
			$data['act3']				= "";
			$data['act4']				= "";
			$data['act5']				= "";
			$data['act6']				= "";
			$data['pewawancara']		= $this->M_admin->getPewawancara();
			// print_r($data['masterPSI']);die();
			$this->load->view('header',$data);
			$this->load->view('pewawancara',$data);
			$this->load->view('footer');
		}
		else
		{
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-danger">
						<center>
							<h4>Maaf!</h4>
							<p>Anda belum login. Silakan login terlebih dahulu!</p>
						</center>
					</div>');	
			redirect('admin/Login');
		}
	}
	
	public function pewawancaraAdd()
	{
		if($this->session->userdata('admin'))
		{
			$data['act1']		= "";
			$data['act2']		= "active";
			$data['act3']		= "";
			$data['act4']		= "";
			$data['act5']		= "";
			$data['act6']		= "";
			// print_r($data['masterPSI']);die();
			$this->load->view('header',$data);
			$this->load->view('pewawancaraAdd',$data);
			$this->load->view('footer');
		}
		else
		{
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-danger">
						<center>
							<h4>Maaf!</h4>
							<p>Anda belum login. Silakan login terlebih dahulu!</p>
						</center>
					</div>');	
			redirect('admin/Login');
		}
	}
	
	public function pewawancaraAddExec()
	{
		if($this->session->userdata('admin'))
		{
			$data['nama_admin']		= $this->input->post('nama_admin');
			$data['email']			= $this->input->post('email');
			$data['no_hp']			= $this->input->post('no_hp');
			$data['password']		= md5($this->input->post('password'));
			$data['role']			= "Pewawancara";
			$this->M_admin->addPewawancara($data);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Pewawancara berhasil ditambah!</p>
						</center>
					</div>');
			redirect('admin/Pewawancara','refresh');
		}
		else
		{
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-danger">
						<center>
							<h4>Maaf!</h4>
							<p>Anda belum login. Silakan login terlebih dahulu!</p>
						</center>
					</div>');	
			redirect('admin/Login');
		}
	}
	
	public function pewawancaraEdit()
	{
		if($this->session->userdata('admin'))
		{
			$data['act1']			= "";
			$data['act2']			= "active";
			$data['act3']			= "";
			$data['act4']			= "";
			$data['act5']			= "";
			$data['act6']			= "";
			$id_admin		 		= $this->uri->segment(4);
			$data['pewawancara']	= $this->M_admin->getPewawancaraDetail($id_admin);
			// print_r($data['masterPSI']);die();
			$this->load->view('header',$data);
			$this->load->view('pewawancaraEdit',$data);
			$this->load->view('footer');
		}
		else
		{
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-danger">
						<center>
							<h4>Maaf!</h4>
							<p>Anda belum login. Silakan login terlebih dahulu!</p>
						</center>
					</div>');	
			redirect('admin/Login');
		}
	}
	
	public function pewawancaraEditExec()
	{
		if($this->session->userdata('admin'))
		{
			$id_admin				= $this->input->post('id_admin');
			$data['nama_admin']		= $this->input->post('nama_admin');
			$data['email']			= $this->input->post('email');
			$data['no_hp']			= $this->input->post('no_hp');
			$password				= $this->input->post('password');
			if($password != NULL)
			{
				$data['password']		= md5($password);
			}
			$this->M_admin->updatePewawancara($id_admin,$data);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Pewawancara berhasil diubah!</p>
						</center>
					</div>');
			redirect('admin/Pewawancara','refresh');
		}
		else
		{
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-danger">
						<center>
							<h4>Maaf!</h4>
							<p>Anda belum login. Silakan login terlebih dahulu!</p>
						</center>
					</div>');	
			redirect('admin/Login');
		}
	}
	
	public function pewawancaraDelete()
	{
		if($this->session->userdata('admin'))
		{
			$id_admin = $this->uri->segment(4);
			$this->M_admin->deletePewawancara($id_admin);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Pewawancara berhasil dihapus!</p>
						</center>
					</div>');
			redirect('admin/Pewawancara','refresh');
		}
		else
		{
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-danger">
						<center>
							<h4>Maaf!</h4>
							<p>Anda belum login. Silakan login terlebih dahulu!</p>
						</center>
					</div>');	
			redirect('admin/Login');
		}
	}
}
