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/www/adminAR/classes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/alliancerealtynb/www/adminAR/classes/wp_wpl_addon_crm_contacts_delete.php
<?php
namespace PHPMaker2020\Alliance;

/**
 * Page class
 */
class wp_wpl_addon_crm_contacts_delete extends wp_wpl_addon_crm_contacts
{

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

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

	// 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", 'delete');

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

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

		// Setup security for API request
	}
	public $DbMasterFilter = "";
	public $DbDetailFilter = "";
	public $StartRecord;
	public $TotalRecords = 0;
	public $RecordCount;
	public $RecKeys = [];
	public $StartRowCount = 1;
	public $RowCount = 0;

	//
	// Page run
	//

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

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

		// Security
		if (ValidApiRequest()) { // API request
			$this->setupApiSecurity(); // Set up API Security
			if (!$Security->canDelete()) {
				SetStatus(401); // Unauthorized
				return;
			}
		} else {
			$Security = new AdvancedSecurity();
			if (!$Security->isLoggedIn())
				$Security->autoLogin();
			$Security->loadCurrentUserLevel($this->ProjectID . $this->TableName);
			if (!$Security->canDelete()) {
				$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;
			}
		}
		$this->CurrentAction = Param("action"); // Set up current action
		$this->id->Visible = FALSE;
		$this->user_id->setVisibility();
		$this->first_name->setVisibility();
		$this->last_name->setVisibility();
		$this->owner->Visible = FALSE;
		$this->type->Visible = FALSE;
		$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->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->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_3087->setVisibility();
		$this->field_3090->setVisibility();
		$this->field_3091->setVisibility();
		$this->field_3088->setVisibility();
		$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
		// Set up Breadcrumb

		$this->setupBreadcrumb();

		// Load key parameters
		$this->RecKeys = $this->getRecordKeys(); // Load record keys
		$filter = $this->getFilterFromRecordKeys();
		if ($filter == "") {
			$this->terminate("wp_wpl_addon_crm_contactslist.php"); // Prevent SQL injection, return to list
			return;
		}

		// Set up filter (WHERE Clause)
		$this->CurrentFilter = $filter;

		// Get action
		if (IsApi()) {
			$this->CurrentAction = "delete"; // Delete record directly
		} elseif (Post("action") !== NULL) {
			$this->CurrentAction = Post("action");
		} elseif (Get("action") == "1") {
			$this->CurrentAction = "delete"; // Delete record directly
		} else {
			$this->CurrentAction = "show"; // Display record
		}
		if ($this->isDelete()) {
			$this->SendEmail = TRUE; // Send email on delete success
			if ($this->deleteRows()) { // Delete rows
				if ($this->getSuccessMessage() == "")
					$this->setSuccessMessage($Language->phrase("DeleteSuccess")); // Set up success message
				if (IsApi()) {
					$this->terminate(TRUE);
					return;
				} else {
					$this->terminate($this->getReturnUrl()); // Return to caller
				}
			} else { // Delete failed
				if (IsApi()) {
					$this->terminate();
					return;
				}
				$this->CurrentAction = "show"; // Display record
			}
		}
		if ($this->isShow()) { // Load records for display
			if ($this->Recordset = $this->loadRecordset())
				$this->TotalRecords = $this->Recordset->RecordCount(); // Get record count
			if ($this->TotalRecords <= 0) { // No record found, exit
				if ($this->Recordset)
					$this->Recordset->close();
				$this->terminate("wp_wpl_addon_crm_contactslist.php"); // Return to list
			}
		}
	}

	// 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 = Config("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->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->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->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_3087->setDbValue($row['field_3087']);
		$this->field_3090->setDbValue($row['field_3090']);
		$this->field_3091->setDbValue($row['field_3091']);
		$this->field_3088->setDbValue($row['field_3088']);
		$this->field_3092->setDbValue($row['field_3092']);
		$this->field_3093->setDbValue($row['field_3093']);
	}

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

	// 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
		// 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
		// 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_3087
		// field_3090
		// field_3091
		// field_3088
		// 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 = "";

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

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

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

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

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

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

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

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

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

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

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

	// Delete records based on current filter
	protected function deleteRows()
	{
		global $Language, $Security;
		$deleteRows = TRUE;
		$sql = $this->getCurrentSql();
		$conn = $this->getConnection();
		$conn->raiseErrorFn = Config("ERROR_FUNC");
		$rs = $conn->execute($sql);
		$conn->raiseErrorFn = "";
		if ($rs === FALSE) {
			return FALSE;
		} elseif ($rs->EOF) {
			$this->setFailureMessage($Language->phrase("NoRecord")); // No record found
			$rs->close();
			return FALSE;
		}
		$rows = ($rs) ? $rs->getRows() : [];
		$conn->beginTrans();

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

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

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

				// Use the message, do nothing
			} elseif ($this->CancelMessage != "") {
				$this->setFailureMessage($this->CancelMessage);
				$this->CancelMessage = "";
			} else {
				$this->setFailureMessage($Language->phrase("DeleteCancelled"));
			}
		}
		if ($deleteRows) {
			$conn->commitTrans(); // Commit the changes
		} else {
			$conn->rollbackTrans(); // Rollback changes
		}

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

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

	// 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 = "delete";
		$Breadcrumb->add("delete", $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";

	}
} // End class
?>

Hry