Diff for /loncom/interface/lonnavmaps.pm between versions 1.509.2.5.4.2 and 1.509.2.7

version 1.509.2.5.4.2, 2017/09/15 23:17:24 version 1.509.2.7, 2018/09/04 19:48:58
Line 486  use Apache::lonlocal; Line 486  use Apache::lonlocal;
 use Apache::lonnet;  use Apache::lonnet;
 use Apache::lonmap;  use Apache::lonmap;
   
 use POSIX qw (ceil floor strftime);  use POSIX qw (floor strftime);
 use Time::HiRes qw( gettimeofday tv_interval );  use Time::HiRes qw( gettimeofday tv_interval );
 use LONCAPA;  use LONCAPA;
 use DateTime();  use DateTime();
Line 643  sub getDescription { Line 643  sub getDescription {
             } elsif ($slot_status == $res->RESERVABLE) {              } elsif ($slot_status == $res->RESERVABLE) {
                 $slotmsg = &mt('Reservable, reservations close [_1]',                  $slotmsg = &mt('Reservable, reservations close [_1]',
                            timeToHumanString($slot_time,'end'));                             timeToHumanString($slot_time,'end'));
               } elsif ($slot_status == $res->NEEDS_CHECKIN) {
                   $slotmsg = &mt('Reserved, check-in needed - ends [_1]',
                              timeToHumanString($slot_time,'end'));
             } elsif ($slot_status == $res->RESERVABLE_LATER) {              } elsif ($slot_status == $res->RESERVABLE_LATER) {
                 $slotmsg = &mt('Reservable, reservations open [_1]',                  $slotmsg = &mt('Reservable, reservations open [_1]',
                            timeToHumanString($slot_time,'start'));                             timeToHumanString($slot_time,'start'));
Line 938  sub render_resource { Line 941  sub render_resource {
     # links to open and close the folder      # links to open and close the folder
   
     my $whitespace = $location.'/whitespace_21.gif';      my $whitespace = $location.'/whitespace_21.gif';
     my $linkopen = "<img src='$whitespace' alt='' />"."<a href=\"$link\">";      my $linkopen = "<img src='$whitespace' alt='' />";
       my $nomodal;
       if (($params->{'modalLink'}) && (!$resource->is_sequence())) {
           if ($link =~m{^(?:|/adm/wrapper)/ext/([^#]+)}) {
               my $exturl = $1;
               if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
                   $nomodal = 1;
               }
           } elsif (($link eq "/public/$LONCAPA::match_domain/$LONCAPA::match_courseid/syllabus") &&
                    ($env{'request.course.id'}) && ($ENV{'SERVER_PORT'} == 443) &&
                    ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
                $nomodal = 1;
           }
           my $esclink = &js_escape($link);
           if ($nomodal) {
               $linkopen .= "<a href=\"#\" onclick=\"javascript:window.open('$esclink','resourcepreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1'); return false;\" />";
           } else {
               $linkopen .= "<a href=\"$link\" onclick=\"javascript:openMyModal('$esclink',600,500,'yes','true'); return false;\">";
           }
       } else {
           $linkopen .= "<a href=\"$link\">";
       }
     my $linkclose = "</a>";      my $linkclose = "</a>";
   
     # Default icon: unknown page      # Default icon: unknown page
Line 992  sub render_resource { Line 1016  sub render_resource {
             # Don't allow users to manipulate folder              # Don't allow users to manipulate folder
             $icon = "navmap.$folderType." . ($nowOpen ? 'closed' : 'open') . '.gif';              $icon = "navmap.$folderType." . ($nowOpen ? 'closed' : 'open') . '.gif';
             $icon = "<img class=\"LC_space\" src='$whitespace' alt='' />"."<img class=\"LC_contentImage\" src='$location/$icon' alt=\"".($nowOpen ? &mt('Open Folder') : &mt('Close Folder')).' '.$title."\" />";              $icon = "<img class=\"LC_space\" src='$whitespace' alt='' />"."<img class=\"LC_contentImage\" src='$location/$icon' alt=\"".($nowOpen ? &mt('Open Folder') : &mt('Close Folder')).' '.$title."\" />";
             if ($params->{'caller'} eq 'sequence') {  
                 $linkopen = "<a href=\"$link\">";              $linkopen = "";
             } else {              $linkclose = "";
                 $linkopen = "";  
                 $linkclose = "";  
             }  
         }          }
         if (((&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) ||          if (((&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) ||
              (&Apache::lonnet::allowed('cev',$env{'request.course.id'}))) &&               (&Apache::lonnet::allowed('cev',$env{'request.course.id'}))) &&
Line 1066  sub render_resource { Line 1087  sub render_resource {
     }      }
   
     if (!$params->{'resource_nolink'} && !$resource->is_sequence() && !$resource->is_empty_sequence) {      if (!$params->{'resource_nolink'} && !$resource->is_sequence() && !$resource->is_empty_sequence) {
         $result .= "$curMarkerBegin<a href=\"$link\">$title$partLabel</a>$curMarkerEnd$editmapLink$nonLinkedText</td>";          $linkclose = '</a>';
     } else {          if ($params->{'modalLink'}) {
         $result .= "$curMarkerBegin$linkopen$title$partLabel</a>$curMarkerEnd$editmapLink$nonLinkedText</td>";              my $esclink = &js_escape($link);
               if ($nomodal) {
                   $linkopen = "<a href=\"#\" onclick=\"javascript:window.open('$esclink','resourcepreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1'); return false;\" />";
               } else {
                   $linkopen = "<a href=\"$link\" onclick=\"javascript:openMyModal('$esclink',600,500,'yes','true'); return false;\">";
               }
           } else {
               $linkopen = "<a href=\"$link\">";
           }
     }      }
       $result .= "$curMarkerBegin$linkopen$title$partLabel$linkclose$curMarkerEnd$editmapLink$nonLinkedText</td>";
   
     return $result;      return $result;
 }  }
Line 1360  sub render { Line 1390  sub render {
             my $currenturl = $env{'form.postdata'};              my $currenturl = $env{'form.postdata'};
             #$currenturl=~s/^http\:\/\///;              #$currenturl=~s/^http\:\/\///;
             #$currenturl=~s/^[^\/]+//;              #$currenturl=~s/^[^\/]+//;
             unless ($args->{'caller'} eq 'sequence') {              
                 $here = $jump = &Apache::lonnet::symbread($currenturl);              $here = $jump = &Apache::lonnet::symbread($currenturl);
             }  
  }   }
  if (($here eq '') && ($args->{'caller'} ne 'sequence')) {   if ($here eq '') {
     my $last;      my $last;
     if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',      if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
                     &GDBM_READER(),0640)) {                      &GDBM_READER(),0640)) {
Line 1691  END Line 1720  END
     }      }
   
   
       my $inhibitmenu;
       if ($args->{'modalLink'}) {
           $inhibitmenu = '&amp;inhibitmenu=yes';
       }
   
     while (1) {      while (1) {
  if ($args->{'sort'}) {   if ($args->{'sort'}) {
     $curRes = shift(@resources);      $curRes = shift(@resources);
Line 1823  END Line 1857  END
  $stack=$it->getStack();   $stack=$it->getStack();
     }      }
     ($src,$symb,$anchor)=getLinkForResource($stack);      ($src,$symb,$anchor)=getLinkForResource($stack);
             my $srcHasQuestion = $src =~ /\?/;   
     if (defined($anchor)) { $anchor='#'.$anchor; }      if (defined($anchor)) { $anchor='#'.$anchor; }
             if (($args->{'caller'} eq 'sequence') && ($curRes->is_map())) {      my $srcHasQuestion = $src =~ /\?/;
                 $args->{"resourceLink"} = $src.($srcHasQuestion?'&amp;':'?') .'navmap=1';      $args->{"resourceLink"} = $src.
             } else {   ($srcHasQuestion?'&amp;':'?') .
                 $args->{"resourceLink"} = $src.   'symb=' . &escape($symb).$inhibitmenu.$anchor;
     ($srcHasQuestion?'&amp;':'?') .  
     'symb=' . &escape($symb).$anchor;  
             }  
  }   }
         # Now, we've decided what parts to show. Loop through them and          # Now, we've decided what parts to show. Loop through them and
         # show them.          # show them.
Line 2245  sub generate_email_discuss_status { Line 2275  sub generate_email_discuss_status {
     foreach my $msgid (@keys) {      foreach my $msgid (@keys) {
  if ((!$emailstatus{$msgid}) || ($emailstatus{$msgid} eq 'new')) {   if ((!$emailstatus{$msgid}) || ($emailstatus{$msgid} eq 'new')) {
             my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid,              my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid,
                 $symb,$error) = &Apache::lonmsg::unpackmsgid(&LONCAPA::escape($msgid));                  $symb,$error) = &Apache::lonmsg::unpackmsgid($msgid);
             &Apache::lonenc::check_decrypt(\$symb);               &Apache::lonenc::check_decrypt(\$symb); 
             if (($fromcid ne '') && ($fromcid ne $cid)) {              if (($fromcid ne '') && ($fromcid ne $cid)) {
                 next;                  next;
Line 2759  sub recurseup_maps { Line 2789  sub recurseup_maps {
     return @recurseup;      return @recurseup;
 }  }
   
 sub recursed_crumbs {  
     my ($self,$mapurl,$restitle) = @_;  
     my (@revmapinfo,@revmapres);  
     my $mapres = $self->getResourceByUrl($mapurl);  
     if (ref($mapres)) {  
         @revmapres = map { $self->getByMapPc($_); } split(/,/,$mapres->map_breadcrumbs());  
         shift(@revmapres);  
     }  
     my $allowedlength = 60;  
     my $minlength = 5;  
     my $allowedtitle = 30;  
     if (($env{'environment.icons'} eq 'iconsonly') && (!$env{'browser.mobile'})) {  
         $allowedlength = 100;  
         $allowedtitle = 70;  
     }  
     if (length($restitle) > $allowedtitle) {  
         $restitle = &truncate_crumb_text($restitle,$allowedtitle);  
     }  
     my $totallength = length($restitle);  
     my @links;  
   
     foreach my $map (@revmapres) {  
         my $pc = $map->map_pc();  
         next if ((!$pc) || ($pc == 1));  
         push(@links,$map);  
         push(@revmapinfo,{'href' => $map->link().'?navmap=1','text' => $map->title(),'no_mt' => 1,});  
         $totallength += length($map->title());  
     }  
     my $numlinks = scalar(@links);  
     if ($numlinks) {  
         if ($totallength - $allowedlength > 0) {  
             my $available = $allowedlength - length($restitle);  
             my $avg = POSIX::ceil($available/$numlinks);  
             if ($avg < $minlength) {  
                 $avg = $minlength;  
             }  
             @revmapinfo = ();  
             foreach my $map (@links) {  
                 my $showntitle = &truncate_crumb_text($map->title(),$avg);  
                 if ($showntitle ne '') {  
                     push(@revmapinfo,{'href' => $map->link().'?navmap=1','text' => $showntitle,'no_mt' => 1,});  
                 }  
             }  
         }  
     }  
     if ($restitle ne '') {  
         push(@revmapinfo,{'text' => $restitle, 'no_mt' => 1});  
     }  
     return @revmapinfo;  
 }  
   
 sub truncate_crumb_text {  
     my ($title,$limit) = @_;  
     my $showntitle = '';  
     if (length($title) > $limit) {  
         my @words = split(/\b\s*/,$title);  
         if (@words == 1) {  
             $showntitle = substr($title,0,$limit).' ...';  
         } else {  
             my $linklength = 0;  
             my $num = 0;  
             foreach my $word (@words) {  
                 $linklength += 1+length($word);  
                 if ($word eq '-') {  
                     $showntitle =~ s/ $//;  
                     $showntitle .= $word;  
                 } elsif ($linklength > $limit) {  
                     if ($num < @words) {  
                         $showntitle .= $word.' ...';  
                         last;  
                     } else {  
                         $showntitle .= $word;  
                     }  
                 } else {  
                     $showntitle .= $word.' ';  
                 }  
             }  
             $showntitle =~ s/ $//;  
         }  
         return $showntitle;  
     } else {  
         return $title;  
     }  
 }  
   
 #  #
 #  Determines the open/close dates for printing a map that  #  Determines the open/close dates for printing a map that
 #  encloses a resource.  #  encloses a resource.
Line 4466  Returns a string with a comma-separated Line 4411  Returns a string with a comma-separated
 for the hierarchy of maps containing a map, with the top level  for the hierarchy of maps containing a map, with the top level
 map first, then descending to deeper levels, with the enclosing map last.  map first, then descending to deeper levels, with the enclosing map last.
   
 =item * B<map_breadcrumbs>:  
   
 Same as map_hierarchy, except maps containing only a single itemm if  
 it's a map, or containing no items are omitted, unless it's the top  
 level map (map_pc = 1), which is always included.  
   
 =back  =back
   
 =cut  =cut
Line 4507  sub map_hierarchy { Line 4446  sub map_hierarchy {
     my $pc = $self->map_pc();      my $pc = $self->map_pc();
     return $self->navHash("map_hierarchy_$pc", 0);      return $self->navHash("map_hierarchy_$pc", 0);
 }  }
 sub map_breadcrumbs {  
     my $self = shift;  
     my $pc = $self->map_pc();  
     return $self->navHash("map_breadcrumbs_$pc", 0);  
 }  
   
 #####  #####
 # Property queries  # Property queries
Line 4736  sub duedate { Line 4670  sub duedate {
     my $date;      my $date;
     my @interval=$self->parmval("interval", $part);      my @interval=$self->parmval("interval", $part);
     my $due_date=$self->parmval("duedate", $part);      my $due_date=$self->parmval("duedate", $part);
     if ($interval[0] =~ /^(\d+)/) {      if ($interval[0] =~ /\d+/) {
         my $timelimit = $1;         my $first_access=&Apache::lonnet::get_first_access($interval[1],
         my $first_access=&Apache::lonnet::get_first_access($interval[1],  
                                                           $self->{SYMB});                                                            $self->{SYMB});
  if (defined($first_access)) {   if (defined($first_access)) {
             my $interval = $first_access+$timelimit;             my $interval = $first_access+$interval[0];
     $date = (!$due_date || $interval < $due_date) ? $interval       $date = (!$due_date || $interval < $due_date) ? $interval 
                                                           : $due_date;                                                            : $due_date;
  } else {   } else {
Line 5647  sub check_for_slot { Line 5580  sub check_for_slot {
                                 ($checkedin,$checkedinslot) = $self->checkedin();                                  ($checkedin,$checkedinslot) = $self->checkedin();
                                 unless ((grep(/^\Q$checkedin\E/,@proctors)) &&                                  unless ((grep(/^\Q$checkedin\E/,@proctors)) &&
                                         ($checkedinslot eq $slot_name)) {                                          ($checkedinslot eq $slot_name)) {
                                     return (NEEDS_CHECKIN,undef,$slot_name);                                       return (NEEDS_CHECKIN,$end,$slot_name); 
                                 }                                  }
                             }                              }
                             return (RESERVED,$end,$slot_name);                              return (RESERVED,$end,$slot_name);

Removed from v.1.509.2.5.4.2  
changed lines
  Added in v.1.509.2.7


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