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

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

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