OK, I'm new to PHP and SQL so you'll probably have to explain most tings in laimen terms!
I have created a website with PHPMaker, a kind of loaning libary where stock gets loaned out and out and then returned. Now it works all ok, however I want to be able to ad multiple items to a 'loan'
At the moment, I have to add a 'loan' to each item that is taken out, but when there are multiple items, I can't figure out how to get them all in at the same time. At the moment the code looks like this for the add page
<?php
session_start(); // Initialize session data
ob_start(); // Turn on output buffering
?>
<?php include "ewcfg6.php" ?>
<?php include "ewmysql6.php" ?>
<?php include "phpfn6.php" ?>
<?php include "loansinfo.php" ?>
<?php include "propsinfo.php" ?>
<?php include "usersinfo.php" ?>
<?php include "userfn6.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
// Define page object
$loans_add = new cloans_add();
$Page =& $loans_add;
// Page init processing
$loans_add->Page_Init();
// Page main processing
$loans_add->Page_Main();
?>
<?php include "header.php" ?>
<script type="text/javascript">
<!--
// Create page object
var loans_add = new ew_Page("loans_add");
// page properties
loans_add.PageID = "add"; // page ID
var EW_PAGE_ID = loans_add.PageID; // for backward compatibility
// extend page with ValidateForm function
loans_add.ValidateForm = function(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 + "_id"];
if (elm && !ew_HasValue(elm))
return ew_OnError(this, elm, "Please enter required field - UniqueID");
elm = fobj.elements["x" + infix + "_owner"];
if (elm && !ew_HasValue(elm))
return ew_OnError(this, elm, "Please enter required field - Loaned To");
elm = fobj.elements["x" + infix + "_location"];
if (elm && !ew_HasValue(elm))
return ew_OnError(this, elm, "Please enter required field - Location");
elm = fobj.elements["x" + infix + "_loaned_date"];
if (elm && !ew_HasValue(elm))
return ew_OnError(this, elm, "Please enter required field - Loaned Date");
elm = fobj.elements["x" + infix + "_loaned_date"];
if (elm && !ew_CheckEuroDate(elm.value))
return ew_OnError(this, elm, "Incorrect date, format = dd/mm/yyyy - Loaned Date");
elm = fobj.elements["x" + infix + "_return_date"];
if (elm && !ew_HasValue(elm))
return ew_OnError(this, elm, "Please enter required field - Return Date");
elm = fobj.elements["x" + infix + "_return_date"];
if (elm && !ew_CheckEuroDate(elm.value))
return ew_OnError(this, elm, "Incorrect date, format = dd/mm/yyyy - Return Date");
elm = fobj.elements["x" + infix + "_returned"];
if (elm && !ew_HasValue(elm))
return ew_OnError(this, elm, "Please enter required field - Returned Status");
elm = fobj.elements["x" + infix + "_deposit_return"];
if (elm && !ew_HasValue(elm))
return ew_OnError(this, elm, "Please enter required field - Deposit Status");
elm = fobj.elements["x" + infix + "_deposit"];
if (elm && !ew_HasValue(elm))
return ew_OnError(this, elm, "Please enter required field - Deposit £");
elm = fobj.elements["x" + infix + "_cost"];
if (elm && !ew_HasValue(elm))
return ew_OnError(this, elm, "Please enter required field - Hire Charge £");
elm = fobj.elements["x" + infix + "_charge"];
if (elm && !ew_HasValue(elm))
return ew_OnError(this, elm, "Please enter required field - Total Charge £");
elm = fobj.elements["x" + infix + "_paid"];
if (elm && !ew_HasValue(elm))
return ew_OnError(this, elm, "Please enter required field - Paid");
// Call Form Custom Validate event
if (!this.Form_CustomValidate(fobj)) return false;
}
return true;
}
// extend page with Form_CustomValidate function
loans_add.Form_CustomValidate =
function(fobj) { // DO NOT CHANGE THIS LINE!
// Your custom validation code here, return false if invalid.
return true;
}
loans_add.SelectAllKey = function(elem) {
ew_SelectAll(elem);
}
<?php if (EW_CLIENT_VALIDATE) { ?>
loans_add.ValidateRequired = true; // uses JavaScript validation
<?php } else { ?>
loans_add.ValidateRequired = false; // no JavaScript validation
<?php } ?>
// search highlight properties
loans_add.ShowHighlightText = "Show highlight";
loans_add.HideHighlightText = "Hide highlight";
//-->
</script>
<link rel="stylesheet" type="text/css" media="all" href="calendar/calendar-win2k-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 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">Add to TABLE: Loans<br><br>
<a href="<?php echo $loans->getReturnUrl() ?>">Go Back</a></span></p>
<?php $loans_add->ShowMessage() ?>
<form name="floansadd" id="floansadd" action="<?php echo ew_CurrentPage() ?>" method="post" onsubmit="return loans_add.ValidateForm(this);">
<p>
<input type="hidden" name="t" id="t" value="loans">
<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 ($loans->id->Visible) { // id ?>
<tr<?php echo $loans->id->RowAttributes ?>>
<td class="ewTableHeader">UniqueID<span class="ewRequired"> *</span></td>
<td<?php echo $loans->id->CellAttributes() ?>><span id="el_id">
<?php if ($loans->id->getSessionValue() <> "") { ?>
<div<?php echo $loans->id->ViewAttributes() ?>><?php echo $loans->id->ViewValue ?></div>
<input type="hidden" id="x_id" name="x_id" value="<?php echo ew_HtmlEncode($loans->id->CurrentValue) ?>">
<?php } else { ?>
<div id="as_x_id" style="z-index: 8980">
<input type="text" name="sv_x_id" id="sv_x_id" value="<?php echo $loans->id->EditValue ?>" size="30"<?php echo $loans->id->EditAttributes() ?>> <span id="em_x_id" class="ewMessage" style="display: none"><img src="images/alert-small.gif" alt="Value does not exist" width="16" height="16" border="0"></span>
<div id="sc_x_id"></div>
</div>
<input type="hidden" name="x_id" id="x_id" value="<?php echo $loans->id->CurrentValue ?>">
<?php
$sSqlWrk = "SELECT `id` FROM `props` WHERE (`id` = {query_value})";
$sSqlWrk = TEAencrypt($sSqlWrk, EW_RANDOM_KEY);
?>
<input type="hidden" name="s_x_id" id="s_x_id" value="<?php echo $sSqlWrk ?>">
<script type="text/javascript">
<!--
var oas_x_id = new ew_AutoSuggest("sv_x_id", "sc_x_id", "s_x_id", "em_x_id", "x_id", "", false);
//-->
</script>
<?php } ?>
</span><?php echo $loans->id->CustomMsg ?></td>
</tr>
<?php } ?>
<?php if ($loans->owner->Visible) { // owner ?>
<tr<?php echo $loans->owner->RowAttributes ?>>
<td class="ewTableHeader">Loaned To<span class="ewRequired"> *</span></td>
<td<?php echo $loans->owner->CellAttributes() ?>><span id="el_owner">
<select id="x_owner" name="x_owner"<?php echo $loans->owner->EditAttributes() ?>>
<?php
if (is_array($loans->owner->EditValue)) {
$arwrk = $loans->owner->EditValue;
$rowswrk = count($arwrk);
$emptywrk = TRUE;
for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
$selwrk = (strval($loans->owner->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 $loans->owner->CustomMsg ?></td>
</tr>
<?php } ?>
<?php if ($loans->location->Visible) { // location ?>
<tr<?php echo $loans->location->RowAttributes ?>>
<td class="ewTableHeader">Location<span class="ewRequired"> *</span></td>
<td<?php echo $loans->location->CellAttributes() ?>><span id="el_location">
<select id="x_location" name="x_location"<?php echo $loans->location->EditAttributes() ?>>
<?php
if (is_array($loans->location->EditValue)) {
$arwrk = $loans->location->EditValue;
$rowswrk = count($arwrk);
$emptywrk = TRUE;
for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
$selwrk = (strval($loans->location->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 $loans->location->CustomMsg ?></td>
</tr>
<?php } ?>
<?php if ($loans->show->Visible) { // show ?>
<tr<?php echo $loans->show->RowAttributes ?>>
<td class="ewTableHeader">Show<span class="ewRequired"> *</span></td>
<td<?php echo $loans->show->CellAttributes() ?>><span id="el_show">
<input type="text" name="x_show" id="x_show" size="30" maxlength="50" value="<?php echo $loans->show->EditValue ?>"<?php echo $loans->show->EditAttributes() ?>>
</span><?php echo $loans->show->CustomMsg ?></td>
</tr>
<?php } ?>
<?php if ($loans->loaned_date->Visible) { // loaned_date ?>
<tr<?php echo $loans->loaned_date->RowAttributes ?>>
<td class="ewTableHeader">Loaned Date<span class="ewRequired"> *</span></td>
<td<?php echo $loans->loaned_date->CellAttributes() ?>><span id="el_loaned_date">
<input type="text" name="x_loaned_date" id="x_loaned_date" value="<?php echo $loans->loaned_date->EditValue ?>"<?php echo $loans->loaned_date->EditAttributes() ?>>
<img src="images/calendar.png" id="cal_x_loaned_date" name="cal_x_loaned_date" alt="Pick a date" style="cursor:pointer;cursor:hand;">
<script type="text/javascript">
Calendar.setup({
inputField : "x_loaned_date", // ID of the input field
ifFormat : "%d/%m/%Y", // the date format
button : "cal_x_loaned_date" // ID of the button
});
</script>
</span><?php echo $loans->loaned_date->CustomMsg ?></td>
</tr>
<?php } ?>
<?php if ($loans->return_date->Visible) { // return_date ?>
<tr<?php echo $loans->return_date->RowAttributes ?>>
<td class="ewTableHeader">Return Date<span class="ewRequired"> *</span></td>
<td<?php echo $loans->return_date->CellAttributes() ?>><span id="el_return_date">
<input type="text" name="x_return_date" id="x_return_date" value="<?php echo $loans->return_date->EditValue ?>"<?php echo $loans->return_date->EditAttributes() ?>>
<img src="images/calendar.png" id="cal_x_return_date" name="cal_x_return_date" alt="Pick a date" style="cursor:pointer;cursor:hand;">
<script type="text/javascript">
Calendar.setup({
inputField : "x_return_date", // ID of the input field
ifFormat : "%d/%m/%Y", // the date format
button : "cal_x_return_date" // ID of the button
});
</script>
</span><?php echo $loans->return_date->CustomMsg ?></td>
</tr>
<?php } ?>
<?php if ($loans->returned->Visible) { // returned ?>
<tr<?php echo $loans->returned->RowAttributes ?>>
<td class="ewTableHeader">Returned Status<span class="ewRequired"> *</span></td>
<td<?php echo $loans->returned->CellAttributes() ?>><span id="el_returned">
<div id="tp_x_returned" class="<?php echo EW_ITEM_TEMPLATE_CLASSNAME ?>"><input type="radio" name="x_returned" id="x_returned" value="{value}"<?php echo $loans->returned->EditAttributes() ?>></div>
<div id="dsl_x_returned" repeatcolumn="5">
<?php
$arwrk = $loans->returned->EditValue;
if (is_array($arwrk)) {
$rowswrk = count($arwrk);
$emptywrk = TRUE;
for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
$selwrk = (strval($loans->returned->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " checked=\"checked\"" : "";
if ($selwrk <> "") $emptywrk = FALSE;
// Note: No spacing within the LABEL tag
?>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 1) ?>
<label><input type="radio" name="x_returned" id="x_returned" value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?><?php echo $loans->returned->EditAttributes() ?>><?php echo $arwrk[$rowcntwrk][1] ?></label>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 2) ?>
<?php
}
}
?>
</div>
</span><?php echo $loans->returned->CustomMsg ?></td>
</tr>
<?php } ?>
<?php if ($loans->deposit_return->Visible) { // deposit_return ?>
<tr<?php echo $loans->deposit_return->RowAttributes ?>>
<td class="ewTableHeader">Deposit Status<span class="ewRequired"> *</span></td>
<td<?php echo $loans->deposit_return->CellAttributes() ?>><span id="el_deposit_return">
<div id="tp_x_deposit_return" class="<?php echo EW_ITEM_TEMPLATE_CLASSNAME ?>"><input type="radio" name="x_deposit_return" id="x_deposit_return" value="{value}"<?php echo $loans->deposit_return->EditAttributes() ?>></div>
<div id="dsl_x_deposit_return" repeatcolumn="5">
<?php
$arwrk = $loans->deposit_return->EditValue;
if (is_array($arwrk)) {
$rowswrk = count($arwrk);
$emptywrk = TRUE;
for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
$selwrk = (strval($loans->deposit_return->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " checked=\"checked\"" : "";
if ($selwrk <> "") $emptywrk = FALSE;
// Note: No spacing within the LABEL tag
?>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 1) ?>
<label><input type="radio" name="x_deposit_return" id="x_deposit_return" value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?><?php echo $loans->deposit_return->EditAttributes() ?>><?php echo $arwrk[$rowcntwrk][1] ?></label>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 2) ?>
<?php
}
}
?>
</div>
</span><?php echo $loans->deposit_return->CustomMsg ?></td>
</tr>
<?php } ?>
<?php if ($loans->condition->Visible) { // condition ?>
<tr<?php echo $loans->condition->RowAttributes ?>>
<td class="ewTableHeader">Condition<span class="ewRequired"> *</span></td>
<td<?php echo $loans->condition->CellAttributes() ?>><span id="el_condition">
<div id="tp_x_condition" class="<?php echo EW_ITEM_TEMPLATE_CLASSNAME ?>"><input type="radio" name="x_condition" id="x_condition" value="{value}"<?php echo $loans->condition->EditAttributes() ?>></div>
<div id="dsl_x_condition" repeatcolumn="5">
<?php
$arwrk = $loans->condition->EditValue;
if (is_array($arwrk)) {
$rowswrk = count($arwrk);
$emptywrk = TRUE;
for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
$selwrk = (strval($loans->condition->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " checked=\"checked\"" : "";
if ($selwrk <> "") $emptywrk = FALSE;
// Note: No spacing within the LABEL tag
?>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 1) ?>
<label><input type="radio" name="x_condition" id="x_condition" value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?><?php echo $loans->condition->EditAttributes() ?>><?php echo $arwrk[$rowcntwrk][1] ?></label>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 2) ?>
<?php
}
}
?>
</div>
</span><?php echo $loans->condition->CustomMsg ?></td>
</tr>
<?php } ?>
<?php if ($loans->deposit->Visible) { // deposit ?>
<tr<?php echo $loans->deposit->RowAttributes ?>>
<td class="ewTableHeader">Deposit £<span class="ewRequired"> *</span></td>
<td<?php echo $loans->deposit->CellAttributes() ?>><span id="el_deposit">
<input type="text" name="x_deposit" id="x_deposit" size="30" maxlength="100" value="<?php echo $loans->deposit->EditValue ?>"<?php echo $loans->deposit->EditAttributes() ?>>
</span><?php echo $loans->deposit->CustomMsg ?></td>
</tr>
<?php } ?>
<?php if ($loans->cost->Visible) { // cost ?>
<tr<?php echo $loans->cost->RowAttributes ?>>
<td class="ewTableHeader">Hire Charge £<span class="ewRequired"> *</span></td>
<td<?php echo $loans->cost->CellAttributes() ?>><span id="el_cost">
<input type="text" name="x_cost" id="x_cost" size="30" maxlength="50" value="<?php echo $loans->cost->EditValue ?>"<?php echo $loans->cost->EditAttributes() ?>>
</span><?php echo $loans->cost->CustomMsg ?></td>
</tr>
<?php } ?>
<?php if ($loans->charge->Visible) { // charge ?>
<tr<?php echo $loans->charge->RowAttributes ?>>
<td class="ewTableHeader">Total Charge £<span class="ewRequired"> *</span></td>
<td<?php echo $loans->charge->CellAttributes() ?>><span id="el_charge">
<input type="text" name="x_charge" id="x_charge" size="30" maxlength="20" value="<?php echo $loans->charge->EditValue ?>"<?php echo $loans->charge->EditAttributes() ?>>
</span><?php echo $loans->charge->CustomMsg ?></td>
</tr>
<?php } ?>
<?php if ($loans->paid->Visible) { // paid ?>
<tr<?php echo $loans->paid->RowAttributes ?>>
<td class="ewTableHeader">Paid<span class="ewRequired"> *</span></td>
<td<?php echo $loans->paid->CellAttributes() ?>><span id="el_paid">
<div id="tp_x_paid" class="<?php echo EW_ITEM_TEMPLATE_CLASSNAME ?>"><input type="radio" name="x_paid" id="x_paid" value="{value}"<?php echo $loans->paid->EditAttributes() ?>></div>
<div id="dsl_x_paid" repeatcolumn="5">
<?php
$arwrk = $loans->paid->EditValue;
if (is_array($arwrk)) {
$rowswrk = count($arwrk);
$emptywrk = TRUE;
for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
$selwrk = (strval($loans->paid->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " checked=\"checked\"" : "";
if ($selwrk <> "") $emptywrk = FALSE;
// Note: No spacing within the LABEL tag
?>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 1) ?>
<label><input type="radio" name="x_paid" id="x_paid" value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?><?php echo $loans->paid->EditAttributes() ?>><?php echo $arwrk[$rowcntwrk][1] ?></label>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 2) ?>
<?php
}
}
?>
</div>
</span><?php echo $loans->paid->CustomMsg ?></td>
</tr>
<?php } ?>
<?php if ($loans->notes->Visible) { // notes ?>
<tr<?php echo $loans->notes->RowAttributes ?>>
<td class="ewTableHeader">Notes<span class="ewRequired"> *</span></td>
<td<?php echo $loans->notes->CellAttributes() ?>><span id="el_notes">
<textarea name="x_notes" id="x_notes" cols="60" rows="6"<?php echo $loans->notes->EditAttributes() ?>><?php echo $loans->notes->EditValue ?></textarea>
</span><?php echo $loans->notes->CustomMsg ?></td>
</tr>
<?php } ?>
</table>
</div>
</td></tr></table>
<p>
<input type="submit" name="btnAction" id="btnAction" value=" Add ">
</form>
<script language="JavaScript" type="text/javascript">
<!--
// Write your table-specific startup script here
// document.write("page loaded");
//-->
</script>
<?php include "footer.php" ?>
<?php
//
// Page Class
//
class cloans_add {
// Page ID
var $PageID = 'add';
// Table Name
var $TableName = 'loans';
// Page Object Name
var $PageObjName = 'loans_add';
// Page Name
function PageName() {
return ew_CurrentPage();
}
// Page Url
function PageUrl() {
$PageUrl = ew_CurrentPage() . "?";
global $loans;
if ($loans->UseTokenInUrl) $PageUrl .= "t=" . $loans->TableVar . "&"; // add page token
return $PageUrl;
}
// 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() {
if ($this->getMessage() <> "") { // Message in Session, display
echo "<p><span class=\"ewMessage\">" . $this->getMessage() . "</span></p>";
$_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
}
}
// Validate Page request
function IsPageRequest() {
global $objForm, $loans;
if ($loans->UseTokenInUrl) {
//IsPageRequest = False
if ($objForm)
return ($loans->TableVar == $objForm->GetValue("t"));
if (@$_GET["t"] <> "")
return ($loans->TableVar == $_GET["t"]);
} else {
return TRUE;
}
}
//
// Class initialize
// - init objects
// - open connection
//
function cloans_add() {
global $conn;
// Initialize table object
$GLOBALS["loans"] = new cloans();
// Initialize other table object
$GLOBALS['props'] = new cprops();
// Initialize other table object
$GLOBALS['users'] = new cusers();
// Intialize page id (for backward compatibility)
if (!defined("EW_PAGE_ID"))
define("EW_PAGE_ID", 'add', TRUE);
// Initialize table name (for backward compatibility)
if (!defined("EW_TABLE_NAME"))
define("EW_TABLE_NAME", 'loans', TRUE);
// Open connection to the database
$conn = ew_Connect();
}
//
// Page_Init
//
function Page_Init() {
global $gsExport, $gsExportFile, $loans;
global $Security;
$Security = new cAdvancedSecurity();
if (!$Security->IsLoggedIn()) $Security->AutoLogin();
if (!$Security->IsLoggedIn()) {
$Security->SaveLastUrl();
$this->Page_Terminate("login.php");
}
// Global page loading event (in userfn6.php)
Page_Loading();
// Page load event, used in current page
$this->Page_Load();
}
//
// Page_Terminate
// - called when exit page
// - if URL specified, redirect to the URL
//
function Page_Terminate($url = "") {
global $conn;
// Page unload event, used in current page
$this->Page_Unload();
// Global page unloaded event (in userfn*.php)
Page_Unloaded();
// Close Connection
$conn->Close();
// Go to URL if specified
if ($url <> "") {
ob_end_clean();
header("Location: $url");
}
exit();
}
var $x_ewPriv = 0;
//
// Page main processing
//
function Page_Main() {
global $objForm, $gsFormError, $loans;
// Load key values from QueryString
$bCopy = TRUE;
if (@$_GET["loanid"] != "") {
$loans->loanid->setQueryStringValue($_GET["loanid"]);
} else {
$bCopy = FALSE;
}
// Create form object
$objForm = new cFormObj();
// Process form if post back
if (@$_POST["a_add"] <> "") {
$loans->CurrentAction = $_POST["a_add"]; // Get form action
$this->LoadFormValues(); // Load form values
// Validate Form
if (!$this->ValidateForm()) {
$loans->CurrentAction = "I"; // Form error, reset action
$this->setMessage($gsFormError);
}
} else { // Not post back
if ($bCopy) {
$loans->CurrentAction = "C"; // Copy Record
} else {
$loans->CurrentAction = "I"; // Display Blank Record
$this->LoadDefaultValues(); // Load default values
}
}
// Perform action based on action code
switch ($loans->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("No records found"); // No record found
$this->Page_Terminate("loanslist.php"); // No matching record, return to list
}
break;
case "A": // ' Add new record
$loans->SendEmail = TRUE; // Send email on add success
if ($this->AddRow()) { // Add successful
$this->setMessage("Add succeeded"); // Set up success message
$sReturnUrl = $loans->getReturnUrl();
$this->Page_Terminate($sReturnUrl); // Clean up and return
} else {
$this->RestoreFormValues(); // Add failed, restore form values
}
}
// Render row based on row type
$loans->RowType = EW_ROWTYPE_ADD; // Render add type
// Render row
$this->RenderRow();
}
// Get upload files
function GetUploadFiles() {
global $objForm, $loans;
// Get upload data
}
// Load default values
function LoadDefaultValues() {
global $loans;
$loans->returned->CurrentValue = N;
$loans->deposit->CurrentValue = 0.00;
$loans->cost->CurrentValue = 0.00;
$loans->charge->CurrentValue = 0.00;
$loans->paid->CurrentValue = Due;
}
// Load form values
function LoadFormValues() {
// Load from form
global $objForm, $loans;
$loans->id->setFormValue($objForm->GetValue("x_id"));
$loans->owner->setFormValue($objForm->GetValue("x_owner"));
$loans->location->setFormValue($objForm->GetValue("x_location"));
$loans->show->setFormValue($objForm->GetValue("x_show"));
$loans->loaned_date->setFormValue($objForm->GetValue("x_loaned_date"));
$loans->loaned_date->CurrentValue = ew_UnFormatDateTime($loans->loaned_date->CurrentValue, 7);
$loans->return_date->setFormValue($objForm->GetValue("x_return_date"));
$loans->return_date->CurrentValue = ew_UnFormatDateTime($loans->return_date->CurrentValue, 7);
$loans->returned->setFormValue($objForm->GetValue("x_returned"));
$loans->deposit_return->setFormValue($objForm->GetValue("x_deposit_return"));
$loans->condition->setFormValue($objForm->GetValue("x_condition"));
$loans->deposit->setFormValue($objForm->GetValue("x_deposit"));
$loans->cost->setFormValue($objForm->GetValue("x_cost"));
$loans->charge->setFormValue($objForm->GetValue("x_charge"));
$loans->paid->setFormValue($objForm->GetValue("x_paid"));
$loans->notes->setFormValue($objForm->GetValue("x_notes"));
$loans->loanid->setFormValue($objForm->GetValue("x_loanid"));
}
// Restore form values
function RestoreFormValues() {
global $loans;
$loans->loanid->CurrentValue = $loans->loanid->FormValue;
$loans->id->CurrentValue = $loans->id->FormValue;
$loans->owner->CurrentValue = $loans->owner->FormValue;
$loans->location->CurrentValue = $loans->location->FormValue;
$loans->show->CurrentValue = $loans->show->FormValue;
$loans->loaned_date->CurrentValue = $loans->loaned_date->FormValue;
$loans->loaned_date->CurrentValue = ew_UnFormatDateTime($loans->loaned_date->CurrentValue, 7);
$loans->return_date->CurrentValue = $loans->return_date->FormValue;
$loans->return_date->CurrentValue = ew_UnFormatDateTime($loans->return_date->CurrentValue, 7);
$loans->returned->CurrentValue = $loans->returned->FormValue;
$loans->deposit_return->CurrentValue = $loans->deposit_return->FormValue;
$loans->condition->CurrentValue = $loans->condition->FormValue;
$loans->deposit->CurrentValue = $loans->deposit->FormValue;
$loans->cost->CurrentValue = $loans->cost->FormValue;
$loans->charge->CurrentValue = $loans->charge->FormValue;
$loans->paid->CurrentValue = $loans->paid->FormValue;
$loans->notes->CurrentValue = $loans->notes->FormValue;
}
// Load row based on key values
function LoadRow() {
global $conn, $Security, $loans;
$sFilter = $loans->KeyFilter();
// Call Row Selecting event
$loans->Row_Selecting($sFilter);
// Load sql based on filter
$loans->CurrentFilter = $sFilter;
$sSql = $loans->SQL();
if ($rs = $conn->Execute($sSql)) {
if ($rs->EOF) {
$LoadRow = FALSE;
} else {
$LoadRow = TRUE;
$rs->MoveFirst();
$this->LoadRowValues($rs); // Load row values
// Call Row Selected event
$loans->Row_Selected($rs);
}
$rs->Close();
} else {
$LoadRow = FALSE;
}
return $LoadRow;
}
// Load row values from recordset
function LoadRowValues(&$rs) {
global $loans;
$loans->loanid->setDbValue($rs->fields('loanid'));
$loans->id->setDbValue($rs->fields('id'));
$loans->owner->setDbValue($rs->fields('owner'));
$loans->location->setDbValue($rs->fields('location'));
$loans->show->setDbValue($rs->fields('show'));
$loans->loaned_date->setDbValue($rs->fields('loaned_date'));
$loans->return_date->setDbValue($rs->fields('return_date'));
$loans->returned->setDbValue($rs->fields('returned'));
$loans->deposit_return->setDbValue($rs->fields('deposit_return'));
$loans->condition->setDbValue($rs->fields('condition'));
$loans->deposit->setDbValue($rs->fields('deposit'));
$loans->cost->setDbValue($rs->fields('cost'));
$loans->charge->setDbValue($rs->fields('charge'));
$loans->paid->setDbValue($rs->fields('paid'));
$loans->notes->setDbValue($rs->fields('notes'));
$loans->userid->setDbValue($rs->fields('userid'));
$loans->updatedate->setDbValue($rs->fields('updatedate'));
}
// Render row values based on field settings
function RenderRow() {
global $conn, $Security, $loans;
// Call Row_Rendering event
$loans->Row_Rendering();
// Common render codes for all row types
// id
$loans->id->CellCssStyle = "";
$loans->id->CellCssClass = "";
// owner
$loans->owner->CellCssStyle = "";
$loans->owner->CellCssClass = "";
// location
$loans->location->CellCssStyle = "";
$loans->location->CellCssClass = "";
// show
$loans->show->CellCssStyle = "";
$loans->show->CellCssClass = "";
// loaned_date
$loans->loaned_date->CellCssStyle = "";
$loans->loaned_date->CellCssClass = "";
// return_date
$loans->return_date->CellCssStyle = "";
$loans->return_date->CellCssClass = "";
// returned
$loans->returned->CellCssStyle = "";
$loans->returned->CellCssClass = "";
// deposit_return
$loans->deposit_return->CellCssStyle = "";
$loans->deposit_return->CellCssClass = "";
// condition
$loans->condition->CellCssStyle = "";
$loans->condition->CellCssClass = "";
// deposit
$loans->deposit->CellCssStyle = "";
$loans->deposit->CellCssClass = "";
// cost
$loans->cost->CellCssStyle = "";
$loans->cost->CellCssClass = "";
// charge
$loans->charge->CellCssStyle = "";
$loans->charge->CellCssClass = "";
// paid
$loans->paid->CellCssStyle = "";
$loans->paid->CellCssClass = "";
// notes
$loans->notes->CellCssStyle = "";
$loans->notes->CellCssClass = "";
if ($loans->RowType == EW_ROWTYPE_VIEW) { // View row
// loanid
$loans->loanid->ViewValue = $loans->loanid->CurrentValue;
$loans->loanid->CssStyle = "";
$loans->loanid->CssClass = "";
$loans->loanid->ViewCustomAttributes = "";
// id
$loans->id->ViewValue = $loans->id->CurrentValue;
if (strval($loans->id->CurrentValue) <> "") {
$sSqlWrk = "SELECT `id` FROM `props` WHERE `id` = " . ew_AdjustSql($loans->id->CurrentValue) . "";
$rswrk = $conn->Execute($sSqlWrk);
if ($rswrk && !$rswrk->EOF) { // Lookup value(s) found
$loans->id->ViewValue = $rswrk->fields('id');
$rswrk->Close();
} else {
$loans->id->ViewValue = $loans->id->CurrentValue;
}
} else {
$loans->id->ViewValue = NULL;
}
$loans->id->CssStyle = "";
$loans->id->CssClass = "";
$loans->id->ViewCustomAttributes = "";
// owner
if (strval($loans->owner->CurrentValue) <> "") {
$sSqlWrk = "SELECT `name` FROM `owners` WHERE `name` = '" . ew_AdjustSql($loans->owner->CurrentValue) . "'";
$sSqlWrk .= " ORDER BY `name` Asc";
$rswrk = $conn->Execute($sSqlWrk);
if ($rswrk && !$rswrk->EOF) { // Lookup value(s) found
$loans->owner->ViewValue = $rswrk->fields('name');
$rswrk->Close();
} else {
$loans->owner->ViewValue = $loans->owner->CurrentValue;
}
} else {
$loans->owner->ViewValue = NULL;
}
$loans->owner->CssStyle = "";
$loans->owner->CssClass = "";
$loans->owner->ViewCustomAttributes = "";
// location
if (strval($loans->location->CurrentValue) <> "") {
$sSqlWrk = "SELECT `name` FROM `location` WHERE `name` = '" . ew_AdjustSql($loans->location->CurrentValue) . "'";
$sSqlWrk .= " ORDER BY `name` Asc";
$rswrk = $conn->Execute($sSqlWrk);
if ($rswrk && !$rswrk->EOF) { // Lookup value(s) found
$loans->location->ViewValue = $rswrk->fields('name');
$rswrk->Close();
} else {
$loans->location->ViewValue = $loans->location->CurrentValue;
}
} else {
$loans->location->ViewValue = NULL;
}
$loans->location->CssStyle = "";
$loans->location->CssClass = "";
$loans->location->ViewCustomAttributes = "";
// show
$loans->show->ViewValue = $loans->show->CurrentValue;
$loans->show->CssStyle = "";
$loans->show->CssClass = "";
$loans->show->ViewCustomAttributes = "";
// loaned_date
$loans->loaned_date->ViewValue = $loans->loaned_date->CurrentValue;
$loans->loaned_date->ViewValue = ew_FormatDateTime($loans->loaned_date->ViewValue, 7);
$loans->loaned_date->CssStyle = "";
$loans->loaned_date->CssClass = "";
$loans->loaned_date->ViewCustomAttributes = "";
// return_date
$loans->return_date->ViewValue = $loans->return_date->CurrentValue;
$loans->return_date->ViewValue = ew_FormatDateTime($loans->return_date->ViewValue, 7);
$loans->return_date->CssStyle = "";
$loans->return_date->CssClass = "";
$loans->return_date->ViewCustomAttributes = "";
// returned
if (strval($loans->returned->CurrentValue) <> "") {
switch ($loans->returned->CurrentValue) {
case "Y":
$loans->returned->ViewValue = "Returned";
break;
case "N":
$loans->returned->ViewValue = "On Loan";
break;
default:
$loans->returned->ViewValue = $loans->returned->CurrentValue;
}
} else {
$loans->returned->ViewValue = NULL;
}
$loans->returned->CssStyle = "";
$loans->returned->CssClass = "";
$loans->returned->ViewCustomAttributes = "";
// deposit_return
if (strval($loans->deposit_return->CurrentValue) <> "") {
switch ($loans->deposit_return->CurrentValue) {
case "Y":
$loans->deposit_return->ViewValue = "Returned";
break;
case "N":
$loans->deposit_return->ViewValue = "Held";
break;
default:
$loans->deposit_return->ViewValue = $loans->deposit_return->CurrentValue;
}
} else {
$loans->deposit_return->ViewValue = NULL;
}
$loans->deposit_return->CssStyle = "";
$loans->deposit_return->CssClass = "";
$loans->deposit_return->ViewCustomAttributes = "";
// condition
if (strval($loans->condition->CurrentValue) <> "") {
switch ($loans->condition->CurrentValue) {
case "1":
$loans->condition->ViewValue = "Excellent";
break;
case "2":
$loans->condition->ViewValue = "Good";
break;
case "3":
$loans->condition->ViewValue = "Damaged";
break;
case "4":
$loans->condition->ViewValue = "Beyond Repair";
break;
default:
$loans->condition->ViewValue = $loans->condition->CurrentValue;
}
} else {
$loans->condition->ViewValue = NULL;
}
$loans->condition->CssStyle = "";
$loans->condition->CssClass = "";
$loans->condition->ViewCustomAttributes = "";
// deposit
$loans->deposit->ViewValue = $loans->deposit->CurrentValue;
$loans->deposit->CssStyle = "";
$loans->deposit->CssClass = "";
$loans->deposit->ViewCustomAttributes = "";
// cost
$loans->cost->ViewValue = $loans->cost->CurrentValue;
$loans->cost->CssStyle = "";
$loans->cost->CssClass = "";
$loans->cost->ViewCustomAttributes = "";
// charge
$loans->charge->ViewValue = $loans->charge->CurrentValue;
$loans->charge->CssStyle = "";
$loans->charge->CssClass = "";
$loans->charge->ViewCustomAttributes = "";
// paid
if (strval($loans->paid->CurrentValue) <> "") {
switch ($loans->paid->CurrentValue) {
case "Due":
$loans->paid->ViewValue = "Due";
break;
case "Paid":
$loans->paid->ViewValue = "Paid";
break;
default:
$loans->paid->ViewValue = $loans->paid->CurrentValue;
}
} else {
$loans->paid->ViewValue = NULL;
}
$loans->paid->CssStyle = "";
$loans->paid->CssClass = "";
$loans->paid->ViewCustomAttributes = "";
// notes
$loans->notes->ViewValue = $loans->notes->CurrentValue;
$loans->notes->CssStyle = "";
$loans->notes->CssClass = "";
$loans->notes->ViewCustomAttributes = "";
// userid
$loans->userid->ViewValue = $loans->userid->CurrentValue;
$loans->userid->CssStyle = "";
$loans->userid->CssClass = "";
$loans->userid->ViewCustomAttributes = "";
// updatedate
$loans->updatedate->ViewValue = $loans->updatedate->CurrentValue;
$loans->updatedate->ViewValue = ew_FormatDateTime($loans->updatedate->ViewValue, 7);
$loans->updatedate->CssStyle = "";
$loans->updatedate->CssClass = "";
$loans->updatedate->ViewCustomAttributes = "";
// id
$loans->id->HrefValue = "";
// owner
$loans->owner->HrefValue = "";
// location
$loans->location->HrefValue = "";
// show
$loans->show->HrefValue = "";
// loaned_date
$loans->loaned_date->HrefValue = "";
// return_date
$loans->return_date->HrefValue = "";
// returned
$loans->returned->HrefValue = "";
// deposit_return
$loans->deposit_return->HrefValue = "";
// condition
$loans->condition->HrefValue = "";
// deposit
$loans->deposit->HrefValue = "";
// cost
$loans->cost->HrefValue = "";
// charge
$loans->charge->HrefValue = "";
// paid
$loans->paid->HrefValue = "";
// notes
$loans->notes->HrefValue = "";
} elseif ($loans->RowType == EW_ROWTYPE_ADD) { // Add row
// id
$loans->id->EditCustomAttributes = "";
if ($loans->id->getSessionValue() <> "") {
$loans->id->CurrentValue = $loans->id->getSessionValue();
$loans->id->ViewValue = $loans->id->CurrentValue;
if (strval($loans->id->CurrentValue) <> "") {
$sSqlWrk = "SELECT `id` FROM `props` WHERE `id` = " . ew_AdjustSql($loans->id->CurrentValue) . "";
$rswrk = $conn->Execute($sSqlWrk);
if ($rswrk && !$rswrk->EOF) { // Lookup value(s) found
$loans->id->ViewValue = $rswrk->fields('id');
$rswrk->Close();
} else {
$loans->id->ViewValue = $loans->id->CurrentValue;
}
} else {
$loans->id->ViewValue = NULL;
}
$loans->id->CssStyle = "";
$loans->id->CssClass = "";
$loans->id->ViewCustomAttributes = "";
} else {
$loans->id->EditValue = ew_HtmlEncode($loans->id->CurrentValue);
if (strval($loans->id->CurrentValue) <> "") {
$sSqlWrk = "SELECT `id` FROM `props` WHERE `id` = " . ew_AdjustSql($loans->id->CurrentValue) . "";
$rswrk = $conn->Execute($sSqlWrk);
if ($rswrk && !$rswrk->EOF) { // Lookup value(s) found
$loans->id->EditValue = $rswrk->fields('id');
$rswrk->Close();
} else {
$loans->id->EditValue = $loans->id->CurrentValue;
}
} else {
$loans->id->EditValue = NULL;
}
}
// owner
$loans->owner->EditCustomAttributes = "";
$sSqlWrk = "SELECT `name`, `name`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `owners`";
$sWhereWrk = "";
if ($sWhereWrk <> "") $sSqlWrk .= " WHERE $sWhereWrk";
$sSqlWrk .= " ORDER BY `name` Asc";
$rswrk = $conn->Execute($sSqlWrk);
$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
if ($rswrk) $rswrk->Close();
array_unshift($arwrk, array("", "Please Select"));
$loans->owner->EditValue = $arwrk;
// location
$loans->location->EditCustomAttributes = "";
$sSqlWrk = "SELECT `name`, `name`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `location`";
$sWhereWrk = "";
if ($sWhereWrk <> "") $sSqlWrk .= " WHERE $sWhereWrk";
$sSqlWrk .= " ORDER BY `name` Asc";
$rswrk = $conn->Execute($sSqlWrk);
$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
if ($rswrk) $rswrk->Close();
array_unshift($arwrk, array("", "Please Select"));
$loans->location->EditValue = $arwrk;
// show
$loans->show->EditCustomAttributes = "";
$loans->show->EditValue = ew_HtmlEncode($loans->show->CurrentValue);
// loaned_date
$loans->loaned_date->EditCustomAttributes = "";
$loans->loaned_date->EditValue = ew_HtmlEncode(ew_FormatDateTime($loans->loaned_date->CurrentValue, 7));
// return_date
$loans->return_date->EditCustomAttributes = "";
$loans->return_date->EditValue = ew_HtmlEncode(ew_FormatDateTime($loans->return_date->CurrentValue, 7));
// returned
$loans->returned->EditCustomAttributes = "";
$arwrk = array();
$arwrk[] = array("Y", "Returned");
$arwrk[] = array("N", "On Loan");
$loans->returned->EditValue = $arwrk;
// deposit_return
$loans->deposit_return->EditCustomAttributes = "";
$arwrk = array();
$arwrk[] = array("Y", "Returned");
$arwrk[] = array("N", "Held");
$loans->deposit_return->EditValue = $arwrk;
// condition
$loans->condition->EditCustomAttributes = "";
$arwrk = array();
$arwrk[] = array("1", "Excellent");
$arwrk[] = array("2", "Good");
$arwrk[] = array("3", "Damaged");
$arwrk[] = array("4", "Beyond Repair");
$loans->condition->EditValue = $arwrk;
// deposit
$loans->deposit->EditCustomAttributes = "";
$loans->deposit->EditValue = ew_HtmlEncode($loans->deposit->CurrentValue);
// cost
$loans->cost->EditCustomAttributes = "";
$loans->cost->EditValue = ew_HtmlEncode($loans->cost->CurrentValue);
// charge
$loans->charge->EditCustomAttributes = "";
$loans->charge->EditValue = ew_HtmlEncode($loans->charge->CurrentValue);
// paid
$loans->paid->EditCustomAttributes = "";
$arwrk = array();
$arwrk[] = array("Due", "Due");
$arwrk[] = array("Paid", "Paid");
$loans->paid->EditValue = $arwrk;
// notes
$loans->notes->EditCustomAttributes = "";
$loans->notes->EditValue = ew_HtmlEncode($loans->notes->CurrentValue);
}
// Call Row Rendered event
$loans->Row_Rendered();
}
// Validate form
function ValidateForm() {
global $gsFormError, $loans;
// Initialize
$gsFormError = "";
// Check if validation required
if (!EW_SERVER_VALIDATE)
return ($gsFormError == "");
if ($loans->id->FormValue == "") {
$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
$gsFormError .= "Please enter required field - UniqueID";
}
if ($loans->owner->FormValue == "") {
$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
$gsFormError .= "Please enter required field - Loaned To";
}
if ($loans->location->FormValue == "") {
$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
$gsFormError .= "Please enter required field - Location";
}
if ($loans->loaned_date->FormValue == "") {
$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
$gsFormError .= "Please enter required field - Loaned Date";
}
if (!ew_CheckEuroDate($loans->loaned_date->FormValue)) {
if ($gsFormError <> "") $gsFormError .= "<br>";
$gsFormError .= "Incorrect date, format = dd/mm/yyyy - Loaned Date";
}
if ($loans->return_date->FormValue == "") {
$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
$gsFormError .= "Please enter required field - Return Date";
}
if (!ew_CheckEuroDate($loans->return_date->FormValue)) {
if ($gsFormError <> "") $gsFormError .= "<br>";
$gsFormError .= "Incorrect date, format = dd/mm/yyyy - Return Date";
}
if ($loans->returned->FormValue == "") {
$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
$gsFormError .= "Please enter required field - Returned Status";
}
if ($loans->deposit_return->FormValue == "") {
$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
$gsFormError .= "Please enter required field - Deposit Status";
}
if ($loans->deposit->FormValue == "") {
$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
$gsFormError .= "Please enter required field - Deposit £";
}
if ($loans->cost->FormValue == "") {
$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
$gsFormError .= "Please enter required field - Hire Charge £";
}
if ($loans->charge->FormValue == "") {
$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
$gsFormError .= "Please enter required field - Total Charge £";
}
if ($loans->paid->FormValue == "") {
$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
$gsFormError .= "Please enter required field - Paid";
}
// 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, $Security, $loans;
$rsnew = array();
// Field id
$loans->id->SetDbValueDef($loans->id->CurrentValue, "");
$rsnew['id'] =& $loans->id->DbValue;
// Field owner
$loans->owner->SetDbValueDef($loans->owner->CurrentValue, "");
$rsnew['owner'] =& $loans->owner->DbValue;
// Field location
$loans->location->SetDbValueDef($loans->location->CurrentValue, "");
$rsnew['location'] =& $loans->location->DbValue;
// Field show
$loans->show->SetDbValueDef($loans->show->CurrentValue, "");
$rsnew['show'] =& $loans->show->DbValue;
// Field loaned_date
$loans->loaned_date->SetDbValueDef(ew_UnFormatDateTime($loans->loaned_date->CurrentValue, 7), ew_CurrentDate());
$rsnew['loaned_date'] =& $loans->loaned_date->DbValue;
// Field return_date
$loans->return_date->SetDbValueDef(ew_UnFormatDateTime($loans->return_date->CurrentValue, 7), ew_CurrentDate());
$rsnew['return_date'] =& $loans->return_date->DbValue;
// Field returned
$loans->returned->SetDbValueDef($loans->returned->CurrentValue, "");
$rsnew['returned'] =& $loans->returned->DbValue;
// Field deposit_return
$loans->deposit_return->SetDbValueDef($loans->deposit_return->CurrentValue, "");
$rsnew['deposit_return'] =& $loans->deposit_return->DbValue;
// Field condition
$loans->condition->SetDbValueDef($loans->condition->CurrentValue, "");
$rsnew['condition'] =& $loans->condition->DbValue;
// Field deposit
$loans->deposit->SetDbValueDef($loans->deposit->CurrentValue, "");
$rsnew['deposit'] =& $loans->deposit->DbValue;
// Field cost
$loans->cost->SetDbValueDef($loans->cost->CurrentValue, "");
$rsnew['cost'] =& $loans->cost->DbValue;
// Field charge
$loans->charge->SetDbValueDef($loans->charge->CurrentValue, "");
$rsnew['charge'] =& $loans->charge->DbValue;
// Field paid
$loans->paid->SetDbValueDef($loans->paid->CurrentValue, "");
$rsnew['paid'] =& $loans->paid->DbValue;
// Field notes
$loans->notes->SetDbValueDef($loans->notes->CurrentValue, "");
$rsnew['notes'] =& $loans->notes->DbValue;
// Call Row Inserting event
$bInsertRow = $loans->Row_Inserting($rsnew);
if ($bInsertRow) {
$conn->raiseErrorFn = 'ew_ErrorFn';
$AddRow = $conn->Execute($loans->InsertSQL($rsnew));
$conn->raiseErrorFn = '';
} else {
if ($loans->CancelMessage <> "") {
$this->setMessage($loans->CancelMessage);
$loans->CancelMessage = "";
} else {
$this->setMessage("Insert cancelled");
}
$AddRow = FALSE;
}
if ($AddRow) {
$loans->loanid->setDbValue($conn->Insert_ID());
$rsnew['loanid'] =& $loans->loanid->DbValue;
// Call Row Inserted event
$loans->Row_Inserted($rsnew);
$this->WriteAuditTrailOnAdd($rsnew);
}
return $AddRow;
}
// Write Audit Trail start/end for grid update
function WriteAuditTrailDummy($typ) {
$table = 'loans';
// Write Audit Trail
$filePfx = "log";
$curDate = date("Y/m/d");
$curTime = date("H:i:s");
$id = ew_ScriptName();
$user = CurrentUserName();
$action = $typ;
ew_WriteAuditTrail($filePfx, $curDate, $curTime, $id, $user, $action, $table, "", "", "", "");
}
// Write Audit Trail (add page)
function WriteAuditTrailOnAdd(&$rs) {
global $loans;
$table = 'loans';
// Get key value
$key = "";
if ($key <> "") $key .= EW_COMPOSITE_KEY_SEPARATOR;
$key .= $rs['loanid'];
// Write Audit Trail
$filePfx = "log";
$curDate = date("Y/m/d");
$curTime = date("H:i:s");
$id = ew_ScriptName();
$user = CurrentUserName();
$action = "A";
$oldvalue = "";
foreach (array_keys($rs) as $fldname) {
if ($loans->fields[$fldname]->FldDataType <> EW_DATATYPE_BLOB) { // Ignore Blob Field
$newvalue = ($loans->fields[$fldname]->FldDataType == EW_DATATYPE_MEMO) ? "<MEMO>" : $rs[$fldname]; // Memo Field
ew_WriteAuditTrail($filePfx, $curDate, $curTime, $id, $user, $action, $table, $fldname, $key, $oldvalue, $newvalue);
}
}
}
// Page Load event
function Page_Load() {
//echo "Page Load";
}
// Page Unload event
function Page_Unload() {
//echo "Page Unload";
}
// Form Custom Validate event
function Form_CustomValidate(&$CustomError) {
// Return error message in CustomError
return TRUE;
}
}
?>
Now I only need to be able to put in multiple 'UniqueID' fields as the rest of the data will be the same, however the end result should be several records made in the table 'loans' with the same information, except UniqueID field.
Any ideas?
Thanks
Nick