--- capa/capa51/Discuss/Ver1.3/Attic/capadiscuss 1999/09/28 21:27:46 1.1.1.1 +++ capa/capa51/Discuss/Ver1.3/Attic/capadiscuss 2000/03/22 21:08:02 1.8 @@ -1,13 +1,15 @@ #!/usr/ucb/perl # # CAPA Discussion Forum -# version 1.3 +# version 1.3.0 # # Michigan State University # Department of Physics and Astronomy # # Ryan J. Shaltry # tech4@msue.msu.edu +# Guy Albertelli +# albertel@msu.edu print "Content-type: text/html\n\n"; @@ -49,12 +51,18 @@ $validadmin = "unchecked"; $psetid = $form{'PSETID'}; if ($snum eq "A12345678") {$debug=1;} if ($snum eq "a12345678") {$debug=1;} +$debug=0; if($psetid eq "") { $psetid = $setid; } if ($debug) {print "GetTeacherInfo
";$BenchmarkTa = new Benchmark;} &GetTeacherInfo; if($debug) {$BenchmarkTb = new Benchmark;print "
",timestr(timediff($BenchmarkTb,$BenchmarkTa)),"\n";} - # check for valid studentnumber/capaid + # check if student is banned from forum +if ($debug) {print "BanUser
";$BenchmarkTa = new Benchmark;} +if (&BanUser) {exit;} +if($debug) {$BenchmarkTb = new Benchmark;print "
",timestr(timediff($BenchmarkTb,$BenchmarkTa)),"\n";} + + # check for valid studentnumber/capaid, an exit will occur here if the set wasn't open if ($debug) {print "ValidateUser
";$BenchmarkTa = new Benchmark;} &ValidateUser; if($debug) {$BenchmarkTb = new Benchmark;print "
",timestr(timediff($BenchmarkTb,$BenchmarkTa)),"\n";} @@ -100,12 +108,57 @@ exit; ####################### ## Begin Subroutines ## ####################### +sub GetSetList { + opendir(DDIR,"$capadir/$class/discussion"); + @sets = grep(/^[0-9]+$/,sort(readdir(DDIR))); + closedir(DDIR); + if ($debug) {print "
Sets:". @sets ."
\n";} +} + +sub SetListHeader { + $pdset = "\n"; +} + +sub GetInfoList { + local(@temp,@alldir,@setdir); +# if ($debug) {print "
GetInfoList
";} + opendir(DDIR,"$capadir/$class/discussion"); + @alldir = sort(grep(/.info$/,readdir(DDIR))); + closedir(DDIR); + + opendir(FORUM,"$capadir/$class/discussion/$setid"); + @setdir = sort(grep(/.info$/,readdir(FORUM))); + closedir(FORUM); + + foreach $file(@setdir) { @setdir2 = (@setdir2,"$setid/$file"); } + @infofiles = (@alldir,@setdir2); + $infostring = ""; +# if ($debug) {print "
GetInfoList" . @infofiles."
";} + foreach $infofile(@infofiles) { +# if ($debug) {print "
GetInfoList" . $infofile."
";} + @temp = reverse split /\//, $infofile; + $infodesc = $temp[0]; + $infodesc =~ s/.info//g; + $infodesc =~ s/_/ /g; + $infostring .= &InfoButtonHTML; + } + if ($infostring ne "") { + # $infostring = "" . $infostring; + } +# if ($debug) {print "
GetInfoList" . $infostring."
";} +} sub NewSet { &Log("NewSet"); if($setid <= $psetid) { #grab capaid - if ($debug) {print "ViewSet
";$BenchmarkTa = new Benchmark;} + if ($debug) {print "NewSet
";$BenchmarkTa = new Benchmark;} @allcapaid = `allcapaid -s $setid -e $setid -stu $snum -c $capadir/$class -i`; $capaid = $allcapaid[2]; @@ -116,23 +169,16 @@ if($debug) {$BenchmarkTb = new Benchmark return; } - opendir(DDIR,"$capadir/$class/discussion"); - @sets = grep(/[0-9]/,sort(readdir(DDIR))); - closedir(DDIR); - - $pdset = "\n"; - + if ($debug) { print "
GetSetList\n"; } + &GetSetList; + if ($debug) { print "
EndGetSetList\n"; } + &SetListHeader; &NewSetHTML; #exit; } sub ViewSet { + local($hidden); if ($debug) {print "InsideViewSet
";$BenchmarkTa = new Benchmark;} &Log("ViewSet"); &CheckAdmin; @@ -143,20 +189,13 @@ sub ViewSet { $capasbin = "$capasbin/$teachdir/capasbin"; &SetJumpBox; + $backfunction="viewset"; + &GetInfoList; + opendir(FORUM,"$capadir/$class/discussion/$setid"); @dir = sort(readdir(FORUM)); closedir(FORUM); - @infofiles = grep(/.info/,@dir); - $infostring = ""; - $backfunction = "viewset"; - foreach $infofile(@infofiles) { - $infodesc = $infofile; - $infodesc =~ s/.info//g; - $infodesc =~ s/_/ /g; - $infostring .= &InfoButtonHTML; - } - foreach $i(@dir) { $probnum = &RemZero(substr($i,0,6)); $found[$probnum]++; @@ -183,6 +222,7 @@ if($debug) {$BenchmarkTb = new Benchmark $col = 1; for($probnum=1; $probnum<=$maxprobs; $probnum++) { + $hidden=0; if($col eq "1" && $probnum > $col1size && $bigtable eq "yes") { $col = 2; &ViewSetEndColHTML; @@ -194,13 +234,19 @@ if($debug) {$BenchmarkTb = new Benchmark closedir(MSG); foreach $msg(@msgs) { if(&RemZero(substr($msg,0,6)) eq $probnum) { - push(@good,$msg); + &OpenMsg("$capadir/$class/discussion/$setid/$msg"); + if(!($status eq "hidden" && $validadmin ne "yes")) { + push(@good,$msg); + } else { $hidden++; } } } - - &OpenMsg("$capadir/$class/discussion/$setid/$good[$#good]"); - $lastpost = "$date at $time"; - $posts = $found[$probnum]; + $posts = $found[$probnum]-$hidden; + if ($posts >0) { + &OpenMsg("$capadir/$class/discussion/$setid/$good[$#good]"); + $lastpost = "$date at $time"; + } else { + $lastpost = "--"; + } } else { $lastpost = "--"; @@ -263,6 +309,7 @@ sub ViewProblem { } if($msgcount eq "1") { + &GetInfoList; $postbutton = &ReplyButtonHTML; &ProblemJumpBox; &ViewProblemTopHTML; @@ -296,14 +343,15 @@ sub ViewProblem { $hidebutton = &UnHideButtonHTML; $messagenote = "Hidden by $hiddenuser on $hiddendate at $hiddentime from $hiddenaddr"; } - $message =~ s//>/g; +# $message =~ s//>/g; &ViewProblemGutsHTML; } } } if($msgfind eq "no") { + &GetInfoList; $postbutton = &PostNewButtonHTML; &ProblemJumpBox; &ViewProblemTopHTML; @@ -317,7 +365,8 @@ sub ViewProblem { } sub ViewInfoFile { - open(INFOFILE,"$capadir/$class/discussion/$setid/$file"); + &Log("InfoFile"); + open(INFOFILE,"$capadir/$class/discussion/$file"); @file = ; closedir(INFOFILE); @@ -549,10 +598,24 @@ sub WriteMsg { $filename = shift(@_); # add sr to grab e-mail address of user + + #


      • + %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1, BR=>1, TT=>1, STRONG=>1, + BLOCKQUOTE=>1, DIV=>1, IMG=>1); + $message = $form{'message'}; - $message =~ s/\n\r\n/

        /g; + + $message =~ s/((\n\r)|(\n))\n/

        /g; $message =~ s/\n/
        /g; + $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/ + {($html{uc($2)}&(length($1)<1000))?"\<$1":"\<$1"}/ge; + $message =~ s/(\]*)\>/ + {($html{uc($2)}&(length($1)<1000))?"$1\>":"$1\>"}/ge; + +# $message =~ s//>/g; + # check if posted anonymously if($form{'ANONYMOUS'} eq "yes") { $username = "Anonymous|$username"; @@ -611,6 +674,7 @@ sub CheckAdmin { last; } } + if ($debug) { print "Admin Sections: ".$adminsection;} @adminsections = split(/\,/,$adminsection); for ($asection=0; $asection <= $#adminsections; $asection++) { $adminsections[$asection]=&RemZero($adminsections[$asection]) @@ -622,10 +686,12 @@ sub CheckAdmin { $snum =~ tr/a-z/A-Z/; LINE: foreach $line(@classl) { - ($course,$coursenum,$section,$stunum,$a) = split(/\ +/,$line); + $section= substr $line, 10, 3; + $stunum= substr $line, 14, 9; $stunum =~ tr/a-z/A-Z/; if ( $stunum ne $snum ) { next LINE;} $section = &RemZero($section); + if ($debug) {print "
        ".$stunum."Is in section:".$section."
        ";} foreach $asection(@adminsections) { if($section eq $asection ) { $validadmin = "yes"; @@ -637,6 +703,30 @@ sub CheckAdmin { if($validadmin eq "no" && $mode eq "kill") { &NotAdminHTML; } } +sub BanUser { + local (@capaconfig,$line,$command,$value,$ban,@banned,$result); + $result = 0; + open(CAPACONFIG,"$capadir/$class/capa.config"); + @capaconfig = ; + close(CAPACONFIG); + foreach $line(@capaconfig) { + chop $line; + ($command,$value) = split(/\ =\ /,$line); + if($command eq "banned_users") { $ban = $value; last; } + } + + if ($debug) { print "Banned Users: ".$ban } + @banned = split(/\,/,$ban); + $snum =~ tr/a-x/A-Z/; + foreach $ban (@banned) { + if ($debug) {print $ban . "is Banned
        ";} + $ban =~ tr/a-z/A-Z/; + $ban =~ tr/\ //d; + if ( $ban eq $snum) { &BannedMessageHTML; $result=1 } + } + return $result +} + sub ValidateUser { local(@allcapaid,@classl,$line); @@ -653,16 +743,29 @@ sub ValidateUser { if($valid eq "no") { &InvalidVarsHTML; } # check w/ allcapaid program - @allcapaid = `allcapaid -s $setid -e $setid -stu $snum -c $capadir/$class -i`; + @allcapaid = `allcapaid -s $setid -e $setid -stu $snum -c $capadir/$class -i -checkopen`; chop $allcapaid[2]; chop $allcapaid[2]; + if ($debug) {print "capaid:" . $allcapaid[2] . "
        \n";} if($allcapaid[2] ne $capaid) { - if($action ne "newset") { &BadPassHTML; } + if ($allcapaid[2] =~ /Open/) { &NotOpen; exit; } + if($action ne "newset") { &BadPassHTML; exit; } #&NewSet; } } +sub NotOpen { + &GetSetList; + &SetListHeader; + &ViewSetTitleHTML; +print < + +NotOpen2 +} + sub UserInfo { local($line,@classl,$last,$first,$middle); @@ -703,17 +806,8 @@ sub ProblemJumpBox { } sub SetJumpBox { - opendir(DDIR,"$capadir/$class/discussion"); - @sets = grep(/[0-9]/,sort(readdir(DDIR))); - closedir(DDIR); - - $pdset = ""; + &GetSetList; + &SetListHeader; } sub AddZero { @@ -754,7 +848,7 @@ sub form_info { foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); - + if ($name eq "message") {$allow_html=1;} else {$allow_html=0;} # Un-Webify plus signs and %-encoding $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; @@ -774,6 +868,8 @@ sub GetDateTime { ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime (time); $mon++; + $year=$year+1900; + if ($hour < 12) { $AMPM = "AM"; } @@ -811,7 +907,7 @@ sub Log { &Lock("lock.file"); open(LOG,">>$capadir/$class/discussion/logs/access.log"); - print LOG "$snum|$capaid|$username|$email|$logmsg|$setid|$probnum|$HyphenDate|$Time\n"; + print LOG "$snum|$capaid|$username|$email|$logmsg|$setid|$probnum|$HyphenDate|$Time|$file\n"; close(LOG); &Unlock("lock.file"); }