<?php

namespace PHPMaker2021\rdigital21;

use Doctrine\DBAL\ParameterType;

/**
 * Table class for nilai_formatif
 */
class NilaiFormatif 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 $nilai_f_id;
    public $kode_tapel;
    public $penilaian_id;
    public $guru_id;
    public $kode_mapel;
    public $kelas;
    public $nis;
    public $nama;
    public $jk;
    public $f1;
    public $f2;
    public $f3;
    public $f4;
    public $f5;
    public $f6;
    public $f7;
    public $f8;
    public $f9;
    public $f10;
    public $f11;
    public $f12;
    public $f13;
    public $f14;
    public $f15;
    public $naf;

    // 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 = 'nilai_formatif';
        $this->TableName = 'nilai_formatif';
        $this->TableType = 'TABLE';

        // Update Table
        $this->UpdateTable = "\"nilai_formatif\"";
        $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->UserIDAllowSecurity = Config("DEFAULT_USER_ID_ALLOW_SECURITY"); // Default User ID allowed permissions
        $this->BasicSearch = new BasicSearch($this->TableVar);

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

        // kode_tapel
        $this->kode_tapel = new DbField('nilai_formatif', 'nilai_formatif', 'x_kode_tapel', 'kode_tapel', '"kode_tapel"', '"kode_tapel"', 203, 255, -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;

        // penilaian_id
        $this->penilaian_id = new DbField('nilai_formatif', 'nilai_formatif', 'x_penilaian_id', 'penilaian_id', '"penilaian_id"', '"penilaian_id"', 203, 255, -1, false, '"penilaian_id"', false, false, false, 'FORMATTED TEXT', 'TEXT');
        $this->penilaian_id->IsForeignKey = true; // Foreign key field
        $this->penilaian_id->Sortable = true; // Allow sort
        $this->penilaian_id->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->penilaian_id->Param, "CustomMsg");
        $this->Fields['penilaian_id'] = &$this->penilaian_id;

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

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

        // kelas
        $this->kelas = new DbField('nilai_formatif', 'nilai_formatif', 'x_kelas', 'kelas', '"kelas"', '"kelas"', 203, 255, -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', 'nilai_formatif', true, 'kelas', ["kelas","","",""], [], [], [], [], [], [], '"kelas" ASC', '');
        $this->kelas->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->kelas->Param, "CustomMsg");
        $this->Fields['kelas'] = &$this->kelas;

        // nis
        $this->nis = new DbField('nilai_formatif', 'nilai_formatif', 'x_nis', 'nis', '"nis"', '"nis"', 203, 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('nilai_formatif', 'nilai_formatif', 'x_nama', 'nama', '"nama"', '"nama"', 203, 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('nilai_formatif', 'nilai_formatif', 'x_jk', 'jk', '"jk"', '"jk"', 203, 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;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        // naf
        $this->naf = new DbField('nilai_formatif', 'nilai_formatif', 'x_naf', 'naf', '"naf"', '"naf"', 203, 255, -1, false, '"naf"', false, false, false, 'FORMATTED TEXT', 'TEXT');
        $this->naf->Sortable = true; // Allow sort
        $this->naf->CustomMsg = $Language->FieldPhrase($this->TableVar, $this->naf->Param, "CustomMsg");
        $this->Fields['naf'] = &$this->naf;
    }

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

    // Current master table name
    public function getCurrentMasterTable()
    {
        return Session(PROJECT_NAME . "_" . $this->TableVar . "_" . Config("TABLE_MASTER_TABLE"));
    }

    public function setCurrentMasterTable($v)
    {
        $_SESSION[PROJECT_NAME . "_" . $this->TableVar . "_" . Config("TABLE_MASTER_TABLE")] = $v;
    }

    // Session master WHERE clause
    public function getMasterFilter()
    {
        // Master filter
        $masterFilter = "";
        if ($this->getCurrentMasterTable() == "penilaian") {
            if ($this->penilaian_id->getSessionValue() != "") {
                $masterFilter .= "" . GetForeignKeySql("\"penilaian_id\"", $this->penilaian_id->getSessionValue(), DATATYPE_NUMBER, "DB");
            } else {
                return "";
            }
        }
        return $masterFilter;
    }

    // Session detail WHERE clause
    public function getDetailFilter()
    {
        // Detail filter
        $detailFilter = "";
        if ($this->getCurrentMasterTable() == "penilaian") {
            if ($this->penilaian_id->getSessionValue() != "") {
                $detailFilter .= "" . GetForeignKeySql("\"penilaian_id\"", $this->penilaian_id->getSessionValue(), DATATYPE_MEMO, "DB");
            } else {
                return "";
            }
        }
        return $detailFilter;
    }

    // Master filter
    public function sqlMasterFilter_penilaian()
    {
        return "\"penilaian_id\"=@penilaian_id@";
    }
    // Detail filter
    public function sqlDetailFilter_penilaian()
    {
        return "\"penilaian_id\"='@penilaian_id@'";
    }

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

    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
            if ($this->getCurrentMasterTable() == "penilaian" || $this->getCurrentMasterTable() == "") {
                $filter = $this->addDetailUserIDFilter($filter, "penilaian"); // Add detail User ID 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->nilai_f_id->setDbValue($conn->lastInsertId());
            $rs['nilai_f_id'] = $this->nilai_f_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('nilai_f_id', $rs)) {
                AddFilter($where, QuotedName('nilai_f_id', $this->Dbid) . '=' . QuotedValue($rs['nilai_f_id'], $this->nilai_f_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->nilai_f_id->DbValue = $row['nilai_f_id'];
        $this->kode_tapel->DbValue = $row['kode_tapel'];
        $this->penilaian_id->DbValue = $row['penilaian_id'];
        $this->guru_id->DbValue = $row['guru_id'];
        $this->kode_mapel->DbValue = $row['kode_mapel'];
        $this->kelas->DbValue = $row['kelas'];
        $this->nis->DbValue = $row['nis'];
        $this->nama->DbValue = $row['nama'];
        $this->jk->DbValue = $row['jk'];
        $this->f1->DbValue = $row['f1'];
        $this->f2->DbValue = $row['f2'];
        $this->f3->DbValue = $row['f3'];
        $this->f4->DbValue = $row['f4'];
        $this->f5->DbValue = $row['f5'];
        $this->f6->DbValue = $row['f6'];
        $this->f7->DbValue = $row['f7'];
        $this->f8->DbValue = $row['f8'];
        $this->f9->DbValue = $row['f9'];
        $this->f10->DbValue = $row['f10'];
        $this->f11->DbValue = $row['f11'];
        $this->f12->DbValue = $row['f12'];
        $this->f13->DbValue = $row['f13'];
        $this->f14->DbValue = $row['f14'];
        $this->f15->DbValue = $row['f15'];
        $this->naf->DbValue = $row['naf'];
    }

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

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

    // Get Key
    public function getKey($current = false)
    {
        $keys = [];
        $val = $current ? $this->nilai_f_id->CurrentValue : $this->nilai_f_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->nilai_f_id->CurrentValue = $keys[0];
            } else {
                $this->nilai_f_id->OldValue = $keys[0];
            }
        }
    }

    // Get record filter
    public function getRecordFilter($row = null)
    {
        $keyFilter = $this->sqlKeyFilter();
        if (is_array($row)) {
            $val = array_key_exists('nilai_f_id', $row) ? $row['nilai_f_id'] : null;
        } else {
            $val = $this->nilai_f_id->OldValue !== null ? $this->nilai_f_id->OldValue : $this->nilai_f_id->CurrentValue;
        }
        if (!is_numeric($val)) {
            return "0=1"; // Invalid key
        }
        if ($val === null) {
            return "0=1"; // Invalid key
        } else {
            $keyFilter = str_replace("@nilai_f_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("NilaiFormatifList");
    }

    // 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 == "NilaiFormatifView") {
            return $Language->phrase("View");
        } elseif ($pageName == "NilaiFormatifEdit") {
            return $Language->phrase("Edit");
        } elseif ($pageName == "NilaiFormatifAdd") {
            return $Language->phrase("Add");
        } else {
            return "";
        }
    }

    // API page name
    public function getApiPageName($action)
    {
        switch (strtolower($action)) {
            case Config("API_VIEW_ACTION"):
                return "NilaiFormatifView";
            case Config("API_ADD_ACTION"):
                return "NilaiFormatifAdd";
            case Config("API_EDIT_ACTION"):
                return "NilaiFormatifEdit";
            case Config("API_DELETE_ACTION"):
                return "NilaiFormatifDelete";
            case Config("API_LIST_ACTION"):
                return "NilaiFormatifList";
            default:
                return "";
        }
    }

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

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

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

    // Edit URL
    public function getEditUrl($parm = "")
    {
        $url = $this->keyUrl("NilaiFormatifEdit", $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("NilaiFormatifAdd", $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("NilaiFormatifDelete", $this->getUrlParm());
    }

    // Add master url
    public function addMasterUrl($url)
    {
        if ($this->getCurrentMasterTable() == "penilaian" && !ContainsString($url, Config("TABLE_SHOW_MASTER") . "=")) {
            $url .= (ContainsString($url, "?") ? "&" : "?") . Config("TABLE_SHOW_MASTER") . "=" . $this->getCurrentMasterTable();
            $url .= "&" . GetForeignKeyUrl("fk_penilaian_id", $this->penilaian_id->CurrentValue ?? $this->penilaian_id->getSessionValue());
        }
        return $url;
    }

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

    // Add key value to URL
    public function keyUrl($url, $parm = "")
    {
        if ($this->nilai_f_id->CurrentValue !== null) {
            $url .= "/" . rawurlencode($this->nilai_f_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("nilai_f_id") ?? Route("nilai_f_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->nilai_f_id->CurrentValue = $key;
            } else {
                $this->nilai_f_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->nilai_f_id->setDbValue($row['nilai_f_id']);
        $this->kode_tapel->setDbValue($row['kode_tapel']);
        $this->penilaian_id->setDbValue($row['penilaian_id']);
        $this->guru_id->setDbValue($row['guru_id']);
        $this->kode_mapel->setDbValue($row['kode_mapel']);
        $this->kelas->setDbValue($row['kelas']);
        $this->nis->setDbValue($row['nis']);
        $this->nama->setDbValue($row['nama']);
        $this->jk->setDbValue($row['jk']);
        $this->f1->setDbValue($row['f1']);
        $this->f2->setDbValue($row['f2']);
        $this->f3->setDbValue($row['f3']);
        $this->f4->setDbValue($row['f4']);
        $this->f5->setDbValue($row['f5']);
        $this->f6->setDbValue($row['f6']);
        $this->f7->setDbValue($row['f7']);
        $this->f8->setDbValue($row['f8']);
        $this->f9->setDbValue($row['f9']);
        $this->f10->setDbValue($row['f10']);
        $this->f11->setDbValue($row['f11']);
        $this->f12->setDbValue($row['f12']);
        $this->f13->setDbValue($row['f13']);
        $this->f14->setDbValue($row['f14']);
        $this->f15->setDbValue($row['f15']);
        $this->naf->setDbValue($row['naf']);
    }

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

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

        // Common render codes

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        // penilaian_id
        $this->penilaian_id->EditAttrs["class"] = "form-control";
        $this->penilaian_id->EditCustomAttributes = "";
        if ($this->penilaian_id->getSessionValue() != "") {
            $this->penilaian_id->CurrentValue = GetForeignKeyValue($this->penilaian_id->getSessionValue());
            $this->penilaian_id->ViewValue = $this->penilaian_id->CurrentValue;
            $this->penilaian_id->ViewCustomAttributes = "";
        } else {
            if (!$this->penilaian_id->Raw) {
                $this->penilaian_id->CurrentValue = HtmlDecode($this->penilaian_id->CurrentValue);
            }
            $this->penilaian_id->EditValue = $this->penilaian_id->CurrentValue;
        }

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

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

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

        // nis
        $this->nis->EditAttrs["class"] = "form-control";
        $this->nis->EditCustomAttributes = "";
        if (!$this->nis->Raw) {
            $this->nis->CurrentValue = HtmlDecode($this->nis->CurrentValue);
        }
        $this->nis->EditValue = $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 = $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 = $this->jk->CurrentValue;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        // naf
        $this->naf->EditAttrs["class"] = "form-control";
        $this->naf->EditCustomAttributes = "";
        if (!$this->naf->Raw) {
            $this->naf->CurrentValue = HtmlDecode($this->naf->CurrentValue);
        }
        $this->naf->EditValue = $this->naf->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->nilai_f_id);
                    $doc->exportCaption($this->kode_tapel);
                    $doc->exportCaption($this->penilaian_id);
                    $doc->exportCaption($this->guru_id);
                    $doc->exportCaption($this->kode_mapel);
                    $doc->exportCaption($this->kelas);
                    $doc->exportCaption($this->nis);
                    $doc->exportCaption($this->nama);
                    $doc->exportCaption($this->jk);
                    $doc->exportCaption($this->f1);
                    $doc->exportCaption($this->f2);
                    $doc->exportCaption($this->f3);
                    $doc->exportCaption($this->f4);
                    $doc->exportCaption($this->f5);
                    $doc->exportCaption($this->f6);
                    $doc->exportCaption($this->f7);
                    $doc->exportCaption($this->f8);
                    $doc->exportCaption($this->f9);
                    $doc->exportCaption($this->f10);
                    $doc->exportCaption($this->f11);
                    $doc->exportCaption($this->f12);
                    $doc->exportCaption($this->f13);
                    $doc->exportCaption($this->f14);
                    $doc->exportCaption($this->f15);
                    $doc->exportCaption($this->naf);
                } else {
                    $doc->exportCaption($this->nilai_f_id);
                    $doc->exportCaption($this->kode_tapel);
                    $doc->exportCaption($this->penilaian_id);
                    $doc->exportCaption($this->guru_id);
                    $doc->exportCaption($this->kode_mapel);
                    $doc->exportCaption($this->kelas);
                    $doc->exportCaption($this->nis);
                    $doc->exportCaption($this->nama);
                    $doc->exportCaption($this->jk);
                    $doc->exportCaption($this->f1);
                    $doc->exportCaption($this->f2);
                    $doc->exportCaption($this->f3);
                    $doc->exportCaption($this->f4);
                    $doc->exportCaption($this->f5);
                    $doc->exportCaption($this->f6);
                    $doc->exportCaption($this->f7);
                    $doc->exportCaption($this->f8);
                    $doc->exportCaption($this->f9);
                    $doc->exportCaption($this->f10);
                    $doc->exportCaption($this->f11);
                    $doc->exportCaption($this->f12);
                    $doc->exportCaption($this->f13);
                    $doc->exportCaption($this->f14);
                    $doc->exportCaption($this->f15);
                    $doc->exportCaption($this->naf);
                }
                $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->nilai_f_id);
                        $doc->exportField($this->kode_tapel);
                        $doc->exportField($this->penilaian_id);
                        $doc->exportField($this->guru_id);
                        $doc->exportField($this->kode_mapel);
                        $doc->exportField($this->kelas);
                        $doc->exportField($this->nis);
                        $doc->exportField($this->nama);
                        $doc->exportField($this->jk);
                        $doc->exportField($this->f1);
                        $doc->exportField($this->f2);
                        $doc->exportField($this->f3);
                        $doc->exportField($this->f4);
                        $doc->exportField($this->f5);
                        $doc->exportField($this->f6);
                        $doc->exportField($this->f7);
                        $doc->exportField($this->f8);
                        $doc->exportField($this->f9);
                        $doc->exportField($this->f10);
                        $doc->exportField($this->f11);
                        $doc->exportField($this->f12);
                        $doc->exportField($this->f13);
                        $doc->exportField($this->f14);
                        $doc->exportField($this->f15);
                        $doc->exportField($this->naf);
                    } else {
                        $doc->exportField($this->nilai_f_id);
                        $doc->exportField($this->kode_tapel);
                        $doc->exportField($this->penilaian_id);
                        $doc->exportField($this->guru_id);
                        $doc->exportField($this->kode_mapel);
                        $doc->exportField($this->kelas);
                        $doc->exportField($this->nis);
                        $doc->exportField($this->nama);
                        $doc->exportField($this->jk);
                        $doc->exportField($this->f1);
                        $doc->exportField($this->f2);
                        $doc->exportField($this->f3);
                        $doc->exportField($this->f4);
                        $doc->exportField($this->f5);
                        $doc->exportField($this->f6);
                        $doc->exportField($this->f7);
                        $doc->exportField($this->f8);
                        $doc->exportField($this->f9);
                        $doc->exportField($this->f10);
                        $doc->exportField($this->f11);
                        $doc->exportField($this->f12);
                        $doc->exportField($this->f13);
                        $doc->exportField($this->f14);
                        $doc->exportField($this->f15);
                        $doc->exportField($this->naf);
                    }
                    $doc->endExportRow($rowCnt);
                }
            }

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

    // Add master User ID filter
    public function addMasterUserIDFilter($filter, $currentMasterTable)
    {
        $filterWrk = $filter;
        if ($currentMasterTable == "penilaian") {
            $filterWrk = Container("penilaian")->addUserIDFilter($filterWrk);
        }
        return $filterWrk;
    }

    // Add detail User ID filter
    public function addDetailUserIDFilter($filter, $currentMasterTable)
    {
        $filterWrk = $filter;
        if ($currentMasterTable == "penilaian") {
            $mastertable = Container("penilaian");
            if (!$mastertable->userIdAllow()) {
                $subqueryWrk = $mastertable->getUserIDSubquery($this->penilaian_id, $mastertable->penilaian_id);
                AddFilter($filterWrk, $subqueryWrk);
            }
        }
        return $filterWrk;
    }

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