<?php

namespace PHPMaker2021\rdigital21;

use PHPMaker2021\rdigital21\{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";
?>

<section>
    <div class="row">

        <div class="col-md-4">
            <div class="card card-success card-outline bg-light">
                <div class="card-body">
                    <h4>Petunjuk</h4>
                    <table>
                        <tr>
                            <td valign="top" align="justify">1.</td>
                            <td valign="top" align="justify">Tampilkan Data Rapor dengan Memilih Kelas pada form disamping</td>
                        </tr>
                        <tr>
                            <td valign="top" align="justify">2.</td>
                            <td valign="top" align="justify">Cetak dengan Pilih Tombol pada masing masing kolom</td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>

        <div class="col-md-8">
            <div class="card card-success card-outline">
                <div class="card-body">
                    <center>
                        <h5>Tahun Pelajaran / Kode : <?= tapel() ?> / <?= $ktp = kode_tapel() ?></h5>
                    </center>

                    <form action="#tampilkan" method="">
                        <div class="form-group row">
                            <select class="form-control col-12" id="kelas" name="kelas" required>
                                <option value="">Pilih Kelas</option>
                                <?php
                                $gkelas = JsEncode(CurrentUserInfo('kelas'));
                                $kelas = ExecuteQuery("SELECT DISTINCT kelas FROM peserta_didik WHERE kode_tapel='$ktp' and kelas='$gkelas'");
                                while ($kelaslist = $kelas->fetch()) {
                                    echo "<option value='" . $kelaslist['kelas'] . "'>" . $kelaslist['kelas'] . "</option>";
                                }
                                ?>
                            </select>
                        </div>
                        <div class="form-group row">
                            <input class="form-control" type="hidden" id="kode_tapel" name="kode_tapel" value="<?= $ktp ?>">
                            <div class="col-md-6">
                                <button class="btn btn-success btn-block m-1" type="submit" id="tampilkan" name="tampilkan">Tampilkan</button>
                            </div>
                            <div class="col-md-6">
                                <a class="btn btn-warning btn-block m-1" href="CRapor">Refresh</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</section>

<section id="tampilkan">
    <?php
    if (isset($_GET['tampilkan'])) { ?>
        <div class="table-responsive">

            <table class="table table-striped table-hover table-sm">
                <tr style="background-color: #40546a; color:white">
                    <td>NO</td>
                    <td>Kelas</td>
                    <td>NIS</td>
                    <td>NISN</td>
                    <td>Nama</td>
                    <td>ADM RAPOR</td>
                    <td>RAPOR UMUM</td>
                    <td>RAPOR KHUSUS</td>
                    <td>RAPOR P5</td>
                </tr>
                <?php
                $no = 1;
                $kelas = $_GET['kelas'];
                $pd = ExecuteQuery("SELECT DISTINCT kelas,nis,nisn,nama FROM peserta_didik where kelas='$kelas' AND kode_tapel='$ktp'");
                while ($pdlist = $pd->fetch()) {
                    echo
                    '<tr>
                    <td>' . $no . '</td>
                    <td>' . $pdlist['kelas'] . '</td>
                    <td>' . $pdlist['nis'] . '</td>
                    <td>' . $pdlist['nisn'] . '</td>
                    <td class="text-nowrap">' . $pdlist['nama'] . '</td>
                    <td class="text-nowrap"><a href="print/pdf.php?p=cover&ktp=' . $ktp . '&nis=' . $pdlist['nis'] . '" class="btn btn-success btn-sm" target="_blank">ADM RAPOR</a></td>
                    <td class="text-nowrap"><a href="print/pdf.php?p=rapor1&ktp=' . $ktp . '&nis=' . $pdlist['nis'] . '" class="btn btn-info btn-sm" target="_blank">RAPOR UMUM</a></td> 
                    <td class="text-nowrap"><a href="print/pdf.php?p=rapor2&ktp=' . $ktp . '&nis=' . $pdlist['nis'] . '" class="btn btn-primary btn-sm" target="_blank">RAPOR KHUSUS</a></td>
                    <td class="text-nowrap"><button type="button" class="btn btn-warning btn-sm" data-toggle="modal" data-target="#exampleModal' . $nis = $pdlist['nis'] . '" class="btn btn-warning btn-sm">RAPOR P5</button></td> 
                    </tr>';
                ?>
                    <!-- Modal -->
                    <div class="modal fade" id="exampleModal<?= $nis ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                        <div class="modal-dialog" role="document">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title" id="exampleModalLabel">Cetak P5</h5>
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">&times;</span>
                                    </button>
                                </div>
                                <center>
                                    <div class="modal-body row">
                                        <?php
                                        $proyek = ExecuteQuery("SELECT project_id, project FROM proyek where kelas='$kelas'");
                                        while ($proyeklist = $proyek->fetch()) {
                                            echo '<div class="col"><a href="print/pdf.php?p=raporp5&pid=' . $proyeklist['project_id'] . '&nis=' . $pdlist['nis'] . '" class="btn btn-primary btn-block" target="_blank">' . $proyeklist['project'] . '</a></div>';
                                        }
                                        ?>
                                    </div>
                                </center>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-danger btn-block" data-dismiss="modal">Tutup</button>
                                </div>
                            </div>
                        </div>
                    </div>
                <?php $no++;
                }
                ?>
            </table>
        </div>
    <?php }  ?>
</section>