File:  [LON-CAPA] / loncom / interface / lonannounce.pm
Revision 1.58: download - view: text, annotated - select for diffs
Mon Jul 3 03:11:07 2006 UTC (17 years, 10 months ago) by albertel
Branches: MAIN
CVS tags: version_2_1_99_0, HEAD
- temp workaround for BUG#4850

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

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