Your IP : 216.73.217.79


Current Path : /var/www/cesa.co.za/cceadmin/
Upload File :
Current File : /var/www/cesa.co.za/cceadmin/CCEExamQuestionsinfo.php

<?php

// Global variable for table object
$CCEExamQuestions = NULL;

//
// Table class for CCEExamQuestions
//
class cCCEExamQuestions {
	var $TableVar = 'CCEExamQuestions';
	var $TableName = 'CCEExamQuestions';
	var $TableType = 'TABLE';
	var $Question_ID;
	var $Questionnaire_ID;
	var $Section_ID;
	var $Question;
	var $Display_Order;
	var $IsMulti;
	var $IsOptional;
	var $Answer_Type;
	var $Answer_Template;
	var $Model_Answer;
	var $ParentQuestionID;
	var $RequireNumber;
	var $MinNum;
	var $MaxNum;
	var $RecallPrevAnswer;
	var $QuestionTitle;
	var $NumMarks;
	var $DropDown;
	var $InUse;
	var $fields = array();
	var $UseTokenInUrl = EW_USE_TOKEN_IN_URL;
	var $Export; // Export
	var $ExportOriginalValue = EW_EXPORT_ORIGINAL_VALUE;
	var $ExportAll = TRUE;
	var $SendEmail; // Send email
	var $TableCustomInnerHtml; // Custom inner HTML
	var $BasicSearchKeyword; // Basic search keyword
	var $BasicSearchType; // Basic search type
	var $CurrentFilter; // Current filter
	var $CurrentOrder; // Current order
	var $CurrentOrderType; // Current order type
	var $RowType; // Row type
	var $CssClass; // CSS class
	var $CssStyle; // CSS style
	var $RowAttrs = array(); // Row custom attributes
	var $TableFilter = "";
	var $CurrentAction; // Current action
	var $UpdateConflict; // Update conflict
	var $EventName; // Event name
	var $EventCancelled; // Event cancelled
	var $CancelMessage; // Cancel message

	//
	// Table class constructor
	//
	function __construct() {
		global $Language;

		// Question_ID
		$this->Question_ID = new cField('CCEExamQuestions', 'CCEExamQuestions', 'x_Question_ID', 'Question_ID', '`Question_ID`', 3, -1, FALSE, '`Question_ID`', FALSE);
		$this->Question_ID->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['Question_ID'] =& $this->Question_ID;

		// Questionnaire_ID
		$this->Questionnaire_ID = new cField('CCEExamQuestions', 'CCEExamQuestions', 'x_Questionnaire_ID', 'Questionnaire_ID', '`Questionnaire_ID`', 3, -1, FALSE, '`Questionnaire_ID`', FALSE);
		$this->Questionnaire_ID->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['Questionnaire_ID'] =& $this->Questionnaire_ID;

		// Section_ID
		$this->Section_ID = new cField('CCEExamQuestions', 'CCEExamQuestions', 'x_Section_ID', 'Section_ID', '`Section_ID`', 3, -1, FALSE, '`Section_ID`', FALSE);
		$this->Section_ID->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['Section_ID'] =& $this->Section_ID;

		// Question
		$this->Question = new cField('CCEExamQuestions', 'CCEExamQuestions', 'x_Question', 'Question', '`Question`', 201, -1, FALSE, '`Question`', FALSE);
		$this->Question->TruncateMemoRemoveHtml = TRUE;
		$this->fields['Question'] =& $this->Question;

		// Display_Order
		$this->Display_Order = new cField('CCEExamQuestions', 'CCEExamQuestions', 'x_Display_Order', 'Display_Order', '`Display_Order`', 3, -1, FALSE, '`Display_Order`', FALSE);
		$this->Display_Order->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['Display_Order'] =& $this->Display_Order;

		// IsMulti
		$this->IsMulti = new cField('CCEExamQuestions', 'CCEExamQuestions', 'x_IsMulti', 'IsMulti', '`IsMulti`', 16, -1, FALSE, '`IsMulti`', FALSE);
		$this->IsMulti->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['IsMulti'] =& $this->IsMulti;

		// IsOptional
		$this->IsOptional = new cField('CCEExamQuestions', 'CCEExamQuestions', 'x_IsOptional', 'IsOptional', '`IsOptional`', 16, -1, FALSE, '`IsOptional`', FALSE);
		$this->IsOptional->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['IsOptional'] =& $this->IsOptional;

		// Answer_Type
		$this->Answer_Type = new cField('CCEExamQuestions', 'CCEExamQuestions', 'x_Answer_Type', 'Answer_Type', '`Answer_Type`', 200, -1, FALSE, '`Answer_Type`', FALSE);
		$this->fields['Answer_Type'] =& $this->Answer_Type;

		// Answer_Template
		$this->Answer_Template = new cField('CCEExamQuestions', 'CCEExamQuestions', 'x_Answer_Template', 'Answer_Template', '`Answer_Template`', 3, -1, FALSE, '`Answer_Template`', FALSE);
		$this->Answer_Template->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['Answer_Template'] =& $this->Answer_Template;

		// Model_Answer
		$this->Model_Answer = new cField('CCEExamQuestions', 'CCEExamQuestions', 'x_Model_Answer', 'Model_Answer', '`Model_Answer`', 201, -1, FALSE, '`Model_Answer`', FALSE);
		$this->fields['Model_Answer'] =& $this->Model_Answer;

		// ParentQuestionID
		$this->ParentQuestionID = new cField('CCEExamQuestions', 'CCEExamQuestions', 'x_ParentQuestionID', 'ParentQuestionID', '`ParentQuestionID`', 3, -1, FALSE, '`ParentQuestionID`', FALSE);
		$this->ParentQuestionID->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['ParentQuestionID'] =& $this->ParentQuestionID;

		// RequireNumber
		$this->RequireNumber = new cField('CCEExamQuestions', 'CCEExamQuestions', 'x_RequireNumber', 'RequireNumber', '`RequireNumber`', 16, -1, FALSE, '`RequireNumber`', FALSE);
		$this->RequireNumber->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['RequireNumber'] =& $this->RequireNumber;

		// MinNum
		$this->MinNum = new cField('CCEExamQuestions', 'CCEExamQuestions', 'x_MinNum', 'MinNum', '`MinNum`', 3, -1, FALSE, '`MinNum`', FALSE);
		$this->MinNum->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['MinNum'] =& $this->MinNum;

		// MaxNum
		$this->MaxNum = new cField('CCEExamQuestions', 'CCEExamQuestions', 'x_MaxNum', 'MaxNum', '`MaxNum`', 3, -1, FALSE, '`MaxNum`', FALSE);
		$this->MaxNum->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['MaxNum'] =& $this->MaxNum;

		// RecallPrevAnswer
		$this->RecallPrevAnswer = new cField('CCEExamQuestions', 'CCEExamQuestions', 'x_RecallPrevAnswer', 'RecallPrevAnswer', '`RecallPrevAnswer`', 16, -1, FALSE, '`RecallPrevAnswer`', FALSE);
		$this->RecallPrevAnswer->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['RecallPrevAnswer'] =& $this->RecallPrevAnswer;

		// QuestionTitle
		$this->QuestionTitle = new cField('CCEExamQuestions', 'CCEExamQuestions', 'x_QuestionTitle', 'QuestionTitle', '`QuestionTitle`', 200, -1, FALSE, '`QuestionTitle`', FALSE);
		$this->fields['QuestionTitle'] =& $this->QuestionTitle;

		// NumMarks
		$this->NumMarks = new cField('CCEExamQuestions', 'CCEExamQuestions', 'x_NumMarks', 'NumMarks', '`NumMarks`', 131, -1, FALSE, '`NumMarks`', FALSE);
		$this->NumMarks->FldDefaultErrMsg = $Language->Phrase("IncorrectFloat");
		$this->fields['NumMarks'] =& $this->NumMarks;

		// DropDown
		$this->DropDown = new cField('CCEExamQuestions', 'CCEExamQuestions', 'x_DropDown', 'DropDown', '`DropDown`', 16, -1, FALSE, '`DropDown`', FALSE);
		$this->DropDown->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['DropDown'] =& $this->DropDown;

		// InUse
		$this->InUse = new cField('CCEExamQuestions', 'CCEExamQuestions', 'x_InUse', 'InUse', '`InUse`', 16, -1, FALSE, '`InUse`', FALSE);
		$this->InUse->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['InUse'] =& $this->InUse;
	}

	// Table caption
	function TableCaption() {
		global $Language;
		return $Language->TablePhrase($this->TableVar, "TblCaption");
	}

	// Page caption
	function PageCaption($Page) {
		global $Language;
		$Caption = $Language->TablePhrase($this->TableVar, "TblPageCaption" . $Page);
		if ($Caption == "") $Caption = "Page " . $Page;
		return $Caption;
	}

	// Export return page
	function ExportReturnUrl() {
		$url = @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_EXPORT_RETURN_URL];
		return ($url <> "") ? $url : ew_CurrentPage();
	}

	function setExportReturnUrl($v) {
		$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_EXPORT_RETURN_URL] = $v;
	}

	// Records per page
	function getRecordsPerPage() {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_REC_PER_PAGE];
	}

	function setRecordsPerPage($v) {
		$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_REC_PER_PAGE] = $v;
	}

	// Start record number
	function getStartRecordNumber() {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_START_REC];
	}

	function setStartRecordNumber($v) {
		$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_START_REC] = $v;
	}

	// Search highlight name
	function HighlightName() {
		return "CCEExamQuestions_Highlight";
	}

	// Advanced search
	function getAdvancedSearch($fld) {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_ADVANCED_SEARCH . "_" . $fld];
	}

	function setAdvancedSearch($fld, $v) {
		if (@$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_ADVANCED_SEARCH . "_" . $fld] <> $v) {
			$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_ADVANCED_SEARCH . "_" . $fld] = $v;
		}
	}

	// Basic search keyword
	function getSessionBasicSearchKeyword() {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_BASIC_SEARCH];
	}

	function setSessionBasicSearchKeyword($v) {
		$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_BASIC_SEARCH] = $v;
	}

	// Basic search type
	function getSessionBasicSearchType() {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_BASIC_SEARCH_TYPE];
	}

	function setSessionBasicSearchType($v) {
		$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_BASIC_SEARCH_TYPE] = $v;
	}

	// Search WHERE clause
	function getSearchWhere() {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_SEARCH_WHERE];
	}

	function setSearchWhere($v) {
		$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_SEARCH_WHERE] = $v;
	}

	// Multiple column sort
	function UpdateSort(&$ofld, $ctrl) {
		if ($this->CurrentOrder == $ofld->FldName) {
			$sSortField = $ofld->FldExpression;
			$sLastSort = $ofld->getSort();
			if ($this->CurrentOrderType == "ASC" || $this->CurrentOrderType == "DESC") {
				$sThisSort = $this->CurrentOrderType;
			} else {
				$sThisSort = ($sLastSort == "ASC") ? "DESC" : "ASC";
			}
			$ofld->setSort($sThisSort);
			if ($ctrl) {
				$sOrderBy = $this->getSessionOrderBy();
				if (strpos($sOrderBy, $sSortField . " " . $sLastSort) !== FALSE) {
					$sOrderBy = str_replace($sSortField . " " . $sLastSort, $sSortField . " " . $sThisSort, $sOrderBy);
				} else {
					if ($sOrderBy <> "") $sOrderBy .= ", ";
					$sOrderBy .= $sSortField . " " . $sThisSort;
				}
				$this->setSessionOrderBy($sOrderBy); // Save to Session
			} else {
				$this->setSessionOrderBy($sSortField . " " . $sThisSort); // Save to Session
			}
		} else {
			if (!$ctrl) $ofld->setSort("");
		}
	}

	// Session WHERE clause
	function getSessionWhere() {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_WHERE];
	}

	function setSessionWhere($v) {
		$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_WHERE] = $v;
	}

	// Session ORDER BY
	function getSessionOrderBy() {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_ORDER_BY];
	}

	function setSessionOrderBy($v) {
		$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_ORDER_BY] = $v;
	}

	// Session key
	function getKey($fld) {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_KEY . "_" . $fld];
	}

	function setKey($fld, $v) {
		$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_KEY . "_" . $fld] = $v;
	}

	// Table level SQL
	function SqlFrom() { // From
		return "`CCEExamQuestions`";
	}

	function SqlSelect() { // Select
		return "SELECT * FROM " . $this->SqlFrom();
	}

	function SqlWhere() { // Where
		$sWhere = "";
		$this->TableFilter = "";
		if ($this->TableFilter <> "") {
			if ($sWhere <> "") $sWhere = "(" . $sWhere . ") AND (";
			$sWhere .= "(" . $this->TableFilter . ")";
		}
		return $sWhere;
	}

	function SqlGroupBy() { // Group By
		return "";
	}

	function SqlHaving() { // Having
		return "";
	}

	function SqlOrderBy() { // Order By
		return "`Display_Order` ASC";
	}

	// Check if Anonymous User is allowed
	function AllowAnonymousUser() {
		switch (EW_PAGE_ID) {
			case "add":
			case "register":
			case "addopt":
				return FALSE;
			case "edit":
			case "update":
				return FALSE;
			case "delete":
				return FALSE;
			case "view":
				return FALSE;
			case "search":
				return FALSE;
			default:
				return FALSE;
		}
	}

	// Apply User ID filters
	function ApplyUserIDFilters($sFilter) {
		return $sFilter;
	}

	// Get SQL
	function GetSQL($where, $orderby) {
		return ew_BuildSelectSql($this->SqlSelect(), $this->SqlWhere(),
			$this->SqlGroupBy(), $this->SqlHaving(), $this->SqlOrderBy(),
			$where, $orderby);
	}

	// Table SQL
	function SQL() {
		$sFilter = $this->CurrentFilter;
		$sFilter = $this->ApplyUserIDFilters($sFilter);
		$sSort = $this->getSessionOrderBy();
		return ew_BuildSelectSql($this->SqlSelect(), $this->SqlWhere(),
			$this->SqlGroupBy(), $this->SqlHaving(), $this->SqlOrderBy(),
			$sFilter, $sSort);
	}

	// Table SQL with List page filter
	function SelectSQL() {
		$sFilter = $this->getSessionWhere();
		if ($this->CurrentFilter <> "") {
			if ($sFilter <> "") $sFilter = "(" . $sFilter . ") AND ";
			$sFilter .= "(" . $this->CurrentFilter . ")";
		}
		$sFilter = $this->ApplyUserIDFilters($sFilter);
		$sSort = $this->getSessionOrderBy();
		return ew_BuildSelectSql($this->SqlSelect(), $this->SqlWhere(), $this->SqlGroupBy(),
			$this->SqlHaving(), $this->SqlOrderBy(), $sFilter, $sSort);
	}

	// Try to get record count
	function TryGetRecordCount($sSql) {
		global $conn;
		$cnt = -1;
		if ($this->TableType == 'TABLE' || $this->TableType == 'VIEW') {
			$sSql = "SELECT COUNT(*) FROM" . substr($sSql, 13);
		} else {
			$sSql = "SELECT COUNT(*) FROM (" . $sSql . ") EW_COUNT_TABLE";
		}
		if ($rs = $conn->Execute($sSql)) {
			if (!$rs->EOF && $rs->FieldCount() > 0) {
				$cnt = $rs->fields[0];
				$rs->Close();
			}
		}
		return intval($cnt);
	}

	// Get record count based on filter (for detail record count in master table pages)
	function LoadRecordCount($sFilter) {
		$origFilter = $this->CurrentFilter;
		$this->CurrentFilter = $sFilter;
		$this->Recordset_Selecting($this->CurrentFilter);
		$sSql = $this->SQL();
		$cnt = $this->TryGetRecordCount($sSql);
		if ($cnt == -1) {
			if ($rs = $this->LoadRs($this->CurrentFilter)) {
				$cnt = $rs->RecordCount();
				$rs->Close();
			}
		}
		$this->CurrentFilter = $origFilter;
		return intval($cnt);
	}

	// Get record count (for current List page)
	function SelectRecordCount() {
		global $conn;
		$origFilter = $this->CurrentFilter;
		$this->Recordset_Selecting($this->CurrentFilter);
		$sSql = $this->SelectSQL();
		$cnt = $this->TryGetRecordCount($sSql);
		if ($cnt == -1) {
			if ($rs = $conn->Execute($this->SelectSQL())) {
				$cnt = $rs->RecordCount();
				$rs->Close();
			}
		}
		$this->CurrentFilter = $origFilter;
		return intval($cnt);
	}

	// INSERT statement
	function InsertSQL(&$rs) {
		global $conn;
		$names = "";
		$values = "";
		foreach ($rs as $name => $value) {
			$names .= $this->fields[$name]->FldExpression . ",";
			$values .= ew_QuotedValue($value, $this->fields[$name]->FldDataType) . ",";
		}
		if (substr($names, -1) == ",") $names = substr($names, 0, strlen($names)-1);
		if (substr($values, -1) == ",") $values = substr($values, 0, strlen($values)-1);
		return "INSERT INTO `CCEExamQuestions` ($names) VALUES ($values)";
	}

	// UPDATE statement
	function UpdateSQL(&$rs) {
		global $conn;
		$SQL = "UPDATE `CCEExamQuestions` SET ";
		foreach ($rs as $name => $value) {
			$SQL .= $this->fields[$name]->FldExpression . "=";
			$SQL .= ew_QuotedValue($value, $this->fields[$name]->FldDataType) . ",";
		}
		if (substr($SQL, -1) == ",") $SQL = substr($SQL, 0, strlen($SQL)-1);
		if ($this->CurrentFilter <> "")	$SQL .= " WHERE " . $this->CurrentFilter;
		return $SQL;
	}

	// DELETE statement
	function DeleteSQL(&$rs) {
		$SQL = "DELETE FROM `CCEExamQuestions` WHERE ";
		$SQL .= ew_QuotedName('Question_ID') . '=' . ew_QuotedValue($rs['Question_ID'], $this->Question_ID->FldDataType) . ' AND ';
		if (substr($SQL, -5) == " AND ") $SQL = substr($SQL, 0, strlen($SQL)-5);
		if ($this->CurrentFilter <> "")	$SQL .= " AND " . $this->CurrentFilter;
		return $SQL;
	}

	// Key filter WHERE clause
	function SqlKeyFilter() {
		return "`Question_ID` = @Question_ID@";
	}

	// Key filter
	function KeyFilter() {
		$sKeyFilter = $this->SqlKeyFilter();
		if (!is_numeric($this->Question_ID->CurrentValue))
			$sKeyFilter = "0=1"; // Invalid key
		$sKeyFilter = str_replace("@Question_ID@", ew_AdjustSql($this->Question_ID->CurrentValue), $sKeyFilter); // Replace key value
		return $sKeyFilter;
	}

	// Return page URL
	function getReturnUrl() {
		$name = EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_RETURN_URL;

		// Get referer URL automatically
		if (ew_ServerVar("HTTP_REFERER") <> "" && ew_ReferPage() <> ew_CurrentPage() && ew_ReferPage() <> "login.php") // Referer not same page or login page
			$_SESSION[$name] = ew_ServerVar("HTTP_REFERER"); // Save to Session
		if (@$_SESSION[$name] <> "") {
			return $_SESSION[$name];
		} else {
			return "CCEExamQuestionslist.php";
		}
	}

	function setReturnUrl($v) {
		$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_RETURN_URL] = $v;
	}

	// List URL
	function ListUrl() {
		return "CCEExamQuestionslist.php";
	}

	// View URL
	function ViewUrl() {
		return $this->KeyUrl("CCEExamQuestionsview.php", $this->UrlParm());
	}

	// Add URL
	function AddUrl() {
		$AddUrl = "CCEExamQuestionsadd.php";
		$sUrlParm = $this->UrlParm();
		if ($sUrlParm <> "")
			$AddUrl .= "?" . $sUrlParm;
		return $AddUrl;
	}

	// Edit URL
	function EditUrl() {
		return $this->KeyUrl("CCEExamQuestionsedit.php", $this->UrlParm());
	}

	// Inline edit URL
	function InlineEditUrl() {
		return $this->KeyUrl(ew_CurrentPage(), $this->UrlParm("a=edit"));
	}

	// Copy URL
	function CopyUrl() {
		return $this->KeyUrl("CCEExamQuestionsadd.php", $this->UrlParm());
	}

	// Inline copy URL
	function InlineCopyUrl() {
		return $this->KeyUrl(ew_CurrentPage(), $this->UrlParm("a=copy"));
	}

	// Delete URL
	function DeleteUrl() {
		return $this->KeyUrl("CCEExamQuestionsdelete.php", $this->UrlParm());
	}

	// Add key value to URL
	function KeyUrl($url, $parm = "") {
		$sUrl = $url . "?";
		if ($parm <> "") $sUrl .= $parm . "&";
		if (!is_null($this->Question_ID->CurrentValue)) {
			$sUrl .= "Question_ID=" . urlencode($this->Question_ID->CurrentValue);
		} else {
			return "javascript:alert(ewLanguage.Phrase(\"InvalidRecord\"));";
		}
		return $sUrl;
	}

	// Sort URL
	function SortUrl(&$fld) {
		if ($this->CurrentAction <> "" || $this->Export <> "" ||
			in_array($fld->FldType, array(128, 204, 205))) { // Unsortable data type
				return "";
		} elseif ($fld->Sortable) {
			$sUrlParm = $this->UrlParm("order=" . urlencode($fld->FldName) . "&ordertype=" . $fld->ReverseSort());
			return ew_CurrentPage() . "?" . $sUrlParm;
		} else {
			return "";
		}
	}

	// Add URL parameter
	function UrlParm($parm = "") {
		$UrlParm = ($this->UseTokenInUrl) ? "t=CCEExamQuestions" : "";
		if ($parm <> "") {
			if ($UrlParm <> "")
				$UrlParm .= "&";
			$UrlParm .= $parm;
		}
		return $UrlParm;
	}

	// Load rows based on filter
	function &LoadRs($sFilter) {
		global $conn;

		// Set up filter (SQL WHERE clause) and get return SQL
		$this->CurrentFilter = $sFilter;
		$sSql = $this->SQL();
		return $conn->Execute($sSql);
	}

	// Load row values from recordset
	function LoadListRowValues(&$rs) {
		$this->Question_ID->setDbValue($rs->fields('Question_ID'));
		$this->Questionnaire_ID->setDbValue($rs->fields('Questionnaire_ID'));
		$this->Section_ID->setDbValue($rs->fields('Section_ID'));
		$this->Question->setDbValue($rs->fields('Question'));
		$this->Display_Order->setDbValue($rs->fields('Display_Order'));
		$this->IsMulti->setDbValue($rs->fields('IsMulti'));
		$this->IsOptional->setDbValue($rs->fields('IsOptional'));
		$this->Answer_Type->setDbValue($rs->fields('Answer_Type'));
		$this->Answer_Template->setDbValue($rs->fields('Answer_Template'));
		$this->Model_Answer->setDbValue($rs->fields('Model_Answer'));
		$this->ParentQuestionID->setDbValue($rs->fields('ParentQuestionID'));
		$this->RequireNumber->setDbValue($rs->fields('RequireNumber'));
		$this->MinNum->setDbValue($rs->fields('MinNum'));
		$this->MaxNum->setDbValue($rs->fields('MaxNum'));
		$this->RecallPrevAnswer->setDbValue($rs->fields('RecallPrevAnswer'));
		$this->QuestionTitle->setDbValue($rs->fields('QuestionTitle'));
		$this->NumMarks->setDbValue($rs->fields('NumMarks'));
		$this->DropDown->setDbValue($rs->fields('DropDown'));
		$this->InUse->setDbValue($rs->fields('InUse'));
	}

	// Render list row values
	function RenderListRow() {
		global $conn, $Security;

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

   // Common render codes
		// Question_ID

		$this->Question_ID->CellCssStyle = ""; $this->Question_ID->CellCssClass = "";
		$this->Question_ID->CellAttrs = array(); $this->Question_ID->ViewAttrs = array(); $this->Question_ID->EditAttrs = array();

		// Questionnaire_ID
		$this->Questionnaire_ID->CellCssStyle = ""; $this->Questionnaire_ID->CellCssClass = "";
		$this->Questionnaire_ID->CellAttrs = array(); $this->Questionnaire_ID->ViewAttrs = array(); $this->Questionnaire_ID->EditAttrs = array();

		// Section_ID
		$this->Section_ID->CellCssStyle = ""; $this->Section_ID->CellCssClass = "";
		$this->Section_ID->CellAttrs = array(); $this->Section_ID->ViewAttrs = array(); $this->Section_ID->EditAttrs = array();

		// Question
		$this->Question->CellCssStyle = ""; $this->Question->CellCssClass = "";
		$this->Question->CellAttrs = array(); $this->Question->ViewAttrs = array(); $this->Question->EditAttrs = array();

		// Display_Order
		$this->Display_Order->CellCssStyle = ""; $this->Display_Order->CellCssClass = "";
		$this->Display_Order->CellAttrs = array(); $this->Display_Order->ViewAttrs = array(); $this->Display_Order->EditAttrs = array();

		// IsMulti
		$this->IsMulti->CellCssStyle = ""; $this->IsMulti->CellCssClass = "";
		$this->IsMulti->CellAttrs = array(); $this->IsMulti->ViewAttrs = array(); $this->IsMulti->EditAttrs = array();

		// IsOptional
		$this->IsOptional->CellCssStyle = ""; $this->IsOptional->CellCssClass = "";
		$this->IsOptional->CellAttrs = array(); $this->IsOptional->ViewAttrs = array(); $this->IsOptional->EditAttrs = array();

		// Answer_Type
		$this->Answer_Type->CellCssStyle = ""; $this->Answer_Type->CellCssClass = "";
		$this->Answer_Type->CellAttrs = array(); $this->Answer_Type->ViewAttrs = array(); $this->Answer_Type->EditAttrs = array();

		// Answer_Template
		$this->Answer_Template->CellCssStyle = ""; $this->Answer_Template->CellCssClass = "";
		$this->Answer_Template->CellAttrs = array(); $this->Answer_Template->ViewAttrs = array(); $this->Answer_Template->EditAttrs = array();

		// Model_Answer
		$this->Model_Answer->CellCssStyle = ""; $this->Model_Answer->CellCssClass = "";
		$this->Model_Answer->CellAttrs = array(); $this->Model_Answer->ViewAttrs = array(); $this->Model_Answer->EditAttrs = array();

		// ParentQuestionID
		$this->ParentQuestionID->CellCssStyle = ""; $this->ParentQuestionID->CellCssClass = "";
		$this->ParentQuestionID->CellAttrs = array(); $this->ParentQuestionID->ViewAttrs = array(); $this->ParentQuestionID->EditAttrs = array();

		// RequireNumber
		$this->RequireNumber->CellCssStyle = ""; $this->RequireNumber->CellCssClass = "";
		$this->RequireNumber->CellAttrs = array(); $this->RequireNumber->ViewAttrs = array(); $this->RequireNumber->EditAttrs = array();

		// MinNum
		$this->MinNum->CellCssStyle = ""; $this->MinNum->CellCssClass = "";
		$this->MinNum->CellAttrs = array(); $this->MinNum->ViewAttrs = array(); $this->MinNum->EditAttrs = array();

		// MaxNum
		$this->MaxNum->CellCssStyle = ""; $this->MaxNum->CellCssClass = "";
		$this->MaxNum->CellAttrs = array(); $this->MaxNum->ViewAttrs = array(); $this->MaxNum->EditAttrs = array();

		// RecallPrevAnswer
		$this->RecallPrevAnswer->CellCssStyle = ""; $this->RecallPrevAnswer->CellCssClass = "";
		$this->RecallPrevAnswer->CellAttrs = array(); $this->RecallPrevAnswer->ViewAttrs = array(); $this->RecallPrevAnswer->EditAttrs = array();

		// QuestionTitle
		$this->QuestionTitle->CellCssStyle = ""; $this->QuestionTitle->CellCssClass = "";
		$this->QuestionTitle->CellAttrs = array(); $this->QuestionTitle->ViewAttrs = array(); $this->QuestionTitle->EditAttrs = array();

		// NumMarks
		$this->NumMarks->CellCssStyle = ""; $this->NumMarks->CellCssClass = "";
		$this->NumMarks->CellAttrs = array(); $this->NumMarks->ViewAttrs = array(); $this->NumMarks->EditAttrs = array();

		// InUse
		$this->InUse->CellCssStyle = ""; $this->InUse->CellCssClass = "";
		$this->InUse->CellAttrs = array(); $this->InUse->ViewAttrs = array(); $this->InUse->EditAttrs = array();

		// Question_ID
		$this->Question_ID->ViewValue = $this->Question_ID->CurrentValue;
		$this->Question_ID->CssStyle = "";
		$this->Question_ID->CssClass = "";
		$this->Question_ID->ViewCustomAttributes = "";

		// Questionnaire_ID
		if (strval($this->Questionnaire_ID->CurrentValue) <> "") {
			$sFilterWrk = "`Questionnaire_ID` = " . ew_AdjustSql($this->Questionnaire_ID->CurrentValue) . "";
		$sSqlWrk = "SELECT `Questionnaire_Name` FROM `CCEExams`";
		$sWhereWrk = "";
		if ($sFilterWrk <> "") {
			if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
			$sWhereWrk .= "(" . $sFilterWrk . ")";
		}
		if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			if ($rswrk && !$rswrk->EOF) { // Lookup values found
				$this->Questionnaire_ID->ViewValue = $rswrk->fields('Questionnaire_Name');
				$rswrk->Close();
			} else {
				$this->Questionnaire_ID->ViewValue = $this->Questionnaire_ID->CurrentValue;
			}
		} else {
			$this->Questionnaire_ID->ViewValue = NULL;
		}
		$this->Questionnaire_ID->CssStyle = "";
		$this->Questionnaire_ID->CssClass = "";
		$this->Questionnaire_ID->ViewCustomAttributes = "";

		// Section_ID
		if (strval($this->Section_ID->CurrentValue) <> "") {
			$sFilterWrk = "`Section_ID` = " . ew_AdjustSql($this->Section_ID->CurrentValue) . "";
		$sSqlWrk = "SELECT `Section_Name` FROM `CCEExamSections`";
		$sWhereWrk = "";
		if ($sFilterWrk <> "") {
			if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
			$sWhereWrk .= "(" . $sFilterWrk . ")";
		}
		if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
		$sSqlWrk .= " ORDER BY `Display_Order` Asc";
			$rswrk = $conn->Execute($sSqlWrk);
			if ($rswrk && !$rswrk->EOF) { // Lookup values found
				$this->Section_ID->ViewValue = $rswrk->fields('Section_Name');
				$rswrk->Close();
			} else {
				$this->Section_ID->ViewValue = $this->Section_ID->CurrentValue;
			}
		} else {
			$this->Section_ID->ViewValue = NULL;
		}
		$this->Section_ID->CssStyle = "";
		$this->Section_ID->CssClass = "";
		$this->Section_ID->ViewCustomAttributes = "";

		// Question
		$this->Question->ViewValue = $this->Question->CurrentValue;
		$this->Question->CssStyle = "";
		$this->Question->CssClass = "";
		$this->Question->ViewCustomAttributes = "";

		// Display_Order
		$this->Display_Order->ViewValue = $this->Display_Order->CurrentValue;
		$this->Display_Order->CssStyle = "";
		$this->Display_Order->CssClass = "";
		$this->Display_Order->ViewCustomAttributes = "";

		// IsMulti
		if (strval($this->IsMulti->CurrentValue) <> "") {
			switch ($this->IsMulti->CurrentValue) {
				case "1":
					$this->IsMulti->ViewValue = "Yes";
					break;
				case "0":
					$this->IsMulti->ViewValue = "No";
					break;
				default:
					$this->IsMulti->ViewValue = $this->IsMulti->CurrentValue;
			}
		} else {
			$this->IsMulti->ViewValue = NULL;
		}
		$this->IsMulti->CssStyle = "";
		$this->IsMulti->CssClass = "";
		$this->IsMulti->ViewCustomAttributes = "";

		// IsOptional
		if (strval($this->IsOptional->CurrentValue) <> "") {
			switch ($this->IsOptional->CurrentValue) {
				case "1":
					$this->IsOptional->ViewValue = "Yes";
					break;
				case "0":
					$this->IsOptional->ViewValue = "No";
					break;
				default:
					$this->IsOptional->ViewValue = $this->IsOptional->CurrentValue;
			}
		} else {
			$this->IsOptional->ViewValue = NULL;
		}
		$this->IsOptional->CssStyle = "";
		$this->IsOptional->CssClass = "";
		$this->IsOptional->ViewCustomAttributes = "";

		// Answer_Type
		if (strval($this->Answer_Type->CurrentValue) <> "") {
			switch ($this->Answer_Type->CurrentValue) {
				case "a":
					$this->Answer_Type->ViewValue = "Text Box";
					break;
				case "m":
					$this->Answer_Type->ViewValue = "Radio/ Check Box";
					break;
				case "s":
					$this->Answer_Type->ViewValue = "Select";
					break;
				case "f":
					$this->Answer_Type->ViewValue = "File";
					break;
				default:
					$this->Answer_Type->ViewValue = $this->Answer_Type->CurrentValue;
			}
		} else {
			$this->Answer_Type->ViewValue = NULL;
		}
		$this->Answer_Type->CssStyle = "";
		$this->Answer_Type->CssClass = "";
		$this->Answer_Type->ViewCustomAttributes = "";

		// Answer_Template
		$this->Answer_Template->ViewValue = $this->Answer_Template->CurrentValue;
		$this->Answer_Template->CssStyle = "";
		$this->Answer_Template->CssClass = "";
		$this->Answer_Template->ViewCustomAttributes = "";

		// Model_Answer
		$this->Model_Answer->ViewValue = $this->Model_Answer->CurrentValue;
		$this->Model_Answer->CssStyle = "";
		$this->Model_Answer->CssClass = "";
		$this->Model_Answer->ViewCustomAttributes = "";

		// ParentQuestionID
		if (strval($this->ParentQuestionID->CurrentValue) <> "") {
			$sFilterWrk = "`Question_ID` = " . ew_AdjustSql($this->ParentQuestionID->CurrentValue) . "";
		$sSqlWrk = "SELECT `QuestionTitle`, `Question` FROM `CCEExamQuestions`";
		$sWhereWrk = "";
		if ($sFilterWrk <> "") {
			if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
			$sWhereWrk .= "(" . $sFilterWrk . ")";
		}
		if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
		$sSqlWrk .= " ORDER BY `Display_Order`";
			$rswrk = $conn->Execute($sSqlWrk);
			if ($rswrk && !$rswrk->EOF) { // Lookup values found
				$this->ParentQuestionID->ViewValue = $rswrk->fields('QuestionTitle');
				$this->ParentQuestionID->ViewValue .= ew_ValueSeparator(0) . $rswrk->fields('Question');
				$rswrk->Close();
			} else {
				$this->ParentQuestionID->ViewValue = $this->ParentQuestionID->CurrentValue;
			}
		} else {
			$this->ParentQuestionID->ViewValue = NULL;
		}
		$this->ParentQuestionID->CssStyle = "";
		$this->ParentQuestionID->CssClass = "";
		$this->ParentQuestionID->ViewCustomAttributes = "";

		// RequireNumber
		$this->RequireNumber->ViewValue = $this->RequireNumber->CurrentValue;
		$this->RequireNumber->CssStyle = "";
		$this->RequireNumber->CssClass = "";
		$this->RequireNumber->ViewCustomAttributes = "";

		// MinNum
		$this->MinNum->ViewValue = $this->MinNum->CurrentValue;
		$this->MinNum->CssStyle = "";
		$this->MinNum->CssClass = "";
		$this->MinNum->ViewCustomAttributes = "";

		// MaxNum
		$this->MaxNum->ViewValue = $this->MaxNum->CurrentValue;
		$this->MaxNum->CssStyle = "";
		$this->MaxNum->CssClass = "";
		$this->MaxNum->ViewCustomAttributes = "";

		// RecallPrevAnswer
		if (strval($this->RecallPrevAnswer->CurrentValue) <> "") {
			switch ($this->RecallPrevAnswer->CurrentValue) {
				case "1":
					$this->RecallPrevAnswer->ViewValue = "Yes";
					break;
				case "0":
					$this->RecallPrevAnswer->ViewValue = "No";
					break;
				default:
					$this->RecallPrevAnswer->ViewValue = $this->RecallPrevAnswer->CurrentValue;
			}
		} else {
			$this->RecallPrevAnswer->ViewValue = NULL;
		}
		$this->RecallPrevAnswer->CssStyle = "";
		$this->RecallPrevAnswer->CssClass = "";
		$this->RecallPrevAnswer->ViewCustomAttributes = "";

		// QuestionTitle
		$this->QuestionTitle->ViewValue = $this->QuestionTitle->CurrentValue;
		$this->QuestionTitle->CssStyle = "";
		$this->QuestionTitle->CssClass = "";
		$this->QuestionTitle->ViewCustomAttributes = "";

		// NumMarks
		$this->NumMarks->ViewValue = $this->NumMarks->CurrentValue;
		$this->NumMarks->CssStyle = "";
		$this->NumMarks->CssClass = "";
		$this->NumMarks->ViewCustomAttributes = "";

		// InUse
		if (strval($this->InUse->CurrentValue) <> "") {
			switch (strval($this->InUse->CurrentValue)) {
				case "1":
					$this->InUse->ViewValue = "Yes";
					break;
				case "0":
					$this->InUse->ViewValue = "No";
					break;
				default:
					$this->InUse->ViewValue = $this->InUse->CurrentValue;
			}
		} else {
			$this->InUse->ViewValue = "No";
		}
		$this->InUse->CssStyle = "";
		$this->InUse->CssClass = "";
		$this->InUse->ViewCustomAttributes = "";

		// Question_ID
		$this->Question_ID->HrefValue = "";
		$this->Question_ID->TooltipValue = "";

		// Questionnaire_ID
		$this->Questionnaire_ID->HrefValue = "";
		$this->Questionnaire_ID->TooltipValue = "";

		// Section_ID
		$this->Section_ID->HrefValue = "";
		$this->Section_ID->TooltipValue = "";

		// Question
		$this->Question->HrefValue = "";
		$this->Question->TooltipValue = "";

		// Display_Order
		$this->Display_Order->HrefValue = "";
		$this->Display_Order->TooltipValue = "";

		// IsMulti
		$this->IsMulti->HrefValue = "";
		$this->IsMulti->TooltipValue = "";

		// IsOptional
		$this->IsOptional->HrefValue = "";
		$this->IsOptional->TooltipValue = "";

		// Answer_Type
		$this->Answer_Type->HrefValue = "";
		$this->Answer_Type->TooltipValue = "";

		// Answer_Template
		$this->Answer_Template->HrefValue = "";
		$this->Answer_Template->TooltipValue = "";

		// Model_Answer
		$this->Model_Answer->HrefValue = "";
		$this->Model_Answer->TooltipValue = "";

		// ParentQuestionID
		$this->ParentQuestionID->HrefValue = "";
		$this->ParentQuestionID->TooltipValue = "";

		// RequireNumber
		$this->RequireNumber->HrefValue = "";
		$this->RequireNumber->TooltipValue = "";

		// MinNum
		$this->MinNum->HrefValue = "";
		$this->MinNum->TooltipValue = "";

		// MaxNum
		$this->MaxNum->HrefValue = "";
		$this->MaxNum->TooltipValue = "";

		// RecallPrevAnswer
		$this->RecallPrevAnswer->HrefValue = "";
		$this->RecallPrevAnswer->TooltipValue = "";

		// QuestionTitle
		$this->QuestionTitle->HrefValue = "";
		$this->QuestionTitle->TooltipValue = "";

		// NumMarks
		$this->NumMarks->HrefValue = "";
		$this->NumMarks->TooltipValue = "";

		// InUse
		$this->InUse->HrefValue = "";
		$this->InUse->TooltipValue = "";

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

	// Aggregate list row values
	function AggregateListRowValues() {
	}

	// Aggregate list row (for rendering)
	function AggregateListRow() {
	}

	// Row styles
	function RowStyles() {
		$sAtt = "";
		$sStyle = trim($this->CssStyle);
		if (@$this->RowAttrs["style"] <> "")
			$sStyle .= " " . $this->RowAttrs["style"];
		$sClass = trim($this->CssClass);
		if (@$this->RowAttrs["class"] <> "")
			$sClass .= " " . $this->RowAttrs["class"];
		if (trim($sStyle) <> "")
			$sAtt .= " style=\"" . trim($sStyle) . "\"";
		if (trim($sClass) <> "")
			$sAtt .= " class=\"" . trim($sClass) . "\"";
		return $sAtt;
	}

	// Row attributes
	function RowAttributes() {
		$sAtt = $this->RowStyles();
		if ($this->Export == "") {
			foreach ($this->RowAttrs as $k => $v) {
				if ($k <> "class" && $k <> "style" && trim($v) <> "")
					$sAtt .= " " . $k . "=\"" . trim($v) . "\"";
			}
		}
		return $sAtt;
	}

	// Field object by name
	function fields($fldname) {
		return $this->fields[$fldname];
	}

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

	}

	// Row Inserting event
	function Row_Inserting(&$rs) {

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

		return TRUE;
	}

	// Row Inserted event
	function Row_Inserted(&$rs) {

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

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