File:  [LON-CAPA] / loncom / interface / lonannounce.pm
Revision 1.62: download - view: text, annotated - select for diffs
Wed Nov 29 07:46:39 2006 UTC (17 years, 7 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
evb privilege - with this privilege users evade blocking of communication functionality defined by blocks placed by users with dcm privilege.

dcm privilege - this is now used to determine if link to block setting is displayed.

loncommon::findallcourses() now return a hash, where the keys are courseIDs instead of an array of courseIDs.  Places where findallcourses() was called - lonannounce, lonpickcourse changed accordingly.

loncommon::findallcourses() now reports courses for a user where the user's only role was a custom role.

lonnet::allowed() can now take a fourth optional argument ($role) which allows privs to be investigated for roles other than the user's currently active role

&blockcheck, &parse_block_record(), and &build_block_table() moved from lonmsgdisplay to loncommon, so they are available for evaluation of blocking state for other communication functions besides COM.

Each block record for a blocking event in a course is now a hash, with key=values of the hash being setter = username:domain of user who set block, title=event title for block, and blocks = hash of blocked features ('com','chat','boards','port','groups').

Backwards compatibility retained with previous : separated text for block record value.

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

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