--- loncom/interface/londocs.pm	2004/12/23 17:50:42	1.161
+++ loncom/interface/londocs.pm	2005/03/10 02:34:58	1.170
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.161 2004/12/23 17:50:42 albertel Exp $
+# $Id: londocs.pm,v 1.170 2005/03/10 02:34:58 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -132,11 +132,17 @@ sub dumpbutton {
     }
 }
 
+sub clean {
+    my ($title)=@_;
+    $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
+    return $title;	
+}
 # -------------------------------------------------------- Actually dump course
 
 sub dumpcourse {
     my $r=shift;
-    $r->print('<html><head><title>Dump DOCS</title></head>'.
+    my $html=&Apache::lonxml::xmlbegin();
+    $r->print($html.'<head><title>Dump DOCS</title></head>'.
         &Apache::loncommon::bodytag('Dump Course DOCS to Construction Space').
 	      '<form name="dumpdoc" method="post">');
     my ($home,$other,%outhash)=&authorhosts();
@@ -149,7 +155,7 @@ sub dumpcourse {
 	my ($ca,$cd)=split(/\@/,$ENV{'form.authorspace'});
 	$r->print('<h3>'.&mt('Copying Files').'</h3>');
 	my $title=$ENV{'form.authorfolder'};
-	$title=~s/[^\w\/]+/\_/g;
+	$title=&clean($title);
 	my %replacehash=();
 	foreach (keys %ENV) {
 	    if ($_=~/^form\.namefor\_(.+)/) {
@@ -160,7 +166,7 @@ sub dumpcourse {
 	$crs=~s/\_/\//g;
 	foreach (keys %replacehash) {
 	    my $newfilename=$title.'/'.$replacehash{$_};
-	    $newfilename=~s/[^\w\/\.\/]+/\_/g;
+	    $newfilename=&clean($newfilename);
 	    my @dirs=split(/\//,$newfilename);
 	    my $path='/home/'.$ca.'/public_html';
 	    my $makepath=$path;
@@ -214,7 +220,7 @@ sub dumpcourse {
 	}
 	my $title=$origcrsdata{'description'};
 	$title=~s/\s+/\_/gs;
-	$title=~s/\W//gs;
+	$title=&clean($title);
 	$r->print('<h3>'.&mt('Folder in Construction Space').'</h3><input type="text" size="50" name="authorfolder" value="'.$title.'" /><br />');
 	&tiehash();
 	$r->print('<h3>'.&mt('Filenames in Construction Space').'</h3><table border="2"><tr><th>'.&mt('Internal Filename').'</th><th>'.&mt('Title').'</th><th>'.&mt('Save as ...').'</th></tr>');
@@ -223,12 +229,13 @@ sub dumpcourse {
 	    my ($ext)=($_=~/\.(\w+)$/);
 	    my $title=$hash{'title_'.$hash{
 		'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$_}};
+	    $title=~s/&colon;/:/g;
 	    $r->print('<td>'.($title?$title:'&nbsp;').'</td>');
 	    unless ($title) {
 		$title=$_;
 	    }
 	    $title=~s/\.(\w+)$//;
-	    $title=~s/[^\w\/]+/\_/gs;
+	    $title=&clean($title);
 	    $title.='.'.$ext;
 	    $r->print("\n<td><input type='text' size='60' name='namefor_".$_."' value='".$title."' /></td></tr>\n");
 	}
@@ -319,8 +326,8 @@ sub exportcourse {
                 $outcome = '<br />Unfortunately you will not be able to retrieve an IMS archive of this posts at this time, because there was a problem creating a manifest file.<br />';
             }
         }
-
-        $r->print('<html><head><title>Export Course</title></head>'.
+	my $html=&Apache::lonxml::xmlbegin();
+        $r->print($html.'<head><title>Export Course</title></head>'.
             &Apache::loncommon::bodytag('Export course to IMS content package'));
         $r->print($outcome);
         $r->print('</body></html>');
@@ -461,7 +468,8 @@ function containerCheck(item) {
 
 </script>
         |;
-        $r->print('<html><head><title>Export Course</title>'.$scripttag.'</head>'.
+	my $html=&Apache::lonxml::xmlbegin();
+        $r->print($html.'<head><title>Export Course</title>'.$scripttag.'</head>'.
             &Apache::loncommon::bodytag('Export course to IMS content package'
 ));
 
@@ -705,12 +713,9 @@ sub process_content {
         if ($contents) {
             $$content_file = &store_template($contents,$tempexport,$count,$content_type);
         }
-    } elsif ($symb =~ m-uploaded/$cdom/$cnum-) {
-        $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
     } elsif ($symb =~ m-\.(sequence|page)___\d+___uploaded/$cdom/$cnum/-) {
         $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
-    } elsif ($symb =~ m-\.(sequence|page)___\d+___([^/])/([^/])-) {
-        my $coauth = $3.':'.$2.':ca';
+    } elsif ($symb =~ m-\.(sequence|page)___\d+___([^/]+)/([^/]+)-) {
         my $canedit = 0;
         if ($2 eq $ENV{'user.domain'} && $3 eq $ENV{'user.name'})  {
             $canedit= 1;
@@ -720,6 +725,8 @@ sub process_content {
         } else {
             $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'noedit');
         }
+    } elsif ($symb =~ m-uploaded/$cdom/$cnum-) {
+        $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
     }
     if (@uploads > 0) {
         foreach my $item (@uploads) {
@@ -761,14 +768,14 @@ sub replicate_content {
         if ($copiedfile = Apache::File->new('>'.$destination)) {
             my $content;
             if ($caller eq 'resource') {
-                $content = &Apache::lonnet::getfile($url);
+                $content = &Apache::lonnet::getfile('/home/httpd/html/res/'.$url);
                 if ($content eq -1) {
                     $$message = 'Could not copy file '.$filename;
                 } else {
                     &extract_media($content,$count,$tempexport,$href,'resource');
                     $repstatus = 'ok';
                 }
-            } elsif ($caller eq 'noedit' || $caller eq 'uploaded' || $caller eq 'templateupload') {
+            } elsif ($caller eq 'uploaded' || $caller eq 'templateupload') {
                 my $rtncode;
                 $repstatus = &Apache::lonnet::getuploaded('GET',$url,$cdom,$cnum,\$content,$rtncode);
                 if ($repstatus eq 'ok') {
@@ -778,6 +785,10 @@ sub replicate_content {
                 } else {
                     $$message = 'Could not render '.$url.' server message - '.$rtncode;
                 }
+            } elsif ($caller eq 'noedit') {
+# Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this. 
+                $repstatus = 'ok';
+                $content = 'Not the owner of this resource'; 
             }
             if ($repstatus eq 'ok') {
                 print $copiedfile $content;
@@ -884,6 +895,14 @@ sub breadcrumbs {
         @folders=split('&',$ENV{'form.folderpath'});
     }
     my $folderpath;
+    my $cpinfo='';
+    if ($ENV{'form.markedcopy_url'}) {
+	&Apache::lonnet::logthis('Found '.$ENV{'form.markedcopy_url'});
+       $cpinfo='&markedcopy_url='.
+               &Apache::lonnet::escape($ENV{'form.markedcopy_url'}).
+               '&markedcopy_title='.
+               &Apache::lonnet::escape($ENV{'form.markedcopy_title'});
+    }
     while (@folders) {
 	my $folder=shift(@folders);
 	my $foldername=shift(@folders);
@@ -892,7 +911,7 @@ sub breadcrumbs {
 	my $url='/adm/coursedocs?folderpath='.
 	    &Apache::lonnet::escape($folderpath);
 	    &Apache::lonhtmlcommon::add_breadcrumb(
-		      {'href'=>$url,
+		      {'href'=>$url.$cpinfo,
 		       'title'=>&Apache::lonnet::unescape($foldername),
 		       'text'=>'<font size="+1">'.
 			   &Apache::lonnet::unescape($foldername).'</font>'
@@ -906,8 +925,6 @@ sub breadcrumbs {
 
 sub editor {
     my ($r,$coursenum,$coursedom,$folder,$allowed)=@_;
-
-    $r->print(&breadcrumbs($folder));
     my $errtext='';
     my $fatal=0;
     my $container='sequence';
@@ -920,6 +937,13 @@ sub editor {
        	$Apache::lonratedt::order[0]=1;
         $Apache::lonratedt::resources[1]='';
     }
+    if (defined($ENV{'form.markcopy'})) {
+# Mark for copying
+	my ($title,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$ENV{'form.markcopy'}]]);
+	$ENV{'form.markedcopy_title'}=$title;
+	$ENV{'form.markedcopy_url'}=$url;
+    }
+    $r->print(&breadcrumbs($folder));
     if ($fatal) {
 	   $r->print('<p><font color="red">'.$errtext.'</font></p>');
     } else {
@@ -990,14 +1014,50 @@ sub editor {
 		}
 		
 	    }
+	    if ($ENV{'form.pastemarked'}) {
+# paste resource to end of list
+                my $url=$ENV{'form.markedcopy_url'};
+		my $title=$ENV{'form.markedcopy_title'};
+# Maps need to be copied first
+		if (($url=~/\.(page|sequence)$/) || ($url=~/^\/uploaded\//)) {
+		    $title=&mt('Copy of').' '.$title;
+                    my $newid=$$.time;
+		    $url=~/^(.+)\.(\w+)$/;
+		    my $newurl=$1.$newid.'.'.$2;
+		    my $storefn=$newurl;
+                    $storefn=~s/^\/\w+\/\w+\/\w+\///;
+		    &Apache::loncreatecourse::writefile
+			($ENV{'request.course.id'},$storefn,
+			 &Apache::lonnet::getfile($url));
+		    $url=$newurl;
+		}
+		$title=~s/\</\&lt\;/g;
+		$title=~s/\>/\&gt\;/g;
+		$title=~s/\:/\&colon;/g;
+		my $ext='false';
+		if ($url=~/^http\:\/\//) { $ext='true'; }
+		$url=~s/\:/\&colon;/g;
+# Now insert the URL at the bottom
+                my $newidx=1+$#Apache::lonratedt::resources;
+		$Apache::lonratedt::resources[$newidx]=
+		    $title.':'.$url.':'.$ext.':normal:res';
+		$Apache::lonratedt::order[1+$#Apache::lonratedt::order]=$newidx;
+# Store the result
+		($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
+		if ($fatal) {
+		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
+		    return;
+		}
 
+	    }
 # upload a file, if present
            if (($ENV{'form.uploaddoc.filename'}) &&
                ($ENV{'form.cmd'}=~/^upload_(\w+)/)) {
 	    if ( ($folder=~/^$1/) || ($1 eq 'default') ) {
 # this is for a course, not a user, so set coursedoc flag
 # probably the only place in the system where this should be "1"
-	      my $url=&Apache::lonnet::userfileupload('uploaddoc',1,'docs');
+              my $newidx=$#Apache::lonratedt::resources+1;
+	      my $url=&Apache::lonnet::userfileupload('uploaddoc',1,'docs/'.$newidx);
               my $ext='false';
               if ($url=~/^http\:\/\//) { $ext='true'; }
               $url=~s/\:/\&colon;/g;
@@ -1009,7 +1069,6 @@ sub editor {
 		  $comment=time.'___&&&___'.$ENV{'user.name'}.'___&&&___'.
 		      $ENV{'user.domain'}.'___&&&___'.$comment;
               }
-              my $newidx=$#Apache::lonratedt::resources+1;
               $Apache::lonratedt::resources[$newidx]=
                   $comment.':'.$url.':'.$ext.':normal:res';
               $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=
@@ -1126,7 +1185,30 @@ sub editor {
 	unless ($shown) {
 	    $r->print('<tr><td>'.&mt('Currently no documents.').'</td></tr>');
 	}
-        $r->print('</table>');
+        $r->print("\n</table>\n");
+	if ($ENV{'form.markedcopy_url'}) {
+	    $r->print(<<ENDPASTE);
+<p><form name="pasteform" action="/adm/coursedocs" method="post">
+<input type="hidden" name="markedcopy_url" value="$ENV{'form.markedcopy_url'}" />
+<input type="hidden" name="markedcopy_title" value="$ENV{'form.markedcopy_title'}" />
+ENDPASTE
+            $r->print(
+	   '<input type="submit" name="pastemarked" value="'.&mt('Paste').
+		      '" /> '.&Apache::loncommon::filedescription(
+		(split(/\./,$ENV{'form.markedcopy_url'}))[-1]).': '.
+		      $ENV{'form.markedcopy_title'});
+            if ($container eq 'page') {
+		$r->print(<<PAGEINFO);
+<input type="hidden" name="pagepath" value="$ENV{'form.pagepath'}" />
+<input type="hidden" name="pagesymb" value="$ENV{'form.pagesymb'}" />
+PAGEINFO
+            } else {
+		$r->print(<<FOLDERINFO);
+<input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
+FOLDERINFO
+	    }
+	    $r->print('</form></p>');
+	}
     }
 }
 
@@ -1164,10 +1246,24 @@ sub entryline {
         $pagepath=&Apache::lonnet::escape($ENV{'form.pagepath'});
         $pagesymb=&Apache::lonnet::escape($ENV{'form.pagesymb'});
     }
+    my $cpinfo='';
+    if ($ENV{'form.markedcopy_url'}) {
+       $cpinfo='&markedcopy_url='.
+               &Apache::lonnet::escape($ENV{'form.markedcopy_url'}).
+               '&markedcopy_title='.
+               &Apache::lonnet::escape($ENV{'form.markedcopy_title'});
+    }
     if ($allowed) {
 	my $incindex=$index+1;
 	my $selectbox='';
-	if ($folder!~/^supplemental/) {
+	if (($folder!~/^supplemental/) &&
+	    ($#Apache::lonratedt::order>0) && 
+	    ((split(/\:/,
+	     $Apache::lonratedt::resources[$Apache::lonratedt::order[0]]))[1] 
+	     ne '') && 
+	    ((split(/\:/,
+	     $Apache::lonratedt::resources[$Apache::lonratedt::order[1]]))[1] 
+	     ne '')) {
 	    $selectbox=
 		'<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
 		'<select name="newpos" onChange="this.form.submit()">';
@@ -1184,19 +1280,22 @@ sub entryline {
                 'up' => 'Move Up',
 		'dw' => 'Move Down',
 		'rm' => 'Remove',
-		'rn' => 'Rename');
+		'rn' => 'Rename',
+		'cp' => 'Copy');
         if ($ENV{'form.pagepath'}) {
             $line.=(<<END);
 <form name="entry_$index" action="/adm/coursedocs" method="post">
 <input type="hidden" name="pagepath" value="$ENV{'form.pagepath'}" />
 <input type="hidden" name="pagesymb" value="$ENV{'form.pagesymb'}" />
+<input type="hidden" name="markedcopy_url" value="$ENV{'form.markedcopy_url'}" />
+<input type="hidden" name="markedcopy_title" value="$ENV{'form.markedcopy_title'}" />
 <input type="hidden" name="setparms" value="$orderidx" />
 <td><table border='0' cellspacing='2' cellpadding='0'>
 <tr><td bgcolor="#DDDDDD">
-<a href='/adm/coursedocs?cmd=up_$index&pagepath=$pagepath&pagesymb=$pagesymb'>
+<a href='/adm/coursedocs?cmd=up_$index&pagepath=$pagepath&pagesymb=$pagesymb$cpinfo'>
 <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
 <tr><td bgcolor="#DDDDDD">
-<a href='/adm/coursedocs?cmd=down_$index&pagepath=$pagepath&pagesymb=$pagesymb'>
+<a href='/adm/coursedocs?cmd=down_$index&pagepath=$pagepath&pagesymb=$pagesymb$cpinfo'>
 <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
 </table></td>
 <td>$selectbox
@@ -1204,19 +1303,23 @@ sub entryline {
 <a href='javascript:removeres("$pagepath","$index","$renametitle","page","$pagesymb");'>
 <font size="-2" color="#990000">$lt{'rm'}</font></a>
 <a href='javascript:changename("$pagepath","$index","$renametitle","page","$pagesymb");'>
-<font size="-2" color="#009900">$lt{'rn'}</font></a></td>
+<font size="-2" color="#009900">$lt{'rn'}</font></a>
+<a href='javascript:markcopy("$pagepath","$index","$renametitle","page","$pagesymb");'>
+<font size="-2" color="#000099">$lt{'cp'}</font></a></td>
 END
         } else {
             $line.=(<<END); 
 <form name="entry_$index" action="/adm/coursedocs" method="post">
 <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
+<input type="hidden" name="markedcopy_url" value="$ENV{'form.markedcopy_url'}" />
+<input type="hidden" name="markedcopy_title" value="$ENV{'form.markedcopy_title'}" />
 <input type="hidden" name="setparms" value="$orderidx" />
 <td><table border='0' cellspacing='2' cellpadding='0'>
 <tr><td bgcolor="#DDDDDD">
-<a href='/adm/coursedocs?cmd=up_$index&folderpath=$folderpath'>
+<a href='/adm/coursedocs?cmd=up_$index&folderpath=$folderpath$cpinfo'>
 <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
 <tr><td bgcolor="#DDDDDD">
-<a href='/adm/coursedocs?cmd=down_$index&folderpath=$folderpath'>
+<a href='/adm/coursedocs?cmd=down_$index&folderpath=$folderpath$cpinfo'>
 <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
 </table></td>
 <td>$selectbox
@@ -1224,7 +1327,9 @@ END
 <a href='javascript:removeres("$folderpath","$index","$renametitle","sequence");'>
 <font size="-2" color="#990000">$lt{'rm'}</font></a>
 <a href='javascript:changename("$folderpath","$index","$renametitle","sequence");'>
-<font size="-2" color="#009900">$lt{'rn'}</font></a></td>
+<font size="-2" color="#009900">$lt{'rn'}</font></a>
+<a href='javascript:markcopy("$folderpath","$index","$renametitle","sequence");'>
+<font size="-2" color="#000099">$lt{'cp'}</font></a></td>
 END
         }
     }
@@ -1292,12 +1397,13 @@ END
 	my $folderpath=$ENV{'form.folderpath'};
 	if ($folderpath) { $folderpath.='&' };
 	$folderpath.=$folderarg.'&'.$foldername;
-	$url.='folderpath='.&Apache::lonnet::escape($folderpath);
+	$url.='folderpath='.&Apache::lonnet::escape($folderpath).$cpinfo;
 	$parameterset='<label>'.&mt('Randomly Pick: ').
-	    '<input type="text" size="4" name="randpick_'.$orderidx.'" value="'.
+	    '<input type="text" size="4" onChange="this.form.submit()" name="randpick_'.$orderidx.'" value="'.
 	    (&Apache::lonratedt::getparameter($orderidx,
                                               'parameter_randompick'))[0].
-                                              '" />'.'</label>';
+                                              '" />'.
+'<font size="-2"><a href="javascript:void(0)">'.&mt('Store').'</a></font></label>';
        
     }
     if ($ispage) {
@@ -1316,7 +1422,7 @@ END
 					       $path.$pagearg.'.page');
 	}
 	$url.='pagepath='.&Apache::lonnet::escape($pagepath).
-	    '&pagesymb='.&Apache::lonnet::escape($symb);
+	    '&pagesymb='.&Apache::lonnet::escape($symb).$cpinfo;
     }
     $line.='<td bgcolor="#FFFFBB"><a href="'.$url.'"><img src="'.$icon.
 	'" border="0"></a></td>'.
@@ -1324,21 +1430,17 @@ END
     if (($allowed) && ($folder!~/^supplemental/)) {
  	my %lt=&Apache::lonlocal::texthash(
  			      'hd' => 'Hidden',
- 			      'ec' => 'URL hidden',
- 			      'sp' => 'Store Parameters');
+ 			      'ec' => 'URL hidden');
 	my $enctext=
 	    ((&Apache::lonratedt::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="1"':'');
 	my $hidtext=
 	    ((&Apache::lonratedt::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':'');
 	$line.=(<<ENDPARMS);
 <td bgcolor="#BBBBFF"><font size='-2'>
-<nobr><label><input type="checkbox" name="hidprs_$orderidx" $hidtext/> $lt{'hd'}</label></nobr></td>
+<nobr><label><input type="checkbox" name="hidprs_$orderidx" onClick="this.form.submit()" $hidtext /> $lt{'hd'}</label></nobr></td>
 <td bgcolor="#BBBBFF"><font size='-2'>
-<nobr><label><input type="checkbox" name="encprs_$orderidx" $enctext/> $lt{'ec'}</label></nobr></td>
+<nobr><label><input type="checkbox" name="encprs_$orderidx" onClick="this.form.submit()" $enctext /> $lt{'ec'}</label></nobr></td>
 <td bgcolor="#BBBBFF"><font size="-2">$parameterset</font></td>
-<td bgcolor="#BBBBFF"><font size='-2'>
-<input type="submit" value="$lt{'sp'}" />
-</font></td>
 ENDPARMS
     }
     $line.="</form></tr>";
@@ -1387,7 +1489,7 @@ sub checkonthis {
        if ($url=~/^\/res\//) {
 	  my $result=&Apache::lonnet::repcopy(
                               &Apache::lonnet::filelocation('',$url));
-          if ($result==OK) {
+          if ($result eq 'OK') {
              $r->print('<font color="green">'.&mt('ok').'</font>');
              $r->rflush();
              &Apache::lonnet::countacc($url);
@@ -1399,23 +1501,19 @@ sub checkonthis {
                      $r->print('&nbsp;');
                  }
                  $r->print('- '.&mt('Rendering').': ');
-                 my $oldpath=$ENV{'request.filename'};
-                 $ENV{'request.filename'}=&Apache::lonnet::filelocation('',$url);
-                 &Apache::lonxml::xmlparse($r,'web',
-                   &Apache::lonnet::getfile(
-                    &Apache::lonnet::filelocation('',$url)));
-		 undef($Apache::lonhomework::parsing_a_problem);
-		 $ENV{'request.filename'}=$oldpath;
-                 if (($Apache::lonxml::errorcount) ||
-                     ($Apache::lonxml::warningcount)) {
-		     if ($Apache::lonxml::errorcount) {
+		 my ($errorcount,$warningcount)=split(/:/,
+	       &Apache::lonnet::ssi_body($url,
+			       ('return_only_error_and_warning_counts' => 1)));
+                 if (($errorcount) ||
+                     ($warningcount)) {
+		     if ($errorcount) {
                         $r->print('<img src="/adm/lonMisc/bomb.gif" /><font color="red"><b>'.
-			  $Apache::lonxml::errorcount.' '.
+			  $errorcount.' '.
 				  &mt('error(s)').'</b></font> ');
                      }
-		     if ($Apache::lonxml::warningcount) {
+		     if ($warningcount) {
                         $r->print('<font color="blue">'.
-			  $Apache::lonxml::warningcount.' '.
+			  $warningcount.' '.
 				  &mt('warning(s)').'</font>');
                      }
                  } else {
@@ -1430,9 +1528,9 @@ sub checkonthis {
                     &checkonthis($r,$_,$level+1);
                  }
              }
-          } elsif ($result==HTTP_SERVICE_UNAVAILABLE) {
+          } elsif ($result eq 'HTTP_SERVICE_UNAVAILABLE') {
              $r->print('<font color="red"><b>'.&mt('connection down').'</b></font>');
-          } elsif ($result==HTTP_NOT_FOUND) {
+          } elsif ($result eq 'HTTP_NOT_FOUND') {
 	      unless ($url=~/\$/) {
 		  $r->print('<font color="red"><b>'.&mt('not found').'</b></font>');
 	      } else {
@@ -1453,8 +1551,8 @@ sub verifycontent {
    my $r=shift; 
    my $loaderror=&Apache::lonnet::overloaderror($r);
    if ($loaderror) { return $loaderror; }
-
-   $r->print('<html><head><title>Verify Content</title></head>'.
+   my $html=&Apache::lonxml::xmlbegin();
+   $r->print($html.'<head><title>Verify Content</title></head>'.
               &Apache::loncommon::bodytag('Verify Course Documents'));
    $hashtied=0;
    undef %alreadyseen;
@@ -1482,7 +1580,8 @@ sub verifycontent {
 
 sub checkversions {
     my $r=shift;
-    $r->print('<html><head><title>Check Versions</title></head>'.
+    my $html=&Apache::lonxml::xmlbegin();
+    $r->print($html.'<head><title>Check Versions</title></head>'.
               &Apache::loncommon::bodytag('Check Course Document Versions'));
     my $header='';
     my $startsel='';
@@ -1817,7 +1916,7 @@ sub handler {
     my $containertag;
     my $uploadtag;
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
-					    ['folderpath','pagepath','pagesymb']);
+    ['folderpath','pagepath','pagesymb','markedcopy_url','markedcopy_title']);
     if ($ENV{'form.folderpath'}) {
 	my (@folderpath)=split('&',$ENV{'form.folderpath'});
 	$ENV{'form.foldername'}=&Apache::lonnet::unescape(pop(@folderpath));
@@ -1873,8 +1972,9 @@ sub handler {
     my $now=time;
 
 # print screen
+       my $html=&Apache::lonxml::xmlbegin();
     $r->print(<<ENDDOCUMENT);
-<html>
+$html
 <head>
 <title>The LearningOnline Network with CAPA</title>
 <script>
@@ -1951,16 +2051,20 @@ function makeabout() {
 	       this.document.forms.newaboutsomeone.importdetail.value=
 		   'About '+user+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
 	       this.document.forms.newaboutsomeone.submit();
-	   }
+	   } else {
+               alert("Not a valid user\@domain");
+           }
+       } else {
+           alert("Please enter both user and domain in the format user\@domain"); 
        }
    }
 }
 
 function makeims() {
-    var caller = document.forms.ims.folder.value
-    var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one"
-    newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes")
-    newWindow.location.href = newlocation
+    var caller = document.forms.ims.folder.value;
+    var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";
+    newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");
+    newWindow.location.href = newlocation;
 }
 
 
@@ -2003,6 +2107,18 @@ function removeres(folderpath,index,oldt
     }
 }
 
+function markcopy(folderpath,index,oldtitle,container,pagesymb) {
+    this.document.forms.renameform.markcopy.value=index;
+    if (container == 'sequence') {
+	this.document.forms.renameform.folderpath.value=folderpath;
+    }
+    if (container == 'page') {
+	this.document.forms.renameform.pagepath.value=folderpath;
+	this.document.forms.renameform.pagesymb.value=pagesymb;
+    }
+    this.document.forms.renameform.submit();
+}
+
 </script>
 
 ENDNEWSCRIPT
@@ -2017,7 +2133,9 @@ ENDNEWSCRIPT
        my %lt=&Apache::lonlocal::texthash(
                 'uplm' => 'Upload a new main course document',
                 'upls' => 'Upload a new supplemental course document',
-                'impp' => 'Import a published document',
+                'impp' => 'Import a document',
+                'pubd' => 'Published documents',
+		'copm' => 'All documents out of a published map',
                 'spec' => 'Special documents',
                 'upld' => 'Upload Document',
                 'srch' => 'Search',
@@ -2066,6 +2184,7 @@ ENDNEWSCRIPT
 <form name="renameform" method="post" action="/adm/coursedocs">
 <input type="hidden" name="title" />
 <input type="hidden" name="cmd" />
+<input type="hidden" name="markcopy" />
 $containertag
 </form>
 <form name="simpleedit" method="post" action="/adm/coursedocs">
@@ -2137,6 +2256,7 @@ $uploadtag
 </td>
 <td bgcolor="#DDDDDD">
 <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
+$lt{'pubd'}<br />
 $uploadtag
 <input type=button onClick="javascript:groupsearch()" value="$lt{'srch'}">
 <nobr>
@@ -2145,6 +2265,7 @@ $help{'Importing_LON-CAPA_Resource'}
 </nobr>
 <p>
 <hr />
+$lt{'copm'}
 <input type="text" size="20" name="importmap"><br />
 <nobr><input type=button 
 onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
@@ -2152,10 +2273,27 @@ value="$lt{'selm'}"> <input type="submit
 $help{'Load_Map'}</nobr>
 </p>
 </form>
-</td>
-<td bgcolor="#DDDDDD">
 ENDFORM
        unless ($ENV{'form.pagepath'}) {
+	   $r->print(<<ENDFORM);
+<hr />
+<form action="/adm/coursedocs" method="post" name="newext">
+$uploadtag
+<input type=hidden name="importdetail" value="">
+<nobr>
+<input name="newext" type="button" onClick="javascript:makenewext('newext');"
+value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
+</nobr>
+</form>
+<form action="/adm/imsimportdocs" method="post" name="ims">
+<input type="hidden" name="folder" value="$folder" />
+<input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />
+</nobr>
+</form>
+ENDFORM
+       }
+       $r->print('</td><td bgcolor="#DDDDDD">');
+       unless ($ENV{'form.pagepath'}) {
            $r->print(<<ENDFORM);
 <form action="/adm/coursedocs" method="post" name="newfolder">
 <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
@@ -2175,14 +2313,6 @@ onClick="javascript:makenewpage(this.for
 value="$lt{'newp'}" />$help{'Adding_Pages'}
 </nobr>
 </form>
-<form action="/adm/coursedocs" method="post" name="newext">
-$uploadtag
-<input type=hidden name="importdetail" value="">
-<nobr>
-<input name="newext" type="button" onClick="javascript:makenewext('newext');"
-value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
-</nobr>
-</form>
 <form action="/adm/coursedocs" method="post" name="newsyl">
 $uploadtag
 <input type=hidden name="importdetail" 
@@ -2271,17 +2401,8 @@ $uploadtag
 onClick="javascript:makeexamupload();" />
 $help{'Score_Upload_Form'}
 </nobr>
-</form>
 ENDBLOCK
-       } else {
-           $r->print(<<ENDFORM);
-</form>
-<form action="/adm/imsimportdocs" method="post" name="ims">
-<input type="hidden" name="folder" value="$folder" />
-<input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />
-</nobr>
-</form>
-ENDFORM
+           $r->print('</form>');
        }
        $r->print('</td></tr>'."\n".
 '</table>');