;
close(MSG);
$poster = $msg[0];
$date = $msg[1];
$time = $msg[2];
$subject = $msg[3];
$email = $msg[4];
$message = $msg[5];
$statusl = $msg[6];
($status, $hiddenuser, $hiddendate, $hiddentime, $hiddenaddr) = split(/\|/,$statusl);
}
sub WriteMsg {
local($filename,$message);
$filename = shift(@_);
# add sr to grab e-mail address of user
$message = $form{'message'};
$message =~ s/\n\r\n//g;
$message =~ s/\n/
/g;
# check if posted anonymously
if($form{'ANONYMOUS'} eq "yes") {
$username = "Anonymous|$username";
}
open (MSG,">$filename");
print MSG "$username\n";
print MSG "$HyphenDate\n";
print MSG "$Time\n";
print MSG "$subject\n";
print MSG "$email\n";
print MSG "$message\n";
print MSG "public||||\n";
close(MSG);
}
sub GetTeacherInfo {
local($capa5dir,$classname,$tdir,@classconf);
# open/read class.conf file
open (CLASSCONF,"$capabin/class.conf");
@classconf = ;
close(CLASSCONF);
$found eq "no";
foreach $line(@classconf) {
($classname,$capa5dir,$tdir) = split(/[\t\ ]+/,$line);
if($classname eq $class) {
$teachdir = $tdir;
$capadir = $capa5dir;
$found = "yes";
}
}
if($found eq "no") { &InvalidVarsHTML; }
chop $teachdir;
}
sub CheckAdmin {
local($asection,@adminsections,$line,@capaconfig,$command,$value,
$adminsection,@classl,$course,$coursenum,$section,$stunum,$a);
$validadmin = "no";
$mode = shift(@_);
# open 'capa.config' file (for admin section read)
open(CAPACONFIG,"$capadir/$class/capa.config");
@capaconfig = ;
close(CAPACONFIG);
foreach $line(@capaconfig) {
chop $line;
($command,$value) = split(/\ =\ /,$line);
if($command eq "admin_section") {
$adminsection = $value;
}
}
@adminsections = split(/\,/,$adminsection);
# open 'classl' file
open(CLASSL,"$capadir/$class/classl");
@classl = ;
close(CLASSL);
foreach $line(@classl) {
chop $line;
($course,$coursenum,$section,$stunum,$a) = split(/\ +/,$line);
$snum =~ tr/a-z/A-Z/;
$stunum =~ tr/a-z/A-Z/;
$section = &RemZero($section);
foreach $asection(@adminsections) {
if(&RemZero($section) eq &RemZero($asection) && $stunum eq $snum) {
$validadmin = "yes";
}
}
}
if($validadmin eq "no" && $mode eq "kill") { &NotAdminHTML; }
}
sub ValidateUser {
local(@allcapaid,@classl,$line);
open (CLASSL,"$capadir/$class/classl");
@classl = ;
close(CLASSL);
$valid = "no";
foreach $line(@classl) {
if(substr($line,15,8) eq substr($snum,1,8)) {
$valid = yes;
}
}
if($valid eq "no") { &InvalidVarsHTML; }
# check w/ allcapaid program
@allcapaid = `allcapaid -s $setid -e $setid -stu $snum -c $capadir/$class -i`;
chop $allcapaid[2];
chop $allcapaid[2];
if($allcapaid[2] ne $capaid) {
if($action ne "newset") { &BadPassHTML; }
&NewSet;
}
}
sub UserInfo {
local($line,@classl,$last,$first,$middle);
open (CLASSL,"$capadir/$class/classl");
@classl = ;
close(CLASSL);
foreach $line(@classl) {
if(substr($line,15,8) eq substr($snum,1,8)) {
$username = substr($line,24,36);
$email = substr($line,60,45);
}
}
($last, $first, $middle) = split(/\ +/,$username);
chop $last;
$username = "$first $last";
$email =~ s/\ //g;
chop $email;
}
sub MaxProbs {
open (SETRECORD,"$capadir/$class/records/set$setid.db");
@setrecord = ;
close(SETRECORD);
chop $setrecord[0];
return $setrecord[0];
}
sub ProblemJumpBox {
$pdprob = "";
}
sub SetJumpBox {
opendir(DDIR,"$capadir/$class/discussion");
@sets = grep(/[0-9]/,sort(readdir(DDIR)));
closedir(DDIR);
$pdset = "";
}
sub AddZero {
$string = shift(@_);
while(length($string) < 6) {
$string = "0$string";
}
return $string;
}
sub RemZero {
$string = shift(@_);
$fc = substr($string,0,1);
while($fc eq "0") {
$string =~ s/.//;
$fc = substr($string,0,1);
}
return $string;
}
sub FormatDate {
$string = shift(@_);
$month = substr($string,0,2);
$day = substr($string,2,2);
$year = substr($string,4,4);
$string = "$month-$day-$year";
return $string;
}
####################
## Get SubRoutine ##
####################
sub form_info {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# Split the name-value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
# Un-Webify plus signs and %-encoding
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s///g;
if ($allow_html != 1) {
$value =~ s/<([^>]|\n)*>//g;
}
$form{$name} = $value;
}
}
##################
## Date/Time sr ##
##################
sub GetDateTime {
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime (time);
$mon++;
if ($hour < 12) {
$AMPM = "AM";
}
if ($hour > 12) {
$hour = $hour - 12;
$AMPM = "PM";
}
if ($hour == 12) {
$AMPM = "PM";
}
if ($hour == 0) {
$hour = "12";
}
$min = sprintf ("%2d", $min);
$min =~tr/ /0/;
$mon = sprintf ("%2d", $mon);
$mon =~tr/ /0/;
$mday = sprintf ("%2d", $mday);
$mday =~tr/ /0/;
$HyphenDate = ("$mon" . "-" . "$mday" . "-" . "$year");
$RunonDate = ("$mon$mday$year");
$Time = ("$hour" . ":" . "$min" . " " . "$AMPM");
}
########################
## Logging Subroutine ##
########################
sub Log {
$logmsg = shift(@_);
&GetDateTime;
&Lock("lock.file");
open(LOG,">>$capadir/$class/discussion/logs/access.log");
print LOG "$snum|$capaid|$username|$email|$logmsg|$setid|$probnum|$HyphenDate|$Time\n";
close(LOG);
&Unlock("lock.file");
}
############################
## Lock/Unlock Subroutine ##
############################
sub Lock {
local ($lockname) = @_;
local ($endtime);
$endtime = 15;
$endtime = time + $endtime;
while (-e $lockname && time < $endtime) {
open (LOCKFILE, ">$lockname");
}
sub Unlock {
local ($lockname) = @_;
close (LOCKFILE);
unlink ($lockname);
}
}
######################
## HTML Subroutines ##
######################
## CapaDiscuss HTML Subroutines
# capadiscuss_html
## end capadiscuss