Annotation of loncom/interface/lonannounce.pm, revision 1.50

1.1       www         1: # The LearningOnline Network
1.2       www         2: # Announce
1.1       www         3: #
1.50    ! albertel    4: # $Id: lonannounce.pm,v 1.49 2006/04/22 16:32:55 albertel Exp $
1.1       www         5: #
1.3       www         6: # Copyright Michigan State University Board of Trustees
1.1       www         7: #
1.3       www         8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
1.1       www         9: #
1.3       www        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.
1.1       www        14: #
1.3       www        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: 
1.2       www        29: package Apache::lonannounce;
1.1       www        30: 
                     31: use strict;
                     32: use Apache::Constants qw(:common);
1.3       www        33: use Apache::loncommon;
1.8       matthew    34: use Apache::lonhtmlcommon();
1.20      www        35: use Apache::lonlocal;
1.43      albertel   36: use Apache::lonnavmaps();
1.36      www        37: use Apache::lonrss();
1.34      albertel   38: use Apache::lonnet;
1.15      www        39: use HTML::Entities();
1.3       www        40: 
1.12      www        41: my %todayhash;
1.16      www        42: my %showedcheck;
1.12      www        43: 
1.10      www        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);
1.29      albertel   53:     my $help=&Apache::loncommon::help_open_menu('','Calendar Add Announcement','Calendar_Add_Announcement','',274,'Communication Tools');
1.36      www        54:     my %lt=&Apache::lonlocal::texthash('post' => 'Post Announcement',
                     55: 				       'start' => 'Starting date',
                     56: 				       'end' => 'Ending date',
1.37      www        57: 				       'incrss' => 'Include in course RSS newsfeed');
1.36      www        58: 
1.10      www        59:     $r->print(<<ENDFORM);
1.25      www        60: $help
1.10      www        61: <form name="anno" method="post">
1.36      www        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>
1.10      www        65: <textarea name="msg" rows="4" cols="60">$text</textarea>
1.36      www        66: <br />
1.46      albertel   67: <label><input type="checkbox" name="rsspost" /> $lt{'incrss'}</label>
1.36      www        68: <br /><input type="button" onClick="trysubmit()" value="$lt{'post'}" /><hr />
1.10      www        69: ENDFORM
                     70: }
                     71: 
1.3       www        72: sub readcalendar {
                     73:     my $courseid=shift;
1.34      albertel   74:     my $coursenum=$env{'course.'.$courseid.'.num'};
                     75:     my $coursedom=$env{'course.'.$courseid.'.domain'};
1.3       www        76:     my %thiscal=&Apache::lonnet::dump('calendar',$coursedom,$coursenum);
                     77:     my %returnhash=();
1.42      albertel   78:     foreach my $item (keys(%thiscal)) {
                     79:         unless (($item=~/^error\:/) || ($thiscal{$item}=~/^error\:/)) {
                     80: 	   $returnhash{$courseid.'@'.$item}=$thiscal{$item};
1.3       www        81:         }
                     82:     }
1.43      albertel   83: 
1.34      albertel   84:     if ($courseid eq $env{'request.course.id'}) {
1.43      albertel   85: 	my $can_see_hidden = $env{'request.role.adv'};
                     86: 	my $navmap = Apache::lonnavmaps::navmap->new();
1.26      www        87: 	my %resourcedata=
                     88: 	    &Apache::lonnet::dump('resourcedata',$coursedom,$coursenum);
                     89: 	foreach my $thiskey (sort keys %resourcedata) {
                     90: 	    if ($resourcedata{$thiskey.'.type'}=~/^date/) {
                     91: 		my ($course,$middle,$part,$name)=
                     92: 		    ($thiskey=~/^(\w+)\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/);
                     93: 		my $section=&mt('All Students');
                     94: 		if ($middle=~/^\[(.*)\]\./) {
1.31      albertel   95: 		    my $sec=$1;
                     96: 		    # if we have a section don't show ones that aren't ours
1.34      albertel   97: 		    if ($env{'request.course.sec'} &&
                     98: 			$env{'request.course.sec'} ne $sec) { next; }
1.31      albertel   99: 		    # if a student without a section don't show any section ones
1.34      albertel  100: 		    if (!$env{'request.role.adv'} &&
                    101: 			!$env{'request.course.sec'}) { next; }
1.26      www       102: 		    $section=&mt('Group/Section').': '.$1;
                    103: 		    $middle=~s/^\[(.*)\]\.//;
                    104: 		}
                    105: 		$middle=~s/\.$//;
                    106: 		my $realm=&mt('All Resources');
                    107: 		if ($middle=~/^(.+)\_\_\_\(all\)$/) {
1.43      albertel  108: 		    my $map_url=$1;
1.45      albertel  109: 		    if (!$can_see_hidden && !$navmap) {
                    110: 			next;
                    111: 		    }
1.43      albertel  112: 		    if (!$can_see_hidden) {
                    113: 			my $res = $navmap->getResourceByUrl($map_url);
1.44      albertel  114: 			if ($res && $res->randomout()) { next; }
1.43      albertel  115: 		    }
                    116: 		    $realm=&mt('Folder/Map').': '.&Apache::lonnet::gettitle($map_url);
1.26      www       117: 		} elsif ($middle) {
1.45      albertel  118: 		    if (!$can_see_hidden && !$navmap) {
                    119: 			next;
                    120: 		    }
1.43      albertel  121: 		    if (!$can_see_hidden) {
                    122: 			my $res = $navmap->getBySymb($middle);
1.44      albertel  123: 			if ($res && $res->randomout()) { next; }
1.43      albertel  124: 		    }
1.26      www       125: 		    $realm=&mt('Resource').': '.&Apache::lonnet::gettitle($middle);
                    126: 		}
                    127: 		my $datetype='';
1.28      www       128: 		if ($name eq 'duedate') { 
                    129: 		    $datetype=&mt('Due'); 
                    130: # see if accidentally answerdate is before duedate
                    131: 		    my $answerkey=$thiskey;
                    132: 		    $answerkey=~s/duedate$/answerdate/;
                    133: 		    if ($resourcedata{$thiskey}>$resourcedata{$answerkey}) {
                    134: 			$datetype='Due and Answer Available';
                    135: 		    }
                    136: 		}
1.26      www       137: 		if ($name eq 'opendate') { $datetype=&mt('Opening'); }
1.28      www       138: 		if ($name eq 'answerdate') {
                    139: # see if accidentally answerdate is before duedate
                    140: 		    my $duekey=$thiskey;
                    141: 		    $duekey=~s/answerdate$/duedate/;
                    142: 		    if ($resourcedata{$duekey}>$resourcedata{$thiskey}) {
                    143: # forget it
                    144: 			next;
                    145: 		    } 
                    146: 		    $datetype=&mt('Answer Available'); 
                    147: 		}
1.26      www       148: 		$returnhash{$courseid.'@'.$resourcedata{$thiskey}.'_'.
                    149: 			    $resourcedata{$thiskey}}=
                    150: 			    'INTERNAL:'.$datetype.': '.$realm.' ('.$section.')';
                    151: 	    }
                    152: 	}
                    153:     }
1.3       www       154:     return %returnhash;
                    155: }
                    156: 
                    157: sub emptycell {
1.49      albertel  158:     return '<td class="LC_calendar_day_empty">&nbsp;</td>';
1.3       www       159: }
                    160: 
                    161: sub normalcell {
1.12      www       162:     my ($day,$month,$year,$text)=@_;
1.4       www       163:     my $output='';
1.40      albertel  164:     my @items=&order($text);
                    165:     foreach my $item (@items) {
                    166:         if ($item) {
1.26      www       167: 	    my $internalflag=0;
1.41      albertel  168: 	    my ($courseid,$start,$end,$msg)=split(/\@/,$item,4);
1.26      www       169: 	    if ($msg=~/INTERNAL\:/) {
                    170: 		$msg=~s/INTERNAL\://gs;
                    171: 		$internalflag=1;
                    172: 	    }
1.34      albertel  173:             my $fullmsg=&mt('Calendar Announcement for ').$env{'course.'.$courseid.'.description'}.
1.32      www       174: 		'\n'.&Apache::lonlocal::locallocaltime($start);
1.26      www       175: 	    if ($start!=$end) {
                    176: 		$fullmsg.=' - '.&Apache::lonlocal::locallocaltime($end);
                    177: 	    }
1.32      www       178: 	    $fullmsg.=':\n'.$msg;
1.34      albertel  179:             if ($courseid eq $env{'request.course.id'}) {
                    180:               if ((&Apache::lonnet::allowed('srm',$env{'request.course.id'}))
1.19      www       181:                && (!$showedcheck{$start.'_'.$end})
1.34      albertel  182: 	       && ($env{'form.pickdate'} ne 'yes')
1.26      www       183: 	       && (!$internalflag)) {
1.5       www       184:                $output.='<input type="checkbox" name="remove_'.$start.'_'.
                    185: 		   $end.'">';
1.16      www       186:                $showedcheck{$start.'_'.$end}=1;
1.5       www       187: 	      }
                    188: 	    }
1.32      www       189: 	    $fullmsg=~s/[\n\r]/\\n/gs;
1.15      www       190:             $fullmsg=&HTML::Entities::encode($fullmsg,'<>&"\'');
                    191:             $fullmsg=~s/&/\\&/g;
1.50    ! albertel  192: 	    my $short_msg = substr($msg,0,20).((length($msg) > 20)?'...':'');
1.5       www       193:             $output.='<a href="javascript:alert('."'$fullmsg'".')">'.
1.50    ! albertel  194: 	       $short_msg.'</a><br />';
1.4       www       195:        }
                    196:     }
1.49      albertel  197:     return '<td class="LC_calendar_day'.
1.12      www       198: 	((($day eq $todayhash{'day'}) &&
                    199:           ($month eq $todayhash{'month'}) &&
1.49      albertel  200:           ($year eq $todayhash{'year'}))?'_current':'').
                    201:            '" ><b>'.&picklink($day,$day,$month,$year).'</b><br />'.$output.'</td>';
1.3       www       202: }
                    203: 
1.11      www       204: sub plaincell {
                    205:     my ($text)=@_;
                    206:     my $output='';
1.40      albertel  207:     my @items=&order($text);
                    208:     foreach my $item (@items) {
                    209:         if ($item) {
1.41      albertel  210: 	    my ($courseid,$start,$end,$msg)=split(/\@/,$item,4);
1.34      albertel  211:             my $fullmsg=&mt('Calendar Announcement for ').$env{'course.'.$courseid.'.description'}.
1.32      www       212: 		'\n'.&Apache::lonlocal::locallocaltime($start);
1.26      www       213: 	    if ($start!=$end) {
                    214: 		$fullmsg.=' - '.&Apache::lonlocal::locallocaltime($end);
                    215: 	    }
1.27      www       216: 	    $msg=~s/INTERNAL\://gs;
1.32      www       217: 	    $fullmsg.=':\n'.$msg;
                    218:  	    $fullmsg=~s/[\n\r]/\\n/gs;
1.15      www       219:             $fullmsg=&HTML::Entities::encode($fullmsg,'<>&"\'');
                    220:             $fullmsg=~s/&/\\&/g;
1.11      www       221:             $output.='<a href="javascript:alert('."'$fullmsg'".')">'.
1.35      www       222: 	       substr($msg,0,80).'...</a><br />';
1.11      www       223:        }
                    224:     }
                    225:     return $output;
                    226: }
                    227: 
                    228: sub listcell {
                    229:     my ($text)=@_;
                    230:     my $output='';
1.40      albertel  231:     my @items=&order($text);
                    232:     foreach my $item (@items) {
                    233:         if ($item) {
1.41      albertel  234: 	    my ($courseid,$start,$end,$msg)=split(/\@/,$item,4);
1.27      www       235: 	    $msg=~s/INTERNAL\://gs;
1.26      www       236:             my $fullmsg=&Apache::lonlocal::locallocaltime($start);
                    237: 	    if ($start!=$end) {
                    238: 		$fullmsg.=&mt(' to ').
                    239: 		    &Apache::lonlocal::locallocaltime($end);
                    240: 	    }
                    241:             $fullmsg.=':<br /><b>'.
1.11      www       242:                $msg.'</b>';
                    243:             $output.='<li>'.$fullmsg.'</li>';
                    244:        }
                    245:     }
                    246:     return $output;
                    247: }
                    248: 
1.40      albertel  249: sub order {
                    250:     my ($text)=@_;
                    251:     my @items = split(/___&&&___/,$text);
                    252:     sort {
                    253: 	my (undef,$astart,$aend)=split(/\@/,$a);
                    254: 	my (undef,$bstart,$bend)=split(/\@/,$b);
                    255: 	if ($astart != $bstart) {
                    256: 	    return $astart <=> $bstart;
                    257: 	}
                    258: 	return $aend <=> $bend;
                    259:     } @items;
                    260: }
                    261: 
1.3       www       262: sub nextday {
                    263:     my %th=@_;
                    264:     $th{'day'}++;
                    265:     return (&Apache::loncommon::maketime(%th),$th{'month'});
                    266: }
                    267: 
                    268: sub showday {
1.11      www       269:     my ($tk,$mode,%allcal)=@_;
1.3       www       270:     my %th=&Apache::loncommon::timehash($tk);
                    271:     my ($nextday,$nextmonth)=&nextday(%th);
                    272:     my $outp='';
1.27      www       273:     if ($mode) {
                    274: 	my $oneday=24*3600;
                    275: 	$tk-=$oneday;
                    276: 	$nextday+=$oneday;
                    277:     }
1.40      albertel  278:     foreach my $item (keys(%allcal)) {
                    279: 	my ($course,$startdate,$enddate)=($item=~/^(\w+)\@(\d+)\_(\d+)$/);
1.39      albertel  280:         if (($startdate<$nextday) && ($enddate>=$tk))  {
1.5       www       281: 	    $outp.='___&&&___'.$course.'@'.$startdate.'@'.$enddate.'@'.
1.40      albertel  282:             $allcal{$item};
1.3       www       283:         }
                    284:     }
1.11      www       285:     unless ($mode) {
1.12      www       286:        return ($nextday,$nextmonth,&normalcell(
                    287:                $th{'day'},$th{'month'},$th{'year'},$outp));
1.11      www       288:    } elsif ($outp) {
                    289:        if ($mode==1) {
                    290:           return '<br />'.&plaincell($outp);
                    291:       } else {
                    292:           return '<ul>'.&listcell($outp).'</ul>';
                    293:       }
                    294:    } else {
                    295:        return '';
                    296:    }
1.3       www       297: }
1.1       www       298: 
1.19      www       299: sub picklink {
                    300:     my ($text,$day,$month,$year)=@_;
1.34      albertel  301:     if ($env{'form.pickdate'} eq 'yes') {
1.19      www       302: 	return '<a href="javascript:dialin('.$day.','.$month.','.$year.')">'.
                    303: 	    $text.'</a>';
                    304:     } else {
                    305: 	return $text;
                    306:     }
                    307: }
                    308: 
                    309: sub dialscript {
                    310:     return (<<ENDDIA);
                    311: <script language="Javascript">
                    312: function dialin(day,month,year) {
1.34      albertel  313: 	opener.document.$env{'form.formname'}.$env{'form.element'}\_year.value=year;
                    314:     var slct=opener.document.$env{'form.formname'}.$env{'form.element'}\_month;
1.19      www       315:     var i;
                    316:     for (i=0;i<slct.length;i++) {
                    317:         if (slct.options[i].value==month) { slct.selectedIndex=i; }
                    318:     }
1.34      albertel  319:     opener.document.$env{'form.formname'}.$env{'form.element'}\_day.value=day;
                    320:     opener.$env{'form.element'}\_checkday();
1.19      www       321:     self.close();
                    322: }
                    323: </script>
                    324: ENDDIA
                    325: }
                    326: 
1.1       www       327: sub handler {
                    328:     my $r = shift;
1.21      www       329:     &Apache::loncommon::content_type($r,'text/html');
1.1       www       330:     $r->send_http_header;
                    331:     return OK if $r->header_only;
                    332: 
1.3       www       333: # ---------------------------------------------------------- Get time right now
                    334:     my $today=time;
1.12      www       335:     %todayhash=&Apache::loncommon::timehash($today);
1.16      www       336: # ----------------------------------------------------------------- Check marks
1.49      albertel  337:     undef(%showedcheck);
1.3       www       338: # ---------------------------------------------------------- Get month and year
                    339:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.19      www       340:                              ['month','year','pickdate','formname','element']);
1.3       www       341: # --------------------------------------------------- Decide what month to show
                    342:     my $year=$todayhash{'year'};
1.34      albertel  343:     if ($env{'form.year'}) { $year=$env{'form.year'}; }
1.3       www       344:     my $month=$todayhash{'month'};
1.34      albertel  345:     if ($env{'form.month'}) { $month=$env{'form.month'}; }
1.18      www       346: 
                    347: # ---------------------------------------------- See if we are in pickdate mode
1.34      albertel  348:     my $pickdatemode=($env{'form.pickdate'} eq 'yes');
                    349:     my $pickinfo='&pickdate=yes&formname='.$env{'form.formname'}.
                    350: 	'&element='.$env{'form.element'};
1.3       www       351: # --------------------------------------------- Find out first day of the month
                    352: 
                    353:     my %firstday=&Apache::loncommon::timehash(
                    354:        &Apache::loncommon::maketime( 'day' => 1, 'month'=> $month,
                    355:                                      'year' => $year, 'hours' => 0,
                    356: 				     'minutes' => 0, 'seconds' => 0,
1.30      www       357:                                      'dlsav' => -1 ));
1.3       www       358:     my $weekday=$firstday{'weekday'};
                    359: # ------------------------------------------------------------ Print the screen
1.47      albertel  360:     my $js = <<ENDDOCUMENT;
                    361: <script type="text/javascript">
1.3       www       362: 
                    363:     function trysubmit() {
                    364:         document.anno.action.value="new";
                    365: 	document.anno.submit();
                    366:     }
                    367: 
                    368:     function removesub() {
                    369:         document.anno.action.value="del";
                    370: 	document.anno.submit();
                    371:     }
                    372: </script>
1.1       www       373: ENDDOCUMENT
1.47      albertel  374: 
1.18      www       375:     if ($pickdatemode) {
                    376: # no big header in pickdate mode
1.47      albertel  377: 	$r->print(&Apache::loncommon::start_page("Pick a Date",$js,
                    378: 						 {'only_body' => 1,}).
1.19      www       379: 		  &dialscript().
1.18      www       380: 		  '<font size="1">');
                    381:     } else {
1.47      albertel  382:        $r->print(&Apache::loncommon::start_page("Announcements and Calendar",
                    383: 						$js));
1.18      www       384:     }
1.3       www       385: # does this user have privileges to post, etc?
                    386:     my $allowed=0;
1.34      albertel  387:     if ($env{'request.course.id'}) {
                    388:        $allowed=&Apache::lonnet::allowed('srm',$env{'request.course.id'});
1.3       www       389:     }
1.17      www       390: # does this user have privileges to post to servers?
                    391:     my $serverpost=0;
1.34      albertel  392:     if ($env{'request.role.domain'}) {
1.17      www       393: 	$serverpost=&Apache::lonnet::allowed('psa',
1.34      albertel  394: 					     $env{'request.role.domain'});
1.17      www       395:     } else {
                    396: 	$serverpost=&Apache::lonnet::allowed('psa','/');
                    397:     }
1.18      www       398: # -------------------------------- BUT: do no fancy stuff when in pickdate mode
                    399:     if ($pickdatemode) { 
                    400: 	$serverpost=0; 
                    401: 	$allowed=0;
                    402:     }
1.17      www       403: # ------------------------------------------------------------ Process commands
                    404:     if ($serverpost) {
1.34      albertel  405: 	if ($env{'form.serveraction'}) {
1.42      albertel  406: 	    foreach my $key (keys(%env)) {
                    407: 		if ($key=~/^form\.postto\_(\w+)/) {
1.17      www       408: 		    $r->print( 
                    409: 			'<br />Posting '.$1.': '.&Apache::lonnet::postannounce
1.34      albertel  410: 			($1,$env{'form.serverannnounce'}));
1.17      www       411: 		}
                    412: 	    }
                    413: 	}
                    414: 	$r->print(<<SERVERANNOUNCE);
                    415: <form name="serveranno" method="post">
                    416: <h3>Post Server Announcements</h3>
                    417: Post announcements to the system login and roles screen<br />
                    418: <i>(leave blank to delete announcement)</i><br />
                    419: <textarea name="serverannnounce" cols="60" rows="5"></textarea><br />
                    420: Check machines:<br />
                    421: SERVERANNOUNCE
                    422: # list servers
1.42      albertel  423:     foreach my $host (sort(keys(%Apache::lonnet::hostname))) {
                    424: 	if (&Apache::lonnet::allowed('psa',$Apache::lonnet::hostdom{$host})) {
                    425: 	    $r->print ('<br /><input type="checkbox" name="postto_'.$host.'" /> '.
                    426: 		       $host.' <tt>'.$Apache::lonnet::hostname{$host}.'</tt> '.
                    427: 		       '<a href="http://'.$Apache::lonnet::hostname{$host}.
1.17      www       428: 		       '/announcement.txt" target="annowin">current</a>');
                    429: 	}
                    430:     }
                    431:     $r->print(
                    432:   '<br /><input type="submit" name="serveraction" value="Post"></form><hr />');
                    433:     }
1.3       www       434:     if ($allowed) {
1.34      albertel  435:         my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
                    436:         my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.3       www       437: # ----------------------------------------------------- Store new submitted one
1.34      albertel  438:         if ($env{'form.action'} eq 'new') {
1.9       www       439: 	    my $startdate = 
                    440: 		&Apache::lonhtmlcommon::get_date_from_form('startdate');
                    441: 	    my $enddate   = 
                    442: 		&Apache::lonhtmlcommon::get_date_from_form('enddate');
                    443: 	    unless ($startdate=~/^\d+$/) { $startdate=time; }
                    444:             unless ($enddate=~/^\d+$/) { $enddate=$startdate+1; }
                    445:             if ($startdate>$enddate) {
                    446: 		my $buffer=$startdate;
                    447: 		$startdate=$enddate;
                    448: 		$enddate=$buffer;
                    449:             }
1.3       www       450: 	    &Apache::lonnet::put('calendar',{ 
1.9       www       451: 		$startdate.'_'.$enddate => 
1.34      albertel  452: 		    $env{'form.msg'} },$coursedom,$coursenum);
1.36      www       453: 	    if ($env{'form.rsspost'}) {
                    454:                &Apache::lonrss::addentry($coursenum,$coursedom,'Course_Announcements',
                    455: 					 &mt('Event from [_1] to [_2]',
                    456: 					     &Apache::lonlocal::locallocaltime($startdate),
                    457: 					     &Apache::lonlocal::locallocaltime($enddate)),
                    458: 					 $env{'form.msg'},'/adm/announcements','public');
                    459: 	   }
1.3       www       460:         }
                    461: # ---------------------------------------------------------------- Remove items
1.34      albertel  462:         if ($env{'form.action'} eq 'del') {
1.3       www       463: 	    my @delwhich=();
1.42      albertel  464:             foreach my $key (keys(%env)) {
                    465: 		if ($key=~/^form\.remove\_(.+)$/) {
1.3       www       466: 		    push(@delwhich,$1);
                    467:                 }
                    468:             }
                    469:             &Apache::lonnet::del('calendar',\@delwhich,$coursedom,$coursenum);
                    470:         }
                    471: # -------------------------------------------------------- Form to post new one
                    472:         my %tomorrowhash=%todayhash;
                    473:         $tomorrowhash{'day'}++;
                    474:         my $tomorrow=&Apache::loncommon::maketime(%tomorrowhash);
                    475:         
1.10      www       476:         &editfield($r,$today,$tomorrow,'');
1.3       www       477:     }
1.5       www       478: # ----------------------------------------------------- Summarize all calendars
                    479:     my %allcal=();
1.49      albertel  480:     foreach my $course (sort(&Apache::loncommon::findallcourses())) {
1.42      albertel  481: 	%allcal=(%allcal,&readcalendar($course));
1.5       www       482:     }
                    483: 
                    484: # ------------------------------- Initialize table and forward backward buttons
1.3       www       485:     my ($pm,$py,$fm,$fy)=($month-1,$year,$month+1,$year);
                    486:     if ($pm<1) { ($pm,$py)=(12,$year-1); }
                    487:     if ($fm>12){ ($fm,$fy)=(1,$year+1); }
1.14      www       488: 
1.20      www       489:     $r->print('<h1>'.('',&mt('January'),&mt('February'),&mt('March'),
                    490: 		      &mt('April'),&mt('May'),
                    491: 		      &mt('June'),&mt('July'),&mt('August'),
                    492:                       &mt('September'),&mt('October'),
                    493:                       &mt('November'),&mt('December'))[$month].' '.
                    494: 	              $year.'</h1>');
1.13      www       495: # Reached the end of times, give up
                    496:     if (($year<1970) || ($year>2037)) {
                    497: 	$r->print('<h3>No calendar available for this date.</h3>'.
                    498:  '<a href="/adm/announcements?month='.$todayhash{'month'}.
1.47      albertel  499:  '&year='.$todayhash{'year'}.'">Current Month</a>'.
                    500: 		  &Apache::loncommon::end_page());
1.13      www       501: 	return OK;
                    502:     }
1.49      albertel  503: 
                    504:     my $class = "LC_calendar";
                    505:     if ($env{'form.pickdate'} eq 'yes') {
                    506: 	$class .= " LC_calendar_pickdate";
                    507:     }
1.13      www       508:     $r->print(
1.18      www       509:  '<a href="/adm/announcements?month='.$pm.'&year='.$py.
1.20      www       510:  ($pickdatemode?$pickinfo:'').'">'.&mt('Previous Month').'</a> '.
1.18      www       511:  '<a href="/adm/announcements?month='.$fm.'&year='.$fy.
1.20      www       512:  ($pickdatemode?$pickinfo:'').'">'.&mt('Next Month').'</a>'.
1.12      www       513:  '&nbsp;&nbsp;&nbsp;<a href="/adm/announcements?month='.$todayhash{'month'}.
1.18      www       514:  '&year='.$todayhash{'year'}.
1.20      www       515:  ($pickdatemode?$pickinfo:'').'">'.&mt('Current Month').'</a><p>'.
1.49      albertel  516:         '<table class="'.$class.'" cols="7" rows="5"><tr>
                    517: <th>'.&mt('Sun').'</th>
                    518: <th>'.&mt('Mon').'</th>
                    519: <th>'.&mt('Tue').'</th>
                    520: <th>'.&mt('Wed').'</th>
                    521: <th>'.&mt('Thu').'</th>
                    522: <th>'.&mt('Fri').'</th>
                    523: <th>'.&mt('Sat').'</th></tr>');
1.3       www       524: 
                    525:     my $tk=&Apache::loncommon::maketime(%firstday);
                    526:     my $outp;
                    527:     my $nm;
                    528: 
                    529: # ---------------------------------------------------------------- Actual table
                    530:     $r->print('<tr>');
                    531:     for (my $i=0;$i<$weekday;$i++) { $r->print(&emptycell); }
                    532:     for (my $i=$weekday;$i<=6;$i++) { 
1.11      www       533:         ($tk,$nm,$outp)=&showday($tk,0,%allcal);
1.3       www       534:         $r->print($outp);
                    535:     }
                    536:     $r->print('</tr>');
                    537: 
1.23      www       538:     for (my $k=0;$k<=4;$k++) {
1.3       www       539:         $r->print('<tr>');
                    540:         for (my $i=0;$i<=6;$i++) {
1.11      www       541:             ($tk,$nm,$outp)=&showday($tk,0,%allcal);
1.3       www       542:             if ($month!=$nm) { $outp=&emptycell; }
                    543:             $r->print($outp);
                    544:         }
                    545:         $r->print('</tr>');
                    546:     }
                    547: # ------------------------------------------------------------------- End table
1.7       matthew   548:     $r->print('</table>');
1.16      www       549: # ----------------------------------------------------------------- Check marks
1.49      albertel  550:     undef(%showedcheck);
1.16      www       551: # --------------------------------------------------------------- Remove button
1.24      www       552:     if ($allowed) { $r->print('<input type="button" onClick="removesub()" value="Remove Checked Entries">'.
                    553: 			      &Apache::loncommon::help_open_topic('Calendar_Remove_Announcement').'</form>'); }
1.7       matthew   554:     $r->print('<p>'.
1.18      www       555:  '<a href="/adm/announcements?month='.$pm.'&year='.$py.
1.20      www       556:  ($pickdatemode?$pickinfo:'').'">'.&mt('Previous Month').'</a> '.
1.18      www       557:  '<a href="/adm/announcements?month='.$fm.'&year='.$fy.
1.20      www       558:  ($pickdatemode?$pickinfo:'').'">'.&mt('Next Month').'</a>'.
1.12      www       559:  '&nbsp;&nbsp;&nbsp;<a href="/adm/announcements?month='.$todayhash{'month'}.
1.18      www       560:  '&year='.$todayhash{'year'}.
1.20      www       561:  ($pickdatemode?$pickinfo:'').'">'.&mt('Current Month').'</a></p>'.
1.47      albertel  562:  ($pickdatemode?'</font>':'').&Apache::loncommon::end_page());
1.1       www       563:     return OK;
                    564: } 
                    565: 
                    566: 1;
                    567: __END__

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