<?php
namespace PHPMaker2019\project_germanos;

/**
 * Page class
 */
class employeeperson_grid extends employeeperson
{

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

	// Project ID
	public $ProjectID = "{8D47CED4-FEF0-4756-8F48-9FC38A15AA2A}";

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

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

	// Grid form hidden field names
	public $FormName = "femployeepersongrid";
	public $FormActionName = "k_action";
	public $FormKeyName = "k_key";
	public $FormOldKeyName = "k_oldkey";
	public $FormBlankRowName = "k_blankrow";
	public $FormKeyCountName = "key_count";

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

	// Audit Trail
	public $AuditTrailOnAdd = TRUE;
	public $AuditTrailOnEdit = TRUE;
	public $AuditTrailOnDelete = TRUE;
	public $AuditTrailOnView = FALSE;
	public $AuditTrailOnViewData = FALSE;
	public $AuditTrailOnSearch = FALSE;

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

	// Token
	public $Token = "";
	public $TokenTimeout = 0;
	public $CheckToken = CHECK_TOKEN;

	// Messages
	private $_message = "";
	private $_failureMessage = "";
	private $_successMessage = "";
	private $_warningMessage = "";

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

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

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

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

	// Get message
	public function getMessage()
	{
		return isset($_SESSION[SESSION_MESSAGE]) ? $_SESSION[SESSION_MESSAGE] : $this->_message;
	}

	// Set message
	public function setMessage($v)
	{
		AddMessage($this->_message, $v);
		$_SESSION[SESSION_MESSAGE] = $this->_message;
	}

	// Get failure message
	public function getFailureMessage()
	{
		return isset($_SESSION[SESSION_FAILURE_MESSAGE]) ? $_SESSION[SESSION_FAILURE_MESSAGE] : $this->_failureMessage;
	}

	// Set failure message
	public function setFailureMessage($v)
	{
		AddMessage($this->_failureMessage, $v);
		$_SESSION[SESSION_FAILURE_MESSAGE] = $this->_failureMessage;
	}

	// Get success message
	public function getSuccessMessage()
	{
		return isset($_SESSION[SESSION_SUCCESS_MESSAGE]) ? $_SESSION[SESSION_SUCCESS_MESSAGE] : $this->_successMessage;
	}

	// Set success message
	public function setSuccessMessage($v)
	{
		AddMessage($this->_successMessage, $v);
		$_SESSION[SESSION_SUCCESS_MESSAGE] = $this->_successMessage;
	}

	// Get warning message
	public function getWarningMessage()
	{
		return isset($_SESSION[SESSION_WARNING_MESSAGE]) ? $_SESSION[SESSION_WARNING_MESSAGE] : $this->_warningMessage;
	}

	// Set warning message
	public function setWarningMessage($v)
	{
		AddMessage($this->_warningMessage, $v);
		$_SESSION[SESSION_WARNING_MESSAGE] = $this->_warningMessage;
	}

	// Clear message
	public function clearMessage()
	{
		$this->_message = "";
		$_SESSION[SESSION_MESSAGE] = "";
	}

	// Clear failure message
	public function clearFailureMessage()
	{
		$this->_failureMessage = "";
		$_SESSION[SESSION_FAILURE_MESSAGE] = "";
	}

	// Clear success message
	public function clearSuccessMessage()
	{
		$this->_successMessage = "";
		$_SESSION[SESSION_SUCCESS_MESSAGE] = "";
	}

	// Clear warning message
	public function clearWarningMessage()
	{
		$this->_warningMessage = "";
		$_SESSION[SESSION_WARNING_MESSAGE] = "";
	}

	// Clear messages
	public function clearMessages()
	{
		$this->clearMessage();
		$this->clearFailureMessage();
		$this->clearSuccessMessage();
		$this->clearWarningMessage();
	}

	// Show message
	public function showMessage()
	{
		$hidden = FALSE;
		$html = "";

		// Message
		$message = $this->getMessage();
		if (method_exists($this, "Message_Showing"))
			$this->Message_Showing($message, "");
		if ($message <> "") { // Message in Session, display
			if (!$hidden)
				$message = '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' . $message;
			$html .= '<div class="alert alert-info alert-dismissible ew-info"><i class="icon fa fa-info"></i>' . $message . '</div>';
			$_SESSION[SESSION_MESSAGE] = ""; // Clear message in Session
		}

		// Warning message
		$warningMessage = $this->getWarningMessage();
		if (method_exists($this, "Message_Showing"))
			$this->Message_Showing($warningMessage, "warning");
		if ($warningMessage <> "") { // Message in Session, display
			if (!$hidden)
				$warningMessage = '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' . $warningMessage;
			$html .= '<div class="alert alert-warning alert-dismissible ew-warning"><i class="icon fa fa-warning"></i>' . $warningMessage . '</div>';
			$_SESSION[SESSION_WARNING_MESSAGE] = ""; // Clear message in Session
		}

		// Success message
		$successMessage = $this->getSuccessMessage();
		if (method_exists($this, "Message_Showing"))
			$this->Message_Showing($successMessage, "success");
		if ($successMessage <> "") { // Message in Session, display
			if (!$hidden)
				$successMessage = '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' . $successMessage;
			$html .= '<div class="alert alert-success alert-dismissible ew-success"><i class="icon fa fa-check"></i>' . $successMessage . '</div>';
			$_SESSION[SESSION_SUCCESS_MESSAGE] = ""; // Clear message in Session
		}

		// Failure message
		$errorMessage = $this->getFailureMessage();
		if (method_exists($this, "Message_Showing"))
			$this->Message_Showing($errorMessage, "failure");
		if ($errorMessage <> "") { // Message in Session, display
			if (!$hidden)
				$errorMessage = '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' . $errorMessage;
			$html .= '<div class="alert alert-danger alert-dismissible ew-error"><i class="icon fa fa-ban"></i>' . $errorMessage . '</div>';
			$_SESSION[SESSION_FAILURE_MESSAGE] = ""; // Clear message in Session
		}
		echo '<div class="ew-message-dialog' . (($hidden) ? ' d-none' : "") . '">' . $html . '</div>';
	}

	// Get message as array
	public function getMessages()
	{
		$ar = array();

		// Message
		$message = $this->getMessage();

		//if (method_exists($this, "Message_Showing"))
		//	$this->Message_Showing($message, "");

		if ($message <> "") { // Message in Session, display
			$ar["message"] = $message;
			$_SESSION[SESSION_MESSAGE] = ""; // Clear message in Session
		}

		// Warning message
		$warningMessage = $this->getWarningMessage();

		//if (method_exists($this, "Message_Showing"))
		//	$this->Message_Showing($warningMessage, "warning");

		if ($warningMessage <> "") { // Message in Session, display
			$ar["warningMessage"] = $warningMessage;
			$_SESSION[SESSION_WARNING_MESSAGE] = ""; // Clear message in Session
		}

		// Success message
		$successMessage = $this->getSuccessMessage();

		//if (method_exists($this, "Message_Showing"))
		//	$this->Message_Showing($successMessage, "success");

		if ($successMessage <> "") { // Message in Session, display
			$ar["successMessage"] = $successMessage;
			$_SESSION[SESSION_SUCCESS_MESSAGE] = ""; // Clear message in Session
		}

		// Failure message
		$failureMessage = $this->getFailureMessage();

		//if (method_exists($this, "Message_Showing"))
		//	$this->Message_Showing($failureMessage, "failure");

		if ($failureMessage <> "") { // Message in Session, display
			$ar["failureMessage"] = $failureMessage;
			$_SESSION[SESSION_FAILURE_MESSAGE] = ""; // Clear message in Session
		}
		return $ar;
	}

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

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

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

	// Valid Post
	protected function validPost()
	{
		if (!$this->CheckToken || !IsPost() || IsApi())
			return TRUE;
		if (Post(TOKEN_NAME) === NULL)
			return FALSE;
		$fn = PROJECT_NAMESPACE . CHECK_TOKEN_FUNC;
		if (is_callable($fn))
			return $fn(Post(TOKEN_NAME), $this->TokenTimeout);
		return FALSE;
	}

	// Create Token
	public function createToken()
	{
		global $CurrentToken;
		$fn = PROJECT_NAMESPACE . CREATE_TOKEN_FUNC; // Always create token, required by API file/lookup request
		if ($this->Token == "" && is_callable($fn)) // Create token
			$this->Token = $fn();
		$CurrentToken = $this->Token; // Save to global variable
	}

	// Constructor
	public function __construct()
	{
		global $Language, $COMPOSITE_KEY_SEPARATOR;
		global $UserTable, $UserTableConn;

		// Initialize
		$this->FormActionName .= "_" . $this->FormName;
		$this->FormKeyName .= "_" . $this->FormName;
		$this->FormOldKeyName .= "_" . $this->FormName;
		$this->FormBlankRowName .= "_" . $this->FormName;
		$this->FormKeyCountName .= "_" . $this->FormName;
		$GLOBALS["Grid"] = &$this;
		$this->TokenTimeout = SessionTimeoutTime();

		// Language object
		if (!isset($Language))
			$Language = new Language();

		// Parent constuctor
		parent::__construct();

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

			// $GLOBALS["MasterTable"] = &$GLOBALS["Table"];
			// if (!isset($GLOBALS["Table"]))
			// 	$GLOBALS["Table"] = &$GLOBALS["employeeperson"];

		}
		$this->AddUrl = "employeepersonadd.php";

		// Table object (employees)
		if (!isset($GLOBALS['employees']))
			$GLOBALS['employees'] = new employees();

		// Page ID
		if (!defined(PROJECT_NAMESPACE . "PAGE_ID"))
			define(PROJECT_NAMESPACE . "PAGE_ID", 'grid');

		// Table name (for backward compatibility)
		if (!defined(PROJECT_NAMESPACE . "TABLE_NAME"))
			define(PROJECT_NAMESPACE . "TABLE_NAME", 'employeeperson');

		// Start timer
		if (!isset($GLOBALS["DebugTimer"]))
			$GLOBALS["DebugTimer"] = new Timer();

		// Debug message
		LoadDebugMessage();

		// Open connection
		if (!isset($GLOBALS["Conn"]))
			$GLOBALS["Conn"] = &$this->getConnection();

		// User table object (employees)
		if (!isset($UserTable)) {
			$UserTable = new employees();
			$UserTableConn = Conn($UserTable->Dbid);
		}

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

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

	// Terminate page
	public function terminate($url = "")
	{
		global $ExportFileName, $TempImages;

		// Export
		global $EXPORT, $employeeperson;
		if ($this->CustomExport && $this->CustomExport == $this->Export && array_key_exists($this->CustomExport, $EXPORT)) {
				$content = ob_get_contents();
			if ($ExportFileName == "")
				$ExportFileName = $this->TableVar;
			$class = PROJECT_NAMESPACE . $EXPORT[$this->CustomExport];
			if (class_exists($class)) {
				$doc = new $class($employeeperson);
				$doc->Text = @$content;
				if ($this->isExport("email"))
					echo $this->exportEmail($doc->Text);
				else
					$doc->export();
				DeleteTempImages(); // Delete temp images
				exit();
			}
		}

//		$GLOBALS["Table"] = &$GLOBALS["MasterTable"];
		unset($GLOBALS["Grid"]);
		if ($url === "")
			return;
		if (!IsApi())
			$this->Page_Redirecting($url);

		// Return for API
		if (IsApi()) {
			$res = $url === TRUE;
			if (!$res) // Show error
				WriteJson(array_merge(["success" => FALSE], $this->getMessages()));
			return;
		}

		// Go to URL if specified
		if ($url <> "") {
			if (!DEBUG_ENABLED && ob_get_length())
				ob_end_clean();
			SaveDebugMessage();
			AddHeader("Location", $url);
		}
		exit();
	}

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

	// Get record from array
	protected function getRecordFromArray($ar)
	{
		$row = array();
		if (is_array($ar)) {
			foreach ($ar as $fldname => $val) {
				if (array_key_exists($fldname, $this->fields) && ($this->fields[$fldname]->Visible || $this->fields[$fldname]->IsPrimaryKey)) { // Primary key or Visible
					$fld = &$this->fields[$fldname];
					if ($fld->HtmlTag == "FILE") { // Upload field
						if (EmptyValue($val)) {
							$row[$fldname] = NULL;
						} else {
							if ($fld->DataType == DATATYPE_BLOB) {

								//$url = FullUrl($fld->TableVar . "/" . API_FILE_ACTION . "/" . $fld->Param . "/" . rawurlencode($this->getRecordKeyValue($ar))); // URL rewrite format
								$url = FullUrl(GetPageName(API_URL) . "?" . API_OBJECT_NAME . "=" . $fld->TableVar . "&" . API_ACTION_NAME . "=" . API_FILE_ACTION . "&" . API_FIELD_NAME . "=" . $fld->Param . "&" . API_KEY_NAME . "=" . rawurlencode($this->getRecordKeyValue($ar))); // Query string format
								$row[$fldname] = ["mimeType" => ContentType($val), "url" => $url];
							} elseif (!$fld->UploadMultiple || !ContainsString($val, MULTIPLE_UPLOAD_SEPARATOR)) { // Single file
								$row[$fldname] = ["mimeType" => MimeContentType($val), "url" => FullUrl($fld->hrefPath() . $val)];
							} else { // Multiple files
								$files = explode(MULTIPLE_UPLOAD_SEPARATOR, $val);
								$ar = [];
								foreach ($files as $file) {
									if (!EmptyValue($file))
										$ar[] = ["type" => MimeContentType($file), "url" => FullUrl($fld->hrefPath() . $file)];
								}
								$row[$fldname] = $ar;
							}
						}
					} else {
						$row[$fldname] = $val;
					}
				}
			}
		}
		return $row;
	}

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

	/**
	 * Hide fields for add/edit
	 *
	 * @return void
	 */
	protected function hideFieldsForAddEdit()
	{
		if ($this->isAdd() || $this->isCopy() || $this->isGridAdd())
			$this->EmployeePersonID->Visible = FALSE;
	}

	// Class variables
	public $ListOptions; // List options
	public $ExportOptions; // Export options
	public $SearchOptions; // Search options
	public $OtherOptions; // Other options
	public $FilterOptions; // Filter options
	public $ImportOptions; // Import options
	public $ListActions; // List actions
	public $SelectedCount = 0;
	public $SelectedIndex = 0;
	public $ShowOtherOptions = FALSE;
	public $DisplayRecs = 10;
	public $StartRec;
	public $StopRec;
	public $TotalRecs = 0;
	public $RecRange = 10;
	public $Pager;
	public $AutoHidePager = AUTO_HIDE_PAGER;
	public $AutoHidePageSizeSelector = AUTO_HIDE_PAGE_SIZE_SELECTOR;
	public $DefaultSearchWhere = ""; // Default search WHERE clause
	public $SearchWhere = ""; // Search WHERE clause
	public $RecCnt = 0; // Record count
	public $EditRowCnt;
	public $StartRowCnt = 1;
	public $RowCnt = 0;
	public $Attrs = array(); // Row attributes and cell attributes
	public $RowIndex = 0; // Row index
	public $KeyCount = 0; // Key count
	public $RowAction = ""; // Row action
	public $RowOldKey = ""; // Row old key (for copy)
	public $MultiColumnClass = "col-sm";
	public $MultiColumnEditClass = "w-100";
	public $DbMasterFilter = ""; // Master filter
	public $DbDetailFilter = ""; // Detail filter
	public $MasterRecordExists;
	public $MultiSelectKey;
	public $Command;
	public $RestoreSearch = FALSE;
	public $DetailPages;
	public $OldRecordset;

	//
	// Page run
	//

	public function run()
	{
		global $ExportType, $CustomExportType, $ExportFileName, $UserProfile, $Language, $Security, $RequestSecurity, $CurrentForm,
			$FormError, $SearchError, $EXPORT;

		// Init Session data for API request if token found
		if (IsApi() && session_status() !== PHP_SESSION_ACTIVE) {
			$func = PROJECT_NAMESPACE . CHECK_TOKEN_FUNC;
			if (is_callable($func) && Param(TOKEN_NAME) !== NULL && $func(Param(TOKEN_NAME), SessionTimeoutTime()))
				session_start();
		}

		// User profile
		$UserProfile = new UserProfile();

		// Security
		$Security = new AdvancedSecurity();
		$validRequest = FALSE;

		// Check security for API request
		If (IsApi()) {

			// Check token first
			$func = PROJECT_NAMESPACE . CHECK_TOKEN_FUNC;
			if (is_callable($func) && Post(TOKEN_NAME) !== NULL)
				$validRequest = $func(Post(TOKEN_NAME), SessionTimeoutTime());
			elseif (is_array($RequestSecurity) && @$RequestSecurity["username"] <> "") // Login user for API request
				$Security->loginUser(@$RequestSecurity["username"], @$RequestSecurity["userid"], @$RequestSecurity["parentuserid"], @$RequestSecurity["userlevelid"]);
		}
		if (!$validRequest) {
			if (IsPasswordExpired())
				$this->terminate(GetUrl("changepwd.php"));
			if (!$Security->isLoggedIn())
				$Security->autoLogin();
			if ($Security->isLoggedIn())
				$Security->TablePermission_Loading();
			$Security->loadCurrentUserLevel($this->ProjectID . $this->TableName);
			if ($Security->isLoggedIn())
				$Security->TablePermission_Loaded();
			if (!$Security->canList()) {
				$Security->saveLastUrl();
				$this->setFailureMessage(DeniedMessage()); // Set no permission
				$this->terminate(GetUrl("index.php"));
				return;
			}
			if ($Security->isLoggedIn()) {
				$Security->UserID_Loading();
				$Security->loadUserID();
				$Security->UserID_Loaded();
			}
		}

		// Update last accessed time
		if ($UserProfile->isValidUser(CurrentUserName(), session_id())) {
		} else {
			Write($Language->phrase("UserProfileCorrupted"));
			$this->terminate();
		}

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

		// Set up list options
		$this->setupListOptions();
		$this->EmployeePersonID->Visible = FALSE;
		$this->EmployeeID->setVisibility();
		$this->MaritalStatusID->setVisibility();
		$this->CivilStatus23->setVisibility();
		$this->CivilStatusPlace->setVisibility();
		$this->IdCard23->setVisibility();
		$this->PracticingProfessionLicense23->setVisibility();
		$this->NationalId23->setVisibility();
		$this->Nationality1->setVisibility();
		$this->Nationality2->setVisibility();
		$this->Nationality3->setVisibility();
		$this->DriverLicense23->setVisibility();
		$this->Extra23->setVisibility();
		$this->Notes->Visible = FALSE;
		$this->_UserID->Visible = FALSE;
		$this->CreatedBy->Visible = FALSE;
		$this->CreatedDate->Visible = FALSE;
		$this->UpdatedBy->Visible = FALSE;
		$this->UpdatedDate->Visible = FALSE;
		$this->hideFieldsForAddEdit();

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

		// Page Load event
		$this->Page_Load();

		// Check token
		if (!$this->validPost()) {
			Write($Language->phrase("InvalidPostRequest"));
			$this->terminate();
		}

		// Create Token
		$this->createToken();

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

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

		// Set up lookup cache
		$this->setupLookupOptions($this->EmployeeID);
		$this->setupLookupOptions($this->MaritalStatusID);

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

		// Get command
		$this->Command = strtolower(Get("cmd"));
		if ($this->isPageRequest()) { // Validate request

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

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

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

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

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

		// Restore display records
		if ($this->Command <> "json" && $this->getRecordsPerPage() <> "") {
			$this->DisplayRecs = $this->getRecordsPerPage(); // Restore from Session
		} else {
			$this->DisplayRecs = 10; // Load default
		}

		// Load Sorting Order
		if ($this->Command <> "json")
			$this->loadSortOrder();

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

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

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

		// Load master record
		if ($this->CurrentMode <> "add" && $this->getMasterFilter() <> "" && $this->getCurrentMasterTable() == "employees") {
			global $employees;
			$rsmaster = $employees->loadRs($this->DbMasterFilter);
			$this->MasterRecordExists = ($rsmaster && !$rsmaster->EOF);
			if (!$this->MasterRecordExists) {
				$this->setFailureMessage($Language->phrase("NoRecord")); // Set no record found
				$this->terminate("employeeslist.php"); // Return to master page
			} else {
				$employees->loadListRowValues($rsmaster);
				$employees->RowType = ROWTYPE_MASTER; // Master row
				$employees->renderListRow();
				$rsmaster->close();
			}
		}

		// Set up filter
		if ($this->Command == "json") {
			$this->UseSessionForListSql = FALSE; // Do not use session for ListSQL
			$this->CurrentFilter = $filter;
		} else {
			$this->setSessionWhere($filter);
			$this->CurrentFilter = "";
		}
		if ($this->isGridAdd()) {
			if ($this->CurrentMode == "copy") {
				$selectLimit = $this->UseSelectLimit;
				if ($selectLimit) {
					$this->TotalRecs = $this->listRecordCount();
					$this->Recordset = $this->loadRecordset($this->StartRec - 1, $this->DisplayRecs);
				} else {
					if ($this->Recordset = $this->loadRecordset())
						$this->TotalRecs = $this->Recordset->RecordCount();
				}
				$this->StartRec = 1;
				$this->DisplayRecs = $this->TotalRecs;
			} else {
				$this->CurrentFilter = "0=1";
				$this->StartRec = 1;
				$this->DisplayRecs = $this->GridAddRowCount;
			}
			$this->TotalRecs = $this->DisplayRecs;
			$this->StopRec = $this->DisplayRecs;
		} else {
			$selectLimit = $this->UseSelectLimit;
			if ($selectLimit) {
				$this->TotalRecs = $this->listRecordCount();
			} else {
				if ($this->Recordset = $this->loadRecordset())
					$this->TotalRecs = $this->Recordset->RecordCount();
			}
			$this->StartRec = 1;
			$this->DisplayRecs = $this->TotalRecs; // Display all records
			if ($selectLimit)
				$this->Recordset = $this->loadRecordset($this->StartRec - 1, $this->DisplayRecs);

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

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

	// Set up number of records displayed per page
	protected function setupDisplayRecs()
	{
		$wrk = Get(TABLE_REC_PER_PAGE, "");
		if ($wrk <> "") {
			if (is_numeric($wrk)) {
				$this->DisplayRecs = (int)$wrk;
			} else {
				if (SameText($wrk, "all")) { // Display all records
					$this->DisplayRecs = -1;
				} else {
					$this->DisplayRecs = 10; // Non-numeric, load default
				}
			}
			$this->setRecordsPerPage($this->DisplayRecs); // Save to Session

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

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

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

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

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

		// Get old recordset
		$this->CurrentFilter = $this->buildKeyFilter();
		if ($this->CurrentFilter == "")
			$this->CurrentFilter = "0=1";
		$sql = $this->getCurrentSql();
		$conn = &$this->getConnection();
		if ($rs = $conn->execute($sql)) {
			$rsold = $rs->getRows();
			$rs->close();
		}

		// Call Grid Updating event
		if (!$this->Grid_Updating($rsold)) {
			if ($this->getFailureMessage() == "")
				$this->setFailureMessage($Language->phrase("GridEditCancelled")); // Set grid edit cancelled message
			return FALSE;
		}
		if ($this->AuditTrailOnEdit)
			$this->writeAuditTrailDummy($Language->phrase("BatchUpdateBegin")); // Batch update begin
		$key = "";

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

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

			// Load all values and keys
			if ($rowaction <> "insertdelete") { // Skip insert then deleted rows
				$this->loadFormValues(); // Get form values
				if ($rowaction == "" || $rowaction == "edit" || $rowaction == "delete") {
					$gridUpdate = $this->setupKeyValues($rowkey); // Set up key values
				} else {
					$gridUpdate = TRUE;
				}

				// Skip empty row
				if ($rowaction == "insert" && $this->emptyRow()) {

					// No action required
				// Validate form and insert/update/delete record

				} elseif ($gridUpdate) {
					if ($rowaction == "delete") {
						$this->CurrentFilter = $this->getRecordFilter();
						$gridUpdate = $this->deleteRows(); // Delete this row
					} else if (!$this->validateForm()) {
						$gridUpdate = FALSE; // Form error, reset action
						$this->setFailureMessage($FormError);
					} else {
						if ($rowaction == "insert") {
							$gridUpdate = $this->addRow(); // Insert this row
						} else {
							if ($rowkey <> "") {
								$this->SendEmail = FALSE; // Do not send email on update success
								$gridUpdate = $this->editRow(); // Update this row
							}
						} // End update
					}
				}
				if ($gridUpdate) {
					if ($key <> "")
						$key .= ", ";
					$key .= $rowkey;
				} else {
					break;
				}
			}
		}
		if ($gridUpdate) {

			// Get new recordset
			if ($rs = $conn->execute($sql)) {
				$rsnew = $rs->getRows();
				$rs->close();
			}

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

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

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

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

	// Set up key values
	protected function setupKeyValues($key)
	{
		$arKeyFlds = explode($GLOBALS["COMPOSITE_KEY_SEPARATOR"], $key);
		if (count($arKeyFlds) >= 1) {
			$this->EmployeePersonID->setFormValue($arKeyFlds[0]);
			if (!is_numeric($this->EmployeePersonID->FormValue))
				return FALSE;
		}
		return TRUE;
	}

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

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

		// Init key filter
		$wrkfilter = "";
		$addcnt = 0;
		if ($this->AuditTrailOnAdd)
			$this->writeAuditTrailDummy($Language->phrase("BatchInsertBegin")); // Batch insert begin
		$key = "";

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

		// Insert all rows
		for ($rowindex = 1; $rowindex <= $rowcnt; $rowindex++) {

			// Load current row values
			$CurrentForm->Index = $rowindex;
			$rowaction = strval($CurrentForm->getValue($this->FormActionName));
			if ($rowaction <> "" && $rowaction <> "insert")
				continue; // Skip
			if ($rowaction == "insert") {
				$this->RowOldKey = strval($CurrentForm->getValue($this->FormOldKeyName));
				$this->loadOldRecord(); // Load old record
			}
			$this->loadFormValues(); // Get form values
			if (!$this->emptyRow()) {
				$addcnt++;
				$this->SendEmail = FALSE; // Do not send email on insert success

				// Validate form
				if (!$this->validateForm()) {
					$gridInsert = FALSE; // Form error, reset action
					$this->setFailureMessage($FormError);
				} else {
					$gridInsert = $this->addRow($this->OldRecordset); // Insert this row
				}
				if ($gridInsert) {
					if ($key <> "")
						$key .= $GLOBALS["COMPOSITE_KEY_SEPARATOR"];
					$key .= $this->EmployeePersonID->CurrentValue;

					// Add filter for this record
					$filter = $this->getRecordFilter();
					if ($wrkfilter <> "")
						$wrkfilter .= " OR ";
					$wrkfilter .= $filter;
				} else {
					break;
				}
			}
		}
		if ($addcnt == 0) { // No record inserted
			$this->clearInlineMode(); // Clear grid add mode and return
			return TRUE;
		}
		if ($gridInsert) {

			// Get new recordset
			$this->CurrentFilter = $wrkfilter;
			$sql = $this->getCurrentSql();
			if ($rs = $conn->execute($sql)) {
				$rsnew = $rs->getRows();
				$rs->close();
			}

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

	// Check if empty row
	public function emptyRow()
	{
		global $CurrentForm;
		if ($CurrentForm->hasValue("x_EmployeeID") && $CurrentForm->hasValue("o_EmployeeID") && $this->EmployeeID->CurrentValue <> $this->EmployeeID->OldValue)
			return FALSE;
		if ($CurrentForm->hasValue("x_MaritalStatusID") && $CurrentForm->hasValue("o_MaritalStatusID") && $this->MaritalStatusID->CurrentValue <> $this->MaritalStatusID->OldValue)
			return FALSE;
		if ($CurrentForm->hasValue("x_CivilStatus23") && $CurrentForm->hasValue("o_CivilStatus23") && $this->CivilStatus23->CurrentValue <> $this->CivilStatus23->OldValue)
			return FALSE;
		if ($CurrentForm->hasValue("x_CivilStatusPlace") && $CurrentForm->hasValue("o_CivilStatusPlace") && $this->CivilStatusPlace->CurrentValue <> $this->CivilStatusPlace->OldValue)
			return FALSE;
		if ($CurrentForm->hasValue("x_IdCard23") && $CurrentForm->hasValue("o_IdCard23") && $this->IdCard23->CurrentValue <> $this->IdCard23->OldValue)
			return FALSE;
		if ($CurrentForm->hasValue("x_PracticingProfessionLicense23") && $CurrentForm->hasValue("o_PracticingProfessionLicense23") && $this->PracticingProfessionLicense23->CurrentValue <> $this->PracticingProfessionLicense23->OldValue)
			return FALSE;
		if ($CurrentForm->hasValue("x_NationalId23") && $CurrentForm->hasValue("o_NationalId23") && $this->NationalId23->CurrentValue <> $this->NationalId23->OldValue)
			return FALSE;
		if ($CurrentForm->hasValue("x_Nationality1") && $CurrentForm->hasValue("o_Nationality1") && $this->Nationality1->CurrentValue <> $this->Nationality1->OldValue)
			return FALSE;
		if ($CurrentForm->hasValue("x_Nationality2") && $CurrentForm->hasValue("o_Nationality2") && $this->Nationality2->CurrentValue <> $this->Nationality2->OldValue)
			return FALSE;
		if ($CurrentForm->hasValue("x_Nationality3") && $CurrentForm->hasValue("o_Nationality3") && $this->Nationality3->CurrentValue <> $this->Nationality3->OldValue)
			return FALSE;
		if ($CurrentForm->hasValue("x_DriverLicense23") && $CurrentForm->hasValue("o_DriverLicense23") && $this->DriverLicense23->CurrentValue <> $this->DriverLicense23->OldValue)
			return FALSE;
		if ($CurrentForm->hasValue("x_Extra23") && $CurrentForm->hasValue("o_Extra23") && $this->Extra23->CurrentValue <> $this->Extra23->OldValue)
			return FALSE;
		return TRUE;
	}

	// Validate grid form
	public function validateGridForm()
	{
		global $CurrentForm;

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

		// Validate all records
		for ($rowindex = 1; $rowindex <= $rowcnt; $rowindex++) {

			// Load current row values
			$CurrentForm->Index = $rowindex;
			$rowaction = strval($CurrentForm->getValue($this->FormActionName));
			if ($rowaction <> "delete" && $rowaction <> "insertdelete") {
				$this->loadFormValues(); // Get form values
				if ($rowaction == "insert" && $this->emptyRow()) {

					// Ignore
				} else if (!$this->validateForm()) {
					return FALSE;
				}
			}
		}
		return TRUE;
	}

	// Get all form values of the grid
	public function getGridFormValues()
	{
		global $CurrentForm;

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

		// Loop through all records
		for ($rowindex = 1; $rowindex <= $rowcnt; $rowindex++) {

			// Load current row values
			$CurrentForm->Index = $rowindex;
			$rowaction = strval($CurrentForm->getValue($this->FormActionName));
			if ($rowaction <> "delete" && $rowaction <> "insertdelete") {
				$this->loadFormValues(); // Get form values
				if ($rowaction == "insert" && $this->emptyRow()) {

					// Ignore
				} else {
					$rows[] = $this->getFieldValues("FormValue"); // Return row as array
				}
			}
		}
		return $rows; // Return as array of array
	}

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

		// Get row based on current index
		$CurrentForm->Index = $idx;
		$this->loadFormValues(); // Load form values
	}

	// Set up sort parameters
	protected function setupSortOrder()
	{

		// Check for "order" parameter
		if (Get("order") !== NULL) {
			$this->CurrentOrder = Get("order");
			$this->CurrentOrderType = Get("ordertype", "");
			$this->setStartRecordNumber(1); // Reset start position
		}
	}

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

	// Reset command
	// - cmd=reset (Reset search parameters)
	// - cmd=resetall (Reset search and master/detail parameters)
	// - cmd=resetsort (Reset sort parameters)

	protected function resetCmd()
	{

		// Check if reset command
		if (substr($this->Command,0,5) == "reset") {

			// Reset master/detail keys
			if ($this->Command == "resetall") {
				$this->setCurrentMasterTable(""); // Clear master table
				$this->DbMasterFilter = "";
				$this->DbDetailFilter = "";
				$this->EmployeeID->setSessionValue("");
			}

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

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

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

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

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

		// "view"
		$item = &$this->ListOptions->add("view");
		$item->CssClass = "text-nowrap";
		$item->Visible = $Security->canView();
		$item->OnLeft = TRUE;

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

		// "copy"
		$item = &$this->ListOptions->add("copy");
		$item->CssClass = "text-nowrap";
		$item->Visible = $Security->canAdd();
		$item->OnLeft = TRUE;

		// "delete"
		$item = &$this->ListOptions->add("delete");
		$item->CssClass = "text-nowrap";
		$item->Visible = $Security->canDelete();
		$item->OnLeft = TRUE;

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

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

		$this->ListOptions_Load();
		$item = &$this->ListOptions->getItem($this->ListOptions->GroupOptionName);
		$item->Visible = $this->ListOptions->groupOptionVisible();
	}

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

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

		// Set up row action and key
		if (is_numeric($this->RowIndex) && $this->CurrentMode <> "view") {
			$CurrentForm->Index = $this->RowIndex;
			$actionName = str_replace("k_", "k" . $this->RowIndex . "_", $this->FormActionName);
			$oldKeyName = str_replace("k_", "k" . $this->RowIndex . "_", $this->FormOldKeyName);
			$keyName = str_replace("k_", "k" . $this->RowIndex . "_", $this->FormKeyName);
			$blankRowName = str_replace("k_", "k" . $this->RowIndex . "_", $this->FormBlankRowName);
			if ($this->RowAction <> "")
				$this->MultiSelectKey .= "<input type=\"hidden\" name=\"" . $actionName . "\" id=\"" . $actionName . "\" value=\"" . $this->RowAction . "\">";
			if ($CurrentForm->hasValue($this->FormOldKeyName))
				$this->RowOldKey = strval($CurrentForm->getValue($this->FormOldKeyName));
			if ($this->RowOldKey <> "")
				$this->MultiSelectKey .= "<input type=\"hidden\" name=\"" . $oldKeyName . "\" id=\"" . $oldKeyName . "\" value=\"" . HtmlEncode($this->RowOldKey) . "\">";
			if ($this->RowAction == "delete") {
				$rowkey = $CurrentForm->getValue($this->FormKeyName);
				$this->setupKeyValues($rowkey);
			}
			if ($this->RowAction == "insert" && $this->isConfirm() && $this->emptyRow())
				$this->MultiSelectKey .= "<input type=\"hidden\" name=\"" . $blankRowName . "\" id=\"" . $blankRowName . "\" value=\"1\">";
		}

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

		// "view"
		$opt = &$this->ListOptions->Items["view"];
		$viewcaption = HtmlTitle($Language->phrase("ViewLink"));
		if ($Security->canView()) {
			$opt->Body = "<a class=\"ew-row-link ew-view\" title=\"" . $viewcaption . "\" data-caption=\"" . $viewcaption . "\" href=\"" . HtmlEncode($this->ViewUrl) . "\">" . $Language->phrase("ViewLink") . "</a>";
		} else {
			$opt->Body = "";
		}

		// "edit"
		$opt = &$this->ListOptions->Items["edit"];
		$editcaption = HtmlTitle($Language->phrase("EditLink"));
		if ($Security->canEdit()) {
			$opt->Body = "<a class=\"ew-row-link ew-edit\" title=\"" . HtmlTitle($Language->phrase("EditLink")) . "\" data-caption=\"" . HtmlTitle($Language->phrase("EditLink")) . "\" href=\"" . HtmlEncode($this->EditUrl) . "\">" . $Language->phrase("EditLink") . "</a>";
		} else {
			$opt->Body = "";
		}

		// "copy"
		$opt = &$this->ListOptions->Items["copy"];
		$copycaption = HtmlTitle($Language->phrase("CopyLink"));
		if ($Security->canAdd()) {
			$opt->Body = "<a class=\"ew-row-link ew-copy\" title=\"" . $copycaption . "\" data-caption=\"" . $copycaption . "\" href=\"" . HtmlEncode($this->CopyUrl) . "\">" . $Language->phrase("CopyLink") . "</a>";
		} else {
			$opt->Body = "";
		}

		// "delete"
		$opt = &$this->ListOptions->Items["delete"];
		if ($Security->canDelete())
			$opt->Body = "<a class=\"ew-row-link ew-delete\"" . "" . " title=\"" . HtmlTitle($Language->phrase("DeleteLink")) . "\" data-caption=\"" . HtmlTitle($Language->phrase("DeleteLink")) . "\" href=\"" . HtmlEncode($this->DeleteUrl) . "\">" . $Language->phrase("DeleteLink") . "</a>";
		else
			$opt->Body = "";
		} // End View mode
		if ($this->CurrentMode == "edit" && is_numeric($this->RowIndex)) {
			$this->MultiSelectKey .= "<input type=\"hidden\" name=\"" . $keyName . "\" id=\"" . $keyName . "\" value=\"" . $this->EmployeePersonID->CurrentValue . "\">";
		}
		$this->renderListOptionsExt();

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

	// Set record key
	public function setRecordKey(&$key, $rs)
	{
		$key = "";
		if ($key <> "")
			$key .= $GLOBALS["COMPOSITE_KEY_SEPARATOR"];
		$key .= $rs->fields('EmployeePersonID');
	}

	// Set up other options
	protected function setupOtherOptions()
	{
		global $Language, $Security;
		$option = &$this->OtherOptions["addedit"];
		$option->UseDropDownButton = FALSE;
		$option->DropDownButtonPhrase = $Language->phrase("ButtonAddEdit");
		$option->UseButtonGroup = TRUE;

		//$option->ButtonClass = ""; // Class for button group
		$item = &$option->add($option->GroupOptionName);
		$item->Body = "";
		$item->Visible = FALSE;

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

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

	// Set up starting record parameters
	public function setupStartRec()
	{
		if ($this->DisplayRecs == 0)
			return;
		if ($this->isPageRequest()) { // Validate request
			if (Get(TABLE_START_REC) !== NULL) { // Check for "start" parameter
				$this->StartRec = Get(TABLE_START_REC);
				$this->setStartRecordNumber($this->StartRec);
			} elseif (Get(TABLE_PAGE_NO) !== NULL) {
				$pageNo = Get(TABLE_PAGE_NO);
				if (is_numeric($pageNo)) {
					$this->StartRec = ($pageNo - 1) * $this->DisplayRecs + 1;
					if ($this->StartRec <= 0) {
						$this->StartRec = 1;
					} elseif ($this->StartRec >= (int)(($this->TotalRecs - 1)/$this->DisplayRecs) * $this->DisplayRecs + 1) {
						$this->StartRec = (int)(($this->TotalRecs - 1)/$this->DisplayRecs) * $this->DisplayRecs + 1;
					}
					$this->setStartRecordNumber($this->StartRec);
				}
			}
		}
		$this->StartRec = $this->getStartRecordNumber();

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

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

	// Load default values
	protected function loadDefaultValues()
	{
		$this->EmployeePersonID->CurrentValue = NULL;
		$this->EmployeePersonID->OldValue = $this->EmployeePersonID->CurrentValue;
		$this->EmployeeID->CurrentValue = NULL;
		$this->EmployeeID->OldValue = $this->EmployeeID->CurrentValue;
		$this->MaritalStatusID->CurrentValue = NULL;
		$this->MaritalStatusID->OldValue = $this->MaritalStatusID->CurrentValue;
		$this->CivilStatus23->CurrentValue = NULL;
		$this->CivilStatus23->OldValue = $this->CivilStatus23->CurrentValue;
		$this->CivilStatusPlace->CurrentValue = NULL;
		$this->CivilStatusPlace->OldValue = $this->CivilStatusPlace->CurrentValue;
		$this->IdCard23->CurrentValue = NULL;
		$this->IdCard23->OldValue = $this->IdCard23->CurrentValue;
		$this->PracticingProfessionLicense23->CurrentValue = NULL;
		$this->PracticingProfessionLicense23->OldValue = $this->PracticingProfessionLicense23->CurrentValue;
		$this->NationalId23->CurrentValue = NULL;
		$this->NationalId23->OldValue = $this->NationalId23->CurrentValue;
		$this->Nationality1->CurrentValue = NULL;
		$this->Nationality1->OldValue = $this->Nationality1->CurrentValue;
		$this->Nationality2->CurrentValue = NULL;
		$this->Nationality2->OldValue = $this->Nationality2->CurrentValue;
		$this->Nationality3->CurrentValue = NULL;
		$this->Nationality3->OldValue = $this->Nationality3->CurrentValue;
		$this->DriverLicense23->CurrentValue = NULL;
		$this->DriverLicense23->OldValue = $this->DriverLicense23->CurrentValue;
		$this->Extra23->CurrentValue = NULL;
		$this->Extra23->OldValue = $this->Extra23->CurrentValue;
		$this->Notes->CurrentValue = NULL;
		$this->Notes->OldValue = $this->Notes->CurrentValue;
		$this->_UserID->CurrentValue = NULL;
		$this->_UserID->OldValue = $this->_UserID->CurrentValue;
		$this->CreatedBy->CurrentValue = NULL;
		$this->CreatedBy->OldValue = $this->CreatedBy->CurrentValue;
		$this->CreatedDate->CurrentValue = NULL;
		$this->CreatedDate->OldValue = $this->CreatedDate->CurrentValue;
		$this->UpdatedBy->CurrentValue = NULL;
		$this->UpdatedBy->OldValue = $this->UpdatedBy->CurrentValue;
		$this->UpdatedDate->CurrentValue = NULL;
		$this->UpdatedDate->OldValue = $this->UpdatedDate->CurrentValue;
	}

	// Load form values
	protected function loadFormValues()
	{

		// Load from form
		global $CurrentForm;
		$CurrentForm->FormName = $this->FormName;

		// Check field name 'EmployeeID' first before field var 'x_EmployeeID'
		$val = $CurrentForm->hasValue("EmployeeID") ? $CurrentForm->getValue("EmployeeID") : $CurrentForm->getValue("x_EmployeeID");
		if (!$this->EmployeeID->IsDetailKey) {
			if (IsApi() && $val == NULL)
				$this->EmployeeID->Visible = FALSE; // Disable update for API request
			else
				$this->EmployeeID->setFormValue($val);
		}
		$this->EmployeeID->setOldValue($CurrentForm->getValue("o_EmployeeID"));

		// Check field name 'MaritalStatusID' first before field var 'x_MaritalStatusID'
		$val = $CurrentForm->hasValue("MaritalStatusID") ? $CurrentForm->getValue("MaritalStatusID") : $CurrentForm->getValue("x_MaritalStatusID");
		if (!$this->MaritalStatusID->IsDetailKey) {
			if (IsApi() && $val == NULL)
				$this->MaritalStatusID->Visible = FALSE; // Disable update for API request
			else
				$this->MaritalStatusID->setFormValue($val);
		}
		$this->MaritalStatusID->setOldValue($CurrentForm->getValue("o_MaritalStatusID"));

		// Check field name 'CivilStatus#' first before field var 'x_CivilStatus23'
		$val = $CurrentForm->hasValue("CivilStatus#") ? $CurrentForm->getValue("CivilStatus#") : $CurrentForm->getValue("x_CivilStatus23");
		if (!$this->CivilStatus23->IsDetailKey) {
			if (IsApi() && $val == NULL)
				$this->CivilStatus23->Visible = FALSE; // Disable update for API request
			else
				$this->CivilStatus23->setFormValue($val);
		}
		$this->CivilStatus23->setOldValue($CurrentForm->getValue("o_CivilStatus23"));

		// Check field name 'CivilStatusPlace' first before field var 'x_CivilStatusPlace'
		$val = $CurrentForm->hasValue("CivilStatusPlace") ? $CurrentForm->getValue("CivilStatusPlace") : $CurrentForm->getValue("x_CivilStatusPlace");
		if (!$this->CivilStatusPlace->IsDetailKey) {
			if (IsApi() && $val == NULL)
				$this->CivilStatusPlace->Visible = FALSE; // Disable update for API request
			else
				$this->CivilStatusPlace->setFormValue($val);
		}
		$this->CivilStatusPlace->setOldValue($CurrentForm->getValue("o_CivilStatusPlace"));

		// Check field name 'IdCard#' first before field var 'x_IdCard23'
		$val = $CurrentForm->hasValue("IdCard#") ? $CurrentForm->getValue("IdCard#") : $CurrentForm->getValue("x_IdCard23");
		if (!$this->IdCard23->IsDetailKey) {
			if (IsApi() && $val == NULL)
				$this->IdCard23->Visible = FALSE; // Disable update for API request
			else
				$this->IdCard23->setFormValue($val);
		}
		$this->IdCard23->setOldValue($CurrentForm->getValue("o_IdCard23"));

		// Check field name 'PracticingProfessionLicense#' first before field var 'x_PracticingProfessionLicense23'
		$val = $CurrentForm->hasValue("PracticingProfessionLicense#") ? $CurrentForm->getValue("PracticingProfessionLicense#") : $CurrentForm->getValue("x_PracticingProfessionLicense23");
		if (!$this->PracticingProfessionLicense23->IsDetailKey) {
			if (IsApi() && $val == NULL)
				$this->PracticingProfessionLicense23->Visible = FALSE; // Disable update for API request
			else
				$this->PracticingProfessionLicense23->setFormValue($val);
		}
		$this->PracticingProfessionLicense23->setOldValue($CurrentForm->getValue("o_PracticingProfessionLicense23"));

		// Check field name 'NationalId#' first before field var 'x_NationalId23'
		$val = $CurrentForm->hasValue("NationalId#") ? $CurrentForm->getValue("NationalId#") : $CurrentForm->getValue("x_NationalId23");
		if (!$this->NationalId23->IsDetailKey) {
			if (IsApi() && $val == NULL)
				$this->NationalId23->Visible = FALSE; // Disable update for API request
			else
				$this->NationalId23->setFormValue($val);
		}
		$this->NationalId23->setOldValue($CurrentForm->getValue("o_NationalId23"));

		// Check field name 'Nationality1' first before field var 'x_Nationality1'
		$val = $CurrentForm->hasValue("Nationality1") ? $CurrentForm->getValue("Nationality1") : $CurrentForm->getValue("x_Nationality1");
		if (!$this->Nationality1->IsDetailKey) {
			if (IsApi() && $val == NULL)
				$this->Nationality1->Visible = FALSE; // Disable update for API request
			else
				$this->Nationality1->setFormValue($val);
		}
		$this->Nationality1->setOldValue($CurrentForm->getValue("o_Nationality1"));

		// Check field name 'Nationality2' first before field var 'x_Nationality2'
		$val = $CurrentForm->hasValue("Nationality2") ? $CurrentForm->getValue("Nationality2") : $CurrentForm->getValue("x_Nationality2");
		if (!$this->Nationality2->IsDetailKey) {
			if (IsApi() && $val == NULL)
				$this->Nationality2->Visible = FALSE; // Disable update for API request
			else
				$this->Nationality2->setFormValue($val);
		}
		$this->Nationality2->setOldValue($CurrentForm->getValue("o_Nationality2"));

		// Check field name 'Nationality3' first before field var 'x_Nationality3'
		$val = $CurrentForm->hasValue("Nationality3") ? $CurrentForm->getValue("Nationality3") : $CurrentForm->getValue("x_Nationality3");
		if (!$this->Nationality3->IsDetailKey) {
			if (IsApi() && $val == NULL)
				$this->Nationality3->Visible = FALSE; // Disable update for API request
			else
				$this->Nationality3->setFormValue($val);
		}
		$this->Nationality3->setOldValue($CurrentForm->getValue("o_Nationality3"));

		// Check field name 'DriverLicense#' first before field var 'x_DriverLicense23'
		$val = $CurrentForm->hasValue("DriverLicense#") ? $CurrentForm->getValue("DriverLicense#") : $CurrentForm->getValue("x_DriverLicense23");
		if (!$this->DriverLicense23->IsDetailKey) {
			if (IsApi() && $val == NULL)
				$this->DriverLicense23->Visible = FALSE; // Disable update for API request
			else
				$this->DriverLicense23->setFormValue($val);
		}
		$this->DriverLicense23->setOldValue($CurrentForm->getValue("o_DriverLicense23"));

		// Check field name 'Extra#' first before field var 'x_Extra23'
		$val = $CurrentForm->hasValue("Extra#") ? $CurrentForm->getValue("Extra#") : $CurrentForm->getValue("x_Extra23");
		if (!$this->Extra23->IsDetailKey) {
			if (IsApi() && $val == NULL)
				$this->Extra23->Visible = FALSE; // Disable update for API request
			else
				$this->Extra23->setFormValue($val);
		}
		$this->Extra23->setOldValue($CurrentForm->getValue("o_Extra23"));

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

	// Restore form values
	public function restoreFormValues()
	{
		global $CurrentForm;
		if (!$this->isGridAdd() && !$this->isAdd())
			$this->EmployeePersonID->CurrentValue = $this->EmployeePersonID->FormValue;
		$this->EmployeeID->CurrentValue = $this->EmployeeID->FormValue;
		$this->MaritalStatusID->CurrentValue = $this->MaritalStatusID->FormValue;
		$this->CivilStatus23->CurrentValue = $this->CivilStatus23->FormValue;
		$this->CivilStatusPlace->CurrentValue = $this->CivilStatusPlace->FormValue;
		$this->IdCard23->CurrentValue = $this->IdCard23->FormValue;
		$this->PracticingProfessionLicense23->CurrentValue = $this->PracticingProfessionLicense23->FormValue;
		$this->NationalId23->CurrentValue = $this->NationalId23->FormValue;
		$this->Nationality1->CurrentValue = $this->Nationality1->FormValue;
		$this->Nationality2->CurrentValue = $this->Nationality2->FormValue;
		$this->Nationality3->CurrentValue = $this->Nationality3->FormValue;
		$this->DriverLicense23->CurrentValue = $this->DriverLicense23->FormValue;
		$this->Extra23->CurrentValue = $this->Extra23->FormValue;
	}

	// Load recordset
	public function loadRecordset($offset = -1, $rowcnt = -1)
	{

		// Load List page SQL
		$sql = $this->getListSql();
		$conn = &$this->getConnection();

		// Load recordset
		$dbtype = GetConnectionType($this->Dbid);
		if ($this->UseSelectLimit) {
			$conn->raiseErrorFn = $GLOBALS["ERROR_FUNC"];
			if ($dbtype == "MSSQL") {
				$rs = $conn->selectLimit($sql, $rowcnt, $offset, ["_hasOrderBy" => trim($this->getOrderBy()) || trim($this->getSessionOrderBy())]);
			} else {
				$rs = $conn->selectLimit($sql, $rowcnt, $offset);
			}
			$conn->raiseErrorFn = '';
		} else {
			$rs = LoadRecordset($sql, $conn);
		}

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

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

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

		// Load SQL based on filter
		$this->CurrentFilter = $filter;
		$sql = $this->getCurrentSql();
		$conn = &$this->getConnection();
		$res = FALSE;
		$rs = LoadRecordset($sql, $conn);
		if ($rs && !$rs->EOF) {
			$res = TRUE;
			$this->loadRowValues($rs); // Load row values
			$rs->close();
		}
		return $res;
	}

	// Load row values from recordset
	public function loadRowValues($rs = NULL)
	{
		if ($rs && !$rs->EOF)
			$row = $rs->fields;
		else
			$row = $this->newRow();

		// Call Row Selected event
		$this->Row_Selected($row);
		if (!$rs || $rs->EOF)
			return;
		$this->EmployeePersonID->setDbValue($row['EmployeePersonID']);
		$this->EmployeeID->setDbValue($row['EmployeeID']);
		$this->MaritalStatusID->setDbValue($row['MaritalStatusID']);
		$this->CivilStatus23->setDbValue($row['CivilStatus#']);
		$this->CivilStatusPlace->setDbValue($row['CivilStatusPlace']);
		$this->IdCard23->setDbValue($row['IdCard#']);
		$this->PracticingProfessionLicense23->setDbValue($row['PracticingProfessionLicense#']);
		$this->NationalId23->setDbValue($row['NationalId#']);
		$this->Nationality1->setDbValue($row['Nationality1']);
		$this->Nationality2->setDbValue($row['Nationality2']);
		$this->Nationality3->setDbValue($row['Nationality3']);
		$this->DriverLicense23->setDbValue($row['DriverLicense#']);
		$this->Extra23->setDbValue($row['Extra#']);
		$this->Notes->setDbValue($row['Notes']);
		$this->_UserID->setDbValue($row['UserID']);
		$this->CreatedBy->setDbValue($row['CreatedBy']);
		$this->CreatedDate->setDbValue($row['CreatedDate']);
		$this->UpdatedBy->setDbValue($row['UpdatedBy']);
		$this->UpdatedDate->setDbValue($row['UpdatedDate']);
	}

	// Return a row with default values
	protected function newRow()
	{
		$this->loadDefaultValues();
		$row = [];
		$row['EmployeePersonID'] = $this->EmployeePersonID->CurrentValue;
		$row['EmployeeID'] = $this->EmployeeID->CurrentValue;
		$row['MaritalStatusID'] = $this->MaritalStatusID->CurrentValue;
		$row['CivilStatus#'] = $this->CivilStatus23->CurrentValue;
		$row['CivilStatusPlace'] = $this->CivilStatusPlace->CurrentValue;
		$row['IdCard#'] = $this->IdCard23->CurrentValue;
		$row['PracticingProfessionLicense#'] = $this->PracticingProfessionLicense23->CurrentValue;
		$row['NationalId#'] = $this->NationalId23->CurrentValue;
		$row['Nationality1'] = $this->Nationality1->CurrentValue;
		$row['Nationality2'] = $this->Nationality2->CurrentValue;
		$row['Nationality3'] = $this->Nationality3->CurrentValue;
		$row['DriverLicense#'] = $this->DriverLicense23->CurrentValue;
		$row['Extra#'] = $this->Extra23->CurrentValue;
		$row['Notes'] = $this->Notes->CurrentValue;
		$row['UserID'] = $this->_UserID->CurrentValue;
		$row['CreatedBy'] = $this->CreatedBy->CurrentValue;
		$row['CreatedDate'] = $this->CreatedDate->CurrentValue;
		$row['UpdatedBy'] = $this->UpdatedBy->CurrentValue;
		$row['UpdatedDate'] = $this->UpdatedDate->CurrentValue;
		return $row;
	}

	// Load old record
	protected function loadOldRecord()
	{

		// Load key values from Session
		$validKey = TRUE;
		$arKeys[] = $this->RowOldKey;
		$cnt = count($arKeys);
		if ($cnt >= 1) {
			if (strval($arKeys[0]) <> "")
				$this->EmployeePersonID->CurrentValue = strval($arKeys[0]); // EmployeePersonID
			else
				$validKey = FALSE;
		} else {
			$validKey = FALSE;
		}

		// Load old record
		$this->OldRecordset = NULL;
		if ($validKey) {
			$this->CurrentFilter = $this->getRecordFilter();
			$sql = $this->getCurrentSql();
			$conn = &$this->getConnection();
			$this->OldRecordset = LoadRecordset($sql, $conn);
		}
		$this->loadRowValues($this->OldRecordset); // Load row values
		return $validKey;
	}

	// Render row values based on field settings
	public function renderRow()
	{
		global $Security, $Language, $CurrentLanguage;

		// Initialize URLs
		$this->ViewUrl = $this->getViewUrl();
		$this->EditUrl = $this->getEditUrl();
		$this->CopyUrl = $this->getCopyUrl();
		$this->DeleteUrl = $this->getDeleteUrl();

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

		// Common render codes for all row types
		// EmployeePersonID
		// EmployeeID
		// MaritalStatusID
		// CivilStatus#
		// CivilStatusPlace
		// IdCard#
		// PracticingProfessionLicense#
		// NationalId#
		// Nationality1
		// Nationality2
		// Nationality3
		// DriverLicense#
		// Extra#
		// Notes
		// UserID

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

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

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

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

		// UpdatedDate
		$this->UpdatedDate->CellCssStyle = "white-space: nowrap;";
		if ($this->RowType == ROWTYPE_VIEW) { // View row

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

			// EmployeeID
			$curVal = strval($this->EmployeeID->CurrentValue);
			if ($curVal <> "") {
				$this->EmployeeID->ViewValue = $this->EmployeeID->lookupCacheOption($curVal);
				if ($this->EmployeeID->ViewValue === NULL) { // Lookup from database
					$filterWrk = "`EmployeeID`" . SearchString("=", $curVal, DATATYPE_NUMBER, "");
					$sqlWrk = $this->EmployeeID->Lookup->getSql(FALSE, $filterWrk, '', $this);
					$rswrk = Conn()->execute($sqlWrk);
					if ($rswrk && !$rswrk->EOF) { // Lookup values found
						$arwrk = array();
						$arwrk[1] = $rswrk->fields('df');
						$arwrk[2] = $rswrk->fields('df2');
						$arwrk[3] = $rswrk->fields('df3');
						$this->EmployeeID->ViewValue = $this->EmployeeID->displayValue($arwrk);
						$rswrk->Close();
					} else {
						$this->EmployeeID->ViewValue = $this->EmployeeID->CurrentValue;
					}
				}
			} else {
				$this->EmployeeID->ViewValue = NULL;
			}
			$this->EmployeeID->ViewCustomAttributes = "";

			// MaritalStatusID
			$curVal = strval($this->MaritalStatusID->CurrentValue);
			if ($curVal <> "") {
				$this->MaritalStatusID->ViewValue = $this->MaritalStatusID->lookupCacheOption($curVal);
				if ($this->MaritalStatusID->ViewValue === NULL) { // Lookup from database
					$filterWrk = "`MaritalStatusID`" . SearchString("=", $curVal, DATATYPE_NUMBER, "");
					$sqlWrk = $this->MaritalStatusID->Lookup->getSql(FALSE, $filterWrk, '', $this);
					$rswrk = Conn()->execute($sqlWrk);
					if ($rswrk && !$rswrk->EOF) { // Lookup values found
						$arwrk = array();
						$arwrk[1] = $rswrk->fields('df');
						$this->MaritalStatusID->ViewValue = $this->MaritalStatusID->displayValue($arwrk);
						$rswrk->Close();
					} else {
						$this->MaritalStatusID->ViewValue = $this->MaritalStatusID->CurrentValue;
					}
				}
			} else {
				$this->MaritalStatusID->ViewValue = NULL;
			}
			$this->MaritalStatusID->ViewCustomAttributes = "";

			// CivilStatus#
			$this->CivilStatus23->ViewValue = $this->CivilStatus23->CurrentValue;
			$this->CivilStatus23->ViewCustomAttributes = "";

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

			// IdCard#
			$this->IdCard23->ViewValue = $this->IdCard23->CurrentValue;
			$this->IdCard23->ViewCustomAttributes = "";

			// PracticingProfessionLicense#
			$this->PracticingProfessionLicense23->ViewValue = $this->PracticingProfessionLicense23->CurrentValue;
			$this->PracticingProfessionLicense23->ViewCustomAttributes = "";

			// NationalId#
			$this->NationalId23->ViewValue = $this->NationalId23->CurrentValue;
			$this->NationalId23->ViewCustomAttributes = "";

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

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

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

			// DriverLicense#
			$this->DriverLicense23->ViewValue = $this->DriverLicense23->CurrentValue;
			$this->DriverLicense23->ViewCustomAttributes = "";

			// Extra#
			$this->Extra23->ViewValue = $this->Extra23->CurrentValue;
			$this->Extra23->ViewCustomAttributes = "";

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

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

			// CivilStatus#
			$this->CivilStatus23->LinkCustomAttributes = "";
			$this->CivilStatus23->HrefValue = "";
			$this->CivilStatus23->TooltipValue = "";
			if (!$this->isExport())
				$this->CivilStatus23->ViewValue = $this->highlightValue($this->CivilStatus23);

			// CivilStatusPlace
			$this->CivilStatusPlace->LinkCustomAttributes = "";
			$this->CivilStatusPlace->HrefValue = "";
			$this->CivilStatusPlace->TooltipValue = "";
			if (!$this->isExport())
				$this->CivilStatusPlace->ViewValue = $this->highlightValue($this->CivilStatusPlace);

			// IdCard#
			$this->IdCard23->LinkCustomAttributes = "";
			$this->IdCard23->HrefValue = "";
			$this->IdCard23->TooltipValue = "";
			if (!$this->isExport())
				$this->IdCard23->ViewValue = $this->highlightValue($this->IdCard23);

			// PracticingProfessionLicense#
			$this->PracticingProfessionLicense23->LinkCustomAttributes = "";
			$this->PracticingProfessionLicense23->HrefValue = "";
			$this->PracticingProfessionLicense23->TooltipValue = "";
			if (!$this->isExport())
				$this->PracticingProfessionLicense23->ViewValue = $this->highlightValue($this->PracticingProfessionLicense23);

			// NationalId#
			$this->NationalId23->LinkCustomAttributes = "";
			$this->NationalId23->HrefValue = "";
			$this->NationalId23->TooltipValue = "";
			if (!$this->isExport())
				$this->NationalId23->ViewValue = $this->highlightValue($this->NationalId23);

			// Nationality1
			$this->Nationality1->LinkCustomAttributes = "";
			$this->Nationality1->HrefValue = "";
			$this->Nationality1->TooltipValue = "";
			if (!$this->isExport())
				$this->Nationality1->ViewValue = $this->highlightValue($this->Nationality1);

			// Nationality2
			$this->Nationality2->LinkCustomAttributes = "";
			$this->Nationality2->HrefValue = "";
			$this->Nationality2->TooltipValue = "";
			if (!$this->isExport())
				$this->Nationality2->ViewValue = $this->highlightValue($this->Nationality2);

			// Nationality3
			$this->Nationality3->LinkCustomAttributes = "";
			$this->Nationality3->HrefValue = "";
			$this->Nationality3->TooltipValue = "";
			if (!$this->isExport())
				$this->Nationality3->ViewValue = $this->highlightValue($this->Nationality3);

			// DriverLicense#
			$this->DriverLicense23->LinkCustomAttributes = "";
			$this->DriverLicense23->HrefValue = "";
			$this->DriverLicense23->TooltipValue = "";
			if (!$this->isExport())
				$this->DriverLicense23->ViewValue = $this->highlightValue($this->DriverLicense23);

			// Extra#
			$this->Extra23->LinkCustomAttributes = "";
			$this->Extra23->HrefValue = "";
			$this->Extra23->TooltipValue = "";
			if (!$this->isExport())
				$this->Extra23->ViewValue = $this->highlightValue($this->Extra23);
		} elseif ($this->RowType == ROWTYPE_ADD) { // Add row

			// EmployeeID
			$this->EmployeeID->EditAttrs["class"] = "form-control";
			$this->EmployeeID->EditCustomAttributes = "";
			if ($this->EmployeeID->getSessionValue() <> "") {
				$this->EmployeeID->CurrentValue = $this->EmployeeID->getSessionValue();
				$this->EmployeeID->OldValue = $this->EmployeeID->CurrentValue;
			$curVal = strval($this->EmployeeID->CurrentValue);
			if ($curVal <> "") {
				$this->EmployeeID->ViewValue = $this->EmployeeID->lookupCacheOption($curVal);
				if ($this->EmployeeID->ViewValue === NULL) { // Lookup from database
					$filterWrk = "`EmployeeID`" . SearchString("=", $curVal, DATATYPE_NUMBER, "");
					$sqlWrk = $this->EmployeeID->Lookup->getSql(FALSE, $filterWrk, '', $this);
					$rswrk = Conn()->execute($sqlWrk);
					if ($rswrk && !$rswrk->EOF) { // Lookup values found
						$arwrk = array();
						$arwrk[1] = $rswrk->fields('df');
						$arwrk[2] = $rswrk->fields('df2');
						$arwrk[3] = $rswrk->fields('df3');
						$this->EmployeeID->ViewValue = $this->EmployeeID->displayValue($arwrk);
						$rswrk->Close();
					} else {
						$this->EmployeeID->ViewValue = $this->EmployeeID->CurrentValue;
					}
				}
			} else {
				$this->EmployeeID->ViewValue = NULL;
			}
			$this->EmployeeID->ViewCustomAttributes = "";
			} else {
			$curVal = trim(strval($this->EmployeeID->CurrentValue));
			if ($curVal <> "")
				$this->EmployeeID->ViewValue = $this->EmployeeID->lookupCacheOption($curVal);
			else
				$this->EmployeeID->ViewValue = $this->EmployeeID->Lookup !== NULL && is_array($this->EmployeeID->Lookup->Options) ? $curVal : NULL;
			if ($this->EmployeeID->ViewValue !== NULL) { // Load from cache
				$this->EmployeeID->EditValue = array_values($this->EmployeeID->Lookup->Options);
			} else { // Lookup from database
				if ($curVal == "") {
					$filterWrk = "0=1";
				} else {
					$filterWrk = "`EmployeeID`" . SearchString("=", $this->EmployeeID->CurrentValue, DATATYPE_NUMBER, "");
				}
				$sqlWrk = $this->EmployeeID->Lookup->getSql(TRUE, $filterWrk, '', $this);
				$rswrk = Conn()->execute($sqlWrk);
				$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
				if ($rswrk) $rswrk->Close();
				$this->EmployeeID->EditValue = $arwrk;
			}
			}

			// MaritalStatusID
			$this->MaritalStatusID->EditAttrs["class"] = "form-control";
			$this->MaritalStatusID->EditCustomAttributes = "";
			$curVal = trim(strval($this->MaritalStatusID->CurrentValue));
			if ($curVal <> "")
				$this->MaritalStatusID->ViewValue = $this->MaritalStatusID->lookupCacheOption($curVal);
			else
				$this->MaritalStatusID->ViewValue = $this->MaritalStatusID->Lookup !== NULL && is_array($this->MaritalStatusID->Lookup->Options) ? $curVal : NULL;
			if ($this->MaritalStatusID->ViewValue !== NULL) { // Load from cache
				$this->MaritalStatusID->EditValue = array_values($this->MaritalStatusID->Lookup->Options);
			} else { // Lookup from database
				if ($curVal == "") {
					$filterWrk = "0=1";
				} else {
					$filterWrk = "`MaritalStatusID`" . SearchString("=", $this->MaritalStatusID->CurrentValue, DATATYPE_NUMBER, "");
				}
				$sqlWrk = $this->MaritalStatusID->Lookup->getSql(TRUE, $filterWrk, '', $this);
				$rswrk = Conn()->execute($sqlWrk);
				$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
				if ($rswrk) $rswrk->Close();
				$this->MaritalStatusID->EditValue = $arwrk;
			}

			// CivilStatus#
			$this->CivilStatus23->EditAttrs["class"] = "form-control";
			$this->CivilStatus23->EditCustomAttributes = "";
			$this->CivilStatus23->EditValue = HtmlEncode($this->CivilStatus23->CurrentValue);
			$this->CivilStatus23->PlaceHolder = RemoveHtml($this->CivilStatus23->caption());

			// CivilStatusPlace
			$this->CivilStatusPlace->EditAttrs["class"] = "form-control";
			$this->CivilStatusPlace->EditCustomAttributes = "";
			$this->CivilStatusPlace->EditValue = HtmlEncode($this->CivilStatusPlace->CurrentValue);
			$this->CivilStatusPlace->PlaceHolder = RemoveHtml($this->CivilStatusPlace->caption());

			// IdCard#
			$this->IdCard23->EditAttrs["class"] = "form-control";
			$this->IdCard23->EditCustomAttributes = "";
			$this->IdCard23->EditValue = HtmlEncode($this->IdCard23->CurrentValue);
			$this->IdCard23->PlaceHolder = RemoveHtml($this->IdCard23->caption());

			// PracticingProfessionLicense#
			$this->PracticingProfessionLicense23->EditAttrs["class"] = "form-control";
			$this->PracticingProfessionLicense23->EditCustomAttributes = "";
			$this->PracticingProfessionLicense23->EditValue = HtmlEncode($this->PracticingProfessionLicense23->CurrentValue);
			$this->PracticingProfessionLicense23->PlaceHolder = RemoveHtml($this->PracticingProfessionLicense23->caption());

			// NationalId#
			$this->NationalId23->EditAttrs["class"] = "form-control";
			$this->NationalId23->EditCustomAttributes = "";
			$this->NationalId23->EditValue = HtmlEncode($this->NationalId23->CurrentValue);
			$this->NationalId23->PlaceHolder = RemoveHtml($this->NationalId23->caption());

			// Nationality1
			$this->Nationality1->EditAttrs["class"] = "form-control";
			$this->Nationality1->EditCustomAttributes = "";
			$this->Nationality1->EditValue = HtmlEncode($this->Nationality1->CurrentValue);
			$this->Nationality1->PlaceHolder = RemoveHtml($this->Nationality1->caption());

			// Nationality2
			$this->Nationality2->EditAttrs["class"] = "form-control";
			$this->Nationality2->EditCustomAttributes = "";
			$this->Nationality2->EditValue = HtmlEncode($this->Nationality2->CurrentValue);
			$this->Nationality2->PlaceHolder = RemoveHtml($this->Nationality2->caption());

			// Nationality3
			$this->Nationality3->EditAttrs["class"] = "form-control";
			$this->Nationality3->EditCustomAttributes = "";
			$this->Nationality3->EditValue = HtmlEncode($this->Nationality3->CurrentValue);
			$this->Nationality3->PlaceHolder = RemoveHtml($this->Nationality3->caption());

			// DriverLicense#
			$this->DriverLicense23->EditAttrs["class"] = "form-control";
			$this->DriverLicense23->EditCustomAttributes = "";
			$this->DriverLicense23->EditValue = HtmlEncode($this->DriverLicense23->CurrentValue);
			$this->DriverLicense23->PlaceHolder = RemoveHtml($this->DriverLicense23->caption());

			// Extra#
			$this->Extra23->EditAttrs["class"] = "form-control";
			$this->Extra23->EditCustomAttributes = "";
			$this->Extra23->EditValue = HtmlEncode($this->Extra23->CurrentValue);
			$this->Extra23->PlaceHolder = RemoveHtml($this->Extra23->caption());

			// Add refer script
			// EmployeeID

			$this->EmployeeID->LinkCustomAttributes = "";
			$this->EmployeeID->HrefValue = "";

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

			// CivilStatus#
			$this->CivilStatus23->LinkCustomAttributes = "";
			$this->CivilStatus23->HrefValue = "";

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

			// IdCard#
			$this->IdCard23->LinkCustomAttributes = "";
			$this->IdCard23->HrefValue = "";

			// PracticingProfessionLicense#
			$this->PracticingProfessionLicense23->LinkCustomAttributes = "";
			$this->PracticingProfessionLicense23->HrefValue = "";

			// NationalId#
			$this->NationalId23->LinkCustomAttributes = "";
			$this->NationalId23->HrefValue = "";

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

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

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

			// DriverLicense#
			$this->DriverLicense23->LinkCustomAttributes = "";
			$this->DriverLicense23->HrefValue = "";

			// Extra#
			$this->Extra23->LinkCustomAttributes = "";
			$this->Extra23->HrefValue = "";
		} elseif ($this->RowType == ROWTYPE_EDIT) { // Edit row

			// EmployeeID
			$this->EmployeeID->EditAttrs["class"] = "form-control";
			$this->EmployeeID->EditCustomAttributes = "";
			if ($this->EmployeeID->getSessionValue() <> "") {
				$this->EmployeeID->CurrentValue = $this->EmployeeID->getSessionValue();
				$this->EmployeeID->OldValue = $this->EmployeeID->CurrentValue;
			$curVal = strval($this->EmployeeID->CurrentValue);
			if ($curVal <> "") {
				$this->EmployeeID->ViewValue = $this->EmployeeID->lookupCacheOption($curVal);
				if ($this->EmployeeID->ViewValue === NULL) { // Lookup from database
					$filterWrk = "`EmployeeID`" . SearchString("=", $curVal, DATATYPE_NUMBER, "");
					$sqlWrk = $this->EmployeeID->Lookup->getSql(FALSE, $filterWrk, '', $this);
					$rswrk = Conn()->execute($sqlWrk);
					if ($rswrk && !$rswrk->EOF) { // Lookup values found
						$arwrk = array();
						$arwrk[1] = $rswrk->fields('df');
						$arwrk[2] = $rswrk->fields('df2');
						$arwrk[3] = $rswrk->fields('df3');
						$this->EmployeeID->ViewValue = $this->EmployeeID->displayValue($arwrk);
						$rswrk->Close();
					} else {
						$this->EmployeeID->ViewValue = $this->EmployeeID->CurrentValue;
					}
				}
			} else {
				$this->EmployeeID->ViewValue = NULL;
			}
			$this->EmployeeID->ViewCustomAttributes = "";
			} else {
			$curVal = trim(strval($this->EmployeeID->CurrentValue));
			if ($curVal <> "")
				$this->EmployeeID->ViewValue = $this->EmployeeID->lookupCacheOption($curVal);
			else
				$this->EmployeeID->ViewValue = $this->EmployeeID->Lookup !== NULL && is_array($this->EmployeeID->Lookup->Options) ? $curVal : NULL;
			if ($this->EmployeeID->ViewValue !== NULL) { // Load from cache
				$this->EmployeeID->EditValue = array_values($this->EmployeeID->Lookup->Options);
			} else { // Lookup from database
				if ($curVal == "") {
					$filterWrk = "0=1";
				} else {
					$filterWrk = "`EmployeeID`" . SearchString("=", $this->EmployeeID->CurrentValue, DATATYPE_NUMBER, "");
				}
				$sqlWrk = $this->EmployeeID->Lookup->getSql(TRUE, $filterWrk, '', $this);
				$rswrk = Conn()->execute($sqlWrk);
				$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
				if ($rswrk) $rswrk->Close();
				$this->EmployeeID->EditValue = $arwrk;
			}
			}

			// MaritalStatusID
			$this->MaritalStatusID->EditAttrs["class"] = "form-control";
			$this->MaritalStatusID->EditCustomAttributes = "";
			$curVal = trim(strval($this->MaritalStatusID->CurrentValue));
			if ($curVal <> "")
				$this->MaritalStatusID->ViewValue = $this->MaritalStatusID->lookupCacheOption($curVal);
			else
				$this->MaritalStatusID->ViewValue = $this->MaritalStatusID->Lookup !== NULL && is_array($this->MaritalStatusID->Lookup->Options) ? $curVal : NULL;
			if ($this->MaritalStatusID->ViewValue !== NULL) { // Load from cache
				$this->MaritalStatusID->EditValue = array_values($this->MaritalStatusID->Lookup->Options);
			} else { // Lookup from database
				if ($curVal == "") {
					$filterWrk = "0=1";
				} else {
					$filterWrk = "`MaritalStatusID`" . SearchString("=", $this->MaritalStatusID->CurrentValue, DATATYPE_NUMBER, "");
				}
				$sqlWrk = $this->MaritalStatusID->Lookup->getSql(TRUE, $filterWrk, '', $this);
				$rswrk = Conn()->execute($sqlWrk);
				$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
				if ($rswrk) $rswrk->Close();
				$this->MaritalStatusID->EditValue = $arwrk;
			}

			// CivilStatus#
			$this->CivilStatus23->EditAttrs["class"] = "form-control";
			$this->CivilStatus23->EditCustomAttributes = "";
			$this->CivilStatus23->EditValue = HtmlEncode($this->CivilStatus23->CurrentValue);
			$this->CivilStatus23->PlaceHolder = RemoveHtml($this->CivilStatus23->caption());

			// CivilStatusPlace
			$this->CivilStatusPlace->EditAttrs["class"] = "form-control";
			$this->CivilStatusPlace->EditCustomAttributes = "";
			$this->CivilStatusPlace->EditValue = HtmlEncode($this->CivilStatusPlace->CurrentValue);
			$this->CivilStatusPlace->PlaceHolder = RemoveHtml($this->CivilStatusPlace->caption());

			// IdCard#
			$this->IdCard23->EditAttrs["class"] = "form-control";
			$this->IdCard23->EditCustomAttributes = "";
			$this->IdCard23->EditValue = HtmlEncode($this->IdCard23->CurrentValue);
			$this->IdCard23->PlaceHolder = RemoveHtml($this->IdCard23->caption());

			// PracticingProfessionLicense#
			$this->PracticingProfessionLicense23->EditAttrs["class"] = "form-control";
			$this->PracticingProfessionLicense23->EditCustomAttributes = "";
			$this->PracticingProfessionLicense23->EditValue = HtmlEncode($this->PracticingProfessionLicense23->CurrentValue);
			$this->PracticingProfessionLicense23->PlaceHolder = RemoveHtml($this->PracticingProfessionLicense23->caption());

			// NationalId#
			$this->NationalId23->EditAttrs["class"] = "form-control";
			$this->NationalId23->EditCustomAttributes = "";
			$this->NationalId23->EditValue = HtmlEncode($this->NationalId23->CurrentValue);
			$this->NationalId23->PlaceHolder = RemoveHtml($this->NationalId23->caption());

			// Nationality1
			$this->Nationality1->EditAttrs["class"] = "form-control";
			$this->Nationality1->EditCustomAttributes = "";
			$this->Nationality1->EditValue = HtmlEncode($this->Nationality1->CurrentValue);
			$this->Nationality1->PlaceHolder = RemoveHtml($this->Nationality1->caption());

			// Nationality2
			$this->Nationality2->EditAttrs["class"] = "form-control";
			$this->Nationality2->EditCustomAttributes = "";
			$this->Nationality2->EditValue = HtmlEncode($this->Nationality2->CurrentValue);
			$this->Nationality2->PlaceHolder = RemoveHtml($this->Nationality2->caption());

			// Nationality3
			$this->Nationality3->EditAttrs["class"] = "form-control";
			$this->Nationality3->EditCustomAttributes = "";
			$this->Nationality3->EditValue = HtmlEncode($this->Nationality3->CurrentValue);
			$this->Nationality3->PlaceHolder = RemoveHtml($this->Nationality3->caption());

			// DriverLicense#
			$this->DriverLicense23->EditAttrs["class"] = "form-control";
			$this->DriverLicense23->EditCustomAttributes = "";
			$this->DriverLicense23->EditValue = HtmlEncode($this->DriverLicense23->CurrentValue);
			$this->DriverLicense23->PlaceHolder = RemoveHtml($this->DriverLicense23->caption());

			// Extra#
			$this->Extra23->EditAttrs["class"] = "form-control";
			$this->Extra23->EditCustomAttributes = "";
			$this->Extra23->EditValue = HtmlEncode($this->Extra23->CurrentValue);
			$this->Extra23->PlaceHolder = RemoveHtml($this->Extra23->caption());

			// Edit refer script
			// EmployeeID

			$this->EmployeeID->LinkCustomAttributes = "";
			$this->EmployeeID->HrefValue = "";

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

			// CivilStatus#
			$this->CivilStatus23->LinkCustomAttributes = "";
			$this->CivilStatus23->HrefValue = "";

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

			// IdCard#
			$this->IdCard23->LinkCustomAttributes = "";
			$this->IdCard23->HrefValue = "";

			// PracticingProfessionLicense#
			$this->PracticingProfessionLicense23->LinkCustomAttributes = "";
			$this->PracticingProfessionLicense23->HrefValue = "";

			// NationalId#
			$this->NationalId23->LinkCustomAttributes = "";
			$this->NationalId23->HrefValue = "";

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

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

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

			// DriverLicense#
			$this->DriverLicense23->LinkCustomAttributes = "";
			$this->DriverLicense23->HrefValue = "";

			// Extra#
			$this->Extra23->LinkCustomAttributes = "";
			$this->Extra23->HrefValue = "";
		}
		if ($this->RowType == ROWTYPE_ADD || $this->RowType == ROWTYPE_EDIT || $this->RowType == ROWTYPE_SEARCH) // Add/Edit/Search row
			$this->setupFieldTitles();

		// Call Row Rendered event
		if ($this->RowType <> ROWTYPE_AGGREGATEINIT)
			$this->Row_Rendered();
	}

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

		// Check if validation required
		if (!SERVER_VALIDATE)
			return ($FormError == "");
		if ($this->EmployeePersonID->Required) {
			if (!$this->EmployeePersonID->IsDetailKey && $this->EmployeePersonID->FormValue != NULL && $this->EmployeePersonID->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->EmployeePersonID->caption(), $this->EmployeePersonID->RequiredErrorMessage));
			}
		}
		if ($this->EmployeeID->Required) {
			if (!$this->EmployeeID->IsDetailKey && $this->EmployeeID->FormValue != NULL && $this->EmployeeID->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->EmployeeID->caption(), $this->EmployeeID->RequiredErrorMessage));
			}
		}
		if ($this->MaritalStatusID->Required) {
			if (!$this->MaritalStatusID->IsDetailKey && $this->MaritalStatusID->FormValue != NULL && $this->MaritalStatusID->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->MaritalStatusID->caption(), $this->MaritalStatusID->RequiredErrorMessage));
			}
		}
		if ($this->CivilStatus23->Required) {
			if (!$this->CivilStatus23->IsDetailKey && $this->CivilStatus23->FormValue != NULL && $this->CivilStatus23->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->CivilStatus23->caption(), $this->CivilStatus23->RequiredErrorMessage));
			}
		}
		if ($this->CivilStatusPlace->Required) {
			if (!$this->CivilStatusPlace->IsDetailKey && $this->CivilStatusPlace->FormValue != NULL && $this->CivilStatusPlace->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->CivilStatusPlace->caption(), $this->CivilStatusPlace->RequiredErrorMessage));
			}
		}
		if ($this->IdCard23->Required) {
			if (!$this->IdCard23->IsDetailKey && $this->IdCard23->FormValue != NULL && $this->IdCard23->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->IdCard23->caption(), $this->IdCard23->RequiredErrorMessage));
			}
		}
		if ($this->PracticingProfessionLicense23->Required) {
			if (!$this->PracticingProfessionLicense23->IsDetailKey && $this->PracticingProfessionLicense23->FormValue != NULL && $this->PracticingProfessionLicense23->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->PracticingProfessionLicense23->caption(), $this->PracticingProfessionLicense23->RequiredErrorMessage));
			}
		}
		if ($this->NationalId23->Required) {
			if (!$this->NationalId23->IsDetailKey && $this->NationalId23->FormValue != NULL && $this->NationalId23->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->NationalId23->caption(), $this->NationalId23->RequiredErrorMessage));
			}
		}
		if ($this->Nationality1->Required) {
			if (!$this->Nationality1->IsDetailKey && $this->Nationality1->FormValue != NULL && $this->Nationality1->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->Nationality1->caption(), $this->Nationality1->RequiredErrorMessage));
			}
		}
		if ($this->Nationality2->Required) {
			if (!$this->Nationality2->IsDetailKey && $this->Nationality2->FormValue != NULL && $this->Nationality2->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->Nationality2->caption(), $this->Nationality2->RequiredErrorMessage));
			}
		}
		if ($this->Nationality3->Required) {
			if (!$this->Nationality3->IsDetailKey && $this->Nationality3->FormValue != NULL && $this->Nationality3->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->Nationality3->caption(), $this->Nationality3->RequiredErrorMessage));
			}
		}
		if ($this->DriverLicense23->Required) {
			if (!$this->DriverLicense23->IsDetailKey && $this->DriverLicense23->FormValue != NULL && $this->DriverLicense23->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->DriverLicense23->caption(), $this->DriverLicense23->RequiredErrorMessage));
			}
		}
		if ($this->Extra23->Required) {
			if (!$this->Extra23->IsDetailKey && $this->Extra23->FormValue != NULL && $this->Extra23->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->Extra23->caption(), $this->Extra23->RequiredErrorMessage));
			}
		}
		if ($this->Notes->Required) {
			if (!$this->Notes->IsDetailKey && $this->Notes->FormValue != NULL && $this->Notes->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->Notes->caption(), $this->Notes->RequiredErrorMessage));
			}
		}
		if ($this->_UserID->Required) {
			if (!$this->_UserID->IsDetailKey && $this->_UserID->FormValue != NULL && $this->_UserID->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->_UserID->caption(), $this->_UserID->RequiredErrorMessage));
			}
		}
		if ($this->CreatedBy->Required) {
			if (!$this->CreatedBy->IsDetailKey && $this->CreatedBy->FormValue != NULL && $this->CreatedBy->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->CreatedBy->caption(), $this->CreatedBy->RequiredErrorMessage));
			}
		}
		if ($this->CreatedDate->Required) {
			if (!$this->CreatedDate->IsDetailKey && $this->CreatedDate->FormValue != NULL && $this->CreatedDate->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->CreatedDate->caption(), $this->CreatedDate->RequiredErrorMessage));
			}
		}
		if ($this->UpdatedBy->Required) {
			if (!$this->UpdatedBy->IsDetailKey && $this->UpdatedBy->FormValue != NULL && $this->UpdatedBy->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->UpdatedBy->caption(), $this->UpdatedBy->RequiredErrorMessage));
			}
		}
		if ($this->UpdatedDate->Required) {
			if (!$this->UpdatedDate->IsDetailKey && $this->UpdatedDate->FormValue != NULL && $this->UpdatedDate->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->UpdatedDate->caption(), $this->UpdatedDate->RequiredErrorMessage));
			}
		}

		// Return validate result
		$validateForm = ($FormError == "");

		// Call Form_CustomValidate event
		$formCustomError = "";
		$validateForm = $validateForm && $this->Form_CustomValidate($formCustomError);
		if ($formCustomError <> "") {
			AddMessage($FormError, $formCustomError);
		}
		return $validateForm;
	}

	// Delete records based on current filter
	protected function deleteRows()
	{
		global $Language, $Security;
		if (!$Security->canDelete()) {
			$this->setFailureMessage($Language->phrase("NoDeletePermission")); // No delete permission
			return FALSE;
		}
		$deleteRows = TRUE;
		$sql = $this->getCurrentSql();
		$conn = &$this->getConnection();
		$conn->raiseErrorFn = $GLOBALS["ERROR_FUNC"];
		$rs = $conn->execute($sql);
		$conn->raiseErrorFn = '';
		if ($rs === FALSE) {
			return FALSE;
		} elseif ($rs->EOF) {
			$this->setFailureMessage($Language->phrase("NoRecord")); // No record found
			$rs->close();
			return FALSE;
		}
		$rows = ($rs) ? $rs->getRows() : [];
		if ($this->AuditTrailOnDelete)
			$this->writeAuditTrailDummy($Language->phrase("BatchDeleteBegin")); // Batch delete begin

		// Clone old rows
		$rsold = $rows;
		if ($rs)
			$rs->close();

		// Call row deleting event
		if ($deleteRows) {
			foreach ($rsold as $row) {
				$deleteRows = $this->Row_Deleting($row);
				if (!$deleteRows)
					break;
			}
		}
		if ($deleteRows) {
			$key = "";
			foreach ($rsold as $row) {
				$thisKey = "";
				if ($thisKey <> "")
					$thisKey .= $GLOBALS["COMPOSITE_KEY_SEPARATOR"];
				$thisKey .= $row['EmployeePersonID'];
				if (DELETE_UPLOADED_FILES) // Delete old files
					$this->deleteUploadedFiles($row);
				$conn->raiseErrorFn = $GLOBALS["ERROR_FUNC"];
				$deleteRows = $this->delete($row); // Delete
				$conn->raiseErrorFn = '';
				if ($deleteRows === FALSE)
					break;
				if ($key <> "")
					$key .= ", ";
				$key .= $thisKey;
			}
		}
		if (!$deleteRows) {

			// Set up error message
			if ($this->getSuccessMessage() <> "" || $this->getFailureMessage() <> "") {

				// Use the message, do nothing
			} elseif ($this->CancelMessage <> "") {
				$this->setFailureMessage($this->CancelMessage);
				$this->CancelMessage = "";
			} else {
				$this->setFailureMessage($Language->phrase("DeleteCancelled"));
			}
		}

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

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

	// Update record based on key values
	protected function editRow()
	{
		global $Security, $Language;
		$filter = $this->getRecordFilter();
		$filter = $this->applyUserIDFilters($filter);
		$conn = &$this->getConnection();
		$this->CurrentFilter = $filter;
		$sql = $this->getCurrentSql();
		$conn->raiseErrorFn = $GLOBALS["ERROR_FUNC"];
		$rs = $conn->execute($sql);
		$conn->raiseErrorFn = '';
		if ($rs === FALSE)
			return FALSE;
		if ($rs->EOF) {
			$this->setFailureMessage($Language->phrase("NoRecord")); // Set no record message
			$editRow = FALSE; // Update Failed
		} else {

			// Save old values
			$rsold = &$rs->fields;
			$this->loadDbValues($rsold);
			$rsnew = [];

			// EmployeeID
			$this->EmployeeID->setDbValueDef($rsnew, $this->EmployeeID->CurrentValue, 0, $this->EmployeeID->ReadOnly);

			// MaritalStatusID
			$this->MaritalStatusID->setDbValueDef($rsnew, $this->MaritalStatusID->CurrentValue, NULL, $this->MaritalStatusID->ReadOnly);

			// CivilStatus#
			$this->CivilStatus23->setDbValueDef($rsnew, $this->CivilStatus23->CurrentValue, NULL, $this->CivilStatus23->ReadOnly);

			// CivilStatusPlace
			$this->CivilStatusPlace->setDbValueDef($rsnew, $this->CivilStatusPlace->CurrentValue, NULL, $this->CivilStatusPlace->ReadOnly);

			// IdCard#
			$this->IdCard23->setDbValueDef($rsnew, $this->IdCard23->CurrentValue, NULL, $this->IdCard23->ReadOnly);

			// PracticingProfessionLicense#
			$this->PracticingProfessionLicense23->setDbValueDef($rsnew, $this->PracticingProfessionLicense23->CurrentValue, NULL, $this->PracticingProfessionLicense23->ReadOnly);

			// NationalId#
			$this->NationalId23->setDbValueDef($rsnew, $this->NationalId23->CurrentValue, NULL, $this->NationalId23->ReadOnly);

			// Nationality1
			$this->Nationality1->setDbValueDef($rsnew, $this->Nationality1->CurrentValue, NULL, $this->Nationality1->ReadOnly);

			// Nationality2
			$this->Nationality2->setDbValueDef($rsnew, $this->Nationality2->CurrentValue, NULL, $this->Nationality2->ReadOnly);

			// Nationality3
			$this->Nationality3->setDbValueDef($rsnew, $this->Nationality3->CurrentValue, NULL, $this->Nationality3->ReadOnly);

			// DriverLicense#
			$this->DriverLicense23->setDbValueDef($rsnew, $this->DriverLicense23->CurrentValue, NULL, $this->DriverLicense23->ReadOnly);

			// Extra#
			$this->Extra23->setDbValueDef($rsnew, $this->Extra23->CurrentValue, NULL, $this->Extra23->ReadOnly);

			// Call Row Updating event
			$updateRow = $this->Row_Updating($rsold, $rsnew);
			if ($updateRow) {
				$conn->raiseErrorFn = $GLOBALS["ERROR_FUNC"];
				if (count($rsnew) > 0)
					$editRow = $this->update($rsnew, "", $rsold);
				else
					$editRow = TRUE; // No field to update
				$conn->raiseErrorFn = '';
				if ($editRow) {
				}
			} else {
				if ($this->getSuccessMessage() <> "" || $this->getFailureMessage() <> "") {

					// Use the message, do nothing
				} elseif ($this->CancelMessage <> "") {
					$this->setFailureMessage($this->CancelMessage);
					$this->CancelMessage = "";
				} else {
					$this->setFailureMessage($Language->phrase("UpdateCancelled"));
				}
				$editRow = FALSE;
			}
		}

		// Call Row_Updated event
		if ($editRow)
			$this->Row_Updated($rsold, $rsnew);
		$rs->close();

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

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

		// Check if valid key values for master user
		if ($Security->currentUserID() <> "" && !$Security->isAdmin()) { // Non system admin
			$masterFilter = $this->sqlMasterFilter_employees();
			if (strval($this->EmployeeID->CurrentValue) <> "") {
				$masterFilter = str_replace("@EmployeeID@", AdjustSql($this->EmployeeID->CurrentValue, "DB"), $masterFilter);
			} else {
				$masterFilter = "";
			}
			if ($masterFilter <> "") {
				$rsmaster = $GLOBALS["employees"]->loadRs($masterFilter);
				$this->MasterRecordExists = ($rsmaster && !$rsmaster->EOF);
				$validMasterKey = TRUE;
				if ($this->MasterRecordExists) {
					$validMasterKey = $Security->isValidUserID($rsmaster->fields['EmployeeID']);
				} elseif ($this->getCurrentMasterTable() == "employees") {
					$validMasterKey = FALSE;
				}
				if (!$validMasterKey) {
					$masterUserIdMsg = str_replace("%c", CurrentUserID(), $Language->phrase("UnAuthorizedMasterUserID"));
					$masterUserIdMsg = str_replace("%f", $sMasterFilter, $masterUserIdMsg);
					$this->setFailureMessage($masterUserIdMsg);
					return FALSE;
				}
				if ($rsmaster)
					$rsmaster->close();
			}
		}

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

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

		// EmployeeID
		$this->EmployeeID->setDbValueDef($rsnew, $this->EmployeeID->CurrentValue, 0, FALSE);

		// MaritalStatusID
		$this->MaritalStatusID->setDbValueDef($rsnew, $this->MaritalStatusID->CurrentValue, NULL, FALSE);

		// CivilStatus#
		$this->CivilStatus23->setDbValueDef($rsnew, $this->CivilStatus23->CurrentValue, NULL, FALSE);

		// CivilStatusPlace
		$this->CivilStatusPlace->setDbValueDef($rsnew, $this->CivilStatusPlace->CurrentValue, NULL, FALSE);

		// IdCard#
		$this->IdCard23->setDbValueDef($rsnew, $this->IdCard23->CurrentValue, NULL, FALSE);

		// PracticingProfessionLicense#
		$this->PracticingProfessionLicense23->setDbValueDef($rsnew, $this->PracticingProfessionLicense23->CurrentValue, NULL, FALSE);

		// NationalId#
		$this->NationalId23->setDbValueDef($rsnew, $this->NationalId23->CurrentValue, NULL, FALSE);

		// Nationality1
		$this->Nationality1->setDbValueDef($rsnew, $this->Nationality1->CurrentValue, NULL, FALSE);

		// Nationality2
		$this->Nationality2->setDbValueDef($rsnew, $this->Nationality2->CurrentValue, NULL, FALSE);

		// Nationality3
		$this->Nationality3->setDbValueDef($rsnew, $this->Nationality3->CurrentValue, NULL, FALSE);

		// DriverLicense#
		$this->DriverLicense23->setDbValueDef($rsnew, $this->DriverLicense23->CurrentValue, NULL, FALSE);

		// Extra#
		$this->Extra23->setDbValueDef($rsnew, $this->Extra23->CurrentValue, NULL, FALSE);

		// Call Row Inserting event
		$rs = ($rsold) ? $rsold->fields : NULL;
		$insertRow = $this->Row_Inserting($rs, $rsnew);
		if ($insertRow) {
			$conn->raiseErrorFn = $GLOBALS["ERROR_FUNC"];
			$addRow = $this->insert($rsnew);
			$conn->raiseErrorFn = '';
			if ($addRow) {
			}
		} else {
			if ($this->getSuccessMessage() <> "" || $this->getFailureMessage() <> "") {

				// Use the message, do nothing
			} elseif ($this->CancelMessage <> "") {
				$this->setFailureMessage($this->CancelMessage);
				$this->CancelMessage = "";
			} else {
				$this->setFailureMessage($Language->phrase("InsertCancelled"));
			}
			$addRow = FALSE;
		}
		if ($addRow) {

			// Call Row Inserted event
			$rs = ($rsold) ? $rsold->fields : NULL;
			$this->Row_Inserted($rs, $rsnew);
		}

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

	// Set up master/detail based on QueryString
	protected function setupMasterParms()
	{

		// Hide foreign keys
		$masterTblVar = $this->getCurrentMasterTable();
		if ($masterTblVar == "employees") {
			$this->EmployeeID->Visible = FALSE;
			if ($GLOBALS["employees"]->EventCancelled)
				$this->EventCancelled = TRUE;
		}
		$this->DbMasterFilter = $this->getMasterFilter(); // Get master filter
		$this->DbDetailFilter = $this->getDetailFilter(); // Get detail filter
	}

	// Setup lookup options
	public function setupLookupOptions($fld)
	{
		if ($fld->Lookup !== NULL && $fld->Lookup->Options === NULL) {

			// No need to check any more
			$fld->Lookup->Options = [];

			// Set up lookup SQL
			switch ($fld->FieldVar) {
				default:
					$lookupFilter = "";
					break;
			}

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

			// Set up lookup cache
			if ($fld->UseLookupCache && $sql <> "" && count($fld->Lookup->Options) == 0) {
				$conn = &$this->getConnection();
				$totalCnt = $this->getRecordCount($sql);
				if ($totalCnt > $fld->LookupCacheCount) // Total count > cache count, do not cache
					return;
				$rs = $conn->execute($sql);
				$ar = [];
				while ($rs && !$rs->EOF) {
					$row = &$rs->fields;

					// Format the field values
					switch ($fld->FieldVar) {
						case "x_EmployeeID":
							break;
						case "x_MaritalStatusID":
							break;
					}
					$ar[strval($row[0])] = $row;
					$rs->moveNext();
				}
				if ($rs)
					$rs->close();
				$fld->Lookup->Options = $ar;
			}
		}
	}

	// Page Load event
	function Page_Load() {

		//echo "Page Load";
	}

	// Page Unload event
	function Page_Unload() {

		//echo "Page Unload";
	}

	// Page Redirecting event
	function Page_Redirecting(&$url) {

		// Example:
		//$url = "your URL";

	}

	// Message Showing event
	// $type = ''|'success'|'failure'|'warning'
	function Message_Showing(&$msg, $type) {
		if ($type == 'success') {

			//$msg = "your success message";
		} elseif ($type == 'failure') {

			//$msg = "your failure message";
		} elseif ($type == 'warning') {

			//$msg = "your warning message";
		} else {

			//$msg = "your message";
		}
	}

	// Page Render event
	function Page_Render() {

		//echo "Page Render";
	}

	// Page Data Rendering event
	function Page_DataRendering(&$header) {

		// Example:
		//$header = "your header";

	}

	// Page Data Rendered event
	function Page_DataRendered(&$footer) {

		// Example:
		//$footer = "your footer";

	}

	// Form Custom Validate event
	function Form_CustomValidate(&$customError) {

		// Return error message in CustomError
		return TRUE;
	}

	// ListOptions Load event
	function ListOptions_Load() {

		// Example:
		//$opt = &$this->ListOptions->Add("new");
		//$opt->Header = "xxx";
		//$opt->OnLeft = TRUE; // Link on left
		//$opt->MoveTo(0); // Move to first column

	}

	// ListOptions Rendering event
	function ListOptions_Rendering() {

		//$GLOBALS["xxx_grid"]->DetailAdd = (...condition...); // Set to TRUE or FALSE conditionally
		//$GLOBALS["xxx_grid"]->DetailEdit = (...condition...); // Set to TRUE or FALSE conditionally
		//$GLOBALS["xxx_grid"]->DetailView = (...condition...); // Set to TRUE or FALSE conditionally

	}

	// ListOptions Rendered event
	function ListOptions_Rendered() {

		// Example:
		//$this->ListOptions->Items["new"]->Body = "xxx";

	}
}
?>
