--- loncom/interface/londocs.pm	2016/11/30 00:27:20	1.618
+++ loncom/interface/londocs.pm	2017/05/08 14:20:20	1.626
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.618 2016/11/30 00:27:20 raeburn Exp $
+# $Id: londocs.pm,v 1.626 2017/05/08 14:20:20 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -654,11 +654,12 @@ sub group_import {
             }
         }
 	if ($url) {
-            if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/exttool)s?\:?(.*)$}) {
+            if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
                 $url = $1;
                 my $marker = $2;
                 my $info = $3;
                 my ($toolid,%toolhash,%toolsettings);
+                my @extras = ('linktext','explanation','crslabel','crstitle');
                 my @toolinfo = split(/:/,$info);
                 if ($residx) {
                     %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
@@ -668,28 +669,36 @@ sub group_import {
                 }
                 $toolid =~ s/\D//g;
                 ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
+                 $toolhash{'linktext'},$toolhash{'explanation'},
                  $toolhash{'crslabel'},$toolhash{'crstitle'}) = @toolinfo;
-                $toolhash{'crslabel'} = &unescape($toolhash{'crslabel'});
-                $toolhash{'crstitle'} = &unescape($toolhash{'crstitle'});
+                foreach my $item (@extras) {
+                    $toolhash{$item} = &unescape($toolhash{$item});
+                }
                 if (ref($ltitoolsref) eq 'HASH') {
                     my @deleted;
                     if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
-                        if ($ltitoolsref->{$toolid}->{'url'} =~ m{^https://}) {
-                            $url =~ s/exttool$/exttools/;
-                        }
                         $toolhash{'id'} = $toolid;
                         if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'window')) {
                             if ($toolhash{'target'} eq 'window') {
                                 foreach my $item ('width','height') {
                                     $toolhash{$item} =~ s/^\s+//;
                                     $toolhash{$item} =~ s/\s+$//;
+                                    if ($toolhash{$item} =~ /\D/) {
+                                        delete($toolhash{$item});
+                                        if ($residx) {
+                                            if ($toolsettings{$item}) {
+                                                push(@deleted,$item);
+                                            }
+                                        }
+                                    }
                                 }
                             }
                         } elsif ($residx) {
                             $toolhash{'target'} = $toolsettings{'target'};
                             if ($toolhash{'target'} eq 'window') {
-                                $toolhash{'width'} = $toolsettings{'width'};
-                                $toolhash{'height'} = $toolsettings{'height'};  
+                                foreach my $item ('width','height') { 
+                                    $toolhash{$item} = $toolsettings{$item};
+                                }
                             }
                         } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
                             $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
@@ -699,31 +708,35 @@ sub group_import {
                             }
                         }
                         if ($toolhash{'target'} eq 'iframe') {
-                            delete($toolhash{'width'});
-                            delete($toolhash{'height'});
-                            if ($residx) {
-                                if ($toolsettings{'width'}) {
-                                    push(@deleted,'width');
-                                }
-                                if ($toolsettings{'height'}) {
-                                    push(@deleted,'height');
+                            foreach my $item ('width','height','linktext','explanation') {
+                                delete($toolhash{$item});
+                                if ($residx) {
+                                    if ($toolsettings{$item}) {
+                                        push(@deleted,$item);
+                                    }
                                 }
                             }
                         }
                         if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
-                            foreach my $item ('label','title') { 
+                            foreach my $item ('label','title','linktext','explanation') {
+                                my $crsitem;
+                                if (($item eq 'label') || ($item eq 'title')) {
+                                    $crsitem = 'crs'.$item;
+                                } else {
+                                    $crsitem = $item;
+                                }
                                 if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
-                                    $toolhash{'crs'.$item} =~ s/^\s+//;
-                                    $toolhash{'crs'.$item} =~ s/\s+$//;
-                                    if ($toolhash{'crs'.$item} eq '') {
-                                        delete($toolhash{'crs'.$item});
+                                    $toolhash{$crsitem} =~ s/^\s+//;
+                                    $toolhash{$crsitem} =~ s/\s+$//;
+                                    if ($toolhash{$crsitem} eq '') {
+                                        delete($toolhash{$crsitem});
                                     }
                                 } else {
-                                    delete($toolhash{'crs'.$item});
+                                    delete($toolhash{$crsitem});
                                 }
-                                if (($residx) && (exists($toolsettings{'crs'.$item}))) {
-                                    unless (exists($toolhash{'crs'.$item})) {
-                                        push(@deleted,'crs'.$item);
+                                if (($residx) && (exists($toolsettings{$crsitem}))) {
+                                    unless (exists($toolhash{$crsitem})) {
+                                        push(@deleted,$crsitem);
                                     }
                                 }
                             }
@@ -920,7 +933,7 @@ sub docs_change_log {
              '// <![CDATA['."\n".
              &Apache::loncommon::display_filter_js('docslog')."\n".
              &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
-                         $coursedom,$coursenum,'','',$canedit,\$navmap)."\n".
+                         $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
              &history_tab_js()."\n".
              &Apache::lonratedt::editscript('simple')."\n".
              '// ]]>'."\n".
@@ -1279,7 +1292,7 @@ sub print_paste_buffer {
             my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
             if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?:&colon;|:))//} ) {
                 $is_external = 1;
-            } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$}) {
+            } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
                 $is_exttool = 1;
             }
             if ($folder =~ /^supplemental/) {
@@ -1490,7 +1503,7 @@ sub supp_pasteable {
         ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
         ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
         ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
-        ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$})) {
+        ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
         return 1;
     }
     return;
@@ -3009,7 +3022,7 @@ sub handle_edit_cmd {
 sub editor {
     my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
         $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
-        $canedit,$navmapref,$hiddentop)=@_;
+        $canedit,$hostname,$navmapref,$hiddentop)=@_;
     my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
     if ($allowed) {
         (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
@@ -3220,7 +3233,7 @@ sub editor {
                         } else {
                             return $errortxt;
                         }
-                    } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/exttool}) {
+                    } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
                         my ($suffix,$errortxt,$locknotfreed) =
                             &new_timebased_suffix($coursedom,$coursenum,'exttool');
                         if ($locknotfreed) {
@@ -3339,7 +3352,8 @@ sub editor {
         $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
                               $coursenum,$coursedom,$crstype,
                               $pathitem,$supplementalflag,$container,
-                              \%filters,\%curr_groups,$ltitoolsref,$canedit,$isencrypted,$navmapref);
+                              \%filters,\%curr_groups,$ltitoolsref,$canedit,
+                              $isencrypted,$navmapref,$hostname);
         $idx++;
         $shown++;
     }
@@ -3720,7 +3734,7 @@ sub is_supplemental_title {
 sub entryline {
     my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
         $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
-        $ltitoolsref,$canedit,$isencrypted,$navmapref)=@_;
+        $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_;
     my ($foldertitle,$renametitle,$oldtitle);
     if (&is_supplemental_title($title)) {
 	($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
@@ -3837,7 +3851,7 @@ END
 			    |/aboutme$
 			    |/navmaps$
 			    |/bulletinboard$
-                            |/exttools?$
+                            |/ext\.tool$
 			    |\.html$)}x)
              || $isexternal) {
 	    $skip_confirm = 1;
@@ -3969,7 +3983,7 @@ END
 	}
     }
 
-    my ($editlink,$extresform,$anchor,$hiddenres);
+    my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
     my $orig_url = $url;
     $orig_url=~s{http(&colon;|:)//https(&colon;|:)//}{https$2//};
     $url=~s{^http(|s)(&colon;|:)//}{/adm/wrapper/ext/};
@@ -3987,10 +4001,23 @@ END
 	        } elsif ($url!~/\.(sequence|page)$/) {
 		    $url='/adm/coursedocs/showdoc'.$url;
 	        }
-	    } elsif ($url=~m|^/ext/|) {
-	        $url='/adm/wrapper'.$url;
-	    } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
+	    } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
+                my $wrapped = $1;
+                my $exturl = $2;
+                if ($wrapped eq '') {
+                    $url='/adm/wrapper'.$url;
+                }
+                if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
+                    $nomodal = 1;
+                }
+	    } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
 		$url='/adm/wrapper'.$url;
+            } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
+                if (($ENV{'SERVER_PORT'} == 443) &&
+                    ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
+                    $url .= '?usehttp=1';
+                    $nomodal = 1;
+                }
             }
             if (&Apache::lonnet::symbverify($symb,$url)) {
                 my $shownsymb = $symb;
@@ -4020,7 +4047,7 @@ END
                 if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
                       $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
                     $checkencrypt = 1;
-                } else {
+                } elsif (ref($navmapref)) {
                     unless (ref($$navmapref)) {
                         $$navmapref = Apache::lonnavmaps::navmap->new();
                     }
@@ -4048,11 +4075,26 @@ END
                 $url='';
             }
 	}
-    } elsif ($supplementalflag) { 
+    } elsif ($supplementalflag) {
         if ($isexternal) {
             if ($url =~ /^([^#]+)#([^#]+)$/) {
                 $url = $1;
                 $anchor = $2;
+                if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
+                    if ($hostname ne '') {
+                        $url = 'http://'.$hostname.$url;
+                    }
+                    $nomodal = 1;
+                }
+            }
+        } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
+            if (($ENV{'SERVER_PORT'} == 443) &&
+                ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
+                if ($hostname ne '') {
+                    $url = 'http://'.$hostname.$url;
+                }
+                $url .= (($url =~ /\?/) ? '&amp;':'?').'usehttp=1';
+                $nomodal = 1;
             }
         }
     }
@@ -4075,25 +4117,29 @@ END
             my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
                                               'parameter_encrypturl'))[0]=~/^yes$/i);
             unless ($hiddenmap) {
-                unless (ref($$navmapref)) {
-                    $$navmapref = Apache::lonnavmaps::navmap->new();
-                }
-                if (ref($$navmapref)) {
-                    if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
-                        my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
-                        unless (@resources) {
-                            $hiddenmap = 1;
-                            unless ($env{'request.role.adv'}) {  
-                                $url = '';
-                                $hiddenfolder = 1;
+                if (ref($navmapref)) {
+                    unless (ref($$navmapref)) {
+                        $$navmapref = Apache::lonnavmaps::navmap->new();
+                    }
+                    if (ref($$navmapref)) {
+                        if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
+                            my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
+                            unless (@resources) {
+                                $hiddenmap = 1;
+                                unless ($env{'request.role.adv'}) {  
+                                    $url = '';
+                                    $hiddenfolder = 1;
+                                }
                             }
                         }
                     }
                 }
             }
             unless ($encryptmap) {
-                if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
-                    $encryptmap = 1;
+                if ((ref($navmapref)) && (ref($$navmapref))) {
+                    if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
+                        $encryptmap = 1;
+                    }
                 }
             }
             
@@ -4139,7 +4185,7 @@ $form_end;
         }
     } elsif ($supplementalflag && !$allowed) {
         my $isexttool;
-        if ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
+        if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
             $url='/adm/wrapper'.$url;
             $isexttool = 1;
         }
@@ -4164,7 +4210,7 @@ $form_end;
                 &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
                                                      undef,undef,undef,undef,undef,undef,
                                                      undef,$disabled);
-        } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
+        } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
             ($editlink,$extresform) =
                 &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
                                                      undef,undef,undef,'tool',$coursedom,
@@ -4183,7 +4229,8 @@ $form_end;
                                                             $forceedit,
                                                             undef,$symb,
                                                             &escape($env{'form.folderpath'}),
-                                                            $renametitle,'','',1,$suppanchor);
+                                                            $renametitle,$hostname,
+                                                            '','',1,$suppanchor);
                 if ($jscall) {
                     $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
                                 $jscall.'" >'.&mt('Edit').'</a>&nbsp;'."\n";
@@ -4200,6 +4247,7 @@ $form_end;
         $reinit = &mt('(re-initialize course to access)');
     }
     $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
+    my $link;
     if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
        $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
     } elsif ($url) {
@@ -4210,9 +4258,20 @@ $form_end;
                $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
            }
        }
-       $line.=&Apache::loncommon::modal_link(&js_escape($url.(($url=~/\?/)?'&amp;':'?').'inhibitmenu=yes'.
-                                             (($anchor ne '')?$anchor:'')),
-                                             '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
+       if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
+           $link = 'http://'.$hostname.$url;
+       } else {
+           $link = $url;
+       }
+       $link = &js_escape($link.(($url=~/\?/)?'&amp;':'?').'inhibitmenu=yes'.
+                                               (($anchor ne '')?$anchor:''));
+       if ($nomodal) {
+           $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
+                  '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
+       } else {
+           $line.=&Apache::loncommon::modal_link($link,
+                                                 '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
+       }
     } else {
        $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
     }
@@ -4220,9 +4279,12 @@ $form_end;
     if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
        $line.='<a href="'.$url.'">'.$title.'</a>';
     } elsif ($url) {
-       $line.=&Apache::loncommon::modal_link(&js_escape($url.(($url=~/\?/)?'&amp;':'?').'inhibitmenu=yes'.
-                                             (($anchor ne '')?$anchor:'')),
-                                             $title,600,500);
+       if ($nomodal) {
+           $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
+                  $title.'</a>';
+       } else {
+           $line.=&Apache::loncommon::modal_link($link,$title,600,500);
+       }
     } elsif (($hiddenfolder) || ($hiddenres)) {
        $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">'.&mt('(Hidden)').'</span>';
     } else {
@@ -4363,6 +4425,8 @@ sub new_timebased_suffix {
             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
         } elsif ($type eq 'smppg') {
             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
+        } elsif ($type eq 'exttool') {
+            $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
         } else {
             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
         }
@@ -4391,6 +4455,9 @@ sub new_timebased_suffix {
         } elsif ($type eq 'smppg') {
             $locknotfreed .=
                 &mt('This will prevent creation of additional simple pages in this course.');
+        } elsif ($type eq 'exttool') {
+            $locknotfreed .=
+                &mt('This will prevent creation of additional external tools in this course.');
         } else {
             $locknotfreed .=
                 &mt('This will prevent creation of additional discussion boards in this course.');
@@ -5343,8 +5410,9 @@ sub handler {
             my $tabidstr = join("','",@tabids);
             %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);
             my $posslti = keys(%ltitools);
+            my $hostname = $r->hostname();
 	    $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
-                                   $londocroot,$canedit,\$navmap).
+                                   $londocroot,$canedit,$hostname,\$navmap).
                        &history_tab_js().
                        &inject_data_js().
                        &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
@@ -5557,7 +5625,7 @@ sub handler {
     if ($disk_quota == 0) {
         $percent = 100.0;
     } else {
-        $percent = 100*($current_disk_usage/$disk_quota);
+        $percent = 100*($usage/$disk_quota);
     }
     $usage = sprintf("%.2f",$usage);
     $quota = sprintf("%.2f",$quota);
@@ -5746,7 +5814,7 @@ HIDDENFORM
     }
 
 #
-
+    my $hostname = $r->hostname();
     my $savefolderpath;
 
     if ($allowed) {
@@ -6216,7 +6284,7 @@ unless ($container eq 'page') {
        unless (($supplementalflag || $toolsflag)) {
           my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
                               $supplementalflag,\%orderhash,$iconpath,$pathitem,
-                              \%ltitools,$canedit,\$navmap,$hiddentop);
+                              \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
           undef($navmap);
           if ($error) {
              $r->print('<p><span class="LC_error">'.$error.'</span></p>');
@@ -6365,7 +6433,7 @@ my %suporderhash = (
         if ($supplementalflag) {
            my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
                                $supplementalflag,\%suporderhash,$iconpath,$pathitem,
-                               \%ltitools,$canedit);
+                               \%ltitools,$canedit,$hostname);
            if ($error) {
               $r->print('<p><span class="LC_error">'.$error.'</span></p>');
            } else {
@@ -6385,7 +6453,7 @@ my %suporderhash = (
         }
     } elsif ($supplementalflag) {
         my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
-                            $supplementalflag,'',$iconpath,$pathitem);
+                            $supplementalflag,'',$iconpath,$pathitem,'','',$hostname);
         if ($error) {
             $r->print('<p><span class="LC_error">'.$error.'</span></p>');
         }
@@ -6759,7 +6827,8 @@ END
 }
 
 sub editing_js {
-    my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,$londocroot,$canedit,$navmapref) = @_;
+    my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
+        $londocroot,$canedit,$hostname,$navmapref) = @_;
     my %js_lt = &Apache::lonlocal::texthash(
                                           p_mnf => 'Name of New Folder',
                                           t_mnf => 'New Folder',
@@ -6836,6 +6905,19 @@ sub editing_js {
                 }
                 $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='.
                              &HTML::Entities::encode($caller,'<>&"');
+                if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
+                    if (($ENV{'SERVER_PORT'} == 443) &&
+                        ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
+                        if ($hostname ne '') {
+                            $backtourl = 'http://'.$hostname.$backtourl;
+                        }
+                        $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
+                    }
+                } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
+                    if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
+                        $backtourl = 'http://'.$hostname.$backtourl;
+                    }
+                }
                 if ($anchor ne '') {
                     $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
                 }