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

class Gelombang extends CI_Controller 
{
	public function __construct() 
	{
        parent::__construct();
		$this->load->model('M_admin');
		$this->load->model('M_gelombang');
    }
	
	public function index()
	{
		if($this->session->userdata('admin'))
		{
			$data['act1']				= "";
			$data['act2']				= "";
			$data['act3']				= "";
			$data['act4']				= "";
			$data['act5']				= "";
			$data['act6']				= "active";
			$data['gelombang']			= $this->M_gelombang->getGelombang();
			// print_r($data['masterPSI']);die();
			$this->load->view('header',$data);
			$this->load->view('gelombang',$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 gelombangAdd()
	{
		if($this->session->userdata('admin'))
		{
			$data['act1']		= "";
			$data['act2']		= "";
			$data['act3']		= "";
			$data['act4']		= "";
			$data['act5']		= "";
			$data['act6']		= "active";
			// print_r($data['masterPSI']);die();
			$this->load->view('header',$data);
			$this->load->view('gelombangAdd',$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 gelombangAddExec()
	{
		if($this->session->userdata('admin'))
		{
			$data['gelombang']		= $this->input->post('gelombang');
			$data['tahun_ajaran']	= $this->input->post('tahun_ajaran');
			$data['start_date']		= $this->input->post('start_date').":00";
			$data['end_date']		= $this->input->post('end_date').":00";
			$this->M_gelombang->addGelombang($data);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Gelombang berhasil ditambah!</p>
						</center>
					</div>');
			redirect('admin/Gelombang','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 gelombangEdit()
	{
		if($this->session->userdata('admin'))
		{
			$data['act1']			= "";
			$data['act2']			= "";
			$data['act3']			= "";
			$data['act4']			= "";
			$data['act5']			= "";
			$data['act6']			= "active";
			$id_gelombang		 	= $this->uri->segment(4);
			$data['gelombang']		= $this->M_gelombang->getGelombangDetail($id_gelombang);
			// print_r($data['masterPSI']);die();
			$this->load->view('header',$data);
			$this->load->view('gelombangEdit',$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 gelombangEditExec()
	{
		if($this->session->userdata('admin'))
		{
			$id_gelombang			= $this->input->post('id_gelombang');
			$data['gelombang']		= $this->input->post('gelombang');
			$data['tahun_ajaran']	= $this->input->post('tahun_ajaran');
			$data['start_date']		= $this->input->post('start_date').":00";
			$data['end_date']		= $this->input->post('end_date').":00";
			$this->M_gelombang->updateGelombang($id_gelombang,$data);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Gelombang Pendaftaran berhasil diubah!</p>
						</center>
					</div>');
			redirect('admin/Gelombang','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 gelombangDelete()
	{
		if($this->session->userdata('admin'))
		{
			$id_gelombang = $this->uri->segment(4);
			$this->M_gelombang->deleteGelombang($id_gelombang);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Gelombang Pendaftaran berhasil dihapus!</p>
						</center>
					</div>');
			redirect('admin/Gelombang','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');
		}
	}
}
