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