<?php

namespace PHPMaker2021\rdigital21;

use Doctrine\DBAL\ParameterType;

/**
 * Page class
 */
class NilaiFormatifGrid extends NilaiFormatif
{
    use MessagesTrait;

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

    // Project ID
    public $ProjectID = PROJECT_ID;

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

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

    // Rendering View
    public $RenderingView = false;

    // Grid form hidden field names
    public $FormName = "fnilai_formatifgrid";
    public $FormActionName = "k_action";
    public $FormBlankRowName = "k_blankrow";
    public $FormKeyCountName = "key_count";

    // Page URLs
    public $AddUrl;
    public $EditUrl;
    public $CopyUrl;
    public $DeleteUrl;
    public $ViewUrl;
    public $ListUrl;

    // 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
        $this->FormActionName .= "_" . $this->FormName;
        $this->OldKeyName .= "_" . $this->FormName;
        $this->FormBlankRowName .= "_" . $this->FormName;
        $this->FormKeyCountName .= "_" . $this->FormName;
        $GLOBALS["Grid"] = &$this;

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

        // Parent constuctor
        parent::__construct();

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

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

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

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

        // Debug message
        LoadDebugMessage();

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

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

        // List options
        $this->ListOptions = new ListOptions();
        $this->ListOptions->TableVar = $this->TableVar;

        // Other options
        if (!$this->OtherOptions) {
            $this->OtherOptions = new ListOptionsArray();
        }
        $this->OtherOptions["addedit"] = new ListOptions("div");
        $this->OtherOptions["addedit"]->TagClassName = "ew-add-edit-option";
    }

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

        // 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_formatif"));
                $doc->Text = @$content;
                if ($this->isExport("email")) {
                    echo $this->exportEmail($doc->Text);
                } else {
                    $doc->export();
                }
                DeleteTempImages(); // Delete temp images
                return;
            }
        }
        unset($GLOBALS["Grid"]);
        if ($url === "") {
            return;
        }
        if (!IsApi() && method_exists($this, "pageRedirecting")) {
            $this->pageRedirecting($url);
        }

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

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

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

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

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

    /**
     * Hide fields for add/edit
     *
     * @return void
     */
    protected function hideFieldsForAddEdit()
    {
        if ($this->isAdd() || $this->isCopy() || $this->isGridAdd()) {
            $this->nilai_f_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
    }

    // Class variables
    public $ListOptions; // List options
    public $ExportOptions; // Export options
    public $SearchOptions; // Search options
    public $OtherOptions; // Other options
    public $FilterOptions; // Filter options
    public $ImportOptions; // Import options
    public $ListActions; // List actions
    public $SelectedCount = 0;
    public $SelectedIndex = 0;
    public $ShowOtherOptions = false;
    public $DisplayRecords = 5;
    public $StartRecord;
    public $StopRecord;
    public $TotalRecords = 0;
    public $RecordRange = 10;
    public $PageSizes = "5,10,15,20,50,100,250,500,1000"; // Page sizes (comma separated)
    public $DefaultSearchWhere = ""; // Default search WHERE clause
    public $SearchWhere = ""; // Search WHERE clause
    public $SearchPanelClass = "ew-search-panel collapse"; // Search Panel class
    public $SearchRowCount = 0; // For extended search
    public $SearchColumnCount = 0; // For extended search
    public $SearchFieldsPerRow = 1; // For extended search
    public $RecordCount = 0; // Record count
    public $EditRowCount;
    public $StartRowCount = 1;
    public $RowCount = 0;
    public $Attrs = []; // Row attributes and cell attributes
    public $RowIndex = 0; // Row index
    public $KeyCount = 0; // Key count
    public $RowAction = ""; // Row action
    public $MultiColumnClass = "col-sm";
    public $MultiColumnEditClass = "w-100";
    public $DbMasterFilter = ""; // Master filter
    public $DbDetailFilter = ""; // Detail filter
    public $MasterRecordExists;
    public $MultiSelectKey;
    public $Command;
    public $RestoreSearch = false;
    public $HashValue; // Hash value
    public $DetailPages;
    public $OldRecordset;

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

        // Get grid add count
        $gridaddcnt = Get(Config("TABLE_GRID_ADD_ROW_COUNT"), "");
        if (is_numeric($gridaddcnt) && $gridaddcnt > 0) {
            $this->GridAddRowCount = $gridaddcnt;
        }

        // Set up list options
        $this->setupListOptions();
        $this->nilai_f_id->setVisibility();
        $this->kode_tapel->Visible = false;
        $this->penilaian_id->Visible = false;
        $this->guru_id->setVisibility();
        $this->kode_mapel->setVisibility();
        $this->kelas->setVisibility();
        $this->nis->Visible = false;
        $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->hideFieldsForAddEdit();

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

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

        // Set up master detail parameters
        $this->setupMasterParms();

        // Setup other options
        $this->setupOtherOptions();

        // Set up lookup cache

        // Search filters
        $srchAdvanced = ""; // Advanced search filter
        $srchBasic = ""; // Basic search filter
        $filter = "";

        // Get command
        $this->Command = strtolower(Get("cmd"));
        if ($this->isPageRequest()) {
            // Set up records per page
            $this->setupDisplayRecords();

            // Handle reset command
            $this->resetCmd();

            // Hide list options
            if ($this->isExport()) {
                $this->ListOptions->hideAllOptions(["sequence"]);
                $this->ListOptions->UseDropDownButton = false; // Disable drop down button
                $this->ListOptions->UseButtonGroup = false; // Disable button group
            } elseif ($this->isGridAdd() || $this->isGridEdit()) {
                $this->ListOptions->hideAllOptions();
                $this->ListOptions->UseDropDownButton = false; // Disable drop down button
                $this->ListOptions->UseButtonGroup = false; // Disable button group
            }

            // Show grid delete link for grid add / grid edit
            if ($this->AllowAddDeleteRow) {
                if ($this->isGridAdd() || $this->isGridEdit()) {
                    $item = $this->ListOptions["griddelete"];
                    if ($item) {
                        $item->Visible = true;
                    }
                }
            }

            // Set up sorting order
            $this->setupSortOrder();
        }

        // Restore display records
        if ($this->Command != "json" && $this->getRecordsPerPage() != "") {
            $this->DisplayRecords = $this->getRecordsPerPage(); // Restore from Session
        } else {
            $this->DisplayRecords = 5; // Load default
            $this->setRecordsPerPage($this->DisplayRecords); // Save default to Session
        }

        // Load Sorting Order
        if ($this->Command != "json") {
            $this->loadSortOrder();
        }

        // Build filter
        $filter = "";
        if (!$Security->canList()) {
            $filter = "(0=1)"; // Filter all records
        }

        // Restore master/detail filter
        $this->DbMasterFilter = $this->getMasterFilter(); // Restore master filter
        $this->DbDetailFilter = $this->getDetailFilter(); // Restore detail filter

        // Add master User ID filter
        if ($Security->currentUserID() != "" && !$Security->isAdmin()) { // Non system admin
                if ($this->getCurrentMasterTable() == "penilaian") {
                    $this->DbMasterFilter = $this->addMasterUserIDFilter($this->DbMasterFilter, "penilaian"); // Add master User ID filter
                }
        }
        AddFilter($filter, $this->DbDetailFilter);
        AddFilter($filter, $this->SearchWhere);

        // Load master record
        if ($this->CurrentMode != "add" && $this->getMasterFilter() != "" && $this->getCurrentMasterTable() == "penilaian") {
            $masterTbl = Container("penilaian");
            $rsmaster = $masterTbl->loadRs($this->DbMasterFilter)->fetch(\PDO::FETCH_ASSOC);
            $this->MasterRecordExists = $rsmaster !== false;
            if (!$this->MasterRecordExists) {
                $this->setFailureMessage($Language->phrase("NoRecord")); // Set no record found
                $this->terminate("PenilaianList"); // Return to master page
                return;
            } else {
                $masterTbl->loadListRowValues($rsmaster);
                $masterTbl->RowType = ROWTYPE_MASTER; // Master row
                $masterTbl->renderListRow();
            }
        }

        // Set up filter
        if ($this->Command == "json") {
            $this->UseSessionForListSql = false; // Do not use session for ListSQL
            $this->CurrentFilter = $filter;
        } else {
            $this->setSessionWhere($filter);
            $this->CurrentFilter = "";
        }
        if ($this->isGridAdd()) {
            if ($this->CurrentMode == "copy") {
                $this->TotalRecords = $this->listRecordCount();
                $this->StartRecord = 1;
                $this->DisplayRecords = $this->TotalRecords;
                $this->Recordset = $this->loadRecordset($this->StartRecord - 1, $this->DisplayRecords);
            } else {
                $this->CurrentFilter = "0=1";
                $this->StartRecord = 1;
                $this->DisplayRecords = $this->GridAddRowCount;
            }
            $this->TotalRecords = $this->DisplayRecords;
            $this->StopRecord = $this->DisplayRecords;
        } else {
            $this->TotalRecords = $this->listRecordCount();
            $this->StartRecord = 1;
            $this->DisplayRecords = $this->TotalRecords; // Display all records
            $this->Recordset = $this->loadRecordset($this->StartRecord - 1, $this->DisplayRecords);
        }

        // Normal return
        if (IsApi()) {
            $rows = $this->getRecordsFromRecordset($this->Recordset);
            $this->Recordset->close();
            WriteJson(["success" => true, $this->TableVar => $rows, "totalRecordCount" => $this->TotalRecords]);
            $this->terminate(true);
            return;
        }

        // Set up pager
        $this->Pager = new PrevNextPager($this->StartRecord, $this->getRecordsPerPage(), $this->TotalRecords, $this->PageSizes, $this->RecordRange, $this->AutoHidePager, $this->AutoHidePageSizeSelector);

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

    // Set up number of records displayed per page
    protected function setupDisplayRecords()
    {
        $wrk = Get(Config("TABLE_REC_PER_PAGE"), "");
        if ($wrk != "") {
            if (is_numeric($wrk)) {
                $this->DisplayRecords = (int)$wrk;
            } else {
                if (SameText($wrk, "all")) { // Display all records
                    $this->DisplayRecords = -1;
                } else {
                    $this->DisplayRecords = 5; // Non-numeric, load default
                }
            }
            $this->setRecordsPerPage($this->DisplayRecords); // Save to Session
            // Reset start position
            $this->StartRecord = 1;
            $this->setStartRecordNumber($this->StartRecord);
        }
    }

    // Exit inline mode
    protected function clearInlineMode()
    {
        $this->LastAction = $this->CurrentAction; // Save last action
        $this->CurrentAction = ""; // Clear action
        $_SESSION[SESSION_INLINE_MODE] = ""; // Clear inline mode
    }

    // Switch to Grid Add mode
    protected function gridAddMode()
    {
        $this->CurrentAction = "gridadd";
        $_SESSION[SESSION_INLINE_MODE] = "gridadd";
        $this->hideFieldsForAddEdit();
    }

    // Switch to Grid Edit mode
    protected function gridEditMode()
    {
        $this->CurrentAction = "gridedit";
        $_SESSION[SESSION_INLINE_MODE] = "gridedit";
        $this->hideFieldsForAddEdit();
    }

    // Perform update to grid
    public function gridUpdate()
    {
        global $Language, $CurrentForm;
        $gridUpdate = true;

        // Get old recordset
        $this->CurrentFilter = $this->buildKeyFilter();
        if ($this->CurrentFilter == "") {
            $this->CurrentFilter = "0=1";
        }
        $sql = $this->getCurrentSql();
        $conn = $this->getConnection();
        if ($rs = $conn->executeQuery($sql)) {
            $rsold = $rs->fetchAll();
            $rs->closeCursor();
        }

        // Call Grid Updating event
        if (!$this->gridUpdating($rsold)) {
            if ($this->getFailureMessage() == "") {
                $this->setFailureMessage($Language->phrase("GridEditCancelled")); // Set grid edit cancelled message
            }
            return false;
        }
        $key = "";

        // Update row index and get row key
        $CurrentForm->Index = -1;
        $rowcnt = strval($CurrentForm->getValue($this->FormKeyCountName));
        if ($rowcnt == "" || !is_numeric($rowcnt)) {
            $rowcnt = 0;
        }

        // Update all rows based on key
        for ($rowindex = 1; $rowindex <= $rowcnt; $rowindex++) {
            $CurrentForm->Index = $rowindex;
            $this->setKey($CurrentForm->getValue($this->OldKeyName));
            $rowaction = strval($CurrentForm->getValue($this->FormActionName));

            // Load all values and keys
            if ($rowaction != "insertdelete") { // Skip insert then deleted rows
                $this->loadFormValues(); // Get form values
                if ($rowaction == "" || $rowaction == "edit" || $rowaction == "delete") {
                    $gridUpdate = $this->OldKey != ""; // Key must not be empty
                } else {
                    $gridUpdate = true;
                }

                // Skip empty row
                if ($rowaction == "insert" && $this->emptyRow()) {
                // Validate form and insert/update/delete record
                } elseif ($gridUpdate) {
                    if ($rowaction == "delete") {
                        $this->CurrentFilter = $this->getRecordFilter();
                        $gridUpdate = $this->deleteRows(); // Delete this row
                    //} elseif (!$this->validateForm()) { // Already done in validateGridForm
                    //    $gridUpdate = false; // Form error, reset action
                    } else {
                        if ($rowaction == "insert") {
                            $gridUpdate = $this->addRow(); // Insert this row
                        } else {
                            if ($this->OldKey != "") {
                                $this->SendEmail = false; // Do not send email on update success
                                $gridUpdate = $this->editRow(); // Update this row
                            }
                        } // End update
                    }
                }
                if ($gridUpdate) {
                    if ($key != "") {
                        $key .= ", ";
                    }
                    $key .= $this->OldKey;
                } else {
                    break;
                }
            }
        }
        if ($gridUpdate) {
            // Get new records
            $rsnew = $conn->fetchAll($sql);

            // Call Grid_Updated event
            $this->gridUpdated($rsold, $rsnew);
            $this->clearInlineMode(); // Clear inline edit mode
        } else {
            if ($this->getFailureMessage() == "") {
                $this->setFailureMessage($Language->phrase("UpdateFailed")); // Set update failed message
            }
        }
        return $gridUpdate;
    }

    // Build filter for all keys
    protected function buildKeyFilter()
    {
        global $CurrentForm;
        $wrkFilter = "";

        // Update row index and get row key
        $rowindex = 1;
        $CurrentForm->Index = $rowindex;
        $thisKey = strval($CurrentForm->getValue($this->OldKeyName));
        while ($thisKey != "") {
            $this->setKey($thisKey);
            if ($this->OldKey != "") {
                $filter = $this->getRecordFilter();
                if ($wrkFilter != "") {
                    $wrkFilter .= " OR ";
                }
                $wrkFilter .= $filter;
            } else {
                $wrkFilter = "0=1";
                break;
            }

            // Update row index and get row key
            $rowindex++; // Next row
            $CurrentForm->Index = $rowindex;
            $thisKey = strval($CurrentForm->getValue($this->OldKeyName));
        }
        return $wrkFilter;
    }

    // Perform Grid Add
    public function gridInsert()
    {
        global $Language, $CurrentForm;
        $rowindex = 1;
        $gridInsert = false;
        $conn = $this->getConnection();

        // Call Grid Inserting event
        if (!$this->gridInserting()) {
            if ($this->getFailureMessage() == "") {
                $this->setFailureMessage($Language->phrase("GridAddCancelled")); // Set grid add cancelled message
            }
            return false;
        }

        // Init key filter
        $wrkfilter = "";
        $addcnt = 0;
        $key = "";

        // Get row count
        $CurrentForm->Index = -1;
        $rowcnt = strval($CurrentForm->getValue($this->FormKeyCountName));
        if ($rowcnt == "" || !is_numeric($rowcnt)) {
            $rowcnt = 0;
        }

        // Insert all rows
        for ($rowindex = 1; $rowindex <= $rowcnt; $rowindex++) {
            // Load current row values
            $CurrentForm->Index = $rowindex;
            $rowaction = strval($CurrentForm->getValue($this->FormActionName));
            if ($rowaction != "" && $rowaction != "insert") {
                continue; // Skip
            }
            if ($rowaction == "insert") {
                $this->OldKey = strval($CurrentForm->getValue($this->OldKeyName));
                $this->loadOldRecord(); // Load old record
            }
            $this->loadFormValues(); // Get form values
            if (!$this->emptyRow()) {
                $addcnt++;
                $this->SendEmail = false; // Do not send email on insert success

                // Validate form // Already done in validateGridForm
                //if (!$this->validateForm()) {
                //    $gridInsert = false; // Form error, reset action
                //} else {
                    $gridInsert = $this->addRow($this->OldRecordset); // Insert this row
                //}
                if ($gridInsert) {
                    if ($key != "") {
                        $key .= Config("COMPOSITE_KEY_SEPARATOR");
                    }
                    $key .= $this->nilai_f_id->CurrentValue;

                    // Add filter for this record
                    $filter = $this->getRecordFilter();
                    if ($wrkfilter != "") {
                        $wrkfilter .= " OR ";
                    }
                    $wrkfilter .= $filter;
                } else {
                    break;
                }
            }
        }
        if ($addcnt == 0) { // No record inserted
            $this->clearInlineMode(); // Clear grid add mode and return
            return true;
        }
        if ($gridInsert) {
            // Get new records
            $this->CurrentFilter = $wrkfilter;
            $sql = $this->getCurrentSql();
            $rsnew = $conn->fetchAll($sql);

            // Call Grid_Inserted event
            $this->gridInserted($rsnew);
            $this->clearInlineMode(); // Clear grid add mode
        } else {
            if ($this->getFailureMessage() == "") {
                $this->setFailureMessage($Language->phrase("InsertFailed")); // Set insert failed message
            }
        }
        return $gridInsert;
    }

    // Check if empty row
    public function emptyRow()
    {
        global $CurrentForm;
        if ($CurrentForm->hasValue("x_guru_id") && $CurrentForm->hasValue("o_guru_id") && $this->guru_id->CurrentValue != $this->guru_id->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_kode_mapel") && $CurrentForm->hasValue("o_kode_mapel") && $this->kode_mapel->CurrentValue != $this->kode_mapel->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_kelas") && $CurrentForm->hasValue("o_kelas") && $this->kelas->CurrentValue != $this->kelas->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_nama") && $CurrentForm->hasValue("o_nama") && $this->nama->CurrentValue != $this->nama->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_jk") && $CurrentForm->hasValue("o_jk") && $this->jk->CurrentValue != $this->jk->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_f1") && $CurrentForm->hasValue("o_f1") && $this->f1->CurrentValue != $this->f1->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_f2") && $CurrentForm->hasValue("o_f2") && $this->f2->CurrentValue != $this->f2->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_f3") && $CurrentForm->hasValue("o_f3") && $this->f3->CurrentValue != $this->f3->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_f4") && $CurrentForm->hasValue("o_f4") && $this->f4->CurrentValue != $this->f4->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_f5") && $CurrentForm->hasValue("o_f5") && $this->f5->CurrentValue != $this->f5->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_f6") && $CurrentForm->hasValue("o_f6") && $this->f6->CurrentValue != $this->f6->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_f7") && $CurrentForm->hasValue("o_f7") && $this->f7->CurrentValue != $this->f7->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_f8") && $CurrentForm->hasValue("o_f8") && $this->f8->CurrentValue != $this->f8->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_f9") && $CurrentForm->hasValue("o_f9") && $this->f9->CurrentValue != $this->f9->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_f10") && $CurrentForm->hasValue("o_f10") && $this->f10->CurrentValue != $this->f10->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_f11") && $CurrentForm->hasValue("o_f11") && $this->f11->CurrentValue != $this->f11->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_f12") && $CurrentForm->hasValue("o_f12") && $this->f12->CurrentValue != $this->f12->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_f13") && $CurrentForm->hasValue("o_f13") && $this->f13->CurrentValue != $this->f13->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_f14") && $CurrentForm->hasValue("o_f14") && $this->f14->CurrentValue != $this->f14->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_f15") && $CurrentForm->hasValue("o_f15") && $this->f15->CurrentValue != $this->f15->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_naf") && $CurrentForm->hasValue("o_naf") && $this->naf->CurrentValue != $this->naf->OldValue) {
            return false;
        }
        return true;
    }

    // Validate grid form
    public function validateGridForm()
    {
        global $CurrentForm;
        // Get row count
        $CurrentForm->Index = -1;
        $rowcnt = strval($CurrentForm->getValue($this->FormKeyCountName));
        if ($rowcnt == "" || !is_numeric($rowcnt)) {
            $rowcnt = 0;
        }

        // Validate all records
        for ($rowindex = 1; $rowindex <= $rowcnt; $rowindex++) {
            // Load current row values
            $CurrentForm->Index = $rowindex;
            $rowaction = strval($CurrentForm->getValue($this->FormActionName));
            if ($rowaction != "delete" && $rowaction != "insertdelete") {
                $this->loadFormValues(); // Get form values
                if ($rowaction == "insert" && $this->emptyRow()) {
                    // Ignore
                } elseif (!$this->validateForm()) {
                    return false;
                }
            }
        }
        return true;
    }

    // Get all form values of the grid
    public function getGridFormValues()
    {
        global $CurrentForm;
        // Get row count
        $CurrentForm->Index = -1;
        $rowcnt = strval($CurrentForm->getValue($this->FormKeyCountName));
        if ($rowcnt == "" || !is_numeric($rowcnt)) {
            $rowcnt = 0;
        }
        $rows = [];

        // Loop through all records
        for ($rowindex = 1; $rowindex <= $rowcnt; $rowindex++) {
            // Load current row values
            $CurrentForm->Index = $rowindex;
            $rowaction = strval($CurrentForm->getValue($this->FormActionName));
            if ($rowaction != "delete" && $rowaction != "insertdelete") {
                $this->loadFormValues(); // Get form values
                if ($rowaction == "insert" && $this->emptyRow()) {
                    // Ignore
                } else {
                    $rows[] = $this->getFieldValues("FormValue"); // Return row as array
                }
            }
        }
        return $rows; // Return as array of array
    }

    // Restore form values for current row
    public function restoreCurrentRowFormValues($idx)
    {
        global $CurrentForm;

        // Get row based on current index
        $CurrentForm->Index = $idx;
        $rowaction = strval($CurrentForm->getValue($this->FormActionName));
        $this->loadFormValues(); // Load form values
        // Set up invalid status correctly
        $this->resetFormError();
        if ($rowaction == "insert" && $this->emptyRow()) {
            // Ignore
        } else {
            $this->validateForm();
        }
    }

    // Reset form status
    public function resetFormError()
    {
        $this->nilai_f_id->clearErrorMessage();
        $this->guru_id->clearErrorMessage();
        $this->kode_mapel->clearErrorMessage();
        $this->kelas->clearErrorMessage();
        $this->nama->clearErrorMessage();
        $this->jk->clearErrorMessage();
        $this->f1->clearErrorMessage();
        $this->f2->clearErrorMessage();
        $this->f3->clearErrorMessage();
        $this->f4->clearErrorMessage();
        $this->f5->clearErrorMessage();
        $this->f6->clearErrorMessage();
        $this->f7->clearErrorMessage();
        $this->f8->clearErrorMessage();
        $this->f9->clearErrorMessage();
        $this->f10->clearErrorMessage();
        $this->f11->clearErrorMessage();
        $this->f12->clearErrorMessage();
        $this->f13->clearErrorMessage();
        $this->f14->clearErrorMessage();
        $this->f15->clearErrorMessage();
        $this->naf->clearErrorMessage();
    }

    // Set up sort parameters
    protected function setupSortOrder()
    {
        // Check for "order" parameter
        if (Get("order") !== null) {
            $this->CurrentOrder = Get("order");
            $this->CurrentOrderType = Get("ordertype", "");
            $this->setStartRecordNumber(1); // Reset start position
        }
    }

    // Load sort order parameters
    protected function loadSortOrder()
    {
        $orderBy = $this->getSessionOrderBy(); // Get ORDER BY from Session
        if ($orderBy == "") {
            $this->DefaultSort = "";
            if ($this->getSqlOrderBy() != "") {
                $useDefaultSort = true;
                if ($useDefaultSort) {
                    $orderBy = $this->getSqlOrderBy();
                    $this->setSessionOrderBy($orderBy);
                } else {
                    $this->setSessionOrderBy("");
                }
            }
        }
    }

    // Reset command
    // - cmd=reset (Reset search parameters)
    // - cmd=resetall (Reset search and master/detail parameters)
    // - cmd=resetsort (Reset sort parameters)
    protected function resetCmd()
    {
        // Check if reset command
        if (StartsString("reset", $this->Command)) {
            // Reset master/detail keys
            if ($this->Command == "resetall") {
                $this->setCurrentMasterTable(""); // Clear master table
                $this->DbMasterFilter = "";
                $this->DbDetailFilter = "";
                        $this->penilaian_id->setSessionValue("");
            }

            // Reset (clear) sorting order
            if ($this->Command == "resetsort") {
                $orderBy = "";
                $this->setSessionOrderBy($orderBy);
            }

            // Reset start position
            $this->StartRecord = 1;
            $this->setStartRecordNumber($this->StartRecord);
        }
    }

    // Set up list options
    protected function setupListOptions()
    {
        global $Security, $Language;

        // "griddelete"
        if ($this->AllowAddDeleteRow) {
            $item = &$this->ListOptions->add("griddelete");
            $item->CssClass = "text-nowrap";
            $item->OnLeft = true;
            $item->Visible = false; // Default hidden
        }

        // Add group option item
        $item = &$this->ListOptions->add($this->ListOptions->GroupOptionName);
        $item->Body = "";
        $item->OnLeft = true;
        $item->Visible = false;

        // "edit"
        $item = &$this->ListOptions->add("edit");
        $item->CssClass = "text-nowrap";
        $item->Visible = $Security->canEdit();
        $item->OnLeft = true;

        // "sequence"
        $item = &$this->ListOptions->add("sequence");
        $item->CssClass = "text-nowrap";
        $item->Visible = true;
        $item->OnLeft = true; // Always on left
        $item->ShowInDropDown = false;
        $item->ShowInButtonGroup = false;

        // Drop down button for ListOptions
        $this->ListOptions->UseDropDownButton = false;
        $this->ListOptions->DropDownButtonPhrase = $Language->phrase("ButtonListOptions");
        $this->ListOptions->UseButtonGroup = false;
        if ($this->ListOptions->UseButtonGroup && IsMobile()) {
            $this->ListOptions->UseDropDownButton = true;
        }

        //$this->ListOptions->ButtonClass = ""; // Class for button group

        // Call ListOptions_Load event
        $this->listOptionsLoad();
        $item = $this->ListOptions[$this->ListOptions->GroupOptionName];
        $item->Visible = $this->ListOptions->groupOptionVisible();
    }

    // Render list options
    public function renderListOptions()
    {
        global $Security, $Language, $CurrentForm;
        $this->ListOptions->loadDefault();

        // Call ListOptions_Rendering event
        $this->listOptionsRendering();

        // Set up row action and key
        if ($CurrentForm && is_numeric($this->RowIndex) && $this->RowType != "view") {
            $CurrentForm->Index = $this->RowIndex;
            $actionName = str_replace("k_", "k" . $this->RowIndex . "_", $this->FormActionName);
            $oldKeyName = str_replace("k_", "k" . $this->RowIndex . "_", $this->OldKeyName);
            $blankRowName = str_replace("k_", "k" . $this->RowIndex . "_", $this->FormBlankRowName);
            if ($this->RowAction != "") {
                $this->MultiSelectKey .= "<input type=\"hidden\" name=\"" . $actionName . "\" id=\"" . $actionName . "\" value=\"" . $this->RowAction . "\">";
            }
            $oldKey = $this->getKey(false); // Get from OldValue
            if ($oldKeyName != "" && $oldKey != "") {
                $this->MultiSelectKey .= "<input type=\"hidden\" name=\"" . $oldKeyName . "\" id=\"" . $oldKeyName . "\" value=\"" . HtmlEncode($oldKey) . "\">";
            }
            if ($this->RowAction == "insert" && $this->isConfirm() && $this->emptyRow()) {
                $this->MultiSelectKey .= "<input type=\"hidden\" name=\"" . $blankRowName . "\" id=\"" . $blankRowName . "\" value=\"1\">";
            }
        }

        // "delete"
        if ($this->AllowAddDeleteRow) {
            if ($this->CurrentMode == "add" || $this->CurrentMode == "copy" || $this->CurrentMode == "edit") {
                $options = &$this->ListOptions;
                $options->UseButtonGroup = true; // Use button group for grid delete button
                $opt = $options["griddelete"];
                if (!$Security->canDelete() && is_numeric($this->RowIndex) && ($this->RowAction == "" || $this->RowAction == "edit")) { // Do not allow delete existing record
                    $opt->Body = "&nbsp;";
                } else {
                    $opt->Body = "<a class=\"ew-grid-link ew-grid-delete\" title=\"" . HtmlTitle($Language->phrase("DeleteLink")) . "\" data-caption=\"" . HtmlTitle($Language->phrase("DeleteLink")) . "\" onclick=\"return ew.deleteGridRow(this, " . $this->RowIndex . ");\">" . $Language->phrase("DeleteLink") . "</a>";
                }
            }
        }

        // "sequence"
        $opt = $this->ListOptions["sequence"];
        $opt->Body = FormatSequenceNumber($this->RecordCount);
        if ($this->CurrentMode == "view") {
            // "edit"
            $opt = $this->ListOptions["edit"];
            $editcaption = HtmlTitle($Language->phrase("EditLink"));
            if ($Security->canEdit() && $this->showOptionLink("edit")) {
                $opt->Body = "<a class=\"ew-row-link ew-edit\" title=\"" . HtmlTitle($Language->phrase("EditLink")) . "\" data-caption=\"" . HtmlTitle($Language->phrase("EditLink")) . "\" href=\"" . HtmlEncode(GetUrl($this->EditUrl)) . "\">" . $Language->phrase("EditLink") . "</a>";
            } else {
                $opt->Body = "";
            }
        } // End View mode
        $this->renderListOptionsExt();

        // Call ListOptions_Rendered event
        $this->listOptionsRendered();
    }

    // Set up other options
    protected function setupOtherOptions()
    {
        global $Language, $Security;
        $option = $this->OtherOptions["addedit"];
        $option->UseDropDownButton = false;
        $option->DropDownButtonPhrase = $Language->phrase("ButtonAddEdit");
        $option->UseButtonGroup = true;
        //$option->ButtonClass = ""; // Class for button group
        $item = &$option->add($option->GroupOptionName);
        $item->Body = "";
        $item->Visible = false;

        // Add
        if ($this->CurrentMode == "view") { // Check view mode
            $item = &$option->add("add");
            $addcaption = HtmlTitle($Language->phrase("AddLink"));
            $this->AddUrl = $this->getAddUrl();
            $item->Body = "<a class=\"ew-add-edit ew-add\" title=\"" . $addcaption . "\" data-caption=\"" . $addcaption . "\" href=\"" . HtmlEncode(GetUrl($this->AddUrl)) . "\">" . $Language->phrase("AddLink") . "</a>";
            $item->Visible = $this->AddUrl != "" && $Security->canAdd();
        }
    }

    // Render other options
    public function renderOtherOptions()
    {
        global $Language, $Security;
        $options = &$this->OtherOptions;
        if (($this->CurrentMode == "add" || $this->CurrentMode == "copy" || $this->CurrentMode == "edit") && !$this->isConfirm()) { // Check add/copy/edit mode
            if ($this->AllowAddDeleteRow) {
                $option = $options["addedit"];
                $option->UseDropDownButton = false;
                $item = &$option->add("addblankrow");
                $item->Body = "<a class=\"ew-add-edit ew-add-blank-row\" title=\"" . HtmlTitle($Language->phrase("AddBlankRow")) . "\" data-caption=\"" . HtmlTitle($Language->phrase("AddBlankRow")) . "\" href=\"#\" onclick=\"return ew.addGridRow(this);\">" . $Language->phrase("AddBlankRow") . "</a>";
                $item->Visible = $Security->canAdd();
                $this->ShowOtherOptions = $item->Visible;
            }
        }
        if ($this->CurrentMode == "view") { // Check view mode
            $option = $options["addedit"];
            $item = $option["add"];
            $this->ShowOtherOptions = $item && $item->Visible;
        }
    }

    // Set up list options (extended codes)
    protected function setupListOptionsExt()
    {
    }

    // Render list options (extended codes)
    protected function renderListOptionsExt()
    {
    }

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

    // Load default values
    protected function loadDefaultValues()
    {
        $this->nilai_f_id->CurrentValue = null;
        $this->nilai_f_id->OldValue = $this->nilai_f_id->CurrentValue;
        $this->kode_tapel->CurrentValue = null;
        $this->kode_tapel->OldValue = $this->kode_tapel->CurrentValue;
        $this->penilaian_id->CurrentValue = null;
        $this->penilaian_id->OldValue = $this->penilaian_id->CurrentValue;
        $this->guru_id->CurrentValue = null;
        $this->guru_id->OldValue = $this->guru_id->CurrentValue;
        $this->kode_mapel->CurrentValue = null;
        $this->kode_mapel->OldValue = $this->kode_mapel->CurrentValue;
        $this->kelas->CurrentValue = CurrentUserID();
        $this->kelas->OldValue = $this->kelas->CurrentValue;
        $this->nis->CurrentValue = null;
        $this->nis->OldValue = $this->nis->CurrentValue;
        $this->nama->CurrentValue = null;
        $this->nama->OldValue = $this->nama->CurrentValue;
        $this->jk->CurrentValue = null;
        $this->jk->OldValue = $this->jk->CurrentValue;
        $this->f1->CurrentValue = null;
        $this->f1->OldValue = $this->f1->CurrentValue;
        $this->f2->CurrentValue = null;
        $this->f2->OldValue = $this->f2->CurrentValue;
        $this->f3->CurrentValue = null;
        $this->f3->OldValue = $this->f3->CurrentValue;
        $this->f4->CurrentValue = null;
        $this->f4->OldValue = $this->f4->CurrentValue;
        $this->f5->CurrentValue = null;
        $this->f5->OldValue = $this->f5->CurrentValue;
        $this->f6->CurrentValue = null;
        $this->f6->OldValue = $this->f6->CurrentValue;
        $this->f7->CurrentValue = null;
        $this->f7->OldValue = $this->f7->CurrentValue;
        $this->f8->CurrentValue = null;
        $this->f8->OldValue = $this->f8->CurrentValue;
        $this->f9->CurrentValue = null;
        $this->f9->OldValue = $this->f9->CurrentValue;
        $this->f10->CurrentValue = null;
        $this->f10->OldValue = $this->f10->CurrentValue;
        $this->f11->CurrentValue = null;
        $this->f11->OldValue = $this->f11->CurrentValue;
        $this->f12->CurrentValue = null;
        $this->f12->OldValue = $this->f12->CurrentValue;
        $this->f13->CurrentValue = null;
        $this->f13->OldValue = $this->f13->CurrentValue;
        $this->f14->CurrentValue = null;
        $this->f14->OldValue = $this->f14->CurrentValue;
        $this->f15->CurrentValue = null;
        $this->f15->OldValue = $this->f15->CurrentValue;
        $this->naf->CurrentValue = null;
        $this->naf->OldValue = $this->naf->CurrentValue;
    }

    // Load form values
    protected function loadFormValues()
    {
        // Load from form
        global $CurrentForm;
        $CurrentForm->FormName = $this->FormName;

        // Check field name 'nilai_f_id' first before field var 'x_nilai_f_id'
        $val = $CurrentForm->hasValue("nilai_f_id") ? $CurrentForm->getValue("nilai_f_id") : $CurrentForm->getValue("x_nilai_f_id");
        if (!$this->nilai_f_id->IsDetailKey && !$this->isGridAdd() && !$this->isAdd()) {
            $this->nilai_f_id->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);
            }
        }
        if ($CurrentForm->hasValue("o_guru_id")) {
            $this->guru_id->setOldValue($CurrentForm->getValue("o_guru_id"));
        }

        // 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);
            }
        }
        if ($CurrentForm->hasValue("o_kode_mapel")) {
            $this->kode_mapel->setOldValue($CurrentForm->getValue("o_kode_mapel"));
        }

        // 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);
            }
        }
        if ($CurrentForm->hasValue("o_kelas")) {
            $this->kelas->setOldValue($CurrentForm->getValue("o_kelas"));
        }

        // 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);
            }
        }
        if ($CurrentForm->hasValue("o_nama")) {
            $this->nama->setOldValue($CurrentForm->getValue("o_nama"));
        }

        // 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);
            }
        }
        if ($CurrentForm->hasValue("o_jk")) {
            $this->jk->setOldValue($CurrentForm->getValue("o_jk"));
        }

        // 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);
            }
        }
        if ($CurrentForm->hasValue("o_f1")) {
            $this->f1->setOldValue($CurrentForm->getValue("o_f1"));
        }

        // 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);
            }
        }
        if ($CurrentForm->hasValue("o_f2")) {
            $this->f2->setOldValue($CurrentForm->getValue("o_f2"));
        }

        // 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);
            }
        }
        if ($CurrentForm->hasValue("o_f3")) {
            $this->f3->setOldValue($CurrentForm->getValue("o_f3"));
        }

        // 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);
            }
        }
        if ($CurrentForm->hasValue("o_f4")) {
            $this->f4->setOldValue($CurrentForm->getValue("o_f4"));
        }

        // 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);
            }
        }
        if ($CurrentForm->hasValue("o_f5")) {
            $this->f5->setOldValue($CurrentForm->getValue("o_f5"));
        }

        // 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);
            }
        }
        if ($CurrentForm->hasValue("o_f6")) {
            $this->f6->setOldValue($CurrentForm->getValue("o_f6"));
        }

        // 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);
            }
        }
        if ($CurrentForm->hasValue("o_f7")) {
            $this->f7->setOldValue($CurrentForm->getValue("o_f7"));
        }

        // 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);
            }
        }
        if ($CurrentForm->hasValue("o_f8")) {
            $this->f8->setOldValue($CurrentForm->getValue("o_f8"));
        }

        // 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);
            }
        }
        if ($CurrentForm->hasValue("o_f9")) {
            $this->f9->setOldValue($CurrentForm->getValue("o_f9"));
        }

        // 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);
            }
        }
        if ($CurrentForm->hasValue("o_f10")) {
            $this->f10->setOldValue($CurrentForm->getValue("o_f10"));
        }

        // 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);
            }
        }
        if ($CurrentForm->hasValue("o_f11")) {
            $this->f11->setOldValue($CurrentForm->getValue("o_f11"));
        }

        // 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);
            }
        }
        if ($CurrentForm->hasValue("o_f12")) {
            $this->f12->setOldValue($CurrentForm->getValue("o_f12"));
        }

        // 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);
            }
        }
        if ($CurrentForm->hasValue("o_f13")) {
            $this->f13->setOldValue($CurrentForm->getValue("o_f13"));
        }

        // 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);
            }
        }
        if ($CurrentForm->hasValue("o_f14")) {
            $this->f14->setOldValue($CurrentForm->getValue("o_f14"));
        }

        // 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);
            }
        }
        if ($CurrentForm->hasValue("o_f15")) {
            $this->f15->setOldValue($CurrentForm->getValue("o_f15"));
        }

        // 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);
            }
        }
        if ($CurrentForm->hasValue("o_naf")) {
            $this->naf->setOldValue($CurrentForm->getValue("o_naf"));
        }
    }

    // Restore form values
    public function restoreFormValues()
    {
        global $CurrentForm;
        if (!$this->isGridAdd() && !$this->isAdd()) {
            $this->nilai_f_id->CurrentValue = $this->nilai_f_id->FormValue;
        }
        $this->guru_id->CurrentValue = $this->guru_id->FormValue;
        $this->kode_mapel->CurrentValue = $this->kode_mapel->FormValue;
        $this->kelas->CurrentValue = $this->kelas->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;
    }

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

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

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

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

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

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

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

        // Call Row Selected event
        $this->rowSelected($row);
        if (!$rs) {
            return;
        }
        $this->nilai_f_id->setDbValue($row['nilai_f_id']);
        $this->kode_tapel->setDbValue($row['kode_tapel']);
        $this->penilaian_id->setDbValue($row['penilaian_id']);
        $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']);
    }

    // Return a row with default values
    protected function newRow()
    {
        $this->loadDefaultValues();
        $row = [];
        $row['nilai_f_id'] = $this->nilai_f_id->CurrentValue;
        $row['kode_tapel'] = $this->kode_tapel->CurrentValue;
        $row['penilaian_id'] = $this->penilaian_id->CurrentValue;
        $row['guru_id'] = $this->guru_id->CurrentValue;
        $row['kode_mapel'] = $this->kode_mapel->CurrentValue;
        $row['kelas'] = $this->kelas->CurrentValue;
        $row['nis'] = $this->nis->CurrentValue;
        $row['nama'] = $this->nama->CurrentValue;
        $row['jk'] = $this->jk->CurrentValue;
        $row['f1'] = $this->f1->CurrentValue;
        $row['f2'] = $this->f2->CurrentValue;
        $row['f3'] = $this->f3->CurrentValue;
        $row['f4'] = $this->f4->CurrentValue;
        $row['f5'] = $this->f5->CurrentValue;
        $row['f6'] = $this->f6->CurrentValue;
        $row['f7'] = $this->f7->CurrentValue;
        $row['f8'] = $this->f8->CurrentValue;
        $row['f9'] = $this->f9->CurrentValue;
        $row['f10'] = $this->f10->CurrentValue;
        $row['f11'] = $this->f11->CurrentValue;
        $row['f12'] = $this->f12->CurrentValue;
        $row['f13'] = $this->f13->CurrentValue;
        $row['f14'] = $this->f14->CurrentValue;
        $row['f15'] = $this->f15->CurrentValue;
        $row['naf'] = $this->naf->CurrentValue;
        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
        $this->ViewUrl = $this->getViewUrl();
        $this->EditUrl = $this->getEditUrl();
        $this->CopyUrl = $this->getCopyUrl();
        $this->DeleteUrl = $this->getDeleteUrl();

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

        // Common render codes for all row types

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            // penilaian_id
            $this->penilaian_id->ViewValue = $this->penilaian_id->CurrentValue;
            $this->penilaian_id->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->ViewCustomAttributes = "";

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            // naf
            $this->naf->ViewValue = $this->naf->CurrentValue;
            $this->naf->CssClass = "font-weight-bold font-italic";
            $this->naf->ViewCustomAttributes = "";

            // nilai_f_id
            $this->nilai_f_id->LinkCustomAttributes = "";
            $this->nilai_f_id->HrefValue = "";
            $this->nilai_f_id->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 = "";

            // 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 = "";
        } elseif ($this->RowType == ROWTYPE_ADD) {
            // nilai_f_id

            // 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 = "";
            $curVal = trim(strval($this->kode_mapel->CurrentValue));
            if ($curVal != "") {
                $this->kode_mapel->ViewValue = $this->kode_mapel->lookupCacheOption($curVal);
            } else {
                $this->kode_mapel->ViewValue = $this->kode_mapel->Lookup !== null && is_array($this->kode_mapel->Lookup->Options) ? $curVal : null;
            }
            if ($this->kode_mapel->ViewValue !== null) { // Load from cache
                $this->kode_mapel->EditValue = array_values($this->kode_mapel->Lookup->Options);
            } else { // Lookup from database
                if ($curVal == "") {
                    $filterWrk = "0=1";
                } else {
                    $filterWrk = "\"kode_mapel\"" . SearchString("=", $this->kode_mapel->CurrentValue, DATATYPE_MEMO, "");
                }
                $sqlWrk = $this->kode_mapel->Lookup->getSql(true, $filterWrk, '', $this, false, true);
                $rswrk = Conn()->executeQuery($sqlWrk)->fetchAll(\PDO::FETCH_BOTH);
                $ari = count($rswrk);
                $arwrk = $rswrk;
                $this->kode_mapel->EditValue = $arwrk;
            }

            // kelas
            $this->kelas->EditAttrs["class"] = "form-control";
            $this->kelas->EditCustomAttributes = "";
            if (!$Security->isAdmin() && $Security->isLoggedIn() && !$this->userIDAllow("grid")) { // Non system admin
                $this->kelas->CurrentValue = CurrentUserID();
                $this->kelas->EditValue = $this->kelas->CurrentValue;
                $this->kelas->ViewCustomAttributes = "";
            } else {
                $curVal = trim(strval($this->kelas->CurrentValue));
                if ($curVal != "") {
                    $this->kelas->ViewValue = $this->kelas->lookupCacheOption($curVal);
                } else {
                    $this->kelas->ViewValue = $this->kelas->Lookup !== null && is_array($this->kelas->Lookup->Options) ? $curVal : null;
                }
                if ($this->kelas->ViewValue !== null) { // Load from cache
                    $this->kelas->EditValue = array_values($this->kelas->Lookup->Options);
                } else { // Lookup from database
                    if ($curVal == "") {
                        $filterWrk = "0=1";
                    } else {
                        $filterWrk = "\"kelas\"" . SearchString("=", $this->kelas->CurrentValue, DATATYPE_MEMO, "");
                    }
                    $lookupFilter = function() {
                        return "`kode_tapel`='".kode_tapel()."'";
                    };
                    $lookupFilter = $lookupFilter->bindTo($this);
                    $sqlWrk = $this->kelas->Lookup->getSql(true, $filterWrk, $lookupFilter, $this, false, true);
                    $rswrk = Conn()->executeQuery($sqlWrk)->fetchAll(\PDO::FETCH_BOTH);
                    $ari = count($rswrk);
                    $arwrk = $rswrk;
                    $this->kelas->EditValue = $arwrk;
                }
            }

            // 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 = "";
            if (!$this->f1->Raw) {
                $this->f1->CurrentValue = HtmlDecode($this->f1->CurrentValue);
            }
            $this->f1->EditValue = HtmlEncode($this->f1->CurrentValue);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            // Add refer script

            // nilai_f_id
            $this->nilai_f_id->LinkCustomAttributes = "";
            $this->nilai_f_id->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 = "";

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

            // 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 = "";
            $curVal = trim(strval($this->kode_mapel->CurrentValue));
            if ($curVal != "") {
                $this->kode_mapel->ViewValue = $this->kode_mapel->lookupCacheOption($curVal);
            } else {
                $this->kode_mapel->ViewValue = $this->kode_mapel->Lookup !== null && is_array($this->kode_mapel->Lookup->Options) ? $curVal : null;
            }
            if ($this->kode_mapel->ViewValue !== null) { // Load from cache
                $this->kode_mapel->EditValue = array_values($this->kode_mapel->Lookup->Options);
            } else { // Lookup from database
                if ($curVal == "") {
                    $filterWrk = "0=1";
                } else {
                    $filterWrk = "\"kode_mapel\"" . SearchString("=", $this->kode_mapel->CurrentValue, DATATYPE_MEMO, "");
                }
                $sqlWrk = $this->kode_mapel->Lookup->getSql(true, $filterWrk, '', $this, false, true);
                $rswrk = Conn()->executeQuery($sqlWrk)->fetchAll(\PDO::FETCH_BOTH);
                $ari = count($rswrk);
                $arwrk = $rswrk;
                $this->kode_mapel->EditValue = $arwrk;
            }

            // kelas
            $this->kelas->EditAttrs["class"] = "form-control";
            $this->kelas->EditCustomAttributes = "";
            if (!$Security->isAdmin() && $Security->isLoggedIn() && !$this->userIDAllow("grid")) { // Non system admin
                $this->kelas->CurrentValue = CurrentUserID();
                $this->kelas->EditValue = $this->kelas->CurrentValue;
                $this->kelas->ViewCustomAttributes = "";
            } else {
                $curVal = trim(strval($this->kelas->CurrentValue));
                if ($curVal != "") {
                    $this->kelas->ViewValue = $this->kelas->lookupCacheOption($curVal);
                } else {
                    $this->kelas->ViewValue = $this->kelas->Lookup !== null && is_array($this->kelas->Lookup->Options) ? $curVal : null;
                }
                if ($this->kelas->ViewValue !== null) { // Load from cache
                    $this->kelas->EditValue = array_values($this->kelas->Lookup->Options);
                } else { // Lookup from database
                    if ($curVal == "") {
                        $filterWrk = "0=1";
                    } else {
                        $filterWrk = "\"kelas\"" . SearchString("=", $this->kelas->CurrentValue, DATATYPE_MEMO, "");
                    }
                    $lookupFilter = function() {
                        return "`kode_tapel`='".kode_tapel()."'";
                    };
                    $lookupFilter = $lookupFilter->bindTo($this);
                    $sqlWrk = $this->kelas->Lookup->getSql(true, $filterWrk, $lookupFilter, $this, false, true);
                    $rswrk = Conn()->executeQuery($sqlWrk)->fetchAll(\PDO::FETCH_BOTH);
                    $ari = count($rswrk);
                    $arwrk = $rswrk;
                    $this->kelas->EditValue = $arwrk;
                }
            }

            // 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 = "";
            if (!$this->f1->Raw) {
                $this->f1->CurrentValue = HtmlDecode($this->f1->CurrentValue);
            }
            $this->f1->EditValue = HtmlEncode($this->f1->CurrentValue);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            // Edit refer script

            // nilai_f_id
            $this->nilai_f_id->LinkCustomAttributes = "";
            $this->nilai_f_id->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 = "";

            // 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 = "";
        }
        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_f_id->Required) {
            if (!$this->nilai_f_id->IsDetailKey && EmptyValue($this->nilai_f_id->FormValue)) {
                $this->nilai_f_id->addErrorMessage(str_replace("%s", $this->nilai_f_id->caption(), $this->nilai_f_id->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->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 ($this->f2->Required) {
            if (!$this->f2->IsDetailKey && EmptyValue($this->f2->FormValue)) {
                $this->f2->addErrorMessage(str_replace("%s", $this->f2->caption(), $this->f2->RequiredErrorMessage));
            }
        }
        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 ($this->f4->Required) {
            if (!$this->f4->IsDetailKey && EmptyValue($this->f4->FormValue)) {
                $this->f4->addErrorMessage(str_replace("%s", $this->f4->caption(), $this->f4->RequiredErrorMessage));
            }
        }
        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 ($this->f6->Required) {
            if (!$this->f6->IsDetailKey && EmptyValue($this->f6->FormValue)) {
                $this->f6->addErrorMessage(str_replace("%s", $this->f6->caption(), $this->f6->RequiredErrorMessage));
            }
        }
        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 ($this->f8->Required) {
            if (!$this->f8->IsDetailKey && EmptyValue($this->f8->FormValue)) {
                $this->f8->addErrorMessage(str_replace("%s", $this->f8->caption(), $this->f8->RequiredErrorMessage));
            }
        }
        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 ($this->f10->Required) {
            if (!$this->f10->IsDetailKey && EmptyValue($this->f10->FormValue)) {
                $this->f10->addErrorMessage(str_replace("%s", $this->f10->caption(), $this->f10->RequiredErrorMessage));
            }
        }
        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 ($this->f12->Required) {
            if (!$this->f12->IsDetailKey && EmptyValue($this->f12->FormValue)) {
                $this->f12->addErrorMessage(str_replace("%s", $this->f12->caption(), $this->f12->RequiredErrorMessage));
            }
        }
        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 ($this->f14->Required) {
            if (!$this->f14->IsDetailKey && EmptyValue($this->f14->FormValue)) {
                $this->f14->addErrorMessage(str_replace("%s", $this->f14->caption(), $this->f14->RequiredErrorMessage));
            }
        }
        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 ($this->naf->Required) {
            if (!$this->naf->IsDetailKey && EmptyValue($this->naf->FormValue)) {
                $this->naf->addErrorMessage(str_replace("%s", $this->naf->caption(), $this->naf->RequiredErrorMessage));
            }
        }

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

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

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

        // Clone old rows
        $rsold = $rows;

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

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

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

    // 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 = [];

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

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

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

    // Add record
    protected function addRow($rsold = null)
    {
        global $Language, $Security;

        // Check if valid User ID
        $validUser = false;
        if ($Security->currentUserID() != "" && !EmptyValue($this->kelas->CurrentValue) && !$Security->isAdmin()) { // Non system admin
            $validUser = $Security->isValidUserID($this->kelas->CurrentValue);
            if (!$validUser) {
                $userIdMsg = str_replace("%c", CurrentUserID(), $Language->phrase("UnAuthorizedUserID"));
                $userIdMsg = str_replace("%u", $this->kelas->CurrentValue, $userIdMsg);
                $this->setFailureMessage($userIdMsg);
                return false;
            }
        }

        // Check if valid key values for master user
        if ($Security->currentUserID() != "" && !$Security->isAdmin()) { // Non system admin
            $masterFilter = $this->sqlMasterFilter_penilaian();
            if (strval($this->penilaian_id->CurrentValue) != "") {
                $masterFilter = str_replace("@penilaian_id@", AdjustSql($this->penilaian_id->CurrentValue, "DB"), $masterFilter);
            } else {
                $masterFilter = "";
            }
            if ($masterFilter != "") {
                $rsmaster = Container("penilaian")->loadRs($masterFilter)->fetch(\PDO::FETCH_ASSOC);
                $masterRecordExists = $rsmaster !== false;
                $validMasterKey = true;
                if ($masterRecordExists) {
                    $validMasterKey = $Security->isValidUserID($rsmaster['kelas']);
                } elseif ($this->getCurrentMasterTable() == "penilaian") {
                    $validMasterKey = false;
                }
                if (!$validMasterKey) {
                    $masterUserIdMsg = str_replace("%c", CurrentUserID(), $Language->phrase("UnAuthorizedMasterUserID"));
                    $masterUserIdMsg = str_replace("%f", $masterFilter, $masterUserIdMsg);
                    $this->setFailureMessage($masterUserIdMsg);
                    return false;
                }
            }
        }

        // Set up foreign key field value from Session
        if ($this->getCurrentMasterTable() == "penilaian") {
            $this->penilaian_id->CurrentValue = $this->penilaian_id->getSessionValue();
        }
        $conn = $this->getConnection();

        // Load db values from rsold
        $this->loadDbValues($rsold);
        if ($rsold) {
        }
        $rsnew = [];

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        // penilaian_id
        if ($this->penilaian_id->getSessionValue() != "") {
            $rsnew['penilaian_id'] = $this->penilaian_id->getSessionValue();
        }

        // Call Row Inserting event
        $insertRow = $this->rowInserting($rsold, $rsnew);
        $addRow = false;
        if ($insertRow) {
            try {
                $addRow = $this->insert($rsnew);
            } catch (\Exception $e) {
                $this->setFailureMessage($e->getMessage());
            }
            if ($addRow) {
            }
        } 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("InsertCancelled"));
            }
            $addRow = false;
        }
        if ($addRow) {
            // Call Row Inserted event
            $this->rowInserted($rsold, $rsnew);
        }

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

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

    // 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 master/detail based on QueryString
    protected function setupMasterParms()
    {
        // Hide foreign keys
        $masterTblVar = $this->getCurrentMasterTable();
        if ($masterTblVar == "penilaian") {
            $masterTbl = Container("penilaian");
            $this->penilaian_id->Visible = false;
            if ($masterTbl->EventCancelled) {
                $this->EventCancelled = true;
            }
        }
        $this->DbMasterFilter = $this->getMasterFilter(); // Get master filter
        $this->DbDetailFilter = $this->getDetailFilter(); // Get detail filter
    }

    // 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) {
                case "x_kode_mapel":
                    break;
                case "x_kelas":
                    $lookupFilter = function () {
                        return "`kode_tapel`='".kode_tapel()."'";
                    };
                    $lookupFilter = $lookupFilter->bindTo($this);
                    break;
                default:
                    $lookupFilter = "";
                    break;
            }

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

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

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

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

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

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

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

    // Page Data Rendering event
    public function pageDataRendering(&$header)
    {
        // Example:
         include "tool/petunjuk.php";
        //$header = ' <button id="reloadButton" class="btn btn-primary" onclick="location.reload();">Reload</button>';
    }

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

    // ListOptions Load event
    public function listOptionsLoad()
    {
        // Example:
        //$opt = &$this->ListOptions->Add("new");
        //$opt->Header = "xxx";
        //$opt->OnLeft = true; // Link on left
        //$opt->MoveTo(0); // Move to first column
    }

    // ListOptions Rendering event
    public function listOptionsRendering()
    {
        //Container("DetailTableGrid")->DetailAdd = (...condition...); // Set to true or false conditionally
        //Container("DetailTableGrid")->DetailEdit = (...condition...); // Set to true or false conditionally
        //Container("DetailTableGrid")->DetailView = (...condition...); // Set to true or false conditionally
    }

    // ListOptions Rendered event
    public function listOptionsRendered()
    {
        // Example:
        //$this->ListOptions["new"]->Body = "xxx";
    }
}
