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

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

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