<?php

namespace PHPMaker2021\rkm21;

use Doctrine\DBAL\ParameterType;

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

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

    // Project ID
    public $ProjectID = PROJECT_ID;

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

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

    // 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();
            }

            // Handle modal response
            if ($this->IsModal) { // Show as modal
                $row = ["url" => GetUrl($url), "modal" => "1"];
                $pageName = GetPageName($url);
                if ($pageName != $this->getListUrl()) { // Not List page
                    $row["caption"] = $this->getModalCaption($pageName);
                    if ($pageName == "NilaiView") {
                        $row["view"] = "1";
                    }
                } else { // List page should not be shown as modal => error
                    $row["error"] = $this->getFailureMessage();
                    $this->clearFailureMessage();
                }
                WriteJson($row);
            } else {
                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;
        }
    }

    // Lookup data
    public function lookup()
    {
        global $Language, $Security;

        // Get lookup object
        $fieldName = Post("field");
        $lookup = $this->Fields[$fieldName]->Lookup;

        // Get lookup parameters
        $lookupType = Post("ajax", "unknown");
        $pageSize = -1;
        $offset = -1;
        $searchValue = "";
        if (SameText($lookupType, "modal")) {
            $searchValue = Post("sv", "");
            $pageSize = Post("recperpage", 10);
            $offset = Post("start", 0);
        } elseif (SameText($lookupType, "autosuggest")) {
            $searchValue = Param("q", "");
            $pageSize = Param("n", -1);
            $pageSize = is_numeric($pageSize) ? (int)$pageSize : -1;
            if ($pageSize <= 0) {
                $pageSize = Config("AUTO_SUGGEST_MAX_ENTRIES");
            }
            $start = Param("start", -1);
            $start = is_numeric($start) ? (int)$start : -1;
            $page = Param("page", -1);
            $page = is_numeric($page) ? (int)$page : -1;
            $offset = $start >= 0 ? $start : ($page > 0 && $pageSize > 0 ? ($page - 1) * $pageSize : 0);
        }
        $userSelect = Decrypt(Post("s", ""));
        $userFilter = Decrypt(Post("f", ""));
        $userOrderBy = Decrypt(Post("o", ""));
        $keys = Post("keys");
        $lookup->LookupType = $lookupType; // Lookup type
        if ($keys !== null) { // Selected records from modal
            if (is_array($keys)) {
                $keys = implode(Config("MULTIPLE_OPTION_SEPARATOR"), $keys);
            }
            $lookup->FilterFields = []; // Skip parent fields if any
            $lookup->FilterValues[] = $keys; // Lookup values
            $pageSize = -1; // Show all records
        } else { // Lookup values
            $lookup->FilterValues[] = Post("v0", Post("lookupValue", ""));
        }
        $cnt = is_array($lookup->FilterFields) ? count($lookup->FilterFields) : 0;
        for ($i = 1; $i <= $cnt; $i++) {
            $lookup->FilterValues[] = Post("v" . $i, "");
        }
        $lookup->SearchValue = $searchValue;
        $lookup->PageSize = $pageSize;
        $lookup->Offset = $offset;
        if ($userSelect != "") {
            $lookup->UserSelect = $userSelect;
        }
        if ($userFilter != "") {
            $lookup->UserFilter = $userFilter;
        }
        if ($userOrderBy != "") {
            $lookup->UserOrderBy = $userOrderBy;
        }
        $lookup->toJson($this); // Use settings from current page
    }
    public $FormClassName = "ew-horizontal ew-form ew-edit-form";
    public $IsModal = false;
    public $IsMobileOrModal = false;
    public $DbMasterFilter;
    public $DbDetailFilter;
    public $HashValue; // Hash Value
    public $DisplayRecords = 1;
    public $StartRecord;
    public $StopRecord;
    public $TotalRecords = 0;
    public $RecordRange = 10;
    public $RecordCount;

    /**
     * Page run
     *
     * @return void
     */
    public function run()
    {
        global $ExportType, $CustomExportType, $ExportFileName, $UserProfile, $Language, $Security, $CurrentForm,
            $SkipHeaderFooter;

        // Is modal
        $this->IsModal = Param("modal") == "1";

        // Create form object
        $CurrentForm = new HttpForm();
        $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

        // Check modal
        if ($this->IsModal) {
            $SkipHeaderFooter = true;
        }
        $this->IsMobileOrModal = IsMobile() || $this->IsModal;
        $this->FormClassName = "ew-form ew-edit-form ew-horizontal";
        $loaded = false;
        $postBack = false;

        // Set up current action and primary key
        if (IsApi()) {
            // Load key values
            $loaded = true;
            if (($keyValue = Get("nilai_id") ?? Key(0) ?? Route(2)) !== null) {
                $this->nilai_id->setQueryStringValue($keyValue);
                $this->nilai_id->setOldValue($this->nilai_id->QueryStringValue);
            } elseif (Post("nilai_id") !== null) {
                $this->nilai_id->setFormValue(Post("nilai_id"));
                $this->nilai_id->setOldValue($this->nilai_id->FormValue);
            } else {
                $loaded = false; // Unable to load key
            }

            // Load record
            if ($loaded) {
                $loaded = $this->loadRow();
            }
            if (!$loaded) {
                $this->setFailureMessage($Language->phrase("NoRecord")); // Set no record message
                $this->terminate();
                return;
            }
            $this->CurrentAction = "update"; // Update record directly
            $this->OldKey = $this->getKey(true); // Get from CurrentValue
            $postBack = true;
        } else {
            if (Post("action") !== null) {
                $this->CurrentAction = Post("action"); // Get action code
                if (!$this->isShow()) { // Not reload record, handle as postback
                    $postBack = true;
                }

                // Get key from Form
                $this->setKey(Post($this->OldKeyName), $this->isShow());
            } else {
                $this->CurrentAction = "show"; // Default action is display

                // Load key from QueryString
                $loadByQuery = false;
                if (($keyValue = Get("nilai_id") ?? Route("nilai_id")) !== null) {
                    $this->nilai_id->setQueryStringValue($keyValue);
                    $loadByQuery = true;
                } else {
                    $this->nilai_id->CurrentValue = null;
                }
            }

            // Load recordset
            if ($this->isShow()) {
                // Load current record
                $loaded = $this->loadRow();
                $this->OldKey = $loaded ? $this->getKey(true) : ""; // Get from CurrentValue
            }
        }

        // Process form if post back
        if ($postBack) {
            $this->loadFormValues(); // Get form values
        }

        // Validate form if post back
        if ($postBack) {
            if (!$this->validateForm()) {
                $this->EventCancelled = true; // Event cancelled
                $this->restoreFormValues();
                if (IsApi()) {
                    $this->terminate();
                    return;
                } else {
                    $this->CurrentAction = ""; // Form error, reset action
                }
            }
        }

        // Perform current action
        switch ($this->CurrentAction) {
            case "show": // Get a record to display
                if (!$loaded) { // Load record based on key
                    if ($this->getFailureMessage() == "") {
                        $this->setFailureMessage($Language->phrase("NoRecord")); // No record found
                    }
                    $this->terminate("NilaiList"); // No matching record, return to list
                    return;
                }
                break;
            case "update": // Update
                $returnUrl = $this->getReturnUrl();
                if (GetPageName($returnUrl) == "NilaiList") {
                    $returnUrl = $this->addMasterUrl($returnUrl); // List page, return to List page with correct master key if necessary
                }
                $this->SendEmail = true; // Send email on update success
                if ($this->editRow()) { // Update record based on key
                    if ($this->getSuccessMessage() == "") {
                        $this->setSuccessMessage($Language->phrase("UpdateSuccess")); // Update success
                    }
                    if (IsApi()) {
                        $this->terminate(true);
                        return;
                    } else {
                        $this->terminate($returnUrl); // Return to caller
                        return;
                    }
                } elseif (IsApi()) { // API request, return
                    $this->terminate();
                    return;
                } elseif ($this->getFailureMessage() == $Language->phrase("NoRecord")) {
                    $this->terminate($returnUrl); // Return to caller
                    return;
                } else {
                    $this->EventCancelled = true; // Event cancelled
                    $this->restoreFormValues(); // Restore form values if update failed
                }
        }

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

        // Render the record
        $this->RowType = ROWTYPE_EDIT; // Render as Edit
        $this->resetAttributes();
        $this->renderRow();

        // 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();
            }
        }
    }

    // Get upload files
    protected function getUploadFiles()
    {
        global $CurrentForm, $Language;
    }

    // Load form values
    protected function loadFormValues()
    {
        // Load from form
        global $CurrentForm;

        // Check field name 'nilai_id' first before field var 'x_nilai_id'
        $val = $CurrentForm->hasValue("nilai_id") ? $CurrentForm->getValue("nilai_id") : $CurrentForm->getValue("x_nilai_id");
        if (!$this->nilai_id->IsDetailKey) {
            $this->nilai_id->setFormValue($val);
        }

        // Check field name 'kode_tapel' first before field var 'x_kode_tapel'
        $val = $CurrentForm->hasValue("kode_tapel") ? $CurrentForm->getValue("kode_tapel") : $CurrentForm->getValue("x_kode_tapel");
        if (!$this->kode_tapel->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->kode_tapel->Visible = false; // Disable update for API request
            } else {
                $this->kode_tapel->setFormValue($val);
            }
        }

        // Check field name 'guru_id' first before field var 'x_guru_id'
        $val = $CurrentForm->hasValue("guru_id") ? $CurrentForm->getValue("guru_id") : $CurrentForm->getValue("x_guru_id");
        if (!$this->guru_id->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->guru_id->Visible = false; // Disable update for API request
            } else {
                $this->guru_id->setFormValue($val);
            }
        }

        // Check field name 'kode_mapel' first before field var 'x_kode_mapel'
        $val = $CurrentForm->hasValue("kode_mapel") ? $CurrentForm->getValue("kode_mapel") : $CurrentForm->getValue("x_kode_mapel");
        if (!$this->kode_mapel->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->kode_mapel->Visible = false; // Disable update for API request
            } else {
                $this->kode_mapel->setFormValue($val);
            }
        }

        // Check field name 'kelas' first before field var 'x_kelas'
        $val = $CurrentForm->hasValue("kelas") ? $CurrentForm->getValue("kelas") : $CurrentForm->getValue("x_kelas");
        if (!$this->kelas->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->kelas->Visible = false; // Disable update for API request
            } else {
                $this->kelas->setFormValue($val);
            }
        }

        // Check field name 'nis' first before field var 'x_nis'
        $val = $CurrentForm->hasValue("nis") ? $CurrentForm->getValue("nis") : $CurrentForm->getValue("x_nis");
        if (!$this->nis->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->nis->Visible = false; // Disable update for API request
            } else {
                $this->nis->setFormValue($val);
            }
        }

        // Check field name 'nama' first before field var 'x_nama'
        $val = $CurrentForm->hasValue("nama") ? $CurrentForm->getValue("nama") : $CurrentForm->getValue("x_nama");
        if (!$this->nama->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->nama->Visible = false; // Disable update for API request
            } else {
                $this->nama->setFormValue($val);
            }
        }

        // Check field name 'jk' first before field var 'x_jk'
        $val = $CurrentForm->hasValue("jk") ? $CurrentForm->getValue("jk") : $CurrentForm->getValue("x_jk");
        if (!$this->jk->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->jk->Visible = false; // Disable update for API request
            } else {
                $this->jk->setFormValue($val);
            }
        }

        // Check field name 'f1' first before field var 'x_f1'
        $val = $CurrentForm->hasValue("f1") ? $CurrentForm->getValue("f1") : $CurrentForm->getValue("x_f1");
        if (!$this->f1->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->f1->Visible = false; // Disable update for API request
            } else {
                $this->f1->setFormValue($val);
            }
        }

        // Check field name 'f2' first before field var 'x_f2'
        $val = $CurrentForm->hasValue("f2") ? $CurrentForm->getValue("f2") : $CurrentForm->getValue("x_f2");
        if (!$this->f2->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->f2->Visible = false; // Disable update for API request
            } else {
                $this->f2->setFormValue($val);
            }
        }

        // Check field name 'f3' first before field var 'x_f3'
        $val = $CurrentForm->hasValue("f3") ? $CurrentForm->getValue("f3") : $CurrentForm->getValue("x_f3");
        if (!$this->f3->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->f3->Visible = false; // Disable update for API request
            } else {
                $this->f3->setFormValue($val);
            }
        }

        // Check field name 'f4' first before field var 'x_f4'
        $val = $CurrentForm->hasValue("f4") ? $CurrentForm->getValue("f4") : $CurrentForm->getValue("x_f4");
        if (!$this->f4->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->f4->Visible = false; // Disable update for API request
            } else {
                $this->f4->setFormValue($val);
            }
        }

        // Check field name 'f5' first before field var 'x_f5'
        $val = $CurrentForm->hasValue("f5") ? $CurrentForm->getValue("f5") : $CurrentForm->getValue("x_f5");
        if (!$this->f5->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->f5->Visible = false; // Disable update for API request
            } else {
                $this->f5->setFormValue($val);
            }
        }

        // Check field name 'f6' first before field var 'x_f6'
        $val = $CurrentForm->hasValue("f6") ? $CurrentForm->getValue("f6") : $CurrentForm->getValue("x_f6");
        if (!$this->f6->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->f6->Visible = false; // Disable update for API request
            } else {
                $this->f6->setFormValue($val);
            }
        }

        // Check field name 'f7' first before field var 'x_f7'
        $val = $CurrentForm->hasValue("f7") ? $CurrentForm->getValue("f7") : $CurrentForm->getValue("x_f7");
        if (!$this->f7->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->f7->Visible = false; // Disable update for API request
            } else {
                $this->f7->setFormValue($val);
            }
        }

        // Check field name 'f8' first before field var 'x_f8'
        $val = $CurrentForm->hasValue("f8") ? $CurrentForm->getValue("f8") : $CurrentForm->getValue("x_f8");
        if (!$this->f8->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->f8->Visible = false; // Disable update for API request
            } else {
                $this->f8->setFormValue($val);
            }
        }

        // Check field name 'f9' first before field var 'x_f9'
        $val = $CurrentForm->hasValue("f9") ? $CurrentForm->getValue("f9") : $CurrentForm->getValue("x_f9");
        if (!$this->f9->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->f9->Visible = false; // Disable update for API request
            } else {
                $this->f9->setFormValue($val);
            }
        }

        // Check field name 'f10' first before field var 'x_f10'
        $val = $CurrentForm->hasValue("f10") ? $CurrentForm->getValue("f10") : $CurrentForm->getValue("x_f10");
        if (!$this->f10->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->f10->Visible = false; // Disable update for API request
            } else {
                $this->f10->setFormValue($val);
            }
        }

        // Check field name 'f11' first before field var 'x_f11'
        $val = $CurrentForm->hasValue("f11") ? $CurrentForm->getValue("f11") : $CurrentForm->getValue("x_f11");
        if (!$this->f11->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->f11->Visible = false; // Disable update for API request
            } else {
                $this->f11->setFormValue($val);
            }
        }

        // Check field name 'f12' first before field var 'x_f12'
        $val = $CurrentForm->hasValue("f12") ? $CurrentForm->getValue("f12") : $CurrentForm->getValue("x_f12");
        if (!$this->f12->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->f12->Visible = false; // Disable update for API request
            } else {
                $this->f12->setFormValue($val);
            }
        }

        // Check field name 'f13' first before field var 'x_f13'
        $val = $CurrentForm->hasValue("f13") ? $CurrentForm->getValue("f13") : $CurrentForm->getValue("x_f13");
        if (!$this->f13->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->f13->Visible = false; // Disable update for API request
            } else {
                $this->f13->setFormValue($val);
            }
        }

        // Check field name 'f14' first before field var 'x_f14'
        $val = $CurrentForm->hasValue("f14") ? $CurrentForm->getValue("f14") : $CurrentForm->getValue("x_f14");
        if (!$this->f14->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->f14->Visible = false; // Disable update for API request
            } else {
                $this->f14->setFormValue($val);
            }
        }

        // Check field name 'f15' first before field var 'x_f15'
        $val = $CurrentForm->hasValue("f15") ? $CurrentForm->getValue("f15") : $CurrentForm->getValue("x_f15");
        if (!$this->f15->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->f15->Visible = false; // Disable update for API request
            } else {
                $this->f15->setFormValue($val);
            }
        }

        // Check field name 'naf' first before field var 'x_naf'
        $val = $CurrentForm->hasValue("naf") ? $CurrentForm->getValue("naf") : $CurrentForm->getValue("x_naf");
        if (!$this->naf->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->naf->Visible = false; // Disable update for API request
            } else {
                $this->naf->setFormValue($val);
            }
        }

        // Check field name 's1' first before field var 'x_s1'
        $val = $CurrentForm->hasValue("s1") ? $CurrentForm->getValue("s1") : $CurrentForm->getValue("x_s1");
        if (!$this->s1->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->s1->Visible = false; // Disable update for API request
            } else {
                $this->s1->setFormValue($val);
            }
        }

        // Check field name 's2' first before field var 'x_s2'
        $val = $CurrentForm->hasValue("s2") ? $CurrentForm->getValue("s2") : $CurrentForm->getValue("x_s2");
        if (!$this->s2->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->s2->Visible = false; // Disable update for API request
            } else {
                $this->s2->setFormValue($val);
            }
        }

        // Check field name 's3' first before field var 'x_s3'
        $val = $CurrentForm->hasValue("s3") ? $CurrentForm->getValue("s3") : $CurrentForm->getValue("x_s3");
        if (!$this->s3->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->s3->Visible = false; // Disable update for API request
            } else {
                $this->s3->setFormValue($val);
            }
        }

        // Check field name 's4' first before field var 'x_s4'
        $val = $CurrentForm->hasValue("s4") ? $CurrentForm->getValue("s4") : $CurrentForm->getValue("x_s4");
        if (!$this->s4->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->s4->Visible = false; // Disable update for API request
            } else {
                $this->s4->setFormValue($val);
            }
        }

        // Check field name 's5' first before field var 'x_s5'
        $val = $CurrentForm->hasValue("s5") ? $CurrentForm->getValue("s5") : $CurrentForm->getValue("x_s5");
        if (!$this->s5->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->s5->Visible = false; // Disable update for API request
            } else {
                $this->s5->setFormValue($val);
            }
        }

        // Check field name 's6' first before field var 'x_s6'
        $val = $CurrentForm->hasValue("s6") ? $CurrentForm->getValue("s6") : $CurrentForm->getValue("x_s6");
        if (!$this->s6->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->s6->Visible = false; // Disable update for API request
            } else {
                $this->s6->setFormValue($val);
            }
        }

        // Check field name 's7' first before field var 'x_s7'
        $val = $CurrentForm->hasValue("s7") ? $CurrentForm->getValue("s7") : $CurrentForm->getValue("x_s7");
        if (!$this->s7->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->s7->Visible = false; // Disable update for API request
            } else {
                $this->s7->setFormValue($val);
            }
        }

        // Check field name 's8' first before field var 'x_s8'
        $val = $CurrentForm->hasValue("s8") ? $CurrentForm->getValue("s8") : $CurrentForm->getValue("x_s8");
        if (!$this->s8->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->s8->Visible = false; // Disable update for API request
            } else {
                $this->s8->setFormValue($val);
            }
        }

        // Check field name 'nas' first before field var 'x_nas'
        $val = $CurrentForm->hasValue("nas") ? $CurrentForm->getValue("nas") : $CurrentForm->getValue("x_nas");
        if (!$this->nas->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->nas->Visible = false; // Disable update for API request
            } else {
                $this->nas->setFormValue($val);
            }
        }

        // Check field name 'sts' first before field var 'x_sts'
        $val = $CurrentForm->hasValue("sts") ? $CurrentForm->getValue("sts") : $CurrentForm->getValue("x_sts");
        if (!$this->sts->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->sts->Visible = false; // Disable update for API request
            } else {
                $this->sts->setFormValue($val);
            }
        }

        // Check field name 'sas' first before field var 'x_sas'
        $val = $CurrentForm->hasValue("sas") ? $CurrentForm->getValue("sas") : $CurrentForm->getValue("x_sas");
        if (!$this->sas->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->sas->Visible = false; // Disable update for API request
            } else {
                $this->sas->setFormValue($val);
            }
        }

        // Check field name 'nr1' first before field var 'x_nr1'
        $val = $CurrentForm->hasValue("nr1") ? $CurrentForm->getValue("nr1") : $CurrentForm->getValue("x_nr1");
        if (!$this->nr1->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->nr1->Visible = false; // Disable update for API request
            } else {
                $this->nr1->setFormValue($val);
            }
        }

        // Check field name 'nr2' first before field var 'x_nr2'
        $val = $CurrentForm->hasValue("nr2") ? $CurrentForm->getValue("nr2") : $CurrentForm->getValue("x_nr2");
        if (!$this->nr2->IsDetailKey) {
            if (IsApi() && $val === null) {
                $this->nr2->Visible = false; // Disable update for API request
            } else {
                $this->nr2->setFormValue($val);
            }
        }
    }

    // Restore form values
    public function restoreFormValues()
    {
        global $CurrentForm;
        $this->nilai_id->CurrentValue = $this->nilai_id->FormValue;
        $this->kode_tapel->CurrentValue = $this->kode_tapel->FormValue;
        $this->guru_id->CurrentValue = $this->guru_id->FormValue;
        $this->kode_mapel->CurrentValue = $this->kode_mapel->FormValue;
        $this->kelas->CurrentValue = $this->kelas->FormValue;
        $this->nis->CurrentValue = $this->nis->FormValue;
        $this->nama->CurrentValue = $this->nama->FormValue;
        $this->jk->CurrentValue = $this->jk->FormValue;
        $this->f1->CurrentValue = $this->f1->FormValue;
        $this->f2->CurrentValue = $this->f2->FormValue;
        $this->f3->CurrentValue = $this->f3->FormValue;
        $this->f4->CurrentValue = $this->f4->FormValue;
        $this->f5->CurrentValue = $this->f5->FormValue;
        $this->f6->CurrentValue = $this->f6->FormValue;
        $this->f7->CurrentValue = $this->f7->FormValue;
        $this->f8->CurrentValue = $this->f8->FormValue;
        $this->f9->CurrentValue = $this->f9->FormValue;
        $this->f10->CurrentValue = $this->f10->FormValue;
        $this->f11->CurrentValue = $this->f11->FormValue;
        $this->f12->CurrentValue = $this->f12->FormValue;
        $this->f13->CurrentValue = $this->f13->FormValue;
        $this->f14->CurrentValue = $this->f14->FormValue;
        $this->f15->CurrentValue = $this->f15->FormValue;
        $this->naf->CurrentValue = $this->naf->FormValue;
        $this->s1->CurrentValue = $this->s1->FormValue;
        $this->s2->CurrentValue = $this->s2->FormValue;
        $this->s3->CurrentValue = $this->s3->FormValue;
        $this->s4->CurrentValue = $this->s4->FormValue;
        $this->s5->CurrentValue = $this->s5->FormValue;
        $this->s6->CurrentValue = $this->s6->FormValue;
        $this->s7->CurrentValue = $this->s7->FormValue;
        $this->s8->CurrentValue = $this->s8->FormValue;
        $this->nas->CurrentValue = $this->nas->FormValue;
        $this->sts->CurrentValue = $this->sts->FormValue;
        $this->sas->CurrentValue = $this->sas->FormValue;
        $this->nr1->CurrentValue = $this->nr1->FormValue;
        $this->nr2->CurrentValue = $this->nr2->FormValue;
    }

    /**
     * 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
        }

        // Check if valid User ID
        if ($res) {
            $res = $this->showOptionLink("edit");
            if (!$res) {
                $userIdMsg = DeniedMessage();
                $this->setFailureMessage($userIdMsg);
            }
        }
        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;
    }

    // Load old record
    protected function loadOldRecord()
    {
        // Load old record
        $this->OldRecordset = null;
        $validKey = $this->OldKey != "";
        if ($validKey) {
            $this->CurrentFilter = $this->getRecordFilter();
            $sql = $this->getCurrentSql();
            $conn = $this->getConnection();
            $this->OldRecordset = LoadRecordset($sql, $conn);
        }
        $this->loadRowValues($this->OldRecordset); // Load row values
        return $validKey;
    }

    // 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

        // kode_tapel

        // guru_id

        // kode_mapel

        // kelas

        // nis

        // nama

        // jk

        // f1

        // f2

        // f3

        // f4

        // f5

        // f6

        // f7

        // f8

        // f9

        // f10

        // f11

        // f12

        // f13

        // f14

        // f15

        // naf

        // s1

        // s2

        // s3

        // s4

        // s5

        // s6

        // s7

        // s8

        // nas

        // sts

        // sas

        // nr1

        // nr2
        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 = "";
        } elseif ($this->RowType == ROWTYPE_EDIT) {
            // nilai_id
            $this->nilai_id->EditAttrs["class"] = "form-control";
            $this->nilai_id->EditCustomAttributes = "";
            $this->nilai_id->EditValue = $this->nilai_id->CurrentValue;
            $this->nilai_id->ViewCustomAttributes = "";

            // kode_tapel
            $this->kode_tapel->EditAttrs["class"] = "form-control";
            $this->kode_tapel->EditCustomAttributes = "";
            if (!$this->kode_tapel->Raw) {
                $this->kode_tapel->CurrentValue = HtmlDecode($this->kode_tapel->CurrentValue);
            }
            $this->kode_tapel->EditValue = HtmlEncode($this->kode_tapel->CurrentValue);

            // guru_id
            $this->guru_id->EditAttrs["class"] = "form-control";
            $this->guru_id->EditCustomAttributes = "";
            if (!$this->guru_id->Raw) {
                $this->guru_id->CurrentValue = HtmlDecode($this->guru_id->CurrentValue);
            }
            $this->guru_id->EditValue = HtmlEncode($this->guru_id->CurrentValue);

            // kode_mapel
            $this->kode_mapel->EditAttrs["class"] = "form-control";
            $this->kode_mapel->EditCustomAttributes = "";
            if (!$this->kode_mapel->Raw) {
                $this->kode_mapel->CurrentValue = HtmlDecode($this->kode_mapel->CurrentValue);
            }
            $this->kode_mapel->EditValue = HtmlEncode($this->kode_mapel->CurrentValue);

            // kelas
            $this->kelas->EditAttrs["class"] = "form-control";
            $this->kelas->EditCustomAttributes = "";
            if (!$Security->isAdmin() && $Security->isLoggedIn() && !$this->userIDAllow("edit")) { // Non system admin
                $this->kelas->CurrentValue = CurrentUserID();
                $this->kelas->EditValue = $this->kelas->CurrentValue;
                $this->kelas->ViewCustomAttributes = "";
            } else {
                if (!$this->kelas->Raw) {
                    $this->kelas->CurrentValue = HtmlDecode($this->kelas->CurrentValue);
                }
                $this->kelas->EditValue = HtmlEncode($this->kelas->CurrentValue);
            }

            // nis
            $this->nis->EditAttrs["class"] = "form-control";
            $this->nis->EditCustomAttributes = "";
            if (!$this->nis->Raw) {
                $this->nis->CurrentValue = HtmlDecode($this->nis->CurrentValue);
            }
            $this->nis->EditValue = HtmlEncode($this->nis->CurrentValue);

            // nama
            $this->nama->EditAttrs["class"] = "form-control";
            $this->nama->EditCustomAttributes = "";
            if (!$this->nama->Raw) {
                $this->nama->CurrentValue = HtmlDecode($this->nama->CurrentValue);
            }
            $this->nama->EditValue = HtmlEncode($this->nama->CurrentValue);

            // jk
            $this->jk->EditAttrs["class"] = "form-control";
            $this->jk->EditCustomAttributes = "";
            if (!$this->jk->Raw) {
                $this->jk->CurrentValue = HtmlDecode($this->jk->CurrentValue);
            }
            $this->jk->EditValue = HtmlEncode($this->jk->CurrentValue);

            // f1
            $this->f1->EditAttrs["class"] = "form-control";
            $this->f1->EditCustomAttributes = "";
            $this->f1->EditValue = HtmlEncode($this->f1->CurrentValue);

            // f2
            $this->f2->EditAttrs["class"] = "form-control";
            $this->f2->EditCustomAttributes = "";
            $this->f2->EditValue = HtmlEncode($this->f2->CurrentValue);

            // f3
            $this->f3->EditAttrs["class"] = "form-control";
            $this->f3->EditCustomAttributes = "";
            $this->f3->EditValue = HtmlEncode($this->f3->CurrentValue);

            // f4
            $this->f4->EditAttrs["class"] = "form-control";
            $this->f4->EditCustomAttributes = "";
            $this->f4->EditValue = HtmlEncode($this->f4->CurrentValue);

            // f5
            $this->f5->EditAttrs["class"] = "form-control";
            $this->f5->EditCustomAttributes = "";
            $this->f5->EditValue = HtmlEncode($this->f5->CurrentValue);

            // f6
            $this->f6->EditAttrs["class"] = "form-control";
            $this->f6->EditCustomAttributes = "";
            $this->f6->EditValue = HtmlEncode($this->f6->CurrentValue);

            // f7
            $this->f7->EditAttrs["class"] = "form-control";
            $this->f7->EditCustomAttributes = "";
            $this->f7->EditValue = HtmlEncode($this->f7->CurrentValue);

            // f8
            $this->f8->EditAttrs["class"] = "form-control";
            $this->f8->EditCustomAttributes = "";
            $this->f8->EditValue = HtmlEncode($this->f8->CurrentValue);

            // f9
            $this->f9->EditAttrs["class"] = "form-control";
            $this->f9->EditCustomAttributes = "";
            $this->f9->EditValue = HtmlEncode($this->f9->CurrentValue);

            // f10
            $this->f10->EditAttrs["class"] = "form-control";
            $this->f10->EditCustomAttributes = "";
            $this->f10->EditValue = HtmlEncode($this->f10->CurrentValue);

            // f11
            $this->f11->EditAttrs["class"] = "form-control";
            $this->f11->EditCustomAttributes = "";
            $this->f11->EditValue = HtmlEncode($this->f11->CurrentValue);

            // f12
            $this->f12->EditAttrs["class"] = "form-control";
            $this->f12->EditCustomAttributes = "";
            $this->f12->EditValue = HtmlEncode($this->f12->CurrentValue);

            // f13
            $this->f13->EditAttrs["class"] = "form-control";
            $this->f13->EditCustomAttributes = "";
            $this->f13->EditValue = HtmlEncode($this->f13->CurrentValue);

            // f14
            $this->f14->EditAttrs["class"] = "form-control";
            $this->f14->EditCustomAttributes = "";
            $this->f14->EditValue = HtmlEncode($this->f14->CurrentValue);

            // f15
            $this->f15->EditAttrs["class"] = "form-control";
            $this->f15->EditCustomAttributes = "";
            $this->f15->EditValue = HtmlEncode($this->f15->CurrentValue);

            // naf
            $this->naf->EditAttrs["class"] = "form-control";
            $this->naf->EditCustomAttributes = "";
            $this->naf->EditValue = HtmlEncode($this->naf->CurrentValue);

            // s1
            $this->s1->EditAttrs["class"] = "form-control";
            $this->s1->EditCustomAttributes = "";
            $this->s1->EditValue = HtmlEncode($this->s1->CurrentValue);

            // s2
            $this->s2->EditAttrs["class"] = "form-control";
            $this->s2->EditCustomAttributes = "";
            $this->s2->EditValue = HtmlEncode($this->s2->CurrentValue);

            // s3
            $this->s3->EditAttrs["class"] = "form-control";
            $this->s3->EditCustomAttributes = "";
            $this->s3->EditValue = HtmlEncode($this->s3->CurrentValue);

            // s4
            $this->s4->EditAttrs["class"] = "form-control";
            $this->s4->EditCustomAttributes = "";
            $this->s4->EditValue = HtmlEncode($this->s4->CurrentValue);

            // s5
            $this->s5->EditAttrs["class"] = "form-control";
            $this->s5->EditCustomAttributes = "";
            $this->s5->EditValue = HtmlEncode($this->s5->CurrentValue);

            // s6
            $this->s6->EditAttrs["class"] = "form-control";
            $this->s6->EditCustomAttributes = "";
            $this->s6->EditValue = HtmlEncode($this->s6->CurrentValue);

            // s7
            $this->s7->EditAttrs["class"] = "form-control";
            $this->s7->EditCustomAttributes = "";
            $this->s7->EditValue = HtmlEncode($this->s7->CurrentValue);

            // s8
            $this->s8->EditAttrs["class"] = "form-control";
            $this->s8->EditCustomAttributes = "";
            $this->s8->EditValue = HtmlEncode($this->s8->CurrentValue);

            // nas
            $this->nas->EditAttrs["class"] = "form-control";
            $this->nas->EditCustomAttributes = "";
            if (!$this->nas->Raw) {
                $this->nas->CurrentValue = HtmlDecode($this->nas->CurrentValue);
            }
            $this->nas->EditValue = HtmlEncode($this->nas->CurrentValue);

            // sts
            $this->sts->EditAttrs["class"] = "form-control";
            $this->sts->EditCustomAttributes = "";
            if (!$this->sts->Raw) {
                $this->sts->CurrentValue = HtmlDecode($this->sts->CurrentValue);
            }
            $this->sts->EditValue = HtmlEncode($this->sts->CurrentValue);

            // sas
            $this->sas->EditAttrs["class"] = "form-control";
            $this->sas->EditCustomAttributes = "";
            if (!$this->sas->Raw) {
                $this->sas->CurrentValue = HtmlDecode($this->sas->CurrentValue);
            }
            $this->sas->EditValue = HtmlEncode($this->sas->CurrentValue);

            // nr1
            $this->nr1->EditAttrs["class"] = "form-control";
            $this->nr1->EditCustomAttributes = "";
            if (!$this->nr1->Raw) {
                $this->nr1->CurrentValue = HtmlDecode($this->nr1->CurrentValue);
            }
            $this->nr1->EditValue = HtmlEncode($this->nr1->CurrentValue);

            // nr2
            $this->nr2->EditAttrs["class"] = "form-control";
            $this->nr2->EditCustomAttributes = "";
            $this->nr2->EditValue = HtmlEncode($this->nr2->CurrentValue);

            // Edit refer script

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            // nr2
            $this->nr2->LinkCustomAttributes = "";
            $this->nr2->HrefValue = "";
        }
        if ($this->RowType == ROWTYPE_ADD || $this->RowType == ROWTYPE_EDIT || $this->RowType == ROWTYPE_SEARCH) { // Add/Edit/Search row
            $this->setupFieldTitles();
        }

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

    // Validate form
    protected function validateForm()
    {
        global $Language;

        // Check if validation required
        if (!Config("SERVER_VALIDATE")) {
            return true;
        }
        if ($this->nilai_id->Required) {
            if (!$this->nilai_id->IsDetailKey && EmptyValue($this->nilai_id->FormValue)) {
                $this->nilai_id->addErrorMessage(str_replace("%s", $this->nilai_id->caption(), $this->nilai_id->RequiredErrorMessage));
            }
        }
        if ($this->kode_tapel->Required) {
            if (!$this->kode_tapel->IsDetailKey && EmptyValue($this->kode_tapel->FormValue)) {
                $this->kode_tapel->addErrorMessage(str_replace("%s", $this->kode_tapel->caption(), $this->kode_tapel->RequiredErrorMessage));
            }
        }
        if ($this->guru_id->Required) {
            if (!$this->guru_id->IsDetailKey && EmptyValue($this->guru_id->FormValue)) {
                $this->guru_id->addErrorMessage(str_replace("%s", $this->guru_id->caption(), $this->guru_id->RequiredErrorMessage));
            }
        }
        if ($this->kode_mapel->Required) {
            if (!$this->kode_mapel->IsDetailKey && EmptyValue($this->kode_mapel->FormValue)) {
                $this->kode_mapel->addErrorMessage(str_replace("%s", $this->kode_mapel->caption(), $this->kode_mapel->RequiredErrorMessage));
            }
        }
        if ($this->kelas->Required) {
            if (!$this->kelas->IsDetailKey && EmptyValue($this->kelas->FormValue)) {
                $this->kelas->addErrorMessage(str_replace("%s", $this->kelas->caption(), $this->kelas->RequiredErrorMessage));
            }
        }
        if ($this->nis->Required) {
            if (!$this->nis->IsDetailKey && EmptyValue($this->nis->FormValue)) {
                $this->nis->addErrorMessage(str_replace("%s", $this->nis->caption(), $this->nis->RequiredErrorMessage));
            }
        }
        if ($this->nama->Required) {
            if (!$this->nama->IsDetailKey && EmptyValue($this->nama->FormValue)) {
                $this->nama->addErrorMessage(str_replace("%s", $this->nama->caption(), $this->nama->RequiredErrorMessage));
            }
        }
        if ($this->jk->Required) {
            if (!$this->jk->IsDetailKey && EmptyValue($this->jk->FormValue)) {
                $this->jk->addErrorMessage(str_replace("%s", $this->jk->caption(), $this->jk->RequiredErrorMessage));
            }
        }
        if ($this->f1->Required) {
            if (!$this->f1->IsDetailKey && EmptyValue($this->f1->FormValue)) {
                $this->f1->addErrorMessage(str_replace("%s", $this->f1->caption(), $this->f1->RequiredErrorMessage));
            }
        }
        if (!CheckInteger($this->f1->FormValue)) {
            $this->f1->addErrorMessage($this->f1->getErrorMessage(false));
        }
        if ($this->f2->Required) {
            if (!$this->f2->IsDetailKey && EmptyValue($this->f2->FormValue)) {
                $this->f2->addErrorMessage(str_replace("%s", $this->f2->caption(), $this->f2->RequiredErrorMessage));
            }
        }
        if (!CheckInteger($this->f2->FormValue)) {
            $this->f2->addErrorMessage($this->f2->getErrorMessage(false));
        }
        if ($this->f3->Required) {
            if (!$this->f3->IsDetailKey && EmptyValue($this->f3->FormValue)) {
                $this->f3->addErrorMessage(str_replace("%s", $this->f3->caption(), $this->f3->RequiredErrorMessage));
            }
        }
        if (!CheckInteger($this->f3->FormValue)) {
            $this->f3->addErrorMessage($this->f3->getErrorMessage(false));
        }
        if ($this->f4->Required) {
            if (!$this->f4->IsDetailKey && EmptyValue($this->f4->FormValue)) {
                $this->f4->addErrorMessage(str_replace("%s", $this->f4->caption(), $this->f4->RequiredErrorMessage));
            }
        }
        if (!CheckInteger($this->f4->FormValue)) {
            $this->f4->addErrorMessage($this->f4->getErrorMessage(false));
        }
        if ($this->f5->Required) {
            if (!$this->f5->IsDetailKey && EmptyValue($this->f5->FormValue)) {
                $this->f5->addErrorMessage(str_replace("%s", $this->f5->caption(), $this->f5->RequiredErrorMessage));
            }
        }
        if (!CheckInteger($this->f5->FormValue)) {
            $this->f5->addErrorMessage($this->f5->getErrorMessage(false));
        }
        if ($this->f6->Required) {
            if (!$this->f6->IsDetailKey && EmptyValue($this->f6->FormValue)) {
                $this->f6->addErrorMessage(str_replace("%s", $this->f6->caption(), $this->f6->RequiredErrorMessage));
            }
        }
        if (!CheckInteger($this->f6->FormValue)) {
            $this->f6->addErrorMessage($this->f6->getErrorMessage(false));
        }
        if ($this->f7->Required) {
            if (!$this->f7->IsDetailKey && EmptyValue($this->f7->FormValue)) {
                $this->f7->addErrorMessage(str_replace("%s", $this->f7->caption(), $this->f7->RequiredErrorMessage));
            }
        }
        if (!CheckInteger($this->f7->FormValue)) {
            $this->f7->addErrorMessage($this->f7->getErrorMessage(false));
        }
        if ($this->f8->Required) {
            if (!$this->f8->IsDetailKey && EmptyValue($this->f8->FormValue)) {
                $this->f8->addErrorMessage(str_replace("%s", $this->f8->caption(), $this->f8->RequiredErrorMessage));
            }
        }
        if (!CheckInteger($this->f8->FormValue)) {
            $this->f8->addErrorMessage($this->f8->getErrorMessage(false));
        }
        if ($this->f9->Required) {
            if (!$this->f9->IsDetailKey && EmptyValue($this->f9->FormValue)) {
                $this->f9->addErrorMessage(str_replace("%s", $this->f9->caption(), $this->f9->RequiredErrorMessage));
            }
        }
        if (!CheckInteger($this->f9->FormValue)) {
            $this->f9->addErrorMessage($this->f9->getErrorMessage(false));
        }
        if ($this->f10->Required) {
            if (!$this->f10->IsDetailKey && EmptyValue($this->f10->FormValue)) {
                $this->f10->addErrorMessage(str_replace("%s", $this->f10->caption(), $this->f10->RequiredErrorMessage));
            }
        }
        if (!CheckInteger($this->f10->FormValue)) {
            $this->f10->addErrorMessage($this->f10->getErrorMessage(false));
        }
        if ($this->f11->Required) {
            if (!$this->f11->IsDetailKey && EmptyValue($this->f11->FormValue)) {
                $this->f11->addErrorMessage(str_replace("%s", $this->f11->caption(), $this->f11->RequiredErrorMessage));
            }
        }
        if (!CheckInteger($this->f11->FormValue)) {
            $this->f11->addErrorMessage($this->f11->getErrorMessage(false));
        }
        if ($this->f12->Required) {
            if (!$this->f12->IsDetailKey && EmptyValue($this->f12->FormValue)) {
                $this->f12->addErrorMessage(str_replace("%s", $this->f12->caption(), $this->f12->RequiredErrorMessage));
            }
        }
        if (!CheckInteger($this->f12->FormValue)) {
            $this->f12->addErrorMessage($this->f12->getErrorMessage(false));
        }
        if ($this->f13->Required) {
            if (!$this->f13->IsDetailKey && EmptyValue($this->f13->FormValue)) {
                $this->f13->addErrorMessage(str_replace("%s", $this->f13->caption(), $this->f13->RequiredErrorMessage));
            }
        }
        if (!CheckInteger($this->f13->FormValue)) {
            $this->f13->addErrorMessage($this->f13->getErrorMessage(false));
        }
        if ($this->f14->Required) {
            if (!$this->f14->IsDetailKey && EmptyValue($this->f14->FormValue)) {
                $this->f14->addErrorMessage(str_replace("%s", $this->f14->caption(), $this->f14->RequiredErrorMessage));
            }
        }
        if (!CheckInteger($this->f14->FormValue)) {
            $this->f14->addErrorMessage($this->f14->getErrorMessage(false));
        }
        if ($this->f15->Required) {
            if (!$this->f15->IsDetailKey && EmptyValue($this->f15->FormValue)) {
                $this->f15->addErrorMessage(str_replace("%s", $this->f15->caption(), $this->f15->RequiredErrorMessage));
            }
        }
        if (!CheckInteger($this->f15->FormValue)) {
            $this->f15->addErrorMessage($this->f15->getErrorMessage(false));
        }
        if ($this->naf->Required) {
            if (!$this->naf->IsDetailKey && EmptyValue($this->naf->FormValue)) {
                $this->naf->addErrorMessage(str_replace("%s", $this->naf->caption(), $this->naf->RequiredErrorMessage));
            }
        }
        if (!CheckInteger($this->naf->FormValue)) {
            $this->naf->addErrorMessage($this->naf->getErrorMessage(false));
        }
        if ($this->s1->Required) {
            if (!$this->s1->IsDetailKey && EmptyValue($this->s1->FormValue)) {
                $this->s1->addErrorMessage(str_replace("%s", $this->s1->caption(), $this->s1->RequiredErrorMessage));
            }
        }
        if (!CheckInteger($this->s1->FormValue)) {
            $this->s1->addErrorMessage($this->s1->getErrorMessage(false));
        }
        if ($this->s2->Required) {
            if (!$this->s2->IsDetailKey && EmptyValue($this->s2->FormValue)) {
                $this->s2->addErrorMessage(str_replace("%s", $this->s2->caption(), $this->s2->RequiredErrorMessage));
            }
        }
        if (!CheckInteger($this->s2->FormValue)) {
            $this->s2->addErrorMessage($this->s2->getErrorMessage(false));
        }
        if ($this->s3->Required) {
            if (!$this->s3->IsDetailKey && EmptyValue($this->s3->FormValue)) {
                $this->s3->addErrorMessage(str_replace("%s", $this->s3->caption(), $this->s3->RequiredErrorMessage));
            }
        }
        if (!CheckInteger($this->s3->FormValue)) {
            $this->s3->addErrorMessage($this->s3->getErrorMessage(false));
        }
        if ($this->s4->Required) {
            if (!$this->s4->IsDetailKey && EmptyValue($this->s4->FormValue)) {
                $this->s4->addErrorMessage(str_replace("%s", $this->s4->caption(), $this->s4->RequiredErrorMessage));
            }
        }
        if (!CheckInteger($this->s4->FormValue)) {
            $this->s4->addErrorMessage($this->s4->getErrorMessage(false));
        }
        if ($this->s5->Required) {
            if (!$this->s5->IsDetailKey && EmptyValue($this->s5->FormValue)) {
                $this->s5->addErrorMessage(str_replace("%s", $this->s5->caption(), $this->s5->RequiredErrorMessage));
            }
        }
        if (!CheckInteger($this->s5->FormValue)) {
            $this->s5->addErrorMessage($this->s5->getErrorMessage(false));
        }
        if ($this->s6->Required) {
            if (!$this->s6->IsDetailKey && EmptyValue($this->s6->FormValue)) {
                $this->s6->addErrorMessage(str_replace("%s", $this->s6->caption(), $this->s6->RequiredErrorMessage));
            }
        }
        if (!CheckInteger($this->s6->FormValue)) {
            $this->s6->addErrorMessage($this->s6->getErrorMessage(false));
        }
        if ($this->s7->Required) {
            if (!$this->s7->IsDetailKey && EmptyValue($this->s7->FormValue)) {
                $this->s7->addErrorMessage(str_replace("%s", $this->s7->caption(), $this->s7->RequiredErrorMessage));
            }
        }
        if (!CheckInteger($this->s7->FormValue)) {
            $this->s7->addErrorMessage($this->s7->getErrorMessage(false));
        }
        if ($this->s8->Required) {
            if (!$this->s8->IsDetailKey && EmptyValue($this->s8->FormValue)) {
                $this->s8->addErrorMessage(str_replace("%s", $this->s8->caption(), $this->s8->RequiredErrorMessage));
            }
        }
        if (!CheckInteger($this->s8->FormValue)) {
            $this->s8->addErrorMessage($this->s8->getErrorMessage(false));
        }
        if ($this->nas->Required) {
            if (!$this->nas->IsDetailKey && EmptyValue($this->nas->FormValue)) {
                $this->nas->addErrorMessage(str_replace("%s", $this->nas->caption(), $this->nas->RequiredErrorMessage));
            }
        }
        if ($this->sts->Required) {
            if (!$this->sts->IsDetailKey && EmptyValue($this->sts->FormValue)) {
                $this->sts->addErrorMessage(str_replace("%s", $this->sts->caption(), $this->sts->RequiredErrorMessage));
            }
        }
        if ($this->sas->Required) {
            if (!$this->sas->IsDetailKey && EmptyValue($this->sas->FormValue)) {
                $this->sas->addErrorMessage(str_replace("%s", $this->sas->caption(), $this->sas->RequiredErrorMessage));
            }
        }
        if ($this->nr1->Required) {
            if (!$this->nr1->IsDetailKey && EmptyValue($this->nr1->FormValue)) {
                $this->nr1->addErrorMessage(str_replace("%s", $this->nr1->caption(), $this->nr1->RequiredErrorMessage));
            }
        }
        if ($this->nr2->Required) {
            if (!$this->nr2->IsDetailKey && EmptyValue($this->nr2->FormValue)) {
                $this->nr2->addErrorMessage(str_replace("%s", $this->nr2->caption(), $this->nr2->RequiredErrorMessage));
            }
        }
        if (!CheckInteger($this->nr2->FormValue)) {
            $this->nr2->addErrorMessage($this->nr2->getErrorMessage(false));
        }

        // Return validate result
        $validateForm = !$this->hasInvalidFields();

        // Call Form_CustomValidate event
        $formCustomError = "";
        $validateForm = $validateForm && $this->formCustomValidate($formCustomError);
        if ($formCustomError != "") {
            $this->setFailureMessage($formCustomError);
        }
        return $validateForm;
    }

    // Update record based on key values
    protected function editRow()
    {
        global $Security, $Language;
        $oldKeyFilter = $this->getRecordFilter();
        $filter = $this->applyUserIDFilters($oldKeyFilter);
        $conn = $this->getConnection();
        $this->CurrentFilter = $filter;
        $sql = $this->getCurrentSql();
        $rsold = $conn->fetchAssoc($sql);
        $editRow = false;
        if (!$rsold) {
            $this->setFailureMessage($Language->phrase("NoRecord")); // Set no record message
            $editRow = false; // Update Failed
        } else {
            // Save old values
            $this->loadDbValues($rsold);
            $rsnew = [];

            // kode_tapel
            $this->kode_tapel->setDbValueDef($rsnew, $this->kode_tapel->CurrentValue, null, $this->kode_tapel->ReadOnly);

            // guru_id
            $this->guru_id->setDbValueDef($rsnew, $this->guru_id->CurrentValue, null, $this->guru_id->ReadOnly);

            // kode_mapel
            $this->kode_mapel->setDbValueDef($rsnew, $this->kode_mapel->CurrentValue, null, $this->kode_mapel->ReadOnly);

            // kelas
            $this->kelas->setDbValueDef($rsnew, $this->kelas->CurrentValue, null, $this->kelas->ReadOnly);

            // nis
            $this->nis->setDbValueDef($rsnew, $this->nis->CurrentValue, null, $this->nis->ReadOnly);

            // nama
            $this->nama->setDbValueDef($rsnew, $this->nama->CurrentValue, null, $this->nama->ReadOnly);

            // jk
            $this->jk->setDbValueDef($rsnew, $this->jk->CurrentValue, null, $this->jk->ReadOnly);

            // f1
            $this->f1->setDbValueDef($rsnew, $this->f1->CurrentValue, null, $this->f1->ReadOnly);

            // f2
            $this->f2->setDbValueDef($rsnew, $this->f2->CurrentValue, null, $this->f2->ReadOnly);

            // f3
            $this->f3->setDbValueDef($rsnew, $this->f3->CurrentValue, null, $this->f3->ReadOnly);

            // f4
            $this->f4->setDbValueDef($rsnew, $this->f4->CurrentValue, null, $this->f4->ReadOnly);

            // f5
            $this->f5->setDbValueDef($rsnew, $this->f5->CurrentValue, null, $this->f5->ReadOnly);

            // f6
            $this->f6->setDbValueDef($rsnew, $this->f6->CurrentValue, null, $this->f6->ReadOnly);

            // f7
            $this->f7->setDbValueDef($rsnew, $this->f7->CurrentValue, null, $this->f7->ReadOnly);

            // f8
            $this->f8->setDbValueDef($rsnew, $this->f8->CurrentValue, null, $this->f8->ReadOnly);

            // f9
            $this->f9->setDbValueDef($rsnew, $this->f9->CurrentValue, null, $this->f9->ReadOnly);

            // f10
            $this->f10->setDbValueDef($rsnew, $this->f10->CurrentValue, null, $this->f10->ReadOnly);

            // f11
            $this->f11->setDbValueDef($rsnew, $this->f11->CurrentValue, null, $this->f11->ReadOnly);

            // f12
            $this->f12->setDbValueDef($rsnew, $this->f12->CurrentValue, null, $this->f12->ReadOnly);

            // f13
            $this->f13->setDbValueDef($rsnew, $this->f13->CurrentValue, null, $this->f13->ReadOnly);

            // f14
            $this->f14->setDbValueDef($rsnew, $this->f14->CurrentValue, null, $this->f14->ReadOnly);

            // f15
            $this->f15->setDbValueDef($rsnew, $this->f15->CurrentValue, null, $this->f15->ReadOnly);

            // naf
            $this->naf->setDbValueDef($rsnew, $this->naf->CurrentValue, null, $this->naf->ReadOnly);

            // s1
            $this->s1->setDbValueDef($rsnew, $this->s1->CurrentValue, null, $this->s1->ReadOnly);

            // s2
            $this->s2->setDbValueDef($rsnew, $this->s2->CurrentValue, null, $this->s2->ReadOnly);

            // s3
            $this->s3->setDbValueDef($rsnew, $this->s3->CurrentValue, null, $this->s3->ReadOnly);

            // s4
            $this->s4->setDbValueDef($rsnew, $this->s4->CurrentValue, null, $this->s4->ReadOnly);

            // s5
            $this->s5->setDbValueDef($rsnew, $this->s5->CurrentValue, null, $this->s5->ReadOnly);

            // s6
            $this->s6->setDbValueDef($rsnew, $this->s6->CurrentValue, null, $this->s6->ReadOnly);

            // s7
            $this->s7->setDbValueDef($rsnew, $this->s7->CurrentValue, null, $this->s7->ReadOnly);

            // s8
            $this->s8->setDbValueDef($rsnew, $this->s8->CurrentValue, null, $this->s8->ReadOnly);

            // nas
            $this->nas->setDbValueDef($rsnew, $this->nas->CurrentValue, null, $this->nas->ReadOnly);

            // sts
            $this->sts->setDbValueDef($rsnew, $this->sts->CurrentValue, null, $this->sts->ReadOnly);

            // sas
            $this->sas->setDbValueDef($rsnew, $this->sas->CurrentValue, null, $this->sas->ReadOnly);

            // nr1
            $this->nr1->setDbValueDef($rsnew, $this->nr1->CurrentValue, null, $this->nr1->ReadOnly);

            // nr2
            $this->nr2->setDbValueDef($rsnew, $this->nr2->CurrentValue, null, $this->nr2->ReadOnly);

            // Call Row Updating event
            $updateRow = $this->rowUpdating($rsold, $rsnew);
            if ($updateRow) {
                if (count($rsnew) > 0) {
                    try {
                        $editRow = $this->update($rsnew, "", $rsold);
                    } catch (\Exception $e) {
                        $this->setFailureMessage($e->getMessage());
                    }
                } else {
                    $editRow = true; // No field to update
                }
                if ($editRow) {
                }
            } else {
                if ($this->getSuccessMessage() != "" || $this->getFailureMessage() != "") {
                    // Use the message, do nothing
                } elseif ($this->CancelMessage != "") {
                    $this->setFailureMessage($this->CancelMessage);
                    $this->CancelMessage = "";
                } else {
                    $this->setFailureMessage($Language->phrase("UpdateCancelled"));
                }
                $editRow = false;
            }
        }

        // Call Row_Updated event
        if ($editRow) {
            $this->rowUpdated($rsold, $rsnew);
        }

        // Clean upload path if any
        if ($editRow) {
        }

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

    // 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 = "edit";
        $Breadcrumb->add("edit", $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;
            }
        }
    }

    // Set up starting record parameters
    public function setupStartRecord()
    {
        if ($this->DisplayRecords == 0) {
            return;
        }
        if ($this->isPageRequest()) { // Validate request
            $startRec = Get(Config("TABLE_START_REC"));
            $pageNo = Get(Config("TABLE_PAGE_NO"));
            if ($pageNo !== null) { // Check for "pageno" parameter first
                if (is_numeric($pageNo)) {
                    $this->StartRecord = ($pageNo - 1) * $this->DisplayRecords + 1;
                    if ($this->StartRecord <= 0) {
                        $this->StartRecord = 1;
                    } elseif ($this->StartRecord >= (int)(($this->TotalRecords - 1) / $this->DisplayRecords) * $this->DisplayRecords + 1) {
                        $this->StartRecord = (int)(($this->TotalRecords - 1) / $this->DisplayRecords) * $this->DisplayRecords + 1;
                    }
                    $this->setStartRecordNumber($this->StartRecord);
                }
            } elseif ($startRec !== null) { // Check for "start" parameter
                $this->StartRecord = $startRec;
                $this->setStartRecordNumber($this->StartRecord);
            }
        }
        $this->StartRecord = $this->getStartRecordNumber();

        // Check if correct start record counter
        if (!is_numeric($this->StartRecord) || $this->StartRecord == "") { // Avoid invalid start record counter
            $this->StartRecord = 1; // Reset start record counter
            $this->setStartRecordNumber($this->StartRecord);
        } elseif ($this->StartRecord > $this->TotalRecords) { // Avoid starting record > total records
            $this->StartRecord = (int)(($this->TotalRecords - 1) / $this->DisplayRecords) * $this->DisplayRecords + 1; // Point to last page first record
            $this->setStartRecordNumber($this->StartRecord);
        } elseif (($this->StartRecord - 1) % $this->DisplayRecords != 0) {
            $this->StartRecord = (int)(($this->StartRecord - 1) / $this->DisplayRecords) * $this->DisplayRecords + 1; // Point to page boundary
            $this->setStartRecordNumber($this->StartRecord);
        }
    }

    // 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";
    }

    // Form Custom Validate event
    public function formCustomValidate(&$customError)
    {
        // Return error message in CustomError
        return true;
    }
}
