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