File:  [LON-CAPA] / loncom / interface / lonannounce.pm
Revision 1.59: download - view: text, annotated - select for diffs
Mon Jul 3 15:30:52 2006 UTC (18 years ago) by www
Branches: MAIN
CVS tags: version_2_2_0, version_2_1_99_3, version_2_1_99_2, version_2_1_99_1, HEAD
Bug #4850: don't display filenames or symbs as titles in announcements, but do
display the fact that there is a deadline, etc.

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

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