<?php

namespace PHPMaker2021\rdigital21;

use Doctrine\DBAL\ParameterType;

/**
 * Table class for extra_absensi
 */
class ExtraAbsensi extends DbTable
{
    protected $SqlFrom = "";
    protected $SqlSelect = null;
    protected $SqlSelectList = null;
    protected $SqlWhere = "";
    protected $SqlGroupBy = "";
    protected $SqlHaving = "";
    protected $SqlOrderBy = "";
    public $UseSessionForListSql = true;

    // Column CSS classes
    public $LeftColumnClass = "col-sm-2 col-form-label ew-label";
    public $RightColumnClass = "col-sm-10";
    public $OffsetColumnClass = "col-sm-10 offset-sm-2";
    public $TableLeftColumnClass = "w-col-2";

    // Export
    public $ExportDoc;

    // Fields
    public $absen_id;
    public $kode_tapel;
    public $kelas;
    public $nisn;
    public $nis;
    public $nama;
    public $jk;
    public $s;
    public $_i;
    public $a;
    public $ekstra1;
    public $deskripsi1;
    public $ekstra2;
    public $deskripsi2;
    public $ekstra3;
    public $deskripsi3;
    public $ekstra4;
    public $deskripsi4;
    public $catatan_siswa;

    // Page ID
    public $PageID = ""; // To be overridden by subclass

    // Constructor
    public function __construct()
    {
        global $Language, $CurrentLanguage;
        parent::__construct();

        // Language object
        $Language = Container("language");
        $this->TableVar = 'extra_absensi';
        $this->TableName = 'extra_absensi';
        $this->TableType = 'TABLE';

        // Update Table
        $this->UpdateTable = "\"extra_absensi\"";
        $this->Dbid = 'DB';
        $this->ExportAll = true;
        $this->ExportPageBreakCount = 0; // Page break per every n record (PDF only)
        $this->ExportPageOrientation = "portrait"; // Page orientation (PDF only)
        $this->ExportPageSize = "a4"; // Page size (PDF only)
        $this->ExportExcelPageOrientation = ""; // Page orientation (PhpSpreadsheet only)
        $this->ExportExcelPageSize = ""; // Page size (PhpSpreadsheet only)
        $this->ExportWordPageOrientation = "portrait"; // Page orientation (PHPWord only)
        $this->ExportWordColumnWidth = null; // Cell width (PHPWord only)
        $this->DetailAdd = false; // Allow detail add
        $this->DetailEdit = false; // Allow detail edit
        $this->DetailView = false; // Allow detail view
        $this->ShowMultipleDetails = false; // Show multiple details
        $this->GridAddRowCount = 5;
        $this->AllowAddDeleteRow = true; // Allow add/delete row
        $this->BasicSearch = new BasicSearch($this->TableVar);

        // absen_id
        $this->absen_id = new DbField('extra_absensi', 'extra_absensi', 'x_absen_id', 'absen_id', '"absen_id"', '"absen_id"', 3, 0, -1, false, '"absen_id"', false, false, false, 'FORMATTED TEXT', 'NO');
        $this->absen_id->IsAutoIncrement = true; // Autoincrement field
        $this->absen_id->IsPrimaryKey = true; // Primary key field
        $this->absen_id->Nullable = false; // NOT NULL field
        $this->absen_id->Sortable = true; // Allow sort
        $this->absen_id->DefaultErrorMessage = $Language->phrase("IncorrectInteger");
        $this->absen_id->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->absen_id->Param, "CustomMsg");
        $this->Fields['absen_id'] = &$this->absen_id;

        // kode_tapel
        $this->kode_tapel = new DbField('extra_absensi', 'extra_absensi', 'x_kode_tapel', 'kode_tapel', '"kode_tapel"', '"kode_tapel"', 203, 0, -1, false, '"kode_tapel"', false, false, false, 'FORMATTED TEXT', 'TEXT');
        $this->kode_tapel->Sortable = true; // Allow sort
        $this->kode_tapel->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->kode_tapel->Param, "CustomMsg");
        $this->Fields['kode_tapel'] = &$this->kode_tapel;

        // kelas
        $this->kelas = new DbField('extra_absensi', 'extra_absensi', 'x_kelas', 'kelas', '"kelas"', '"kelas"', 203, 0, -1, false, '"kelas"', false, false, false, 'FORMATTED TEXT', 'SELECT');
        $this->kelas->Sortable = true; // Allow sort
        $this->kelas->UsePleaseSelect = true; // Use PleaseSelect by default
        $this->kelas->PleaseSelectText = $Language->phrase("PleaseSelect"); // "PleaseSelect" text
        $this->kelas->Lookup = new Lookup('kelas', 'extra_absensi', true, 'kelas', ["kelas","","",""], [], [], [], [], [], [], '"kelas" ASC', '');
        $this->kelas->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->kelas->Param, "CustomMsg");
        $this->Fields['kelas'] = &$this->kelas;

        // nisn
        $this->nisn = new DbField('extra_absensi', 'extra_absensi', 'x_nisn', 'nisn', '"nisn"', '"nisn"', 202, 255, -1, false, '"nisn"', false, false, false, 'FORMATTED TEXT', 'TEXT');
        $this->nisn->Sortable = true; // Allow sort
        $this->nisn->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->nisn->Param, "CustomMsg");
        $this->Fields['nisn'] = &$this->nisn;

        // nis
        $this->nis = new DbField('extra_absensi', 'extra_absensi', 'x_nis', 'nis', '"nis"', '"nis"', 202, 255, -1, false, '"nis"', false, false, false, 'FORMATTED TEXT', 'TEXT');
        $this->nis->Sortable = true; // Allow sort
        $this->nis->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->nis->Param, "CustomMsg");
        $this->Fields['nis'] = &$this->nis;

        // nama
        $this->nama = new DbField('extra_absensi', 'extra_absensi', 'x_nama', 'nama', '"nama"', '"nama"', 202, 255, -1, false, '"nama"', false, false, false, 'FORMATTED TEXT', 'TEXT');
        $this->nama->Sortable = true; // Allow sort
        $this->nama->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->nama->Param, "CustomMsg");
        $this->Fields['nama'] = &$this->nama;

        // jk
        $this->jk = new DbField('extra_absensi', 'extra_absensi', 'x_jk', 'jk', '"jk"', '"jk"', 202, 255, -1, false, '"jk"', false, false, false, 'FORMATTED TEXT', 'TEXT');
        $this->jk->Sortable = true; // Allow sort
        $this->jk->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->jk->Param, "CustomMsg");
        $this->Fields['jk'] = &$this->jk;

        // s
        $this->s = new DbField('extra_absensi', 'extra_absensi', 'x_s', 's', '"s"', '"s"', 202, 255, -1, false, '"s"', false, false, false, 'FORMATTED TEXT', 'TEXT');
        $this->s->Sortable = true; // Allow sort
        $this->s->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->s->Param, "CustomMsg");
        $this->Fields['s'] = &$this->s;

        // i
        $this->_i = new DbField('extra_absensi', 'extra_absensi', 'x__i', 'i', '"i"', '"i"', 202, 255, -1, false, '"i"', false, false, false, 'FORMATTED TEXT', 'TEXT');
        $this->_i->Sortable = true; // Allow sort
        $this->_i->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->_i->Param, "CustomMsg");
        $this->Fields['i'] = &$this->_i;

        // a
        $this->a = new DbField('extra_absensi', 'extra_absensi', 'x_a', 'a', '"a"', '"a"', 202, 255, -1, false, '"a"', false, false, false, 'FORMATTED TEXT', 'TEXT');
        $this->a->Sortable = true; // Allow sort
        $this->a->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->a->Param, "CustomMsg");
        $this->Fields['a'] = &$this->a;

        // ekstra1
        $this->ekstra1 = new DbField('extra_absensi', 'extra_absensi', 'x_ekstra1', 'ekstra1', '"ekstra1"', '"ekstra1"', 202, 255, -1, false, '"ekstra1"', false, false, false, 'FORMATTED TEXT', 'SELECT');
        $this->ekstra1->Sortable = true; // Allow sort
        $this->ekstra1->UsePleaseSelect = true; // Use PleaseSelect by default
        $this->ekstra1->PleaseSelectText = $Language->phrase("PleaseSelect"); // "PleaseSelect" text
        $this->ekstra1->Lookup = new Lookup('ekstra1', 'ektrakurikuler', false, 'ektrakurikuler', ["ektrakurikuler","","",""], [], [], [], [], [], [], '', '');
        $this->ekstra1->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->ekstra1->Param, "CustomMsg");
        $this->Fields['ekstra1'] = &$this->ekstra1;

        // deskripsi1
        $this->deskripsi1 = new DbField('extra_absensi', 'extra_absensi', 'x_deskripsi1', 'deskripsi1', '"deskripsi1"', '"deskripsi1"', 202, 255, -1, false, '"deskripsi1"', false, false, false, 'FORMATTED TEXT', 'SELECT');
        $this->deskripsi1->Sortable = true; // Allow sort
        $this->deskripsi1->UsePleaseSelect = true; // Use PleaseSelect by default
        $this->deskripsi1->PleaseSelectText = $Language->phrase("PleaseSelect"); // "PleaseSelect" text
        $this->deskripsi1->Lookup = new Lookup('deskripsi1', 'extra_absensi', false, '', ["","","",""], [], [], [], [], [], [], '', '');
        $this->deskripsi1->OptionCount = 4;
        $this->deskripsi1->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->deskripsi1->Param, "CustomMsg");
        $this->Fields['deskripsi1'] = &$this->deskripsi1;

        // ekstra2
        $this->ekstra2 = new DbField('extra_absensi', 'extra_absensi', 'x_ekstra2', 'ekstra2', '"ekstra2"', '"ekstra2"', 202, 255, -1, false, '"ekstra2"', false, false, false, 'FORMATTED TEXT', 'SELECT');
        $this->ekstra2->Sortable = true; // Allow sort
        $this->ekstra2->UsePleaseSelect = true; // Use PleaseSelect by default
        $this->ekstra2->PleaseSelectText = $Language->phrase("PleaseSelect"); // "PleaseSelect" text
        $this->ekstra2->Lookup = new Lookup('ekstra2', 'ektrakurikuler', false, 'ektrakurikuler', ["ektrakurikuler","","",""], [], [], [], [], [], [], '', '');
        $this->ekstra2->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->ekstra2->Param, "CustomMsg");
        $this->Fields['ekstra2'] = &$this->ekstra2;

        // deskripsi2
        $this->deskripsi2 = new DbField('extra_absensi', 'extra_absensi', 'x_deskripsi2', 'deskripsi2', '"deskripsi2"', '"deskripsi2"', 202, 255, -1, false, '"deskripsi2"', false, false, false, 'FORMATTED TEXT', 'SELECT');
        $this->deskripsi2->Sortable = true; // Allow sort
        $this->deskripsi2->UsePleaseSelect = true; // Use PleaseSelect by default
        $this->deskripsi2->PleaseSelectText = $Language->phrase("PleaseSelect"); // "PleaseSelect" text
        $this->deskripsi2->Lookup = new Lookup('deskripsi2', 'extra_absensi', false, '', ["","","",""], [], [], [], [], [], [], '', '');
        $this->deskripsi2->OptionCount = 4;
        $this->deskripsi2->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->deskripsi2->Param, "CustomMsg");
        $this->Fields['deskripsi2'] = &$this->deskripsi2;

        // ekstra3
        $this->ekstra3 = new DbField('extra_absensi', 'extra_absensi', 'x_ekstra3', 'ekstra3', '"ekstra3"', '"ekstra3"', 202, 255, -1, false, '"ekstra3"', false, false, false, 'FORMATTED TEXT', 'SELECT');
        $this->ekstra3->Sortable = true; // Allow sort
        $this->ekstra3->UsePleaseSelect = true; // Use PleaseSelect by default
        $this->ekstra3->PleaseSelectText = $Language->phrase("PleaseSelect"); // "PleaseSelect" text
        $this->ekstra3->Lookup = new Lookup('ekstra3', 'ektrakurikuler', false, 'ektrakurikuler', ["ektrakurikuler","","",""], [], [], [], [], [], [], '', '');
        $this->ekstra3->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->ekstra3->Param, "CustomMsg");
        $this->Fields['ekstra3'] = &$this->ekstra3;

        // deskripsi3
        $this->deskripsi3 = new DbField('extra_absensi', 'extra_absensi', 'x_deskripsi3', 'deskripsi3', '"deskripsi3"', '"deskripsi3"', 202, 255, -1, false, '"deskripsi3"', false, false, false, 'FORMATTED TEXT', 'SELECT');
        $this->deskripsi3->Sortable = true; // Allow sort
        $this->deskripsi3->UsePleaseSelect = true; // Use PleaseSelect by default
        $this->deskripsi3->PleaseSelectText = $Language->phrase("PleaseSelect"); // "PleaseSelect" text
        $this->deskripsi3->Lookup = new Lookup('deskripsi3', 'extra_absensi', false, '', ["","","",""], [], [], [], [], [], [], '', '');
        $this->deskripsi3->OptionCount = 4;
        $this->deskripsi3->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->deskripsi3->Param, "CustomMsg");
        $this->Fields['deskripsi3'] = &$this->deskripsi3;

        // ekstra4
        $this->ekstra4 = new DbField('extra_absensi', 'extra_absensi', 'x_ekstra4', 'ekstra4', '"ekstra4"', '"ekstra4"', 202, 255, -1, false, '"ekstra4"', false, false, false, 'FORMATTED TEXT', 'SELECT');
        $this->ekstra4->Sortable = true; // Allow sort
        $this->ekstra4->UsePleaseSelect = true; // Use PleaseSelect by default
        $this->ekstra4->PleaseSelectText = $Language->phrase("PleaseSelect"); // "PleaseSelect" text
        $this->ekstra4->Lookup = new Lookup('ekstra4', 'ektrakurikuler', false, 'ektrakurikuler', ["ektrakurikuler","","",""], [], [], [], [], [], [], '', '');
        $this->ekstra4->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->ekstra4->Param, "CustomMsg");
        $this->Fields['ekstra4'] = &$this->ekstra4;

        // deskripsi4
        $this->deskripsi4 = new DbField('extra_absensi', 'extra_absensi', 'x_deskripsi4', 'deskripsi4', '"deskripsi4"', '"deskripsi4"', 202, 255, -1, false, '"deskripsi4"', false, false, false, 'FORMATTED TEXT', 'SELECT');
        $this->deskripsi4->Sortable = true; // Allow sort
        $this->deskripsi4->UsePleaseSelect = true; // Use PleaseSelect by default
        $this->deskripsi4->PleaseSelectText = $Language->phrase("PleaseSelect"); // "PleaseSelect" text
        $this->deskripsi4->Lookup = new Lookup('deskripsi4', 'extra_absensi', false, '', ["","","",""], [], [], [], [], [], [], '', '');
        $this->deskripsi4->OptionCount = 4;
        $this->deskripsi4->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->deskripsi4->Param, "CustomMsg");
        $this->Fields['deskripsi4'] = &$this->deskripsi4;

        // catatan_siswa
        $this->catatan_siswa = new DbField('extra_absensi', 'extra_absensi', 'x_catatan_siswa', 'catatan_siswa', '"catatan_siswa"', '"catatan_siswa"', 203, 0, -1, false, '"catatan_siswa"', false, false, false, 'FORMATTED TEXT', 'TEXTAREA');
        $this->catatan_siswa->Sortable = true; // Allow sort
        $this->catatan_siswa->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->catatan_siswa->Param, "CustomMsg");
        $this->Fields['catatan_siswa'] = &$this->catatan_siswa;
    }

    // Field Visibility
    public function getFieldVisibility($fldParm)
    {
        global $Security;
        return $this->$fldParm->Visible; // Returns original value
    }

    // Set left column class (must be predefined col-*-* classes of Bootstrap grid system)
    public function setLeftColumnClass($class)
    {
        if (preg_match('/^col\-(\w+)\-(\d+)$/', $class, $match)) {
            $this->LeftColumnClass = $class . " col-form-label ew-label";
            $this->RightColumnClass = "col-" . $match[1] . "-" . strval(12 - (int)$match[2]);
            $this->OffsetColumnClass = $this->RightColumnClass . " " . str_replace("col-", "offset-", $class);
            $this->TableLeftColumnClass = preg_replace('/^col-\w+-(\d+)$/', "w-col-$1", $class); // Change to w-col-*
        }
    }

    // Single column sort
    public function updateSort(&$fld)
    {
        if ($this->CurrentOrder == $fld->Name) {
            $sortField = $fld->Expression;
            $lastSort = $fld->getSort();
            if (in_array($this->CurrentOrderType, ["ASC", "DESC", "NO"])) {
                $curSort = $this->CurrentOrderType;
            } else {
                $curSort = $lastSort;
            }
            $fld->setSort($curSort);
            $orderBy = in_array($curSort, ["ASC", "DESC"]) ? $sortField . " " . $curSort : "";
            $this->setSessionOrderBy($orderBy); // Save to Session
        } else {
            $fld->setSort("");
        }
    }

    // Table level SQL
    public function getSqlFrom() // From
    {
        return ($this->SqlFrom != "") ? $this->SqlFrom : "\"extra_absensi\"";
    }

    public function sqlFrom() // For backward compatibility
    {
        return $this->getSqlFrom();
    }

    public function setSqlFrom($v)
    {
        $this->SqlFrom = $v;
    }

    public function getSqlSelect() // Select
    {
        return $this->SqlSelect ?? $this->getQueryBuilder()->select("*");
    }

    public function sqlSelect() // For backward compatibility
    {
        return $this->getSqlSelect();
    }

    public function setSqlSelect($v)
    {
        $this->SqlSelect = $v;
    }

    public function getSqlWhere() // Where
    {
        $where = ($this->SqlWhere != "") ? $this->SqlWhere : "";
        $this->DefaultFilter = "`kode_tapel`='".kode_tapel()."'";
        AddFilter($where, $this->DefaultFilter);
        return $where;
    }

    public function sqlWhere() // For backward compatibility
    {
        return $this->getSqlWhere();
    }

    public function setSqlWhere($v)
    {
        $this->SqlWhere = $v;
    }

    public function getSqlGroupBy() // Group By
    {
        return ($this->SqlGroupBy != "") ? $this->SqlGroupBy : "";
    }

    public function sqlGroupBy() // For backward compatibility
    {
        return $this->getSqlGroupBy();
    }

    public function setSqlGroupBy($v)
    {
        $this->SqlGroupBy = $v;
    }

    public function getSqlHaving() // Having
    {
        return ($this->SqlHaving != "") ? $this->SqlHaving : "";
    }

    public function sqlHaving() // For backward compatibility
    {
        return $this->getSqlHaving();
    }

    public function setSqlHaving($v)
    {
        $this->SqlHaving = $v;
    }

    public function getSqlOrderBy() // Order By
    {
        return ($this->SqlOrderBy != "") ? $this->SqlOrderBy : $this->DefaultSort;
    }

    public function sqlOrderBy() // For backward compatibility
    {
        return $this->getSqlOrderBy();
    }

    public function setSqlOrderBy($v)
    {
        $this->SqlOrderBy = $v;
    }

    // Apply User ID filters
    public function applyUserIDFilters($filter)
    {
        global $Security;
        // Add User ID filter
        if ($Security->currentUserID() != "" && !$Security->isAdmin()) { // Non system admin
            $filter = $this->addUserIDFilter($filter);
        }
        return $filter;
    }

    // Check if User ID security allows view all
    public function userIDAllow($id = "")
    {
        $allow = $this->UserIDAllowSecurity;
        switch ($id) {
            case "add":
            case "copy":
            case "gridadd":
            case "register":
            case "addopt":
                return (($allow & 1) == 1);
            case "edit":
            case "gridedit":
            case "update":
            case "changepassword":
            case "resetpassword":
                return (($allow & 4) == 4);
            case "delete":
                return (($allow & 2) == 2);
            case "view":
                return (($allow & 32) == 32);
            case "search":
                return (($allow & 64) == 64);
            default:
                return (($allow & 8) == 8);
        }
    }

    /**
     * Get record count
     *
     * @param string|QueryBuilder $sql SQL or QueryBuilder
     * @param mixed $c Connection
     * @return int
     */
    public function getRecordCount($sql, $c = null)
    {
        $cnt = -1;
        $rs = null;
        if ($sql instanceof \Doctrine\DBAL\Query\QueryBuilder) { // Query builder
            $sqlwrk = clone $sql;
            $sqlwrk = $sqlwrk->resetQueryPart("orderBy")->getSQL();
        } else {
            $sqlwrk = $sql;
        }
        $pattern = '/^SELECT\s([\s\S]+)\sFROM\s/i';
        // Skip Custom View / SubQuery / SELECT DISTINCT / ORDER BY
        if (
            ($this->TableType == 'TABLE' || $this->TableType == 'VIEW' || $this->TableType == 'LINKTABLE') &&
            preg_match($pattern, $sqlwrk) && !preg_match('/\(\s*(SELECT[^)]+)\)/i', $sqlwrk) &&
            !preg_match('/^\s*select\s+distinct\s+/i', $sqlwrk) && !preg_match('/\s+order\s+by\s+/i', $sqlwrk)
        ) {
            $sqlwrk = "SELECT COUNT(*) FROM " . preg_replace($pattern, "", $sqlwrk);
        } else {
            $sqlwrk = "SELECT COUNT(*) FROM (" . $sqlwrk . ") COUNT_TABLE";
        }
        $conn = $c ?? $this->getConnection();
        $rs = $conn->executeQuery($sqlwrk);
        $cnt = $rs->fetchColumn();
        if ($cnt !== false) {
            return (int)$cnt;
        }

        // Unable to get count by SELECT COUNT(*), execute the SQL to get record count directly
        return ExecuteRecordCount($sql, $conn);
    }

    // Get SQL
    public function getSql($where, $orderBy = "")
    {
        return $this->buildSelectSql(
            $this->getSqlSelect(),
            $this->getSqlFrom(),
            $this->getSqlWhere(),
            $this->getSqlGroupBy(),
            $this->getSqlHaving(),
            $this->getSqlOrderBy(),
            $where,
            $orderBy
        )->getSQL();
    }

    // Table SQL
    public function getCurrentSql()
    {
        $filter = $this->CurrentFilter;
        $filter = $this->applyUserIDFilters($filter);
        $sort = $this->getSessionOrderBy();
        return $this->getSql($filter, $sort);
    }

    /**
     * Table SQL with List page filter
     *
     * @return QueryBuilder
     */
    public function getListSql()
    {
        $filter = $this->UseSessionForListSql ? $this->getSessionWhere() : "";
        AddFilter($filter, $this->CurrentFilter);
        $filter = $this->applyUserIDFilters($filter);
        $this->recordsetSelecting($filter);
        $select = $this->getSqlSelect();
        $from = $this->getSqlFrom();
        $sort = $this->UseSessionForListSql ? $this->getSessionOrderBy() : "";
        $this->Sort = $sort;
        return $this->buildSelectSql(
            $select,
            $from,
            $this->getSqlWhere(),
            $this->getSqlGroupBy(),
            $this->getSqlHaving(),
            $this->getSqlOrderBy(),
            $filter,
            $sort
        );
    }

    // Get ORDER BY clause
    public function getOrderBy()
    {
        $orderBy = $this->getSqlOrderBy();
        $sort = $this->getSessionOrderBy();
        if ($orderBy != "" && $sort != "") {
            $orderBy .= ", " . $sort;
        } elseif ($sort != "") {
            $orderBy = $sort;
        }
        return $orderBy;
    }

    // Get record count based on filter (for detail record count in master table pages)
    public function loadRecordCount($filter)
    {
        $origFilter = $this->CurrentFilter;
        $this->CurrentFilter = $filter;
        $this->recordsetSelecting($this->CurrentFilter);
        $select = $this->TableType == 'CUSTOMVIEW' ? $this->getSqlSelect() : $this->getQueryBuilder()->select("*");
        $groupBy = $this->TableType == 'CUSTOMVIEW' ? $this->getSqlGroupBy() : "";
        $having = $this->TableType == 'CUSTOMVIEW' ? $this->getSqlHaving() : "";
        $sql = $this->buildSelectSql($select, $this->getSqlFrom(), $this->getSqlWhere(), $groupBy, $having, "", $this->CurrentFilter, "");
        $cnt = $this->getRecordCount($sql);
        $this->CurrentFilter = $origFilter;
        return $cnt;
    }

    // Get record count (for current List page)
    public function listRecordCount()
    {
        $filter = $this->getSessionWhere();
        AddFilter($filter, $this->CurrentFilter);
        $filter = $this->applyUserIDFilters($filter);
        $this->recordsetSelecting($filter);
        $select = $this->TableType == 'CUSTOMVIEW' ? $this->getSqlSelect() : $this->getQueryBuilder()->select("*");
        $groupBy = $this->TableType == 'CUSTOMVIEW' ? $this->getSqlGroupBy() : "";
        $having = $this->TableType == 'CUSTOMVIEW' ? $this->getSqlHaving() : "";
        $sql = $this->buildSelectSql($select, $this->getSqlFrom(), $this->getSqlWhere(), $groupBy, $having, "", $filter, "");
        $cnt = $this->getRecordCount($sql);
        return $cnt;
    }

    /**
     * INSERT statement
     *
     * @param mixed $rs
     * @return QueryBuilder
     */
    protected function insertSql(&$rs)
    {
        $queryBuilder = $this->getQueryBuilder();
        $queryBuilder->insert($this->UpdateTable);
        foreach ($rs as $name => $value) {
            if (!isset($this->Fields[$name]) || $this->Fields[$name]->IsCustom) {
                continue;
            }
            $type = GetParameterType($this->Fields[$name], $value, $this->Dbid);
            $queryBuilder->setValue($this->Fields[$name]->Expression, $queryBuilder->createPositionalParameter($value, $type));
        }
        return $queryBuilder;
    }

    // Insert
    public function insert(&$rs)
    {
        $conn = $this->getConnection();
        $success = $this->insertSql($rs)->execute();
        if ($success) {
            // Get insert id if necessary
            $this->absen_id->setDbValue($conn->lastInsertId());
            $rs['absen_id'] = $this->absen_id->DbValue;
        }
        return $success;
    }

    /**
     * UPDATE statement
     *
     * @param array $rs Data to be updated
     * @param string|array $where WHERE clause
     * @param string $curfilter Filter
     * @return QueryBuilder
     */
    protected function updateSql(&$rs, $where = "", $curfilter = true)
    {
        $queryBuilder = $this->getQueryBuilder();
        $queryBuilder->update($this->UpdateTable);
        foreach ($rs as $name => $value) {
            if (!isset($this->Fields[$name]) || $this->Fields[$name]->IsCustom || $this->Fields[$name]->IsAutoIncrement) {
                continue;
            }
            $type = GetParameterType($this->Fields[$name], $value, $this->Dbid);
            $queryBuilder->set($this->Fields[$name]->Expression, $queryBuilder->createPositionalParameter($value, $type));
        }
        $filter = ($curfilter) ? $this->CurrentFilter : "";
        if (is_array($where)) {
            $where = $this->arrayToFilter($where);
        }
        AddFilter($filter, $where);
        if ($filter != "") {
            $queryBuilder->where($filter);
        }
        return $queryBuilder;
    }

    // Update
    public function update(&$rs, $where = "", $rsold = null, $curfilter = true)
    {
        // If no field is updated, execute may return 0. Treat as success
        $success = $this->updateSql($rs, $where, $curfilter)->execute();
        $success = ($success > 0) ? $success : true;
        return $success;
    }

    /**
     * DELETE statement
     *
     * @param array $rs Key values
     * @param string|array $where WHERE clause
     * @param string $curfilter Filter
     * @return QueryBuilder
     */
    protected function deleteSql(&$rs, $where = "", $curfilter = true)
    {
        $queryBuilder = $this->getQueryBuilder();
        $queryBuilder->delete($this->UpdateTable);
        if (is_array($where)) {
            $where = $this->arrayToFilter($where);
        }
        if ($rs) {
            if (array_key_exists('absen_id', $rs)) {
                AddFilter($where, QuotedName('absen_id', $this->Dbid) . '=' . QuotedValue($rs['absen_id'], $this->absen_id->DataType, $this->Dbid));
            }
        }
        $filter = ($curfilter) ? $this->CurrentFilter : "";
        AddFilter($filter, $where);
        return $queryBuilder->where($filter != "" ? $filter : "0=1");
    }

    // Delete
    public function delete(&$rs, $where = "", $curfilter = false)
    {
        $success = true;
        if ($success) {
            $success = $this->deleteSql($rs, $where, $curfilter)->execute();
        }
        return $success;
    }

    // Load DbValue from recordset or array
    protected function loadDbValues($row)
    {
        if (!is_array($row)) {
            return;
        }
        $this->absen_id->DbValue = $row['absen_id'];
        $this->kode_tapel->DbValue = $row['kode_tapel'];
        $this->kelas->DbValue = $row['kelas'];
        $this->nisn->DbValue = $row['nisn'];
        $this->nis->DbValue = $row['nis'];
        $this->nama->DbValue = $row['nama'];
        $this->jk->DbValue = $row['jk'];
        $this->s->DbValue = $row['s'];
        $this->_i->DbValue = $row['i'];
        $this->a->DbValue = $row['a'];
        $this->ekstra1->DbValue = $row['ekstra1'];
        $this->deskripsi1->DbValue = $row['deskripsi1'];
        $this->ekstra2->DbValue = $row['ekstra2'];
        $this->deskripsi2->DbValue = $row['deskripsi2'];
        $this->ekstra3->DbValue = $row['ekstra3'];
        $this->deskripsi3->DbValue = $row['deskripsi3'];
        $this->ekstra4->DbValue = $row['ekstra4'];
        $this->deskripsi4->DbValue = $row['deskripsi4'];
        $this->catatan_siswa->DbValue = $row['catatan_siswa'];
    }

    // Delete uploaded files
    public function deleteUploadedFiles($row)
    {
        $this->loadDbValues($row);
    }

    // Record filter WHERE clause
    protected function sqlKeyFilter()
    {
        return "\"absen_id\" = @absen_id@";
    }

    // Get Key
    public function getKey($current = false)
    {
        $keys = [];
        $val = $current ? $this->absen_id->CurrentValue : $this->absen_id->OldValue;
        if (EmptyValue($val)) {
            return "";
        } else {
            $keys[] = $val;
        }
        return implode(Config("COMPOSITE_KEY_SEPARATOR"), $keys);
    }

    // Set Key
    public function setKey($key, $current = false)
    {
        $this->OldKey = strval($key);
        $keys = explode(Config("COMPOSITE_KEY_SEPARATOR"), $this->OldKey);
        if (count($keys) == 1) {
            if ($current) {
                $this->absen_id->CurrentValue = $keys[0];
            } else {
                $this->absen_id->OldValue = $keys[0];
            }
        }
    }

    // Get record filter
    public function getRecordFilter($row = null)
    {
        $keyFilter = $this->sqlKeyFilter();
        if (is_array($row)) {
            $val = array_key_exists('absen_id', $row) ? $row['absen_id'] : null;
        } else {
            $val = $this->absen_id->OldValue !== null ? $this->absen_id->OldValue : $this->absen_id->CurrentValue;
        }
        if (!is_numeric($val)) {
            return "0=1"; // Invalid key
        }
        if ($val === null) {
            return "0=1"; // Invalid key
        } else {
            $keyFilter = str_replace("@absen_id@", AdjustSql($val, $this->Dbid), $keyFilter); // Replace key value
        }
        return $keyFilter;
    }

    // Return page URL
    public function getReturnUrl()
    {
        $referUrl = ReferUrl();
        $referPageName = ReferPageName();
        $name = PROJECT_NAME . "_" . $this->TableVar . "_" . Config("TABLE_RETURN_URL");
        // Get referer URL automatically
        if ($referUrl != "" && $referPageName != CurrentPageName() && $referPageName != "login") { // Referer not same page or login page
            $_SESSION[$name] = $referUrl; // Save to Session
        }
        return $_SESSION[$name] ?? GetUrl("ExtraAbsensiList");
    }

    // Set return page URL
    public function setReturnUrl($v)
    {
        $_SESSION[PROJECT_NAME . "_" . $this->TableVar . "_" . Config("TABLE_RETURN_URL")] = $v;
    }

    // Get modal caption
    public function getModalCaption($pageName)
    {
        global $Language;
        if ($pageName == "ExtraAbsensiView") {
            return $Language->phrase("View");
        } elseif ($pageName == "ExtraAbsensiEdit") {
            return $Language->phrase("Edit");
        } elseif ($pageName == "ExtraAbsensiAdd") {
            return $Language->phrase("Add");
        } else {
            return "";
        }
    }

    // API page name
    public function getApiPageName($action)
    {
        switch (strtolower($action)) {
            case Config("API_VIEW_ACTION"):
                return "ExtraAbsensiView";
            case Config("API_ADD_ACTION"):
                return "ExtraAbsensiAdd";
            case Config("API_EDIT_ACTION"):
                return "ExtraAbsensiEdit";
            case Config("API_DELETE_ACTION"):
                return "ExtraAbsensiDelete";
            case Config("API_LIST_ACTION"):
                return "ExtraAbsensiList";
            default:
                return "";
        }
    }

    // List URL
    public function getListUrl()
    {
        return "ExtraAbsensiList";
    }

    // View URL
    public function getViewUrl($parm = "")
    {
        if ($parm != "") {
            $url = $this->keyUrl("ExtraAbsensiView", $this->getUrlParm($parm));
        } else {
            $url = $this->keyUrl("ExtraAbsensiView", $this->getUrlParm(Config("TABLE_SHOW_DETAIL") . "="));
        }
        return $this->addMasterUrl($url);
    }

    // Add URL
    public function getAddUrl($parm = "")
    {
        if ($parm != "") {
            $url = "ExtraAbsensiAdd?" . $this->getUrlParm($parm);
        } else {
            $url = "ExtraAbsensiAdd";
        }
        return $this->addMasterUrl($url);
    }

    // Edit URL
    public function getEditUrl($parm = "")
    {
        $url = $this->keyUrl("ExtraAbsensiEdit", $this->getUrlParm($parm));
        return $this->addMasterUrl($url);
    }

    // Inline edit URL
    public function getInlineEditUrl()
    {
        $url = $this->keyUrl(CurrentPageName(), $this->getUrlParm("action=edit"));
        return $this->addMasterUrl($url);
    }

    // Copy URL
    public function getCopyUrl($parm = "")
    {
        $url = $this->keyUrl("ExtraAbsensiAdd", $this->getUrlParm($parm));
        return $this->addMasterUrl($url);
    }

    // Inline copy URL
    public function getInlineCopyUrl()
    {
        $url = $this->keyUrl(CurrentPageName(), $this->getUrlParm("action=copy"));
        return $this->addMasterUrl($url);
    }

    // Delete URL
    public function getDeleteUrl()
    {
        return $this->keyUrl("ExtraAbsensiDelete", $this->getUrlParm());
    }

    // Add master url
    public function addMasterUrl($url)
    {
        return $url;
    }

    public function keyToJson($htmlEncode = false)
    {
        $json = "";
        $json .= "absen_id:" . JsonEncode($this->absen_id->CurrentValue, "number");
        $json = "{" . $json . "}";
        if ($htmlEncode) {
            $json = HtmlEncode($json);
        }
        return $json;
    }

    // Add key value to URL
    public function keyUrl($url, $parm = "")
    {
        if ($this->absen_id->CurrentValue !== null) {
            $url .= "/" . rawurlencode($this->absen_id->CurrentValue);
        } else {
            return "javascript:ew.alert(ew.language.phrase('InvalidRecord'));";
        }
        if ($parm != "") {
            $url .= "?" . $parm;
        }
        return $url;
    }

    // Render sort
    public function renderSort($fld)
    {
        $classId = $fld->TableVar . "_" . $fld->Param;
        $scriptId = str_replace("%id%", $classId, "tpc_%id%");
        $scriptStart = $this->UseCustomTemplate ? "<template id=\"" . $scriptId . "\">" : "";
        $scriptEnd = $this->UseCustomTemplate ? "</template>" : "";
        $jsSort = " class=\"ew-pointer\" onclick=\"ew.sort(event, '" . $this->sortUrl($fld) . "', 1);\"";
        if ($this->sortUrl($fld) == "") {
            $html = <<<NOSORTHTML
{$scriptStart}<div class="ew-table-header-caption">{$fld->caption()}</div>{$scriptEnd}
NOSORTHTML;
        } else {
            if ($fld->getSort() == "ASC") {
                $sortIcon = '<i class="fas fa-sort-up"></i>';
            } elseif ($fld->getSort() == "DESC") {
                $sortIcon = '<i class="fas fa-sort-down"></i>';
            } else {
                $sortIcon = '';
            }
            $html = <<<SORTHTML
{$scriptStart}<div{$jsSort}><div class="ew-table-header-btn"><span class="ew-table-header-caption">{$fld->caption()}</span><span class="ew-table-header-sort">{$sortIcon}</span></div></div>{$scriptEnd}
SORTHTML;
        }
        return $html;
    }

    // Sort URL
    public function sortUrl($fld)
    {
        if (
            $this->CurrentAction || $this->isExport() ||
            in_array($fld->Type, [141, 201, 203, 128, 204, 205])
        ) { // Unsortable data type
                return "";
        } elseif ($fld->Sortable) {
            $urlParm = $this->getUrlParm("order=" . urlencode($fld->Name) . "&amp;ordertype=" . $fld->getNextSort());
            return $this->addMasterUrl(CurrentPageName() . "?" . $urlParm);
        } else {
            return "";
        }
    }

    // Get record keys from Post/Get/Session
    public function getRecordKeys()
    {
        $arKeys = [];
        $arKey = [];
        if (Param("key_m") !== null) {
            $arKeys = Param("key_m");
            $cnt = count($arKeys);
        } else {
            if (($keyValue = Param("absen_id") ?? Route("absen_id")) !== null) {
                $arKeys[] = $keyValue;
            } elseif (IsApi() && (($keyValue = Key(0) ?? Route(2)) !== null)) {
                $arKeys[] = $keyValue;
            } else {
                $arKeys = null; // Do not setup
            }

            //return $arKeys; // Do not return yet, so the values will also be checked by the following code
        }
        // Check keys
        $ar = [];
        if (is_array($arKeys)) {
            foreach ($arKeys as $key) {
                if (!is_numeric($key)) {
                    continue;
                }
                $ar[] = $key;
            }
        }
        return $ar;
    }

    // Get filter from record keys
    public function getFilterFromRecordKeys($setCurrent = true)
    {
        $arKeys = $this->getRecordKeys();
        $keyFilter = "";
        foreach ($arKeys as $key) {
            if ($keyFilter != "") {
                $keyFilter .= " OR ";
            }
            if ($setCurrent) {
                $this->absen_id->CurrentValue = $key;
            } else {
                $this->absen_id->OldValue = $key;
            }
            $keyFilter .= "(" . $this->getRecordFilter() . ")";
        }
        return $keyFilter;
    }

    // Load recordset based on filter
    public function &loadRs($filter)
    {
        $sql = $this->getSql($filter); // Set up filter (WHERE Clause)
        $conn = $this->getConnection();
        $stmt = $conn->executeQuery($sql);
        return $stmt;
    }

    // Load row values from record
    public function loadListRowValues(&$rs)
    {
        if (is_array($rs)) {
            $row = $rs;
        } elseif ($rs && property_exists($rs, "fields")) { // Recordset
            $row = $rs->fields;
        } else {
            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']);
    }

    // Render list row values
    public function renderListRow()
    {
        global $Security, $CurrentLanguage, $Language;

        // Call Row Rendering event
        $this->rowRendering();

        // Common render codes

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

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

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

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

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

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

        // Call Row Rendered event
        $this->rowRendered();

        // Save data for Custom Template
        $this->Rows[] = $this->customTemplateFieldValues();
    }

    // Render edit row values
    public function renderEditRow()
    {
        global $Security, $CurrentLanguage, $Language;

        // Call Row Rendering event
        $this->rowRendering();

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

        // 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 = $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 = $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 = $this->a->CurrentValue;

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

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

        // Call Row Rendered event
        $this->rowRendered();
    }

    // Aggregate list row values
    public function aggregateListRowValues()
    {
    }

    // Aggregate list row (for rendering)
    public function aggregateListRow()
    {
        // Call Row Rendered event
        $this->rowRendered();
    }

    // Export data in HTML/CSV/Word/Excel/Email/PDF format
    public function exportDocument($doc, $recordset, $startRec = 1, $stopRec = 1, $exportPageType = "")
    {
        if (!$recordset || !$doc) {
            return;
        }
        if (!$doc->ExportCustom) {
            // Write header
            $doc->exportTableHeader();
            if ($doc->Horizontal) { // Horizontal format, write header
                $doc->beginExportRow();
                if ($exportPageType == "view") {
                    $doc->exportCaption($this->absen_id);
                    $doc->exportCaption($this->kode_tapel);
                    $doc->exportCaption($this->kelas);
                    $doc->exportCaption($this->nisn);
                    $doc->exportCaption($this->nis);
                    $doc->exportCaption($this->nama);
                    $doc->exportCaption($this->jk);
                    $doc->exportCaption($this->s);
                    $doc->exportCaption($this->_i);
                    $doc->exportCaption($this->a);
                    $doc->exportCaption($this->ekstra1);
                    $doc->exportCaption($this->deskripsi1);
                    $doc->exportCaption($this->ekstra2);
                    $doc->exportCaption($this->deskripsi2);
                    $doc->exportCaption($this->ekstra3);
                    $doc->exportCaption($this->deskripsi3);
                    $doc->exportCaption($this->ekstra4);
                    $doc->exportCaption($this->deskripsi4);
                } else {
                    $doc->exportCaption($this->absen_id);
                    $doc->exportCaption($this->kode_tapel);
                    $doc->exportCaption($this->kelas);
                    $doc->exportCaption($this->nisn);
                    $doc->exportCaption($this->nis);
                    $doc->exportCaption($this->nama);
                    $doc->exportCaption($this->jk);
                    $doc->exportCaption($this->s);
                    $doc->exportCaption($this->_i);
                    $doc->exportCaption($this->a);
                    $doc->exportCaption($this->ekstra1);
                    $doc->exportCaption($this->deskripsi1);
                    $doc->exportCaption($this->ekstra2);
                    $doc->exportCaption($this->deskripsi2);
                    $doc->exportCaption($this->ekstra3);
                    $doc->exportCaption($this->deskripsi3);
                    $doc->exportCaption($this->ekstra4);
                    $doc->exportCaption($this->deskripsi4);
                }
                $doc->endExportRow();
            }
        }

        // Move to first record
        $recCnt = $startRec - 1;
        $stopRec = ($stopRec > 0) ? $stopRec : PHP_INT_MAX;
        while (!$recordset->EOF && $recCnt < $stopRec) {
            $row = $recordset->fields;
            $recCnt++;
            if ($recCnt >= $startRec) {
                $rowCnt = $recCnt - $startRec + 1;

                // Page break
                if ($this->ExportPageBreakCount > 0) {
                    if ($rowCnt > 1 && ($rowCnt - 1) % $this->ExportPageBreakCount == 0) {
                        $doc->exportPageBreak();
                    }
                }
                $this->loadListRowValues($row);

                // Render row
                $this->RowType = ROWTYPE_VIEW; // Render view
                $this->resetAttributes();
                $this->renderListRow();
                if (!$doc->ExportCustom) {
                    $doc->beginExportRow($rowCnt); // Allow CSS styles if enabled
                    if ($exportPageType == "view") {
                        $doc->exportField($this->absen_id);
                        $doc->exportField($this->kode_tapel);
                        $doc->exportField($this->kelas);
                        $doc->exportField($this->nisn);
                        $doc->exportField($this->nis);
                        $doc->exportField($this->nama);
                        $doc->exportField($this->jk);
                        $doc->exportField($this->s);
                        $doc->exportField($this->_i);
                        $doc->exportField($this->a);
                        $doc->exportField($this->ekstra1);
                        $doc->exportField($this->deskripsi1);
                        $doc->exportField($this->ekstra2);
                        $doc->exportField($this->deskripsi2);
                        $doc->exportField($this->ekstra3);
                        $doc->exportField($this->deskripsi3);
                        $doc->exportField($this->ekstra4);
                        $doc->exportField($this->deskripsi4);
                    } else {
                        $doc->exportField($this->absen_id);
                        $doc->exportField($this->kode_tapel);
                        $doc->exportField($this->kelas);
                        $doc->exportField($this->nisn);
                        $doc->exportField($this->nis);
                        $doc->exportField($this->nama);
                        $doc->exportField($this->jk);
                        $doc->exportField($this->s);
                        $doc->exportField($this->_i);
                        $doc->exportField($this->a);
                        $doc->exportField($this->ekstra1);
                        $doc->exportField($this->deskripsi1);
                        $doc->exportField($this->ekstra2);
                        $doc->exportField($this->deskripsi2);
                        $doc->exportField($this->ekstra3);
                        $doc->exportField($this->deskripsi3);
                        $doc->exportField($this->ekstra4);
                        $doc->exportField($this->deskripsi4);
                    }
                    $doc->endExportRow($rowCnt);
                }
            }

            // Call Row Export server event
            if ($doc->ExportCustom) {
                $this->rowExport($row);
            }
            $recordset->moveNext();
        }
        if (!$doc->ExportCustom) {
            $doc->exportTableFooter();
        }
    }

    // Add User ID filter
    public function addUserIDFilter($filter = "")
    {
        global $Security;
        $filterWrk = "";
        $id = (CurrentPageID() == "list") ? $this->CurrentAction : CurrentPageID();
        if (!$this->userIDAllow($id) && !$Security->isAdmin()) {
            $filterWrk = $Security->userIdList();
            if ($filterWrk != "") {
                $filterWrk = '"kelas" IN (' . $filterWrk . ')';
            }
        }

        // Call User ID Filtering event
        $this->userIdFiltering($filterWrk);
        AddFilter($filter, $filterWrk);
        return $filter;
    }

    // User ID subquery
    public function getUserIDSubquery(&$fld, &$masterfld)
    {
        global $UserTable;
        $wrk = "";
        $sql = "SELECT " . $masterfld->Expression . " FROM \"extra_absensi\"";
        $filter = $this->addUserIDFilter("");
        if ($filter != "") {
            $sql .= " WHERE " . $filter;
        }

        // List all values
        if ($rs = Conn($UserTable->Dbid)->executeQuery($sql)->fetchAll(\PDO::FETCH_NUM)) {
            foreach ($rs as $row) {
                if ($wrk != "") {
                    $wrk .= ",";
                }
                $wrk .= QuotedValue($row[0], $masterfld->DataType, Config("USER_TABLE_DBID"));
            }
        }
        if ($wrk != "") {
            $wrk = $fld->Expression . " IN (" . $wrk . ")";
        } else { // No User ID value found
            $wrk = "0=1";
        }
        return $wrk;
    }

    // Get file data
    public function getFileData($fldparm, $key, $resize, $width = 0, $height = 0, $plugins = [])
    {
        // No binary fields
        return false;
    }

    // Table level events

    // Recordset Selecting event
    public function recordsetSelecting(&$filter)
    {
        // Enter your code here
    }

    // Recordset Selected event
    public function recordsetSelected(&$rs)
    {
        //Log("Recordset Selected");
    }

    // Recordset Search Validated event
    public function recordsetSearchValidated()
    {
        // Example:
        //$this->MyField1->AdvancedSearch->SearchValue = "your search criteria"; // Search value
    }

    // Recordset Searching event
    public function recordsetSearching(&$filter)
    {
        // Enter your code here
    }

    // Row_Selecting event
    public function rowSelecting(&$filter)
    {
        // Enter your code here
    }

    // Row Selected event
    public function rowSelected(&$rs)
    {
        //Log("Row Selected");
    }

    // Row Inserting event
    public function rowInserting($rsold, &$rsnew)
    {
        // Enter your code here
        // To cancel, set return value to false
        return true;
    }

    // Row Inserted event
    public function rowInserted($rsold, &$rsnew)
    {
        //Log("Row Inserted");
    }

    // Row Updating event
    public function rowUpdating($rsold, &$rsnew)
    {
        // Enter your code here
        // To cancel, set return value to false
        return true;
    }

    // Row Updated event
    public function rowUpdated($rsold, &$rsnew)
    {
        //Log("Row Updated");
    }

    // Row Update Conflict event
    public function rowUpdateConflict($rsold, &$rsnew)
    {
        // Enter your code here
        // To ignore conflict, set return value to false
        return true;
    }

    // Grid Inserting event
    public function gridInserting()
    {
        // Enter your code here
        // To reject grid insert, set return value to false
        return true;
    }

    // Grid Inserted event
    public function gridInserted($rsnew)
    {
        //Log("Grid Inserted");
    }

    // Grid Updating event
    public function gridUpdating($rsold)
    {
        // Enter your code here
        // To reject grid update, set return value to false
        return true;
    }

    // Grid Updated event
    public function gridUpdated($rsold, $rsnew)
    {
        //Log("Grid Updated");
    }

    // Row Deleting event
    public function rowDeleting(&$rs)
    {
        // Enter your code here
        // To cancel, set return value to False
        return true;
    }

    // Row Deleted event
    public function rowDeleted(&$rs)
    {
        //Log("Row Deleted");
    }

    // Email Sending event
    public function emailSending($email, &$args)
    {
        //var_dump($email); var_dump($args); exit();
        return true;
    }

    // Lookup Selecting event
    public function lookupSelecting($fld, &$filter)
    {
        //var_dump($fld->Name, $fld->Lookup, $filter); // Uncomment to view the filter
        // Enter your code here
    }

    // Row Rendering event
    public function rowRendering()
    {
        // Enter your code here
    }

    // Row Rendered event
    public function rowRendered()
    {
        // To view properties of field class, use:
        //var_dump($this-><FieldName>);
    }

    // User ID Filtering event
    public function userIdFiltering(&$filter)
    {
        // Enter your code here
    }
}
