<?php 
ob_start();
 require '../../config/Config.php';
  $config = new Config();
   if(!empty($_SESSION['student_id'])) { 
  include 'style.css';

$student_id=$_GET['id'];
$school_id=$_GET['sc'];

  $ins=$config->getDatum("SELECT * FROM entity__school WHERE school_id ='$school_id'");
  $mad=$ins['school_name'];

  $student_data=$config->getData("SELECT* FROM entity__students_data WHERE student_id='$student_id' ");
            foreach($student_data as $stdt){
            $sch_id =  $stdt['school_class_id'];

            $school_class = $config->getDatum("SELECT * FROM entity__school_class scc,  entity__teacher WHERE scc.teacher_id = entity__teacher.teacher_id AND scc.school_class_id='$sch_id' ");
           
              $teacher_name = $school_class['teacher_name'];
              $kl = $school_class['teacher_gender'];
              $class=  $school_class['category_level_id'];
              $class_name = $school_class['school_class_name'];
              $year = $school_class['category_year_name'];
          }

          $sis = $config->getDatum("SELECT * FROM entity__student WHERE student_id='$student_id'");
          $sis_nama= $sis['student_name'];
          $nisn= $sis['student_nisn'];
          $nis= $sis['student_nis'];

          $kurikulum=$config->getDatum("SELECT * FROM entity__school_curriculum WHERE school_id='$school_id' AND category_level_id='$class'  ");
          $tapel=$kurikulum['category_year_name'];
          $semester=$kurikulum['category_semester_name'];
?>
<!DOCTYPE html>
<html>
<head>
	<title>Print Nilai</title>
</head>
<body>

<div  style="margin-left: 50px; margin-right: 50px; page-break-before:always;">

	<div class="hr"></div>

<div  style="margin-top: 5px; margin-bottom: 5px;">
	<table class="table1" border="0" align="left" width="50%">
		<tr>
			<td>Nama</td>
			<TD>:</TD>
			<td style="text-transform: capitalize; "><?=$sis_nama;?></td>
		</tr>

		
		<tr>
			<td>NIS</td>
			<TD>:</TD>
			<td><?= $nis;?></td>
		</tr>

		<tr>
			<td>NISN</td>
			<TD>:</TD>
			<td><?= $nisn;?></td>
		</tr>
	</table>
</div>


<div style="margin-top: 0px; margin-bottom: 5px;">
	<table class="table1" border="0" align="right"   width="50%">
		<tr>
			<td>Madrasah</td>
			<TD>:</TD>
			<td style="text-transform: capitalize;"><?=  $mad;?></td>
		</tr>

		
		<tr>
			<td>Kelas/Semester</td>
			<TD>:</TD>
			<td style="text-transform: capitalize;"> <?= $config->format_romawi($class);?> . <?=  $class_name;?> / <?=$semester;?> </td>
		</tr>

		<tr>
			<td>Tahun Ajaran</td>
			<TD>:</TD>
			<td><?= $tapel;?></td>
		</tr>
	</table>
</div>

<div >
	<table border="1"width="100%" cellspacing="0"></table>
</div>

<p style="font-weight: bold;">A. NILAI PENGETAHUAN DAN KETERAMPILAN</p>

<div>
	 <table class='table' border="1"width="100%" cellspacing="0" >
                <thead>
                <tr>
                  <th class="tngh" rowspan="2" width="5%">No.</th>
                  <th class="tngh" rowspan="2">MATA PELAJARAN</th>
                  <th class="tngh" colspan="2">PENGETAHUAN</th>                         
                  <th class="tngh" colspan="2"> KETERAMPILAN</th>
                  
                </tr>
                <tr>
                  <th class="tngh">NILAI</th>
                  <th class="tngh" width="10%">PREDIKAT</th>
                   <th class="tngh"  width="10%">NILAI</th>
                  <th class="tngh"  width="15%">PREDIKAT</th>

                </tr>
                </thead>

                <tbody>
                    <?php
                    $i=1;

                    $nilai = $config->getData("SELECT * FROM entity__student_subjects_value WHERE student_id='$student_id' ORDER BY subjects_value_id ");
                    foreach ($nilai as $nil){

                      $pj = $nil['student_subjects_value_daily_project'];
                      $pc = $nil['student_subjects_value_daily_practice'];
                      $pf = $nil['student_subjects_value_daily_portfolio'];

                      if ($pj <= 0 && $pc<= 0&& $pf<= 0){
                          $avg=0;
                      }
                      elseif($pj>0 && $pc > 0 && $pf > 0){
                        $avg = ($pj+$pc+$pf)/3;
                      }
                      elseif ($pj > 0 && $pc > 0 && $pf <= 0) {
                        $avg=($pj+$pc)/2;
                      }
                      elseif ($pj > 0 && $pc<= 0 && $pf>0) {
                        $avg=($pj+$pf)/2;
                      }
                      elseif ($pj>0 && $pc<=0 && $pf<=0) {
                        $avg=$pj;
                      }
                      elseif ($pc>0 && $pj<= 0 && $pf<=0) {
                        $avg = $pc;
                      }
                      elseif ($pc>0 && $pj<=0 && $pf>0) {
                        $avg = ($pc+$pf)/2;
                      }
                      elseif ($pf>0 && $pj<=0 && $pc<=0) {
                        $avg = $pf;
                      }

                     
                       $svi_n = $nil['subjects_value_id'];

                     $subjects_value = $config->getData("SELECT esv.subjects_value_id, esv.school_id, esv.category_subjects_id,
                      ecs.category_subjects_id, ecs.category_level_id, ecs.category_majors_id, ecs.master_subjects_id

                      FROM entity__subjects_value esv INNER JOIN entity__category_subjects ecs ON esv.category_subjects_id=ecs.category_subjects_id   WHERE esv.school_id='$school_id' AND esv.subjects_value_id='$svi_n' ");
                      foreach ($subjects_value as $subv){
                        $msi=$subv['master_subjects_id'];
                        $svi = $subv['subjects_value_id'];

                      $master_subjects=$config->getDatum("SELECT * FROM entity__master_subjects WHERE master_subjects_id='$msi' ORDER BY master_subjects_name ");
                      ?>
                <tr>
                  <td class="tngh"> <?=$i ;?></td>                  
                  <td class="th"><?=$master_subjects['master_subjects_name'] ;?></td>
                  <td class="th1"><?=$nil['student_subjects_value_knowledge_total'] ;?></td>
                  <td class="th1"><?=$nil['student_subjects_value_knowledge_predicate'] ;?></td>
                  <td class="th1"><?=round($avg);?></td>
                  <td class="th1"><?=$nil['student_subjects_value_skill_predicate'] ;?></td>

                  <?php                                                               
                    $i++;
                                  }
                              }?>
                  </tr>
<!-- Local Value-->
                  <tr>
                      <td class="th" colspan="6" style="padding-left:67px; font-weight: bold; ">MUATAN LOKAL</td>
                   
                  </tr>


                  <?php $nlokal = $config->getData("SELECT * FROM entity__student_local_subjects_value sls, entity__local_subjects_value ls  WHERE sls.local_subjects_value_id = ls.local_subjects_value_id AND  sls.student_id='$student_id' AND ls.school_id='$school_id' GROUP BY sls.local_subjects_value_id ");
                    foreach ($nlokal as $nl){ 

                      $pjl = $nl['student_local_subjects_value_daily_project'];
                      $pcl = $nl['student_local_subjects_value_daily_practice'];
                      $pfl = $nl['student_local_subjects_value_daily_portfolio'];

                      if ($pjl <= 0 && $pcl<= 0&& $pfl<= 0){
                          $avgl=0;
                      }
                      elseif($pjl>0 && $pcl > 0 && $pfl > 0){
                        $avgl = ($pjl+$pcl+$pfl)/3;
                      }
                      elseif ($pjl > 0 && $pcl > 0 && $pfl <= 0) {
                        $avgl=($pjl+$pcl)/2;
                      }
                      elseif ($pjl > 0 && $pcl<= 0 && $pfl>0) {
                        $avgl=($pjl+$pfl)/2;
                      }
                      elseif ($pjl>0 && $pcl<=0 && $pfl<=0) {
                        $avgl=$pjl;
                      }
                      elseif ($pcl>0 && $pjl<= 0 && $pfl<=0) {
                        $avgl = $pcl;
                      }
                      elseif ($pcl>0 && $pjl<=0 && $pfl>0) {
                        $avgl = ($pcl+$pfl)/2;
                      }
                      elseif ($pfl>0 && $pjl<=0 && $pcl<=0) {
                        $avgl = $pfl;
                      }


                      ?>
                  <tr>
                    <td class="tngh"><?= $i ;?></td>

                     <td class="th" width="30%"><?=$nl['local_subjects_value_name'] ;?></td>
                      <td class="th1"><?=$nl['student_local_subjects_value_knowledge_total'] ;?></td>
                      <td class="th1"><?=$nl['student_local_subjects_value_knowledge_predicate'] ;?></td>
                       <td class="th1"><?=round($avgl);?></td>
                      <td class="th1"><?=$nl['student_local_subjects_value_skill_predicate'] ;?></td>

                  <?php   $i++; }?>
                  </tr>
<!-- Local Value-->
                </tbody>
                                              
              </table>

	</div>

	<div style="margin-top: 20px;">
		<p style="font-weight: bold;">B. DESKRIPSI PENGETAHUAN DAN KETERAMPILAN</p>
		<table class='table' border="1"width="100%" cellspacing="0"  >
                <thead>
                <tr>
                  <th class="tngh"  width="5%">No.</th>
                  <th class="tngh" >MATA PELAJARAN</th>
                  <th class="tngh" >PENGETAHUAN</th>                         
                  <th class="tngh" > KETERAMPILAN</th>
                  
                </tr>
               
                </thead>

                <tbody>
                    <?php
                    $i=1;

                    $nilai = $config->getData("SELECT * FROM entity__student_subjects_value WHERE student_id='$student_id' ORDER BY subjects_value_id ");
                    foreach ($nilai as $nil){

                      $pj = $nil['student_subjects_value_daily_project'];
                      $pc = $nil['student_subjects_value_daily_practice'];
                      $pf = $nil['student_subjects_value_daily_portfolio'];

                      if ($pj <= 0 && $pc<= 0&& $pf<= 0){
                          $avg=0;
                      }
                      elseif($pj>0 && $pc > 0 && $pf > 0){
                        $avg = ($pj+$pc+$pf)/3;
                      }
                      elseif ($pj > 0 && $pc > 0 && $pf <= 0) {
                        $avg=($pj+$pc)/2;
                      }
                      elseif ($pj > 0 && $pc<= 0 && $pf>0) {
                        $avg=($pj+$pf)/2;
                      }
                      elseif ($pj>0 && $pc<=0 && $pf<=0) {
                        $avg=$pj;
                      }
                      elseif ($pc>0 && $pj<= 0 && $pf<=0) {
                        $avg = $pc;
                      }
                      elseif ($pc>0 && $pj<=0 && $pf>0) {
                        $avg = ($pc+$pf)/2;
                      }
                      elseif ($pf>0 && $pj<=0 && $pc<=0) {
                        $avg = $pf;
                      }

                       $svi_n = $nil['subjects_value_id'];

                     $subjects_value = $config->getData("SELECT esv.subjects_value_id, esv.school_id, esv.category_subjects_id,
                      ecs.category_subjects_id, ecs.category_level_id, ecs.category_majors_id, ecs.master_subjects_id

                      FROM entity__subjects_value esv INNER JOIN entity__category_subjects ecs ON esv.category_subjects_id=ecs.category_subjects_id   WHERE esv.school_id='$school_id' AND esv.subjects_value_id='$svi_n' ");
                      foreach ($subjects_value as $subv){
                        $msi=$subv['master_subjects_id'];
                        $svi = $subv['subjects_value_id'];

                      $master_subjects=$config->getDatum("SELECT * FROM entity__master_subjects WHERE master_subjects_id='$msi' ORDER BY master_subjects_name ");
                      ?>
                <tr>
                  <td class="tngh"> <?=$i ;?></td>                  
                  <td  class="th" width="40%"><?=$master_subjects['master_subjects_name'] ;?></td>
                  <td class="th" width="30%"><?=$nil['student_subjects_value_knowledge_description'] ;?></td>
                  <td class="th" width="30%"><?=$nil['student_subjects_value_skill_description'] ;?></td>
                 
                  <?php                                                               
                    $i++;
                                  }
                              }?>
                  </tr>
<!-- Local Value-->
                  <tr>
                      <td  class="th" colspan="4" style="padding-left:67px; font-weight: bold; ">MUATAN LOKAL</td>
                      
                      
                  </tr>


                  <?php $nlokal = $config->getData("SELECT * FROM entity__student_local_subjects_value sls, entity__local_subjects_value ls  WHERE sls.local_subjects_value_id = ls.local_subjects_value_id AND  sls.student_id='$student_id ' AND ls.school_id='$school_id' GROUP BY sls.local_subjects_value_id ");
                    foreach ($nlokal as $nl){ ?>
                  <tr>
                    <td class="tngh"><?= $i ;?></td>

                     <td class="th" width="40%"><?=$nl['local_subjects_value_name'] ;?></td>
                      <td class="th" width="30%"><?=$nl['student_local_subjects_value_knowledge_description'] ;?></td>
                      <td class="th" width="30%"><?=$nl['student_local_subjects_value_skill_description'] ;?></td>
                      
                  <?php   $i++; }?>
                  </tr>
<!-- Local Value-->
                </tbody>
                               
              </table>

              <?php $spirit=$config->getdatum("SELECT * FROM entity__student_report WHERE student_id='$student_id' AND school_id ='$school_id' ");

              $lap= $spirit['student_report_status'];?>
              <div style="margin-top: 20px;">
              	<p style="font-weight: bold;">C. STATUS KENAIKAN / KELULUSAN</p>
              	<table class='table' border="1" cellspacing="0" width="100%" >
              		<tr>
              			<td style="text-transform: uppercase; font-size: 22px; text-align: center; font-weight: bold;"> <?php if($class==='9' OR $class==='12' OR $class==='6'){ 

                      if($lap==='naik'){?>
                      <dd  class="si2" style="color:black;">LULUS</dd>
                      <?php }else{ echo '<dd  class="si2" style="color:black;">TIDAK LULUS</dd>';}?>

                
                 <?php }else{?>

                      <dd  class="si2" <?php if($lap === 'naik'){echo 'style="color:black;"';}else{echo 'style="color:black;"';}?> ><?=$lap ;?></dd>

                <?php }?></td>
              		</tr>

              	</table>
              </div>


              <?php $cetak=$config->getDatum("SELECT * FROM entity__pencetakkan_rapor  ");
              $tmp=$cetak['tempat'];
              $tgl=$cetak['tanggal'];
            ;
             ?>
              <div style="padding-top: 50px;">
              	<table boder="1" align="right">
              		<tr>
              			<td><?=$tmp;?>, <?=$config->tgl_indo($tgl);?></td>
              		
              		</tr>
              		<tr>
              			<td>Wali Kelas,</td>
              		</tr>
              		<tr>
              			<td style="padding-top: 50px; font-weight: bold;"><?=$teacher_name;?></td>
              		</tr>
              	</table>
              </div>

              <div  style="padding-top: 110px;">
              	<table align="left" >
              		<tr>
              			<td style="font-size: 7px;">* Form ini hanya laporan nilai sementara, form RAPORT yang sesungguhnya akan dibagikan oleh Wali Kelas pada saat masuk sekolah.</td>
              		</tr>
              	</table>
              </div>
	</div>


</div>




</body>
</html>
<?php
} else {
    header("Location:../../login/logout.php");
}
?>