public function giveProduct()
    {
        $this->return .= <<<HTML
                <div id="currencyHistoryBoard" class="card">
                <table style="width:100%">
                    <tr class="blue">
                        <th class="center">Currency</th>
                        <th class="center">Time</th>
                        <th class="center">Bid Rate</th>
                        <th class="center">Offer Rate</th>
                    </tr>
HTML;
        $db = UniversalConnect::doConnect();
        $query = "SELECT starttime FROM startendtime LIMIT 1";
        $result = $db->query($query);
        $row = $result->fetch_assoc();
        $startTime = $row["starttime"];
        $query = "SELECT currency.shortname, valuechanges.newbuyvalue, valuechanges.newsellvalue, valuechanges.time FROM valuechanges INNER JOIN currency ON valuechanges.currencyid = currency.currencyid WHERE valuechanges.yetcompleted=0 ORDER BY valuechanges.time DESC";
        $result = $db->query($query) or die($db->error);
        while ($row = $result->fetch_assoc()) {
            $this->return .= "<tr>";
            $this->return .= "<td class=\"center\">" . $row["shortname"] . "</td>";
            $this->return .= "<td class=\"center\">" . FormatTimePassed::format($row["time"] + $startTime) . "</td>";
            $this->return .= "<td class=\"center\">" . number_format($row["newbuyvalue"], 2) . "</td>";
            $this->return .= "<td class=\"center\">" . number_format($row["newsellvalue"], 2) . "</td>";
            $this->return .= "</tr>";
        }
        $this->return .= "</table></div>";
        return $this->return;
    }
    public function giveProduct()
    {
        if (session_status() === PHP_SESSION_NONE) {
            session_start();
        }
        $userkey = intval($_SESSION["userkey"]);
        $db = UniversalConnect::doConnect();
        $this->return .= <<<HTML
<div id="currencyHistoryBoard" class="card">
            <table style="width:100%">
                    <tr class="blue center">
                        <th>No.</th>
                        <th>Time</th>
                        <th>Transaction Type</th>
                        <th>Rate Transacted</th>
                        <th>Amount Sold</th>
                        <th>Amount Received</th>
                    </tr>
HTML;
        $query = "SELECT transactions.transtype, currency.shortname, transactions.amount, transactions.rate, transactions.receiveamt, transactions.time FROM transactions INNER JOIN currency ON currency.currencyid = transactions.currencyid WHERE transactions.userkey = {$userkey} ORDER BY time DESC";
        $result = $db->query($query) or die($db->error);
        $count = 1;
        if ($result->num_rows <= 0) {
            $this->return .= "<tr><td class=\"center\" colspan=\"6\">No previous transactions found.</td></tr>";
        } else {
            while ($row = $result->fetch_assoc()) {
                $this->return .= "<tr class=\"center\">";
                if (intval($row["transtype"]) === 0) {
                    $newcurrname = $row["shortname"];
                    $this->return .= "<td>{$count}</td>";
                    $this->return .= "<td>" . FormatTimePassed::format($row["time"]) . "</td>";
                    $this->return .= "<td>" . $this->baseCurrency->getShortName() . " to {$newcurrname} (Sell)</td>";
                    $this->return .= "<td>" . $row["rate"] . "</td>";
                    $this->return .= "<td>" . $this->baseCurrency->getShortName() . number_format($row["amount"], 2) . "</td>";
                    $this->return .= "<td>{$newcurrname}" . number_format($row["receiveamt"], 2) . "</td>";
                } else {
                    $newcurrname = $row["shortname"];
                    $this->return .= "<td>{$count}</td>";
                    $this->return .= "<td>" . FormatTimePassed::format($row["time"]) . "</td>";
                    $this->return .= "<td>{$newcurrname} to " . $this->baseCurrency->getShortName() . " (Buy)</td>";
                    $this->return .= "<td>" . $row["rate"] . "</td>";
                    $this->return .= "<td>{$newcurrname}" . number_format($row["amount"]) . "</td>";
                    $this->return .= "<td>" . $this->baseCurrency->getShortName() . number_format($row["receiveamt"]) . "</td>";
                }
                $count++;
                $this->return .= "</tr>";
            }
        }
        $this->return .= "</table></div>";
        return $this->return;
    }
    public function giveProduct()
    {
        $db = UniversalConnect::doConnect();
        date_default_timezone_set('Asia/Singapore');
        $this->return .= <<<HTML
            <div id="news">
                <div class="card-panel pink accent-2 z-depth-1">
                    <div class="card-title">NEWS</div>
                </div>
                <div class="relative">
                    <ul class="collapsible" data-collapsible="accordion">
                    <!-- OR <ul class="collapsible popout" data-collapsible="accordion"> -->
HTML;
        $query = "SELECT starttime FROM startendtime LIMIT 1";
        $result = $db->query($query);
        $row = $result->fetch_assoc();
        $startTime = $row["starttime"];
        if ($this->newsCount !== 0) {
            $query = "SELECT newstext, time FROM news WHERE time <= " . (time() - $startTime) . " ORDER BY time DESC LIMIT {$this->newsCount}";
        } else {
            $query = "SELECT newstext, time FROM news WHERE time <= " . (time() - $startTime) . " ORDER BY time DESC";
        }
        $result = $db->query($query) or die($db->error);
        if ($result->num_rows <= 0) {
            $this->return .= "<li><div class=\"collapsible-header\">";
            $this->return .= "There are no news reports at the moment.";
            $this->return .= "</div></li>";
        }
        while ($row = $result->fetch_assoc()) {
            $this->return .= "<li class=\"z-depth-1\">";
            $this->return .= "<div class=\"collapsible-header\">";
            $this->return .= "<b>" . FormatTimePassed::format(intval($row["time"]) + $startTime) . "</b>";
            $this->return .= $row["newstext"] . "</div>";
            //                $this->return .= "<div class=\"collapsible-body\"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam eu tortor sed nulla porta fringilla. In risus tellus, dictum quis purus id, euismod lacinia elit. Vivamus ac viverra magna, eget accumsan mauris. Nulla molestie vulputate lectus sit amet rutrum. Sed tempus efficitur sagittis. Aenean ultricies quis sapien ut tempus. Pellentesque euismod nisl a felis interdum pharetra. Nullam id nisi in ante volutpat posuere.</p></div>"; // Add article info before this
            $this->return .= "</li>";
        }
        $this->return .= "</ul></div></div>";
        return $this->return;
    }
示例#4
0
    public function __construct()
    {
        //Checks if user is logged in or has posted passwords. Redirects as appropriate.
        $SessAuthWorker = new SessionAuthenticate();
        if ($SessAuthWorker->authenticate()) {
            header("Location: " . GenerateRootPath::getRoot(1) . "/dashboard/");
            exit;
        }
        if (isset($_POST["username"]) && isset($_POST["password"])) {
            $PassAuthWorker = new PasswordAuthenticate();
            if ($PassAuthWorker->authenticate($_POST["username"], $_POST["password"])) {
                $TimeAuthWorker = new TimeAuthenticate();
                $PrivAuthWorker = new PrivilegeAuthenticate();
                if (session_status() === PHP_SESSION_NONE) {
                    session_start();
                }
                $db = UniversalConnect::doConnect();
                $query = "SELECT userkey, usertype FROM users WHERE userid=\"" . $db->real_escape_string(trim($_POST["username"])) . "\" LIMIT 1";
                $result = $db->query($query);
                if ($result->num_rows < 1) {
                    die("An unexpected error has occurred. The problem should go away by itself after some time.");
                }
                $row = $result->fetch_assoc();
                $_SESSION["userkey"] = $row["userkey"];
                $_SESSION["usertype"] = $row["usertype"];
                if (!$PrivAuthWorker->authenticate($_SESSION["usertype"]) && !$TimeAuthWorker->authenticate()) {
                    $this->authenticationStatus = 2;
                } else {
                    header("Location: " . GenerateRootPath::getRoot(1) . "/dashboard/");
                    exit;
                }
            } else {
                $this->authenticationStatus = 0;
            }
        }
        //generates header from <!DOCTYPE html> all the way to </head>
        //Title of the page is set in constructor i.e. new HeaderProduct("Title of page here");
        $headerFactory = new HeaderFactory();
        echo $headerFactory->startFactory(new HeaderProduct("Login - Forex Trading Simulator ", 1));
        echo <<<HTML
    <body class="blue lighten-5">
        <div class="container">
            <div id="login-card" class="pageCenter card
HTML;
        if ($this->authenticationStatus === 0) {
            echo " failed";
        }
        echo <<<HTML
">
                <div class="center">
                    <h3 class="title">Forex Trading Simulator</h3>
                    <h5 class="title top-margin">Exchange rates, made easier</h5>
                </div>
                <form id="loginform" name="loginform" method="post">
                    <div class="row">
                        <div class="input-field col s12 m10 l10 push-m1 push-l1">
                            <i class="material-icons prefix">account_circle</i>
HTML;
        echo "<input type=\"text\" required=\"\" name=\"username\" id=\"username\"";
        if ($this->authenticationStatus === 2 || $this->authenticationStatus === 0) {
            echo " value=\"" . htmlentities($_POST["username"], ENT_QUOTES, "UTF-8") . "\"";
        }
        echo "/>";
        echo <<<HTML
                            <label for="username">Username</label>
                        </div>
                    </div>
                    <div class="row">
                        <div class="input-field col s12 m10 l10 push-m1 push-l1">
                            <i class="material-icons prefix">vpn_key</i>
                            <input type="password" name="password" id="password" />
                            <label for="password">Password</label>
                        </div>
                    </div>
                    <div class="row input-field center" id="Submit">
                        <button class="btn waves-effect waves-light blue accent-4" type="submit" name="action">Login
                        </button>
                    </div>
                </form>
HTML;
        if ($this->authenticationStatus === 2) {
            $db = new UniversalConnect();
            $result = $db->query("SELECT starttime FROM startendtime LIMIT 1");
            $row = $result->fetch_assoc();
            $startTime = $row["starttime"];
            echo "<script>alert('The game has not started yet. It starts in " . FormatTimePassed::format($startTime) . ".');window.onload = function(){document.getElementById(\"password\").focus();};</script>";
            $db->close();
        }
        echo <<<HTML
            </div>
        </div>
    </body>
</html>
HTML;
    }