#!usr/local/bin/perl;
package viewdata;
use lib '\\\\140.247.216.106\\inetpub\wwwroot\is';
use CGI ("shortcuts");
use CGI::Carp qw(fatalsToBrowser);
$query=new CGI;
#Use the ODBC module
use Win32::ODBC;
#our dsn
my $DSN='DRIVER={Microsoft Access Driver (*.mdb)};DBQ=\\\\140.247.216.106\\inetpub\wwwroot\is\database\hls_is_981.Mdb';
use ISLib;
$user=$query->remote_user();
my $ISobj=new ISLib('View Data');
print $query->header();
print $ISobj->pagetop;

#open a connection to DSN
#my $O = new Win32::ODBC($DSN) || die "Unable to open DSN $DSN\n";
#(! $O->Sql("SELECT QuestionText, Week, QuestionID 
#	FROM Questions
#	ORDER BY Week, QuestionID ASC")) || print $O->DumpError();
#while ($O->FetchRow() ) {
#	my %qdata=$O->DataHash();
#	$qtext=$ISobj->shorten($qdata{'QuestionText'}, 60);
#	print qq! <DD><a href="viewquestion.cgi?QuestionID=$qdata{'QuestionID'}">Week $qdata{'Week'}: 
#	$qtext</a><br>\n
#	!;
#	} #next row
#$O->Close();



###Questions
print qq!<a name="questions"></a><DL><DT><font size="+2">View All Responses to an Earlier Question</font><br>\n!;
#open a connection to DSN
my $O = new Win32::ODBC($DSN) || die "Unable to open DSN $DSN\n";
(! $O->Sql("SELECT QuestionText, Week, QuestionID 
	FROM Questions
	ORDER BY Week, QuestionID ASC")) || print $O->DumpError();
while ($O->FetchRow() ) {
	my %qdata=$O->DataHash();
	$qtext=$ISobj->shorten($qdata{'QuestionText'}, 60);
	print qq! <DD><a href="viewquestion.cgi?QuestionID=$qdata{'QuestionID'}">Week $qdata{'Week'}: 
	$qtext</a><br>\n
	!;
	} #next row
$O->Close();

print qq!</DL>!;
print "<P>\n";
###Students
print qq!<a name="students"></a><DL><DT><font size="+2">View a Classmate's Responses to All Earlier Questions</font><br>\n!;
#open a connection to DSN
$O = new Win32::ODBC($DSN) || die "Unable to open DSN $DSN\n";
(! $O->Sql("SELECT * 
	FROM Students
	WHERE Approved=1
	ORDER BY LastName ASC")) || print $O->DumpError();
while ($O->FetchRow() ) {
	my %sdata=$O->DataHash();
	if (($user eq "is98") || ($user eq "webedit")) {print qq! <DD><a href="viewstudent.cgi?StudentID=$sdata{'StudentID'}">\u$sdata{'FirstName'} \u$sdata{'LastName'}</a> (\u$sdata{FirstReal} \u$sdata{LastReal})<br>\n!; } 
	else { 	print qq! <DD><a href="viewstudent.cgi?StudentID=$sdata{'StudentID'}">\u$sdata{'FirstName'} \u$sdata{'LastName'}</a><br>\n!; }
	} #next row
$O->Close();
print qq!</DL>!;
#print qq!<a name="classlist"></a><DL><DT><font size="+2"><a href="classlist.cgi">View Class List</a></font></DL>\n!;
print $ISobj->pagebottom;