<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
	class M_admin extends CI_Model
	{
		function __construct()
		{
			parent::__construct();
		}
		
		function login($email,$password)
		{
			$this->db->select('*');
			$this->db->from('admin');
			$this->db->where('email',$email);
			$this->db->where('password',$password);
			$result =  $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->row();	
			}
			else
			{
				return array();	
			}
		}
		
		function getJurusan()
		{
			$this->db->select('*');
			$this->db->from('jurusanku');
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->result_array();	
			}
			else
			{
				return array();	
			}
		}
		
		function addJurusan($data)
		{
			return $this->db->insert('jurusanku',$data);
		}
		
		function getJurusanDetail($id_jurusan)
		{
			$this->db->select('*');
			$this->db->from('jurusanku');
			$this->db->where('id_jurusan',$id_jurusan);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->row();	
			}
			else
			{
				return array();	
			}
		}
		
		function updateJurusan($id_jurusan,$data)
		{
			$this->db->where('id_jurusan',$id_jurusan);
			return $this->db->update('jurusanku',$data);
		}
		
		function deleteJurusan($id_jurusan)
		{
			$this->db->delete('jurusanku', array('id_jurusan' => $id_jurusan));
		}
		
		function getPertanyaan()
		{
			$this->db->select('*');
			$this->db->from('pertanyaan');
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->result_array();	
			}
			else
			{
				return array();	
			}
		}
		
		function addPertanyaan($data)
		{
			return $this->db->insert('pertanyaan',$data);
		}
		
		function getPertanyaanDetail($id_pertanyaan)
		{
			$this->db->select('*');
			$this->db->from('pertanyaan');
			$this->db->where('id_pertanyaan',$id_pertanyaan);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->row();	
			}
			else
			{
				return array();	
			}
		}
		
		function updatePertanyaan($id_pertanyaan,$data)
		{
			$this->db->where('id_pertanyaan',$id_pertanyaan);
			return $this->db->update('pertanyaan',$data);
		}
		
		function deletePertanyaan($id_pertanyaan)
		{
			$this->db->delete('pertanyaan', array('id_pertanyaan' => $id_pertanyaan));
		}
		
		function getPertanyaanSiswa($kode_jurusan)
		{
			$this->db->select('*');
			$this->db->from('pertanyaan');
			$this->db->where('kode_jurusan',$kode_jurusan);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->result_array();	
			}
			else
			{
				return array();	
			}
		}
		
		function getPilihanJawaban($id_pertanyaan)
		{
			$this->db->select('*');
			$this->db->from('pilihan_jawaban');
			$this->db->where('id_pertanyaan',$id_pertanyaan);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->result_array();	
			}
			else
			{
				return array();	
			}
		}
		
		function addPilihanJawaban($data)
		{
			return $this->db->insert('pilihan_jawaban',$data);
		}
		
		function getPilihanJawabanDetail($id_pilihan_jawaban)
		{
			$this->db->select('*');
			$this->db->from('pilihan_jawaban');
			$this->db->where('id_pilihan_jawaban',$id_pilihan_jawaban);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->row();	
			}
			else
			{
				return array();	
			}
		}
		
		function updatePilihanJawaban($id_pilihan_jawaban,$data)
		{
			$this->db->where('id_pilihan_jawaban',$id_pilihan_jawaban);
			return $this->db->update('pilihan_jawaban',$data);
		}
		
		function deletePilihanJawaban($id_pilihan_jawaban)
		{
			$this->db->delete('pilihan_jawaban', array('id_pilihan_jawaban' => $id_pilihan_jawaban));
		}
		
		function addJawaban($data)
		{
			return $this->db->insert('jawaban',$data);
		}
		
		function getCalonSiswaJawaban($id_calon_siswa)
		{
			$this->db->select('*');
			$this->db->from('jawaban');
			$this->db->join('pilihan_jawaban', 'jawaban.id_pilihan_jawaban = pilihan_jawaban.id_pilihan_jawaban', 'left');
			$this->db->where('id_calon_siswa',$id_calon_siswa);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->result_array();	
			}
			else
			{
				return array();	
			}
		}
		
		function getPewawancara()
		{
			$this->db->select('*');
			$this->db->from('admin');
			$this->db->where('role','Pewawancara');
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->result_array();	
			}
			else
			{
				return array();	
			}
		}
		
		function addPewawancara($data)
		{
			return $this->db->insert('admin',$data);
		}
		
		function getPewawancaraDetail($id_admin)
		{
			$this->db->select('*');
			$this->db->from('admin');
			$this->db->where('id_admin',$id_admin);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->row();	
			}
			else
			{
				return array();	
			}
		}
		
		function updatePewawancara($id_admin,$data)
		{
			$this->db->where('id_admin',$id_admin);
			return $this->db->update('admin',$data);
		}
		
		function deletePewawancara($id_admin)
		{
			$this->db->delete('admin', array('id_admin' => $id_admin));
		}
	}
