#!/usr/bin/perl

use CGI qw(:standard);



$invitems = param("items");
$invingreds = param("ingreds");

print header();

$userinfo = cookie("powerstone_mixomatic_items");

($iteminfo,$ingredinfo) = split(/\t/,$userinfo);     

foreach $key (split (/\,/,$iteminfo)){
    $checkeditem{$key} = " CHECKED ";
}
foreach $key (split (/\,/,$ingredinfo)){
    $checkedingred{$key} = " CHECKED ";
}


print<<__EOQ__;
<HEAD><TITLE>Power Stone 2 Mix-o-Matic</TITLE></HEAD>
<FORM ACTION="mixomatic.cgi">
    <INPUT TYPE="HIDDEN" NAME="ui" VALUE="on">
<BODY BGCOLOR="#FFFFFF">
<div align="center">
<B>Easy Mix-o-Matic Interface</B> - <A HREF=".">Back</A><BR>
Select the Items and Ingredients you currently have, then click "Submit"
<TABLE BORDER=0>
<TR><TH ALIGN=CENTER COLSPAN=4>Items</TH></TR>
<TR><TD VALIGN=TOP>

__EOQ__



$oldlevel = "";
open(READ,"items.txt");
while(defined($line=<READ>)){
    chomp $line;
    $line =~ s/( *)$//;
    $line =~ /(\d+)\#(\d+)( *)(.*)$/;
    $level = $1;
    $itemno = $2;
    $itemname = $4;

    $what = $itemno;


    $itemlist {$itemno} = $itemname;




    

}
$i = 0;
foreach $key (sort{$a <=> $b} keys %itemlist){
    if($i % 31 ==0 && $i != 0){ print "</TD><TD VALIGN=TOP>\n";}
    print <<__EOQ__;
    <INPUT TYPE=CHECKBOX $checkeditem{$key} NAME="item$key">#$key $itemlist{$key}<BR>
__EOQ__
    $i++;
}
print "</TR><TR><TH COLSPAN=2>\n";
print "<B>Ingredients</B><BR></TH>\n";
print "</TR><TR><TD>\n";

close READ;
open(READ,"ingred.txt");
while(defined($line=<READ>)){
    chomp $line;
    $line =~ /^(\d+)\#(.*)\#(.*)$/;

    $itemno = $1;
    $itemname = $2;
    $stuff = $3;

    if($stuff =~ /^(.*)(\ \ +)(.*?)$/){
    $cost = $3;
}
    if($itemno == 12) { print "</TD><TD>\n";}
    print<<__EOQ__;
<INPUT TYPE="CHECKBOX" $checkedingred{$itemno}  NAME="ingred$itemno">
    \@$itemno $itemname<BR>
__EOQ__

}
    

print <<__EOQ__;
</TD><TD ALIGN=CENTER colspan=2> 
Put checks next to the items and ingredients<BR>

that you currently own. Then hit 'Submit' to<BR>
see what other items you can by mixing them.<P>
<INPUT TYPE="SUBMIT" VALUE="Submit">



__EOQ__

close READ;


print "</TD></TR></TABLE></FORM>\n\n";


















