--- loncom/interface/londocs.pm	2017/02/20 18:29:22	1.622
+++ loncom/interface/londocs.pm	2017/05/07 13:57:58	1.625
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.622 2017/02/20 18:29:22 raeburn Exp $
+# $Id: londocs.pm,v 1.625 2017/05/07 13:57:58 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+)/exttool)\:?(.*)$}) {
                 $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);
                                     }
                                 }
                             }
@@ -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)(?::|:))//} ) {
                 $is_external = 1;
-            } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$}) {
+            } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttool$}) {
                 $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+/exttool$})) {
         return 1;
     }
     return;
@@ -3838,7 +3851,7 @@ END
 			    |/aboutme$
 			    |/navmaps$
 			    |/bulletinboard$
-                            |/exttools?$
+                            |/exttool$
 			    |\.html$)}x)
              || $isexternal) {
 	    $skip_confirm = 1;
@@ -3988,9 +4001,16 @@ 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+/exttool$}) {
 		$url='/adm/wrapper'.$url;
             } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
                 if (($ENV{'SERVER_PORT'} == 443) &&
@@ -4060,6 +4080,12 @@ END
             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) &&
@@ -4159,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+/exttool$}) {
             $url='/adm/wrapper'.$url;
             $isexttool = 1;
         }
@@ -4184,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+/exttool$}) {
             ($editlink,$extresform) =
                 &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
                                                      undef,undef,undef,'tool',$coursedom,
@@ -6882,6 +6908,10 @@ sub editing_js {
                         }
                         $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,'<>&"');