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

class Pertanyaan 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']				= "";
			$data['act4']				= "active";
			$data['act5']				= "";
			$data['act6']				= "";
			$data['pertanyaan']			= $this->M_admin->getPertanyaan();
			// print_r($data['masterPSI']);die();
			$this->load->view('header',$data);
			$this->load->view('pertanyaan',$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 pertanyaanAdd()
	{
		if($this->session->userdata('admin'))
		{
			$data['act1']		= "";
			$data['act2']		= "";
			$data['act3']		= "";
			$data['act4']		= "active";
			$data['act5']		= "";
			// print_r($data['masterPSI']);die();
			$this->load->view('header',$data);
			$this->load->view('pertanyaanAdd',$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 pertanyaanAddExec()
	{
		if($this->session->userdata('admin'))
		{
			$data['pertanyaan']		= $this->input->post('pertanyaan');
			$data['kode_jurusan']	= $this->input->post('kode_jurusan');
			$this->M_admin->addPertanyaan($data);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Pertanyaan berhasil ditambah!</p>
						</center>
					</div>');
			redirect('admin/Pertanyaan','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 pertanyaanEdit()
	{
		if($this->session->userdata('admin'))
		{
			$data['act1']		= "";
			$data['act2']		= "";
			$data['act3']		= "";
			$data['act4']		= "active";
			$data['act5']		= "";
			$data['act6']		= "";
			$id_pertanyaan 		= $this->uri->segment(4);
			$data['pertanyaan']	= $this->M_admin->getPertanyaanDetail($id_pertanyaan);
			// print_r($data['masterPSI']);die();
			$this->load->view('header',$data);
			$this->load->view('pertanyaanEdit',$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 pertanyaanEditExec()
	{
		if($this->session->userdata('admin'))
		{
			$id_pertanyaan				= $this->input->post('id_pertanyaan');
			$data['pertanyaan']			= $this->input->post('pertanyaan');
			$data['kode_jurusan']		= $this->input->post('kode_jurusan');
			$this->M_admin->updatePertanyaan($id_pertanyaan,$data);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Pertanyaan berhasil diubah!</p>
						</center>
					</div>');
			redirect('admin/Pertanyaan','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 pertanyaanDelete()
	{
		if($this->session->userdata('admin'))
		{
			$id_pertanyaan	= $this->uri->segment(4);
			$this->M_admin->deletePertanyaan($id_pertanyaan);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Pertanyaan berhasil dihapus!</p>
						</center>
					</div>');
			redirect('admin/Pertanyaan','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 pilihanJawaban()
	{
		if($this->session->userdata('admin'))
		{
			$data['act1']				= "";
			$data['act2']				= "";
			$data['act3']				= "";
			$data['act4']				= "active";
			$data['act5']				= "";
			$data['act6']				= "";
			$id_pertanyaan				= $this->uri->segment(4);
			$data['pertanyaan']			= $this->M_admin->getPertanyaanDetail($id_pertanyaan);
			$data['pilihan_jawaban']	= $this->M_admin->getPilihanJawaban($id_pertanyaan);
			// print_r($data['masterPSI']);die();
			$this->load->view('header',$data);
			$this->load->view('pilihanJawaban',$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 pilihanJawabanAdd()
	{
		if($this->session->userdata('admin'))
		{
			$data['act1']		= "";
			$data['act2']		= "";
			$data['act3']		= "";
			$data['act4']		= "active";
			$data['act5']		= "";
			$data['act6']		= "";
			$id_pertanyaan		= $this->uri->segment(4);
			$data['pertanyaan']	= $this->M_admin->getPertanyaanDetail($id_pertanyaan);
			// print_r($data['masterPSI']);die();
			$this->load->view('header',$data);
			$this->load->view('pilihanJawabanAdd',$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 pilihanJawabanAddExec()
	{
		if($this->session->userdata('admin'))
		{
			$data['id_pertanyaan']	= $this->input->post('id_pertanyaan');
			$data['pilihan_jawaban']= $this->input->post('pilihan_jawaban');
			$data['nilai']			= $this->input->post('nilai');
			$this->M_admin->addPilihanJawaban($data);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Pilihan Jabawana berhasil ditambah!</p>
						</center>
					</div>');
			redirect('admin/Pertanyaan/pilihanJawaban/'.$data['id_pertanyaan'],'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 pilihanJawabanEdit()
	{
		if($this->session->userdata('admin'))
		{
			$data['act1']			= "";
			$data['act2']			= "";
			$data['act3']			= "";
			$data['act4']			= "active";
			$data['act5']			= "";
			$data['act6']			= "";
			$id_pilihan_jawaban		= $this->uri->segment(4);
			$data['pilihan_jawaban']= $this->M_admin->getPilihanJawabanDetail($id_pilihan_jawaban);
			$id_pertanyaan			= $data['pilihan_jawaban']->id_pertanyaan;
			$data['pertanyaan']		= $this->M_admin->getPertanyaanDetail($id_pertanyaan);
			// print_r($data['masterPSI']);die();
			$this->load->view('header',$data);
			$this->load->view('pilihanJawabanEdit',$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 pilihanJawabanEditExec()
	{
		if($this->session->userdata('admin'))
		{
			$id_pilihan_jawaban			= $this->input->post('id_pilihan_jawaban');
			$pilihan_jawaban			= $this->M_admin->getPilihanJawabanDetail($id_pilihan_jawaban);
			$data['pilihan_jawaban']	= $this->input->post('pilihan_jawaban');
			$data['nilai']				= $this->input->post('nilai');
			$this->M_admin->updatePilihanJawaban($id_pilihan_jawaban,$data);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Pilihan Jawaban berhasil diubah!</p>
						</center>
					</div>');
			redirect('admin/Pertanyaan/pilihanJawaban/'.$pilihan_jawaban->id_pertanyaan,'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 pilihanJawabanDelete()
	{
		if($this->session->userdata('admin'))
		{
			$id_pilihan_jawaban	= $this->uri->segment(4);
			$data['pilihan_jawaban']= $this->M_admin->getPilihanJawabanDetail($id_pilihan_jawaban);
			$this->M_admin->deletePilihanJawaban($id_pilihan_jawaban);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Pilihan Jawaban berhasil dihapus!</p>
						</center>
					</div>');
			redirect('admin/Pertanyaan/pilihanJawaban/'.$data['pilihan_jawaban']->id_pertanyaan,'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');
		}
	}
}