Ejemplo n.º 1
0
function draw_coupon($time = false)
{
    global $client;
    global $error;
    global $onload, $body;
    $t = $client->t;
    settitle('Coupon');
    setmenu('balance');
    $outbox = $client->getoutbox();
    if (!$time) {
        $time = mq($_REQUEST['time']);
    }
    $items = $outbox[$time];
    $timestr = hsc($time);
    $datestr = datestr($time);
    if ($items) {
        foreach ($items as $item) {
            $request = $item[$t->REQUEST];
            if ($request == $t->SPEND) {
                $assetname = hsc($item[$t->ASSETNAME]);
                $formattedamount = hsc($item[$t->FORMATTEDAMOUNT]);
                $note = hsc($item[$t->NOTE]);
                if ($note) {
                    $note = "<tr><td><b>Note:</b></td><td><span style=\"margin: 5px;\">{$note}</span></td></tr>\n";
                }
            } elseif ($request == $t->COUPONENVELOPE) {
                $coupon = hsc(trim($item[$t->COUPON]));
                $body = <<<EOT
<br/>
<b>Coupon for outbox entry at {$datestr}</b>
<table border="1">
<tr><td><b>Amount:</b></td><td><span style="margin: 5px;">{$formattedamount} {$assetname}</span></td></tr>
{$note}<tr><td><b>Coupon:</b></td><td><span style="margin: 5px;">{$coupon}</span></td></tr>
</table>
EOT;
                return;
            }
        }
    }
    $error = "Couldn't find coupon: {$timestr}";
    draw_balance();
}
Ejemplo n.º 2
0
}
if ($product = $_GET["updatecart"]) {
    $qty = $_GET["qty"];
    if ($options = $_GET["options"]) {
        foreach ($options as $option) {
            $OptionList[$option] = $_GET[$option];
        }
    }
    echo "<script>alert('{$product} {$qty}');</script>";
    $cart->set_item($product, $qty, $OptionList);
    $cart->show_all();
}
function strtotime_uk($str)
{
    $str = preg_replace("/^\\s*([0-9]{1,2})[\\/\\. -]+([0-9]{1,2})[\\/\\. -]*([0-9]{0,4})/", "\\2/\\1/\\3", $str);
    $str = trim($str, '/');
    return strtotime($str);
}
function datestr($dt)
{
    date_default_timezone_set("Australia/Brisbane");
    $tm = strtotime_uk($dt);
    if ($tm > 0) {
        return date("Y-m-d H:i:s", $tm);
    }
    return "unknown";
}
if ($dt = $_GET["dt"]) {
    echo datestr($dt);
}
page_close(array("silent" => "silent"));
Ejemplo n.º 3
0
    function draw_history($start = 1, $count = false)
    {
        global $body;
        global $error;
        global $client;
        $t = $client->t;
        if ($count === false) {
            $count = $this->historycount();
        }
        $times = $client->gethistorytimes();
        if (is_string($times)) {
            $error = $times;
        } elseif (count($times) == 0) {
            $error = "No saved history";
        } else {
            settitle('History');
            setmenu('balance');
            // Need controls for pagination, and date search.
            // Eventually, recipient, note, and amount search, too.
            $cnt = count($times);
            $count2 = $count <= 0 ? $cnt : $count;
            if ($count2 >= $cnt) {
                $start = 1;
            }
            $strt = $start - 1;
            $end = $strt + $count2;
            if ($end > $cnt) {
                $end = $cnt;
            }
            $idx = 0;
            $body = "<br/>\n";
            $this->scroller($start, $count, $cnt);
            $body .= <<<EOT
<form method="post" action="./" autocomplete="off">
<input type="hidden" name="cmd" value="dohistory"/>
<input type="hidden" name="start" value="{$start}"/>
<input type="hidden" name="count" value="{$count}"/>
<input type="hidden" name="chkcnt" value="{$cnt}"/>
<table border="1">
<caption><b>=== History ===</b></caption>
<tr>
<th>Time</th>
<th>Request</th>
<th>From</th>
<th>To</th>
<th colspan="2">Amount</th>
<th>Note</th>
<th>Response</th>
<th>x</th>
</tr>

EOT;
            $nickcnt = 0;
            for ($i = $strt; $i < $end; $i++) {
                $time = $times[$i];
                $items = $client->gethistoryitems($time);
                if (is_string($items)) {
                    $error = $items;
                    break;
                }
                $datestr = datestr($time);
                $timestr = hsc($time);
                $datestr = "<span title=\"{$timestr}\">{$datestr}</span>";
                $body .= <<<EOT
<tr>

EOT;
                // There are currently three types of history items:
                // 1) Spend
                // 2) Process Inbox
                //   a) Accept or reject of somebody else's spend
                //   b) Acknowledgement of somebody else's accept or reject of my spend
                $item = $items[0];
                $request = $item[$t->REQUEST];
                if ($request == $t->SPEND) {
                    $req = 'spend';
                    $from = 'You';
                    $toid = $item[$t->ID];
                    $to = id_namestr($toid, $contact);
                    if (!@$contact[$t->CONTACT] && $toid != $client->id && $toid != 'coupon') {
                        $to .= <<<EOT
<br/>
<input type="hidden" name="nickid{$nickcnt}" value="{$toid}"/>
Nickname:
<input type="text" name="nick{$nickcnt}" size="10"/>
EOT;
                        $nickcnt++;
                    }
                    $amount = $item[$t->FORMATTEDAMOUNT];
                    $assetname = $item[$t->ASSETNAME];
                    $note = @$item[$t->NOTE];
                    if (!$note) {
                        $note = '&nbsp;';
                    }
                    $body .= <<<EOT
<td>{$datestr}</td>
<td>{$req}</td>
<td>{$from}</td>
<td>{$to}</td>
<td align="right" style="border-right-width: 0;">{$amount}</td>
<td style="border-left-width: 0;">{$assetname}</td>
<td>{$note}</td>
<td>&nbsp;</td>
<td>
<input type="hidden" name="time{$idx}" value="{$timestr}"/>
<input type="checkbox" name="chk{$idx}"/>
</td>

EOT;
                } elseif ($request == $t->PROCESSINBOX) {
                    $rows = array();
                    $req = false;
                    for ($j = 1; $j < count($items); $j++) {
                        for (; $j < count($items); $j++) {
                            $item = $items[$j];
                            $request = $item[$t->REQUEST];
                            if ($request == $t->SPENDACCEPT || $request == $t->SPENDREJECT) {
                                if ($req) {
                                    break;
                                }
                                $req = $request == $t->SPENDACCEPT ? 'accept' : 'reject';
                                $cancelp = $item[$t->CUSTOMER] == $client->id;
                                $response = $item[$t->NOTE];
                                $toid = $item[$t->CUSTOMER];
                                $to = id_namestr($toid, $contact, 'You');
                                if (!@$contact[$t->CONTACT] && $toid != $client->id && $toid != 'coupon') {
                                    $to .= <<<EOT
<br/>
<input type="hidden" name="nickid{$nickcnt}" value="{$toid}"/>
Nickname:
<input type="text" name="nick{$nickcnt}" size="10"/>
EOT;
                                    $nickcnt++;
                                }
                            } elseif ($request == $t->SPEND) {
                                $fromid = $item[$t->CUSTOMER];
                                $from = id_namestr($fromid, $contact, 'You');
                                if (!@$contact[$t->CONTACT] && $fromid != $client->id && $toid != 'coupon') {
                                    $from .= <<<EOT
<br/>
<input type="hidden" name="nickid{$nickcnt}" value="{$fromid}"/>
Nickname:
<input type="text" name="nick{$nickcnt}" size="10"/>
EOT;
                                    $nickcnt++;
                                }
                                $toid = $item[$t->ID];
                                if ($to) {
                                    // $to set above by spendaccept/spendredeem code
                                    if ($toid == 'coupon') {
                                        $to = "Coupon redeemed by:<br/>{$to}";
                                    }
                                } else {
                                    $to = id_namestr($toid, $contact, 'You');
                                    if (!$contact[$t->CONTACT] && $toid != $client->id && $toid != 'coupon') {
                                        $to .= <<<EOT
<br/>
<input type="hidden" name="nickid{$nickcnt}" value="{$toid}"/>
Nickname:
<input type="text" name="nick{$nickcnt}" size="10"/>
EOT;
                                        $nickcnt++;
                                    }
                                }
                                $amount = $item[$t->FORMATTEDAMOUNT];
                                $assetname = $item[$t->ASSETNAME];
                                $note = @$item[$t->NOTE];
                                if ($item[$t->ATREQUEST] == $t->ATSPEND) {
                                    $req = $cancelp ? "={$req}" : "@{$req}";
                                }
                            }
                        }
                        if ($req) {
                            $row = array('req' => $req, 'from' => $from, 'to' => $to, 'amount' => $amount, 'assetname' => $assetname, 'note' => $note, 'response' => $response);
                            $rows[] = $row;
                            if ($j > 1) {
                                $j--;
                            }
                            $req = false;
                            $from = false;
                            $to = false;
                            $amount = false;
                            $assetname = false;
                            $note = false;
                            $response = false;
                        }
                    }
                    $rowcnt = count($rows);
                    if ($rowcnt > 0) {
                        $body .= "<td rowspan=\"{$rowcnt}\">{$datestr}</td>\n";
                        $first = true;
                        foreach ($rows as $row) {
                            if (!$first) {
                                $body .= "<tr>\n";
                            }
                            $req = $row['req'];
                            $from = $row['from'];
                            $to = $row['to'];
                            $amount = $row['amount'];
                            $assetname = $row['assetname'];
                            $note = $row['note'];
                            $response = $row['response'];
                            $checkcode = '';
                            if ($first) {
                                $checkcode = <<<EOT

<td rowspan="{$rowcnt}">
<input type="hidden" name="time{$idx}" value="{$timestr}"/>
<input type="checkbox" name="chk{$idx}"/>
</td>
EOT;
                                $first = false;
                            }
                            if (!$note) {
                                $note = '&nbsp;';
                            }
                            if (!$response) {
                                $response = '&nbsp;';
                            }
                            $body .= <<<EOT
<td>{$req}</td>
<td>{$from}</td>
<td>{$to}</td>
<td align="right" style="border-right-width: 0;">{$amount}</td>
<td style="border-left-width: 0;">{$assetname}</td>
<td>{$note}</td>
<td>{$response}</td>{$checkcode}
</tr>

EOT;
                        }
                    }
                } else {
                    $req = hsc($req);
                    $body .= <<<EOT
<td>{$datestr}</td>
<td>{$req}</td>
<td colspan="6">Unknown request type</td>

EOT;
                }
                $body .= "</tr>\n";
                $idx++;
            }
            if ($nickcnt > 0) {
                $body .= <<<EOT
<input type="hidden" name="nickcnt" value="{$nickcnt}"/>

EOT;
                $submitlabel = "Delete Checked & Add Nicknames";
            } else {
                $submitlabel = "Delete Checked";
            }
            $body .= <<<EOT
</table>
<br/>
<input type="submit" name="delete" value="{$submitlabel}"/>
<input type="submit" name="deleteolder" value="Delete Checked & Older"/>
</form>

EOT;
            $this->scroller($start, $count, $cnt);
            if (hideinstructions()) {
                $body .= <<<EOT
<a href="./?cmd=toggleinstructions&page=history">Show Instructions</a>

EOT;
            } else {
                $body .= <<<EOT
<table border="1">
<caption><b>=== Key ===</b></caption>
<tr><td>spend</td><td>You made a spend</td></tr>
<tr><td>accept</td><td>You accepted a spend</td></tr>
<tr><td>reject</td><td>You rejected a spend</td></tr>
<tr><td>@accept</td><td>You acknowledged acceptance of your spend</td></tr>
<tr><td>@reject</td><td>You acknowledged rejection of your spend</td></tr>
<tr><td>=reject</td><td>You acknowledged your cancel of a spend</td></tr>
<tr><td>=accept</td><td>You acknowledged your acceptance of a coupon you spent to yourself</td></tr>
</table>
<br/>
<a href="./?cmd=toggleinstructions&page=history">Hide Instructions</a>

EOT;
            }
        }
        if ($error) {
            draw_balance();
        }
    }