#!/opt/local/bin/perl

use strict;
use HTML::Entities ();
use CGI;
use lib '/Library/WebServer/perl/lib';
use EduFileTwo;

my $form = new CGI;

#my $ok_chars = 'a-zA-Z0-9 ,-';
my $ok_chars = '%+\-0-9<=>A-Z_a-z{|}@.,';
foreach my $param_name ( $form->param ) {
    $_ = HTML::Entities::decode( $form->param($param_name) );
    $_ =~ s/[^$ok_chars]//go;
    $form->param($param_name,$_);
}

my $course_id = $form->param('course_id');


my $courseObj = new EduFileTwo::Course($course_id, 1);


print $form->header;

EduFileTwo::Util::printHead("");

if (!$courseObj->getID())
{
print <<END_HTML;
<h2>Login Error</h2>
<P>The course ID you specified is invalid. Please consult your instructor for assistance.</P>
END_HTML
}
elsif($course_id eq "")
{
print <<END_HTML;
<h2>Login Error</h2>
<P>No course ID has been specified for logging into the system. Please consult your
instructor for assistance.</P>
END_HTML
}
else
{
print <<END_HTML;
<div id="content2" align="center">
<p>Enter your student information for $course_id to download course supplements.</p>
<form action="login.cgi" method="post">
<table align="center" cellpadding="3" cellspacing="0" border="0">
  <tr>
	<td align="right">
	Student ID: 
	</td>
	<td>
	<input type="text" name="user_id" maxlength="100" size="30" style = "background-color: #FAF5E2;">	
	<input type="hidden" name="course_id" value="$course_id" style = "background-color: #FAF5E2;">
	</td>
</tr>
<tr>
	<td align="right">
	Password: 
	</td>
	<td>
	<input type="password" name="password" maxlength="100" size="30" style = "background-color: #FAF5E2;">	
	</td>
</tr>
</table>
<div align="center"><input type="submit" value="Login">&nbsp;&nbsp;<input type="reset" value="Clear"></div>
<p>If you haven't used this system before, you will need to  <a href="adduser.cgi?course_id=$course_id">register</a>.</p>
</form>
</div><br>
	
END_HTML
}

EduFileTwo::Util::printFoot();
