Diff for /capa/capa51/Discuss/Ver1.3/Attic/capadiscuss between versions 1.1.1.1 and 1.8

version 1.1.1.1, 1999/09/28 21:27:46 version 1.8, 2000/03/22 21:08:02
Line 1 Line 1
 #!/usr/ucb/perl  #!/usr/ucb/perl
 #  #
 # CAPA Discussion Forum  # CAPA Discussion Forum
 # version 1.3  # version 1.3.0
 #  #
 # Michigan State University  # Michigan State University
 # Department of Physics and Astronomy  # Department of Physics and Astronomy
 #  #
 # Ryan J. Shaltry  # Ryan J. Shaltry
 # tech4@msue.msu.edu  # tech4@msue.msu.edu
   # Guy Albertelli
   # albertel@msu.edu
   
 print "Content-type: text/html\n\n";  print "Content-type: text/html\n\n";
   
Line 49  $validadmin = "unchecked"; Line 51  $validadmin = "unchecked";
   $psetid   = $form{'PSETID'};    $psetid   = $form{'PSETID'};
 if ($snum eq "A12345678") {$debug=1;}  if ($snum eq "A12345678") {$debug=1;}
 if ($snum eq "a12345678") {$debug=1;}  if ($snum eq "a12345678") {$debug=1;}
   $debug=0;
   if($psetid eq "") { $psetid = $setid; }    if($psetid eq "") { $psetid = $setid; }
 if ($debug) {print "GetTeacherInfo<BR>";$BenchmarkTa = new Benchmark;}  if ($debug) {print "GetTeacherInfo<BR>";$BenchmarkTa = new Benchmark;}
   &GetTeacherInfo;    &GetTeacherInfo;
 if($debug) {$BenchmarkTb = new Benchmark;print "<BR>",timestr(timediff($BenchmarkTb,$BenchmarkTa)),"\n";}  if($debug) {$BenchmarkTb = new Benchmark;print "<BR>",timestr(timediff($BenchmarkTb,$BenchmarkTa)),"\n";}
   
   # check for valid studentnumber/capaid    # check if student is banned from forum
   if ($debug) {print "BanUser<BR>";$BenchmarkTa = new Benchmark;}
   if (&BanUser) {exit;}
   if($debug) {$BenchmarkTb = new Benchmark;print "<BR>",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<BR>";$BenchmarkTa = new Benchmark;}  if ($debug) {print "ValidateUser<BR>";$BenchmarkTa = new Benchmark;}
   &ValidateUser;    &ValidateUser;
 if($debug) {$BenchmarkTb = new Benchmark;print "<BR>",timestr(timediff($BenchmarkTb,$BenchmarkTa)),"\n";}  if($debug) {$BenchmarkTb = new Benchmark;print "<BR>",timestr(timediff($BenchmarkTb,$BenchmarkTa)),"\n";}
Line 100  exit; Line 108  exit;
 #######################  #######################
 ## Begin Subroutines ##  ## Begin Subroutines ##
 #######################  #######################
   sub GetSetList {
     opendir(DDIR,"$capadir/$class/discussion");
     @sets = grep(/^[0-9]+$/,sort(readdir(DDIR)));
     closedir(DDIR);
     if ($debug) {print "<br> Sets:". @sets ."<BR>\n";}
   }
   
   sub SetListHeader {
     $pdset = "<select name=\"SETID\">\n";
     foreach $setnum(@sets) {
       $selected = "";
       if($setnum eq $setid) { $selected = "selected"; }
       $pdset .= "<option value=\"$setnum\" $selected>$setnum\n";
     }
     $pdset .= "</select>\n";
   }
   
   sub GetInfoList {
     local(@temp,@alldir,@setdir);
   #  if ($debug) {print "<br> GetInfoList <br>";}
     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 "<br> GetInfoList" . @infofiles."<br>";}
     foreach $infofile(@infofiles) {
   #    if ($debug) {print "<br> GetInfoList" . $infofile."<br>";}
       @temp = reverse split /\//, $infofile;
       $infodesc = $temp[0];
       $infodesc =~ s/.info//g;
       $infodesc =~ s/_/ /g;
       $infostring .= &InfoButtonHTML;
     }
     if ($infostring ne "") {
    #   $infostring = "</tr><tr>" . $infostring;
     }
   #  if ($debug) {print "<br> GetInfoList" . $infostring."<br>";}
   }
   
 sub NewSet {  sub NewSet {
   &Log("NewSet");    &Log("NewSet");
   
   if($setid <= $psetid) {   #grab capaid    if($setid <= $psetid) {   #grab capaid
     if ($debug) {print "ViewSet<BR>";$BenchmarkTa = new Benchmark;}      if ($debug) {print "NewSet<BR>";$BenchmarkTa = new Benchmark;}
     @allcapaid = `allcapaid -s $setid -e $setid -stu $snum -c $capadir/$class -i`;      @allcapaid = `allcapaid -s $setid -e $setid -stu $snum -c $capadir/$class -i`;
   
     $capaid = $allcapaid[2];      $capaid = $allcapaid[2];
Line 116  if($debug) {$BenchmarkTb = new Benchmark Line 169  if($debug) {$BenchmarkTb = new Benchmark
     return;      return;
   }    }
   
   opendir(DDIR,"$capadir/$class/discussion");    if ($debug) { print "<br> GetSetList\n"; }
     @sets = grep(/[0-9]/,sort(readdir(DDIR)));    &GetSetList;
   closedir(DDIR);    if ($debug) { print "<br> EndGetSetList\n"; }
     &SetListHeader;
   $pdset = "<select name=\"SETID\">\n";  
   foreach $setnum(@sets) {  
     $selected = "";  
     if($setnum eq $setid) { $selected = "selected"; }  
     $pdset .= "<option value=\"$setnum\" $selected>$setnum\n";  
   }  
   $pdset .= "</select>\n";  
   
   &NewSetHTML;    &NewSetHTML;
   #exit;    #exit;
 }  }
   
 sub ViewSet {  sub ViewSet {
     local($hidden);
   if ($debug) {print "InsideViewSet<BR>";$BenchmarkTa = new Benchmark;}    if ($debug) {print "InsideViewSet<BR>";$BenchmarkTa = new Benchmark;}
   &Log("ViewSet");    &Log("ViewSet");
   &CheckAdmin;    &CheckAdmin;
Line 143  sub ViewSet { Line 189  sub ViewSet {
   
   $capasbin = "$capasbin/$teachdir/capasbin";    $capasbin = "$capasbin/$teachdir/capasbin";
   &SetJumpBox;    &SetJumpBox;
     $backfunction="viewset";
     &GetInfoList;
   
   opendir(FORUM,"$capadir/$class/discussion/$setid");    opendir(FORUM,"$capadir/$class/discussion/$setid");
     @dir = sort(readdir(FORUM));      @dir = sort(readdir(FORUM));
   closedir(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) {    foreach $i(@dir) {
     $probnum = &RemZero(substr($i,0,6));      $probnum = &RemZero(substr($i,0,6));
     $found[$probnum]++;      $found[$probnum]++;
Line 183  if($debug) {$BenchmarkTb = new Benchmark Line 222  if($debug) {$BenchmarkTb = new Benchmark
   
   $col = 1;    $col = 1;
   for($probnum=1; $probnum<=$maxprobs; $probnum++) {    for($probnum=1; $probnum<=$maxprobs; $probnum++) {
       $hidden=0;
     if($col eq "1" && $probnum > $col1size && $bigtable eq "yes") {      if($col eq "1" && $probnum > $col1size && $bigtable eq "yes") {
       $col = 2;        $col = 2;
       &ViewSetEndColHTML;        &ViewSetEndColHTML;
Line 194  if($debug) {$BenchmarkTb = new Benchmark Line 234  if($debug) {$BenchmarkTb = new Benchmark
       closedir(MSG);        closedir(MSG);
       foreach $msg(@msgs) {        foreach $msg(@msgs) {
         if(&RemZero(substr($msg,0,6)) eq $probnum) {          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++; }
         }          }
       }        }
         $posts = $found[$probnum]-$hidden;
       &OpenMsg("$capadir/$class/discussion/$setid/$good[$#good]");        if ($posts >0) {
       $lastpost = "$date at $time";           &OpenMsg("$capadir/$class/discussion/$setid/$good[$#good]");
       $posts = $found[$probnum];           $lastpost = "$date at $time";
         } else {
            $lastpost = "--";
         }
     }      }
     else {      else {
       $lastpost = "--";        $lastpost = "--";
Line 263  sub ViewProblem { Line 309  sub ViewProblem {
       }        }
   
       if($msgcount eq "1") {        if($msgcount eq "1") {
    &GetInfoList;
         $postbutton = &ReplyButtonHTML;          $postbutton = &ReplyButtonHTML;
         &ProblemJumpBox;          &ProblemJumpBox;
         &ViewProblemTopHTML;          &ViewProblemTopHTML;
Line 296  sub ViewProblem { Line 343  sub ViewProblem {
           $hidebutton = &UnHideButtonHTML;            $hidebutton = &UnHideButtonHTML;
           $messagenote = "Hidden by $hiddenuser on $hiddendate at $hiddentime from $hiddenaddr";            $messagenote = "Hidden by $hiddenuser on $hiddendate at $hiddentime from $hiddenaddr";
         }          }
  $message =~ s/</&lt;/g;  # $message =~ s/</&lt;/g;
  $message =~ s/>/&gt;/g;  # $message =~ s/>/&gt;/g;
         &ViewProblemGutsHTML;          &ViewProblemGutsHTML;
       }        }
     }      }
   }    }
   
   if($msgfind eq "no") {    if($msgfind eq "no") {
       &GetInfoList;
     $postbutton = &PostNewButtonHTML;      $postbutton = &PostNewButtonHTML;
     &ProblemJumpBox;      &ProblemJumpBox;
     &ViewProblemTopHTML;      &ViewProblemTopHTML;
Line 317  sub ViewProblem { Line 365  sub ViewProblem {
 }  }
   
 sub ViewInfoFile {  sub ViewInfoFile {
   open(INFOFILE,"$capadir/$class/discussion/$setid/$file");    &Log("InfoFile");
     open(INFOFILE,"$capadir/$class/discussion/$file");
     @file = <INFOFILE>;      @file = <INFOFILE>;
   closedir(INFOFILE);    closedir(INFOFILE);
   
Line 549  sub WriteMsg { Line 598  sub WriteMsg {
   $filename = shift(@_);    $filename = shift(@_);
   # add sr to grab e-mail address of user    # add sr to grab e-mail address of user
   
     
     # <B> <I> <P> <A> <LI> <OL> <UL> <EM> <BR> <TT> <STRONG> <BLOCKQUOTE> <DIV .*> <DIV> <IMG>
     %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 = $form{'message'};
   $message =~ s/\n\r\n/<p>/g;  
     $message =~ s/((\n\r)|(\n))\n/<p>/g;
   $message =~ s/\n/<br>/g;    $message =~ s/\n/<br>/g;
   
     $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
       {($html{uc($2)}&(length($1)<1000))?"\<$1":"\&lt;$1"}/ge;
     $message =~ s/(\<?\s*(\w+)[^\<\>]*)\>/
       {($html{uc($2)}&(length($1)<1000))?"$1\>":"$1\&gt;"}/ge;
   
   #  $message =~ s/</&lt;/g;
   #  $message =~ s/>/&gt;/g;
   
   # check if posted anonymously    # check if posted anonymously
   if($form{'ANONYMOUS'} eq "yes") {    if($form{'ANONYMOUS'} eq "yes") {
     $username = "Anonymous|$username";      $username = "Anonymous|$username";
Line 611  sub CheckAdmin { Line 674  sub CheckAdmin {
  last;   last;
       }        }
     }      }
    if ($debug) { print "Admin Sections: ".$adminsection;}
     @adminsections = split(/\,/,$adminsection);      @adminsections = split(/\,/,$adminsection);
     for ($asection=0; $asection <= $#adminsections; $asection++) {      for ($asection=0; $asection <= $#adminsections; $asection++) {
       $adminsections[$asection]=&RemZero($adminsections[$asection])        $adminsections[$asection]=&RemZero($adminsections[$asection])
Line 622  sub CheckAdmin { Line 686  sub CheckAdmin {
           
     $snum =~ tr/a-z/A-Z/;      $snum =~ tr/a-z/A-Z/;
     LINE: foreach $line(@classl) {      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/;        $stunum =~ tr/a-z/A-Z/;
       if ( $stunum ne $snum ) { next LINE;}        if ( $stunum ne $snum ) { next LINE;}
       $section = &RemZero($section);        $section = &RemZero($section);
    if ($debug) {print "<BR>".$stunum."Is in section:".$section."<BR>";}
       foreach $asection(@adminsections) {        foreach $asection(@adminsections) {
  if($section eq $asection ) {   if($section eq $asection ) {
   $validadmin = "yes";    $validadmin = "yes";
Line 637  sub CheckAdmin { Line 703  sub CheckAdmin {
   if($validadmin eq "no" && $mode eq "kill") { &NotAdminHTML; }    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 = <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 <br>";}
       $ban =~ tr/a-z/A-Z/;
       $ban =~ tr/\ //d;
       if ( $ban eq $snum) { &BannedMessageHTML; $result=1 }
     }
     return $result
   }
   
 sub ValidateUser {  sub ValidateUser {
   local(@allcapaid,@classl,$line);    local(@allcapaid,@classl,$line);
   
Line 653  sub ValidateUser { Line 743  sub ValidateUser {
   if($valid eq "no") { &InvalidVarsHTML; }    if($valid eq "no") { &InvalidVarsHTML; }
   
   # check w/ allcapaid program    # 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];
   chop $allcapaid[2];    chop $allcapaid[2];
     if ($debug) {print "capaid:" . $allcapaid[2] . "<BR>\n";}
   if($allcapaid[2] ne $capaid) {    if($allcapaid[2] ne $capaid) {
     if($action ne "newset") { &BadPassHTML; }      if ($allcapaid[2] =~ /Open/) { &NotOpen; exit; }
       if($action ne "newset") { &BadPassHTML; exit; }
     #&NewSet;      #&NewSet;
   }    }
 }  }
   
   sub NotOpen {
     &GetSetList;
     &SetListHeader;
     &ViewSetTitleHTML;
   print <<NotOpen2;
   This set is not yet open. Please choose a different set.
   </body>
   </html>
   NotOpen2
   }
   
 sub UserInfo {  sub UserInfo {
   local($line,@classl,$last,$first,$middle);    local($line,@classl,$last,$first,$middle);
   
Line 703  sub ProblemJumpBox { Line 806  sub ProblemJumpBox {
 }  }
   
 sub SetJumpBox {  sub SetJumpBox {
   opendir(DDIR,"$capadir/$class/discussion");    &GetSetList;
     @sets = grep(/[0-9]/,sort(readdir(DDIR)));    &SetListHeader;
   closedir(DDIR);  
   
   $pdset = "<select name=\"SETID\">\n";  
   foreach $set(@sets) {  
     $selected = "";  
     if($set eq $setid) { $selected = " selected"; }  
     $pdset .= "  <option value=\"$set\"$selected>$set\n";  
   }  
   $pdset .= "</select>";  
 }  }
   
 sub AddZero {  sub AddZero {
Line 754  sub form_info { Line 848  sub form_info {
   
   foreach $pair (@pairs) {    foreach $pair (@pairs) {
      ($name, $value) = split(/=/, $pair);       ($name, $value) = split(/=/, $pair);
        if ($name eq "message") {$allow_html=1;} else {$allow_html=0;}
      # Un-Webify plus signs and %-encoding       # Un-Webify plus signs and %-encoding
      $value =~ tr/+/ /;       $value =~ tr/+/ /;
      $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
Line 774  sub GetDateTime  { Line 868  sub GetDateTime  {
   ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime (time);    ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime (time);
   $mon++;    $mon++;
   
     $year=$year+1900;
   
   if ($hour < 12) {    if ($hour < 12) {
   $AMPM = "AM";    $AMPM = "AM";
   }    }
Line 811  sub Log { Line 907  sub Log {
   
   &Lock("lock.file");    &Lock("lock.file");
   open(LOG,">>$capadir/$class/discussion/logs/access.log");    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);    close(LOG);
   &Unlock("lock.file");    &Unlock("lock.file");
 }  }

Removed from v.1.1.1.1  
changed lines
  Added in v.1.8


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>