Пример #1
0
function draw_assets($scale = false, $precision = false, $assetname = false, $storage = false)
{
    global $onload, $body;
    global $error;
    global $client;
    $t = $client->t;
    $onload = "document.forms[0].scale.focus()";
    settitle('Assets');
    setmenu('assets');
    $scale = hsc($scale);
    $precision = hsc($precision);
    $assetname = hsc($assetname);
    $body .= <<<EOT
<span style="color: red;">{$error}</span><br/>
<form method="post" action="./" autocomplete="off">
<input type="hidden" name="cmd" value="asset"/>
<table>
<tr>
<td><b>Scale:</b></td>
<td><input type="text" name="scale" size="3" value="{$scale}"/>
</tr><tr>
<td><b>Precision:</b></td>
<td><input type="text" name="precision" size="3" value="{$precision}"/></td>
</tr><tr>
<td><b>Asset name:</b></td>
<td><input type="text" name="assetname" size="30" value="{$assetname}"/></td>
</tr><tr>
<td><b>Storage fee (%/year):</b></td>
<td><input type="text" name="storage" size="5" value="{$storage}"/></td>
</tr><tr>
<td></td>
<td><input type="submit" name="newasset" value="Add Asset"/>
<input type="submit" name="cancel" value="Cancel"/></td>
</tr>
</table>
</form>

EOT;
    $assets = $client->getassets();
    if (count($assets) > 0) {
        $body .= '<form method="post" action="./" autocomplete="off">
<table border="1">
<tr>
<th>Asset name</th>
<th>Scale</th>
<th>Precision</th>
<th>Storage Fee<br/>(%/year)</th>
<th>Owner</th>
<th>Asset ID</th>
</tr>
';
        $incnt = 0;
        foreach ($assets as $asset) {
            $ownerid = $asset[$t->ID];
            $namestr = id_namestr($ownerid, $contact);
            $assetid = $asset[$t->ASSET];
            $scale = $asset[$t->SCALE];
            $precision = $asset[$t->PRECISION];
            $assetname = $asset[$t->ASSETNAME];
            $percent = $asset[$t->PERCENT];
            if ($ownerid == $client->id) {
                $percent = <<<EOT
<input type="hidden" name="assetid{$incnt}" value="{$assetid}"/>
<input type="hidden" name="opercent{$incnt}" value="{$percent}"/>
<input type="text" name="percent{$incnt}" value="{$percent}" size="10" style="text-align: right;"/>
EOT;
                $incnt++;
            }
            if (!$percent) {
                $percent = "&nbsp;";
            }
            $body .= <<<EOT
<tr>
<td>{$assetname}</td>
<td align="right">{$scale}</td>
<td align="right">{$precision}</td>
<td align="right">{$percent}</td>
<td>{$namestr}</td>
<td>{$assetid}</td>
</tr>

EOT;
        }
        $body .= "</table>\n";
        if ($incnt > 0) {
            $body .= '<input type="hidden" name="percentcnt" value="' . $incnt . '"/>
<input type="hidden" name="cmd" value="asset"/>
<br/><input type="submit" name="updatepercent" value="Update Storage Fees"/>
';
        }
        $body .= "</form>\n";
    }
}
Пример #2
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();
        }
    }