--- loncom/interface/portfolio.pm 2004/12/04 18:37:36 1.61 +++ loncom/interface/portfolio.pm 2005/04/07 04:46:36 1.81 @@ -83,12 +83,14 @@ 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::dump('file_permissions', - $ENV{'user.domain'},$ENV{'user.name'}); - my $locked_file; - foreach my $key (keys %locked_files) { - $locked_file .= $locked_files{$key}.':'; - } + my $select_mode; + my $checked_files; + my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash ($ENV{'user.domain'},$ENV{'user.name'}); + if ($ENV{"form.mode"} eq 'selectfile'){ + &select_files($r); + $checked_files =&Apache::lonnet::files_in_path($ENV{'user.name'},$ENV{'form.currentpath'}); + $select_mode = 'true'; + } if ($is_empty && ($current_path ne '/')) { $display_out = '
'. ''. @@ -100,78 +102,17 @@ sub display_directory { $r->print($display_out); return; } - $r->print(''. - ''); - my $href_location="/uploaded/$ENV{'user.domain'}/$ENV{'user.name'}/portfolio$current_path"; - foreach my $line (sort - { - my ($afile)=split('&',$a,2); - my ($bfile)=split('&',$b,2); - return (lc($afile) cmp lc($bfile)); - } (@$dir_list)) { - #$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); - if (($filename ne '.') && ($filename ne '..')) { - if ($dirptr&$testdir) { - $r->print(''); - $r->print(''); - $r->print(''); - $r->print(''); - } else { - $r->print(''); - $r->print(''); - $r->print(''); - $r->print(''); - $r->print(''); - $r->print(''); - $r->print(''); - } - } - } -# pink bg -# blue bg -# $r->print(&display_directory($current_path, $currentFile, @dir_list)); -# $r->print('>
Actions NameSizeLast Modified
Go to ...'.&make_anchor($filename.'/',$current_path.$filename.'/',$ENV{'form.mode'},$ENV{"form.fieldname"}).'
- - - - - - - '. - $filename.''.$size.''.&Apache::lonlocal::locallocaltime($mtime).'
'); -# $r->print(&display_actions($current_path, $currentFile, $isEmpty)); - $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'}); - foreach my $key (keys %$checked_files) { - &Apache::lonnet::logthis("a key is $key $$checked_files{$key} is the value"); - } - if ($is_empty && ($current_path ne '/')) { - $display_out = '
'. - ''. - ''. - ''. - ''. - - '
'; - - $r->print($display_out); - return; - } - $r->print(''. + if ($select_mode eq 'true') { + $r->print('
'. ''); + $r->print(''); + } else { + $r->print('
Select NameSizeLast Modified
'. + ''); + $r->print(''); + } my $href_location="/uploaded/$ENV{'user.domain'}/$ENV{'user.name'}/portfolio$current_path"; - $r->print(''); + my $href_edit_location="/editupload/$ENV{'user.domain'}/$ENV{'user.name'}/portfolio$current_path"; foreach my $line (sort { my ($afile)=split('&',$a,2); @@ -182,22 +123,34 @@ sub display_file_select { #$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 (($filename ne '.') && ($filename ne '..') && ($filename !~ /\.meta$/ )) { if ($dirptr&$testdir) { - $r->print(''); + if ($select_mode eq 'true'){ + $r->print(''); + } else { + $r->print(''); + } $r->print(''); $r->print(''); $r->print(''); } else { $r->print(''); - $r->print(''); } else { - &Apache::lonnet::logthis("not checked $$checked_files{$filename} $filename"); + if (exists $locked_files{$current_path.$filename}){ + $r->print(''); + } else { + $r->print(' + '); + } } - $r->print('>'); $r->print(''); $r->print(''); @@ -207,24 +160,35 @@ sub display_file_select { } } } - $r->print('
Actions NameSizeLast Modified
Go to ...'.&make_anchor($filename.'/',$current_path.$filename.'/',$ENV{'form.mode'},$ENV{"form.fieldname"}).'
print("CHECKED"); - &Apache::lonnet::logthis("checked"); + if ($select_mode eq 'true'){ + $r->print('print("CHECKED"); + } + $r->print('>Locked + RenameMeta + '. $filename.'
+ if ($select_mode eq 'true') { + $r->print('
- '); + '); + } else { + $r->print(' + + + + '); + } } 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(''); } @@ -244,42 +208,67 @@ 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 { + my ($message)=@_; + unless (defined $message) { + $message='Done'; + } return ('

'.&mt('Done').'

'); + '">'.&mt($message).''); } sub delete { my ($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()); + $r->print(&done('Back')); } else { - &open_form($r); - $r->print('

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

'); - &close_form($r); + 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()); } @@ -294,8 +283,7 @@ sub delete_dir { sub delete_dir_confirmed { my ($r)=@_; my $directory_name = $ENV{'form.currentpath'}; - $directory_name =~ m/\/$/; - $directory_name = $`; + $directory_name =~ s|/$||; # remove any trailing slash my $result=&Apache::lonnet::removeuserfile($ENV{'user.name'}, $ENV{'user.domain'},'portfolio'. $directory_name); @@ -321,7 +309,7 @@ sub delete_dir_confirmed { sub rename { my ($r)=@_; - my $file_name = $ENV{'form.currentpath'}.$ENV{'form.selectfile'}; + 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()); @@ -352,6 +340,9 @@ sub rename_confirmed { ') 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 { @@ -359,13 +350,25 @@ sub select_files { if ($ENV{'form.continue'} eq 'true') { # here we update the selections for the currentpath # eventually, have to handle removing those not checked, but . . . - my @items=&Apache::loncommon::get_env_multiple('form.selectedfile'); + my @items=&Apache::loncommon::get_env_multiple('form.selectfile'); &Apache::lonnet::save_selected_files($ENV{'user.name'}, $ENV{'form.currentpath'}, @items); + } else { + if ($ENV{'form.currentpath'} eq '/') { + #empty the file for a fresh start + # &Apache::lonnet::clear_selected_files($ENV{'user.name'}); + } } - 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:
"); @@ -402,31 +405,49 @@ sub upload { $ENV{'user.domain'}, $ENV{'user.name'},$portfolio_root); my $found_file = 0; + my $locked_file = 0; foreach my $line (@dir_list) { - my ($filename)=split(/\&/,$line,2); - if ($filename eq $fname){ + my ($file_name)=split(/\&/,$line,2); + if ($file_name eq $fname){ $found_file = 1; + if (&Apache::lonnet::is_locked($ENV{'form.currentpath'}.$file_name,$ENV{'user.domain'},$ENV{'user.name'} ) eq 'true') { + $locked_file = 1; + } } } my $current_disk_usage = &Apache::lonnet::diskusage($ENV{'user.domain'}, $ENV{'user.name'},$portfolio_root); - if (($current_disk_usage + $filesize) > $disk_quota){ + if ((($current_disk_usage/1000) + $filesize) > $disk_quota){ $r->print('Unable to upload '.$fname.' (size = '.$filesize.' kilobytes. Disk quota will be exceeded.'. '
Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.'); + $r->print(&done('Back')); } - elsif ($found_file){ - $r->print('Unable to upload '.$fname.', a file by that name was found in '.$ENV{'form.currentpath'}.''. - '
To upload, rename or delete existing '.$fname.' in '.$ENV{'form.currentpath'}); + elsif ($found_file){ + if ($locked_file){ + $r->print('Unable to upload '.$fname.', a locked file by that name was found in portfolio'.$ENV{'form.currentpath'}.''. + '
You will be able to rename or delete existing '.$fname.' after a grade has been assigned.'); + $r->print(&done('Back')); + } else { + $r->print('Unable to upload '.$fname.', a file by that name was found in portfolio'.$ENV{'form.currentpath'}.''. + '
To upload, rename or delete existing '.$fname.' in portfolio'.$ENV{'form.currentpath'}); + $r->print(&done('Back')); + } } else { my $result=&Apache::lonnet::userfileupload('uploaddoc','', 'portfolio'.$ENV{'form.currentpath'}); if ($result !~ m|^/uploaded/|) { $r->print(' An errror occured ('.$result. ') while trying to upload '.&display_file().'
'); + $r->print(&done('Back')); + } else { + $r->print(&done()); } } - $r->print(&done()); } - +sub lock_info { + my ($r) = @_; + $r->print("lock info here"); + return 'ok'; +} sub createdir { my ($r)=@_; my $newdir=&Apache::lonnet::clean_filename($ENV{'form.newdir'}); @@ -461,6 +482,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()); } @@ -470,23 +494,37 @@ sub handler { my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'}, $ENV{'user.name'}). '/userfiles/portfolio'; + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, + ['selectfile','currentpath','meta','lockinfo', + 'currentfile','action','fieldname','mode','rename']); &Apache::loncommon::no_cache($r); &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; # Give the LON-CAPA page header - $r->print(''. + my $html=&Apache::lonxml::xmlbegin(); + $r->print($html.'<head><title>'. &mt('Portfolio Manager'). - "\n". - &Apache::loncommon::bodytag('Portfolio Manager')); + "\n"); + if ($ENV{"form.mode"} eq 'selectfile'){ + $r->print(&Apache::loncommon::bodytag('Portfolio Manager',undef,undef,1)); + } else { + $r->print(&Apache::loncommon::bodytag('Portfolio Manager')); + } $r->rflush(); - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['selectfile','currentpath', - 'currentfile','action','fieldname','mode']); if (($ENV{'form.storeupl'} eq 'Upload') & (!$ENV{'form.uploaddoc.filename'})){ $r->print(' No file was selected to upload.'. 'To upload a file, click Browse...'. ', select a file, then click Upload,'); } + if ($ENV{'form.meta'}) { + &open_form($r); +# $r->print(&edit_meta_data($r, $ENV{'form.currentpath'}.$ENV{'form.selectfile'})); + $r->print('Edit the meta data
'); + &close_form($r); + } + if ($ENV{'form.store'}) { + } + if ($ENV{'form.uploaddoc.filename'}) { &upload($r); } elsif ($ENV{'form.action'} eq 'delete' && $ENV{'form.confirmed'}) { @@ -499,10 +537,14 @@ 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); + } elsif ($ENV{'form.lockinfo'}) { + &lock_info($r); } else { my $current_path='/'; if ($ENV{'form.currentpath'}) { @@ -533,12 +575,7 @@ sub handler { # need to know if directory is empty so it can be removed if desired my $is_empty=(@dir_list == 2); &display_common($r,$current_path,$is_empty,\@dir_list); - if ($ENV{"form.mode"} eq 'selectfile'){ - &select_files($r); - &display_file_select($r,$current_path,$is_empty,\@dir_list); - } else { - &display_directory($r,$current_path,$is_empty,\@dir_list); - } + &display_directory($r,$current_path,$is_empty,\@dir_list); $r->print("\n\n"); return OK; }