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