<?php
require "./Cart.php";

if (empty($blist)) {
     $sql =    "SELECT BuyerID FROM Buyers WHERE Name LIKE '%$name%' ORDER BY Name";
     $buyer = mysql_query($sql);
     $bno = 0;
     while (list($bid) = mysql_fetch_row($buyer)) {
          $bset[$bno++] = $bid;
     }
     mysql_free_result($buyer);
} else {
     $bset = explode(',', $blist);
     $bno = count($bset);
}

$step = 1;
if (empty($ix))
     $ix = 0;

$prev = $ix - $step;
$next = $ix + $step;

for ($i = 0; ($i < $step) && ($ix+$i < $bno); $i++) {
     $pset[] = $bset[$ix + $i];
}

$blist = implode(',', $bset);
$plist = implode(',', $pset);

adminHeader('','');

blueFont("Arial","<B></B><BR><BR>");
echo "<TABLE border=1>";
echo "<TR><TD>Name</td><td>Email</td></tr>";

$sql =    "SELECT BuyerID, Name, Email FROM Buyers WHERE BuyerID IN ($plist) ORDER BY Name";
$buyer = mysql_query($sql);

while (list($bid, $bname, $bemail) = mysql_fetch_row($buyer)) {
     fontFace("Arial","<TR><td>$bname</td><td>$bemail</td>");
     fontFace("Arial","<td><A href=$PHP_SELF?topic=buyerDetail.php&BID=$bid>View Buyer Detail</a></td>");
     fontFace("Arial","<td><A href=$PHP_SELF?topic=searchReceiptsResponse.php&BID=$bid>View Buyer Orders</a></td>");
     fontFace("Arial","</TR>");
     $i++;
}
echo "</TABLE>";

if ($i == 0)
     blueFont("Arial","<B>No buyers matched name</B><BR><BR>");

echo '<table><tr>';
if ($prev >= 0) {
     echo "<td valign=top>\n";
     echo "<FORM METHOD=post action=$PHP_SELF?topic=buyerList.php>\n";
     echo "<input type=hidden name=blist value=$blist>\n";
     echo "<input type=hidden name=ix value=$prev>\n";
     echo "<input type=submit name=go value=prev></form></td>\n";
}
if ($next < $bno) {
     echo "<td valign=top>\n";
     echo "<FORM METHOD=post action=$PHP_SELF?topic=buyerList.php>\n";
     echo "<input type=hidden name=blist value=$blist>\n";
     echo "<input type=hidden name=ix value=$next>\n";
     echo "<input type=submit name=go value=next></form></td>\n";
}
echo '</tr></table>';

adminFooter($Relative);
?>
