Annotation of capa/capa51/Discuss/Ver1.3/capadiscuss, revision 1.2

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

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