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

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

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