<?php
namespace PHPMaker2019\project_germanos;

/**
 * Page class
 */
class clientadditinalinfo_edit extends clientadditinalinfo
{

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

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

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

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

	// 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
		$GLOBALS["Page"] = &$this;
		$this->TokenTimeout = SessionTimeoutTime();

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

		// Parent constuctor
		parent::__construct();

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

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

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

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

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

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

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

		// Page Unload event
		$this->Page_Unload();

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

		// Export
		global $EXPORT, $clientadditinalinfo;
		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($clientadditinalinfo);
				$doc->Text = @$content;
				if ($this->isExport("email"))
					echo $this->exportEmail($doc->Text);
				else
					$doc->export();
				DeleteTempImages(); // Delete temp images
				exit();
			}
		}
		if (!IsApi())
			$this->Page_Redirecting($url);

		// Close connection
		CloseConnections();

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

			// Handle modal response
			if ($this->IsModal) { // Show as modal
				$row = array("url" => $url, "modal" => "1");
				$pageName = GetPageName($url);
				if ($pageName != $this->getListUrl()) { // Not List page
					$row["caption"] = $this->getModalCaption($pageName);
					if ($pageName == "clientadditinalinfoview.php")
						$row["view"] = "1";
				} else { // List page should not be shown as modal => error
					$row["error"] = $this->getFailureMessage();
					$this->clearFailureMessage();
				}
				WriteJson($row);
			} else {
				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['ClientInfoID'];
		}
		return $key;
	}

	/**
	 * Hide fields for add/edit
	 *
	 * @return void
	 */
	protected function hideFieldsForAddEdit()
	{
		if ($this->isAdd() || $this->isCopy() || $this->isGridAdd())
			$this->ClientInfoID->Visible = FALSE;
	}
	public $FormClassName = "ew-horizontal ew-form ew-edit-form";
	public $IsModal = FALSE;
	public $IsMobileOrModal = FALSE;
	public $DbMasterFilter;
	public $DbDetailFilter;
	public $DisplayRecs = 1;
	public $StartRec;
	public $StopRec;
	public $TotalRecs = 0;
	public $RecRange = 10;
	public $Pager;
	public $AutoHidePager = AUTO_HIDE_PAGER;
	public $RecCnt;

	//
	// Page run
	//

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

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

		// Is modal
		$this->IsModal = (Param("modal") == "1");

		// 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->canEdit()) {
				$Security->saveLastUrl();
				$this->setFailureMessage(DeniedMessage()); // Set no permission
				if ($Security->canList())
					$this->terminate(GetUrl("clientadditinalinfolist.php"));
				else
					$this->terminate(GetUrl("login.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();
		}

		// Create form object
		$CurrentForm = new HttpForm();
		$this->CurrentAction = Param("action"); // Set up current action
		$this->ClientInfoID->setVisibility();
		$this->ClientID->setVisibility();
		$this->Notes->setVisibility();
		$this->MaritalStatusID->setVisibility();
		$this->CivilStatus23->setVisibility();
		$this->CivilStatusPlace->setVisibility();
		$this->IdCard23->setVisibility();
		$this->NationalId23->setVisibility();
		$this->Nationality1->setVisibility();
		$this->Nationality2->setVisibility();
		$this->Nationality3->setVisibility();
		$this->DriverLicense23->setVisibility();
		$this->SocialSecurity23->setVisibility();
		$this->Financial23->setVisibility();
		$this->Extra23->setVisibility();
		$this->Field1->setVisibility();
		$this->Field2->setVisibility();
		$this->Field3->setVisibility();
		$this->_UserID->Visible = FALSE;
		$this->CreatedBy->Visible = FALSE;
		$this->CreatedDate->Visible = FALSE;
		$this->UpdatedBy->Visible = FALSE;
		$this->UpdatedDate->Visible = FALSE;
		$this->hideFieldsForAddEdit();

		// Do not use lookup cache
		$this->setUseLookupCache(FALSE);

		// 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 lookup cache
		$this->setupLookupOptions($this->ClientID);
		$this->setupLookupOptions($this->MaritalStatusID);

		// Check modal
		if ($this->IsModal)
			$SkipHeaderFooter = TRUE;
		$this->IsMobileOrModal = IsMobile() || $this->IsModal;
		$this->FormClassName = "ew-form ew-edit-form ew-horizontal";

		// Load record by position
		$loadByPosition = FALSE;
		$loaded = FALSE;
		$postBack = FALSE;

		// Set up current action and primary key
		if (IsApi()) {
			$this->CurrentAction = "update"; // Update record directly
			$postBack = TRUE;
		} elseif (Post("action") !== NULL) {
			$this->CurrentAction = Post("action"); // Get action code
			if (!$this->isShow()) // Not reload record, handle as postback
				$postBack = TRUE;

			// Load key from Form
			if ($CurrentForm->hasValue("x_ClientInfoID")) {
				$this->ClientInfoID->setFormValue($CurrentForm->getValue("x_ClientInfoID"));
			}
		} else {
			$this->CurrentAction = "show"; // Default action is display

			// Load key from QueryString
			$loadByQuery = FALSE;
			if (Get("ClientInfoID") !== NULL) {
				$this->ClientInfoID->setQueryStringValue(Get("ClientInfoID"));
				$loadByQuery = TRUE;
			} else {
				$this->ClientInfoID->CurrentValue = NULL;
			}
			if (!$loadByQuery)
				$loadByPosition = TRUE;
		}

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

		// Load recordset
		$this->StartRec = 1; // Initialize start position
		if ($rs = $this->loadRecordset()) // Load records
			$this->TotalRecs = $rs->RecordCount(); // Get record count
		if ($this->TotalRecs <= 0) { // No record found
			if ($this->getSuccessMessage() == "" && $this->getFailureMessage() == "")
				$this->setFailureMessage($Language->phrase("NoRecord")); // Set no record message
			$this->terminate("clientadditinalinfolist.php"); // Return to list page
		} elseif ($loadByPosition) { // Load record by position
			$this->setupStartRec(); // Set up start record position

			// Point to current record
			if ($this->StartRec <= $this->TotalRecs) {
				$rs->move($this->StartRec - 1);
				$loaded = TRUE;
			}
		} else { // Match key values
			if ($this->ClientInfoID->CurrentValue != NULL) {
				while (!$rs->EOF) {
					if (SameString($this->ClientInfoID->CurrentValue, $rs->fields('ClientInfoID'))) {
						$this->setStartRecordNumber($this->StartRec); // Save record position
						$loaded = TRUE;
						break;
					} else {
						$this->StartRec++;
						$rs->moveNext();
					}
				}
			}
		}

		// Load current row values
		if ($loaded)
			$this->loadRowValues($rs);

		// Process form if post back
		if ($postBack) {
			$this->loadFormValues(); // Get form values
		}

		// Validate form if post back
		if ($postBack) {
			if (!$this->validateForm()) {
				$this->setFailureMessage($FormError);
				$this->EventCancelled = TRUE; // Event cancelled
				$this->restoreFormValues();
				if (IsApi()) {
					$this->terminate();
					return;
				} else {
					$this->CurrentAction = ""; // Form error, reset action
				}
			}
		}

		// Perform current action
		switch ($this->CurrentAction) {
			case "show": // Get a record to display
				if (!$loaded) {
					if ($this->getSuccessMessage() == "" && $this->getFailureMessage() == "")
						$this->setFailureMessage($Language->phrase("NoRecord")); // Set no record message
					$this->terminate("clientadditinalinfolist.php"); // Return to list page
				} else {
				}
				break;
			case "update": // Update
				$returnUrl = $this->getReturnUrl();
				if (GetPageName($returnUrl) == "clientadditinalinfolist.php")
					$returnUrl = $this->addMasterUrl($returnUrl); // List page, return to List page with correct master key if necessary
				$this->SendEmail = TRUE; // Send email on update success
				if ($this->editRow()) { // Update record based on key
					if ($this->getSuccessMessage() == "")
						$this->setSuccessMessage($Language->phrase("UpdateSuccess")); // Update success
					if (IsApi()) {
						$this->terminate(TRUE);
						return;
					} else {
						$this->terminate($returnUrl); // Return to caller
					}
				} elseif (IsApi()) { // API request, return
					$this->terminate();
					return;
				} elseif ($this->getFailureMessage() == $Language->phrase("NoRecord")) {
					$this->terminate($returnUrl); // Return to caller
				} else {
					$this->EventCancelled = TRUE; // Event cancelled
					$this->restoreFormValues(); // Restore form values if update failed
				}
		}

		// Set up Breadcrumb
		$this->setupBreadcrumb();

		// Render the record
		$this->RowType = ROWTYPE_EDIT; // Render as Edit
		$this->resetAttributes();
		$this->renderRow();
	}

	// 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 form values
	protected function loadFormValues()
	{

		// Load from form
		global $CurrentForm;

		// Check field name 'ClientInfoID' first before field var 'x_ClientInfoID'
		$val = $CurrentForm->hasValue("ClientInfoID") ? $CurrentForm->getValue("ClientInfoID") : $CurrentForm->getValue("x_ClientInfoID");
		if (!$this->ClientInfoID->IsDetailKey)
			$this->ClientInfoID->setFormValue($val);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	// Restore form values
	public function restoreFormValues()
	{
		global $CurrentForm;
		$this->ClientInfoID->CurrentValue = $this->ClientInfoID->FormValue;
		$this->ClientID->CurrentValue = $this->ClientID->FormValue;
		$this->Notes->CurrentValue = $this->Notes->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->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->SocialSecurity23->CurrentValue = $this->SocialSecurity23->FormValue;
		$this->Financial23->CurrentValue = $this->Financial23->FormValue;
		$this->Extra23->CurrentValue = $this->Extra23->FormValue;
		$this->Field1->CurrentValue = $this->Field1->FormValue;
		$this->Field2->CurrentValue = $this->Field2->FormValue;
		$this->Field3->CurrentValue = $this->Field3->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->ClientInfoID->setDbValue($row['ClientInfoID']);
		$this->ClientID->setDbValue($row['ClientID']);
		$this->Notes->setDbValue($row['Notes']);
		$this->MaritalStatusID->setDbValue($row['MaritalStatusID']);
		$this->CivilStatus23->setDbValue($row['CivilStatus#']);
		$this->CivilStatusPlace->setDbValue($row['CivilStatusPlace']);
		$this->IdCard23->setDbValue($row['IdCard#']);
		$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->SocialSecurity23->setDbValue($row['SocialSecurity#']);
		$this->Financial23->setDbValue($row['Financial#']);
		$this->Extra23->setDbValue($row['Extra#']);
		$this->Field1->setDbValue($row['Field1']);
		$this->Field2->setDbValue($row['Field2']);
		$this->Field3->setDbValue($row['Field3']);
		$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()
	{
		$row = [];
		$row['ClientInfoID'] = NULL;
		$row['ClientID'] = NULL;
		$row['Notes'] = NULL;
		$row['MaritalStatusID'] = NULL;
		$row['CivilStatus#'] = NULL;
		$row['CivilStatusPlace'] = NULL;
		$row['IdCard#'] = NULL;
		$row['NationalId#'] = NULL;
		$row['Nationality1'] = NULL;
		$row['Nationality2'] = NULL;
		$row['Nationality3'] = NULL;
		$row['DriverLicense#'] = NULL;
		$row['SocialSecurity#'] = NULL;
		$row['Financial#'] = NULL;
		$row['Extra#'] = NULL;
		$row['Field1'] = NULL;
		$row['Field2'] = NULL;
		$row['Field3'] = NULL;
		$row['UserID'] = NULL;
		$row['CreatedBy'] = NULL;
		$row['CreatedDate'] = NULL;
		$row['UpdatedBy'] = NULL;
		$row['UpdatedDate'] = NULL;
		return $row;
	}

	// Load old record
	protected function loadOldRecord()
	{

		// Load key values from Session
		$validKey = TRUE;
		if (strval($this->getKey("ClientInfoID")) <> "")
			$this->ClientInfoID->CurrentValue = $this->getKey("ClientInfoID"); // ClientInfoID
		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
		// Call Row_Rendering event

		$this->Row_Rendering();

		// Common render codes for all row types
		// ClientInfoID
		// ClientID
		// Notes
		// MaritalStatusID
		// CivilStatus#
		// CivilStatusPlace
		// IdCard#
		// NationalId#
		// Nationality1
		// Nationality2
		// Nationality3
		// DriverLicense#
		// SocialSecurity#
		// Financial#
		// Extra#
		// Field1
		// Field2
		// Field3
		// UserID
		// CreatedBy
		// CreatedDate
		// UpdatedBy
		// UpdatedDate

		if ($this->RowType == ROWTYPE_VIEW) { // View row

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

			// ClientID
			$curVal = strval($this->ClientID->CurrentValue);
			if ($curVal <> "") {
				$this->ClientID->ViewValue = $this->ClientID->lookupCacheOption($curVal);
				if ($this->ClientID->ViewValue === NULL) { // Lookup from database
					$filterWrk = "`ClientID`" . SearchString("=", $curVal, DATATYPE_NUMBER, "");
					$sqlWrk = $this->ClientID->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->ClientID->ViewValue = $this->ClientID->displayValue($arwrk);
						$rswrk->Close();
					} else {
						$this->ClientID->ViewValue = $this->ClientID->CurrentValue;
					}
				}
			} else {
				$this->ClientID->ViewValue = NULL;
			}
			$this->ClientID->ViewCustomAttributes = "";

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

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

			// SocialSecurity#
			$this->SocialSecurity23->ViewValue = $this->SocialSecurity23->CurrentValue;
			$this->SocialSecurity23->ViewCustomAttributes = "";

			// Financial#
			$this->Financial23->ViewValue = $this->Financial23->CurrentValue;
			$this->Financial23->ViewCustomAttributes = "";

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

			// SocialSecurity#
			$this->SocialSecurity23->LinkCustomAttributes = "";
			$this->SocialSecurity23->HrefValue = "";
			$this->SocialSecurity23->TooltipValue = "";

			// Financial#
			$this->Financial23->LinkCustomAttributes = "";
			$this->Financial23->HrefValue = "";
			$this->Financial23->TooltipValue = "";

			// Extra#
			$this->Extra23->LinkCustomAttributes = "";
			$this->Extra23->HrefValue = "";
			$this->Extra23->TooltipValue = "";

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

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

			// Field3
			$this->Field3->LinkCustomAttributes = "";
			$this->Field3->HrefValue = "";
			$this->Field3->TooltipValue = "";
		} elseif ($this->RowType == ROWTYPE_EDIT) { // Edit row

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

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

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

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

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

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

			// Financial#
			$this->Financial23->EditAttrs["class"] = "form-control";
			$this->Financial23->EditCustomAttributes = "";
			$this->Financial23->EditValue = HtmlEncode($this->Financial23->CurrentValue);
			$this->Financial23->PlaceHolder = RemoveHtml($this->Financial23->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());

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

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

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

			// Edit refer script
			// ClientInfoID

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

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

			// Notes
			$this->Notes->LinkCustomAttributes = "";
			$this->Notes->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 = "";

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

			// SocialSecurity#
			$this->SocialSecurity23->LinkCustomAttributes = "";
			$this->SocialSecurity23->HrefValue = "";

			// Financial#
			$this->Financial23->LinkCustomAttributes = "";
			$this->Financial23->HrefValue = "";

			// Extra#
			$this->Extra23->LinkCustomAttributes = "";
			$this->Extra23->HrefValue = "";

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

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

			// Field3
			$this->Field3->LinkCustomAttributes = "";
			$this->Field3->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;

		// Initialize form error message
		$FormError = "";

		// Check if validation required
		if (!SERVER_VALIDATE)
			return ($FormError == "");
		if ($this->ClientInfoID->Required) {
			if (!$this->ClientInfoID->IsDetailKey && $this->ClientInfoID->FormValue != NULL && $this->ClientInfoID->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->ClientInfoID->caption(), $this->ClientInfoID->RequiredErrorMessage));
			}
		}
		if ($this->ClientID->Required) {
			if (!$this->ClientID->IsDetailKey && $this->ClientID->FormValue != NULL && $this->ClientID->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->ClientID->caption(), $this->ClientID->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->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->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->SocialSecurity23->Required) {
			if (!$this->SocialSecurity23->IsDetailKey && $this->SocialSecurity23->FormValue != NULL && $this->SocialSecurity23->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->SocialSecurity23->caption(), $this->SocialSecurity23->RequiredErrorMessage));
			}
		}
		if ($this->Financial23->Required) {
			if (!$this->Financial23->IsDetailKey && $this->Financial23->FormValue != NULL && $this->Financial23->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->Financial23->caption(), $this->Financial23->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->Field1->Required) {
			if (!$this->Field1->IsDetailKey && $this->Field1->FormValue != NULL && $this->Field1->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->Field1->caption(), $this->Field1->RequiredErrorMessage));
			}
		}
		if ($this->Field2->Required) {
			if (!$this->Field2->IsDetailKey && $this->Field2->FormValue != NULL && $this->Field2->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->Field2->caption(), $this->Field2->RequiredErrorMessage));
			}
		}
		if ($this->Field3->Required) {
			if (!$this->Field3->IsDetailKey && $this->Field3->FormValue != NULL && $this->Field3->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->Field3->caption(), $this->Field3->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;
	}

	// 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 = [];

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

			// Notes
			$this->Notes->setDbValueDef($rsnew, $this->Notes->CurrentValue, NULL, $this->Notes->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);

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

			// SocialSecurity#
			$this->SocialSecurity23->setDbValueDef($rsnew, $this->SocialSecurity23->CurrentValue, NULL, $this->SocialSecurity23->ReadOnly);

			// Financial#
			$this->Financial23->setDbValueDef($rsnew, $this->Financial23->CurrentValue, NULL, $this->Financial23->ReadOnly);

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

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

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

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

	// Set up master/detail based on QueryString
	protected function setupMasterParms()
	{
		$validMaster = FALSE;

		// Get the keys for master table
		if (Get(TABLE_SHOW_MASTER) !== NULL) {
			$masterTblVar = Get(TABLE_SHOW_MASTER);
			if ($masterTblVar == "") {
				$validMaster = TRUE;
				$this->DbMasterFilter = "";
				$this->DbDetailFilter = "";
			}
			if ($masterTblVar == "clients") {
				$validMaster = TRUE;
				if (Get("fk_ClientID") !== NULL) {
					$GLOBALS["clients"]->ClientID->setQueryStringValue(Get("fk_ClientID"));
					$this->ClientID->setQueryStringValue($GLOBALS["clients"]->ClientID->QueryStringValue);
					$this->ClientID->setSessionValue($this->ClientID->QueryStringValue);
					if (!is_numeric($GLOBALS["clients"]->ClientID->QueryStringValue))
						$validMaster = FALSE;
				} else {
					$validMaster = FALSE;
				}
			}
		} elseif (Post(TABLE_SHOW_MASTER) !== NULL) {
			$masterTblVar = Post(TABLE_SHOW_MASTER);
			if ($masterTblVar == "") {
				$validMaster = TRUE;
				$this->DbMasterFilter = "";
				$this->DbDetailFilter = "";
			}
			if ($masterTblVar == "clients") {
				$validMaster = TRUE;
				if (Post("fk_ClientID") !== NULL) {
					$GLOBALS["clients"]->ClientID->setFormValue(Post("fk_ClientID"));
					$this->ClientID->setFormValue($GLOBALS["clients"]->ClientID->FormValue);
					$this->ClientID->setSessionValue($this->ClientID->FormValue);
					if (!is_numeric($GLOBALS["clients"]->ClientID->FormValue))
						$validMaster = FALSE;
				} else {
					$validMaster = FALSE;
				}
			}
		}
		if ($validMaster) {

			// Save current master table
			$this->setCurrentMasterTable($masterTblVar);
			$this->setSessionWhere($this->getDetailFilter());

			// Reset start record counter (new master key)
			if (!$this->isAddOrEdit()) {
				$this->StartRec = 1;
				$this->setStartRecordNumber($this->StartRec);
			}

			// Clear previous master key from Session
			if ($masterTblVar <> "clients") {
				if ($this->ClientID->CurrentValue == "")
					$this->ClientID->setSessionValue("");
			}
		}
		$this->DbMasterFilter = $this->getMasterFilter(); // Get master filter
		$this->DbDetailFilter = $this->getDetailFilter(); // Get detail filter
	}

	// Set up Breadcrumb
	protected function setupBreadcrumb()
	{
		global $Breadcrumb, $Language;
		$Breadcrumb = new Breadcrumb();
		$url = substr(CurrentUrl(), strrpos(CurrentUrl(), "/")+1);
		$Breadcrumb->add("list", $this->TableVar, $this->addMasterUrl("clientadditinalinfolist.php"), "", $this->TableVar, TRUE);
		$pageId = "edit";
		$Breadcrumb->add("edit", $pageId, $url);
	}

	// 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_ClientID":
							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;
	}
}
?>
