<?php
ob_start();
$page = "nilaiku"; ?>
<?php
      require '../../config/Config.php';
  $config = new Config();
  include "hak-akses.php";

  if(!empty($_SESSION['student_id'])) {   
  include "../../layout/header.php";
  include "style.css";
  
?> 
<?php
    

    $query = "SELECT * FROM entity__student WHERE student_id='$student_id'  
    ";

    $result = $config->getDatum($query);



 ?>
 <!-- SIDEBAR END -->


  <!-- CONTENT START -->

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
       <span class="badge bg-red"><font style="font-size: 14px; font-family: Lemonada;"><i class="fa fa-user"></i> <?= $student_name; ?></font></span>
        <small></small>
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li><a href="#">Nilai</a></li>
        <li class="active">Sikap</li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="row">

        <div class="col-md-6">
          <div class="box box-primary box-solid">
            <div class="box-header with-border">
              <i class="fa fa-heart"></i>

              <?php $spirit=$config->getdatum("SELECT * FROM entity__student_report WHERE student_id='$student_id' AND school_id ='$school_id' ");?>
             <h3 class="box-title"  style="font-size: 18px; font-family: Lemonada;">Sikap Spiritual</h3>
            </div>
            <!-- /.box-header -->
            <div class="box-body" style="height: 220px;">
              <dl>
                <dt class="pred">Predikat</dt>
                <dd class="si"><font class="badge bg-green" style="font-size: 14px; padding-left: 5px; padding-right: 5px;"><?=$spirit['student_report_predicate_attitude_spiritual'] ?></font></dd>
                <dt class="pred">Deskripsi</dt>
                <dd><font style=" color:#483D8B;"><?=$spirit['student_report_description_attitude_spiritual'] ?></font></dd>                                
              </dl>
            </div>
            <!-- /.box-body -->
          </div>
        </div>


         <div class="col-md-6">
          <div class="box box-success box-solid">
            <div class="box-header with-border">
              <i class="fa fa-users"></i>

              <h3 class="box-title" style="font-size: 18px; font-family: Lemonada;">Sikap Sosial</h3>
            </div>
            <!-- /.box-header -->
            <div class="box-body" style="height: 220px;">
              <dl>
                <dt class="pred">Predikat</dt>
                <dd class="si"><font class="badge bg-green" style="font-size: 14px; padding-left: 5px; padding-right: 5px;"><?=$spirit['student_report_predicate_attitude_social'] ?></font></dd>
                
                <dt class="pred">Deskripsi</dt>
                <dd><font style=" color:#483D8B;"><?=$spirit['student_report_description_attitude_social'] ?></font></dd>
         
                
              </dl>
            </div>
            <!-- /.box-body -->
          </div>
        </div>

   
       
        <div class="col-xs-12">
          <?= @$_SESSION['status']; 
                    unset($_SESSION['status']);
                ?>
          
          <div class="box box-warning box-solid">
            <div class="box-header">
              <h3 class="box-title">Nilai Pengetahuan dan Keterampilan </h3>
            </div>
            <!-- /.box-header -->
            <div class="box-body">

              <div class="scr">
              <table class="table table-bordered table-striped">
                <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" >PREDIKAT</th>
                   <th class="tngh">NILAI</th>
                  <th class="tngh">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 ><?=$master_subjects['master_subjects_name'] ;?></td>
                  <td class="tngh"><?=$nil['student_subjects_value_knowledge_total'] ;?></td>
                  <td class="tngh"><?=$nil['student_subjects_value_knowledge_predicate'] ;?></td>
                  <td class="tngh"><?=round($avg);?></td>
                  <td class="tngh"><?=$nil['student_subjects_value_skill_predicate'] ;?></td>

                  <?php                                                               
                    $i++;
                                  }
                              }?>
                  </tr>
<!-- Local Value-->
                  <tr>
                      <td colspan="2" style="font-weight: bold; font-size: 14px; background-color: #FAEBD7;">MUATAN LOKAL</td>
                      <td style="font-weight: bold; font-size: 14px; background-color: #FAEBD7;"></td>
                      <td style="font-weight: bold; font-size: 14px; background-color: #FAEBD7;"></td>
                      <td style="font-weight: bold; font-size: 14px; background-color: #FAEBD7;"></td>
                      <td style="font-weight: bold; font-size: 14px; background-color: #FAEBD7;"></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 ><?=$nl['local_subjects_value_name'] ;?></td>
                      <td class="tngh"><?=$nl['student_local_subjects_value_knowledge_total'] ;?></td>
                      <td class="tngh"><?=$nl['student_local_subjects_value_knowledge_predicate'] ;?></td>
                       <td class="tngh"><?=round($avgl);?></td>
                      <td class="tngh"><?=$nl['student_local_subjects_value_skill_predicate'] ;?></td>

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


                  <tr>
                    <td colspan="2" style="font-weight: bold; font-size: 14px; background-color: #FAEBD7;">TOTAL</td>

                  <?php

                      $nilait = $config->getData("SELECT SUM(student_subjects_value_knowledge_total)  as tp,
                      SUM(student_subjects_value_daily_project) as pro, 
                      SUM(student_subjects_value_daily_practice) as pra, 
                      SUM(student_subjects_value_daily_portfolio) as por FROM entity__student_subjects_value WHERE student_id='$student_id'  ");
                    foreach ($nilait as $npt){

                      $ttp= $npt['tp'];
                      $tok = $npt['pro']+$npt['pra']+$npt['por'];

                     $nlokalt = $config->getData("SELECT  SUM(student_local_subjects_value_knowledge_total) as tk,
                        SUM(student_local_subjects_value_daily_project) as lpro,
                        SUM(student_local_subjects_value_daily_practice)  as lpra,
                        SUM(student_local_subjects_value_daily_portfolio) as lpor
                       FROM entity__student_local_subjects_value WHERE student_id='$student_id'  GROUP BY local_subjects_value_id ");
                          foreach ($nlokalt as $nlt){ 
                      $tlp= $nlt['tk'];
                      $tlk= $nlt['lpro']+$nlt['lpra']+$nlt['lpor'];

                     

                    } }


                     $sum=$ttp+$tlp;
                     $sumk=$tok+$tlk;?>


                     
                    
                    <td><?=$ttp?></td>
                    <td><?=$student_id?></td>
                    <td><?=$tok?></td>

                  
                  </tr>
                </tfoot> -->
                               
              </table>
            </div>
              <a href="print.php?id=<?=$student_id;?>&&sc=<?=$school_id;?>" class="act-btn" title="SIMPAN NILAI" target="_blank"><i class="glyphicon glyphicon-print"></i></a>
            </div>
            <!-- /.box-body -->
         
          </div>
          <!-- /.box -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
    </section>
    <!-- /.content -->
  </div>

<!-- CONTENT END -->
<?php
    include "../../layout/footer.php";
} else {
    header("Location:../../login/logout.php");
}
?>