#!/usr/local/bin/perl -- -*- C -*-

# $Header: /cys/people/brenner/http/docs/web/RCS/simple-form.cgi,v 1.2 1995/04/07 21:36:57 brenner Exp $
# Copyright (C) 1994 Steven E. Brenner
# This is a small demonstration script to demonstrate the use of 
# the cgi-lib.pl library

require "cgi-lib.pl";

MAIN:
{
# Read in all the variables set by the form
  &ReadParse(*input);

open(ratefile, "ratefile") || die "cant open file";
$cnt=0;
$none=0;
while(<ratefile>){
chop;
($names[$cnt],$convert[$cnt]) =split(/:/);
$cnt++;
}

$numcurrencies=$cnt;




for($i = 0; $i < $numcurrencies; $i++){



if($input{'currency'} eq $names[$i]){
		$constant=$i;
		$none=1;
		$checked[$constant]="checked";	
	}
	




}


 if($none == 0){
	$checked[$i]=" ";
	$constant=0;
	$input{'currency'}="dollar";
	$input{'amount'}=1.00;
	$checked[$constant]="checked";
	
 }


$currency[0]=($convert[0]/$convert[$constant])*$input{'amount'};
$printout[0]="$input{'amount'} $input{'currency'}  = $currency[0] $names[0]<BR>";
				
	for($i = 0; $i < $numcurrencies; $i++){

       $radio[$i]="<input type=\"radio\" name=\"currency\" value=$names[$i] $checked[$i]> $names[$i] <BR>";

		
   
		if($i != $constant) {
		$currency[$i]=($currency[0]*$convert[$i]);
		$printout[$i]="$input{'amount'} $input{'currency'}  = $currency[$i] $names[$i]<BR>";
		}
		
		else {
		$printout[$i]="";
		}
	
	}
	}





print "Content-type: text/html\n\n";


print <<"ending_print_tag"; 

<html>
<head><title>exchange rates</title></head>
<BODY BGCOLOR="#999999">
<BLOCKQUOTE><BLOCKQUOTE>
<h1>Calcuate foriegn exchange rates</h1>
<hr noshade>

<FORM Method=POST Action="docal3.cgi">
<P>

which base curency <BR>
@radio

<P>

<P>
<STRONG><FONT SIZE="-1">enter amount no more the 7 numbers</STRONG></FONT><BR>
<INPUT type=text name="amount" SIZE="8" MAXLENGTH="7" VALUE="$input{'amount'}">
</P>
<P>



<input type=submit name="dum" VALUE="submit">



<h3>current values based on input</h3>
@printout



<br>
<A HREF="index.html">back home</a>

</form>
</center>
<hr noshade>
</body>
</html>

ending_print_tag
