--- loncom/interface/portfolio.pm 2004/10/25 13:04:58 1.51 +++ loncom/interface/portfolio.pm 2004/12/16 21:19:46 1.68 @@ -33,8 +33,8 @@ use Apache::lonlocal; # receives a file name and path stub from username/userfiles/portfolio/ # returns an anchor tag consisting encoding filename and currentpath sub make_anchor { - my ($filename, $current_path) = @_; - my $anchor = ''.$filename.''; + my ($filename, $current_path, $current_mode, $field_name) = @_; + my $anchor = ''.$filename.''; return $anchor; } my $dirptr=16384; @@ -48,6 +48,7 @@ sub display_common { ''. ''. ''. + ''. ''. ''; $r->print($displayOut); @@ -57,23 +58,23 @@ sub display_common { ''. ''. ''. + ''. ''. ''; $r->print($displayOut); $r->print(''); my @tree = split (/\//,$current_path); - $r->print(''.&make_anchor('portfolio','/').'/'); + $r->print(''.&make_anchor('portfolio','/',$ENV{"form.mode"},$ENV{"form.fieldname"}).'/'); if (@tree > 1){ my $newCurrentPath = ''; for (my $i = 1; $i< @tree; $i++){ $newCurrentPath .= $tree[$i].'/'; - $r->print(&make_anchor($tree[$i],'/'.$newCurrentPath).'/'); + $r->print(&make_anchor($tree[$i],'/'.$newCurrentPath, $ENV{"form.mode"},$ENV{"form.fieldname"}).'/'); } } $r->print(''); &Apache::lonhtmlcommon::store_recent('portfolio',$current_path,$current_path); - #Fixme -- remove from recent those paths that are deleted - $r->print('
'. + $r->print('
'. &Apache::lonhtmlcommon::select_recent('portfolio','currentpath', 'this.form.submit();')); $r->print("
"); @@ -82,6 +83,7 @@ sub display_directory { my ($r,$current_path,$is_empty,$dir_list)=@_; my $iconpath= $r->dir_config('lonIconsURL') . "/"; my $display_out; + my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash ($ENV{'user.domain'},$ENV{'user.name'}); if ($is_empty && ($current_path ne '/')) { $display_out = '
'. ''. @@ -96,6 +98,7 @@ sub display_directory { $r->print(''. ''); my $href_location="/uploaded/$ENV{'user.domain'}/$ENV{'user.name'}/portfolio$current_path"; + $r->print(''); foreach my $line (sort { my ($afile)=split('&',$a,2); @@ -109,22 +112,17 @@ sub display_directory { if ($dirptr&$testdir) { $r->print(''); $r->print(''); - $r->print(''); + $r->print(''); $r->print(''); } else { $r->print(''); - $r->print(''); + if (exists $locked_files{$current_path.$filename}){ + $r->print(''); + } else { + $r->print(''); + } $r->print(''); $r->print(''); @@ -139,12 +137,17 @@ sub display_directory { # $r->print(&display_directory($current_path, $currentFile, @dir_list)); # $r->print('>
Actions NameSizeLast Modified
Go to ...'.&make_anchor($filename.'/',$current_path.$filename.'/').''.&make_anchor($filename.'/',$current_path.$filename.'/',$ENV{'form.mode'},$ENV{"form.fieldname"}).'
- - - - - - - LockedDelete + Rename + '. $filename.''); # $r->print(&display_actions($current_path, $currentFile, $isEmpty)); - $r->print('
'); + $r->print(' + + + + '); } sub display_file_select { my ($r,$current_path,$is_empty,$dir_list)=@_; my $iconpath= $r->dir_config('lonIconsURL') . "/"; my $display_out; + my $checked_files = &Apache::lonnet::files_in_path($ENV{'user.name'}, $ENV{'form.currentpath'}); if ($is_empty && ($current_path ne '/')) { $display_out = '
'. ''. @@ -170,17 +173,20 @@ sub display_file_select { #$strip holds directory/file name #$dom my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); + $filename =~ s/\s+$//; if (($filename ne '.') && ($filename ne '..')) { if ($dirptr&$testdir) { $r->print(''); $r->print('Go to ...'); - $r->print(''.&make_anchor($filename.'/',$current_path.$filename.'/').''); + $r->print(''.&make_anchor($filename.'/',$current_path.$filename.'/',$ENV{'form.mode'},$ENV{"form.fieldname"}).''); $r->print(''); } else { $r->print(''); - $r->print(' - - '); + $r->print('print("CHECKED"); + } + $r->print('>'); $r->print(''); $r->print(''. $filename.''); @@ -191,6 +197,10 @@ sub display_file_select { } } $r->print(' + + + +
'); @@ -198,12 +208,15 @@ sub display_file_select { sub open_form { my ($r)=@_; + my @files=&Apache::loncommon::get_env_multiple('form.selectfile'); $r->print('
'); $r->print(''); $r->print(''); - $r->print(''); + foreach (@files) { + $r->print(''); + } $r->print(''); } @@ -223,34 +236,63 @@ sub close_form { sub display_file { my ($path,$filename)=@_; + my $display_file_text; if (!defined($path)) { $path=$ENV{'form.currentpath'}; } - if (!defined($filename)) { $filename=$ENV{'form.selectfile'}; } - return ''.$path.$filename.''; + if (!defined($filename)) { + $filename=$ENV{'form.selectfile'}; + $display_file_text = ''.$path.$filename.''; + } elsif (ref($filename) eq "ARRAY") { + foreach (@$filename) { + $display_file_text .= ''.$path.$_.'
'; + } + } elsif (ref($filename) eq "SCALAR") { + $display_file_text = ''.$path.$filename.''; + } + return $display_file_text; } sub done { return ('

'.&mt('Done').'

'); } sub delete { my ($r)=@_; - &open_form($r); - $r->print('

'.&mt('Delete').' '.&display_file().'?

'); - &close_form($r); + my @check; + my $file_name = $ENV{'form.currentpath'}.$ENV{'form.selectfile'}; + my @files=&Apache::loncommon::get_env_multiple('form.selectfile'); + + if (&Apache::lonnet::is_locked($file_name,$ENV{'user.domain'},$ENV{'user.name'} ) eq 'true') { + $r->print ("The file is locked and cannot be deleted.
"); + $r->print(&done()); + } else { + if (scalar(@files)) { + &open_form($r); + $r->print('

'.&mt('Delete').' '.&display_file(undef,\@files).'?

'); + &close_form($r); + } else { + $r->print("No file was checked to delete.
"); + $r->print(&done()); + } + } } sub delete_confirmed { my ($r)=@_; - my $result=&Apache::lonnet::removeuserfile($ENV{'user.name'}, + my @files=&Apache::loncommon::get_env_multiple('form.selectfile'); + my $result; + foreach my $delete_file (@files) { + $result=&Apache::lonnet::removeuserfile($ENV{'user.name'}, $ENV{'user.domain'},'portfolio'. $ENV{'form.currentpath'}. - $ENV{'form.selectfile'}); - if ($result ne 'ok') { + $delete_file); + if ($result ne 'ok') { $r->print(' An error occured ('.$result. - ') while trying to delete '.&display_file().'
'); + ') while trying to delete '.&display_file(undef, $delete_file).'

'); + } } $r->print(&done()); } @@ -292,10 +334,16 @@ sub delete_dir_confirmed { sub rename { my ($r)=@_; - &open_form($r); - $r->print('

'.&mt('Rename').' '.&display_file().' to - ?

'); - &close_form($r); + my $file_name = $ENV{'form.currentpath'}.$ENV{'form.rename'}; + if (&Apache::lonnet::is_locked($file_name,$ENV{'user.domain'},$ENV{'user.name'}) eq 'true') { + $r->print ("The file is locked and cannot be renamed.
"); + $r->print(&done()); + } else { + &open_form($r); + $r->print('

'.&mt('Rename').' '.&display_file().' to + ?

'); + &close_form($r); + } } sub rename_confirmed { @@ -311,37 +359,62 @@ sub rename_confirmed { my $result= &Apache::lonnet::renameuserfile($ENV{'user.name'},$ENV{'user.domain'}, 'portfolio'.$ENV{'form.currentpath'}.$ENV{'form.selectfile'}, - 'portfolio'.$ENV{'form.currentpath'}.$ENV{'form.filenewname'}); + 'portfolio'.$ENV{'form.currentpath'}.$filenewname); if ($result ne 'ok') { $r->print(' An errror occured ('.$result. ') while trying to rename '.&display_file().' to '. &display_file(undef,$filenewname).'
'); } + if ($filenewname ne $ENV{'form.filenewname'}) { + $r->print("The new file name was changed from:
".$ENV{'form.filenewname'}." to $filenewname "); + } $r->print(&done()); } sub select_files { my ($r)=@_; - my $java_script =(< function finishSelect() { - fileList = ""; +ENDSMP + $javascript .= 'fileList = "'.$java_files.'";'; + $javascript .= (< ENDSMP - $r->print($java_script); + $r->print($javascript); $r->print("

Select portfolio files

Check as many as you wish in response to the essay problem.
"); + $r->print("Files selected from other directories:
"); + foreach (&Apache::lonnet::files_not_in_path($ENV{'user.name'}, $ENV{'form.currentpath'})) { + $r->print($_."
"); + } } sub upload { my ($r)=@_; @@ -416,6 +489,9 @@ sub createdir { ') while trying to create a new directory '.&display_file().'
'); } } + if ($newdir ne $ENV{'form.newdir'}) { + $r->print("The new directory name was changed from:
".$ENV{'form.newdir'}." to $newdir "); + } $r->print(&done()); } @@ -436,7 +512,7 @@ sub handler { $r->rflush(); &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['selectfile','currentpath', - 'currentfile','action','fieldname']); + 'currentfile','action','fieldname','mode','rename']); if (($ENV{'form.storeupl'} eq 'Upload') & (!$ENV{'form.uploaddoc.filename'})){ $r->print(' No file was selected to upload.'. 'To upload a file, click Browse...'. @@ -454,7 +530,9 @@ sub handler { &delete_dir($r); } elsif ($ENV{'form.action'} eq 'rename' && $ENV{'form.confirmed'}) { &rename_confirmed($r); - } elsif ($ENV{'form.action'} eq 'rename') { + } elsif ($ENV{'form.rename'}) { + $ENV{'form.selectfile'} = $ENV{'form.rename'}; + $ENV{'form.action'} = 'rename'; &rename($r); } elsif ($ENV{'form.createdir'}) { &createdir($r);