#!/opt/local/bin/perl

use DBI;
use lib '/Library/WebServer/perl/lib';
use EduFileTwo;

print "Content-type: text/html\n\n";

EduFileTwo::Util::printHead("Select A Course");

print <<END_EOF;
			<form action="addcourse.cgi" method="post"> 
<div id="content2" align="center">
END_EOF

my $dbh = DBI->connect(EduFileTwo::Constants::DB_DRIVER . ":" . EduFileTwo::Constants::DB_NAME, EduFileTwo::Constants::DB_USERNAME, EduFileTwo::Constants::DB_PASSWORD);
my $sth = $dbh->prepare("select id from courses");
$sth->execute or die "DB Error: " . $sth->errstr;

my $firstTime = 1;
my $rowsExist = 0;
while(@row = $sth->fetchrow_array())
{
	$rowsExist = 1;
	if($firstTime)
	{
		print "        <p>Click on the appropriate link to edit a course.</p>";		
	}
	print "                     <a href=\"managecourse.cgi?course_id=$row[0]\">$row[0]</a><br>\n";
	$firstTime = 0;
}

$sth->finish();
$dbh->disconnect();

if(!$rowsExist)
{
	print "<P>There are currently no courses to edit.</P>";
}
	
print <<END_HTML;
</div>
			  </form>
	
END_HTML

EduFileTwo::Util::printFoot();
