Annotation of capa/capa51/Discuss/Ver1.3/capadiscuss, revision 1.4
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/</</g;
331: $message =~ s/>/>/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.4 ! albertel 352: &Log("InfoFile");
1.3 albertel 353: open(INFOFILE,"$capadir/$class/discussion/$file");
1.1 albertel 354: @file = <INFOFILE>;
355: closedir(INFOFILE);
356:
357: print "<html><head></head><body bgcolor=\"#ffffff\">";
358: $backfunction = $form{'BACKFUNCTION'};
359: &InfoBackButtonHTML;
360: foreach $line(@file) {
361: print "$line";
362: }
363:
364: #exit;
365: }
366:
367: sub Post {
368: local(@msgs,$pn,$msg);
369:
370: # grab last message in thread
371: opendir(MSGS,"$capadir/$class/discussion/$setid");
372: @msgs = grep(/.msg/,sort(readdir(MSGS)));
373: closedir(MSGS);
374:
375: foreach $msg(@msgs) {
376: $pn = &RemZero(substr($msg,0,6));
377: if($pn eq $probnum) {
378: $lastfile = $msg;
379: }
380: }
381:
382: $PostType = "New Message";
383: if($lastfile ne "") {
384: &OpenMsg("$capadir/$class/discussion/$setid/$lastfile");
385: if($status eq "public" || $validadmin eq "yes") {
386: ($poster,$rposter) = split(/\|/,$poster);
387: $inreplyto = &InReplyToHTML;
388: $PostType = "Reply";
389: }
390: }
391:
392: &PostHTML;
393: #exit;
394: }
395:
396: sub PostSubmit {
397: local($message,$subject,$date);
398:
399: $message = $form{'message'};
400: $subject = $form{'subject'};
401:
402: if($message eq "" || $subject eq "") { &MFPostReplyHTML; }
403:
404: &Log("Post");
405:
406: # find last message in thread
407: opendir(FORUM,"$capadir/$class/discussion/$setid");
408: @dir = sort(readdir(FORUM));
409: closedir(FORUM);
410:
411: $probnum = &AddZero($probnum);
412: $replynum = "000000";
413: foreach $msg(@dir) {
414: if(substr($msg,0,6) eq $probnum) {
415: $replynum = &AddZero(&RemZero(substr($msg,7,6)) + 1);
416: }
417: }
418:
419: $date = substr($RunonDate,0,4) . $yp . substr($RunonDate,4,2);
420: &WriteMsg("$capadir/$class/discussion/$setid/$probnum-$replynum-$date-000000.msg");
421:
422: $probnum = &RemZero($probnum);
423: &PostDoneHTML;
424: #exit;
425: }
426:
427: sub DelMsgPre {
428: &CheckAdmin('kill');
429: &OpenMsg("$capadir/$class/discussion/$setid/$file");
430: &DelMsgPreHTML;
431: #exit;
432: }
433:
434: sub DelMsg {
435: &CheckAdmin('kill');
436: unlink("$capadir/$class/discussion/$setid/$file");
437: &DelMsgDoneHTML;
438: #exit;
439: }
440:
441: sub HideMsgPre {
442: &CheckAdmin('kill');
443: &OpenMsg("$capadir/$class/discussion/$setid/$file");
444: &HideMsgPreHTML;
445: #exit;
446: }
447:
448: sub HideMsg {
449: &CheckAdmin('kill');
450: open(MSG,"$capadir/$class/discussion/$setid/$file");
451: @msg = <MSG>;
452: close(MSG);
453:
454: unlink("$capadir/$class/discussion/$setid/$file");
455:
456: open(MSG,">$capadir/$class/discussion/$setid/$file");
457: for($i=0;$i<=5;$i++) {
458: print MSG "$msg[$i]";
459: }
460: print MSG "hidden|$username|$HyphenDate|$Time|$ENV{'REMOTE_ADDR'}\n";
461: close(MSG);
462:
463: &HideMsgDoneHTML;
464: }
465:
466: sub UnHideMsgPre {
467: &CheckAdmin('kill');
468: &OpenMsg("$capadir/$class/discussion/$setid/$file");
469: &UnHideMsgPreHTML;
470: #exit;
471: }
472:
473: sub UnHideMsg {
474: &CheckAdmin('kill');
475: open(MSG,"$capadir/$class/discussion/$setid/$file");
476: @msg = <MSG>;
477: close(MSG);
478:
479: unlink("$capadir/$class/discussion/$setid/$file");
480:
481: open(MSG,">$capadir/$class/discussion/$setid/$file");
482: for($i=0;$i<=5;$i++) {
483: print MSG "$msg[$i]";
484: }
485: print MSG "public||||}\n";
486: close(MSG);
487:
488: &UnHideMsgDoneHTML;
489: }
490:
491:
492: sub TopMsg {
493: &CheckAdmin('kill');
494:
495: $ext = shift(@_);
496:
497: open(MSG,"$capadir/$class/discussion/$setid/$file");
498: @msg = <MSG>;
499: close(MSG);
500:
501: unlink("$capadir/$class/discussion/$setid/$file");
502:
503: ($filename, $extension) = split(/\./,$file);
504: $filename = "$filename-$ext.msg";
505: open(MSG,">$capadir/$class/discussion/$setid/$filename");
506: for($i=0;$i<=6;$i++) {
507: print MSG "$msg[$i]";
508: }
509: close(MSG);
510:
511: if($ext eq "") {
512: $function = "restored to its original position in the thread.";
513: }
514: else {
515: $function = "moved to the top of the thread list.";
516: }
517:
518: &TopMsgDoneHTML;
519: }
520:
521: ###############################
522: ## Administrator Subroutines ##
523: ###############################
524:
525: sub AdminMain {
526: &CheckAdmin('kill');
527: &AdminMainHTML;
528: #exit;
529: }
530:
531:
532: sub AdminUserSearch {
533: &CheckAdmin('kill');
534: &AdminUserSearchHTML;
535: #exit;
536: }
537:
538:
539: sub AdminUserSearchSubmit {
540: local($sname,$semail,$saction,$sset,$sprob,$sdate,$stime);
541: &CheckAdmin('kill');
542:
543: $query = $form{'usersearch'};
544: open(LOG,"$capadir/$class/discussion/logs/access.log");
545: @log = <LOG>;
546: close(LOG);
547:
548: @linematches = grep /$query/, @log;
549:
550: foreach $line(@linematches) { print $line; }
551:
552: #exit;
553: }
554:
555: ######################
556: ## Misc Subroutines ##
557: ######################
558:
559: sub OpenMsg {
560: local($filename,$statusl);
561:
562: $filename = shift(@_);
563:
564: open (MSG,"$filename");
565: @msg = <MSG>;
566: close(MSG);
567:
568: $poster = $msg[0];
569: $date = $msg[1];
570: $time = $msg[2];
571: $subject = $msg[3];
572: $email = $msg[4];
573: $message = $msg[5];
574: $statusl = $msg[6];
575:
576: ($status, $hiddenuser, $hiddendate, $hiddentime, $hiddenaddr) = split(/\|/,$statusl);
577: }
578:
579: sub WriteMsg {
580: local($filename,$message);
581:
582: $filename = shift(@_);
583: # add sr to grab e-mail address of user
584:
585: $message = $form{'message'};
586: $message =~ s/\n\r\n/<p>/g;
587: $message =~ s/\n/<br>/g;
588:
589: # check if posted anonymously
590: if($form{'ANONYMOUS'} eq "yes") {
591: $username = "Anonymous|$username";
592: }
593:
594: open (MSG,">$filename");
595: print MSG "$username\n";
596: print MSG "$HyphenDate\n";
597: print MSG "$Time\n";
598: print MSG "$subject\n";
599: print MSG "$email\n";
600: print MSG "$message\n";
601: print MSG "public||||\n";
602: close(MSG);
603: }
604:
605: sub GetTeacherInfo {
606: local($capa5dir,$classname,$tdir,@classconf);
607:
608: # open/read class.conf file
609: open (CLASSCONF,"$capabin/class.conf");
610: @classconf = <CLASSCONF>;
611: close(CLASSCONF);
612:
613: $found eq "no";
614: foreach $line(@classconf) {
615: ($classname,$capa5dir,$tdir) = split(/[\t\ ]+/,$line);
616: if($classname eq $class) {
617: $teachdir = $tdir;
618: $capadir = $capa5dir;
619: $found = "yes";
620: $cgidirurl = join "/", $capasbin,$teachdir;
621: }
622: }
623: if($found eq "no") { &InvalidVarsHTML; }
624: }
625:
626: sub CheckAdmin {
627: local($asection,@adminsections,$line,@capaconfig,$command,$value,
628: $adminsection,@classl,$course,$coursenum,$section,$stunum,$a);
629:
630: $mode = shift(@_);
631:
632: if ($validadmin eq "unchecked") {
633: $validadmin = "no";
634:
635: # open 'capa.config' file (for admin section read)
636: open(CAPACONFIG,"$capadir/$class/capa.config");
637: @capaconfig = <CAPACONFIG>;
638: close(CAPACONFIG);
639: foreach $line(@capaconfig) {
640: chop $line;
641: ($command,$value) = split(/\ =\ /,$line);
642: if($command eq "admin_section") {
643: $adminsection = $value;
644: last;
645: }
646: }
647: @adminsections = split(/\,/,$adminsection);
648: for ($asection=0; $asection <= $#adminsections; $asection++) {
649: $adminsections[$asection]=&RemZero($adminsections[$asection])
650: }
651: # open 'classl' file
652: open(CLASSL,"$capadir/$class/classl");
653: @classl = <CLASSL>;
654: close(CLASSL);
655:
656: $snum =~ tr/a-z/A-Z/;
657: LINE: foreach $line(@classl) {
658: ($course,$coursenum,$section,$stunum,$a) = split(/\ +/,$line);
659: $stunum =~ tr/a-z/A-Z/;
660: if ( $stunum ne $snum ) { next LINE;}
661: $section = &RemZero($section);
662: foreach $asection(@adminsections) {
663: if($section eq $asection ) {
664: $validadmin = "yes";
665: last LINE;
666: }
667: }
668: }
669: }
670: if($validadmin eq "no" && $mode eq "kill") { &NotAdminHTML; }
671: }
672:
673: sub ValidateUser {
674: local(@allcapaid,@classl,$line);
675:
676: open (CLASSL,"$capadir/$class/classl");
677: @classl = <CLASSL>;
678: close(CLASSL);
679:
680: $valid = "no";
681: foreach $line(@classl) {
682: if(substr($line,15,8) eq substr($snum,1,8)) {
683: $valid = yes;
684: }
685: }
686: if($valid eq "no") { &InvalidVarsHTML; }
687:
688: # check w/ allcapaid program
1.2 albertel 689: @allcapaid = `allcapaid51 -s $setid -e $setid -stu $snum -c $capadir/$class -i -checkopen`;
1.1 albertel 690:
691: chop $allcapaid[2];
692: chop $allcapaid[2];
1.2 albertel 693: if ($debug) {print "capaid:" . $allcapaid[2] . "<BR>\n";}
1.1 albertel 694: if($allcapaid[2] ne $capaid) {
1.2 albertel 695: if ($allcapaid[2] =~ /Open/) { &NotOpen; exit; }
696: if($action ne "newset") { &BadPassHTML; exit; }
1.1 albertel 697: #&NewSet;
698: }
1.2 albertel 699: }
700:
701: sub NotOpen {
702: &GetSetList;
703: &SetListHeader;
704: &ViewSetTitleHTML;
705: print <<NotOpen2;
706: This set is not yet open. Please choose a different set.
707: </body>
708: </html>
709: NotOpen2
1.1 albertel 710: }
711:
712: sub UserInfo {
713: local($line,@classl,$last,$first,$middle);
714:
715: open (CLASSL,"$capadir/$class/classl");
716: @classl = <CLASSL>;
717: close(CLASSL);
718:
719: foreach $line(@classl) {
720: if(substr($line,15,8) eq substr($snum,1,8)) {
721: $username = substr($line,24,36);
722: $email = substr($line,60,45);
723: }
724: }
725: ($last, $first, $middle) = split(/\ +/,$username);
726:
727: chop $last;
728: $username = "$first $last";
729: $email =~ s/\ //g;
730: chop $email;
731: }
732:
733: sub MaxProbs {
734: open (SETRECORD,"$capadir/$class/records/set$setid.db");
735: $setrecord = <SETRECORD>;
736: close(SETRECORD);
737: chop $setrecord;
738: return $setrecord;
739: }
740:
741: sub ProblemJumpBox {
742: $pdprob = "<select name=\"PROBNUM\">\n";
743: for($jumpnum=1;$jumpnum<=&MaxProbs;$jumpnum++) {
744: $selected = "";
745: if($jumpnum eq $probnum) { $selected = " selected"; }
746: $pdprob .= " <option value=$jumpnum$selected>$jumpnum\n";
747: }
748: $pdprob .= "</select>";
749: }
750:
751: sub SetJumpBox {
1.3 albertel 752: &GetSetList;
753: &SetListHeader;
1.1 albertel 754: }
755:
756: sub AddZero {
757: $string = shift(@_);
758:
759: while(length($string) < 6) {
760: $string = "0$string";
761: }
762: return $string;
763: }
764:
765: sub RemZero {
766: $string = shift(@_);
767: $string =~ s/^0*//g;
768: return $string;
769: }
770:
771: sub FormatDate {
772: $string = shift(@_);
773:
774: $month = substr($string,0,2);
775: $day = substr($string,2,2);
776: $year = substr($string,4,4);
777:
778: $string = "$month-$day-$year";
779:
780: return $string;
781: }
782:
783: ####################
784: ## Get SubRoutine ##
785: ####################
786: sub form_info {
787: read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
788:
789: # Split the name-value pairs
790: @pairs = split(/&/, $buffer);
791:
792: foreach $pair (@pairs) {
793: ($name, $value) = split(/=/, $pair);
794:
795: # Un-Webify plus signs and %-encoding
796: $value =~ tr/+/ /;
797: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
798: $value =~ s/<!--(.|\n)*-->//g;
799:
800: if ($allow_html != 1) {
801: $value =~ s/<([^>]|\n)*>//g;
802: }
803: $form{$name} = $value;
804: }
805: }
806:
807: ##################
808: ## Date/Time sr ##
809: ##################
810: sub GetDateTime {
811: ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime (time);
812: $mon++;
813:
814: if ($hour < 12) {
815: $AMPM = "AM";
816: }
817:
818: if ($hour > 12) {
819: $hour = $hour - 12;
820: $AMPM = "PM";
821: }
822: if ($hour == 12) {
823: $AMPM = "PM";
824: }
825:
826: if ($hour == 0) {
827: $hour = "12";
828: }
829:
830: $min = sprintf ("%2d", $min);
831: $min =~tr/ /0/;
832: $mon = sprintf ("%2d", $mon);
833: $mon =~tr/ /0/;
834: $mday = sprintf ("%2d", $mday);
835: $mday =~tr/ /0/;
836: $HyphenDate = ("$mon" . "-" . "$mday" . "-" . "$year");
837: $RunonDate = ("$mon$mday$year");
838: $Time = ("$hour" . ":" . "$min" . " " . "$AMPM");
839: }
840:
841: ########################
842: ## Logging Subroutine ##
843: ########################
844: sub Log {
845: $logmsg = shift(@_);
846:
847: &GetDateTime;
848:
849: &Lock("lock.file");
850: open(LOG,">>$capadir/$class/discussion/logs/access.log");
1.4 ! albertel 851: print LOG "$snum|$capaid|$username|$email|$logmsg|$setid|$probnum|$HyphenDate|$Time|$file\n";
1.1 albertel 852: close(LOG);
853: &Unlock("lock.file");
854: }
855:
856: ############################
857: ## Lock/Unlock Subroutine ##
858: ############################
859: sub Lock {
860: local ($lockname) = @_;
861: local ($endtime);
862: $endtime = 15;
863: $endtime = time + $endtime;
864:
865: while (-e $lockname && time < $endtime) {
866: open (LOCKFILE, ">$lockname");
867: }
868:
869: sub Unlock {
870: local ($lockname) = @_;
871: close (LOCKFILE);
872: unlink ($lockname);
873: }
874: }
875:
876:
877: ######################
878: ## HTML Subroutines ##
879: ######################
880:
881: ## CapaDiscuss HTML Subroutines
882:
883: # capadiscuss_html
884:
885: ## end capadiscuss
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>