<?php
@$keyfilter=$_REQUEST['keyfilter'];
@$keyorder=$_REQUEST['keyorder'];
@$keylimit=$_REQUEST['keylimit'];
@$keyoffset=$_REQUEST['keyoffset'];
?>

<!--//
// These are required files we must include these libraries 
untuk tabel dinamis dengan paging
//-->

<!-- <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">-->
<!--<link href="assets/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!--<link rel="stylesheet" href="http://cdn.datatables.net/1.10.2/css/jquery.dataTables.min.css">-->
<link rel="stylesheet" href="../../assets/datatables/css/jquery.dataTables.min.css">  

<!-- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>-->
<script src="../../assets/jquery/jquery.min.js"></script>
<!--<script type="text/javascript" src="http://cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js"></script>-->
<script type="text/javascript" src="../../assets/datatables/js/jquery.dataTables.min.js"></script>
<!--<script type="text/javascript" src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>-->
<script type="text/javascript" src="../../assets/bootstrap/js/bootstrap.min.js"></script>

<!-- dinamis tabel n paging -->
	<link href="../../assets/css/icons/icons.min.css" rel="stylesheet">
    <link href="../../assets/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <!--<link href="assets/css/plugins.min.css" rel="stylesheet">-->
    <link href="../../assets/css/style.min.css" rel="stylesheet">
  <!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>-->
  <!--<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>-->
  <!--<script src="dist/js/bootstrap-select.js"></script>-->

</head>
<body id="onan">
<div class="container">

<?php
//include "session.php";
@$tabel=$_GET['tabel'];
@$jenis=$_GET['jenis'];
switch($_GET['act']){
	
	
	case "lihat" :
				echo "<h1> Struktur Tabel ".$tabel."</h1>";
				//echo "ini case lihat tabel ".$tabel;
				?>
				<!--<table class="table table-bordered" border="1" cellspacing="1" cellpadding="1" class="box_cccccc">-->
                <table id="myTable" class="display table" width="100%" border="0" >
		
                         <!-- Membuat Judul Kolom dan Warna Sesuai Tabelnya-->
                          
                          <thead>
                          <tr>
                        <?php
                        @$result=$proxy->GetDictionary($token,$tabel);
                        @$coba=$result['result'];
                        @$coba1=array_unique($coba);
                        //print_r($coba1);
                        foreach($coba1 as $key=>$value)
                        {
						?>
                        <th bgcolor="#FFA6D2">No</th>
                        <?php
                          foreach($value as $item=>$final_item)
                          {
                    		?>
                            <th height="20" align="center" bgcolor="#FFA6D2" >&nbsp;<?php echo $item; ?>&nbsp;</th>
                    	<?php
                          }
                         }
                    	?>
                          </tr>
                          </thead>
                          	
                          <!-- end judul Kolom -->
                    	<tbody>
                    	<?php
                      /* mengatur warna pada isi tabel berdasarkan ganjil/genap */
                         $a=0;
                         foreach(@$coba as $key=>$value){
                        	for($i=0;$i<1;$i++){
							   $a++;
							   //$NO++;
							   	if ($a%2==1){
									$warna="success";
                           	   	}else{
                            		$warna="danger";
									}
							 ?>
							   <!-- menerapkan background isi tabel -->
							   <tr class="<?php echo $warna; ?>">
								
								 <!-- loop mencari isi tabel */-->
								<td class=<?php echo $warna;?>><?php echo $a;?></td>
                                <?php
								foreach(@$value as $item=>$final_item){
									?>
									<!-- isi tabel -->
									<td height="20" align="center" class=<?php echo $warna;?>>&nbsp;<?php echo $final_item; ?>&nbsp;</td>
									<?php
								}
							}
                        /* end pengaturan warna isi tabel */
                       }
                    	?>
                  			  </tr>
                     </tbody>
                  </table>
                  <?php		
	break;
	
	case "data" :
				
				?>
                <h1> Data Tabel <?="$tabel";?></h1> 
                <a class="btn btn-info" href="<?php if(isset($_SERVER['HTTP_REFERER'])){ echo $_SERVER['HTTP_REFERER']; } ?>">Kembali</a>
				<br>
				<?php
				if ($jenis=='Data'){
					echo "Program Studi :";
					
						$nama_pt="id_sp='$id_sp'";
						//echo "<br> $nama_pt";
						$result=$proxy->GetRecordset($gettoken,'sms',$nama_pt,'id_jenj_didik,nm_lemb asc','','');
						$coba=$result['result'];
						@$coba1=array_unique($coba);
					
					
					?>
					
					<form method="post" name="prodi" action="<?php echo $_SERVER['PHP_SELF']."?module=struktur&act=records&tabel1=".$tabel."&id_pt=".$id_sp; ?>">
					<?php
						
						
						
							// menampilkan prodi
							?>
							<select name="keyfilter" class="inputbox" id="keyfilter">
							<?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>
							<button class="btn btn-primary" name="Submit" type="image" value="Submit" data-toggle="submit">OK</button>
                            
							</form>
                            <?php
				break;
				}else{
						$result=$proxy->GetRecordset($gettoken,$tabel,'','','','');
						$coba=$result['result'];
						@$coba1=array_unique($coba);	
						?>
						<div class="table-responsive">
						<table id="myTable" class="display table" width="100%" border="0" >
									
						<thead>  
							<tr> 
							<?php
							// judul kolom
							foreach(@$coba1 as $key=>$value){
								?>
									<th bgcolor="#FFA6D2">No</th>
                                    <?php
									foreach(@$value as $item=>$final_item){
										?>
										<th height="20" align="center" bgcolor="#FFA6D2">&nbsp;<?php echo $item; ?>&nbsp;</th>
										<?php
									}
							}
							// end judul kolom
							?> 
							</tr>  
						</thead>  
							<tbody>
							<?php
							//  tampil data dalam kolom
							$a=0;
							//$NO=0;
							foreach(@$coba as $key=>$value){
									for($i=0;$i<1;$i++){
										$a++;
										//$NO++;
									  	if ($a%2==1)
										  $warna="success";
									  	else
										  $warna="danger";	 
										?>
										<tr class=<?php echo $warna; ?>>
										
										<td class=<?php echo $warna;?>><?php echo $a;?></td>
                                        <?php
										  foreach(@$value as $item=>$final_item){
												?>
											 	<td height="20" align="center" class=<?php echo $warna;?>>&nbsp;<?php echo $final_item; ?>&nbsp;</td> 
												<?php
										  }
										?>
                                        </tr>
                                        <?php
									}
							}
							?>  
							</tbody>  
						</table>
						</div>
						<?php						
			
											
					//default :
					//echo "ini default case";
					break;
					}
			//echo "ini case edit";
			
//}
//switch($_GET['act1']){
	case "records":
						
							//if(isset($_GET['op']))
							$tabel1=$_GET['tabel1'];
							@$nama_pt=$_GET['id_sp'];
							$filter=$_POST['keyfilter'];
							$filter1="id_sms='$filter'";
							//$filter1="id_sms='d1871911-d62d-4c60-8c0f-ef6b5f0b6f77'"; 
							$result=$proxy->GetRecord($gettoken,'sms',$filter1);
							$prod=$result['result'];
							$prodi_data=$prod['nm_lemb'];
							
							//echo "filter ".$filter1;
							//echo "nama pt :".$nama_pt;
							//{
							//  	if($_GET['op']=='records'){
									//echo "ini record ".$filter."<br>";
									//echo "ini record ".$filter1."<br>";
									//echo "nama prodi ".$prodi;
									?>
									<h1>Prodi : <?php echo $prodi_data;?></h1>
                                    <h3><?php //echo "Tabel :".$tabel1."<br>";?></h3>
									<?php
									//if ($tabel1=='mahasiswa' || $tabel1=='dosen_pt'){
									if ($tabel1=='mahasiswa'){  //|| $tabel1=='dosen_pt'){
										$tbl='mahasiswa_pt';
										$filter1="p.id_sms='$filter'";
									}elseif($tabel1=='dosen'){
										$tbl='dosen_pt';
										$filter1="p.id_sms='$filter'";
									}elseif($tabel1=='kelas_kuliah'){
										$tbl=$tabel1;
										$filter1="p.id_sms='$filter'";
									}elseif($tabel1=='mata_kuliah'){
										$tbl=$tabel1;
										$filter1="p.id_sms='$filter'";
									}else{
//									if($tabel1=='mahasiswa' || $tabel1=='dosen'){
										$tbl=$tabel1;
										//$filter1="p.id_sms='$filter'";
										$filer1="id_sms ILIKE '%$filter%'";
										}
										//echo "<br>$tbl";
										//$filter1="p.id_sms='$filter'";
										
										
										//echo "<br>$filter1";
//										$filter2=$nama_pt;
										$result=$proxy->GetRecordset($gettoken,$tbl,$filter1,'','','');
										//echo "tabel yang dipilih mahasiswa di rubah ke mahasiswa_pt";								
//									}else{
//										$result=$proxy->GetRecordset($gettoken,$tabel1,$filter1,'','','');
//									}
									
									$coba=$result['result'];
									@$coba1=array_unique($coba);
									//echo $gettoken."<br>";
									//print_r($coba1);	
								//}
							
								?>
								<div class="table-responsive">
								<table id="myTable" class="display table" width="100%" border="0" >
								
								<thead>  
								  <tr> 
								  <?php
								  // untuh membuat judul kolom
								  foreach(@$coba1 as $key=>$value){
								   	 ?>
									<th bgcolor="#FFA6D2">No</th>
                                    <?php
									 foreach(@$value as $item=>$final_item){
										?>
										<th height="20" align="center" bgcolor="#FFA6D2">&nbsp;<?php echo $item; ?>&nbsp;</th>
										<?php
                                     }
								  }
								  // akhir judul kolom
								  ?> 
                                  </tr>  
								</thead>  
								<tbody>
								<?php
									// untuk menampilkan data dalam tabel
									$a=0;
									//$NO=0;
									foreach(@$coba as $key=>$value){
										for($i=0;$i<1;$i++){
									  	$a++;
									 	//$NO++;
										if ($a%2==1)
											$warna="success";
										else
											$warna="danger";	 
										?>
										
                                        <tr class="text" bgcolor=<?php echo $warna; ?>>
										
											  <td class=<?php echo $warna;?>><?php echo $a;?></td>
											  <?php
                                              foreach(@$value as $item=>$final_item){
												?>
                                                
												<td height="20" align="center" class=<?php echo $warna;?>>&nbsp <?php echo $final_item; ?>&nbsp;</td> 
                                                
												<?php
											  }
										?>
										</tr>
										<?php
										}	
								   	}
									// end tampil data 
break;							//}
}
							
							
							//		$keyfilter=$_REQUEST['keyfilter'];
							//		$result=$proxy->GetRecordset($gettoken,$tabel,$keyfilter,'','','');
							//		$coba=$result['result'];
							//		@$coba1=array_unique($coba);
				
				
?>
</div>

<script>
$(document).ready(function(){
    $('#myTable').dataTable();
});
</script>