| Current Path : /var/www/cesa.co.za/echasl23/ |
| Current File : /var/www/cesa.co.za/echasl23/Applicationsdelete.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 "Applicationsinfo.php" ?>
<?php include "adminusersinfo.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
$Applications_delete = new cApplications_delete();
$Page =& $Applications_delete;
// Page init
$Applications_delete->Page_Init();
// Page main
$Applications_delete->Page_Main();
?>
<?php include "header.php" ?>
<script type="text/javascript">
<!--
// Create page object
var Applications_delete = new ew_Page("Applications_delete");
// page properties
Applications_delete.PageID = "delete"; // page ID
Applications_delete.FormID = "fApplicationsdelete"; // form ID
var EW_PAGE_ID = Applications_delete.PageID; // for backward compatibility
// extend page with Form_CustomValidate function
Applications_delete.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) { ?>
Applications_delete.ValidateRequired = true; // uses JavaScript validation
<?php } else { ?>
Applications_delete.ValidateRequired = false; // no JavaScript validation
<?php } ?>
//-->
</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>
<?php
// Load records for display
if ($rs = $Applications_delete->LoadRecordset())
$Applications_deletelTotalRecs = $rs->RecordCount(); // Get record count
if ($Applications_deletelTotalRecs <= 0) { // No record found, exit
if ($rs)
$rs->Close();
$Applications_delete->Page_Terminate("Applicationslist.php"); // Return to list
}
?>
<p><span class="phpmaker"><?php echo $Language->Phrase("Delete") ?> <?php echo $Language->Phrase("TblTypeTABLE") ?><?php echo $Applications->TableCaption() ?><br><br>
<a href="<?php echo $Applications->getReturnUrl() ?>"><?php echo $Language->Phrase("GoBack") ?></a></span></p>
<?php
if (EW_DEBUG_ENABLED)
echo ew_DebugMsg();
$Applications_delete->ShowMessage();
?>
<form action="<?php echo ew_CurrentPage() ?>" method="post">
<p>
<input type="hidden" name="t" id="t" value="Applications">
<input type="hidden" name="a_delete" id="a_delete" value="D">
<?php foreach ($Applications_delete->arRecKeys as $key) { ?>
<input type="hidden" name="key_m[]" id="key_m[]" value="<?php echo ew_HtmlEncode($key) ?>">
<?php } ?>
<table class="ewGrid"><tr><td class="ewGridContent">
<div class="ewGridMiddlePanel">
<table cellspacing="0" class="ewTable ewTableSeparate">
<?php echo $Applications->TableCustomInnerHtml ?>
<thead>
<tr class="ewTableHeader">
<td valign="top"><?php echo $Applications->FirmName->FldCaption() ?></td>
<td valign="top"><?php echo $Applications->DateCreated->FldCaption() ?></td>
<td valign="top"><?php echo $Applications->Status->FldCaption() ?></td>
</tr>
</thead>
<tbody>
<?php
$Applications_delete->lRecCnt = 0;
$i = 0;
while (!$rs->EOF) {
$Applications_delete->lRecCnt++;
// Set row properties
$Applications->CssClass = "";
$Applications->CssStyle = "";
$Applications->RowAttrs = array();
$Applications->RowType = EW_ROWTYPE_VIEW; // View
// Get the field contents
$Applications_delete->LoadRowValues($rs);
// Render row
$Applications_delete->RenderRow();
?>
<tr<?php echo $Applications->RowAttributes() ?>>
<td<?php echo $Applications->FirmName->CellAttributes() ?>>
<div<?php echo $Applications->FirmName->ViewAttributes() ?>><?php echo $Applications->FirmName->ListViewValue() ?></div></td>
<td<?php echo $Applications->DateCreated->CellAttributes() ?>>
<div<?php echo $Applications->DateCreated->ViewAttributes() ?>><?php echo $Applications->DateCreated->ListViewValue() ?></div></td>
<td<?php echo $Applications->Status->CellAttributes() ?>>
<div<?php echo $Applications->Status->ViewAttributes() ?>><?php echo $Applications->Status->ListViewValue() ?></div></td>
</tr>
<?php
$rs->MoveNext();
}
$rs->Close();
?>
</tbody>
</table>
</div>
</td></tr></table>
<p>
<input type="submit" name="Action" id="Action" value="<?php echo ew_BtnCaption($Language->Phrase("DeleteBtn")) ?>">
</form>
<script language="JavaScript" type="text/javascript">
<!--
// Write your table-specific startup script here
// document.write("page loaded");
//-->
</script>
<?php include "footer.php" ?>
<?php
$Applications_delete->Page_Terminate();
?>
<?php
//
// Page class
//
class cApplications_delete {
// Page ID
var $PageID = 'delete';
// Table name
var $TableName = 'Applications';
// Page object name
var $PageObjName = 'Applications_delete';
// Page name
function PageName() {
return ew_CurrentPage();
}
// Page URL
function PageUrl() {
$PageUrl = ew_CurrentPage() . "?";
global $Applications;
if ($Applications->UseTokenInUrl) $PageUrl .= "t=" . $Applications->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, $Applications;
if ($Applications->UseTokenInUrl) {
if ($objForm)
return ($Applications->TableVar == $objForm->GetValue("t"));
if (@$_GET["t"] <> "")
return ($Applications->TableVar == $_GET["t"]);
} else {
return TRUE;
}
}
//
// Page class constructor
//
function __construct() {
global $conn, $Language;
// Language object
$Language = new cLanguage();
// Table object (Applications)
$GLOBALS["Applications"] = new cApplications();
// Table object (adminusers)
$GLOBALS['adminusers'] = new cadminusers();
// Page ID
if (!defined("EW_PAGE_ID"))
define("EW_PAGE_ID", 'delete', TRUE);
// Table name (for backward compatibility)
if (!defined("EW_TABLE_NAME"))
define("EW_TABLE_NAME", 'Applications', 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 $Applications;
// 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->CanDelete()) {
$Security->SaveLastUrl();
$this->Page_Terminate("Applicationslist.php");
}
$Security->UserID_Loading();
if ($Security->IsLoggedIn()) $Security->LoadUserID();
$Security->UserID_Loaded();
// 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 $lTotalRecs = 0;
var $lRecCnt;
var $arRecKeys = array();
//
// Page main
//
function Page_Main() {
global $Language, $Applications;
// Load key parameters
$sKey = "";
$bSingleDelete = TRUE; // Initialize as single delete
$nKeySelected = 0; // Initialize selected key count
$sFilter = "";
if (@$_GET["ApplicationID"] <> "") {
$Applications->ApplicationID->setQueryStringValue($_GET["ApplicationID"]);
if (!is_numeric($Applications->ApplicationID->QueryStringValue))
$this->Page_Terminate("Applicationslist.php"); // Prevent SQL injection, exit
$sKey .= $Applications->ApplicationID->QueryStringValue;
} else {
$bSingleDelete = FALSE;
}
if ($bSingleDelete) {
$nKeySelected = 1; // Set up key selected count
$this->arRecKeys[0] = $sKey;
} else {
if (isset($_POST["key_m"])) { // Key in form
$nKeySelected = count($_POST["key_m"]); // Set up key selected count
$this->arRecKeys = ew_StripSlashes($_POST["key_m"]);
}
}
if ($nKeySelected <= 0)
$this->Page_Terminate("Applicationslist.php"); // No key specified, return to list
// Build filter
foreach ($this->arRecKeys as $sKey) {
$sFilter .= "(";
// Set up key field
$sKeyFld = $sKey;
if (!is_numeric($sKeyFld))
$this->Page_Terminate("Applicationslist.php"); // Prevent SQL injection, return to list
$sFilter .= "`ApplicationID`=" . ew_AdjustSql($sKeyFld) . " AND ";
if (substr($sFilter, -5) == " AND ") $sFilter = substr($sFilter, 0, strlen($sFilter)-5) . ") OR ";
}
if (substr($sFilter, -4) == " OR ") $sFilter = substr($sFilter, 0, strlen($sFilter)-4);
// Set up filter (SQL WHHERE clause) and get return SQL
// SQL constructor in Applications class, Applicationsinfo.php
$Applications->CurrentFilter = $sFilter;
// Get action
if (@$_POST["a_delete"] <> "") {
$Applications->CurrentAction = $_POST["a_delete"];
} else {
$Applications->CurrentAction = "I"; // Display record
}
switch ($Applications->CurrentAction) {
case "D": // Delete
$Applications->SendEmail = TRUE; // Send email on delete success
if ($this->DeleteRows()) { // delete rows
$this->setMessage($Language->Phrase("DeleteSuccess")); // Set up success message
$this->Page_Terminate($Applications->getReturnUrl()); // Return to caller
}
}
}
//
// Delete records based on current filter
//
function DeleteRows() {
global $conn, $Language, $Security, $Applications;
$DeleteRows = TRUE;
$sWrkFilter = $Applications->CurrentFilter;
// Set up filter (SQL WHERE clause) and get return SQL
// SQL constructor in Applications class, Applicationsinfo.php
$Applications->CurrentFilter = $sWrkFilter;
$sSql = $Applications->SQL();
$conn->raiseErrorFn = 'ew_ErrorFn';
$rs = $conn->Execute($sSql);
$conn->raiseErrorFn = '';
if ($rs === FALSE) {
return FALSE;
} elseif ($rs->EOF) {
$this->setMessage($Language->Phrase("NoRecord")); // No record found
$rs->Close();
return FALSE;
}
$conn->BeginTrans();
// Clone old rows
$rsold = ($rs) ? $rs->GetRows() : array();
if ($rs)
$rs->Close();
// Call row deleting event
if ($DeleteRows) {
foreach ($rsold as $row) {
$DeleteRows = $Applications->Row_Deleting($row);
if (!$DeleteRows) break;
}
}
if ($DeleteRows) {
$sKey = "";
foreach ($rsold as $row) {
$sThisKey = "";
if ($sThisKey <> "") $sThisKey .= EW_COMPOSITE_KEY_SEPARATOR;
$sThisKey .= $row['ApplicationID'];
@unlink(ew_UploadPathEx(TRUE, $Applications->AppForm->UploadPath) . $row['AppForm']);
@unlink(ew_UploadPathEx(TRUE, $Applications->CIPCReg->UploadPath) . $row['CIPCReg']);
@unlink(ew_UploadPathEx(TRUE, $Applications->MPRes->UploadPath) . $row['MPRes']);
@unlink(ew_UploadPathEx(TRUE, $Applications->PIInsurance->UploadPath) . $row['PIInsurance']);
@unlink(ew_UploadPathEx(TRUE, $Applications->Letterhead->UploadPath) . $row['Letterhead']);
$conn->raiseErrorFn = 'ew_ErrorFn';
$DeleteRows = $conn->Execute($Applications->DeleteSQL($row)); // Delete
$conn->raiseErrorFn = '';
if ($DeleteRows === FALSE)
break;
if ($sKey <> "") $sKey .= ", ";
$sKey .= $sThisKey;
}
} else {
// Set up error message
if ($Applications->CancelMessage <> "") {
$this->setMessage($Applications->CancelMessage);
$Applications->CancelMessage = "";
} else {
$this->setMessage($Language->Phrase("DeleteCancelled"));
}
}
if ($DeleteRows) {
$conn->CommitTrans(); // Commit the changes
} else {
$conn->RollbackTrans(); // Rollback changes
}
// Call Row Deleted event
if ($DeleteRows) {
foreach ($rsold as $row) {
$Applications->Row_Deleted($row);
}
}
return $DeleteRows;
}
// Load recordset
function LoadRecordset($offset = -1, $rowcnt = -1) {
global $conn, $Applications;
// Call Recordset Selecting event
$Applications->Recordset_Selecting($Applications->CurrentFilter);
// Load List page SQL
$sSql = $Applications->SelectSQL();
if ($offset > -1 && $rowcnt > -1)
$sSql .= " LIMIT $offset, $rowcnt";
// Load recordset
$rs = ew_LoadRecordset($sSql);
// Call Recordset Selected event
$Applications->Recordset_Selected($rs);
return $rs;
}
// Load row based on key values
function LoadRow() {
global $conn, $Security, $Applications;
$sFilter = $Applications->KeyFilter();
// Call Row Selecting event
$Applications->Row_Selecting($sFilter);
// Load SQL based on filter
$Applications->CurrentFilter = $sFilter;
$sSql = $Applications->SQL();
$res = FALSE;
$rs = ew_LoadRecordset($sSql);
if ($rs && !$rs->EOF) {
$res = TRUE;
$this->LoadRowValues($rs); // Load row values
// Call Row Selected event
$Applications->Row_Selected($rs);
$rs->Close();
}
return $res;
}
// Load row values from recordset
function LoadRowValues(&$rs) {
global $conn, $Applications;
$Applications->ApplicationID->setDbValue($rs->fields('ApplicationID'));
$Applications->FirmName->setDbValue($rs->fields('FirmName'));
$Applications->PhysicalAddress->setDbValue($rs->fields('PhysicalAddress'));
$Applications->FoundingDate->setDbValue($rs->fields('FoundingDate'));
$Applications->VATNumber->setDbValue($rs->fields('VATNumber'));
$Applications->AppForm->Upload->DbValue = $rs->fields('AppForm');
$Applications->CIPCReg->Upload->DbValue = $rs->fields('CIPCReg');
$Applications->MPRes->Upload->DbValue = $rs->fields('MPRes');
$Applications->PIInsurance->Upload->DbValue = $rs->fields('PIInsurance');
$Applications->Letterhead->Upload->DbValue = $rs->fields('Letterhead');
$Applications->DateCreated->setDbValue($rs->fields('DateCreated'));
$Applications->Status->setDbValue($rs->fields('Status'));
$Applications->DateApproved->setDbValue($rs->fields('DateApproved'));
$Applications->Comments->setDbValue($rs->fields('Comments'));
}
// Render row values based on field settings
function RenderRow() {
global $conn, $Security, $Language, $Applications;
// Initialize URLs
// Call Row_Rendering event
$Applications->Row_Rendering();
// Common render codes for all row types
// FirmName
$Applications->FirmName->CellCssStyle = ""; $Applications->FirmName->CellCssClass = "";
$Applications->FirmName->CellAttrs = array(); $Applications->FirmName->ViewAttrs = array(); $Applications->FirmName->EditAttrs = array();
// DateCreated
$Applications->DateCreated->CellCssStyle = ""; $Applications->DateCreated->CellCssClass = "";
$Applications->DateCreated->CellAttrs = array(); $Applications->DateCreated->ViewAttrs = array(); $Applications->DateCreated->EditAttrs = array();
// Status
$Applications->Status->CellCssStyle = ""; $Applications->Status->CellCssClass = "";
$Applications->Status->CellAttrs = array(); $Applications->Status->ViewAttrs = array(); $Applications->Status->EditAttrs = array();
if ($Applications->RowType == EW_ROWTYPE_VIEW) { // View row
// ApplicationID
$Applications->ApplicationID->ViewValue = $Applications->ApplicationID->CurrentValue;
$Applications->ApplicationID->CssStyle = "";
$Applications->ApplicationID->CssClass = "";
$Applications->ApplicationID->ViewCustomAttributes = "";
// FirmName
$Applications->FirmName->ViewValue = $Applications->FirmName->CurrentValue;
$Applications->FirmName->CssStyle = "";
$Applications->FirmName->CssClass = "";
$Applications->FirmName->ViewCustomAttributes = "";
// FoundingDate
$Applications->FoundingDate->ViewValue = $Applications->FoundingDate->CurrentValue;
$Applications->FoundingDate->ViewValue = ew_FormatDateTime($Applications->FoundingDate->ViewValue, 5);
$Applications->FoundingDate->CssStyle = "";
$Applications->FoundingDate->CssClass = "";
$Applications->FoundingDate->ViewCustomAttributes = "";
// VATNumber
$Applications->VATNumber->ViewValue = $Applications->VATNumber->CurrentValue;
$Applications->VATNumber->CssStyle = "";
$Applications->VATNumber->CssClass = "";
$Applications->VATNumber->ViewCustomAttributes = "";
// AppForm
if (!ew_Empty($Applications->AppForm->Upload->DbValue)) {
$Applications->AppForm->ViewValue = $Applications->AppForm->Upload->DbValue;
} else {
$Applications->AppForm->ViewValue = "";
}
$Applications->AppForm->CssStyle = "";
$Applications->AppForm->CssClass = "";
$Applications->AppForm->ViewCustomAttributes = "";
// CIPCReg
if (!ew_Empty($Applications->CIPCReg->Upload->DbValue)) {
$Applications->CIPCReg->ViewValue = $Applications->CIPCReg->Upload->DbValue;
} else {
$Applications->CIPCReg->ViewValue = "";
}
$Applications->CIPCReg->CssStyle = "";
$Applications->CIPCReg->CssClass = "";
$Applications->CIPCReg->ViewCustomAttributes = "";
// MPRes
if (!ew_Empty($Applications->MPRes->Upload->DbValue)) {
$Applications->MPRes->ViewValue = $Applications->MPRes->Upload->DbValue;
} else {
$Applications->MPRes->ViewValue = "";
}
$Applications->MPRes->CssStyle = "";
$Applications->MPRes->CssClass = "";
$Applications->MPRes->ViewCustomAttributes = "";
// PIInsurance
if (!ew_Empty($Applications->PIInsurance->Upload->DbValue)) {
$Applications->PIInsurance->ViewValue = $Applications->PIInsurance->Upload->DbValue;
} else {
$Applications->PIInsurance->ViewValue = "";
}
$Applications->PIInsurance->CssStyle = "";
$Applications->PIInsurance->CssClass = "";
$Applications->PIInsurance->ViewCustomAttributes = "";
// Letterhead
if (!ew_Empty($Applications->Letterhead->Upload->DbValue)) {
$Applications->Letterhead->ViewValue = $Applications->Letterhead->Upload->DbValue;
} else {
$Applications->Letterhead->ViewValue = "";
}
$Applications->Letterhead->CssStyle = "";
$Applications->Letterhead->CssClass = "";
$Applications->Letterhead->ViewCustomAttributes = "";
// DateCreated
$Applications->DateCreated->ViewValue = $Applications->DateCreated->CurrentValue;
$Applications->DateCreated->ViewValue = ew_FormatDateTime($Applications->DateCreated->ViewValue, 5);
$Applications->DateCreated->CssStyle = "";
$Applications->DateCreated->CssClass = "";
$Applications->DateCreated->ViewCustomAttributes = "";
// Status
if (strval($Applications->Status->CurrentValue) <> "") {
switch ($Applications->Status->CurrentValue) {
case "P":
$Applications->Status->ViewValue = "Pending";
break;
case "A":
$Applications->Status->ViewValue = "Approved";
break;
case "R":
$Applications->Status->ViewValue = "Rejected";
break;
default:
$Applications->Status->ViewValue = $Applications->Status->CurrentValue;
}
} else {
$Applications->Status->ViewValue = NULL;
}
$Applications->Status->CssStyle = "";
$Applications->Status->CssClass = "";
$Applications->Status->ViewCustomAttributes = "";
// DateApproved
$Applications->DateApproved->ViewValue = $Applications->DateApproved->CurrentValue;
$Applications->DateApproved->ViewValue = ew_FormatDateTime($Applications->DateApproved->ViewValue, 5);
$Applications->DateApproved->CssStyle = "";
$Applications->DateApproved->CssClass = "";
$Applications->DateApproved->ViewCustomAttributes = "";
// FirmName
$Applications->FirmName->HrefValue = "";
$Applications->FirmName->TooltipValue = "";
// DateCreated
$Applications->DateCreated->HrefValue = "";
$Applications->DateCreated->TooltipValue = "";
// Status
$Applications->Status->HrefValue = "";
$Applications->Status->TooltipValue = "";
}
// Call Row Rendered event
if ($Applications->RowType <> EW_ROWTYPE_AGGREGATEINIT)
$Applications->Row_Rendered();
}
// 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";
}
}
?>