<?php

namespace PHPMaker2021\rdigital21;

use Doctrine\DBAL\ParameterType;

/**
 * Page class
 */
class ExtraAbsensiList extends ExtraAbsensi
{
    use MessagesTrait;

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

    // Project ID
    public $ProjectID = PROJECT_ID;

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

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

    // Rendering View
    public $RenderingView = false;

    // Grid form hidden field names
    public $FormName = "fextra_absensilist";
    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;

    // Export URLs
    public $ExportPrintUrl;
    public $ExportHtmlUrl;
    public $ExportExcelUrl;
    public $ExportWordUrl;
    public $ExportXmlUrl;
    public $ExportCsvUrl;
    public $ExportPdfUrl;

    // Custom export
    public $ExportExcelCustom = false;
    public $ExportWordCustom = false;
    public $ExportPdfCustom = false;
    public $ExportEmailCustom = false;

    // Update URLs
    public $InlineAddUrl;
    public $InlineCopyUrl;
    public $InlineEditUrl;
    public $GridAddUrl;
    public $GridEditUrl;
    public $MultiDeleteUrl;
    public $MultiUpdateUrl;

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

    // Page terminated
    private $terminated = false;

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

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

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

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

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

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

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

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

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

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

        // Parent constuctor
        parent::__construct();

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

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

        // Initialize URLs
        $this->ExportPrintUrl = $pageUrl . "export=print";
        $this->ExportExcelUrl = $pageUrl . "export=excel";
        $this->ExportWordUrl = $pageUrl . "export=word";
        $this->ExportPdfUrl = $pageUrl . "export=pdf";
        $this->ExportHtmlUrl = $pageUrl . "export=html";
        $this->ExportXmlUrl = $pageUrl . "export=xml";
        $this->ExportCsvUrl = $pageUrl . "export=csv";
        $this->AddUrl = "ExtraAbsensiAdd";
        $this->InlineAddUrl = $pageUrl . "action=add";
        $this->GridAddUrl = $pageUrl . "action=gridadd";
        $this->GridEditUrl = $pageUrl . "action=gridedit";
        $this->MultiDeleteUrl = "ExtraAbsensiDelete";
        $this->MultiUpdateUrl = "ExtraAbsensiUpdate";

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

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

        // Export options
        $this->ExportOptions = new ListOptions("div");
        $this->ExportOptions->TagClassName = "ew-export-option";

        // Import options
        $this->ImportOptions = new ListOptions("div");
        $this->ImportOptions->TagClassName = "ew-import-option";

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

        // Filter options
        $this->FilterOptions = new ListOptions("div");
        $this->FilterOptions->TagClassName = "ew-filter-option fextra_absensilistsrch";

        // List actions
        $this->ListActions = new ListActions();
    }

    // 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;
        global $OldSkipHeaderFooter, $SkipHeaderFooter;
        $SkipHeaderFooter = $OldSkipHeaderFooter;

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

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

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

        // Close connection
        CloseConnections();

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

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

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

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

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

    /**
     * Hide fields for add/edit
     *
     * @return void
     */
    protected function hideFieldsForAddEdit()
    {
        if ($this->isAdd() || $this->isCopy() || $this->isGridAdd()) {
            $this->absen_id->Visible = false;
        }
        if ($this->isAddOrEdit()) {
            $this->kode_tapel->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 $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;

        // Create form object
        $CurrentForm = new HttpForm();

        // Get export parameters
        $custom = "";
        if (Param("export") !== null) {
            $this->Export = Param("export");
            $custom = Param("custom", "");
        } elseif (IsPost()) {
            if (Post("exporttype") !== null) {
                $this->Export = Post("exporttype");
            }
            $custom = Post("custom", "");
        } elseif (Get("cmd") == "json") {
            $this->Export = Get("cmd");
        } else {
            $this->setExportReturnUrl(CurrentUrl());
        }
        $ExportFileName = $this->TableVar; // Get export file, used in header

        // Get custom export parameters
        if ($this->isExport() && $custom != "") {
            $this->CustomExport = $this->Export;
            $this->Export = "print";
        }
        $CustomExportType = $this->CustomExport;
        $ExportType = $this->Export; // Get export parameter, used in header

        // Update Export URLs
        if (Config("USE_PHPEXCEL")) {
            $this->ExportExcelCustom = false;
        }
        if (Config("USE_PHPWORD")) {
            $this->ExportWordCustom = false;
        }
        if ($this->ExportExcelCustom) {
            $this->ExportExcelUrl .= "&amp;custom=1";
        }
        if ($this->ExportWordCustom) {
            $this->ExportWordUrl .= "&amp;custom=1";
        }
        if ($this->ExportPdfCustom) {
            $this->ExportPdfUrl .= "&amp;custom=1";
        }
        $this->CurrentAction = Param("action"); // Set up current action

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

        // Setup export options
        $this->setupExportOptions();
        global $OldSkipHeaderFooter, $SkipHeaderFooter;
        $OldSkipHeaderFooter = $SkipHeaderFooter;
        $SkipHeaderFooter = true;
        $this->absen_id->Visible = false;
        $this->kode_tapel->setVisibility();
        $this->kelas->setVisibility();
        $this->nisn->setVisibility();
        $this->nis->setVisibility();
        $this->nama->setVisibility();
        $this->jk->setVisibility();
        $this->s->setVisibility();
        $this->_i->setVisibility();
        $this->a->setVisibility();
        $this->ekstra1->setVisibility();
        $this->deskripsi1->setVisibility();
        $this->ekstra2->setVisibility();
        $this->deskripsi2->setVisibility();
        $this->ekstra3->setVisibility();
        $this->deskripsi3->setVisibility();
        $this->ekstra4->setVisibility();
        $this->deskripsi4->setVisibility();
        $this->catatan_siswa->Visible = false;
        $this->hideFieldsForAddEdit();

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

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

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

        // Set up custom action (compatible with old version)
        foreach ($this->CustomActions as $name => $action) {
            $this->ListActions->add($name, $action);
        }

        // Show checkbox column if multiple action
        foreach ($this->ListActions->Items as $listaction) {
            if ($listaction->Select == ACTION_MULTIPLE && $listaction->Allow) {
                $this->ListOptions["checkbox"]->Visible = true;
                break;
            }
        }

        // Set up lookup cache
        $this->setupLookupOptions($this->ekstra1);
        $this->setupLookupOptions($this->ekstra2);
        $this->setupLookupOptions($this->ekstra3);
        $this->setupLookupOptions($this->ekstra4);

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

        // Get command
        $this->Command = strtolower(Get("cmd"));
        if ($this->isPageRequest()) {
            // Process list action first
            if ($this->processListAction()) { // Ajax request
                $this->terminate();
                return;
            }

            // Set up records per page
            $this->setupDisplayRecords();

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

            // Set up Breadcrumb
            if (!$this->isExport()) {
                $this->setupBreadcrumb();
            }

            // Check QueryString parameters
            if (Get("action") !== null) {
                $this->CurrentAction = Get("action");

                // Clear inline mode
                if ($this->isCancel()) {
                    $this->clearInlineMode();
                }

                // Switch to grid edit mode
                if ($this->isGridEdit()) {
                    $this->gridEditMode();
                }
            } else {
                if (Post("action") !== null) {
                    $this->CurrentAction = Post("action"); // Get action

                    // Grid Update
                    if (($this->isGridUpdate() || $this->isGridOverwrite()) && Session(SESSION_INLINE_MODE) == "gridedit") {
                        if ($this->validateGridForm()) {
                            $gridUpdate = $this->gridUpdate();
                        } else {
                            $gridUpdate = false;
                        }
                        if ($gridUpdate) {
                        } else {
                            $this->EventCancelled = true;
                            $this->gridEditMode(); // Stay in Grid edit mode
                        }
                    }
                } elseif (Session(SESSION_INLINE_MODE) == "gridedit") { // Previously in grid edit mode
                    if (Get(Config("TABLE_START_REC")) !== null || Get(Config("TABLE_PAGE_NO")) !== null) { // Stay in grid edit mode if paging
                        $this->gridEditMode();
                    } else { // Reset grid edit
                        $this->clearInlineMode();
                    }
                }
            }

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

            // Hide options
            if ($this->isExport() || $this->CurrentAction) {
                $this->ExportOptions->hideAllOptions();
                $this->FilterOptions->hideAllOptions();
                $this->ImportOptions->hideAllOptions();
            }

            // Hide other options
            if ($this->isExport()) {
                $this->OtherOptions->hideAllOptions();
            }

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

            // Get default search criteria
            AddFilter($this->DefaultSearchWhere, $this->basicSearchWhere(true));
            AddFilter($this->DefaultSearchWhere, $this->advancedSearchWhere(true));

            // Get basic search values
            $this->loadBasicSearchValues();

            // Get and validate search values for advanced search
            $this->loadSearchValues(); // Get search values

            // Process filter list
            if ($this->processFilterList()) {
                $this->terminate();
                return;
            }
            if (!$this->validateSearch()) {
                // Nothing to do
            }

            // Restore search parms from Session if not searching / reset / export
            if (($this->isExport() || $this->Command != "search" && $this->Command != "reset" && $this->Command != "resetall") && $this->Command != "json" && $this->checkSearchParms()) {
                $this->restoreSearchParms();
            }

            // Call Recordset SearchValidated event
            $this->recordsetSearchValidated();

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

            // Get basic search criteria
            if (!$this->hasInvalidFields()) {
                $srchBasic = $this->basicSearchWhere();
            }

            // Get search criteria for advanced search
            if (!$this->hasInvalidFields()) {
                $srchAdvanced = $this->advancedSearchWhere();
            }
        }

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

        // Load search default if no existing search criteria
        if (!$this->checkSearchParms()) {
            // Load basic search from default
            $this->BasicSearch->loadDefault();
            if ($this->BasicSearch->Keyword != "") {
                $srchBasic = $this->basicSearchWhere();
            }

            // Load advanced search from default
            if ($this->loadAdvancedSearchDefault()) {
                $srchAdvanced = $this->advancedSearchWhere();
            }
        }

        // Restore search settings from Session
        if (!$this->hasInvalidFields()) {
            $this->loadAdvancedSearch();
        }

        // Build search criteria
        AddFilter($this->SearchWhere, $srchAdvanced);
        AddFilter($this->SearchWhere, $srchBasic);

        // Call Recordset_Searching event
        $this->recordsetSearching($this->SearchWhere);

        // Save search criteria
        if ($this->Command == "search" && !$this->RestoreSearch) {
            $this->setSearchWhere($this->SearchWhere); // Save to Session
            $this->StartRecord = 1; // Reset start record counter
            $this->setStartRecordNumber($this->StartRecord);
        } elseif ($this->Command != "json") {
            $this->SearchWhere = $this->getSearchWhere();
        }

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

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

        // Export data only
        if (!$this->CustomExport && in_array($this->Export, array_keys(Config("EXPORT_CLASSES")))) {
            $this->exportData();
            $this->terminate();
            return;
        }
        if ($this->isGridAdd()) {
            $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;
            if ($this->DisplayRecords <= 0 || ($this->isExport() && $this->ExportAll)) { // Display all records
                $this->DisplayRecords = $this->TotalRecords;
            }
            if (!($this->isExport() && $this->ExportAll)) { // Set up start record position
                $this->setupStartRecord();
            }
            $this->Recordset = $this->loadRecordset($this->StartRecord - 1, $this->DisplayRecords);

            // Set no record found message
            if (!$this->CurrentAction && $this->TotalRecords == 0) {
                if (!$Security->canList()) {
                    $this->setWarningMessage(DeniedMessage());
                }
                if ($this->SearchWhere == "0=101") {
                    $this->setWarningMessage($Language->phrase("EnterSearchCriteria"));
                } else {
                    $this->setWarningMessage($Language->phrase("NoRecord"));
                }
            }
        }

        // Search options
        $this->setupSearchOptions();

        // Set up search panel class
        if ($this->SearchWhere != "") {
            AppendClass($this->SearchPanelClass, "show");
        }

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

        // Begin transaction
        $conn->beginTransaction();
        $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) {
            $conn->commit(); // Commit transaction

            // Get new records
            $rsnew = $conn->fetchAll($sql);

            // Call Grid_Updated event
            $this->gridUpdated($rsold, $rsnew);
            if ($this->getSuccessMessage() == "") {
                $this->setSuccessMessage($Language->phrase("UpdateSuccess")); // Set up update success message
            }
            $this->clearInlineMode(); // Clear inline edit mode
        } else {
            $conn->rollback(); // Rollback transaction
            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;
    }

    // Check if empty row
    public function emptyRow()
    {
        global $CurrentForm;
        if ($CurrentForm->hasValue("x_kelas") && $CurrentForm->hasValue("o_kelas") && $this->kelas->CurrentValue != $this->kelas->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_nisn") && $CurrentForm->hasValue("o_nisn") && $this->nisn->CurrentValue != $this->nisn->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_nis") && $CurrentForm->hasValue("o_nis") && $this->nis->CurrentValue != $this->nis->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_s") && $CurrentForm->hasValue("o_s") && $this->s->CurrentValue != $this->s->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x__i") && $CurrentForm->hasValue("o__i") && $this->_i->CurrentValue != $this->_i->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_a") && $CurrentForm->hasValue("o_a") && $this->a->CurrentValue != $this->a->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_ekstra1") && $CurrentForm->hasValue("o_ekstra1") && $this->ekstra1->CurrentValue != $this->ekstra1->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_deskripsi1") && $CurrentForm->hasValue("o_deskripsi1") && $this->deskripsi1->CurrentValue != $this->deskripsi1->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_ekstra2") && $CurrentForm->hasValue("o_ekstra2") && $this->ekstra2->CurrentValue != $this->ekstra2->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_deskripsi2") && $CurrentForm->hasValue("o_deskripsi2") && $this->deskripsi2->CurrentValue != $this->deskripsi2->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_ekstra3") && $CurrentForm->hasValue("o_ekstra3") && $this->ekstra3->CurrentValue != $this->ekstra3->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_deskripsi3") && $CurrentForm->hasValue("o_deskripsi3") && $this->deskripsi3->CurrentValue != $this->deskripsi3->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_ekstra4") && $CurrentForm->hasValue("o_ekstra4") && $this->ekstra4->CurrentValue != $this->ekstra4->OldValue) {
            return false;
        }
        if ($CurrentForm->hasValue("x_deskripsi4") && $CurrentForm->hasValue("o_deskripsi4") && $this->deskripsi4->CurrentValue != $this->deskripsi4->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->kode_tapel->clearErrorMessage();
        $this->kelas->clearErrorMessage();
        $this->nisn->clearErrorMessage();
        $this->nis->clearErrorMessage();
        $this->nama->clearErrorMessage();
        $this->jk->clearErrorMessage();
        $this->s->clearErrorMessage();
        $this->_i->clearErrorMessage();
        $this->a->clearErrorMessage();
        $this->ekstra1->clearErrorMessage();
        $this->deskripsi1->clearErrorMessage();
        $this->ekstra2->clearErrorMessage();
        $this->deskripsi2->clearErrorMessage();
        $this->ekstra3->clearErrorMessage();
        $this->deskripsi3->clearErrorMessage();
        $this->ekstra4->clearErrorMessage();
        $this->deskripsi4->clearErrorMessage();
    }

    // Get list of filters
    public function getFilterList()
    {
        global $UserProfile;

        // Initialize
        $filterList = "";
        $savedFilterList = "";
        $filterList = Concat($filterList, $this->absen_id->AdvancedSearch->toJson(), ","); // Field absen_id
        $filterList = Concat($filterList, $this->kode_tapel->AdvancedSearch->toJson(), ","); // Field kode_tapel
        $filterList = Concat($filterList, $this->kelas->AdvancedSearch->toJson(), ","); // Field kelas
        $filterList = Concat($filterList, $this->nisn->AdvancedSearch->toJson(), ","); // Field nisn
        $filterList = Concat($filterList, $this->nis->AdvancedSearch->toJson(), ","); // Field nis
        $filterList = Concat($filterList, $this->nama->AdvancedSearch->toJson(), ","); // Field nama
        $filterList = Concat($filterList, $this->jk->AdvancedSearch->toJson(), ","); // Field jk
        $filterList = Concat($filterList, $this->s->AdvancedSearch->toJson(), ","); // Field s
        $filterList = Concat($filterList, $this->_i->AdvancedSearch->toJson(), ","); // Field i
        $filterList = Concat($filterList, $this->a->AdvancedSearch->toJson(), ","); // Field a
        $filterList = Concat($filterList, $this->ekstra1->AdvancedSearch->toJson(), ","); // Field ekstra1
        $filterList = Concat($filterList, $this->deskripsi1->AdvancedSearch->toJson(), ","); // Field deskripsi1
        $filterList = Concat($filterList, $this->ekstra2->AdvancedSearch->toJson(), ","); // Field ekstra2
        $filterList = Concat($filterList, $this->deskripsi2->AdvancedSearch->toJson(), ","); // Field deskripsi2
        $filterList = Concat($filterList, $this->ekstra3->AdvancedSearch->toJson(), ","); // Field ekstra3
        $filterList = Concat($filterList, $this->deskripsi3->AdvancedSearch->toJson(), ","); // Field deskripsi3
        $filterList = Concat($filterList, $this->ekstra4->AdvancedSearch->toJson(), ","); // Field ekstra4
        $filterList = Concat($filterList, $this->deskripsi4->AdvancedSearch->toJson(), ","); // Field deskripsi4
        $filterList = Concat($filterList, $this->catatan_siswa->AdvancedSearch->toJson(), ","); // Field catatan_siswa
        if ($this->BasicSearch->Keyword != "") {
            $wrk = "\"" . Config("TABLE_BASIC_SEARCH") . "\":\"" . JsEncode($this->BasicSearch->Keyword) . "\",\"" . Config("TABLE_BASIC_SEARCH_TYPE") . "\":\"" . JsEncode($this->BasicSearch->Type) . "\"";
            $filterList = Concat($filterList, $wrk, ",");
        }

        // Return filter list in JSON
        if ($filterList != "") {
            $filterList = "\"data\":{" . $filterList . "}";
        }
        if ($savedFilterList != "") {
            $filterList = Concat($filterList, "\"filters\":" . $savedFilterList, ",");
        }
        return ($filterList != "") ? "{" . $filterList . "}" : "null";
    }

    // Process filter list
    protected function processFilterList()
    {
        global $UserProfile;
        if (Post("ajax") == "savefilters") { // Save filter request (Ajax)
            $filters = Post("filters");
            $UserProfile->setSearchFilters(CurrentUserName(), "fextra_absensilistsrch", $filters);
            WriteJson([["success" => true]]); // Success
            return true;
        } elseif (Post("cmd") == "resetfilter") {
            $this->restoreFilterList();
        }
        return false;
    }

    // Restore list of filters
    protected function restoreFilterList()
    {
        // Return if not reset filter
        if (Post("cmd") !== "resetfilter") {
            return false;
        }
        $filter = json_decode(Post("filter"), true);
        $this->Command = "search";

        // Field absen_id
        $this->absen_id->AdvancedSearch->SearchValue = @$filter["x_absen_id"];
        $this->absen_id->AdvancedSearch->SearchOperator = @$filter["z_absen_id"];
        $this->absen_id->AdvancedSearch->SearchCondition = @$filter["v_absen_id"];
        $this->absen_id->AdvancedSearch->SearchValue2 = @$filter["y_absen_id"];
        $this->absen_id->AdvancedSearch->SearchOperator2 = @$filter["w_absen_id"];
        $this->absen_id->AdvancedSearch->save();

        // Field kode_tapel
        $this->kode_tapel->AdvancedSearch->SearchValue = @$filter["x_kode_tapel"];
        $this->kode_tapel->AdvancedSearch->SearchOperator = @$filter["z_kode_tapel"];
        $this->kode_tapel->AdvancedSearch->SearchCondition = @$filter["v_kode_tapel"];
        $this->kode_tapel->AdvancedSearch->SearchValue2 = @$filter["y_kode_tapel"];
        $this->kode_tapel->AdvancedSearch->SearchOperator2 = @$filter["w_kode_tapel"];
        $this->kode_tapel->AdvancedSearch->save();

        // Field kelas
        $this->kelas->AdvancedSearch->SearchValue = @$filter["x_kelas"];
        $this->kelas->AdvancedSearch->SearchOperator = @$filter["z_kelas"];
        $this->kelas->AdvancedSearch->SearchCondition = @$filter["v_kelas"];
        $this->kelas->AdvancedSearch->SearchValue2 = @$filter["y_kelas"];
        $this->kelas->AdvancedSearch->SearchOperator2 = @$filter["w_kelas"];
        $this->kelas->AdvancedSearch->save();

        // Field nisn
        $this->nisn->AdvancedSearch->SearchValue = @$filter["x_nisn"];
        $this->nisn->AdvancedSearch->SearchOperator = @$filter["z_nisn"];
        $this->nisn->AdvancedSearch->SearchCondition = @$filter["v_nisn"];
        $this->nisn->AdvancedSearch->SearchValue2 = @$filter["y_nisn"];
        $this->nisn->AdvancedSearch->SearchOperator2 = @$filter["w_nisn"];
        $this->nisn->AdvancedSearch->save();

        // Field nis
        $this->nis->AdvancedSearch->SearchValue = @$filter["x_nis"];
        $this->nis->AdvancedSearch->SearchOperator = @$filter["z_nis"];
        $this->nis->AdvancedSearch->SearchCondition = @$filter["v_nis"];
        $this->nis->AdvancedSearch->SearchValue2 = @$filter["y_nis"];
        $this->nis->AdvancedSearch->SearchOperator2 = @$filter["w_nis"];
        $this->nis->AdvancedSearch->save();

        // Field nama
        $this->nama->AdvancedSearch->SearchValue = @$filter["x_nama"];
        $this->nama->AdvancedSearch->SearchOperator = @$filter["z_nama"];
        $this->nama->AdvancedSearch->SearchCondition = @$filter["v_nama"];
        $this->nama->AdvancedSearch->SearchValue2 = @$filter["y_nama"];
        $this->nama->AdvancedSearch->SearchOperator2 = @$filter["w_nama"];
        $this->nama->AdvancedSearch->save();

        // Field jk
        $this->jk->AdvancedSearch->SearchValue = @$filter["x_jk"];
        $this->jk->AdvancedSearch->SearchOperator = @$filter["z_jk"];
        $this->jk->AdvancedSearch->SearchCondition = @$filter["v_jk"];
        $this->jk->AdvancedSearch->SearchValue2 = @$filter["y_jk"];
        $this->jk->AdvancedSearch->SearchOperator2 = @$filter["w_jk"];
        $this->jk->AdvancedSearch->save();

        // Field s
        $this->s->AdvancedSearch->SearchValue = @$filter["x_s"];
        $this->s->AdvancedSearch->SearchOperator = @$filter["z_s"];
        $this->s->AdvancedSearch->SearchCondition = @$filter["v_s"];
        $this->s->AdvancedSearch->SearchValue2 = @$filter["y_s"];
        $this->s->AdvancedSearch->SearchOperator2 = @$filter["w_s"];
        $this->s->AdvancedSearch->save();

        // Field i
        $this->_i->AdvancedSearch->SearchValue = @$filter["x__i"];
        $this->_i->AdvancedSearch->SearchOperator = @$filter["z__i"];
        $this->_i->AdvancedSearch->SearchCondition = @$filter["v__i"];
        $this->_i->AdvancedSearch->SearchValue2 = @$filter["y__i"];
        $this->_i->AdvancedSearch->SearchOperator2 = @$filter["w__i"];
        $this->_i->AdvancedSearch->save();

        // Field a
        $this->a->AdvancedSearch->SearchValue = @$filter["x_a"];
        $this->a->AdvancedSearch->SearchOperator = @$filter["z_a"];
        $this->a->AdvancedSearch->SearchCondition = @$filter["v_a"];
        $this->a->AdvancedSearch->SearchValue2 = @$filter["y_a"];
        $this->a->AdvancedSearch->SearchOperator2 = @$filter["w_a"];
        $this->a->AdvancedSearch->save();

        // Field ekstra1
        $this->ekstra1->AdvancedSearch->SearchValue = @$filter["x_ekstra1"];
        $this->ekstra1->AdvancedSearch->SearchOperator = @$filter["z_ekstra1"];
        $this->ekstra1->AdvancedSearch->SearchCondition = @$filter["v_ekstra1"];
        $this->ekstra1->AdvancedSearch->SearchValue2 = @$filter["y_ekstra1"];
        $this->ekstra1->AdvancedSearch->SearchOperator2 = @$filter["w_ekstra1"];
        $this->ekstra1->AdvancedSearch->save();

        // Field deskripsi1
        $this->deskripsi1->AdvancedSearch->SearchValue = @$filter["x_deskripsi1"];
        $this->deskripsi1->AdvancedSearch->SearchOperator = @$filter["z_deskripsi1"];
        $this->deskripsi1->AdvancedSearch->SearchCondition = @$filter["v_deskripsi1"];
        $this->deskripsi1->AdvancedSearch->SearchValue2 = @$filter["y_deskripsi1"];
        $this->deskripsi1->AdvancedSearch->SearchOperator2 = @$filter["w_deskripsi1"];
        $this->deskripsi1->AdvancedSearch->save();

        // Field ekstra2
        $this->ekstra2->AdvancedSearch->SearchValue = @$filter["x_ekstra2"];
        $this->ekstra2->AdvancedSearch->SearchOperator = @$filter["z_ekstra2"];
        $this->ekstra2->AdvancedSearch->SearchCondition = @$filter["v_ekstra2"];
        $this->ekstra2->AdvancedSearch->SearchValue2 = @$filter["y_ekstra2"];
        $this->ekstra2->AdvancedSearch->SearchOperator2 = @$filter["w_ekstra2"];
        $this->ekstra2->AdvancedSearch->save();

        // Field deskripsi2
        $this->deskripsi2->AdvancedSearch->SearchValue = @$filter["x_deskripsi2"];
        $this->deskripsi2->AdvancedSearch->SearchOperator = @$filter["z_deskripsi2"];
        $this->deskripsi2->AdvancedSearch->SearchCondition = @$filter["v_deskripsi2"];
        $this->deskripsi2->AdvancedSearch->SearchValue2 = @$filter["y_deskripsi2"];
        $this->deskripsi2->AdvancedSearch->SearchOperator2 = @$filter["w_deskripsi2"];
        $this->deskripsi2->AdvancedSearch->save();

        // Field ekstra3
        $this->ekstra3->AdvancedSearch->SearchValue = @$filter["x_ekstra3"];
        $this->ekstra3->AdvancedSearch->SearchOperator = @$filter["z_ekstra3"];
        $this->ekstra3->AdvancedSearch->SearchCondition = @$filter["v_ekstra3"];
        $this->ekstra3->AdvancedSearch->SearchValue2 = @$filter["y_ekstra3"];
        $this->ekstra3->AdvancedSearch->SearchOperator2 = @$filter["w_ekstra3"];
        $this->ekstra3->AdvancedSearch->save();

        // Field deskripsi3
        $this->deskripsi3->AdvancedSearch->SearchValue = @$filter["x_deskripsi3"];
        $this->deskripsi3->AdvancedSearch->SearchOperator = @$filter["z_deskripsi3"];
        $this->deskripsi3->AdvancedSearch->SearchCondition = @$filter["v_deskripsi3"];
        $this->deskripsi3->AdvancedSearch->SearchValue2 = @$filter["y_deskripsi3"];
        $this->deskripsi3->AdvancedSearch->SearchOperator2 = @$filter["w_deskripsi3"];
        $this->deskripsi3->AdvancedSearch->save();

        // Field ekstra4
        $this->ekstra4->AdvancedSearch->SearchValue = @$filter["x_ekstra4"];
        $this->ekstra4->AdvancedSearch->SearchOperator = @$filter["z_ekstra4"];
        $this->ekstra4->AdvancedSearch->SearchCondition = @$filter["v_ekstra4"];
        $this->ekstra4->AdvancedSearch->SearchValue2 = @$filter["y_ekstra4"];
        $this->ekstra4->AdvancedSearch->SearchOperator2 = @$filter["w_ekstra4"];
        $this->ekstra4->AdvancedSearch->save();

        // Field deskripsi4
        $this->deskripsi4->AdvancedSearch->SearchValue = @$filter["x_deskripsi4"];
        $this->deskripsi4->AdvancedSearch->SearchOperator = @$filter["z_deskripsi4"];
        $this->deskripsi4->AdvancedSearch->SearchCondition = @$filter["v_deskripsi4"];
        $this->deskripsi4->AdvancedSearch->SearchValue2 = @$filter["y_deskripsi4"];
        $this->deskripsi4->AdvancedSearch->SearchOperator2 = @$filter["w_deskripsi4"];
        $this->deskripsi4->AdvancedSearch->save();

        // Field catatan_siswa
        $this->catatan_siswa->AdvancedSearch->SearchValue = @$filter["x_catatan_siswa"];
        $this->catatan_siswa->AdvancedSearch->SearchOperator = @$filter["z_catatan_siswa"];
        $this->catatan_siswa->AdvancedSearch->SearchCondition = @$filter["v_catatan_siswa"];
        $this->catatan_siswa->AdvancedSearch->SearchValue2 = @$filter["y_catatan_siswa"];
        $this->catatan_siswa->AdvancedSearch->SearchOperator2 = @$filter["w_catatan_siswa"];
        $this->catatan_siswa->AdvancedSearch->save();
        $this->BasicSearch->setKeyword(@$filter[Config("TABLE_BASIC_SEARCH")]);
        $this->BasicSearch->setType(@$filter[Config("TABLE_BASIC_SEARCH_TYPE")]);
    }

    // Advanced search WHERE clause based on QueryString
    protected function advancedSearchWhere($default = false)
    {
        global $Security;
        $where = "";
        if (!$Security->canSearch()) {
            return "";
        }
        $this->buildSearchSql($where, $this->absen_id, $default, false); // absen_id
        $this->buildSearchSql($where, $this->kode_tapel, $default, false); // kode_tapel
        $this->buildSearchSql($where, $this->kelas, $default, false); // kelas
        $this->buildSearchSql($where, $this->nisn, $default, false); // nisn
        $this->buildSearchSql($where, $this->nis, $default, false); // nis
        $this->buildSearchSql($where, $this->nama, $default, false); // nama
        $this->buildSearchSql($where, $this->jk, $default, false); // jk
        $this->buildSearchSql($where, $this->s, $default, false); // s
        $this->buildSearchSql($where, $this->_i, $default, false); // i
        $this->buildSearchSql($where, $this->a, $default, false); // a
        $this->buildSearchSql($where, $this->ekstra1, $default, false); // ekstra1
        $this->buildSearchSql($where, $this->deskripsi1, $default, false); // deskripsi1
        $this->buildSearchSql($where, $this->ekstra2, $default, false); // ekstra2
        $this->buildSearchSql($where, $this->deskripsi2, $default, false); // deskripsi2
        $this->buildSearchSql($where, $this->ekstra3, $default, false); // ekstra3
        $this->buildSearchSql($where, $this->deskripsi3, $default, false); // deskripsi3
        $this->buildSearchSql($where, $this->ekstra4, $default, false); // ekstra4
        $this->buildSearchSql($where, $this->deskripsi4, $default, false); // deskripsi4
        $this->buildSearchSql($where, $this->catatan_siswa, $default, false); // catatan_siswa

        // Set up search parm
        if (!$default && $where != "" && in_array($this->Command, ["", "reset", "resetall"])) {
            $this->Command = "search";
        }
        if (!$default && $this->Command == "search") {
            $this->absen_id->AdvancedSearch->save(); // absen_id
            $this->kode_tapel->AdvancedSearch->save(); // kode_tapel
            $this->kelas->AdvancedSearch->save(); // kelas
            $this->nisn->AdvancedSearch->save(); // nisn
            $this->nis->AdvancedSearch->save(); // nis
            $this->nama->AdvancedSearch->save(); // nama
            $this->jk->AdvancedSearch->save(); // jk
            $this->s->AdvancedSearch->save(); // s
            $this->_i->AdvancedSearch->save(); // i
            $this->a->AdvancedSearch->save(); // a
            $this->ekstra1->AdvancedSearch->save(); // ekstra1
            $this->deskripsi1->AdvancedSearch->save(); // deskripsi1
            $this->ekstra2->AdvancedSearch->save(); // ekstra2
            $this->deskripsi2->AdvancedSearch->save(); // deskripsi2
            $this->ekstra3->AdvancedSearch->save(); // ekstra3
            $this->deskripsi3->AdvancedSearch->save(); // deskripsi3
            $this->ekstra4->AdvancedSearch->save(); // ekstra4
            $this->deskripsi4->AdvancedSearch->save(); // deskripsi4
            $this->catatan_siswa->AdvancedSearch->save(); // catatan_siswa
        }
        return $where;
    }

    // Build search SQL
    protected function buildSearchSql(&$where, &$fld, $default, $multiValue)
    {
        $fldParm = $fld->Param;
        $fldVal = ($default) ? $fld->AdvancedSearch->SearchValueDefault : $fld->AdvancedSearch->SearchValue;
        $fldOpr = ($default) ? $fld->AdvancedSearch->SearchOperatorDefault : $fld->AdvancedSearch->SearchOperator;
        $fldCond = ($default) ? $fld->AdvancedSearch->SearchConditionDefault : $fld->AdvancedSearch->SearchCondition;
        $fldVal2 = ($default) ? $fld->AdvancedSearch->SearchValue2Default : $fld->AdvancedSearch->SearchValue2;
        $fldOpr2 = ($default) ? $fld->AdvancedSearch->SearchOperator2Default : $fld->AdvancedSearch->SearchOperator2;
        $wrk = "";
        if (is_array($fldVal)) {
            $fldVal = implode(Config("MULTIPLE_OPTION_SEPARATOR"), $fldVal);
        }
        if (is_array($fldVal2)) {
            $fldVal2 = implode(Config("MULTIPLE_OPTION_SEPARATOR"), $fldVal2);
        }
        $fldOpr = strtoupper(trim($fldOpr));
        if ($fldOpr == "") {
            $fldOpr = "=";
        }
        $fldOpr2 = strtoupper(trim($fldOpr2));
        if ($fldOpr2 == "") {
            $fldOpr2 = "=";
        }
        if (Config("SEARCH_MULTI_VALUE_OPTION") == 1 || !IsMultiSearchOperator($fldOpr)) {
            $multiValue = false;
        }
        if ($multiValue) {
            $wrk1 = ($fldVal != "") ? GetMultiSearchSql($fld, $fldOpr, $fldVal, $this->Dbid) : ""; // Field value 1
            $wrk2 = ($fldVal2 != "") ? GetMultiSearchSql($fld, $fldOpr2, $fldVal2, $this->Dbid) : ""; // Field value 2
            $wrk = $wrk1; // Build final SQL
            if ($wrk2 != "") {
                $wrk = ($wrk != "") ? "($wrk) $fldCond ($wrk2)" : $wrk2;
            }
        } else {
            $fldVal = $this->convertSearchValue($fld, $fldVal);
            $fldVal2 = $this->convertSearchValue($fld, $fldVal2);
            $wrk = GetSearchSql($fld, $fldVal, $fldOpr, $fldCond, $fldVal2, $fldOpr2, $this->Dbid);
        }
        AddFilter($where, $wrk);
    }

    // Convert search value
    protected function convertSearchValue(&$fld, $fldVal)
    {
        if ($fldVal == Config("NULL_VALUE") || $fldVal == Config("NOT_NULL_VALUE")) {
            return $fldVal;
        }
        $value = $fldVal;
        if ($fld->isBoolean()) {
            if ($fldVal != "") {
                $value = (SameText($fldVal, "1") || SameText($fldVal, "y") || SameText($fldVal, "t")) ? $fld->TrueValue : $fld->FalseValue;
            }
        } elseif ($fld->DataType == DATATYPE_DATE || $fld->DataType == DATATYPE_TIME) {
            if ($fldVal != "") {
                $value = UnFormatDateTime($fldVal, $fld->DateTimeFormat);
            }
        }
        return $value;
    }

    // Return basic search SQL
    protected function basicSearchSql($arKeywords, $type)
    {
        $where = "";
        $this->buildBasicSearchSql($where, $this->kode_tapel, $arKeywords, $type);
        $this->buildBasicSearchSql($where, $this->kelas, $arKeywords, $type);
        $this->buildBasicSearchSql($where, $this->nisn, $arKeywords, $type);
        $this->buildBasicSearchSql($where, $this->nis, $arKeywords, $type);
        $this->buildBasicSearchSql($where, $this->nama, $arKeywords, $type);
        $this->buildBasicSearchSql($where, $this->jk, $arKeywords, $type);
        $this->buildBasicSearchSql($where, $this->s, $arKeywords, $type);
        $this->buildBasicSearchSql($where, $this->_i, $arKeywords, $type);
        $this->buildBasicSearchSql($where, $this->a, $arKeywords, $type);
        $this->buildBasicSearchSql($where, $this->ekstra1, $arKeywords, $type);
        $this->buildBasicSearchSql($where, $this->deskripsi1, $arKeywords, $type);
        $this->buildBasicSearchSql($where, $this->ekstra2, $arKeywords, $type);
        $this->buildBasicSearchSql($where, $this->deskripsi2, $arKeywords, $type);
        $this->buildBasicSearchSql($where, $this->ekstra3, $arKeywords, $type);
        $this->buildBasicSearchSql($where, $this->deskripsi3, $arKeywords, $type);
        $this->buildBasicSearchSql($where, $this->ekstra4, $arKeywords, $type);
        $this->buildBasicSearchSql($where, $this->deskripsi4, $arKeywords, $type);
        return $where;
    }

    // Build basic search SQL
    protected function buildBasicSearchSql(&$where, &$fld, $arKeywords, $type)
    {
        $defCond = ($type == "OR") ? "OR" : "AND";
        $arSql = []; // Array for SQL parts
        $arCond = []; // Array for search conditions
        $cnt = count($arKeywords);
        $j = 0; // Number of SQL parts
        for ($i = 0; $i < $cnt; $i++) {
            $keyword = $arKeywords[$i];
            $keyword = trim($keyword);
            if (Config("BASIC_SEARCH_IGNORE_PATTERN") != "") {
                $keyword = preg_replace(Config("BASIC_SEARCH_IGNORE_PATTERN"), "\\", $keyword);
                $ar = explode("\\", $keyword);
            } else {
                $ar = [$keyword];
            }
            foreach ($ar as $keyword) {
                if ($keyword != "") {
                    $wrk = "";
                    if ($keyword == "OR" && $type == "") {
                        if ($j > 0) {
                            $arCond[$j - 1] = "OR";
                        }
                    } elseif ($keyword == Config("NULL_VALUE")) {
                        $wrk = $fld->Expression . " IS NULL";
                    } elseif ($keyword == Config("NOT_NULL_VALUE")) {
                        $wrk = $fld->Expression . " IS NOT NULL";
                    } elseif ($fld->IsVirtual && $fld->Visible) {
                        $wrk = $fld->VirtualExpression . Like(QuotedValue("%" . $keyword . "%", DATATYPE_STRING, $this->Dbid), $this->Dbid);
                    } elseif ($fld->DataType != DATATYPE_NUMBER || is_numeric($keyword)) {
                        $wrk = $fld->BasicSearchExpression . Like(QuotedValue("%" . $keyword . "%", DATATYPE_STRING, $this->Dbid), $this->Dbid);
                    }
                    if ($wrk != "") {
                        $arSql[$j] = $wrk;
                        $arCond[$j] = $defCond;
                        $j += 1;
                    }
                }
            }
        }
        $cnt = count($arSql);
        $quoted = false;
        $sql = "";
        if ($cnt > 0) {
            for ($i = 0; $i < $cnt - 1; $i++) {
                if ($arCond[$i] == "OR") {
                    if (!$quoted) {
                        $sql .= "(";
                    }
                    $quoted = true;
                }
                $sql .= $arSql[$i];
                if ($quoted && $arCond[$i] != "OR") {
                    $sql .= ")";
                    $quoted = false;
                }
                $sql .= " " . $arCond[$i] . " ";
            }
            $sql .= $arSql[$cnt - 1];
            if ($quoted) {
                $sql .= ")";
            }
        }
        if ($sql != "") {
            if ($where != "") {
                $where .= " OR ";
            }
            $where .= "(" . $sql . ")";
        }
    }

    // Return basic search WHERE clause based on search keyword and type
    protected function basicSearchWhere($default = false)
    {
        global $Security;
        $searchStr = "";
        if (!$Security->canSearch()) {
            return "";
        }
        $searchKeyword = ($default) ? $this->BasicSearch->KeywordDefault : $this->BasicSearch->Keyword;
        $searchType = ($default) ? $this->BasicSearch->TypeDefault : $this->BasicSearch->Type;

        // Get search SQL
        if ($searchKeyword != "") {
            $ar = $this->BasicSearch->keywordList($default);
            // Search keyword in any fields
            if (($searchType == "OR" || $searchType == "AND") && $this->BasicSearch->BasicSearchAnyFields) {
                foreach ($ar as $keyword) {
                    if ($keyword != "") {
                        if ($searchStr != "") {
                            $searchStr .= " " . $searchType . " ";
                        }
                        $searchStr .= "(" . $this->basicSearchSql([$keyword], $searchType) . ")";
                    }
                }
            } else {
                $searchStr = $this->basicSearchSql($ar, $searchType);
            }
            if (!$default && in_array($this->Command, ["", "reset", "resetall"])) {
                $this->Command = "search";
            }
        }
        if (!$default && $this->Command == "search") {
            $this->BasicSearch->setKeyword($searchKeyword);
            $this->BasicSearch->setType($searchType);
        }
        return $searchStr;
    }

    // Check if search parm exists
    protected function checkSearchParms()
    {
        // Check basic search
        if ($this->BasicSearch->issetSession()) {
            return true;
        }
        if ($this->absen_id->AdvancedSearch->issetSession()) {
            return true;
        }
        if ($this->kode_tapel->AdvancedSearch->issetSession()) {
            return true;
        }
        if ($this->kelas->AdvancedSearch->issetSession()) {
            return true;
        }
        if ($this->nisn->AdvancedSearch->issetSession()) {
            return true;
        }
        if ($this->nis->AdvancedSearch->issetSession()) {
            return true;
        }
        if ($this->nama->AdvancedSearch->issetSession()) {
            return true;
        }
        if ($this->jk->AdvancedSearch->issetSession()) {
            return true;
        }
        if ($this->s->AdvancedSearch->issetSession()) {
            return true;
        }
        if ($this->_i->AdvancedSearch->issetSession()) {
            return true;
        }
        if ($this->a->AdvancedSearch->issetSession()) {
            return true;
        }
        if ($this->ekstra1->AdvancedSearch->issetSession()) {
            return true;
        }
        if ($this->deskripsi1->AdvancedSearch->issetSession()) {
            return true;
        }
        if ($this->ekstra2->AdvancedSearch->issetSession()) {
            return true;
        }
        if ($this->deskripsi2->AdvancedSearch->issetSession()) {
            return true;
        }
        if ($this->ekstra3->AdvancedSearch->issetSession()) {
            return true;
        }
        if ($this->deskripsi3->AdvancedSearch->issetSession()) {
            return true;
        }
        if ($this->ekstra4->AdvancedSearch->issetSession()) {
            return true;
        }
        if ($this->deskripsi4->AdvancedSearch->issetSession()) {
            return true;
        }
        if ($this->catatan_siswa->AdvancedSearch->issetSession()) {
            return true;
        }
        return false;
    }

    // Clear all search parameters
    protected function resetSearchParms()
    {
        // Clear search WHERE clause
        $this->SearchWhere = "";
        $this->setSearchWhere($this->SearchWhere);

        // Clear basic search parameters
        $this->resetBasicSearchParms();

        // Clear advanced search parameters
        $this->resetAdvancedSearchParms();
    }

    // Load advanced search default values
    protected function loadAdvancedSearchDefault()
    {
        return false;
    }

    // Clear all basic search parameters
    protected function resetBasicSearchParms()
    {
        $this->BasicSearch->unsetSession();
    }

    // Clear all advanced search parameters
    protected function resetAdvancedSearchParms()
    {
                $this->absen_id->AdvancedSearch->unsetSession();
                $this->kode_tapel->AdvancedSearch->unsetSession();
                $this->kelas->AdvancedSearch->unsetSession();
                $this->nisn->AdvancedSearch->unsetSession();
                $this->nis->AdvancedSearch->unsetSession();
                $this->nama->AdvancedSearch->unsetSession();
                $this->jk->AdvancedSearch->unsetSession();
                $this->s->AdvancedSearch->unsetSession();
                $this->_i->AdvancedSearch->unsetSession();
                $this->a->AdvancedSearch->unsetSession();
                $this->ekstra1->AdvancedSearch->unsetSession();
                $this->deskripsi1->AdvancedSearch->unsetSession();
                $this->ekstra2->AdvancedSearch->unsetSession();
                $this->deskripsi2->AdvancedSearch->unsetSession();
                $this->ekstra3->AdvancedSearch->unsetSession();
                $this->deskripsi3->AdvancedSearch->unsetSession();
                $this->ekstra4->AdvancedSearch->unsetSession();
                $this->deskripsi4->AdvancedSearch->unsetSession();
                $this->catatan_siswa->AdvancedSearch->unsetSession();
    }

    // Restore all search parameters
    protected function restoreSearchParms()
    {
        $this->RestoreSearch = true;

        // Restore basic search values
        $this->BasicSearch->load();

        // Restore advanced search values
                $this->absen_id->AdvancedSearch->load();
                $this->kode_tapel->AdvancedSearch->load();
                $this->kelas->AdvancedSearch->load();
                $this->nisn->AdvancedSearch->load();
                $this->nis->AdvancedSearch->load();
                $this->nama->AdvancedSearch->load();
                $this->jk->AdvancedSearch->load();
                $this->s->AdvancedSearch->load();
                $this->_i->AdvancedSearch->load();
                $this->a->AdvancedSearch->load();
                $this->ekstra1->AdvancedSearch->load();
                $this->deskripsi1->AdvancedSearch->load();
                $this->ekstra2->AdvancedSearch->load();
                $this->deskripsi2->AdvancedSearch->load();
                $this->ekstra3->AdvancedSearch->load();
                $this->deskripsi3->AdvancedSearch->load();
                $this->ekstra4->AdvancedSearch->load();
                $this->deskripsi4->AdvancedSearch->load();
                $this->catatan_siswa->AdvancedSearch->load();
    }

    // Set up sort parameters
    protected function setupSortOrder()
    {
        // Check for "order" parameter
        if (Get("order") !== null) {
            $this->CurrentOrder = Get("order");
            $this->CurrentOrderType = Get("ordertype", "");
            $this->updateSort($this->kode_tapel); // kode_tapel
            $this->updateSort($this->kelas); // kelas
            $this->updateSort($this->nisn); // nisn
            $this->updateSort($this->nis); // nis
            $this->updateSort($this->nama); // nama
            $this->updateSort($this->jk); // jk
            $this->updateSort($this->s); // s
            $this->updateSort($this->_i); // i
            $this->updateSort($this->a); // a
            $this->updateSort($this->ekstra1); // ekstra1
            $this->updateSort($this->deskripsi1); // deskripsi1
            $this->updateSort($this->ekstra2); // ekstra2
            $this->updateSort($this->deskripsi2); // deskripsi2
            $this->updateSort($this->ekstra3); // ekstra3
            $this->updateSort($this->deskripsi3); // deskripsi3
            $this->updateSort($this->ekstra4); // ekstra4
            $this->updateSort($this->deskripsi4); // deskripsi4
            $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 search criteria
            if ($this->Command == "reset" || $this->Command == "resetall") {
                $this->resetSearchParms();
            }

            // Reset (clear) sorting order
            if ($this->Command == "resetsort") {
                $orderBy = "";
                $this->setSessionOrderBy($orderBy);
                $this->absen_id->setSort("");
                $this->kode_tapel->setSort("");
                $this->kelas->setSort("");
                $this->nisn->setSort("");
                $this->nis->setSort("");
                $this->nama->setSort("");
                $this->jk->setSort("");
                $this->s->setSort("");
                $this->_i->setSort("");
                $this->a->setSort("");
                $this->ekstra1->setSort("");
                $this->deskripsi1->setSort("");
                $this->ekstra2->setSort("");
                $this->deskripsi2->setSort("");
                $this->ekstra3->setSort("");
                $this->deskripsi3->setSort("");
                $this->ekstra4->setSort("");
                $this->deskripsi4->setSort("");
                $this->catatan_siswa->setSort("");
            }

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

        // List actions
        $item = &$this->ListOptions->add("listactions");
        $item->CssClass = "text-nowrap";
        $item->OnLeft = true;
        $item->Visible = false;
        $item->ShowInButtonGroup = false;
        $item->ShowInDropDown = false;

        // "checkbox"
        $item = &$this->ListOptions->add("checkbox");
        $item->Visible = $Security->canDelete();
        $item->OnLeft = true;
        $item->Header = "<div class=\"custom-control custom-checkbox d-inline-block\"><input type=\"checkbox\" name=\"key\" id=\"key\" class=\"custom-control-input\" onclick=\"ew.selectAllKey(this);\"><label class=\"custom-control-label\" for=\"key\"></label></div>";
        $item->moveTo(0);
        $item->ShowInDropDown = false;
        $item->ShowInButtonGroup = false;

        // "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 = true;
        if ($this->ListOptions->UseButtonGroup && IsMobile()) {
            $this->ListOptions->UseDropDownButton = true;
        }

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

        // Call ListOptions_Load event
        $this->listOptionsLoad();
        $this->setupListOptionsExt();
        $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->isGridAdd() || $this->isGridEdit()) {
                $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);
        $pageUrl = $this->pageUrl();
        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

        // Set up list action buttons
        $opt = $this->ListOptions["listactions"];
        if ($opt && !$this->isExport() && !$this->CurrentAction) {
            $body = "";
            $links = [];
            foreach ($this->ListActions->Items as $listaction) {
                if ($listaction->Select == ACTION_SINGLE && $listaction->Allow) {
                    $action = $listaction->Action;
                    $caption = $listaction->Caption;
                    $icon = ($listaction->Icon != "") ? "<i class=\"" . HtmlEncode(str_replace(" ew-icon", "", $listaction->Icon)) . "\" data-caption=\"" . HtmlTitle($caption) . "\"></i> " : "";
                    $links[] = "<li><a class=\"dropdown-item ew-action ew-list-action\" data-action=\"" . HtmlEncode($action) . "\" data-caption=\"" . HtmlTitle($caption) . "\" href=\"#\" onclick=\"return ew.submitAction(event,jQuery.extend({key:" . $this->keyToJson(true) . "}," . $listaction->toJson(true) . "));\">" . $icon . $listaction->Caption . "</a></li>";
                    if (count($links) == 1) { // Single button
                        $body = "<a class=\"ew-action ew-list-action\" data-action=\"" . HtmlEncode($action) . "\" title=\"" . HtmlTitle($caption) . "\" data-caption=\"" . HtmlTitle($caption) . "\" href=\"#\" onclick=\"return ew.submitAction(event,jQuery.extend({key:" . $this->keyToJson(true) . "}," . $listaction->toJson(true) . "));\">" . $icon . $listaction->Caption . "</a>";
                    }
                }
            }
            if (count($links) > 1) { // More than one buttons, use dropdown
                $body = "<button class=\"dropdown-toggle btn btn-default ew-actions\" title=\"" . HtmlTitle($Language->phrase("ListActionButton")) . "\" data-toggle=\"dropdown\">" . $Language->phrase("ListActionButton") . "</button>";
                $content = "";
                foreach ($links as $link) {
                    $content .= "<li>" . $link . "</li>";
                }
                $body .= "<ul class=\"dropdown-menu" . ($opt->OnLeft ? "" : " dropdown-menu-right") . "\">" . $content . "</ul>";
                $body = "<div class=\"btn-group btn-group-sm\">" . $body . "</div>";
            }
            if (count($links) > 0) {
                $opt->Body = $body;
                $opt->Visible = true;
            }
        }

        // "checkbox"
        $opt = $this->ListOptions["checkbox"];
        $opt->Body = "<div class=\"custom-control custom-checkbox d-inline-block\"><input type=\"checkbox\" id=\"key_m_" . $this->RowCount . "\" name=\"key_m[]\" class=\"custom-control-input ew-multi-select\" value=\"" . HtmlEncode($this->absen_id->CurrentValue) . "\" onclick=\"ew.clickMultiCheckbox(event);\"><label class=\"custom-control-label\" for=\"key_m_" . $this->RowCount . "\"></label></div>";
        $this->renderListOptionsExt();

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

    // Set up other options
    protected function setupOtherOptions()
    {
        global $Language, $Security;
        $options = &$this->OtherOptions;

        // Add grid edit
        $option = $options["addedit"];
        $item = &$option->add("gridedit");
        $item->Body = "<a class=\"ew-add-edit ew-grid-edit\" title=\"" . HtmlTitle($Language->phrase("GridEditLink")) . "\" data-caption=\"" . HtmlTitle($Language->phrase("GridEditLink")) . "\" href=\"" . HtmlEncode(GetUrl($this->GridEditUrl)) . "\">" . $Language->phrase("GridEditLink") . "</a>";
        $item->Visible = $this->GridEditUrl != "" && $Security->canEdit();
        $option = $options["action"];

        // Add multi delete
        $item = &$option->add("multidelete");
        $item->Body = "<a class=\"ew-action ew-multi-delete\" title=\"" . HtmlTitle($Language->phrase("DeleteSelectedLink")) . "\" data-caption=\"" . HtmlTitle($Language->phrase("DeleteSelectedLink")) . "\" href=\"#\" onclick=\"return ew.submitAction(event, {f:document.fextra_absensilist, url:'" . GetUrl($this->MultiDeleteUrl) . "', data:{action:'delete'}, msg:ew.language.phrase('DeleteConfirmMsg')});return false;\">" . $Language->phrase("DeleteSelectedLink") . "</a>";
        $item->Visible = $Security->canDelete();

        // Set up options default
        foreach ($options as $option) {
            $option->UseDropDownButton = false;
            $option->UseButtonGroup = true;
            //$option->ButtonClass = ""; // Class for button group
            $item = &$option->add($option->GroupOptionName);
            $item->Body = "";
            $item->Visible = false;
        }
        $options["addedit"]->DropDownButtonPhrase = $Language->phrase("ButtonAddEdit");
        $options["detail"]->DropDownButtonPhrase = $Language->phrase("ButtonDetails");
        $options["action"]->DropDownButtonPhrase = $Language->phrase("ButtonActions");

        // Filter button
        $item = &$this->FilterOptions->add("savecurrentfilter");
        $item->Body = "<a class=\"ew-save-filter\" data-form=\"fextra_absensilistsrch\" href=\"#\" onclick=\"return false;\">" . $Language->phrase("SaveCurrentFilter") . "</a>";
        $item->Visible = true;
        $item = &$this->FilterOptions->add("deletefilter");
        $item->Body = "<a class=\"ew-delete-filter\" data-form=\"fextra_absensilistsrch\" href=\"#\" onclick=\"return false;\">" . $Language->phrase("DeleteFilter") . "</a>";
        $item->Visible = true;
        $this->FilterOptions->UseDropDownButton = true;
        $this->FilterOptions->UseButtonGroup = !$this->FilterOptions->UseDropDownButton;
        $this->FilterOptions->DropDownButtonPhrase = $Language->phrase("Filters");

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

    // Render other options
    public function renderOtherOptions()
    {
        global $Language, $Security;
        $options = &$this->OtherOptions;
        if (!$this->isGridAdd() && !$this->isGridEdit()) { // Not grid add/edit mode
            $option = $options["action"];
            // Set up list action buttons
            foreach ($this->ListActions->Items as $listaction) {
                if ($listaction->Select == ACTION_MULTIPLE) {
                    $item = &$option->add("custom_" . $listaction->Action);
                    $caption = $listaction->Caption;
                    $icon = ($listaction->Icon != "") ? '<i class="' . HtmlEncode($listaction->Icon) . '" data-caption="' . HtmlEncode($caption) . '"></i>' . $caption : $caption;
                    $item->Body = '<a class="ew-action ew-list-action" title="' . HtmlEncode($caption) . '" data-caption="' . HtmlEncode($caption) . '" href="#" onclick="return ew.submitAction(event,jQuery.extend({f:document.fextra_absensilist},' . $listaction->toJson(true) . '));">' . $icon . '</a>';
                    $item->Visible = $listaction->Allow;
                }
            }

            // Hide grid edit and other options
            if ($this->TotalRecords <= 0) {
                $option = $options["addedit"];
                $item = $option["gridedit"];
                if ($item) {
                    $item->Visible = false;
                }
                $option = $options["action"];
                $option->hideAllOptions();
            }
        } else { // Grid add/edit mode
            // Hide all options first
            foreach ($options as $option) {
                $option->hideAllOptions();
            }
            $pageUrl = $this->pageUrl();

            // Grid-Edit
            if ($this->isGridEdit()) {
                if ($this->AllowAddDeleteRow) {
                    // Add add blank row
                    $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 = false;
                }
                $option = $options["action"];
                $option->UseDropDownButton = false;
                    $item = &$option->add("gridsave");
                    $item->Body = "<a class=\"ew-action ew-grid-save\" title=\"" . HtmlTitle($Language->phrase("GridSaveLink")) . "\" data-caption=\"" . HtmlTitle($Language->phrase("GridSaveLink")) . "\" href=\"#\" onclick=\"ew.forms.get(this).submit(event, '" . $this->pageName() . "'); return false;\">" . $Language->phrase("GridSaveLink") . "</a>";
                    $item = &$option->add("gridcancel");
                    $cancelurl = $this->addMasterUrl($pageUrl . "action=cancel");
                    $item->Body = "<a class=\"ew-action ew-grid-cancel\" title=\"" . HtmlTitle($Language->phrase("GridCancelLink")) . "\" data-caption=\"" . HtmlTitle($Language->phrase("GridCancelLink")) . "\" href=\"" . $cancelurl . "\">" . $Language->phrase("GridCancelLink") . "</a>";
            }
        }
    }

    // Process list action
    protected function processListAction()
    {
        global $Language, $Security;
        $userlist = "";
        $user = "";
        $filter = $this->getFilterFromRecordKeys();
        $userAction = Post("useraction", "");
        if ($filter != "" && $userAction != "") {
            // Check permission first
            $actionCaption = $userAction;
            if (array_key_exists($userAction, $this->ListActions->Items)) {
                $actionCaption = $this->ListActions[$userAction]->Caption;
                if (!$this->ListActions[$userAction]->Allow) {
                    $errmsg = str_replace('%s', $actionCaption, $Language->phrase("CustomActionNotAllowed"));
                    if (Post("ajax") == $userAction) { // Ajax
                        echo "<p class=\"text-danger\">" . $errmsg . "</p>";
                        return true;
                    } else {
                        $this->setFailureMessage($errmsg);
                        return false;
                    }
                }
            }
            $this->CurrentFilter = $filter;
            $sql = $this->getCurrentSql();
            $conn = $this->getConnection();
            $rs = LoadRecordset($sql, $conn, \PDO::FETCH_ASSOC);
            $this->CurrentAction = $userAction;

            // Call row action event
            if ($rs) {
                $conn->beginTransaction();
                $this->SelectedCount = $rs->recordCount();
                $this->SelectedIndex = 0;
                while (!$rs->EOF) {
                    $this->SelectedIndex++;
                    $row = $rs->fields;
                    $processed = $this->rowCustomAction($userAction, $row);
                    if (!$processed) {
                        break;
                    }
                    $rs->moveNext();
                }
                if ($processed) {
                    $conn->commit(); // Commit the changes
                    if ($this->getSuccessMessage() == "" && !ob_get_length()) { // No output
                        $this->setSuccessMessage(str_replace('%s', $actionCaption, $Language->phrase("CustomActionCompleted"))); // Set up success message
                    }
                } else {
                    $conn->rollback(); // Rollback changes

                    // 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(str_replace('%s', $actionCaption, $Language->phrase("CustomActionFailed")));
                    }
                }
            }
            if ($rs) {
                $rs->close();
            }
            $this->CurrentAction = ""; // Clear action
            if (Post("ajax") == $userAction) { // Ajax
                if ($this->getSuccessMessage() != "") {
                    echo "<p class=\"text-success\">" . $this->getSuccessMessage() . "</p>";
                    $this->clearSuccessMessage(); // Clear message
                }
                if ($this->getFailureMessage() != "") {
                    echo "<p class=\"text-danger\">" . $this->getFailureMessage() . "</p>";
                    $this->clearFailureMessage(); // Clear message
                }
                return true;
            }
        }
        return false; // Not ajax request
    }

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

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

    // Load default values
    protected function loadDefaultValues()
    {
        $this->absen_id->CurrentValue = null;
        $this->absen_id->OldValue = $this->absen_id->CurrentValue;
        $this->kode_tapel->CurrentValue = null;
        $this->kode_tapel->OldValue = $this->kode_tapel->CurrentValue;
        $this->kelas->CurrentValue = CurrentUserID();
        $this->kelas->OldValue = $this->kelas->CurrentValue;
        $this->nisn->CurrentValue = null;
        $this->nisn->OldValue = $this->nisn->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->s->CurrentValue = null;
        $this->s->OldValue = $this->s->CurrentValue;
        $this->_i->CurrentValue = null;
        $this->_i->OldValue = $this->_i->CurrentValue;
        $this->a->CurrentValue = null;
        $this->a->OldValue = $this->a->CurrentValue;
        $this->ekstra1->CurrentValue = null;
        $this->ekstra1->OldValue = $this->ekstra1->CurrentValue;
        $this->deskripsi1->CurrentValue = null;
        $this->deskripsi1->OldValue = $this->deskripsi1->CurrentValue;
        $this->ekstra2->CurrentValue = null;
        $this->ekstra2->OldValue = $this->ekstra2->CurrentValue;
        $this->deskripsi2->CurrentValue = null;
        $this->deskripsi2->OldValue = $this->deskripsi2->CurrentValue;
        $this->ekstra3->CurrentValue = null;
        $this->ekstra3->OldValue = $this->ekstra3->CurrentValue;
        $this->deskripsi3->CurrentValue = null;
        $this->deskripsi3->OldValue = $this->deskripsi3->CurrentValue;
        $this->ekstra4->CurrentValue = null;
        $this->ekstra4->OldValue = $this->ekstra4->CurrentValue;
        $this->deskripsi4->CurrentValue = null;
        $this->deskripsi4->OldValue = $this->deskripsi4->CurrentValue;
        $this->catatan_siswa->CurrentValue = null;
        $this->catatan_siswa->OldValue = $this->catatan_siswa->CurrentValue;
    }

    // Load basic search values
    protected function loadBasicSearchValues()
    {
        $this->BasicSearch->setKeyword(Get(Config("TABLE_BASIC_SEARCH"), ""), false);
        if ($this->BasicSearch->Keyword != "" && $this->Command == "") {
            $this->Command = "search";
        }
        $this->BasicSearch->setType(Get(Config("TABLE_BASIC_SEARCH_TYPE"), ""), false);
    }

    // Load search values for validation
    protected function loadSearchValues()
    {
        // Load search values
        $hasValue = false;

        // absen_id
        if (!$this->isAddOrEdit() && $this->absen_id->AdvancedSearch->get()) {
            $hasValue = true;
            if (($this->absen_id->AdvancedSearch->SearchValue != "" || $this->absen_id->AdvancedSearch->SearchValue2 != "") && $this->Command == "") {
                $this->Command = "search";
            }
        }

        // kode_tapel
        if (!$this->isAddOrEdit() && $this->kode_tapel->AdvancedSearch->get()) {
            $hasValue = true;
            if (($this->kode_tapel->AdvancedSearch->SearchValue != "" || $this->kode_tapel->AdvancedSearch->SearchValue2 != "") && $this->Command == "") {
                $this->Command = "search";
            }
        }

        // kelas
        if (!$this->isAddOrEdit() && $this->kelas->AdvancedSearch->get()) {
            $hasValue = true;
            if (($this->kelas->AdvancedSearch->SearchValue != "" || $this->kelas->AdvancedSearch->SearchValue2 != "") && $this->Command == "") {
                $this->Command = "search";
            }
        }

        // nisn
        if (!$this->isAddOrEdit() && $this->nisn->AdvancedSearch->get()) {
            $hasValue = true;
            if (($this->nisn->AdvancedSearch->SearchValue != "" || $this->nisn->AdvancedSearch->SearchValue2 != "") && $this->Command == "") {
                $this->Command = "search";
            }
        }

        // nis
        if (!$this->isAddOrEdit() && $this->nis->AdvancedSearch->get()) {
            $hasValue = true;
            if (($this->nis->AdvancedSearch->SearchValue != "" || $this->nis->AdvancedSearch->SearchValue2 != "") && $this->Command == "") {
                $this->Command = "search";
            }
        }

        // nama
        if (!$this->isAddOrEdit() && $this->nama->AdvancedSearch->get()) {
            $hasValue = true;
            if (($this->nama->AdvancedSearch->SearchValue != "" || $this->nama->AdvancedSearch->SearchValue2 != "") && $this->Command == "") {
                $this->Command = "search";
            }
        }

        // jk
        if (!$this->isAddOrEdit() && $this->jk->AdvancedSearch->get()) {
            $hasValue = true;
            if (($this->jk->AdvancedSearch->SearchValue != "" || $this->jk->AdvancedSearch->SearchValue2 != "") && $this->Command == "") {
                $this->Command = "search";
            }
        }

        // s
        if (!$this->isAddOrEdit() && $this->s->AdvancedSearch->get()) {
            $hasValue = true;
            if (($this->s->AdvancedSearch->SearchValue != "" || $this->s->AdvancedSearch->SearchValue2 != "") && $this->Command == "") {
                $this->Command = "search";
            }
        }

        // i
        if (!$this->isAddOrEdit() && $this->_i->AdvancedSearch->get()) {
            $hasValue = true;
            if (($this->_i->AdvancedSearch->SearchValue != "" || $this->_i->AdvancedSearch->SearchValue2 != "") && $this->Command == "") {
                $this->Command = "search";
            }
        }

        // a
        if (!$this->isAddOrEdit() && $this->a->AdvancedSearch->get()) {
            $hasValue = true;
            if (($this->a->AdvancedSearch->SearchValue != "" || $this->a->AdvancedSearch->SearchValue2 != "") && $this->Command == "") {
                $this->Command = "search";
            }
        }

        // ekstra1
        if (!$this->isAddOrEdit() && $this->ekstra1->AdvancedSearch->get()) {
            $hasValue = true;
            if (($this->ekstra1->AdvancedSearch->SearchValue != "" || $this->ekstra1->AdvancedSearch->SearchValue2 != "") && $this->Command == "") {
                $this->Command = "search";
            }
        }

        // deskripsi1
        if (!$this->isAddOrEdit() && $this->deskripsi1->AdvancedSearch->get()) {
            $hasValue = true;
            if (($this->deskripsi1->AdvancedSearch->SearchValue != "" || $this->deskripsi1->AdvancedSearch->SearchValue2 != "") && $this->Command == "") {
                $this->Command = "search";
            }
        }

        // ekstra2
        if (!$this->isAddOrEdit() && $this->ekstra2->AdvancedSearch->get()) {
            $hasValue = true;
            if (($this->ekstra2->AdvancedSearch->SearchValue != "" || $this->ekstra2->AdvancedSearch->SearchValue2 != "") && $this->Command == "") {
                $this->Command = "search";
            }
        }

        // deskripsi2
        if (!$this->isAddOrEdit() && $this->deskripsi2->AdvancedSearch->get()) {
            $hasValue = true;
            if (($this->deskripsi2->AdvancedSearch->SearchValue != "" || $this->deskripsi2->AdvancedSearch->SearchValue2 != "") && $this->Command == "") {
                $this->Command = "search";
            }
        }

        // ekstra3
        if (!$this->isAddOrEdit() && $this->ekstra3->AdvancedSearch->get()) {
            $hasValue = true;
            if (($this->ekstra3->AdvancedSearch->SearchValue != "" || $this->ekstra3->AdvancedSearch->SearchValue2 != "") && $this->Command == "") {
                $this->Command = "search";
            }
        }

        // deskripsi3
        if (!$this->isAddOrEdit() && $this->deskripsi3->AdvancedSearch->get()) {
            $hasValue = true;
            if (($this->deskripsi3->AdvancedSearch->SearchValue != "" || $this->deskripsi3->AdvancedSearch->SearchValue2 != "") && $this->Command == "") {
                $this->Command = "search";
            }
        }

        // ekstra4
        if (!$this->isAddOrEdit() && $this->ekstra4->AdvancedSearch->get()) {
            $hasValue = true;
            if (($this->ekstra4->AdvancedSearch->SearchValue != "" || $this->ekstra4->AdvancedSearch->SearchValue2 != "") && $this->Command == "") {
                $this->Command = "search";
            }
        }

        // deskripsi4
        if (!$this->isAddOrEdit() && $this->deskripsi4->AdvancedSearch->get()) {
            $hasValue = true;
            if (($this->deskripsi4->AdvancedSearch->SearchValue != "" || $this->deskripsi4->AdvancedSearch->SearchValue2 != "") && $this->Command == "") {
                $this->Command = "search";
            }
        }

        // catatan_siswa
        if (!$this->isAddOrEdit() && $this->catatan_siswa->AdvancedSearch->get()) {
            $hasValue = true;
            if (($this->catatan_siswa->AdvancedSearch->SearchValue != "" || $this->catatan_siswa->AdvancedSearch->SearchValue2 != "") && $this->Command == "") {
                $this->Command = "search";
            }
        }
        return $hasValue;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    // Restore form values
    public function restoreFormValues()
    {
        global $CurrentForm;
        if (!$this->isGridAdd() && !$this->isAdd()) {
            $this->absen_id->CurrentValue = $this->absen_id->FormValue;
        }
        $this->kode_tapel->CurrentValue = $this->kode_tapel->FormValue;
        $this->kelas->CurrentValue = $this->kelas->FormValue;
        $this->nisn->CurrentValue = $this->nisn->FormValue;
        $this->nis->CurrentValue = $this->nis->FormValue;
        $this->nama->CurrentValue = $this->nama->FormValue;
        $this->jk->CurrentValue = $this->jk->FormValue;
        $this->s->CurrentValue = $this->s->FormValue;
        $this->_i->CurrentValue = $this->_i->FormValue;
        $this->a->CurrentValue = $this->a->FormValue;
        $this->ekstra1->CurrentValue = $this->ekstra1->FormValue;
        $this->deskripsi1->CurrentValue = $this->deskripsi1->FormValue;
        $this->ekstra2->CurrentValue = $this->ekstra2->FormValue;
        $this->deskripsi2->CurrentValue = $this->deskripsi2->FormValue;
        $this->ekstra3->CurrentValue = $this->ekstra3->FormValue;
        $this->deskripsi3->CurrentValue = $this->deskripsi3->FormValue;
        $this->ekstra4->CurrentValue = $this->ekstra4->FormValue;
        $this->deskripsi4->CurrentValue = $this->deskripsi4->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
            if (!$this->EventCancelled) {
                $this->HashValue = $this->getRowHash($row); // Get hash value for record
            }
        }
        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->absen_id->setDbValue($row['absen_id']);
        $this->kode_tapel->setDbValue($row['kode_tapel']);
        $this->kelas->setDbValue($row['kelas']);
        $this->nisn->setDbValue($row['nisn']);
        $this->nis->setDbValue($row['nis']);
        $this->nama->setDbValue($row['nama']);
        $this->jk->setDbValue($row['jk']);
        $this->s->setDbValue($row['s']);
        $this->_i->setDbValue($row['i']);
        $this->a->setDbValue($row['a']);
        $this->ekstra1->setDbValue($row['ekstra1']);
        $this->deskripsi1->setDbValue($row['deskripsi1']);
        $this->ekstra2->setDbValue($row['ekstra2']);
        $this->deskripsi2->setDbValue($row['deskripsi2']);
        $this->ekstra3->setDbValue($row['ekstra3']);
        $this->deskripsi3->setDbValue($row['deskripsi3']);
        $this->ekstra4->setDbValue($row['ekstra4']);
        $this->deskripsi4->setDbValue($row['deskripsi4']);
        $this->catatan_siswa->setDbValue($row['catatan_siswa']);
    }

    // Return a row with default values
    protected function newRow()
    {
        $this->loadDefaultValues();
        $row = [];
        $row['absen_id'] = $this->absen_id->CurrentValue;
        $row['kode_tapel'] = $this->kode_tapel->CurrentValue;
        $row['kelas'] = $this->kelas->CurrentValue;
        $row['nisn'] = $this->nisn->CurrentValue;
        $row['nis'] = $this->nis->CurrentValue;
        $row['nama'] = $this->nama->CurrentValue;
        $row['jk'] = $this->jk->CurrentValue;
        $row['s'] = $this->s->CurrentValue;
        $row['i'] = $this->_i->CurrentValue;
        $row['a'] = $this->a->CurrentValue;
        $row['ekstra1'] = $this->ekstra1->CurrentValue;
        $row['deskripsi1'] = $this->deskripsi1->CurrentValue;
        $row['ekstra2'] = $this->ekstra2->CurrentValue;
        $row['deskripsi2'] = $this->deskripsi2->CurrentValue;
        $row['ekstra3'] = $this->ekstra3->CurrentValue;
        $row['deskripsi3'] = $this->deskripsi3->CurrentValue;
        $row['ekstra4'] = $this->ekstra4->CurrentValue;
        $row['deskripsi4'] = $this->deskripsi4->CurrentValue;
        $row['catatan_siswa'] = $this->catatan_siswa->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->InlineEditUrl = $this->getInlineEditUrl();
        $this->CopyUrl = $this->getCopyUrl();
        $this->InlineCopyUrl = $this->getInlineCopyUrl();
        $this->DeleteUrl = $this->getDeleteUrl();

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

        // Common render codes for all row types

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

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

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

        // nisn
        $this->nisn->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;";

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            // i
            $this->_i->ViewValue = $this->_i->CurrentValue;
            $this->_i->ViewCustomAttributes = "";

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

            // ekstra1
            $curVal = trim(strval($this->ekstra1->CurrentValue));
            if ($curVal != "") {
                $this->ekstra1->ViewValue = $this->ekstra1->lookupCacheOption($curVal);
                if ($this->ekstra1->ViewValue === null) { // Lookup from database
                    $filterWrk = "\"ektrakurikuler\"" . SearchString("=", $curVal, DATATYPE_STRING, "");
                    $lookupFilter = function() {
                        return "`kode_tapel`='".kode_tapel()."'";
                    };
                    $lookupFilter = $lookupFilter->bindTo($this);
                    $sqlWrk = $this->ekstra1->Lookup->getSql(false, $filterWrk, $lookupFilter, $this, true, true);
                    $rswrk = Conn()->executeQuery($sqlWrk)->fetchAll(\PDO::FETCH_BOTH);
                    $ari = count($rswrk);
                    if ($ari > 0) { // Lookup values found
                        $arwrk = $this->ekstra1->Lookup->renderViewRow($rswrk[0]);
                        $this->ekstra1->ViewValue = $this->ekstra1->displayValue($arwrk);
                    } else {
                        $this->ekstra1->ViewValue = $this->ekstra1->CurrentValue;
                    }
                }
            } else {
                $this->ekstra1->ViewValue = null;
            }
            $this->ekstra1->ViewCustomAttributes = "";

            // deskripsi1
            if (strval($this->deskripsi1->CurrentValue) != "") {
                $this->deskripsi1->ViewValue = $this->deskripsi1->optionCaption($this->deskripsi1->CurrentValue);
            } else {
                $this->deskripsi1->ViewValue = null;
            }
            $this->deskripsi1->ViewCustomAttributes = "";

            // ekstra2
            $curVal = trim(strval($this->ekstra2->CurrentValue));
            if ($curVal != "") {
                $this->ekstra2->ViewValue = $this->ekstra2->lookupCacheOption($curVal);
                if ($this->ekstra2->ViewValue === null) { // Lookup from database
                    $filterWrk = "\"ektrakurikuler\"" . SearchString("=", $curVal, DATATYPE_STRING, "");
                    $lookupFilter = function() {
                        return "`kode_tapel`='".kode_tapel()."'";
                    };
                    $lookupFilter = $lookupFilter->bindTo($this);
                    $sqlWrk = $this->ekstra2->Lookup->getSql(false, $filterWrk, $lookupFilter, $this, true, true);
                    $rswrk = Conn()->executeQuery($sqlWrk)->fetchAll(\PDO::FETCH_BOTH);
                    $ari = count($rswrk);
                    if ($ari > 0) { // Lookup values found
                        $arwrk = $this->ekstra2->Lookup->renderViewRow($rswrk[0]);
                        $this->ekstra2->ViewValue = $this->ekstra2->displayValue($arwrk);
                    } else {
                        $this->ekstra2->ViewValue = $this->ekstra2->CurrentValue;
                    }
                }
            } else {
                $this->ekstra2->ViewValue = null;
            }
            $this->ekstra2->ViewCustomAttributes = "";

            // deskripsi2
            if (strval($this->deskripsi2->CurrentValue) != "") {
                $this->deskripsi2->ViewValue = $this->deskripsi2->optionCaption($this->deskripsi2->CurrentValue);
            } else {
                $this->deskripsi2->ViewValue = null;
            }
            $this->deskripsi2->ViewCustomAttributes = "";

            // ekstra3
            $curVal = trim(strval($this->ekstra3->CurrentValue));
            if ($curVal != "") {
                $this->ekstra3->ViewValue = $this->ekstra3->lookupCacheOption($curVal);
                if ($this->ekstra3->ViewValue === null) { // Lookup from database
                    $filterWrk = "\"ektrakurikuler\"" . SearchString("=", $curVal, DATATYPE_STRING, "");
                    $lookupFilter = function() {
                        return "`kode_tapel`='".kode_tapel()."'";
                    };
                    $lookupFilter = $lookupFilter->bindTo($this);
                    $sqlWrk = $this->ekstra3->Lookup->getSql(false, $filterWrk, $lookupFilter, $this, true, true);
                    $rswrk = Conn()->executeQuery($sqlWrk)->fetchAll(\PDO::FETCH_BOTH);
                    $ari = count($rswrk);
                    if ($ari > 0) { // Lookup values found
                        $arwrk = $this->ekstra3->Lookup->renderViewRow($rswrk[0]);
                        $this->ekstra3->ViewValue = $this->ekstra3->displayValue($arwrk);
                    } else {
                        $this->ekstra3->ViewValue = $this->ekstra3->CurrentValue;
                    }
                }
            } else {
                $this->ekstra3->ViewValue = null;
            }
            $this->ekstra3->ViewCustomAttributes = "";

            // deskripsi3
            if (strval($this->deskripsi3->CurrentValue) != "") {
                $this->deskripsi3->ViewValue = $this->deskripsi3->optionCaption($this->deskripsi3->CurrentValue);
            } else {
                $this->deskripsi3->ViewValue = null;
            }
            $this->deskripsi3->ViewCustomAttributes = "";

            // ekstra4
            $curVal = trim(strval($this->ekstra4->CurrentValue));
            if ($curVal != "") {
                $this->ekstra4->ViewValue = $this->ekstra4->lookupCacheOption($curVal);
                if ($this->ekstra4->ViewValue === null) { // Lookup from database
                    $filterWrk = "\"ektrakurikuler\"" . SearchString("=", $curVal, DATATYPE_STRING, "");
                    $lookupFilter = function() {
                        return "`kode_tapel`='".kode_tapel()."'";
                    };
                    $lookupFilter = $lookupFilter->bindTo($this);
                    $sqlWrk = $this->ekstra4->Lookup->getSql(false, $filterWrk, $lookupFilter, $this, true, true);
                    $rswrk = Conn()->executeQuery($sqlWrk)->fetchAll(\PDO::FETCH_BOTH);
                    $ari = count($rswrk);
                    if ($ari > 0) { // Lookup values found
                        $arwrk = $this->ekstra4->Lookup->renderViewRow($rswrk[0]);
                        $this->ekstra4->ViewValue = $this->ekstra4->displayValue($arwrk);
                    } else {
                        $this->ekstra4->ViewValue = $this->ekstra4->CurrentValue;
                    }
                }
            } else {
                $this->ekstra4->ViewValue = null;
            }
            $this->ekstra4->ViewCustomAttributes = "";

            // deskripsi4
            if (strval($this->deskripsi4->CurrentValue) != "") {
                $this->deskripsi4->ViewValue = $this->deskripsi4->optionCaption($this->deskripsi4->CurrentValue);
            } else {
                $this->deskripsi4->ViewValue = null;
            }
            $this->deskripsi4->ViewCustomAttributes = "";

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

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

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

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

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

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

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

            // i
            $this->_i->LinkCustomAttributes = "";
            $this->_i->HrefValue = "";
            $this->_i->TooltipValue = "";

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

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

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

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

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

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

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

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

            // deskripsi4
            $this->deskripsi4->LinkCustomAttributes = "";
            $this->deskripsi4->HrefValue = "";
            $this->deskripsi4->TooltipValue = "";
        } elseif ($this->RowType == ROWTYPE_ADD) {
            // kode_tapel

            // kelas
            $this->kelas->EditAttrs["class"] = "form-control";
            $this->kelas->EditCustomAttributes = "";
            if (!$Security->isAdmin() && $Security->isLoggedIn() && !$this->userIDAllow($this->CurrentAction)) { // 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;
                }
            }

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

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

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

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

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

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

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

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

            // deskripsi1
            $this->deskripsi1->EditAttrs["class"] = "form-control";
            $this->deskripsi1->EditCustomAttributes = "";
            $this->deskripsi1->EditValue = $this->deskripsi1->options(true);

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

            // deskripsi2
            $this->deskripsi2->EditAttrs["class"] = "form-control";
            $this->deskripsi2->EditCustomAttributes = "";
            $this->deskripsi2->EditValue = $this->deskripsi2->options(true);

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

            // deskripsi3
            $this->deskripsi3->EditAttrs["class"] = "form-control";
            $this->deskripsi3->EditCustomAttributes = "";
            $this->deskripsi3->EditValue = $this->deskripsi3->options(true);

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

            // deskripsi4
            $this->deskripsi4->EditAttrs["class"] = "form-control";
            $this->deskripsi4->EditCustomAttributes = "";
            $this->deskripsi4->EditValue = $this->deskripsi4->options(true);

            // Add refer script

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

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

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

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

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

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

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

            // i
            $this->_i->LinkCustomAttributes = "";
            $this->_i->HrefValue = "";

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

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

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

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

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

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

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

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

            // deskripsi4
            $this->deskripsi4->LinkCustomAttributes = "";
            $this->deskripsi4->HrefValue = "";
        } elseif ($this->RowType == ROWTYPE_EDIT) {
            // kode_tapel

            // kelas
            $this->kelas->EditAttrs["class"] = "form-control";
            $this->kelas->EditCustomAttributes = "";
            $this->kelas->EditValue = $this->kelas->CurrentValue;
            $this->kelas->ViewCustomAttributes = "";

            // nisn
            $this->nisn->EditAttrs["class"] = "form-control";
            $this->nisn->EditCustomAttributes = "";
            $this->nisn->EditValue = $this->nisn->CurrentValue;
            $this->nisn->ViewCustomAttributes = "";

            // nis
            $this->nis->EditAttrs["class"] = "form-control";
            $this->nis->EditCustomAttributes = "";
            $this->nis->EditValue = $this->nis->CurrentValue;
            $this->nis->ViewCustomAttributes = "";

            // nama
            $this->nama->EditAttrs["class"] = "form-control";
            $this->nama->EditCustomAttributes = "";
            $this->nama->EditValue = $this->nama->CurrentValue;
            $this->nama->ViewCustomAttributes = "";

            // jk
            $this->jk->EditAttrs["class"] = "form-control";
            $this->jk->EditCustomAttributes = "";
            $this->jk->EditValue = $this->jk->CurrentValue;
            $this->jk->ViewCustomAttributes = "";

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

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

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

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

            // deskripsi1
            $this->deskripsi1->EditAttrs["class"] = "form-control";
            $this->deskripsi1->EditCustomAttributes = "";
            $this->deskripsi1->EditValue = $this->deskripsi1->options(true);

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

            // deskripsi2
            $this->deskripsi2->EditAttrs["class"] = "form-control";
            $this->deskripsi2->EditCustomAttributes = "";
            $this->deskripsi2->EditValue = $this->deskripsi2->options(true);

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

            // deskripsi3
            $this->deskripsi3->EditAttrs["class"] = "form-control";
            $this->deskripsi3->EditCustomAttributes = "";
            $this->deskripsi3->EditValue = $this->deskripsi3->options(true);

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

            // deskripsi4
            $this->deskripsi4->EditAttrs["class"] = "form-control";
            $this->deskripsi4->EditCustomAttributes = "";
            $this->deskripsi4->EditValue = $this->deskripsi4->options(true);

            // Edit refer script

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

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

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

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

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

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

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

            // i
            $this->_i->LinkCustomAttributes = "";
            $this->_i->HrefValue = "";

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

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

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

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

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

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

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

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

            // deskripsi4
            $this->deskripsi4->LinkCustomAttributes = "";
            $this->deskripsi4->HrefValue = "";
        } elseif ($this->RowType == ROWTYPE_SEARCH) {
            // kode_tapel
            $this->kode_tapel->EditAttrs["class"] = "form-control";
            $this->kode_tapel->EditCustomAttributes = "";
            if (!$this->kode_tapel->Raw) {
                $this->kode_tapel->AdvancedSearch->SearchValue = HtmlDecode($this->kode_tapel->AdvancedSearch->SearchValue);
            }
            $this->kode_tapel->EditValue = HtmlEncode($this->kode_tapel->AdvancedSearch->SearchValue);

            // kelas
            $this->kelas->EditAttrs["class"] = "form-control";
            $this->kelas->EditCustomAttributes = "";
            if (!$Security->isAdmin() && $Security->isLoggedIn() && !$this->userIDAllow($this->CurrentAction)) { // Non system admin
                $this->kelas->AdvancedSearch->SearchValue = CurrentUserID();
                $this->kelas->EditValue = $this->kelas->AdvancedSearch->SearchValue;
                $this->kelas->ViewCustomAttributes = "";
            } else {
                $curVal = trim(strval($this->kelas->AdvancedSearch->SearchValue));
                if ($curVal != "") {
                    $this->kelas->AdvancedSearch->ViewValue = $this->kelas->lookupCacheOption($curVal);
                } else {
                    $this->kelas->AdvancedSearch->ViewValue = $this->kelas->Lookup !== null && is_array($this->kelas->Lookup->Options) ? $curVal : null;
                }
                if ($this->kelas->AdvancedSearch->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->AdvancedSearch->SearchValue, 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;
                }
            }

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

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

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

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

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

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

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

            // ekstra1
            $this->ekstra1->EditAttrs["class"] = "form-control";
            $this->ekstra1->EditCustomAttributes = "";

            // deskripsi1
            $this->deskripsi1->EditAttrs["class"] = "form-control";
            $this->deskripsi1->EditCustomAttributes = "";
            $this->deskripsi1->EditValue = $this->deskripsi1->options(true);

            // ekstra2
            $this->ekstra2->EditAttrs["class"] = "form-control";
            $this->ekstra2->EditCustomAttributes = "";

            // deskripsi2
            $this->deskripsi2->EditAttrs["class"] = "form-control";
            $this->deskripsi2->EditCustomAttributes = "";
            $this->deskripsi2->EditValue = $this->deskripsi2->options(true);

            // ekstra3
            $this->ekstra3->EditAttrs["class"] = "form-control";
            $this->ekstra3->EditCustomAttributes = "";

            // deskripsi3
            $this->deskripsi3->EditAttrs["class"] = "form-control";
            $this->deskripsi3->EditCustomAttributes = "";
            $this->deskripsi3->EditValue = $this->deskripsi3->options(true);

            // ekstra4
            $this->ekstra4->EditAttrs["class"] = "form-control";
            $this->ekstra4->EditCustomAttributes = "";

            // deskripsi4
            $this->deskripsi4->EditAttrs["class"] = "form-control";
            $this->deskripsi4->EditCustomAttributes = "";
            $this->deskripsi4->EditValue = $this->deskripsi4->options(true);
        }
        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 search
    protected function validateSearch()
    {
        // Check if validation required
        if (!Config("SERVER_VALIDATE")) {
            return true;
        }

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

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

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

        // Check if validation required
        if (!Config("SERVER_VALIDATE")) {
            return true;
        }
        if ($this->kode_tapel->Required) {
            if (!$this->kode_tapel->IsDetailKey && EmptyValue($this->kode_tapel->FormValue)) {
                $this->kode_tapel->addErrorMessage(str_replace("%s", $this->kode_tapel->caption(), $this->kode_tapel->RequiredErrorMessage));
            }
        }
        if ($this->kelas->Required) {
            if (!$this->kelas->IsDetailKey && EmptyValue($this->kelas->FormValue)) {
                $this->kelas->addErrorMessage(str_replace("%s", $this->kelas->caption(), $this->kelas->RequiredErrorMessage));
            }
        }
        if ($this->nisn->Required) {
            if (!$this->nisn->IsDetailKey && EmptyValue($this->nisn->FormValue)) {
                $this->nisn->addErrorMessage(str_replace("%s", $this->nisn->caption(), $this->nisn->RequiredErrorMessage));
            }
        }
        if ($this->nis->Required) {
            if (!$this->nis->IsDetailKey && EmptyValue($this->nis->FormValue)) {
                $this->nis->addErrorMessage(str_replace("%s", $this->nis->caption(), $this->nis->RequiredErrorMessage));
            }
        }
        if ($this->nama->Required) {
            if (!$this->nama->IsDetailKey && EmptyValue($this->nama->FormValue)) {
                $this->nama->addErrorMessage(str_replace("%s", $this->nama->caption(), $this->nama->RequiredErrorMessage));
            }
        }
        if ($this->jk->Required) {
            if (!$this->jk->IsDetailKey && EmptyValue($this->jk->FormValue)) {
                $this->jk->addErrorMessage(str_replace("%s", $this->jk->caption(), $this->jk->RequiredErrorMessage));
            }
        }
        if ($this->s->Required) {
            if (!$this->s->IsDetailKey && EmptyValue($this->s->FormValue)) {
                $this->s->addErrorMessage(str_replace("%s", $this->s->caption(), $this->s->RequiredErrorMessage));
            }
        }
        if ($this->_i->Required) {
            if (!$this->_i->IsDetailKey && EmptyValue($this->_i->FormValue)) {
                $this->_i->addErrorMessage(str_replace("%s", $this->_i->caption(), $this->_i->RequiredErrorMessage));
            }
        }
        if ($this->a->Required) {
            if (!$this->a->IsDetailKey && EmptyValue($this->a->FormValue)) {
                $this->a->addErrorMessage(str_replace("%s", $this->a->caption(), $this->a->RequiredErrorMessage));
            }
        }
        if ($this->ekstra1->Required) {
            if (!$this->ekstra1->IsDetailKey && EmptyValue($this->ekstra1->FormValue)) {
                $this->ekstra1->addErrorMessage(str_replace("%s", $this->ekstra1->caption(), $this->ekstra1->RequiredErrorMessage));
            }
        }
        if ($this->deskripsi1->Required) {
            if (!$this->deskripsi1->IsDetailKey && EmptyValue($this->deskripsi1->FormValue)) {
                $this->deskripsi1->addErrorMessage(str_replace("%s", $this->deskripsi1->caption(), $this->deskripsi1->RequiredErrorMessage));
            }
        }
        if ($this->ekstra2->Required) {
            if (!$this->ekstra2->IsDetailKey && EmptyValue($this->ekstra2->FormValue)) {
                $this->ekstra2->addErrorMessage(str_replace("%s", $this->ekstra2->caption(), $this->ekstra2->RequiredErrorMessage));
            }
        }
        if ($this->deskripsi2->Required) {
            if (!$this->deskripsi2->IsDetailKey && EmptyValue($this->deskripsi2->FormValue)) {
                $this->deskripsi2->addErrorMessage(str_replace("%s", $this->deskripsi2->caption(), $this->deskripsi2->RequiredErrorMessage));
            }
        }
        if ($this->ekstra3->Required) {
            if (!$this->ekstra3->IsDetailKey && EmptyValue($this->ekstra3->FormValue)) {
                $this->ekstra3->addErrorMessage(str_replace("%s", $this->ekstra3->caption(), $this->ekstra3->RequiredErrorMessage));
            }
        }
        if ($this->deskripsi3->Required) {
            if (!$this->deskripsi3->IsDetailKey && EmptyValue($this->deskripsi3->FormValue)) {
                $this->deskripsi3->addErrorMessage(str_replace("%s", $this->deskripsi3->caption(), $this->deskripsi3->RequiredErrorMessage));
            }
        }
        if ($this->ekstra4->Required) {
            if (!$this->ekstra4->IsDetailKey && EmptyValue($this->ekstra4->FormValue)) {
                $this->ekstra4->addErrorMessage(str_replace("%s", $this->ekstra4->caption(), $this->ekstra4->RequiredErrorMessage));
            }
        }
        if ($this->deskripsi4->Required) {
            if (!$this->deskripsi4->IsDetailKey && EmptyValue($this->deskripsi4->FormValue)) {
                $this->deskripsi4->addErrorMessage(str_replace("%s", $this->deskripsi4->caption(), $this->deskripsi4->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['absen_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 = [];

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

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

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

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

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

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

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

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

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

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

            // deskripsi4
            $this->deskripsi4->setDbValueDef($rsnew, $this->deskripsi4->CurrentValue, null, $this->deskripsi4->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;
    }

    // Load row hash
    protected function loadRowHash()
    {
        $filter = $this->getRecordFilter();

        // Load SQL based on filter
        $this->CurrentFilter = $filter;
        $sql = $this->getCurrentSql();
        $conn = $this->getConnection();
        $row = $conn->fetchAssoc($sql);
        $this->HashValue = $row ? $this->getRowHash($row) : ""; // Get hash value for record
    }

    // Get Row Hash
    public function getRowHash(&$rs)
    {
        if (!$rs) {
            return "";
        }
        $row = ($rs instanceof Recordset) ? $rs->fields : $rs;
        $hash = "";
        $hash .= GetFieldHash($row['s']); // s
        $hash .= GetFieldHash($row['i']); // i
        $hash .= GetFieldHash($row['a']); // a
        $hash .= GetFieldHash($row['ekstra1']); // ekstra1
        $hash .= GetFieldHash($row['deskripsi1']); // deskripsi1
        $hash .= GetFieldHash($row['ekstra2']); // ekstra2
        $hash .= GetFieldHash($row['deskripsi2']); // deskripsi2
        $hash .= GetFieldHash($row['ekstra3']); // ekstra3
        $hash .= GetFieldHash($row['deskripsi3']); // deskripsi3
        $hash .= GetFieldHash($row['ekstra4']); // ekstra4
        $hash .= GetFieldHash($row['deskripsi4']); // deskripsi4
        return md5($hash);
    }

    // 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;
            }
        }
        $conn = $this->getConnection();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    // Load advanced search
    public function loadAdvancedSearch()
    {
        $this->absen_id->AdvancedSearch->load();
        $this->kode_tapel->AdvancedSearch->load();
        $this->kelas->AdvancedSearch->load();
        $this->nisn->AdvancedSearch->load();
        $this->nis->AdvancedSearch->load();
        $this->nama->AdvancedSearch->load();
        $this->jk->AdvancedSearch->load();
        $this->s->AdvancedSearch->load();
        $this->_i->AdvancedSearch->load();
        $this->a->AdvancedSearch->load();
        $this->ekstra1->AdvancedSearch->load();
        $this->deskripsi1->AdvancedSearch->load();
        $this->ekstra2->AdvancedSearch->load();
        $this->deskripsi2->AdvancedSearch->load();
        $this->ekstra3->AdvancedSearch->load();
        $this->deskripsi3->AdvancedSearch->load();
        $this->ekstra4->AdvancedSearch->load();
        $this->deskripsi4->AdvancedSearch->load();
        $this->catatan_siswa->AdvancedSearch->load();
    }

    // Get export HTML tag
    protected function getExportTag($type, $custom = false)
    {
        global $Language;
        $pageUrl = $this->pageUrl();
        if (SameText($type, "excel")) {
            if ($custom) {
                return "<a href=\"#\" class=\"ew-export-link ew-excel\" title=\"" . HtmlEncode($Language->phrase("ExportToExcelText")) . "\" data-caption=\"" . HtmlEncode($Language->phrase("ExportToExcelText")) . "\" onclick=\"return ew.export(document.fextra_absensilist, '" . $this->ExportExcelUrl . "', 'excel', true);\">" . $Language->phrase("ExportToExcel") . "</a>";
            } else {
                return "<a href=\"" . $this->ExportExcelUrl . "\" class=\"ew-export-link ew-excel\" title=\"" . HtmlEncode($Language->phrase("ExportToExcelText")) . "\" data-caption=\"" . HtmlEncode($Language->phrase("ExportToExcelText")) . "\">" . $Language->phrase("ExportToExcel") . "</a>";
            }
        } elseif (SameText($type, "word")) {
            if ($custom) {
                return "<a href=\"#\" class=\"ew-export-link ew-word\" title=\"" . HtmlEncode($Language->phrase("ExportToWordText")) . "\" data-caption=\"" . HtmlEncode($Language->phrase("ExportToWordText")) . "\" onclick=\"return ew.export(document.fextra_absensilist, '" . $this->ExportWordUrl . "', 'word', true);\">" . $Language->phrase("ExportToWord") . "</a>";
            } else {
                return "<a href=\"" . $this->ExportWordUrl . "\" class=\"ew-export-link ew-word\" title=\"" . HtmlEncode($Language->phrase("ExportToWordText")) . "\" data-caption=\"" . HtmlEncode($Language->phrase("ExportToWordText")) . "\">" . $Language->phrase("ExportToWord") . "</a>";
            }
        } elseif (SameText($type, "pdf")) {
            if ($custom) {
                return "<a href=\"#\" class=\"ew-export-link ew-pdf\" title=\"" . HtmlEncode($Language->phrase("ExportToPDFText")) . "\" data-caption=\"" . HtmlEncode($Language->phrase("ExportToPDFText")) . "\" onclick=\"return ew.export(document.fextra_absensilist, '" . $this->ExportPdfUrl . "', 'pdf', true);\">" . $Language->phrase("ExportToPDF") . "</a>";
            } else {
                return "<a href=\"" . $this->ExportPdfUrl . "\" class=\"ew-export-link ew-pdf\" title=\"" . HtmlEncode($Language->phrase("ExportToPDFText")) . "\" data-caption=\"" . HtmlEncode($Language->phrase("ExportToPDFText")) . "\">" . $Language->phrase("ExportToPDF") . "</a>";
            }
        } elseif (SameText($type, "html")) {
            return "<a href=\"" . $this->ExportHtmlUrl . "\" class=\"ew-export-link ew-html\" title=\"" . HtmlEncode($Language->phrase("ExportToHtmlText")) . "\" data-caption=\"" . HtmlEncode($Language->phrase("ExportToHtmlText")) . "\">" . $Language->phrase("ExportToHtml") . "</a>";
        } elseif (SameText($type, "xml")) {
            return "<a href=\"" . $this->ExportXmlUrl . "\" class=\"ew-export-link ew-xml\" title=\"" . HtmlEncode($Language->phrase("ExportToXmlText")) . "\" data-caption=\"" . HtmlEncode($Language->phrase("ExportToXmlText")) . "\">" . $Language->phrase("ExportToXml") . "</a>";
        } elseif (SameText($type, "csv")) {
            return "<a href=\"" . $this->ExportCsvUrl . "\" class=\"ew-export-link ew-csv\" title=\"" . HtmlEncode($Language->phrase("ExportToCsvText")) . "\" data-caption=\"" . HtmlEncode($Language->phrase("ExportToCsvText")) . "\">" . $Language->phrase("ExportToCsv") . "</a>";
        } elseif (SameText($type, "email")) {
            $url = $custom ? ",url:'" . $pageUrl . "export=email&amp;custom=1'" : "";
            return '<button id="emf_extra_absensi" class="ew-export-link ew-email" title="' . $Language->phrase("ExportToEmailText") . '" data-caption="' . $Language->phrase("ExportToEmailText") . '" onclick="ew.emailDialogShow({lnk:\'emf_extra_absensi\', hdr:ew.language.phrase(\'ExportToEmailText\'), f:document.fextra_absensilist, sel:false' . $url . '});">' . $Language->phrase("ExportToEmail") . '</button>';
        } elseif (SameText($type, "print")) {
            return "<a href=\"" . $this->ExportPrintUrl . "\" class=\"ew-export-link ew-print\" title=\"" . HtmlEncode($Language->phrase("PrinterFriendlyText")) . "\" data-caption=\"" . HtmlEncode($Language->phrase("PrinterFriendlyText")) . "\">" . $Language->phrase("PrinterFriendly") . "</a>";
        }
    }

    // Set up export options
    protected function setupExportOptions()
    {
        global $Language;

        // Printer friendly
        $item = &$this->ExportOptions->add("print");
        $item->Body = $this->getExportTag("print");
        $item->Visible = true;

        // Export to Excel
        $item = &$this->ExportOptions->add("excel");
        $item->Body = $this->getExportTag("excel");
        $item->Visible = true;

        // Export to Word
        $item = &$this->ExportOptions->add("word");
        $item->Body = $this->getExportTag("word");
        $item->Visible = false;

        // Export to Html
        $item = &$this->ExportOptions->add("html");
        $item->Body = $this->getExportTag("html");
        $item->Visible = false;

        // Export to Xml
        $item = &$this->ExportOptions->add("xml");
        $item->Body = $this->getExportTag("xml");
        $item->Visible = false;

        // Export to Csv
        $item = &$this->ExportOptions->add("csv");
        $item->Body = $this->getExportTag("csv");
        $item->Visible = false;

        // Export to Pdf
        $item = &$this->ExportOptions->add("pdf");
        $item->Body = $this->getExportTag("pdf");
        $item->Visible = false;

        // Export to Email
        $item = &$this->ExportOptions->add("email");
        $item->Body = $this->getExportTag("email");
        $item->Visible = false;

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

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

    // Set up search options
    protected function setupSearchOptions()
    {
        global $Language, $Security;
        $pageUrl = $this->pageUrl();
        $this->SearchOptions = new ListOptions("div");
        $this->SearchOptions->TagClassName = "ew-search-option";

        // Search button
        $item = &$this->SearchOptions->add("searchtoggle");
        $searchToggleClass = ($this->SearchWhere != "") ? " active" : "";
        $item->Body = "<a class=\"btn btn-default ew-search-toggle" . $searchToggleClass . "\" href=\"#\" role=\"button\" title=\"" . $Language->phrase("SearchPanel") . "\" data-caption=\"" . $Language->phrase("SearchPanel") . "\" data-toggle=\"button\" data-form=\"fextra_absensilistsrch\" aria-pressed=\"" . ($searchToggleClass == " active" ? "true" : "false") . "\">" . $Language->phrase("SearchLink") . "</a>";
        $item->Visible = true;

        // Show all button
        $item = &$this->SearchOptions->add("showall");
        $item->Body = "<a class=\"btn btn-default ew-show-all\" title=\"" . $Language->phrase("ShowAll") . "\" data-caption=\"" . $Language->phrase("ShowAll") . "\" href=\"" . $pageUrl . "cmd=reset\">" . $Language->phrase("ShowAllBtn") . "</a>";
        $item->Visible = ($this->SearchWhere != $this->DefaultSearchWhere && $this->SearchWhere != "0=101");

        // Button group for search
        $this->SearchOptions->UseDropDownButton = false;
        $this->SearchOptions->UseButtonGroup = true;
        $this->SearchOptions->DropDownButtonPhrase = $Language->phrase("ButtonSearch");

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

        // Hide search options
        if ($this->isExport() || $this->CurrentAction) {
            $this->SearchOptions->hideAllOptions();
        }
        if (!$Security->canSearch()) {
            $this->SearchOptions->hideAllOptions();
            $this->FilterOptions->hideAllOptions();
        }
    }

    /**
    * Export data in HTML/CSV/Word/Excel/XML/Email/PDF format
    *
    * @param bool $return Return the data rather than output it
    * @return mixed
    */
    public function exportData($return = false)
    {
        global $Language;
        $utf8 = SameText(Config("PROJECT_CHARSET"), "utf-8");

        // Load recordset
        $this->TotalRecords = $this->listRecordCount();
        $this->StartRecord = 1;

        // Export all
        if ($this->ExportAll) {
            if (Config("EXPORT_ALL_TIME_LIMIT") >= 0) {
                @set_time_limit(Config("EXPORT_ALL_TIME_LIMIT"));
            }
            $this->DisplayRecords = $this->TotalRecords;
            $this->StopRecord = $this->TotalRecords;
        } else { // Export one page only
            $this->setupStartRecord(); // Set up start record position
            // Set the last record to display
            if ($this->DisplayRecords <= 0) {
                $this->StopRecord = $this->TotalRecords;
            } else {
                $this->StopRecord = $this->StartRecord + $this->DisplayRecords - 1;
            }
        }
        $rs = $this->loadRecordset($this->StartRecord - 1, $this->DisplayRecords <= 0 ? $this->TotalRecords : $this->DisplayRecords);
        $this->ExportDoc = GetExportDocument($this, "h");
        $doc = &$this->ExportDoc;
        if (!$doc) {
            $this->setFailureMessage($Language->phrase("ExportClassNotFound")); // Export class not found
        }
        if (!$rs || !$doc) {
            RemoveHeader("Content-Type"); // Remove header
            RemoveHeader("Content-Disposition");
            $this->showMessage();
            return;
        }
        $this->StartRecord = 1;
        $this->StopRecord = $this->DisplayRecords <= 0 ? $this->TotalRecords : $this->DisplayRecords;

        // Call Page Exporting server event
        $this->ExportDoc->ExportCustom = !$this->pageExporting();
        $header = $this->PageHeader;
        $this->pageDataRendering($header);
        $doc->Text .= $header;
        $this->exportDocument($doc, $rs, $this->StartRecord, $this->StopRecord, "");
        $footer = $this->PageFooter;
        $this->pageDataRendered($footer);
        $doc->Text .= $footer;

        // Close recordset
        $rs->close();

        // Call Page Exported server event
        $this->pageExported();

        // Export header and footer
        $doc->exportHeaderAndFooter();

        // Clean output buffer (without destroying output buffer)
        $buffer = ob_get_contents(); // Save the output buffer
        if (!Config("DEBUG") && $buffer) {
            ob_clean();
        }

        // Write debug message if enabled
        if (Config("DEBUG") && !$this->isExport("pdf")) {
            echo GetDebugMessage();
        }

        // Output data
        if ($this->isExport("email")) {
            // Export-to-email disabled
        } else {
            $doc->export();
            if ($return) {
                RemoveHeader("Content-Type"); // Remove header
                RemoveHeader("Content-Disposition");
                $content = ob_get_contents();
                if ($content) {
                    ob_clean();
                }
                if ($buffer) {
                    echo $buffer; // Resume the output buffer
                }
                return $content;
            }
        }
    }

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

    // Set up Breadcrumb
    protected function setupBreadcrumb()
    {
        global $Breadcrumb, $Language;
        $Breadcrumb = new Breadcrumb("index");
        $url = CurrentUrl();
        $url = preg_replace('/\?cmd=reset(all){0,1}$/i', '', $url); // Remove cmd=reset / cmd=resetall
        $Breadcrumb->add("list", $this->TableVar, $url, "", $this->TableVar, true);
    }

    // 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_kelas":
                    $lookupFilter = function () {
                        return "\"kode_tapel\"='".kode_tapel()."'";
                    };
                    $lookupFilter = $lookupFilter->bindTo($this);
                    break;
                case "x_ekstra1":
                    $lookupFilter = function () {
                        return "`kode_tapel`='".kode_tapel()."'";
                    };
                    $lookupFilter = $lookupFilter->bindTo($this);
                    break;
                case "x_deskripsi1":
                    break;
                case "x_ekstra2":
                    $lookupFilter = function () {
                        return "`kode_tapel`='".kode_tapel()."'";
                    };
                    $lookupFilter = $lookupFilter->bindTo($this);
                    break;
                case "x_deskripsi2":
                    break;
                case "x_ekstra3":
                    $lookupFilter = function () {
                        return "`kode_tapel`='".kode_tapel()."'";
                    };
                    $lookupFilter = $lookupFilter->bindTo($this);
                    break;
                case "x_deskripsi3":
                    break;
                case "x_ekstra4":
                    $lookupFilter = function () {
                        return "`kode_tapel`='".kode_tapel()."'";
                    };
                    $lookupFilter = $lookupFilter->bindTo($this);
                    break;
                case "x_deskripsi4":
                    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;
            }
        }
    }

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

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

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

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

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

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

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

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

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

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

    public function listOptionsLoad() {
    $opt = &$this->ListOptions->Items["sequence"];
    $opt->Header = "#";
    $opt->OnLeft = TRUE; // Link on left
    $opt->MoveTo(1); // Move to first column
    $opt = &$this->ListOptions->Items["button"];
    $opt->Header = "Tool";
    $opt->OnLeft = TRUE; // Link on left
    $opt->MoveTo(2); // 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";
    }

    // Row Custom Action event
    public function rowCustomAction($action, $row)
    {
        // Return false to abort
        return true;
    }

    // Page Exporting event
    // $this->ExportDoc = export document object
    public function pageExporting()
    {
        //$this->ExportDoc->Text = "my header"; // Export header
        //return false; // Return false to skip default export and use Row_Export event
        return true; // Return true to use default export and skip Row_Export event
    }

    // Row Export event
    // $this->ExportDoc = export document object
    public function rowExport($rs)
    {
        //$this->ExportDoc->Text .= "my content"; // Build HTML with field value: $rs["MyField"] or $this->MyField->ViewValue
    }

    // Page Exported event
    // $this->ExportDoc = export document object
    public function pageExported()
    {
        //$this->ExportDoc->Text .= "my footer"; // Export footer
        //Log($this->ExportDoc->Text);
    }

    // Page Importing event
    public function pageImporting($reader, &$options)
    {
        //var_dump($reader); // Import data reader
        //var_dump($options); // Show all options for importing
        //return false; // Return false to skip import
        return true;
    }

    // Row Import event
    public function rowImport(&$row, $cnt)
    {
        //Log($cnt); // Import record count
        //var_dump($row); // Import row
        //return false; // Return false to skip import
        return true;
    }

    // Page Imported event
    public function pageImported($reader, $results)
    {
        //var_dump($reader); // Import data reader
        //var_dump($results); // Import results
    }
}
