Annotation of loncom/interface/lonannounce.pm, revision 1.58
1.1 www 1: # The LearningOnline Network
1.2 www 2: # Announce
1.1 www 3: #
1.58 ! albertel 4: # $Id: lonannounce.pm,v 1.57 2006/06/29 16:44:49 albertel 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.20 www 35: use Apache::lonlocal;
1.43 albertel 36: use Apache::lonnavmaps();
1.36 www 37: use Apache::lonrss();
1.34 albertel 38: use Apache::lonnet;
1.15 www 39: use HTML::Entities();
1.3 www 40:
1.12 www 41: my %todayhash;
1.16 www 42: my %showedcheck;
1.12 www 43:
1.10 www 44: sub editfield {
45: my ($r,$start,$end,$text)=@_;
46: # Deal with date forms
47: my $startdateform = &Apache::lonhtmlcommon::date_setter('anno',
48: 'startdate',
49: $start);
50: my $enddateform = &Apache::lonhtmlcommon::date_setter('anno',
51: 'enddate',
52: $end);
1.55 albertel 53: my $help=&Apache::loncommon::help_open_menu('Calendar Add Announcement','Calendar_Add_Announcement',274,'Communication Tools');
1.36 www 54: my %lt=&Apache::lonlocal::texthash('post' => 'Post Announcement',
55: 'start' => 'Starting date',
56: 'end' => 'Ending date',
1.37 www 57: 'incrss' => 'Include in course RSS newsfeed');
1.36 www 58:
1.10 www 59: $r->print(<<ENDFORM);
1.25 www 60: $help
1.10 www 61: <form name="anno" method="post">
1.36 www 62: <input type="hidden" value='' name="action" />
63: <table><tr><td>$lt{'start'}:</td><td>$startdateform</td></tr>
64: <tr><td>$lt{'end'}:</td><td>$enddateform</td></tr></table>
1.10 www 65: <textarea name="msg" rows="4" cols="60">$text</textarea>
1.36 www 66: <br />
1.46 albertel 67: <label><input type="checkbox" name="rsspost" /> $lt{'incrss'}</label>
1.36 www 68: <br /><input type="button" onClick="trysubmit()" value="$lt{'post'}" /><hr />
1.10 www 69: ENDFORM
70: }
71:
1.3 www 72: sub readcalendar {
73: my $courseid=shift;
1.34 albertel 74: my $coursenum=$env{'course.'.$courseid.'.num'};
75: my $coursedom=$env{'course.'.$courseid.'.domain'};
1.3 www 76: my %thiscal=&Apache::lonnet::dump('calendar',$coursedom,$coursenum);
77: my %returnhash=();
1.42 albertel 78: foreach my $item (keys(%thiscal)) {
79: unless (($item=~/^error\:/) || ($thiscal{$item}=~/^error\:/)) {
80: $returnhash{$courseid.'@'.$item}=$thiscal{$item};
1.3 www 81: }
82: }
1.43 albertel 83:
1.58 ! albertel 84: return %returnhash if ($courseid ne $env{'request.course.id'});
! 85:
1.53 www 86: my $can_see_hidden = $env{'request.role.adv'};
1.54 albertel 87: my $navmap;# = Apache::lonnavmaps::navmap->new();
1.53 www 88: my %resourcedata=
89: &Apache::lonnet::dump('resourcedata',$coursedom,$coursenum);
90: foreach my $thiskey (sort keys %resourcedata) {
91: if ($resourcedata{$thiskey.'.type'}=~/^date/) {
92: my ($course,$middle,$part,$name)=
93: ($thiskey=~/^(\w+)\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/);
1.56 albertel 94: my %data = ( 'section' => &mt('All Students'));
1.53 www 95: if ($middle=~/^\[(.*)\]\./) {
96: my $sec=$1;
97: # if we have a section don't show ones that aren't ours
98: if ($env{'request.course.sec'} &&
99: $env{'request.course.sec'} ne $sec) { next; }
100: # if a student without a section don't show any section ones
101: if (!$env{'request.role.adv'} &&
102: !$env{'request.course.sec'}) { next; }
1.56 albertel 103: $data{'section'}=&mt('Group/Section').': '.$1;
1.53 www 104: $middle=~s/^\[(.*)\]\.//;
105: }
106: $middle=~s/\.$//;
1.56 albertel 107: $data{'realm'}=&mt('All Resources');
1.53 www 108: if ($middle eq '___(all)') {
109: if (!$can_see_hidden && !$navmap) {
110: next;
111: }
112: } elsif ($middle=~/^(.+)\_\_\_\(all\)$/) {
113: my $map_url=$1;
114: if (!$can_see_hidden && !$navmap) {
115: next;
116: }
117: if (!$can_see_hidden) {
118: my $res = $navmap->getResourceByUrl($map_url);
119: if ($res && $res->randomout()) { next; }
1.26 www 120: }
1.56 albertel 121: $data{'realm'}=&mt('Folder/Map');
122: $data{'url'} = $map_url;
1.53 www 123: } elsif ($middle) {
124: if (!$can_see_hidden && !$navmap) {
125: next;
1.26 www 126: }
1.53 www 127: if (!$can_see_hidden) {
128: my $res = $navmap->getBySymb($middle);
129: if ($res && $res->randomout()) { next; }
130: }
1.56 albertel 131: $data{'realm'} = &mt('Resource');
132: $data{'symb'} = $middle;
1.53 www 133: }
1.56 albertel 134: $data{'datetype'} = $name;
1.53 www 135: if ($name eq 'duedate') {
1.56 albertel 136: $data{'datetype'} = &mt('Due');
1.28 www 137: # see if accidentally answerdate is before duedate
1.53 www 138: my $answerkey=$thiskey;
139: $answerkey=~s/duedate$/answerdate/;
140: if ($resourcedata{$thiskey}>$resourcedata{$answerkey}) {
1.56 albertel 141: $data{'datetype'} = &mt('Due and Answer Available');
1.28 www 142: }
1.53 www 143: }
1.56 albertel 144: if ($name eq 'opendate'
145: || $name eq 'contentopen' ) {
146: $data{'datetype'}=&mt('Opening');
147: }
148: if ($name eq 'contentclose') {
149: $data{'datetype'}=&mt('Closing');
150: }
1.53 www 151: if ($name eq 'answerdate') {
1.28 www 152: # see if accidentally answerdate is before duedate
1.53 www 153: my $duekey=$thiskey;
154: $duekey=~s/answerdate$/duedate/;
155: if ($resourcedata{$duekey}>$resourcedata{$thiskey}) {
1.28 www 156: # forget it
1.53 www 157: next;
158: }
1.56 albertel 159: $data{'datetype'}=&mt('Answer Available');
1.53 www 160: }
161: $returnhash{$courseid.'@'.$resourcedata{$thiskey}.'_'.
1.56 albertel 162: $resourcedata{$thiskey}}=\%data;
1.26 www 163: }
164: }
1.3 www 165: return %returnhash;
166: }
167:
168: sub emptycell {
1.49 albertel 169: return '<td class="LC_calendar_day_empty"> </td>';
1.3 www 170: }
171:
172: sub normalcell {
1.56 albertel 173: my ($day,$month,$year,$items_ref)=@_;
1.51 albertel 174: my $output;
1.56 albertel 175: my @items=&order($items_ref);
1.40 albertel 176: foreach my $item (@items) {
177: if ($item) {
1.56 albertel 178: my ($courseid,$start,$end,$msg)=@$item;
179: my $internalflag= (ref($msg)) ? 1 : 0;
180: $msg = &display_msg($msg);
1.34 albertel 181: my $fullmsg=&mt('Calendar Announcement for ').$env{'course.'.$courseid.'.description'}.
1.32 www 182: '\n'.&Apache::lonlocal::locallocaltime($start);
1.26 www 183: if ($start!=$end) {
184: $fullmsg.=' - '.&Apache::lonlocal::locallocaltime($end);
185: }
1.32 www 186: $fullmsg.=':\n'.$msg;
1.56 albertel 187: $fullmsg=~s/[\n\r]/\\n/gs;
188: $fullmsg=&HTML::Entities::encode($fullmsg,'<>&"\'');
189: $fullmsg=~s/&/\\&/g;
190: my $short_msg = substr($msg,0,20).((length($msg) > 20)?'...':'');
191: if (defined($output)) { $output.='<br />'; }
1.34 albertel 192: if ($courseid eq $env{'request.course.id'}) {
193: if ((&Apache::lonnet::allowed('srm',$env{'request.course.id'}))
1.19 www 194: && (!$showedcheck{$start.'_'.$end})
1.34 albertel 195: && ($env{'form.pickdate'} ne 'yes')
1.26 www 196: && (!$internalflag)) {
1.5 www 197: $output.='<input type="checkbox" name="remove_'.$start.'_'.
198: $end.'">';
1.16 www 199: $showedcheck{$start.'_'.$end}=1;
1.5 www 200: }
201: }
202: $output.='<a href="javascript:alert('."'$fullmsg'".')">'.
1.51 albertel 203: $short_msg.'</a>';
1.4 www 204: }
205: }
1.49 albertel 206: return '<td class="LC_calendar_day'.
1.12 www 207: ((($day eq $todayhash{'day'}) &&
208: ($month eq $todayhash{'month'}) &&
1.49 albertel 209: ($year eq $todayhash{'year'}))?'_current':'').
210: '" ><b>'.&picklink($day,$day,$month,$year).'</b><br />'.$output.'</td>';
1.3 www 211: }
212:
1.11 www 213: sub plaincell {
1.56 albertel 214: my ($items_ref)=@_;
1.51 albertel 215: my $output;
1.56 albertel 216: my @items=&order($items_ref);
1.40 albertel 217: foreach my $item (@items) {
1.56 albertel 218: if (ref($item)) {
219: my ($courseid,$start,$end,$msg)=@$item;
1.34 albertel 220: my $fullmsg=&mt('Calendar Announcement for ').$env{'course.'.$courseid.'.description'}.
1.32 www 221: '\n'.&Apache::lonlocal::locallocaltime($start);
1.26 www 222: if ($start!=$end) {
223: $fullmsg.=' - '.&Apache::lonlocal::locallocaltime($end);
224: }
1.56 albertel 225: $msg = &display_msg($msg);
1.32 www 226: $fullmsg.=':\n'.$msg;
227: $fullmsg=~s/[\n\r]/\\n/gs;
1.15 www 228: $fullmsg=&HTML::Entities::encode($fullmsg,'<>&"\'');
229: $fullmsg=~s/&/\\&/g;
1.51 albertel 230: my $short_msg = substr($msg,0,80).((length($msg) > 80)?'...':'');
231: if (defined($output)) { $output.='<br />'; }
1.11 www 232: $output.='<a href="javascript:alert('."'$fullmsg'".')">'.
1.51 albertel 233: $short_msg.'</a>';
1.11 www 234: }
235: }
236: return $output;
237: }
238:
239: sub listcell {
1.56 albertel 240: my ($items_ref)=@_;
1.11 www 241: my $output='';
1.56 albertel 242: my @items=&order($items_ref);
1.40 albertel 243: foreach my $item (@items) {
1.56 albertel 244: if (ref($item)) {
245: my ($courseid,$start,$end,$msg)=@$item;
246: my $fullmsg=&Apache::lonlocal::locallocaltime($start);
1.26 www 247: if ($start!=$end) {
248: $fullmsg.=&mt(' to ').
249: &Apache::lonlocal::locallocaltime($end);
250: }
1.56 albertel 251: $fullmsg.=':<br /><b>'.&display_msg($msg).'</b>';
1.11 www 252: $output.='<li>'.$fullmsg.'</li>';
253: }
254: }
255: return $output;
256: }
257:
1.40 albertel 258: sub order {
1.56 albertel 259: my ($items)=@_;
260: return sort {
261: my ($astart,$aend)=$a->[1,2];
262: my ($bstart,$bend)=$b->[1,2];
1.40 albertel 263: if ($astart != $bstart) {
264: return $astart <=> $bstart;
265: }
266: return $aend <=> $bend;
1.56 albertel 267: } @$items;
1.40 albertel 268: }
269:
1.3 www 270: sub nextday {
271: my %th=@_;
272: $th{'day'}++;
273: return (&Apache::loncommon::maketime(%th),$th{'month'});
274: }
275:
1.56 albertel 276: sub display_msg {
277: my ($msg) = @_;
278:
279: # if it's not a ref, it's an instructor provided message
280: return $msg if (!ref($msg));
281:
282: my $output = $msg->{'datetype'}. ': '.$msg->{'realm'};
283: if (exists($msg->{'url'})) {
284: $output .= ': '.&Apache::lonnet::gettitle($msg->{'url'});
285: }
286: if (exists($msg->{'symb'})) {
287: $output .= ': '.&Apache::lonnet::gettitle($msg->{'symb'});
288: }
289: $output .= ' ('.$msg->{'section'}.') ';
290: return $output;
291: }
292:
1.3 www 293: sub showday {
1.11 www 294: my ($tk,$mode,%allcal)=@_;
1.3 www 295: my %th=&Apache::loncommon::timehash($tk);
296: my ($nextday,$nextmonth)=&nextday(%th);
1.56 albertel 297: my @outp;
1.27 www 298: if ($mode) {
299: my $oneday=24*3600;
300: $tk-=$oneday;
301: $nextday+=$oneday;
302: }
1.40 albertel 303: foreach my $item (keys(%allcal)) {
304: my ($course,$startdate,$enddate)=($item=~/^(\w+)\@(\d+)\_(\d+)$/);
1.39 albertel 305: if (($startdate<$nextday) && ($enddate>=$tk)) {
1.56 albertel 306: push(@outp,[$course,$startdate,$enddate,$allcal{$item}]);
1.3 www 307: }
308: }
1.11 www 309: unless ($mode) {
1.12 www 310: return ($nextday,$nextmonth,&normalcell(
1.56 albertel 311: $th{'day'},$th{'month'},$th{'year'},\@outp));
312: } elsif (@outp) {
1.11 www 313: if ($mode==1) {
1.56 albertel 314: return '<br />'.&plaincell(\@outp);
1.11 www 315: } else {
1.56 albertel 316: return '<ul>'.&listcell(\@outp).'</ul>';
1.11 www 317: }
318: } else {
319: return '';
320: }
1.3 www 321: }
1.1 www 322:
1.19 www 323: sub picklink {
324: my ($text,$day,$month,$year)=@_;
1.34 albertel 325: if ($env{'form.pickdate'} eq 'yes') {
1.19 www 326: return '<a href="javascript:dialin('.$day.','.$month.','.$year.')">'.
327: $text.'</a>';
328: } else {
329: return $text;
330: }
331: }
332:
333: sub dialscript {
334: return (<<ENDDIA);
335: <script language="Javascript">
336: function dialin(day,month,year) {
1.34 albertel 337: opener.document.$env{'form.formname'}.$env{'form.element'}\_year.value=year;
338: var slct=opener.document.$env{'form.formname'}.$env{'form.element'}\_month;
1.19 www 339: var i;
340: for (i=0;i<slct.length;i++) {
341: if (slct.options[i].value==month) { slct.selectedIndex=i; }
342: }
1.34 albertel 343: opener.document.$env{'form.formname'}.$env{'form.element'}\_day.value=day;
344: opener.$env{'form.element'}\_checkday();
1.19 www 345: self.close();
346: }
347: </script>
348: ENDDIA
349: }
1.52 www 350: # ----------------------------------------------------- Summarize all calendars
351: sub get_all_calendars {
352: my %allcal=();
353: foreach my $course (sort(&Apache::loncommon::findallcourses())) {
354: %allcal=(%allcal,&readcalendar($course));
355: }
356: return %allcal;
357: }
358:
359: sub output_ics_file {
360: my ($r)=@_;
361: # RFC 2445 wants CRLF
362: my $crlf="\015\012";
363: # Header
364: $r->print("BEGIN:VCALENDAR$crlf");
365: $r->print("VERSION:2.0$crlf");
366: $r->print("PRODID:-//LONCAPA//LONCAPA Calendar Output//EN$crlf");
367: my %allcal=&get_all_calendars();
368: foreach my $event (keys(%allcal)) {
1.53 www 369: my ($courseid,$startdate,$enddate)=($event=~/^(\w+)\@(\d+)\_(\d+)$/);
370: my $uid=$event;
371: $uid=~s/[\W\_]/-/gs;
372: $uid.='@loncapa';
1.56 albertel 373: my $summary=&display_msg($allcal{$event});
1.53 www 374: $summary=~s/\s+/ /gs;
375: $summary=$env{'course.'.$courseid.'.description'}.': '.$summary;
1.52 www 376: $r->print("BEGIN:VEVENT$crlf");
377: $r->print("DTSTART:".&Apache::loncommon::utc_string($startdate).$crlf);
378: $r->print("DTEND:".&Apache::loncommon::utc_string($enddate).$crlf);
1.53 www 379: $r->print("SUMMARY:$summary$crlf");
380: $r->print("UID:$uid$crlf");
1.52 www 381: $r->print("END:VEVENT$crlf");
382: }
383: # Footer
384: $r->print("END:VCALENDAR$crlf");
385: }
1.19 www 386:
1.1 www 387: sub handler {
388: my $r = shift;
1.52 www 389: if ($r->uri=~/\.(ics|ical)$/) {
390: &Apache::loncommon::content_type($r,'text/calendar');
391: &output_ics_file($r);
392: return OK;
393: }
1.21 www 394: &Apache::loncommon::content_type($r,'text/html');
1.1 www 395: $r->send_http_header;
396: return OK if $r->header_only;
397:
1.3 www 398: # ---------------------------------------------------------- Get time right now
399: my $today=time;
1.12 www 400: %todayhash=&Apache::loncommon::timehash($today);
1.16 www 401: # ----------------------------------------------------------------- Check marks
1.49 albertel 402: undef(%showedcheck);
1.3 www 403: # ---------------------------------------------------------- Get month and year
404: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.19 www 405: ['month','year','pickdate','formname','element']);
1.3 www 406: # --------------------------------------------------- Decide what month to show
407: my $year=$todayhash{'year'};
1.34 albertel 408: if ($env{'form.year'}) { $year=$env{'form.year'}; }
1.3 www 409: my $month=$todayhash{'month'};
1.34 albertel 410: if ($env{'form.month'}) { $month=$env{'form.month'}; }
1.18 www 411:
412: # ---------------------------------------------- See if we are in pickdate mode
1.34 albertel 413: my $pickdatemode=($env{'form.pickdate'} eq 'yes');
414: my $pickinfo='&pickdate=yes&formname='.$env{'form.formname'}.
415: '&element='.$env{'form.element'};
1.3 www 416: # --------------------------------------------- Find out first day of the month
417:
418: my %firstday=&Apache::loncommon::timehash(
419: &Apache::loncommon::maketime( 'day' => 1, 'month'=> $month,
420: 'year' => $year, 'hours' => 0,
421: 'minutes' => 0, 'seconds' => 0,
1.30 www 422: 'dlsav' => -1 ));
1.3 www 423: my $weekday=$firstday{'weekday'};
424: # ------------------------------------------------------------ Print the screen
1.47 albertel 425: my $js = <<ENDDOCUMENT;
426: <script type="text/javascript">
1.3 www 427:
428: function trysubmit() {
429: document.anno.action.value="new";
430: document.anno.submit();
431: }
432:
433: function removesub() {
434: document.anno.action.value="del";
435: document.anno.submit();
436: }
437: </script>
1.1 www 438: ENDDOCUMENT
1.47 albertel 439:
1.18 www 440: if ($pickdatemode) {
441: # no big header in pickdate mode
1.47 albertel 442: $r->print(&Apache::loncommon::start_page("Pick a Date",$js,
443: {'only_body' => 1,}).
1.19 www 444: &dialscript().
1.18 www 445: '<font size="1">');
446: } else {
1.47 albertel 447: $r->print(&Apache::loncommon::start_page("Announcements and Calendar",
448: $js));
1.18 www 449: }
1.3 www 450: # does this user have privileges to post, etc?
451: my $allowed=0;
1.34 albertel 452: if ($env{'request.course.id'}) {
453: $allowed=&Apache::lonnet::allowed('srm',$env{'request.course.id'});
1.3 www 454: }
1.17 www 455: # does this user have privileges to post to servers?
456: my $serverpost=0;
1.34 albertel 457: if ($env{'request.role.domain'}) {
1.17 www 458: $serverpost=&Apache::lonnet::allowed('psa',
1.34 albertel 459: $env{'request.role.domain'});
1.17 www 460: } else {
461: $serverpost=&Apache::lonnet::allowed('psa','/');
462: }
1.18 www 463: # -------------------------------- BUT: do no fancy stuff when in pickdate mode
464: if ($pickdatemode) {
465: $serverpost=0;
466: $allowed=0;
467: }
1.17 www 468: # ------------------------------------------------------------ Process commands
469: if ($serverpost) {
1.34 albertel 470: if ($env{'form.serveraction'}) {
1.42 albertel 471: foreach my $key (keys(%env)) {
472: if ($key=~/^form\.postto\_(\w+)/) {
1.17 www 473: $r->print(
474: '<br />Posting '.$1.': '.&Apache::lonnet::postannounce
1.34 albertel 475: ($1,$env{'form.serverannnounce'}));
1.17 www 476: }
477: }
478: }
479: $r->print(<<SERVERANNOUNCE);
480: <form name="serveranno" method="post">
481: <h3>Post Server Announcements</h3>
482: Post announcements to the system login and roles screen<br />
483: <i>(leave blank to delete announcement)</i><br />
484: <textarea name="serverannnounce" cols="60" rows="5"></textarea><br />
485: Check machines:<br />
486: SERVERANNOUNCE
487: # list servers
1.42 albertel 488: foreach my $host (sort(keys(%Apache::lonnet::hostname))) {
489: if (&Apache::lonnet::allowed('psa',$Apache::lonnet::hostdom{$host})) {
490: $r->print ('<br /><input type="checkbox" name="postto_'.$host.'" /> '.
491: $host.' <tt>'.$Apache::lonnet::hostname{$host}.'</tt> '.
492: '<a href="http://'.$Apache::lonnet::hostname{$host}.
1.17 www 493: '/announcement.txt" target="annowin">current</a>');
494: }
495: }
496: $r->print(
497: '<br /><input type="submit" name="serveraction" value="Post"></form><hr />');
498: }
1.3 www 499: if ($allowed) {
1.34 albertel 500: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
501: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.3 www 502: # ----------------------------------------------------- Store new submitted one
1.34 albertel 503: if ($env{'form.action'} eq 'new') {
1.9 www 504: my $startdate =
505: &Apache::lonhtmlcommon::get_date_from_form('startdate');
506: my $enddate =
507: &Apache::lonhtmlcommon::get_date_from_form('enddate');
508: unless ($startdate=~/^\d+$/) { $startdate=time; }
509: unless ($enddate=~/^\d+$/) { $enddate=$startdate+1; }
510: if ($startdate>$enddate) {
511: my $buffer=$startdate;
512: $startdate=$enddate;
513: $enddate=$buffer;
514: }
1.3 www 515: &Apache::lonnet::put('calendar',{
1.9 www 516: $startdate.'_'.$enddate =>
1.34 albertel 517: $env{'form.msg'} },$coursedom,$coursenum);
1.36 www 518: if ($env{'form.rsspost'}) {
519: &Apache::lonrss::addentry($coursenum,$coursedom,'Course_Announcements',
520: &mt('Event from [_1] to [_2]',
521: &Apache::lonlocal::locallocaltime($startdate),
522: &Apache::lonlocal::locallocaltime($enddate)),
523: $env{'form.msg'},'/adm/announcements','public');
524: }
1.3 www 525: }
526: # ---------------------------------------------------------------- Remove items
1.34 albertel 527: if ($env{'form.action'} eq 'del') {
1.3 www 528: my @delwhich=();
1.42 albertel 529: foreach my $key (keys(%env)) {
530: if ($key=~/^form\.remove\_(.+)$/) {
1.3 www 531: push(@delwhich,$1);
532: }
533: }
534: &Apache::lonnet::del('calendar',\@delwhich,$coursedom,$coursenum);
535: }
536: # -------------------------------------------------------- Form to post new one
537: my %tomorrowhash=%todayhash;
538: $tomorrowhash{'day'}++;
539: my $tomorrow=&Apache::loncommon::maketime(%tomorrowhash);
540:
1.10 www 541: &editfield($r,$today,$tomorrow,'');
1.3 www 542: }
1.5 www 543: # ----------------------------------------------------- Summarize all calendars
1.52 www 544: my %allcal=&get_all_calendars();
1.5 www 545: # ------------------------------- Initialize table and forward backward buttons
1.3 www 546: my ($pm,$py,$fm,$fy)=($month-1,$year,$month+1,$year);
547: if ($pm<1) { ($pm,$py)=(12,$year-1); }
548: if ($fm>12){ ($fm,$fy)=(1,$year+1); }
1.14 www 549:
1.20 www 550: $r->print('<h1>'.('',&mt('January'),&mt('February'),&mt('March'),
551: &mt('April'),&mt('May'),
552: &mt('June'),&mt('July'),&mt('August'),
553: &mt('September'),&mt('October'),
554: &mt('November'),&mt('December'))[$month].' '.
555: $year.'</h1>');
1.13 www 556: # Reached the end of times, give up
557: if (($year<1970) || ($year>2037)) {
558: $r->print('<h3>No calendar available for this date.</h3>'.
559: '<a href="/adm/announcements?month='.$todayhash{'month'}.
1.47 albertel 560: '&year='.$todayhash{'year'}.'">Current Month</a>'.
561: &Apache::loncommon::end_page());
1.13 www 562: return OK;
563: }
1.49 albertel 564:
565: my $class = "LC_calendar";
566: if ($env{'form.pickdate'} eq 'yes') {
567: $class .= " LC_calendar_pickdate";
568: }
1.13 www 569: $r->print(
1.18 www 570: '<a href="/adm/announcements?month='.$pm.'&year='.$py.
1.20 www 571: ($pickdatemode?$pickinfo:'').'">'.&mt('Previous Month').'</a> '.
1.18 www 572: '<a href="/adm/announcements?month='.$fm.'&year='.$fy.
1.20 www 573: ($pickdatemode?$pickinfo:'').'">'.&mt('Next Month').'</a>'.
1.12 www 574: ' <a href="/adm/announcements?month='.$todayhash{'month'}.
1.18 www 575: '&year='.$todayhash{'year'}.
1.20 www 576: ($pickdatemode?$pickinfo:'').'">'.&mt('Current Month').'</a><p>'.
1.49 albertel 577: '<table class="'.$class.'" cols="7" rows="5"><tr>
578: <th>'.&mt('Sun').'</th>
579: <th>'.&mt('Mon').'</th>
580: <th>'.&mt('Tue').'</th>
581: <th>'.&mt('Wed').'</th>
582: <th>'.&mt('Thu').'</th>
583: <th>'.&mt('Fri').'</th>
584: <th>'.&mt('Sat').'</th></tr>');
1.3 www 585:
586: my $tk=&Apache::loncommon::maketime(%firstday);
587: my $outp;
588: my $nm;
589:
590: # ---------------------------------------------------------------- Actual table
591: $r->print('<tr>');
592: for (my $i=0;$i<$weekday;$i++) { $r->print(&emptycell); }
593: for (my $i=$weekday;$i<=6;$i++) {
1.11 www 594: ($tk,$nm,$outp)=&showday($tk,0,%allcal);
1.3 www 595: $r->print($outp);
596: }
597: $r->print('</tr>');
598:
1.23 www 599: for (my $k=0;$k<=4;$k++) {
1.3 www 600: $r->print('<tr>');
601: for (my $i=0;$i<=6;$i++) {
1.11 www 602: ($tk,$nm,$outp)=&showday($tk,0,%allcal);
1.3 www 603: if ($month!=$nm) { $outp=&emptycell; }
604: $r->print($outp);
605: }
606: $r->print('</tr>');
607: }
608: # ------------------------------------------------------------------- End table
1.7 matthew 609: $r->print('</table>');
1.16 www 610: # ----------------------------------------------------------------- Check marks
1.49 albertel 611: undef(%showedcheck);
1.16 www 612: # --------------------------------------------------------------- Remove button
1.24 www 613: if ($allowed) { $r->print('<input type="button" onClick="removesub()" value="Remove Checked Entries">'.
614: &Apache::loncommon::help_open_topic('Calendar_Remove_Announcement').'</form>'); }
1.7 matthew 615: $r->print('<p>'.
1.18 www 616: '<a href="/adm/announcements?month='.$pm.'&year='.$py.
1.20 www 617: ($pickdatemode?$pickinfo:'').'">'.&mt('Previous Month').'</a> '.
1.18 www 618: '<a href="/adm/announcements?month='.$fm.'&year='.$fy.
1.20 www 619: ($pickdatemode?$pickinfo:'').'">'.&mt('Next Month').'</a>'.
1.12 www 620: ' <a href="/adm/announcements?month='.$todayhash{'month'}.
1.18 www 621: '&year='.$todayhash{'year'}.
1.20 www 622: ($pickdatemode?$pickinfo:'').'">'.&mt('Current Month').'</a></p>'.
1.47 albertel 623: ($pickdatemode?'</font>':'').&Apache::loncommon::end_page());
1.53 www 624: $r->print('<a href="/adm/announcements.ics">'.&mt('Download your Calendar as iCalendar File').'</a>');
1.1 www 625: return OK;
626: }
627:
628: 1;
629: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>