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

1.1       www         1: # The LearningOnline Network
1.2       www         2: # Announce
1.1       www         3: #
1.46    ! albertel    4: # $Id: lonannounce.pm,v 1.45 2006/01/16 21:24:29 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 {
                    158:     return '<td bgcolor="#AAAAAA">&nbsp;</td>';
                    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.30      www       196:     return '<td valign="top"'.
1.12      www       197: 	((($day eq $todayhash{'day'}) &&
                    198:           ($month eq $todayhash{'month'}) &&
                    199:           ($year eq $todayhash{'year'}))?' bgcolor="#FFFF00"':'').
1.30      www       200:            '>'.&tfont('<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 tfont {
                    299:     my $text=shift;
1.34      albertel  300:     if ($env{'form.pickdate'} eq 'yes') {
1.19      www       301: 	return '<font size="1">'.$text.'</font>';
                    302:     } else {
                    303: 	return $text;
                    304:     }
                    305: }
                    306: 
                    307: sub picklink {
                    308:     my ($text,$day,$month,$year)=@_;
1.34      albertel  309:     if ($env{'form.pickdate'} eq 'yes') {
1.19      www       310: 	return '<a href="javascript:dialin('.$day.','.$month.','.$year.')">'.
                    311: 	    $text.'</a>';
                    312:     } else {
                    313: 	return $text;
                    314:     }
                    315: }
                    316: 
                    317: sub dialscript {
                    318:     return (<<ENDDIA);
                    319: <script language="Javascript">
                    320: function dialin(day,month,year) {
1.34      albertel  321: 	opener.document.$env{'form.formname'}.$env{'form.element'}\_year.value=year;
                    322:     var slct=opener.document.$env{'form.formname'}.$env{'form.element'}\_month;
1.19      www       323:     var i;
                    324:     for (i=0;i<slct.length;i++) {
                    325:         if (slct.options[i].value==month) { slct.selectedIndex=i; }
                    326:     }
1.34      albertel  327:     opener.document.$env{'form.formname'}.$env{'form.element'}\_day.value=day;
                    328:     opener.$env{'form.element'}\_checkday();
1.19      www       329:     self.close();
                    330: }
                    331: </script>
                    332: ENDDIA
                    333: }
                    334: 
1.1       www       335: sub handler {
                    336:     my $r = shift;
1.21      www       337:     &Apache::loncommon::content_type($r,'text/html');
1.1       www       338:     $r->send_http_header;
                    339:     return OK if $r->header_only;
                    340: 
1.3       www       341: # ---------------------------------------------------------- Get time right now
                    342:     my $today=time;
1.12      www       343:     %todayhash=&Apache::loncommon::timehash($today);
1.16      www       344: # ----------------------------------------------------------------- Check marks
                    345:     %showedcheck=();
                    346:     undef %showedcheck;
1.3       www       347: # ---------------------------------------------------------- Get month and year
                    348:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.19      www       349:                              ['month','year','pickdate','formname','element']);
1.3       www       350: # --------------------------------------------------- Decide what month to show
                    351:     my $year=$todayhash{'year'};
1.34      albertel  352:     if ($env{'form.year'}) { $year=$env{'form.year'}; }
1.3       www       353:     my $month=$todayhash{'month'};
1.34      albertel  354:     if ($env{'form.month'}) { $month=$env{'form.month'}; }
1.18      www       355: 
                    356: # ---------------------------------------------- See if we are in pickdate mode
1.34      albertel  357:     my $pickdatemode=($env{'form.pickdate'} eq 'yes');
                    358:     my $pickinfo='&pickdate=yes&formname='.$env{'form.formname'}.
                    359: 	'&element='.$env{'form.element'};
1.3       www       360: # --------------------------------------------- Find out first day of the month
                    361: 
                    362:     my %firstday=&Apache::loncommon::timehash(
                    363:        &Apache::loncommon::maketime( 'day' => 1, 'month'=> $month,
                    364:                                      'year' => $year, 'hours' => 0,
                    365: 				     'minutes' => 0, 'seconds' => 0,
1.30      www       366:                                      'dlsav' => -1 ));
1.3       www       367:     my $weekday=$firstday{'weekday'};
                    368: # ------------------------------------------------------------ Print the screen
1.33      albertel  369:     my $html=&Apache::lonxml::xmlbegin();
1.1       www       370:     $r->print(<<ENDDOCUMENT);
1.33      albertel  371: $html
1.1       www       372: <head>
                    373: <title>The LearningOnline Network with CAPA</title>
1.3       www       374: <script>
                    375: 
                    376:     function trysubmit() {
                    377:         document.anno.action.value="new";
                    378: 	document.anno.submit();
                    379:     }
                    380: 
                    381:     function removesub() {
                    382:         document.anno.action.value="del";
                    383: 	document.anno.submit();
                    384:     }
                    385: </script>
1.1       www       386: </head>
                    387: ENDDOCUMENT
1.18      www       388:     if ($pickdatemode) {
                    389: # no big header in pickdate mode
                    390: 	$r->print(&Apache::loncommon::bodytag("Pick a Date",'','',1).
1.19      www       391: 		  &dialscript().
1.18      www       392: 		  '<font size="1">');
                    393:     } else {
                    394:        $r->print(&Apache::loncommon::bodytag("Announcements and Calendar"));
                    395:     }
1.3       www       396: # does this user have privileges to post, etc?
                    397:     my $allowed=0;
1.34      albertel  398:     if ($env{'request.course.id'}) {
                    399:        $allowed=&Apache::lonnet::allowed('srm',$env{'request.course.id'});
1.3       www       400:     }
1.17      www       401: # does this user have privileges to post to servers?
                    402:     my $serverpost=0;
1.34      albertel  403:     if ($env{'request.role.domain'}) {
1.17      www       404: 	$serverpost=&Apache::lonnet::allowed('psa',
1.34      albertel  405: 					     $env{'request.role.domain'});
1.17      www       406:     } else {
                    407: 	$serverpost=&Apache::lonnet::allowed('psa','/');
                    408:     }
1.18      www       409: # -------------------------------- BUT: do no fancy stuff when in pickdate mode
                    410:     if ($pickdatemode) { 
                    411: 	$serverpost=0; 
                    412: 	$allowed=0;
                    413:     }
1.17      www       414: # ------------------------------------------------------------ Process commands
                    415:     if ($serverpost) {
1.34      albertel  416: 	if ($env{'form.serveraction'}) {
1.42      albertel  417: 	    foreach my $key (keys(%env)) {
                    418: 		if ($key=~/^form\.postto\_(\w+)/) {
1.17      www       419: 		    $r->print( 
                    420: 			'<br />Posting '.$1.': '.&Apache::lonnet::postannounce
1.34      albertel  421: 			($1,$env{'form.serverannnounce'}));
1.17      www       422: 		}
                    423: 	    }
                    424: 	}
                    425: 	$r->print(<<SERVERANNOUNCE);
                    426: <form name="serveranno" method="post">
                    427: <h3>Post Server Announcements</h3>
                    428: Post announcements to the system login and roles screen<br />
                    429: <i>(leave blank to delete announcement)</i><br />
                    430: <textarea name="serverannnounce" cols="60" rows="5"></textarea><br />
                    431: Check machines:<br />
                    432: SERVERANNOUNCE
                    433: # list servers
1.42      albertel  434:     foreach my $host (sort(keys(%Apache::lonnet::hostname))) {
                    435: 	if (&Apache::lonnet::allowed('psa',$Apache::lonnet::hostdom{$host})) {
                    436: 	    $r->print ('<br /><input type="checkbox" name="postto_'.$host.'" /> '.
                    437: 		       $host.' <tt>'.$Apache::lonnet::hostname{$host}.'</tt> '.
                    438: 		       '<a href="http://'.$Apache::lonnet::hostname{$host}.
1.17      www       439: 		       '/announcement.txt" target="annowin">current</a>');
                    440: 	}
                    441:     }
                    442:     $r->print(
                    443:   '<br /><input type="submit" name="serveraction" value="Post"></form><hr />');
                    444:     }
1.3       www       445:     if ($allowed) {
1.34      albertel  446:         my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
                    447:         my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.3       www       448: # ----------------------------------------------------- Store new submitted one
1.34      albertel  449:         if ($env{'form.action'} eq 'new') {
1.9       www       450: 	    my $startdate = 
                    451: 		&Apache::lonhtmlcommon::get_date_from_form('startdate');
                    452: 	    my $enddate   = 
                    453: 		&Apache::lonhtmlcommon::get_date_from_form('enddate');
                    454: 	    unless ($startdate=~/^\d+$/) { $startdate=time; }
                    455:             unless ($enddate=~/^\d+$/) { $enddate=$startdate+1; }
                    456:             if ($startdate>$enddate) {
                    457: 		my $buffer=$startdate;
                    458: 		$startdate=$enddate;
                    459: 		$enddate=$buffer;
                    460:             }
1.3       www       461: 	    &Apache::lonnet::put('calendar',{ 
1.9       www       462: 		$startdate.'_'.$enddate => 
1.34      albertel  463: 		    $env{'form.msg'} },$coursedom,$coursenum);
1.36      www       464: 	    if ($env{'form.rsspost'}) {
                    465:                &Apache::lonrss::addentry($coursenum,$coursedom,'Course_Announcements',
                    466: 					 &mt('Event from [_1] to [_2]',
                    467: 					     &Apache::lonlocal::locallocaltime($startdate),
                    468: 					     &Apache::lonlocal::locallocaltime($enddate)),
                    469: 					 $env{'form.msg'},'/adm/announcements','public');
                    470: 	   }
1.3       www       471:         }
                    472: # ---------------------------------------------------------------- Remove items
1.34      albertel  473:         if ($env{'form.action'} eq 'del') {
1.3       www       474: 	    my @delwhich=();
1.42      albertel  475:             foreach my $key (keys(%env)) {
                    476: 		if ($key=~/^form\.remove\_(.+)$/) {
1.3       www       477: 		    push(@delwhich,$1);
                    478:                 }
                    479:             }
                    480:             &Apache::lonnet::del('calendar',\@delwhich,$coursedom,$coursenum);
                    481:         }
                    482: # -------------------------------------------------------- Form to post new one
                    483:         my %tomorrowhash=%todayhash;
                    484:         $tomorrowhash{'day'}++;
                    485:         my $tomorrow=&Apache::loncommon::maketime(%tomorrowhash);
                    486:         
1.10      www       487:         &editfield($r,$today,$tomorrow,'');
1.3       www       488:     }
1.5       www       489: # ----------------------------------------------------- Summarize all calendars
                    490:     my %allcal=();
1.42      albertel  491:     foreach my $course (&Apache::loncommon::findallcourses()) {
                    492: 	%allcal=(%allcal,&readcalendar($course));
1.5       www       493:     }
                    494: 
                    495: # ------------------------------- Initialize table and forward backward buttons
1.3       www       496:     my ($pm,$py,$fm,$fy)=($month-1,$year,$month+1,$year);
                    497:     if ($pm<1) { ($pm,$py)=(12,$year-1); }
                    498:     if ($fm>12){ ($fm,$fy)=(1,$year+1); }
1.14      www       499: 
1.20      www       500:     $r->print('<h1>'.('',&mt('January'),&mt('February'),&mt('March'),
                    501: 		      &mt('April'),&mt('May'),
                    502: 		      &mt('June'),&mt('July'),&mt('August'),
                    503:                       &mt('September'),&mt('October'),
                    504:                       &mt('November'),&mt('December'))[$month].' '.
                    505: 	              $year.'</h1>');
1.13      www       506: # Reached the end of times, give up
                    507:     if (($year<1970) || ($year>2037)) {
                    508: 	$r->print('<h3>No calendar available for this date.</h3>'.
                    509:  '<a href="/adm/announcements?month='.$todayhash{'month'}.
                    510:  '&year='.$todayhash{'year'}.'">Current Month</a></body></html>');
                    511: 	return OK;
                    512:     }
                    513:     $r->print(
1.18      www       514:  '<a href="/adm/announcements?month='.$pm.'&year='.$py.
1.20      www       515:  ($pickdatemode?$pickinfo:'').'">'.&mt('Previous Month').'</a> '.
1.18      www       516:  '<a href="/adm/announcements?month='.$fm.'&year='.$fy.
1.20      www       517:  ($pickdatemode?$pickinfo:'').'">'.&mt('Next Month').'</a>'.
1.12      www       518:  '&nbsp;&nbsp;&nbsp;<a href="/adm/announcements?month='.$todayhash{'month'}.
1.18      www       519:  '&year='.$todayhash{'year'}.
1.20      www       520:  ($pickdatemode?$pickinfo:'').'">'.&mt('Current Month').'</a><p>'.
1.19      www       521:         '<table border="2" cols="7" rows="5"><tr><th>'.
1.20      www       522: &tfont(&mt('Sun'))
1.19      www       523: .'</th><th>'.
1.20      www       524: &tfont(&mt('Mon'))
1.19      www       525: .'</th><th>'.
1.20      www       526: &tfont(&mt('Tue'))
1.19      www       527: .'</th><th>'.
1.20      www       528: &tfont(&mt('Wed'))
1.19      www       529: .'</th><th>'.
1.20      www       530: &tfont(&mt('Thu'))
1.19      www       531: .'</th><th>'.
1.20      www       532: &tfont(&mt('Fri'))
1.19      www       533: .'</th><th>'.
1.20      www       534: &tfont(&mt('Sat'))
1.19      www       535: .'</th></tr>');
1.3       www       536: 
                    537:     my $tk=&Apache::loncommon::maketime(%firstday);
                    538:     my $outp;
                    539:     my $nm;
                    540: 
                    541: # ---------------------------------------------------------------- Actual table
                    542:     $r->print('<tr>');
                    543:     for (my $i=0;$i<$weekday;$i++) { $r->print(&emptycell); }
                    544:     for (my $i=$weekday;$i<=6;$i++) { 
1.11      www       545:         ($tk,$nm,$outp)=&showday($tk,0,%allcal);
1.3       www       546:         $r->print($outp);
                    547:     }
                    548:     $r->print('</tr>');
                    549: 
1.23      www       550:     for (my $k=0;$k<=4;$k++) {
1.3       www       551:         $r->print('<tr>');
                    552:         for (my $i=0;$i<=6;$i++) {
1.11      www       553:             ($tk,$nm,$outp)=&showday($tk,0,%allcal);
1.3       www       554:             if ($month!=$nm) { $outp=&emptycell; }
                    555:             $r->print($outp);
                    556:         }
                    557:         $r->print('</tr>');
                    558:     }
                    559: # ------------------------------------------------------------------- End table
1.7       matthew   560:     $r->print('</table>');
1.16      www       561: # ----------------------------------------------------------------- Check marks
                    562:     %showedcheck=();
                    563:     undef %showedcheck;
                    564: # --------------------------------------------------------------- Remove button
1.24      www       565:     if ($allowed) { $r->print('<input type="button" onClick="removesub()" value="Remove Checked Entries">'.
                    566: 			      &Apache::loncommon::help_open_topic('Calendar_Remove_Announcement').'</form>'); }
1.7       matthew   567:     $r->print('<p>'.
1.18      www       568:  '<a href="/adm/announcements?month='.$pm.'&year='.$py.
1.20      www       569:  ($pickdatemode?$pickinfo:'').'">'.&mt('Previous Month').'</a> '.
1.18      www       570:  '<a href="/adm/announcements?month='.$fm.'&year='.$fy.
1.20      www       571:  ($pickdatemode?$pickinfo:'').'">'.&mt('Next Month').'</a>'.
1.12      www       572:  '&nbsp;&nbsp;&nbsp;<a href="/adm/announcements?month='.$todayhash{'month'}.
1.18      www       573:  '&year='.$todayhash{'year'}.
1.20      www       574:  ($pickdatemode?$pickinfo:'').'">'.&mt('Current Month').'</a></p>'.
1.18      www       575:  ($pickdatemode?'</font>':'').
1.3       www       576:  '</body></html>');
1.1       www       577:     return OK;
                    578: } 
                    579: 
                    580: 1;
                    581: __END__

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