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

1.1       www         1: # The LearningOnline Network
1.2       www         2: # Announce
1.1       www         3: #
1.49    ! albertel    4: # $Id: lonannounce.pm,v 1.48 2006/03/23 22:32:10 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.5       www       192:             $output.='<a href="javascript:alert('."'$fullmsg'".')">'.
1.11      www       193: 	       substr($msg,0,20).'...</a><br />';
1.4       www       194:        }
                    195:     }
1.49    ! albertel  196:     return '<td class="LC_calendar_day'.
1.12      www       197: 	((($day eq $todayhash{'day'}) &&
                    198:           ($month eq $todayhash{'month'}) &&
1.49    ! albertel  199:           ($year eq $todayhash{'year'}))?'_current':'').
        !           200:            '" ><b>'.&picklink($day,$day,$month,$year).'</b><br />'.$output.'</td>';
1.3       www       201: }
                    202: 
1.11      www       203: sub plaincell {
                    204:     my ($text)=@_;
                    205:     my $output='';
1.40      albertel  206:     my @items=&order($text);
                    207:     foreach my $item (@items) {
                    208:         if ($item) {
1.41      albertel  209: 	    my ($courseid,$start,$end,$msg)=split(/\@/,$item,4);
1.34      albertel  210:             my $fullmsg=&mt('Calendar Announcement for ').$env{'course.'.$courseid.'.description'}.
1.32      www       211: 		'\n'.&Apache::lonlocal::locallocaltime($start);
1.26      www       212: 	    if ($start!=$end) {
                    213: 		$fullmsg.=' - '.&Apache::lonlocal::locallocaltime($end);
                    214: 	    }
1.27      www       215: 	    $msg=~s/INTERNAL\://gs;
1.32      www       216: 	    $fullmsg.=':\n'.$msg;
                    217:  	    $fullmsg=~s/[\n\r]/\\n/gs;
1.15      www       218:             $fullmsg=&HTML::Entities::encode($fullmsg,'<>&"\'');
                    219:             $fullmsg=~s/&/\\&/g;
1.11      www       220:             $output.='<a href="javascript:alert('."'$fullmsg'".')">'.
1.35      www       221: 	       substr($msg,0,80).'...</a><br />';
1.11      www       222:        }
                    223:     }
                    224:     return $output;
                    225: }
                    226: 
                    227: sub listcell {
                    228:     my ($text)=@_;
                    229:     my $output='';
1.40      albertel  230:     my @items=&order($text);
                    231:     foreach my $item (@items) {
                    232:         if ($item) {
1.41      albertel  233: 	    my ($courseid,$start,$end,$msg)=split(/\@/,$item,4);
1.27      www       234: 	    $msg=~s/INTERNAL\://gs;
1.26      www       235:             my $fullmsg=&Apache::lonlocal::locallocaltime($start);
                    236: 	    if ($start!=$end) {
                    237: 		$fullmsg.=&mt(' to ').
                    238: 		    &Apache::lonlocal::locallocaltime($end);
                    239: 	    }
                    240:             $fullmsg.=':<br /><b>'.
1.11      www       241:                $msg.'</b>';
                    242:             $output.='<li>'.$fullmsg.'</li>';
                    243:        }
                    244:     }
                    245:     return $output;
                    246: }
                    247: 
1.40      albertel  248: sub order {
                    249:     my ($text)=@_;
                    250:     my @items = split(/___&&&___/,$text);
                    251:     sort {
                    252: 	my (undef,$astart,$aend)=split(/\@/,$a);
                    253: 	my (undef,$bstart,$bend)=split(/\@/,$b);
                    254: 	if ($astart != $bstart) {
                    255: 	    return $astart <=> $bstart;
                    256: 	}
                    257: 	return $aend <=> $bend;
                    258:     } @items;
                    259: }
                    260: 
1.3       www       261: sub nextday {
                    262:     my %th=@_;
                    263:     $th{'day'}++;
                    264:     return (&Apache::loncommon::maketime(%th),$th{'month'});
                    265: }
                    266: 
                    267: sub showday {
1.11      www       268:     my ($tk,$mode,%allcal)=@_;
1.3       www       269:     my %th=&Apache::loncommon::timehash($tk);
                    270:     my ($nextday,$nextmonth)=&nextday(%th);
                    271:     my $outp='';
1.27      www       272:     if ($mode) {
                    273: 	my $oneday=24*3600;
                    274: 	$tk-=$oneday;
                    275: 	$nextday+=$oneday;
                    276:     }
1.40      albertel  277:     foreach my $item (keys(%allcal)) {
                    278: 	my ($course,$startdate,$enddate)=($item=~/^(\w+)\@(\d+)\_(\d+)$/);
1.39      albertel  279:         if (($startdate<$nextday) && ($enddate>=$tk))  {
1.5       www       280: 	    $outp.='___&&&___'.$course.'@'.$startdate.'@'.$enddate.'@'.
1.40      albertel  281:             $allcal{$item};
1.3       www       282:         }
                    283:     }
1.11      www       284:     unless ($mode) {
1.12      www       285:        return ($nextday,$nextmonth,&normalcell(
                    286:                $th{'day'},$th{'month'},$th{'year'},$outp));
1.11      www       287:    } elsif ($outp) {
                    288:        if ($mode==1) {
                    289:           return '<br />'.&plaincell($outp);
                    290:       } else {
                    291:           return '<ul>'.&listcell($outp).'</ul>';
                    292:       }
                    293:    } else {
                    294:        return '';
                    295:    }
1.3       www       296: }
1.1       www       297: 
1.19      www       298: sub picklink {
                    299:     my ($text,$day,$month,$year)=@_;
1.34      albertel  300:     if ($env{'form.pickdate'} eq 'yes') {
1.19      www       301: 	return '<a href="javascript:dialin('.$day.','.$month.','.$year.')">'.
                    302: 	    $text.'</a>';
                    303:     } else {
                    304: 	return $text;
                    305:     }
                    306: }
                    307: 
                    308: sub dialscript {
                    309:     return (<<ENDDIA);
                    310: <script language="Javascript">
                    311: function dialin(day,month,year) {
1.34      albertel  312: 	opener.document.$env{'form.formname'}.$env{'form.element'}\_year.value=year;
                    313:     var slct=opener.document.$env{'form.formname'}.$env{'form.element'}\_month;
1.19      www       314:     var i;
                    315:     for (i=0;i<slct.length;i++) {
                    316:         if (slct.options[i].value==month) { slct.selectedIndex=i; }
                    317:     }
1.34      albertel  318:     opener.document.$env{'form.formname'}.$env{'form.element'}\_day.value=day;
                    319:     opener.$env{'form.element'}\_checkday();
1.19      www       320:     self.close();
                    321: }
                    322: </script>
                    323: ENDDIA
                    324: }
                    325: 
1.1       www       326: sub handler {
                    327:     my $r = shift;
1.21      www       328:     &Apache::loncommon::content_type($r,'text/html');
1.1       www       329:     $r->send_http_header;
                    330:     return OK if $r->header_only;
                    331: 
1.3       www       332: # ---------------------------------------------------------- Get time right now
                    333:     my $today=time;
1.12      www       334:     %todayhash=&Apache::loncommon::timehash($today);
1.16      www       335: # ----------------------------------------------------------------- Check marks
1.49    ! albertel  336:     undef(%showedcheck);
1.3       www       337: # ---------------------------------------------------------- Get month and year
                    338:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.19      www       339:                              ['month','year','pickdate','formname','element']);
1.3       www       340: # --------------------------------------------------- Decide what month to show
                    341:     my $year=$todayhash{'year'};
1.34      albertel  342:     if ($env{'form.year'}) { $year=$env{'form.year'}; }
1.3       www       343:     my $month=$todayhash{'month'};
1.34      albertel  344:     if ($env{'form.month'}) { $month=$env{'form.month'}; }
1.18      www       345: 
                    346: # ---------------------------------------------- See if we are in pickdate mode
1.34      albertel  347:     my $pickdatemode=($env{'form.pickdate'} eq 'yes');
                    348:     my $pickinfo='&pickdate=yes&formname='.$env{'form.formname'}.
                    349: 	'&element='.$env{'form.element'};
1.3       www       350: # --------------------------------------------- Find out first day of the month
                    351: 
                    352:     my %firstday=&Apache::loncommon::timehash(
                    353:        &Apache::loncommon::maketime( 'day' => 1, 'month'=> $month,
                    354:                                      'year' => $year, 'hours' => 0,
                    355: 				     'minutes' => 0, 'seconds' => 0,
1.30      www       356:                                      'dlsav' => -1 ));
1.3       www       357:     my $weekday=$firstday{'weekday'};
                    358: # ------------------------------------------------------------ Print the screen
1.47      albertel  359:     my $js = <<ENDDOCUMENT;
                    360: <script type="text/javascript">
1.3       www       361: 
                    362:     function trysubmit() {
                    363:         document.anno.action.value="new";
                    364: 	document.anno.submit();
                    365:     }
                    366: 
                    367:     function removesub() {
                    368:         document.anno.action.value="del";
                    369: 	document.anno.submit();
                    370:     }
                    371: </script>
1.1       www       372: ENDDOCUMENT
1.47      albertel  373: 
1.18      www       374:     if ($pickdatemode) {
                    375: # no big header in pickdate mode
1.47      albertel  376: 	$r->print(&Apache::loncommon::start_page("Pick a Date",$js,
                    377: 						 {'only_body' => 1,}).
1.19      www       378: 		  &dialscript().
1.18      www       379: 		  '<font size="1">');
                    380:     } else {
1.47      albertel  381:        $r->print(&Apache::loncommon::start_page("Announcements and Calendar",
                    382: 						$js));
1.18      www       383:     }
1.3       www       384: # does this user have privileges to post, etc?
                    385:     my $allowed=0;
1.34      albertel  386:     if ($env{'request.course.id'}) {
                    387:        $allowed=&Apache::lonnet::allowed('srm',$env{'request.course.id'});
1.3       www       388:     }
1.17      www       389: # does this user have privileges to post to servers?
                    390:     my $serverpost=0;
1.34      albertel  391:     if ($env{'request.role.domain'}) {
1.17      www       392: 	$serverpost=&Apache::lonnet::allowed('psa',
1.34      albertel  393: 					     $env{'request.role.domain'});
1.17      www       394:     } else {
                    395: 	$serverpost=&Apache::lonnet::allowed('psa','/');
                    396:     }
1.18      www       397: # -------------------------------- BUT: do no fancy stuff when in pickdate mode
                    398:     if ($pickdatemode) { 
                    399: 	$serverpost=0; 
                    400: 	$allowed=0;
                    401:     }
1.17      www       402: # ------------------------------------------------------------ Process commands
                    403:     if ($serverpost) {
1.34      albertel  404: 	if ($env{'form.serveraction'}) {
1.42      albertel  405: 	    foreach my $key (keys(%env)) {
                    406: 		if ($key=~/^form\.postto\_(\w+)/) {
1.17      www       407: 		    $r->print( 
                    408: 			'<br />Posting '.$1.': '.&Apache::lonnet::postannounce
1.34      albertel  409: 			($1,$env{'form.serverannnounce'}));
1.17      www       410: 		}
                    411: 	    }
                    412: 	}
                    413: 	$r->print(<<SERVERANNOUNCE);
                    414: <form name="serveranno" method="post">
                    415: <h3>Post Server Announcements</h3>
                    416: Post announcements to the system login and roles screen<br />
                    417: <i>(leave blank to delete announcement)</i><br />
                    418: <textarea name="serverannnounce" cols="60" rows="5"></textarea><br />
                    419: Check machines:<br />
                    420: SERVERANNOUNCE
                    421: # list servers
1.42      albertel  422:     foreach my $host (sort(keys(%Apache::lonnet::hostname))) {
                    423: 	if (&Apache::lonnet::allowed('psa',$Apache::lonnet::hostdom{$host})) {
                    424: 	    $r->print ('<br /><input type="checkbox" name="postto_'.$host.'" /> '.
                    425: 		       $host.' <tt>'.$Apache::lonnet::hostname{$host}.'</tt> '.
                    426: 		       '<a href="http://'.$Apache::lonnet::hostname{$host}.
1.17      www       427: 		       '/announcement.txt" target="annowin">current</a>');
                    428: 	}
                    429:     }
                    430:     $r->print(
                    431:   '<br /><input type="submit" name="serveraction" value="Post"></form><hr />');
                    432:     }
1.3       www       433:     if ($allowed) {
1.34      albertel  434:         my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
                    435:         my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.3       www       436: # ----------------------------------------------------- Store new submitted one
1.34      albertel  437:         if ($env{'form.action'} eq 'new') {
1.9       www       438: 	    my $startdate = 
                    439: 		&Apache::lonhtmlcommon::get_date_from_form('startdate');
                    440: 	    my $enddate   = 
                    441: 		&Apache::lonhtmlcommon::get_date_from_form('enddate');
                    442: 	    unless ($startdate=~/^\d+$/) { $startdate=time; }
                    443:             unless ($enddate=~/^\d+$/) { $enddate=$startdate+1; }
                    444:             if ($startdate>$enddate) {
                    445: 		my $buffer=$startdate;
                    446: 		$startdate=$enddate;
                    447: 		$enddate=$buffer;
                    448:             }
1.3       www       449: 	    &Apache::lonnet::put('calendar',{ 
1.9       www       450: 		$startdate.'_'.$enddate => 
1.34      albertel  451: 		    $env{'form.msg'} },$coursedom,$coursenum);
1.36      www       452: 	    if ($env{'form.rsspost'}) {
                    453:                &Apache::lonrss::addentry($coursenum,$coursedom,'Course_Announcements',
                    454: 					 &mt('Event from [_1] to [_2]',
                    455: 					     &Apache::lonlocal::locallocaltime($startdate),
                    456: 					     &Apache::lonlocal::locallocaltime($enddate)),
                    457: 					 $env{'form.msg'},'/adm/announcements','public');
                    458: 	   }
1.3       www       459:         }
                    460: # ---------------------------------------------------------------- Remove items
1.34      albertel  461:         if ($env{'form.action'} eq 'del') {
1.3       www       462: 	    my @delwhich=();
1.42      albertel  463:             foreach my $key (keys(%env)) {
                    464: 		if ($key=~/^form\.remove\_(.+)$/) {
1.3       www       465: 		    push(@delwhich,$1);
                    466:                 }
                    467:             }
                    468:             &Apache::lonnet::del('calendar',\@delwhich,$coursedom,$coursenum);
                    469:         }
                    470: # -------------------------------------------------------- Form to post new one
                    471:         my %tomorrowhash=%todayhash;
                    472:         $tomorrowhash{'day'}++;
                    473:         my $tomorrow=&Apache::loncommon::maketime(%tomorrowhash);
                    474:         
1.10      www       475:         &editfield($r,$today,$tomorrow,'');
1.3       www       476:     }
1.5       www       477: # ----------------------------------------------------- Summarize all calendars
                    478:     my %allcal=();
1.49    ! albertel  479:     foreach my $course (sort(&Apache::loncommon::findallcourses())) {
1.42      albertel  480: 	%allcal=(%allcal,&readcalendar($course));
1.5       www       481:     }
                    482: 
                    483: # ------------------------------- Initialize table and forward backward buttons
1.3       www       484:     my ($pm,$py,$fm,$fy)=($month-1,$year,$month+1,$year);
                    485:     if ($pm<1) { ($pm,$py)=(12,$year-1); }
                    486:     if ($fm>12){ ($fm,$fy)=(1,$year+1); }
1.14      www       487: 
1.20      www       488:     $r->print('<h1>'.('',&mt('January'),&mt('February'),&mt('March'),
                    489: 		      &mt('April'),&mt('May'),
                    490: 		      &mt('June'),&mt('July'),&mt('August'),
                    491:                       &mt('September'),&mt('October'),
                    492:                       &mt('November'),&mt('December'))[$month].' '.
                    493: 	              $year.'</h1>');
1.13      www       494: # Reached the end of times, give up
                    495:     if (($year<1970) || ($year>2037)) {
                    496: 	$r->print('<h3>No calendar available for this date.</h3>'.
                    497:  '<a href="/adm/announcements?month='.$todayhash{'month'}.
1.47      albertel  498:  '&year='.$todayhash{'year'}.'">Current Month</a>'.
                    499: 		  &Apache::loncommon::end_page());
1.13      www       500: 	return OK;
                    501:     }
1.49    ! albertel  502: 
        !           503:     my $class = "LC_calendar";
        !           504:     if ($env{'form.pickdate'} eq 'yes') {
        !           505: 	$class .= " LC_calendar_pickdate";
        !           506:     }
1.13      www       507:     $r->print(
1.18      www       508:  '<a href="/adm/announcements?month='.$pm.'&year='.$py.
1.20      www       509:  ($pickdatemode?$pickinfo:'').'">'.&mt('Previous Month').'</a> '.
1.18      www       510:  '<a href="/adm/announcements?month='.$fm.'&year='.$fy.
1.20      www       511:  ($pickdatemode?$pickinfo:'').'">'.&mt('Next Month').'</a>'.
1.12      www       512:  '&nbsp;&nbsp;&nbsp;<a href="/adm/announcements?month='.$todayhash{'month'}.
1.18      www       513:  '&year='.$todayhash{'year'}.
1.20      www       514:  ($pickdatemode?$pickinfo:'').'">'.&mt('Current Month').'</a><p>'.
1.49    ! albertel  515:         '<table class="'.$class.'" cols="7" rows="5"><tr>
        !           516: <th>'.&mt('Sun').'</th>
        !           517: <th>'.&mt('Mon').'</th>
        !           518: <th>'.&mt('Tue').'</th>
        !           519: <th>'.&mt('Wed').'</th>
        !           520: <th>'.&mt('Thu').'</th>
        !           521: <th>'.&mt('Fri').'</th>
        !           522: <th>'.&mt('Sat').'</th></tr>');
1.3       www       523: 
                    524:     my $tk=&Apache::loncommon::maketime(%firstday);
                    525:     my $outp;
                    526:     my $nm;
                    527: 
                    528: # ---------------------------------------------------------------- Actual table
                    529:     $r->print('<tr>');
                    530:     for (my $i=0;$i<$weekday;$i++) { $r->print(&emptycell); }
                    531:     for (my $i=$weekday;$i<=6;$i++) { 
1.11      www       532:         ($tk,$nm,$outp)=&showday($tk,0,%allcal);
1.3       www       533:         $r->print($outp);
                    534:     }
                    535:     $r->print('</tr>');
                    536: 
1.23      www       537:     for (my $k=0;$k<=4;$k++) {
1.3       www       538:         $r->print('<tr>');
                    539:         for (my $i=0;$i<=6;$i++) {
1.11      www       540:             ($tk,$nm,$outp)=&showday($tk,0,%allcal);
1.3       www       541:             if ($month!=$nm) { $outp=&emptycell; }
                    542:             $r->print($outp);
                    543:         }
                    544:         $r->print('</tr>');
                    545:     }
                    546: # ------------------------------------------------------------------- End table
1.7       matthew   547:     $r->print('</table>');
1.16      www       548: # ----------------------------------------------------------------- Check marks
1.49    ! albertel  549:     undef(%showedcheck);
1.16      www       550: # --------------------------------------------------------------- Remove button
1.24      www       551:     if ($allowed) { $r->print('<input type="button" onClick="removesub()" value="Remove Checked Entries">'.
                    552: 			      &Apache::loncommon::help_open_topic('Calendar_Remove_Announcement').'</form>'); }
1.7       matthew   553:     $r->print('<p>'.
1.18      www       554:  '<a href="/adm/announcements?month='.$pm.'&year='.$py.
1.20      www       555:  ($pickdatemode?$pickinfo:'').'">'.&mt('Previous Month').'</a> '.
1.18      www       556:  '<a href="/adm/announcements?month='.$fm.'&year='.$fy.
1.20      www       557:  ($pickdatemode?$pickinfo:'').'">'.&mt('Next Month').'</a>'.
1.12      www       558:  '&nbsp;&nbsp;&nbsp;<a href="/adm/announcements?month='.$todayhash{'month'}.
1.18      www       559:  '&year='.$todayhash{'year'}.
1.20      www       560:  ($pickdatemode?$pickinfo:'').'">'.&mt('Current Month').'</a></p>'.
1.47      albertel  561:  ($pickdatemode?'</font>':'').&Apache::loncommon::end_page());
1.1       www       562:     return OK;
                    563: } 
                    564: 
                    565: 1;
                    566: __END__

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