Your IP : 216.73.217.79


Current Path : /var/www/cesa.co.za/ccmadmin/
Upload File :
Current File : /var/www/cesa.co.za/ccmadmin/CCMMessagesedit.php

<?php
session_start(); // Initialize Session data
ob_start(); // Turn on output buffering
?>
<?php include "ewcfg7.php" ?>
<?php include "ewmysql7.php" ?>
<?php include "phpfn7.php" ?>
<?php include "CCMMessagesinfo.php" ?>
<?php include "CCMUsersinfo.php" ?>
<?php include "userfn7.php" ?>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
<?php

// Create page object
$CCMMessages_edit = new cCCMMessages_edit();
$Page =& $CCMMessages_edit;

// Page init
$CCMMessages_edit->Page_Init();

// Page main
$CCMMessages_edit->Page_Main();
?>
<?php include "header.php" ?>
<script type="text/javascript">
<!--

// Create page object
var CCMMessages_edit = new ew_Page("CCMMessages_edit");

// page properties
CCMMessages_edit.PageID = "edit"; // page ID
CCMMessages_edit.FormID = "fCCMMessagesedit"; // form ID
var EW_PAGE_ID = CCMMessages_edit.PageID; // for backward compatibility

// extend page with ValidateForm function
CCMMessages_edit.ValidateForm = function(fobj) {
	ew_PostAutoSuggest(fobj);
	if (!this.ValidateRequired)
		return true; // ignore validation
	if (fobj.a_confirm && fobj.a_confirm.value == "F")
		return true;
	var i, elm, aelm, infix;
	var rowcnt = (fobj.key_count) ? Number(fobj.key_count.value) : 1;
	for (i=0; i<rowcnt; i++) {
		infix = (fobj.key_count) ? String(i+1) : "";
		elm = fobj.elements["x" + infix + "_SentDateTime"];
		if (elm && !ew_CheckDate(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($CCMMessages->SentDateTime->FldErrMsg()) ?>");
		elm = fobj.elements["x" + infix + "_SentByStudentID"];
		if (elm && !ew_CheckInteger(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($CCMMessages->SentByStudentID->FldErrMsg()) ?>");
		elm = fobj.elements["x" + infix + "_SentByFacilitatorID"];
		if (elm && !ew_CheckInteger(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($CCMMessages->SentByFacilitatorID->FldErrMsg()) ?>");
		elm = fobj.elements["x" + infix + "_MessageFile"];
		if (elm && !ew_CheckFileType(elm.value))
			return ew_OnError(this, elm, ewLanguage.Phrase("WrongFileType"));

		// Call Form Custom Validate event
		if (!this.Form_CustomValidate(fobj)) return false;
	}
	return true;
}

// extend page with Form_CustomValidate function
CCMMessages_edit.Form_CustomValidate =  
 function(fobj) { // DO NOT CHANGE THIS LINE!

 	// Your custom validation code here, return false if invalid. 
 	return true;
 }
<?php if (EW_CLIENT_VALIDATE) { ?>
CCMMessages_edit.ValidateRequired = true; // uses JavaScript validation
<?php } else { ?>
CCMMessages_edit.ValidateRequired = false; // no JavaScript validation
<?php } ?>

//-->
</script>
<link rel="stylesheet" type="text/css" media="all" href="calendar/calendar-win2k-cold-1.css" title="win2k-1">
<script type="text/javascript" src="calendar/calendar.js"></script>
<script type="text/javascript" src="calendar/lang/calendar-en.js"></script>
<script type="text/javascript" src="calendar/calendar-setup.js"></script>
<script type="text/javascript">
<!--
var ew_DHTMLEditors = [];

//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--

// Write your client script here, no need to add script tags.
// To include another .js script, use:
// ew_ClientScriptInclude("my_javascript.js"); 
//-->

</script>
<p><span class="phpmaker"><?php echo $Language->Phrase("Edit") ?>&nbsp;<?php echo $Language->Phrase("TblTypeTABLE") ?><?php echo $CCMMessages->TableCaption() ?><br><br>
<a href="<?php echo $CCMMessages->getReturnUrl() ?>"><?php echo $Language->Phrase("GoBack") ?></a></span></p>
<?php
if (EW_DEBUG_ENABLED)
	echo ew_DebugMsg();
$CCMMessages_edit->ShowMessage();
?>
<form name="fCCMMessagesedit" id="fCCMMessagesedit" action="<?php echo ew_CurrentPage() ?>" method="post" enctype="multipart/form-data" onsubmit="return CCMMessages_edit.ValidateForm(this);">
<p>
<input type="hidden" name="a_table" id="a_table" value="CCMMessages">
<input type="hidden" name="a_edit" id="a_edit" value="U">
<table cellspacing="0" class="ewGrid"><tr><td class="ewGridContent">
<div class="ewGridMiddlePanel">
<table cellspacing="0" class="ewTable">
<?php if ($CCMMessages->CCMMessageID->Visible) { // CCMMessageID ?>
	<tr<?php echo $CCMMessages->CCMMessageID->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $CCMMessages->CCMMessageID->FldCaption() ?></td>
		<td<?php echo $CCMMessages->CCMMessageID->CellAttributes() ?>><span id="el_CCMMessageID">
<div<?php echo $CCMMessages->CCMMessageID->ViewAttributes() ?>><?php echo $CCMMessages->CCMMessageID->EditValue ?></div><input type="hidden" name="x_CCMMessageID" id="x_CCMMessageID" value="<?php echo ew_HtmlEncode($CCMMessages->CCMMessageID->CurrentValue) ?>">
</span><?php echo $CCMMessages->CCMMessageID->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($CCMMessages->SentDateTime->Visible) { // SentDateTime ?>
	<tr<?php echo $CCMMessages->SentDateTime->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $CCMMessages->SentDateTime->FldCaption() ?></td>
		<td<?php echo $CCMMessages->SentDateTime->CellAttributes() ?>><span id="el_SentDateTime">
<input type="text" name="x_SentDateTime" id="x_SentDateTime" title="<?php echo $CCMMessages->SentDateTime->FldTitle() ?>" value="<?php echo $CCMMessages->SentDateTime->EditValue ?>"<?php echo $CCMMessages->SentDateTime->EditAttributes() ?>>
&nbsp;<img src="images/calendar.png" id="cal_x_SentDateTime" name="cal_x_SentDateTime" alt="<?php echo $Language->Phrase("PickDate") ?>" title="<?php echo $Language->Phrase("PickDate") ?>" style="cursor:pointer;cursor:hand;">
<script type="text/javascript">
Calendar.setup({
	inputField: "x_SentDateTime", // input field id
	ifFormat: "%Y/%m/%d", // date format
	button: "cal_x_SentDateTime" // button id
});
</script>
</span><?php echo $CCMMessages->SentDateTime->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($CCMMessages->SentByName->Visible) { // SentByName ?>
	<tr<?php echo $CCMMessages->SentByName->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $CCMMessages->SentByName->FldCaption() ?></td>
		<td<?php echo $CCMMessages->SentByName->CellAttributes() ?>><span id="el_SentByName">
<input type="text" name="x_SentByName" id="x_SentByName" title="<?php echo $CCMMessages->SentByName->FldTitle() ?>" size="30" maxlength="255" value="<?php echo $CCMMessages->SentByName->EditValue ?>"<?php echo $CCMMessages->SentByName->EditAttributes() ?>>
</span><?php echo $CCMMessages->SentByName->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($CCMMessages->SentTo->Visible) { // SentTo ?>
	<tr<?php echo $CCMMessages->SentTo->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $CCMMessages->SentTo->FldCaption() ?></td>
		<td<?php echo $CCMMessages->SentTo->CellAttributes() ?>><span id="el_SentTo">
<textarea name="x_SentTo" id="x_SentTo" title="<?php echo $CCMMessages->SentTo->FldTitle() ?>" cols="35" rows="4"<?php echo $CCMMessages->SentTo->EditAttributes() ?>><?php echo $CCMMessages->SentTo->EditValue ?></textarea>
</span><?php echo $CCMMessages->SentTo->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($CCMMessages->MessageSubject->Visible) { // MessageSubject ?>
	<tr<?php echo $CCMMessages->MessageSubject->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $CCMMessages->MessageSubject->FldCaption() ?></td>
		<td<?php echo $CCMMessages->MessageSubject->CellAttributes() ?>><span id="el_MessageSubject">
<input type="text" name="x_MessageSubject" id="x_MessageSubject" title="<?php echo $CCMMessages->MessageSubject->FldTitle() ?>" size="30" maxlength="255" value="<?php echo $CCMMessages->MessageSubject->EditValue ?>"<?php echo $CCMMessages->MessageSubject->EditAttributes() ?>>
</span><?php echo $CCMMessages->MessageSubject->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($CCMMessages->MessageText->Visible) { // MessageText ?>
	<tr<?php echo $CCMMessages->MessageText->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $CCMMessages->MessageText->FldCaption() ?></td>
		<td<?php echo $CCMMessages->MessageText->CellAttributes() ?>><span id="el_MessageText">
<textarea name="x_MessageText" id="x_MessageText" title="<?php echo $CCMMessages->MessageText->FldTitle() ?>" cols="35" rows="4"<?php echo $CCMMessages->MessageText->EditAttributes() ?>><?php echo $CCMMessages->MessageText->EditValue ?></textarea>
</span><?php echo $CCMMessages->MessageText->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($CCMMessages->SentByStudentID->Visible) { // SentByStudentID ?>
	<tr<?php echo $CCMMessages->SentByStudentID->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $CCMMessages->SentByStudentID->FldCaption() ?></td>
		<td<?php echo $CCMMessages->SentByStudentID->CellAttributes() ?>><span id="el_SentByStudentID">
<input type="text" name="x_SentByStudentID" id="x_SentByStudentID" title="<?php echo $CCMMessages->SentByStudentID->FldTitle() ?>" size="30" value="<?php echo $CCMMessages->SentByStudentID->EditValue ?>"<?php echo $CCMMessages->SentByStudentID->EditAttributes() ?>>
</span><?php echo $CCMMessages->SentByStudentID->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($CCMMessages->SentByFacilitatorID->Visible) { // SentByFacilitatorID ?>
	<tr<?php echo $CCMMessages->SentByFacilitatorID->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $CCMMessages->SentByFacilitatorID->FldCaption() ?></td>
		<td<?php echo $CCMMessages->SentByFacilitatorID->CellAttributes() ?>><span id="el_SentByFacilitatorID">
<input type="text" name="x_SentByFacilitatorID" id="x_SentByFacilitatorID" title="<?php echo $CCMMessages->SentByFacilitatorID->FldTitle() ?>" size="30" value="<?php echo $CCMMessages->SentByFacilitatorID->EditValue ?>"<?php echo $CCMMessages->SentByFacilitatorID->EditAttributes() ?>>
</span><?php echo $CCMMessages->SentByFacilitatorID->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($CCMMessages->MessageFile->Visible) { // MessageFile ?>
	<tr<?php echo $CCMMessages->MessageFile->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $CCMMessages->MessageFile->FldCaption() ?></td>
		<td<?php echo $CCMMessages->MessageFile->CellAttributes() ?>><span id="el_MessageFile">
<div id="old_x_MessageFile">
<?php if ($CCMMessages->MessageFile->HrefValue <> "" || $CCMMessages->MessageFile->TooltipValue <> "") { ?>
<?php if (!empty($CCMMessages->MessageFile->Upload->DbValue)) { ?>
<a href="<?php echo $CCMMessages->MessageFile->HrefValue ?>"><?php echo $CCMMessages->MessageFile->EditValue ?></a>
<?php } elseif (!in_array($CCMMessages->CurrentAction, array("I", "edit", "gridedit"))) { ?>	
&nbsp;
<?php } ?>
<?php } else { ?>
<?php if (!empty($CCMMessages->MessageFile->Upload->DbValue)) { ?>
<?php echo $CCMMessages->MessageFile->EditValue ?>
<?php } elseif (!in_array($CCMMessages->CurrentAction, array("I", "edit", "gridedit"))) { ?>	
&nbsp;
<?php } ?>
<?php } ?>
</div>
<div id="new_x_MessageFile">
<?php if (!empty($CCMMessages->MessageFile->Upload->DbValue)) { ?>
<label><input type="radio" name="a_MessageFile" id="a_MessageFile" value="1" checked="checked"><?php echo $Language->Phrase("Keep") ?></label>&nbsp;
<label><input type="radio" name="a_MessageFile" id="a_MessageFile" value="2"><?php echo $Language->Phrase("Remove") ?></label>&nbsp;
<label><input type="radio" name="a_MessageFile" id="a_MessageFile" value="3"><?php echo $Language->Phrase("Replace") ?><br></label>
<?php $CCMMessages->MessageFile->EditAttrs["onchange"] = "this.form.a_MessageFile[2].checked=true;" . @$CCMMessages->MessageFile->EditAttrs["onchange"]; ?>
<?php } else { ?>
<input type="hidden" name="a_MessageFile" id="a_MessageFile" value="3">
<?php } ?>
<input type="file" name="x_MessageFile" id="x_MessageFile" title="<?php echo $CCMMessages->MessageFile->FldTitle() ?>" size="30"<?php echo $CCMMessages->MessageFile->EditAttributes() ?>>
</div>
</span><?php echo $CCMMessages->MessageFile->CustomMsg ?></td>
	</tr>
<?php } ?>
</table>
</div>
</td></tr></table>
<p>
<input type="submit" name="btnAction" id="btnAction" value="<?php echo ew_BtnCaption($Language->Phrase("EditBtn")) ?>">
</form>
<script language="JavaScript" type="text/javascript">
<!--

// Write your table-specific startup script here
// document.write("page loaded");
//-->

</script>
<?php include "footer.php" ?>
<?php
$CCMMessages_edit->Page_Terminate();
?>
<?php

//
// Page class
//
class cCCMMessages_edit {

	// Page ID
	var $PageID = 'edit';

	// Table name
	var $TableName = 'CCMMessages';

	// Page object name
	var $PageObjName = 'CCMMessages_edit';

	// Page name
	function PageName() {
		return ew_CurrentPage();
	}

	// Page URL
	function PageUrl() {
		$PageUrl = ew_CurrentPage() . "?";
		global $CCMMessages;
		if ($CCMMessages->UseTokenInUrl) $PageUrl .= "t=" . $CCMMessages->TableVar . "&"; // Add page token
		return $PageUrl;
	}

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

	// Export URLs
	var $ExportPrintUrl;
	var $ExportHtmlUrl;
	var $ExportExcelUrl;
	var $ExportWordUrl;
	var $ExportXmlUrl;
	var $ExportCsvUrl;

	// Update URLs
	var $InlineAddUrl;
	var $InlineCopyUrl;
	var $InlineEditUrl;
	var $GridAddUrl;
	var $GridEditUrl;
	var $MultiDeleteUrl;
	var $MultiUpdateUrl;

	// Message
	function getMessage() {
		return @$_SESSION[EW_SESSION_MESSAGE];
	}

	function setMessage($v) {
		if (@$_SESSION[EW_SESSION_MESSAGE] <> "") { // Append
			$_SESSION[EW_SESSION_MESSAGE] .= "<br>" . $v;
		} else {
			$_SESSION[EW_SESSION_MESSAGE] = $v;
		}
	}

	// Show message
	function ShowMessage() {
		$sMessage = $this->getMessage();
		$this->Message_Showing($sMessage);
		if ($sMessage <> "") { // Message in Session, display
			echo "<p><span class=\"ewMessage\">" . $sMessage . "</span></p>";
			$_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
		}
	}

	// Validate page request
	function IsPageRequest() {
		global $objForm, $CCMMessages;
		if ($CCMMessages->UseTokenInUrl) {
			if ($objForm)
				return ($CCMMessages->TableVar == $objForm->GetValue("t"));
			if (@$_GET["t"] <> "")
				return ($CCMMessages->TableVar == $_GET["t"]);
		} else {
			return TRUE;
		}
	}

	//
	// Page class constructor
	//
	function cCCMMessages_edit() {
		global $conn, $Language;

		// Language object
		$Language = new cLanguage();

		// Table object (CCMMessages)
		$GLOBALS["CCMMessages"] = new cCCMMessages();

		// Table object (CCMUsers)
		$GLOBALS['CCMUsers'] = new cCCMUsers();

		// Page ID
		if (!defined("EW_PAGE_ID"))
			define("EW_PAGE_ID", 'edit', TRUE);

		// Table name (for backward compatibility)
		if (!defined("EW_TABLE_NAME"))
			define("EW_TABLE_NAME", 'CCMMessages', TRUE);

		// Start timer
		$GLOBALS["gsTimer"] = new cTimer();

		// Open connection
		$conn = ew_Connect();
	}

	// 
	//  Page_Init
	//
	function Page_Init() {
		global $gsExport, $gsExportFile, $UserProfile, $Language, $Security, $objForm;
		global $CCMMessages;

		// Security
		$Security = new cAdvancedSecurity();
		if (!$Security->IsLoggedIn()) $Security->AutoLogin();
		if (!$Security->IsLoggedIn()) {
			$Security->SaveLastUrl();
			$this->Page_Terminate("login.php");
		}
		$Security->TablePermission_Loading();
		$Security->LoadCurrentUserLevel($this->TableName);
		$Security->TablePermission_Loaded();
		if (!$Security->IsLoggedIn()) {
			$Security->SaveLastUrl();
			$this->Page_Terminate("login.php");
		}
		if (!$Security->CanEdit()) {
			$Security->SaveLastUrl();
			$this->Page_Terminate("CCMMessageslist.php");
		}

		// Create form object
		$objForm = new cFormObj();

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

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

	//
	// Page_Terminate
	//
	function Page_Terminate($url = "") {
		global $conn;

		// Page Unload event
		$this->Page_Unload();

		// Global Page Unloaded event (in userfn*.php)
		Page_Unloaded();

		 // Close connection
		$conn->Close();

		// Go to URL if specified
		$this->Page_Redirecting($url);
		if ($url <> "") {
			if (!EW_DEBUG_ENABLED && ob_get_length())
				ob_end_clean();
			header("Location: " . $url);
		}
		exit();
	}
	var $sDbMasterFilter;
	var $sDbDetailFilter;

	// 
	// Page main
	//
	function Page_Main() {
		global $objForm, $Language, $gsFormError, $CCMMessages;

		// Load key from QueryString
		if (@$_GET["CCMMessageID"] <> "")
			$CCMMessages->CCMMessageID->setQueryStringValue($_GET["CCMMessageID"]);
		if (@$_POST["a_edit"] <> "") {
			$CCMMessages->CurrentAction = $_POST["a_edit"]; // Get action code
			$this->GetUploadFiles(); // Get upload files
			$this->LoadFormValues(); // Get form values

			// Validate form
			if (!$this->ValidateForm()) {
				$CCMMessages->CurrentAction = ""; // Form error, reset action
				$this->setMessage($gsFormError);
				$CCMMessages->EventCancelled = TRUE; // Event cancelled
				$this->RestoreFormValues();
			}
		} else {
			$CCMMessages->CurrentAction = "I"; // Default action is display
		}

		// Check if valid key
		if ($CCMMessages->CCMMessageID->CurrentValue == "")
			$this->Page_Terminate("CCMMessageslist.php"); // Invalid key, return to list
		switch ($CCMMessages->CurrentAction) {
			case "I": // Get a record to display
				if (!$this->LoadRow()) { // Load record based on key
					$this->setMessage($Language->Phrase("NoRecord")); // No record found
					$this->Page_Terminate("CCMMessageslist.php"); // No matching record, return to list
				}
				break;
			Case "U": // Update
				$CCMMessages->SendEmail = TRUE; // Send email on update success
				if ($this->EditRow()) { // Update record based on key
					$this->setMessage($Language->Phrase("UpdateSuccess")); // Update success
					$sReturnUrl = $CCMMessages->getReturnUrl();
					if (ew_GetPageName($sReturnUrl) == "CCMMessagesview.php")
						$sReturnUrl = $CCMMessages->ViewUrl(); // View paging, return to View page directly
					$this->Page_Terminate($sReturnUrl); // Return to caller
				} else {
					$CCMMessages->EventCancelled = TRUE; // Event cancelled
					$this->RestoreFormValues(); // Restore form values if update failed
				}
		}

		// Render the record
		$CCMMessages->RowType = EW_ROWTYPE_EDIT; // Render as Edit
		$this->RenderRow();
	}

	// Get upload files
	function GetUploadFiles() {
		global $objForm, $CCMMessages;

		// Get upload data
			if ($CCMMessages->MessageFile->Upload->UploadFile()) {

				// No action required
			} else {
				echo $CCMMessages->MessageFile->Upload->Message;
				$this->Page_Terminate();
				exit();
			}
	}

	// Load form values
	function LoadFormValues() {

		// Load from form
		global $objForm, $CCMMessages;
		$CCMMessages->CCMMessageID->setFormValue($objForm->GetValue("x_CCMMessageID"));
		$CCMMessages->SentDateTime->setFormValue($objForm->GetValue("x_SentDateTime"));
		$CCMMessages->SentDateTime->CurrentValue = ew_UnFormatDateTime($CCMMessages->SentDateTime->CurrentValue, 5);
		$CCMMessages->SentByName->setFormValue($objForm->GetValue("x_SentByName"));
		$CCMMessages->SentTo->setFormValue($objForm->GetValue("x_SentTo"));
		$CCMMessages->MessageSubject->setFormValue($objForm->GetValue("x_MessageSubject"));
		$CCMMessages->MessageText->setFormValue($objForm->GetValue("x_MessageText"));
		$CCMMessages->SentByStudentID->setFormValue($objForm->GetValue("x_SentByStudentID"));
		$CCMMessages->SentByFacilitatorID->setFormValue($objForm->GetValue("x_SentByFacilitatorID"));
	}

	// Restore form values
	function RestoreFormValues() {
		global $objForm, $CCMMessages;
		$this->LoadRow();
		$CCMMessages->CCMMessageID->CurrentValue = $CCMMessages->CCMMessageID->FormValue;
		$CCMMessages->SentDateTime->CurrentValue = $CCMMessages->SentDateTime->FormValue;
		$CCMMessages->SentDateTime->CurrentValue = ew_UnFormatDateTime($CCMMessages->SentDateTime->CurrentValue, 5);
		$CCMMessages->SentByName->CurrentValue = $CCMMessages->SentByName->FormValue;
		$CCMMessages->SentTo->CurrentValue = $CCMMessages->SentTo->FormValue;
		$CCMMessages->MessageSubject->CurrentValue = $CCMMessages->MessageSubject->FormValue;
		$CCMMessages->MessageText->CurrentValue = $CCMMessages->MessageText->FormValue;
		$CCMMessages->SentByStudentID->CurrentValue = $CCMMessages->SentByStudentID->FormValue;
		$CCMMessages->SentByFacilitatorID->CurrentValue = $CCMMessages->SentByFacilitatorID->FormValue;
	}

	// Load row based on key values
	function LoadRow() {
		global $conn, $Security, $CCMMessages;
		$sFilter = $CCMMessages->KeyFilter();

		// Call Row Selecting event
		$CCMMessages->Row_Selecting($sFilter);

		// Load SQL based on filter
		$CCMMessages->CurrentFilter = $sFilter;
		$sSql = $CCMMessages->SQL();
		$res = FALSE;
		$rs = ew_LoadRecordset($sSql);
		if ($rs && !$rs->EOF) {
			$res = TRUE;
			$this->LoadRowValues($rs); // Load row values

			// Call Row Selected event
			$CCMMessages->Row_Selected($rs);
			$rs->Close();
		}
		return $res;
	}

	// Load row values from recordset
	function LoadRowValues(&$rs) {
		global $conn, $CCMMessages;
		$CCMMessages->CCMMessageID->setDbValue($rs->fields('CCMMessageID'));
		$CCMMessages->SentDateTime->setDbValue($rs->fields('SentDateTime'));
		$CCMMessages->SentByName->setDbValue($rs->fields('SentByName'));
		$CCMMessages->SentTo->setDbValue($rs->fields('SentTo'));
		$CCMMessages->MessageSubject->setDbValue($rs->fields('MessageSubject'));
		$CCMMessages->MessageText->setDbValue($rs->fields('MessageText'));
		$CCMMessages->SentByStudentID->setDbValue($rs->fields('SentByStudentID'));
		$CCMMessages->SentByFacilitatorID->setDbValue($rs->fields('SentByFacilitatorID'));
		$CCMMessages->MessageFile->Upload->DbValue = $rs->fields('MessageFile');
	}

	// Render row values based on field settings
	function RenderRow() {
		global $conn, $Security, $Language, $CCMMessages;

		// Initialize URLs
		// Call Row_Rendering event

		$CCMMessages->Row_Rendering();

		// Common render codes for all row types
		// CCMMessageID

		$CCMMessages->CCMMessageID->CellCssStyle = ""; $CCMMessages->CCMMessageID->CellCssClass = "";
		$CCMMessages->CCMMessageID->CellAttrs = array(); $CCMMessages->CCMMessageID->ViewAttrs = array(); $CCMMessages->CCMMessageID->EditAttrs = array();

		// SentDateTime
		$CCMMessages->SentDateTime->CellCssStyle = ""; $CCMMessages->SentDateTime->CellCssClass = "";
		$CCMMessages->SentDateTime->CellAttrs = array(); $CCMMessages->SentDateTime->ViewAttrs = array(); $CCMMessages->SentDateTime->EditAttrs = array();

		// SentByName
		$CCMMessages->SentByName->CellCssStyle = ""; $CCMMessages->SentByName->CellCssClass = "";
		$CCMMessages->SentByName->CellAttrs = array(); $CCMMessages->SentByName->ViewAttrs = array(); $CCMMessages->SentByName->EditAttrs = array();

		// SentTo
		$CCMMessages->SentTo->CellCssStyle = ""; $CCMMessages->SentTo->CellCssClass = "";
		$CCMMessages->SentTo->CellAttrs = array(); $CCMMessages->SentTo->ViewAttrs = array(); $CCMMessages->SentTo->EditAttrs = array();

		// MessageSubject
		$CCMMessages->MessageSubject->CellCssStyle = ""; $CCMMessages->MessageSubject->CellCssClass = "";
		$CCMMessages->MessageSubject->CellAttrs = array(); $CCMMessages->MessageSubject->ViewAttrs = array(); $CCMMessages->MessageSubject->EditAttrs = array();

		// MessageText
		$CCMMessages->MessageText->CellCssStyle = ""; $CCMMessages->MessageText->CellCssClass = "";
		$CCMMessages->MessageText->CellAttrs = array(); $CCMMessages->MessageText->ViewAttrs = array(); $CCMMessages->MessageText->EditAttrs = array();

		// SentByStudentID
		$CCMMessages->SentByStudentID->CellCssStyle = ""; $CCMMessages->SentByStudentID->CellCssClass = "";
		$CCMMessages->SentByStudentID->CellAttrs = array(); $CCMMessages->SentByStudentID->ViewAttrs = array(); $CCMMessages->SentByStudentID->EditAttrs = array();

		// SentByFacilitatorID
		$CCMMessages->SentByFacilitatorID->CellCssStyle = ""; $CCMMessages->SentByFacilitatorID->CellCssClass = "";
		$CCMMessages->SentByFacilitatorID->CellAttrs = array(); $CCMMessages->SentByFacilitatorID->ViewAttrs = array(); $CCMMessages->SentByFacilitatorID->EditAttrs = array();

		// MessageFile
		$CCMMessages->MessageFile->CellCssStyle = ""; $CCMMessages->MessageFile->CellCssClass = "";
		$CCMMessages->MessageFile->CellAttrs = array(); $CCMMessages->MessageFile->ViewAttrs = array(); $CCMMessages->MessageFile->EditAttrs = array();
		if ($CCMMessages->RowType == EW_ROWTYPE_VIEW) { // View row

			// CCMMessageID
			$CCMMessages->CCMMessageID->ViewValue = $CCMMessages->CCMMessageID->CurrentValue;
			$CCMMessages->CCMMessageID->CssStyle = "";
			$CCMMessages->CCMMessageID->CssClass = "";
			$CCMMessages->CCMMessageID->ViewCustomAttributes = "";

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

			// SentByName
			$CCMMessages->SentByName->ViewValue = $CCMMessages->SentByName->CurrentValue;
			$CCMMessages->SentByName->CssStyle = "";
			$CCMMessages->SentByName->CssClass = "";
			$CCMMessages->SentByName->ViewCustomAttributes = "";

			// SentTo
			$CCMMessages->SentTo->ViewValue = $CCMMessages->SentTo->CurrentValue;
			$CCMMessages->SentTo->CssStyle = "";
			$CCMMessages->SentTo->CssClass = "";
			$CCMMessages->SentTo->ViewCustomAttributes = "";

			// MessageSubject
			$CCMMessages->MessageSubject->ViewValue = $CCMMessages->MessageSubject->CurrentValue;
			$CCMMessages->MessageSubject->CssStyle = "";
			$CCMMessages->MessageSubject->CssClass = "";
			$CCMMessages->MessageSubject->ViewCustomAttributes = "";

			// MessageText
			$CCMMessages->MessageText->ViewValue = $CCMMessages->MessageText->CurrentValue;
			$CCMMessages->MessageText->CssStyle = "";
			$CCMMessages->MessageText->CssClass = "";
			$CCMMessages->MessageText->ViewCustomAttributes = "";

			// SentByStudentID
			$CCMMessages->SentByStudentID->ViewValue = $CCMMessages->SentByStudentID->CurrentValue;
			$CCMMessages->SentByStudentID->CssStyle = "";
			$CCMMessages->SentByStudentID->CssClass = "";
			$CCMMessages->SentByStudentID->ViewCustomAttributes = "";

			// SentByFacilitatorID
			$CCMMessages->SentByFacilitatorID->ViewValue = $CCMMessages->SentByFacilitatorID->CurrentValue;
			$CCMMessages->SentByFacilitatorID->CssStyle = "";
			$CCMMessages->SentByFacilitatorID->CssClass = "";
			$CCMMessages->SentByFacilitatorID->ViewCustomAttributes = "";

			// MessageFile
			if (!ew_Empty($CCMMessages->MessageFile->Upload->DbValue)) {
				$CCMMessages->MessageFile->ViewValue = $CCMMessages->MessageFile->Upload->DbValue;
			} else {
				$CCMMessages->MessageFile->ViewValue = "";
			}
			$CCMMessages->MessageFile->CssStyle = "";
			$CCMMessages->MessageFile->CssClass = "";
			$CCMMessages->MessageFile->ViewCustomAttributes = "";

			// CCMMessageID
			$CCMMessages->CCMMessageID->HrefValue = "";
			$CCMMessages->CCMMessageID->TooltipValue = "";

			// SentDateTime
			$CCMMessages->SentDateTime->HrefValue = "";
			$CCMMessages->SentDateTime->TooltipValue = "";

			// SentByName
			$CCMMessages->SentByName->HrefValue = "";
			$CCMMessages->SentByName->TooltipValue = "";

			// SentTo
			$CCMMessages->SentTo->HrefValue = "";
			$CCMMessages->SentTo->TooltipValue = "";

			// MessageSubject
			$CCMMessages->MessageSubject->HrefValue = "";
			$CCMMessages->MessageSubject->TooltipValue = "";

			// MessageText
			$CCMMessages->MessageText->HrefValue = "";
			$CCMMessages->MessageText->TooltipValue = "";

			// SentByStudentID
			$CCMMessages->SentByStudentID->HrefValue = "";
			$CCMMessages->SentByStudentID->TooltipValue = "";

			// SentByFacilitatorID
			$CCMMessages->SentByFacilitatorID->HrefValue = "";
			$CCMMessages->SentByFacilitatorID->TooltipValue = "";

			// MessageFile
			if (!ew_Empty($CCMMessages->MessageFile->Upload->DbValue)) {
				$CCMMessages->MessageFile->HrefValue = ew_UploadPathEx(FALSE, $CCMMessages->MessageFile->UploadPath) . ((!empty($CCMMessages->MessageFile->ViewValue)) ? $CCMMessages->MessageFile->ViewValue : $CCMMessages->MessageFile->CurrentValue);
				if ($CCMMessages->Export <> "") $CCMMessages->MessageFile->HrefValue = ew_ConvertFullUrl($CCMMessages->MessageFile->HrefValue);
			} else {
				$CCMMessages->MessageFile->HrefValue = "";
			}
			$CCMMessages->MessageFile->TooltipValue = "";
		} elseif ($CCMMessages->RowType == EW_ROWTYPE_EDIT) { // Edit row

			// CCMMessageID
			$CCMMessages->CCMMessageID->EditCustomAttributes = "";
			$CCMMessages->CCMMessageID->EditValue = $CCMMessages->CCMMessageID->CurrentValue;
			$CCMMessages->CCMMessageID->CssStyle = "";
			$CCMMessages->CCMMessageID->CssClass = "";
			$CCMMessages->CCMMessageID->ViewCustomAttributes = "";

			// SentDateTime
			$CCMMessages->SentDateTime->EditCustomAttributes = "";
			$CCMMessages->SentDateTime->EditValue = ew_HtmlEncode(ew_FormatDateTime($CCMMessages->SentDateTime->CurrentValue, 5));

			// SentByName
			$CCMMessages->SentByName->EditCustomAttributes = "";
			$CCMMessages->SentByName->EditValue = ew_HtmlEncode($CCMMessages->SentByName->CurrentValue);

			// SentTo
			$CCMMessages->SentTo->EditCustomAttributes = "";
			$CCMMessages->SentTo->EditValue = ew_HtmlEncode($CCMMessages->SentTo->CurrentValue);

			// MessageSubject
			$CCMMessages->MessageSubject->EditCustomAttributes = "";
			$CCMMessages->MessageSubject->EditValue = ew_HtmlEncode($CCMMessages->MessageSubject->CurrentValue);

			// MessageText
			$CCMMessages->MessageText->EditCustomAttributes = "";
			$CCMMessages->MessageText->EditValue = ew_HtmlEncode($CCMMessages->MessageText->CurrentValue);

			// SentByStudentID
			$CCMMessages->SentByStudentID->EditCustomAttributes = "";
			$CCMMessages->SentByStudentID->EditValue = ew_HtmlEncode($CCMMessages->SentByStudentID->CurrentValue);

			// SentByFacilitatorID
			$CCMMessages->SentByFacilitatorID->EditCustomAttributes = "";
			$CCMMessages->SentByFacilitatorID->EditValue = ew_HtmlEncode($CCMMessages->SentByFacilitatorID->CurrentValue);

			// MessageFile
			$CCMMessages->MessageFile->EditCustomAttributes = "";
			if (!ew_Empty($CCMMessages->MessageFile->Upload->DbValue)) {
				$CCMMessages->MessageFile->EditValue = $CCMMessages->MessageFile->Upload->DbValue;
			} else {
				$CCMMessages->MessageFile->EditValue = "";
			}

			// Edit refer script
			// CCMMessageID

			$CCMMessages->CCMMessageID->HrefValue = "";

			// SentDateTime
			$CCMMessages->SentDateTime->HrefValue = "";

			// SentByName
			$CCMMessages->SentByName->HrefValue = "";

			// SentTo
			$CCMMessages->SentTo->HrefValue = "";

			// MessageSubject
			$CCMMessages->MessageSubject->HrefValue = "";

			// MessageText
			$CCMMessages->MessageText->HrefValue = "";

			// SentByStudentID
			$CCMMessages->SentByStudentID->HrefValue = "";

			// SentByFacilitatorID
			$CCMMessages->SentByFacilitatorID->HrefValue = "";

			// MessageFile
			if (!ew_Empty($CCMMessages->MessageFile->Upload->DbValue)) {
				$CCMMessages->MessageFile->HrefValue = ew_UploadPathEx(FALSE, $CCMMessages->MessageFile->UploadPath) . ((!empty($CCMMessages->MessageFile->EditValue)) ? $CCMMessages->MessageFile->EditValue : $CCMMessages->MessageFile->CurrentValue);
				if ($CCMMessages->Export <> "") $CCMMessages->MessageFile->HrefValue = ew_ConvertFullUrl($CCMMessages->MessageFile->HrefValue);
			} else {
				$CCMMessages->MessageFile->HrefValue = "";
			}
		}

		// Call Row Rendered event
		if ($CCMMessages->RowType <> EW_ROWTYPE_AGGREGATEINIT)
			$CCMMessages->Row_Rendered();
	}

	// Validate form
	function ValidateForm() {
		global $Language, $gsFormError, $CCMMessages;

		// Initialize form error message
		$gsFormError = "";
		if (!ew_CheckFileType($CCMMessages->MessageFile->Upload->FileName)) {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $Language->Phrase("WrongFileType");
		}
		if ($CCMMessages->MessageFile->Upload->FileSize > 0 && EW_MAX_FILE_SIZE > 0 && $CCMMessages->MessageFile->Upload->FileSize > EW_MAX_FILE_SIZE) {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= str_replace("%s", EW_MAX_FILE_SIZE, $Language->Phrase("MaxFileSize"));
		}
		if (in_array($CCMMessages->MessageFile->Upload->Error, array(1, 2, 3, 6, 7, 8))) {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $Language->Phrase("PhpUploadErr" . $CCMMessages->MessageFile->Upload->Error);
		}

		// Check if validation required
		if (!EW_SERVER_VALIDATE)
			return ($gsFormError == "");
		if (!ew_CheckDate($CCMMessages->SentDateTime->FormValue)) {
			if ($gsFormError <> "") $gsFormError .= "<br>";
			$gsFormError .= $CCMMessages->SentDateTime->FldErrMsg();
		}
		if (!ew_CheckInteger($CCMMessages->SentByStudentID->FormValue)) {
			if ($gsFormError <> "") $gsFormError .= "<br>";
			$gsFormError .= $CCMMessages->SentByStudentID->FldErrMsg();
		}
		if (!ew_CheckInteger($CCMMessages->SentByFacilitatorID->FormValue)) {
			if ($gsFormError <> "") $gsFormError .= "<br>";
			$gsFormError .= $CCMMessages->SentByFacilitatorID->FldErrMsg();
		}

		// Return validate result
		$ValidateForm = ($gsFormError == "");

		// Call Form_CustomValidate event
		$sFormCustomError = "";
		$ValidateForm = $ValidateForm && $this->Form_CustomValidate($sFormCustomError);
		if ($sFormCustomError <> "") {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $sFormCustomError;
		}
		return $ValidateForm;
	}

	// Update record based on key values
	function EditRow() {
		global $conn, $Security, $Language, $CCMMessages;
		$sFilter = $CCMMessages->KeyFilter();
		$CCMMessages->CurrentFilter = $sFilter;
		$sSql = $CCMMessages->SQL();
		$conn->raiseErrorFn = 'ew_ErrorFn';
		$rs = $conn->Execute($sSql);
		$conn->raiseErrorFn = '';
		if ($rs === FALSE)
			return FALSE;
		if ($rs->EOF) {
			$EditRow = FALSE; // Update Failed
		} else {

			// Save old values
			$rsold =& $rs->fields;
			$rsnew = array();

			// SentDateTime
			$CCMMessages->SentDateTime->SetDbValueDef($rsnew, ew_UnFormatDateTime($CCMMessages->SentDateTime->CurrentValue, 5, FALSE), NULL);

			// SentByName
			$CCMMessages->SentByName->SetDbValueDef($rsnew, $CCMMessages->SentByName->CurrentValue, NULL, FALSE);

			// SentTo
			$CCMMessages->SentTo->SetDbValueDef($rsnew, $CCMMessages->SentTo->CurrentValue, NULL, FALSE);

			// MessageSubject
			$CCMMessages->MessageSubject->SetDbValueDef($rsnew, $CCMMessages->MessageSubject->CurrentValue, NULL, FALSE);

			// MessageText
			$CCMMessages->MessageText->SetDbValueDef($rsnew, $CCMMessages->MessageText->CurrentValue, NULL, FALSE);

			// SentByStudentID
			$CCMMessages->SentByStudentID->SetDbValueDef($rsnew, $CCMMessages->SentByStudentID->CurrentValue, NULL, FALSE);

			// SentByFacilitatorID
			$CCMMessages->SentByFacilitatorID->SetDbValueDef($rsnew, $CCMMessages->SentByFacilitatorID->CurrentValue, NULL, FALSE);

			// MessageFile
			$CCMMessages->MessageFile->Upload->SaveToSession(); // Save file value to Session
						if ($CCMMessages->MessageFile->Upload->Action == "2" || $CCMMessages->MessageFile->Upload->Action == "3") { // Update/Remove
			$CCMMessages->MessageFile->Upload->DbValue = $rs->fields('MessageFile'); // Get original value
			if (is_null($CCMMessages->MessageFile->Upload->Value)) {
				$rsnew['MessageFile'] = NULL;
			} else {
				$rsnew['MessageFile'] = ew_UploadFileNameEx(ew_UploadPathEx(TRUE, $CCMMessages->MessageFile->UploadPath), $CCMMessages->MessageFile->Upload->FileName);
			}
			}

			// Call Row Updating event
			$bUpdateRow = $CCMMessages->Row_Updating($rsold, $rsnew);
			if ($bUpdateRow) {
			if (!ew_Empty($CCMMessages->MessageFile->Upload->Value)) {
				$CCMMessages->MessageFile->Upload->SaveToFile($CCMMessages->MessageFile->UploadPath, $rsnew['MessageFile'], FALSE);
			}
				$conn->raiseErrorFn = 'ew_ErrorFn';
				$EditRow = $conn->Execute($CCMMessages->UpdateSQL($rsnew));
				$conn->raiseErrorFn = '';
			} else {
				if ($CCMMessages->CancelMessage <> "") {
					$this->setMessage($CCMMessages->CancelMessage);
					$CCMMessages->CancelMessage = "";
				} else {
					$this->setMessage($Language->Phrase("UpdateCancelled"));
				}
				$EditRow = FALSE;
			}
		}

		// Call Row_Updated event
		if ($EditRow)
			$CCMMessages->Row_Updated($rsold, $rsnew);
		$rs->Close();

		// MessageFile
		$CCMMessages->MessageFile->Upload->RemoveFromSession(); // Remove file value from Session
		return $EditRow;
	}

	// Page Load event
	function Page_Load() {

		//echo "Page Load";
	}

	// Page Unload event
	function Page_Unload() {

		//echo "Page Unload";
	}

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

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

	}

	// Message Showing event
	function Message_Showing(&$msg) {

		// Example:
		//$msg = "your new message";

	}

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

		// Return error message in CustomError
		return TRUE;
	}
}
?>