<?php
/*******************************************************************************
 *  [ bid monkey ]                                                             *
 *                                                                             *
 *  pedram amini (pedram.amini@tulane.edu)                                     *
 *  www.redhive.com                                                            *
 *                                                                             *
 *  tired of forgetting to place my bid on ebay auctions i threw together this *
 *  little script. usage is fairly self explanatory, but beware little to no   *
 *  error/sanity checking is done. which leads us right to...                  *
 *                                                                             *
 *  todo:                                                                      *
 *  - add some real error checking                                             *
 *  - grab/display item description                                            *
 *  - teach monkey how to bid on other auction sites                           *
 *                                                                             *
 *******************************************************************************/
?>

<html>
<head>
    <title>bidmonkey</title>

    <style type="text/css">
        <!--
        a:link    {color:#990000;text-decoration:none;}
        a:visited {color:#990000;text-decoration:none;}
        a:hover   {color:#C5C5C5;text-decoration:none;}
        -->
    </style>
</head>

<body bgcolor="#FFFFFF" marginwidth="0" marginheight="0" style='margin: -10px'>

<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" >
    <tr>
        <td valign="center">
            <!-- code may look mangled in view-source from here, why? i don't know. -->
            <script language="JavaScript">
                var random = Math.floor(Math.random() * 10);
                var monkey = "<img src=\"images/monkey";

                if (random % 2)
                    monkey = monkey + "1";
                else
                    monkey = monkey + "2";

                monkey = monkey + ".gif\" width=\"200\" height=\"450\" alt=\"monkey\">";

                document.writeln(monkey);
            </script>
        </td>

        <td>
            <img src="images/spacer.gif" height="1" width="25">
        </td>
<?
/******************************************************************************
 * form was submitted so get the values                                       *
 ******************************************************************************/
if ($form_submitted)    {
    
$makeBid file("http://cgi.ebay.com/aw-cgi/eBayISAPI.dll?MfcISAPICommand=MakeBid&item=" $itemnum "&maxbid=" $maxbid);

    if (
$makeBid)   {
        for (
$i 0$i count$makeBid ); $i++)  {
            if (
ereg("name=key"$makeBid[$i])) {
                
$key substr($makeBid[$i], strpos($makeBid[$i], "name=key value=\"") + 16);
                
$key substr($key0strpos($key"\""));
                break;
            }
            if (
$i == count($makeBid)-1)    {
                
// if we're here it means the key was not found ... tabooo
                
die("<p><center><b><font color=\"#990000\" size=\"4\">step 1 failed: monkey could not obtain key.</font></b></center>");
            }
        }
    }
/******************************************************************************
 * there was an error so display the error page                               *
 ******************************************************************************/
    
else
        die(
"<p><center><b><font color=\"#990000\" size=\"4\">step 1 failed: monkey could not find item.</font></b></center>");

/******************************************************************************
 * we have the values so display the countdown page                           *
 ******************************************************************************/
?>
        <td align="left" valign="center" width="100%">
            <font face="arial" size="2">
                bid<b>monkey</b><p><p>
                bidmonkey will bid using the following information ... <br>
                <font color="#336699">make sure these values are right</font><p>
<?
                
if (!$bchours$bchours 0;
                if (!
$bcmins)  $bcmins  0;
                if (!
$bcsecs)  $bcsecs  0;

                
$bidcount 3600 $bchours 60 $bcmins $bcsecs;

                echo 
"itemnum: "    $itemnum  "<br>";
                echo 
"quantity: "   $quantity "<br>";
                echo 
"key: "        $key      "<br>";
                echo 
"maxbid: "     $maxbid   "<br>";
                echo 
"countdown: "  $bchours  "hrs "  $bcmins   "mins " $bcsecs   "secs<br>";
                echo 
"username: "   $username "<br>";
                echo 
"password: "   $password "<br>";

                
$acceptbid "cgi.ebay.com/aw-cgi/eBayISAPI.dll?MfcISAPICommand=AcceptBid&item=" $itemnum .
                                
"&key="    $key      .
                                
"&maxbid=" $maxbid   .
                                
"&quant="  $quantity .
                                
"&userid=" $username .
                                
"&pass="   $password ;
?>
                <form name="counterform">
                    <input type="text" name="countertext" size="40">
                </form>

                <script language="JavaScript">
                    counter = <?echo $bidcount?>;

                    function countDown()  {
                        if (counter == 0)
                            window.location.replace("http://<?echo $acceptbid?>");
                        else    {
                            hrs  = Math.floor(counter / 3600);
                            mins = Math.floor((counter - 3600*hrs) / 60);
                            secs = counter - 3600*hrs - 60*mins;
                            window.document.counterform.countertext.value = "deploying monkey in: " + hrs + "hrs " + mins + "mins " + secs + "secs";
                            counter--;
                            setTimeout("countDown();", 1000);
                        }
                    }

                    setTimeout("countDown();", 0);  // begin the countdown
                </script>

                <p align="right">
                    <a href="source/bidmonkey.phps">view source</a>
                </p>
            </font>
        </td>
<?
}
else    {
/******************************************************************************
 * no form was submitted so display the form page                             *
 ******************************************************************************/
?>
        <td align="left" valign="center" width="100%">
            <font face="arial" size="2">
                bid<b>monkey</b><p>

                <font color="#336699">
                    frustrated that i had missed yet another ebay auction, i set out to train a monkey to do the job for me. we're still in initial training so bidmonkey knows little in the area of error/sanity checking. in other words: make sure you give him the right values here. the fields are fairly self explanatory. <i>maximum bid</i> is the maximum amount your willing to bid, the monkey will bid as low as possible but it would like to know how far your willing to go. <i>monkey deployment countdown</i> is when you want the monkey to place your bid. i generally check ebay for how much time is left and ask the monkey to bid 2 mins before the auctions ends.  also don't forget that you must leave your browser open in order for bidmonkey to work. if anyone actually uses this thing and wants support for another auction server, tell me and the monkey shall be trained. if you want to view the source use the link on the bottom right and not your browser button.
                </font>
                <p>

                <form method="post" action="<?echo $PHP_SELF?>">
                    item number: <br><font color="orange">(get this from ebay page)</font><br>
                    <input type="text" name="itemnum" size="25"><p>

                    quantity: <br><font color="orange">(generally this will be 1)</font><br>
                    <input type="text" name="quantity" size="25"><p>

                    maximum bid: <br><font color="orange">(maximum amount you wish to bid)</font><br>
                    <input type="text" name="maxbid" size="25"><p>

                    monkey deployment countdown: <br><font color="orange">(monkey will bid when counter reaches zero)</font><br>
                    <input type="text" name="bchours" size="5">hrs <input type="text" name="bcmins" size="5">mins <input type="text" name="bcsecs" size="5">secs<p>

                    username: <br><font color="orange">(your ebay userid)</font><br>
                    <input type="text" name="username" size="25"><p>

                    password: <br><font color="orange">(your ebay password)</font><br>
                    <input type="text" name="password" size="25"><p>

                    <input type="submit" name="form_submitted" value="go monkey">
                </form>
                <p align="right">
                    <a href="source/bidmonkey.phps">view source</a>
                </p>
            </font>
        </td>
<?
// end if
?>
    </tr>
</table>
</body>
</html>