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