Hello everyone,
I am trying to edit this code so that i can add which user i want to see ALL warranty claims when instead of how it is now where most users only see the claims associated with them. Please help if you can and thank you in advance. Also if i need to explain further just ask and i will do so.
<?php include "./include/application.php"; //********************************************************** class CForm extends CApplication { function CForm() { $this->CApplication(); } //********************************************************** function viewPage($msg = "") { $sWhere = ""; $data = array(); // Get page number from querystring $page = ( isset($_GET['page']) ) ? $_GET['page'] : ""; if (isset($_GET['showall'])) { $page = 1; $_SESSION['reportsSQL'] = ""; $_REQUEST["showonly"] = ""; $_SESSION['rpSort'] = ""; } // If search button is pressed or "Show All" link is clicked if (isset($_POST['btnSearch']) or isset($_GET['showall'])) { // Store search text to the session $_SESSION['SearchText'] = (isset($_POST["SearchText"]))? $_POST["SearchText"] : ""; // Get search clause $sWhere = $this->GetSearchSQL($_SESSION['SearchText']); // Reset page to first $page = 1; $_SESSION['reportsSQL'] = ""; $_SESSION['rpSort'] = ""; } if ($_REQUEST["showonly"] != "") { $_SESSION["ShowOnly"] = $_REQUEST["showonly"]; if ($_SESSION["ShowOnly"] != "All" AND $_SESSION["ShowOnly"] != "") { $sWhere .= " AND (wStatus = '".$_SESSION["ShowOnly"]."')"; } $page = 1; if ($_SESSION["ShowOnly"] == "All") { $_SESSION['reportsSQL'] = ereg_replace('AND \(wStatus = \'[a-zA-Z]{1,10}\'\)', '', $_SESSION['reportsSQL']); } else if (preg_match('/wStatus = \'.*\'/',$_SESSION['reportsSQL'])) { $_SESSION['reportsSQL'] = ereg_replace('wStatus = \'[a-zA-Z]{1,10}\'', "wStatus = '".$_SESSION["ShowOnly"]."'", $_SESSION['reportsSQL']); } else { $_SESSION['reportsSQL'] = ereg_replace('WHERE 1', "WHERE 1 AND (wStatus = '".$_SESSION["ShowOnly"]."')", $_SESSION['reportsSQL']); } } else if ($_SESSION["ShowOnly"] == "") { $_SESSION["ShowOnly"] = "All"; //$sWhere .= " AND (wStatus = 'All')"; } // If regular member then show only member's reports // Or Member is ksb or tommm - Cameron S. Joyner if ($_SESSION["aID"] == "" && $_SESSION["mID"] !== "237" && $_SESSION["mID"] !== "178" && $_SESSION["tmID"] !== "1" && $_SESSION["mID"] !== "507") { $sWhere .= " AND wDealerID = '$_SESSION[mID]'"; } // Main SQL query with additional search clauses $sql = "SELECT * FROM dl_warranty_claims WHERE 1 ".$sWhere. " GROUP BY wID ORDER BY wID DESC"; if ($_GET['sort'] != "") { $_SESSION['rpSort'] = $_GET['sort']; } if ($_SESSION['reportsSQL'] == "") { $_SESSION['reportsSQL'] = $sql; } // Init paging object // This object will display the paging links (prev,next), // dropdown box with pages and number of results $Pager = new Paging($_SESSION['reportsSQL'], $this, RECORDS_PER_PAGE, $page, "report:reports", $_SESSION['rpSort']) ; $Pager->AddSortField("Dealer Name","wDealerName"); $Pager->AddSortField("Customer Name","wCustomerName"); $Pager->AddSortField("Date Submited","wDatePosted"); $Pager->AddSortField("Status","wStatus"); $Pager->AddSortField("Claim Number","wID"); // Set paging (prev, next) link $Pager->SetPageURL("reports.php?page="); // Set paging css style $Pager->SetPagesStyle("form"); // If no records if ( !$Pager->RecordsCount ) { // Print message $this->smarty->assign("Msg", "No results were found."); } else { $res = $Pager->GetSqlResult(); // Get rows of current page while ( $row = $this->FetchArray($res) ) { $data[] = array_map("htmlspecialchars",$row); } } $sText = ( isset($_SESSION['SearchText']) ) ? $_SESSION['SearchText'] : ""; $Pager->SetSortFieldStyle("aheader"); $this->smarty->assign("HeaderDealerName", $Pager->GetSortField("Dealer Name")); $this->smarty->assign("HeaderCustomerName", $Pager->GetSortField("Customer Name")); $this->smarty->assign("HeaderDateSubmited", $Pager->GetSortField("Date Submited")); $this->smarty->assign("HeaderStatus", $Pager->GetSortField("Status")); $this->smarty->assign("HeaderClaimNumber", $Pager->GetSortField("Claim Number")); $this->smarty->assign("Msg", $msg); // Set Smarty options // Set text in search input box $this->smarty->assign("SearchText", $this->PrepareOutput($sText)); // Set page title $this->smarty->assign("title", "Warranty Claims"); // Set page index data $this->smarty->assign("pages_index", $Pager->GetPagesFormated()); $this->smarty->assign("data", $data); // Display template $this->smarty->display('reports.tpl'); } //************************************************************* // Prepare the search clause in main SQL query //************************************************************* Function GetSearchSQL($sText) { if ($sText != "") { return " AND ( wDealerName like '%$sText%' OR wCustomerName like '%$sText%' OR wMachineLocation like '%$sText%' OR wDateFailure like '%$sText%' OR wDateDelivery like '%$sText%' OR wModelName like '%$sText%' OR wChassisSN like '%$sText%' OR wOperatingHours like '%$sText%' OR wEngineSN like '%$sText%' OR wApplication like '%$sText%' OR wFailureAreaCode like '%$sText%' OR wFailureStatusCode like '%$sText%' OR wID like '%$sText%' ) "; } else if (is_array($_POST['warr'])) { foreach ($_POST['warr'] as $key=>$val) { if ($val != "") { $sql .= " AND ($key LIKE '%$val%')"; } } $data = $_POST["date"]; $DateFailure = $data["YearFailure"]."-".$data["MonthFailure"]."-".$data["DayFailure"]; $DateDelivery = $data["YearDelivery"]."-".$data["MonthDelivery"]."-".$data["DayDelivery"]; $DateClaim = $data["YearClaim"]."-".$data["MonthClaim"]."-".$data["DayClaim"]; $sql .= $this->getDateExpression("wDateFailure",$DateFailure); $sql .= $this->getDateExpression("wDateDelivery",$DateDelivery); $sql .= $this->getDateExpression("wDateClaim",$DateClaim); return $sql; } } //**************************************************************************************** function getDateExpression($field, $date) { $row = Split("-", $date); $sql = ""; // Get Year if ($row[0] != "" and $row[0] != "0") { $sql = $row[0]."-"; // Get Month if ($row[1] != "" and $row[1] != "0") { $sql .= $row[1]."-"; // Get Day if ($row[2] != "" and $row[2] != "0") { $sql .= $row[2]; return " AND ($field LIKE '$sql')"; } } if ($sql != "") { $sql .= "%"; $sql = " AND ($field LIKE '$sql')"; } } return $sql; } //**************************************************************************************** Function Execute() { $cmd = ""; $Actions = array("Approved", "Pending", "Processed", "Cancelled"); if (in_array($_POST['acttype'], $Actions)) { $cmd = $_POST['acttype']; } else if ($_POST['acttype'] == "Delete") { $cmd = $_POST['acttype']; } // Check whether some checkbox is selected if (!is_array($_POST['action'])) { $this->Msg("Reports", "Please, go back and select a report.Back"); } else if ($cmd == "Delete") { // Deleting reports $sql = "DELETE FROM dl_warranty_actions WHERE waWarrantyClaimID in ('".join("','", $_POST['action'])."')"; $res = $this->SQL($sql); $sql = "DELETE FROM dl_warranty_parts WHERE wpWarrantyClaimID in ('".join("','", $_POST['action'])."')"; $res = $this->SQL($sql); $sql = "DELETE FROM dl_warranty_claims WHERE wID in ('".join("','", $_POST['action'])."')"; $res = $this->SQL($sql); $this->Msg("Reports", "The selected reports has been deleted.
Back"); } else if ($cmd != "") { // Updating satatus $sql = "UPDATE dl_warranty_claims SET wStatus = '$cmd' WHERE wID in ('".join("','", $_POST['action'])."')"; $this->SQL($sql); $this->Msg("Reports", "The selected reports has been updated.
Back"); } else { $this->Msg("Reports", "Invalid parameters.
Back"); } } } ?>