File:  [LON-CAPA] / loncom / interface / lonannounce.pm
Revision 1.53: download - view: text, annotated - select for diffs
Fri May 12 15:53:10 2006 UTC (18 years, 2 months ago) by www
Branches: MAIN
CVS tags: HEAD
iCalendar working, at least with Apple iCal

    1: # The LearningOnline Network
    2: # Announce
    3: #
    4: # $Id: lonannounce.pm,v 1.53 2006/05/12 15:53:10 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:     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; }
  118: 		}
  119: 		$realm=&mt('Folder/Map').': '.&Apache::lonnet::gettitle($map_url);
  120: 	    } elsif ($middle) {
  121: 		if (!$can_see_hidden && !$navmap) {
  122: 		    next;
  123: 		}
  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'); 
  133: # see if accidentally answerdate is before duedate
  134: 		my $answerkey=$thiskey;
  135: 		$answerkey=~s/duedate$/answerdate/;
  136: 		if ($resourcedata{$thiskey}>$resourcedata{$answerkey}) {
  137: 		    $datetype=&mt('Due and Answer Available');
  138: 		}
  139: 	    }
  140: 	    if ($name eq 'opendate') { $datetype=&mt('Opening'); }
  141: 	    if ($name eq 'answerdate') {
  142: # see if accidentally answerdate is before duedate
  143: 		my $duekey=$thiskey;
  144: 		$duekey=~s/answerdate$/duedate/;
  145: 		if ($resourcedata{$duekey}>$resourcedata{$thiskey}) {
  146: # forget it
  147: 		    next;
  148: 		} 
  149: 		$datetype=&mt('Answer Available'); 
  150: 	    }
  151: 	    $returnhash{$courseid.'@'.$resourcedata{$thiskey}.'_'.
  152: 			    $resourcedata{$thiskey}}=
  153: 			    'INTERNAL:'.$datetype.': '.$realm.' ('.$section.')';
  154: 	}
  155:     }
  156:     return %returnhash;
  157: }
  158: 
  159: sub emptycell {
  160:     return '<td class="LC_calendar_day_empty">&nbsp;</td>';
  161: }
  162: 
  163: sub normalcell {
  164:     my ($day,$month,$year,$text)=@_;
  165:     my $output;
  166:     my @items=&order($text);
  167:     foreach my $item (@items) {
  168:         if ($item) {
  169: 	    my $internalflag=0;
  170: 	    my ($courseid,$start,$end,$msg)=split(/\@/,$item,4);
  171: 	    if ($msg=~/INTERNAL\:/) {
  172: 		$msg=~s/INTERNAL\://gs;
  173: 		$internalflag=1;
  174: 	    }
  175:             my $fullmsg=&mt('Calendar Announcement for ').$env{'course.'.$courseid.'.description'}.
  176: 		'\n'.&Apache::lonlocal::locallocaltime($start);
  177: 	    if ($start!=$end) {
  178: 		$fullmsg.=' - '.&Apache::lonlocal::locallocaltime($end);
  179: 	    }
  180: 	    $fullmsg.=':\n'.$msg;
  181:             if ($courseid eq $env{'request.course.id'}) {
  182:               if ((&Apache::lonnet::allowed('srm',$env{'request.course.id'}))
  183:                && (!$showedcheck{$start.'_'.$end})
  184: 	       && ($env{'form.pickdate'} ne 'yes')
  185: 	       && (!$internalflag)) {
  186:                $output.='<input type="checkbox" name="remove_'.$start.'_'.
  187: 		   $end.'">';
  188:                $showedcheck{$start.'_'.$end}=1;
  189: 	      }
  190: 	    }
  191: 	    $fullmsg=~s/[\n\r]/\\n/gs;
  192:             $fullmsg=&HTML::Entities::encode($fullmsg,'<>&"\'');
  193:             $fullmsg=~s/&/\\&/g;
  194: 	    my $short_msg = substr($msg,0,20).((length($msg) > 20)?'...':'');
  195: 	    if (defined($output)) { $output.='<br />'; }
  196:             $output.='<a href="javascript:alert('."'$fullmsg'".')">'.
  197: 	       $short_msg.'</a>';
  198:        }
  199:     }
  200:     return '<td class="LC_calendar_day'.
  201: 	((($day eq $todayhash{'day'}) &&
  202:           ($month eq $todayhash{'month'}) &&
  203:           ($year eq $todayhash{'year'}))?'_current':'').
  204:            '" ><b>'.&picklink($day,$day,$month,$year).'</b><br />'.$output.'</td>';
  205: }
  206: 
  207: sub plaincell {
  208:     my ($text)=@_;
  209:     my $output;
  210:     my @items=&order($text);
  211:     foreach my $item (@items) {
  212:         if ($item) {
  213: 	    my ($courseid,$start,$end,$msg)=split(/\@/,$item,4);
  214:             my $fullmsg=&mt('Calendar Announcement for ').$env{'course.'.$courseid.'.description'}.
  215: 		'\n'.&Apache::lonlocal::locallocaltime($start);
  216: 	    if ($start!=$end) {
  217: 		$fullmsg.=' - '.&Apache::lonlocal::locallocaltime($end);
  218: 	    }
  219: 	    $msg=~s/INTERNAL\://gs;
  220: 	    $fullmsg.=':\n'.$msg;
  221:  	    $fullmsg=~s/[\n\r]/\\n/gs;
  222:             $fullmsg=&HTML::Entities::encode($fullmsg,'<>&"\'');
  223:             $fullmsg=~s/&/\\&/g;
  224: 	    my $short_msg = substr($msg,0,80).((length($msg) > 80)?'...':'');
  225: 	    if (defined($output)) { $output.='<br />'; }
  226:             $output.='<a href="javascript:alert('."'$fullmsg'".')">'.
  227: 	       $short_msg.'</a>';
  228:        }
  229:     }
  230:     return $output;
  231: }
  232: 
  233: sub listcell {
  234:     my ($text)=@_;
  235:     my $output='';
  236:     my @items=&order($text);
  237:     foreach my $item (@items) {
  238:         if ($item) {
  239: 	    my ($courseid,$start,$end,$msg)=split(/\@/,$item,4);
  240: 	    $msg=~s/INTERNAL\://gs;
  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>'.
  247:                $msg.'</b>';
  248:             $output.='<li>'.$fullmsg.'</li>';
  249:        }
  250:     }
  251:     return $output;
  252: }
  253: 
  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: 
  267: sub nextday {
  268:     my %th=@_;
  269:     $th{'day'}++;
  270:     return (&Apache::loncommon::maketime(%th),$th{'month'});
  271: }
  272: 
  273: sub showday {
  274:     my ($tk,$mode,%allcal)=@_;
  275:     my %th=&Apache::loncommon::timehash($tk);
  276:     my ($nextday,$nextmonth)=&nextday(%th);
  277:     my $outp='';
  278:     if ($mode) {
  279: 	my $oneday=24*3600;
  280: 	$tk-=$oneday;
  281: 	$nextday+=$oneday;
  282:     }
  283:     foreach my $item (keys(%allcal)) {
  284: 	my ($course,$startdate,$enddate)=($item=~/^(\w+)\@(\d+)\_(\d+)$/);
  285:         if (($startdate<$nextday) && ($enddate>=$tk))  {
  286: 	    $outp.='___&&&___'.$course.'@'.$startdate.'@'.$enddate.'@'.
  287:             $allcal{$item};
  288:         }
  289:     }
  290:     unless ($mode) {
  291:        return ($nextday,$nextmonth,&normalcell(
  292:                $th{'day'},$th{'month'},$th{'year'},$outp));
  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:    }
  302: }
  303: 
  304: sub picklink {
  305:     my ($text,$day,$month,$year)=@_;
  306:     if ($env{'form.pickdate'} eq 'yes') {
  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) {
  318: 	opener.document.$env{'form.formname'}.$env{'form.element'}\_year.value=year;
  319:     var slct=opener.document.$env{'form.formname'}.$env{'form.element'}\_month;
  320:     var i;
  321:     for (i=0;i<slct.length;i++) {
  322:         if (slct.options[i].value==month) { slct.selectedIndex=i; }
  323:     }
  324:     opener.document.$env{'form.formname'}.$env{'form.element'}\_day.value=day;
  325:     opener.$env{'form.element'}\_checkday();
  326:     self.close();
  327: }
  328: </script>
  329: ENDDIA
  330: }
  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)) {
  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;
  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);
  361: 	$r->print("SUMMARY:$summary$crlf");
  362: 	$r->print("UID:$uid$crlf");
  363: 	$r->print("END:VEVENT$crlf");
  364:     }
  365: # Footer
  366:     $r->print("END:VCALENDAR$crlf");
  367: }
  368: 
  369: sub handler {
  370:     my $r = shift;
  371:     if ($r->uri=~/\.(ics|ical)$/) {
  372:         &Apache::loncommon::content_type($r,'text/calendar');
  373: 	&output_ics_file($r);
  374: 	return OK;
  375:     }
  376:     &Apache::loncommon::content_type($r,'text/html');
  377:     $r->send_http_header;
  378:     return OK if $r->header_only;
  379: 
  380: # ---------------------------------------------------------- Get time right now
  381:     my $today=time;
  382:     %todayhash=&Apache::loncommon::timehash($today);
  383: # ----------------------------------------------------------------- Check marks
  384:     undef(%showedcheck);
  385: # ---------------------------------------------------------- Get month and year
  386:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  387:                              ['month','year','pickdate','formname','element']);
  388: # --------------------------------------------------- Decide what month to show
  389:     my $year=$todayhash{'year'};
  390:     if ($env{'form.year'}) { $year=$env{'form.year'}; }
  391:     my $month=$todayhash{'month'};
  392:     if ($env{'form.month'}) { $month=$env{'form.month'}; }
  393: 
  394: # ---------------------------------------------- See if we are in pickdate mode
  395:     my $pickdatemode=($env{'form.pickdate'} eq 'yes');
  396:     my $pickinfo='&pickdate=yes&formname='.$env{'form.formname'}.
  397: 	'&element='.$env{'form.element'};
  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,
  404:                                      'dlsav' => -1 ));
  405:     my $weekday=$firstday{'weekday'};
  406: # ------------------------------------------------------------ Print the screen
  407:     my $js = <<ENDDOCUMENT;
  408: <script type="text/javascript">
  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>
  420: ENDDOCUMENT
  421: 
  422:     if ($pickdatemode) {
  423: # no big header in pickdate mode
  424: 	$r->print(&Apache::loncommon::start_page("Pick a Date",$js,
  425: 						 {'only_body' => 1,}).
  426: 		  &dialscript().
  427: 		  '<font size="1">');
  428:     } else {
  429:        $r->print(&Apache::loncommon::start_page("Announcements and Calendar",
  430: 						$js));
  431:     }
  432: # does this user have privileges to post, etc?
  433:     my $allowed=0;
  434:     if ($env{'request.course.id'}) {
  435:        $allowed=&Apache::lonnet::allowed('srm',$env{'request.course.id'});
  436:     }
  437: # does this user have privileges to post to servers?
  438:     my $serverpost=0;
  439:     if ($env{'request.role.domain'}) {
  440: 	$serverpost=&Apache::lonnet::allowed('psa',
  441: 					     $env{'request.role.domain'});
  442:     } else {
  443: 	$serverpost=&Apache::lonnet::allowed('psa','/');
  444:     }
  445: # -------------------------------- BUT: do no fancy stuff when in pickdate mode
  446:     if ($pickdatemode) { 
  447: 	$serverpost=0; 
  448: 	$allowed=0;
  449:     }
  450: # ------------------------------------------------------------ Process commands
  451:     if ($serverpost) {
  452: 	if ($env{'form.serveraction'}) {
  453: 	    foreach my $key (keys(%env)) {
  454: 		if ($key=~/^form\.postto\_(\w+)/) {
  455: 		    $r->print( 
  456: 			'<br />Posting '.$1.': '.&Apache::lonnet::postannounce
  457: 			($1,$env{'form.serverannnounce'}));
  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
  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}.
  475: 		       '/announcement.txt" target="annowin">current</a>');
  476: 	}
  477:     }
  478:     $r->print(
  479:   '<br /><input type="submit" name="serveraction" value="Post"></form><hr />');
  480:     }
  481:     if ($allowed) {
  482:         my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
  483:         my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
  484: # ----------------------------------------------------- Store new submitted one
  485:         if ($env{'form.action'} eq 'new') {
  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:             }
  497: 	    &Apache::lonnet::put('calendar',{ 
  498: 		$startdate.'_'.$enddate => 
  499: 		    $env{'form.msg'} },$coursedom,$coursenum);
  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: 	   }
  507:         }
  508: # ---------------------------------------------------------------- Remove items
  509:         if ($env{'form.action'} eq 'del') {
  510: 	    my @delwhich=();
  511:             foreach my $key (keys(%env)) {
  512: 		if ($key=~/^form\.remove\_(.+)$/) {
  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:         
  523:         &editfield($r,$today,$tomorrow,'');
  524:     }
  525: # ----------------------------------------------------- Summarize all calendars
  526:     my %allcal=&get_all_calendars();
  527: # ------------------------------- Initialize table and forward backward buttons
  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); }
  531: 
  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>');
  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'}.
  542:  '&year='.$todayhash{'year'}.'">Current Month</a>'.
  543: 		  &Apache::loncommon::end_page());
  544: 	return OK;
  545:     }
  546: 
  547:     my $class = "LC_calendar";
  548:     if ($env{'form.pickdate'} eq 'yes') {
  549: 	$class .= " LC_calendar_pickdate";
  550:     }
  551:     $r->print(
  552:  '<a href="/adm/announcements?month='.$pm.'&year='.$py.
  553:  ($pickdatemode?$pickinfo:'').'">'.&mt('Previous Month').'</a> '.
  554:  '<a href="/adm/announcements?month='.$fm.'&year='.$fy.
  555:  ($pickdatemode?$pickinfo:'').'">'.&mt('Next Month').'</a>'.
  556:  '&nbsp;&nbsp;&nbsp;<a href="/adm/announcements?month='.$todayhash{'month'}.
  557:  '&year='.$todayhash{'year'}.
  558:  ($pickdatemode?$pickinfo:'').'">'.&mt('Current Month').'</a><p>'.
  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>');
  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++) { 
  576:         ($tk,$nm,$outp)=&showday($tk,0,%allcal);
  577:         $r->print($outp);
  578:     }
  579:     $r->print('</tr>');
  580: 
  581:     for (my $k=0;$k<=4;$k++) {
  582:         $r->print('<tr>');
  583:         for (my $i=0;$i<=6;$i++) {
  584:             ($tk,$nm,$outp)=&showday($tk,0,%allcal);
  585:             if ($month!=$nm) { $outp=&emptycell; }
  586:             $r->print($outp);
  587:         }
  588:         $r->print('</tr>');
  589:     }
  590: # ------------------------------------------------------------------- End table
  591:     $r->print('</table>');
  592: # ----------------------------------------------------------------- Check marks
  593:     undef(%showedcheck);
  594: # --------------------------------------------------------------- Remove button
  595:     if ($allowed) { $r->print('<input type="button" onClick="removesub()" value="Remove Checked Entries">'.
  596: 			      &Apache::loncommon::help_open_topic('Calendar_Remove_Announcement').'</form>'); }
  597:     $r->print('<p>'.
  598:  '<a href="/adm/announcements?month='.$pm.'&year='.$py.
  599:  ($pickdatemode?$pickinfo:'').'">'.&mt('Previous Month').'</a> '.
  600:  '<a href="/adm/announcements?month='.$fm.'&year='.$fy.
  601:  ($pickdatemode?$pickinfo:'').'">'.&mt('Next Month').'</a>'.
  602:  '&nbsp;&nbsp;&nbsp;<a href="/adm/announcements?month='.$todayhash{'month'}.
  603:  '&year='.$todayhash{'year'}.
  604:  ($pickdatemode?$pickinfo:'').'">'.&mt('Current Month').'</a></p>'.
  605:  ($pickdatemode?'</font>':'').&Apache::loncommon::end_page());
  606:     $r->print('<a href="/adm/announcements.ics">'.&mt('Download your Calendar as iCalendar File').'</a>');
  607:     return OK;
  608: } 
  609: 
  610: 1;
  611: __END__

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