Annotation of loncom/interface/lonannounce.pm, revision 1.61
1.1 www 1: # The LearningOnline Network
1.2 www 2: # Announce
1.1 www 3: #
1.61 ! albertel 4: # $Id: lonannounce.pm,v 1.60 2006/09/02 20:47:11 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.55 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.61 ! albertel 83: my $can_see_hidden = ($env{'request.role.adv'} &&
! 84: ($courseid eq $env{'request.course.id'}));
! 85:
! 86: my $navmap;
! 87: if ($courseid eq $env{'request.course.id'}) {
! 88: $navmap = Apache::lonnavmaps::navmap->new();
! 89: }
1.53 www 90: my %resourcedata=
91: &Apache::lonnet::dump('resourcedata',$coursedom,$coursenum);
92: foreach my $thiskey (sort keys %resourcedata) {
93: if ($resourcedata{$thiskey.'.type'}=~/^date/) {
94: my ($course,$middle,$part,$name)=
95: ($thiskey=~/^(\w+)\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/);
1.56 albertel 96: my %data = ( 'section' => &mt('All Students'));
1.53 www 97: if ($middle=~/^\[(.*)\]\./) {
98: my $sec=$1;
99: # if we have a section don't show ones that aren't ours
100: if ($env{'request.course.sec'} &&
101: $env{'request.course.sec'} ne $sec) { next; }
102: # if a student without a section don't show any section ones
103: if (!$env{'request.role.adv'} &&
104: !$env{'request.course.sec'}) { next; }
1.56 albertel 105: $data{'section'}=&mt('Group/Section').': '.$1;
1.53 www 106: $middle=~s/^\[(.*)\]\.//;
107: }
108: $middle=~s/\.$//;
1.56 albertel 109: $data{'realm'}=&mt('All Resources');
1.53 www 110: if ($middle eq '___(all)') {
111: if (!$can_see_hidden && !$navmap) {
112: next;
113: }
114: } elsif ($middle=~/^(.+)\_\_\_\(all\)$/) {
115: my $map_url=$1;
116: if (!$can_see_hidden && !$navmap) {
117: next;
118: }
119: if (!$can_see_hidden) {
120: my $res = $navmap->getResourceByUrl($map_url);
121: if ($res && $res->randomout()) { next; }
1.26 www 122: }
1.56 albertel 123: $data{'realm'}=&mt('Folder/Map');
124: $data{'url'} = $map_url;
1.53 www 125: } elsif ($middle) {
126: if (!$can_see_hidden && !$navmap) {
127: next;
1.26 www 128: }
1.53 www 129: if (!$can_see_hidden) {
130: my $res = $navmap->getBySymb($middle);
131: if ($res && $res->randomout()) { next; }
132: }
1.56 albertel 133: $data{'realm'} = &mt('Resource');
134: $data{'symb'} = $middle;
1.53 www 135: }
1.56 albertel 136: $data{'datetype'} = $name;
1.53 www 137: if ($name eq 'duedate') {
1.56 albertel 138: $data{'datetype'} = &mt('Due');
1.28 www 139: # see if accidentally answerdate is before duedate
1.53 www 140: my $answerkey=$thiskey;
141: $answerkey=~s/duedate$/answerdate/;
142: if ($resourcedata{$thiskey}>$resourcedata{$answerkey}) {
1.56 albertel 143: $data{'datetype'} = &mt('Due and Answer Available');
1.28 www 144: }
1.53 www 145: }
1.56 albertel 146: if ($name eq 'opendate'
147: || $name eq 'contentopen' ) {
148: $data{'datetype'}=&mt('Opening');
149: }
150: if ($name eq 'contentclose') {
151: $data{'datetype'}=&mt('Closing');
152: }
1.53 www 153: if ($name eq 'answerdate') {
1.28 www 154: # see if accidentally answerdate is before duedate
1.53 www 155: my $duekey=$thiskey;
156: $duekey=~s/answerdate$/duedate/;
157: if ($resourcedata{$duekey}>$resourcedata{$thiskey}) {
1.28 www 158: # forget it
1.53 www 159: next;
160: }
1.56 albertel 161: $data{'datetype'}=&mt('Answer Available');
1.53 www 162: }
163: $returnhash{$courseid.'@'.$resourcedata{$thiskey}.'_'.
1.56 albertel 164: $resourcedata{$thiskey}}=\%data;
1.26 www 165: }
166: }
1.3 www 167: return %returnhash;
168: }
169:
170: sub emptycell {
1.49 albertel 171: return '<td class="LC_calendar_day_empty"> </td>';
1.3 www 172: }
173:
174: sub normalcell {
1.56 albertel 175: my ($day,$month,$year,$items_ref)=@_;
1.51 albertel 176: my $output;
1.56 albertel 177: my @items=&order($items_ref);
1.40 albertel 178: foreach my $item (@items) {
179: if ($item) {
1.56 albertel 180: my ($courseid,$start,$end,$msg)=@$item;
181: my $internalflag= (ref($msg)) ? 1 : 0;
182: $msg = &display_msg($msg);
1.34 albertel 183: my $fullmsg=&mt('Calendar Announcement for ').$env{'course.'.$courseid.'.description'}.
1.32 www 184: '\n'.&Apache::lonlocal::locallocaltime($start);
1.26 www 185: if ($start!=$end) {
186: $fullmsg.=' - '.&Apache::lonlocal::locallocaltime($end);
187: }
1.32 www 188: $fullmsg.=':\n'.$msg;
1.56 albertel 189: $fullmsg=~s/[\n\r]/\\n/gs;
190: $fullmsg=&HTML::Entities::encode($fullmsg,'<>&"\'');
191: $fullmsg=~s/&/\\&/g;
192: my $short_msg = substr($msg,0,20).((length($msg) > 20)?'...':'');
193: if (defined($output)) { $output.='<br />'; }
1.34 albertel 194: if ($courseid eq $env{'request.course.id'}) {
195: if ((&Apache::lonnet::allowed('srm',$env{'request.course.id'}))
1.19 www 196: && (!$showedcheck{$start.'_'.$end})
1.34 albertel 197: && ($env{'form.pickdate'} ne 'yes')
1.26 www 198: && (!$internalflag)) {
1.5 www 199: $output.='<input type="checkbox" name="remove_'.$start.'_'.
200: $end.'">';
1.16 www 201: $showedcheck{$start.'_'.$end}=1;
1.5 www 202: }
203: }
204: $output.='<a href="javascript:alert('."'$fullmsg'".')">'.
1.51 albertel 205: $short_msg.'</a>';
1.4 www 206: }
207: }
1.49 albertel 208: return '<td class="LC_calendar_day'.
1.12 www 209: ((($day eq $todayhash{'day'}) &&
210: ($month eq $todayhash{'month'}) &&
1.49 albertel 211: ($year eq $todayhash{'year'}))?'_current':'').
212: '" ><b>'.&picklink($day,$day,$month,$year).'</b><br />'.$output.'</td>';
1.3 www 213: }
214:
1.11 www 215: sub plaincell {
1.56 albertel 216: my ($items_ref)=@_;
1.51 albertel 217: my $output;
1.56 albertel 218: my @items=&order($items_ref);
1.40 albertel 219: foreach my $item (@items) {
1.56 albertel 220: if (ref($item)) {
221: my ($courseid,$start,$end,$msg)=@$item;
1.34 albertel 222: my $fullmsg=&mt('Calendar Announcement for ').$env{'course.'.$courseid.'.description'}.
1.32 www 223: '\n'.&Apache::lonlocal::locallocaltime($start);
1.26 www 224: if ($start!=$end) {
225: $fullmsg.=' - '.&Apache::lonlocal::locallocaltime($end);
226: }
1.56 albertel 227: $msg = &display_msg($msg);
1.32 www 228: $fullmsg.=':\n'.$msg;
229: $fullmsg=~s/[\n\r]/\\n/gs;
1.15 www 230: $fullmsg=&HTML::Entities::encode($fullmsg,'<>&"\'');
231: $fullmsg=~s/&/\\&/g;
1.51 albertel 232: my $short_msg = substr($msg,0,80).((length($msg) > 80)?'...':'');
233: if (defined($output)) { $output.='<br />'; }
1.11 www 234: $output.='<a href="javascript:alert('."'$fullmsg'".')">'.
1.51 albertel 235: $short_msg.'</a>';
1.11 www 236: }
237: }
238: return $output;
239: }
240:
241: sub listcell {
1.56 albertel 242: my ($items_ref)=@_;
1.11 www 243: my $output='';
1.56 albertel 244: my @items=&order($items_ref);
1.40 albertel 245: foreach my $item (@items) {
1.56 albertel 246: if (ref($item)) {
247: my ($courseid,$start,$end,$msg)=@$item;
248: my $fullmsg=&Apache::lonlocal::locallocaltime($start);
1.26 www 249: if ($start!=$end) {
250: $fullmsg.=&mt(' to ').
251: &Apache::lonlocal::locallocaltime($end);
252: }
1.56 albertel 253: $fullmsg.=':<br /><b>'.&display_msg($msg).'</b>';
1.11 www 254: $output.='<li>'.$fullmsg.'</li>';
255: }
256: }
257: return $output;
258: }
259:
1.40 albertel 260: sub order {
1.56 albertel 261: my ($items)=@_;
262: return sort {
263: my ($astart,$aend)=$a->[1,2];
264: my ($bstart,$bend)=$b->[1,2];
1.40 albertel 265: if ($astart != $bstart) {
266: return $astart <=> $bstart;
267: }
268: return $aend <=> $bend;
1.56 albertel 269: } @$items;
1.40 albertel 270: }
271:
1.3 www 272: sub nextday {
273: my %th=@_;
274: $th{'day'}++;
275: return (&Apache::loncommon::maketime(%th),$th{'month'});
276: }
277:
1.56 albertel 278: sub display_msg {
279: my ($msg) = @_;
280:
281: # if it's not a ref, it's an instructor provided message
282: return $msg if (!ref($msg));
283:
284: my $output = $msg->{'datetype'}. ': '.$msg->{'realm'};
285: if (exists($msg->{'url'})) {
1.59 www 286: my $displayurl=&Apache::lonnet::gettitle($msg->{'url'});
287: if ($msg->{'url'}!~/\Q$displayurl\E$/) {
288: $output .= ' - '.$displayurl;
289: }
1.56 albertel 290: }
291: if (exists($msg->{'symb'})) {
1.59 www 292: my $displaysymb=&Apache::lonnet::gettitle($msg->{'symb'});
293: if ($msg->{'symb'}!~/\Q$displaysymb\E$/) {
294: $output .= ' - '.$displaysymb;
295: }
1.56 albertel 296: }
297: $output .= ' ('.$msg->{'section'}.') ';
298: return $output;
299: }
300:
1.3 www 301: sub showday {
1.11 www 302: my ($tk,$mode,%allcal)=@_;
1.3 www 303: my %th=&Apache::loncommon::timehash($tk);
304: my ($nextday,$nextmonth)=&nextday(%th);
1.56 albertel 305: my @outp;
1.27 www 306: if ($mode) {
307: my $oneday=24*3600;
308: $tk-=$oneday;
309: $nextday+=$oneday;
310: }
1.40 albertel 311: foreach my $item (keys(%allcal)) {
312: my ($course,$startdate,$enddate)=($item=~/^(\w+)\@(\d+)\_(\d+)$/);
1.39 albertel 313: if (($startdate<$nextday) && ($enddate>=$tk)) {
1.56 albertel 314: push(@outp,[$course,$startdate,$enddate,$allcal{$item}]);
1.3 www 315: }
316: }
1.11 www 317: unless ($mode) {
1.12 www 318: return ($nextday,$nextmonth,&normalcell(
1.56 albertel 319: $th{'day'},$th{'month'},$th{'year'},\@outp));
320: } elsif (@outp) {
1.11 www 321: if ($mode==1) {
1.56 albertel 322: return '<br />'.&plaincell(\@outp);
1.11 www 323: } else {
1.56 albertel 324: return '<ul>'.&listcell(\@outp).'</ul>';
1.11 www 325: }
326: } else {
327: return '';
328: }
1.3 www 329: }
1.1 www 330:
1.19 www 331: sub picklink {
332: my ($text,$day,$month,$year)=@_;
1.34 albertel 333: if ($env{'form.pickdate'} eq 'yes') {
1.19 www 334: return '<a href="javascript:dialin('.$day.','.$month.','.$year.')">'.
335: $text.'</a>';
336: } else {
337: return $text;
338: }
339: }
340:
341: sub dialscript {
342: return (<<ENDDIA);
343: <script language="Javascript">
344: function dialin(day,month,year) {
1.34 albertel 345: opener.document.$env{'form.formname'}.$env{'form.element'}\_year.value=year;
346: var slct=opener.document.$env{'form.formname'}.$env{'form.element'}\_month;
1.19 www 347: var i;
348: for (i=0;i<slct.length;i++) {
349: if (slct.options[i].value==month) { slct.selectedIndex=i; }
350: }
1.34 albertel 351: opener.document.$env{'form.formname'}.$env{'form.element'}\_day.value=day;
352: opener.$env{'form.element'}\_checkday();
1.19 www 353: self.close();
354: }
355: </script>
356: ENDDIA
357: }
1.52 www 358: # ----------------------------------------------------- Summarize all calendars
359: sub get_all_calendars {
360: my %allcal=();
361: foreach my $course (sort(&Apache::loncommon::findallcourses())) {
362: %allcal=(%allcal,&readcalendar($course));
363: }
364: return %allcal;
365: }
366:
367: sub output_ics_file {
368: my ($r)=@_;
369: # RFC 2445 wants CRLF
370: my $crlf="\015\012";
371: # Header
372: $r->print("BEGIN:VCALENDAR$crlf");
373: $r->print("VERSION:2.0$crlf");
374: $r->print("PRODID:-//LONCAPA//LONCAPA Calendar Output//EN$crlf");
375: my %allcal=&get_all_calendars();
376: foreach my $event (keys(%allcal)) {
1.53 www 377: my ($courseid,$startdate,$enddate)=($event=~/^(\w+)\@(\d+)\_(\d+)$/);
378: my $uid=$event;
379: $uid=~s/[\W\_]/-/gs;
380: $uid.='@loncapa';
1.56 albertel 381: my $summary=&display_msg($allcal{$event});
1.53 www 382: $summary=~s/\s+/ /gs;
383: $summary=$env{'course.'.$courseid.'.description'}.': '.$summary;
1.52 www 384: $r->print("BEGIN:VEVENT$crlf");
385: $r->print("DTSTART:".&Apache::loncommon::utc_string($startdate).$crlf);
386: $r->print("DTEND:".&Apache::loncommon::utc_string($enddate).$crlf);
1.53 www 387: $r->print("SUMMARY:$summary$crlf");
388: $r->print("UID:$uid$crlf");
1.52 www 389: $r->print("END:VEVENT$crlf");
390: }
391: # Footer
392: $r->print("END:VCALENDAR$crlf");
393: }
1.19 www 394:
1.1 www 395: sub handler {
396: my $r = shift;
1.52 www 397: if ($r->uri=~/\.(ics|ical)$/) {
398: &Apache::loncommon::content_type($r,'text/calendar');
399: &output_ics_file($r);
400: return OK;
401: }
1.21 www 402: &Apache::loncommon::content_type($r,'text/html');
1.1 www 403: $r->send_http_header;
404: return OK if $r->header_only;
405:
1.3 www 406: # ---------------------------------------------------------- Get time right now
407: my $today=time;
1.12 www 408: %todayhash=&Apache::loncommon::timehash($today);
1.16 www 409: # ----------------------------------------------------------------- Check marks
1.49 albertel 410: undef(%showedcheck);
1.3 www 411: # ---------------------------------------------------------- Get month and year
412: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.19 www 413: ['month','year','pickdate','formname','element']);
1.3 www 414: # --------------------------------------------------- Decide what month to show
415: my $year=$todayhash{'year'};
1.34 albertel 416: if ($env{'form.year'}) { $year=$env{'form.year'}; }
1.3 www 417: my $month=$todayhash{'month'};
1.34 albertel 418: if ($env{'form.month'}) { $month=$env{'form.month'}; }
1.18 www 419:
420: # ---------------------------------------------- See if we are in pickdate mode
1.34 albertel 421: my $pickdatemode=($env{'form.pickdate'} eq 'yes');
422: my $pickinfo='&pickdate=yes&formname='.$env{'form.formname'}.
423: '&element='.$env{'form.element'};
1.3 www 424: # --------------------------------------------- Find out first day of the month
425:
426: my %firstday=&Apache::loncommon::timehash(
427: &Apache::loncommon::maketime( 'day' => 1, 'month'=> $month,
428: 'year' => $year, 'hours' => 0,
429: 'minutes' => 0, 'seconds' => 0,
1.30 www 430: 'dlsav' => -1 ));
1.3 www 431: my $weekday=$firstday{'weekday'};
432: # ------------------------------------------------------------ Print the screen
1.47 albertel 433: my $js = <<ENDDOCUMENT;
434: <script type="text/javascript">
1.3 www 435:
436: function trysubmit() {
437: document.anno.action.value="new";
438: document.anno.submit();
439: }
440:
441: function removesub() {
442: document.anno.action.value="del";
443: document.anno.submit();
444: }
445: </script>
1.1 www 446: ENDDOCUMENT
1.47 albertel 447:
1.18 www 448: if ($pickdatemode) {
449: # no big header in pickdate mode
1.47 albertel 450: $r->print(&Apache::loncommon::start_page("Pick a Date",$js,
451: {'only_body' => 1,}).
1.19 www 452: &dialscript().
1.18 www 453: '<font size="1">');
454: } else {
1.47 albertel 455: $r->print(&Apache::loncommon::start_page("Announcements and Calendar",
456: $js));
1.18 www 457: }
1.3 www 458: # does this user have privileges to post, etc?
459: my $allowed=0;
1.34 albertel 460: if ($env{'request.course.id'}) {
461: $allowed=&Apache::lonnet::allowed('srm',$env{'request.course.id'});
1.3 www 462: }
1.17 www 463: # does this user have privileges to post to servers?
464: my $serverpost=0;
1.34 albertel 465: if ($env{'request.role.domain'}) {
1.17 www 466: $serverpost=&Apache::lonnet::allowed('psa',
1.34 albertel 467: $env{'request.role.domain'});
1.17 www 468: } else {
469: $serverpost=&Apache::lonnet::allowed('psa','/');
470: }
1.18 www 471: # -------------------------------- BUT: do no fancy stuff when in pickdate mode
472: if ($pickdatemode) {
473: $serverpost=0;
474: $allowed=0;
475: }
1.17 www 476: # ------------------------------------------------------------ Process commands
477: if ($serverpost) {
1.34 albertel 478: if ($env{'form.serveraction'}) {
1.42 albertel 479: foreach my $key (keys(%env)) {
480: if ($key=~/^form\.postto\_(\w+)/) {
1.17 www 481: $r->print(
482: '<br />Posting '.$1.': '.&Apache::lonnet::postannounce
1.34 albertel 483: ($1,$env{'form.serverannnounce'}));
1.17 www 484: }
485: }
486: }
487: $r->print(<<SERVERANNOUNCE);
488: <form name="serveranno" method="post">
489: <h3>Post Server Announcements</h3>
490: Post announcements to the system login and roles screen<br />
491: <i>(leave blank to delete announcement)</i><br />
492: <textarea name="serverannnounce" cols="60" rows="5"></textarea><br />
493: Check machines:<br />
494: SERVERANNOUNCE
495: # list servers
1.42 albertel 496: foreach my $host (sort(keys(%Apache::lonnet::hostname))) {
497: if (&Apache::lonnet::allowed('psa',$Apache::lonnet::hostdom{$host})) {
1.60 albertel 498: $r->print ('<br /><label><input type="checkbox" name="postto_'.$host.'" /> '.
1.42 albertel 499: $host.' <tt>'.$Apache::lonnet::hostname{$host}.'</tt> '.
1.60 albertel 500: '</label><a href="http://'.$Apache::lonnet::hostname{$host}.
1.17 www 501: '/announcement.txt" target="annowin">current</a>');
502: }
503: }
504: $r->print(
505: '<br /><input type="submit" name="serveraction" value="Post"></form><hr />');
506: }
1.3 www 507: if ($allowed) {
1.34 albertel 508: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
509: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.3 www 510: # ----------------------------------------------------- Store new submitted one
1.34 albertel 511: if ($env{'form.action'} eq 'new') {
1.9 www 512: my $startdate =
513: &Apache::lonhtmlcommon::get_date_from_form('startdate');
514: my $enddate =
515: &Apache::lonhtmlcommon::get_date_from_form('enddate');
516: unless ($startdate=~/^\d+$/) { $startdate=time; }
517: unless ($enddate=~/^\d+$/) { $enddate=$startdate+1; }
518: if ($startdate>$enddate) {
519: my $buffer=$startdate;
520: $startdate=$enddate;
521: $enddate=$buffer;
522: }
1.3 www 523: &Apache::lonnet::put('calendar',{
1.9 www 524: $startdate.'_'.$enddate =>
1.34 albertel 525: $env{'form.msg'} },$coursedom,$coursenum);
1.36 www 526: if ($env{'form.rsspost'}) {
527: &Apache::lonrss::addentry($coursenum,$coursedom,'Course_Announcements',
528: &mt('Event from [_1] to [_2]',
529: &Apache::lonlocal::locallocaltime($startdate),
530: &Apache::lonlocal::locallocaltime($enddate)),
531: $env{'form.msg'},'/adm/announcements','public');
532: }
1.3 www 533: }
534: # ---------------------------------------------------------------- Remove items
1.34 albertel 535: if ($env{'form.action'} eq 'del') {
1.3 www 536: my @delwhich=();
1.42 albertel 537: foreach my $key (keys(%env)) {
538: if ($key=~/^form\.remove\_(.+)$/) {
1.3 www 539: push(@delwhich,$1);
540: }
541: }
542: &Apache::lonnet::del('calendar',\@delwhich,$coursedom,$coursenum);
543: }
544: # -------------------------------------------------------- Form to post new one
545: my %tomorrowhash=%todayhash;
546: $tomorrowhash{'day'}++;
547: my $tomorrow=&Apache::loncommon::maketime(%tomorrowhash);
548:
1.10 www 549: &editfield($r,$today,$tomorrow,'');
1.3 www 550: }
1.5 www 551: # ----------------------------------------------------- Summarize all calendars
1.52 www 552: my %allcal=&get_all_calendars();
1.5 www 553: # ------------------------------- Initialize table and forward backward buttons
1.3 www 554: my ($pm,$py,$fm,$fy)=($month-1,$year,$month+1,$year);
555: if ($pm<1) { ($pm,$py)=(12,$year-1); }
556: if ($fm>12){ ($fm,$fy)=(1,$year+1); }
1.14 www 557:
1.20 www 558: $r->print('<h1>'.('',&mt('January'),&mt('February'),&mt('March'),
559: &mt('April'),&mt('May'),
560: &mt('June'),&mt('July'),&mt('August'),
561: &mt('September'),&mt('October'),
562: &mt('November'),&mt('December'))[$month].' '.
563: $year.'</h1>');
1.13 www 564: # Reached the end of times, give up
565: if (($year<1970) || ($year>2037)) {
566: $r->print('<h3>No calendar available for this date.</h3>'.
567: '<a href="/adm/announcements?month='.$todayhash{'month'}.
1.47 albertel 568: '&year='.$todayhash{'year'}.'">Current Month</a>'.
569: &Apache::loncommon::end_page());
1.13 www 570: return OK;
571: }
1.49 albertel 572:
573: my $class = "LC_calendar";
574: if ($env{'form.pickdate'} eq 'yes') {
575: $class .= " LC_calendar_pickdate";
576: }
1.13 www 577: $r->print(
1.18 www 578: '<a href="/adm/announcements?month='.$pm.'&year='.$py.
1.20 www 579: ($pickdatemode?$pickinfo:'').'">'.&mt('Previous Month').'</a> '.
1.18 www 580: '<a href="/adm/announcements?month='.$fm.'&year='.$fy.
1.20 www 581: ($pickdatemode?$pickinfo:'').'">'.&mt('Next Month').'</a>'.
1.12 www 582: ' <a href="/adm/announcements?month='.$todayhash{'month'}.
1.18 www 583: '&year='.$todayhash{'year'}.
1.20 www 584: ($pickdatemode?$pickinfo:'').'">'.&mt('Current Month').'</a><p>'.
1.49 albertel 585: '<table class="'.$class.'" cols="7" rows="5"><tr>
586: <th>'.&mt('Sun').'</th>
587: <th>'.&mt('Mon').'</th>
588: <th>'.&mt('Tue').'</th>
589: <th>'.&mt('Wed').'</th>
590: <th>'.&mt('Thu').'</th>
591: <th>'.&mt('Fri').'</th>
592: <th>'.&mt('Sat').'</th></tr>');
1.3 www 593:
594: my $tk=&Apache::loncommon::maketime(%firstday);
595: my $outp;
596: my $nm;
597:
598: # ---------------------------------------------------------------- Actual table
599: $r->print('<tr>');
600: for (my $i=0;$i<$weekday;$i++) { $r->print(&emptycell); }
601: for (my $i=$weekday;$i<=6;$i++) {
1.11 www 602: ($tk,$nm,$outp)=&showday($tk,0,%allcal);
1.3 www 603: $r->print($outp);
604: }
605: $r->print('</tr>');
606:
1.23 www 607: for (my $k=0;$k<=4;$k++) {
1.3 www 608: $r->print('<tr>');
609: for (my $i=0;$i<=6;$i++) {
1.11 www 610: ($tk,$nm,$outp)=&showday($tk,0,%allcal);
1.3 www 611: if ($month!=$nm) { $outp=&emptycell; }
612: $r->print($outp);
613: }
614: $r->print('</tr>');
615: }
616: # ------------------------------------------------------------------- End table
1.7 matthew 617: $r->print('</table>');
1.16 www 618: # ----------------------------------------------------------------- Check marks
1.49 albertel 619: undef(%showedcheck);
1.16 www 620: # --------------------------------------------------------------- Remove button
1.24 www 621: if ($allowed) { $r->print('<input type="button" onClick="removesub()" value="Remove Checked Entries">'.
622: &Apache::loncommon::help_open_topic('Calendar_Remove_Announcement').'</form>'); }
1.7 matthew 623: $r->print('<p>'.
1.18 www 624: '<a href="/adm/announcements?month='.$pm.'&year='.$py.
1.20 www 625: ($pickdatemode?$pickinfo:'').'">'.&mt('Previous Month').'</a> '.
1.18 www 626: '<a href="/adm/announcements?month='.$fm.'&year='.$fy.
1.20 www 627: ($pickdatemode?$pickinfo:'').'">'.&mt('Next Month').'</a>'.
1.12 www 628: ' <a href="/adm/announcements?month='.$todayhash{'month'}.
1.18 www 629: '&year='.$todayhash{'year'}.
1.20 www 630: ($pickdatemode?$pickinfo:'').'">'.&mt('Current Month').'</a></p>'.
1.47 albertel 631: ($pickdatemode?'</font>':'').&Apache::loncommon::end_page());
1.53 www 632: $r->print('<a href="/adm/announcements.ics">'.&mt('Download your Calendar as iCalendar File').'</a>');
1.1 www 633: return OK;
634: }
635:
636: 1;
637: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>