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

class Jurusan 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']				= "";
			$data['act3']				= "active";
			$data['act4']				= "";
			$data['act5']				= "";
			$data['act6']				= "";
			$data['jurusan']			= $this->M_admin->getJurusan();
			// print_r($data['masterPSI']);die();
			$this->load->view('header',$data);
			$this->load->view('jurusan',$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 jurusanAdd()
	{
		if($this->session->userdata('admin'))
		{
			$data['act1']		= "";
			$data['act2']		= "";
			$data['act3']		= "active";
			$data['act4']		= "";
			$data['act5']		= "";
			$data['act6']		= "";
			// print_r($data['masterPSI']);die();
			$this->load->view('header',$data);
			$this->load->view('jurusanAdd',$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 jurusanAddExec()
	{
		if($this->session->userdata('admin'))
		{
			$data['jurusan']		= $this->input->post('jurusan');
			$data['kode_jurusan']	= $this->input->post('kode_jurusan');
			$this->M_admin->addJurusan($data);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Jurusan berhasil ditambah!</p>
						</center>
					</div>');
			redirect('admin/Jurusan','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 jurusanEdit()
	{
		if($this->session->userdata('admin'))
		{
			$data['act1']		= "";
			$data['act2']		= "";
			$data['act3']		= "active";
			$data['act4']		= "";
			$data['act5']		= "";
			$data['act6']		= "";
			$id_jurusan 		= $this->uri->segment(4);
			$data['jurusan']	= $this->M_admin->getJurusanDetail($id_jurusan);
			// print_r($data['masterPSI']);die();
			$this->load->view('header',$data);
			$this->load->view('jurusanEdit',$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 jurusanEditExec()
	{
		if($this->session->userdata('admin'))
		{
			$id_jurusan				= $this->input->post('id_jurusan');
			$data['jurusan']		= $this->input->post('jurusan');
			$data['kode_jurusan']	= $this->input->post('kode_jurusan');
			$data['status']			= $this->input->post('status');
			$this->M_admin->updateJurusan($id_jurusan,$data);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Jurusan berhasil diubah!</p>
						</center>
					</div>');
			redirect('admin/Jurusan','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 jurusanDelete()
	{
		if($this->session->userdata('admin'))
		{
			$id_jurusan	= $this->uri->segment(4);
			$this->M_admin->deleteJurusan($id_jurusan);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Jurusan berhasil dihapus!</p>
						</center>
					</div>');
			redirect('admin/Jurusan','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');
		}
	}
}
