<?php

namespace PHPMaker2021\rkm21;

use PHPMaker2021\rkm21\{UserProfile, Language, AdvancedSecurity, Timer, HttpErrorHandler};
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Container\ContainerInterface;
use DI\Container as Container;
use DI\ContainerBuilder;
use Selective\SameSiteCookie\SameSiteCookieConfiguration;
use Selective\SameSiteCookie\SameSiteCookieMiddleware;
use Selective\SameSiteCookie\SameSiteSessionMiddleware;
use Slim\Factory\AppFactory;
use Slim\Factory\ServerRequestCreatorFactory;
use Slim\Exception\HttpInternalServerErrorException;
use Nyholm\Psr7\Factory\Psr17Factory;
use Nyholm\Psr7Server\ServerRequestCreator;

// Relative path
$RELATIVE_PATH = "";

// Require files
require_once "vendor/autoload.php";
require_once "src/constants.php";
require_once "src/config.php";
require_once "src/phpfn.php";
require_once "src/userfn.php";
?> 

<div style="page-break-after:none; min-height: 100%;"> 

    <?php if (isset($_GET['p'])): ?>

        <?php
        $gurl = $_GET['url'];
        $url=urldecode($gurl);
        $text= explode("|", $url);
        $nis = $text[0];
        $nisn = $text[1];
        $nama_sekolah = $text[2];
        $kelas = $text[3];
        $alamat = $text[4];
        $kecamatan = $text[5];
        $nama_lengkap = $text[6];
        define("nama_lengkap", $nama_lengkap);
        $tahun_pelajaran = $text[7]; 
        $tanggal_cetak_rapor = $text[8];
        $project_id=$_GET['p'];
        $project=ExecuteScalar("SELECT project FROM db_proyek where project_id='$project_id'");
        $cek=ExecuteScalar("SELECT COUNT(*) FROM db_nilai where proyek='$project' AND nis='$nis'");
        $nama_proyek=ExecuteScalar("SELECT nama_proyek FROM db_proyek where project_id='$project_id'");
        ?>


        <script type="text/javascript">
            window.print();
        </script>

        <style type="text/css">
        .pace-progress{
            display: none;
        }
        body{
            font-family: "Arial Narrow";
            font-size: 11pt;
            text-align: justify; 
            line-height: 12pt;  
        } 
        p{
            line-height: 12pt;  
        }
        .center{
            text-align: center;
            line-height: 12pt;
        }
        .justify{
            text-align: justify;    
            line-height: 12pt;
        } 
        #footer {
            font-size: 8pt;
        }
    </style>

    <?php   
    if ($cek!=0) {  
        $header = "<table class='table-borderless' cellspacing='0' cellpadding='0' width='100%'>
        <tr>
        <td width='104'>&nbsp;Nama</td>
        <td width='329'><strong>:&nbsp; {$nama_lengkap}</strong></td>
        <td width='129'>&nbsp;Kelas</td>
        <td width='147'><strong>:&nbsp; {$kelas}</strong></td>
        </tr>
        <tr>
        <td width='104'>&nbsp;NISN/NIS</td>
        <td width='329'><strong>:&nbsp; {$nisn} / {$nis}</strong></td>
        <td width='129'>&nbsp;Fase</td>
        <td width='147'><strong>:&nbsp; D</strong></td>
        </tr>
        <tr>
        <td width='104'>&nbsp;Nama Sekolah</td>
        <td width='329'><strong>:&nbsp; {$nama_sekolah}</strong></td>
        <td width='129'>&nbsp;Tahun Pelajaran</td>
        <td width='147'><strong>:&nbsp; {$tahun_pelajaran}</strong></td>
        </tr>
        <tr>
        <td width='104'>&nbsp;Alamat</td>
        <td width='329'><strong>:&nbsp; {$alamat}, {$kecamatan}</strong></td>
        </tr>
        </table>";
        echo $header;
        ?> 
        <hr> 
        <table class="table-bordered" width="100%">
            <tr>
                <td>
                    <strong>
                        &nbsp;<?=$project_id?>. <?=$nama_proyek ?>
                    </strong>
                </td>
                <td><strong><center>MB</center></strong></td>
                <td><strong><center>SB</center></strong></td>
                <td><strong><center>BSH</center></strong></td>
                <td><strong><center>SAB</center></strong></td>
            </tr>  
            <tr>
                <?php  
                $sql_dimensi="SELECT DISTINCT dimensi FROM db_nilai WHERE nis='$nis' AND proyek='$project'";
                $stmt_dimensi = ExecuteQuery($sql_dimensi); 
                while ($row_dimensi = $stmt_dimensi->fetch()) { ?>  
                    <td colspan="5" class="bg-secondary">
                        <strong>
                            <div style="margin-left: 20px; margin-Right: 15px; text-align: justify;"><?= $dimensi=$row_dimensi['dimensi']?></div>
                        </strong>
                    </td> 
                </tr>
                <tr>
                    <?php  
                    $sql_sub_elemen1="SELECT nilai, sub_elemen FROM db_nilai WHERE nis='$nis' AND proyek='$project' AND dimensi='$dimensi'";
                    $stmt_sub_elemen1 = ExecuteQuery($sql_sub_elemen1); 
                    while ($row_sub_elemen1 = $stmt_sub_elemen1->fetch()) { ?>  
                        <td colspan="5">
                            <strong>
                                <div style="margin-left: 20px; margin-Right: 15px; text-align: justify;"><?=$sub_elemen1=$row_sub_elemen1['sub_elemen'];?></div>
                            </strong>
                        </td>
                    </tr>  
                    <tr>
                        <?php  
                        $sql_fase_capaian="SELECT fase_capaian_d FROM db_dimensi WHERE dimensi='$dimensi' AND sub_elemen='$sub_elemen1'";
                        $stmt_fase_capaian = ExecuteQuery($sql_fase_capaian);
                        while ($row_fase_capaian = $stmt_fase_capaian->fetch()) { ?>  
                            <td width="80%"> 
                                <div style="margin-left: 20px; margin-Right: 5px; text-align: justify;"><?=$fase_capaian=$row_fase_capaian['fase_capaian_d'];?> </div>
                            </td>
                            <?php 
                            $nilai_sub_elemen1=$row_sub_elemen1['nilai'];
                            if ($nilai_sub_elemen1=='MB') {
                                echo $bb = "
                                <td width='5%'><strong><center><i class='fa fa-check'></i></center></strong></td>
                                <td width='5%'><strong><center></center></strong></td>
                                <td width='5%'><strong><center></center></strong></td>
                                <td width='5%'><strong><center></center></strong></td>
                                ";
                            }
                            if ($nilai_sub_elemen1=='SB') {
                                echo $mb = "
                                <td width='5%'><strong><center></center></strong></td>
                                <td width='5%'><strong><center><i class='fa fa-check'></i></center></strong></td>
                                <td width='5%'><strong><center></center></strong></td>
                                <td width='5%'><strong><center></center></strong></td>
                                ";
                            }
                            if ($nilai_sub_elemen1=='BSH') {
                                echo $bsh = "
                                <td width='5%'><strong><center></center></strong></td>
                                <td width='5%'><strong><center></center></strong></td>
                                <td width='5%'><strong><center><i class='fa fa-check'></i></center></strong></td>
                                <td width='5%'><strong><center></center></strong></td>
                                ";
                            }
                            if ($nilai_sub_elemen1=='SAB') {
                                echo $sb = "
                                <td width='5%'><strong><center></center></strong></td>
                                <td width='5%'><strong><center></center></strong></td>
                                <td width='5%'><strong><center></center></strong></td>
                                <td width='5%'><strong><center><i class='fa fa-check'></i></center></strong></td>
                                ";
                            }
                            ?>
                        </tr>  
                    <?php } ?>
                <?php } ?>
            <?php } ?>
        </table>
        <br>
        <table border="1" width="100%">
            <tr>
                <td><div style="margin: 5px;">Catatan Proses</div></td>
            </tr>
            <tr>
                <td>
                    <div style="margin: 5px;">
                        <table> 
                            <tr>
                                <?php   
                                $cek_sab=ExecuteScalar("SELECT count(*) FROM db_nilai WHERE nis='$nis' AND proyek='$project' AND nilai='SAB'");
                                $cek_bsh=ExecuteScalar("SELECT count(*) FROM db_nilai WHERE nis='$nis' AND proyek='$project' AND nilai='BSH'");
                                $cek_sb=ExecuteScalar("SELECT count(*) FROM db_nilai WHERE nis='$nis' AND proyek='$project' AND nilai='SB'");
                                $cek_mb=ExecuteScalar("SELECT count(*) FROM db_nilai WHERE nis='$nis' AND proyek='$project' AND nilai='MB'");


                                echo "Dalam Mengerjakan Projek ini ".nama_lengkap." ";

                                if ($cek_sab!="0") {
                                    echo "Memiliki kemampuan yang sangat baik dalam "; 
                                    $sql_nilai=" SELECT * FROM db_nilai WHERE nis='$nis' AND proyek='$project' AND nilai='SAB'";
                                    $stmt_nilai = ExecuteQuery($sql_nilai); 
                                    while ($row_nilai = $stmt_nilai->fetch()) {  
                                        echo $row_nilai['sub_elemen'].", "; 
                                    }
                                } else { echo ""; }

                                if ($cek_sab!="0" && $cek_bsh=="0" && $cek_sb=="0" && $cek_mb=="0") {
                                    echo "Memiliki kemampuan yang sangat baik dalam "; 
                                    $sql_nilai=" SELECT * FROM db_nilai WHERE nis='$nis' AND proyek='$project' AND nilai='SAB'";
                                    $stmt_nilai = ExecuteQuery($sql_nilai); 
                                    while ($row_nilai = $stmt_nilai->fetch()) {  
                                        echo $row_nilai['sub_elemen'].". "; 
                                    }
                                } else { echo ""; }

                                if ($cek_bsh!="0" && $cek_sab=="0") {
                                    echo " Memiliki kemampuan yang baik dalam "; 
                                    $sql_nilai=" SELECT * FROM db_nilai WHERE nis='$nis' AND proyek='$project' AND nilai='BSH'";
                                    $stmt_nilai = ExecuteQuery($sql_nilai); 
                                    while ($row_nilai = $stmt_nilai->fetch()) {  
                                        echo $row_nilai['sub_elemen'].", ";  
                                    }
                                } else { echo ""; }

                                if ($cek_bsh!="0") {
                                    echo " dan Memiliki kemampuan yang baik dalam "; 
                                    $sql_nilai=" SELECT * FROM db_nilai WHERE nis='$nis' AND proyek='$project' AND nilai='BSH'";
                                    $stmt_nilai = ExecuteQuery($sql_nilai); 
                                    while ($row_nilai = $stmt_nilai->fetch()) {  
                                        echo $row_nilai['sub_elemen'].", ";  
                                    }
                                } else { echo ""; }

                                if ($cek_bsh!="0" && $cek_sb=="0" && $cek_mb=="0") {
                                    echo " serta Memiliki kemampuan yang baik dalam "; 
                                    $sql_nilai=" SELECT * FROM db_nilai WHERE nis='$nis' AND proyek='$project' AND nilai='BSH'";
                                    $stmt_nilai = ExecuteQuery($sql_nilai); 
                                    while ($row_nilai = $stmt_nilai->fetch()) {  
                                        echo $row_nilai['sub_elemen'].". ";  
                                    }
                                } else { echo ""; }

                                if ($cek_sb!="0" && $cek_bsh=="0" && $cek_sab=="0") {
                                    echo " Memiliki kemampuan yang cukup dalam "; 
                                    $sql_nilai=" SELECT * FROM db_nilai WHERE nis='$nis' AND proyek='$project' AND nilai='SB'";
                                    $stmt_nilai = ExecuteQuery($sql_nilai); 
                                    while ($row_nilai = $stmt_nilai->fetch()) {  
                                        echo $row_nilai['sub_elemen'].", ";  
                                    }
                                } else { echo ""; }

                                if ($cek_sb!="0") {
                                    echo " dan Memiliki kemampuan yang cukup dalam "; 
                                    $sql_nilai=" SELECT * FROM db_nilai WHERE nis='$nis' AND proyek='$project' AND nilai='SB'";
                                    $stmt_nilai = ExecuteQuery($sql_nilai); 
                                    while ($row_nilai = $stmt_nilai->fetch()) {  
                                        echo $row_nilai['sub_elemen'].", ";  
                                    }
                                } else { echo ""; }

                                if ($cek_sb!="0" && $cek_mb=="0") {
                                    echo " serta Memiliki kemampuan yang cukup dalam "; 
                                    $sql_nilai=" SELECT * FROM db_nilai WHERE nis='$nis' AND proyek='$project' AND nilai='SB'";
                                    $stmt_nilai = ExecuteQuery($sql_nilai); 
                                    while ($row_nilai = $stmt_nilai->fetch()) {  
                                        echo $row_nilai['sub_elemen'].". ";  
                                    }
                                } else { echo ""; }

                                if ($cek_mb!="0") {
                                    echo "serta Perlu Bimbingan dalam "; 
                                    $sql_nilai=" SELECT * FROM db_nilai WHERE nis='$nis' AND proyek='$project' AND nilai='MB'";
                                    $stmt_nilai = ExecuteQuery($sql_nilai); 
                                    while ($row_nilai = $stmt_nilai->fetch()) {  
                                        echo $row_nilai['sub_elemen'].". ";  
                                    }
                                } else { echo ""; }
                                //echo ".";
                                ?>     
                            </table>
                        </div>
                    </td>
                </tr> 
            </table>

            <?php 
            echo $footer="
            <div id='footer' style='bottom: 0px; position: fixed;'>
            ".$nisn."/".$nis." | ".$nama_lengkap." | Kelas : ".$kelas." | TP : ".$tahun_pelajaran."
            </div>";  
            ?> 

        <?php } else { 
            echo "<script>";
            echo "window.alert('Nilai Proyek Belum Ada')";
            echo "</script>"; 
            echo '<meta http-equiv="refresh" content="0;url=Act?act=cetak&nis='.$nis.'" />';
        } 
        ?>

        <meta http-equiv="refresh" content="0;url=Act?act=cetak&nis=<?=$nis?>" />

    <?php  endif ?>

</div>