#!/usr/bin/perl -wT # --------------------------------------------- # # Description: # This script is designed to be used once to install the system # We will use DBI and DBD::AnyData to create CSV datafiles # We use CGI.PM to handle HTML # # History: # ======== # 07 April 2004, - Initial file created, based on e-judo.cgi at e-judo.sourceforge.net # 08 April 2004, - Wrote the subs to create all the data files. my $DEBUG = 1; # If this is set to 1 then we see the debug messages. use strict; # force strict programming controls use CGI qw(:standard); # use the CGI.PM module use lib './MyLib'; # use the modules in MyLib, this is the DBD::Anydata used for database activities use DBI; # This calls the DBI module, which along with the line above allows us to do database activities # Sub Routines # ---------------------------------------------------------------- sub create_users_file { # This sub creates the users_csv file print p("Start of create_users_file") if $DEBUG; # create the scalers we need to use in the sql # ---------------------------------------------- my $table = "data/users_csv/"; print p(" table name = ", $table ) if $DEBUG; # Okay now we must create the database files # here is the DBI/SQL code # ---------------------------------------------------- # First create the array and hash to hold the table fields and data definitions # ------------------------------------------------------------------------------ my @table_fields = qw/ user_id first_name last_name email credits login_id password /; my %table_field_def = ( user_id => 'char(20)', first_name => 'char(20)', last_name => 'char(20)', email => 'char(20)', credits => 'char(20)', login_id => 'char(20)', password => 'char(20)' ); print p(" Table Fields = ", @table_fields) if $DEBUG; print p(" Table Fields def = ", %table_field_def) if $DEBUG; my $dbh = DBI->connect('dbi:AnyData(RaiseError=>1):') or die "Can not create database connection"; # build the table using SQL # --------------------------------- $dbh->do ( "CREATE TABLE the_table (" . join(',', map { $_ . ' ' . $table_field_def{$_} } @table_fields) . ")" ) or die "Can not create table"; $dbh->func( 'the_table', 'CSV', $table, 'ad_export'); print p("User table created") if $DEBUG; print p("END of create_users_file") if $DEBUG; } # End Sub-Routines # ------------------ # Main Code starts here # ----------------------- print header(), start_html("Installation"), h1("Install Script"); # This line uses CGI.PM to to create the webpage if (param()){ # If there is a parameter(or parameters) then validate, else show the login screen. # the following lines are excecuted if paramaters HAVE been entered my $confirm = param("confirm"); # $confirm is the text entered on the webpage form entered by the user if ($confirm eq "YES") { # If the user enetered YES (in caps) then run the install # first, check if the users datafile exists, if not we will create it. if (-e "data/users_csv"){ print p("users_csv exists") if $DEBUG; } else { print p("users_csv does not exist so about to call the create_users_file sub") if $DEBUG; create_users_file(); } } # end if if statement for $confirm } else { # if there no parameters print a webform and ask conformation to install print hr, start_form; # create a form using CGI.PM print p("Please type in YES (In capitals) to proceed with installation: ", textfield("confirm")); print submit(-name=>'submit button'); print end_form, hr; # end the form } print end_html; # this closes the web page properly