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

class Rep_spp_siswa extends CI_Controller {
	
	var $gparam = array();
	
	public function __construct() {
        parent::__construct();
		$this->gparam['controller'] = $this->router->fetch_class();
		$this->load->model('rep_spp_model', 'spp');
		$this->gparam['privilage'] = getPrivilage($this->gparam['controller']);
		$this->gparam['restrict'] = 'You Cannot Access This Menu';
    }
	
	public function index()	{
		
		if ($this->gparam['privilage']->privilage_view == 'Y') {
		
			$gridopt = $this->input->get(array('psize', 'pnumber'));
			header('Content-Type: text/html');
			$act = base_url()."index.php/".$this->gparam['controller']."/load_data";
			
			$excell_download = '<a class="btn btn-success" id="save_excell" href="#" >
								<i class="fa fa-lg fa-fw fa-download"></i>Excell
							  </a>';		

			
			$get_smk = $this->spp->getDataSMK();
			$nama_smk='	<select name="smk" class="chosen-select" style="width:195px;" onchange="getJurusan(this.value);cekKelas(0,0);getRuang(0,0);" >
									<option value="">--Semua Sekolah--</option>';
					
			foreach ($get_smk as $v_smk) {
				$nama_smk .='<option value="'.$v_smk['id'].'">'.$v_smk['name'].'</option>';
			}
			$nama_smk .='</select> ';
			
			
			$get_thn = $this->spp->getDataThn();
			$nama_thn='	<select name="thn" class="chosen-select" style="width:195px;" ><option value="" selected>--Tahun Ajaran--</option>';
					
			foreach ($get_thn as $v_thn) {
				//if(($v_thn['status']=='U')){
					//$nama_thn .='<option value="'.$v_thn['tahun_ajaran'].'" selected="selected">Tahun Ajaran : '.$v_thn['tahun_ajaran'].'</option>';
				//}else{
					$nama_thn .='<option value="'.$v_thn['tahun_ajaran'].'">Tahun Ajaran : '.$v_thn['tahun_ajaran'].'</option>';
				//}
				
			}
			$nama_thn .='</select> ';
			
			
			
			$mappingJur = '<div id="id-MappingJur">
					<label class="select">
						<select name="id_mapping_jur" class="chosen-select" style="width:195px;" id="id_mapping_jur">
							<option value="">--Semua Jurusan--</option>																
						</select> <i></i> 
					</label></div>';
					$kelas='<div id="id-MappingKls"><label class="select">
									<select name="kelas" style="width:195px;" class="chosen-select" onchange="getRuang(this.value);" >
									<option value="">--Semua Kelas--</option></select> <i></i> 
								</label></div>';
								
			$ruang='<div id="id-MappingRuang"><label class="select">
									<select name="ruang" style="width:195px;" class="chosen-select">
									<option value="">--Semua Ruang Kelas--</option></select> <i></i> 
								</label></div>';
								
			// pnumber, psize
			$data = array(
					'controller'  	=> $this->gparam['controller'],
					'excell' 		=> $excell_download,
					'action'		=> $act,
					'nama_smk'	=> $nama_smk,
					'ruang'	=> $ruang,
					'mappingJur'	=> $mappingJur,
					'kelas'	=> $kelas,
					'thn'	=> $nama_thn
			);
			
			$this->load->view('rep_spp_view',$data);
		} else {
			echo $this->gparam['restrict'];
		}
	}
	
	
	function load_data() {
	
		/* $periode = $this->input->post("periode");
		$until = $this->input->post("until");
	    $get_id_siswa = $this->rep_sis->get_id_siswa($peride,$until);
		 */
		
		$smk = $this->input->post("smk");
		$jur = $this->input->post("id_mapping_jur");
		$kelas = $this->input->post("kelas");
		$ruang = $this->input->post("id_mapping_ruang");
		$thn = $this->input->post("thn");
		$get_data = $this->spp->get_data($smk, $jur, $kelas, $ruang, $thn);
		//if(!empty($ruang)){
			$get_data_ppdb = $this->spp->get_data_ppdb($smk, $jur, $kelas, $ruang, $thn);
		//}
		//print_r($get_data); die();
		/*Header*/
		$html = '<table class="table table-bordered" id="activity_table"><thead><tr>';
		
		$html .='<th style="text-align:center;">No</th>';
		$html .='<th style="text-align:center;">NIS</th>';
		$html .='<th style="text-align:center;">Nama Siswa</th>';
		$html .='<th style="text-align:center;">Juli</th>';
		$html .='<th style="text-align:center;">Agustus</th>';
		$html .='<th style="text-align:center;">September</th>';
		$html .='<th style="text-align:center;">Oktober</th>';
		$html .='<th style="text-align:center;">November</th>';
		$html .='<th style="text-align:center;">Desember</th>';
		$html .='<th style="text-align:center;">Januari</th>';
		$html .='<th style="text-align:center;">Februari</th>';
		$html .='<th style="text-align:center;">Maret</th>';
		$html .='<th style="text-align:center;">April</th>';
		$html .='<th style="text-align:center;">Mei</th>';
		$html .='<th style="text-align:center;">Juni</th>';
		
		$html .= '</tr></thead>';
		$html .= '<tbody>';
		$i = 1;
		$total = 0;
		
		foreach ($get_data as $v_data) {
			
			$html .='<tr>';
			$html .='<td>'.$i.'</td>';
			$html .='<td>'.$v_data['nis'].'</td>';
			$html .='<td>'.$v_data['nama'].'</td>';
			$html .='<td>'.$v_data['July'].'</td>';
			$html .='<td>'.$v_data['August'].'</td>';
			$html .='<td>'.$v_data['September'].'</td>';
			$html .='<td>'.$v_data['October'].'</td>';
			$html .='<td>'.$v_data['November'].'</td>';
			$html .='<td>'.$v_data['December'].'</td>';
			$html .='<td>'.$v_data['January'].'</td>';
			$html .='<td>'.$v_data['February'].'</td>';
			$html .='<td>'.$v_data['March'].'</td>';
			$html .='<td>'.$v_data['April'].'</td>';
			$html .='<td>'.$v_data['May'].'</td>';
			$html .='<td>'.$v_data['June'].'</td>';
				
			$html .='</tr>';
			$i++;
		}
		
		foreach ($get_data_ppdb as $v_data_ppdb) {
			
			$html .='<tr>';
			$html .='<td>'.$i.'</td>';
			$html .='<td bgcolor="#FFCC00">'.$v_data_ppdb['nis'].'</td>';
			$html .='<td bgcolor="#FFCC00">'.$v_data_ppdb['nama'].'</td>';
			$html .='<td>'.$v_data_ppdb['July'].'</td>';
			$html .='<td>'.$v_data_ppdb['August'].'</td>';
			$html .='<td>'.$v_data_ppdb['September'].'</td>';
			$html .='<td>'.$v_data_ppdb['October'].'</td>';
			$html .='<td>'.$v_data_ppdb['November'].'</td>';
			$html .='<td>'.$v_data_ppdb['December'].'</td>';
			$html .='<td>'.$v_data_ppdb['January'].'</td>';
			$html .='<td>'.$v_data_ppdb['February'].'</td>';
			$html .='<td>'.$v_data_ppdb['March'].'</td>';
			$html .='<td>'.$v_data_ppdb['April'].'</td>';
			$html .='<td>'.$v_data_ppdb['May'].'</td>';
			$html .='<td>'.$v_data_ppdb['June'].'</td>';
				
			$html .='</tr>';
			$i++;
		}
		
		
		$html .= '</tbody>';
		$html .= '</table>';
		$html .= '<script>
					var name = "ReportingSppSiswa.xls";
					$("#save_excell").on("click", function () {
						var uri = $("#activity_table").btechco_excelexport({
						containerid: "activity_table"
						, datatype: $datatype.Table
						, returnUri: true
						});
				$(this).attr("download", name).attr("href", uri).attr("target", "_blank");
			});
		</script>';
		echo $html;
	}
	
	function getJurusan() {
		$id_smk = $this->input->post("smk");
		$options = $this->spp->getJurusan($id_smk);
	
		$html = '<label class="select">
						<select name="id_mapping_jur" style="width:195px;" class="chosen-select" id="id_mapping_jur" onchange="cekKelas('.$id_smk.',this.value);getRuang(0,0);">
							<option value="">--Semua Jurusan--</option>																
						'.$options.'
						</select> <i></i> 
					</label>';
		$html .='<script>
					$(function() {
						$(".chosen-select").chosen();
					})
				</script>';	
		echo $html;			
	}
	
	function cekKelas() {
		$id_jur = $this->input->post("id_jur");
		$id_smk = $this->input->post("id_smk");
		$options = $this->spp->cekKelas($id_smk);
		$html='<label class="select">
									<select name="kelas" style="width:195px;" class="chosen-select"  onchange="getRuang(this.value,'.$id_jur.');" >
									<option value="">--Semua Kelas--</option>'.$options.'</select> <i></i> 
								</label>';
		$html .='<script>
					$(function() {
						$(".chosen-select").chosen();
					})
				</script>';	
								
		echo $html;			
	}
	
	function getRuang(){
		$kelas = $this->input->post("kelas");
		$id_mapping_jur = $this->input->post("id_mapping_jur");
		
		$options = $this->spp->getRuang($kelas, $id_mapping_jur);
	
		$html = '<label class="select">
						<select name="id_mapping_ruang"  class="chosen-select" id="id_mapping_ruang">
							<option value="">--Semua Ruang Kelas--</option>																
						'.$options.'
						</select> <i></i> 
					</label>';
		$html .='<script>
					$(function() {
						$(".chosen-select").chosen();
					})
				</script>';	
				
		echo $html;			
	}
}
