--- loncom/interface/lonhtmlcommon.pm	2015/07/17 19:11:06	1.368
+++ loncom/interface/lonhtmlcommon.pm	2017/05/07 13:57:58	1.385
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.368 2015/07/17 19:11:06 raeburn Exp $
+# $Id: lonhtmlcommon.pm,v 1.385 2017/05/07 13:57:58 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -407,7 +407,7 @@ sub textbox {
 ##############################################
 ##############################################
 sub checkbox {
-    my ($name,$checked,$value) = @_;
+    my ($name,$checked,$value,$special) = @_;
     my $Str = '<input type="checkbox" name="'.$name.'" ';
     if (defined($value)) {
         $Str .= 'value="'.$value.'"';
@@ -415,7 +415,7 @@ sub checkbox {
     if ($checked) {
         $Str .= ' checked="checked"';
     }
-    $Str .= ' />';
+    $Str .= $special.' />';
     return $Str;
 }
 
@@ -538,6 +538,8 @@ sub date_setter {
 
     if (! defined($state) || $state ne 'disabled') {
         $state = '';
+    } else {
+        $state = 'disabled="disabled"';
     }
     if (! defined($no_hh_mm_ss)) {
         $no_hh_mm_ss = 0;
@@ -673,7 +675,7 @@ ENDJS
     my $minuteselector = qq{<input type="text" name="$dname\_minute" $special $state value="$min" size="3" />};
     my $secondselector= qq{<input type="text" name="$dname\_second" $special $state value="$sec" size="3" />};
     my $cal_link;
-    if (!$nolink) {
+    unless (($nolink) || ($state eq 'disabled')) {
         $cal_link = qq{<a href="javascript:$dname\_opencalendar()">};
     }
     #
@@ -700,7 +702,7 @@ ENDJS
                       $hourselector,$minuteselector,$secondselector).
                    $tzone;
     }
-    if (!$nolink) {
+    unless (($nolink) || ($state eq 'disabled')) {
         $result .= &mt('[_1]Select Date[_2]',$cal_link,'</a>');
     }
     $result .= "</span>\n<!-- end $dname date setting form -->\n";
@@ -1194,9 +1196,9 @@ sub Close_PrgWin {
 # ------------------------------------------------------- Puts directory header
 
 sub crumbs {
-    my ($uri,$target,$prefix,$form,$skiplast)=@_;
+    my ($uri,$target,$prefix,$form,$skiplast,$onclick)=@_;
 # You cannot crumbnify uploaded or adm resources
-    if ($uri=~/^\/*(uploaded|adm)\//) { return &mt('(Internal Course/Group Content)'); }
+    if ($uri=~/^\/*(uploaded|adm)\//) { return &mt('(Internal Course/Community Content)'); }
     if ($target) {
         $target = ' target="'.
                   &Apache::loncommon::escape_single($target).'"';
@@ -1216,13 +1218,19 @@ sub crumbs {
             } else {
                 $path.='/'; 
             }
+            if ($path eq '/res/') {
+                unless (&Apache::lonnet::allowed('bre',$path)) {
+                    $output.="$dir/";
+                    next;
+                }
+            }
             my $href_path = &HTML::Entities::encode($path,'<>&"');
             &Apache::loncommon::inhibit_menu_check(\$href_path);
             if ($form) {
                 my $href = 'javascript:'.$form.".action='".$href_path."';".$form.'.submit();';
-                $output.=qq{<a href="$href"$target>$dir</a>/};
+                $output.=qq{<a href="$href"$onclick$target>$dir</a>/};
             } else {
-                $output.=qq{<a href="$href_path"$target>$dir</a>/};
+                $output.=qq{<a href="$href_path"$onclick$target>$dir</a>/};
             }
         }
     } else {
@@ -1704,7 +1712,8 @@ sub show_return_link {
     if ($env{'request.noversionuri'}=~m{^/priv/} ||
         $env{'request.uri'}=~m{^/priv/}) { return 1; }
     return if ($env{'request.noversionuri'} eq '/adm/supplemental');
-
+    return if (($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') &&
+               (!$env{'request.role.adv'}));
     if (($env{'request.noversionuri'} =~ m{^/adm/(viewclasslist|navmaps)($|\?)})
         || ($env{'request.noversionuri'} =~ m{^/adm/.*/aboutme($|\?)})) {
 
@@ -1718,7 +1727,7 @@ sub show_return_link {
             (($env{'request.noversionuri'}=~/^\/adm\//) &&
              ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
              ($env{'request.noversionuri'}!~
-              m{^/adm/.*/(smppg|bulletinboard)($|\?)})
+              m{^/adm/.*/(smppg|bulletinboard|exttool)($|\?)})
            ));
 }
 
@@ -1868,7 +1877,7 @@ returns: nothing
     
     sub breadcrumbs {
         my ($component,$component_help,$menulink,$helplink,$css_class,$no_mt, 
-            $CourseBreadcrumbs,$topic_help,$topic_help_text) = @_;
+            $CourseBreadcrumbs,$topic_help,$topic_help_text,$crstype) = @_;
         #
         $css_class ||= 'LC_breadcrumbs';
 
@@ -1893,7 +1902,7 @@ returns: nothing
                     $env{'course.'.$env{'request.course.id'}.'.description'};
                 $no_mt_descr = 1;
                 if ($env{'request.noversionuri'} =~ 
-                    m{^/public/($match_domain)/($match_courseid)/syllabus$}) {
+                    m{^/?public/($match_domain)/($match_courseid)/syllabus$}) {
                     unless (($env{'course.'.$env{'request.course.id'}.'.domain'} eq $1) &&
                             ($env{'course.'.$env{'request.course.id'}.'.num'} eq $2)) {
                         $description = 'Menu';
@@ -2192,11 +2201,11 @@ sub docs_breadcrumbs {
         my $foldername=shift(@folders);
         if ($folderpath) {$folderpath.='&';}
         $folderpath.=$folder.'&'.$foldername;
-        my $url;
+        my $url = $env{'request.use_absolute'};
         if ($allowed) {
-            $url = '/adm/coursedocs?folderpath=';
+            $url .= '/adm/coursedocs?folderpath=';
         } else {
-            $url = '/adm/supplemental?folderpath=';
+            $url .= '/adm/supplemental?folderpath=';
         }
         $url .= &escape($folderpath);
         my $name=&unescape($foldername);
@@ -2667,9 +2676,9 @@ sub resource_info_box {
 #
 
 sub display_usage {
-    my ($current_disk_usage,$disk_quota) = @_;
-    my $usage = $current_disk_usage/1000;
-    my $quota = $disk_quota/1000;
+    my ($current_disk_usage,$disk_quota,$context) = @_;
+    my $usage = $current_disk_usage/1024;
+    my $quota = $disk_quota/1024;
     my $percent;
     if ($disk_quota == 0) {
         $percent = 100.0;
@@ -2693,9 +2702,13 @@ sub display_usage {
     if ($prog_width > 100) {
         $prog_width = 100;
     }
+    my $display = 'block';
+    if ($context eq 'authoring') {
+        $display = 'inline';
+    }
     return '
-  <div id="meter1" align="left" '.$cssclass.'>'.&mt('Currently using [_1] of the [_2] available.',$usage.' MB <span style="font-weight:bold;">('.$percent.'%)</span>',$quota.' MB')."\n".
-'   <div id="meter2" style="display:block; margin-top:5px; margin-bottom:5px; margin-left:0px; margin-right:0px; width:400px; border:1px solid #000000; height:10px;">'."\n".
+  <div id="meter1" align="left" style="display:'.$display.'" '.$cssclass.'>'.&mt('Currently using [_1] of the [_2] available.',$usage.' MB <span style="font-weight:bold;">('.$percent.'%)</span>',$quota.' MB')."\n".
+'   <div id="meter2" style="display:block; margin-top:3px; margin-bottom:3px; margin-left:0px; margin-right:0px; width:400px; border:1px solid #000000; height:10px;">'."\n".
 '    <div id="meter3" style="display:block; background-color:'.$color.'; width:'.$prog_width.'%; height:10px; color:#000000; margin:0px;"></div>'."\n".
 '   </div>'."\n".
 '  </div>';
@@ -3464,7 +3477,8 @@ function go(url) {
    if (url!='' && url!= null) {
        currentURL = null;
        currentSymb= null;
-       window.location.href=url;
+       var lcHostname = setLCHost();
+       window.location.href=lcHostname+url;
    }
 }
 
@@ -3483,8 +3497,8 @@ ENDUTILITY
 
 sub jump_to_editres {
     my ($cfile,$home,$switchserver,$forceedit,$forcereg,$symb,$folderpath,
-        $title,$idx,$suppurl,$todocs) = @_;
-    my $jscall;
+        $title,$hostname,$idx,$suppurl,$todocs,$suppanchor) = @_;
+    my ($jscall,$anchor,$usehttp,$usehttps,$is_ext);
     if ($switchserver) {
         if ($home) {
             $cfile = '/adm/switchserver?otherserver='.$home.'&amp;role='.
@@ -3504,7 +3518,40 @@ sub jump_to_editres {
         }
     } else {
         unless ($cfile =~ m{^/priv/}) {
+            if ($cfile =~ m{^(/adm/wrapper/ext/([^#]+))#([^#]+)$}) {
+                $cfile = $1;
+                my $extlink = $2;
+                $anchor = $3;
+                $is_ext = 1;
+                if (($extlink !~ /^https:/) && ($ENV{'SERVER_PORT'} == 443)) {
+                    $usehttp = 1;
+                } elsif ($env{'request.use_absolute'}) {
+                    if ($env{'request.use_absolute'} =~ m{^https://}) {
+                        $usehttps = 1;
+                    }
+                } 
+            } elsif ($cfile =~ m{^/?public/($match_domain)/($match_courseid)/syllabus}) {
+                if ($ENV{'SERVER_PORT'} == 443) {
+                    my ($cdom,$cnum) = ($1,$2);
+                    if (($env{'request.course.id'}) &&
+                        ($env{'course.'.$env{'request.course.id'}.'.num'} eq $cnum) &&
+                        ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $cdom)) {
+                        if ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://}) {
+                            $usehttp = 1;
+                        }
+                    }
+                } elsif ($env{'request.use_absolute'}) {
+                    if ($env{'request.use_absolute'} =~ m{^https://}) {
+                        $usehttps = 1;
+                    }
+                }
+            }
             if ($symb) {
+                if ($anchor ne '') {
+                    if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
+                        $symb = $1.&escape(&escape('#')).$anchor;
+                    }
+                }
                 $cfile .= (($cfile=~/\?/)?'&amp;':'?')."symb=$symb";
             } elsif ($folderpath) {
                 $cfile .= (($cfile=~/\?/)?'&amp;':'?').
@@ -3523,13 +3570,32 @@ sub jump_to_editres {
             }
             if ($forceedit) {
                 $cfile .= (($cfile=~/\?/)?'&amp;':'?').'forceedit=1';
+                if ($usehttps) {
+                    $cfile = $env{'request.use_absolute'}.(($cfile =~ /^\//)? '':'/').$cfile;
+                }
+            } elsif ($usehttp) {
+                if ($hostname ne '') {
+                    $cfile = 'http://'.$hostname.(($cfile =~ /^\//)? '':'/').$cfile;
+                }
+                unless ($is_ext) {
+                    $cfile .= (($cfile=~/\?/)?'&amp;':'?').'usehttp=1';
+                }
+            } elsif ($usehttps) {
+                $cfile = $env{'request.use_absolute'}.(($cfile =~ /^\//)? '':'/').$cfile;
             }
             if ($forcereg) {
                 $cfile .= (($cfile=~/\?/)?'&amp;':'?').'register=1';
             }
             if ($todocs) {
-               $cfile .= (($cfile=~/\?/)?'&amp;':'?').'todocs=1';
+                $cfile .= (($cfile=~/\?/)?'&amp;':'?').'todocs=1';
             }
+            if ($suppanchor ne '') {
+                $cfile .= (($cfile=~/\?/)?'&amp;':'?').'anchor='.
+                          &HTML::Entities::encode($suppanchor,'"<>&');
+            }
+        }
+        if ($anchor ne '') {
+            $cfile .= '#'.$anchor;
         }
         $jscall = "go('".&Apache::loncommon::escape_single($cfile)."')";
     }