--- loncom/interface/portfolio.pm 2006/08/24 17:38:21 1.161 +++ loncom/interface/portfolio.pm 2006/11/01 16:12:35 1.169 @@ -1,7 +1,7 @@ # The LearningOnline Network # portfolio browser # -# $Id: portfolio.pm,v 1.161 2006/08/24 17:38:21 banghart Exp $ +# $Id: portfolio.pm,v 1.169 2006/11/01 16:12:35 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -95,6 +95,13 @@ sub display_common { 'createdir_label' => 'Create subdirectory in current directory:'); my $escuri = &HTML::Entities::encode($r->uri,'&<>"'); + my $help_fileupload = &Apache::loncommon::help_open_topic('Portfolio AddFiles'); + my $help_createdir = &Apache::loncommon::help_open_topic('Portfolio CreateDirectory'); + + # FIXME: This line should be deleted once Portfolio uses breadcrumbs + $r->print(&Apache::loncommon::help_open_topic('Portfolio About', 'Help on the portfolio')); + + $r->print(<<"TABLE"); @@ -109,7 +116,7 @@ sub display_common { - + $help_fileupload @@ -124,7 +131,7 @@ sub display_common { - + $help_createdir @@ -155,6 +162,7 @@ TABLE } } $r->print(''); + $r->print(&Apache::loncommon::help_open_topic('Portfolio ChangeDirectory')); &Apache::lonhtmlcommon::store_recent($namespace,$current_path,$current_path); $r->print('
'. @@ -259,8 +267,14 @@ sub display_directory { ''); } else { $r->print(''); + $r->print(&Apache::loncommon::help_open_topic('Portfolio FileList', + 'Using the portfolio file list')); $r->print('
Select  NameSizeLast Modified
'. - ''); + ''); } $r->print("\n".&group_form_data()."\n"); @@ -294,7 +308,7 @@ sub display_directory { my $version_flag; my $show_versions; my $fullpath = &prepend_group($current_path.$filename); - if ($env{'form.showversions'} eq $filename) { + if ($env{'form.showversions'} =~ /$filename/) { $show_versions = 'true'; } if (exists($versioned{$fullpath})) { @@ -304,10 +318,15 @@ sub display_directory { 'currentpath' => $current_path, ); if ($show_versions) { + # Must preserve other possible showversion files + my $version_remainder = $env{'form.showversions'}; + $version_remainder =~ s/$filename//g; + $anchor_fields{'showversions'} = $version_remainder; $version_flag = &make_anchor('portfolio',\%anchor_fields, ''.&mt('opened folder').''); } else { - $anchor_fields{'showversions'} = $filename; + # allow multiple files to show versioned + $anchor_fields{'showversions'} = $env{'form.showversions'}.','.$filename; $version_flag = &make_anchor('portfolio',\%anchor_fields, ''.&mt('closed folder').''); } @@ -431,7 +450,8 @@ sub display_directory { $r->print('
Actions  NameSizeLast ModifiedCurrent Access Status
Actions  Name'. + &Apache::loncommon::help_open_topic('Portfolio OpenFile'). + 'SizeLast ModifiedCurrent Access Status'. + &Apache::loncommon::help_open_topic('Portfolio ShareFile'). + '
'); if ($can_delete) { $r->print(' - + '. + &Apache::loncommon::help_open_topic('Portfolio DeleteFile').' ' @@ -518,7 +538,7 @@ sub delete { my @files=&Apache::loncommon::get_env_multiple('form.selectfile'); my ($uname,$udom) = &get_name_dom(); if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') { - $r->print ("The file is locked and cannot be deleted.
"); + $r->print("The file is locked and cannot be deleted.
"); $r->print(&done('Back',$url)); } else { if (scalar(@files)) { @@ -533,18 +553,55 @@ sub delete { } sub delete_confirmed { - my ($r,$url)=@_; + my ($r,$url,$group)=@_; my @files=&Apache::loncommon::get_env_multiple('form.selectfile'); my $result; my ($uname,$udom) = &get_name_dom(); my $port_path = &get_port_path(); + my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom, + $uname); foreach my $delete_file (@files) { $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path. $env{'form.currentpath'}. $delete_file); if ($result ne 'ok') { - $r->print(' An error occured ('.$result. - ') while trying to delete '.&display_file(undef, $delete_file).'
'); + $r->print(''. + &mt('An error occured ([_1]) while trying to delete + [_2].',$result,&display_file(undef, $delete_file)). + '

'); + } else { + $r->print(&mt('File: [_1] deleted.', + &display_file(undef,$delete_file))); + my $file_name = $env{'form.currentpath'}.$delete_file; + $file_name = &prepend_group($file_name); + my %access_controls = + &Apache::lonnet::get_access_controls($current_permissions, + $group,$file_name); + if (keys(%access_controls) > 0) { + my %changes; + foreach my $key (keys(%{$access_controls{$file_name}})) { + $changes{'delete'}{$key} = 1; + } + if (keys(%changes) > 0) { + my ($outcome,$deloutcome,$new_values,$translation) = + &Apache::lonnet::modify_access_controls($file_name,\%changes, + $udom,$uname); + if ($outcome ne 'ok') { + $r->print('
'.&mt("An error occured ([_1]) while ". + "trying to delete access controls for the file.",$outcome). + '

'); + } else { + if ($deloutcome eq 'ok') { + $r->print('
'.&mt('Access controls also deleted for the file.').'

'); + } else { + $r->print(''.'
'. + &mt("An error occured ([_1]) while ". + "trying to delete access controls for the file.",$deloutcome). + '


'); + } + } + } + } } } $r->print(&done(undef,$url)); @@ -592,7 +649,7 @@ sub rename { my ($uname,$udom) = &get_name_dom(); $file_name = &prepend_group($file_name); if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') { - $r->print ("The file is locked and cannot be renamed.
"); + $r->print("The file is locked and cannot be renamed.
"); $r->print(&done(undef,$url)); } else { &open_form($r,$url); @@ -603,7 +660,7 @@ sub rename { } sub rename_confirmed { - my ($r,$url)=@_; + my ($r,$url,$group)=@_; my $filenewname=&Apache::lonnet::clean_filename($env{'form.filenewname'}); my ($uname,$udom) = &get_name_dom(); my $port_path = &get_port_path(); @@ -614,24 +671,79 @@ sub rename_confirmed { $r->print(&done(undef,$url)); return; } + my $chg_access; my $result= &Apache::lonnet::renameuserfile($uname,$udom, $port_path.$env{'form.currentpath'}.$env{'form.selectfile'}, $port_path.$env{'form.currentpath'}.$filenewname); - if ($result ne 'ok') { + if ($result eq 'ok') { + $chg_access = &access_for_renamed($filenewname,$group,$udom,$uname); + } else { $r->print(''. - &mt('An errror occured ([_1]) while trying to rename [_2]' + &mt('An error occured ([_1]) while trying to rename [_2]' .' to [_3]',$result,&display_file(), &display_file('',$filenewname)).'
'); + return; } if ($filenewname ne $env{'form.filenewname'}) { $r->print(&mt("The new file name was changed from:
[_1] to [_2]", ''.&display_file('',$env{'form.filenewname'}).'', ''.&display_file('',$filenewname).'')); } + $r->print($chg_access); $r->print(&done(undef,$url)); } +sub access_for_renamed { + my ($filenewname,$group,$udom,$uname) = @_; + my $oldfile = $env{'form.currentpath'}.$env{'form.selectfile'}; + $oldfile = &prepend_group($oldfile); + my $newfile = $env{'form.currentpath'}.$filenewname; + $newfile = &prepend_group($newfile); + my $current_permissions = + &Apache::lonnet::get_portfile_permissions($udom,$uname); + my %access_controls = + &Apache::lonnet::get_access_controls($current_permissions, + $group,$oldfile); + my $chg_text; + if (keys(%access_controls) > 0) { + my %change_old; + my %change_new; + foreach my $key (keys(%{$access_controls{$oldfile}})) { + $change_old{'delete'}{$key} = 1; + $change_new{'activate'}{$key} = $access_controls{$oldfile}{$key}; + } + my ($outcome,$deloutcome,$new_values,$translation) = + &Apache::lonnet::modify_access_controls($oldfile,\%change_old, + $udom,$uname); + if ($outcome ne 'ok') { + $chg_text ='

'.&mt("An error occured ([_1]) while ". + "trying to delete access control records for the old name.",$outcome). + '
'; + } else { + if ($deloutcome ne 'ok') { + $chg_text = '


'. + &mt("An error occured ([_1]) while ". + "trying to delete access control records for the old name.",$deloutcome). + '

'; + } + } + ($outcome,$deloutcome,$new_values,$translation) = + &Apache::lonnet::modify_access_controls($newfile,\%change_new, + $udom,$uname); + if ($outcome ne 'ok') { + $chg_text .= '

'. + &mt("An error occured ([_1]) while ". + "trying to update access control records for the new name.",$outcome). + '
'; + } + if ($chg_text eq '') { + $chg_text = '

'.&mt('Access controls updated to reflect the name change.'); + } + } + return $chg_text; +} + sub display_access { my ($r,$url,$group,$can_setacl,$port_path) = @_; my ($uname,$udom) = &get_name_dom(); @@ -651,10 +763,12 @@ sub display_access { if ($group eq '') { $info .= (&mt("A listing of files viewable without log-in is available at: http://$ENV{'SERVER_NAME'}/adm/$udom/$uname/aboutme/portfolio.
For logged in users a 'Display file listing' link will also appear (when there are viewable files) on your personal information page:
http://$ENV{'SERVER_NAME'}/adm/$udom/$uname/aboutme
")); } - if ($can_setacl) { &open_form($r,$url); $r->print($header.$info); + $r->print('
'.&Apache::loncommon::help_open_topic('Portfolio ShareFile SetAccess', 'Help on setting up share access')); + $r->print(&Apache::loncommon::help_open_topic('Portfolio ShareFile ChangeSetting', 'Help on changing settings')); + $r->print(&Apache::loncommon::help_open_topic('Portfolio ShareFile StopAccess', 'Help on removing share access')); &access_setting_table($r,$access_controls{$file_name}); my $button_text = { 'continue' => &mt('Proceed'), @@ -1683,16 +1797,19 @@ sub createdir { } sub get_portfolio_root { - my ($udom,$uname) = @_; + my ($udom,$uname,$group) = @_; if (!(defined($udom)) || !(defined($uname))) { ($uname,$udom) = &get_name_dom(); } - my $path; - if (defined($env{'form.group'})) { - $path = '/userfiles/groups/'.$env{'form.group'}.'/portfolio'; - } else { - $path = '/userfiles/portfolio'; + my $path = '/userfiles/portfolio'; + if (!defined($group)) { + if (defined($env{'form.group'})) { + $group = $env{'form.group'}; + } } + if (defined($group)) { + $path = '/userfiles/groups/'.$group.'/portfolio'; + } return (&Apache::loncommon::propath($udom,$uname).$path); } @@ -1933,7 +2050,7 @@ sub handler { } } elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) { if ($can_delete) { - &delete_confirmed($r,$url); + &delete_confirmed($r,$url,$group); } else { &missing_priv($r,$url,'delete'); } @@ -1957,7 +2074,7 @@ sub handler { } } elsif ($env{'form.action'} eq 'rename' && $env{'form.confirmed'}) { if ($can_modify) { - &rename_confirmed($r,$url); + &rename_confirmed($r,$url,$group); } else { &missing_priv($r,$url,'rename'); }