| Current Path : /var/www/cesa.co.za/echasl23/ |
| Current File : /var/www/cesa.co.za/echasl23/BranchDocumentsadd.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 "BranchDocumentsinfo.php" ?>
<?php include "adminusersinfo.php" ?>
<?php include "SAACEBranchesinfo.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
$BranchDocuments_add = new cBranchDocuments_add();
$Page =& $BranchDocuments_add;
// Page init
$BranchDocuments_add->Page_Init();
// Page main
$BranchDocuments_add->Page_Main();
?>
<?php include "header.php" ?>
<script type="text/javascript">
<!--
// Create page object
var BranchDocuments_add = new ew_Page("BranchDocuments_add");
// page properties
BranchDocuments_add.PageID = "add"; // page ID
BranchDocuments_add.FormID = "fBranchDocumentsadd"; // form ID
var EW_PAGE_ID = BranchDocuments_add.PageID; // for backward compatibility
// extend page with ValidateForm function
BranchDocuments_add.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 + "_Document"];
if (elm && !ew_CheckFileType(elm.value))
return ew_OnError(this, elm, ewLanguage.Phrase("WrongFileType"));
elm = fobj.elements["x" + infix + "_SortOrder"];
if (elm && !ew_CheckInteger(elm.value))
return ew_OnError(this, elm, "<?php echo ew_JsEncode2($BranchDocuments->SortOrder->FldErrMsg()) ?>");
// Call Form Custom Validate event
if (!this.Form_CustomValidate(fobj)) return false;
}
return true;
}
// extend page with Form_CustomValidate function
BranchDocuments_add.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) { ?>
BranchDocuments_add.ValidateRequired = true; // uses JavaScript validation
<?php } else { ?>
BranchDocuments_add.ValidateRequired = false; // no JavaScript validation
<?php } ?>
// search highlight properties
BranchDocuments_add.ShowHighlightText = ewLanguage.Phrase("ShowHighlight");
BranchDocuments_add.HideHighlightText = ewLanguage.Phrase("HideHighlight");
//-->
</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("Add") ?> <?php echo $Language->Phrase("TblTypeTABLE") ?><?php echo $BranchDocuments->TableCaption() ?><br><br>
<a href="<?php echo $BranchDocuments->getReturnUrl() ?>"><?php echo $Language->Phrase("GoBack") ?></a></span></p>
<?php
if (EW_DEBUG_ENABLED)
echo ew_DebugMsg();
$BranchDocuments_add->ShowMessage();
?>
<form name="fBranchDocumentsadd" id="fBranchDocumentsadd" action="<?php echo ew_CurrentPage() ?>" method="post" enctype="multipart/form-data" onsubmit="return BranchDocuments_add.ValidateForm(this);">
<p>
<input type="hidden" name="t" id="t" value="BranchDocuments">
<input type="hidden" name="a_add" id="a_add" value="A">
<table cellspacing="0" class="ewGrid"><tr><td class="ewGridContent">
<div class="ewGridMiddlePanel">
<table cellspacing="0" class="ewTable">
<?php if ($BranchDocuments->BranchID->getSessionValue() <> "") { ?>
<input type="hidden" id="x_BranchID" name="x_BranchID" value="<?php echo ew_HtmlEncode($BranchDocuments->BranchID->CurrentValue) ?>">
<?php } else { ?>
<input type="text" name="x_BranchID" id="x_BranchID" title="<?php echo $BranchDocuments->BranchID->FldTitle() ?>" size="30" value="<?php echo $BranchDocuments->BranchID->EditValue ?>"<?php echo $BranchDocuments->BranchID->EditAttributes() ?>>
<?php } ?>
<?php if ($BranchDocuments->Category->Visible) { // Category ?>
<tr<?php echo $BranchDocuments->RowAttributes() ?>>
<td class="ewTableHeader"><?php echo $BranchDocuments->Category->FldCaption() ?></td>
<td<?php echo $BranchDocuments->Category->CellAttributes() ?>><span id="el_Category">
<select id="x_Category" name="x_Category" title="<?php echo $BranchDocuments->Category->FldTitle() ?>"<?php echo $BranchDocuments->Category->EditAttributes() ?>>
<?php
if (is_array($BranchDocuments->Category->EditValue)) {
$arwrk = $BranchDocuments->Category->EditValue;
$rowswrk = count($arwrk);
$emptywrk = TRUE;
for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
$selwrk = (strval($BranchDocuments->Category->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
}
}
?>
</select>
</span><?php echo $BranchDocuments->Category->CustomMsg ?></td>
</tr>
<?php } ?>
<?php if ($BranchDocuments->Document->Visible) { // Document ?>
<tr<?php echo $BranchDocuments->RowAttributes() ?>>
<td class="ewTableHeader"><?php echo $BranchDocuments->Document->FldCaption() ?></td>
<td<?php echo $BranchDocuments->Document->CellAttributes() ?>><span id="el_Document">
<input type="file" name="x_Document" id="x_Document" title="<?php echo $BranchDocuments->Document->FldTitle() ?>" size="30"<?php echo $BranchDocuments->Document->EditAttributes() ?>>
</div>
</span><?php echo $BranchDocuments->Document->CustomMsg ?></td>
</tr>
<?php } ?>
<?php if ($BranchDocuments->DocName->Visible) { // DocName ?>
<tr<?php echo $BranchDocuments->RowAttributes() ?>>
<td class="ewTableHeader"><?php echo $BranchDocuments->DocName->FldCaption() ?></td>
<td<?php echo $BranchDocuments->DocName->CellAttributes() ?>><span id="el_DocName">
<input type="text" name="x_DocName" id="x_DocName" title="<?php echo $BranchDocuments->DocName->FldTitle() ?>" size="30" maxlength="255" value="<?php echo $BranchDocuments->DocName->EditValue ?>"<?php echo $BranchDocuments->DocName->EditAttributes() ?>>
</span><?php echo $BranchDocuments->DocName->CustomMsg ?></td>
</tr>
<?php } ?>
<?php if ($BranchDocuments->SortOrder->Visible) { // SortOrder ?>
<tr<?php echo $BranchDocuments->RowAttributes() ?>>
<td class="ewTableHeader"><?php echo $BranchDocuments->SortOrder->FldCaption() ?></td>
<td<?php echo $BranchDocuments->SortOrder->CellAttributes() ?>><span id="el_SortOrder">
<input type="text" name="x_SortOrder" id="x_SortOrder" title="<?php echo $BranchDocuments->SortOrder->FldTitle() ?>" size="30" value="<?php echo $BranchDocuments->SortOrder->EditValue ?>"<?php echo $BranchDocuments->SortOrder->EditAttributes() ?>>
</span><?php echo $BranchDocuments->SortOrder->CustomMsg ?></td>
</tr>
<?php } ?>
</table>
</div>
</td></tr></table>
<p>
<input type="submit" name="btnAction" id="btnAction" value="<?php echo ew_BtnCaption($Language->Phrase("AddBtn")) ?>">
</form>
<script language="JavaScript" type="text/javascript">
<!--
// Write your table-specific startup script here
// document.write("page loaded");
//-->
</script>
<?php include "footer.php" ?>
<?php
$BranchDocuments_add->Page_Terminate();
?>
<?php
//
// Page class
//
class cBranchDocuments_add {
// Page ID
var $PageID = 'add';
// Table name
var $TableName = 'BranchDocuments';
// Page object name
var $PageObjName = 'BranchDocuments_add';
// Page name
function PageName() {
return ew_CurrentPage();
}
// Page URL
function PageUrl() {
$PageUrl = ew_CurrentPage() . "?";
global $BranchDocuments;
if ($BranchDocuments->UseTokenInUrl) $PageUrl .= "t=" . $BranchDocuments->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;
//
// Page class constructor
//
function __construct() {
global $conn, $Language;
// Language object
$Language = new cLanguage();
// Table object (BranchDocuments)
$GLOBALS["BranchDocuments"] = new cBranchDocuments();
// Table object (adminusers)
$GLOBALS['adminusers'] = new cadminusers();
// Table object (SAACEBranches)
$GLOBALS['SAACEBranches'] = new cSAACEBranches();
// Page ID
if (!defined("EW_PAGE_ID"))
define("EW_PAGE_ID", 'add', TRUE);
// Table name (for backward compatibility)
if (!defined("EW_TABLE_NAME"))
define("EW_TABLE_NAME", 'BranchDocuments', TRUE);
// Start timer
$GLOBALS["gsTimer"] = new cTimer();
// Open connection
$conn = ew_Connect();
}
// 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, $BranchDocuments;
if ($BranchDocuments->UseTokenInUrl) {
if ($objForm)
return ($BranchDocuments->TableVar == $objForm->GetValue("t"));
if (@$_GET["t"] <> "")
return ($BranchDocuments->TableVar == $_GET["t"]);
} else {
return TRUE;
}
}
//
// Page_Init
//
function Page_Init() {
global $gsExport, $gsExportFile, $UserProfile, $Language, $Security, $objForm;
global $BranchDocuments;
// User profile
$UserProfile = new cUserProfile();
$UserProfile->LoadProfile(@$_SESSION[EW_SESSION_USER_PROFILE]);
// Security
$Security = new cAdvancedSecurity();
if (IsPasswordExpired())
$this->Page_Terminate("changepwd.php");
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->CanAdd()) {
$Security->SaveLastUrl();
$this->Page_Terminate("BranchDocumentslist.php");
}
$Security->UserID_Loading();
if ($Security->IsLoggedIn()) $Security->LoadUserID();
$Security->UserID_Loaded();
// 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 = "";
var $lPriv = 0;
//
// Page main
//
function Page_Main() {
global $objForm, $Language, $gsFormError, $BranchDocuments;
// Load key values from QueryString
$bCopy = TRUE;
if (@$_GET["BranchDocID"] != "") {
$BranchDocuments->BranchDocID->setQueryStringValue($_GET["BranchDocID"]);
} else {
$bCopy = FALSE;
}
// Set up master/detail parameters
$this->SetUpMasterDetail();
// Process form if post back
if (@$_POST["a_add"] <> "") {
$BranchDocuments->CurrentAction = $_POST["a_add"]; // Get form action
$this->GetUploadFiles(); // Get upload files
$this->LoadFormValues(); // Load form values
// Validate form
if (!$this->ValidateForm()) {
$BranchDocuments->CurrentAction = "I"; // Form error, reset action
$this->setMessage($gsFormError);
}
} else { // Not post back
if ($bCopy) {
$BranchDocuments->CurrentAction = "C"; // Copy record
} else {
$BranchDocuments->CurrentAction = "I"; // Display blank record
$this->LoadDefaultValues(); // Load default values
}
}
// Perform action based on action code
switch ($BranchDocuments->CurrentAction) {
case "I": // Blank record, no action required
break;
case "C": // Copy an existing record
if (!$this->LoadRow()) { // Load record based on key
$this->setMessage($Language->Phrase("NoRecord")); // No record found
$this->Page_Terminate("BranchDocumentslist.php"); // No matching record, return to list
}
break;
case "A": // ' Add new record
$BranchDocuments->SendEmail = TRUE; // Send email on add success
if ($this->AddRow()) { // Add successful
$this->setMessage($Language->Phrase("AddSuccess")); // Set up success message
$sReturnUrl = $BranchDocuments->getReturnUrl();
if (ew_GetPageName($sReturnUrl) == "BranchDocumentsview.php")
$sReturnUrl = $BranchDocuments->ViewUrl(); // View paging, return to view page with keyurl directly
$this->Page_Terminate($sReturnUrl); // Clean up and return
} else {
$this->RestoreFormValues(); // Add failed, restore form values
}
}
// Render row based on row type
$BranchDocuments->RowType = EW_ROWTYPE_ADD; // Render add type
// Render row
$this->RenderRow();
}
// Get upload files
function GetUploadFiles() {
global $objForm, $BranchDocuments;
// Get upload data
if ($BranchDocuments->Document->Upload->UploadFile()) {
// No action required
} else {
echo $BranchDocuments->Document->Upload->Message;
$this->Page_Terminate();
exit();
}
}
// Load default values
function LoadDefaultValues() {
global $BranchDocuments;
$BranchDocuments->Document->CurrentValue = NULL; // Clear file related field
}
// Load form values
function LoadFormValues() {
// Load from form
global $objForm, $BranchDocuments;
$BranchDocuments->BranchID->setFormValue($objForm->GetValue("x_BranchID"));
$BranchDocuments->Category->setFormValue($objForm->GetValue("x_Category"));
$BranchDocuments->DocName->setFormValue($objForm->GetValue("x_DocName"));
$BranchDocuments->SortOrder->setFormValue($objForm->GetValue("x_SortOrder"));
$BranchDocuments->BranchDocID->setFormValue($objForm->GetValue("x_BranchDocID"));
}
// Restore form values
function RestoreFormValues() {
global $objForm, $BranchDocuments;
$BranchDocuments->BranchDocID->CurrentValue = $BranchDocuments->BranchDocID->FormValue;
$BranchDocuments->BranchID->CurrentValue = $BranchDocuments->BranchID->FormValue;
$BranchDocuments->Category->CurrentValue = $BranchDocuments->Category->FormValue;
$BranchDocuments->DocName->CurrentValue = $BranchDocuments->DocName->FormValue;
$BranchDocuments->SortOrder->CurrentValue = $BranchDocuments->SortOrder->FormValue;
}
// Load row based on key values
function LoadRow() {
global $conn, $Security, $BranchDocuments;
$sFilter = $BranchDocuments->KeyFilter();
// Call Row Selecting event
$BranchDocuments->Row_Selecting($sFilter);
// Load SQL based on filter
$BranchDocuments->CurrentFilter = $sFilter;
$sSql = $BranchDocuments->SQL();
$res = FALSE;
$rs = ew_LoadRecordset($sSql);
if ($rs && !$rs->EOF) {
$res = TRUE;
$this->LoadRowValues($rs); // Load row values
// Call Row Selected event
$BranchDocuments->Row_Selected($rs);
$rs->Close();
}
return $res;
}
// Load row values from recordset
function LoadRowValues(&$rs) {
global $conn, $BranchDocuments;
$BranchDocuments->BranchDocID->setDbValue($rs->fields('BranchDocID'));
$BranchDocuments->BranchID->setDbValue($rs->fields('BranchID'));
$BranchDocuments->Category->setDbValue($rs->fields('Category'));
$BranchDocuments->Document->Upload->DbValue = $rs->fields('Document');
$BranchDocuments->DocName->setDbValue($rs->fields('DocName'));
$BranchDocuments->SortOrder->setDbValue($rs->fields('SortOrder'));
}
// Render row values based on field settings
function RenderRow() {
global $conn, $Security, $Language, $BranchDocuments;
// Initialize URLs
// Call Row_Rendering event
$BranchDocuments->Row_Rendering();
// Common render codes for all row types
// BranchID
$BranchDocuments->BranchID->CellCssStyle = ""; $BranchDocuments->BranchID->CellCssClass = "";
$BranchDocuments->BranchID->CellAttrs = array(); $BranchDocuments->BranchID->ViewAttrs = array(); $BranchDocuments->BranchID->EditAttrs = array();
// Category
$BranchDocuments->Category->CellCssStyle = ""; $BranchDocuments->Category->CellCssClass = "";
$BranchDocuments->Category->CellAttrs = array(); $BranchDocuments->Category->ViewAttrs = array(); $BranchDocuments->Category->EditAttrs = array();
// Document
$BranchDocuments->Document->CellCssStyle = ""; $BranchDocuments->Document->CellCssClass = "";
$BranchDocuments->Document->CellAttrs = array(); $BranchDocuments->Document->ViewAttrs = array(); $BranchDocuments->Document->EditAttrs = array();
// DocName
$BranchDocuments->DocName->CellCssStyle = ""; $BranchDocuments->DocName->CellCssClass = "";
$BranchDocuments->DocName->CellAttrs = array(); $BranchDocuments->DocName->ViewAttrs = array(); $BranchDocuments->DocName->EditAttrs = array();
// SortOrder
$BranchDocuments->SortOrder->CellCssStyle = ""; $BranchDocuments->SortOrder->CellCssClass = "";
$BranchDocuments->SortOrder->CellAttrs = array(); $BranchDocuments->SortOrder->ViewAttrs = array(); $BranchDocuments->SortOrder->EditAttrs = array();
if ($BranchDocuments->RowType == EW_ROWTYPE_VIEW) { // View row
// BranchDocID
$BranchDocuments->BranchDocID->ViewValue = $BranchDocuments->BranchDocID->CurrentValue;
$BranchDocuments->BranchDocID->CssStyle = "";
$BranchDocuments->BranchDocID->CssClass = "";
$BranchDocuments->BranchDocID->ViewCustomAttributes = "";
// BranchID
$BranchDocuments->BranchID->ViewValue = $BranchDocuments->BranchID->CurrentValue;
$BranchDocuments->BranchID->CssStyle = "";
$BranchDocuments->BranchID->CssClass = "";
$BranchDocuments->BranchID->ViewCustomAttributes = "";
// Category
if (strval($BranchDocuments->Category->CurrentValue) <> "") {
switch ($BranchDocuments->Category->CurrentValue) {
case "Agenda Minutes":
$BranchDocuments->Category->ViewValue = "Agenda Minutes";
break;
case "General Correspondence":
$BranchDocuments->Category->ViewValue = "General Correspondence";
break;
default:
$BranchDocuments->Category->ViewValue = $BranchDocuments->Category->CurrentValue;
}
} else {
$BranchDocuments->Category->ViewValue = NULL;
}
$BranchDocuments->Category->CssStyle = "";
$BranchDocuments->Category->CssClass = "";
$BranchDocuments->Category->ViewCustomAttributes = "";
// Document
if (!ew_Empty($BranchDocuments->Document->Upload->DbValue)) {
$BranchDocuments->Document->ViewValue = $BranchDocuments->Document->Upload->DbValue;
} else {
$BranchDocuments->Document->ViewValue = "";
}
$BranchDocuments->Document->CssStyle = "";
$BranchDocuments->Document->CssClass = "";
$BranchDocuments->Document->ViewCustomAttributes = "";
// DocName
$BranchDocuments->DocName->ViewValue = $BranchDocuments->DocName->CurrentValue;
$BranchDocuments->DocName->CssStyle = "";
$BranchDocuments->DocName->CssClass = "";
$BranchDocuments->DocName->ViewCustomAttributes = "";
// SortOrder
$BranchDocuments->SortOrder->ViewValue = $BranchDocuments->SortOrder->CurrentValue;
$BranchDocuments->SortOrder->CssStyle = "";
$BranchDocuments->SortOrder->CssClass = "";
$BranchDocuments->SortOrder->ViewCustomAttributes = "";
// BranchID
$BranchDocuments->BranchID->HrefValue = "";
$BranchDocuments->BranchID->TooltipValue = "";
// Category
$BranchDocuments->Category->HrefValue = "";
$BranchDocuments->Category->TooltipValue = "";
// Document
if (!ew_Empty($BranchDocuments->Document->Upload->DbValue)) {
$BranchDocuments->Document->HrefValue = ew_UploadPathEx(FALSE, $BranchDocuments->Document->UploadPath) . ((!empty($BranchDocuments->Document->ViewValue)) ? $BranchDocuments->Document->ViewValue : $BranchDocuments->Document->CurrentValue);
if ($BranchDocuments->Export <> "") $BranchDocuments->Document->HrefValue = ew_ConvertFullUrl($BranchDocuments->Document->HrefValue);
} else {
$BranchDocuments->Document->HrefValue = "";
}
$BranchDocuments->Document->TooltipValue = "";
// DocName
$BranchDocuments->DocName->HrefValue = "";
$BranchDocuments->DocName->TooltipValue = "";
// SortOrder
$BranchDocuments->SortOrder->HrefValue = "";
$BranchDocuments->SortOrder->TooltipValue = "";
} elseif ($BranchDocuments->RowType == EW_ROWTYPE_ADD) { // Add row
// BranchID
$BranchDocuments->BranchID->EditCustomAttributes = "";
if ($BranchDocuments->BranchID->getSessionValue() <> "") {
$BranchDocuments->BranchID->CurrentValue = $BranchDocuments->BranchID->getSessionValue();
$BranchDocuments->BranchID->ViewValue = $BranchDocuments->BranchID->CurrentValue;
$BranchDocuments->BranchID->CssStyle = "";
$BranchDocuments->BranchID->CssClass = "";
$BranchDocuments->BranchID->ViewCustomAttributes = "";
} else {
$BranchDocuments->BranchID->EditValue = ew_HtmlEncode($BranchDocuments->BranchID->CurrentValue);
}
// Category
$BranchDocuments->Category->EditCustomAttributes = "";
$arwrk = array();
$arwrk[] = array("Agenda Minutes", "Agenda Minutes");
$arwrk[] = array("General Correspondence", "General Correspondence");
array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
$BranchDocuments->Category->EditValue = $arwrk;
// Document
$BranchDocuments->Document->EditCustomAttributes = "";
if (!ew_Empty($BranchDocuments->Document->Upload->DbValue)) {
$BranchDocuments->Document->EditValue = $BranchDocuments->Document->Upload->DbValue;
} else {
$BranchDocuments->Document->EditValue = "";
}
// DocName
$BranchDocuments->DocName->EditCustomAttributes = "";
$BranchDocuments->DocName->EditValue = ew_HtmlEncode($BranchDocuments->DocName->CurrentValue);
// SortOrder
$BranchDocuments->SortOrder->EditCustomAttributes = "";
$BranchDocuments->SortOrder->EditValue = ew_HtmlEncode($BranchDocuments->SortOrder->CurrentValue);
}
// Call Row Rendered event
if ($BranchDocuments->RowType <> EW_ROWTYPE_AGGREGATEINIT)
$BranchDocuments->Row_Rendered();
}
// Validate form
function ValidateForm() {
global $Language, $gsFormError, $BranchDocuments;
// Initialize form error message
$gsFormError = "";
if (!ew_CheckFileType($BranchDocuments->Document->Upload->FileName)) {
$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
$gsFormError .= $Language->Phrase("WrongFileType");
}
if ($BranchDocuments->Document->Upload->FileSize > 0 && EW_MAX_FILE_SIZE > 0 && $BranchDocuments->Document->Upload->FileSize > EW_MAX_FILE_SIZE) {
$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
$gsFormError .= str_replace("%s", EW_MAX_FILE_SIZE, $Language->Phrase("MaxFileSize"));
}
if (in_array($BranchDocuments->Document->Upload->Error, array(1, 2, 3, 6, 7, 8))) {
$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
$gsFormError .= $Language->Phrase("PhpUploadErr" . $BranchDocuments->Document->Upload->Error);
}
// Check if validation required
if (!EW_SERVER_VALIDATE)
return ($gsFormError == "");
if (!ew_CheckInteger($BranchDocuments->SortOrder->FormValue)) {
if ($gsFormError <> "") $gsFormError .= "<br>";
$gsFormError .= $BranchDocuments->SortOrder->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;
}
// Add record
function AddRow() {
global $conn, $Language, $Security, $BranchDocuments;
$rsnew = array();
// BranchID
$BranchDocuments->BranchID->SetDbValueDef($rsnew, $BranchDocuments->BranchID->CurrentValue, NULL, FALSE);
// Category
$BranchDocuments->Category->SetDbValueDef($rsnew, $BranchDocuments->Category->CurrentValue, NULL, FALSE);
// Document
$BranchDocuments->Document->Upload->SaveToSession(); // Save file value to Session
if (is_null($BranchDocuments->Document->Upload->Value)) {
$rsnew['Document'] = NULL;
} else {
$rsnew['Document'] = ew_UploadFileNameEx(ew_UploadPathEx(TRUE, $BranchDocuments->Document->UploadPath), $BranchDocuments->Document->Upload->FileName);
}
// DocName
$BranchDocuments->DocName->SetDbValueDef($rsnew, $BranchDocuments->DocName->CurrentValue, NULL, FALSE);
// SortOrder
$BranchDocuments->SortOrder->SetDbValueDef($rsnew, $BranchDocuments->SortOrder->CurrentValue, NULL, FALSE);
// Call Row Inserting event
$bInsertRow = $BranchDocuments->Row_Inserting($rsnew);
if ($bInsertRow) {
if (!ew_Empty($BranchDocuments->Document->Upload->Value)) {
if ($BranchDocuments->Document->Upload->FileName == $BranchDocuments->Document->Upload->DbValue) { // Overwrite if same file name
$BranchDocuments->Document->Upload->SaveToFile($BranchDocuments->Document->UploadPath, $rsnew['Document'], TRUE);
$BranchDocuments->Document->Upload->DbValue = ""; // No need to delete any more
} else {
$BranchDocuments->Document->Upload->SaveToFile($BranchDocuments->Document->UploadPath, $rsnew['Document'], FALSE);
}
}
if ($BranchDocuments->Document->Upload->Action == "2" || $BranchDocuments->Document->Upload->Action == "3") { // Update/Remove
if ($BranchDocuments->Document->Upload->DbValue <> "")
@unlink(ew_UploadPathEx(TRUE, $BranchDocuments->Document->UploadPath) . $BranchDocuments->Document->Upload->DbValue);
}
$conn->raiseErrorFn = 'ew_ErrorFn';
$AddRow = $conn->Execute($BranchDocuments->InsertSQL($rsnew));
$conn->raiseErrorFn = '';
} else {
if ($BranchDocuments->CancelMessage <> "") {
$this->setMessage($BranchDocuments->CancelMessage);
$BranchDocuments->CancelMessage = "";
} else {
$this->setMessage($Language->Phrase("InsertCancelled"));
}
$AddRow = FALSE;
}
if ($AddRow) {
$BranchDocuments->BranchDocID->setDbValue($conn->Insert_ID());
$rsnew['BranchDocID'] = $BranchDocuments->BranchDocID->DbValue;
// Call Row Inserted event
$BranchDocuments->Row_Inserted($rsnew);
$this->WriteAuditTrailOnAdd($rsnew);
}
// Document
$BranchDocuments->Document->Upload->RemoveFromSession(); // Remove file value from Session
return $AddRow;
}
// Set up master/detail based on QueryString
function SetUpMasterDetail() {
global $BranchDocuments;
$bValidMaster = FALSE;
// Get the keys for master table
if (@$_GET[EW_TABLE_SHOW_MASTER] <> "") {
$sMasterTblVar = $_GET[EW_TABLE_SHOW_MASTER];
if ($sMasterTblVar == "") {
$bValidMaster = TRUE;
$this->sDbMasterFilter = "";
$this->sDbDetailFilter = "";
}
if ($sMasterTblVar == "SAACEBranches") {
$bValidMaster = TRUE;
$this->sDbMasterFilter = $BranchDocuments->SqlMasterFilter_SAACEBranches();
$this->sDbDetailFilter = $BranchDocuments->SqlDetailFilter_SAACEBranches();
if (@$_GET["SAACEBranchID"] <> "") {
$GLOBALS["SAACEBranches"]->SAACEBranchID->setQueryStringValue($_GET["SAACEBranchID"]);
$BranchDocuments->BranchID->setQueryStringValue($GLOBALS["SAACEBranches"]->SAACEBranchID->QueryStringValue);
$BranchDocuments->BranchID->setSessionValue($BranchDocuments->BranchID->QueryStringValue);
if (!is_numeric($GLOBALS["SAACEBranches"]->SAACEBranchID->QueryStringValue)) $bValidMaster = FALSE;
$this->sDbMasterFilter = str_replace("@SAACEBranchID@", ew_AdjustSql($GLOBALS["SAACEBranches"]->SAACEBranchID->QueryStringValue), $this->sDbMasterFilter);
$this->sDbDetailFilter = str_replace("@BranchID@", ew_AdjustSql($GLOBALS["SAACEBranches"]->SAACEBranchID->QueryStringValue), $this->sDbDetailFilter);
} else {
$bValidMaster = FALSE;
}
}
}
if ($bValidMaster) {
// Save current master table
$BranchDocuments->setCurrentMasterTable($sMasterTblVar);
// Reset start record counter (new master key)
$this->lStartRec = 1;
$BranchDocuments->setStartRecordNumber($this->lStartRec);
$BranchDocuments->setMasterFilter($this->sDbMasterFilter); // Set up master filter
$BranchDocuments->setDetailFilter($this->sDbDetailFilter); // Set up detail filter
// Clear previous master key from Session
if ($sMasterTblVar <> "SAACEBranches") {
if ($BranchDocuments->BranchID->QueryStringValue == "") $BranchDocuments->BranchID->setSessionValue("");
}
} else {
$this->sDbMasterFilter = $BranchDocuments->getMasterFilter(); // Restore master filter
$this->sDbDetailFilter = $BranchDocuments->getDetailFilter(); // Restore detail filter
}
}
// Write Audit Trail start/end for grid update
function WriteAuditTrailDummy($typ) {
$table = 'BranchDocuments';
$usr = CurrentUserID();
ew_WriteAuditTrail("log", ew_StdCurrentDateTime(), ew_ScriptName(), $usr, $typ, $table, "", "", "", "");
}
// Write Audit Trail (add page)
function WriteAuditTrailOnAdd(&$rs) {
global $BranchDocuments;
$table = 'BranchDocuments';
// Get key value
$key = "";
if ($key <> "") $key .= EW_COMPOSITE_KEY_SEPARATOR;
$key .= $rs['BranchDocID'];
// Write Audit Trail
$dt = ew_StdCurrentDateTime();
$id = ew_ScriptName();
$usr = CurrentUserID();
foreach (array_keys($rs) as $fldname) {
if ($BranchDocuments->fields[$fldname]->FldDataType <> EW_DATATYPE_BLOB) { // Ignore BLOB fields
if ($BranchDocuments->fields[$fldname]->FldDataType == EW_DATATYPE_MEMO) {
$newvalue = "<MEMO>"; // Memo Field
} elseif ($BranchDocuments->fields[$fldname]->FldDataType == EW_DATATYPE_XML) {
$newvalue = "<XML>"; // XML Field
} else {
$newvalue = $rs[$fldname];
}
ew_WriteAuditTrail("log", $dt, $id, $usr, "A", $table, $fldname, $key, "", $newvalue);
}
}
}
// 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;
}
}
?>