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