Annotation of capa/capa51/Discuss/capadiscuss, revision 1.1

1.1     ! albertel    1: #!/usr/ucb/perl
        !             2: #
        !             3: # Ryan J. Shaltry
        !             4: # tech4@msue.msu.edu
        !             5: # Guy Albertelli
        !             6: # albertel@msu.edu
        !             7: #
        !             8: # CAPA Discussion Forum
        !             9: # version 1.3.0
        !            10: #  Copyright (C) 1992-2000 Michigan State University
        !            11: #
        !            12: #  The CAPA system is free software; you can redistribute it and/or
        !            13: #  modify it under the terms of the GNU Library General Public License as
        !            14: #  published by the Free Software Foundation; either version 2 of the
        !            15: #  License, or (at your option) any later version.
        !            16: #
        !            17: #  The CAPA system is distributed in the hope that it will be useful,
        !            18: #  but WITHOUT ANY WARRANTY; without even the implied warranty of
        !            19: #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
        !            20: #  Library General Public License for more details.
        !            21: #
        !            22: #  You should have received a copy of the GNU Library General Public
        !            23: #  License along with the CAPA system; see the file COPYING.  If not,
        !            24: #  write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
        !            25: #  Boston, MA 02111-1307, USA.
        !            26: #
        !            27: #  As a special exception, you have permission to link this program
        !            28: #  with the TtH/TtM library and distribute executables, as long as you
        !            29: #  follow the requirements of the GNU GPL in regard to all of the
        !            30: #  software in the executable aside from TtH/TtM.
        !            31: 
        !            32: 
        !            33: print "Content-type: text/html\n\n";
        !            34: 
        !            35: use Benchmark;
        !            36: $BenchmarkT0 = new Benchmark;
        !            37: #require "capadiscuss.setup";
        !            38: require "../capadiscuss_html";
        !            39: 
        !            40: ################################################
        !            41: ## Configuration - Change these appropriately ##
        !            42: ################################################
        !            43: $discussurl = "capadiscuss";
        !            44: $capasbin = "/capa-bin";
        !            45: use Cwd;
        !            46: $capabin = cwd();
        !            47: @capabinparts = split /\//, $capabin;
        !            48: $capabin = join "/", @capabinparts[0..$#capabinparts-1];
        !            49: 
        !            50: # capadiscuss.setup
        !            51: $debug = 0;
        !            52: ################################################
        !            53: ## End Configuration ###########################
        !            54: ################################################
        !            55: 
        !            56: &form_info;
        !            57: 
        !            58: $yp = "19";
        !            59: $validadmin = "unchecked";
        !            60: 
        !            61:   # define variables
        !            62:   $class    = $form{'CLASS'};
        !            63:   $snum     = $form{'SNUM'};
        !            64:   $capaid   = $form{'CAPAID'};
        !            65:   $setid    = $form{'SETID'};
        !            66:   $action   = $form{'ACTION'};
        !            67:   $file     = $form{'FILE'};
        !            68:   $probnum  = $form{'PROBNUM'};
        !            69:   $replynum = $form{'REPLYNUM'};
        !            70:   $psetid   = $form{'PSETID'};
        !            71: if ($snum eq "A12345678") {$debug=1;}
        !            72: if ($snum eq "a12345678") {$debug=1;}
        !            73: $debug=0;
        !            74:   if($psetid eq "") { $psetid = $setid; }
        !            75: if ($debug) {print "GetTeacherInfo<BR>";$BenchmarkTa = new Benchmark;}
        !            76:   &GetTeacherInfo;
        !            77: if($debug) {$BenchmarkTb = new Benchmark;print "<BR>",timestr(timediff($BenchmarkTb,$BenchmarkTa)),"\n";}
        !            78: 
        !            79:   # check if student is banned from forum
        !            80: if ($debug) {print "BanUser<BR>";$BenchmarkTa = new Benchmark;}
        !            81: if (&BanUser) {exit;}
        !            82: if($debug) {$BenchmarkTb = new Benchmark;print "<BR>",timestr(timediff($BenchmarkTb,$BenchmarkTa)),"\n";}
        !            83: 
        !            84:   # check for valid studentnumber/capaid, an exit will occur here if the set wasn't open
        !            85: if ($debug) {print "ValidateUser<BR>";$BenchmarkTa = new Benchmark;}
        !            86:   &ValidateUser;
        !            87: if($debug) {$BenchmarkTb = new Benchmark;print "<BR>",timestr(timediff($BenchmarkTb,$BenchmarkTa)),"\n";}
        !            88: 
        !            89:   # grab username from student number
        !            90: if ($debug) {print "UserInfo<BR>";$BenchmarkTa = new Benchmark;}
        !            91:   &UserInfo($snum);
        !            92: if($debug) {$BenchmarkTb = new Benchmark;print "<BR>",timestr(timediff($BenchmarkTb,$BenchmarkTa)),"\n";}
        !            93: 
        !            94: if ($debug) {print "GetDateTime<BR>";$BenchmarkTa = new Benchmark;}
        !            95:   &GetDateTime;
        !            96: if($debug) {$BenchmarkTb = new Benchmark;print "<BR>",timestr(timediff($BenchmarkTb,$BenchmarkTa)),"\n";}
        !            97: 
        !            98: if ($debug) {print $action . "<BR>";$BenchmarkTa = new Benchmark;}
        !            99:   # call appropriate sr
        !           100:   if($action eq "newset"                   ) { &NewSet;                }
        !           101:   if($action eq "viewset" || $action eq "" ) { &ViewSet;               }
        !           102:   if($action eq "viewproblem"              ) { &ViewProblem;           }
        !           103:   if($action eq "post"                     ) { &Post;                  }
        !           104:   if($action eq "postsubmit"               ) { &PostSubmit;            }
        !           105:   if($action eq "delmsgpre"                ) { &DelMsgPre;             }
        !           106:   if($action eq "delmsg"                   ) { &DelMsg;                }
        !           107:   if($action eq "hidemsgpre"               ) { &HideMsgPre;            }
        !           108:   if($action eq "hidemsg"                  ) { &HideMsg;               }
        !           109:   if($action eq "unhidemsgpre"             ) { &UnHideMsgPre;          }
        !           110:   if($action eq "unhidemsg"                ) { &UnHideMsg;             }
        !           111: 
        !           112:   if($action eq "admin"                    ) { &AdminMain;             }
        !           113:   if($action eq "adminusersearch"          ) { &AdminUserSearch;       }
        !           114:   if($action eq "adminusersearchsubmit"    ) { &AdminUserSearchSubmit; }
        !           115: 
        !           116:   if($action eq "viewinfofile"             ) { &ViewInfoFile;          }
        !           117: 
        !           118:   if($action eq "topmsg"                   ) { &TopMsg("top");        }
        !           119:   if($action eq "untopmsg"                 ) { &TopMsg("");            }
        !           120: if($debug) {$BenchmarkTb = new Benchmark;print "<BR>",timestr(timediff($BenchmarkTb,$BenchmarkTa)),"\n";}
        !           121: 
        !           122: $BenchmarkT1 = new Benchmark;
        !           123: if($debug) { print "<BR>",timestr(timediff($BenchmarkT1,$BenchmarkT0)),"\n";}
        !           124: 
        !           125: exit;
        !           126: 
        !           127: #######################
        !           128: ## Begin Subroutines ##
        !           129: #######################
        !           130: sub GetSetList {
        !           131:   opendir(DDIR,"$capadir/$class/discussion");
        !           132:   @sets = grep(/^[0-9]+$/,sort(readdir(DDIR)));
        !           133:   closedir(DDIR);
        !           134:   if ($debug) {print "<br> Sets:". @sets ."<BR>\n";}
        !           135: }
        !           136: 
        !           137: sub SetListHeader {
        !           138:   $pdset = "<select name=\"SETID\">\n";
        !           139:   foreach $setnum(@sets) {
        !           140:     $selected = "";
        !           141:     if($setnum eq $setid) { $selected = "selected"; }
        !           142:     $pdset .= "<option value=\"$setnum\" $selected>$setnum\n";
        !           143:   }
        !           144:   $pdset .= "</select>\n";
        !           145: }
        !           146: 
        !           147: sub GetInfoList {
        !           148:   local(@temp,@alldir,@setdir);
        !           149: #  if ($debug) {print "<br> GetInfoList <br>";}
        !           150:   opendir(DDIR,"$capadir/$class/discussion");
        !           151:   @alldir = sort(grep(/.info$/,readdir(DDIR)));
        !           152:   closedir(DDIR);
        !           153: 
        !           154:   opendir(FORUM,"$capadir/$class/discussion/$setid");
        !           155:   @setdir = sort(grep(/.info$/,readdir(FORUM)));
        !           156:   closedir(FORUM);
        !           157: 
        !           158:   foreach $file(@setdir) { @setdir2 = (@setdir2,"$setid/$file"); }
        !           159:   @infofiles = (@alldir,@setdir2);
        !           160:   $infostring = "";
        !           161: #  if ($debug) {print "<br> GetInfoList" . @infofiles."<br>";}
        !           162:   foreach $infofile(@infofiles) {
        !           163: #    if ($debug) {print "<br> GetInfoList" . $infofile."<br>";}
        !           164:     @temp = reverse split /\//, $infofile;
        !           165:     $infodesc = $temp[0];
        !           166:     $infodesc =~ s/.info//g;
        !           167:     $infodesc =~ s/_/ /g;
        !           168:     $infostring .= &InfoButtonHTML;
        !           169:   }
        !           170:   if ($infostring ne "") {
        !           171:  #   $infostring = "</tr><tr>" . $infostring;
        !           172:   }
        !           173: #  if ($debug) {print "<br> GetInfoList" . $infostring."<br>";}
        !           174: }
        !           175: 
        !           176: sub NewSet {
        !           177:   &Log("NewSet");
        !           178: 
        !           179:   if($setid <= $psetid) {   #grab capaid
        !           180:     if ($debug) {print "NewSet<BR>";$BenchmarkTa = new Benchmark;}
        !           181:     @allcapaid = `allcapaid -s $setid -e $setid -stu $snum -c $capadir/$class -i`;
        !           182: 
        !           183:     $capaid = $allcapaid[2];
        !           184:     chop $capaid;
        !           185:     chop $capaid;
        !           186:     &ViewSet;
        !           187: if($debug) {$BenchmarkTb = new Benchmark;print "<BR>",timestr(timediff($BenchmarkTb,$BenchmarkTa)),"\n";}
        !           188:     return;
        !           189:   }
        !           190: 
        !           191:   if ($debug) { print "<br> GetSetList\n"; }
        !           192:   &GetSetList;
        !           193:   if ($debug) { print "<br> EndGetSetList\n"; }
        !           194:   &SetListHeader;
        !           195:   &NewSetHTML;
        !           196:   #exit;
        !           197: }
        !           198: 
        !           199: sub ViewSet {
        !           200:   local($hidden);
        !           201:   if ($debug) {print "InsideViewSet<BR>";$BenchmarkTa = new Benchmark;}
        !           202:   &Log("ViewSet");
        !           203:   &CheckAdmin;
        !           204:   $adminbutton = "";
        !           205:   if($validadmin eq "yes") {
        !           206:     $adminbutton = &AdminButtonHTML;
        !           207:   }
        !           208: 
        !           209:   $capasbin = "$capasbin/$teachdir/capasbin";
        !           210:   &SetJumpBox;
        !           211:   $backfunction="viewset";
        !           212:   &GetInfoList;
        !           213: 
        !           214:   opendir(FORUM,"$capadir/$class/discussion/$setid");
        !           215:     @dir = sort(readdir(FORUM));
        !           216:   closedir(FORUM);
        !           217: 
        !           218:   foreach $i(@dir) {
        !           219:     $probnum = &RemZero(substr($i,0,6));
        !           220:     $found[$probnum]++;
        !           221:   }
        !           222:   $maxprobs = &MaxProbs($setid);
        !           223: 
        !           224:   # split table (if more than 15 problems)
        !           225:   $bigtable = "no";
        !           226:   if($maxprobs > 5) {
        !           227:     $bigtable = "yes";
        !           228:     $col1size = int ($maxprobs / 2);
        !           229:     $col2size = $maxprobs - $col1size;
        !           230:     if($col1size < $col2size) {
        !           231:       $t = $col1size;
        !           232:       $col1size = $col2size;
        !           233:       $col2size = $t;
        !           234:     }
        !           235:   }
        !           236: if($debug) {$BenchmarkTb = new Benchmark;print "<BR>2",timestr(timediff($BenchmarkTb,$BenchmarkTa)),"\n";}
        !           237:   &ViewSetTitleHTML;
        !           238: 
        !           239:   if($bigtable eq "no") { &ViewSetTopSmallHTML; }
        !           240:   else                  { &ViewSetTopBigHTML; }
        !           241: 
        !           242:   $col = 1;
        !           243:   for($probnum=1; $probnum<=$maxprobs; $probnum++) {
        !           244:     $hidden=0;
        !           245:     if($col eq "1" && $probnum > $col1size && $bigtable eq "yes") {
        !           246:       $col = 2;
        !           247:       &ViewSetEndColHTML;
        !           248:       &ViewSetTopSmallHTML;
        !           249:     }
        !           250:     if($found[$probnum] ne "") {
        !           251:       opendir(MSG,"$capadir/$class/discussion/$setid");
        !           252:         @msgs = grep(/.msg/,sort(readdir(MSG)));
        !           253:       closedir(MSG);
        !           254:       foreach $msg(@msgs) {
        !           255:         if(&RemZero(substr($msg,0,6)) eq $probnum) {
        !           256:           &OpenMsg("$capadir/$class/discussion/$setid/$msg");
        !           257:           if(!($status eq "hidden" && $validadmin ne "yes")) { 
        !           258:             push(@good,$msg); 
        !           259:           } else { $hidden++; }
        !           260:         }
        !           261:       }
        !           262:       $posts = $found[$probnum]-$hidden;
        !           263:       if ($posts >0) {
        !           264:          &OpenMsg("$capadir/$class/discussion/$setid/$good[$#good]");
        !           265:          $lastpost = "$date at $time";
        !           266:       } else {
        !           267:          $lastpost = "--";
        !           268:       }
        !           269:     }
        !           270:     else {
        !           271:       $lastpost = "--";
        !           272:       $posts = "0"; }
        !           273:     &ViewSetGutsHTML;
        !           274:   }
        !           275:   &ViewSetBotHTML;
        !           276: if($debug) {$BenchmarkTb = new Benchmark;print "<BR>3",timestr(timediff($BenchmarkTb,$BenchmarkTa)),"\n";}
        !           277:   #exit;
        !           278: }
        !           279: 
        !           280: sub ViewProblem {
        !           281:   &Log("ViewProblem");
        !           282: 
        !           283:   # check if user is administrator (for admin button)
        !           284:   &CheckAdmin;
        !           285:   if($validadmin eq "yes") {
        !           286:     $adminbutton = &AdminButtonHTML;
        !           287:   }
        !           288:   else {
        !           289:     $adminbutton = "";
        !           290:   }
        !           291: 
        !           292:   opendir (MSGS,"$capadir/$class/discussion/$setid");
        !           293:     @msgs = sort(readdir(MSGS));
        !           294:   closedir(MSGS);
        !           295: 
        !           296:   # search for top message
        !           297:   @top = grep (/top/, @msgs);
        !           298:   $topmsg = "";
        !           299: #  print "$#top";
        !           300:   if($#top ne "0") {
        !           301:     $pnum = &AddZero($probnum);
        !           302:     foreach $entry(@top) {
        !           303:       $find = $entry =~ s/\A$pnum/$pnum/o;
        !           304:       if($find eq "1") {
        !           305:         $topmsg = $entry;
        !           306:         @msgs = grep(!/$topmsg/,@msgs);
        !           307:         unshift(@msgs,$topmsg);
        !           308:         print "$topmsg";
        !           309:       }
        !           310:     }
        !           311:   }
        !           312: 
        !           313:   $msgfind = "no";
        !           314:   $msgcount = 0;
        !           315: 
        !           316:   $capasbin = "$capasbin/$teachdir/capasbin";
        !           317: 
        !           318:   foreach $i(@msgs) {
        !           319:     $pn = &RemZero(substr($i,0,6));
        !           320:     if($pn eq $probnum) {
        !           321:       $msgcount++;
        !           322:       $msgfind = "yes";
        !           323:       &OpenMsg("$capadir/$class/discussion/$setid/$i");
        !           324: 
        !           325:       if($status eq "hidden" && $validadmin ne "yes") {
        !           326:         $msgcount--;
        !           327:         $msgfind = "no";
        !           328:       }
        !           329: 
        !           330:       if($msgcount eq "1") {
        !           331: 	&GetInfoList;
        !           332:         $postbutton = &ReplyButtonHTML;
        !           333:         &ProblemJumpBox;
        !           334:         &ViewProblemTopHTML;
        !           335:       }
        !           336: 
        !           337:       ($token1,$token2) = split(/\|/,$poster);
        !           338:       chop $token2;
        !           339:       if($token1 eq "Anonymous") {
        !           340:          if($validadmin eq "yes") {
        !           341:            $poster = "$token2 (anonymously)";
        !           342:          }
        !           343:          else {
        !           344:            $poster = "$token1";
        !           345:            $email = "";
        !           346:          }
        !           347:       }
        !           348:       $topfind = grep(/-top.msg/,$i);
        !           349:       if($validadmin eq "yes") {
        !           350:         $file = "$i";
        !           351:         $delbutton = &DelButtonHTML;
        !           352:         $hidebutton = &HideButtonHTML;
        !           353:         $topbutton = &TopButtonHTML;
        !           354:         if($topfind eq "1") { $topbutton = &UnTopButtonHTML; }
        !           355:       }
        !           356:       $subjectbgcolor = "#92D1D0";
        !           357:       if($topfind eq "1") { $subjectbgcolor = "blue"; }
        !           358:       $messagenote = "";
        !           359:       if($validadmin eq "yes" || $status eq "public") {
        !           360:         if($status eq "hidden") {
        !           361:           $subjectbgcolor = "red";
        !           362:           $hidebutton = &UnHideButtonHTML;
        !           363:           $messagenote = "Hidden by $hiddenuser on $hiddendate at $hiddentime from $hiddenaddr";
        !           364:         }
        !           365: #	$message =~ s/</&lt;/g;
        !           366: #	$message =~ s/>/&gt;/g;
        !           367:         &ViewProblemGutsHTML;
        !           368:       }
        !           369:     }
        !           370:   }
        !           371: 
        !           372:   if($msgfind eq "no") {
        !           373:     &GetInfoList;
        !           374:     $postbutton = &PostNewButtonHTML;
        !           375:     &ProblemJumpBox;
        !           376:     &ViewProblemTopHTML;
        !           377:     &ViewProblemNoneHTML;
        !           378:     &ViewProblemBotHTML;
        !           379:   } else {
        !           380:     &ViewProblemBotHTML;
        !           381:   }
        !           382:   
        !           383:   #exit;
        !           384: }
        !           385: 
        !           386: sub ViewInfoFile {
        !           387:   &Log("InfoFile");
        !           388:   open(INFOFILE,"$capadir/$class/discussion/$file");
        !           389:     @file = <INFOFILE>;
        !           390:   closedir(INFOFILE);
        !           391: 
        !           392:   print "<html><head></head><body bgcolor=\"#ffffff\">";
        !           393:   $backfunction = $form{'BACKFUNCTION'};
        !           394:   &InfoBackButtonHTML;
        !           395:   foreach $line(@file) {
        !           396:     print "$line";
        !           397:   }
        !           398: 
        !           399:   #exit;
        !           400: }
        !           401: 
        !           402: sub Post {
        !           403:   local(@msgs,$pn,$msg);
        !           404: 
        !           405:   # grab last message in thread
        !           406:   opendir(MSGS,"$capadir/$class/discussion/$setid");
        !           407:     @msgs = grep(/.msg/,sort(readdir(MSGS)));
        !           408:   closedir(MSGS); 
        !           409: 
        !           410:   foreach $msg(@msgs) {
        !           411:     $pn = &RemZero(substr($msg,0,6));
        !           412:     if($pn eq $probnum) {
        !           413:       $lastfile = $msg;
        !           414:     }
        !           415:   }
        !           416: 
        !           417:   $PostType = "New Message";
        !           418:   if($lastfile ne "") {
        !           419:     &OpenMsg("$capadir/$class/discussion/$setid/$lastfile");
        !           420:     if($status eq "public" || $validadmin eq "yes") {
        !           421:       ($poster,$rposter) = split(/\|/,$poster);
        !           422:       $inreplyto = &InReplyToHTML;
        !           423:       $PostType = "Reply";
        !           424:     }
        !           425:   }
        !           426: 
        !           427:   &PostHTML;
        !           428:   #exit;
        !           429: }
        !           430: 
        !           431: sub PostSubmit {
        !           432:   local($message,$subject,$date);
        !           433: 
        !           434:   $message = $form{'message'};
        !           435:   $subject = $form{'subject'};
        !           436:   
        !           437:   if($message eq "" || $subject eq "") { &MFPostReplyHTML; }
        !           438: 
        !           439:   &Log("Post");
        !           440: 
        !           441:   # find last message in thread
        !           442:   opendir(FORUM,"$capadir/$class/discussion/$setid");
        !           443:     @dir = sort(readdir(FORUM));
        !           444:   closedir(FORUM);
        !           445: 
        !           446:   $probnum = &AddZero($probnum);
        !           447:   $replynum = "000000";
        !           448:   foreach $msg(@dir) {
        !           449:     if(substr($msg,0,6) eq $probnum) {
        !           450:         $replynum = &AddZero(&RemZero(substr($msg,7,6)) + 1);
        !           451:     }
        !           452:   }
        !           453: 
        !           454:   $date = substr($RunonDate,0,4) . $yp . substr($RunonDate,4,2);
        !           455:   &WriteMsg("$capadir/$class/discussion/$setid/$probnum-$replynum-$date-000000.msg");
        !           456: 
        !           457:   $probnum = &RemZero($probnum);
        !           458:   &PostDoneHTML;
        !           459:   #exit;
        !           460: }
        !           461: 
        !           462: sub DelMsgPre {
        !           463:   &CheckAdmin('kill');
        !           464:   &OpenMsg("$capadir/$class/discussion/$setid/$file");
        !           465:   &DelMsgPreHTML;
        !           466:   #exit;
        !           467: }
        !           468: 
        !           469: sub DelMsg {
        !           470:   &CheckAdmin('kill');
        !           471:   unlink("$capadir/$class/discussion/$setid/$file");
        !           472:   &DelMsgDoneHTML;
        !           473:   #exit;
        !           474: }
        !           475: 
        !           476: sub HideMsgPre {
        !           477:   &CheckAdmin('kill');
        !           478:   &OpenMsg("$capadir/$class/discussion/$setid/$file");
        !           479:   &HideMsgPreHTML;
        !           480:   #exit;
        !           481: }
        !           482: 
        !           483: sub HideMsg {
        !           484:   &CheckAdmin('kill');
        !           485:   open(MSG,"$capadir/$class/discussion/$setid/$file");
        !           486:     @msg = <MSG>;
        !           487:   close(MSG);
        !           488: 
        !           489:   unlink("$capadir/$class/discussion/$setid/$file");
        !           490: 
        !           491:   open(MSG,">$capadir/$class/discussion/$setid/$file");
        !           492:     for($i=0;$i<=5;$i++) {
        !           493:       print MSG "$msg[$i]";
        !           494:     }
        !           495:     print MSG "hidden|$username|$HyphenDate|$Time|$ENV{'REMOTE_ADDR'}\n";
        !           496:   close(MSG);
        !           497: 
        !           498:   &HideMsgDoneHTML;
        !           499: }
        !           500: 
        !           501: sub UnHideMsgPre {
        !           502:   &CheckAdmin('kill');
        !           503:   &OpenMsg("$capadir/$class/discussion/$setid/$file");
        !           504:   &UnHideMsgPreHTML;
        !           505:   #exit;
        !           506: }
        !           507: 
        !           508: sub UnHideMsg {
        !           509:   &CheckAdmin('kill');
        !           510:   open(MSG,"$capadir/$class/discussion/$setid/$file");
        !           511:     @msg = <MSG>;
        !           512:   close(MSG);
        !           513: 
        !           514:   unlink("$capadir/$class/discussion/$setid/$file");
        !           515: 
        !           516:   open(MSG,">$capadir/$class/discussion/$setid/$file");
        !           517:     for($i=0;$i<=5;$i++) {
        !           518:       print MSG "$msg[$i]";
        !           519:     }
        !           520:     print MSG "public||||}\n";
        !           521:   close(MSG);
        !           522: 
        !           523:   &UnHideMsgDoneHTML;
        !           524: }
        !           525: 
        !           526: 
        !           527: sub TopMsg {
        !           528:   &CheckAdmin('kill');
        !           529: 
        !           530:   $ext = shift(@_);
        !           531:   
        !           532:   open(MSG,"$capadir/$class/discussion/$setid/$file");
        !           533:     @msg = <MSG>;
        !           534:   close(MSG);
        !           535:   
        !           536:   unlink("$capadir/$class/discussion/$setid/$file");
        !           537:   
        !           538:   ($filename, $extension) = split(/\./,$file);
        !           539:   $filename = "$filename-$ext.msg";
        !           540:   open(MSG,">$capadir/$class/discussion/$setid/$filename");
        !           541:     for($i=0;$i<=6;$i++) {
        !           542:       print MSG "$msg[$i]";
        !           543:     }
        !           544:   close(MSG);
        !           545:   
        !           546:   if($ext eq "") {
        !           547:     $function = "restored to its original position in the thread.";
        !           548:   }
        !           549:   else {
        !           550:     $function = "moved to the top of the thread list.";
        !           551:   }
        !           552: 
        !           553:   &TopMsgDoneHTML;
        !           554: }
        !           555: 
        !           556: ###############################
        !           557: ## Administrator Subroutines ##
        !           558: ###############################
        !           559: 
        !           560: sub AdminMain {
        !           561:   &CheckAdmin('kill');
        !           562:   &AdminMainHTML;
        !           563:   #exit;
        !           564: }
        !           565: 
        !           566: 
        !           567: sub AdminUserSearch {
        !           568:   &CheckAdmin('kill');
        !           569:   &AdminUserSearchHTML;
        !           570:   #exit;
        !           571: }
        !           572: 
        !           573: 
        !           574: sub AdminUserSearchSubmit {
        !           575:   local($sname,$semail,$saction,$sset,$sprob,$sdate,$stime);
        !           576:   &CheckAdmin('kill');
        !           577: 
        !           578:   $query = $form{'usersearch'};
        !           579:   open(LOG,"$capadir/$class/discussion/logs/access.log");
        !           580:     @log = <LOG>;
        !           581:   close(LOG);
        !           582: 
        !           583:   @linematches = grep /$query/, @log;
        !           584:   
        !           585:   foreach $line(@linematches) { print $line; }
        !           586: 
        !           587:   #exit;
        !           588: }
        !           589: 
        !           590: ######################
        !           591: ## Misc Subroutines ##
        !           592: ######################
        !           593: 
        !           594: sub OpenMsg {
        !           595:   local($filename,$statusl);
        !           596: 
        !           597:   $filename = shift(@_);
        !           598:   
        !           599:   open (MSG,"$filename");
        !           600:     @msg = <MSG>;
        !           601:   close(MSG);
        !           602: 
        !           603:   $poster   = $msg[0];
        !           604:   $date     = $msg[1];
        !           605:   $time     = $msg[2];
        !           606:   $subject  = $msg[3];
        !           607:   $email    = $msg[4];
        !           608:   $message  = $msg[5];
        !           609:   $statusl  = $msg[6];
        !           610: 
        !           611:   ($status, $hiddenuser, $hiddendate, $hiddentime, $hiddenaddr) = split(/\|/,$statusl);
        !           612: }
        !           613: 
        !           614: sub WriteMsg {
        !           615:   local($filename,$message);
        !           616: 
        !           617:   $filename = shift(@_);
        !           618:   # add sr to grab e-mail address of user
        !           619: 
        !           620:   
        !           621:   # <B> <I> <P> <A> <LI> <OL> <UL> <EM> <BR> <TT> <STRONG> <BLOCKQUOTE> <DIV .*> <DIV> <IMG>
        !           622:   %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1, BR=>1, TT=>1, STRONG=>1,
        !           623: 	 BLOCKQUOTE=>1, DIV=>1, IMG=>1);
        !           624: 
        !           625:   $message = $form{'message'};
        !           626: 
        !           627:   $message =~ s/((\n\r)|(\n))\n/<p>/g;
        !           628:   $message =~ s/\n/<br>/g;
        !           629: 
        !           630:   $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
        !           631:     {($html{uc($2)}&(length($1)<1000))?"\<$1":"\&lt;$1"}/ge;
        !           632:   $message =~ s/(\<?\s*(\w+)[^\<\>]*)\>/
        !           633:     {($html{uc($2)}&(length($1)<1000))?"$1\>":"$1\&gt;"}/ge;
        !           634: 
        !           635: #  $message =~ s/</&lt;/g;
        !           636: #  $message =~ s/>/&gt;/g;
        !           637: 
        !           638:   # check if posted anonymously
        !           639:   if($form{'ANONYMOUS'} eq "yes") {
        !           640:     $username = "Anonymous|$username";
        !           641:   }
        !           642: 
        !           643:   open (MSG,">$filename");
        !           644:     print MSG "$username\n";
        !           645:     print MSG "$HyphenDate\n";
        !           646:     print MSG "$Time\n";
        !           647:     print MSG "$subject\n";
        !           648:     print MSG "$email\n";
        !           649:     print MSG "$message\n";
        !           650:     print MSG "public||||\n";
        !           651:   close(MSG);
        !           652: }
        !           653: 
        !           654: sub GetTeacherInfo {
        !           655:   local($capa5dir,$classname,$tdir,@classconf);
        !           656: 
        !           657:   # open/read class.conf file
        !           658:   open (CLASSCONF,"$capabin/class.conf");
        !           659:     @classconf = <CLASSCONF>;
        !           660:   close(CLASSCONF);
        !           661: 
        !           662:   $found eq "no";
        !           663:   foreach $line(@classconf) {
        !           664:     ($classname,$capa5dir,$tdir) = split(/[\t\ ]+/,$line);
        !           665:     if($classname eq $class) {
        !           666:       $teachdir = $tdir;
        !           667:       $capadir  = $capa5dir;
        !           668:       $found    = "yes";
        !           669:       $cgidirurl = join "/", $capasbin,$teachdir;
        !           670:     }
        !           671:   }
        !           672:   if($found eq "no") { &InvalidVarsHTML; }
        !           673: }
        !           674: 
        !           675: sub CheckAdmin {
        !           676:   local($asection,@adminsections,$line,@capaconfig,$command,$value,
        !           677:         $adminsection,@classl,$course,$coursenum,$section,$stunum,$a);
        !           678: 
        !           679:   $mode = shift(@_);
        !           680: 
        !           681:   if ($validadmin eq "unchecked") {
        !           682:     $validadmin = "no";
        !           683:     
        !           684:     # open 'capa.config' file (for admin section read)
        !           685:     open(CAPACONFIG,"$capadir/$class/capa.config");
        !           686:     @capaconfig = <CAPACONFIG>;
        !           687:     close(CAPACONFIG);
        !           688:     foreach $line(@capaconfig) {
        !           689:       chop $line;
        !           690:       ($command,$value) = split(/\ =\ /,$line);
        !           691:       if($command eq "admin_section") {
        !           692: 	$adminsection = $value;
        !           693: 	last;
        !           694:       }
        !           695:     }
        !           696: 	if ($debug) { print "Admin Sections: ".$adminsection;}
        !           697:     @adminsections = split(/\,/,$adminsection);
        !           698:     for ($asection=0; $asection <= $#adminsections; $asection++) {
        !           699:       $adminsections[$asection]=&RemZero($adminsections[$asection])
        !           700:     }
        !           701:     # open 'classl' file
        !           702:     open(CLASSL,"$capadir/$class/classl");
        !           703:     @classl = <CLASSL>;
        !           704:     close(CLASSL);
        !           705:     
        !           706:     $snum =~ tr/a-z/A-Z/;
        !           707:     LINE: foreach $line(@classl) {
        !           708:       $section= substr $line, 10, 3;
        !           709:       $stunum= substr $line, 14, 9;
        !           710:       $stunum =~ tr/a-z/A-Z/;
        !           711:       if ( $stunum ne $snum ) { next LINE;}
        !           712:       $section = &RemZero($section);
        !           713: 	if ($debug) {print "<BR>".$stunum."Is in section:".$section."<BR>";}
        !           714:       foreach $asection(@adminsections) {
        !           715: 	if($section eq $asection ) {
        !           716: 	  $validadmin = "yes";
        !           717: 	  last LINE;
        !           718: 	}
        !           719:       }
        !           720:     }
        !           721:   }
        !           722:   if($validadmin eq "no" && $mode eq "kill") { &NotAdminHTML; }
        !           723: }
        !           724: 
        !           725: sub BanUser {
        !           726:   local (@capaconfig,$line,$command,$value,$ban,@banned,$result);
        !           727:   $result = 0;
        !           728:   open(CAPACONFIG,"$capadir/$class/capa.config");
        !           729:   @capaconfig = <CAPACONFIG>;
        !           730:   close(CAPACONFIG);
        !           731:   foreach $line(@capaconfig) {
        !           732:     chop $line;
        !           733:     ($command,$value) = split(/\ =\ /,$line);
        !           734:     if($command eq "banned_users") { $ban = $value; last; }
        !           735:   }
        !           736:   
        !           737:   if ($debug) { print "Banned Users: ".$ban }
        !           738:   @banned = split(/\,/,$ban);
        !           739:   $snum =~ tr/a-x/A-Z/;
        !           740:   foreach $ban (@banned) {
        !           741:     if ($debug) {print $ban . "is Banned <br>";}
        !           742:     $ban =~ tr/a-z/A-Z/;
        !           743:     $ban =~ tr/\ //d;
        !           744:     if ( $ban eq $snum) { &BannedMessageHTML; $result=1 }
        !           745:   }
        !           746:   return $result
        !           747: }
        !           748: 
        !           749: sub ValidateUser {
        !           750:   local(@allcapaid,@classl,$line);
        !           751: 
        !           752:   open (CLASSL,"$capadir/$class/classl");
        !           753:     @classl = <CLASSL>;
        !           754:   close(CLASSL);
        !           755: 
        !           756:   $valid = "no";
        !           757:   foreach $line(@classl) {
        !           758:     if(substr($line,15,8) eq substr($snum,1,8)) {
        !           759:       $valid = yes;
        !           760:     }
        !           761:   }
        !           762:   if($valid eq "no") { &InvalidVarsHTML; }
        !           763: 
        !           764:   # check w/ allcapaid program
        !           765:   @allcapaid = `allcapaid -s $setid -e $setid -stu $snum -c $capadir/$class -i -checkopen`;
        !           766: 
        !           767:   chop $allcapaid[2];
        !           768:   chop $allcapaid[2];
        !           769:   if ($debug) {print "capaid:" . $allcapaid[2] . "<BR>\n";}
        !           770:   if($allcapaid[2] ne $capaid) {
        !           771:     if ($allcapaid[2] =~ /Open/) { &NotOpen; exit; }
        !           772:     if($action ne "newset") { &BadPassHTML; exit; }
        !           773:     #&NewSet;
        !           774:   }
        !           775: }
        !           776: 
        !           777: sub NotOpen {
        !           778:   &GetSetList;
        !           779:   &SetListHeader;
        !           780:   &ViewSetTitleHTML;
        !           781: print <<NotOpen2;
        !           782: This set is not yet open. Please choose a different set.
        !           783: </body>
        !           784: </html>
        !           785: NotOpen2
        !           786: }
        !           787: 
        !           788: sub UserInfo {
        !           789:   local($line,@classl,$last,$first,$middle);
        !           790: 
        !           791:   open (CLASSL,"$capadir/$class/classl");
        !           792:     @classl = <CLASSL>;
        !           793:   close(CLASSL);
        !           794: 
        !           795:   foreach $line(@classl) {
        !           796:     if(substr($line,15,8) eq substr($snum,1,8)) {
        !           797:       $username = substr($line,24,36);
        !           798:       $email    = substr($line,60,45);
        !           799:     }
        !           800:   }
        !           801:   ($last, $first, $middle) = split(/\ +/,$username);
        !           802: 
        !           803:   chop $last;
        !           804:   $username = "$first $last";
        !           805:   $email    =~ s/\ //g;
        !           806:   chop $email;
        !           807: }
        !           808: 
        !           809: sub MaxProbs {
        !           810:   open (SETRECORD,"$capadir/$class/records/set$setid.db");
        !           811:   $setrecord = <SETRECORD>;
        !           812:   close(SETRECORD);
        !           813:   chop $setrecord;
        !           814:   return $setrecord;
        !           815: }
        !           816: 
        !           817: sub ProblemJumpBox {
        !           818:   $pdprob = "<select name=\"PROBNUM\">\n";
        !           819:   for($jumpnum=1;$jumpnum<=&MaxProbs;$jumpnum++) {
        !           820:     $selected = "";
        !           821:     if($jumpnum eq $probnum) { $selected = " selected"; }
        !           822:     $pdprob .= "  <option value=$jumpnum$selected>$jumpnum\n";
        !           823:   }
        !           824:   $pdprob .= "</select>";
        !           825: }
        !           826: 
        !           827: sub SetJumpBox {
        !           828:   &GetSetList;
        !           829:   &SetListHeader;
        !           830: }
        !           831: 
        !           832: sub AddZero {
        !           833:   $string = shift(@_);
        !           834:   
        !           835:   while(length($string) < 6) {
        !           836:     $string = "0$string";
        !           837:   }
        !           838:   return $string;
        !           839: }
        !           840: 
        !           841: sub RemZero {
        !           842:   $string = shift(@_);
        !           843:   $string =~ s/^0*//g;
        !           844:   return $string;
        !           845: }
        !           846: 
        !           847: sub FormatDate {
        !           848:   $string = shift(@_);
        !           849:   
        !           850:   $month = substr($string,0,2);
        !           851:   $day   = substr($string,2,2);
        !           852:   $year  = substr($string,4,4);
        !           853: 
        !           854:   $string = "$month-$day-$year";
        !           855: 
        !           856:   return $string;
        !           857: }
        !           858: 
        !           859: ####################
        !           860: ## Get SubRoutine ##
        !           861: ####################
        !           862: sub form_info {
        !           863:   read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
        !           864: 
        !           865:   # Split the name-value pairs
        !           866:   @pairs = split(/&/, $buffer);
        !           867: 
        !           868:   foreach $pair (@pairs) {
        !           869:      ($name, $value) = split(/=/, $pair);
        !           870:      if ($name eq "message") {$allow_html=1;} else {$allow_html=0;}
        !           871:      # Un-Webify plus signs and %-encoding
        !           872:      $value =~ tr/+/ /;
        !           873:      $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
        !           874:      $value =~ s/<!--(.|\n)*-->//g;
        !           875: 
        !           876:      if ($allow_html != 1) {
        !           877:         $value =~ s/<([^>]|\n)*>//g;
        !           878:      }
        !           879:      $form{$name} = $value;
        !           880:   }
        !           881: }
        !           882: 
        !           883: ##################
        !           884: ## Date/Time sr ##
        !           885: ##################
        !           886: sub GetDateTime  {
        !           887:   ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime (time);
        !           888:   $mon++;
        !           889: 
        !           890:   $year=$year+1900;
        !           891: 
        !           892:   if ($hour < 12) {
        !           893:   $AMPM = "AM";
        !           894:   }
        !           895: 
        !           896:   if ($hour > 12) {
        !           897:   $hour = $hour - 12;
        !           898:     $AMPM = "PM";
        !           899:   }  	
        !           900:   if ($hour == 12) {
        !           901:     $AMPM = "PM";
        !           902:   }  	
        !           903: 	
        !           904:   if ($hour == 0) {
        !           905:     $hour = "12";
        !           906:   }
        !           907: 
        !           908:   $min = sprintf ("%2d", $min);
        !           909:   $min =~tr/ /0/;
        !           910:   $mon = sprintf ("%2d", $mon);
        !           911:   $mon =~tr/ /0/;
        !           912:   $mday = sprintf ("%2d", $mday);
        !           913:   $mday =~tr/ /0/;
        !           914:   $HyphenDate = ("$mon" . "-" . "$mday" . "-" . "$year");
        !           915:   $RunonDate = ("$mon$mday$year");
        !           916:   $Time = ("$hour" . ":" . "$min" . " " . "$AMPM");
        !           917: }
        !           918: 
        !           919: ########################
        !           920: ## Logging Subroutine ##
        !           921: ########################
        !           922: sub Log {
        !           923:   $logmsg = shift(@_);
        !           924:   
        !           925:   &GetDateTime;
        !           926: 
        !           927:   &Lock("lock.file");
        !           928:   open(LOG,">>$capadir/$class/discussion/logs/access.log");
        !           929:     print LOG "$snum|$capaid|$username|$email|$logmsg|$setid|$probnum|$HyphenDate|$Time|$file\n";
        !           930:   close(LOG);
        !           931:   &Unlock("lock.file");
        !           932: }
        !           933: 
        !           934: ############################
        !           935: ## Lock/Unlock Subroutine ##
        !           936: ############################
        !           937: sub Lock {
        !           938:   local ($lockname) = @_;
        !           939:   local ($endtime);
        !           940:   $endtime = 15;
        !           941:   $endtime = time + $endtime;
        !           942:   
        !           943:   while (-e $lockname && time < $endtime) {
        !           944:     open (LOCKFILE, ">$lockname");
        !           945:   }
        !           946:   
        !           947: sub Unlock {
        !           948:   local ($lockname) = @_;
        !           949:   close (LOCKFILE);
        !           950:   unlink ($lockname);
        !           951:   }
        !           952: }
        !           953: 
        !           954: 
        !           955: ######################
        !           956: ## HTML Subroutines ##
        !           957: ######################
        !           958: 
        !           959: ## CapaDiscuss HTML Subroutines
        !           960: 
        !           961: # capadiscuss_html
        !           962: 
        !           963: ## end capadiscuss

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