#!/usr/bin/perl
# make_index version 0.04;
use strict;
use warnings;
use CGI::Carp('fatalsToBrowser');
use CGI::Pretty qw(:standard *table -no_undef_params);
$CGI::Pretty::INDENT = '    ';
use Finance::Shares::CGI 0.11;

my $w = new Finance::Shares::CGI;
my $file = "$w->{base_dir}/index.html";
open OUTFILE, '>', $file or die $!;
select OUTFILE;

my $script;
($script = <<end_script) =~ s/^\s+//gm;
    function set_vars() {
	var frames = 1;
	var css = 1;
	
	if (screen.width) bwidth = 0.9 * screen.width;
	if (window.innerWidth) bwidth = 0.95 * window.innerWidth;

	browserVersion = parseInt(navigator.appVersion);
	if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {
	    frames = 1; css=1;
	} else {
	    frames = 1;
	}
	document.forms[0].frames.value=frames;
	document.forms[0].css.value=css;
    }
end_script

my $form_start = start_form(-action => "$w->{base_cgi}/shares.pl");
my $user_name = textfield(-name => 'u', -maxlength => '20');
my $enter = submit(-name => 'choice', -value => 'Enter');
my $form_end = end_form();
my $intro;
($intro = <<end_intro) =~ s/^\s+//gm;
    <p class='centered'>A user interface to the Finance::Shares modules, producing printable charts of share
    quotes along with functions and test results.</p>
    <p class='centered'>An internet connection is required although an
    offline mode allows for analysing previously fetched quotes.</p>
    <p class = 'centered'>In order to keep track of your Models, you need to identify yourself.  There is no
    security, but your choices will be stored under the user name you give so you may access it again.</p>
    $form_start
    <p class = 'centered'><b>Please enter a user name</b></p>
    <p class = 'centered'>$user_name</p>
    <p class = 'centered'>$enter</p>
    <input type='hidden' name='frames' value='99'>
    <input type='hidden' name='css' value='99'>
    $form_end
    <script language='javascript'>set_vars()</script>
    <p align='center'>Although this might give a taste of what the Finance::Shares modules are about, they were intended to be
    used as a scripting toolbox comprising the following.  See their man pages for further details.</p>
end_intro
$w->print_header(undef, $intro, $script);

my $html;
($html = <<end_html) =~ s/^\s+//gm;
    <table bgcolor='$w->{bgcolor}' width='90%' align='center' border='3' cellpadding='8'>
    <tr>
	<td>
	    Finance::Shares::Overview
	</td>
	<td>
	    An introduction, tutorial and setup details.  Read this first.
	</td>
    </tr>
    <tr>
	<td>
	    Finance::Shares::Lesson1 etc.
	</td>
	<td>
	    Tutorial lessons on how to use the modules.
	</td>
    </tr>
    <tr>
	<td>
	    Finance::Shares::Model
	</td>
	<td>
	    This is one of the top level modules.  It applies tests to various samples, adding 'buy' and 'sell'
	    signals to the charts.
	</td>
    </tr>
    <tr>
	<td>
	    Finance::Shares::Portfolio
	</td>
	<td>
	    <i>[Proposed.]</i> Another top level module.  This uses the Model's buy/sell signals to maintain stock
	    positions.
	</td>
    </tr>
    <tr>
	<td>
	    Finance::Shares::CGI
	</td>
	<td>
	    The 'input' module, this supports the CGI scripts used in this site.  Unlike the other modules, it
	    needs manual installation.  Scripts need to be copied into the cgi-bin directory and a suitable mysql
	    database must be set up before it can work.
	</td>
    </tr>
    <tr>
	<td>
	    Finance::Shares::Chart
	</td>
	<td>
	    The 'output' module, this turns the data held within a Sample into a PostScript file for printing or
	    viewing with GhostView.
	</td>
    </tr>
    <tr>
	<td>
	    Finance::Shares::MySQL
	</td>
	<td>
	    This interfaces with the mysql database used for storing quotes and handles the internet access which
	    fetches them.
	</td>
    </tr>
    <tr>
	<td>
	    Finance::Shares::Sample
	</td>
	<td>
	    The main object holding share quotes as well as function and test results.  Most of the other modules
	    make direct use of this data.
	</td>
    </tr>
    <tr>
	<td>
	    Finance::Shares::Averages
	</td>
	<td>
	    A collection of functions providing moving averages.
	</td>
    </tr>
    <tr>
	<td>
	    Finance::Shares::Bands
	</td>
	<td>
	    A collection of functions adding lines above and below other functions.
	</td>
    </tr>
    <tr>
	<td>
	    Finance::Shares::Momentum
	</td>
	<td>
	    Functions for identifying over-bought and over-sold conditions by looking at the rate prices change.
	</td>
    </tr>
    <tr>
	<td>
	    Finance::Shares::Oscillators
	</td>
	<td>
	    Functions attempting to identify cycles.  <i>Not implemented yet.</i>
	</td>
    </tr>
    <tr>
	<td>
	    Finance::Shares::Trends
	</td>
	<td>
	    <i>[Under development.]</i> This gives an indication of rising and falling trends.
	</td>
    </tr>
    </table>
end_html
print $html;
 
$w->print_form_end();
$w->print_footer();

select STDOUT;
print "$file created\n";

