<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/mahasiswa/business/AppMahasiswa.class.php';
require_once GTFWConfiguration::GetValue('application', 'docroot') . 'main/function/date.php';

class ViewDaftarMahasiswaDataInduk extends XlsResponse{
   var $mWorksheets = array('Data');
   
   function GetFileName() {
      // name it whatever you want
      return 'DaftarMahasiswaFormatDataInduk.xls';
   }
function ProcessRequest(){
      $mhsObj=new AppMahasiswa ();
      
      $tahunMasuk=$_SESSION['tahunMasuk'];
      $isCalon=$_SESSION['isCalon'];
      $notes_nim=$_SESSION['notes_nim'];
      $semsMasuk=$_SESSION['semsMasuk'];
      $prodi=$_SESSION['prodi'];
      $nama=$_SESSION['nama'];
      //print_r($_SESSION);exit;
           
      if($prodi=='all'){
         $prodi='';
         $prodiCtk='Semua';
      }
      
      if($tahunMasuk=='all'){
         $tahunMasuk='';
      }   
      if($semsMasuk=='all'){
         $semsMasuk='';
      }      
      
      if($isCalon=='all'){
         $isCalon='';
      }
      if(($tahunMasuk=='') or ($semsMasuk='')){
         $periode='semua';
      }else{
         $periode=$semsMasuk.' '.$tahunMasuk.'/'.$tahunMasuk + 1;
      }
      $dataDaftarMhs=$mhsObj->GetPrintMahasiswaDataInduk($tahunMasuk,$notes_nim,$isCalon,$prodi,$nama,$semsMasuk);
      
      //print_r($dataDaftarMhs);exit;
      $periodeAktif=$mhsObj->GetPeriodeAktif();
      $tahunAktif=$mhsObj->GetTahunPeriodeAktif();
      
      if(empty($dataDaftarMhs)){
         $this->mWorksheets['Data']->write(0, 0, 'Tidak Ada Data');
      }else{
         //$worksheet =$this->mrWorkbook->add_worksheet();
      
         $h1 = $this->mrWorkbook->add_format();
         $h1->set_bold();
         $h1->set_size(14);
         $h1->set_align('vcenter');
         
         $h2 = $this->mrWorkbook->add_format();
         $h2->set_bold();
         $h2->set_size(12);
         $h2->set_align('center');
         $h2->set_align('vcenter');
         
         $h3 = $this->mrWorkbook->add_format();
         $h3->set_bold();
         $h3->set_size(11);
         $h3->set_align('center');
         $h3->set_align('vcenter');
         
         $strong = $this->mrWorkbook->add_format();
         $strong->set_bold();
         
         $sign = $this->mrWorkbook->add_format();
         $sign->set_size(10);
         $sign->set_align('center');
         
         $left = $this->mrWorkbook->add_format();
         $left->set_size(10);
         $left->set_align('left');
         
         #set colom
         $th = $this->mrWorkbook->add_format();
         $th->set_border(1);
         $th->set_bold();
         $th->set_size(10);
         $th->set_align('center');
         $th->set_align('vcenter');
         $th->set_text_wrap();
         
         
         $td = $this->mrWorkbook->add_format();
         $td->set_border(1);
         $td->set_size(10);         
         $td->set_align('left');         
         $td->set_text_wrap();
         
         $tdTop = $this->mrWorkbook->add_format();
         $tdTop->set_left(1);
         $tdTop->set_right(1);
         $tdTop->set_top(1);
         $tdTop->set_size(10);         
         $tdTop->set_align('left');
         $tdTop->set_text_wrap();
         
         $tdMid = $this->mrWorkbook->add_format();
         $tdMid->set_left(1);
         $tdMid->set_right(1);
         $tdMid->set_size(10);         
         $tdMid->set_align('left'); 
         
         $tdCenter = $this->mrWorkbook->add_format();
         $tdCenter->set_border(1);
         $tdCenter->set_size(10);         
         $tdCenter->set_align('center');         
         
         $tdMidCenter = $this->mrWorkbook->add_format();
         $tdMidCenter->set_left(1);
         $tdMidCenter->set_right(1);
         $tdMidCenter->set_size(10);         
         $tdMidCenter->set_align('center');         
         $tdMidCenter->set_text_wrap();  
         
         $tdBtmCenter = $this->mrWorkbook->add_format();
         $tdBtmCenter->set_left(1);
         $tdBtmCenter->set_right(1);
         $tdBtmCenter->set_bottom(1);
         $tdBtmCenter->set_size(10);         
         $tdBtmCenter->set_align('center'); 
         $tdBtmCenter->set_text_wrap();
         
         $tdTopCenter = $this->mrWorkbook->add_format();
         $tdTopCenter->set_left(1);
         $tdTopCenter->set_right(1);
         $tdTopCenter->set_top(1);
         $tdTopCenter->set_size(10);         
         $tdTopCenter->set_align('center');
         $tdTopCenter->set_text_wrap();
                 
         
         $tdRight = $this->mrWorkbook->add_format();
         $tdRight->set_border(1);
         $tdRight->set_size(10);         
         $tdRight->set_align('right');
         $tdRight->set_text_wrap();
         
         $tdValueMid = $this->mrWorkbook->add_format();
         $tdValueMid->set_left(1);
         $tdValueMid->set_right(1);
         $tdValueMid->set_size(7);         
         $tdValueMid->set_align('center');   
         
         $tdValueBtm = $this->mrWorkbook->add_format();
         $tdValueBtm->set_left(1);
         $tdValueBtm->set_right(1);
         $tdValueBtm->set_bottom(1);
         $tdValueBtm->set_size(7);         
         $tdValueBtm->set_align('center');  
         

            
         $this->mWorksheets['Data']->set_column(0, 0, 4);
         $this->mWorksheets['Data']->set_column(1, 1, 15);
         $this->mWorksheets['Data']->set_column(2, 2, 25);
         $this->mWorksheets['Data']->set_column(3, 3, 5);
         $this->mWorksheets['Data']->set_column(4, 4, 20);
         $this->mWorksheets['Data']->set_column(5, 5, 20);
         $this->mWorksheets['Data']->set_column(6, 6,30);
         $this->mWorksheets['Data']->set_column(7, 7, 20);
         #set header
         $row = 0;
         $this->mWorksheets['Data']->write($row, 0, GTFWConfiguration::GetValue('organization', 'company_name'), $h1);
         $this->mWorksheets['Data']->merge_cells($row, 0, 1, 7);
         
         $row+=3;
         $this->mWorksheets['Data']->write($row, 0, 'DAFTAR MAHASISWA FORMAT DATA INDUK', $h2);
         $this->mWorksheets['Data']->merge_cells($row, 0, $row, 7);
         $row++;
         
         $this->mWorksheets['Data']->write($row, 0, $periodeAktif .' '.$tahunAktif , $h3);
         $this->mWorksheets['Data']->merge_cells($row, 0, $row, 7);
         $row++;
    
         $row+=1;
         $this->mWorksheets['Data']->write($row, 0, 'Periode Masuk', '');
         $this->mWorksheets['Data']->merge_cells($row, 0, $row, 1);
         $this->mWorksheets['Data']->write($row, 2, ':'.$periode, '');
         $this->mWorksheets['Data']->merge_cells($row, 2, $row, 4);
         $row++;
         
         $this->mWorksheets['Data']->write($row, 0, 'Program Studi', '');
         $this->mWorksheets['Data']->merge_cells($row, 0, $row, 1);
         $this->mWorksheets['Data']->write($row, 2, ': '.$prodiCtk, '');
         $this->mWorksheets['Data']->merge_cells($row, 2, $row, 5);
         $row++;
         
                  //set header
         $row+=2;

         $this->mWorksheets['Data']->write($row, 0, 'NO', $th);
         $this->mWorksheets['Data']->write($row, 1, '', $th);
         $this->mWorksheets['Data']->merge_cells($row, 0, $row,1);
         

         $this->mWorksheets['Data']->write($row+1, 0, 'Urut', $th);
         $this->mWorksheets['Data']->write($row+1, 1, 'Induk', $th);
        
         $this->mWorksheets['Data']->write($row, 2, 'N A M A', $th);
         $this->mWorksheets['Data']->write($row+1, 2, '', $th);
         $this->mWorksheets['Data']->merge_cells($row, 2, $row+1, 2);
         
         $this->mWorksheets['Data']->write($row, 3, 'JKL', $th);
         $this->mWorksheets['Data']->write($row+1, 3, '', $th);
         $this->mWorksheets['Data']->merge_cells($row, 3, $row+1, 3);
      
         $this->mWorksheets['Data']->write($row, 4, 'Tempat/Tanggal Lahir', $th);
         $this->mWorksheets['Data']->write($row+1, 4, '', $th);
         $this->mWorksheets['Data']->merge_cells($row, 4, $row+1, 4);

         $this->mWorksheets['Data']->write($row, 5, 'Orang Tua', $th);
         $this->mWorksheets['Data']->write($row+1, 5, '', $th);
         $this->mWorksheets['Data']->merge_cells($row, 5, $row+1, 5);
         
         $this->mWorksheets['Data']->write($row, 6, 'Alamat Asal', $th);
         $this->mWorksheets['Data']->write($row+1, 6, '', $th);
         $this->mWorksheets['Data']->merge_cells($row, 6, $row+1, 6);

         
         $this->mWorksheets['Data']->write($row, 7, 'Asal Sekolah', $th);
         $this->mWorksheets['Data']->write($row+1, 7, '', $th);
         $this->mWorksheets['Data']->merge_cells($row, 7, $row+1, 7);

         $row=$row+2;
         for($i=0;$i<count($dataDaftarMhs);$i++){

            #start Kolom Urut
            $no=$i+1;
            $this->mWorksheets['Data']->write($row, 0,$no , $tdTopCenter);
            for($j=1;$j<10;$j++)
               $this->mWorksheets['Data']->write($row+$j, 0,'' , $tdMidCenter);
            
            $this->mWorksheets['Data']->write($row+10, 0,'' , $tdBtmCenter); 
            #end Kolom Urut

            #start Kolom Induk
            $this->mWorksheets['Data']->write($row, 1, $dataDaftarMhs[$i]['mhs_nim'], $tdTopCenter);
            for ($j=1;$j<10;$j++)
               $this->mWorksheets['Data']->write($row+$j, 1, '', $tdMidCenter);
            
            $this->mWorksheets['Data']->write($row+10, 1,'' , $tdBtmCenter); 
            #end kolom induk
            
            #start Kolom Nama
            $this->mWorksheets['Data']->write($row, 2, $dataDaftarMhs[$i]['mhs_nama'], $tdTopCenter);
            
            for ($j=1;$j<10;$j++)             
               $this->mWorksheets['Data']->write($row+$j, 2, '', $tdMidCenter);

            $this->mWorksheets['Data']->write($row+10, 2,'' , $tdBtmCenter); 
            #End Kolom Nama
            
            #start Kolom Jenis Kelamin
            $this->mWorksheets['Data']->write($row, 3, $dataDaftarMhs[$i]['mhs_jkl'], $tdTopCenter);

            
            for ($j=1;$j<10;$j++)
               $this->mWorksheets['Data']->write($row+$j, 3, '', $tdMidCenter);
            
            $this->mWorksheets['Data']->write($row+10, 3,'' , $tdBtmCenter); 
            #end kolom jenis Kelamin
            
            #start Kolom Tgl lahir
            $this->mWorksheets['Data']->write($row, 4, $dataDaftarMhs[$i]['mhs_tmpt_lhr'], $tdTopCenter);
            $this->mWorksheets['Data']->write($row+1, 4, '', $tdMidCenter);
            $this->mWorksheets['Data']->write($row+2, 4, ConvertDate($dataDaftarMhs[$i]['mhs_tgl_lhr'],"YYYY-MM-DD","DD-MM-YYYY"), $tdMidCenter);

            for($j=3;$j<10;$j++)
               $this->mWorksheets['Data']->write($row+$j, 4, '', $tdMidCenter);
            
            $this->mWorksheets['Data']->write($row+10, 4,'' , $tdBtmCenter); 
            #end kolom tgl lahir
            
            #start kolom Orang Tua
            $this->mWorksheets['Data']->write($row, 5, 'NAMA:', $tdTopCenter);
            $this->mWorksheets['Data']->write($row+1, 5, $dataDaftarMhs[$i]['nama_ortu'], $tdValueMid);
            
            $this->mWorksheets['Data']->write($row+2, 5, '', $tdMidCenter);

            $this->mWorksheets['Data']->write($row+3, 5, 'PEKERJAAN:', $tdMidCenter);
            $this->mWorksheets['Data']->write($row+4, 5, $dataDaftarMhs[$i]['pekerjaan_ortu'], $tdValueMid);
            
            $this->mWorksheets['Data']->write($row+5, 5, '', $tdMiddleCenter);
            
 
            $this->mWorksheets['Data']->write($row+6, 5, 'PENGHASILAN:', $tdMidCenter);
            $this->mWorksheets['Data']->write($row+7, 5, $dataDaftarMhs[$i]['penghasilan_ortu'], $tdValueMid);


            $this->mWorksheets['Data']->write($row+8, 5, '', $tdMiddleCenter);

            $this->mWorksheets['Data']->write($row+9, 5, 'PENDIDIKAN:', $tdMidCenter);
            $this->mWorksheets['Data']->write($row+10, 5, $dataDaftarMhs[$i]['pendidikan_ortu'], $tdValueBtm);
            # End Kolom Orang Tua
            
            #START Kolom ALamat Asal
            $this->mWorksheets['Data']->write($row, 6, $dataDaftarMhs[$i]['mhs_alamat'], $tdTop);
            $this->mWorksheets['Data']->write($row+1, 6, 'KAB/KOTA. '.$dataDaftarMhs[$i]['mhs_kota'], $tdMid);
            $this->mWorksheets['Data']->write($row+2, 6, 'PROP. '.$dataDaftarMhs[$i]['mhs_prop'], $tdMid);          
            $this->mWorksheets['Data']->write($row+3, 6, 'KODE POS:'. $dataDaftarMhs[$i]['mhs_kode_pos'], $tdMid);
            $this->mWorksheets['Data']->write($row+4, 6, 'NO_TELP '. $dataDaftarMhs[$i]['mhs_telp'], $tdMid);          
            
            for($j=5;$j<10;$j++)   
               $this->mWorksheets['Data']->write($row+$j, 6, '', $tdMid);          
                      
            $this->mWorksheets['Data']->write($row+10, 6,'' , $tdBtmCenter); 
            #End Alamat Asal
            
            #start Asal Sekolah
            $this->mWorksheets['Data']->write($row, 7, $dataDaftarMhs[$i]['jenis_smta'], $tdTopCenter);
            $this->mWorksheets['Data']->write($row+1, 7, $dataDaftarMhs[$i]['jurusan_smta'], $tdValueMid);

            $this->mWorksheets['Data']->write($row+2, 7, '', $tdMidCenter);

            $this->mWorksheets['Data']->write($row+3, 7,'MASUK UIN MELALUI UJIAN:', $tdMidCenter);
            $this->mWorksheets['Data']->write($row+4, 7, $dataDaftarMhs[$i]['jalur_masuk'], $tdMidCenter);
            
            for ($j=5;$j<10;$j++)
               $this->mWorksheets['Data']->write($row+$j, 7, '', $tdMidCenter);          
            
            $this->mWorksheets['Data']->write($row+10, 7, '', $tdBtmCenter);          
            #end asal Sekolah
         $row=$row+11;
         }
      }
   }
}