#!/usr/local/bin/perl 

# In the event that the setup script does not work
# the above line will need to be modifed.  All you 
# will need to do is replace the /usr/local/bin/perl
# with the proper path to perl.  The perl path can be
# found by asking your hosting company.  Please note
# the #! MUST remain at the begining.

use strict;
use CGI::Carp qw(fatalsToBrowser); 
use CGI;

my $query;
$query = new CGI;

my $perlpath = `which perl`;
my $host = $query->param("host");
my $dbname = $query->param("dbname");
my $username = $query->param("uname");
my $password = $query->param("password");
my $submitted = $query->param("submitted");

chop($perlpath);

    if($submitted ==1){

	open(OUTF, ">ofcourse/information.txt");
	
	print OUTF "$host\n";
	print OUTF "$dbname\n";
	print OUTF "$username\n";
	print OUTF "$password\n";
	print OUTF "$perlpath";
	
	close(OUTF);
	

	my $input = "ofcourse/serversidesetup.cgi";
	my $i;
	open(INPUT, "$input");  # open the file to read it
	$/=undef;
	my $data = <INPUT>;         # read the whole file into an array
	close(INPUT);            # close the file
	$data =~ s/pathtoperl/$perlpath/;
	
	open (OUTPUT, ">$input"); # now open it to write to
	print OUTPUT $data;
	
	close(OUTPUT);       # and close it
	print "Location: ofcourse/serversidesetup.cgi\n\n";
	
    }
else{

    `gunzip ofcourseReleaseV*.tar.gz`;
    `tar -xf ofcourseReleaseV*.tar`;
    `rm -f ofcourseReleaseV*.tar`;
    `chmod 755 ofcourse/`;
    
    
    print "Content-type: text/html\n\n";
    print <<HTML
	
	<HTML>
	<BODY>
	<P><B>Step 4: Setup the mysql Database</B></P>
<P>This step will setup the databse for you.  All you need to do is fill out the required information and click the button.  If you do not know the information you will need to contact your web hosting company.</P>	
<div align="center">
	
<br>
	<table cellspacing = 3>
	<form name="update" action="setupcgi.cgi" method="post">
	<tr><td align=right>Enter Hostname: </td><td><input type=text name="host"></td></tr>
	<tr><td align=right>Enter Database name: </td><td><input type=text name="dbname"></td></tr>
	<tr><td align=right>Enter Username: </td><td><input type=text name="uname"></td></tr>
	<tr><td align=right>Enter Password: </td><td><input type=password name="password"></td></tr>
	<input type=hidden name=\"submitted\" value=1>
	<tr><td align=center colspan=2><input type="submit" name="submit" value="Go on to Step 5"></td></tr>
	
	</form>
	</table>
	</div>
	</body>
	</html>

HTML


    }
