<?php

namespace PHPMaker2021\rdigital21;

// Table
$penilaian = Container("penilaian");
?>
<?php if ($penilaian->Visible) { ?>
<div class="ew-master-div">
<table id="tbl_penilaianmaster" class="table ew-view-table ew-master-table ew-vertical d-none">
    <tbody>
<?php if ($penilaian->penilaian_id->Visible) { // penilaian_id ?>
        <tr id="r_penilaian_id">
            <td class="<?= $penilaian->TableLeftColumnClass ?>"><template id="tpc_penilaian_penilaian_id"><?= $penilaian->penilaian_id->caption() ?></template></td>
            <td <?= $penilaian->penilaian_id->cellAttributes() ?>>
<template id="tpx_penilaian_penilaian_id" class="penilaianmaster">
<div class="btn-group" role="group" aria-label="Basic example">
    <?php
    $kode_tapel=$penilaian->kode_tapel->getViewValue();
    $penilaian_id=$penilaian->penilaian_id->getViewValue();
    $guru_id=$penilaian->guru_id->getViewValue();
    $kode_mapel=$penilaian->mapel_id->getViewValue();
    $kelas=$penilaian->kelas->getViewValue();
    $materi=$penilaian->materi->getViewValue();
    $tujuan_pembelajaran=$penilaian->tujuan_pembelajaran->getViewValue();
    $txt=$kode_tapel."|".$penilaian_id."|".$guru_id."|".$kode_mapel."|".$kelas."|".$materi."|".$tujuan_pembelajaran;
    $formatif = ExecuteScalar("SELECT COUNT(f1) FROM nilai_formatif WHERE penilaian_id='$penilaian_id'");
    $cek = ExecuteScalar("SELECT COUNT(*) FROM nilai_formatif WHERE penilaian_id='$penilaian_id'");
    $ctp= ExecuteScalar("SELECT COUNT(tujuan_pembelajaran) FROM penilaian WHERE penilaian_id='$penilaian_id'");
    $ctm= ExecuteScalar("SELECT COUNT(materi) FROM penilaian WHERE penilaian_id='$penilaian_id'");
    if ($ctp==0 && $ctm==0) {
       echo '<a href="javascript:void(0);" class="btn bg-secondary" onclick="tpm()"><i class="fas fa-remove"></i> Formatif</a>&nbsp;';
       echo '<a href="javascript:void(0);" class="btn bg-secondary" onclick="tpm()"><i class="fas fa-remove"></i> Sumatif</a>&nbsp;';
   } else {
    if ($formatif<=0 && $cek<=0) {
        echo '<a href="tool/buat_nilai_f.php?penilaian='.base64_encode($txt).'" class="btn bg-danger"><i class="fas fa-refresh"></i> Formatif</a>&nbsp;';
    } else {
        echo '<a href="" class="btn bg-success" disabled><i class="fas fa-check-square"></i> Formatif</a>&nbsp;';
    }                 
    $sumatif = ExecuteScalar("SELECT COUNT(*) FROM nilai_sumatif WHERE penilaian_id='$penilaian_id'");
    if ($sumatif<=0 && $formatif<=0) {
       echo '<a href="javascript:void(0);" class="btn bg-warning btn-sm" onclick="formatif()"><i class="fas fa-remove"></i> Sumatif</a>&nbsp;';
   } else if ($sumatif<=0 && $formatif>=0) {
    echo '<a href="tool/buat_nilai_s.php?penilaian='.base64_encode($txt).'" class="btn bg-danger"><i class="fas fa-refresh"></i> Sumatif</a>&nbsp;';
} else {
    echo '<a href="" class="btn bg-success" disabled><i class="fas fa-check-square"></i> Sumatif</a>&nbsp;';
} 
}
?>
</div>
<script>

    function formatif() { 
        alert('Pastikan Nilai Formatif Sudah Terisi');
    }

    function tpm() { 
        alert('Pastikan Tujuan Pembelajaran dan Materi Sudah Terisi');
    }
</script>
</template>
<template id="tpx_penilaian_penilaian_id"><span id="el_penilaian_penilaian_id">
<span<?= $penilaian->penilaian_id->viewAttributes() ?>><slot name="tpx_penilaian_penilaian_id"></slot></span>
</span></template>
</td>
        </tr>
<?php } ?>
<?php if ($penilaian->kode_tapel->Visible) { // kode_tapel ?>
        <tr id="r_kode_tapel">
            <td class="<?= $penilaian->TableLeftColumnClass ?>"><template id="tpc_penilaian_kode_tapel"><?= $penilaian->kode_tapel->caption() ?></template></td>
            <td <?= $penilaian->kode_tapel->cellAttributes() ?>>
<template id="tpx_penilaian_kode_tapel"><span id="el_penilaian_kode_tapel">
<span<?= $penilaian->kode_tapel->viewAttributes() ?>>
<?= $penilaian->kode_tapel->getViewValue() ?></span>
</span></template>
</td>
        </tr>
<?php } ?>
<?php if ($penilaian->guru_id->Visible) { // guru_id ?>
        <tr id="r_guru_id">
            <td class="<?= $penilaian->TableLeftColumnClass ?>"><template id="tpc_penilaian_guru_id"><?= $penilaian->guru_id->caption() ?></template></td>
            <td <?= $penilaian->guru_id->cellAttributes() ?>>
<template id="tpx_penilaian_guru_id"><span id="el_penilaian_guru_id">
<span<?= $penilaian->guru_id->viewAttributes() ?>>
<?= $penilaian->guru_id->getViewValue() ?></span>
</span></template>
</td>
        </tr>
<?php } ?>
<?php if ($penilaian->mapel_id->Visible) { // mapel_id ?>
        <tr id="r_mapel_id">
            <td class="<?= $penilaian->TableLeftColumnClass ?>"><template id="tpc_penilaian_mapel_id"><?= $penilaian->mapel_id->caption() ?></template></td>
            <td <?= $penilaian->mapel_id->cellAttributes() ?>>
<template id="tpx_penilaian_mapel_id" class="penilaianmaster">
<?php
$penilaian_id=$penilaian->penilaian_id->getViewValue();
echo $kode_mapel=ExecuteScalar("SELECT mapel_id FROM penilaian WHERE penilaian_id='$penilaian_id'");
?>
</template>
<template id="tpx_penilaian_mapel_id"><span id="el_penilaian_mapel_id">
<span<?= $penilaian->mapel_id->viewAttributes() ?>><slot name="tpx_penilaian_mapel_id"></slot></span>
</span></template>
</td>
        </tr>
<?php } ?>
<?php if ($penilaian->kelas->Visible) { // kelas ?>
        <tr id="r_kelas">
            <td class="<?= $penilaian->TableLeftColumnClass ?>"><template id="tpc_penilaian_kelas"><?= $penilaian->kelas->caption() ?></template></td>
            <td <?= $penilaian->kelas->cellAttributes() ?>>
<template id="tpx_penilaian_kelas"><span id="el_penilaian_kelas">
<span<?= $penilaian->kelas->viewAttributes() ?>>
<?= $penilaian->kelas->getViewValue() ?></span>
</span></template>
</td>
        </tr>
<?php } ?>
<?php if ($penilaian->fase->Visible) { // fase ?>
        <tr id="r_fase">
            <td class="<?= $penilaian->TableLeftColumnClass ?>"><template id="tpc_penilaian_fase"><?= $penilaian->fase->caption() ?></template></td>
            <td <?= $penilaian->fase->cellAttributes() ?>>
<template id="tpx_penilaian_fase"><span id="el_penilaian_fase">
<span<?= $penilaian->fase->viewAttributes() ?>>
<?= $penilaian->fase->getViewValue() ?></span>
</span></template>
</td>
        </tr>
<?php } ?>
    </tbody>
</table>
</div>
<div id="tpd_penilaianmaster" class="ew-custom-template"></div>
<template id="tpm_penilaianmaster">
<div id="ct_PenilaianMaster"><div id="penilaian" class="card card-primary card-outline card-body">
 <table class="table table-striped table-sm table-borderless">
    <tr id="r_kode_tapel">
        <td class="w-col-2">Kode Tahun Pelajaran</td>
        <td><slot class="ew-slot" name="tpx_penilaian_kode_tapel"></slot></td>
    </tr>
    <tr id="r_guru_id">
        <td class="w-col-2">Guru</td>
        <td><slot class="ew-slot" name="tpx_penilaian_guru_id"></slot></td>
    </tr>
    <tr id="r_mapel_id">
        <td class="w-col-2">Mata Pelajaran</td>
        <td><slot class="ew-slot" name="tpx_penilaian_mapel_id"></slot></td>
    </tr>
    <tr id="r_kelas">
        <td class="w-col-2">Kelas</td>
        <td><slot class="ew-slot" name="tpx_penilaian_kelas"></slot></td>
    </tr> 
    <tr id="r_fase">
        <td class="w-col-2">Fase</td>
        <td>Fase <slot class="ew-slot" name="tpx_penilaian_fase"></slot></td>
    </tr>
</table>
</div>
</div>
</template>
<script class="ew-apply-template">
loadjs.ready(["jsrender", "makerjs"], function() {
    ew.templateData = { rows: <?= JsonEncode($penilaian->Rows) ?> };
    ew.applyTemplate("tpd_penilaianmaster", "tpm_penilaianmaster", "penilaianmaster", "<?= $penilaian->CustomExport ?>", ew.templateData.rows[0]);
    loadjs.done("customtemplate");
});
</script>
<?php } ?>
