function showSummary($query) { global $db_conn; print '<table align="center" border="1">'; // print table column headers $tableHeaders = array("id", "Name", "Phone #", "Email", "Points", "Details"); writeTableHeader($tableHeaders); // retrieve all data from the database to be displayed $result = $db_conn->query($query); if ($result == true) { $result->data_seek(0); while ($row = $result->fetch_assoc()) { $id = $row[tcCustomer::$custIdStr]; $fname = $row[tcCustomer::$fnameStr]; $lname = $row[tcCustomer::$lnameStr]; $phone = $row[tcCustomer::$phoneStr]; $email = $row[tcCustomer::$emailStr]; $totalPtrs = tcVisits::getTotalPointsById($db_conn, $id); writeTRBegin(); writeTD('<a href="' . 'editcustomer.php?custId=' . $id . '">' . $id . '</a>'); writeTDArray(array("{$fname} {$lname}", $phone, $email)); writeTD($totalPtrs, "right"); writeTD('<a href="' . 'showdetails.php?custId=' . $id . '">Details</a>'); writeTREnd(); } $result->free(); } else { exit("Unable to access the database."); } print "</table>"; }
function emailReceipt($db_conn, $id) { // get the customer information from the database $customer = tcCustomer::getCustomerById($db_conn, $id); $totalPoints = tcVisits::getTotalPointsById($db_conn, $id); $toAddr = $customer->email; $subject = "Thanks for visiting Classic Polish 168!"; $msg = ""; $header = "MIME-Version: 1.0" . "\r\n"; $header .= "Content-type:text/html;charset=UTF-8" . "\r\n"; $param = "-FClassicPolish168"; // populate the email body $visits = new tcVisits($id, $db_conn); $visits->initVisits(); $msg = $msg . '<html>'; $msg = $msg . '<head><title>Visit History</title></head>'; $msg = $msg . '<body>'; $msg = $msg . '<p>Dear ' . "{$customer->fname} {$customer->lname}:"; $msg = $msg . '<p>Below is a copy of your visit history and point balance for your reference.'; $msg = $msg . 'We look forward to serve you again. Have a great day!</p>'; $msg = $msg . '<table align="center" border="1">'; $msg = $msg . '<th>Date</th>'; $msg = $msg . '<th>Points</th>'; for ($i = 0; $i < count($visits->visits); ++$i) { $msg = $msg . '<tr>'; $msg = $msg . '<td align="center">' . $visits->visits[$i]->dtime . '</td>'; $msg = $msg . '<td align="right">' . $visits->visits[$i]->point . '</td>'; $msg = $msg . '</tr>'; } $msg = $msg . '<tr>'; $msg = $msg . '<td align="left"><strong>Balance:</strong></td>'; $totalPtrs = tcVisits::getTotalPointsById($db_conn, $id); $msg = $msg . '<td align="right">' . $totalPtrs . '</td>'; $msg = $msg . '</tr>'; $msg = $msg . '</table>'; $msg = $msg . '</body>'; $msg = $msg . '</html>'; if (mail($toAddr, $subject, $msg, $header, $param)) { $infoMsg = "Email sent successfully to {$customer->fname} {$customer->lname}!"; if (isset($_POST["id"])) { print $msg; print '<br/>'; print '<p align="center"><font color="green" size=20><strong>' . $infoMsg . '</strong></font></p>'; header("refresh:5; url=showdetails.php?custId=" . $id); } else { print $infoMsg; } } else { $errorMsg = "Failed to send email to {$customer->fname} {$customer->lname} with email {$customer->email}!"; if (isset($_POST["id"])) { print '<p align="center"><font color="red" size=20><strong>' . $errorMsg . '</strong></font></p>'; } else { print $errorMsg; } } }
public function showDetailTable() { print '<table align="center" border="1">'; // write the table header information writeTableHeader(array("Name", "Phone", "Email", "Date", "Points")); // write the table row to the web page writeTRBegin(); writeTDArray(array("{$this->fname} {$this->lname}", $this->phone, $this->email)); print '<td colspan=2></td>'; writeTREnd(); $visits = new tcVisits($this->custId, $this->db_conn); $visits->initVisits(); $numVisits = count($visits->visits); // NOTE: rowspan number has to plus 2 for unknown reason print '<td colspan=3 rowspan=' . ($numVisits + 2) . '></td>'; for ($i = 0; $i < $numVisits; ++$i) { writeTRBegin(); writeTD($visits->visits[$i]->dtime); writeTD($visits->visits[$i]->point, "right"); writeTREnd(); } $totalPtrs = tcVisits::getTotalPointsById($this->db_conn, $this->custId); writeTRBegin(); writeTD("Balance:"); writeTD($totalPtrs, "right"); writeTREnd(); print '</table>'; }
$id = $_POST["id"]; $intSign = $_POST["intSign"]; $point = $_POST["point"]; $newVisit = new tcVisit(); $newVisit->id = $id; if ($intSign == "plus") { $newVisit->point = $point; } else { if ($intSign == "minus") { $newVisit->point = $point * -1; } else { exit("Unable to add point for a unkown integer sign"); } } // print "debug: " . $newVisit->insertQueryStr() . "<br/>"; $pointBalance = tcVisits::getTotalPointsById($db_conn, $newVisit->id); if ($newVisit->point + $pointBalance < 0) { print "<h1>Sorry, you don't have enough points to use!</h1>"; $back_url = '<a href="showdetails.php?custId=' . $id . '">Go Back</a>'; print "<br/> {$back_url}"; exit; } $result = $db_conn->query($newVisit->insertQueryStr()); if ($result == true) { // points added successfully. go back to the detailed page header("Location: showdetails.php?custId=" . $id); } else { print "Failed to add points."; } ?>