<?php

namespace PHPMaker2021\rkm21;

use Doctrine\DBAL\ParameterType;

/**
 * Page class
 */
class NilaiDelete extends Nilai
{
    use MessagesTrait;

    // Page ID
    public $PageID = "delete";

    // Project ID
    public $ProjectID = PROJECT_ID;

    // Table name
    public $TableName = 'nilai';

    // Page object name
    public $PageObjName = "NilaiDelete";

    // Rendering View
    public $RenderingView = false;

    // Page headings
    public $Heading = "";
    public $Subheading = "";
    public $PageHeader;
    public $PageFooter;

    // Page terminated
    private $terminated = false;

    // Page heading
    public function pageHeading()
    {
        global $Language;
        if ($this->Heading != "") {
            return $this->Heading;
        }
        if (method_exists($this, "tableCaption")) {
            return $this->tableCaption();
        }
        return "";
    }

    // Page subheading
    public function pageSubheading()
    {
        global $Language;
        if ($this->Subheading != "") {
            return $this->Subheading;
        }
        if ($this->TableName) {
            return $Language->phrase($this->PageID);
        }
        return "";
    }

    // Page name
    public function pageName()
    {
        return CurrentPageName();
    }

    // Page URL
    public function pageUrl()
    {
        $url = ScriptName() . "?";
        if ($this->UseTokenInUrl) {
            $url .= "t=" . $this->TableVar . "&"; // Add page token
        }
        return $url;
    }

    // Show Page Header
    public function showPageHeader()
    {
        $header = $this->PageHeader;
        $this->pageDataRendering($header);
        if ($header != "") { // Header exists, display
            echo '<p id="ew-page-header">' . $header . '</p>';
        }
    }

    // Show Page Footer
    public function showPageFooter()
    {
        $footer = $this->PageFooter;
        $this->pageDataRendered($footer);
        if ($footer != "") { // Footer exists, display
            echo '<p id="ew-page-footer">' . $footer . '</p>';
        }
    }

    // Validate page request
    protected function isPageRequest()
    {
        global $CurrentForm;
        if ($this->UseTokenInUrl) {
            if ($CurrentForm) {
                return ($this->TableVar == $CurrentForm->getValue("t"));
            }
            if (Get("t") !== null) {
                return ($this->TableVar == Get("t"));
            }
        }
        return true;
    }

    // Constructor
    public function __construct()
    {
        global $Language, $DashboardReport, $DebugTimer;
        global $UserTable;

        // Initialize
        $GLOBALS["Page"] = &$this;

        // Language object
        $Language = Container("language");

        // Parent constuctor
        parent::__construct();

        // Table object (nilai)
        if (!isset($GLOBALS["nilai"]) || get_class($GLOBALS["nilai"]) == PROJECT_NAMESPACE . "nilai") {
            $GLOBALS["nilai"] = &$this;
        }

        // Page URL
        $pageUrl = $this->pageUrl();

        // Table name (for backward compatibility only)
        if (!defined(PROJECT_NAMESPACE . "TABLE_NAME")) {
            define(PROJECT_NAMESPACE . "TABLE_NAME", 'nilai');
        }

        // Start timer
        $DebugTimer = Container("timer");

        // Debug message
        LoadDebugMessage();

        // Open connection
        $GLOBALS["Conn"] = $GLOBALS["Conn"] ?? $this->getConnection();

        // User table object
        $UserTable = Container("usertable");
    }

    // Get content from stream
    public function getContents($stream = null): string
    {
        global $Response;
        return is_object($Response) ? $Response->getBody() : ob_get_clean();
    }

    // Is lookup
    public function isLookup()
    {
        return SameText(Route(0), Config("API_LOOKUP_ACTION"));
    }

    // Is AutoFill
    public function isAutoFill()
    {
        return $this->isLookup() && SameText(Post("ajax"), "autofill");
    }

    // Is AutoSuggest
    public function isAutoSuggest()
    {
        return $this->isLookup() && SameText(Post("ajax"), "autosuggest");
    }

    // Is modal lookup
    public function isModalLookup()
    {
        return $this->isLookup() && SameText(Post("ajax"), "modal");
    }

    // Is terminated
    public function isTerminated()
    {
        return $this->terminated;
    }

    /**
     * Terminate page
     *
     * @param string $url URL for direction
     * @return void
     */
    public function terminate($url = "")
    {
        if ($this->terminated) {
            return;
        }
        global $ExportFileName, $TempImages, $DashboardReport, $Response;

        // Page is terminated
        $this->terminated = true;

         // Page Unload event
        if (method_exists($this, "pageUnload")) {
            $this->pageUnload();
        }

        // Global Page Unloaded event (in userfn*.php)
        Page_Unloaded();

        // Export
        if ($this->CustomExport && $this->CustomExport == $this->Export && array_key_exists($this->CustomExport, Config("EXPORT_CLASSES"))) {
            $content = $this->getContents();
            if ($ExportFileName == "") {
                $ExportFileName = $this->TableVar;
            }
            $class = PROJECT_NAMESPACE . Config("EXPORT_CLASSES." . $this->CustomExport);
            if (class_exists($class)) {
                $doc = new $class(Container("nilai"));
                $doc->Text = @$content;
                if ($this->isExport("email")) {
                    echo $this->exportEmail($doc->Text);
                } else {
                    $doc->export();
                }
                DeleteTempImages(); // Delete temp images
                return;
            }
        }
        if (!IsApi() && method_exists($this, "pageRedirecting")) {
            $this->pageRedirecting($url);
        }

        // Close connection
        CloseConnections();

        // Return for API
        if (IsApi()) {
            $res = $url === true;
            if (!$res) { // Show error
                WriteJson(array_merge(["success" => false], $this->getMessages()));
            }
            return;
        } else { // Check if response is JSON
            if (StartsString("application/json", $Response->getHeaderLine("Content-type")) && $Response->getBody()->getSize()) { // With JSON response
                $this->clearMessages();
                return;
            }
        }

        // Go to URL if specified
        if ($url != "") {
            if (!Config("DEBUG") && ob_get_length()) {
                ob_end_clean();
            }
            SaveDebugMessage();
            Redirect(GetUrl($url));
        }
        return; // Return to controller
    }

    // Get records from recordset
    protected function getRecordsFromRecordset($rs, $current = false)
    {
        $rows = [];
        if (is_object($rs)) { // Recordset
            while ($rs && !$rs->EOF) {
                $this->loadRowValues($rs); // Set up DbValue/CurrentValue
                $row = $this->getRecordFromArray($rs->fields);
                if ($current) {
                    return $row;
                } else {
                    $rows[] = $row;
                }
                $rs->moveNext();
            }
        } elseif (is_array($rs)) {
            foreach ($rs as $ar) {
                $row = $this->getRecordFromArray($ar);
                if ($current) {
                    return $row;
                } else {
                    $rows[] = $row;
                }
            }
        }
        return $rows;
    }

    // Get record from array
    protected function getRecordFromArray($ar)
    {
        $row = [];
        if (is_array($ar)) {
            foreach ($ar as $fldname => $val) {
                if (array_key_exists($fldname, $this->Fields) && ($this->Fields[$fldname]->Visible || $this->Fields[$fldname]->IsPrimaryKey)) { // Primary key or Visible
                    $fld = &$this->Fields[$fldname];
                    if ($fld->HtmlTag == "FILE") { // Upload field
                        if (EmptyValue($val)) {
                            $row[$fldname] = null;
                        } else {
                            if ($fld->DataType == DATATYPE_BLOB) {
                                $url = FullUrl(GetApiUrl(Config("API_FILE_ACTION") .
                                    "/" . $fld->TableVar . "/" . $fld->Param . "/" . rawurlencode($this->getRecordKeyValue($ar))));
                                $row[$fldname] = ["type" => ContentType($val), "url" => $url, "name" => $fld->Param . ContentExtension($val)];
                            } elseif (!$fld->UploadMultiple || !ContainsString($val, Config("MULTIPLE_UPLOAD_SEPARATOR"))) { // Single file
                                $url = FullUrl(GetApiUrl(Config("API_FILE_ACTION") .
                                    "/" . $fld->TableVar . "/" . Encrypt($fld->physicalUploadPath() . $val)));
                                $row[$fldname] = ["type" => MimeContentType($val), "url" => $url, "name" => $val];
                            } else { // Multiple files
                                $files = explode(Config("MULTIPLE_UPLOAD_SEPARATOR"), $val);
                                $ar = [];
                                foreach ($files as $file) {
                                    $url = FullUrl(GetApiUrl(Config("API_FILE_ACTION") .
                                        "/" . $fld->TableVar . "/" . Encrypt($fld->physicalUploadPath() . $file)));
                                    if (!EmptyValue($file)) {
                                        $ar[] = ["type" => MimeContentType($file), "url" => $url, "name" => $file];
                                    }
                                }
                                $row[$fldname] = $ar;
                            }
                        }
                    } else {
                        $row[$fldname] = $val;
                    }
                }
            }
        }
        return $row;
    }

    // Get record key value from array
    protected function getRecordKeyValue($ar)
    {
        $key = "";
        if (is_array($ar)) {
            $key .= @$ar['nilai_id'];
        }
        return $key;
    }

    /**
     * Hide fields for add/edit
     *
     * @return void
     */
    protected function hideFieldsForAddEdit()
    {
        if ($this->isAdd() || $this->isCopy() || $this->isGridAdd()) {
            $this->nilai_id->Visible = false;
        }
    }
    public $DbMasterFilter = "";
    public $DbDetailFilter = "";
    public $StartRecord;
    public $TotalRecords = 0;
    public $RecordCount;
    public $RecKeys = [];
    public $StartRowCount = 1;
    public $RowCount = 0;

    /**
     * Page run
     *
     * @return void
     */
    public function run()
    {
        global $ExportType, $CustomExportType, $ExportFileName, $UserProfile, $Language, $Security, $CurrentForm;
        $this->CurrentAction = Param("action"); // Set up current action
        $this->nilai_id->setVisibility();
        $this->kode_tapel->setVisibility();
        $this->guru_id->setVisibility();
        $this->kode_mapel->setVisibility();
        $this->kelas->setVisibility();
        $this->nis->setVisibility();
        $this->nama->setVisibility();
        $this->jk->setVisibility();
        $this->f1->setVisibility();
        $this->f2->setVisibility();
        $this->f3->setVisibility();
        $this->f4->setVisibility();
        $this->f5->setVisibility();
        $this->f6->setVisibility();
        $this->f7->setVisibility();
        $this->f8->setVisibility();
        $this->f9->setVisibility();
        $this->f10->setVisibility();
        $this->f11->setVisibility();
        $this->f12->setVisibility();
        $this->f13->setVisibility();
        $this->f14->setVisibility();
        $this->f15->setVisibility();
        $this->naf->setVisibility();
        $this->s1->setVisibility();
        $this->s2->setVisibility();
        $this->s3->setVisibility();
        $this->s4->setVisibility();
        $this->s5->setVisibility();
        $this->s6->setVisibility();
        $this->s7->setVisibility();
        $this->s8->setVisibility();
        $this->nas->setVisibility();
        $this->sts->setVisibility();
        $this->sas->setVisibility();
        $this->nr1->setVisibility();
        $this->nr2->setVisibility();
        $this->hideFieldsForAddEdit();

        // Do not use lookup cache
        $this->setUseLookupCache(false);

        // Global Page Loading event (in userfn*.php)
        Page_Loading();

        // Page Load event
        if (method_exists($this, "pageLoad")) {
            $this->pageLoad();
        }

        // Set up lookup cache

        // Set up Breadcrumb
        $this->setupBreadcrumb();

        // Load key parameters
        $this->RecKeys = $this->getRecordKeys(); // Load record keys
        $filter = $this->getFilterFromRecordKeys();
        if ($filter == "") {
            $this->terminate("NilaiList"); // Prevent SQL injection, return to list
            return;
        }

        // Set up filter (WHERE Clause)
        $this->CurrentFilter = $filter;

        // Check if valid User ID
        $conn = $this->getConnection();
        $sql = $this->getSql($this->CurrentFilter);
        $rows = $conn->fetchAll($sql);
        $res = true;
        foreach ($rows as $row) {
            $this->loadRowValues($row);
            if (!$this->showOptionLink("delete")) {
                $userIdMsg = $Language->phrase("NoDeletePermission");
                $this->setFailureMessage($userIdMsg);
                $res = false;
                break;
            }
        }
        if (!$res) {
            $this->terminate("NilaiList"); // Return to list
            return;
        }

        // Get action
        if (IsApi()) {
            $this->CurrentAction = "delete"; // Delete record directly
        } elseif (Post("action") !== null) {
            $this->CurrentAction = Post("action");
        } elseif (Get("action") == "1") {
            $this->CurrentAction = "delete"; // Delete record directly
        } else {
            $this->CurrentAction = "delete"; // Delete record directly
        }
        if ($this->isDelete()) {
            $this->SendEmail = true; // Send email on delete success
            if ($this->deleteRows()) { // Delete rows
                if ($this->getSuccessMessage() == "") {
                    $this->setSuccessMessage($Language->phrase("DeleteSuccess")); // Set up success message
                }
                if (IsApi()) {
                    $this->terminate(true);
                    return;
                } else {
                    $this->terminate($this->getReturnUrl()); // Return to caller
                    return;
                }
            } else { // Delete failed
                if (IsApi()) {
                    $this->terminate();
                    return;
                }
                $this->terminate($this->getReturnUrl()); // Return to caller
                return;
            }
        }
        if ($this->isShow()) { // Load records for display
            if ($this->Recordset = $this->loadRecordset()) {
                $this->TotalRecords = $this->Recordset->recordCount(); // Get record count
            }
            if ($this->TotalRecords <= 0) { // No record found, exit
                if ($this->Recordset) {
                    $this->Recordset->close();
                }
                $this->terminate("NilaiList"); // Return to list
                return;
            }
        }

        // Set LoginStatus / Page_Rendering / Page_Render
        if (!IsApi() && !$this->isTerminated()) {
            // Pass table and field properties to client side
            $this->toClientVar(["tableCaption"], ["caption", "Visible", "Required", "IsInvalid", "Raw"]);

            // Setup login status
            SetupLoginStatus();

            // Pass login status to client side
            SetClientVar("login", LoginStatus());

            // Global Page Rendering event (in userfn*.php)
            Page_Rendering();

            // Page Render event
            if (method_exists($this, "pageRender")) {
                $this->pageRender();
            }
        }
    }

    // Load recordset
    public function loadRecordset($offset = -1, $rowcnt = -1)
    {
        // Load List page SQL (QueryBuilder)
        $sql = $this->getListSql();

        // Load recordset
        if ($offset > -1) {
            $sql->setFirstResult($offset);
        }
        if ($rowcnt > 0) {
            $sql->setMaxResults($rowcnt);
        }
        $stmt = $sql->execute();
        $rs = new Recordset($stmt, $sql);

        // Call Recordset Selected event
        $this->recordsetSelected($rs);
        return $rs;
    }

    /**
     * Load row based on key values
     *
     * @return void
     */
    public function loadRow()
    {
        global $Security, $Language;
        $filter = $this->getRecordFilter();

        // Call Row Selecting event
        $this->rowSelecting($filter);

        // Load SQL based on filter
        $this->CurrentFilter = $filter;
        $sql = $this->getCurrentSql();
        $conn = $this->getConnection();
        $res = false;
        $row = $conn->fetchAssoc($sql);
        if ($row) {
            $res = true;
            $this->loadRowValues($row); // Load row values
        }
        return $res;
    }

    /**
     * Load row values from recordset or record
     *
     * @param Recordset|array $rs Record
     * @return void
     */
    public function loadRowValues($rs = null)
    {
        if (is_array($rs)) {
            $row = $rs;
        } elseif ($rs && property_exists($rs, "fields")) { // Recordset
            $row = $rs->fields;
        } else {
            $row = $this->newRow();
        }

        // Call Row Selected event
        $this->rowSelected($row);
        if (!$rs) {
            return;
        }
        $this->nilai_id->setDbValue($row['nilai_id']);
        $this->kode_tapel->setDbValue($row['kode_tapel']);
        $this->guru_id->setDbValue($row['guru_id']);
        $this->kode_mapel->setDbValue($row['kode_mapel']);
        $this->kelas->setDbValue($row['kelas']);
        $this->nis->setDbValue($row['nis']);
        $this->nama->setDbValue($row['nama']);
        $this->jk->setDbValue($row['jk']);
        $this->f1->setDbValue($row['f1']);
        $this->f2->setDbValue($row['f2']);
        $this->f3->setDbValue($row['f3']);
        $this->f4->setDbValue($row['f4']);
        $this->f5->setDbValue($row['f5']);
        $this->f6->setDbValue($row['f6']);
        $this->f7->setDbValue($row['f7']);
        $this->f8->setDbValue($row['f8']);
        $this->f9->setDbValue($row['f9']);
        $this->f10->setDbValue($row['f10']);
        $this->f11->setDbValue($row['f11']);
        $this->f12->setDbValue($row['f12']);
        $this->f13->setDbValue($row['f13']);
        $this->f14->setDbValue($row['f14']);
        $this->f15->setDbValue($row['f15']);
        $this->naf->setDbValue($row['naf']);
        $this->s1->setDbValue($row['s1']);
        $this->s2->setDbValue($row['s2']);
        $this->s3->setDbValue($row['s3']);
        $this->s4->setDbValue($row['s4']);
        $this->s5->setDbValue($row['s5']);
        $this->s6->setDbValue($row['s6']);
        $this->s7->setDbValue($row['s7']);
        $this->s8->setDbValue($row['s8']);
        $this->nas->setDbValue($row['nas']);
        $this->sts->setDbValue($row['sts']);
        $this->sas->setDbValue($row['sas']);
        $this->nr1->setDbValue($row['nr1']);
        $this->nr2->setDbValue($row['nr2']);
    }

    // Return a row with default values
    protected function newRow()
    {
        $row = [];
        $row['nilai_id'] = null;
        $row['kode_tapel'] = null;
        $row['guru_id'] = null;
        $row['kode_mapel'] = null;
        $row['kelas'] = null;
        $row['nis'] = null;
        $row['nama'] = null;
        $row['jk'] = null;
        $row['f1'] = null;
        $row['f2'] = null;
        $row['f3'] = null;
        $row['f4'] = null;
        $row['f5'] = null;
        $row['f6'] = null;
        $row['f7'] = null;
        $row['f8'] = null;
        $row['f9'] = null;
        $row['f10'] = null;
        $row['f11'] = null;
        $row['f12'] = null;
        $row['f13'] = null;
        $row['f14'] = null;
        $row['f15'] = null;
        $row['naf'] = null;
        $row['s1'] = null;
        $row['s2'] = null;
        $row['s3'] = null;
        $row['s4'] = null;
        $row['s5'] = null;
        $row['s6'] = null;
        $row['s7'] = null;
        $row['s8'] = null;
        $row['nas'] = null;
        $row['sts'] = null;
        $row['sas'] = null;
        $row['nr1'] = null;
        $row['nr2'] = null;
        return $row;
    }

    // Render row values based on field settings
    public function renderRow()
    {
        global $Security, $Language, $CurrentLanguage;

        // Initialize URLs

        // Call Row_Rendering event
        $this->rowRendering();

        // Common render codes for all row types

        // nilai_id
        $this->nilai_id->CellCssStyle = "white-space: nowrap;";

        // kode_tapel
        $this->kode_tapel->CellCssStyle = "white-space: nowrap;";

        // guru_id
        $this->guru_id->CellCssStyle = "white-space: nowrap;";

        // kode_mapel
        $this->kode_mapel->CellCssStyle = "white-space: nowrap;";

        // kelas
        $this->kelas->CellCssStyle = "white-space: nowrap;";

        // nis
        $this->nis->CellCssStyle = "white-space: nowrap;";

        // nama
        $this->nama->CellCssStyle = "white-space: nowrap;";

        // jk
        $this->jk->CellCssStyle = "white-space: nowrap;";

        // f1
        $this->f1->CellCssStyle = "white-space: nowrap;";

        // f2
        $this->f2->CellCssStyle = "white-space: nowrap;";

        // f3
        $this->f3->CellCssStyle = "white-space: nowrap;";

        // f4
        $this->f4->CellCssStyle = "white-space: nowrap;";

        // f5
        $this->f5->CellCssStyle = "white-space: nowrap;";

        // f6
        $this->f6->CellCssStyle = "white-space: nowrap;";

        // f7
        $this->f7->CellCssStyle = "white-space: nowrap;";

        // f8
        $this->f8->CellCssStyle = "white-space: nowrap;";

        // f9
        $this->f9->CellCssStyle = "white-space: nowrap;";

        // f10
        $this->f10->CellCssStyle = "white-space: nowrap;";

        // f11
        $this->f11->CellCssStyle = "white-space: nowrap;";

        // f12
        $this->f12->CellCssStyle = "white-space: nowrap;";

        // f13
        $this->f13->CellCssStyle = "white-space: nowrap;";

        // f14
        $this->f14->CellCssStyle = "white-space: nowrap;";

        // f15
        $this->f15->CellCssStyle = "white-space: nowrap;";

        // naf
        $this->naf->CellCssStyle = "white-space: nowrap;";

        // s1
        $this->s1->CellCssStyle = "white-space: nowrap;";

        // s2
        $this->s2->CellCssStyle = "white-space: nowrap;";

        // s3
        $this->s3->CellCssStyle = "white-space: nowrap;";

        // s4
        $this->s4->CellCssStyle = "white-space: nowrap;";

        // s5
        $this->s5->CellCssStyle = "white-space: nowrap;";

        // s6
        $this->s6->CellCssStyle = "white-space: nowrap;";

        // s7
        $this->s7->CellCssStyle = "white-space: nowrap;";

        // s8
        $this->s8->CellCssStyle = "white-space: nowrap;";

        // nas
        $this->nas->CellCssStyle = "white-space: nowrap;";

        // sts
        $this->sts->CellCssStyle = "white-space: nowrap;";

        // sas
        $this->sas->CellCssStyle = "white-space: nowrap;";

        // nr1
        $this->nr1->CellCssStyle = "white-space: nowrap;";

        // nr2
        $this->nr2->CellCssStyle = "white-space: nowrap;";
        if ($this->RowType == ROWTYPE_VIEW) {
            // nilai_id
            $this->nilai_id->ViewValue = $this->nilai_id->CurrentValue;
            $this->nilai_id->ViewCustomAttributes = "";

            // kode_tapel
            $this->kode_tapel->ViewValue = $this->kode_tapel->CurrentValue;
            $this->kode_tapel->ViewCustomAttributes = "";

            // guru_id
            $this->guru_id->ViewValue = $this->guru_id->CurrentValue;
            $this->guru_id->ViewCustomAttributes = "";

            // kode_mapel
            $this->kode_mapel->ViewValue = $this->kode_mapel->CurrentValue;
            $this->kode_mapel->ViewCustomAttributes = "";

            // kelas
            $this->kelas->ViewValue = $this->kelas->CurrentValue;
            $this->kelas->ViewCustomAttributes = "";

            // nis
            $this->nis->ViewValue = $this->nis->CurrentValue;
            $this->nis->ViewCustomAttributes = "";

            // nama
            $this->nama->ViewValue = $this->nama->CurrentValue;
            $this->nama->ViewCustomAttributes = "";

            // jk
            $this->jk->ViewValue = $this->jk->CurrentValue;
            $this->jk->ViewCustomAttributes = "";

            // f1
            $this->f1->ViewValue = $this->f1->CurrentValue;
            $this->f1->ViewValue = FormatNumber($this->f1->ViewValue, 0, -2, -2, -2);
            $this->f1->ViewCustomAttributes = "";

            // f2
            $this->f2->ViewValue = $this->f2->CurrentValue;
            $this->f2->ViewValue = FormatNumber($this->f2->ViewValue, 0, -2, -2, -2);
            $this->f2->ViewCustomAttributes = "";

            // f3
            $this->f3->ViewValue = $this->f3->CurrentValue;
            $this->f3->ViewValue = FormatNumber($this->f3->ViewValue, 0, -2, -2, -2);
            $this->f3->ViewCustomAttributes = "";

            // f4
            $this->f4->ViewValue = $this->f4->CurrentValue;
            $this->f4->ViewValue = FormatNumber($this->f4->ViewValue, 0, -2, -2, -2);
            $this->f4->ViewCustomAttributes = "";

            // f5
            $this->f5->ViewValue = $this->f5->CurrentValue;
            $this->f5->ViewValue = FormatNumber($this->f5->ViewValue, 0, -2, -2, -2);
            $this->f5->ViewCustomAttributes = "";

            // f6
            $this->f6->ViewValue = $this->f6->CurrentValue;
            $this->f6->ViewValue = FormatNumber($this->f6->ViewValue, 0, -2, -2, -2);
            $this->f6->ViewCustomAttributes = "";

            // f7
            $this->f7->ViewValue = $this->f7->CurrentValue;
            $this->f7->ViewValue = FormatNumber($this->f7->ViewValue, 0, -2, -2, -2);
            $this->f7->ViewCustomAttributes = "";

            // f8
            $this->f8->ViewValue = $this->f8->CurrentValue;
            $this->f8->ViewValue = FormatNumber($this->f8->ViewValue, 0, -2, -2, -2);
            $this->f8->ViewCustomAttributes = "";

            // f9
            $this->f9->ViewValue = $this->f9->CurrentValue;
            $this->f9->ViewValue = FormatNumber($this->f9->ViewValue, 0, -2, -2, -2);
            $this->f9->ViewCustomAttributes = "";

            // f10
            $this->f10->ViewValue = $this->f10->CurrentValue;
            $this->f10->ViewValue = FormatNumber($this->f10->ViewValue, 0, -2, -2, -2);
            $this->f10->ViewCustomAttributes = "";

            // f11
            $this->f11->ViewValue = $this->f11->CurrentValue;
            $this->f11->ViewValue = FormatNumber($this->f11->ViewValue, 0, -2, -2, -2);
            $this->f11->ViewCustomAttributes = "";

            // f12
            $this->f12->ViewValue = $this->f12->CurrentValue;
            $this->f12->ViewValue = FormatNumber($this->f12->ViewValue, 0, -2, -2, -2);
            $this->f12->ViewCustomAttributes = "";

            // f13
            $this->f13->ViewValue = $this->f13->CurrentValue;
            $this->f13->ViewValue = FormatNumber($this->f13->ViewValue, 0, -2, -2, -2);
            $this->f13->ViewCustomAttributes = "";

            // f14
            $this->f14->ViewValue = $this->f14->CurrentValue;
            $this->f14->ViewValue = FormatNumber($this->f14->ViewValue, 0, -2, -2, -2);
            $this->f14->ViewCustomAttributes = "";

            // f15
            $this->f15->ViewValue = $this->f15->CurrentValue;
            $this->f15->ViewValue = FormatNumber($this->f15->ViewValue, 0, -2, -2, -2);
            $this->f15->ViewCustomAttributes = "";

            // naf
            $this->naf->ViewValue = $this->naf->CurrentValue;
            $this->naf->ViewValue = FormatNumber($this->naf->ViewValue, 0, -2, -2, -2);
            $this->naf->ViewCustomAttributes = "";

            // s1
            $this->s1->ViewValue = $this->s1->CurrentValue;
            $this->s1->ViewValue = FormatNumber($this->s1->ViewValue, 0, -2, -2, -2);
            $this->s1->ViewCustomAttributes = "";

            // s2
            $this->s2->ViewValue = $this->s2->CurrentValue;
            $this->s2->ViewValue = FormatNumber($this->s2->ViewValue, 0, -2, -2, -2);
            $this->s2->ViewCustomAttributes = "";

            // s3
            $this->s3->ViewValue = $this->s3->CurrentValue;
            $this->s3->ViewValue = FormatNumber($this->s3->ViewValue, 0, -2, -2, -2);
            $this->s3->ViewCustomAttributes = "";

            // s4
            $this->s4->ViewValue = $this->s4->CurrentValue;
            $this->s4->ViewValue = FormatNumber($this->s4->ViewValue, 0, -2, -2, -2);
            $this->s4->ViewCustomAttributes = "";

            // s5
            $this->s5->ViewValue = $this->s5->CurrentValue;
            $this->s5->ViewValue = FormatNumber($this->s5->ViewValue, 0, -2, -2, -2);
            $this->s5->ViewCustomAttributes = "";

            // s6
            $this->s6->ViewValue = $this->s6->CurrentValue;
            $this->s6->ViewValue = FormatNumber($this->s6->ViewValue, 0, -2, -2, -2);
            $this->s6->ViewCustomAttributes = "";

            // s7
            $this->s7->ViewValue = $this->s7->CurrentValue;
            $this->s7->ViewValue = FormatNumber($this->s7->ViewValue, 0, -2, -2, -2);
            $this->s7->ViewCustomAttributes = "";

            // s8
            $this->s8->ViewValue = $this->s8->CurrentValue;
            $this->s8->ViewValue = FormatNumber($this->s8->ViewValue, 0, -2, -2, -2);
            $this->s8->ViewCustomAttributes = "";

            // nas
            $this->nas->ViewValue = $this->nas->CurrentValue;
            $this->nas->ViewCustomAttributes = "";

            // sts
            $this->sts->ViewValue = $this->sts->CurrentValue;
            $this->sts->ViewCustomAttributes = "";

            // sas
            $this->sas->ViewValue = $this->sas->CurrentValue;
            $this->sas->ViewCustomAttributes = "";

            // nr1
            $this->nr1->ViewValue = $this->nr1->CurrentValue;
            $this->nr1->ViewCustomAttributes = "";

            // nr2
            $this->nr2->ViewValue = $this->nr2->CurrentValue;
            $this->nr2->ViewValue = FormatNumber($this->nr2->ViewValue, 0, -2, -2, -2);
            $this->nr2->ViewCustomAttributes = "";

            // nilai_id
            $this->nilai_id->LinkCustomAttributes = "";
            $this->nilai_id->HrefValue = "";
            $this->nilai_id->TooltipValue = "";

            // kode_tapel
            $this->kode_tapel->LinkCustomAttributes = "";
            $this->kode_tapel->HrefValue = "";
            $this->kode_tapel->TooltipValue = "";

            // guru_id
            $this->guru_id->LinkCustomAttributes = "";
            $this->guru_id->HrefValue = "";
            $this->guru_id->TooltipValue = "";

            // kode_mapel
            $this->kode_mapel->LinkCustomAttributes = "";
            $this->kode_mapel->HrefValue = "";
            $this->kode_mapel->TooltipValue = "";

            // kelas
            $this->kelas->LinkCustomAttributes = "";
            $this->kelas->HrefValue = "";
            $this->kelas->TooltipValue = "";

            // nis
            $this->nis->LinkCustomAttributes = "";
            $this->nis->HrefValue = "";
            $this->nis->TooltipValue = "";

            // nama
            $this->nama->LinkCustomAttributes = "";
            $this->nama->HrefValue = "";
            $this->nama->TooltipValue = "";

            // jk
            $this->jk->LinkCustomAttributes = "";
            $this->jk->HrefValue = "";
            $this->jk->TooltipValue = "";

            // f1
            $this->f1->LinkCustomAttributes = "";
            $this->f1->HrefValue = "";
            $this->f1->TooltipValue = "";

            // f2
            $this->f2->LinkCustomAttributes = "";
            $this->f2->HrefValue = "";
            $this->f2->TooltipValue = "";

            // f3
            $this->f3->LinkCustomAttributes = "";
            $this->f3->HrefValue = "";
            $this->f3->TooltipValue = "";

            // f4
            $this->f4->LinkCustomAttributes = "";
            $this->f4->HrefValue = "";
            $this->f4->TooltipValue = "";

            // f5
            $this->f5->LinkCustomAttributes = "";
            $this->f5->HrefValue = "";
            $this->f5->TooltipValue = "";

            // f6
            $this->f6->LinkCustomAttributes = "";
            $this->f6->HrefValue = "";
            $this->f6->TooltipValue = "";

            // f7
            $this->f7->LinkCustomAttributes = "";
            $this->f7->HrefValue = "";
            $this->f7->TooltipValue = "";

            // f8
            $this->f8->LinkCustomAttributes = "";
            $this->f8->HrefValue = "";
            $this->f8->TooltipValue = "";

            // f9
            $this->f9->LinkCustomAttributes = "";
            $this->f9->HrefValue = "";
            $this->f9->TooltipValue = "";

            // f10
            $this->f10->LinkCustomAttributes = "";
            $this->f10->HrefValue = "";
            $this->f10->TooltipValue = "";

            // f11
            $this->f11->LinkCustomAttributes = "";
            $this->f11->HrefValue = "";
            $this->f11->TooltipValue = "";

            // f12
            $this->f12->LinkCustomAttributes = "";
            $this->f12->HrefValue = "";
            $this->f12->TooltipValue = "";

            // f13
            $this->f13->LinkCustomAttributes = "";
            $this->f13->HrefValue = "";
            $this->f13->TooltipValue = "";

            // f14
            $this->f14->LinkCustomAttributes = "";
            $this->f14->HrefValue = "";
            $this->f14->TooltipValue = "";

            // f15
            $this->f15->LinkCustomAttributes = "";
            $this->f15->HrefValue = "";
            $this->f15->TooltipValue = "";

            // naf
            $this->naf->LinkCustomAttributes = "";
            $this->naf->HrefValue = "";
            $this->naf->TooltipValue = "";

            // s1
            $this->s1->LinkCustomAttributes = "";
            $this->s1->HrefValue = "";
            $this->s1->TooltipValue = "";

            // s2
            $this->s2->LinkCustomAttributes = "";
            $this->s2->HrefValue = "";
            $this->s2->TooltipValue = "";

            // s3
            $this->s3->LinkCustomAttributes = "";
            $this->s3->HrefValue = "";
            $this->s3->TooltipValue = "";

            // s4
            $this->s4->LinkCustomAttributes = "";
            $this->s4->HrefValue = "";
            $this->s4->TooltipValue = "";

            // s5
            $this->s5->LinkCustomAttributes = "";
            $this->s5->HrefValue = "";
            $this->s5->TooltipValue = "";

            // s6
            $this->s6->LinkCustomAttributes = "";
            $this->s6->HrefValue = "";
            $this->s6->TooltipValue = "";

            // s7
            $this->s7->LinkCustomAttributes = "";
            $this->s7->HrefValue = "";
            $this->s7->TooltipValue = "";

            // s8
            $this->s8->LinkCustomAttributes = "";
            $this->s8->HrefValue = "";
            $this->s8->TooltipValue = "";

            // nas
            $this->nas->LinkCustomAttributes = "";
            $this->nas->HrefValue = "";
            $this->nas->TooltipValue = "";

            // sts
            $this->sts->LinkCustomAttributes = "";
            $this->sts->HrefValue = "";
            $this->sts->TooltipValue = "";

            // sas
            $this->sas->LinkCustomAttributes = "";
            $this->sas->HrefValue = "";
            $this->sas->TooltipValue = "";

            // nr1
            $this->nr1->LinkCustomAttributes = "";
            $this->nr1->HrefValue = "";
            $this->nr1->TooltipValue = "";

            // nr2
            $this->nr2->LinkCustomAttributes = "";
            $this->nr2->HrefValue = "";
            $this->nr2->TooltipValue = "";
        }

        // Call Row Rendered event
        if ($this->RowType != ROWTYPE_AGGREGATEINIT) {
            $this->rowRendered();
        }
    }

    // Delete records based on current filter
    protected function deleteRows()
    {
        global $Language, $Security;
        if (!$Security->canDelete()) {
            $this->setFailureMessage($Language->phrase("NoDeletePermission")); // No delete permission
            return false;
        }
        $deleteRows = true;
        $sql = $this->getCurrentSql();
        $conn = $this->getConnection();
        $rows = $conn->fetchAll($sql);
        if (count($rows) == 0) {
            $this->setFailureMessage($Language->phrase("NoRecord")); // No record found
            return false;
        }
        $conn->beginTransaction();

        // Clone old rows
        $rsold = $rows;

        // Call row deleting event
        if ($deleteRows) {
            foreach ($rsold as $row) {
                $deleteRows = $this->rowDeleting($row);
                if (!$deleteRows) {
                    break;
                }
            }
        }
        if ($deleteRows) {
            $key = "";
            foreach ($rsold as $row) {
                $thisKey = "";
                if ($thisKey != "") {
                    $thisKey .= Config("COMPOSITE_KEY_SEPARATOR");
                }
                $thisKey .= $row['nilai_id'];
                if (Config("DELETE_UPLOADED_FILES")) { // Delete old files
                    $this->deleteUploadedFiles($row);
                }
                $deleteRows = $this->delete($row); // Delete
                if ($deleteRows === false) {
                    break;
                }
                if ($key != "") {
                    $key .= ", ";
                }
                $key .= $thisKey;
            }
        }
        if (!$deleteRows) {
            // Set up error message
            if ($this->getSuccessMessage() != "" || $this->getFailureMessage() != "") {
                // Use the message, do nothing
            } elseif ($this->CancelMessage != "") {
                $this->setFailureMessage($this->CancelMessage);
                $this->CancelMessage = "";
            } else {
                $this->setFailureMessage($Language->phrase("DeleteCancelled"));
            }
        }
        if ($deleteRows) {
            $conn->commit(); // Commit the changes
        } else {
            $conn->rollback(); // Rollback changes
        }

        // Call Row Deleted event
        if ($deleteRows) {
            foreach ($rsold as $row) {
                $this->rowDeleted($row);
            }
        }

        // Write JSON for API request
        if (IsApi() && $deleteRows) {
            $row = $this->getRecordsFromRecordset($rsold);
            WriteJson(["success" => true, $this->TableVar => $row]);
        }
        return $deleteRows;
    }

    // Show link optionally based on User ID
    protected function showOptionLink($id = "")
    {
        global $Security;
        if ($Security->isLoggedIn() && !$Security->isAdmin() && !$this->userIDAllow($id)) {
            return $Security->isValidUserID($this->kelas->CurrentValue);
        }
        return true;
    }

    // Set up Breadcrumb
    protected function setupBreadcrumb()
    {
        global $Breadcrumb, $Language;
        $Breadcrumb = new Breadcrumb("index");
        $url = CurrentUrl();
        $Breadcrumb->add("list", $this->TableVar, $this->addMasterUrl("NilaiList"), "", $this->TableVar, true);
        $pageId = "delete";
        $Breadcrumb->add("delete", $pageId, $url);
    }

    // Setup lookup options
    public function setupLookupOptions($fld)
    {
        if ($fld->Lookup !== null && $fld->Lookup->Options === null) {
            // Get default connection and filter
            $conn = $this->getConnection();
            $lookupFilter = "";

            // No need to check any more
            $fld->Lookup->Options = [];

            // Set up lookup SQL and connection
            switch ($fld->FieldVar) {
                default:
                    $lookupFilter = "";
                    break;
            }

            // Always call to Lookup->getSql so that user can setup Lookup->Options in Lookup_Selecting server event
            $sql = $fld->Lookup->getSql(false, "", $lookupFilter, $this);

            // Set up lookup cache
            if ($fld->UseLookupCache && $sql != "" && count($fld->Lookup->Options) == 0) {
                $totalCnt = $this->getRecordCount($sql, $conn);
                if ($totalCnt > $fld->LookupCacheCount) { // Total count > cache count, do not cache
                    return;
                }
                $rows = $conn->executeQuery($sql)->fetchAll(\PDO::FETCH_BOTH);
                $ar = [];
                foreach ($rows as $row) {
                    $row = $fld->Lookup->renderViewRow($row);
                    $ar[strval($row[0])] = $row;
                }
                $fld->Lookup->Options = $ar;
            }
        }
    }

    // Page Load event
    public function pageLoad()
    {
        //Log("Page Load");
    }

    // Page Unload event
    public function pageUnload()
    {
        //Log("Page Unload");
    }

    // Page Redirecting event
    public function pageRedirecting(&$url)
    {
        // Example:
        //$url = "your URL";
    }

    // Message Showing event
    // $type = ''|'success'|'failure'|'warning'
    public function messageShowing(&$msg, $type)
    {
        if ($type == 'success') {
            //$msg = "your success message";
        } elseif ($type == 'failure') {
            //$msg = "your failure message";
        } elseif ($type == 'warning') {
            //$msg = "your warning message";
        } else {
            //$msg = "your message";
        }
    }

    // Page Render event
    public function pageRender()
    {
        //Log("Page Render");
    }

    // Page Data Rendering event
    public function pageDataRendering(&$header)
    {
        // Example:
        //$header = "your header";
    }

    // Page Data Rendered event
    public function pageDataRendered(&$footer)
    {
        // Example:
        //$footer = "your footer";
    }
}
