<!-- // created by : KuduSinau_Hendrik_081275532220 (TERIMAKASIH UNTUK MENDAPATKAN KEBERKAHAN, DENGAN TIDAK MERUBAH NAMA HAK CIPTA, PLAGIAT, DAN TIDAK MEMPERJUALBELIKAN APLIKASI INI, SEMOGA KITA SEMUA MENDAPAT MANFAAT DAN KEBERKAHAN DARI APLIKASI INI)
// created by : KuduSinau_Hendrik_081275532220 (UNTUK MASUKAN DAN SARAN SERTA PENGEMBANGAN BISA MENGHUBUNGI NOMOR) -->
<script>
    window.print();
</script>
<style>
    table {
        background-color: white;
        border-collapse: collapse;
        border-color: black;
    }

    head>tr {
        background-color: white;
        color: black;
        border-color: black;
    }

    head>tr>th {
        background-color: black;
        color: black;
        padding: 10px;
        border-color: black;
    }

    th,
    td {
        background-color: white;
        padding: 2px;
        border-color: black;

    }

    th {
        background-color: white;
        color: black;
        text-align: center;
        border-color: black;
    }

    body {
        background-color: white;
        font-family: 'Century Gothic';
        font-size: 8pt;
        border-color: black;
    }
</style>
<style type="text/css" media="print">
    @page {
        size: 297mm 210mm;
        margin: 20px;
    }
</style>

<body onload="hide_loading();">
    <div class="loading overlay">
        <div class="lds-spinner">
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
        </div>
    </div>
    <table width="95%" border="0" align="center">
        <tr text="center">
            <br><br>
            <center>
                <b>DAFTAR LEGGER NILAI</b>
            </center>
            <br><br>
        </tr>
        <tr text="center">
            <td width="12%">Nama Lembaga</td>
            <td width="50%"> : <?= $nmJenjang['sgkt_jenjang'] . ' ' . $nmStatus['nm_status'] . ' ' . $nmLembaga['nm_lembaga']; ?></td>
            <td width="12%">Wali Kelas</td>
            <td width="26%"> : <?= $teachers['gelardepan'] . ' ' . $teachers['nama_guru']; ?><?php if (!empty($teachers['gelarbelakang'])) {
                                                                                                    echo ', ' . $teachers['gelarbelakang'];
                                                                                                } else {
                                                                                                    echo $teachers['gelarbelakang'];
                                                                                                } ?></td>
        </tr>
        <tr text="center">
            <td>NSM/NPSN</td>
            <td> : <?= $nmLembaga['nsm_lembaga'] . ' / ' . $nmLembaga['npsn_lembaga']; ?></td>
            <td>Kelas/Semester</td>
            <td> : <?= $nmKelas['rombel']; ?> / Semester <?= $waktu['semester']; ?></td>
        </tr>
        <tr text="center">
            <td>Kabupaten/Kota</td>
            <td> : <?= ucwords(strtolower($nmLembaga['kab_lembaga'])); ?></td>
            <td>Tahun Pelajaran</td>
            <td> : <?php if ($waktu['semester'] == 'Ganjil') {
                        echo $waktu['tahun'] . ' / ' . ($waktu['tahun'] + 1);
                    } elseif ($waktu['semester'] == 'Genap') {
                        echo ($waktu['tahun'] - 1) . ' / ' . $waktu['tahun'];
                    }; ?></td>
        </tr>
    </table>
    <br>
    <?php if ($nmUser['kd_jenjang'] == 2) { ?>
        <table width="95%" align="center" border="1" cellspacing="0">
            <thead>
                <tr>
                    <th rowspan="2">
                        <font face="Century Gothic">No.</font>
                    </th>
                    <th rowspan="2">
                        <font face="Century Gothic">NISN</font>
                    </th>
                    <th rowspan="2">
                        <font face="Century Gothic">Nama Siswa
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">AQH</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">AKA</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">FKH</font>
                    </th>
                    <?php if (($nmKelas['tingkat'] == 'III') || ($nmKelas['tingkat'] == 'IV') || ($nmKelas['tingkat'] == 'V') || ($nmKelas['tingkat'] == 'VI')) { ?>
                        <th colspan="2">
                            <font face="Century Gothic">SKI</font>
                        </th>
                    <?php } ?>
                    <th colspan="2">
                        <font face="Century Gothic">PKN</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">INA</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">ARB</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">MTK</font>
                    </th>
                    <?php if (($nmKelas['tingkat'] == 'IV') || ($nmKelas['tingkat'] == 'V') || ($nmKelas['tingkat'] == 'VI')) { ?>
                        <th colspan="2">
                            <font face="Century Gothic">IPA</font>
                        </th>
                        <th colspan="2">
                            <font face="Century Gothic">IPS</font>
                        </th>
                    <?php } ?>
                    <th colspan="2">
                        <font face="Century Gothic">SBP</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">PJK</font>
                    </th>
                    <?php foreach ($nmMulok as $mlk) : ?>
                        <th colspan="2">
                            <font face="Century Gothic"><?= $mlk['kode_mapel'] ?></font>
                        </th>
                    <?php endforeach; ?>
                    <th colspan="2" rowspan="2">
                        <font face="Century Gothic">TOTAL</font>
                    </th>
                </tr>
                <tr>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K3</th>
                    <?php if (($nmKelas['tingkat'] == 'III') || ($nmKelas['tingkat'] == 'IV') || ($nmKelas['tingkat'] == 'V') || ($nmKelas['tingkat'] == 'VI')) { ?>
                        <th>P</th>
                        <th>K</th>
                    <?php } ?>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K8</th>
                    <?php if (($nmKelas['tingkat'] == 'IV') || ($nmKelas['tingkat'] == 'V') || ($nmKelas['tingkat'] == 'VI')) { ?>
                        <th>P</th>
                        <th>K</th>
                        <th>P</th>
                        <th>K</th>
                    <?php } ?>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <?php foreach ($nmMulok as $mlk) : ?>
                        <th>P</th>
                        <th>K</th>
                    <?php endforeach; ?>
                </tr>
            </thead>
            <tbody>
                <?php
                $i = 1;
                foreach ($students as $std) :
                ?>
                    <tr align="center">
                        <td><?php
                            echo $i . '.';
                            $i++; ?></td>
                        <td><?= $std['nisn_siswa']; ?></td>
                        <td align="left"><?= $std['nama_siswa']; ?></td>
                        <td>
                            <?php
                            foreach ($quran_hp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($quran_hk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($akidah_ap as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($akidah_ak as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($fikihp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($fikihk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <?php if (($nmKelas['tingkat'] == 'III') || ($nmKelas['tingkat'] == 'IV') || ($nmKelas['tingkat'] == 'V') || ($nmKelas['tingkat'] == 'VI')) { ?>
                            <td>
                                <?php
                                foreach ($skip as $np) :
                                    if ($np['kdp_siswa'] == $std['id_siswa']) {
                                        echo $np['nilaip_mapel'];
                                    }
                                endforeach;
                                ?>
                            </td>
                            <td>
                                <?php
                                foreach ($skik as $nk) :
                                    if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                        echo $nk['nilaik_mapel'];
                                    }
                                endforeach;
                                ?>
                            </td>
                        <?php } ?>
                        <td>
                            <?php
                            foreach ($pknp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($pknk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($b_indop as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($b_indok as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($b_arabp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($b_arabk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($mtkp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($mtkk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <?php if (($nmKelas['tingkat'] == 'IV') || ($nmKelas['tingkat'] == 'V') || ($nmKelas['tingkat'] == 'VI')) { ?>
                            <td>
                                <?php
                                foreach ($ipap as $np) :
                                    if ($np['kdp_siswa'] == $std['id_siswa']) {
                                        echo $np['nilaip_mapel'];
                                    }
                                endforeach;
                                ?>
                            </td>
                            <td>
                                <?php
                                foreach ($ipak as $nk) :
                                    if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                        echo $nk['nilaik_mapel'];
                                    }
                                endforeach;
                                ?>
                            </td>
                            <td>
                                <?php
                                foreach ($ipsp as $np) :
                                    if ($np['kdp_siswa'] == $std['id_siswa']) {
                                        echo $np['nilaip_mapel'];
                                    }
                                endforeach;
                                ?>
                            </td>
                            <td>
                                <?php
                                foreach ($ipsk as $nk) :
                                    if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                        echo $nk['nilaik_mapel'];
                                    }
                                endforeach;
                                ?>
                            </td>
                        <?php } ?>
                        <td>
                            <?php
                            foreach ($sb_prap as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($sb_prak as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($penjasorkesp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($penjasorkesk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <?php foreach ($nmMulok as $mlk) :
                        ?>
                            <td>
                                <?php
                                foreach ($npMulok as $nk) :
                                    if ($nk['kode_siswa'] == $std['id_siswa']) {
                                        if ($nk['kode_mapel'] == $mlk['kode_mapel']) {
                                            echo $nk['nilaip_mapel'];
                                        }
                                    }
                                endforeach;
                                ?>
                            </td>
                            <td>
                                <?php
                                foreach ($nkMulok as $kk) :
                                    if ($kk['kode_siswa'] == $std['id_siswa']) {
                                        if ($kk['kode_mapel'] == $mlk['kode_mapel']) {
                                            echo $kk['nilaik_mapel'];
                                        }
                                    }
                                endforeach;
                                ?>
                            </td>
                        <?php
                        endforeach;
                        ?>
                        <td>
                            <?php
                            $this->db->select_sum('n_akhirp', 'jlhp');
                            $this->db->from('t_akhirp');
                            $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
                            $this->db->join('t_students', 't_akhirp.kd_students = t_students.id_students');
                            $this->db->where('t_students.id_students', $std['id_siswa']);
                            $this->db->where('t_gmapel.kd_kelas', $kdKelas);
                            $this->db->where('t_akhirp.aktif_p', 1);
                            $this->db->where('t_gmapel.kd_tapel', $waktu['tapel']);
                            $this->db->where('t_gmapel.kd_lembaga', $nmLembaga['id_lembaga']);
                            $jlhnilaip = $this->db->get()->row_array();
                            if (is_null($jlhnilaip)) {
                                $datap = 0;
                            } else {
                                $datap = $jlhnilaip['jlhp'];
                            }
                            $this->db->select_sum('n_akhirk', 'jlhk');
                            $this->db->from('t_akhirk');
                            $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
                            $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
                            $this->db->where('t_students.id_students', $std['id_siswa']);
                            $this->db->where('t_gmapel.kd_kelas', $kdKelas);
                            $this->db->where('t_akhirk.aktif_k', 1);
                            $this->db->where('t_gmapel.kd_tapel', $waktu['tapel']);
                            $this->db->where('t_gmapel.kd_lembaga', $nmLembaga['id_lembaga']);
                            $jlhnilaip = $this->db->get()->row_array();
                            if (is_null($jlhnilaip)) {
                                $datak = 0;
                            } else {
                                $datak = $jlhnilaip['jlhk'];
                            }
                            echo $total = $datap + $datak;
                            ?>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    <?php } elseif ($nmUser['kd_jenjang'] == 3) { ?>
        <table width="95%" align="center" border="1" cellspacing="0">
            <thead>
                <tr>
                    <th rowspan="2">
                        <font face="Century Gothic">No.</font>
                    </th>
                    <th rowspan="2">
                        <font face="Century Gothic">NISN</font>
                    </th>
                    <th rowspan="2">
                        <font face="Century Gothic">Nama Siswa
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">AQH</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">AKA</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">FKH</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">SKI</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">PKN</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">INA</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">ARB</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">MTK</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">IPA</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">IPS</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">ING</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">SBD</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">PJK</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">
                            <?php if (!is_null($nmInf)) {
                                echo 'INF';
                            } else if (!is_null($nmPra)) {
                                echo 'PRK';
                            } else if (!is_null($nmInf) and !is_null($nmPra)) {
                            } ?>
                        </font>
                    </th>
                    <?php foreach ($nmMulok as $mlk) : ?>
                        <th colspan="2">
                            <font face="Century Gothic"><?= $mlk['kode_mapel'] ?></font>
                        </th>
                    <?php endforeach; ?>
                    <th colspan="2" rowspan="2">
                        <font face="Century Gothic">TOTAL</font>
                    </th>
                </tr>
                <tr>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <?php foreach ($nmMulok as $mlk) : ?>
                        <th>P</th>
                        <th>K</th>
                    <?php endforeach; ?>
                </tr>
            </thead>
            <tbody>
                <?php
                $i = 1;
                foreach ($students as $std) :
                ?>
                    <tr align="center">
                        <td><?php
                            echo $i . '.';
                            $i++; ?></td>
                        <td><?= $std['nisn_siswa']; ?></td>
                        <td align="left"><?= $std['nama_siswa']; ?></td>
                        <td>
                            <?php
                            foreach ($quran_hp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($quran_hk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($akidah_ap as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($akidah_ak as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($fikihp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($fikihk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($skip as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($skik as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($pknp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($pknk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($b_indop as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($b_indok as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($b_arabp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($b_arabk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($mtkp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($mtkk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($ipap as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($ipak as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($ipsp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($ipsk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($b_ingp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($b_ingk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($sen_budp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($sen_budk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($penjasorkesp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($penjasorkesk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php if (!is_null($nmInf)) {
                                foreach ($informatikap as $np) :
                                    if ($np['kdp_siswa'] == $std['id_siswa']) {
                                        echo $np['nilaip_mapel'];
                                    }
                                endforeach;
                            } else if (!is_null($nmPra)) {
                                foreach ($prakaryap as $np) :
                                    if ($np['kdp_siswa'] == $std['id_siswa']) {
                                        echo $np['nilaip_mapel'];
                                    }
                                endforeach;
                            } else if (!is_null($nmInf) and !is_null($nmPra)) {
                            } ?>
                        </td>
                        <td>
                            <?php if (!is_null($nmInf)) {
                                foreach ($informatikak as $nk) :
                                    if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                        echo $nk['nilaik_mapel'];
                                    }
                                endforeach;
                            } else if (!is_null($nmPra)) {
                                foreach ($prakaryak as $nk) :
                                    if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                        echo $nk['nilaik_mapel'];
                                    }
                                endforeach;
                            } else if (!is_null($nmInf) and !is_null($nmPra)) {
                            } ?>
                        </td>
                        <?php foreach ($nmMulok as $mlk) :
                        ?>
                            <td>
                                <?php
                                foreach ($npMulok as $nk) :
                                    if ($nk['kode_siswa'] == $std['id_siswa']) {
                                        if ($nk['kode_mapel'] == $mlk['kode_mapel']) {
                                            echo $nk['nilaip_mapel'];
                                        }
                                    }
                                endforeach;
                                ?>
                            </td>
                            <td>
                                <?php
                                foreach ($nkMulok as $kk) :
                                    if ($kk['kode_siswa'] == $std['id_siswa']) {
                                        if ($kk['kode_mapel'] == $mlk['kode_mapel']) {
                                            echo $kk['nilaik_mapel'];
                                        }
                                    }
                                endforeach;
                                ?>
                            </td>
                        <?php
                        endforeach;
                        ?>
                        <td>
                            <?php
                            $this->db->select_sum('n_akhirp', 'jlhp');
                            $this->db->from('t_akhirp');
                            $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
                            $this->db->join('t_students', 't_akhirp.kd_students = t_students.id_students');
                            $this->db->where('t_students.id_students', $std['id_siswa']);
                            $this->db->where('t_gmapel.kd_kelas', $kdKelas);
                            $this->db->where('t_akhirp.aktif_p', 1);
                            $this->db->where('t_gmapel.kd_tapel', $waktu['tapel']);
                            $this->db->where('t_gmapel.kd_lembaga', $nmLembaga['id_lembaga']);
                            $jlhnilaip = $this->db->get()->row_array();
                            if (is_null($jlhnilaip)) {
                                $datap = 0;
                            } else {
                                $datap = $jlhnilaip['jlhp'];
                            }
                            $this->db->select_sum('n_akhirk', 'jlhk');
                            $this->db->from('t_akhirk');
                            $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
                            $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
                            $this->db->where('t_students.id_students', $std['id_siswa']);
                            $this->db->where('t_gmapel.kd_kelas', $kdKelas);
                            $this->db->where('t_akhirk.aktif_k', 1);
                            $this->db->where('t_gmapel.kd_tapel', $waktu['tapel']);
                            $this->db->where('t_gmapel.kd_lembaga', $nmLembaga['id_lembaga']);
                            $jlhnilaip = $this->db->get()->row_array();
                            if (is_null($jlhnilaip)) {
                                $datak = 0;
                            } else {
                                $datak = $jlhnilaip['jlhk'];
                            }
                            echo $total = $datap + $datak;
                            ?>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    <?php } elseif ($nmUser['kd_jenjang'] == 4) { ?>
        <table width="95%" align="center" border="1" cellspacing="0">
            <thead>
                <tr>
                    <th rowspan="2">
                        <font face="Century Gothic">No.</font>
                    </th>
                    <th rowspan="2">
                        <font face="Century Gothic">NISN</font>
                    </th>
                    <th rowspan="2">
                        <font face="Century Gothic">Nama Siswa
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">AQH</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">AKA</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">FKH</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">SKI</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">PKN</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">INA</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">ARB</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">MTK</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">SJI</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">ING</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">SBD</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">PJK</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">PDK</font>
                    </th>
                    <?php foreach ($nmMulok as $mlk) : ?>
                        <th colspan="2">
                            <font face="Century Gothic"><?= $mlk['kode_mapel'] ?></font>
                        </th>
                    <?php endforeach; ?>
                    <?php foreach ($nmPeminatan as $mlk) : ?>
                        <th colspan="2">
                            <font face="Century Gothic"><?= $mlk['kode_mapel'] ?></font>
                        </th>
                    <?php endforeach; ?>
                    <?php foreach ($nmPilihan as $mlk) : ?>
                        <th colspan="2">
                            <font face="Century Gothic"><?= $mlk['kode_mapel'] ?></font>
                        </th>
                    <?php endforeach; ?>
                    <th colspan="2" rowspan="2">
                        <font face="Century Gothic">TOTAL</font>
                    </th>
                </tr>
                <tr>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <?php foreach ($nmMulok as $mlk) : ?>
                        <th>P</th>
                        <th>K</th>
                    <?php endforeach; ?>
                    <?php foreach ($nmPeminatan as $mlk) : ?>
                        <th>P</th>
                        <th>K</th>
                    <?php endforeach; ?>
                    <?php foreach ($nmPilihan as $mlk) : ?>
                        <th>P</th>
                        <th>K</th>
                    <?php endforeach; ?>
                </tr>
            </thead>
            <tbody>
                <?php
                $i = 1;
                foreach ($students as $std) :
                ?>
                    <tr align="center">
                        <td><?php
                            echo $i . '.';
                            $i++; ?></td>
                        <td><?= $std['nisn_siswa']; ?></td>
                        <td align="left"><?= $std['nama_siswa']; ?></td>
                        <td>
                            <?php
                            foreach ($quran_hp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($quran_hk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($akidah_ap as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($akidah_ak as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($fikihp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($fikihk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($skip as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($skik as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($pknp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($pknk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($b_indop as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($b_indok as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($b_arabp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($b_arabk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($mtkp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($mtkk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($sej_indop as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($sej_indok as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($b_ingp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($b_ingk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($sen_budp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($sen_budk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($penjasorkesp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($penjasorkesk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($pra_kwhp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($pra_kwhk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <?php foreach ($nmMulok as $mlk) :
                        ?>
                            <td>
                                <?php
                                foreach ($npMulok as $nk) :
                                    if ($nk['kode_siswa'] == $std['id_siswa']) {
                                        if ($nk['kode_mapel'] == $mlk['kode_mapel']) {
                                            echo $nk['nilaip_mapel'];
                                        }
                                    }
                                endforeach;
                                ?>
                            </td>
                            <td>
                                <?php
                                foreach ($nkMulok as $kk) :
                                    if ($kk['kode_siswa'] == $std['id_siswa']) {
                                        if ($kk['kode_mapel'] == $mlk['kode_mapel']) {
                                            echo $kk['nilaik_mapel'];
                                        }
                                    }
                                endforeach;
                                ?>
                            </td>
                        <?php
                        endforeach;
                        ?>
                        <?php foreach ($nmPeminatan as $mlk) :
                        ?>
                            <td>
                                <?php
                                foreach ($npPeminatan as $nk) :
                                    if ($nk['kode_siswa'] == $std['id_siswa']) {
                                        if ($nk['kode_mapel'] == $mlk['kode_mapel']) {
                                            echo $nk['nilaip_mapel'];
                                        }
                                    }
                                endforeach;
                                ?>
                            </td>
                            <td>
                                <?php
                                foreach ($nkPeminatan as $kk) :
                                    if ($kk['kode_siswa'] == $std['id_siswa']) {
                                        if ($kk['kode_mapel'] == $mlk['kode_mapel']) {
                                            echo $kk['nilaik_mapel'];
                                        }
                                    }
                                endforeach;
                                ?>
                            </td>
                        <?php
                        endforeach;
                        ?>
                        <?php foreach ($nmPilihan as $mlk) :
                        ?>
                            <td>
                                <?php
                                foreach ($npPilihan as $nk) :
                                    if ($nk['kode_siswa'] == $std['id_siswa']) {
                                        if ($nk['kode_mapel'] == $mlk['kode_mapel']) {
                                            echo $nk['nilaip_mapel'];
                                        }
                                    }
                                endforeach;
                                ?>
                            </td>
                            <td>
                                <?php
                                foreach ($nkPilihan as $kk) :
                                    if ($kk['kode_siswa'] == $std['id_siswa']) {
                                        if ($kk['kode_mapel'] == $mlk['kode_mapel']) {
                                            echo $kk['nilaik_mapel'];
                                        }
                                    }
                                endforeach;
                                ?>
                            </td>
                        <?php
                        endforeach;
                        ?>
                        <td>
                            <?php
                            $this->db->select_sum('n_akhirp', 'jlhp');
                            $this->db->from('t_akhirp');
                            $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
                            $this->db->join('t_students', 't_akhirp.kd_students = t_students.id_students');
                            $this->db->where('t_students.id_students', $std['id_siswa']);
                            $this->db->where('t_gmapel.kd_kelas', $kdKelas);
                            $this->db->where('t_akhirp.aktif_p', 1);
                            $this->db->where('t_gmapel.kd_tapel', $waktu['tapel']);
                            $this->db->where('t_gmapel.kd_lembaga', $nmLembaga['id_lembaga']);
                            $jlhnilaip = $this->db->get()->row_array();
                            if (is_null($jlhnilaip)) {
                                $datap = 0;
                            } else {
                                $datap = $jlhnilaip['jlhp'];
                            }
                            $this->db->select_sum('n_akhirk', 'jlhk');
                            $this->db->from('t_akhirk');
                            $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
                            $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
                            $this->db->where('t_students.id_students', $std['id_siswa']);
                            $this->db->where('t_gmapel.kd_kelas', $kdKelas);
                            $this->db->where('t_akhirk.aktif_k', 1);
                            $this->db->where('t_gmapel.kd_tapel', $waktu['tapel']);
                            $this->db->where('t_gmapel.kd_lembaga', $nmLembaga['id_lembaga']);
                            $jlhnilaip = $this->db->get()->row_array();
                            if (is_null($jlhnilaip)) {
                                $datak = 0;
                            } else {
                                $datak = $jlhnilaip['jlhk'];
                            }
                            echo $total = $datap + $datak;
                            ?>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    <?php } elseif ($nmUser['kd_jenjang'] == 5) { ?>
        <table width="95%" align="center" border="1" cellspacing="0">
            <thead>
                <tr>
                    <th rowspan="2">
                        <font face="Century Gothic">No.</font>
                    </th>
                    <th rowspan="2">
                        <font face="Century Gothic">NISN</font>
                    </th>
                    <th rowspan="2">
                        <font face="Century Gothic">Nama Siswa
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">AQH</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">AKA</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">FKH</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">SKI</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">PKN</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">INA</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">ARB</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">MTK</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">SJI</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">ING</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">SBD</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">PJK</font>
                    </th>
                    <th colspan="2">
                        <font face="Century Gothic">PDK</font>
                    </th>

                    <?php foreach ($nmMulok as $mlk) : ?>
                        <th colspan="2">
                            <font face="Century Gothic"><?= $mlk['kode_mapel'] ?></font>
                        </th>
                    <?php endforeach; ?>

                    <?php foreach ($nmDbk as $mlk) : ?>
                        <th colspan="2">
                            <font face="Century Gothic"><?= $mlk['kode_mapel'] ?></font>
                        </th>
                    <?php endforeach; ?>

                    <?php foreach ($nmDpk as $mlk) : ?>
                        <th colspan="2">
                            <font face="Century Gothic"><?= $mlk['kode_mapel'] ?></font>
                        </th>
                    <?php endforeach; ?>

                    <?php foreach ($nmPk as $mlk) : ?>
                        <th colspan="2">
                            <font face="Century Gothic"><?= $mlk['kode_mapel'] ?></font>
                        </th>
                    <?php endforeach; ?>

                    <th colspan="2" rowspan="2">
                        <font face="Century Gothic">TOTAL</font>
                    </th>
                </tr>
                <tr>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <th>P</th>
                    <th>K</th>
                    <?php foreach ($nmMulok as $mlk) : ?>
                        <th>P</th>
                        <th>K</th>
                    <?php endforeach; ?>
                    <?php foreach ($nmDbk as $mlk) : ?>
                        <th>P</th>
                        <th>K</th>
                    <?php endforeach; ?>
                    <?php foreach ($nmDpk as $mlk) : ?>
                        <th>P</th>
                        <th>K</th>
                    <?php endforeach; ?>
                    <?php foreach ($nmPk as $mlk) : ?>
                        <th>P</th>
                        <th>K</th>
                    <?php endforeach; ?>
                </tr>
            </thead>
            <tbody>
                <?php
                $i = 1;
                foreach ($students as $std) :
                ?>
                    <tr align="center">
                        <td><?php
                            echo $i . '.';
                            $i++; ?></td>
                        <td><?= $std['nisn_siswa']; ?></td>
                        <td align="left"><?= $std['nama_siswa']; ?></td>
                        <td>
                            <?php
                            foreach ($quran_hp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($quran_hk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($akidah_ap as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($akidah_ak as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($fikihp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($fikihk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($skip as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($skik as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($pknp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($pknk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($b_indop as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($b_indok as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($b_arabp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($b_arabk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($mtkp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($mtkk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($sej_indop as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($sej_indok as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($b_ingp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($b_ingk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($sen_budp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($sen_budk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($penjasorkesp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($penjasorkesk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($pra_kwhp as $np) :
                                if ($np['kdp_siswa'] == $std['id_siswa']) {
                                    echo $np['nilaip_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <td>
                            <?php
                            foreach ($pra_kwhk as $nk) :
                                if ($nk['kdk_siswa'] == $std['id_siswa']) {
                                    echo $nk['nilaik_mapel'];
                                }
                            endforeach;
                            ?>
                        </td>
                        <?php foreach ($nmMulok as $mlk) :
                        ?>
                            <td>
                                <?php
                                foreach ($npMulok as $nk) :
                                    if ($nk['kode_siswa'] == $std['id_siswa']) {
                                        if ($nk['kode_mapel'] == $mlk['kode_mapel']) {
                                            echo $nk['nilaip_mapel'];
                                        }
                                    }
                                endforeach;
                                ?>
                            </td>
                            <td>
                                <?php
                                foreach ($nkMulok as $kk) :
                                    if ($kk['kode_siswa'] == $std['id_siswa']) {
                                        if ($kk['kode_mapel'] == $mlk['kode_mapel']) {
                                            echo $kk['nilaik_mapel'];
                                        }
                                    }
                                endforeach;
                                ?>
                            </td>
                        <?php
                        endforeach;
                        ?>
                        <?php foreach ($nmDbk as $mlk) :
                        ?>
                            <td>
                                <?php
                                foreach ($npDbk as $nk) :
                                    if ($nk['kode_siswa'] == $std['id_siswa']) {
                                        if ($nk['kode_mapel'] == $mlk['kode_mapel']) {
                                            echo $nk['nilaip_mapel'];
                                        }
                                    }
                                endforeach;
                                ?>
                            </td>
                            <td>
                                <?php
                                foreach ($nkDbk as $kk) :
                                    if ($kk['kode_siswa'] == $std['id_siswa']) {
                                        if ($kk['kode_mapel'] == $mlk['kode_mapel']) {
                                            echo $kk['nilaik_mapel'];
                                        }
                                    }
                                endforeach;
                                ?>
                            </td>
                        <?php
                        endforeach;
                        ?>
                        <?php foreach ($nmDpk as $mlk) :
                        ?>
                            <td>
                                <?php
                                foreach ($npDpk as $nk) :
                                    if ($nk['kode_siswa'] == $std['id_siswa']) {
                                        if ($nk['kode_mapel'] == $mlk['kode_mapel']) {
                                            echo $nk['nilaip_mapel'];
                                        }
                                    }
                                endforeach;
                                ?>
                            </td>
                            <td>
                                <?php
                                foreach ($nkDpk as $kk) :
                                    if ($kk['kode_siswa'] == $std['id_siswa']) {
                                        if ($kk['kode_mapel'] == $mlk['kode_mapel']) {
                                            echo $kk['nilaik_mapel'];
                                        }
                                    }
                                endforeach;
                                ?>
                            </td>
                        <?php
                        endforeach;
                        ?>
                        <?php foreach ($nmPk as $mlk) :
                        ?>
                            <td>
                                <?php
                                foreach ($npPk as $nk) :
                                    if ($nk['kode_siswa'] == $std['id_siswa']) {
                                        if ($nk['kode_mapel'] == $mlk['kode_mapel']) {
                                            echo $nk['nilaip_mapel'];
                                        }
                                    }
                                endforeach;
                                ?>
                            </td>
                            <td>
                                <?php
                                foreach ($nkPk as $kk) :
                                    if ($kk['kode_siswa'] == $std['id_siswa']) {
                                        if ($kk['kode_mapel'] == $mlk['kode_mapel']) {
                                            echo $kk['nilaik_mapel'];
                                        }
                                    }
                                endforeach;
                                ?>
                            </td>
                        <?php
                        endforeach;
                        ?>
                        <td>
                            <?php
                            $this->db->select_sum('n_akhirp', 'jlhp');
                            $this->db->from('t_akhirp');
                            $this->db->join('t_gmapel', 't_akhirp.kd_gmapel = t_gmapel.id_gmapel');
                            $this->db->join('t_students', 't_akhirp.kd_students = t_students.id_students');
                            $this->db->where('t_students.id_students', $std['id_siswa']);
                            $this->db->where('t_gmapel.kd_kelas', $kdKelas);
                            $this->db->where('t_akhirp.aktif_p', 1);
                            $this->db->where('t_gmapel.kd_tapel', $waktu['tapel']);
                            $this->db->where('t_gmapel.kd_lembaga', $nmLembaga['id_lembaga']);
                            $jlhnilaip = $this->db->get()->row_array();
                            if (is_null($jlhnilaip)) {
                                $datap = 0;
                            } else {
                                $datap = $jlhnilaip['jlhp'];
                            }
                            $this->db->select_sum('n_akhirk', 'jlhk');
                            $this->db->from('t_akhirk');
                            $this->db->join('t_gmapel', 't_akhirk.kd_gmapel = t_gmapel.id_gmapel');
                            $this->db->join('t_students', 't_akhirk.kd_students = t_students.id_students');
                            $this->db->where('t_students.id_students', $std['id_siswa']);
                            $this->db->where('t_gmapel.kd_kelas', $kdKelas);
                            $this->db->where('t_akhirk.aktif_k', 1);
                            $this->db->where('t_gmapel.kd_tapel', $waktu['tapel']);
                            $this->db->where('t_gmapel.kd_lembaga', $nmLembaga['id_lembaga']);
                            $jlhnilaip = $this->db->get()->row_array();
                            if (is_null($jlhnilaip)) {
                                $datak = 0;
                            } else {
                                $datak = $jlhnilaip['jlhk'];
                            }
                            echo $total = $datap + $datak;
                            ?>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    <?php } ?>
    <small style="margin-left: 0.4in;  font-size: 6pt;">Keterangan :</small>
    <table>
        <tr>
            <td>
                <table style="margin-left: 0.4in;  font-size: 6pt;">
                    <tbody>
                        <tr>
                            <td>P</td>
                            <td> : </td>
                            <td>Pengetahuan</td>
                        </tr>
                        <tr>
                            <td>K</td>
                            <td> : </td>
                            <td>Keterampilan</td>
                        </tr>
                        <?php foreach ($nmMulok as $mlk) : ?>
                            <tr>
                                <td><?= $mlk['kode_mapel']; ?></td>
                                <td> : </td>
                                <td><?= ucwords(strtolower($mlk['nama_mapel'])); ?></td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </td>
            <?php if ($nmUser['kd_jenjang'] == 4) { ?>
                <td>
                    <table style="margin-left: 0.4in;  font-size: 6pt;">
                        <tbody>
                            <?php foreach ($nmPeminatan as $mlk) : ?>
                                <tr>
                                    <td><?= $mlk['kode_mapel']; ?></td>
                                    <td> : </td>
                                    <td><?= ucwords(strtolower($mlk['nama_mapel'])); ?></td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </td>
                <td>
                    <table style="margin-left: 0.4in;  font-size: 6pt;">
                        <tbody>
                            <?php foreach ($nmPilihan as $mlk) : ?>
                                <tr>
                                    <td><?= $mlk['kode_mapel']; ?></td>
                                    <td> : </td>
                                    <td><?= ucwords(strtolower($mlk['nama_mapel'])); ?></td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </td>
            <?php } elseif ($nmUser['kd_jenjang'] == 5) { ?>
                <td>
                    <table style="margin-left: 0.4in;  font-size: 6pt;">
                        <tbody>
                            <?php foreach ($nmDbk as $mlk) : ?>
                                <tr>
                                    <td><?= $mlk['kode_mapel']; ?></td>
                                    <td> : </td>
                                    <td><?= ucwords(strtolower($mlk['nama_mapel'])); ?></td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </td>
                <td>
                    <table style="margin-left: 0.4in;  font-size: 6pt;">
                        <tbody>
                            <?php foreach ($nmDpk as $mlk) : ?>
                                <tr>
                                    <td><?= $mlk['kode_mapel']; ?></td>
                                    <td> : </td>
                                    <td><?= ucwords(strtolower($mlk['nama_mapel'])); ?></td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </td>
                <td>
                    <table style="margin-left: 0.4in;  font-size: 6pt;">
                        <tbody>
                            <?php foreach ($nmPk as $mlk) : ?>
                                <tr>
                                    <td><?= $mlk['kode_mapel']; ?></td>
                                    <td> : </td>
                                    <td><?= ucwords(strtolower($mlk['nama_mapel'])); ?></td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </td>
            <?php } ?>
        </tr>
    </table>
    <br>
    <table width="95%" border="0" align="center">
        <tr text="center">
            <td width="10%"></td>
            <td width="50%"></td>
            <td width="12%"></td>
            <td width="28%"><?php
                            if ((($nmKelas['tingkat'] == 'VI') || ($nmKelas['tingkat'] == 'IX') || ($nmKelas['tingkat'] == 'XII')) && ($waktu['semester'] == 'Genap')) {
                                echo ucwords(strtolower($waktu['tempat'])) . ', ' . $this->m_walas->tgl_indo(date('d-m-Y', strtotime($waktu['tanggal3'])));
                            } else {
                                echo ucwords(strtolower($waktu['tempat'])) . ', ' . $this->m_walas->tgl_indo(date('d-m-Y', strtotime($waktu['tanggal'])));
                            } ?></td>
        </tr>
        <tr text="center">
            <td></td>
            <td>Mengetahui,</td>
            <td></td>
            <td></td>
        </tr>
        <tr text="center">
            <td></td>
            <td>Kepala Madrasah</td>
            <td></td>
            <td>Guru Mata Pelajaran,</td>
        </tr>
        <tr text="center">
            <td></td>
            <td><br><br><br><u><?= $waktu['gelardepan'] . ' ' . $waktu['kamad']; ?><?php if (!empty($waktu['gelarbelakang'])) {
                                                                                        echo ', ' . $waktu['gelarbelakang'];
                                                                                    } else {
                                                                                        echo $waktu['gelarbelakang'];
                                                                                    } ?></u>
            </td>
            <td></td>
            <td><br><br><br><u><?= $teachers['gelardepan'] . ' ' . $teachers['nama_guru']; ?><?php if (!empty($teachers['gelarbelakang'])) {
                                                                                                    echo ', ' . $teachers['gelarbelakang'];
                                                                                                } else {
                                                                                                    echo $teachers['gelarbelakang'];
                                                                                                } ?></u>
            </td>
        </tr>
        <tr text="center">
            <td></td>
            <td>NIP. <?= $waktu['nip_kamad']; ?></td>
            <td></td>
            <td>NIP. <?= $teachers['nip_guru']; ?></td>
        </tr>
    </table>
</body>
<script>
    let fadeTarget = document.querySelector(".loading")

    function show_loading() {
        fadeTarget.style.display = "block";
        fadeTarget.style.opacity = 1;
    }

    function hide_loading() {
        // fadeTarget.style.display = "none";
        let fadeEffect = setInterval(() => {
            if (!fadeTarget.style.opacity) {
                fadeTarget.style.opacity = 1;
            }
            if (fadeTarget.style.opacity > 0) {
                fadeTarget.style.opacity -= 0.1;
            } else {
                clearInterval(fadeEffect)
                fadeTarget.style.display = "none"
            }
        }, 100)
    }
</script>

</html>