File:  [LON-CAPA] / loncom / interface / lonannounce.pm
Revision 1.56: download - view: text, annotated - select for diffs
Thu Jun 29 15:23:59 2006 UTC (18 years ago) by albertel
Branches: MAIN
CVS tags: HEAD
- BUG#4850, restore titles to calaendar events associated with resources, but retian the speedups of doing delayed gettile

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

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