#!/usr/local/bin/perl

###########################################################
#**********************************************************
# Interactive resume program
# Ronald Schmidt
# project initiated 12/97
#
# 
#
# Since "here" documents (eg print <<EOF) are used frequently
# many comments are in html format <!-- -->.
#**********************************************************
###########################################################

require "cgi-lib.pl";
&ReadParse(*input);

###########################################################
# Formulas for financial analysis section of page.
#
# Formulas here are generally well known but if you are not
# familiar you might see 
#	"Fixed Income Mathematics"
#	Frank J. Fabozzi, PROBUS PUBLISHING COMPANY, 1993
###########################################################

###########################################################
# Future value formula.
# Calculates value of net after periods at given rate.
###########################################################
sub fut_val {
	my ($net, $rate, $periods) = @_;
	return $net * (1 + $rate) ** $periods;
}

###########################################################
# Present value formula.
# Calculates amount needed to invest now to reach net after periods at rate.
###########################################################
sub pres_val {
	my ($net, $rate, $periods) = @_;
	my $denom = (1 + $rate) ** $periods;

	if (abs($denom) < 1e-100) {
		return '1.#INF';
	}
	else {
		return $net / $denom;
	}
}


###########################################################
# Print header info 
###########################################################
	print <<EOT;
Content-type: text/html

<html><head>
<title>Dynamic Resumé for Ronald Schmidt</title>
</head>
<body>
EOT

###########################################################
# used for debugging
###########################################################
print "<pre>";
#while (<>) {
#	print ;
#}
#print join "\n", @INC;
print "</pre>";


print <<EOT;

<!-- ---------------------------------------------------- -->
<!-- Essential Data (date/time) -->

<table width="100%"><tr>
<td align="left" valign="top">
EOT

$now = scalar localtime();
if ($now =~ /(\w+\W+\w+\W+\d+)\W+([0-9:]+)\W+(\d+)/){
	$date = $1 . ", " . $3;
	$time = $2;
        $time =~ s/(\d\d)(.*)/($1 -12) . $2/e if ($time + 0 > 12); 
}

#if ($ENV{REMOTE_USER}) {

#$last_greet_row = sprintf <<EOT;
#<tr>
#<td align=\"LEFT\"> Greetings to </td>
#<td align=\"RIGHT\"> $ENV{REMOTE_USER </td>
#</tr>
#EOT

#}

print <<EOT;
<table border cellpadding=3>
<tr>
<td align="LEFT"> Date </td>
<td align="RIGHT"> $date </td>
</tr>
<tr>
<td align="LEFT"> Time </td>
<td align="RIGHT"> $time </td>
</tr>
$last_greet_row
</table>
EOT


###########################################################
# Print name and address on page header
###########################################################
	print <<EOT;
<!-- ---------------------------------------------------- -->
<!-- Name/email/address -->

<TD align="right" valign="center">
Ronald Schmidt<BR><A HREF=\"mailto://RonaldWS\@software-path.com\">
RonaldWS\@software-path.com</A><BR>
1350 Pennington Rd.<BR> Teaneck, NJ 07666
</TD>
</tr></table>
EOT

###########################################################
# prepare to print word unscrambling game or solution as appropriate.
###########################################################
$word_game_pref = "<H1>You want my services because my goal is to deliver a";

#did user solve word game?
if (    ($input{user_word_guess} eq 'satisfying')               ||
        (       ($input{action} eq 'Guess at the missing word')         &&
                ($input{user_word_guess} !~ /(^[\s]*$)|(say fit sing)/) )
    ){
        $word_game = $word_game_pref . " <I>satisfying</I> product.</H1>";
        if (    $input{user_word_guess}=~/satisfying/i          &&
                $input{action} eq 'Guess at the missing word'   ){
                $word_game .= "<H3>Thank you for straightening that out " .
                        "for me. :)";
	}
        $word_game .= "\n" .
                '<INPUT TYPE="HIDDEN" NAME="user_word_guess" ' .
                ' value="satisfying">' . "\n";
}
else {

if ($input{user_word_guess} =~ /^[\s]*$/) { # all blank
	$input{user_word_guess} = "say fit sing";
}

$word_game = sprintf <<EOT;
$word_game_pref
<input type=text name=user_word_guess size=15 maxlength=15 
	value="$input{user_word_guess}">
 product.</H1>
<input type=submit name=action value="Guess at the missing word">
EOT

}

###########################################################
# About the owner of The Software Path ...
###########################################################
print <<EOT;
<!-- ---------------------------------------------------- -->
<!-- Sales statement. (Why should you buy from me) -->
<!-- Includes word game. -->

<form method="post" action="resume2.cgi">

<CENTER>
$word_game
</CENTER>
<HR WIDTH=30%>
<TABLE border cellpadding=4>
<TR>
<TD>
<H2>More specifically the objective is a product that is:</H2>
<ul>
<li>A pleasure to use
<ul>
<li>Reliable
<li>aesthetically pleasing
<li>intuitive
</ul>
<li>Cost effective
<ul>
<li>Scales gracefully
<li>Minimal effort to correct faults (easy to fix)
<li>Simple
</ul>
<li>Reasonable
<ul>
<li>Compatible with a realistic environment
<li>In harmony with the attitudes of owners, users, administrators, operators,
	and even programmers
<li>Conscious of the contractor's resource limitations
</ul>
</ul>
</TD>
<TD align="left" valign="center">
<ul>
<li>A press of the button
<ul><li>like the flip of a switch</ul>
<li>Creates a warm glow
<ul><li>the decors smiles back</ul>
<li>You press at random
<ul><li>the fuse does not twitch</ul>
<li>There is no distraction
<ul><li>you are on the right track.</ul>
</ul>
</TD>
</TR>
</TABLE>
<HR>

<H3>This resume was written in Perl.  Please
look at the <A href="/TSPWeb/resume2.html">source code</A>.</H3>
<HR>

<!-- ---------------------------------------------------- -->
<!-- Sales statement (What am I selling) -->

<CENTER>
<H1>I want to write your software.</H1>
</CENTER>
<H2>If you are looking to contract out software that includes 
technologies such as 
HTML, CGI, PERL, and C on platforms like UNIX and Windows NT,
look at the sample work below, then contact me.
</H2>
<BR>
<HR>

EOT

###########################################################
#import results from interest rate program
###########################################################

$rate = $input{rate};
$periods = $input{periods};
$init_inv = $input{init_inv};
$goal = $input{goal};
$future_value = $input{future_value};
$present_value = $input{present_value};

if ($input{action} eq 'Calculate Present and Future Values') {
	$future_value = fut_val($init_inv, $rate / 100.0, $periods);
	if ($future_value =~ /INF$/) {
		$future_value = 'Error';
	}
	else {
		$future_value = sprintf ("%.2f", $future_value);
	}
	$present_value = pres_val($goal, $rate / 100.0, $periods);
	if ($present_value =~ /INF$/) {
		$present_value = 'Error';
	}
	else {
		$present_value = sprintf ("%.2f", $present_value);
	}
	$present_value = 'Error' if ($present_value =~ /INF$/);
}

# If this resume is generated by a present and future value
# request we generate columns for the table in the financial analysis
# form.
if ($future_value) {

$hidden_field = 
	"<input type=hidden name=future_value value=\"$future_value\">\n";

$future_value_line = sprintf <<EOT;
<td width="50%">
<table border width="100%">
<tr>
<td align="left" valign="center">
Future Value:
</td>
<td align="right" valign="center">
<b>\$$future_value</b>
</td>
</tr>
</table>
</td>
EOT

}

if ($present_value) {

$hidden_field .= 
	"<input type=hidden name=present_value value=\"$present_value\">\n";

$pres_value_line = sprintf <<EOT;
<td width=50%>
<table border width="100%">
<tr>
<td align="left" valign="center">
Present Value:
</td>
<td align="right" valign="center">
<b>\$$present_value</b>
</td>
</tr>
</table>
</td>
EOT

}



###########################################################
# Financial Analysis section of form.
###########################################################
	print <<EOT;
$hidden_field
<H1>Are you interested in financial analysis?</H1>
<!-- form method="post" action="http://localhost/cgi-bin/pf.tcl" -->

<!-- ---------------------------------------------------- -->
<!-- save other forms variables to prevent other form from -->
<!-- being reset -->
<!-- input type=hidden name=sv_user_word_guess value="$rate"-->
<p><font size=+1>I have some experience with financial analysis.  
Future and present 
values measure the effect of compound interest over time.  A future
value gives the result achieved by investing an initial balance at an
interest rate over a specified number of compounding periods.  A present
value gives the inverse which may be used to determine the amount to be 
invested, for a compounding rate and time, in order to achieve some 
goals.  Fill in the number of periods and interest rate for your investment.
Then fill in an initial amount for a future value or a desired goal 
for a present value.
<br><br>
<hr width="30%">
<br>
<table border>

<tr>
<td>

<table width="100%">

<tr><td>
<table width="100%">
<tr>
<td align="left" valign="center">
Interest rate:
</td>
<td align="right" valign="center">
<input type=text name=rate size=5 maxlength=5 value="$rate">%
</td>
</tr>
</table>
</td></tr>

<tr><td>
<table width="100%">
<tr>
<td align="left" valign="center">
Periods:
</td>
<td align="right" valign="center">
<input type=text name=periods size=5 maxlength=5 value=$periods> 
</td>
</tr>
</table>
</td></tr>

<tr><td>
<table width="100%">
<tr>
<td align="left" valign="center">
Initial Investment:
</td>
<td align="right" valign="center">
<input type=text name=init_inv size=12 maxlength=12 value=$init_inv>
</td>
</tr>
</table>
</td>
$future_value_line
</tr>

<tr><td>
<table width="100%">
<tr>
<td align="left" valign="center">
Investment Goal:
</td>
<td align="right" valign="center">
<input type=text name=goal size=12 maxlength=12 value=$goal>
</td>
</tr>
</table>
</td>
$pres_value_line
</tr>

</table>

</td>

</tr>

</table>
<br>
<input type=submit name=action value="Calculate Present and Future Values">
</font>
<hr width="30%">
<HR>
EOT

###########################################################
# Post email reply vi cgi as opposed to direct use of 
# mail system.
###########################################################
if ($input{action} eq 'Contact Me') {
	if (open( FH, ">>contact.log")) {
		print FH "\n", $input{message}, "\n";
		close(FH);
	}
}
print <<EOT;
<H1>If you wish to contact me you may send mail or use the form below. </H1>
<textarea name=message cols=40 rows =7>
</textarea>
<input type=submit name=action value="Contact Me">
</form>
</body>
</html>
EOT