Example #1
0
function draw_balance($spend_amount = false, $recipient = false, $note = false, $toacct = false, $tonewacct = false, $nickname = false)
{
    global $client;
    global $error;
    global $onload, $body;
    global $iphone, $keephistory;
    global $fraction_asset;
    $t = $client->t;
    $bankid = $client->bankid();
    $banks = $client->getbanks();
    settitle('Balance');
    setmenu('balance');
    $saveerror = $error;
    $error = false;
    $bankopts = '';
    foreach ($banks as $bid => $b) {
        if ($bid != $bankid) {
            if ($client->userreq($bid) != -1) {
                $bname = $b[$t->NAME];
                $burl = $b[$t->URL];
                $bankopts .= "<option value=\"{$bid}\">{$bname} {$burl}</option>\n";
            }
        }
    }
    $bankcode = '';
    if ($bankopts) {
        $bankcode .= <<<EOT
<form method="post" action="./" autocomplete="off">
<input type="hidden" name="cmd" value="bank">
<select name="bank">
<option value="">Choose a bank...</option>
{$bankopts}
</select>
<input type="submit" name="selectbank" value="Change Bank"/>
</form>

EOT;
    }
    $inboxcode = '';
    $balcode = '';
    $assetlist = '';
    $assetidx = 0;
    $acctidx = 0;
    $gotbal = false;
    $contacts = $client->getcontacts();
    $havecontacts = count($contacts) > 0;
    if (!$error && $client->bankid) {
        // Print inbox, if there is one
        $inbox = $client->getinbox();
        $outbox = $client->getoutbox();
        $accts = $client->getaccts();
        $acctoptions = '';
        if (count($accts) > 1) {
            $first = true;
            foreach ($accts as $acct) {
                $acct = hsc($acct);
                $acctoptions .= <<<EOT
          <option value="{$acct}">{$acct}</option>

EOT;
            }
        }
        // Try again, in case we just needed to sync.
        // Maybe this should be hidden by getinbox()
        if (is_string($inbox)) {
            $inbox = $client->getinbox();
        }
        $acctheader = '';
        if (is_string($inbox)) {
            $error = "Error getting inbox: {$inbox}";
            $inbox = array();
        } elseif (count($inbox) == 0) {
            $inboxcode .= "<b>=== Inbox empty ===</b><br/><br/>\n";
        } else {
            if ($acctoptions) {
                $acctheader = "\n<th>To Acct</th>";
            }
            $inboxcode .= <<<EOT
<table border="1">
<caption><b>=== Inbox ===</b></caption>
<tr>
<th>Request</th>
<th>From</th>
<th colspan="2">Amount</th>
<th>Note</th>
<th>Action</th>
<th>Reply</th>{$acctheader}
<th>Time</th>
</tr>

EOT;
            $seloptions = <<<EOT
<option value="accept">Accept</option>
<option value="reject">Reject</option>
<option value="ignore">Ignore</option>

EOT;
            if (is_string($outbox)) {
                $error = "Error getting outbox: {$outbox}";
                $outbox = array();
            }
            $nonspends = array();
            $spendcnt = 0;
            $assets = $client->getassets();
            foreach ($inbox as $itemkey => $item) {
                $item = $item[0];
                $request = $item[$t->REQUEST];
                $fromid = $item[$t->ID];
                $time = $item[$t->TIME];
                $namestr = id_namestr($fromid, $contact);
                if ($request != $t->SPEND) {
                    $msgtime = $item[$t->MSGTIME];
                    $outitem = $outbox[$msgtime];
                    // outbox entries are array($spend, $tranfee)
                    if ($outitem) {
                        $outitem = $outitem[0];
                    }
                    if ($outitem) {
                        $item[$t->ASSETNAME] = $outitem[$t->ASSETNAME];
                        $item[$t->FORMATTEDAMOUNT] = $outitem[$t->FORMATTEDAMOUNT];
                        $item['reply'] = $item[$t->NOTE];
                        $item[$t->NOTE] = $outitem[$t->NOTE];
                    }
                    $nonspends[] = $item;
                } else {
                    $assetid = $item[$t->ASSET];
                    $assetname = hsc($item[$t->ASSETNAME]);
                    if (!@$assets[$assetid]) {
                        $assetname .= ' <span style="color: red;"><i>(new)</i></span>';
                    }
                    $amount = hsc($item[$t->FORMATTEDAMOUNT]);
                    $itemnote = hsc($item[$t->NOTE]);
                    if (!$itemnote) {
                        $itemnote = '&nbsp;';
                    } else {
                        $itemnote = str_replace("\n", "<br/>\n", $itemnote);
                    }
                    $selname = "spend{$spendcnt}";
                    $notename = "spendnote{$spendcnt}";
                    $acctselname = "acct{$spendcnt}";
                    if (!@$contact[$t->CONTACT]) {
                        $namestr .= <<<EOT
<br/>
<input type="hidden" name="spendid{$spendcnt}" value="{$fromid}"/>
Nickname:
<input type="text" name="spendnick{$spendcnt}" size="10"/>
EOT;
                    }
                    $timecode = <<<EOT
<input type="hidden" name="spendtime{$spendcnt}" value="{$time}">
EOT;
                    $spendcnt++;
                    $selcode = <<<EOT
<select name="{$selname}">
{$seloptions}
</select>

EOT;
                    $acctcode = '';
                    if ($acctoptions) {
                        $acctcode = <<<EOT
<td><select name="{$acctselname}">
{$acctoptions}
</select></td>
EOT;
                    }
                    $date = datestr($time);
                    $inboxcode .= <<<EOT
{$timecode}
<tr>
<td>Spend</td>
<td>{$namestr}</td>
<td align="right" style="border-right-width: 0;">{$amount}</td>
<td style="border-left-width: 0;">{$assetname}</td>
<td>{$itemnote}</td>
<td>{$selcode}</td>
<td><textarea name="{$notename}" cols="20" rows="2"></textarea></td>
{$acctcode}
<td>{$date}</td>
</tr>

EOT;
                }
            }
            $nonspendcnt = 0;
            foreach ($nonspends as $item) {
                $request = $item[$t->REQUEST];
                $fromid = $item[$t->ID];
                $reqstr = $request == $t->SPENDACCEPT ? "Accept" : "Reject";
                $time = $item[$t->TIME];
                $namestr = id_namestr($fromid, $contact);
                $assetname = hsc($item[$t->ASSETNAME]);
                $amount = hsc($item[$t->FORMATTEDAMOUNT]);
                $itemnote = hsc($item[$t->NOTE]);
                if (!$itemnote) {
                    $itemnote = '&nbsp;';
                } else {
                    $itemnote = $itemnote = str_replace("\n", "<br/>\n", $itemnote);
                }
                $reply = hsc($item['reply']);
                if (!$reply) {
                    $reply = '&nbsp;';
                } else {
                    $reply = str_replace("\n", "<br/>\n", $reply);
                }
                $selname = "nonspend{$nonspendcnt}";
                if (!@$contact[$t->CONTACT]) {
                    $namestr .= <<<EOT
<br/>
<input type="hidden" name="nonspendid{$nonspendcnt}" value="{$fromid}"/>
Nickname:
<input type="text" name="nonspendnick{$nonspendcnt}" size="10"/>
EOT;
                }
                $timecode = <<<EOT
<input type="hidden" name="nonspendtime{$nonspendcnt}" value="{$time}">
EOT;
                $nonspendcnt++;
                $selcode = <<<EOT
<input type="checkbox" name="{$selname}" checked="checked">Remove</input>

EOT;
                $date = datestr($time);
                $acctcode = '';
                if ($acctoptions) {
                    $acctcode = "\n<td>&nbsp;</td>";
                }
                $inboxcode .= <<<EOT
{$timecode}
<tr>
<td>{$reqstr}</td>
<td>{$namestr}</td>
<td align="right" style="border-right-width: 0;">{$amount}</td>
<td style="border-left-width: 0;">{$assetname}</td>
<td>{$itemnote}</td>
<td>{$selcode}</td>
<td>{$reply}</td>{$acctcode}
<td>{$date}</td>
</tr>

EOT;
            }
            $inboxcode = <<<EOT
<form method="post" action="./" autocomplete="off">
<input type="hidden" name="cmd" value="processinbox"/>
<input type="hidden" name="spendcnt" value="{$spendcnt}"/>
<input type="hidden" name="nonspendcnt" value="{$nonspendcnt}"/>
{$inboxcode}
</table>
<br/>
<input type="submit" name="submit" value="Process Inbox"/>
</form>

EOT;
        }
        // Index the spends in the inbox by MSGTIME
        $inboxspends = array();
        foreach ($inbox as $items) {
            $item = $items[0];
            $request = $item[$t->REQUEST];
            $inboxspends[$item[$t->MSGTIME]] = $item;
        }
        // Prepare outbox display
        $cancelcount = 0;
        $outboxcode = '';
        foreach ($outbox as $time => $items) {
            $timestr = hsc($time);
            $date = datestr($time);
            foreach ($items as $item) {
                $request = $item[$t->REQUEST];
                if ($request == $t->SPEND) {
                    $recip = $item[$t->ID];
                    if (!$outboxcode) {
                        $outboxcode = <<<EOT
<table border="1">
<caption><b>=== Outbox ===</b></caption>
<tr>
<th>Time</th>
<th>Recipient</th>
<th colspan="2">Amount</th>
<th>Note</th>
<th>Action</th>
</tr>
EOT;
                    }
                    $assetname = hsc($item[$t->ASSETNAME]);
                    $amount = hsc($item[$t->FORMATTEDAMOUNT]);
                    $not = hsc($item[$t->NOTE]);
                    if (!$not) {
                        $not = '&nbsp;';
                    }
                    $label = 'Cancel';
                    if ($recip == $t->COUPON) {
                        $label = 'Redeem';
                        $recip = hsc($recip);
                        $timearg = urlencode($time);
                        $namestr = <<<EOT
<a href="./?cmd=coupon&time={$timearg}">{$recip}</a>
EOT;
                    } else {
                        $namestr = id_namestr($recip, $contact);
                    }
                    $cancelcode = '&nbsp;';
                    if (!@$inboxspends[$time]) {
                        $cancelcode = <<<EOT
<input type="hidden" name="canceltime{$cancelcount}" value="{$timestr}"/>
<input type="submit" name="cancel{$cancelcount}" value="{$label}"/>

EOT;
                        $cancelcount++;
                    }
                    $outboxcode .= <<<EOT
<tr>
<td>{$date}</td>
<td>{$namestr}</td>
<td align="right" style="border-right-width: 0;">{$amount}</td>
<td style="border-left-width: 0;">{$assetname}</td>
<td>{$not}</td>
<td>{$cancelcode}</td>
</tr>
EOT;
                }
            }
        }
        if ($outboxcode) {
            $outboxcode .= "</table>\n";
            if ($cancelcount > 0) {
                $outboxcode = <<<EOT
<form method="post" action="./" autocomplete="off">
<input type="hidden" name="cmd" value="canceloutbox"/>
<input type="hidden" name="cancelcount" value="{$cancelcount}"/>
{$outboxcode}
</form>

EOT;
            }
        }
        $balance = $client->getbalance();
        if (is_string($balance)) {
            $error = $balance;
        } elseif (count($balance) > 0) {
            $balcode = "<table border=\"1\">\n<caption><b>=== Balances ===</b></caption>\n<tr><td><table>";
            $firstacct = true;
            foreach ($balance as $acct => $assets) {
                $acct = hsc($acct);
                $assetcode = '';
                $newassetlist = '';
                foreach ($assets as $asset => $data) {
                    if ($data[$t->AMOUNT] != 0) {
                        $gotbal = true;
                        $assetid = hsc($data[$t->ASSET]);
                        $assetname = hsc($data[$t->ASSETNAME]);
                        $formattedamount = hsc($data[$t->FORMATTEDAMOUNT]);
                        $submitcode = '';
                        $newassetlist .= <<<EOT
<input type="hidden" name="assetid{$acctidx}|{$assetidx}" value="{$assetid}"/>

EOT;
                        $submitcode = <<<EOT
<input type="submit" name="spentasset{$acctidx}|{$assetidx}" value="Spend"/>

EOT;
                        $assetidx++;
                        $assetcode .= <<<EOT
<tr>
<td align="right"><span style="margin-right: 5px">{$formattedamount}</span></td>
<td>{$assetname}</td>
<td>{$submitcode}</td>
</tr>

EOT;
                    }
                }
                if ($assetcode) {
                    if (!$firstacct) {
                        $balcode .= "<tr><td colspan=\"3\">&nbsp;</td></tr>\n";
                    } else {
                        $firstacct = false;
                    }
                    $balcode .= "<tr><th colspan=\"3\">- {$acct} -</th></tr>\n{$assetcode}";
                }
                if ($newassetlist) {
                    $assetlist .= <<<EOT
<input type="hidden" name="acct{$acctidx}" value="{$acct}"/>
{$newassetlist}
EOT;
                    $acctidx++;
                }
            }
            $balcode .= "</table>\n</td></tr></table>\n";
            $enabled = $keephistory == 'keep' ? 'enabled' : 'disabled';
            if ($fraction_asset && $_COOKIE['debug']) {
                $fraction = $client->getfraction($fraction_asset);
                $amt = $fraction[$t->AMOUNT];
                $scale = $fraction[$t->SCALE];
                $balcode .= "Fractional balance: {$amt}";
                if ($scale) {
                    $balcode .= " x 10<sup>-{$scale}</sup>";
                }
                $balcode .= "<br/>\n";
            }
            $balcode .= <<<EOT
<br/>
<a href="./?cmd=rawbalance">Show raw balance</a>
<br/>
<a href="./?cmd=history">Show history</a> ({$enabled})
<br/>

EOT;
        }
        $openspend = '';
        $spendcode = '';
        $closespend = '';
        $instructions = '';
        $storagefeecode = '';
        if ($gotbal) {
            $recipopts = '<select name="recipient">
<option value="">Choose contact...</option>
';
            $found = false;
            foreach ($contacts as $contact) {
                $namestr = contact_namestr($contact);
                $recipid = $contact[$t->ID];
                if ($recipid != $client->id) {
                    $selected = '';
                    if ($recipid == $recipient) {
                        $selected = ' selected="selected"';
                        $found = true;
                    }
                    $recipopts .= <<<EOT
<option value="{$recipid}"{$selected}>{$namestr}</option>

EOT;
                }
            }
            $recipopts .= "</select>\n";
            $selectmint = '';
            if ($recipient == $t->COUPON) {
                $selectmint = ' checked="checked"';
            }
            $recipientid = '';
            if (!$found && $recipient != $t->COUPON) {
                $recipientid = $recipient;
            }
            $openspend = '<form method="post" action="./" autocomplete="off">
<input type="hidden" name="cmd" value="spend"/>

';
            $acctoptions = '';
            if (count($accts) > 1) {
                $first = true;
                foreach ($accts as $acct) {
                    $selcode = '';
                    if ($acct == $toacct) {
                        $selcode = ' selected="selected"';
                    }
                    $acct = hsc($acct);
                    $acctoptions .= <<<EOT
<option value="{$acct}"{$selcode}>{$acct}</option>

EOT;
                }
            }
            $acctcode = '';
            if ($acctoptions) {
                $acctcode = <<<EOT

<td><select name="toacct">
<option value="">Select or fill-in below...</option>
{$acctoptions}
</select></td>
</tr>
<tr>
<td><b>&nbsp;</b></td>

EOT;
            }
            $storagefeecode = '';
            $storagefees = $client->getstoragefee();
            if (is_string($storagefees)) {
                $error = $storagefees;
                $storagefees = array();
            }
            $storagefeecode = '';
            if (count($storagefees) > 0) {
                $storagefeecode = <<<EOT
<form method="post" action="./" autocomplete="off">
<input type="hidden" name="cmd" value="storagefees"/>
<table border="1">
<caption><b>=== Storage Fees ===</b></caption>
<tr><td><table>

EOT;
                foreach ($storagefees as $assetid => $storagefee) {
                    $formattedamount = $storagefee[$t->FORMATTEDAMOUNT];
                    $assetname = $storagefee[$t->ASSETNAME];
                    $time = $storagefee[$t->TIME];
                    $timestr = hsc($time);
                    $date = datestr($time);
                    $storagefeecode .= <<<EOT
<tr>
<td align="right"><span style="margin-right: 5px">{$formattedamount}</span></td>
<td><span style="margin-right: 5px">{$assetname}</span></td>
<td>{$date}</td>
</tr>

EOT;
                }
                $storagefeecode .= <<<EOT
</table></td></tr>
</table>
<input type="submit" name="accept" value="Move to Inbox"/>
</form>

EOT;
            }
            $disablemint = '';
            if ($client->id == $client->bankid) {
                $selectmint = '';
                $disablemint = ' disabled="disabled"';
            }
            $spendcode = <<<EOT

<table>
<tr>
<td><b>Spend amount:</b></td>
<td><input type="text" name="amount" size="20" value="{$spend_amount}" style="text-align: right;"/>
</tr><tr>
<td><b>Recipient:</b></td>
<td>{$recipopts}
<input type="checkbox" name="mintcoupon"{$selectmint}{$disablemint}>Mint coupon</input></td>
</tr><tr>
<td><b>Note:</b></td>
<td><textarea name="note" cols="40" rows="10">{$note}</textarea></td>
</tr><tr>
<td><b>Recipient ID:</b></td>
<td><input type="text" name="recipientid" size="40" value="{$recipientid}"/>
<input type="checkbox" name="allowunregistered">Allow unregistered</input></td>
</tr><tr>
<td><b>Nickname:</b></td>
<td><input type="text" name="nickname" size="30" value="{$nickname}"/></td>
<tr>
<td><b>Transfer to:</b></td>{$acctcode}
<td><input type="text" name="tonewacct" size="30" value="{$tonewacct}"/></td>
</tr>
</table>
EOT;
            $onload = "document.forms[0].amount.focus()";
            $closespend = "</form>\n";
            $historytext = ($keephistory == 'keep' ? "Disable" : "Enable") . " history";
            $instructions = '<p><a href="./?cmd=togglehistory">' . $historytext . "</a>\n";
            if (hideinstructions()) {
                $instructions .= '<br>
<a href="./?cmd=toggleinstructions">Show Instructions</a>
</p>
';
            } else {
                $instructions .= <<<EOT
</p>
<p>
To make a spend, fill in the "Spend amount", choose a "Recipient" or
enter a "Recipient ID, enter (optionally) a "Note", and click the
"Spend" button next to the asset you wish to spend.
</p>
<p>
To transfer balances, enter the "Spend Amount", select or fill-in the
"Transfer to" name (letters, numbers, and spaces only), and click
the"Spend" button next to the asset you want to transfer from. Each
storage location costs one usage token, and there is currently no way
to recover an unused location. 0 balances will show only on the raw
balance screen.
</p>
<p>
To mint a coupon, enter the "Spend Amount", check the "Mint coupon"
box, and click the "Spend" button next to the asset you want to
transfer to the coupon. You can redeem a coupon on the "Banks" page.
</p>
<p>
Entering a "Nickname" will add the "Recipient ID" to your contacts
list with that nickname, or change the nickname of the selected
"Recipient".
</p>
<p>
<a href="./?cmd=toggleinstructions">Hide Instructions</a>
</p>
EOT;
            }
        }
    }
    if ($saveerror) {
        if ($error) {
            $error = "{$saveerror}<br/>{$error}";
        } else {
            $error = $saveerror;
        }
    }
    if ($error) {
        $error = "<span style=\"color: red\";\">{$error}</span>\n";
    }
    $fullspend = <<<EOT
{$openspend}
<table>
<tr>
<td valign="top">
{$assetlist}{$balcode}
</td>

EOT;
    if ($iphone) {
        $fullspend .= "</tr>\n<tr>\n";
    }
    $fullspend .= <<<EOT
<td valign="top">
{$spendcode}
</td>
</table>
{$closespend}
EOT;
    $body = "{$error}<br/>{$bankcode}{$inboxcode}{$fullspend}{$outboxcode}{$storagefeecode}{$instructions}";
}
Example #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();
        }
    }