コード例 #1
0
ファイル: email.php プロジェクト: ghyousu/nailpointsystem
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;
        }
    }
}
コード例 #2
0
ファイル: test.php プロジェクト: ghyousu/nailpointsystem
function insertTestData()
{
    $db_conn = new mysqli("localhost", "zdliu", "63859", "classicpolish168");
    if ($db_conn->connect_error) {
        $errString = "Failed to connect to the database";
        echo "<br/> {$errString} ";
        throw new Exception($errString);
    }
    tcCustomer::runTest($db_conn);
    tcVisits::runTest($db_conn);
    $insert1 = "INSERT INTO customers ( fname, lname, phone, email ) VALUES ( " . '"mason",' . '"you",' . '"2125187517",' . '"*****@*****.**")';
    $insert2 = "INSERT INTO customers ( fname, lname, phone, email ) VALUES ( " . '"candy",' . '"liu",' . '"2125187518",' . '"*****@*****.**")';
    $insert3 = "INSERT INTO customers ( fname, lname, phone, email ) VALUES ( " . '"sheryl",' . '"liu",' . '"2125187519",' . '"*****@*****.**")';
    $db_conn->query($insert1);
    $db_conn->query($insert2);
    $db_conn->query($insert3);
    $visit1a = "INSERT INTO visits ( id, points ) VALUES ( 1, " . '10 )';
    $visit1b = "INSERT INTO visits ( id, points ) VALUES ( 1, " . '14 )';
    $visit2a = "INSERT INTO visits ( id, points ) VALUES ( 2, " . '30 )';
    $visit2b = "INSERT INTO visits ( id, points ) VALUES ( 2, " . '24 )';
    $visit2c = "INSERT INTO visits ( id, points ) VALUES ( 2, " . '14 )';
    $visit3a = "INSERT INTO visits ( id, points ) VALUES ( 3, " . '4 )';
    $db_conn->query($visit1a);
    $db_conn->query($visit1b);
    $db_conn->query($visit2a);
    $db_conn->query($visit2b);
    $db_conn->query($visit2c);
    $db_conn->query($visit3a);
    $db_conn->close();
}
コード例 #3
0
ファイル: showall.php プロジェクト: ghyousu/nailpointsystem
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>";
}
コード例 #4
0
 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>';
 }
コード例 #5
0
<?php

require_once "tcCustomer.php";
require_once "tcVisits.php";
// database information
$DB_HOSTNAME = "localhost";
$DB_USERNAME = "******";
$DB_PASSWORD = "******";
$DB_NAME = "classicpolish168";
$TABLE_NAME = "customers";
// this is reg-exp used for querying the database
$SQL_ANY_STRING = " REGEXP '[a-z]|[A-Z]*' ";
// make connection to the database
$db_conn = new mysqli($DB_HOSTNAME, $DB_USERNAME, $DB_PASSWORD, $DB_NAME);
if ($db_conn->connect_error) {
    $errString = "Failed to connect to the database";
    echo "<br/> {$errString} ";
    exit($errString);
}
tcCustomer::createTable($db_conn);
tcVisits::createTable($db_conn);
// cheat sheet:
// create user 'zdliu'@'localhost' identified by 'password';
// grant all privileges on classicpolish168.* to 'zdliu'@'localhost'
// $dtime = new DateTime( $result->my_datetime );
// print $dtime->format( "Y-m-d H:i:s");
// insert into visits ( id, datetime, points ) values ( 1, "2014/04/25 15:22:38", 100 );
コード例 #6
0
ファイル: addpoint.php プロジェクト: ghyousu/nailpointsystem
$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.";
}
?>