<?php

namespace PHPMaker2021\rdigital21;

// Page object
$PenilaianDelete = &$Page;
?>
<script>
var currentForm, currentPageID;
var fpenilaiandelete;
loadjs.ready("head", function () {
    var $ = jQuery;
    // Form object
    currentPageID = ew.PAGE_ID = "delete";
    fpenilaiandelete = currentForm = new ew.Form("fpenilaiandelete", "delete");
    loadjs.done("fpenilaiandelete");
});
</script>
<script>
loadjs.ready("head", function () {
    // Write your table-specific client script here, no need to add script tags.
});
</script>
<script>
if (!ew.vars.tables.penilaian) ew.vars.tables.penilaian = <?= JsonEncode(GetClientVar("tables", "penilaian")) ?>;
</script>
<?php $Page->showPageHeader(); ?>
<?php
$Page->showMessage();
?>
<form name="fpenilaiandelete" id="fpenilaiandelete" class="form-inline ew-form ew-delete-form" action="<?= CurrentPageUrl(false) ?>" method="post">
<?php if (Config("CHECK_TOKEN")) { ?>
<input type="hidden" name="<?= $TokenNameKey ?>" value="<?= $TokenName ?>"><!-- CSRF token name -->
<input type="hidden" name="<?= $TokenValueKey ?>" value="<?= $TokenValue ?>"><!-- CSRF token value -->
<?php } ?>
<input type="hidden" name="t" value="penilaian">
<input type="hidden" name="action" id="action" value="delete">
<?php foreach ($Page->RecKeys as $key) { ?>
<?php $keyvalue = is_array($key) ? implode(Config("COMPOSITE_KEY_SEPARATOR"), $key) : $key; ?>
<input type="hidden" name="key_m[]" value="<?= HtmlEncode($keyvalue) ?>">
<?php } ?>
<div class="card ew-card ew-grid">
<div class="<?= ResponsiveTableClass() ?>card-body ew-grid-middle-panel">
<table class="table ew-table">
    <thead>
    <tr class="ew-table-header">
<?php if ($Page->penilaian_id->Visible) { // penilaian_id ?>
        <th class="<?= $Page->penilaian_id->headerCellClass() ?>"><span id="elh_penilaian_penilaian_id" class="penilaian_penilaian_id"><?= $Page->penilaian_id->caption() ?></span></th>
<?php } ?>
<?php if ($Page->kode_tapel->Visible) { // kode_tapel ?>
        <th class="<?= $Page->kode_tapel->headerCellClass() ?>"><span id="elh_penilaian_kode_tapel" class="penilaian_kode_tapel"><?= $Page->kode_tapel->caption() ?></span></th>
<?php } ?>
<?php if ($Page->guru_id->Visible) { // guru_id ?>
        <th class="<?= $Page->guru_id->headerCellClass() ?>"><span id="elh_penilaian_guru_id" class="penilaian_guru_id"><?= $Page->guru_id->caption() ?></span></th>
<?php } ?>
<?php if ($Page->mapel_id->Visible) { // mapel_id ?>
        <th class="<?= $Page->mapel_id->headerCellClass() ?>"><span id="elh_penilaian_mapel_id" class="penilaian_mapel_id"><?= $Page->mapel_id->caption() ?></span></th>
<?php } ?>
<?php if ($Page->kelas->Visible) { // kelas ?>
        <th class="<?= $Page->kelas->headerCellClass() ?>"><span id="elh_penilaian_kelas" class="penilaian_kelas"><?= $Page->kelas->caption() ?></span></th>
<?php } ?>
<?php if ($Page->fase->Visible) { // fase ?>
        <th class="<?= $Page->fase->headerCellClass() ?>"><span id="elh_penilaian_fase" class="penilaian_fase"><?= $Page->fase->caption() ?></span></th>
<?php } ?>
    </tr>
    </thead>
    <tbody>
<?php
$Page->RecordCount = 0;
$i = 0;
while (!$Page->Recordset->EOF) {
    $Page->RecordCount++;
    $Page->RowCount++;

    // Set row properties
    $Page->resetAttributes();
    $Page->RowType = ROWTYPE_VIEW; // View

    // Get the field contents
    $Page->loadRowValues($Page->Recordset);

    // Render row
    $Page->renderRow();
?>
    <tr <?= $Page->rowAttributes() ?>>
<?php if ($Page->penilaian_id->Visible) { // penilaian_id ?>
        <td <?= $Page->penilaian_id->cellAttributes() ?>>
<span id="el<?= $Page->RowCount ?>_penilaian_penilaian_id" class="penilaian_penilaian_id">
<span<?= $Page->penilaian_id->viewAttributes() ?>><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>
</span>
</span>
</td>
<?php } ?>
<?php if ($Page->kode_tapel->Visible) { // kode_tapel ?>
        <td <?= $Page->kode_tapel->cellAttributes() ?>>
<span id="el<?= $Page->RowCount ?>_penilaian_kode_tapel" class="penilaian_kode_tapel">
<span<?= $Page->kode_tapel->viewAttributes() ?>>
<?= $Page->kode_tapel->getViewValue() ?></span>
</span>
</td>
<?php } ?>
<?php if ($Page->guru_id->Visible) { // guru_id ?>
        <td <?= $Page->guru_id->cellAttributes() ?>>
<span id="el<?= $Page->RowCount ?>_penilaian_guru_id" class="penilaian_guru_id">
<span<?= $Page->guru_id->viewAttributes() ?>>
<?= $Page->guru_id->getViewValue() ?></span>
</span>
</td>
<?php } ?>
<?php if ($Page->mapel_id->Visible) { // mapel_id ?>
        <td <?= $Page->mapel_id->cellAttributes() ?>>
<span id="el<?= $Page->RowCount ?>_penilaian_mapel_id" class="penilaian_mapel_id">
<span<?= $Page->mapel_id->viewAttributes() ?>><?php
$penilaian_id=$penilaian->penilaian_id->getViewValue();
echo $kode_mapel=ExecuteScalar("SELECT mapel_id FROM penilaian WHERE penilaian_id='$penilaian_id'");
?>
</span>
</span>
</td>
<?php } ?>
<?php if ($Page->kelas->Visible) { // kelas ?>
        <td <?= $Page->kelas->cellAttributes() ?>>
<span id="el<?= $Page->RowCount ?>_penilaian_kelas" class="penilaian_kelas">
<span<?= $Page->kelas->viewAttributes() ?>>
<?= $Page->kelas->getViewValue() ?></span>
</span>
</td>
<?php } ?>
<?php if ($Page->fase->Visible) { // fase ?>
        <td <?= $Page->fase->cellAttributes() ?>>
<span id="el<?= $Page->RowCount ?>_penilaian_fase" class="penilaian_fase">
<span<?= $Page->fase->viewAttributes() ?>>
<?= $Page->fase->getViewValue() ?></span>
</span>
</td>
<?php } ?>
    </tr>
<?php
    $Page->Recordset->moveNext();
}
$Page->Recordset->close();
?>
</tbody>
</table>
</div>
</div>
<div>
<button class="btn btn-primary ew-btn" name="btn-action" id="btn-action" type="submit"><?= $Language->phrase("DeleteBtn") ?></button>
<button class="btn btn-default ew-btn" name="btn-cancel" id="btn-cancel" type="button" data-href="<?= HtmlEncode(GetUrl($Page->getReturnUrl())) ?>"><?= $Language->phrase("CancelBtn") ?></button>
</div>
</form>
<?php
$Page->showPageFooter();
echo GetDebugMessage();
?>
<script>
loadjs.ready("load", function () {
    // Write your table-specific startup script here, no need to add script tags.
});
</script>
