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