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