<section class="content-header">
      <h1>Pelengkap <small><i>Validasi AKM</i></small></h1>
      <ol class="breadcrumb">
        <li><a href="?module=validasi"><i class="fa fa-university"></i>Pelengkap </a></li>
        <li class="active">Validasi AKM</li>
      </ol>
    </section>
    <br />
<?php
@$keyfilter=$_REQUEST['keyfilter'];
@$th_smt=$_REQUEST['semester'];

//echo "Program Studi :";
					
	  $nama_pt="id_sp='$id_sp'";
	  //echo $nama_pt;
	  $result=$proxy->GetRecordset($gettoken,'sms',$nama_pt,'id_jenj_didik,nm_lemb asc','','');
	  //print_r($result);
	  $coba=$result['result'];
	  @$coba1=array_unique($coba);
  
  
  ?>
  
  <form method="post" name="prodi" action="<?php echo $_SERVER['PHP_SELF'];?>?module=validasi&op=lihat">
  <table width="100%" border="0">
  <tr>
  
  <td width="10">Program Studi&nbsp;
  
		  <select name="keyfilter" class="inputbox" id="keyfilter">
          <option value="All Prodi" selected>-- All Prodi --</option>
		  <?php
		  
		  for($i=0;$i<count($coba);$i++){
			  $prodi = $coba[$i]['nm_lemb'];
			  $id_sms = $coba[$i]['id_sms'];
			  $jenjang=$coba[$i]['id_jenj_didik'];
			  
			  // untuk menggabungkan jenjang dengan prodi
			  $result=$proxy->GetRecord($gettoken,'jenjang_pendidikan',"id_jenj_didik='$jenjang'");
			  $jenj=$result['result'];
			  $j=$jenj['nm_jenj_didik'];
			  
			  //echo "$j"."-"."$prodi<br>";
			  
			  
			  if (isset($_POST['keyfilter']))
				 {
				 $selected = (isset($_POST['keyfilter']) and $_POST['keyfilter'] == $test) ? 'selected' : '';
				 echo "<option value='$id_sms' $selected>$j"." ("."$prodi".")</option>\n";
				 }
			  else
				 {
				 $selected = (isset($_GET['keyfilter']) and $_GET['keyfilter'] == $test) ? 'selected' : '';
				 echo "<option value='$id_sms' $selected>$j"." ("."$prodi".")</option>\n";
				 }
		  }
		  ?>
		  
		  </select>
		   &nbsp;Semester :&nbsp; 
		  <?php
		  
		  $result=$proxy->GetRecordset($gettoken,'semester','','id_smt DESC','','');
		  //print_r($result);
		  $smt=$result['result'];
		  ?>
		 
		  
		  <select name="semester" class="inputbox" id="semester">
		  <!--<option>--struktur--</option>-->
		  <?php
                            
			for($i=0;$i<count($smt);$i++){
			$nm_smt = $smt[$i]['nm_smt'];
			$id_smt = $smt[$i]['id_smt'];
			
			  if (isset($_POST['semester']))
				 {
				 $selected = (isset($_POST['semester']) and $_POST['semester'] == $nm_smt) ? 'selected' : '';
				 echo "<option value='$id_smt' $selected>$nm_smt</option>\n";
				 
				 }
			  else
				 {
				 $selected = (isset($_GET['semester']) and $_GET['semester'] == $nm_smt) ? 'selected' : '';
				 echo "<option value='$id_smt' $selected>$nm_smt</option>\n";
				 
				 }
			}
		?>
		  
		  </select>
		  <button class="btn btn-primary" name="Submit" type="image" value="Submit" data-toggle="submit">OK</button>
		  </form>
		  </td>
		  </tr>
		  
		  </table>
<?php

if(isset($_GET['op'])){
	if($_GET['op']=='lihat')
	  {
		if ($_POST['keyfilter'] == 'All Prodi'){
		@$myFile = "validasi.txt";
		@unlink(@$myFile);
		echo "<b>validasi seluruh prodi </b><br />";
		$data=$th_smt;
		echo "<b>Pelaporan semester ".$data,"</b>";
		 	for($b=0;$b<count($coba);$b++){
				echo "<br />";
			  @$prodi = $coba[$b]['nm_lemb'];
			  @$id_sms = $coba[$b]['id_sms'];
			  @$jenjang=$coba[$b]['id_jenj_didik'];
			  
			  // untuk menggabungkan jenjang dengan prodi
			  $result=$proxy->GetRecord($gettoken,'jenjang_pendidikan',"id_jenj_didik='$jenjang'");
			  $jenj=$result['result'];
			  $j=$jenj['nm_jenj_didik'];
			  
			echo "Prodi $prodi - $j";
			
			$data1=substr($data,0,4);
			if ($jenjang==35 || $jenjang==40){			
				$validasi=$data1-4;			
			}
			elseif($jenjang==31){
				$validasi=$data1-1;
			}
			else {
			$validasi=$data1-6;
			} 
		
			for ($a=$validasi;$a<$data1+1;$a++) {
			  echo "<br /><b>Th_masuk - $a</b>";
			  $mulai_smt="p.id_sms='$id_sms' AND mulai_smt='".$a."1' AND p.id_jns_keluar IS NULL OR p.id_sms='$id_sms' AND mulai_smt='".$a."2' AND p.id_jns_keluar IS NULL";
			  //echo "<br> $mulai_smt";
			  $result=$proxy->GetRecordset($gettoken,'mahasiswa_pt',$mulai_smt,'nipd ASC','','');
			  $all=$result['result'];
//			}
			
			for($x=0;$x<count($all);$x++){
				$nipd = $all[$x]['nipd'];
				$nm_pd = $all[$x]['nm_pd'];
				$id_reg_pd=$all[$x]['id_reg_pd'];
				$fk__sms=$all[$x]['fk__sms'];
				$id_jns_keluar=$all[$x]['id_jns_keluar'];
//				
//				//echo $nipd."-".$nm_pd."-".$id_jns_keluar."<br />";
//				if($id_jns_keluar==''){
//					 $status="AKTIF";
//					 //echo "<br />".$nipd."-".$nm_pd."-".$status;
//					 
					   $npm="p.id_reg_pd='$id_reg_pd' AND p.id_smt='$data'";
						echo "<br />".$npm;
						$result=$proxy->GetRecord($gettoken,'kuliah_mahasiswa',$npm,'','','');
						//print_r($result);
						
						@$id_smt=$result['result']['id_smt'];
						@$id_stat_mhs=$result['result']['id_stat_mhs'];
						if ($id_smt=='' || $id_stat_mhs=='') {
								$smt='?';
								$sts='?';
								echo "<br />".$nipd."-".$nm_pd."-".$smt."-".$sts;
								
//						
//						// untuk membuat file validasi.txt
						$myFile = "validasi.txt";
						$fh = fopen($myFile, 'a') or die("can't open file");
						$stringData = "\r\n $nipd - $nm_pd - $smt - $sts";
						fwrite($fh, $stringData);
						fclose($fh);
//						
						} /* end if */
						//else {echo "<br />".$nipd."-".$nm_pd."-".$id_smt."-".$id_stat_mhs;}
//						
			} /* end for */
			}
			echo "<br />";
//			}
			}
			  
			  
		}
		else {
		$key_sms="id_sms='$keyfilter'"; 
	
		$result=$proxy->GetRecord($gettoken,'sms',$key_sms);
		$prodi=$result['result']['nm_lemb'];
		//echo "<br>$key_sms";
		$id_jenj_didik=$result['result']['id_jenj_didik'];
		
			$result=$proxy->GetRecord($gettoken,'jenjang_pendidikan',"id_jenj_didik='$id_jenj_didik'");
			$jenj=$result['result'];
			$j=$jenj['nm_jenj_didik'];
		echo "<pre style='background-color:#BFE3FE'>";
		echo "<h4> Mahasiswa dibawah ini yang berstatus aktif, tapi belum di transaksikan aktifitasnya </h4>";			
		echo "Program Studi : $prodi ($j) <br />";
		$data=$th_smt;
		$data1=substr($data,0,4);
		if ($id_jenj_didik==35 || $id_jenj_didik==40){			
			$validasi=$data1-4;			
		}
		elseif($id_jenj_didik==31){
			$validasi=$data1-1;
		}
		else {
		$validasi=$data1-6;
		}
		echo "Pelaporan semester ".$data;
		@$myFile = "validasi.txt";
		@unlink(@$myFile);
		echo "<br />NPM          Nama              Semester             Status";
		for ($a=$validasi;$a<$data1+1;$a++) {
		echo "<br /> <br /><b>Th_masuk - $a</b>";		
			//echo "<br />berarti validasi dimulai dari ".$a;
			
			$mulai_smt="p.$key_sms AND mulai_smt='".$a."1' AND p.id_jns_keluar IS NULL OR p.$key_sms AND mulai_smt='".$a."2' AND p.id_jns_keluar IS NULL";
			//echo "<br>$mulai_smt";
			$result=$proxy->GetRecordset($gettoken,'mahasiswa_pt',$mulai_smt,'nipd ASC','','');
			$coba=$result['result'];
			//var_dump($coba);
			//$coba1=array_unique($coba);
			
			for($i=0;$i<count($coba);$i++){
				$nipd = $coba[$i]['nipd'];
				$nm_pd = $coba[$i]['nm_pd'];
				$id_reg_pd=$coba[$i]['id_reg_pd'];
				$fk__sms=$coba[$i]['fk__sms'];
				$id_jns_keluar=$coba[$i]['id_jns_keluar'];
				
				//echo $nipd."-".$nm_pd."-".$id_jns_keluar."<br />";
//				if($id_jns_keluar==''){
//					 $status="AKTIF";
					 //echo "<br />".$nipd."-".$nm_pd."-".$status;
					 
					   $npm="p.id_reg_pd='$id_reg_pd' AND p.id_smt='$data'";
						//echo "<br />".$npm;
						$result=$proxy->GetRecord($gettoken,'kuliah_mahasiswa',$npm,'','','');
						//print_r($result);
						
						@$id_smt=$result['result']['id_smt'];
						@$id_stat_mhs=$result['result']['id_stat_mhs'];
						if ($id_smt=='' || $id_stat_mhs=='') {
								$smt='?';
								$sts='?';
								echo "<br />".$nipd."-".$nm_pd."-".$smt."-".$sts;
								
						
						// untuk membuat file validasi.txt
						
						$myFile = "validasi.txt";
						$fh = fopen($myFile, 'a') or die("can't open file");
						$stringData = "\r\n $nipd - $nm_pd - $smt - $sts";
						fwrite($fh, $stringData);
						fclose($fh);
						
						
						} /* end if */
						//else {echo "<br />".$nipd."-".$nm_pd."-".$id_smt."-".$id_stat_mhs;}
						
//				} /* end if */
			} /* end for */
		} /* end for */
		echo "</pre>";
		} /* end of $keyfilter */
	  } /* end ig get lihat */
} /* end if get OP */
?>