Diff for /loncom/interface/lonannounce.pm between versions 1.49 and 1.55

version 1.49, 2006/04/22 16:32:55 version 1.55, 2006/06/26 22:31:56
Line 50  sub editfield { Line 50  sub editfield {
     my $enddateform = &Apache::lonhtmlcommon::date_setter('anno',      my $enddateform = &Apache::lonhtmlcommon::date_setter('anno',
                                                           'enddate',                                                            'enddate',
                                                           $end);                                                            $end);
     my $help=&Apache::loncommon::help_open_menu('','Calendar Add Announcement','Calendar_Add_Announcement','',274,'Communication Tools');      my $help=&Apache::loncommon::help_open_menu('Calendar Add Announcement','Calendar_Add_Announcement',274,'Communication Tools');
     my %lt=&Apache::lonlocal::texthash('post' => 'Post Announcement',      my %lt=&Apache::lonlocal::texthash('post' => 'Post Announcement',
        'start' => 'Starting date',         'start' => 'Starting date',
        'end' => 'Ending date',         'end' => 'Ending date',
Line 81  sub readcalendar { Line 81  sub readcalendar {
         }          }
     }      }
   
     if ($courseid eq $env{'request.course.id'}) {      my $can_see_hidden = $env{'request.role.adv'};
  my $can_see_hidden = $env{'request.role.adv'};      my $navmap;# = Apache::lonnavmaps::navmap->new();
  my $navmap = Apache::lonnavmaps::navmap->new();      my %resourcedata=
  my %resourcedata=   &Apache::lonnet::dump('resourcedata',$coursedom,$coursenum);
     &Apache::lonnet::dump('resourcedata',$coursedom,$coursenum);      foreach my $thiskey (sort keys %resourcedata) {
  foreach my $thiskey (sort keys %resourcedata) {   if ($resourcedata{$thiskey.'.type'}=~/^date/) {
     if ($resourcedata{$thiskey.'.type'}=~/^date/) {      my ($course,$middle,$part,$name)=
  my ($course,$middle,$part,$name)=   ($thiskey=~/^(\w+)\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/);
     ($thiskey=~/^(\w+)\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/);      my $section=&mt('All Students');
  my $section=&mt('All Students');      if ($middle=~/^\[(.*)\]\./) {
  if ($middle=~/^\[(.*)\]\./) {   my $sec=$1;
     my $sec=$1;   # if we have a section don't show ones that aren't ours
     # if we have a section don't show ones that aren't ours   if ($env{'request.course.sec'} &&
     if ($env{'request.course.sec'} &&      $env{'request.course.sec'} ne $sec) { next; }
  $env{'request.course.sec'} ne $sec) { next; }   # if a student without a section don't show any section ones
     # if a student without a section don't show any section ones   if (!$env{'request.role.adv'} &&
     if (!$env{'request.role.adv'} &&      !$env{'request.course.sec'}) { next; }
  !$env{'request.course.sec'}) { next; }   $section=&mt('Group/Section').': '.$1;
     $section=&mt('Group/Section').': '.$1;   $middle=~s/^\[(.*)\]\.//;
     $middle=~s/^\[(.*)\]\.//;      }
       $middle=~s/\.$//;
       my $realm=&mt('All Resources');
       if ($middle eq '___(all)') {
    if (!$can_see_hidden && !$navmap) {
       next;
    }
       } elsif ($middle=~/^(.+)\_\_\_\(all\)$/) {
    my $map_url=$1;
    if (!$can_see_hidden && !$navmap) {
       next;
    }
    if (!$can_see_hidden) {
       my $res = $navmap->getResourceByUrl($map_url);
       if ($res && $res->randomout()) { next; }
    }
    # need to do this looks up in showday or /*cell for speed resaons
    #$realm=&mt('Folder/Map').': '.&Apache::lonnet::gettitle($map_url);
    $realm=&mt('Folder/Map').': '.$map_url;
       } elsif ($middle) {
    if (!$can_see_hidden && !$navmap) {
       next;
  }   }
  $middle=~s/\.$//;   if (!$can_see_hidden) {
  my $realm=&mt('All Resources');      my $res = $navmap->getBySymb($middle);
  if ($middle=~/^(.+)\_\_\_\(all\)$/) {      if ($res && $res->randomout()) { next; }
     my $map_url=$1;  
     if (!$can_see_hidden && !$navmap) {  
  next;  
     }  
     if (!$can_see_hidden) {  
  my $res = $navmap->getResourceByUrl($map_url);  
  if ($res && $res->randomout()) { next; }  
     }  
     $realm=&mt('Folder/Map').': '.&Apache::lonnet::gettitle($map_url);  
  } elsif ($middle) {  
     if (!$can_see_hidden && !$navmap) {  
  next;  
     }  
     if (!$can_see_hidden) {  
  my $res = $navmap->getBySymb($middle);  
  if ($res && $res->randomout()) { next; }  
     }  
     $realm=&mt('Resource').': '.&Apache::lonnet::gettitle($middle);  
  }   }
  my $datetype='';   #$realm=&mt('Resource').': '.&Apache::lonnet::gettitle($middle);
  if ($name eq 'duedate') {    $realm=&mt('Resource').': '.$middle;
     $datetype=&mt('Due');       }
       my $datetype='';
       if ($name eq 'duedate') { 
    $datetype=&mt('Due'); 
 # see if accidentally answerdate is before duedate  # see if accidentally answerdate is before duedate
     my $answerkey=$thiskey;   my $answerkey=$thiskey;
     $answerkey=~s/duedate$/answerdate/;   $answerkey=~s/duedate$/answerdate/;
     if ($resourcedata{$thiskey}>$resourcedata{$answerkey}) {   if ($resourcedata{$thiskey}>$resourcedata{$answerkey}) {
  $datetype='Due and Answer Available';      $datetype=&mt('Due and Answer Available');
     }  
  }   }
  if ($name eq 'opendate') { $datetype=&mt('Opening'); }      }
  if ($name eq 'answerdate') {      if ($name eq 'opendate') { $datetype=&mt('Opening'); }
       if ($name eq 'answerdate') {
 # see if accidentally answerdate is before duedate  # see if accidentally answerdate is before duedate
     my $duekey=$thiskey;   my $duekey=$thiskey;
     $duekey=~s/answerdate$/duedate/;   $duekey=~s/answerdate$/duedate/;
     if ($resourcedata{$duekey}>$resourcedata{$thiskey}) {   if ($resourcedata{$duekey}>$resourcedata{$thiskey}) {
 # forget it  # forget it
  next;      next;
     }    } 
     $datetype=&mt('Answer Available');    $datetype=&mt('Answer Available'); 
  }      }
  $returnhash{$courseid.'@'.$resourcedata{$thiskey}.'_'.      $returnhash{$courseid.'@'.$resourcedata{$thiskey}.'_'.
     $resourcedata{$thiskey}}=      $resourcedata{$thiskey}}=
     'INTERNAL:'.$datetype.': '.$realm.' ('.$section.')';      'INTERNAL:'.$datetype.': '.$realm.' ('.$section.')';
     }  
  }   }
     }      }
     return %returnhash;      return %returnhash;
Line 160  sub emptycell { Line 165  sub emptycell {
   
 sub normalcell {  sub normalcell {
     my ($day,$month,$year,$text)=@_;      my ($day,$month,$year,$text)=@_;
     my $output='';      my $output;
     my @items=&order($text);      my @items=&order($text);
     foreach my $item (@items) {      foreach my $item (@items) {
         if ($item) {          if ($item) {
Line 189  sub normalcell { Line 194  sub normalcell {
     $fullmsg=~s/[\n\r]/\\n/gs;      $fullmsg=~s/[\n\r]/\\n/gs;
             $fullmsg=&HTML::Entities::encode($fullmsg,'<>&"\'');              $fullmsg=&HTML::Entities::encode($fullmsg,'<>&"\'');
             $fullmsg=~s/&/\\&/g;              $fullmsg=~s/&/\\&/g;
       my $short_msg = substr($msg,0,20).((length($msg) > 20)?'...':'');
       if (defined($output)) { $output.='<br />'; }
             $output.='<a href="javascript:alert('."'$fullmsg'".')">'.              $output.='<a href="javascript:alert('."'$fullmsg'".')">'.
        substr($msg,0,20).'...</a><br />';         $short_msg.'</a>';
        }         }
     }      }
     return '<td class="LC_calendar_day'.      return '<td class="LC_calendar_day'.
Line 202  sub normalcell { Line 209  sub normalcell {
   
 sub plaincell {  sub plaincell {
     my ($text)=@_;      my ($text)=@_;
     my $output='';      my $output;
     my @items=&order($text);      my @items=&order($text);
     foreach my $item (@items) {      foreach my $item (@items) {
         if ($item) {          if ($item) {
Line 217  sub plaincell { Line 224  sub plaincell {
      $fullmsg=~s/[\n\r]/\\n/gs;       $fullmsg=~s/[\n\r]/\\n/gs;
             $fullmsg=&HTML::Entities::encode($fullmsg,'<>&"\'');              $fullmsg=&HTML::Entities::encode($fullmsg,'<>&"\'');
             $fullmsg=~s/&/\\&/g;              $fullmsg=~s/&/\\&/g;
       my $short_msg = substr($msg,0,80).((length($msg) > 80)?'...':'');
       if (defined($output)) { $output.='<br />'; }
             $output.='<a href="javascript:alert('."'$fullmsg'".')">'.              $output.='<a href="javascript:alert('."'$fullmsg'".')">'.
        substr($msg,0,80).'...</a><br />';         $short_msg.'</a>';
        }         }
     }      }
     return $output;      return $output;
Line 322  function dialin(day,month,year) { Line 331  function dialin(day,month,year) {
 </script>  </script>
 ENDDIA  ENDDIA
 }  }
   # ----------------------------------------------------- Summarize all calendars
   sub get_all_calendars {
       my %allcal=();
       foreach my $course (sort(&Apache::loncommon::findallcourses())) {
    %allcal=(%allcal,&readcalendar($course));
       }
       return %allcal;
   }
   
   sub output_ics_file {
       my ($r)=@_;
   # RFC 2445 wants CRLF
       my $crlf="\015\012";
   # Header
       $r->print("BEGIN:VCALENDAR$crlf");
       $r->print("VERSION:2.0$crlf");
       $r->print("PRODID:-//LONCAPA//LONCAPA Calendar Output//EN$crlf");
       my %allcal=&get_all_calendars();
       foreach my $event (keys(%allcal)) {
    my ($courseid,$startdate,$enddate)=($event=~/^(\w+)\@(\d+)\_(\d+)$/);
    my $uid=$event;
    $uid=~s/[\W\_]/-/gs;
    $uid.='@loncapa';
    my $summary=$allcal{$event};
    $summary=~s/^INTERNAL\://;
    $summary=~s/\s+/ /gs;
           $summary=$env{'course.'.$courseid.'.description'}.': '.$summary;
    $r->print("BEGIN:VEVENT$crlf");
    $r->print("DTSTART:".&Apache::loncommon::utc_string($startdate).$crlf);
    $r->print("DTEND:".&Apache::loncommon::utc_string($enddate).$crlf);
    $r->print("SUMMARY:$summary$crlf");
    $r->print("UID:$uid$crlf");
    $r->print("END:VEVENT$crlf");
       }
   # Footer
       $r->print("END:VCALENDAR$crlf");
   }
   
 sub handler {  sub handler {
     my $r = shift;      my $r = shift;
       if ($r->uri=~/\.(ics|ical)$/) {
           &Apache::loncommon::content_type($r,'text/calendar');
    &output_ics_file($r);
    return OK;
       }
     &Apache::loncommon::content_type($r,'text/html');      &Apache::loncommon::content_type($r,'text/html');
     $r->send_http_header;      $r->send_http_header;
     return OK if $r->header_only;      return OK if $r->header_only;
Line 475  SERVERANNOUNCE Line 526  SERVERANNOUNCE
         &editfield($r,$today,$tomorrow,'');          &editfield($r,$today,$tomorrow,'');
     }      }
 # ----------------------------------------------------- Summarize all calendars  # ----------------------------------------------------- Summarize all calendars
     my %allcal=();      my %allcal=&get_all_calendars();
     foreach my $course (sort(&Apache::loncommon::findallcourses())) {  
  %allcal=(%allcal,&readcalendar($course));  
     }  
   
 # ------------------------------- Initialize table and forward backward buttons  # ------------------------------- Initialize table and forward backward buttons
     my ($pm,$py,$fm,$fy)=($month-1,$year,$month+1,$year);      my ($pm,$py,$fm,$fy)=($month-1,$year,$month+1,$year);
     if ($pm<1) { ($pm,$py)=(12,$year-1); }      if ($pm<1) { ($pm,$py)=(12,$year-1); }
Line 559  SERVERANNOUNCE Line 606  SERVERANNOUNCE
  '&year='.$todayhash{'year'}.   '&year='.$todayhash{'year'}.
  ($pickdatemode?$pickinfo:'').'">'.&mt('Current Month').'</a></p>'.   ($pickdatemode?$pickinfo:'').'">'.&mt('Current Month').'</a></p>'.
  ($pickdatemode?'</font>':'').&Apache::loncommon::end_page());   ($pickdatemode?'</font>':'').&Apache::loncommon::end_page());
       $r->print('<a href="/adm/announcements.ics">'.&mt('Download your Calendar as iCalendar File').'</a>');
     return OK;      return OK;
 }   } 
   

Removed from v.1.49  
changed lines
  Added in v.1.55


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