UseTokenInUrl) $PageUrl .= "t=" . $this->TableVar . "&"; // Add page token return $PageUrl; } // Message function getMessage() { return @$_SESSION[EW_SESSION_MESSAGE]; } function setMessage($v) { ew_AddMessage($_SESSION[EW_SESSION_MESSAGE], $v); } function getFailureMessage() { return @$_SESSION[EW_SESSION_FAILURE_MESSAGE]; } function setFailureMessage($v) { ew_AddMessage($_SESSION[EW_SESSION_FAILURE_MESSAGE], $v); } function getSuccessMessage() { return @$_SESSION[EW_SESSION_SUCCESS_MESSAGE]; } function setSuccessMessage($v) { ew_AddMessage($_SESSION[EW_SESSION_SUCCESS_MESSAGE], $v); } function getWarningMessage() { return @$_SESSION[EW_SESSION_WARNING_MESSAGE]; } function setWarningMessage($v) { ew_AddMessage($_SESSION[EW_SESSION_WARNING_MESSAGE], $v); } // Methods to clear message function ClearMessage() { $_SESSION[EW_SESSION_MESSAGE] = ""; } function ClearFailureMessage() { $_SESSION[EW_SESSION_FAILURE_MESSAGE] = ""; } function ClearSuccessMessage() { $_SESSION[EW_SESSION_SUCCESS_MESSAGE] = ""; } function ClearWarningMessage() { $_SESSION[EW_SESSION_WARNING_MESSAGE] = ""; } function ClearMessages() { $_SESSION[EW_SESSION_MESSAGE] = ""; $_SESSION[EW_SESSION_FAILURE_MESSAGE] = ""; $_SESSION[EW_SESSION_SUCCESS_MESSAGE] = ""; $_SESSION[EW_SESSION_WARNING_MESSAGE] = ""; } // Show message function ShowMessage() { $hidden = FALSE; $html = ""; // Message $sMessage = $this->getMessage(); if (method_exists($this, "Message_Showing")) $this->Message_Showing($sMessage, ""); if ($sMessage <> "") { // Message in Session, display if (!$hidden) $sMessage = "" . $sMessage; $html .= "
" . $sHeader . "
"; } } // Show Page Footer function ShowPageFooter() { $sFooter = $this->PageFooter; $this->Page_DataRendered($sFooter); if ($sFooter <> "") { // Footer exists, display echo "" . $sFooter . "
"; } } // Validate page request function IsPageRequest() { global $objForm; if ($this->UseTokenInUrl) { if ($objForm) return ($this->TableVar == $objForm->GetValue("t")); if (@$_GET["t"] <> "") return ($this->TableVar == $_GET["t"]); } else { return TRUE; } } var $Token = ""; var $TokenTimeout = 0; var $CheckToken = EW_CHECK_TOKEN; var $CheckTokenFn = "ew_CheckToken"; var $CreateTokenFn = "ew_CreateToken"; // Valid Post function ValidPost() { if (!$this->CheckToken || !ew_IsHttpPost()) return TRUE; if (!isset($_POST[EW_TOKEN_NAME])) return FALSE; $fn = $this->CheckTokenFn; if (is_callable($fn)) return $fn($_POST[EW_TOKEN_NAME], $this->TokenTimeout); return FALSE; } // Create Token function CreateToken() { global $gsToken; if ($this->CheckToken) { $fn = $this->CreateTokenFn; if ($this->Token == "" && is_callable($fn)) // Create token $this->Token = $fn(); $gsToken = $this->Token; // Save to global variable } } // // Page class constructor // function __construct() { global $conn, $Language; global $UserTable, $UserTableConn; $GLOBALS["Page"] = &$this; $this->TokenTimeout = ew_SessionTimeoutTime(); // Language object if (!isset($Language)) $Language = new cLanguage(); // Parent constuctor parent::__construct(); // Table object (tass_notes) if (!isset($GLOBALS["tass_notes"]) || get_class($GLOBALS["tass_notes"]) == "ctass_notes") { $GLOBALS["tass_notes"] = &$this; $GLOBALS["Table"] = &$GLOBALS["tass_notes"]; } // Table object (users) if (!isset($GLOBALS['users'])) $GLOBALS['users'] = new cusers(); // Table object (tassigment) if (!isset($GLOBALS['tassigment'])) $GLOBALS['tassigment'] = new ctassigment(); // 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", 'tass_notes', TRUE); // Start timer if (!isset($GLOBALS["gTimer"])) $GLOBALS["gTimer"] = new cTimer(); // Open connection if (!isset($conn)) $conn = ew_Connect($this->DBID); // User table object (users) if (!isset($UserTable)) { $UserTable = new cusers(); $UserTableConn = Conn($UserTable->DBID); } } // // Page_Init // function Page_Init() { global $gsExport, $gsCustomExport, $gsExportFile, $UserProfile, $Language, $Security, $objForm; // Security $Security = new cAdvancedSecurity(); if (!$Security->IsLoggedIn()) $Security->AutoLogin(); if ($Security->IsLoggedIn()) $Security->TablePermission_Loading(); $Security->LoadCurrentUserLevel($this->ProjectID . $this->TableName); if ($Security->IsLoggedIn()) $Security->TablePermission_Loaded(); if (!$Security->CanDelete()) { $Security->SaveLastUrl(); $this->setFailureMessage(ew_DeniedMsg()); // Set no permission if ($Security->CanList()) $this->Page_Terminate(ew_GetUrl("tass_noteslist.php")); else $this->Page_Terminate(ew_GetUrl("login.php")); } $this->CurrentAction = (@$_GET["a"] <> "") ? $_GET["a"] : @$_POST["a_list"]; // Set up current action $this->Note_Date->SetVisibility(); $this->Note_author->SetVisibility(); $this->Note->SetVisibility(); // Global Page Loading event (in userfn*.php) Page_Loading(); // Page Load event $this->Page_Load(); // Check token if (!$this->ValidPost()) { echo $Language->Phrase("InvalidPostRequest"); $this->Page_Terminate(); exit(); } // Create Token $this->CreateToken(); } // // Page_Terminate // function Page_Terminate($url = "") { global $gsExportFile, $gTmpImages; // Page Unload event $this->Page_Unload(); // Global Page Unloaded event (in userfn*.php) Page_Unloaded(); // Export global $EW_EXPORT, $tass_notes; if ($this->CustomExport <> "" && $this->CustomExport == $this->Export && array_key_exists($this->CustomExport, $EW_EXPORT)) { $sContent = ob_get_contents(); if ($gsExportFile == "") $gsExportFile = $this->TableVar; $class = $EW_EXPORT[$this->CustomExport]; if (class_exists($class)) { $doc = new $class($tass_notes); $doc->Text = $sContent; if ($this->Export == "email") echo $this->ExportEmail($doc->Text); else $doc->Export(); ew_DeleteTmpImages(); // Delete temp images exit(); } } $this->Page_Redirecting($url); // Close connection ew_CloseConn(); // Go to URL if specified if ($url <> "") { if (!EW_DEBUG_ENABLED && ob_get_length()) ob_end_clean(); header("Location: " . $url); } exit(); } var $DbMasterFilter = ""; var $DbDetailFilter = ""; var $StartRec; var $TotalRecs = 0; var $RecCnt; var $RecKeys = array(); var $Recordset; var $StartRowCnt = 1; var $RowCnt = 0; // // Page main // function Page_Main() { global $Language; // Set up master/detail parameters $this->SetUpMasterParms(); // Set up Breadcrumb $this->SetupBreadcrumb(); // Load key parameters $this->RecKeys = $this->GetRecordKeys(); // Load record keys $sFilter = $this->GetKeyFilter(); if ($sFilter == "") $this->Page_Terminate("tass_noteslist.php"); // Prevent SQL injection, return to list // Set up filter (SQL WHHERE clause) and get return SQL // SQL constructor in tass_notes class, tass_notesinfo.php $this->CurrentFilter = $sFilter; // Get action if (@$_POST["a_delete"] <> "") { $this->CurrentAction = $_POST["a_delete"]; } elseif (@$_GET["a_delete"] == "1") { $this->CurrentAction = "D"; // Delete record directly } else { $this->CurrentAction = "I"; // Display record } if ($this->CurrentAction == "D") { $this->SendEmail = TRUE; // Send email on delete success if ($this->DeleteRows()) { // Delete rows if ($this->getSuccessMessage() == "") $this->setSuccessMessage($Language->Phrase("DeleteSuccess")); // Set up success message $this->Page_Terminate($this->getReturnUrl()); // Return to caller } else { // Delete failed $this->CurrentAction = "I"; // Display record } } if ($this->CurrentAction == "I") { // Load records for display if ($this->Recordset = $this->LoadRecordset()) $this->TotalRecs = $this->Recordset->RecordCount(); // Get record count if ($this->TotalRecs <= 0) { // No record found, exit if ($this->Recordset) $this->Recordset->Close(); $this->Page_Terminate("tass_noteslist.php"); // Return to list } } } // Load recordset function LoadRecordset($offset = -1, $rowcnt = -1) { // Load List page SQL $sSql = $this->SelectSQL(); $conn = &$this->Connection(); // Load recordset $dbtype = ew_GetConnectionType($this->DBID); if ($this->UseSelectLimit) { $conn->raiseErrorFn = $GLOBALS["EW_ERROR_FN"]; if ($dbtype == "MSSQL") { $rs = $conn->SelectLimit($sSql, $rowcnt, $offset, array("_hasOrderBy" => trim($this->getOrderBy()) || trim($this->getSessionOrderBy()))); } else { $rs = $conn->SelectLimit($sSql, $rowcnt, $offset); } $conn->raiseErrorFn = ''; } else { $rs = ew_LoadRecordset($sSql, $conn); } // Call Recordset Selected event $this->Recordset_Selected($rs); return $rs; } // Load row based on key values function LoadRow() { global $Security, $Language; $sFilter = $this->KeyFilter(); // Call Row Selecting event $this->Row_Selecting($sFilter); // Load SQL based on filter $this->CurrentFilter = $sFilter; $sSql = $this->SQL(); $conn = &$this->Connection(); $res = FALSE; $rs = ew_LoadRecordset($sSql, $conn); if ($rs && !$rs->EOF) { $res = TRUE; $this->LoadRowValues($rs); // Load row values $rs->Close(); } return $res; } // Load row values from recordset function LoadRowValues(&$rs) { if (!$rs || $rs->EOF) return; // Call Row Selected event $row = &$rs->fields; $this->Row_Selected($row); $this->idAss_note->setDbValue($rs->fields('idAss_note')); $this->idkAssignment->setDbValue($rs->fields('idkAssignment')); $this->Note_Date->setDbValue($rs->fields('Note_Date')); $this->Note_author->setDbValue($rs->fields('Note_author')); $this->Note->setDbValue($rs->fields('Note')); } // Load DbValue from recordset function LoadDbValues(&$rs) { if (!$rs || !is_array($rs) && $rs->EOF) return; $row = is_array($rs) ? $rs : $rs->fields; $this->idAss_note->DbValue = $row['idAss_note']; $this->idkAssignment->DbValue = $row['idkAssignment']; $this->Note_Date->DbValue = $row['Note_Date']; $this->Note_author->DbValue = $row['Note_author']; $this->Note->DbValue = $row['Note']; } // Render row values based on field settings function RenderRow() { global $Security, $Language, $gsLanguage; // Initialize URLs // Call Row_Rendering event $this->Row_Rendering(); // Common render codes for all row types // idAss_note // idkAssignment // Note_Date // Note_author // Note if ($this->RowType == EW_ROWTYPE_VIEW) { // View row // idAss_note $this->idAss_note->ViewValue = $this->idAss_note->CurrentValue; $this->idAss_note->ViewCustomAttributes = ""; // idkAssignment $this->idkAssignment->ViewValue = $this->idkAssignment->CurrentValue; $this->idkAssignment->ViewCustomAttributes = ""; // Note_Date $this->Note_Date->ViewValue = $this->Note_Date->CurrentValue; $this->Note_Date->ViewValue = ew_FormatDateTime($this->Note_Date->ViewValue, 7); $this->Note_Date->ViewCustomAttributes = ""; // Note_author $this->Note_author->ViewValue = $this->Note_author->CurrentValue; $this->Note_author->ViewCustomAttributes = ""; // Note $this->Note->ViewValue = $this->Note->CurrentValue; $this->Note->ViewCustomAttributes = ""; // Note_Date $this->Note_Date->LinkCustomAttributes = ""; $this->Note_Date->HrefValue = ""; $this->Note_Date->TooltipValue = ""; // Note_author $this->Note_author->LinkCustomAttributes = ""; $this->Note_author->HrefValue = ""; $this->Note_author->TooltipValue = ""; // Note $this->Note->LinkCustomAttributes = ""; $this->Note->HrefValue = ""; $this->Note->TooltipValue = ""; } // Call Row Rendered event if ($this->RowType <> EW_ROWTYPE_AGGREGATEINIT) $this->Row_Rendered(); } // // Delete records based on current filter // function DeleteRows() { global $Language, $Security; if (!$Security->CanDelete()) { $this->setFailureMessage($Language->Phrase("NoDeletePermission")); // No delete permission return FALSE; } $DeleteRows = TRUE; $sSql = $this->SQL(); $conn = &$this->Connection(); $conn->raiseErrorFn = $GLOBALS["EW_ERROR_FN"]; $rs = $conn->Execute($sSql); $conn->raiseErrorFn = ''; if ($rs === FALSE) { return FALSE; } elseif ($rs->EOF) { $this->setFailureMessage($Language->Phrase("NoRecord")); // No record found $rs->Close(); return FALSE; //} else { // $this->LoadRowValues($rs); // Load row values } $rows = ($rs) ? $rs->GetRows() : array(); $conn->BeginTrans(); // Clone old rows $rsold = $rows; if ($rs) $rs->Close(); // Call row deleting event if ($DeleteRows) { foreach ($rsold as $row) { $DeleteRows = $this->Row_Deleting($row); if (!$DeleteRows) break; } } if ($DeleteRows) { $sKey = ""; foreach ($rsold as $row) { $sThisKey = ""; if ($sThisKey <> "") $sThisKey .= $GLOBALS["EW_COMPOSITE_KEY_SEPARATOR"]; $sThisKey .= $row['idAss_note']; $conn->raiseErrorFn = $GLOBALS["EW_ERROR_FN"]; $DeleteRows = $this->Delete($row); // Delete $conn->raiseErrorFn = ''; if ($DeleteRows === FALSE) break; if ($sKey <> "") $sKey .= ", "; $sKey .= $sThisKey; } } else { // Set up error message if ($this->getSuccessMessage() <> "" || $this->getFailureMessage() <> "") { // Use the message, do nothing } elseif ($this->CancelMessage <> "") { $this->setFailureMessage($this->CancelMessage); $this->CancelMessage = ""; } else { $this->setFailureMessage($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) { $this->Row_Deleted($row); } } return $DeleteRows; } // Set up master/detail based on QueryString function SetUpMasterParms() { $bValidMaster = FALSE; // Get the keys for master table if (isset($_GET[EW_TABLE_SHOW_MASTER])) { $sMasterTblVar = $_GET[EW_TABLE_SHOW_MASTER]; if ($sMasterTblVar == "") { $bValidMaster = TRUE; $this->DbMasterFilter = ""; $this->DbDetailFilter = ""; } if ($sMasterTblVar == "tassigment") { $bValidMaster = TRUE; if (@$_GET["fk_idAssigment"] <> "") { $GLOBALS["tassigment"]->idAssigment->setQueryStringValue($_GET["fk_idAssigment"]); $this->idkAssignment->setQueryStringValue($GLOBALS["tassigment"]->idAssigment->QueryStringValue); $this->idkAssignment->setSessionValue($this->idkAssignment->QueryStringValue); if (!is_numeric($GLOBALS["tassigment"]->idAssigment->QueryStringValue)) $bValidMaster = FALSE; } else { $bValidMaster = FALSE; } } } elseif (isset($_POST[EW_TABLE_SHOW_MASTER])) { $sMasterTblVar = $_POST[EW_TABLE_SHOW_MASTER]; if ($sMasterTblVar == "") { $bValidMaster = TRUE; $this->DbMasterFilter = ""; $this->DbDetailFilter = ""; } if ($sMasterTblVar == "tassigment") { $bValidMaster = TRUE; if (@$_POST["fk_idAssigment"] <> "") { $GLOBALS["tassigment"]->idAssigment->setFormValue($_POST["fk_idAssigment"]); $this->idkAssignment->setFormValue($GLOBALS["tassigment"]->idAssigment->FormValue); $this->idkAssignment->setSessionValue($this->idkAssignment->FormValue); if (!is_numeric($GLOBALS["tassigment"]->idAssigment->FormValue)) $bValidMaster = FALSE; } else { $bValidMaster = FALSE; } } } if ($bValidMaster) { // Save current master table $this->setCurrentMasterTable($sMasterTblVar); // Reset start record counter (new master key) $this->StartRec = 1; $this->setStartRecordNumber($this->StartRec); // Clear previous master key from Session if ($sMasterTblVar <> "tassigment") { if ($this->idkAssignment->CurrentValue == "") $this->idkAssignment->setSessionValue(""); } } $this->DbMasterFilter = $this->GetMasterFilter(); // Get master filter $this->DbDetailFilter = $this->GetDetailFilter(); // Get detail filter } // Set up Breadcrumb function SetupBreadcrumb() { global $Breadcrumb, $Language; $Breadcrumb = new cBreadcrumb(); $url = substr(ew_CurrentUrl(), strrpos(ew_CurrentUrl(), "/")+1); $Breadcrumb->Add("list", $this->TableVar, $this->AddMasterUrl("tass_noteslist.php"), "", $this->TableVar, TRUE); $PageId = "delete"; $Breadcrumb->Add("delete", $PageId, $url); } // Setup lookup filters of a field function SetupLookupFilters($fld, $pageId = null) { global $gsLanguage; $pageId = $pageId ?: $this->PageID; switch ($fld->FldVar) { } } // Setup AutoSuggest filters of a field function SetupAutoSuggestFilters($fld, $pageId = null) { global $gsLanguage; $pageId = $pageId ?: $this->PageID; switch ($fld->FldVar) { } } // 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 // $type = ''|'success'|'failure'|'warning' function Message_Showing(&$msg, $type) { if ($type == 'success') { //$msg = "your success message"; } elseif ($type == 'failure') { //$msg = "your failure message"; } elseif ($type == 'warning') { //$msg = "your warning message"; } else { //$msg = "your message"; } } // Page Render event function Page_Render() { //echo "Page Render"; } // Page Data Rendering event function Page_DataRendering(&$header) { // Example: //$header = "your header"; } // Page Data Rendered event function Page_DataRendered(&$footer) { // Example: //$footer = "your footer"; } } ?> Page_Init(); // Page main $tass_notes_delete->Page_Main(); // Global Page Rendering event (in userfn*.php) Page_Rendering(); // Page Rendering event $tass_notes_delete->Page_Render(); ?> ShowPageHeader(); ?> ShowMessage(); ?> ShowPageFooter(); if (EW_DEBUG_ENABLED) echo ew_DebugMsg(); ?> Page_Terminate(); ?>