<?php
namespace PHPMaker2020\hostelmgr20;

/**
 * Page class
 */
class activity_grid extends activity
{

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

	// Project ID
	public $ProjectID = "{9D95FE21-5D89-4075-ACEB-258B1CE35B16}";

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

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

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

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

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

		// Message
		$message = $this->getMessage();
		if (method_exists($this, "Message_Showing"))
			$this->Message_Showing($message, "");
		if ($message != "") { // Message in Session, display
			if (!$hidden)
				$message = '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' . $message;
			$html .= '<div class="alert alert-info alert-dismissible ew-info"><i class="icon 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;
		global $UserTable;

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

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

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

		// Parent constuctor
		parent::__construct();

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

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

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

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

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

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

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

		// Debug message
		LoadDebugMessage();

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

		// User table object (staff)
		$UserTable = $UserTable ?: new staff();

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

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

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

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

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

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

		// Go to URL if specified
		if ($url != "") {
			if (!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] = ["mimeType" => ContentType($val), "url" => $url];
							} elseif (!$fld->UploadMultiple || !ContainsString($val, Config("MULTIPLE_UPLOAD_SEPARATOR"))) { // Single file
								$row[$fldname] = ["mimeType" => MimeContentType($val), "url" => FullUrl($fld->hrefPath() . $val)];
							} else { // Multiple files
								$files = explode(Config("MULTIPLE_UPLOAD_SEPARATOR"), $val);
								$ar = [];
								foreach ($files as $file) {
									if (!EmptyValue($file))
										$ar[] = ["type" => MimeContentType($file), "url" => FullUrl($fld->hrefPath() . $file)];
								}
								$row[$fldname] = $ar;
							}
						}
					} else {
						$row[$fldname] = $val;
					}
				}
			}
		}
		return $row;
	}

	// Get record key value from array
	protected function getRecordKeyValue($ar)
	{
		$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;
		if ($this->isAddOrEdit())
			$this->Updatedby->Visible = FALSE;
		if ($this->isAddOrEdit())
			$this->Updated_Date->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 (!$this->setupApiRequest())
			return FALSE;

		// 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;
		$tbl = $lookup->getTable();
		if (!$Security->allowLookup(Config("PROJECT_ID") . $tbl->TableName)) // Lookup permission
			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 = Get("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 request
	public function setupApiRequest()
	{
		global $Security;

		// Check security for API request
		If (ValidApiRequest()) {
			if ($Security->isLoggedIn()) $Security->TablePermission_Loading();
			$Security->loadCurrentUserLevel(Config("PROJECT_ID") . $this->TableName);
			if ($Security->isLoggedIn()) $Security->TablePermission_Loaded();
			return TRUE;
		}
		return FALSE;
	}

	// Class variables
	public $ListOptions; // List options
	public $ExportOptions; // Export options
	public $SearchOptions; // Search options
	public $OtherOptions; // Other options
	public $FilterOptions; // Filter options
	public $ImportOptions; // Import options
	public $ListActions; // List actions
	public $SelectedCount = 0;
	public $SelectedIndex = 0;
	public $ShowOtherOptions = FALSE;
	public $DisplayRecords = 20;
	public $StartRecord;
	public $StopRecord;
	public $TotalRecords = 0;
	public $RecordRange = 10;
	public $PageSizes = "10,20,50,-1"; // Page sizes (comma separated)
	public $DefaultSearchWhere = ""; // Default search WHERE clause
	public $SearchWhere = ""; // Search WHERE clause
	public $SearchPanelClass = "ew-search-panel collapse show"; // Search Panel class
	public $SearchRowCount = 0; // For extended search
	public $SearchColumnCount = 0; // For extended search
	public $SearchFieldsPerRow = 1; // For extended search
	public $RecordCount = 0; // Record count
	public $EditRowCount;
	public $StartRowCount = 1;
	public $RowCount = 0;
	public $Attrs = []; // Row attributes and cell attributes
	public $RowIndex = 0; // Row index
	public $KeyCount = 0; // Key count
	public $RowAction = ""; // Row action
	public $RowOldKey = ""; // Row old key (for copy)
	public $MultiColumnClass = "col-sm";
	public $MultiColumnEditClass = "w-100";
	public $DbMasterFilter = ""; // Master filter
	public $DbDetailFilter = ""; // Detail filter
	public $MasterRecordExists;
	public $MultiSelectKey;
	public $Command;
	public $RestoreSearch = FALSE;
	public $DetailPages;
	public $OldRecordset;

	//
	// Page run
	//

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

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

		// Security
		if (!$this->setupApiRequest()) {
			$Security = new AdvancedSecurity();
			if (!$Security->isLoggedIn())
				$Security->autoLogin();
			if ($Security->isLoggedIn())
				$Security->TablePermission_Loading();
			$Security->loadCurrentUserLevel($this->ProjectID . $this->TableName);
			if ($Security->isLoggedIn())
				$Security->TablePermission_Loaded();
			if (!$Security->canList()) {
				$Security->saveLastUrl();
				$this->setFailureMessage(DeniedMessage()); // Set no permission
				$this->terminate(GetUrl("index.php"));
				return;
			}
		}

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

		// Set up list options
		$this->setupListOptions();
		$this->id->setVisibility();
		$this->HotelID->setVisibility();
		$this->RollNo->setVisibility();
		$this->Name->setVisibility();
		$this->Hostel->setVisibility();
		$this->Floor->setVisibility();
		$this->Room_No->setVisibility();
		$this->Health_issue->setVisibility();
		$this->Indiscipline_activity->setVisibility();
		$this->Involvement->setVisibility();
		$this->Remarks->Visible = FALSE;
		$this->Others->Visible = FALSE;
		$this->Updatedby->Visible = FALSE;
		$this->Updated_Date->setVisibility();
		$this->hideFieldsForAddEdit();

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

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

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

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

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

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

		// Set up lookup cache
		$this->setupLookupOptions($this->Hostel);
		$this->setupLookupOptions($this->Floor);
		$this->setupLookupOptions($this->Room_No);
		$this->setupLookupOptions($this->Health_issue);
		$this->setupLookupOptions($this->Indiscipline_activity);
		$this->setupLookupOptions($this->Involvement);

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

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

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

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

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

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

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

		// Restore display records
		if ($this->Command != "json" && $this->getRecordsPerPage() != "") {
			$this->DisplayRecords = $this->getRecordsPerPage(); // Restore from Session
		} else {
			$this->DisplayRecords = 20; // Load default
			$this->setRecordsPerPage($this->DisplayRecords); // Save default to Session
		}

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

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

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

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

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

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

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

		// Set up pager
		$this->Pager = new PrevNextPager($this->StartRecord, $this->getRecordsPerPage(), $this->TotalRecords, $this->PageSizes, $this->RecordRange, $this->AutoHidePager, $this->AutoHidePageSizeSelector);
	}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

		// Init key filter
		$wrkfilter = "";
		$addcnt = 0;
		$key = "";

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

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

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

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

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

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

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

	// Check if empty row
	public function emptyRow()
	{
		global $CurrentForm;
		if ($CurrentForm->hasValue("x_HotelID") && $CurrentForm->hasValue("o_HotelID") && $this->HotelID->CurrentValue != $this->HotelID->OldValue)
			return FALSE;
		if ($CurrentForm->hasValue("x_RollNo") && $CurrentForm->hasValue("o_RollNo") && $this->RollNo->CurrentValue != $this->RollNo->OldValue)
			return FALSE;
		if ($CurrentForm->hasValue("x_Name") && $CurrentForm->hasValue("o_Name") && $this->Name->CurrentValue != $this->Name->OldValue)
			return FALSE;
		if ($CurrentForm->hasValue("x_Hostel") && $CurrentForm->hasValue("o_Hostel") && $this->Hostel->CurrentValue != $this->Hostel->OldValue)
			return FALSE;
		if ($CurrentForm->hasValue("x_Floor") && $CurrentForm->hasValue("o_Floor") && $this->Floor->CurrentValue != $this->Floor->OldValue)
			return FALSE;
		if ($CurrentForm->hasValue("x_Room_No") && $CurrentForm->hasValue("o_Room_No") && $this->Room_No->CurrentValue != $this->Room_No->OldValue)
			return FALSE;
		if ($CurrentForm->hasValue("x_Health_issue") && $CurrentForm->hasValue("o_Health_issue") && $this->Health_issue->CurrentValue != $this->Health_issue->OldValue)
			return FALSE;
		if ($CurrentForm->hasValue("x_Indiscipline_activity") && $CurrentForm->hasValue("o_Indiscipline_activity") && $this->Indiscipline_activity->CurrentValue != $this->Indiscipline_activity->OldValue)
			return FALSE;
		if ($CurrentForm->hasValue("x_Involvement") && $CurrentForm->hasValue("o_Involvement") && $this->Involvement->CurrentValue != $this->Involvement->OldValue)
			return FALSE;
		return TRUE;
	}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	protected function resetCmd()
	{

		// Check if reset command
		if (StartsString("reset", $this->Command)) {

			// Reset master/detail keys
			if ($this->Command == "resetall") {
				$this->setCurrentMasterTable(""); // Clear master table
				$this->DbMasterFilter = "";
				$this->DbDetailFilter = "";
				$this->HotelID->setSessionValue("");
				$this->RollNo->setSessionValue("");
				$this->Name->setSessionValue("");
				$this->Hostel->setSessionValue("");
				$this->Floor->setSessionValue("");
				$this->Room_No->setSessionValue("");
				$this->Indiscipline_activity->setSessionValue("");
			}

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

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

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

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

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

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

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

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

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

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

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

		$this->ListOptions_Load();
		$item = $this->ListOptions[$this->ListOptions->GroupOptionName];
		$item->Visible = $this->ListOptions->groupOptionVisible();
	}

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

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

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

				// Reload hidden key for delete
				$this->MultiSelectKey .= "<input type=\"hidden\" name=\"" . $keyName . "\" id=\"" . $keyName . "\" value=\"" . HtmlEncode($rowkey) . "\">";
			}
			if ($this->RowAction == "insert" && $this->isConfirm() && $this->emptyRow())
				$this->MultiSelectKey .= "<input type=\"hidden\" name=\"" . $blankRowName . "\" id=\"" . $blankRowName . "\" value=\"1\">";
		}

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

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

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

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

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

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

	// Set record key
	public function setRecordKey(&$key, $rs)
	{
		$key = "";
		if ($key != "")
			$key .= Config("COMPOSITE_KEY_SEPARATOR");
		$key .= $rs->fields('id');
	}

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

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

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

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

	// Set up list options (extended codes)
	protected function setupListOptionsExt()
	{
	}

	// Render list options (extended codes)
	protected function renderListOptionsExt()
	{
	}

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

	// Load default values
	protected function loadDefaultValues()
	{
		$this->id->CurrentValue = NULL;
		$this->id->OldValue = $this->id->CurrentValue;
		$this->HotelID->CurrentValue = NULL;
		$this->HotelID->OldValue = $this->HotelID->CurrentValue;
		$this->RollNo->CurrentValue = NULL;
		$this->RollNo->OldValue = $this->RollNo->CurrentValue;
		$this->Name->CurrentValue = NULL;
		$this->Name->OldValue = $this->Name->CurrentValue;
		$this->Hostel->CurrentValue = NULL;
		$this->Hostel->OldValue = $this->Hostel->CurrentValue;
		$this->Floor->CurrentValue = NULL;
		$this->Floor->OldValue = $this->Floor->CurrentValue;
		$this->Room_No->CurrentValue = NULL;
		$this->Room_No->OldValue = $this->Room_No->CurrentValue;
		$this->Health_issue->CurrentValue = NULL;
		$this->Health_issue->OldValue = $this->Health_issue->CurrentValue;
		$this->Indiscipline_activity->CurrentValue = NULL;
		$this->Indiscipline_activity->OldValue = $this->Indiscipline_activity->CurrentValue;
		$this->Involvement->CurrentValue = NULL;
		$this->Involvement->OldValue = $this->Involvement->CurrentValue;
		$this->Remarks->CurrentValue = NULL;
		$this->Remarks->OldValue = $this->Remarks->CurrentValue;
		$this->Others->CurrentValue = NULL;
		$this->Others->OldValue = $this->Others->CurrentValue;
		$this->Updatedby->CurrentValue = NULL;
		$this->Updatedby->OldValue = $this->Updatedby->CurrentValue;
		$this->Updated_Date->CurrentValue = NULL;
		$this->Updated_Date->OldValue = $this->Updated_Date->CurrentValue;
	}

	// Load form values
	protected function loadFormValues()
	{

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

		// 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->isGridAdd() && !$this->isAdd())
			$this->id->setFormValue($val);

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

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

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

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

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

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

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

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

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

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

	// Restore form values
	public function restoreFormValues()
	{
		global $CurrentForm;
		if (!$this->isGridAdd() && !$this->isAdd())
			$this->id->CurrentValue = $this->id->FormValue;
		$this->HotelID->CurrentValue = $this->HotelID->FormValue;
		$this->RollNo->CurrentValue = $this->RollNo->FormValue;
		$this->Name->CurrentValue = $this->Name->FormValue;
		$this->Hostel->CurrentValue = $this->Hostel->FormValue;
		$this->Floor->CurrentValue = $this->Floor->FormValue;
		$this->Room_No->CurrentValue = $this->Room_No->FormValue;
		$this->Health_issue->CurrentValue = $this->Health_issue->FormValue;
		$this->Indiscipline_activity->CurrentValue = $this->Indiscipline_activity->FormValue;
		$this->Involvement->CurrentValue = $this->Involvement->FormValue;
		$this->Updated_Date->CurrentValue = $this->Updated_Date->FormValue;
		$this->Updated_Date->CurrentValue = UnFormatDateTime($this->Updated_Date->CurrentValue, 0);
	}

	// 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->HotelID->setDbValue($row['HotelID']);
		$this->RollNo->setDbValue($row['RollNo']);
		$this->Name->setDbValue($row['Name']);
		$this->Hostel->setDbValue($row['Hostel']);
		$this->Floor->setDbValue($row['Floor']);
		$this->Room_No->setDbValue($row['Room_No']);
		$this->Health_issue->setDbValue($row['Health_issue']);
		$this->Indiscipline_activity->setDbValue($row['Indiscipline_activity']);
		$this->Involvement->setDbValue($row['Involvement']);
		$this->Remarks->setDbValue($row['Remarks']);
		$this->Others->setDbValue($row['Others']);
		$this->Updatedby->setDbValue($row['Updatedby']);
		$this->Updated_Date->setDbValue($row['Updated_Date']);
	}

	// Return a row with default values
	protected function newRow()
	{
		$this->loadDefaultValues();
		$row = [];
		$row['id'] = $this->id->CurrentValue;
		$row['HotelID'] = $this->HotelID->CurrentValue;
		$row['RollNo'] = $this->RollNo->CurrentValue;
		$row['Name'] = $this->Name->CurrentValue;
		$row['Hostel'] = $this->Hostel->CurrentValue;
		$row['Floor'] = $this->Floor->CurrentValue;
		$row['Room_No'] = $this->Room_No->CurrentValue;
		$row['Health_issue'] = $this->Health_issue->CurrentValue;
		$row['Indiscipline_activity'] = $this->Indiscipline_activity->CurrentValue;
		$row['Involvement'] = $this->Involvement->CurrentValue;
		$row['Remarks'] = $this->Remarks->CurrentValue;
		$row['Others'] = $this->Others->CurrentValue;
		$row['Updatedby'] = $this->Updatedby->CurrentValue;
		$row['Updated_Date'] = $this->Updated_Date->CurrentValue;
		return $row;
	}

	// Load old record
	protected function loadOldRecord()
	{

		// Load key values from Session
		$validKey = TRUE;
		$keys = [$this->RowOldKey];
		$cnt = count($keys);
		if ($cnt >= 1) {
			if (strval($keys[0]) != "")
				$this->id->OldValue = strval($keys[0]); // id
			else
				$validKey = FALSE;
		} else {
			$validKey = FALSE;
		}

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

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

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

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

		// Common render codes for all row types
		// id
		// HotelID
		// RollNo
		// Name
		// Hostel
		// Floor
		// Room_No
		// Health_issue
		// Indiscipline_activity
		// Involvement
		// Remarks
		// Others
		// Updatedby
		// Updated_Date

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

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

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

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

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

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

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

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

			// Health_issue
			$curVal = strval($this->Health_issue->CurrentValue);
			if ($curVal != "") {
				$this->Health_issue->ViewValue = $this->Health_issue->lookupCacheOption($curVal);
				if ($this->Health_issue->ViewValue === NULL) { // Lookup from database
					$arwrk = explode(",", $curVal);
					$filterWrk = "";
					foreach ($arwrk as $wrk) {
						if ($filterWrk != "")
							$filterWrk .= " OR ";
						$filterWrk .= "`Health_Issue`" . SearchString("=", trim($wrk), DATATYPE_STRING, "");
					}
					$lookupFilter = function() {
						return "`Status`='1'";
					};
					$lookupFilter = $lookupFilter->bindTo($this);
					$sqlWrk = $this->Health_issue->Lookup->getSql(FALSE, $filterWrk, $lookupFilter, $this);
					$rswrk = Conn()->execute($sqlWrk);
					if ($rswrk && !$rswrk->EOF) { // Lookup values found
						$this->Health_issue->ViewValue = new OptionValues();
						$ari = 0;
						while (!$rswrk->EOF) {
							$arwrk = [];
							$arwrk[1] = $rswrk->fields('df');
							$this->Health_issue->ViewValue->add($this->Health_issue->displayValue($arwrk));
							$rswrk->MoveNext();
							$ari++;
						}
						$rswrk->Close();
					} else {
						$this->Health_issue->ViewValue = $this->Health_issue->CurrentValue;
					}
				}
			} else {
				$this->Health_issue->ViewValue = NULL;
			}
			$this->Health_issue->ViewCustomAttributes = "";

			// Indiscipline_activity
			$curVal = strval($this->Indiscipline_activity->CurrentValue);
			if ($curVal != "") {
				$this->Indiscipline_activity->ViewValue = $this->Indiscipline_activity->lookupCacheOption($curVal);
				if ($this->Indiscipline_activity->ViewValue === NULL) { // Lookup from database
					$arwrk = explode(",", $curVal);
					$filterWrk = "";
					foreach ($arwrk as $wrk) {
						if ($filterWrk != "")
							$filterWrk .= " OR ";
						$filterWrk .= "`id`" . SearchString("=", trim($wrk), DATATYPE_NUMBER, "");
					}
					$lookupFilter = function() {
						return "`Status`='1'";
					};
					$lookupFilter = $lookupFilter->bindTo($this);
					$sqlWrk = $this->Indiscipline_activity->Lookup->getSql(FALSE, $filterWrk, $lookupFilter, $this);
					$rswrk = Conn()->execute($sqlWrk);
					if ($rswrk && !$rswrk->EOF) { // Lookup values found
						$this->Indiscipline_activity->ViewValue = new OptionValues();
						$ari = 0;
						while (!$rswrk->EOF) {
							$arwrk = [];
							$arwrk[1] = $rswrk->fields('df');
							$this->Indiscipline_activity->ViewValue->add($this->Indiscipline_activity->displayValue($arwrk));
							$rswrk->MoveNext();
							$ari++;
						}
						$rswrk->Close();
					} else {
						$this->Indiscipline_activity->ViewValue = $this->Indiscipline_activity->CurrentValue;
					}
				}
			} else {
				$this->Indiscipline_activity->ViewValue = NULL;
			}
			$this->Indiscipline_activity->ViewCustomAttributes = "";

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

			// id
			// HotelID

			$this->HotelID->EditAttrs["class"] = "form-control";
			$this->HotelID->EditCustomAttributes = "";
			if ($this->HotelID->getSessionValue() != "") {
				$this->HotelID->CurrentValue = $this->HotelID->getSessionValue();
				$this->HotelID->OldValue = $this->HotelID->CurrentValue;
				$this->HotelID->ViewValue = $this->HotelID->CurrentValue;
				$this->HotelID->ViewCustomAttributes = "";
			} else {
				if (!$this->HotelID->Raw)
					$this->HotelID->CurrentValue = HtmlDecode($this->HotelID->CurrentValue);
				$this->HotelID->EditValue = HtmlEncode($this->HotelID->CurrentValue);
				$this->HotelID->PlaceHolder = RemoveHtml($this->HotelID->caption());
			}

			// RollNo
			$this->RollNo->EditAttrs["class"] = "form-control";
			$this->RollNo->EditCustomAttributes = "";
			if ($this->RollNo->getSessionValue() != "") {
				$this->RollNo->CurrentValue = $this->RollNo->getSessionValue();
				$this->RollNo->OldValue = $this->RollNo->CurrentValue;
				$this->RollNo->ViewValue = $this->RollNo->CurrentValue;
				$this->RollNo->ViewCustomAttributes = "";
			} else {
				if (!$this->RollNo->Raw)
					$this->RollNo->CurrentValue = HtmlDecode($this->RollNo->CurrentValue);
				$this->RollNo->EditValue = HtmlEncode($this->RollNo->CurrentValue);
				$this->RollNo->PlaceHolder = RemoveHtml($this->RollNo->caption());
			}

			// Name
			$this->Name->EditAttrs["class"] = "form-control";
			$this->Name->EditCustomAttributes = "";
			if ($this->Name->getSessionValue() != "") {
				$this->Name->CurrentValue = $this->Name->getSessionValue();
				$this->Name->OldValue = $this->Name->CurrentValue;
				$this->Name->ViewValue = $this->Name->CurrentValue;
				$this->Name->ViewCustomAttributes = "";
			} else {
				if (!$this->Name->Raw)
					$this->Name->CurrentValue = HtmlDecode($this->Name->CurrentValue);
				$this->Name->EditValue = HtmlEncode($this->Name->CurrentValue);
				$this->Name->PlaceHolder = RemoveHtml($this->Name->caption());
			}

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

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

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

			// Health_issue
			$this->Health_issue->EditCustomAttributes = "";
			$curVal = trim(strval($this->Health_issue->CurrentValue));
			if ($curVal != "")
				$this->Health_issue->ViewValue = $this->Health_issue->lookupCacheOption($curVal);
			else
				$this->Health_issue->ViewValue = $this->Health_issue->Lookup !== NULL && is_array($this->Health_issue->Lookup->Options) ? $curVal : NULL;
			if ($this->Health_issue->ViewValue !== NULL) { // Load from cache
				$this->Health_issue->EditValue = array_values($this->Health_issue->Lookup->Options);
				if ($this->Health_issue->ViewValue == "")
					$this->Health_issue->ViewValue = $Language->phrase("PleaseSelect");
			} else { // Lookup from database
				if ($curVal == "") {
					$filterWrk = "0=1";
				} else {
					$arwrk = explode(",", $curVal);
					$filterWrk = "";
					foreach ($arwrk as $wrk) {
						if ($filterWrk != "")
							$filterWrk .= " OR ";
						$filterWrk .= "`Health_Issue`" . SearchString("=", trim($wrk), DATATYPE_STRING, "");
					}
				}
				$lookupFilter = function() {
					return "`Status`='1'";
				};
				$lookupFilter = $lookupFilter->bindTo($this);
				$sqlWrk = $this->Health_issue->Lookup->getSql(TRUE, $filterWrk, $lookupFilter, $this);
				$rswrk = Conn()->execute($sqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$this->Health_issue->ViewValue = new OptionValues();
					$ari = 0;
					while (!$rswrk->EOF) {
						$arwrk = [];
						$arwrk[1] = HtmlEncode($rswrk->fields('df'));
						$this->Health_issue->ViewValue->add($this->Health_issue->displayValue($arwrk));
						$rswrk->MoveNext();
						$ari++;
					}
					$rswrk->MoveFirst();
				} else {
					$this->Health_issue->ViewValue = $Language->phrase("PleaseSelect");
				}
				$arwrk = $rswrk ? $rswrk->getRows() : [];
				if ($rswrk)
					$rswrk->close();
				$this->Health_issue->EditValue = $arwrk;
			}

			// Indiscipline_activity
			$this->Indiscipline_activity->EditCustomAttributes = "";
			if ($this->Indiscipline_activity->getSessionValue() != "") {
				$this->Indiscipline_activity->CurrentValue = $this->Indiscipline_activity->getSessionValue();
				$this->Indiscipline_activity->OldValue = $this->Indiscipline_activity->CurrentValue;
				$curVal = strval($this->Indiscipline_activity->CurrentValue);
				if ($curVal != "") {
					$this->Indiscipline_activity->ViewValue = $this->Indiscipline_activity->lookupCacheOption($curVal);
					if ($this->Indiscipline_activity->ViewValue === NULL) { // Lookup from database
						$arwrk = explode(",", $curVal);
						$filterWrk = "";
						foreach ($arwrk as $wrk) {
							if ($filterWrk != "")
								$filterWrk .= " OR ";
							$filterWrk .= "`id`" . SearchString("=", trim($wrk), DATATYPE_NUMBER, "");
						}
						$lookupFilter = function() {
							return "`Status`='1'";
						};
						$lookupFilter = $lookupFilter->bindTo($this);
						$sqlWrk = $this->Indiscipline_activity->Lookup->getSql(FALSE, $filterWrk, $lookupFilter, $this);
						$rswrk = Conn()->execute($sqlWrk);
						if ($rswrk && !$rswrk->EOF) { // Lookup values found
							$this->Indiscipline_activity->ViewValue = new OptionValues();
							$ari = 0;
							while (!$rswrk->EOF) {
								$arwrk = [];
								$arwrk[1] = $rswrk->fields('df');
								$this->Indiscipline_activity->ViewValue->add($this->Indiscipline_activity->displayValue($arwrk));
								$rswrk->MoveNext();
								$ari++;
							}
							$rswrk->Close();
						} else {
							$this->Indiscipline_activity->ViewValue = $this->Indiscipline_activity->CurrentValue;
						}
					}
				} else {
					$this->Indiscipline_activity->ViewValue = NULL;
				}
				$this->Indiscipline_activity->ViewCustomAttributes = "";
			} else {
				$curVal = trim(strval($this->Indiscipline_activity->CurrentValue));
				if ($curVal != "")
					$this->Indiscipline_activity->ViewValue = $this->Indiscipline_activity->lookupCacheOption($curVal);
				else
					$this->Indiscipline_activity->ViewValue = $this->Indiscipline_activity->Lookup !== NULL && is_array($this->Indiscipline_activity->Lookup->Options) ? $curVal : NULL;
				if ($this->Indiscipline_activity->ViewValue !== NULL) { // Load from cache
					$this->Indiscipline_activity->EditValue = array_values($this->Indiscipline_activity->Lookup->Options);
					if ($this->Indiscipline_activity->ViewValue == "")
						$this->Indiscipline_activity->ViewValue = $Language->phrase("PleaseSelect");
				} else { // Lookup from database
					if ($curVal == "") {
						$filterWrk = "0=1";
					} else {
						$arwrk = explode(",", $curVal);
						$filterWrk = "";
						foreach ($arwrk as $wrk) {
							if ($filterWrk != "")
								$filterWrk .= " OR ";
							$filterWrk .= "`id`" . SearchString("=", trim($wrk), DATATYPE_NUMBER, "");
						}
					}
					$lookupFilter = function() {
						return "`Status`='1'";
					};
					$lookupFilter = $lookupFilter->bindTo($this);
					$sqlWrk = $this->Indiscipline_activity->Lookup->getSql(TRUE, $filterWrk, $lookupFilter, $this);
					$rswrk = Conn()->execute($sqlWrk);
					if ($rswrk && !$rswrk->EOF) { // Lookup values found
						$this->Indiscipline_activity->ViewValue = new OptionValues();
						$ari = 0;
						while (!$rswrk->EOF) {
							$arwrk = [];
							$arwrk[1] = HtmlEncode($rswrk->fields('df'));
							$this->Indiscipline_activity->ViewValue->add($this->Indiscipline_activity->displayValue($arwrk));
							$rswrk->MoveNext();
							$ari++;
						}
						$rswrk->MoveFirst();
					} else {
						$this->Indiscipline_activity->ViewValue = $Language->phrase("PleaseSelect");
					}
					$arwrk = $rswrk ? $rswrk->getRows() : [];
					if ($rswrk)
						$rswrk->close();
					$this->Indiscipline_activity->EditValue = $arwrk;
				}
			}

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

			// Updated_Date
			// Add refer script
			// id

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

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

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

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

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

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

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

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

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

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

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

			// HotelID
			$this->HotelID->EditAttrs["class"] = "form-control";
			$this->HotelID->EditCustomAttributes = "";
			if ($this->HotelID->getSessionValue() != "") {
				$this->HotelID->CurrentValue = $this->HotelID->getSessionValue();
				$this->HotelID->OldValue = $this->HotelID->CurrentValue;
				$this->HotelID->ViewValue = $this->HotelID->CurrentValue;
				$this->HotelID->ViewCustomAttributes = "";
			} else {
				if (!$this->HotelID->Raw)
					$this->HotelID->CurrentValue = HtmlDecode($this->HotelID->CurrentValue);
				$this->HotelID->EditValue = HtmlEncode($this->HotelID->CurrentValue);
				$this->HotelID->PlaceHolder = RemoveHtml($this->HotelID->caption());
			}

			// RollNo
			$this->RollNo->EditAttrs["class"] = "form-control";
			$this->RollNo->EditCustomAttributes = "";
			if ($this->RollNo->getSessionValue() != "") {
				$this->RollNo->CurrentValue = $this->RollNo->getSessionValue();
				$this->RollNo->OldValue = $this->RollNo->CurrentValue;
				$this->RollNo->ViewValue = $this->RollNo->CurrentValue;
				$this->RollNo->ViewCustomAttributes = "";
			} else {
				if (!$this->RollNo->Raw)
					$this->RollNo->CurrentValue = HtmlDecode($this->RollNo->CurrentValue);
				$this->RollNo->EditValue = HtmlEncode($this->RollNo->CurrentValue);
				$this->RollNo->PlaceHolder = RemoveHtml($this->RollNo->caption());
			}

			// Name
			$this->Name->EditAttrs["class"] = "form-control";
			$this->Name->EditCustomAttributes = "";
			if ($this->Name->getSessionValue() != "") {
				$this->Name->CurrentValue = $this->Name->getSessionValue();
				$this->Name->OldValue = $this->Name->CurrentValue;
				$this->Name->ViewValue = $this->Name->CurrentValue;
				$this->Name->ViewCustomAttributes = "";
			} else {
				if (!$this->Name->Raw)
					$this->Name->CurrentValue = HtmlDecode($this->Name->CurrentValue);
				$this->Name->EditValue = HtmlEncode($this->Name->CurrentValue);
				$this->Name->PlaceHolder = RemoveHtml($this->Name->caption());
			}

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

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

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

			// Health_issue
			$this->Health_issue->EditCustomAttributes = "";
			$curVal = trim(strval($this->Health_issue->CurrentValue));
			if ($curVal != "")
				$this->Health_issue->ViewValue = $this->Health_issue->lookupCacheOption($curVal);
			else
				$this->Health_issue->ViewValue = $this->Health_issue->Lookup !== NULL && is_array($this->Health_issue->Lookup->Options) ? $curVal : NULL;
			if ($this->Health_issue->ViewValue !== NULL) { // Load from cache
				$this->Health_issue->EditValue = array_values($this->Health_issue->Lookup->Options);
				if ($this->Health_issue->ViewValue == "")
					$this->Health_issue->ViewValue = $Language->phrase("PleaseSelect");
			} else { // Lookup from database
				if ($curVal == "") {
					$filterWrk = "0=1";
				} else {
					$arwrk = explode(",", $curVal);
					$filterWrk = "";
					foreach ($arwrk as $wrk) {
						if ($filterWrk != "")
							$filterWrk .= " OR ";
						$filterWrk .= "`Health_Issue`" . SearchString("=", trim($wrk), DATATYPE_STRING, "");
					}
				}
				$lookupFilter = function() {
					return "`Status`='1'";
				};
				$lookupFilter = $lookupFilter->bindTo($this);
				$sqlWrk = $this->Health_issue->Lookup->getSql(TRUE, $filterWrk, $lookupFilter, $this);
				$rswrk = Conn()->execute($sqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$this->Health_issue->ViewValue = new OptionValues();
					$ari = 0;
					while (!$rswrk->EOF) {
						$arwrk = [];
						$arwrk[1] = HtmlEncode($rswrk->fields('df'));
						$this->Health_issue->ViewValue->add($this->Health_issue->displayValue($arwrk));
						$rswrk->MoveNext();
						$ari++;
					}
					$rswrk->MoveFirst();
				} else {
					$this->Health_issue->ViewValue = $Language->phrase("PleaseSelect");
				}
				$arwrk = $rswrk ? $rswrk->getRows() : [];
				if ($rswrk)
					$rswrk->close();
				$this->Health_issue->EditValue = $arwrk;
			}

			// Indiscipline_activity
			$this->Indiscipline_activity->EditCustomAttributes = "";
			if ($this->Indiscipline_activity->getSessionValue() != "") {
				$this->Indiscipline_activity->CurrentValue = $this->Indiscipline_activity->getSessionValue();
				$this->Indiscipline_activity->OldValue = $this->Indiscipline_activity->CurrentValue;
				$curVal = strval($this->Indiscipline_activity->CurrentValue);
				if ($curVal != "") {
					$this->Indiscipline_activity->ViewValue = $this->Indiscipline_activity->lookupCacheOption($curVal);
					if ($this->Indiscipline_activity->ViewValue === NULL) { // Lookup from database
						$arwrk = explode(",", $curVal);
						$filterWrk = "";
						foreach ($arwrk as $wrk) {
							if ($filterWrk != "")
								$filterWrk .= " OR ";
							$filterWrk .= "`id`" . SearchString("=", trim($wrk), DATATYPE_NUMBER, "");
						}
						$lookupFilter = function() {
							return "`Status`='1'";
						};
						$lookupFilter = $lookupFilter->bindTo($this);
						$sqlWrk = $this->Indiscipline_activity->Lookup->getSql(FALSE, $filterWrk, $lookupFilter, $this);
						$rswrk = Conn()->execute($sqlWrk);
						if ($rswrk && !$rswrk->EOF) { // Lookup values found
							$this->Indiscipline_activity->ViewValue = new OptionValues();
							$ari = 0;
							while (!$rswrk->EOF) {
								$arwrk = [];
								$arwrk[1] = $rswrk->fields('df');
								$this->Indiscipline_activity->ViewValue->add($this->Indiscipline_activity->displayValue($arwrk));
								$rswrk->MoveNext();
								$ari++;
							}
							$rswrk->Close();
						} else {
							$this->Indiscipline_activity->ViewValue = $this->Indiscipline_activity->CurrentValue;
						}
					}
				} else {
					$this->Indiscipline_activity->ViewValue = NULL;
				}
				$this->Indiscipline_activity->ViewCustomAttributes = "";
			} else {
				$curVal = trim(strval($this->Indiscipline_activity->CurrentValue));
				if ($curVal != "")
					$this->Indiscipline_activity->ViewValue = $this->Indiscipline_activity->lookupCacheOption($curVal);
				else
					$this->Indiscipline_activity->ViewValue = $this->Indiscipline_activity->Lookup !== NULL && is_array($this->Indiscipline_activity->Lookup->Options) ? $curVal : NULL;
				if ($this->Indiscipline_activity->ViewValue !== NULL) { // Load from cache
					$this->Indiscipline_activity->EditValue = array_values($this->Indiscipline_activity->Lookup->Options);
					if ($this->Indiscipline_activity->ViewValue == "")
						$this->Indiscipline_activity->ViewValue = $Language->phrase("PleaseSelect");
				} else { // Lookup from database
					if ($curVal == "") {
						$filterWrk = "0=1";
					} else {
						$arwrk = explode(",", $curVal);
						$filterWrk = "";
						foreach ($arwrk as $wrk) {
							if ($filterWrk != "")
								$filterWrk .= " OR ";
							$filterWrk .= "`id`" . SearchString("=", trim($wrk), DATATYPE_NUMBER, "");
						}
					}
					$lookupFilter = function() {
						return "`Status`='1'";
					};
					$lookupFilter = $lookupFilter->bindTo($this);
					$sqlWrk = $this->Indiscipline_activity->Lookup->getSql(TRUE, $filterWrk, $lookupFilter, $this);
					$rswrk = Conn()->execute($sqlWrk);
					if ($rswrk && !$rswrk->EOF) { // Lookup values found
						$this->Indiscipline_activity->ViewValue = new OptionValues();
						$ari = 0;
						while (!$rswrk->EOF) {
							$arwrk = [];
							$arwrk[1] = HtmlEncode($rswrk->fields('df'));
							$this->Indiscipline_activity->ViewValue->add($this->Indiscipline_activity->displayValue($arwrk));
							$rswrk->MoveNext();
							$ari++;
						}
						$rswrk->MoveFirst();
					} else {
						$this->Indiscipline_activity->ViewValue = $Language->phrase("PleaseSelect");
					}
					$arwrk = $rswrk ? $rswrk->getRows() : [];
					if ($rswrk)
						$rswrk->close();
					$this->Indiscipline_activity->EditValue = $arwrk;
				}
			}

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

			// Updated_Date
			// Edit refer script
			// id

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

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

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

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

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

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

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

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

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

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

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

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

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

		// Check if validation required
		if (!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->HotelID->Required) {
			if (!$this->HotelID->IsDetailKey && $this->HotelID->FormValue != NULL && $this->HotelID->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->HotelID->caption(), $this->HotelID->RequiredErrorMessage));
			}
		}
		if ($this->RollNo->Required) {
			if (!$this->RollNo->IsDetailKey && $this->RollNo->FormValue != NULL && $this->RollNo->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->RollNo->caption(), $this->RollNo->RequiredErrorMessage));
			}
		}
		if ($this->Name->Required) {
			if (!$this->Name->IsDetailKey && $this->Name->FormValue != NULL && $this->Name->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->Name->caption(), $this->Name->RequiredErrorMessage));
			}
		}
		if ($this->Hostel->Required) {
			if (!$this->Hostel->IsDetailKey && $this->Hostel->FormValue != NULL && $this->Hostel->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->Hostel->caption(), $this->Hostel->RequiredErrorMessage));
			}
		}
		if ($this->Floor->Required) {
			if (!$this->Floor->IsDetailKey && $this->Floor->FormValue != NULL && $this->Floor->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->Floor->caption(), $this->Floor->RequiredErrorMessage));
			}
		}
		if ($this->Room_No->Required) {
			if (!$this->Room_No->IsDetailKey && $this->Room_No->FormValue != NULL && $this->Room_No->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->Room_No->caption(), $this->Room_No->RequiredErrorMessage));
			}
		}
		if ($this->Health_issue->Required) {
			if ($this->Health_issue->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->Health_issue->caption(), $this->Health_issue->RequiredErrorMessage));
			}
		}
		if ($this->Indiscipline_activity->Required) {
			if ($this->Indiscipline_activity->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->Indiscipline_activity->caption(), $this->Indiscipline_activity->RequiredErrorMessage));
			}
		}
		if ($this->Involvement->Required) {
			if (!$this->Involvement->IsDetailKey && $this->Involvement->FormValue != NULL && $this->Involvement->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->Involvement->caption(), $this->Involvement->RequiredErrorMessage));
			}
		}
		if ($this->Updated_Date->Required) {
			if (!$this->Updated_Date->IsDetailKey && $this->Updated_Date->FormValue != NULL && $this->Updated_Date->FormValue == "") {
				AddMessage($FormError, str_replace("%s", $this->Updated_Date->caption(), $this->Updated_Date->RequiredErrorMessage));
			}
		}

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

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

	// Delete records based on current filter
	protected function deleteRows()
	{
		global $Language, $Security;
		if (!$Security->canDelete()) {
			$this->setFailureMessage($Language->phrase("NoDeletePermission")); // No delete permission
			return FALSE;
		}
		$deleteRows = TRUE;
		$sql = $this->getCurrentSql();
		$conn = $this->getConnection();
		$conn->raiseErrorFn = 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() : [];

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

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

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

	// Update record based on key values
	protected function editRow()
	{
		global $Security, $Language;
		$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 = [];

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

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

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

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

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

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

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

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

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

			// Updated_Date
			$this->Updated_Date->setDbValueDef($rsnew, CurrentDateTime(), CurrentDate());
			$rsnew['Updated_Date'] = &$this->Updated_Date->DbValue;

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

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

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

		// Set up foreign key field value from Session
			if ($this->getCurrentMasterTable() == "admission") {
				$this->HotelID->CurrentValue = $this->HotelID->getSessionValue();
				$this->RollNo->CurrentValue = $this->RollNo->getSessionValue();
				$this->Name->CurrentValue = $this->Name->getSessionValue();
				$this->Hostel->CurrentValue = $this->Hostel->getSessionValue();
				$this->Floor->CurrentValue = $this->Floor->getSessionValue();
				$this->Room_No->CurrentValue = $this->Room_No->getSessionValue();
			}
			if ($this->getCurrentMasterTable() == "indiscipline") {
				$this->Indiscipline_activity->CurrentValue = $this->Indiscipline_activity->getSessionValue();
			}
		$conn = $this->getConnection();

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

		// HotelID
		$this->HotelID->setDbValueDef($rsnew, $this->HotelID->CurrentValue, "", FALSE);

		// RollNo
		$this->RollNo->setDbValueDef($rsnew, $this->RollNo->CurrentValue, "", FALSE);

		// Name
		$this->Name->setDbValueDef($rsnew, $this->Name->CurrentValue, "", FALSE);

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

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

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

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

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

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

		// Updated_Date
		$this->Updated_Date->setDbValueDef($rsnew, CurrentDateTime(), CurrentDate());
		$rsnew['Updated_Date'] = &$this->Updated_Date->DbValue;

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

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

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

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

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

		// Hide foreign keys
		$masterTblVar = $this->getCurrentMasterTable();
		if ($masterTblVar == "admission") {
			$this->HotelID->Visible = FALSE;
			if ($GLOBALS["admission"]->EventCancelled)
				$this->EventCancelled = TRUE;
			$this->RollNo->Visible = FALSE;
			if ($GLOBALS["admission"]->EventCancelled)
				$this->EventCancelled = TRUE;
			$this->Name->Visible = FALSE;
			if ($GLOBALS["admission"]->EventCancelled)
				$this->EventCancelled = TRUE;
			$this->Hostel->Visible = FALSE;
			if ($GLOBALS["admission"]->EventCancelled)
				$this->EventCancelled = TRUE;
			$this->Floor->Visible = FALSE;
			if ($GLOBALS["admission"]->EventCancelled)
				$this->EventCancelled = TRUE;
			$this->Room_No->Visible = FALSE;
			if ($GLOBALS["admission"]->EventCancelled)
				$this->EventCancelled = TRUE;
		}
		if ($masterTblVar == "indiscipline") {
			$this->Indiscipline_activity->Visible = FALSE;
			if ($GLOBALS["indiscipline"]->EventCancelled)
				$this->EventCancelled = TRUE;
		}
		$this->DbMasterFilter = $this->getMasterFilter(); // Get master filter
		$this->DbDetailFilter = $this->getDetailFilter(); // Get detail filter
	}

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

			// 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_Hostel":
					$conn = Conn("");
					break;
				case "x_Floor":
					$conn = Conn("");
					break;
				case "x_Room_No":
					$conn = Conn("");
					break;
				case "x_Health_issue":
					$conn = Conn("");
					$lookupFilter = function() {
						return "`Status`='1'";
					};
					$lookupFilter = $lookupFilter->bindTo($this);
					break;
				case "x_Indiscipline_activity":
					$conn = Conn("");
					$lookupFilter = function() {
						return "`Status`='1'";
					};
					$lookupFilter = $lookupFilter->bindTo($this);
					break;
				case "x_Involvement":
					$conn = Conn("");
					$lookupFilter = function() {
						return "`Status`='1'";
					};
					$lookupFilter = $lookupFilter->bindTo($this);
					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) {
						case "x_Hostel":
							break;
						case "x_Floor":
							break;
						case "x_Room_No":
							$row[1] = FormatNumber($row[1], 0, -2, -2, -2);
							$row['df'] = $row[1];
							break;
						case "x_Health_issue":
							break;
						case "x_Indiscipline_activity":
							break;
						case "x_Involvement":
							break;
					}
					$ar[strval($row[0])] = $row;
					$rs->moveNext();
				}
				if ($rs)
					$rs->close();
				$fld->Lookup->Options = $ar;
			}
		}
	}

	// Page Load event
	function Page_Load() {

		//echo "Page Load";
	}

	// Page Unload event
	function Page_Unload() {

		//echo "Page Unload";
	}

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

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

	}

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

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

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

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

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

	// Page Render event
	function Page_Render() {

		//echo "Page Render";
	}

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

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

	}

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

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

	}

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

		// Return error message in CustomError
		return TRUE;
	}

	// ListOptions Load event
	function ListOptions_Load() {

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

	}

	// ListOptions Rendering event
	function ListOptions_Rendering() {

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

	}

	// ListOptions Rendered event
	function ListOptions_Rendered() {

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

	}
} // End class
?>