Annotation of capa/capa51/Discuss/Ver1.3/capadiscuss, revision 1.5
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: }
1.5 ! albertel 330: # $message =~ s/</</g;
! 331: # $message =~ s/>/>/g;
1.1 albertel 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'};
1.5 ! albertel 586: $message =~ s/</</g;
! 587: $message =~ s/>/>/g;
! 588: $message =~ s/((\n\r)|(\n))\n/<p>/g;
1.1 albertel 589: $message =~ s/\n/<br>/g;
590:
591: # check if posted anonymously
592: if($form{'ANONYMOUS'} eq "yes") {
593: $username = "Anonymous|$username";
594: }
595:
596: open (MSG,">$filename");
597: print MSG "$username\n";
598: print MSG "$HyphenDate\n";
599: print MSG "$Time\n";
600: print MSG "$subject\n";
601: print MSG "$email\n";
602: print MSG "$message\n";
603: print MSG "public||||\n";
604: close(MSG);
605: }
606:
607: sub GetTeacherInfo {
608: local($capa5dir,$classname,$tdir,@classconf);
609:
610: # open/read class.conf file
611: open (CLASSCONF,"$capabin/class.conf");
612: @classconf = <CLASSCONF>;
613: close(CLASSCONF);
614:
615: $found eq "no";
616: foreach $line(@classconf) {
617: ($classname,$capa5dir,$tdir) = split(/[\t\ ]+/,$line);
618: if($classname eq $class) {
619: $teachdir = $tdir;
620: $capadir = $capa5dir;
621: $found = "yes";
622: $cgidirurl = join "/", $capasbin,$teachdir;
623: }
624: }
625: if($found eq "no") { &InvalidVarsHTML; }
626: }
627:
628: sub CheckAdmin {
629: local($asection,@adminsections,$line,@capaconfig,$command,$value,
630: $adminsection,@classl,$course,$coursenum,$section,$stunum,$a);
631:
632: $mode = shift(@_);
633:
634: if ($validadmin eq "unchecked") {
635: $validadmin = "no";
636:
637: # open 'capa.config' file (for admin section read)
638: open(CAPACONFIG,"$capadir/$class/capa.config");
639: @capaconfig = <CAPACONFIG>;
640: close(CAPACONFIG);
641: foreach $line(@capaconfig) {
642: chop $line;
643: ($command,$value) = split(/\ =\ /,$line);
644: if($command eq "admin_section") {
645: $adminsection = $value;
646: last;
647: }
648: }
649: @adminsections = split(/\,/,$adminsection);
650: for ($asection=0; $asection <= $#adminsections; $asection++) {
651: $adminsections[$asection]=&RemZero($adminsections[$asection])
652: }
653: # open 'classl' file
654: open(CLASSL,"$capadir/$class/classl");
655: @classl = <CLASSL>;
656: close(CLASSL);
657:
658: $snum =~ tr/a-z/A-Z/;
659: LINE: foreach $line(@classl) {
660: ($course,$coursenum,$section,$stunum,$a) = split(/\ +/,$line);
661: $stunum =~ tr/a-z/A-Z/;
662: if ( $stunum ne $snum ) { next LINE;}
663: $section = &RemZero($section);
664: foreach $asection(@adminsections) {
665: if($section eq $asection ) {
666: $validadmin = "yes";
667: last LINE;
668: }
669: }
670: }
671: }
672: if($validadmin eq "no" && $mode eq "kill") { &NotAdminHTML; }
673: }
674:
675: sub ValidateUser {
676: local(@allcapaid,@classl,$line);
677:
678: open (CLASSL,"$capadir/$class/classl");
679: @classl = <CLASSL>;
680: close(CLASSL);
681:
682: $valid = "no";
683: foreach $line(@classl) {
684: if(substr($line,15,8) eq substr($snum,1,8)) {
685: $valid = yes;
686: }
687: }
688: if($valid eq "no") { &InvalidVarsHTML; }
689:
690: # check w/ allcapaid program
1.2 albertel 691: @allcapaid = `allcapaid51 -s $setid -e $setid -stu $snum -c $capadir/$class -i -checkopen`;
1.1 albertel 692:
693: chop $allcapaid[2];
694: chop $allcapaid[2];
1.2 albertel 695: if ($debug) {print "capaid:" . $allcapaid[2] . "<BR>\n";}
1.1 albertel 696: if($allcapaid[2] ne $capaid) {
1.2 albertel 697: if ($allcapaid[2] =~ /Open/) { &NotOpen; exit; }
698: if($action ne "newset") { &BadPassHTML; exit; }
1.1 albertel 699: #&NewSet;
700: }
1.2 albertel 701: }
702:
703: sub NotOpen {
704: &GetSetList;
705: &SetListHeader;
706: &ViewSetTitleHTML;
707: print <<NotOpen2;
708: This set is not yet open. Please choose a different set.
709: </body>
710: </html>
711: NotOpen2
1.1 albertel 712: }
713:
714: sub UserInfo {
715: local($line,@classl,$last,$first,$middle);
716:
717: open (CLASSL,"$capadir/$class/classl");
718: @classl = <CLASSL>;
719: close(CLASSL);
720:
721: foreach $line(@classl) {
722: if(substr($line,15,8) eq substr($snum,1,8)) {
723: $username = substr($line,24,36);
724: $email = substr($line,60,45);
725: }
726: }
727: ($last, $first, $middle) = split(/\ +/,$username);
728:
729: chop $last;
730: $username = "$first $last";
731: $email =~ s/\ //g;
732: chop $email;
733: }
734:
735: sub MaxProbs {
736: open (SETRECORD,"$capadir/$class/records/set$setid.db");
737: $setrecord = <SETRECORD>;
738: close(SETRECORD);
739: chop $setrecord;
740: return $setrecord;
741: }
742:
743: sub ProblemJumpBox {
744: $pdprob = "<select name=\"PROBNUM\">\n";
745: for($jumpnum=1;$jumpnum<=&MaxProbs;$jumpnum++) {
746: $selected = "";
747: if($jumpnum eq $probnum) { $selected = " selected"; }
748: $pdprob .= " <option value=$jumpnum$selected>$jumpnum\n";
749: }
750: $pdprob .= "</select>";
751: }
752:
753: sub SetJumpBox {
1.3 albertel 754: &GetSetList;
755: &SetListHeader;
1.1 albertel 756: }
757:
758: sub AddZero {
759: $string = shift(@_);
760:
761: while(length($string) < 6) {
762: $string = "0$string";
763: }
764: return $string;
765: }
766:
767: sub RemZero {
768: $string = shift(@_);
769: $string =~ s/^0*//g;
770: return $string;
771: }
772:
773: sub FormatDate {
774: $string = shift(@_);
775:
776: $month = substr($string,0,2);
777: $day = substr($string,2,2);
778: $year = substr($string,4,4);
779:
780: $string = "$month-$day-$year";
781:
782: return $string;
783: }
784:
785: ####################
786: ## Get SubRoutine ##
787: ####################
788: sub form_info {
789: read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
790:
791: # Split the name-value pairs
792: @pairs = split(/&/, $buffer);
793:
794: foreach $pair (@pairs) {
795: ($name, $value) = split(/=/, $pair);
796:
797: # Un-Webify plus signs and %-encoding
798: $value =~ tr/+/ /;
799: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
800: $value =~ s/<!--(.|\n)*-->//g;
801:
802: if ($allow_html != 1) {
803: $value =~ s/<([^>]|\n)*>//g;
804: }
805: $form{$name} = $value;
806: }
807: }
808:
809: ##################
810: ## Date/Time sr ##
811: ##################
812: sub GetDateTime {
813: ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime (time);
814: $mon++;
815:
816: if ($hour < 12) {
817: $AMPM = "AM";
818: }
819:
820: if ($hour > 12) {
821: $hour = $hour - 12;
822: $AMPM = "PM";
823: }
824: if ($hour == 12) {
825: $AMPM = "PM";
826: }
827:
828: if ($hour == 0) {
829: $hour = "12";
830: }
831:
832: $min = sprintf ("%2d", $min);
833: $min =~tr/ /0/;
834: $mon = sprintf ("%2d", $mon);
835: $mon =~tr/ /0/;
836: $mday = sprintf ("%2d", $mday);
837: $mday =~tr/ /0/;
838: $HyphenDate = ("$mon" . "-" . "$mday" . "-" . "$year");
839: $RunonDate = ("$mon$mday$year");
840: $Time = ("$hour" . ":" . "$min" . " " . "$AMPM");
841: }
842:
843: ########################
844: ## Logging Subroutine ##
845: ########################
846: sub Log {
847: $logmsg = shift(@_);
848:
849: &GetDateTime;
850:
851: &Lock("lock.file");
852: open(LOG,">>$capadir/$class/discussion/logs/access.log");
1.4 albertel 853: print LOG "$snum|$capaid|$username|$email|$logmsg|$setid|$probnum|$HyphenDate|$Time|$file\n";
1.1 albertel 854: close(LOG);
855: &Unlock("lock.file");
856: }
857:
858: ############################
859: ## Lock/Unlock Subroutine ##
860: ############################
861: sub Lock {
862: local ($lockname) = @_;
863: local ($endtime);
864: $endtime = 15;
865: $endtime = time + $endtime;
866:
867: while (-e $lockname && time < $endtime) {
868: open (LOCKFILE, ">$lockname");
869: }
870:
871: sub Unlock {
872: local ($lockname) = @_;
873: close (LOCKFILE);
874: unlink ($lockname);
875: }
876: }
877:
878:
879: ######################
880: ## HTML Subroutines ##
881: ######################
882:
883: ## CapaDiscuss HTML Subroutines
884:
885: # capadiscuss_html
886:
887: ## end capadiscuss
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>