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

	class M_daftar extends CI_Model

	{

		function __construct()

		{

			parent::__construct();

			

		}



		//-------------------------------search-----------------------------------------------------------



		//-------------------------------search end-------------------------------------------------------



		function login($nik,$password)

		{

			$this->db->select('*');

			$this->db->from('calon_siswa');

			$this->db->where('nik',$nik);

			$this->db->where('password',$password);

			return $this->db->get();

		}

		

		function cekNIK($nik)

		{

			$this->db->select('*');

			$this->db->from('calon_siswa');

			$this->db->where('nik',$nik);

			return $this->db->get()->row();

		}

		

		function addCalonSiswa($data)

		{

			return $this->db->insert('calon_siswa',$data);

		}

		

		function addCalonSiswaTes($data2)

		{

			return $this->db->insert('mahasiswa',$data2);

		}

		

		function addPrestasi($data)

		{

			return $this->db->insert('prestasi',$data);

		}

		

		function getCalonSiswa($id_calon_siswa)

		{

			$this->db->select('*');

			$this->db->from('calon_siswa');

			$this->db->where('id_calon_siswa',$id_calon_siswa);

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->row();	

			}

			else

			{

				return array();	

			}

		}
		
		
		function getMahasiswaID($id_calon_siswa)

		{

			$this->db->select('*');

			$this->db->from('calon_siswa');
			$this->db->join('mahasiswa', 'calon_siswa.nomor_pendaftaran = mahasiswa.nim', 'left');
            $this->db->join('h_ujian', 'mahasiswa.id_mahasiswa = h_ujian.mahasiswa_id', 'left');
			$this->db->where('calon_siswa.id_calon_siswa',$id_calon_siswa);

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->row();	

			}

			else

			{

				return array();	

			}

		}

		

		function getCalonSiswaRaport($id_calon_siswa)

		{

			$this->db->select('*');

			$this->db->from('calon_siswa');

			$this->db->join('nilai_raport', 'calon_siswa.id_calon_siswa = nilai_raport.id_calon_siswa', 'left');

			$this->db->where('calon_siswa.id_calon_siswa',$id_calon_siswa);

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->row();	

			}

			else

			{

				return array();	

			}

		}

		

		function getCalonSiswaExcel()

		{

			date_default_timezone_set('Asia/Jakarta');

			$awal_tahun = date('Y')."-01-01";

			// print_r($awal_tahun);die();

			$this->db->select('*');

			$this->db->from('calon_siswa');

			$this->db->join('jurusanku', 'calon_siswa.id_jurusan = jurusanku.id_jurusan', 'left');

			$this->db->join('nilai_raport', 'calon_siswa.id_calon_siswa = nilai_raport.id_calon_siswa', 'left');

			$this->db->join('status', 'calon_siswa.id_status = status.id_status', 'left');

			$this->db->where('calon_siswa.tanggal_daftar >=',$awal_tahun);

			$this->db->order_by('calon_siswa.id_status','desc');

			$this->db->order_by('tanggal_submit','asc');

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}

		
		
		function resetUjianSiswa($id_calon_siswa)

		{

			$this->db->from('h_ujian a');
            $this->db->join('mahasiswa b', 'a.mahasiswa_id = b.id_mahasiswa');
            $this->db->join('calon_siswa c', 'b.nim = c.nomor_pendaftaran');
            $this->db->where('c.id_calon_siswa', $id_calon_siswa);

            return $this->db->delete('a');

		}
		

		function deleteCalonSiswa($id_calon_siswa)

		{

			$this->db->where('id_calon_siswa',$id_calon_siswa);

			return $this->db->delete('calon_siswa');

		}

		

		function getSiswaRaport($id_calon_siswa)

		{

			$this->db->select('*');

			$this->db->from('nilai_raport');

			$this->db->where('id_calon_siswa',$id_calon_siswa);

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->row();	

			}

			else

			{

				return array();	

			}

		}

		

		function getTenggat()

		{

			$this->db->select('*');

			$this->db->from('tenggat');

			$this->db->where('id_tenggat',1);

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->row();	

			}

			else

			{

				return array();	

			}

		}

		

		function updateTenggat($data)

		{

			$this->db->where('id_tenggat',1);

			return $this->db->update('tenggat',$data);

		}

		

		function getSiswaJurusan($id_calon_siswa)

		{

			$this->db->select('*');

			$this->db->from('calon_siswa');

			$this->db->join('jurusanku', 'calon_siswa.id_jurusan = jurusanku.id_jurusan', 'left');

			$this->db->where('calon_siswa.id_calon_siswa',$id_calon_siswa);

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->row();	

			}

			else

			{

				return array();	

			}

		}

		

		function getCalonSiswaJurusanStatus($tahun)

		{

			$this->db->select('calon_siswa.id_calon_siswa,calon_siswa.nama,calon_siswa.nomor_pendaftaran,calon_siswa.asal_sekolah,calon_siswa.id_jurusan,calon_siswa.id_jurusan2,calon_siswa.id_jurusan_diterima,calon_siswa.id_status,jurusanku.jurusan,calon_siswa.hasil_wawancara,status.status,calon_siswa.tanggal_daftar,calon_siswa.tanggal_submit');

			$this->db->from('calon_siswa');

			$this->db->join('jurusanku', 'calon_siswa.id_jurusan = jurusanku.id_jurusan', 'left');

			$this->db->join('status', 'calon_siswa.id_status = status.id_status', 'left');

			$this->db->like('tanggal_daftar',$tahun,'after');

			//$this->db->where('calon_siswa.id_status',2);

			//$this->db->or_where('calon_siswa.id_status',1);

			$this->db->order_by('id_status','desc');

			$this->db->order_by('tanggal_submit','asc');

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}



		//-----------------------------------------------new-------------------------------------------



		function getJumlahCalon1($tahun)

		{

			$this->db->select('count(*) as jc1');

			$this->db->from('calon_siswa');

			$this->db->like('tanggal_daftar',$tahun,'after');

			//$this->db->like('id_status',2);

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}

		function getJumlahCalon2a($tahun)

		{

			$this->db->select('count(*) as jc2a');

			$this->db->from('calon_siswa');

			$this->db->like('tanggal_daftar',$tahun,'after');

			$this->db->where('id_status >',1);

			$this->db->where('jen_kel','L');

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}

		function getJumlahCalon2b($tahun)

		{

			$this->db->select('count(*) as jc2b');

			$this->db->from('calon_siswa');

			$this->db->like('tanggal_daftar',$tahun,'after');

			$this->db->where('id_status >',1);

			$this->db->where('jen_kel','P');

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}

		function getJumlahCalon3a($tahun)

		{

			$this->db->select('count(*) as jc3a');

			$this->db->from('calon_siswa');

			$this->db->like('tanggal_daftar',$tahun,'after');

			$this->db->where('id_status >',1);

			$this->db->where('kode_asal_sekolah','S');

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}	

		function getJumlahCalon3b($tahun)

		{

			$this->db->select('count(*) as jc3b');

			$this->db->from('calon_siswa');

			$this->db->like('tanggal_daftar',$tahun,'after');

			$this->db->where('id_status >',1);

			$this->db->where('kode_asal_sekolah','M');

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}

		function getJumlahCalon4a($tahun)

		{

			$this->db->select('count(*) as jc4a');

			$this->db->from('calon_siswa');

			$this->db->like('tanggal_daftar',$tahun,'after');

			$this->db->where('id_status >',1);

			$this->db->where('id_jurusan =',38);

			$this->db->where('jen_kel','L');

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}

		function getJumlahCalon4b($tahun)

		{

			$this->db->select('count(*) as jc4b');

			$this->db->from('calon_siswa');

			$this->db->like('tanggal_daftar',$tahun,'after');

			$this->db->where('id_status >',1);

			$this->db->where('id_jurusan =',38);

			$this->db->where('jen_kel','P');

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}

		function getJumlahCalon5($tahun)

		{

			$this->db->select('count(*) as jc5');

			$this->db->from('calon_siswa');

			$this->db->like('tanggal_daftar',$tahun,'after');

			$this->db->where('id_status >',1);

			$this->db->where('id_jurusan =',39);

			//$this->db->where('jen_kel','P');

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}

		function getJumlahCalon6($tahun)

		{

			$this->db->select('count(*) as jc6');

			$this->db->from('calon_siswa');

			$this->db->like('tanggal_daftar',$tahun,'after');

			$this->db->where('id_status >',1);

			$this->db->where('id_jurusan =',40);

			

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}

		function getJumlahCalon7($tahun)

		{

			$this->db->select('count(*) as jc7');

			$this->db->from('calon_siswa');

			$this->db->like('tanggal_daftar',$tahun,'after');

			$this->db->where('id_status >',1);

			$this->db->where('id_jurusan =',41);

			

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}

		function getJumlahCalon8($tahun)

		{

			$this->db->select('count(*) as jc8');

			$this->db->from('calon_siswa');

			$this->db->like('tanggal_daftar',$tahun,'after');

			$this->db->where('id_status >',1);

			$this->db->where('id_jurusan =',42);

			

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}

		function getJumlahCalon2c($tahun)

		{

			$this->db->select('count(*) as jc2c');

			$this->db->from('calon_siswa');

			$this->db->like('tanggal_daftar',$tahun,'after');

			$this->db->where('id_status >',1);

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}

		function getJumlahCalon4c($tahun)

		{

			$this->db->select('count(*) as jc4c');

			$this->db->from('calon_siswa');

			$this->db->like('tanggal_daftar',$tahun,'after');

			$this->db->where('id_status >',1);

			$this->db->where('id_jurusan =',38);

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}			

		//---------------------------------------------------------------------------------------------

		

		function getCalonSiswaJurusan($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 getBerkas($id_calon_siswa)

		{

			$this->db->select('*');

			$this->db->from('berkas');

			$this->db->join('kategori_berkas', 'berkas.id_kategori_berkas = kategori_berkas.id_kategori_berkas', 'left');

			$this->db->where('berkas.id_calon_siswa',$id_calon_siswa);

			$this->db->order_by('berkas.id_kategori_berkas', 'asc');

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}

		

		function getKelasTerakhir()

		{

			$this->db->select('*');

			$this->db->from('kelas');

			$this->db->order_by('id_kelas', 'desc');

			$this->db->limit(1);

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->row();	

			}

			else

			{

				return array();	

			}

		}

		

		function addBerkas($data)

		{

			return $this->db->insert('berkas',$data);

		}

		

		function getBerkasDetail($id_berkas)

		{

			$this->db->select('*');

			$this->db->from('berkas');

			$this->db->where('id_berkas',$id_berkas);

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->row();	

			}

			else

			{

				return array();	

			}

		}

		

		function deleteBerkas($id_berkas)

		{

			$this->db->where('id_berkas',$id_berkas);

			return $this->db->delete('berkas');

		}

		

		function getKategoriBerkas()

		{

			$this->db->select('*');

			$this->db->from('kategori_berkas');

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}

		

		function cekAkta($id_calon_siswa)

		{

			$this->db->select('*');

			$this->db->from('berkas');

			$this->db->where('id_calon_siswa',$id_calon_siswa);

			$this->db->where('id_kategori_berkas',1);

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}

		

		function cekKK($id_calon_siswa)

		{

			$this->db->select('*');

			$this->db->from('berkas');

			$this->db->where('id_calon_siswa',$id_calon_siswa);

			$this->db->where('id_kategori_berkas',2);

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}

		

		function cekRaportSem1($id_calon_siswa)

		{

			$this->db->select('*');

			$this->db->from('berkas');

			$this->db->where('id_calon_siswa',$id_calon_siswa);

			$this->db->where('id_kategori_berkas',3);

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}
			else

			{

				return array();	

			}

		}

		

		function cekRaportSem2($id_calon_siswa)

		{

			$this->db->select('*');

			$this->db->from('berkas');

			$this->db->where('id_calon_siswa',$id_calon_siswa);

			$this->db->where('id_kategori_berkas',4);

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}

		

		function cekRaportSem3($id_calon_siswa)

		{

			$this->db->select('*');

			$this->db->from('berkas');

			$this->db->where('id_calon_siswa',$id_calon_siswa);

			$this->db->where('id_kategori_berkas',5);

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}

		

		function cekRaportSem4($id_calon_siswa)

		{

			$this->db->select('*');

			$this->db->from('berkas');

			$this->db->where('id_calon_siswa',$id_calon_siswa);

			$this->db->where('id_kategori_berkas',6);

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}

		

		function cekRaportSem5($id_calon_siswa)

		{

			$this->db->select('*');

			$this->db->from('berkas');

			$this->db->where('id_calon_siswa',$id_calon_siswa);

			$this->db->where('id_kategori_berkas',7);

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}

		function cekSKS($id_calon_siswa)

		{

			$this->db->select('*');

			$this->db->from('berkas');

			$this->db->where('id_calon_siswa',$id_calon_siswa);

			$this->db->where('id_kategori_berkas',8);

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}

		function cekSPBN($id_calon_siswa)

		{

			$this->db->select('*');

			$this->db->from('berkas');

			$this->db->where('id_calon_siswa',$id_calon_siswa);

			$this->db->where('id_kategori_berkas',9);

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}

		

		function getPrestasi($id_calon_siswa)

		{

			$this->db->select('*');

			$this->db->from('prestasi');

			$this->db->join('calon_siswa', 'calon_siswa.id_calon_siswa = prestasi.id_calon_siswa', 'left');

			$this->db->where('prestasi.id_calon_siswa',$id_calon_siswa);

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}

		

		function getPrestasiDetail($id_prestasi)

		{

			$this->db->select('*');

			$this->db->from('prestasi');

			$this->db->where('id_prestasi',$id_prestasi);

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->row();

			}

			else

			{

				return array();	

			}

		}

		

		function updatePrestasi($id_prestasi,$data)

		{

			$this->db->where('id_prestasi',$id_prestasi);

			return $this->db->update('prestasi',$data);

		}

		

		function deletePrestasi($id_prestasi)

		{

			$this->db->where('id_prestasi',$id_prestasi);

			return $this->db->delete('prestasi');

		}

		

		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 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 getJurusanAktif()

		{

			$this->db->select('*');

			$this->db->from('jurusanku');

			$this->db->where('status','Aktif');

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->result_array();	

			}

			else

			{

				return array();	

			}

		}

		

		function getAntrian($tahun)

		{

			$this->db->select('*');

			$this->db->from('antrian');

			$this->db->where('tahun',$tahun);

			$result = $this->db->get();

			if ($result->num_rows() > 0 )

			{

				return $result->row();	

			}

			else

			{

				return array();	

			}

		}

		

		function updateAntrian($tahun,$data)

		{

			$this->db->where('tahun',$tahun);

			return $this->db->update('antrian',$data);

		}

		

		function updateCalonSiswa($id_calon_siswa,$data)

		{

			$this->db->where('id_calon_siswa',$id_calon_siswa);

			return $this->db->update('calon_siswa',$data);

		}

		

		function addNilaiRaport($data)

		{

			return $this->db->insert('nilai_raport',$data);

		}

		

		function updateNilaiRaport($id_calon_siswa,$data)

		{

			$this->db->where('id_calon_siswa',$id_calon_siswa);

			return $this->db->update('nilai_raport',$data);

		}

	}

