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/avantmaj.alliancerealty.nb.ca/adminAR/classes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

/**
 * Page class
 */
class wp_wpl_items_edit extends wp_wpl_items
{

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

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

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

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

	// 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_items)
		if (!isset($GLOBALS["wp_wpl_items"]) || get_class($GLOBALS["wp_wpl_items"]) == PROJECT_NAMESPACE . "wp_wpl_items") {
			$GLOBALS["wp_wpl_items"] = &$this;
			$GLOBALS["Table"] = &$GLOBALS["wp_wpl_items"];
		}

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

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

		// 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_items;
		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_items);
				$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_itemsview.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-edit-form";
	public $IsModal = FALSE;
	public $IsMobileOrModal = FALSE;
	public $DbMasterFilter;
	public $DbDetailFilter;

	//
	// 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->canEdit()) {
				SetStatus(401); // Unauthorized
				return;
			}
		} else {
			$Security = new AdvancedSecurity();
			if (!$Security->isLoggedIn())
				$Security->autoLogin();
			$Security->loadCurrentUserLevel($this->ProjectID . $this->TableName);
			if (!$Security->canEdit()) {
				$Security->saveLastUrl();
				$this->setFailureMessage(DeniedMessage()); // Set no permission
				if ($Security->canList())
					$this->terminate(GetUrl("wp_wpl_itemslist.php"));
				else
					$this->terminate(GetUrl("login.php"));
				return;
			}
		}

		// Create form object
		$CurrentForm = new HttpForm();
		$this->CurrentAction = Param("action"); // Set up current action
		$this->id->setVisibility();
		$this->parent_kind->setVisibility();
		$this->parent_id->setVisibility();
		$this->item_type->setVisibility();
		$this->item_cat->setVisibility();
		$this->item_name->setVisibility();
		$this->creation_date->setVisibility();
		$this->edit_date->setVisibility();
		$this->enabled->setVisibility();
		$this->item_extra1->setVisibility();
		$this->item_extra2->setVisibility();
		$this->item_extra3->setVisibility();
		$this->item_extra4->setVisibility();
		$this->item_extra5->setVisibility();
		$this->params->setVisibility();
		$this->_index->setVisibility();
		$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-edit-form ew-horizontal";
		$loaded = FALSE;
		$postBack = FALSE;

		// Set up current action and primary key
		if (IsApi()) {

			// Load key values
			$loaded = TRUE;
			if (Get("id") !== NULL) {
				$this->id->setQueryStringValue(Get("id"));
				$this->id->setOldValue($this->id->QueryStringValue);
			} elseif (Key(0) !== NULL) {
				$this->id->setQueryStringValue(Key(0));
				$this->id->setOldValue($this->id->QueryStringValue);
			} elseif (Post("id") !== NULL) {
				$this->id->setFormValue(Post("id"));
				$this->id->setOldValue($this->id->FormValue);
			} elseif (Route(2) !== NULL) {
				$this->id->setQueryStringValue(Route(2));
				$this->id->setOldValue($this->id->QueryStringValue);
			} else {
				$loaded = FALSE; // Unable to load key
			}

			// Load record
			if ($loaded)
				$loaded = $this->loadRow();
			if (!$loaded) {
				$this->setFailureMessage($Language->phrase("NoRecord")); // Set no record message
				$this->terminate();
				return;
			}
			$this->CurrentAction = "update"; // Update record directly
			$postBack = TRUE;
		} else {
			if (Post("action") !== NULL) {
				$this->CurrentAction = Post("action"); // Get action code
				if (!$this->isShow()) // Not reload record, handle as postback
					$postBack = TRUE;

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

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

			// Load current record
			$loaded = $this->loadRow();
		}

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

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

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

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

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

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

	// Load form values
	protected function loadFormValues()
	{

		// Load from form
		global $CurrentForm;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	// Restore form values
	public function restoreFormValues()
	{
		global $CurrentForm;
		$this->id->CurrentValue = $this->id->FormValue;
		$this->parent_kind->CurrentValue = $this->parent_kind->FormValue;
		$this->parent_id->CurrentValue = $this->parent_id->FormValue;
		$this->item_type->CurrentValue = $this->item_type->FormValue;
		$this->item_cat->CurrentValue = $this->item_cat->FormValue;
		$this->item_name->CurrentValue = $this->item_name->FormValue;
		$this->creation_date->CurrentValue = $this->creation_date->FormValue;
		$this->creation_date->CurrentValue = UnFormatDateTime($this->creation_date->CurrentValue, 0);
		$this->edit_date->CurrentValue = $this->edit_date->FormValue;
		$this->edit_date->CurrentValue = UnFormatDateTime($this->edit_date->CurrentValue, 0);
		$this->enabled->CurrentValue = $this->enabled->FormValue;
		$this->item_extra1->CurrentValue = $this->item_extra1->FormValue;
		$this->item_extra2->CurrentValue = $this->item_extra2->FormValue;
		$this->item_extra3->CurrentValue = $this->item_extra3->FormValue;
		$this->item_extra4->CurrentValue = $this->item_extra4->FormValue;
		$this->item_extra5->CurrentValue = $this->item_extra5->FormValue;
		$this->params->CurrentValue = $this->params->FormValue;
		$this->_index->CurrentValue = $this->_index->FormValue;
	}

	// 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->parent_kind->setDbValue($row['parent_kind']);
		$this->parent_id->setDbValue($row['parent_id']);
		$this->item_type->setDbValue($row['item_type']);
		$this->item_cat->setDbValue($row['item_cat']);
		$this->item_name->setDbValue($row['item_name']);
		$this->creation_date->setDbValue($row['creation_date']);
		$this->edit_date->setDbValue($row['edit_date']);
		$this->enabled->setDbValue($row['enabled']);
		$this->item_extra1->setDbValue($row['item_extra1']);
		$this->item_extra2->setDbValue($row['item_extra2']);
		$this->item_extra3->setDbValue($row['item_extra3']);
		$this->item_extra4->setDbValue($row['item_extra4']);
		$this->item_extra5->setDbValue($row['item_extra5']);
		$this->params->setDbValue($row['params']);
		$this->_index->setDbValue($row['index']);
	}

	// Return a row with default values
	protected function newRow()
	{
		$row = [];
		$row['id'] = NULL;
		$row['parent_kind'] = NULL;
		$row['parent_id'] = NULL;
		$row['item_type'] = NULL;
		$row['item_cat'] = NULL;
		$row['item_name'] = NULL;
		$row['creation_date'] = NULL;
		$row['edit_date'] = NULL;
		$row['enabled'] = NULL;
		$row['item_extra1'] = NULL;
		$row['item_extra2'] = NULL;
		$row['item_extra3'] = NULL;
		$row['item_extra4'] = NULL;
		$row['item_extra5'] = NULL;
		$row['params'] = NULL;
		$row['index'] = NULL;
		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
		// Convert decimal values if posted back

		if ($this->_index->FormValue == $this->_index->CurrentValue && is_numeric(ConvertToFloatString($this->_index->CurrentValue)))
			$this->_index->CurrentValue = ConvertToFloatString($this->_index->CurrentValue);

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

		// Common render codes for all row types
		// id
		// parent_kind
		// parent_id
		// item_type
		// item_cat
		// item_name
		// creation_date
		// edit_date
		// enabled
		// item_extra1
		// item_extra2
		// item_extra3
		// item_extra4
		// item_extra5
		// params
		// index

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

			// index
			$this->_index->EditAttrs["class"] = "form-control";
			$this->_index->EditCustomAttributes = "";
			$this->_index->EditValue = HtmlEncode($this->_index->CurrentValue);
			$this->_index->PlaceHolder = RemoveHtml($this->_index->caption());
			if (strval($this->_index->EditValue) != "" && is_numeric($this->_index->EditValue))
				$this->_index->EditValue = FormatNumber($this->_index->EditValue, -2, -2, -2, -2);
			

			// Edit refer script
			// id

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

			// index
			$this->_index->LinkCustomAttributes = "";
			$this->_index->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->id->Required) {
			if (!$this->id->IsDetailKey && $this->id->FormValue != NULL && $this->id->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->id->caption(), $this->id->RequiredErrorMessage));
			}
		}
		if ($this->parent_kind->Required) {
			if (!$this->parent_kind->IsDetailKey && $this->parent_kind->FormValue != NULL && $this->parent_kind->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->parent_kind->caption(), $this->parent_kind->RequiredErrorMessage));
			}
		}
		if ($this->parent_id->Required) {
			if (!$this->parent_id->IsDetailKey && $this->parent_id->FormValue != NULL && $this->parent_id->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->parent_id->caption(), $this->parent_id->RequiredErrorMessage));
			}
		}
		if (!CheckInteger($this->parent_id->FormValue)) {
			AddMessage($FormError, $this->parent_id->errorMessage());
		}
		if ($this->item_type->Required) {
			if (!$this->item_type->IsDetailKey && $this->item_type->FormValue != NULL && $this->item_type->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->item_type->caption(), $this->item_type->RequiredErrorMessage));
			}
		}
		if ($this->item_cat->Required) {
			if (!$this->item_cat->IsDetailKey && $this->item_cat->FormValue != NULL && $this->item_cat->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->item_cat->caption(), $this->item_cat->RequiredErrorMessage));
			}
		}
		if ($this->item_name->Required) {
			if (!$this->item_name->IsDetailKey && $this->item_name->FormValue != NULL && $this->item_name->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->item_name->caption(), $this->item_name->RequiredErrorMessage));
			}
		}
		if ($this->creation_date->Required) {
			if (!$this->creation_date->IsDetailKey && $this->creation_date->FormValue != NULL && $this->creation_date->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->creation_date->caption(), $this->creation_date->RequiredErrorMessage));
			}
		}
		if (!CheckDate($this->creation_date->FormValue)) {
			AddMessage($FormError, $this->creation_date->errorMessage());
		}
		if ($this->edit_date->Required) {
			if (!$this->edit_date->IsDetailKey && $this->edit_date->FormValue != NULL && $this->edit_date->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->edit_date->caption(), $this->edit_date->RequiredErrorMessage));
			}
		}
		if (!CheckDate($this->edit_date->FormValue)) {
			AddMessage($FormError, $this->edit_date->errorMessage());
		}
		if ($this->enabled->Required) {
			if (!$this->enabled->IsDetailKey && $this->enabled->FormValue != NULL && $this->enabled->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->enabled->caption(), $this->enabled->RequiredErrorMessage));
			}
		}
		if (!CheckInteger($this->enabled->FormValue)) {
			AddMessage($FormError, $this->enabled->errorMessage());
		}
		if ($this->item_extra1->Required) {
			if (!$this->item_extra1->IsDetailKey && $this->item_extra1->FormValue != NULL && $this->item_extra1->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->item_extra1->caption(), $this->item_extra1->RequiredErrorMessage));
			}
		}
		if ($this->item_extra2->Required) {
			if (!$this->item_extra2->IsDetailKey && $this->item_extra2->FormValue != NULL && $this->item_extra2->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->item_extra2->caption(), $this->item_extra2->RequiredErrorMessage));
			}
		}
		if ($this->item_extra3->Required) {
			if (!$this->item_extra3->IsDetailKey && $this->item_extra3->FormValue != NULL && $this->item_extra3->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->item_extra3->caption(), $this->item_extra3->RequiredErrorMessage));
			}
		}
		if ($this->item_extra4->Required) {
			if (!$this->item_extra4->IsDetailKey && $this->item_extra4->FormValue != NULL && $this->item_extra4->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->item_extra4->caption(), $this->item_extra4->RequiredErrorMessage));
			}
		}
		if ($this->item_extra5->Required) {
			if (!$this->item_extra5->IsDetailKey && $this->item_extra5->FormValue != NULL && $this->item_extra5->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->item_extra5->caption(), $this->item_extra5->RequiredErrorMessage));
			}
		}
		if ($this->params->Required) {
			if (!$this->params->IsDetailKey && $this->params->FormValue != NULL && $this->params->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->params->caption(), $this->params->RequiredErrorMessage));
			}
		}
		if ($this->_index->Required) {
			if (!$this->_index->IsDetailKey && $this->_index->FormValue != NULL && $this->_index->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->_index->caption(), $this->_index->RequiredErrorMessage));
			}
		}
		if (!CheckNumber($this->_index->FormValue)) {
			AddMessage($FormError, $this->_index->errorMessage());
		}

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

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

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

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

			// parent_kind
			$this->parent_kind->setDbValueDef($rsnew, $this->parent_kind->CurrentValue, "", $this->parent_kind->ReadOnly);

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

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

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

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

			// creation_date
			$this->creation_date->setDbValueDef($rsnew, UnFormatDateTime($this->creation_date->CurrentValue, 0), NULL, $this->creation_date->ReadOnly);

			// edit_date
			$this->edit_date->setDbValueDef($rsnew, UnFormatDateTime($this->edit_date->CurrentValue, 0), NULL, $this->edit_date->ReadOnly);

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

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

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

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

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

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

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

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

			// Call Row Updating event
			$updateRow = $this->Row_Updating($rsold, $rsnew);

			// Check for duplicate key when key changed
			if ($updateRow) {
				$newKeyFilter = $this->getRecordFilter($rsnew);
				if ($newKeyFilter != $oldKeyFilter) {
					$rsChk = $this->loadRs($newKeyFilter);
					if ($rsChk && !$rsChk->EOF) {
						$keyErrMsg = str_replace("%f", $newKeyFilter, $Language->phrase("DupKey"));
						$this->setFailureMessage($keyErrMsg);
						$rsChk->close();
						$updateRow = FALSE;
					}
				}
			}
			if ($updateRow) {
				$conn->raiseErrorFn = Config("ERROR_FUNC");
				if (count($rsnew) > 0)
					$editRow = $this->update($rsnew, "", $rsold);
				else
					$editRow = TRUE; // No field to update
				$conn->raiseErrorFn = "";
				if ($editRow) {
				}
			} else {
				if ($this->getSuccessMessage() != "" || $this->getFailureMessage() != "") {

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

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

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

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

	// 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_itemslist.php"), "", $this->TableVar, TRUE);
		$pageId = "edit";
		$Breadcrumb->add("edit", $pageId, $url);
	}

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

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

	// Set up starting record parameters
	public function setupStartRecord()
	{
		if ($this->DisplayRecords == 0)
			return;
		if ($this->isPageRequest()) { // Validate request
			$startRec = Get(Config("TABLE_START_REC"));
			$pageNo = Get(Config("TABLE_PAGE_NO"));
			if ($pageNo !== NULL) { // Check for "pageno" parameter first
				if (is_numeric($pageNo)) {
					$this->StartRecord = ($pageNo - 1) * $this->DisplayRecords + 1;
					if ($this->StartRecord <= 0) {
						$this->StartRecord = 1;
					} elseif ($this->StartRecord >= (int)(($this->TotalRecords - 1)/$this->DisplayRecords) * $this->DisplayRecords + 1) {
						$this->StartRecord = (int)(($this->TotalRecords - 1)/$this->DisplayRecords) * $this->DisplayRecords + 1;
					}
					$this->setStartRecordNumber($this->StartRecord);
				}
			} elseif ($startRec !== NULL) { // Check for "start" parameter
				$this->StartRecord = $startRec;
				$this->setStartRecordNumber($this->StartRecord);
			}
		}
		$this->StartRecord = $this->getStartRecordNumber();

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

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