<?php

namespace PHPMaker2021\rdigital21;

use Doctrine\DBAL\ParameterType;

/**
 * Table class for nilai_sumatif
 */
class NilaiSumatif 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_s_id;
    public $kode_tapel;
    public $penilaian_id;
    public $guru_id;
    public $kode_mapel;
    public $kelas;
    public $nis;
    public $nisn;
    public $nama;
    public $jk;
    public $s1;
    public $s2;
    public $s3;
    public $s4;
    public $s5;
    public $s6;
    public $s7;
    public $s8;
    public $nas;
    public $sts;
    public $sas;
    public $nr1;
    public $nr2;

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

        // Update Table
        $this->UpdateTable = "\"nilai_sumatif\"";
        $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);

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

        // kode_tapel
        $this->kode_tapel = new DbField('nilai_sumatif', 'nilai_sumatif', '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_sumatif', 'nilai_sumatif', '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_sumatif', 'nilai_sumatif', '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_sumatif', 'nilai_sumatif', '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_sumatif', true, 'kode_mapel', ["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_sumatif', 'nilai_sumatif', '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_sumatif', 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_sumatif', 'nilai_sumatif', '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;

        // nisn
        $this->nisn = new DbField('nilai_sumatif', 'nilai_sumatif', 'x_nisn', 'nisn', '"nisn"', '"nisn"', 203, 0, -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;

        // nama
        $this->nama = new DbField('nilai_sumatif', 'nilai_sumatif', '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_sumatif', 'nilai_sumatif', '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;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    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->nilai_s_id->setDbValue($conn->lastInsertId());
            $rs['nilai_s_id'] = $this->nilai_s_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_s_id', $rs)) {
                AddFilter($where, QuotedName('nilai_s_id', $this->Dbid) . '=' . QuotedValue($rs['nilai_s_id'], $this->nilai_s_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_s_id->DbValue = $row['nilai_s_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->nisn->DbValue = $row['nisn'];
        $this->nama->DbValue = $row['nama'];
        $this->jk->DbValue = $row['jk'];
        $this->s1->DbValue = $row['s1'];
        $this->s2->DbValue = $row['s2'];
        $this->s3->DbValue = $row['s3'];
        $this->s4->DbValue = $row['s4'];
        $this->s5->DbValue = $row['s5'];
        $this->s6->DbValue = $row['s6'];
        $this->s7->DbValue = $row['s7'];
        $this->s8->DbValue = $row['s8'];
        $this->nas->DbValue = $row['nas'];
        $this->sts->DbValue = $row['sts'];
        $this->sas->DbValue = $row['sas'];
        $this->nr1->DbValue = $row['nr1'];
        $this->nr2->DbValue = $row['nr2'];
    }

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

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

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

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

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

    // API page name
    public function getApiPageName($action)
    {
        switch (strtolower($action)) {
            case Config("API_VIEW_ACTION"):
                return "NilaiSumatifView";
            case Config("API_ADD_ACTION"):
                return "NilaiSumatifAdd";
            case Config("API_EDIT_ACTION"):
                return "NilaiSumatifEdit";
            case Config("API_DELETE_ACTION"):
                return "NilaiSumatifDelete";
            case Config("API_LIST_ACTION"):
                return "NilaiSumatifList";
            default:
                return "";
        }
    }

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

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

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

    // Edit URL
    public function getEditUrl($parm = "")
    {
        $url = $this->keyUrl("NilaiSumatifEdit", $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("NilaiSumatifAdd", $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("NilaiSumatifDelete", $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_s_id:" . JsonEncode($this->nilai_s_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_s_id->CurrentValue !== null) {
            $url .= "/" . rawurlencode($this->nilai_s_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_s_id") ?? Route("nilai_s_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_s_id->CurrentValue = $key;
            } else {
                $this->nilai_s_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_s_id->setDbValue($row['nilai_s_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->nisn->setDbValue($row['nisn']);
        $this->nama->setDbValue($row['nama']);
        $this->jk->setDbValue($row['jk']);
        $this->s1->setDbValue($row['s1']);
        $this->s2->setDbValue($row['s2']);
        $this->s3->setDbValue($row['s3']);
        $this->s4->setDbValue($row['s4']);
        $this->s5->setDbValue($row['s5']);
        $this->s6->setDbValue($row['s6']);
        $this->s7->setDbValue($row['s7']);
        $this->s8->setDbValue($row['s8']);
        $this->nas->setDbValue($row['nas']);
        $this->sts->setDbValue($row['sts']);
        $this->sas->setDbValue($row['sas']);
        $this->nr1->setDbValue($row['nr1']);
        $this->nr2->setDbValue($row['nr2']);
    }

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

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

        // Common render codes

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

        // nisn

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        // 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_s_id
        $this->nilai_s_id->EditAttrs["class"] = "form-control";
        $this->nilai_s_id->EditCustomAttributes = "";
        $this->nilai_s_id->EditValue = $this->nilai_s_id->CurrentValue;
        $this->nilai_s_id->ViewCustomAttributes = "";

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        // nr2
        $this->nr2->EditAttrs["class"] = "form-control";
        $this->nr2->EditCustomAttributes = "";
        if (!$this->nr2->Raw) {
            $this->nr2->CurrentValue = HtmlDecode($this->nr2->CurrentValue);
        }
        $this->nr2->EditValue = $this->nr2->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_s_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->nisn);
                    $doc->exportCaption($this->nama);
                    $doc->exportCaption($this->jk);
                    $doc->exportCaption($this->s1);
                    $doc->exportCaption($this->s2);
                    $doc->exportCaption($this->s3);
                    $doc->exportCaption($this->s4);
                    $doc->exportCaption($this->s5);
                    $doc->exportCaption($this->s6);
                    $doc->exportCaption($this->s7);
                    $doc->exportCaption($this->s8);
                    $doc->exportCaption($this->nas);
                    $doc->exportCaption($this->sts);
                    $doc->exportCaption($this->sas);
                    $doc->exportCaption($this->nr1);
                    $doc->exportCaption($this->nr2);
                } else {
                    $doc->exportCaption($this->nilai_s_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->nisn);
                    $doc->exportCaption($this->nama);
                    $doc->exportCaption($this->jk);
                    $doc->exportCaption($this->s1);
                    $doc->exportCaption($this->s2);
                    $doc->exportCaption($this->s3);
                    $doc->exportCaption($this->s4);
                    $doc->exportCaption($this->s5);
                    $doc->exportCaption($this->s6);
                    $doc->exportCaption($this->s7);
                    $doc->exportCaption($this->s8);
                    $doc->exportCaption($this->nas);
                    $doc->exportCaption($this->sts);
                    $doc->exportCaption($this->sas);
                    $doc->exportCaption($this->nr1);
                    $doc->exportCaption($this->nr2);
                }
                $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_s_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->nisn);
                        $doc->exportField($this->nama);
                        $doc->exportField($this->jk);
                        $doc->exportField($this->s1);
                        $doc->exportField($this->s2);
                        $doc->exportField($this->s3);
                        $doc->exportField($this->s4);
                        $doc->exportField($this->s5);
                        $doc->exportField($this->s6);
                        $doc->exportField($this->s7);
                        $doc->exportField($this->s8);
                        $doc->exportField($this->nas);
                        $doc->exportField($this->sts);
                        $doc->exportField($this->sas);
                        $doc->exportField($this->nr1);
                        $doc->exportField($this->nr2);
                    } else {
                        $doc->exportField($this->nilai_s_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->nisn);
                        $doc->exportField($this->nama);
                        $doc->exportField($this->jk);
                        $doc->exportField($this->s1);
                        $doc->exportField($this->s2);
                        $doc->exportField($this->s3);
                        $doc->exportField($this->s4);
                        $doc->exportField($this->s5);
                        $doc->exportField($this->s6);
                        $doc->exportField($this->s7);
                        $doc->exportField($this->s8);
                        $doc->exportField($this->nas);
                        $doc->exportField($this->sts);
                        $doc->exportField($this->sas);
                        $doc->exportField($this->nr1);
                        $doc->exportField($this->nr2);
                    }
                    $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 \"nilai_sumatif\"";
        $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;
    }

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