<?php namespace PHPMaker2020\hostelmgr20; ?>
<?php

/**
 * Table class for activity
 */
class activity extends DbTable
{
	protected $SqlFrom = "";
	protected $SqlSelect = "";
	protected $SqlSelectList = "";
	protected $SqlWhere = "";
	protected $SqlGroupBy = "";
	protected $SqlHaving = "";
	protected $SqlOrderBy = "";
	public $UseSessionForListSql = TRUE;

	// Column CSS classes
	public $LeftColumnClass = "col-sm-2 col-form-label ew-label";
	public $RightColumnClass = "col-sm-10";
	public $OffsetColumnClass = "col-sm-10 offset-sm-2";
	public $TableLeftColumnClass = "w-col-2";

	// Export
	public $ExportDoc;

	// Fields
	public $id;
	public $HotelID;
	public $RollNo;
	public $Name;
	public $Hostel;
	public $Floor;
	public $Room_No;
	public $Health_issue;
	public $Indiscipline_activity;
	public $Involvement;
	public $Remarks;
	public $Others;
	public $Updatedby;
	public $Updated_Date;

	// Constructor
	public function __construct()
	{
		global $Language, $CurrentLanguage;
		parent::__construct();

		// Language object
		if (!isset($Language))
			$Language = new Language();
		$this->TableVar = 'activity';
		$this->TableName = 'activity';
		$this->TableType = 'TABLE';

		// Update Table
		$this->UpdateTable = "`activity`";
		$this->Dbid = 'DB';
		$this->ExportAll = TRUE;
		$this->ExportPageBreakCount = 0; // Page break per every n record (PDF only)
		$this->ExportPageOrientation = "portrait"; // Page orientation (PDF only)
		$this->ExportPageSize = "a4"; // Page size (PDF only)
		$this->ExportExcelPageOrientation = ""; // Page orientation (PhpSpreadsheet only)
		$this->ExportExcelPageSize = ""; // Page size (PhpSpreadsheet only)
		$this->ExportWordPageOrientation = "portrait"; // Page orientation (PHPWord only)
		$this->ExportWordColumnWidth = NULL; // Cell width (PHPWord only)
		$this->DetailAdd = FALSE; // Allow detail add
		$this->DetailEdit = FALSE; // Allow detail edit
		$this->DetailView = FALSE; // Allow detail view
		$this->ShowMultipleDetails = FALSE; // Show multiple details
		$this->GridAddRowCount = 5;
		$this->AllowAddDeleteRow = TRUE; // Allow add/delete row
		$this->UserIDAllowSecurity = 0; // User ID Allow
		$this->BasicSearch = new BasicSearch($this->TableVar);

		// id
		$this->id = new DbField('activity', 'activity', 'x_id', 'id', '`id`', '`id`', 3, 11, -1, FALSE, '`id`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'NO');
		$this->id->IsAutoIncrement = TRUE; // Autoincrement field
		$this->id->IsPrimaryKey = TRUE; // Primary key field
		$this->id->Sortable = TRUE; // Allow sort
		$this->id->DefaultErrorMessage = $Language->phrase("IncorrectInteger");
		$this->fields['id'] = &$this->id;

		// HotelID
		$this->HotelID = new DbField('activity', 'activity', 'x_HotelID', 'HotelID', '`HotelID`', '`HotelID`', 200, 12, -1, FALSE, '`HotelID`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'TEXT');
		$this->HotelID->IsForeignKey = TRUE; // Foreign key field
		$this->HotelID->Nullable = FALSE; // NOT NULL field
		$this->HotelID->Required = TRUE; // Required field
		$this->HotelID->Sortable = TRUE; // Allow sort
		$this->fields['HotelID'] = &$this->HotelID;

		// RollNo
		$this->RollNo = new DbField('activity', 'activity', 'x_RollNo', 'RollNo', '`RollNo`', '`RollNo`', 200, 12, -1, FALSE, '`RollNo`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'TEXT');
		$this->RollNo->IsForeignKey = TRUE; // Foreign key field
		$this->RollNo->Nullable = FALSE; // NOT NULL field
		$this->RollNo->Required = TRUE; // Required field
		$this->RollNo->Sortable = TRUE; // Allow sort
		$this->fields['RollNo'] = &$this->RollNo;

		// Name
		$this->Name = new DbField('activity', 'activity', 'x_Name', 'Name', '`Name`', '`Name`', 200, 55, -1, FALSE, '`Name`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'TEXT');
		$this->Name->IsForeignKey = TRUE; // Foreign key field
		$this->Name->Nullable = FALSE; // NOT NULL field
		$this->Name->Required = TRUE; // Required field
		$this->Name->Sortable = TRUE; // Allow sort
		$this->fields['Name'] = &$this->Name;

		// Hostel
		$this->Hostel = new DbField('activity', 'activity', 'x_Hostel', 'Hostel', '`Hostel`', '`Hostel`', 3, 11, -1, FALSE, '`Hostel`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'SELECT');
		$this->Hostel->IsForeignKey = TRUE; // Foreign key field
		$this->Hostel->Nullable = FALSE; // NOT NULL field
		$this->Hostel->Required = TRUE; // Required field
		$this->Hostel->Sortable = TRUE; // Allow sort
		$this->Hostel->UsePleaseSelect = TRUE; // Use PleaseSelect by default
		$this->Hostel->PleaseSelectText = $Language->phrase("PleaseSelect"); // "PleaseSelect" text
		$this->Hostel->Lookup = new Lookup('Hostel', 'hostel', FALSE, 'id', ["Hostel_Name","","",""], [], ["x_Floor"], [], [], [], [], '', '');
		$this->Hostel->DefaultErrorMessage = $Language->phrase("IncorrectInteger");
		$this->fields['Hostel'] = &$this->Hostel;

		// Floor
		$this->Floor = new DbField('activity', 'activity', 'x_Floor', 'Floor', '`Floor`', '`Floor`', 3, 11, -1, FALSE, '`Floor`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'SELECT');
		$this->Floor->IsForeignKey = TRUE; // Foreign key field
		$this->Floor->Nullable = FALSE; // NOT NULL field
		$this->Floor->Required = TRUE; // Required field
		$this->Floor->Sortable = TRUE; // Allow sort
		$this->Floor->UsePleaseSelect = TRUE; // Use PleaseSelect by default
		$this->Floor->PleaseSelectText = $Language->phrase("PleaseSelect"); // "PleaseSelect" text
		$this->Floor->Lookup = new Lookup('Floor', 'floor', FALSE, 'id', ["Floor","","",""], ["x_Hostel"], ["x_Room_No"], ["Hostel_Name"], ["x_Hostel_Name"], [], [], '', '');
		$this->Floor->DefaultErrorMessage = $Language->phrase("IncorrectInteger");
		$this->fields['Floor'] = &$this->Floor;

		// Room_No
		$this->Room_No = new DbField('activity', 'activity', 'x_Room_No', 'Room_No', '`Room_No`', '`Room_No`', 3, 11, -1, FALSE, '`Room_No`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'SELECT');
		$this->Room_No->IsForeignKey = TRUE; // Foreign key field
		$this->Room_No->Nullable = FALSE; // NOT NULL field
		$this->Room_No->Required = TRUE; // Required field
		$this->Room_No->Sortable = TRUE; // Allow sort
		$this->Room_No->UsePleaseSelect = TRUE; // Use PleaseSelect by default
		$this->Room_No->PleaseSelectText = $Language->phrase("PleaseSelect"); // "PleaseSelect" text
		$this->Room_No->Lookup = new Lookup('Room_No', 'rooms', FALSE, 'Room_No', ["Room_No","","",""], ["x_Floor"], [], ["Floor"], ["x_Floor"], [], [], '', '');
		$this->Room_No->DefaultErrorMessage = $Language->phrase("IncorrectInteger");
		$this->fields['Room_No'] = &$this->Room_No;

		// Health_issue
		$this->Health_issue = new DbField('activity', 'activity', 'x_Health_issue', 'Health_issue', '`Health_issue`', '`Health_issue`', 200, 75, -1, FALSE, '`Health_issue`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'CHECKBOX');
		$this->Health_issue->Sortable = TRUE; // Allow sort
		$this->Health_issue->Lookup = new Lookup('Health_issue', 'health', FALSE, 'Health_Issue', ["Health_Issue","","",""], [], [], [], [], [], [], '', '');
		$this->Health_issue->DefaultErrorMessage = $Language->phrase("IncorrectInteger");
		$this->fields['Health_issue'] = &$this->Health_issue;

		// Indiscipline_activity
		$this->Indiscipline_activity = new DbField('activity', 'activity', 'x_Indiscipline_activity', 'Indiscipline_activity', '`Indiscipline_activity`', '`Indiscipline_activity`', 3, 11, -1, FALSE, '`Indiscipline_activity`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'CHECKBOX');
		$this->Indiscipline_activity->IsForeignKey = TRUE; // Foreign key field
		$this->Indiscipline_activity->Sortable = TRUE; // Allow sort
		$this->Indiscipline_activity->Lookup = new Lookup('Indiscipline_activity', 'indiscipline', FALSE, 'id', ["Indiscipline_activity","","",""], [], [], [], [], [], [], '', '');
		$this->Indiscipline_activity->DefaultErrorMessage = $Language->phrase("IncorrectInteger");
		$this->fields['Indiscipline_activity'] = &$this->Indiscipline_activity;

		// Involvement
		$this->Involvement = new DbField('activity', 'activity', 'x_Involvement', 'Involvement', '`Involvement`', '`Involvement`', 3, 11, -1, FALSE, '`Involvement`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'SELECT');
		$this->Involvement->Sortable = TRUE; // Allow sort
		$this->Involvement->UsePleaseSelect = TRUE; // Use PleaseSelect by default
		$this->Involvement->PleaseSelectText = $Language->phrase("PleaseSelect"); // "PleaseSelect" text
		$this->Involvement->Lookup = new Lookup('Involvement', 'involvement', FALSE, 'id', ["Activity","","",""], [], [], [], [], [], [], '', '');
		$this->Involvement->DefaultErrorMessage = $Language->phrase("IncorrectInteger");
		$this->fields['Involvement'] = &$this->Involvement;

		// Remarks
		$this->Remarks = new DbField('activity', 'activity', 'x_Remarks', 'Remarks', '`Remarks`', '`Remarks`', 200, 55, -1, FALSE, '`Remarks`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'TEXT');
		$this->Remarks->Sortable = TRUE; // Allow sort
		$this->Remarks->DefaultErrorMessage = $Language->phrase("IncorrectInteger");
		$this->fields['Remarks'] = &$this->Remarks;

		// Others
		$this->Others = new DbField('activity', 'activity', 'x_Others', 'Others', '`Others`', '`Others`', 200, 120, -1, FALSE, '`Others`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'TEXT');
		$this->Others->Sortable = TRUE; // Allow sort
		$this->fields['Others'] = &$this->Others;

		// Updatedby
		$this->Updatedby = new DbField('activity', 'activity', 'x_Updatedby', 'Updatedby', '`Updatedby`', '`Updatedby`', 200, 55, -1, FALSE, '`Updatedby`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'TEXT');
		$this->Updatedby->Nullable = FALSE; // NOT NULL field
		$this->Updatedby->Sortable = TRUE; // Allow sort
		$this->fields['Updatedby'] = &$this->Updatedby;

		// Updated_Date
		$this->Updated_Date = new DbField('activity', 'activity', 'x_Updated_Date', 'Updated_Date', '`Updated_Date`', CastDateFieldForLike("`Updated_Date`", 0, "DB"), 135, 19, 0, FALSE, '`Updated_Date`', FALSE, FALSE, FALSE, 'FORMATTED TEXT', 'TEXT');
		$this->Updated_Date->Nullable = FALSE; // NOT NULL field
		$this->Updated_Date->Sortable = TRUE; // Allow sort
		$this->Updated_Date->DefaultErrorMessage = str_replace("%s", $GLOBALS["DATE_FORMAT"], $Language->phrase("IncorrectDate"));
		$this->fields['Updated_Date'] = &$this->Updated_Date;
	}

	// Field Visibility
	public function getFieldVisibility($fldParm)
	{
		global $Security;
		return $this->$fldParm->Visible; // Returns original value
	}

	// Set left column class (must be predefined col-*-* classes of Bootstrap grid system)
	function setLeftColumnClass($class)
	{
		if (preg_match('/^col\-(\w+)\-(\d+)$/', $class, $match)) {
			$this->LeftColumnClass = $class . " col-form-label ew-label";
			$this->RightColumnClass = "col-" . $match[1] . "-" . strval(12 - (int)$match[2]);
			$this->OffsetColumnClass = $this->RightColumnClass . " " . str_replace("col-", "offset-", $class);
			$this->TableLeftColumnClass = preg_replace('/^col-\w+-(\d+)$/', "w-col-$1", $class); // Change to w-col-*
		}
	}

	// Single column sort
	public function updateSort(&$fld)
	{
		if ($this->CurrentOrder == $fld->Name) {
			$sortField = $fld->Expression;
			$lastSort = $fld->getSort();
			if ($this->CurrentOrderType == "ASC" || $this->CurrentOrderType == "DESC") {
				$thisSort = $this->CurrentOrderType;
			} else {
				$thisSort = ($lastSort == "ASC") ? "DESC" : "ASC";
			}
			$fld->setSort($thisSort);
			$this->setSessionOrderBy($sortField . " " . $thisSort); // Save to Session
		} else {
			$fld->setSort("");
		}
	}

	// Current master table name
	public function getCurrentMasterTable()
	{
		return @$_SESSION[PROJECT_NAME . "_" . $this->TableVar . "_" . Config("TABLE_MASTER_TABLE")];
	}
	public function setCurrentMasterTable($v)
	{
		$_SESSION[PROJECT_NAME . "_" . $this->TableVar . "_" . Config("TABLE_MASTER_TABLE")] = $v;
	}

	// Session master WHERE clause
	public function getMasterFilter()
	{

		// Master filter
		$masterFilter = "";
		if ($this->getCurrentMasterTable() == "admission") {
			if ($this->HotelID->getSessionValue() != "")
				$masterFilter .= "`HostelID`=" . QuotedValue($this->HotelID->getSessionValue(), DATATYPE_NUMBER, "DB");
			else
				return "";
			if ($this->RollNo->getSessionValue() != "")
				$masterFilter .= " AND `RollNo`=" . QuotedValue($this->RollNo->getSessionValue(), DATATYPE_STRING, "DB");
			else
				return "";
			if ($this->Name->getSessionValue() != "")
				$masterFilter .= " AND `Name`=" . QuotedValue($this->Name->getSessionValue(), DATATYPE_STRING, "DB");
			else
				return "";
			if ($this->Hostel->getSessionValue() != "")
				$masterFilter .= " AND `Hostel`=" . QuotedValue($this->Hostel->getSessionValue(), DATATYPE_NUMBER, "DB");
			else
				return "";
			if ($this->Floor->getSessionValue() != "")
				$masterFilter .= " AND `Floor`=" . QuotedValue($this->Floor->getSessionValue(), DATATYPE_NUMBER, "DB");
			else
				return "";
			if ($this->Room_No->getSessionValue() != "")
				$masterFilter .= " AND `RoomNo`=" . QuotedValue($this->Room_No->getSessionValue(), DATATYPE_NUMBER, "DB");
			else
				return "";
		}
		if ($this->getCurrentMasterTable() == "indiscipline") {
			if ($this->Indiscipline_activity->getSessionValue() != "")
				$masterFilter .= "`id`=" . QuotedValue($this->Indiscipline_activity->getSessionValue(), DATATYPE_NUMBER, "DB");
			else
				return "";
		}
		return $masterFilter;
	}

	// Session detail WHERE clause
	public function getDetailFilter()
	{

		// Detail filter
		$detailFilter = "";
		if ($this->getCurrentMasterTable() == "admission") {
			if ($this->HotelID->getSessionValue() != "")
				$detailFilter .= "`HotelID`=" . QuotedValue($this->HotelID->getSessionValue(), DATATYPE_STRING, "DB");
			else
				return "";
			if ($this->RollNo->getSessionValue() != "")
				$detailFilter .= " AND `RollNo`=" . QuotedValue($this->RollNo->getSessionValue(), DATATYPE_STRING, "DB");
			else
				return "";
			if ($this->Name->getSessionValue() != "")
				$detailFilter .= " AND `Name`=" . QuotedValue($this->Name->getSessionValue(), DATATYPE_STRING, "DB");
			else
				return "";
			if ($this->Hostel->getSessionValue() != "")
				$detailFilter .= " AND `Hostel`=" . QuotedValue($this->Hostel->getSessionValue(), DATATYPE_NUMBER, "DB");
			else
				return "";
			if ($this->Floor->getSessionValue() != "")
				$detailFilter .= " AND `Floor`=" . QuotedValue($this->Floor->getSessionValue(), DATATYPE_NUMBER, "DB");
			else
				return "";
			if ($this->Room_No->getSessionValue() != "")
				$detailFilter .= " AND `Room_No`=" . QuotedValue($this->Room_No->getSessionValue(), DATATYPE_NUMBER, "DB");
			else
				return "";
		}
		if ($this->getCurrentMasterTable() == "indiscipline") {
			if ($this->Indiscipline_activity->getSessionValue() != "")
				$detailFilter .= "`Indiscipline_activity`=" . QuotedValue($this->Indiscipline_activity->getSessionValue(), DATATYPE_NUMBER, "DB");
			else
				return "";
		}
		return $detailFilter;
	}

	// Master filter
	public function sqlMasterFilter_admission()
	{
		return "`HostelID`=@HostelID@ AND `RollNo`='@RollNo@' AND `Name`='@Name@' AND `Hostel`=@Hostel@ AND `Floor`=@Floor@ AND `RoomNo`=@RoomNo@";
	}

	// Detail filter
	public function sqlDetailFilter_admission()
	{
		return "`HotelID`='@HotelID@' AND `RollNo`='@RollNo@' AND `Name`='@Name@' AND `Hostel`=@Hostel@ AND `Floor`=@Floor@ AND `Room_No`=@Room_No@";
	}

	// Master filter
	public function sqlMasterFilter_indiscipline()
	{
		return "`id`=@id@";
	}

	// Detail filter
	public function sqlDetailFilter_indiscipline()
	{
		return "`Indiscipline_activity`=@Indiscipline_activity@";
	}

	// Table level SQL
	public function getSqlFrom() // From
	{
		return ($this->SqlFrom != "") ? $this->SqlFrom : "`activity`";
	}
	public function sqlFrom() // For backward compatibility
	{
		return $this->getSqlFrom();
	}
	public function setSqlFrom($v)
	{
		$this->SqlFrom = $v;
	}
	public function getSqlSelect() // Select
	{
		return ($this->SqlSelect != "") ? $this->SqlSelect : "SELECT * FROM " . $this->getSqlFrom();
	}
	public function sqlSelect() // For backward compatibility
	{
		return $this->getSqlSelect();
	}
	public function setSqlSelect($v)
	{
		$this->SqlSelect = $v;
	}
	public function getSqlWhere() // Where
	{
		$where = ($this->SqlWhere != "") ? $this->SqlWhere : "";
		$this->TableFilter = "";
		AddFilter($where, $this->TableFilter);
		return $where;
	}
	public function sqlWhere() // For backward compatibility
	{
		return $this->getSqlWhere();
	}
	public function setSqlWhere($v)
	{
		$this->SqlWhere = $v;
	}
	public function getSqlGroupBy() // Group By
	{
		return ($this->SqlGroupBy != "") ? $this->SqlGroupBy : "";
	}
	public function sqlGroupBy() // For backward compatibility
	{
		return $this->getSqlGroupBy();
	}
	public function setSqlGroupBy($v)
	{
		$this->SqlGroupBy = $v;
	}
	public function getSqlHaving() // Having
	{
		return ($this->SqlHaving != "") ? $this->SqlHaving : "";
	}
	public function sqlHaving() // For backward compatibility
	{
		return $this->getSqlHaving();
	}
	public function setSqlHaving($v)
	{
		$this->SqlHaving = $v;
	}
	public function getSqlOrderBy() // Order By
	{
		return ($this->SqlOrderBy != "") ? $this->SqlOrderBy : "";
	}
	public function sqlOrderBy() // For backward compatibility
	{
		return $this->getSqlOrderBy();
	}
	public function setSqlOrderBy($v)
	{
		$this->SqlOrderBy = $v;
	}

	// Apply User ID filters
	public function applyUserIDFilters($filter)
	{
		return $filter;
	}

	// Check if User ID security allows view all
	public function userIDAllow($id = "")
	{
		$allow = Config("USER_ID_ALLOW");
		switch ($id) {
			case "add":
			case "copy":
			case "gridadd":
			case "register":
			case "addopt":
				return (($allow & 1) == 1);
			case "edit":
			case "gridedit":
			case "update":
			case "changepwd":
			case "forgotpwd":
				return (($allow & 4) == 4);
			case "delete":
				return (($allow & 2) == 2);
			case "view":
				return (($allow & 32) == 32);
			case "search":
				return (($allow & 64) == 64);
			default:
				return (($allow & 8) == 8);
		}
	}

	// Get recordset
	public function getRecordset($sql, $rowcnt = -1, $offset = -1)
	{
		$conn = $this->getConnection();
		$conn->raiseErrorFn = Config("ERROR_FUNC");
		$rs = $conn->selectLimit($sql, $rowcnt, $offset);
		$conn->raiseErrorFn = "";
		return $rs;
	}

	// Get record count
	public function getRecordCount($sql, $c = NULL)
	{
		$cnt = -1;
		$rs = NULL;
		$sql = preg_replace('/\/\*BeginOrderBy\*\/[\s\S]+\/\*EndOrderBy\*\//', "", $sql); // Remove ORDER BY clause (MSSQL)
		$pattern = '/^SELECT\s([\s\S]+)\sFROM\s/i';

		// Skip Custom View / SubQuery / SELECT DISTINCT / ORDER BY
		if (($this->TableType == 'TABLE' || $this->TableType == 'VIEW' || $this->TableType == 'LINKTABLE') &&
			preg_match($pattern, $sql) && !preg_match('/\(\s*(SELECT[^)]+)\)/i', $sql) &&
			!preg_match('/^\s*select\s+distinct\s+/i', $sql) && !preg_match('/\s+order\s+by\s+/i', $sql)) {
			$sqlwrk = "SELECT COUNT(*) FROM " . preg_replace($pattern, "", $sql);
		} else {
			$sqlwrk = "SELECT COUNT(*) FROM (" . $sql . ") COUNT_TABLE";
		}
		$conn = $c ?: $this->getConnection();
		if ($rs = $conn->execute($sqlwrk)) {
			if (!$rs->EOF && $rs->FieldCount() > 0) {
				$cnt = $rs->fields[0];
				$rs->close();
			}
			return (int)$cnt;
		}

		// Unable to get count, get record count directly
		if ($rs = $conn->execute($sql)) {
			$cnt = $rs->RecordCount();
			$rs->close();
			return (int)$cnt;
		}
		return $cnt;
	}

	// Get SQL
	public function getSql($where, $orderBy = "")
	{
		return BuildSelectSql($this->getSqlSelect(), $this->getSqlWhere(),
			$this->getSqlGroupBy(), $this->getSqlHaving(), $this->getSqlOrderBy(),
			$where, $orderBy);
	}

	// Table SQL
	public function getCurrentSql()
	{
		$filter = $this->CurrentFilter;
		$filter = $this->applyUserIDFilters($filter);
		$sort = $this->getSessionOrderBy();
		return $this->getSql($filter, $sort);
	}

	// Table SQL with List page filter
	public function getListSql()
	{
		$filter = $this->UseSessionForListSql ? $this->getSessionWhere() : "";
		AddFilter($filter, $this->CurrentFilter);
		$filter = $this->applyUserIDFilters($filter);
		$this->Recordset_Selecting($filter);
		$select = $this->getSqlSelect();
		$sort = $this->UseSessionForListSql ? $this->getSessionOrderBy() : "";
		return BuildSelectSql($select, $this->getSqlWhere(), $this->getSqlGroupBy(),
			$this->getSqlHaving(), $this->getSqlOrderBy(), $filter, $sort);
	}

	// Get ORDER BY clause
	public function getOrderBy()
	{
		$sort = $this->getSessionOrderBy();
		return BuildSelectSql("", "", "", "", $this->getSqlOrderBy(), "", $sort);
	}

	// Get record count based on filter (for detail record count in master table pages)
	public function loadRecordCount($filter)
	{
		$origFilter = $this->CurrentFilter;
		$this->CurrentFilter = $filter;
		$this->Recordset_Selecting($this->CurrentFilter);
		$select = $this->TableType == 'CUSTOMVIEW' ? $this->getSqlSelect() : "SELECT * FROM " . $this->getSqlFrom();
		$groupBy = $this->TableType == 'CUSTOMVIEW' ? $this->getSqlGroupBy() : "";
		$having = $this->TableType == 'CUSTOMVIEW' ? $this->getSqlHaving() : "";
		$sql = BuildSelectSql($select, $this->getSqlWhere(), $groupBy, $having, "", $this->CurrentFilter, "");
		$cnt = $this->getRecordCount($sql);
		$this->CurrentFilter = $origFilter;
		return $cnt;
	}

	// Get record count (for current List page)
	public function listRecordCount()
	{
		$filter = $this->getSessionWhere();
		AddFilter($filter, $this->CurrentFilter);
		$filter = $this->applyUserIDFilters($filter);
		$this->Recordset_Selecting($filter);
		$select = $this->TableType == 'CUSTOMVIEW' ? $this->getSqlSelect() : "SELECT * FROM " . $this->getSqlFrom();
		$groupBy = $this->TableType == 'CUSTOMVIEW' ? $this->getSqlGroupBy() : "";
		$having = $this->TableType == 'CUSTOMVIEW' ? $this->getSqlHaving() : "";
		$sql = BuildSelectSql($select, $this->getSqlWhere(), $groupBy, $having, "", $filter, "");
		$cnt = $this->getRecordCount($sql);
		return $cnt;
	}

	// INSERT statement
	protected function insertSql(&$rs)
	{
		$names = "";
		$values = "";
		foreach ($rs as $name => $value) {
			if (!isset($this->fields[$name]) || $this->fields[$name]->IsCustom)
				continue;
			$names .= $this->fields[$name]->Expression . ",";
			$values .= QuotedValue($value, $this->fields[$name]->DataType, $this->Dbid) . ",";
		}
		$names = preg_replace('/,+$/', "", $names);
		$values = preg_replace('/,+$/', "", $values);
		return "INSERT INTO " . $this->UpdateTable . " ($names) VALUES ($values)";
	}

	// Insert
	public function insert(&$rs)
	{
		$conn = $this->getConnection();
		$success = $conn->execute($this->insertSql($rs));
		if ($success) {

			// Get insert id if necessary
			$this->id->setDbValue($conn->insert_ID());
			$rs['id'] = $this->id->DbValue;
		}
		return $success;
	}

	// UPDATE statement
	protected function updateSql(&$rs, $where = "", $curfilter = TRUE)
	{
		$sql = "UPDATE " . $this->UpdateTable . " SET ";
		foreach ($rs as $name => $value) {
			if (!isset($this->fields[$name]) || $this->fields[$name]->IsCustom || $this->fields[$name]->IsAutoIncrement)
				continue;
			$sql .= $this->fields[$name]->Expression . "=";
			$sql .= QuotedValue($value, $this->fields[$name]->DataType, $this->Dbid) . ",";
		}
		$sql = preg_replace('/,+$/', "", $sql);
		$filter = ($curfilter) ? $this->CurrentFilter : "";
		if (is_array($where))
			$where = $this->arrayToFilter($where);
		AddFilter($filter, $where);
		if ($filter != "")
			$sql .= " WHERE " . $filter;
		return $sql;
	}

	// Update
	public function update(&$rs, $where = "", $rsold = NULL, $curfilter = TRUE)
	{
		$conn = $this->getConnection();
		$success = $conn->execute($this->updateSql($rs, $where, $curfilter));
		return $success;
	}

	// DELETE statement
	protected function deleteSql(&$rs, $where = "", $curfilter = TRUE)
	{
		$sql = "DELETE FROM " . $this->UpdateTable . " WHERE ";
		if (is_array($where))
			$where = $this->arrayToFilter($where);
		if ($rs) {
			if (array_key_exists('id', $rs))
				AddFilter($where, QuotedName('id', $this->Dbid) . '=' . QuotedValue($rs['id'], $this->id->DataType, $this->Dbid));
		}
		$filter = ($curfilter) ? $this->CurrentFilter : "";
		AddFilter($filter, $where);
		if ($filter != "")
			$sql .= $filter;
		else
			$sql .= "0=1"; // Avoid delete
		return $sql;
	}

	// Delete
	public function delete(&$rs, $where = "", $curfilter = FALSE)
	{
		$success = TRUE;
		$conn = $this->getConnection();
		if ($success)
			$success = $conn->execute($this->deleteSql($rs, $where, $curfilter));
		return $success;
	}

	// Load DbValue from recordset or array
	protected function loadDbValues(&$rs)
	{
		if (!$rs || !is_array($rs) && $rs->EOF)
			return;
		$row = is_array($rs) ? $rs : $rs->fields;
		$this->id->DbValue = $row['id'];
		$this->HotelID->DbValue = $row['HotelID'];
		$this->RollNo->DbValue = $row['RollNo'];
		$this->Name->DbValue = $row['Name'];
		$this->Hostel->DbValue = $row['Hostel'];
		$this->Floor->DbValue = $row['Floor'];
		$this->Room_No->DbValue = $row['Room_No'];
		$this->Health_issue->DbValue = $row['Health_issue'];
		$this->Indiscipline_activity->DbValue = $row['Indiscipline_activity'];
		$this->Involvement->DbValue = $row['Involvement'];
		$this->Remarks->DbValue = $row['Remarks'];
		$this->Others->DbValue = $row['Others'];
		$this->Updatedby->DbValue = $row['Updatedby'];
		$this->Updated_Date->DbValue = $row['Updated_Date'];
	}

	// Delete uploaded files
	public function deleteUploadedFiles($row)
	{
		$this->loadDbValues($row);
	}

	// Record filter WHERE clause
	protected function sqlKeyFilter()
	{
		return "`id` = @id@";
	}

	// Get record filter
	public function getRecordFilter($row = NULL)
	{
		$keyFilter = $this->sqlKeyFilter();
		if (is_array($row))
			$val = array_key_exists('id', $row) ? $row['id'] : NULL;
		else
			$val = $this->id->OldValue !== NULL ? $this->id->OldValue : $this->id->CurrentValue;
		if (!is_numeric($val))
			return "0=1"; // Invalid key
		if ($val == NULL)
			return "0=1"; // Invalid key
		else
			$keyFilter = str_replace("@id@", AdjustSql($val, $this->Dbid), $keyFilter); // Replace key value
		return $keyFilter;
	}

	// Return page URL
	public function getReturnUrl()
	{
		$name = PROJECT_NAME . "_" . $this->TableVar . "_" . Config("TABLE_RETURN_URL");

		// Get referer URL automatically
		if (ServerVar("HTTP_REFERER") != "" && ReferPageName() != CurrentPageName() && ReferPageName() != "login.php") // Referer not same page or login page
			$_SESSION[$name] = ServerVar("HTTP_REFERER"); // Save to Session
		if (@$_SESSION[$name] != "") {
			return $_SESSION[$name];
		} else {
			return "activitylist.php";
		}
	}
	public function setReturnUrl($v)
	{
		$_SESSION[PROJECT_NAME . "_" . $this->TableVar . "_" . Config("TABLE_RETURN_URL")] = $v;
	}

	// Get modal caption
	public function getModalCaption($pageName)
	{
		global $Language;
		if ($pageName == "activityview.php")
			return $Language->phrase("View");
		elseif ($pageName == "activityedit.php")
			return $Language->phrase("Edit");
		elseif ($pageName == "activityadd.php")
			return $Language->phrase("Add");
		else
			return "";
	}

	// List URL
	public function getListUrl()
	{
		return "activitylist.php";
	}

	// View URL
	public function getViewUrl($parm = "")
	{
		if ($parm != "")
			$url = $this->keyUrl("activityview.php", $this->getUrlParm($parm));
		else
			$url = $this->keyUrl("activityview.php", $this->getUrlParm(Config("TABLE_SHOW_DETAIL") . "="));
		return $this->addMasterUrl($url);
	}

	// Add URL
	public function getAddUrl($parm = "")
	{
		if ($parm != "")
			$url = "activityadd.php?" . $this->getUrlParm($parm);
		else
			$url = "activityadd.php";
		return $this->addMasterUrl($url);
	}

	// Edit URL
	public function getEditUrl($parm = "")
	{
		$url = $this->keyUrl("activityedit.php", $this->getUrlParm($parm));
		return $this->addMasterUrl($url);
	}

	// Inline edit URL
	public function getInlineEditUrl()
	{
		$url = $this->keyUrl(CurrentPageName(), $this->getUrlParm("action=edit"));
		return $this->addMasterUrl($url);
	}

	// Copy URL
	public function getCopyUrl($parm = "")
	{
		$url = $this->keyUrl("activityadd.php", $this->getUrlParm($parm));
		return $this->addMasterUrl($url);
	}

	// Inline copy URL
	public function getInlineCopyUrl()
	{
		$url = $this->keyUrl(CurrentPageName(), $this->getUrlParm("action=copy"));
		return $this->addMasterUrl($url);
	}

	// Delete URL
	public function getDeleteUrl()
	{
		return $this->keyUrl("activitydelete.php", $this->getUrlParm());
	}

	// Add master url
	public function addMasterUrl($url)
	{
		if ($this->getCurrentMasterTable() == "admission" && !ContainsString($url, Config("TABLE_SHOW_MASTER") . "=")) {
			$url .= (ContainsString($url, "?") ? "&" : "?") . Config("TABLE_SHOW_MASTER") . "=" . $this->getCurrentMasterTable();
			$url .= "&fk_HostelID=" . urlencode($this->HotelID->CurrentValue);
			$url .= "&fk_RollNo=" . urlencode($this->RollNo->CurrentValue);
			$url .= "&fk_Name=" . urlencode($this->Name->CurrentValue);
			$url .= "&fk_Hostel=" . urlencode($this->Hostel->CurrentValue);
			$url .= "&fk_Floor=" . urlencode($this->Floor->CurrentValue);
			$url .= "&fk_RoomNo=" . urlencode($this->Room_No->CurrentValue);
		}
		if ($this->getCurrentMasterTable() == "indiscipline" && !ContainsString($url, Config("TABLE_SHOW_MASTER") . "=")) {
			$url .= (ContainsString($url, "?") ? "&" : "?") . Config("TABLE_SHOW_MASTER") . "=" . $this->getCurrentMasterTable();
			$url .= "&fk_id=" . urlencode($this->Indiscipline_activity->CurrentValue);
		}
		return $url;
	}
	public function keyToJson($htmlEncode = FALSE)
	{
		$json = "";
		$json .= "id:" . JsonEncode($this->id->CurrentValue, "number");
		$json = "{" . $json . "}";
		if ($htmlEncode)
			$json = HtmlEncode($json);
		return $json;
	}

	// Add key value to URL
	public function keyUrl($url, $parm = "")
	{
		$url = $url . "?";
		if ($parm != "")
			$url .= $parm . "&";
		if ($this->id->CurrentValue != NULL) {
			$url .= "id=" . urlencode($this->id->CurrentValue);
		} else {
			return "javascript:ew.alert(ew.language.phrase('InvalidRecord'));";
		}
		return $url;
	}

	// Sort URL
	public function sortUrl(&$fld)
	{
		if ($this->CurrentAction || $this->isExport() ||
			in_array($fld->Type, [128, 204, 205])) { // Unsortable data type
				return "";
		} elseif ($fld->Sortable) {
			$urlParm = $this->getUrlParm("order=" . urlencode($fld->Name) . "&amp;ordertype=" . $fld->reverseSort());
			return $this->addMasterUrl(CurrentPageName() . "?" . $urlParm);
		} else {
			return "";
		}
	}

	// Get record keys from Post/Get/Session
	public function getRecordKeys()
	{
		$arKeys = [];
		$arKey = [];
		if (Param("key_m") !== NULL) {
			$arKeys = Param("key_m");
			$cnt = count($arKeys);
		} else {
			if (Param("id") !== NULL)
				$arKeys[] = Param("id");
			elseif (IsApi() && Key(0) !== NULL)
				$arKeys[] = Key(0);
			elseif (IsApi() && Route(2) !== NULL)
				$arKeys[] = Route(2);
			else
				$arKeys = NULL; // Do not setup

			//return $arKeys; // Do not return yet, so the values will also be checked by the following code
		}

		// Check keys
		$ar = [];
		if (is_array($arKeys)) {
			foreach ($arKeys as $key) {
				if (!is_numeric($key))
					continue;
				$ar[] = $key;
			}
		}
		return $ar;
	}

	// Get filter from record keys
	public function getFilterFromRecordKeys($setCurrent = TRUE)
	{
		$arKeys = $this->getRecordKeys();
		$keyFilter = "";
		foreach ($arKeys as $key) {
			if ($keyFilter != "") $keyFilter .= " OR ";
			if ($setCurrent)
				$this->id->CurrentValue = $key;
			else
				$this->id->OldValue = $key;
			$keyFilter .= "(" . $this->getRecordFilter() . ")";
		}
		return $keyFilter;
	}

	// Load rows based on filter
	public function &loadRs($filter)
	{

		// Set up filter (WHERE Clause)
		$sql = $this->getSql($filter);
		$conn = $this->getConnection();
		$rs = $conn->execute($sql);
		return $rs;
	}

	// Load row values from recordset
	public function loadListRowValues(&$rs)
	{
		$this->id->setDbValue($rs->fields('id'));
		$this->HotelID->setDbValue($rs->fields('HotelID'));
		$this->RollNo->setDbValue($rs->fields('RollNo'));
		$this->Name->setDbValue($rs->fields('Name'));
		$this->Hostel->setDbValue($rs->fields('Hostel'));
		$this->Floor->setDbValue($rs->fields('Floor'));
		$this->Room_No->setDbValue($rs->fields('Room_No'));
		$this->Health_issue->setDbValue($rs->fields('Health_issue'));
		$this->Indiscipline_activity->setDbValue($rs->fields('Indiscipline_activity'));
		$this->Involvement->setDbValue($rs->fields('Involvement'));
		$this->Remarks->setDbValue($rs->fields('Remarks'));
		$this->Others->setDbValue($rs->fields('Others'));
		$this->Updatedby->setDbValue($rs->fields('Updatedby'));
		$this->Updated_Date->setDbValue($rs->fields('Updated_Date'));
	}

	// Render list row values
	public function renderListRow()
	{
		global $Security, $CurrentLanguage, $Language;

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

		// Common render codes
		// id
		// HotelID
		// RollNo
		// Name
		// Hostel
		// Floor
		// Room_No
		// Health_issue
		// Indiscipline_activity
		// Involvement
		// Remarks
		// Others
		// Updatedby
		// Updated_Date
		// 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 = "";

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

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

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

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

		// Call Row Rendered event
		$this->Row_Rendered();

		// Save data for Custom Template
		$this->Rows[] = $this->customTemplateFieldValues();
	}

	// Render edit row values
	public function renderEditRow()
	{
		global $Security, $CurrentLanguage, $Language;

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

		// 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->ViewValue = $this->HotelID->CurrentValue;
			$this->HotelID->ViewCustomAttributes = "";
		} else {
			if (!$this->HotelID->Raw)
				$this->HotelID->CurrentValue = HtmlDecode($this->HotelID->CurrentValue);
			$this->HotelID->EditValue = $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->ViewValue = $this->RollNo->CurrentValue;
			$this->RollNo->ViewCustomAttributes = "";
		} else {
			if (!$this->RollNo->Raw)
				$this->RollNo->CurrentValue = HtmlDecode($this->RollNo->CurrentValue);
			$this->RollNo->EditValue = $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->ViewValue = $this->Name->CurrentValue;
			$this->Name->ViewCustomAttributes = "";
		} else {
			if (!$this->Name->Raw)
				$this->Name->CurrentValue = HtmlDecode($this->Name->CurrentValue);
			$this->Name->EditValue = $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();
			$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 {
		}

		// Floor
		$this->Floor->EditAttrs["class"] = "form-control";
		$this->Floor->EditCustomAttributes = "";
		if ($this->Floor->getSessionValue() != "") {
			$this->Floor->CurrentValue = $this->Floor->getSessionValue();
			$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 {
		}

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

		// Health_issue
		$this->Health_issue->EditCustomAttributes = "";

		// Indiscipline_activity
		$this->Indiscipline_activity->EditCustomAttributes = "";
		if ($this->Indiscipline_activity->getSessionValue() != "") {
			$this->Indiscipline_activity->CurrentValue = $this->Indiscipline_activity->getSessionValue();
			$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 {
		}

		// Involvement
		$this->Involvement->EditAttrs["class"] = "form-control";
		$this->Involvement->EditCustomAttributes = "";

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

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

		// Updatedby
		// Updated_Date
		// Call Row Rendered event

		$this->Row_Rendered();
	}

	// Aggregate list row values
	public function aggregateListRowValues()
	{
	}

	// Aggregate list row (for rendering)
	public function aggregateListRow()
	{

		// Call Row Rendered event
		$this->Row_Rendered();
	}

	// Export data in HTML/CSV/Word/Excel/Email/PDF format
	public function exportDocument($doc, $recordset, $startRec = 1, $stopRec = 1, $exportPageType = "")
	{
		if (!$recordset || !$doc)
			return;
		if (!$doc->ExportCustom) {

			// Write header
			$doc->exportTableHeader();
			if ($doc->Horizontal) { // Horizontal format, write header
				$doc->beginExportRow();
				if ($exportPageType == "view") {
					$doc->exportCaption($this->id);
					$doc->exportCaption($this->HotelID);
					$doc->exportCaption($this->RollNo);
					$doc->exportCaption($this->Name);
					$doc->exportCaption($this->Hostel);
					$doc->exportCaption($this->Floor);
					$doc->exportCaption($this->Room_No);
					$doc->exportCaption($this->Health_issue);
					$doc->exportCaption($this->Indiscipline_activity);
					$doc->exportCaption($this->Involvement);
					$doc->exportCaption($this->Remarks);
					$doc->exportCaption($this->Others);
					$doc->exportCaption($this->Updatedby);
					$doc->exportCaption($this->Updated_Date);
				} else {
					$doc->exportCaption($this->id);
					$doc->exportCaption($this->HotelID);
					$doc->exportCaption($this->RollNo);
					$doc->exportCaption($this->Name);
					$doc->exportCaption($this->Hostel);
					$doc->exportCaption($this->Floor);
					$doc->exportCaption($this->Room_No);
					$doc->exportCaption($this->Health_issue);
					$doc->exportCaption($this->Indiscipline_activity);
					$doc->exportCaption($this->Involvement);
					$doc->exportCaption($this->Remarks);
					$doc->exportCaption($this->Others);
					$doc->exportCaption($this->Updatedby);
					$doc->exportCaption($this->Updated_Date);
				}
				$doc->endExportRow();
			}
		}

		// Move to first record
		$recCnt = $startRec - 1;
		if (!$recordset->EOF) {
			$recordset->moveFirst();
			if ($startRec > 1)
				$recordset->move($startRec - 1);
		}
		while (!$recordset->EOF && $recCnt < $stopRec) {
			$recCnt++;
			if ($recCnt >= $startRec) {
				$rowCnt = $recCnt - $startRec + 1;

				// Page break
				if ($this->ExportPageBreakCount > 0) {
					if ($rowCnt > 1 && ($rowCnt - 1) % $this->ExportPageBreakCount == 0)
						$doc->exportPageBreak();
				}
				$this->loadListRowValues($recordset);

				// Render row
				$this->RowType = ROWTYPE_VIEW; // Render view
				$this->resetAttributes();
				$this->renderListRow();
				if (!$doc->ExportCustom) {
					$doc->beginExportRow($rowCnt); // Allow CSS styles if enabled
					if ($exportPageType == "view") {
						$doc->exportField($this->id);
						$doc->exportField($this->HotelID);
						$doc->exportField($this->RollNo);
						$doc->exportField($this->Name);
						$doc->exportField($this->Hostel);
						$doc->exportField($this->Floor);
						$doc->exportField($this->Room_No);
						$doc->exportField($this->Health_issue);
						$doc->exportField($this->Indiscipline_activity);
						$doc->exportField($this->Involvement);
						$doc->exportField($this->Remarks);
						$doc->exportField($this->Others);
						$doc->exportField($this->Updatedby);
						$doc->exportField($this->Updated_Date);
					} else {
						$doc->exportField($this->id);
						$doc->exportField($this->HotelID);
						$doc->exportField($this->RollNo);
						$doc->exportField($this->Name);
						$doc->exportField($this->Hostel);
						$doc->exportField($this->Floor);
						$doc->exportField($this->Room_No);
						$doc->exportField($this->Health_issue);
						$doc->exportField($this->Indiscipline_activity);
						$doc->exportField($this->Involvement);
						$doc->exportField($this->Remarks);
						$doc->exportField($this->Others);
						$doc->exportField($this->Updatedby);
						$doc->exportField($this->Updated_Date);
					}
					$doc->endExportRow($rowCnt);
				}
			}

			// Call Row Export server event
			if ($doc->ExportCustom)
				$this->Row_Export($recordset->fields);
			$recordset->moveNext();
		}
		if (!$doc->ExportCustom) {
			$doc->exportTableFooter();
		}
	}

	// Get file data
	public function getFileData($fldparm, $key, $resize, $width = 0, $height = 0)
	{

		// No binary fields
		return FALSE;
	}

	// Table level events
	// Recordset Selecting event
	function Recordset_Selecting(&$filter) {

		// Enter your code here
	}

	// Recordset Selected event
	function Recordset_Selected(&$rs) {

		//echo "Recordset Selected";
	}

	// Recordset Search Validated event
	function Recordset_SearchValidated() {

		// Example:
		//$this->MyField1->AdvancedSearch->SearchValue = "your search criteria"; // Search value

	}

	// Recordset Searching event
	function Recordset_Searching(&$filter) {

		// Enter your code here
	}

	// Row_Selecting event
	function Row_Selecting(&$filter) {

		// Enter your code here
	}

	// Row Selected event
	function Row_Selected(&$rs) {

		//echo "Row Selected";
	}

	// Row Inserting event
	function Row_Inserting($rsold, &$rsnew) {

		// Enter your code here
		// To cancel, set return value to FALSE

		return TRUE;
	}

	// Row Inserted event
	function Row_Inserted($rsold, &$rsnew) {

		//echo "Row Inserted"
	}

	// Row Updating event
	function Row_Updating($rsold, &$rsnew) {

		// Enter your code here
		// To cancel, set return value to FALSE

		return TRUE;
	}

	// Row Updated event
	function Row_Updated($rsold, &$rsnew) {

		//echo "Row Updated";
	}

	// Row Update Conflict event
	function Row_UpdateConflict($rsold, &$rsnew) {

		// Enter your code here
		// To ignore conflict, set return value to FALSE

		return TRUE;
	}

	// Grid Inserting event
	function Grid_Inserting() {

		// Enter your code here
		// To reject grid insert, set return value to FALSE

		return TRUE;
	}

	// Grid Inserted event
	function Grid_Inserted($rsnew) {

		//echo "Grid Inserted";
	}

	// Grid Updating event
	function Grid_Updating($rsold) {

		// Enter your code here
		// To reject grid update, set return value to FALSE

		return TRUE;
	}

	// Grid Updated event
	function Grid_Updated($rsold, $rsnew) {

		//echo "Grid Updated";
	}

	// Row Deleting event
	function Row_Deleting(&$rs) {

		// Enter your code here
		// To cancel, set return value to False

		return TRUE;
	}

	// Row Deleted event
	function Row_Deleted(&$rs) {

		//echo "Row Deleted";
	}

	// Email Sending event
	function Email_Sending($email, &$args) {

		//var_dump($email); var_dump($args); exit();
		return TRUE;
	}

	// Lookup Selecting event
	function Lookup_Selecting($fld, &$filter) {

		//var_dump($fld->Name, $fld->Lookup, $filter); // Uncomment to view the filter
		// Enter your code here

	}

	// Row Rendering event
	function Row_Rendering() {

		// Enter your code here
	}

	// Row Rendered event
	function Row_Rendered() {

		// To view properties of field class, use:
		//var_dump($this-><FieldName>);

	}

	// User ID Filtering event
	function UserID_Filtering(&$filter) {

		// Enter your code here
	}
}
?>