--- loncom/interface/londocs.pm	2017/11/16 23:45:03	1.484.2.72.2.4
+++ loncom/interface/londocs.pm	2020/04/10 12:52:34	1.484.2.72.4.2
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.484.2.72.2.4 2017/11/16 23:45:03 raeburn Exp $
+# $Id: londocs.pm,v 1.484.2.72.4.2 2020/04/10 12:52:34 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -656,7 +656,7 @@ sub group_import {
                 my $marker = $2;
                 my $info = $3;
                 my ($toolid,%toolhash,%toolsettings);
-                my @extras = ('linktext','explanation','crslabel','crstitle'); 
+                my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
                 my @toolinfo = split(/:/,$info);
                 if ($residx) {
                     %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
@@ -667,7 +667,7 @@ sub group_import {
                 $toolid =~ s/\D//g;
                 ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
                  $toolhash{'linktext'},$toolhash{'explanation'},
-                 $toolhash{'crslabel'},$toolhash{'crstitle'}) = @toolinfo;
+                 $toolhash{'crslabel'},$toolhash{'crstitle'},$toolhash{'crsappend'}) = @toolinfo;
                 foreach my $item (@extras) {
                     $toolhash{$item} = &unescape($toolhash{$item});
                 }
@@ -1325,8 +1325,7 @@ sub print_paste_buffer {
                         }
                         $is_uploaded_map = 1;
                     }
-                } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
-                         ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
+                } elsif ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$}) {
                     if ($cid ne $env{'request.course.id'}) {
                         my ($srcdom,$srcnum) = split(/_/,$cid);
                         if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
@@ -1347,7 +1346,7 @@ sub print_paste_buffer {
                push(@pasteable,$suffix);
             }
             my $buffer;
-            if ($is_external) { 
+            if ($is_external) {
                 $buffer = &mt('External Resource').': '.
                     &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
                     &LONCAPA::map::qtescape($url).')';
@@ -1660,7 +1659,8 @@ sub do_paste_from_buffer {
             }
             $srcdom{$suffix} = $srcd;
             $srcnum{$suffix} = $srcn;
-        } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
+        } elsif (($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) || 
+                 ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
             my ($srcd,$srcn) = split(/_/,$cid);
 # When paste buffer was populated using an active role in a different course
 # check for mdc privilege in the course from which the resource was pasted
@@ -1728,7 +1728,7 @@ sub do_paste_from_buffer {
     %msgs = &Apache::lonlocal::texthash (
                 notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
                 notincrs  => 'Paste failed: Item is from a different course which you do not have rights to edit.',
-                notindom  => 'Paste failed: Item is an external tool from a course in a different donain.', 
+                notindom  => 'Paste failed: Item is an external tool from a course in a different domain.',
                 duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
             );
 
@@ -1837,7 +1837,7 @@ sub do_paste_from_buffer {
                 }
             }
         }
-        if ($url=~ m{/(ext\.tool)$}) {
+        if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
             my $prefix = $1;
             my $fromothercrs;
             #need to copy the db contents to a new one, unless this is a move.
@@ -1861,7 +1861,11 @@ sub do_paste_from_buffer {
                     $url = $newurl;
                     $title=&mt('Copy of').' '.$title;
                 } else {
-                    if ($prefix eq 'ext.tool') {
+                    if ($prefix eq 'smppg') {
+                        $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
+                    } elsif ($prefix eq 'bulletinboard') {
+                        $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
+                    } elsif ($prefix eq 'ext.tool') {
                         $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
                     }
                     $results{$suffix} = $result;
@@ -3925,7 +3929,7 @@ END
                     }
                 }
                 if ($url ne '') {
-                    $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
+                    $url.=(($url=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
                 }
             } elsif (!$env{'request.role.adv'}) {
                 my $checkencrypt;
@@ -3946,7 +3950,7 @@ END
                     my $shownsymb = &Apache::lonenc::encrypted($symb);
                     my $shownurl = &Apache::lonenc::encrypted($url);
                     if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
-                        $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
+                        $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
                         if ($env{'request.enc'} ne '') {
                             delete($env{'request.enc'});
                         }
@@ -4086,7 +4090,8 @@ $form_end;
         if ($isexternal) {
             ($editlink,$extresform) = 
                 &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
-                                                     undef,undef,undef,$disabled);
+                                                     undef,undef,undef,undef,undef,undef,
+                                                     undef,$disabled);
         } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
             ($editlink,$extresform) =
                 &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
@@ -4951,8 +4956,8 @@ sub handler {
 	               'Adding_External_Resource','Adding_External_Tool',
                        'Navigate_Content','Adding_Folders','Docs_Overview',
 	               'Load_Map','Supplemental','Score_Upload_Form',
-                       'Adding_Pages','Importing_LON-CAPA_Resource',
-                       'Importing_IMS_Course','Uploading_From_Harddrive',
+	               'Adding_Pages','Importing_LON-CAPA_Resource',
+	               'Importing_IMS_Course','Uploading_From_Harddrive',
                        'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
 	$help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
     }
@@ -4985,11 +4990,6 @@ sub handler {
         $disabled = ' disabled="disabled"';
     }
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
-    if ($env{'form.inhibitmenu'}) {
-        unless ($env{'form.inhibitmenu'} eq 'yes') {
-            delete($env{'form.inhibitmenu'});
-        }
-    }
   if ($allowed && $env{'form.verify'}) {
       &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
       &verifycontent($r);
@@ -5023,25 +5023,6 @@ sub handler {
                                              'forcesupplement','forcestandard',
                                              'tools','symb','command','supppath']);
 
-    foreach my $item ('forcesupplement','forcestandard','tools') {
-        next if ($env{'form.'.$item} eq '');
-        unless ($env{'form.'.$item} eq '1') {
-            delete($env{'form.'.$item});
-        }
-    }
-
-    if ($env{'form.command'}) {
-        unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
-            delete($env{'form.command'});
-        }
-    }
-
-    if ($env{'form.symb'}) {
-        my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
-        unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
-            delete($env{'form.symb'});
-        }
-    }
 # standard=1: this is a "new-style" course with an uploaded map as top level
 # standard=2: this is a "old-style" course, and there is nothing we can do
 
@@ -5064,38 +5045,6 @@ sub handler {
     my $toolsflag=0;
     if ($env{'form.tools'}) { $toolsflag=1; }
 
-    if ($env{'form.folderpath'} ne '') {
-        my @items = split(/\&/,$env{'form.folderpath'});
-        my $badpath;
-        for (my $i=0; $i<@items; $i++) {
-            my $odd = $i%2;
-            if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
-                $badpath = 1;
-            } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
-                $badpath = 1;
-            }
-            last if ($badpath);
-        }
-        if ($badpath) {
-            delete($env{'form.folderpath'});
-        }
-    }
-
-    if ($env{'form.supppath'} ne '') {
-        my @items = split(/\&/,$env{'form.supppath'});
-        my $badpath;
-        for (my $i=0; $i<@items; $i++) {
-            my $odd = $i%2;
-            if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
-                $badpath = 1;
-            }
-            last if ($badpath);
-        }
-        if ($badpath) {
-            delete($env{'form.supppath'});
-        }
-    }
-
     my $script='';
     my $showdoc=0;
     my $addentries = {};
@@ -5280,7 +5229,7 @@ sub handler {
                 }
             }
             my $tabidstr = join("','",@tabids);
-            %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);
+            %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
             my $posslti = keys(%ltitools);
 	    $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
                                    $canedit,\$navmap).
@@ -5365,7 +5314,6 @@ sub handler {
 	  undef($hadchanges);
           $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
                                               \%allfiles,\%codebase,$context,$crstype);
-          undef($navmap);
 	  if ($hadchanges) {
 	      &mark_hash_old();
 	  }
@@ -5593,7 +5541,7 @@ SEDFFORM
         my $extresourcesform =
             &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
                                                  $help{'Adding_External_Resource'},
-                                                 undef,undef,$disabled);
+                                                 undef,undef,undef,undef,undef,undef,$disabled);
         my $exttoolform =
             &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
                                                  $help{'Adding_External_Tool'},undef,
@@ -5899,10 +5847,9 @@ unless ($container eq 'page') {
              $r->print('<p><span class="LC_error">'.$error.'</span></p>');
           }
           if ($hadchanges) {
-             unless (&is_hash_old()) {
-                 &mark_hash_old();
-             }
+             &mark_hash_old();
           }
+
           &changewarning($r,'');
         }
     }
@@ -5961,7 +5908,8 @@ SNFFORM
         my $supextform =
             &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
                                                  $help{'Adding_External_Resource'},
-                                                 undef,undef,$disabled);
+                                                 undef,undef,undef,undef,undef,undef,
+                                                 $disabled);
 
         my $supexttoolform =
             &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
@@ -6095,7 +6043,6 @@ my %suporderhash = (
 sub embedded_form_elems {
     my ($phase,$primaryurl,$newidx) = @_;
     my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
-    $newidx =~s /\D+//g;
     return <<STATE;
     <input type="hidden" name="folderpath" value="$folderpath" />
     <input type="hidden" name="cmd" value="upload_embedded" />
@@ -6116,11 +6063,7 @@ sub embedded_destination {
     } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
         $destination .=  $2.'/';
     }
-    my $newidx = $env{'form.newidx'};
-    $newidx =~s /\D+//g;
-    if ($newidx) {
-        $destination .= $newidx;
-    }
+    $destination .= $env{'form.newidx'};
     my $dir_root = '/userfiles';
     return ($destination,$dir_root);
 }
@@ -6146,9 +6089,6 @@ sub decompression_info {
     }
     unshift(@hiddens,$pathitem);
     foreach my $item (@hiddens) {
-        if ($item eq 'newidx') {
-            next if ($env{'form.'.$item} =~ /\D/);
-        }
         if ($env{'form.'.$item}) {
             $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
                            &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
@@ -6513,13 +6453,8 @@ sub editing_js {
                 } else {
                     $url = $res;
                 }
-                $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
-                if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
-                    $backtourl .= '?navmap=1';
-                } else {
-                    $backtourl .= '?symb='.
-                                  &HTML::Entities::encode($caller,'<>&"');
-                }
+                $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='.
+                             &HTML::Entities::encode($caller,'<>&"');
                 if ($anchor ne '') {
                     $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
                 }
@@ -7734,9 +7669,7 @@ check on this
 
 Verify Content
 
-=item devalidateversioncache() 
-
-=item checkversions()
+=item devalidateversioncache() & checkversions()
 
 Check Versions