Heray-Was-Here
Server : Apache
System : Linux hybrid3195.ca.ns.planethoster.net 3.10.0-1160.119.1.el7.tuxcare.els19.x86_64 #1 SMP Mon Mar 31 17:29:00 UTC 2025 x86_64
User : alliancerealtynb ( 1004)
PHP Version : 7.4.33
Disable Function : noop
Directory :  /home/alliancerealtynb/dev.alliancerealty.nb.ca/adminAR/classes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/alliancerealtynb/dev.alliancerealty.nb.ca/adminAR/classes/wp_wpl_addon_crm_contacts_add.php
<?php
namespace PHPMaker2020\Alliance;

/**
 * Page class
 */
class wp_wpl_addon_crm_contacts_add extends wp_wpl_addon_crm_contacts
{

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

	// Project ID
	public $ProjectID = "{FE4AA35B-E768-461D-8010-4FE2D8E13345}";

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

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

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

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

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

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

	// 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 = TRUE;
		$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 fas 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 fas fa-exclamation"></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 fas 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 fas 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 = [];

		// 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(Config("TOKEN_NAME")) === NULL)
			return FALSE;
		$fn = Config("CHECK_TOKEN_FUNC");
		if (is_callable($fn))
			return $fn(Post(Config("TOKEN_NAME")), $this->TokenTimeout);
		return FALSE;
	}

	// Create Token
	public function createToken()
	{
		global $CurrentToken;
		$fn = Config("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, $DashboardReport;

		// Check token
		$this->CheckToken = Config("CHECK_TOKEN");

		// Initialize
		$GLOBALS["Page"] = &$this;
		$this->TokenTimeout = SessionTimeoutTime();

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

		// Parent constuctor
		parent::__construct();

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

		// Page ID (for backward compatibility only)
		if (!defined(PROJECT_NAMESPACE . "PAGE_ID"))
			define(PROJECT_NAMESPACE . "PAGE_ID", 'add');

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

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

		// Debug message
		LoadDebugMessage();

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

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

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

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

		// Export
		global $wp_wpl_addon_crm_contacts;
		if ($this->CustomExport && $this->CustomExport == $this->Export && array_key_exists($this->CustomExport, Config("EXPORT_CLASSES"))) {
				$content = ob_get_contents();
			if ($ExportFileName == "")
				$ExportFileName = $this->TableVar;
			$class = PROJECT_NAMESPACE . Config("EXPORT_CLASSES." . $this->CustomExport);
			if (class_exists($class)) {
				$doc = new $class($wp_wpl_addon_crm_contacts);
				$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 (!Config("DEBUG") && ob_get_length())
				ob_end_clean();

			// Handle modal response
			if ($this->IsModal) { // Show as modal
				$row = ["url" => $url, "modal" => "1"];
				$pageName = GetPageName($url);
				if ($pageName != $this->getListUrl()) { // Not List page
					$row["caption"] = $this->getModalCaption($pageName);
					if ($pageName == "wp_wpl_addon_crm_contactsview.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 = [];
		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 = [];
		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(GetApiUrl(Config("API_FILE_ACTION"),
									Config("API_OBJECT_NAME") . "=" . $fld->TableVar . "&" .
									Config("API_FIELD_NAME") . "=" . $fld->Param . "&" .
									Config("API_KEY_NAME") . "=" . rawurlencode($this->getRecordKeyValue($ar)))); //*** need to add this? API may not be in the same folder
								$row[$fldname] = ["type" => ContentType($val), "url" => $url, "name" => $fld->Param . ContentExtension($val)];
							} elseif (!$fld->UploadMultiple || !ContainsString($val, Config("MULTIPLE_UPLOAD_SEPARATOR"))) { // Single file
								$url = FullUrl(GetApiUrl(Config("API_FILE_ACTION"),
									Config("API_OBJECT_NAME") . "=" . $fld->TableVar . "&" .
									"fn=" . Encrypt($fld->physicalUploadPath() . $val)));
								$row[$fldname] = ["type" => MimeContentType($val), "url" => $url, "name" => $val];
							} else { // Multiple files
								$files = explode(Config("MULTIPLE_UPLOAD_SEPARATOR"), $val);
								$ar = [];
								foreach ($files as $file) {
									$url = FullUrl(GetApiUrl(Config("API_FILE_ACTION"),
										Config("API_OBJECT_NAME") . "=" . $fld->TableVar . "&" .
										"fn=" . Encrypt($fld->physicalUploadPath() . $file)));
									if (!EmptyValue($file))
										$ar[] = ["type" => MimeContentType($file), "url" => $url, "name" => $file];
								}
								$row[$fldname] = $ar;
							}
						}
					} else {
						$row[$fldname] = $val;
					}
				}
			}
		}
		return $row;
	}

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

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

	// Lookup data
	public function lookup()
	{
		global $Language, $Security;
		if (!isset($Language))
			$Language = new Language(Config("LANGUAGE_FOLDER"), Post("language", ""));

		// Set up API request
		if (!ValidApiRequest())
			return FALSE;
		$this->setupApiSecurity();

		// Get lookup object
		$fieldName = Post("field");
		if (!array_key_exists($fieldName, $this->fields))
			return FALSE;
		$lookupField = $this->fields[$fieldName];
		$lookup = $lookupField->Lookup;
		if ($lookup === NULL)
			return FALSE;
		if (!$Security->isLoggedIn()) // Logged in
			return FALSE;

		// Get lookup parameters
		$lookupType = Post("ajax", "unknown");
		$pageSize = -1;
		$offset = -1;
		$searchValue = "";
		if (SameText($lookupType, "modal")) {
			$searchValue = Post("sv", "");
			$pageSize = Post("recperpage", 10);
			$offset = Post("start", 0);
		} elseif (SameText($lookupType, "autosuggest")) {
			$searchValue = Param("q", "");
			$pageSize = Param("n", -1);
			$pageSize = is_numeric($pageSize) ? (int)$pageSize : -1;
			if ($pageSize <= 0)
				$pageSize = Config("AUTO_SUGGEST_MAX_ENTRIES");
			$start = Param("start", -1);
			$start = is_numeric($start) ? (int)$start : -1;
			$page = Param("page", -1);
			$page = is_numeric($page) ? (int)$page : -1;
			$offset = $start >= 0 ? $start : ($page > 0 && $pageSize > 0 ? ($page - 1) * $pageSize : 0);
		}
		$userSelect = Decrypt(Post("s", ""));
		$userFilter = Decrypt(Post("f", ""));
		$userOrderBy = Decrypt(Post("o", ""));
		$keys = Post("keys");
		$lookup->LookupType = $lookupType; // Lookup type
		if ($keys !== NULL) { // Selected records from modal
			if (is_array($keys))
				$keys = implode(Config("MULTIPLE_OPTION_SEPARATOR"), $keys);
			$lookup->FilterFields = []; // Skip parent fields if any
			$lookup->FilterValues[] = $keys; // Lookup values
			$pageSize = -1; // Show all records
		} else { // Lookup values
			$lookup->FilterValues[] = Post("v0", Post("lookupValue", ""));
		}
		$cnt = is_array($lookup->FilterFields) ? count($lookup->FilterFields) : 0;
		for ($i = 1; $i <= $cnt; $i++)
			$lookup->FilterValues[] = Post("v" . $i, "");
		$lookup->SearchValue = $searchValue;
		$lookup->PageSize = $pageSize;
		$lookup->Offset = $offset;
		if ($userSelect != "")
			$lookup->UserSelect = $userSelect;
		if ($userFilter != "")
			$lookup->UserFilter = $userFilter;
		if ($userOrderBy != "")
			$lookup->UserOrderBy = $userOrderBy;
		$lookup->toJson($this); // Use settings from current page
	}

	// Set up API security
	public function setupApiSecurity()
	{
		global $Security;

		// Setup security for API request
	}
	public $FormClassName = "ew-horizontal ew-form ew-add-form";
	public $IsModal = FALSE;
	public $IsMobileOrModal = FALSE;
	public $DbMasterFilter = "";
	public $DbDetailFilter = "";
	public $StartRecord;
	public $Priv = 0;
	public $OldRecordset;
	public $CopyRecord;

	//
	// Page run
	//

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

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

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

		// Security
		if (ValidApiRequest()) { // API request
			$this->setupApiSecurity(); // Set up API Security
			if (!$Security->canAdd()) {
				SetStatus(401); // Unauthorized
				return;
			}
		} else {
			$Security = new AdvancedSecurity();
			if (!$Security->isLoggedIn())
				$Security->autoLogin();
			$Security->loadCurrentUserLevel($this->ProjectID . $this->TableName);
			if (!$Security->canAdd()) {
				$Security->saveLastUrl();
				$this->setFailureMessage(DeniedMessage()); // Set no permission
				if ($Security->canList())
					$this->terminate(GetUrl("wp_wpl_addon_crm_contactslist.php"));
				else
					$this->terminate(GetUrl("login.php"));
				return;
			}
		}

		// Create form object
		$CurrentForm = new HttpForm();
		$this->CurrentAction = Param("action"); // Set up current action
		$this->id->Visible = FALSE;
		$this->user_id->Visible = FALSE;
		$this->first_name->setVisibility();
		$this->last_name->setVisibility();
		$this->owner->Visible = FALSE;
		$this->type->setVisibility();
		$this->_private->Visible = FALSE;
		$this->archive->Visible = FALSE;
		$this->title->Visible = FALSE;
		$this->gender->Visible = FALSE;
		$this->marital->Visible = FALSE;
		$this->_email->setVisibility();
		$this->tel->setVisibility();
		$this->birthday->Visible = FALSE;
		$this->mobile->setVisibility();
		$this->field_3090->setVisibility();
		$this->field_3091->setVisibility();
		$this->field_3088->setVisibility();
		$this->location1_id->Visible = FALSE;
		$this->location2_id->Visible = FALSE;
		$this->location3_id->Visible = FALSE;
		$this->location4_id->Visible = FALSE;
		$this->location5_id->Visible = FALSE;
		$this->location6_id->Visible = FALSE;
		$this->location7_id->Visible = FALSE;
		$this->location1_name->Visible = FALSE;
		$this->location2_name->Visible = FALSE;
		$this->location3_name->Visible = FALSE;
		$this->location4_name->Visible = FALSE;
		$this->location5_name->Visible = FALSE;
		$this->location6_name->Visible = FALSE;
		$this->location7_name->Visible = FALSE;
		$this->zip_id->Visible = FALSE;
		$this->zip_name->setVisibility();
		$this->field_3087->setVisibility();
		$this->rating->Visible = FALSE;
		$this->group->Visible = FALSE;
		$this->date_added->setVisibility();
		$this->logins->Visible = FALSE;
		$this->saved_searches->Visible = FALSE;
		$this->listings_viewed->Visible = FALSE;
		$this->last_login_date->Visible = FALSE;
		$this->f_3011_options->Visible = FALSE;
		$this->f_3011->Visible = FALSE;
		$this->field_3004_en_us->Visible = FALSE;
		$this->field_3004_fr_fr->Visible = FALSE;
		$this->field_3092->Visible = FALSE;
		$this->field_3093->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
		// Check modal

		if ($this->IsModal)
			$SkipHeaderFooter = TRUE;
		$this->IsMobileOrModal = IsMobile() || $this->IsModal;
		$this->FormClassName = "ew-form ew-add-form ew-horizontal";
		$postBack = FALSE;

		// Set up current action
		if (IsApi()) {
			$this->CurrentAction = "insert"; // Add record directly
			$postBack = TRUE;
		} elseif (Post("action") !== NULL) {
			$this->CurrentAction = Post("action"); // Get form action
			$postBack = TRUE;
		} else { // Not post back

			// Load key values from QueryString
			$this->CopyRecord = TRUE;
			if (Get("id") !== NULL) {
				$this->id->setQueryStringValue(Get("id"));
				$this->setKey("id", $this->id->CurrentValue); // Set up key
			} else {
				$this->setKey("id", ""); // Clear key
				$this->CopyRecord = FALSE;
			}
			if ($this->CopyRecord) {
				$this->CurrentAction = "copy"; // Copy record
			} else {
				$this->CurrentAction = "show"; // Display blank record
			}
		}

		// Load old record / default values
		$loaded = $this->loadOldRecord();

		// Load form values
		if ($postBack) {
			$this->loadFormValues(); // Load form values
		}

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

		// Perform current action
		switch ($this->CurrentAction) {
			case "copy": // Copy an existing record
				if (!$loaded) { // Record not loaded
					if ($this->getFailureMessage() == "")
						$this->setFailureMessage($Language->phrase("NoRecord")); // No record found
					$this->terminate("wp_wpl_addon_crm_contactslist.php"); // No matching record, return to list
				}
				break;
			case "insert": // Add new record
				$this->SendEmail = TRUE; // Send email on add success
				if ($this->addRow($this->OldRecordset)) { // Add successful
					if ($this->getSuccessMessage() == "")
						$this->setSuccessMessage($Language->phrase("AddSuccess")); // Set up success message
					$returnUrl = $this->getReturnUrl();
					if (GetPageName($returnUrl) == "wp_wpl_addon_crm_contactslist.php")
						$returnUrl = $this->addMasterUrl($returnUrl); // List page, return to List page with correct master key if necessary
					elseif (GetPageName($returnUrl) == "wp_wpl_addon_crm_contactsview.php")
						$returnUrl = $this->getViewUrl(); // View page, return to View page with keyurl directly
					if (IsApi()) { // Return to caller
						$this->terminate(TRUE);
						return;
					} else {
						$this->terminate($returnUrl);
					}
				} elseif (IsApi()) { // API request, return
					$this->terminate();
					return;
				} else {
					$this->EventCancelled = TRUE; // Event cancelled
					$this->restoreFormValues(); // Add failed, restore form values
				}
		}

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

		// Render row based on row type
		$this->RowType = ROWTYPE_ADD; // Render add type

		// Render row
		$this->resetAttributes();
		$this->renderRow();
	}

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

	// Load default values
	protected function loadDefaultValues()
	{
		$this->id->CurrentValue = NULL;
		$this->id->OldValue = $this->id->CurrentValue;
		$this->user_id->CurrentValue = 0;
		$this->first_name->CurrentValue = NULL;
		$this->first_name->OldValue = $this->first_name->CurrentValue;
		$this->last_name->CurrentValue = NULL;
		$this->last_name->OldValue = $this->last_name->CurrentValue;
		$this->owner->CurrentValue = 0;
		$this->type->CurrentValue = NULL;
		$this->type->OldValue = $this->type->CurrentValue;
		$this->_private->CurrentValue = 0;
		$this->archive->CurrentValue = 0;
		$this->title->CurrentValue = 0;
		$this->gender->CurrentValue = 0;
		$this->marital->CurrentValue = 0;
		$this->_email->CurrentValue = NULL;
		$this->_email->OldValue = $this->_email->CurrentValue;
		$this->tel->CurrentValue = NULL;
		$this->tel->OldValue = $this->tel->CurrentValue;
		$this->birthday->CurrentValue = NULL;
		$this->birthday->OldValue = $this->birthday->CurrentValue;
		$this->mobile->CurrentValue = NULL;
		$this->mobile->OldValue = $this->mobile->CurrentValue;
		$this->field_3090->CurrentValue = NULL;
		$this->field_3090->OldValue = $this->field_3090->CurrentValue;
		$this->field_3091->CurrentValue = NULL;
		$this->field_3091->OldValue = $this->field_3091->CurrentValue;
		$this->field_3088->CurrentValue = NULL;
		$this->field_3088->OldValue = $this->field_3088->CurrentValue;
		$this->location1_id->CurrentValue = 0;
		$this->location2_id->CurrentValue = 0;
		$this->location3_id->CurrentValue = 0;
		$this->location4_id->CurrentValue = 0;
		$this->location5_id->CurrentValue = 0;
		$this->location6_id->CurrentValue = 0;
		$this->location7_id->CurrentValue = 0;
		$this->location1_name->CurrentValue = NULL;
		$this->location1_name->OldValue = $this->location1_name->CurrentValue;
		$this->location2_name->CurrentValue = NULL;
		$this->location2_name->OldValue = $this->location2_name->CurrentValue;
		$this->location3_name->CurrentValue = NULL;
		$this->location3_name->OldValue = $this->location3_name->CurrentValue;
		$this->location4_name->CurrentValue = NULL;
		$this->location4_name->OldValue = $this->location4_name->CurrentValue;
		$this->location5_name->CurrentValue = NULL;
		$this->location5_name->OldValue = $this->location5_name->CurrentValue;
		$this->location6_name->CurrentValue = NULL;
		$this->location6_name->OldValue = $this->location6_name->CurrentValue;
		$this->location7_name->CurrentValue = NULL;
		$this->location7_name->OldValue = $this->location7_name->CurrentValue;
		$this->zip_id->CurrentValue = 0;
		$this->zip_name->CurrentValue = NULL;
		$this->zip_name->OldValue = $this->zip_name->CurrentValue;
		$this->field_3087->CurrentValue = NULL;
		$this->field_3087->OldValue = $this->field_3087->CurrentValue;
		$this->rating->CurrentValue = 0;
		$this->group->CurrentValue = NULL;
		$this->group->OldValue = $this->group->CurrentValue;
		$this->date_added->CurrentValue = NULL;
		$this->date_added->OldValue = $this->date_added->CurrentValue;
		$this->logins->CurrentValue = 0;
		$this->saved_searches->CurrentValue = 0;
		$this->listings_viewed->CurrentValue = 0;
		$this->last_login_date->CurrentValue = NULL;
		$this->last_login_date->OldValue = $this->last_login_date->CurrentValue;
		$this->f_3011_options->CurrentValue = NULL;
		$this->f_3011_options->OldValue = $this->f_3011_options->CurrentValue;
		$this->f_3011->CurrentValue = NULL;
		$this->f_3011->OldValue = $this->f_3011->CurrentValue;
		$this->field_3004_en_us->CurrentValue = NULL;
		$this->field_3004_en_us->OldValue = $this->field_3004_en_us->CurrentValue;
		$this->field_3004_fr_fr->CurrentValue = NULL;
		$this->field_3004_fr_fr->OldValue = $this->field_3004_fr_fr->CurrentValue;
		$this->field_3092->CurrentValue = NULL;
		$this->field_3092->OldValue = $this->field_3092->CurrentValue;
		$this->field_3093->CurrentValue = NULL;
		$this->field_3093->OldValue = $this->field_3093->CurrentValue;
	}

	// Load form values
	protected function loadFormValues()
	{

		// Load from form
		global $CurrentForm;

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

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

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

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

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

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

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

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

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

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

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

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

		// Check field name 'id' first before field var 'x_id'
		$val = $CurrentForm->hasValue("id") ? $CurrentForm->getValue("id") : $CurrentForm->getValue("x_id");
	}

	// Restore form values
	public function restoreFormValues()
	{
		global $CurrentForm;
		$this->first_name->CurrentValue = $this->first_name->FormValue;
		$this->last_name->CurrentValue = $this->last_name->FormValue;
		$this->type->CurrentValue = $this->type->FormValue;
		$this->_email->CurrentValue = $this->_email->FormValue;
		$this->tel->CurrentValue = $this->tel->FormValue;
		$this->mobile->CurrentValue = $this->mobile->FormValue;
		$this->field_3090->CurrentValue = $this->field_3090->FormValue;
		$this->field_3091->CurrentValue = $this->field_3091->FormValue;
		$this->field_3088->CurrentValue = $this->field_3088->FormValue;
		$this->zip_name->CurrentValue = $this->zip_name->FormValue;
		$this->field_3087->CurrentValue = $this->field_3087->FormValue;
		$this->date_added->CurrentValue = $this->date_added->FormValue;
		$this->date_added->CurrentValue = UnFormatDateTime($this->date_added->CurrentValue, 9);
	}

	// 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->id->setDbValue($row['id']);
		$this->user_id->setDbValue($row['user_id']);
		$this->first_name->setDbValue($row['first_name']);
		$this->last_name->setDbValue($row['last_name']);
		$this->owner->setDbValue($row['owner']);
		$this->type->setDbValue($row['type']);
		$this->_private->setDbValue($row['private']);
		$this->archive->setDbValue($row['archive']);
		$this->title->setDbValue($row['title']);
		$this->gender->setDbValue($row['gender']);
		$this->marital->setDbValue($row['marital']);
		$this->_email->setDbValue($row['email']);
		$this->tel->setDbValue($row['tel']);
		$this->birthday->setDbValue($row['birthday']);
		$this->mobile->setDbValue($row['mobile']);
		$this->field_3090->setDbValue($row['field_3090']);
		$this->field_3091->setDbValue($row['field_3091']);
		$this->field_3088->setDbValue($row['field_3088']);
		$this->location1_id->setDbValue($row['location1_id']);
		$this->location2_id->setDbValue($row['location2_id']);
		$this->location3_id->setDbValue($row['location3_id']);
		$this->location4_id->setDbValue($row['location4_id']);
		$this->location5_id->setDbValue($row['location5_id']);
		$this->location6_id->setDbValue($row['location6_id']);
		$this->location7_id->setDbValue($row['location7_id']);
		$this->location1_name->setDbValue($row['location1_name']);
		$this->location2_name->setDbValue($row['location2_name']);
		$this->location3_name->setDbValue($row['location3_name']);
		$this->location4_name->setDbValue($row['location4_name']);
		$this->location5_name->setDbValue($row['location5_name']);
		$this->location6_name->setDbValue($row['location6_name']);
		$this->location7_name->setDbValue($row['location7_name']);
		$this->zip_id->setDbValue($row['zip_id']);
		$this->zip_name->setDbValue($row['zip_name']);
		$this->field_3087->setDbValue($row['field_3087']);
		$this->rating->setDbValue($row['rating']);
		$this->group->setDbValue($row['group']);
		$this->date_added->setDbValue($row['date_added']);
		$this->logins->setDbValue($row['logins']);
		$this->saved_searches->setDbValue($row['saved_searches']);
		$this->listings_viewed->setDbValue($row['listings_viewed']);
		$this->last_login_date->setDbValue($row['last_login_date']);
		$this->f_3011_options->setDbValue($row['f_3011_options']);
		$this->f_3011->setDbValue($row['f_3011']);
		$this->field_3004_en_us->setDbValue($row['field_3004_en_us']);
		$this->field_3004_fr_fr->setDbValue($row['field_3004_fr_fr']);
		$this->field_3092->setDbValue($row['field_3092']);
		$this->field_3093->setDbValue($row['field_3093']);
	}

	// Return a row with default values
	protected function newRow()
	{
		$this->loadDefaultValues();
		$row = [];
		$row['id'] = $this->id->CurrentValue;
		$row['user_id'] = $this->user_id->CurrentValue;
		$row['first_name'] = $this->first_name->CurrentValue;
		$row['last_name'] = $this->last_name->CurrentValue;
		$row['owner'] = $this->owner->CurrentValue;
		$row['type'] = $this->type->CurrentValue;
		$row['private'] = $this->_private->CurrentValue;
		$row['archive'] = $this->archive->CurrentValue;
		$row['title'] = $this->title->CurrentValue;
		$row['gender'] = $this->gender->CurrentValue;
		$row['marital'] = $this->marital->CurrentValue;
		$row['email'] = $this->_email->CurrentValue;
		$row['tel'] = $this->tel->CurrentValue;
		$row['birthday'] = $this->birthday->CurrentValue;
		$row['mobile'] = $this->mobile->CurrentValue;
		$row['field_3090'] = $this->field_3090->CurrentValue;
		$row['field_3091'] = $this->field_3091->CurrentValue;
		$row['field_3088'] = $this->field_3088->CurrentValue;
		$row['location1_id'] = $this->location1_id->CurrentValue;
		$row['location2_id'] = $this->location2_id->CurrentValue;
		$row['location3_id'] = $this->location3_id->CurrentValue;
		$row['location4_id'] = $this->location4_id->CurrentValue;
		$row['location5_id'] = $this->location5_id->CurrentValue;
		$row['location6_id'] = $this->location6_id->CurrentValue;
		$row['location7_id'] = $this->location7_id->CurrentValue;
		$row['location1_name'] = $this->location1_name->CurrentValue;
		$row['location2_name'] = $this->location2_name->CurrentValue;
		$row['location3_name'] = $this->location3_name->CurrentValue;
		$row['location4_name'] = $this->location4_name->CurrentValue;
		$row['location5_name'] = $this->location5_name->CurrentValue;
		$row['location6_name'] = $this->location6_name->CurrentValue;
		$row['location7_name'] = $this->location7_name->CurrentValue;
		$row['zip_id'] = $this->zip_id->CurrentValue;
		$row['zip_name'] = $this->zip_name->CurrentValue;
		$row['field_3087'] = $this->field_3087->CurrentValue;
		$row['rating'] = $this->rating->CurrentValue;
		$row['group'] = $this->group->CurrentValue;
		$row['date_added'] = $this->date_added->CurrentValue;
		$row['logins'] = $this->logins->CurrentValue;
		$row['saved_searches'] = $this->saved_searches->CurrentValue;
		$row['listings_viewed'] = $this->listings_viewed->CurrentValue;
		$row['last_login_date'] = $this->last_login_date->CurrentValue;
		$row['f_3011_options'] = $this->f_3011_options->CurrentValue;
		$row['f_3011'] = $this->f_3011->CurrentValue;
		$row['field_3004_en_us'] = $this->field_3004_en_us->CurrentValue;
		$row['field_3004_fr_fr'] = $this->field_3004_fr_fr->CurrentValue;
		$row['field_3092'] = $this->field_3092->CurrentValue;
		$row['field_3093'] = $this->field_3093->CurrentValue;
		return $row;
	}

	// Load old record
	protected function loadOldRecord()
	{

		// Load key values from Session
		$validKey = TRUE;
		if (strval($this->getKey("id")) != "")
			$this->id->OldValue = $this->getKey("id"); // id
		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
		// id
		// user_id
		// first_name
		// last_name
		// owner
		// type
		// private
		// archive
		// title
		// gender
		// marital
		// email
		// tel
		// birthday
		// mobile
		// field_3090
		// field_3091
		// field_3088
		// location1_id
		// location2_id
		// location3_id
		// location4_id
		// location5_id
		// location6_id
		// location7_id
		// location1_name
		// location2_name
		// location3_name
		// location4_name
		// location5_name
		// location6_name
		// location7_name
		// zip_id
		// zip_name
		// field_3087
		// rating
		// group
		// date_added
		// logins
		// saved_searches
		// listings_viewed
		// last_login_date
		// f_3011_options
		// f_3011
		// field_3004_en_us
		// field_3004_fr_fr
		// field_3092
		// field_3093

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

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

			// user_id
			$this->user_id->ViewValue = $this->user_id->CurrentValue;
			$this->user_id->ViewValue = FormatNumber($this->user_id->ViewValue, 0, -2, -2, -2);
			$this->user_id->ViewCustomAttributes = "";

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

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

			// owner
			$this->owner->ViewValue = $this->owner->CurrentValue;
			$this->owner->ViewValue = FormatNumber($this->owner->ViewValue, 0, -2, -2, -2);
			$this->owner->ViewCustomAttributes = "";

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

			// private
			if (ConvertToBool($this->_private->CurrentValue)) {
				$this->_private->ViewValue = $this->_private->tagCaption(1) != "" ? $this->_private->tagCaption(1) : "Yes";
			} else {
				$this->_private->ViewValue = $this->_private->tagCaption(2) != "" ? $this->_private->tagCaption(2) : "No";
			}
			$this->_private->ViewCustomAttributes = "";

			// archive
			if (ConvertToBool($this->archive->CurrentValue)) {
				$this->archive->ViewValue = $this->archive->tagCaption(1) != "" ? $this->archive->tagCaption(1) : "Yes";
			} else {
				$this->archive->ViewValue = $this->archive->tagCaption(2) != "" ? $this->archive->tagCaption(2) : "No";
			}
			$this->archive->ViewCustomAttributes = "";

			// title
			$this->title->ViewValue = $this->title->CurrentValue;
			$this->title->ViewValue = FormatNumber($this->title->ViewValue, 0, -2, -2, -2);
			$this->title->ViewCustomAttributes = "";

			// gender
			$this->gender->ViewValue = $this->gender->CurrentValue;
			$this->gender->ViewValue = FormatNumber($this->gender->ViewValue, 0, -2, -2, -2);
			$this->gender->ViewCustomAttributes = "";

			// marital
			$this->marital->ViewValue = $this->marital->CurrentValue;
			$this->marital->ViewValue = FormatNumber($this->marital->ViewValue, 0, -2, -2, -2);
			$this->marital->ViewCustomAttributes = "";

			// email
			$this->_email->ViewValue = $this->_email->CurrentValue;
			$this->_email->ViewCustomAttributes = "";

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

			// birthday
			$this->birthday->ViewValue = $this->birthday->CurrentValue;
			$this->birthday->ViewValue = FormatDateTime($this->birthday->ViewValue, 0);
			$this->birthday->ViewCustomAttributes = "";

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

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

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

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

			// location1_id
			$this->location1_id->ViewValue = $this->location1_id->CurrentValue;
			$this->location1_id->ViewValue = FormatNumber($this->location1_id->ViewValue, 0, -2, -2, -2);
			$this->location1_id->ViewCustomAttributes = "";

			// location2_id
			$this->location2_id->ViewValue = $this->location2_id->CurrentValue;
			$this->location2_id->ViewValue = FormatNumber($this->location2_id->ViewValue, 0, -2, -2, -2);
			$this->location2_id->ViewCustomAttributes = "";

			// location3_id
			$this->location3_id->ViewValue = $this->location3_id->CurrentValue;
			$this->location3_id->ViewValue = FormatNumber($this->location3_id->ViewValue, 0, -2, -2, -2);
			$this->location3_id->ViewCustomAttributes = "";

			// location4_id
			$this->location4_id->ViewValue = $this->location4_id->CurrentValue;
			$this->location4_id->ViewValue = FormatNumber($this->location4_id->ViewValue, 0, -2, -2, -2);
			$this->location4_id->ViewCustomAttributes = "";

			// location5_id
			$this->location5_id->ViewValue = $this->location5_id->CurrentValue;
			$this->location5_id->ViewValue = FormatNumber($this->location5_id->ViewValue, 0, -2, -2, -2);
			$this->location5_id->ViewCustomAttributes = "";

			// location6_id
			$this->location6_id->ViewValue = $this->location6_id->CurrentValue;
			$this->location6_id->ViewValue = FormatNumber($this->location6_id->ViewValue, 0, -2, -2, -2);
			$this->location6_id->ViewCustomAttributes = "";

			// location7_id
			$this->location7_id->ViewValue = $this->location7_id->CurrentValue;
			$this->location7_id->ViewValue = FormatNumber($this->location7_id->ViewValue, 0, -2, -2, -2);
			$this->location7_id->ViewCustomAttributes = "";

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

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

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

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

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

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

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

			// zip_id
			$this->zip_id->ViewValue = $this->zip_id->CurrentValue;
			$this->zip_id->ViewValue = FormatNumber($this->zip_id->ViewValue, 0, -2, -2, -2);
			$this->zip_id->ViewCustomAttributes = "";

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

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

			// rating
			$this->rating->ViewValue = $this->rating->CurrentValue;
			$this->rating->ViewValue = FormatNumber($this->rating->ViewValue, 0, -2, -2, -2);
			$this->rating->ViewCustomAttributes = "";

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

			// date_added
			$this->date_added->ViewValue = $this->date_added->CurrentValue;
			$this->date_added->ViewValue = FormatDateTime($this->date_added->ViewValue, 9);
			$this->date_added->ViewCustomAttributes = "";

			// logins
			$this->logins->ViewValue = $this->logins->CurrentValue;
			$this->logins->ViewValue = FormatNumber($this->logins->ViewValue, 0, -2, -2, -2);
			$this->logins->ViewCustomAttributes = "";

			// saved_searches
			$this->saved_searches->ViewValue = $this->saved_searches->CurrentValue;
			$this->saved_searches->ViewValue = FormatNumber($this->saved_searches->ViewValue, 0, -2, -2, -2);
			$this->saved_searches->ViewCustomAttributes = "";

			// listings_viewed
			$this->listings_viewed->ViewValue = $this->listings_viewed->CurrentValue;
			$this->listings_viewed->ViewValue = FormatNumber($this->listings_viewed->ViewValue, 0, -2, -2, -2);
			$this->listings_viewed->ViewCustomAttributes = "";

			// last_login_date
			$this->last_login_date->ViewValue = $this->last_login_date->CurrentValue;
			$this->last_login_date->ViewValue = FormatDateTime($this->last_login_date->ViewValue, 0);
			$this->last_login_date->ViewCustomAttributes = "";

			// f_3011
			$this->f_3011->ViewValue = $this->f_3011->CurrentValue;
			$this->f_3011->ViewValue = FormatNumber($this->f_3011->ViewValue, 0, -2, -2, -2);
			$this->f_3011->ViewCustomAttributes = "";

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

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

			// field_3092
			$this->field_3092->ViewValue = $this->field_3092->CurrentValue;
			$this->field_3092->ViewValue = FormatNumber($this->field_3092->ViewValue, 0, -2, -2, -2);
			$this->field_3092->ViewCustomAttributes = "";

			// field_3093
			$this->field_3093->ViewValue = $this->field_3093->CurrentValue;
			$this->field_3093->ViewValue = FormatDateTime($this->field_3093->ViewValue, 0);
			$this->field_3093->ViewCustomAttributes = "";

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

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

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

			// email
			$this->_email->LinkCustomAttributes = "";
			$this->_email->HrefValue = "";
			$this->_email->TooltipValue = "";

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

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

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

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

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

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

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

			// date_added
			$this->date_added->LinkCustomAttributes = "";
			$this->date_added->HrefValue = "";
			$this->date_added->TooltipValue = "";
		} elseif ($this->RowType == ROWTYPE_ADD) { // Add row

			// first_name
			$this->first_name->EditAttrs["class"] = "form-control";
			$this->first_name->EditCustomAttributes = "";
			if (!$this->first_name->Raw)
				$this->first_name->CurrentValue = HtmlDecode($this->first_name->CurrentValue);
			$this->first_name->EditValue = HtmlEncode($this->first_name->CurrentValue);
			$this->first_name->PlaceHolder = RemoveHtml($this->first_name->caption());

			// last_name
			$this->last_name->EditAttrs["class"] = "form-control";
			$this->last_name->EditCustomAttributes = "";
			if (!$this->last_name->Raw)
				$this->last_name->CurrentValue = HtmlDecode($this->last_name->CurrentValue);
			$this->last_name->EditValue = HtmlEncode($this->last_name->CurrentValue);
			$this->last_name->PlaceHolder = RemoveHtml($this->last_name->caption());

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

			// email
			$this->_email->EditAttrs["class"] = "form-control";
			$this->_email->EditCustomAttributes = "";
			if (!$this->_email->Raw)
				$this->_email->CurrentValue = HtmlDecode($this->_email->CurrentValue);
			$this->_email->EditValue = HtmlEncode($this->_email->CurrentValue);
			$this->_email->PlaceHolder = RemoveHtml($this->_email->caption());

			// tel
			$this->tel->EditAttrs["class"] = "form-control";
			$this->tel->EditCustomAttributes = "";
			if (!$this->tel->Raw)
				$this->tel->CurrentValue = HtmlDecode($this->tel->CurrentValue);
			$this->tel->EditValue = HtmlEncode($this->tel->CurrentValue);
			$this->tel->PlaceHolder = RemoveHtml($this->tel->caption());

			// mobile
			$this->mobile->EditAttrs["class"] = "form-control";
			$this->mobile->EditCustomAttributes = "";
			if (!$this->mobile->Raw)
				$this->mobile->CurrentValue = HtmlDecode($this->mobile->CurrentValue);
			$this->mobile->EditValue = HtmlEncode($this->mobile->CurrentValue);
			$this->mobile->PlaceHolder = RemoveHtml($this->mobile->caption());

			// field_3090
			$this->field_3090->EditAttrs["class"] = "form-control";
			$this->field_3090->EditCustomAttributes = "";
			if (!$this->field_3090->Raw)
				$this->field_3090->CurrentValue = HtmlDecode($this->field_3090->CurrentValue);
			$this->field_3090->EditValue = HtmlEncode($this->field_3090->CurrentValue);
			$this->field_3090->PlaceHolder = RemoveHtml($this->field_3090->caption());

			// field_3091
			$this->field_3091->EditAttrs["class"] = "form-control";
			$this->field_3091->EditCustomAttributes = "";
			if (!$this->field_3091->Raw)
				$this->field_3091->CurrentValue = HtmlDecode($this->field_3091->CurrentValue);
			$this->field_3091->EditValue = HtmlEncode($this->field_3091->CurrentValue);
			$this->field_3091->PlaceHolder = RemoveHtml($this->field_3091->caption());

			// field_3088
			$this->field_3088->EditAttrs["class"] = "form-control";
			$this->field_3088->EditCustomAttributes = "";
			if (!$this->field_3088->Raw)
				$this->field_3088->CurrentValue = HtmlDecode($this->field_3088->CurrentValue);
			$this->field_3088->EditValue = HtmlEncode($this->field_3088->CurrentValue);
			$this->field_3088->PlaceHolder = RemoveHtml($this->field_3088->caption());

			// zip_name
			$this->zip_name->EditAttrs["class"] = "form-control";
			$this->zip_name->EditCustomAttributes = "";
			if (!$this->zip_name->Raw)
				$this->zip_name->CurrentValue = HtmlDecode($this->zip_name->CurrentValue);
			$this->zip_name->EditValue = HtmlEncode($this->zip_name->CurrentValue);
			$this->zip_name->PlaceHolder = RemoveHtml($this->zip_name->caption());

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

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

			// Add refer script
			// first_name

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

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

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

			// email
			$this->_email->LinkCustomAttributes = "";
			$this->_email->HrefValue = "";

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

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

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

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

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

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

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

			// date_added
			$this->date_added->LinkCustomAttributes = "";
			$this->date_added->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 (!Config("SERVER_VALIDATE"))
			return ($FormError == "");
		if ($this->first_name->Required) {
			if (!$this->first_name->IsDetailKey && $this->first_name->FormValue != NULL && $this->first_name->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->first_name->caption(), $this->first_name->RequiredErrorMessage));
			}
		}
		if ($this->last_name->Required) {
			if (!$this->last_name->IsDetailKey && $this->last_name->FormValue != NULL && $this->last_name->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->last_name->caption(), $this->last_name->RequiredErrorMessage));
			}
		}
		if ($this->type->Required) {
			if (!$this->type->IsDetailKey && $this->type->FormValue != NULL && $this->type->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->type->caption(), $this->type->RequiredErrorMessage));
			}
		}
		if ($this->_email->Required) {
			if (!$this->_email->IsDetailKey && $this->_email->FormValue != NULL && $this->_email->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->_email->caption(), $this->_email->RequiredErrorMessage));
			}
		}
		if ($this->tel->Required) {
			if (!$this->tel->IsDetailKey && $this->tel->FormValue != NULL && $this->tel->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->tel->caption(), $this->tel->RequiredErrorMessage));
			}
		}
		if ($this->mobile->Required) {
			if (!$this->mobile->IsDetailKey && $this->mobile->FormValue != NULL && $this->mobile->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->mobile->caption(), $this->mobile->RequiredErrorMessage));
			}
		}
		if ($this->field_3090->Required) {
			if (!$this->field_3090->IsDetailKey && $this->field_3090->FormValue != NULL && $this->field_3090->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->field_3090->caption(), $this->field_3090->RequiredErrorMessage));
			}
		}
		if ($this->field_3091->Required) {
			if (!$this->field_3091->IsDetailKey && $this->field_3091->FormValue != NULL && $this->field_3091->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->field_3091->caption(), $this->field_3091->RequiredErrorMessage));
			}
		}
		if ($this->field_3088->Required) {
			if (!$this->field_3088->IsDetailKey && $this->field_3088->FormValue != NULL && $this->field_3088->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->field_3088->caption(), $this->field_3088->RequiredErrorMessage));
			}
		}
		if ($this->zip_name->Required) {
			if (!$this->zip_name->IsDetailKey && $this->zip_name->FormValue != NULL && $this->zip_name->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->zip_name->caption(), $this->zip_name->RequiredErrorMessage));
			}
		}
		if ($this->field_3087->Required) {
			if (!$this->field_3087->IsDetailKey && $this->field_3087->FormValue != NULL && $this->field_3087->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->field_3087->caption(), $this->field_3087->RequiredErrorMessage));
			}
		}
		if ($this->date_added->Required) {
			if (!$this->date_added->IsDetailKey && $this->date_added->FormValue != NULL && $this->date_added->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->date_added->caption(), $this->date_added->RequiredErrorMessage));
			}
		}
		if (!CheckStdDate($this->date_added->FormValue)) {
			AddMessage($FormError, $this->date_added->errorMessage());
		}

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

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

	// Add record
	protected function addRow($rsold = NULL)
	{
		global $Language, $Security;
		$conn = $this->getConnection();

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

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

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

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

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

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

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

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

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

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

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

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

		// date_added
		$this->date_added->setDbValueDef($rsnew, UnFormatDateTime($this->date_added->CurrentValue, 9), NULL, FALSE);

		// Call Row Inserting event
		$rs = ($rsold) ? $rsold->fields : NULL;
		$insertRow = $this->Row_Inserting($rs, $rsnew);
		if ($insertRow) {
			$conn->raiseErrorFn = Config("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);
		}

		// Clean upload path if any
		if ($addRow) {
		}

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

	// 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("wp_wpl_addon_crm_contactslist.php"), "", $this->TableVar, TRUE);
		$pageId = ($this->isCopy()) ? "Copy" : "Add";
		$Breadcrumb->add("add", $pageId, $url);
	}

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

			// Get default connection and filter
			$conn = $this->getConnection();
			$lookupFilter = "";

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

			// Set up lookup SQL and connection
			switch ($fld->FieldVar) {
				case "x__private":
					break;
				case "x_archive":
					break;
				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) {
				$totalCnt = $this->getRecordCount($sql, $conn);
				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) {
					}
					$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;
	}
} // End class
?>

Hry