<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/laporan_kelompok_mhs/business/AppLaporanKelompokMhs.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/laporan_kelompok_mhs/business/AppLaporanKelompokMhsSia.class.php';

class ViewLaporanKelompokMhs extends HtmlResponse{
	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/laporan_kelompok_mhs/template');
		$this->SetTemplateFile('view_laporan_kelompok_mhs.html');
	}
	
	function ProcessRequest() {
		$lapObj = new AppLaporanKelompokMhs();
		$siaObj = new AppLaporanKelompokMhsSia();
		$_GET = $_GET->AsArray();		
		
		//cek apakah proses cari?
		if(isset($_POST['btncari'])){			
			//proses cari			
			$periodeSelected = $_POST['periode'];			
			if($periodeSelected == 'all') $periodeSelected = '';
			
			$prodiSelected = $_POST['prodi'];
			if($prodiSelected == 'all') $prodiSelected = '';
			
			$dataCheckBoxSelected = $_POST['status_keluarga']->AsArray();
			if(!empty($dataCheckBoxSelected)){
				for ($i=0; $i < count($dataCheckBoxSelected); $i++) { 					
					$tempDataCheckBoxSelected[$i] = "'".$dataCheckBoxSelected[$i]."'";				
				}
				$statusKeluarga = implode(',',$tempDataCheckBoxSelected);	
				
				//hilangkan petik didepan dan belakang
				$statusKeluarga = substr($statusKeluarga,1);
				$statusKeluarga = substr($statusKeluarga,0,-1);
			}else{
				$statusKeluarga = '';
			}																		
		}else if($_GET['cari'] == 1){
			//paging cari
						
			$periodeSelected = $_GET['periode'];			
			if($periodeSelected == 'all') $periodeSelected = '';
			
			$prodiSelected = $_GET['prodi'];			
			if($prodiSelected == 'all') $prodiSelected = '';
			
			$statusKeluarga = $_GET['statuskeluarga'];
			$statusKeluarga = stripslashes($statusKeluarga);
			//strip petik2
			$temp = str_replace("'","",$statusKeluarga);
			$dataCheckBoxSelected = explode(',',$temp);
		}
		
		//proses list data (begin)
		$totalData = $lapObj->getCountDataSearch($periodeSelected,$prodiSelected,$statusKeluarga);			
		$itemViewed = 20;
		$currPage = 1;
		$startRec = 0 ;
		
		if(isset($_GET['page'])) {
			$currPage = (string)$_GET['page'];
			$startRec =($currPage-1) * $itemViewed;
		}
		
		$dataListSearch = $lapObj->getDataSearch($periodeSelected,$prodiSelected,$statusKeluarga,$startRec,$itemViewed);
		
		//ambil data dari sia
		for ($j=0; $j<sizeof($dataListSearch); $j++){
	    	$nim[$j] = $dataListSearch[$j]['nim'];
	    }	    
		if ($nim!='') $nim = implode("','",$nim);
		
		$dataListSearchSia = $siaObj->getDataSearchSia($nim);
		
		for ($j=0; $j<sizeof($dataListSearch); $j++){
			for($k=0; $k<sizeof($dataListSearchSia); $k++){
				if($dataListSearchSia[$k]['nim']==$dataListSearch[$j]['nim'])
				   $dataListSearch[$j]['status_akd'] = $dataListSearchSia[$k]['status_all'];
			}
	    }
	    
	    //url paging
	    $url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 
            Dispatcher::Instance()->mSubModule, 
            Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType . 
            '&periode=' . Dispatcher::Instance()->Encrypt($periodeSelected) . 
            '&prodi=' . Dispatcher::Instance()->Encrypt($prodiSelected) . 
            '&statuskeluarga=' . Dispatcher::Instance()->Encrypt($statusKeluarga) .             
            '&cari=' . Dispatcher::Instance()->Encrypt(1));
            
        Messenger::Instance()->SendToComponent('paging', 'Paging', 'view', 'html', 'paging_top', array($itemViewed,$totalData, $url, $currPage), Messenger::CurrentRequest);
      	//$msg = Messenger::Instance()->Receive(__file__);
            
		//proses list data (end)
		
		
		$dataPeriodeAktif = $lapObj->GetPeriodeAktif();		
		
		//combo box periode
		$dataComboPeriode = $lapObj->GetDataPeriode();		
        Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'periode',array('periode',$dataComboPeriode,$periodeSelected,'true',''), Messenger::CurrentRequest);
        
        //combo box prodi
        $dataComboProdi = $lapObj->getDataComboProdi();
        Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'prodi',
         array('prodi',$dataComboProdi,$prodiSelected,'true',''), Messenger::CurrentRequest);		
         
		//ambil list status keluarga / kelompok mahasiswa
		$dataCheckBox = $lapObj->getDataCheckStatusKeluarga();								
				
		$return['dataCheckBox'] = $dataCheckBox;		
		$return['dataCheckBoxSelected'] = $dataCheckBoxSelected;
		$return['dataPeriodeAktif'] = $dataPeriodeAktif;
		$return['dataComboPeriode'] = $dataComboPeriode;
		$return['dataListSearch'] = $dataListSearch;		
		return $return;				
	}
	
	function ParseTemplate($data = NULL) {
		$dataCheckBox = $data['dataCheckBox'];		
		$dataCheckBoxSelected = $data['dataCheckBoxSelected'];
		$dataPeriodeAktif = $data['dataPeriodeAktif'];
		$dataListSearch = $data['dataListSearch'];
		
		//url search box
		$this->mrTemplate->AddVar('content', 'URL_SEARCH', 
         Dispatcher::Instance()->GetUrl('laporan_kelompok_mhs', 'laporanKelompokMhs', 'view', 'html'));
		
		//periode
		$this->mrTemplate->SetAttribute('periode', 'visibility', 'visible');
        $this->mrTemplate->AddVars('periode', $data['dataPeriodeAktif'][0], '');				        
        
		//parse checkbox				
		for ($i=0; $i < count($dataCheckBox); $i++) {
			
			if(!empty($dataCheckBoxSelected)){				
				if(in_array($dataCheckBox[$i]['STSKLRGA_ID'],$dataCheckBoxSelected)){
					$this->mrTemplate->addVar('checkbox_status_keluarga', 'CHECK','checked="checked"');
				}else{
					$this->mrTemplate->addVar('checkbox_status_keluarga', 'CHECK','');
				}	
			}			
			 
			$this->mrTemplate->addVar('checkbox_status_keluarga', 'STSKLRGA_ID', $dataCheckBox[$i]['STSKLRGA_ID']);
			$this->mrTemplate->addVar('checkbox_status_keluarga', 'STSKLRGA_NAMA', $dataCheckBox[$i]['STSKLRGA_NAMA']);         
			$this->mrTemplate->parseTemplate('checkbox_status_keluarga', 'a');
		}
		
		//parse list data search
		if(count($dataListSearch) > 0){			
			$this->mrTemplate->addVar("list_data_search","SEARCH",1);
			
			for ($i=0; $i<sizeof($dataListSearch); $i++) {
				$no = ($i+1)+$data['start'];
				$dataListSearch[$i]['number'] = $no;
				if ($no % 2 != 0) $dataListSearch[$i]['class_name'] = 'table-common-even';
				else $dataListSearch[$i]['class_name'] = '';
								
				
				if($dataListSearch[$i]['jenis_kelamin'] == 'L'){
				   $dataListSearch[$i]['JK_TITLE'] = 'Laki-laki';
				}else{
				   $dataListSearch[$i]['JK_TITLE'] = 'Perempuan';
				}
			
				if($dataListSearch[$i]['status_reg'] == 'S'){
				   $dataListSearch[$i]['STATUS_TITLE_REG'] = 'Sudah Registrasi';
				}else{
				   $dataListSearch[$i]['STATUS_TITLE_REG'] = 'Belum Registrasi';
				}
			
				if($dataListSearch[$i]['status_mhs'] == 'CM'){
				   $dataListSearch[$i]['status_akd'] = 'N';
				   $dataListSearch[$i]['STATUS_TITLE_MHS'] = 'Calon Mahasiswa';
				   $dataListSearch[$i]['STATUS_TITLE_AKD'] = 'Non Aktif';
				}else{
				   $dataListSearch[$i]['STATUS_TITLE_MHS'] = 'Mahasiswa';
				}
			
				if($dataListSearch[$i]['status_akd'] == 'A'){
				   $dataListSearch[$i]['STATUS_TITLE_AKD'] = 'Aktif';
				}elseif($dataListSearch[$i]['status_akd'] == 'N'){
				   $dataListSearch[$i]['STATUS_TITLE_AKD'] = 'Non Aktif';
				}elseif($dataListSearch[$i]['status_akd'] == 'C'){
				   $dataListSearch[$i]['STATUS_TITLE_AKD'] = 'Cuti';
				}elseif($dataListSearch[$i]['status_akd'] == 'K'){
				   $dataListSearch[$i]['STATUS_TITLE_AKD'] = 'Keluar';
				}elseif($dataListSearch[$i]['status_akd'] == 'L'){
				   $dataListSearch[$i]['STATUS_TITLE_AKD'] = 'Lulus';
				}elseif($dataListSearch[$i]['status_akd'] == 'B'){
				   $dataListSearch[$i]['STATUS_TITLE_AKD'] = 'Blokir';
				}
			
				$dataListSearch[$i]['total_bayar'] = number_format($dataListSearch[$i]['total_bayar'], 2,',','.');					
				$this->mrTemplate->AddVars('data_search_item', $dataListSearch[$i], 'LAPORAN_');
				$this->mrTemplate->parseTemplate('data_search_item', 'a');
			}
		}
	}
}
?>