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

class Pegawai extends CI_Controller 
{
	public function __construct() 
	{
        parent::__construct();
		$this->load->model('M_pegawai');
		$this->load->model('M_admin');
    }
	
	public function index()
	{
		if($this->session->userdata('pegawai'))
		{
			$data['peraturan'] = $this->M_admin->getPeraturan();
			$this->load->view('salam',$data);
			
		}
		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('Login');
		}
	}
	
	public function gantiPassword()
	{
		if($this->session->userdata('pegawai'))
		{
			$this->load->view('gantiPassword');
		}
		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('Login');
		}
	}
	
	public function gantiPasswordExec()
	{
		$session_data		= $this->session->userdata('pegawai');
		$id_pegawai			= $session_data['id'];
		$data['password']	= md5($this->input->post('new_password'));
		$password			= md5($this->input->post('old_password'));
		$check				= $this->M_pegawai->checkPassword($id_pegawai,$password)->row();
		if($check != NULL)
		{
			$update				= $this->M_pegawai->updatePegawai($id_pegawai,$data);
			// print_r($check);die();
			if($update)
			{
				$this->session->set_flashdata('msg', 
						'<div class="alert alert-success">
							<center>
								<h4>Password berhasil diubah!</h4>
								<p>Silakan login menggunakan password baru Anda!</p>
							</center>
						</div>');
				redirect('Login');
			}
			else
			{
				$this->session->set_flashdata('msg', 
						'<div class="alert alert-danger">
							<center>
								<h4>Password gagal diubah!</h4>
								<p>Silakan Coba lagi!</p>
							</center>
						</div>');	
				redirect('Pegawai/gantiPassword');		
			}
		}
		else
		{
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-danger">
						<center>
							<h4>Password lama yang Anda masukkan salah!</h4>
							<p>Silakan Coba lagi!</p>
						</center>
					</div>');	
			redirect('Pegawai/gantiPassword');
		}
	}
	
	public function personal()
	{
		if($this->session->userdata('pegawai'))
		{
			$session_data		= $this->session->userdata('pegawai');
			$id_pegawai			= $session_data['id'];
			$data['pegawai']	= $this->M_pegawai->getPegawai($id_pegawai);
			// print_r($data['pegawai']);die();
			$this->load->view('personal',$data);
		}
		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('Login');
		}
	}
	
	public function personalEdit()
	{
		if($this->session->userdata('pegawai'))
		{
			$session_data		= $this->session->userdata('pegawai');
			$id_pegawai			= $session_data['id'];
			$data['pegawai']	= $this->M_pegawai->getPegawai($id_pegawai);
			// print_r($data['pegawai']);die();
			$this->load->view('personalEdit',$data);
		}
		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('Login');
		}
	}
	
	public function personalEditExec()
	{
		if($this->session->userdata('pegawai'))
		{
			if (! empty($_FILES['foto_ktp']['name']))
			{
				$this->load->library('upload');
				$config['upload_path'] 		= './assets/pegawai/docs/';
				$config['allowed_types']	= '*';
				$config['max_size'] 		= '10000';
				$this->upload->initialize($config);
				$this->upload->do_upload('foto_ktp');
				$foto_ktp					= $_FILES['foto_ktp']['name'];
				$data['foto_ktp']			= str_replace(" ","_",$foto_ktp);
				// print_r($this->input->post('foto_ktp'));die();
			}
			if (! empty($_FILES['foto_kk']['name']))
			{
				$this->load->library('upload');
				$config2['upload_path'] 	= './assets/pegawai/docs/';
				$config2['allowed_types']	= '*';
				$config2['max_size'] 		= '10000';
				$this->upload->initialize($config2);
				$this->upload->do_upload('foto_kk');
				$foto_kk					= $_FILES['foto_kk']['name'];
				$data['foto_kk']			= str_replace(" ","_",$foto_kk);
			}
			if (! empty($_FILES['foto_ijazah_terakhir']['name']))
			{
				$this->load->library('upload');
				$config3['upload_path'] 	= './assets/pegawai/docs/';
				$config3['allowed_types']	= '*';
				$config3['max_size'] 		= '10000';
				$this->upload->initialize($config3);
				$this->upload->do_upload('foto_ijazah_terakhir');
				$foto_ijazah_terakhir		= $_FILES['foto_ijazah_terakhir']['name'];
				$data['foto_ijazah_terakhir']= str_replace(" ","_",$foto_ijazah_terakhir);
			}
			$session_data				= $this->session->userdata('pegawai');
			$id_pegawai					= $session_data['id'];
			$data['nama']				= $this->input->post('nama');
			$data['gelar_depan']		= $this->input->post('gelar_depan');
			$data['gelar_belakang']		= $this->input->post('gelar_belakang');
			// $data['no_pegawai']			= $this->input->post('no_pegawai');
			$data['alamat']				= $this->input->post('alamat');
			$data['nohp']				= $this->input->post('nohp');
			$data['tempat_lahir']		= $this->input->post('tempat_lahir');
			$data['tanggal_lahir']		= $this->input->post('tanggal_lahir');
			$data['tanggal_lahir']		= $this->input->post('tanggal_lahir');
			$data['jenkel']				= $this->input->post('jenkel');
			$data['gol_darah']			= $this->input->post('gol_darah');
			$data['lain']				= $this->input->post('lain');
			$this->M_pegawai->updatePegawai($id_pegawai,$data);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Data Personal Anda berhasil diubah!</p>
						</center>
					</div>');
			redirect('Pegawai/personal');
		}
		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('Login');
		}
	}
	
	public function pegawai()
	{
		if($this->session->userdata('pegawai'))
		{
			$session_data		= $this->session->userdata('pegawai');
			$id_pegawai			= $session_data['id'];
			$data['pegawai']	= $this->M_pegawai->getPegawai($id_pegawai);
			$data['kepegawaian']= $this->M_pegawai->getKepegawaian($id_pegawai);
			$data['gaji']		= $this->M_pegawai->getGajiPegawai($id_pegawai);
			$data['jabatan']	= $this->M_pegawai->getJabatan($id_pegawai);
			$data['riwayat_sk']	= $this->M_pegawai->getRiwayatSK($id_pegawai);
			$data['nilai_pegawai']	= $this->M_pegawai->getNilai($id_pegawai);
			$data['riwayat_pembinaan']	= $this->M_pegawai->getPembinaan($id_pegawai);
			// print_r($data);die();
			$this->load->view('kepegawaian',$data);
		}
		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('Login');
		}
	}
	
	public function pegawaiEdit()
	{
		if($this->session->userdata('pegawai'))
		{
			$session_data				= $this->session->userdata('pegawai');
			$id_pegawai					= $session_data['id'];
			$data['pegawai']			= $this->M_pegawai->getPegawai($id_pegawai);
			$data['kepegawaian']		= $this->M_pegawai->getKepegawaian($id_pegawai);
			$data['unit_kerja']			= $this->M_pegawai->getUnitKerja();
			$data['status_kepegawaian']	= $this->M_pegawai->getStatusKepegawaian();
			// $data['gaji']		= $this->M_pegawai->getGajiPegawai($id_pegawai);
			// print_r($data['gaji']);die();
			$this->load->view('kepegawaianEdit',$data);
		}
		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('Login');
		}
	}
	
	public function pegawaiEditExec()
	{
		if($this->session->userdata('pegawai'))
		{
			if (! empty($_FILES['foto_spksk']['name']))
			{
				$this->load->library('upload');
				$config['upload_path'] 		= './assets/pegawai/docs/';
				$config['allowed_types']	= '*';
				$config['max_size'] 		= '10000';
				$this->upload->initialize($config);
				$this->upload->do_upload('foto_spksk');
				$foto_spksk					= $_FILES['foto_spksk']['name'];
				$data['foto_spksk']			= str_replace(" ","_",$foto_spksk);
				// print_r($this->input->post('foto_ktp'));die();
			}
			$session_data					= $this->session->userdata('pegawai');
			$id_pegawai						= $session_data['id'];
			$data['id_unit_kerja']			= $this->input->post('id_unit_kerja');
			$data['id_status_kepegawaian']	= $this->input->post('id_status_kepegawaian');
			$data['tahun_masuk']			= $this->input->post('tahun_masuk');
			$kepegawaian					= $this->M_pegawai->getKepegawaian($id_pegawai);
			// print_r($data);die();
			if($kepegawaian == NULL)
			{
				$data['id_pegawai']				= $id_pegawai;
				$this->M_pegawai->addPegawai($data);
			}
			else
			{
				$this->M_pegawai->updateKepegawaian($id_pegawai,$data);
			}
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Data Personal Anda berhasil diubah!</p>
						</center>
					</div>');
			redirect('Pegawai/pegawai');
		}
		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('Login');
		}
	}
	
	public function keluarga()
	{
		if($this->session->userdata('pegawai'))
		{
			$session_data		= $this->session->userdata('pegawai');
			$id_pegawai			= $session_data['id'];
			$data['pegawai']	= $this->M_pegawai->getPegawai($id_pegawai);
			$data['keluarga']	= $this->M_pegawai->getKeluarga($id_pegawai);
			// print_r($data['keluarga']);die();
			$this->load->view('keluarga',$data);
		}
		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('Login');
		}
	}
	
	public function keluargaAdd()
	{
		if($this->session->userdata('pegawai'))
		{
			$data['profesi']	= $this->M_admin->getPSI();
			$this->load->view('keluargaAdd',$data);
		}
		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('Login');
		}
	}
	
	public function keluargaAddExec()
	{
		if($this->session->userdata('pegawai'))
		{
			$session_data						= $this->session->userdata('pegawai');
			$data['id_pegawai']					= $session_data['id'];
			$data['nama']						= $this->input->post('nama');
			$data['hubungan']					= $this->input->post('hubungan');
			$data['profesi']					= $this->input->post('profesi');
			$data['tanggal_lahir']				= $this->input->post('tanggal_lahir');
			$this->M_pegawai->addKeluarga($data);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Anggota keluarga berhasil!</p>
						</center>
					</div>');
			redirect('Pegawai/keluarga');
		}
		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('Login');
		}
	}
	
	public function keluargaEdit()
	{
		if($this->session->userdata('pegawai'))
		{
			$id_keluarga_pegawai			= $this->uri->segment(3);
			$data['keluarga_pegawai']		= $this->M_pegawai->getKeluargaDetail($id_keluarga_pegawai);
			$data['profesi']				= $this->M_admin->getPSI();
			// print_r($data['pekerjaan_suami_istri']);die();
			$this->load->view('keluargaEdit',$data);
		}
		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('Login');
		}
	}
	
	public function keluargaEditExec()
	{
		if($this->session->userdata('pegawai'))
		{
			$id_keluarga_pegawai				= $this->input->post('id_keluarga_pegawai');
			$data['nama']						= $this->input->post('nama');
			$data['hubungan']					= $this->input->post('hubungan');
			$data['profesi']					= $this->input->post('profesi');
			$data['tanggal_lahir']				= $this->input->post('tanggal_lahir');
			$this->M_pegawai->updateKeluarga($id_keluarga_pegawai,$data);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Data anggota keluarga berhasil diubah!</p>
						</center>
					</div>');
			redirect('Pegawai/keluarga');
		}
		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('Login');
		}
	}
	
	public function keluargaDelete()
	{
		if($this->session->userdata('pegawai'))
		{
			$id_keluarga_pegawai				= $this->uri->segment(3);
			$this->M_pegawai->deleteKeluarga($id_keluarga_pegawai);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Data anggota keluarga berhasil dihapus!</p>
						</center>
					</div>');
			redirect('Pegawai/keluarga');
		}
		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('Login');
		}
	}
	
	public function kesehatan()
	{
		if($this->session->userdata('pegawai'))
		{
			$session_data		= $this->session->userdata('pegawai');
			$id_pegawai			= $session_data['id'];
			$data['pegawai']	= $this->M_pegawai->getPegawai($id_pegawai);
			$data['penyakit']	= $this->M_pegawai->getPenyakit($id_pegawai);
			// print_r($data['penyakit']);die();
			$this->load->view('kesehatan',$data);
		}
		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('Login');
		}
	}
	
	public function kesehatanAdd()
	{
		if($this->session->userdata('pegawai'))
		{
			$session_data		= $this->session->userdata('pegawai');
			$id_pegawai			= $session_data['id'];
			$data['pegawai']	= $this->M_pegawai->getPegawai($id_pegawai);
			// print_r($data['gaji']);die();
			$this->load->view('kesehatanAdd',$data);
		}
		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('Login');
		}
	}
	
	public function kesehatanAddExec()
	{
		if($this->session->userdata('pegawai'))
		{
			$session_data			= $this->session->userdata('pegawai');
			$data['id_pegawai']		= $session_data['id'];
			$data['penyakit']		= $this->input->post('penyakit');
			$data['tahun']			= $this->input->post('tahun');
			$data['tingkat']		= $this->input->post('tingkat');
			$data['menular']		= $this->input->post('menular');
			$data['sembuh']			= $this->input->post('sembuh');
			$this->M_pegawai->addKesehatan($data);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Data riwayat penyakit Anda berhasil ditambah!</p>
						</center>
					</div>');
			redirect('Pegawai/kesehatan');
		}
		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('Login');
		}
	}
	
	public function kesehatanEdit()
	{
		if($this->session->userdata('pegawai'))
		{
			$session_data		= $this->session->userdata('pegawai');
			$id_pegawai			= $session_data['id'];
			$data['pegawai']	= $this->M_pegawai->getPegawai($id_pegawai);
			$id_penyakit		= $this->uri->segment(3);
			$data['penyakit']	= $this->M_pegawai->getPenyakitDetail($id_penyakit);
			// print_r($data['penyakit']);die();
			$this->load->view('kesehatanEdit',$data);
		}
		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('Login');
		}
	}
	
	public function kesehatanEditExec()
	{
		if($this->session->userdata('pegawai'))
		{
			$id_penyakit			= $this->input->post('id_penyakit');
			$data['penyakit']		= $this->input->post('penyakit');
			$data['tahun']			= $this->input->post('tahun');
			$data['tingkat']		= $this->input->post('tingkat');
			$data['menular']		= $this->input->post('menular');
			$data['sembuh']			= $this->input->post('sembuh');
			$this->M_pegawai->updateKesehatan($id_penyakit,$data);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Data riwayat penyakit Anda berhasil diubah!</p>
						</center>
					</div>');
			redirect('Pegawai/kesehatan');
		}
		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('Login');
		}
	}
	
	public function kesehatanDelete()
	{
		if($this->session->userdata('pegawai'))
		{
			$id_penyakit			= $this->uri->segment(3);
			// print_r($id_penyakit);die();
			$this->M_pegawai->deleteKesehatan($id_penyakit);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Data riwayat penyakit Anda berhasil dihapus!</p>
						</center>
					</div>');
			redirect('Pegawai/kesehatan');
		}
		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('Login');
		}
	}
	
	public function pendidikan()
	{
		if($this->session->userdata('pegawai'))
		{
			$session_data		= $this->session->userdata('pegawai');
			$id_pegawai			= $session_data['id'];
			$data['pegawai']	= $this->M_pegawai->getPegawai($id_pegawai);
			$data['pendidikan']	= $this->M_pegawai->getPendidikan($id_pegawai);
			$data['pelatihan']	= $this->M_pegawai->getPelatihan($id_pegawai);
			$data['prestasi']	= $this->M_pegawai->getPrestasi($id_pegawai);
			// print_r($data['penyakit']);die();
			$this->load->view('pendidikan',$data);
		}
		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('Login');
		}
	}
	
	public function pendidikanAdd()
	{
		if($this->session->userdata('pegawai'))
		{
			$session_data		= $this->session->userdata('pegawai');
			$id_pegawai			= $session_data['id'];
			$data['pegawai']	= $this->M_pegawai->getPegawai($id_pegawai);
			// print_r($data['gaji']);die();
			$this->load->view('pendidikanAdd',$data);
		}
		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('Login');
		}
	}
	
	public function pendidikanAddExec()
	{
		if($this->session->userdata('pegawai'))
		{
			$session_data			= $this->session->userdata('pegawai');
			$data['id_pegawai']		= $session_data['id'];
			$data['instansi']		= $this->input->post('instansi');
			$data['tahun_masuk']	= $this->input->post('tahun_masuk');
			$data['tahun_lulus']	= $this->input->post('tahun_lulus');
			$this->M_pegawai->addPendidikan($data);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Data riwayat pendidikan Anda berhasil ditambah!</p>
						</center>
					</div>');
			redirect('Pegawai/pendidikan');
		}
		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('Login');
		}
	}
	
	public function pendidikanEdit()
	{
		if($this->session->userdata('pegawai'))
		{
			$id_pendidikan		= $this->uri->segment(3);
			$data['pendidikan']	= $this->M_pegawai->getPendidikanDetail($id_pendidikan);
			// print_r($data['penyakit']);die();
			$this->load->view('pendidikanEdit',$data);
		}
		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('Login');
		}
	}
	
	public function pendidikanEditExec()
	{
		if($this->session->userdata('pegawai'))
		{
			$id_pendidikan			= $this->input->post('id_pendidikan');
			$data['instansi']		= $this->input->post('instansi');
			$data['tahun_masuk']	= $this->input->post('tahun_masuk');
			$data['tahun_lulus']	= $this->input->post('tahun_lulus');
			$this->M_pegawai->updatePendidikan($id_pendidikan,$data);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Data riwayat pendidikan Anda berhasil diubah!</p>
						</center>
					</div>');
			redirect('Pegawai/pendidikan');
		}
		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('Login');
		}
	}
	
	public function pendidikanDelete()
	{
		if($this->session->userdata('pegawai'))
		{
			$id_pendidikan			= $this->uri->segment(3);
			// print_r($id_penyakit);die();
			$this->M_pegawai->deletePendidikan($id_pendidikan);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Data riwayat pendidikan Anda berhasil dihapus!</p>
						</center>
					</div>');
			redirect('Pegawai/pendidikan');
		}
		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('Login');
		}
	}
	
	public function pelatihanAdd()
	{
		if($this->session->userdata('pegawai'))
		{
			$session_data		= $this->session->userdata('pegawai');
			$id_pegawai			= $session_data['id'];
			$data['pegawai']	= $this->M_pegawai->getPegawai($id_pegawai);
			// print_r($data['gaji']);die();
			$this->load->view('pelatihanAdd',$data);
		}
		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('Login');
		}
	}
	
	public function pelatihanAddExec()
	{
		if($this->session->userdata('pegawai'))
		{
			$session_data			= $this->session->userdata('pegawai');
			$data['id_pegawai']		= $session_data['id'];
			$data['nama_pelatihan']	= $this->input->post('nama_pelatihan');
			$data['tahun']			= $this->input->post('tahun');
			$data['sertifikat']		= $this->input->post('sertifikat');
			$this->M_pegawai->addPelatihan($data);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Data riwayat pelatihan Anda berhasil ditambah!</p>
						</center>
					</div>');
			redirect('Pegawai/pendidikan');
		}
		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('Login');
		}
	}
	
	public function pelatihanEdit()
	{
		if($this->session->userdata('pegawai'))
		{
			$id_pelatihan		= $this->uri->segment(3);
			$data['pelatihan']	= $this->M_pegawai->getPelatihanDetail($id_pelatihan);
			// print_r($data['penyakit']);die();
			$this->load->view('pelatihanEdit',$data);
		}
		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('Login');
		}
	}
	
	public function pelatihanEditExec()
	{
		if($this->session->userdata('pegawai'))
		{
			$id_pelatihan			= $this->input->post('id_pelatihan');
			$data['nama_pelatihan']	= $this->input->post('nama_pelatihan');
			$data['tahun']			= $this->input->post('tahun');
			$data['sertifikat']		= $this->input->post('sertifikat');
			$this->M_pegawai->updatePelatihan($id_pelatihan,$data);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Data riwayat pelatihan Anda berhasil diubah!</p>
						</center>
					</div>');
			redirect('Pegawai/pendidikan');
		}
		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('Login');
		}
	}
	
	public function pelatihanDelete()
	{
		if($this->session->userdata('pegawai'))
		{
			$id_pelatihan			= $this->uri->segment(3);
			// print_r($id_penyakit);die();
			$this->M_pegawai->deletePelatihan($id_pelatihan);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Data riwayat pelatihan Anda berhasil dihapus!</p>
						</center>
					</div>');
					redirect('Pegawai/pendidikan');
		}
		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('Login');
		}
	}
	
	public function prestasiAdd()
	{
		if($this->session->userdata('pegawai'))
		{
			$session_data		= $this->session->userdata('pegawai');
			$id_pegawai			= $session_data['id'];
			$data['pegawai']	= $this->M_pegawai->getPegawai($id_pegawai);
			// print_r($data['gaji']);die();
			$this->load->view('prestasiAdd',$data);
		}
		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('Login');
		}
	}
	
	public function prestasiAddExec()
	{
		if($this->session->userdata('pegawai'))
		{
			$session_data			= $this->session->userdata('pegawai');
			$data['id_pegawai']		= $session_data['id'];
			$data['kegiatan']		= $this->input->post('kegiatan');
			$data['prestasi']		= $this->input->post('prestasi');
			$data['tingkat']		= $this->input->post('tingkat');
			$data['tahun']			= $this->input->post('tahun');
			$this->M_pegawai->addPrestasi($data);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Data riwayat prestasi Anda berhasil ditambah!</p>
						</center>
					</div>');
			redirect('Pegawai/pendidikan');
		}
		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('Login');
		}
	}
	
	public function prestasiEdit()
	{
		if($this->session->userdata('pegawai'))
		{
			$id_prestasi		= $this->uri->segment(3);
			$data['prestasi']	= $this->M_pegawai->getPrestasiDetail($id_prestasi);
			// print_r($data['penyakit']);die();
			$this->load->view('prestasiEdit',$data);
		}
		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('Login');
		}
	}
	
	public function prestasiEditExec()
	{
		if($this->session->userdata('pegawai'))
		{
			$id_prestasi			= $this->input->post('id_prestasi');
			$data['kegiatan']		= $this->input->post('kegiatan');
			$data['prestasi']		= $this->input->post('prestasi');
			$data['tingkat']		= $this->input->post('tingkat');
			$data['tahun']			= $this->input->post('tahun');
			$this->M_pegawai->updatePrestasi($id_prestasi,$data);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Data riwayat prestasi Anda berhasil diubah!</p>
						</center>
					</div>');
			redirect('Pegawai/pendidikan');
		}
		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('Login');
		}
	}
	
	public function prestasiDelete()
	{
		if($this->session->userdata('pegawai'))
		{
			$id_prestasi		= $this->uri->segment(3);
			// print_r($id_penyakit);die();
			$this->M_pegawai->deletePrestasi($id_prestasi);
			$this->session->set_flashdata('msg', 
					'<div class="alert alert-success">
						<center>
							<p>Data riwayat prestasi Anda berhasil dihapus!</p>
						</center>
					</div>');
			redirect('Pegawai/pendidikan');
		}
		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('Login');
		}
	}
	
	public function downloadcv()
	{
		if($this->session->userdata('pegawai'))
		{
			$session_data		= $this->session->userdata('pegawai');
			$data['id_pegawai']	= $session_data['id'];
			$data['pegawai']	= $this->M_pegawai->getPegawai($data['id_pegawai']);
			$data['kepegawaian']= $this->M_pegawai->getKepegawaian($data['id_pegawai']);
			$data['gaji']		= $this->M_pegawai->getGajiPegawai($data['id_pegawai']);
			$data['keluarga']	= $this->M_pegawai->getKeluarga($data['id_pegawai']);
			$data['penyakit']	= $this->M_pegawai->getPenyakit($data['id_pegawai']);
			$data['pendidikan']	= $this->M_pegawai->getPendidikan($data['id_pegawai']);
			$data['pelatihan']	= $this->M_pegawai->getPelatihan($data['id_pegawai']);
			$data['prestasi']	= $this->M_pegawai->getPrestasi($data['id_pegawai']);
			$data['jabatan']	= $this->M_pegawai->getJabatan($data['id_pegawai']);
			$this->load->library('pdfgenerator');
			$file_pdf = 'Curriculum Vitae - '.$data['pegawai']->nama;
			$paper = 'A4';
			$orientation = "portrait";
			$html = $this->load->view('curriculumVitae',$data, true);
			$this->pdfgenerator->generate($html, $file_pdf,$paper,$orientation);
		}
		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('Login');
		}
	}
}
