<?php
class AppCetakDokumen extends Database{
	protected $mSqlFile= 'module/cetak_dokumen/business/appcetakdokumen.sql.php';
	function __construct($connectionNumber=0) {
		parent::__construct($connectionNumber);
		
	}   
   
   function GetCountDataMahasiswaWithNim($thnMasukAwal,$thnMasukAkhir,$nim_notest,
                                         $isCalon,$programStudi,$nama,$semsMasukAwal,
                                         $semsMasukAkhir){   

      if ($semsMasukAwal=='') {
         $semsMasukAwal=1;
      }
      if ($semsMasukAkhir=='') {
         $semsMasukAkhir=2;
      }
      if ($thnMasukAwal=='') {
         $thnMasukAwal='1900';
      }
      if ($thnMasukAkhir=='') {
         $thnMasukAkhir=date('Y');
      }
      $periodeAwal = $thnMasukAwal.$semsMasukAwal;
      $periodeAkhir = $thnMasukAkhir.$semsMasukAkhir;
      //if($thnMasukAwal==''){$periodeAwal='19001';}else{$periodeAwal=$thnMasukAwal.$semsMasukAwal;}
      //if($thnMasukAkhir==''){$periodeAkhir=date('Y').'2';}else{$periodeAkhir=$thnMasukAkhir.$semsMasukAkhir;}            
                                         
      if($nim_notest==""){
      
          $new_sql="";
          
      }else{
      
         $new_sql = "AND(
         mhsNiu  LIKE '%s' OR
         mhsNomorTes LIKE '%s') ";
         
      }
      
      $sql = $this->mSqlQueries['get_count_data_mahasiswa_with_nim']. $new_sql;
      
      if($nim_notest==""){
      
         $result=$this->Open($sql,array($periodeAwal,$periodeAkhir,
                                        '%'.$isCalon.'%','%'.$programStudi.'%','%'.$nama.'%'));
                                       
      }else{
      
         $result=$this->Open($sql,array($periodeAwal,$periodeAkhir,
                                        '%'.$isCalon.'%','%'.$programStudi.'%','%'.$nama.'%',                                    
                                        '%'.$nim_notest.'%','%'.$nim_notest.'%'));
      } 
      if(!$result){
         return 0;
      }else{
         return $result[0]['total'];
      } 
   }

   function GetCountDataMahasiswaWithoutNim($thnMasukAwal,$thnMasukAkhir,$nim_notest,
                                            $isCalon,$programStudi,$nama,$semsMasukAwal,
                                            $semsMasukAkhir){

      if ($semsMasukAwal=='') {
         $semsMasukAwal=1;
      }
      if ($semsMasukAkhir=='') {
         $semsMasukAkhir=2;
      }
      if ($thnMasukAwal=='') {
         $thnMasukAwal='1900';
      }
      if ($thnMasukAkhir=='') {
         $thnMasukAkhir=date('Y');
      }
      $periodeAwal = $thnMasukAwal.$semsMasukAwal;
      $periodeAkhir = $thnMasukAkhir.$semsMasukAkhir;
      //if($thnMasukAwal==''){$periodeAwal='19001';}else{$periodeAwal=$thnMasukAwal.$semsMasukAwal;}
      //if($thnMasukAkhir==''){$periodeAkhir=date('Y').'2';}else{$periodeAkhir=$thnMasukAkhir.$semsMasukAkhir;}            
              
      if($nim_notest==""){
      
          $new_sql="";
          
      }else{
      
         $new_sql = "AND(
         mhsNiu  LIKE '%s' OR
         mhsNomorTes LIKE '%s') ";
         
      }
      
      $sql = $this->mSqlQueries['get_count_data_mahasiswa_without_nim']. $new_sql;
      
      if($nim_notest==""){
      
         $result=$this->Open($sql,array($periodeAwal,$periodeAkhir,
                                        '%'.$isCalon.'%','%'.$programStudi.'%','%'.$nama.'%'));
                                       
      }else{
      
         $result=$this->Open($sql,array($periodeAwal,$periodeAkhir,
                                        '%'.$isCalon.'%','%'.$programStudi.'%','%'.$nama.'%',                            
                                        '%'.$nim_notest.'%','%'.$nim_notest.'%'));
      } 
      //
      if(!$result){
         return 0;
      }else{
         return $result[0]['total'];
      } 
   }

   function GetDataMahasiswaWithNim($thnMasukAwal,$thnMasukAkhir,$nim_notest,
                                    $isCalon,$programStudi,$nama,$semsMasukAwal,
                                    $semsMasukAkhir,$offset,$limit){

      if ($semsMasukAwal=='') {
         $semsMasukAwal=1;
      }
      if ($semsMasukAkhir=='') {
         $semsMasukAkhir=2;
      }
      if ($thnMasukAwal=='') {
         $thnMasukAwal='1900';
      }
      if ($thnMasukAkhir=='') {
         $thnMasukAkhir=date('Y');
      }
      $periodeAwal = $thnMasukAwal.$semsMasukAwal;
      $periodeAkhir = $thnMasukAkhir.$semsMasukAkhir;
      //if($thnMasukAwal==''){$periodeAwal='19001';}else{$periodeAwal=$thnMasukAwal.$semsMasukAwal;}
      //if($thnMasukAkhir==''){$periodeAkhir=date('Y').'2';}else{$periodeAkhir=$thnMasukAkhir.$semsMasukAkhir;}
      
      if($nim_notest==""){
      
          $new_sql=" ORDER BY mhsNomorTes LIMIT %s, %s";
      }else{
      
         $new_sql = "AND(
         mhsNiu  LIKE '%s'OR
         mhsNomorTes LIKE '%s') 
         ORDER BY mhsNomorTes LIMIT %s, %s";
         
      }      
      
      $sql = $this->mSqlQueries['get_data_mahasiswa_with_nim']. $new_sql;
      
      if($nim_notest==""){
      
         $result=$this->Open($sql,array($periodeAwal,$periodeAkhir,
                                        '%'.$isCalon.'%','%'.$programStudi.'%','%'.$nama.'%'
                                        ,$offset,$limit));
      }else{
      
         $result=$this->Open($sql,array($periodeAwal,$periodeAkhir,
                                        '%'.$isCalon.'%','%'.$programStudi.'%','%'.$nama.'%',
                                        '%'.$nim_notest.'%','%'.$nim_notest.'%',
                                        $offset, $limit));
      }
//
      return $result;

   }
   
   function GetDataMahasiswaWithoutNim($thnMasukAwal,$thnMasukAkhir,$nim_notest,
                                       $isCalon,$programStudi,$nama,$semsMasukAwal,
                                       $semsMasukAkhir,$offset,$limit){

      if ($semsMasukAwal=='') {
         $semsMasukAwal=1;
      }
      if ($semsMasukAkhir=='') {
         $semsMasukAkhir=2;
      }
      if ($thnMasukAwal=='') {
         $thnMasukAwal='1900';
      }
      if ($thnMasukAkhir=='') {
         $thnMasukAkhir=date('Y');
      }
      $periodeAwal = $thnMasukAwal.$semsMasukAwal;
      $periodeAkhir = $thnMasukAkhir.$semsMasukAkhir;
      //if($thnMasukAwal==''){$periodeAwal='19001';}else{$periodeAwal=$thnMasukAwal.$semsMasukAwal;}
      //if($thnMasukAkhir==''){$periodeAkhir=date('Y').'2';}else{$periodeAkhir=$thnMasukAkhir.$semsMasukAkhir;}

      if($nim_notest==""){
      
          $new_sql=" ORDER BY mhsNomorTes LIMIT %s, %s";
      }else{
      
         $new_sql = "AND(
         mhsNiu  LIKE '%s'OR
         mhsNomorTes LIKE '%s') 
         ORDER BY mhsNomorTes LIMIT %s, %s";
         
      }      
      
      $sql = $this->mSqlQueries['get_data_mahasiswa_without_nim']. $new_sql;
      
      if($nim_notest==""){
      
         $result=$this->Open($sql,array($periodeAwal,$periodeAkhir,
                                        '%'.$isCalon.'%','%'.$programStudi.'%','%'.$nama.'%'
                                        ,$offset,$limit));
      }else{
      
         $result=$this->Open($sql,array($periodeAwal,$periodeAkhir,
                                        '%'.$isCalon.'%','%'.$programStudi.'%','%'.$nama.'%',
                                        '%'.$nim_notest.'%','%'.$nim_notest.'%',
                                        $offset, $limit));
      }

      return $result;

   }
   
   function GetTemplateCetak(){
      $result=$this->Open($this->mSqlQueries['get_template'],array());
      return $result;
   }
   
   function GetTemplateCetakById($idTemplate){
      $result=$this->Open($this->mSqlQueries['get_template_by_id'],array($idTemplate));
      return $result;
   }
   
   function GetVariableTemplate(){
      $result=$this->Open($this->mSqlQueries['get_variable_template'],array());
      return $result;
   }
   
   function GetDataCetak($idMhs){
      $result=$this->Open($this->mSqlQueries['get_data_cetak'],array($idMhs));
      //exit;
      return $result;
   }
   
   function GetTotalProdi(){
      $result=$this->Open($this->mSqlQueries['get_total_prodi'],array());
      if(!$result){
         return 0;
      }else{
         return $result[0]['total_prodi'];
      } 
   }
   
   function GetTotalMahasiswa(){
      $result=$this->Open($this->mSqlQueries['get_total_mahasiswa'],array());
      if(!$result){
         return 0;
      }else{
         return $result[0]['jumlah_mhs'];
      } 
   }   
   
   function GetTotalTemplateAktif(){
      $result=$this->Open($this->mSqlQueries['get_total_template_aktif'],array());
      if(!$result){
         return 0;
      }else{
         return $result[0]['total'];
      } 
   }
   
   function GetTahunAjaran(){
      $result=$this->Open($this->mSqlQueries['get_tahun_ajaran'],array());
      return $result;
   }
}
?>