Your IP : 216.73.217.79


Current Path : /var/www/cesa.co.za/cpdadmin/
Upload File :
Current File : /var/www/cesa.co.za/cpdadmin/CPDTMReviewinfo.php

<?php

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

//
// Table class for CPDTMReview
//
class cCPDTMReview {
	var $TableVar = 'CPDTMReview';
	var $TableName = 'CPDTMReview';
	var $TableType = 'TABLE';
	var $CPDTMReviewID;
	var $ProviderID;
	var $MaterialID;
	var $CPDAssessorID;
	var $DateReviewed;
	var $Q1Knowledge;
	var $Q2Learning;
	var $Q3Depth;
	var $Q4EvalForm;
	var $Q5Objectives;
	var $Q6Outcomes;
	var $Q7Presentation;
	var $Q8Benefit;
	var $FinalStatus;
	var $ChangesRequired;
	var $NotionalHours;
	var $CPDCredits;
	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;

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

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

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

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

		// DateReviewed
		$this->DateReviewed = new cField('CPDTMReview', 'CPDTMReview', 'x_DateReviewed', 'DateReviewed', '`DateReviewed`', 133, 5, FALSE, '`DateReviewed`', FALSE);
		$this->DateReviewed->FldDefaultErrMsg = str_replace("%s", "/", $Language->Phrase("IncorrectDateYMD"));
		$this->fields['DateReviewed'] =& $this->DateReviewed;

		// Q1Knowledge
		$this->Q1Knowledge = new cField('CPDTMReview', 'CPDTMReview', 'x_Q1Knowledge', 'Q1Knowledge', '`Q1Knowledge`', 200, -1, FALSE, '`Q1Knowledge`', FALSE);
		$this->fields['Q1Knowledge'] =& $this->Q1Knowledge;

		// Q2Learning
		$this->Q2Learning = new cField('CPDTMReview', 'CPDTMReview', 'x_Q2Learning', 'Q2Learning', '`Q2Learning`', 200, -1, FALSE, '`Q2Learning`', FALSE);
		$this->fields['Q2Learning'] =& $this->Q2Learning;

		// Q3Depth
		$this->Q3Depth = new cField('CPDTMReview', 'CPDTMReview', 'x_Q3Depth', 'Q3Depth', '`Q3Depth`', 200, -1, FALSE, '`Q3Depth`', FALSE);
		$this->fields['Q3Depth'] =& $this->Q3Depth;

		// Q4EvalForm
		$this->Q4EvalForm = new cField('CPDTMReview', 'CPDTMReview', 'x_Q4EvalForm', 'Q4EvalForm', '`Q4EvalForm`', 200, -1, FALSE, '`Q4EvalForm`', FALSE);
		$this->fields['Q4EvalForm'] =& $this->Q4EvalForm;

		// Q5Objectives
		$this->Q5Objectives = new cField('CPDTMReview', 'CPDTMReview', 'x_Q5Objectives', 'Q5Objectives', '`Q5Objectives`', 200, -1, FALSE, '`Q5Objectives`', FALSE);
		$this->fields['Q5Objectives'] =& $this->Q5Objectives;

		// Q6Outcomes
		$this->Q6Outcomes = new cField('CPDTMReview', 'CPDTMReview', 'x_Q6Outcomes', 'Q6Outcomes', '`Q6Outcomes`', 200, -1, FALSE, '`Q6Outcomes`', FALSE);
		$this->fields['Q6Outcomes'] =& $this->Q6Outcomes;

		// Q7Presentation
		$this->Q7Presentation = new cField('CPDTMReview', 'CPDTMReview', 'x_Q7Presentation', 'Q7Presentation', '`Q7Presentation`', 200, -1, FALSE, '`Q7Presentation`', FALSE);
		$this->fields['Q7Presentation'] =& $this->Q7Presentation;

		// Q8Benefit
		$this->Q8Benefit = new cField('CPDTMReview', 'CPDTMReview', 'x_Q8Benefit', 'Q8Benefit', '`Q8Benefit`', 200, -1, FALSE, '`Q8Benefit`', FALSE);
		$this->fields['Q8Benefit'] =& $this->Q8Benefit;

		// FinalStatus
		$this->FinalStatus = new cField('CPDTMReview', 'CPDTMReview', 'x_FinalStatus', 'FinalStatus', '`FinalStatus`', 200, -1, FALSE, '`FinalStatus`', FALSE);
		$this->fields['FinalStatus'] =& $this->FinalStatus;

		// ChangesRequired
		$this->ChangesRequired = new cField('CPDTMReview', 'CPDTMReview', 'x_ChangesRequired', 'ChangesRequired', '`ChangesRequired`', 201, -1, FALSE, '`ChangesRequired`', FALSE);
		$this->fields['ChangesRequired'] =& $this->ChangesRequired;

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

		// CPDCredits
		$this->CPDCredits = new cField('CPDTMReview', 'CPDTMReview', 'x_CPDCredits', 'CPDCredits', '`CPDCredits`', 3, -1, FALSE, '`CPDCredits`', FALSE);
		$this->CPDCredits->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['CPDCredits'] =& $this->CPDCredits;
	}

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

	// Current master table name
	function getCurrentMasterTable() {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_MASTER_TABLE];
	}

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

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

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

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

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

	// Master filter
	function SqlMasterFilter_CPDTrainingMaterial() {
		return "`MaterialID`=@MaterialID@";
	}

	// Detail filter
	function SqlDetailFilter_CPDTrainingMaterial() {
		return "`MaterialID`=@MaterialID@";
	}

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

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

	function SqlWhere() { // Where
		$sWhere = "";
		$this->TableFilter = CPDFilterTMReviews();
		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 "`DateReviewed` DESC";
	}

	// 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 `CPDTMReview` ($names) VALUES ($values)";
	}

	// UPDATE statement
	function UpdateSQL(&$rs) {
		global $conn;
		$SQL = "UPDATE `CPDTMReview` 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 `CPDTMReview` WHERE ";
		$SQL .= ew_QuotedName('CPDTMReviewID') . '=' . ew_QuotedValue($rs['CPDTMReviewID'], $this->CPDTMReviewID->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 "`CPDTMReviewID` = @CPDTMReviewID@";
	}

	// Key filter
	function KeyFilter() {
		$sKeyFilter = $this->SqlKeyFilter();
		if (!is_numeric($this->CPDTMReviewID->CurrentValue))
			$sKeyFilter = "0=1"; // Invalid key
		$sKeyFilter = str_replace("@CPDTMReviewID@", ew_AdjustSql($this->CPDTMReviewID->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 "CPDTMReviewlist.php";
		}
	}

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

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

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

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

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

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

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

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

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

	// Add key value to URL
	function KeyUrl($url, $parm = "") {
		$sUrl = $url . "?";
		if ($parm <> "") $sUrl .= $parm . "&";
		if (!is_null($this->CPDTMReviewID->CurrentValue)) {
			$sUrl .= "CPDTMReviewID=" . urlencode($this->CPDTMReviewID->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=CPDTMReview" : "";
		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->CPDTMReviewID->setDbValue($rs->fields('CPDTMReviewID'));
		$this->ProviderID->setDbValue($rs->fields('ProviderID'));
		$this->MaterialID->setDbValue($rs->fields('MaterialID'));
		$this->CPDAssessorID->setDbValue($rs->fields('CPDAssessorID'));
		$this->DateReviewed->setDbValue($rs->fields('DateReviewed'));
		$this->Q1Knowledge->setDbValue($rs->fields('Q1Knowledge'));
		$this->Q2Learning->setDbValue($rs->fields('Q2Learning'));
		$this->Q3Depth->setDbValue($rs->fields('Q3Depth'));
		$this->Q4EvalForm->setDbValue($rs->fields('Q4EvalForm'));
		$this->Q5Objectives->setDbValue($rs->fields('Q5Objectives'));
		$this->Q6Outcomes->setDbValue($rs->fields('Q6Outcomes'));
		$this->Q7Presentation->setDbValue($rs->fields('Q7Presentation'));
		$this->Q8Benefit->setDbValue($rs->fields('Q8Benefit'));
		$this->FinalStatus->setDbValue($rs->fields('FinalStatus'));
		$this->ChangesRequired->setDbValue($rs->fields('ChangesRequired'));
		$this->NotionalHours->setDbValue($rs->fields('NotionalHours'));
		$this->CPDCredits->setDbValue($rs->fields('CPDCredits'));
	}

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

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

   // Common render codes
		// ProviderID

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

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

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

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

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

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

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

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

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

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

		// DateReviewed
		$this->DateReviewed->ViewValue = $this->DateReviewed->CurrentValue;
		$this->DateReviewed->ViewValue = ew_FormatDateTime($this->DateReviewed->ViewValue, 5);
		$this->DateReviewed->CssStyle = "";
		$this->DateReviewed->CssClass = "";
		$this->DateReviewed->ViewCustomAttributes = "";

		// FinalStatus
		if (strval($this->FinalStatus->CurrentValue) <> "") {
			switch ($this->FinalStatus->CurrentValue) {
				case "a":
					$this->FinalStatus->ViewValue = "Approved";
					break;
				case "d":
					$this->FinalStatus->ViewValue = "Declined";
					break;
				case "c":
					$this->FinalStatus->ViewValue = "Approved Pending Changes";
					break;
				default:
					$this->FinalStatus->ViewValue = $this->FinalStatus->CurrentValue;
			}
		} else {
			$this->FinalStatus->ViewValue = NULL;
		}
		$this->FinalStatus->CssStyle = "";
		$this->FinalStatus->CssClass = "";
		$this->FinalStatus->ViewCustomAttributes = "";

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

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

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

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

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

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

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

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

		// CPDCredits
		$this->CPDCredits->HrefValue = "";
		$this->CPDCredits->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"     
    global $conni;
    CPDTMReview_Inserted($rs);
}      

	// 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";  
    // Same process as the Inserted event
    // if status changes from Declined to Approved  
    global $conni;
    CPDTMReview_Updated($rsold,$rsnew);
}

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