Annotation of loncom/interface/lonannounce.pm, revision 1.11
1.1 www 1: # The LearningOnline Network
1.2 www 2: # Announce
1.1 www 3: #
1.11 ! www 4: # $Id: lonannounce.pm,v 1.10 2003/05/21 19:15:41 www Exp $
1.1 www 5: #
1.3 www 6: # Copyright Michigan State University Board of Trustees
1.1 www 7: #
1.3 www 8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
1.1 www 9: #
1.3 www 10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
1.1 www 14: #
1.3 www 15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
1.2 www 29: package Apache::lonannounce;
1.1 www 30:
31: use strict;
32: use Apache::Constants qw(:common);
1.3 www 33: use Apache::loncommon;
1.8 matthew 34: use Apache::lonhtmlcommon();
1.3 www 35:
1.10 www 36: sub editfield {
37: my ($r,$start,$end,$text)=@_;
38: # Deal with date forms
39: my $startdateform = &Apache::lonhtmlcommon::date_setter('anno',
40: 'startdate',
41: $start);
42: my $enddateform = &Apache::lonhtmlcommon::date_setter('anno',
43: 'enddate',
44: $end);
45:
46: $r->print(<<ENDFORM);
47: <form name="anno" method="post">
48: <input type="hidden" value='' name="action" >
49: <table><tr><td>Starting date:</td><td>$startdateform</td></tr>
50: <tr><td>Ending date:</td><td>$enddateform</td></tr></table>
51: <textarea name="msg" rows="4" cols="60">$text</textarea>
52: <input type="button" onClick="trysubmit()" value="Post Announcement"><hr>
53: ENDFORM
54: }
55:
1.3 www 56: sub readcalendar {
57: my $courseid=shift;
58: my $coursenum=$ENV{'course.'.$courseid.'.num'};
59: my $coursedom=$ENV{'course.'.$courseid.'.domain'};
60: my %thiscal=&Apache::lonnet::dump('calendar',$coursedom,$coursenum);
61: my %returnhash=();
62: foreach (keys %thiscal) {
63: unless (($_=~/^error\:/) || ($thiscal{$_}=~/^error\:/)) {
64: $returnhash{$courseid.'@'.$_}=$thiscal{$_};
65: }
66: }
67: return %returnhash;
68: }
69:
70: sub emptycell {
71: return '<td bgcolor="#AAAAAA"> </td>';
72: }
73:
74: sub normalcell {
75: my ($day,$text)=@_;
1.4 www 76: my $output='';
77: foreach (split(/\_\_\_\&\&\&\_\_\_/,$text)) {
78: if ($_) {
1.5 www 79: my ($courseid,$start,$end,@msg)=split(/\@/,$_);
80: my $msg=join('@',@msg);
1.11 ! www 81: my $fullmsg=$ENV{'course.'.$courseid.'.description'}.
! 82: ', '.localtime($start).' - '.localtime($end).': '.$msg;
1.5 www 83: if ($courseid eq $ENV{'request.course.id'}) {
84: if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
85: $output.='<input type="checkbox" name="remove_'.$start.'_'.
86: $end.'">';
87: }
88: }
89: $output.='<a href="javascript:alert('."'$fullmsg'".')">'.
1.11 ! www 90: substr($msg,0,20).'...</a><br />';
1.4 www 91: }
92: }
93: return '<td><b>'.$day.'</b><br>'.$output.'</td>';
1.3 www 94: }
95:
1.11 ! www 96: sub plaincell {
! 97: my ($text)=@_;
! 98: my $output='';
! 99: foreach (split(/\_\_\_\&\&\&\_\_\_/,$text)) {
! 100: if ($_) {
! 101: my ($courseid,$start,$end,@msg)=split(/\@/,$_);
! 102: my $msg=join('@',@msg);
! 103: my $fullmsg=$ENV{'course.'.$courseid.'.description'}.
! 104: ', '.localtime($start).' - '.localtime($end).': '.$msg;
! 105: $output.='<a href="javascript:alert('."'$fullmsg'".')">'.
! 106: substr($msg,0,40).'...</a><br />';
! 107: }
! 108: }
! 109: return $output;
! 110: }
! 111:
! 112: sub listcell {
! 113: my ($text)=@_;
! 114: my $output='';
! 115: foreach (split(/\_\_\_\&\&\&\_\_\_/,$text)) {
! 116: if ($_) {
! 117: my ($courseid,$start,$end,@msg)=split(/\@/,$_);
! 118: my $msg=join('@',@msg);
! 119: my $fullmsg=localtime($start).' to '.localtime($end).':<br /><b>'.
! 120: $msg.'</b>';
! 121: $output.='<li>'.$fullmsg.'</li>';
! 122: }
! 123: }
! 124: return $output;
! 125: }
! 126:
1.3 www 127: sub nextday {
128: my %th=@_;
129: $th{'day'}++;
130: return (&Apache::loncommon::maketime(%th),$th{'month'});
131: }
132:
133: sub showday {
1.11 ! www 134: my ($tk,$mode,%allcal)=@_;
1.3 www 135: my %th=&Apache::loncommon::timehash($tk);
136: my ($nextday,$nextmonth)=&nextday(%th);
137: my $outp='';
1.4 www 138: my $oneday=24*3600;
1.3 www 139: foreach (keys %allcal) {
140: my ($course,$startdate,$enddate)=($_=~/^(\w+)\@(\d+)\_(\d+)$/);
1.4 www 141: if (($startdate<$nextday) && ($enddate>$tk)) {
1.5 www 142: $outp.='___&&&___'.$course.'@'.$startdate.'@'.$enddate.'@'.
143: $allcal{$_};
1.3 www 144: }
145: }
1.11 ! www 146: unless ($mode) {
! 147: return ($nextday,$nextmonth,&normalcell($th{'day'},$outp));
! 148: } elsif ($outp) {
! 149: if ($mode==1) {
! 150: return '<br />'.&plaincell($outp);
! 151: } else {
! 152: return '<ul>'.&listcell($outp).'</ul>';
! 153: }
! 154: } else {
! 155: return '';
! 156: }
1.3 www 157: }
1.1 www 158:
159: sub handler {
160: my $r = shift;
161: $r->content_type('text/html');
162: $r->send_http_header;
163: return OK if $r->header_only;
164:
1.3 www 165: # ---------------------------------------------------------- Get time right now
166: my $today=time;
167: my %todayhash=&Apache::loncommon::timehash($today);
168:
169: # ---------------------------------------------------------- Get month and year
170: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
171: ['month','year']);
172: # --------------------------------------------------- Decide what month to show
173: my $year=$todayhash{'year'};
174: if ($ENV{'form.year'}) { $year=$ENV{'form.year'}; }
175: my $month=$todayhash{'month'};
176: if ($ENV{'form.month'}) { $month=$ENV{'form.month'}; }
177: # --------------------------------------------- Find out first day of the month
178:
179: my %firstday=&Apache::loncommon::timehash(
180: &Apache::loncommon::maketime( 'day' => 1, 'month'=> $month,
181: 'year' => $year, 'hours' => 0,
182: 'minutes' => 0, 'seconds' => 0,
183: 'dlsav' => $todayhash{'dlsav'} ));
184: my $weekday=$firstday{'weekday'};
185: # ------------------------------------------------------------ Print the screen
1.9 www 186:
1.1 www 187: $r->print(<<ENDDOCUMENT);
188: <html>
189: <head>
190: <title>The LearningOnline Network with CAPA</title>
1.3 www 191: <script>
192:
193: function trysubmit() {
194: document.anno.action.value="new";
195: document.anno.submit();
196: }
197:
198: function removesub() {
199: document.anno.action.value="del";
200: document.anno.submit();
201: }
202: </script>
1.1 www 203: </head>
204: ENDDOCUMENT
1.6 www 205: $r->print(&Apache::loncommon::bodytag("Announcements and Calendar"));
1.3 www 206: # does this user have privileges to post, etc?
207: my $allowed=0;
208: if ($ENV{'request.course.id'}) {
209: $allowed=&Apache::lonnet::allowed('srm',$ENV{'request.course.id'});
210: }
211:
212: if ($allowed) {
213: my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
214: my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
215: # ----------------------------------------------------- Store new submitted one
216: if ($ENV{'form.action'} eq 'new') {
1.9 www 217: my $startdate =
218: &Apache::lonhtmlcommon::get_date_from_form('startdate');
219: my $enddate =
220: &Apache::lonhtmlcommon::get_date_from_form('enddate');
221: unless ($startdate=~/^\d+$/) { $startdate=time; }
222: unless ($enddate=~/^\d+$/) { $enddate=$startdate+1; }
223: if ($startdate>$enddate) {
224: my $buffer=$startdate;
225: $startdate=$enddate;
226: $enddate=$buffer;
227: }
1.3 www 228: &Apache::lonnet::put('calendar',{
1.9 www 229: $startdate.'_'.$enddate =>
1.3 www 230: $ENV{'form.msg'} },$coursedom,$coursenum);
231: }
232: # ---------------------------------------------------------------- Remove items
233: if ($ENV{'form.action'} eq 'del') {
234: my @delwhich=();
235: foreach (keys %ENV) {
236: if ($_=~/^form\.remove\_(.+)$/) {
237: push(@delwhich,$1);
238: }
239: }
240: &Apache::lonnet::del('calendar',\@delwhich,$coursedom,$coursenum);
241: }
242: # -------------------------------------------------------- Form to post new one
243: my %tomorrowhash=%todayhash;
244: $tomorrowhash{'day'}++;
245: my $tomorrow=&Apache::loncommon::maketime(%tomorrowhash);
246:
1.10 www 247: &editfield($r,$today,$tomorrow,'');
1.3 www 248: }
1.5 www 249: # ----------------------------------------------------- Summarize all calendars
250: my %allcal=();
251: foreach (&Apache::loncommon::findallcourses()) {
252: %allcal=(%allcal,&readcalendar($_));
253: }
254:
255: # ------------------------------- Initialize table and forward backward buttons
1.3 www 256: my ($pm,$py,$fm,$fy)=($month-1,$year,$month+1,$year);
257: if ($pm<1) { ($pm,$py)=(12,$year-1); }
258: if ($fm>12){ ($fm,$fy)=(1,$year+1); }
259: $r->print('<h1>'.('','January','February','March','April','May',
260: 'June','July','August','September','October',
261: 'November','December')[$month].' '.$year.'</h1>'.
262: '<a href="/adm/announcements?month='.$pm.'&year='.$py.'">Previous Month</a> '.
263: '<a href="/adm/announcements?month='.$fm.'&year='.$fy.'">Next Month</a><p>'.
264: '<table border="2" cols="7" rows="5"><tr><th>Sun</th><th>Mon</th>'.
1.7 matthew 265: '<th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th></tr>');
1.3 www 266:
267: my $tk=&Apache::loncommon::maketime(%firstday);
268: my $outp;
269: my $nm;
270:
271: # ---------------------------------------------------------------- Actual table
272: $r->print('<tr>');
273: for (my $i=0;$i<$weekday;$i++) { $r->print(&emptycell); }
274: for (my $i=$weekday;$i<=6;$i++) {
1.11 ! www 275: ($tk,$nm,$outp)=&showday($tk,0,%allcal);
1.3 www 276: $r->print($outp);
277: }
278: $r->print('</tr>');
279:
280: for (my $k=0;$k<=3;$k++) {
281: $r->print('<tr>');
282: for (my $i=0;$i<=6;$i++) {
1.11 ! www 283: ($tk,$nm,$outp)=&showday($tk,0,%allcal);
1.3 www 284: if ($month!=$nm) { $outp=&emptycell; }
285: $r->print($outp);
286: }
287: $r->print('</tr>');
288: }
289: # ------------------------------------------------------------------- End table
1.7 matthew 290: $r->print('</table>');
1.9 www 291: if ($allowed) { $r->print('<input type="button" onClick="removesub()" value="Remove Checked Entries"></form>'); }
1.7 matthew 292: $r->print('<p>'.
1.3 www 293: '<a href="/adm/announcements?month='.$pm.'&year='.$py.'">Previous Month</a> '.
294: '<a href="/adm/announcements?month='.$fm.'&year='.$fy.'">Next Month</a><p>'.
295: '</body></html>');
1.1 www 296: return OK;
297: }
298:
299: 1;
300: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>