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