File:  [LON-CAPA] / loncom / interface / lonannounce.pm
Revision 1.52: download - view: text, annotated - select for diffs
Fri May 12 02:17:50 2006 UTC (18 years, 1 month ago) by www
Branches: MAIN
CVS tags: HEAD
Saving my work on iCalendar files.

Still left to do:

* time format wrong: 200656 instead of 20060506
* Calendar does not seem to collect all data from all courses
* remove "INTERNAL:"
* put in course description

    1: # The LearningOnline Network
    2: # Announce
    3: #
    4: # $Id: lonannounce.pm,v 1.52 2006/05/12 02:17:50 www Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   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.
   14: #
   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: 
   29: package Apache::lonannounce;
   30: 
   31: use strict;
   32: use Apache::Constants qw(:common);
   33: use Apache::loncommon;
   34: use Apache::lonhtmlcommon();
   35: use Apache::lonlocal;
   36: use Apache::lonnavmaps();
   37: use Apache::lonrss();
   38: use Apache::lonnet;
   39: use HTML::Entities();
   40: 
   41: my %todayhash;
   42: my %showedcheck;
   43: 
   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);
   53:     my $help=&Apache::loncommon::help_open_menu('','Calendar Add Announcement','Calendar_Add_Announcement','',274,'Communication Tools');
   54:     my %lt=&Apache::lonlocal::texthash('post' => 'Post Announcement',
   55: 				       'start' => 'Starting date',
   56: 				       'end' => 'Ending date',
   57: 				       'incrss' => 'Include in course RSS newsfeed');
   58: 
   59:     $r->print(<<ENDFORM);
   60: $help
   61: <form name="anno" method="post">
   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>
   65: <textarea name="msg" rows="4" cols="60">$text</textarea>
   66: <br />
   67: <label><input type="checkbox" name="rsspost" /> $lt{'incrss'}</label>
   68: <br /><input type="button" onClick="trysubmit()" value="$lt{'post'}" /><hr />
   69: ENDFORM
   70: }
   71: 
   72: sub readcalendar {
   73:     my $courseid=shift;
   74:     my $coursenum=$env{'course.'.$courseid.'.num'};
   75:     my $coursedom=$env{'course.'.$courseid.'.domain'};
   76:     my %thiscal=&Apache::lonnet::dump('calendar',$coursedom,$coursenum);
   77:     my %returnhash=();
   78:     foreach my $item (keys(%thiscal)) {
   79:         unless (($item=~/^error\:/) || ($thiscal{$item}=~/^error\:/)) {
   80: 	   $returnhash{$courseid.'@'.$item}=$thiscal{$item};
   81:         }
   82:     }
   83: 
   84:     if ($courseid eq $env{'request.course.id'}) {
   85: 	my $can_see_hidden = $env{'request.role.adv'};
   86: 	my $navmap = Apache::lonnavmaps::navmap->new();
   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=~/^\[(.*)\]\./) {
   95: 		    my $sec=$1;
   96: 		    # if we have a section don't show ones that aren't ours
   97: 		    if ($env{'request.course.sec'} &&
   98: 			$env{'request.course.sec'} ne $sec) { next; }
   99: 		    # if a student without a section don't show any section ones
  100: 		    if (!$env{'request.role.adv'} &&
  101: 			!$env{'request.course.sec'}) { next; }
  102: 		    $section=&mt('Group/Section').': '.$1;
  103: 		    $middle=~s/^\[(.*)\]\.//;
  104: 		}
  105: 		$middle=~s/\.$//;
  106: 		my $realm=&mt('All Resources');
  107: 		if ($middle=~/^(.+)\_\_\_\(all\)$/) {
  108: 		    my $map_url=$1;
  109: 		    if (!$can_see_hidden && !$navmap) {
  110: 			next;
  111: 		    }
  112: 		    if (!$can_see_hidden) {
  113: 			my $res = $navmap->getResourceByUrl($map_url);
  114: 			if ($res && $res->randomout()) { next; }
  115: 		    }
  116: 		    $realm=&mt('Folder/Map').': '.&Apache::lonnet::gettitle($map_url);
  117: 		} elsif ($middle) {
  118: 		    if (!$can_see_hidden && !$navmap) {
  119: 			next;
  120: 		    }
  121: 		    if (!$can_see_hidden) {
  122: 			my $res = $navmap->getBySymb($middle);
  123: 			if ($res && $res->randomout()) { next; }
  124: 		    }
  125: 		    $realm=&mt('Resource').': '.&Apache::lonnet::gettitle($middle);
  126: 		}
  127: 		my $datetype='';
  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: 		}
  137: 		if ($name eq 'opendate') { $datetype=&mt('Opening'); }
  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: 		}
  148: 		$returnhash{$courseid.'@'.$resourcedata{$thiskey}.'_'.
  149: 			    $resourcedata{$thiskey}}=
  150: 			    'INTERNAL:'.$datetype.': '.$realm.' ('.$section.')';
  151: 	    }
  152: 	}
  153:     }
  154:     return %returnhash;
  155: }
  156: 
  157: sub emptycell {
  158:     return '<td class="LC_calendar_day_empty">&nbsp;</td>';
  159: }
  160: 
  161: sub normalcell {
  162:     my ($day,$month,$year,$text)=@_;
  163:     my $output;
  164:     my @items=&order($text);
  165:     foreach my $item (@items) {
  166:         if ($item) {
  167: 	    my $internalflag=0;
  168: 	    my ($courseid,$start,$end,$msg)=split(/\@/,$item,4);
  169: 	    if ($msg=~/INTERNAL\:/) {
  170: 		$msg=~s/INTERNAL\://gs;
  171: 		$internalflag=1;
  172: 	    }
  173:             my $fullmsg=&mt('Calendar Announcement for ').$env{'course.'.$courseid.'.description'}.
  174: 		'\n'.&Apache::lonlocal::locallocaltime($start);
  175: 	    if ($start!=$end) {
  176: 		$fullmsg.=' - '.&Apache::lonlocal::locallocaltime($end);
  177: 	    }
  178: 	    $fullmsg.=':\n'.$msg;
  179:             if ($courseid eq $env{'request.course.id'}) {
  180:               if ((&Apache::lonnet::allowed('srm',$env{'request.course.id'}))
  181:                && (!$showedcheck{$start.'_'.$end})
  182: 	       && ($env{'form.pickdate'} ne 'yes')
  183: 	       && (!$internalflag)) {
  184:                $output.='<input type="checkbox" name="remove_'.$start.'_'.
  185: 		   $end.'">';
  186:                $showedcheck{$start.'_'.$end}=1;
  187: 	      }
  188: 	    }
  189: 	    $fullmsg=~s/[\n\r]/\\n/gs;
  190:             $fullmsg=&HTML::Entities::encode($fullmsg,'<>&"\'');
  191:             $fullmsg=~s/&/\\&/g;
  192: 	    my $short_msg = substr($msg,0,20).((length($msg) > 20)?'...':'');
  193: 	    if (defined($output)) { $output.='<br />'; }
  194:             $output.='<a href="javascript:alert('."'$fullmsg'".')">'.
  195: 	       $short_msg.'</a>';
  196:        }
  197:     }
  198:     return '<td class="LC_calendar_day'.
  199: 	((($day eq $todayhash{'day'}) &&
  200:           ($month eq $todayhash{'month'}) &&
  201:           ($year eq $todayhash{'year'}))?'_current':'').
  202:            '" ><b>'.&picklink($day,$day,$month,$year).'</b><br />'.$output.'</td>';
  203: }
  204: 
  205: sub plaincell {
  206:     my ($text)=@_;
  207:     my $output;
  208:     my @items=&order($text);
  209:     foreach my $item (@items) {
  210:         if ($item) {
  211: 	    my ($courseid,$start,$end,$msg)=split(/\@/,$item,4);
  212:             my $fullmsg=&mt('Calendar Announcement for ').$env{'course.'.$courseid.'.description'}.
  213: 		'\n'.&Apache::lonlocal::locallocaltime($start);
  214: 	    if ($start!=$end) {
  215: 		$fullmsg.=' - '.&Apache::lonlocal::locallocaltime($end);
  216: 	    }
  217: 	    $msg=~s/INTERNAL\://gs;
  218: 	    $fullmsg.=':\n'.$msg;
  219:  	    $fullmsg=~s/[\n\r]/\\n/gs;
  220:             $fullmsg=&HTML::Entities::encode($fullmsg,'<>&"\'');
  221:             $fullmsg=~s/&/\\&/g;
  222: 	    my $short_msg = substr($msg,0,80).((length($msg) > 80)?'...':'');
  223: 	    if (defined($output)) { $output.='<br />'; }
  224:             $output.='<a href="javascript:alert('."'$fullmsg'".')">'.
  225: 	       $short_msg.'</a>';
  226:        }
  227:     }
  228:     return $output;
  229: }
  230: 
  231: sub listcell {
  232:     my ($text)=@_;
  233:     my $output='';
  234:     my @items=&order($text);
  235:     foreach my $item (@items) {
  236:         if ($item) {
  237: 	    my ($courseid,$start,$end,$msg)=split(/\@/,$item,4);
  238: 	    $msg=~s/INTERNAL\://gs;
  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>'.
  245:                $msg.'</b>';
  246:             $output.='<li>'.$fullmsg.'</li>';
  247:        }
  248:     }
  249:     return $output;
  250: }
  251: 
  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: 
  265: sub nextday {
  266:     my %th=@_;
  267:     $th{'day'}++;
  268:     return (&Apache::loncommon::maketime(%th),$th{'month'});
  269: }
  270: 
  271: sub showday {
  272:     my ($tk,$mode,%allcal)=@_;
  273:     my %th=&Apache::loncommon::timehash($tk);
  274:     my ($nextday,$nextmonth)=&nextday(%th);
  275:     my $outp='';
  276:     if ($mode) {
  277: 	my $oneday=24*3600;
  278: 	$tk-=$oneday;
  279: 	$nextday+=$oneday;
  280:     }
  281:     foreach my $item (keys(%allcal)) {
  282: 	my ($course,$startdate,$enddate)=($item=~/^(\w+)\@(\d+)\_(\d+)$/);
  283:         if (($startdate<$nextday) && ($enddate>=$tk))  {
  284: 	    $outp.='___&&&___'.$course.'@'.$startdate.'@'.$enddate.'@'.
  285:             $allcal{$item};
  286:         }
  287:     }
  288:     unless ($mode) {
  289:        return ($nextday,$nextmonth,&normalcell(
  290:                $th{'day'},$th{'month'},$th{'year'},$outp));
  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:    }
  300: }
  301: 
  302: sub picklink {
  303:     my ($text,$day,$month,$year)=@_;
  304:     if ($env{'form.pickdate'} eq 'yes') {
  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) {
  316: 	opener.document.$env{'form.formname'}.$env{'form.element'}\_year.value=year;
  317:     var slct=opener.document.$env{'form.formname'}.$env{'form.element'}\_month;
  318:     var i;
  319:     for (i=0;i<slct.length;i++) {
  320:         if (slct.options[i].value==month) { slct.selectedIndex=i; }
  321:     }
  322:     opener.document.$env{'form.formname'}.$env{'form.element'}\_day.value=day;
  323:     opener.$env{'form.element'}\_checkday();
  324:     self.close();
  325: }
  326: </script>
  327: ENDDIA
  328: }
  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: }
  358: 
  359: sub handler {
  360:     my $r = shift;
  361:     if ($r->uri=~/\.(ics|ical)$/) {
  362:         &Apache::loncommon::content_type($r,'text/calendar');
  363: 	&output_ics_file($r);
  364: 	return OK;
  365:     }
  366:     &Apache::loncommon::content_type($r,'text/html');
  367:     $r->send_http_header;
  368:     return OK if $r->header_only;
  369: 
  370: # ---------------------------------------------------------- Get time right now
  371:     my $today=time;
  372:     %todayhash=&Apache::loncommon::timehash($today);
  373: # ----------------------------------------------------------------- Check marks
  374:     undef(%showedcheck);
  375: # ---------------------------------------------------------- Get month and year
  376:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  377:                              ['month','year','pickdate','formname','element']);
  378: # --------------------------------------------------- Decide what month to show
  379:     my $year=$todayhash{'year'};
  380:     if ($env{'form.year'}) { $year=$env{'form.year'}; }
  381:     my $month=$todayhash{'month'};
  382:     if ($env{'form.month'}) { $month=$env{'form.month'}; }
  383: 
  384: # ---------------------------------------------- See if we are in pickdate mode
  385:     my $pickdatemode=($env{'form.pickdate'} eq 'yes');
  386:     my $pickinfo='&pickdate=yes&formname='.$env{'form.formname'}.
  387: 	'&element='.$env{'form.element'};
  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,
  394:                                      'dlsav' => -1 ));
  395:     my $weekday=$firstday{'weekday'};
  396: # ------------------------------------------------------------ Print the screen
  397:     my $js = <<ENDDOCUMENT;
  398: <script type="text/javascript">
  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>
  410: ENDDOCUMENT
  411: 
  412:     if ($pickdatemode) {
  413: # no big header in pickdate mode
  414: 	$r->print(&Apache::loncommon::start_page("Pick a Date",$js,
  415: 						 {'only_body' => 1,}).
  416: 		  &dialscript().
  417: 		  '<font size="1">');
  418:     } else {
  419:        $r->print(&Apache::loncommon::start_page("Announcements and Calendar",
  420: 						$js));
  421:     }
  422: # does this user have privileges to post, etc?
  423:     my $allowed=0;
  424:     if ($env{'request.course.id'}) {
  425:        $allowed=&Apache::lonnet::allowed('srm',$env{'request.course.id'});
  426:     }
  427: # does this user have privileges to post to servers?
  428:     my $serverpost=0;
  429:     if ($env{'request.role.domain'}) {
  430: 	$serverpost=&Apache::lonnet::allowed('psa',
  431: 					     $env{'request.role.domain'});
  432:     } else {
  433: 	$serverpost=&Apache::lonnet::allowed('psa','/');
  434:     }
  435: # -------------------------------- BUT: do no fancy stuff when in pickdate mode
  436:     if ($pickdatemode) { 
  437: 	$serverpost=0; 
  438: 	$allowed=0;
  439:     }
  440: # ------------------------------------------------------------ Process commands
  441:     if ($serverpost) {
  442: 	if ($env{'form.serveraction'}) {
  443: 	    foreach my $key (keys(%env)) {
  444: 		if ($key=~/^form\.postto\_(\w+)/) {
  445: 		    $r->print( 
  446: 			'<br />Posting '.$1.': '.&Apache::lonnet::postannounce
  447: 			($1,$env{'form.serverannnounce'}));
  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
  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}.
  465: 		       '/announcement.txt" target="annowin">current</a>');
  466: 	}
  467:     }
  468:     $r->print(
  469:   '<br /><input type="submit" name="serveraction" value="Post"></form><hr />');
  470:     }
  471:     if ($allowed) {
  472:         my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
  473:         my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
  474: # ----------------------------------------------------- Store new submitted one
  475:         if ($env{'form.action'} eq 'new') {
  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:             }
  487: 	    &Apache::lonnet::put('calendar',{ 
  488: 		$startdate.'_'.$enddate => 
  489: 		    $env{'form.msg'} },$coursedom,$coursenum);
  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: 	   }
  497:         }
  498: # ---------------------------------------------------------------- Remove items
  499:         if ($env{'form.action'} eq 'del') {
  500: 	    my @delwhich=();
  501:             foreach my $key (keys(%env)) {
  502: 		if ($key=~/^form\.remove\_(.+)$/) {
  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:         
  513:         &editfield($r,$today,$tomorrow,'');
  514:     }
  515: # ----------------------------------------------------- Summarize all calendars
  516:     my %allcal=&get_all_calendars();
  517: # ------------------------------- Initialize table and forward backward buttons
  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); }
  521: 
  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>');
  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'}.
  532:  '&year='.$todayhash{'year'}.'">Current Month</a>'.
  533: 		  &Apache::loncommon::end_page());
  534: 	return OK;
  535:     }
  536: 
  537:     my $class = "LC_calendar";
  538:     if ($env{'form.pickdate'} eq 'yes') {
  539: 	$class .= " LC_calendar_pickdate";
  540:     }
  541:     $r->print(
  542:  '<a href="/adm/announcements?month='.$pm.'&year='.$py.
  543:  ($pickdatemode?$pickinfo:'').'">'.&mt('Previous Month').'</a> '.
  544:  '<a href="/adm/announcements?month='.$fm.'&year='.$fy.
  545:  ($pickdatemode?$pickinfo:'').'">'.&mt('Next Month').'</a>'.
  546:  '&nbsp;&nbsp;&nbsp;<a href="/adm/announcements?month='.$todayhash{'month'}.
  547:  '&year='.$todayhash{'year'}.
  548:  ($pickdatemode?$pickinfo:'').'">'.&mt('Current Month').'</a><p>'.
  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>');
  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++) { 
  566:         ($tk,$nm,$outp)=&showday($tk,0,%allcal);
  567:         $r->print($outp);
  568:     }
  569:     $r->print('</tr>');
  570: 
  571:     for (my $k=0;$k<=4;$k++) {
  572:         $r->print('<tr>');
  573:         for (my $i=0;$i<=6;$i++) {
  574:             ($tk,$nm,$outp)=&showday($tk,0,%allcal);
  575:             if ($month!=$nm) { $outp=&emptycell; }
  576:             $r->print($outp);
  577:         }
  578:         $r->print('</tr>');
  579:     }
  580: # ------------------------------------------------------------------- End table
  581:     $r->print('</table>');
  582: # ----------------------------------------------------------------- Check marks
  583:     undef(%showedcheck);
  584: # --------------------------------------------------------------- Remove button
  585:     if ($allowed) { $r->print('<input type="button" onClick="removesub()" value="Remove Checked Entries">'.
  586: 			      &Apache::loncommon::help_open_topic('Calendar_Remove_Announcement').'</form>'); }
  587:     $r->print('<p>'.
  588:  '<a href="/adm/announcements?month='.$pm.'&year='.$py.
  589:  ($pickdatemode?$pickinfo:'').'">'.&mt('Previous Month').'</a> '.
  590:  '<a href="/adm/announcements?month='.$fm.'&year='.$fy.
  591:  ($pickdatemode?$pickinfo:'').'">'.&mt('Next Month').'</a>'.
  592:  '&nbsp;&nbsp;&nbsp;<a href="/adm/announcements?month='.$todayhash{'month'}.
  593:  '&year='.$todayhash{'year'}.
  594:  ($pickdatemode?$pickinfo:'').'">'.&mt('Current Month').'</a></p>'.
  595:  ($pickdatemode?'</font>':'').&Apache::loncommon::end_page());
  596:     return OK;
  597: } 
  598: 
  599: 1;
  600: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>