--- loncom/interface/londocs.pm	2014/02/24 17:10:37	1.484.2.50
+++ loncom/interface/londocs.pm	2014/12/21 19:20:41	1.484.2.57
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.484.2.50 2014/02/24 17:10:37 raeburn Exp $
+# $Id: londocs.pm,v 1.484.2.57 2014/12/21 19:20:41 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -46,6 +46,7 @@ use Apache::lonsimplepage();
 use HTML::Entities;
 use HTML::TokeParser;
 use GDBM_File;
+use File::MMagic;
 use Apache::lonlocal;
 use Cwd;
 use LONCAPA qw(:DEFAULT :match);
@@ -976,7 +977,7 @@ sub docs_change_log {
 
 sub update_paste_buffer {
     my ($coursenum,$coursedom,$folder) = @_;
-    my (@possibles,%removals,%cuts);
+    my (@possibles,%removals,%cuts,$output);
     if ($env{'form.multiremove'}) {
         $env{'form.multiremove'} =~ s/,$//;
         map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
@@ -1044,10 +1045,12 @@ sub update_paste_buffer {
         next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
         my ($suffix,$errortxt,$locknotfreed) =
             &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
-        push(@newpaste,$suffix);
-        if ($locknotfreed) {
-            return $locknotfreed;
-            last;
+        if ($suffix ne '') {
+            push(@newpaste,$suffix);
+        } else {
+            if ($locknotfreed) {
+                return $locknotfreed;
+            }
         }
         if (&is_supplemental_title($title)) {
             &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
@@ -1081,13 +1084,17 @@ sub update_paste_buffer {
                 }
             }
         }
+        if ($locknotfreed) {
+            $output = $locknotfreed;
+            last;
+        }
     }
     if (@newpaste) {
         $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
     }
     &Apache::lonnet::appenv(\%addtoenv);
     delete($env{'form.markcopy'});
-    return;
+    return $output;
 }
 
 sub recurse_uploaded_maps {
@@ -1190,10 +1197,14 @@ sub print_paste_buffer {
                     $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
                     $icon .= '/navmap.folder.closed.gif';
                 }
+                my $title = $env{'docs.markedcopy_title_'.$suffix};
+                if ($title eq '') {
+                    ($title) = ($url =~ m{/([^/]+)$});
+                }
                 $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
                           ': '.
                           &Apache::loncommon::parse_supplemental_title(
-                             &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}));
+                             &LONCAPA::map::qtescape($title));
             }
             $pasteitems .= '<div class="LC_left_float">';
             my ($options,$onclick);
@@ -2809,7 +2820,7 @@ sub editor {
                     my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                     $name=&LONCAPA::map::qtescape($name);
                     $url=&LONCAPA::map::qtescape($url);
-                    next unless ($name && $url);
+                    next unless $url;
                     my %denied =
                         &action_restrictions($coursenum,$coursedom,$url,
                                              $env{'form.folderpath'},\%curr_groups);
@@ -3174,7 +3185,7 @@ sub process_file_upload {
     my $quotatype = 'unofficial';
     if ($crstype eq 'Community') {
         $quotatype = 'community';
-    } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.instcode'}) {
+    } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
         $quotatype = 'official';
     } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
         $quotatype = 'textbook';
@@ -3182,7 +3193,8 @@ sub process_file_upload {
     if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
         $filesize = int($filesize/1000); #expressed in kb
         $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
-                                                                      $env{'form.uploaddoc.filename'},$filesize,'upload');
+                                                                      $env{'form.uploaddoc.filename'},$filesize,
+                                                                      'upload',$quotatype);
         return if ($$upload_output);
     }
     my ($parseaction,$showupload,$nextphase,$mimetype);
@@ -3280,7 +3292,8 @@ sub process_file_upload {
                     $$upload_output .= &mt('No embedded items identified').'<br />';
                 }
                 $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
-            } elsif (&Apache::loncommon::is_archive_file($mimetype)) {
+            } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
+                     ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
                 $nextphase = 'decompress_uploaded';
                 my $position = scalar(@LONCAPA::map::order)-1;
                 my $noextract = &return_to_editor();
@@ -3342,7 +3355,7 @@ sub is_supplemental_title {
 sub entryline {
     my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
         $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups)=@_;
-    my ($foldertitle,$renametitle);
+    my ($foldertitle,$renametitle,$oldtitle);
     if (&is_supplemental_title($title)) {
 	($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
     } else {
@@ -3355,8 +3368,10 @@ sub entryline {
 
     $renametitle=~s/\\/\\\\/g;
     $renametitle=~s/\&quot\;/\\\"/g;
-    $renametitle=~s/\&#39\;/\\\'/g;
+    $renametitle=~s/"/%22/g;
     $renametitle=~s/ /%20/g;
+    $oldtitle = $renametitle;
+    $renametitle=~s/\&#39\;/\\\'/g;
     my $line=&Apache::loncommon::start_data_table_row();
     my ($form_start,$form_end,$form_common,$form_param);
 # Edit commands
@@ -3506,7 +3521,7 @@ ENDREM
             }
         }
         $renamelink=(<<ENDREN);
-<a href='javascript:changename("$esc_path","$index","$renametitle");' class="LC_docs_rename">$lt{'rn'}</a>
+<a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
 ENDREN
 	$line.=(<<END);
 <td>
@@ -3821,6 +3836,7 @@ sub new_timebased_suffix {
     if ($type eq 'paste') {
         $prefix = $type;
         $namespace = 'courseeditor';
+        $idtype = 'addcode';
     } elsif ($type eq 'map') {
         $prefix = 'docs';
         if ($area eq 'supplemental') {
@@ -3832,9 +3848,8 @@ sub new_timebased_suffix {
         $prefix = $type;
         $namespace = 'templated';
     }
-    $idtype = 'concat';
     my ($suffix,$freedlock,$error) =
-        &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num);
+        &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
     if (!$suffix) {
         if ($type eq 'paste') {
             $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
@@ -3854,9 +3869,19 @@ sub new_timebased_suffix {
             '<div class="LC_error">'.
             &mt('There was a problem removing a lockfile.').' ';
         if ($type eq 'paste') {
-            &mt('This will prevent use of the paste buffer until th next log-in.');
+            if ($freedlock eq 'nolock') {
+                $locknotfreed =
+                    '<div class="LC_error">'.
+                    &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
+
+                    &mt('As a result addition of items to the clipboard wll be unavailable until your next log-in.');
+            } else {
+                $locknotfreed .=
+                    &mt('This will prevent addition of items to the clipboard until your next log-in.');
+            }
         } elsif ($type eq 'map') {
-            &mt('This will prevent creation of additional folders or composite pages in this course.');
+            $locknotfreed .=
+                &mt('This will prevent creation of additional folders or composite pages in this course.');
         } elsif ($type eq 'smppg') {
             $locknotfreed .=
                 &mt('This will prevent creation of additional simple pages in this course.');
@@ -4501,12 +4526,8 @@ sub handler {
         $allowed = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
     }
 
-    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['chooseserver',
-                                            'inhibitmenu']);
-  if ($allowed && $env{'form.chooseserver'}) {
-      &choose_dump_server($r);
-      return OK;
-  } elsif ($allowed && $env{'form.verify'}) {
+    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
+  if ($allowed && $env{'form.verify'}) {
       &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
       &verifycontent($r);
   } elsif ($allowed && $env{'form.listsymbs'}) {
@@ -5459,7 +5480,7 @@ sub decompression_info {
     my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
     my $container='sequence';
     my ($pathitem,$hiddenelem);
-    my @hiddens = ('newidx','comment','position','folderpath');
+    my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
     if ($env{'form.folderpath'} =~ /\:1$/) {
         $container='page';
     }
@@ -5467,7 +5488,7 @@ sub decompression_info {
     foreach my $item (@hiddens) {
         if ($env{'form.'.$item}) {
             $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
-                           $env{'form.'.$item}.'" />'."\n";
+                           &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
         }
     }
     return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
@@ -5524,25 +5545,34 @@ sub remove_archive {
         } else {
             $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
         }
-        $delwarning .= &mt('As a result the archive file has not been removed.');
+        $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
     } else {
         my $currcmd = $env{'form.cmd'};
         my $position = $env{'form.position'};
-        if ($position > 0) { 
-            $env{'form.cmd'} = 'remove_'.$position;
-            my ($title,$url,@rrest) = 
-                split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$position]]);
-            if (&handle_edit_cmd($docuname,$docudom)) {
-                ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
-                if ($fatal) {
-                    if ($container eq 'page') {
-                        $delwarning = &mt('An error occurred updating the contents of the current page.');
+        my $archiveidx = $position;
+        if ($position > 0) {
+            if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
+                $archiveidx = $position-1;
+            }
+            $env{'form.cmd'} = 'remove_'.$archiveidx;
+            my ($title,$url,@rrest) =
+                split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
+            if ($url eq $env{'form.archiveurl'}) {
+                if (&handle_edit_cmd($docuname,$docudom)) {
+                    ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
+                    if ($fatal) {
+                        if ($container eq 'page') {
+                            $delwarning = &mt('An error occurred updating the contents of the current page.');
+                        } else {
+                            $delwarning = &mt('An error occurred updating the contents of the current folder.');
+                        }
                     } else {
-                        $delwarning = &mt('An error occurred updating the contents of the current folder.');
+                        $delresult = &mt('Archive file removed.');
                     }
-                } else {
-                    $delresult = &mt('Archive file removed.');
                 }
+            } else {
+                $delwarning .=  &mt('Archive file had unexpected item number in folder.').
+                                ' '.&mt('As a result the archive file has not been removed.');
             }
         }
         $env{'form.cmd'} = $currcmd;
@@ -5805,6 +5835,7 @@ sub editing_js {
             if (&Apache::lonnet::is_on_map($res)) {
                 $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($res),'<>&"').'?symb='.
                              &HTML::Entities::encode($caller,'<>&"');
+                $backtourl = &Apache::loncommon::escape_single($backtourl); 
             } else {
                 $backtourl = '/adm/navmaps';
             }