--- loncom/interface/portfolio.pm 2006/08/14 21:25:42 1.156
+++ loncom/interface/portfolio.pm 2006/10/19 20:36:12 1.165
@@ -1,7 +1,7 @@
# The LearningOnline Network
# portfolio browser
#
-# $Id: portfolio.pm,v 1.156 2006/08/14 21:25:42 albertel Exp $
+# $Id: portfolio.pm,v 1.165 2006/10/19 20:36:12 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -191,6 +191,11 @@ sub display_directory_line {
}
if ($lock_info) {
my %anchor_fields = ('lockinfo' => $fullpath);
+ if ($versions) { # hold the folder open
+ my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($fullpath);
+ $fname =~ s|^/||;
+ $anchor_fields{'showversions'} = $fname.'.'.$extension;
+ }
$lock_info = &make_anchor(undef,\%anchor_fields,$lock_info);
}
$r->print('
'.$lock_info.' | ');
@@ -289,7 +294,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})) {
@@ -299,10 +304,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,
'');
} 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,
'');
}
@@ -358,7 +368,7 @@ sub display_directory {
currentpath => $current_path
);
$line .= &make_anchor($url,\%anchor_fields,'Rename');
- $line .= ''.&make_anchor($href_edit_location.$filename.'.meta',undef,$cat);
+ $line .= ' | '.&make_anchor($href_edit_location.$filename.'.meta',\%anchor_fields,$cat);
# ''.$cat.'';
}
$line .= ' | ';
@@ -496,6 +506,7 @@ sub done {
$message='Done';
}
my %anchor_fields = (
+ 'showversions' => $env{'form.showversions'},
'currentpath' => $env{'form.currentpath'},
'fieldname' => $env{'form.fieldname'},
'mode' => $env{'form.mode'}
@@ -527,18 +538,54 @@ 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(' An error occured ('.$result.
+ ') while trying to delete '.
+ &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 (%{$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));
@@ -597,7 +644,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();
@@ -608,24 +655,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();
@@ -643,7 +745,7 @@ sub display_access {
$info .= &mt('The conditions can include affiliation with a particular course or group, or a user account in a specific domain.').'
';
$info .= &mt('Alternatively access can be granted to people with specific LON-CAPA usernames and domains.').'';
if ($group eq '') {
- $info .= (&mt("Direct others to the 'Display file listing' link (shown when there are viewable files) on your personal information page:
http://$ENV{'SERVER_NAME'}/adm/$udom/$uname/aboutme"));
+ $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) {
@@ -1677,13 +1779,19 @@ sub createdir {
}
sub get_portfolio_root {
- my ($uname,$udom) = &get_name_dom();
- my $path;
- if (defined($env{'form.group'})) {
- $path = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
- } else {
- $path = '/userfiles/portfolio';
+ my ($udom,$uname,$group) = @_;
+ if (!(defined($udom)) || !(defined($uname))) {
+ ($uname,$udom) = &get_name_dom();
}
+ 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);
}
@@ -1924,7 +2032,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');
}
@@ -1948,7 +2056,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');
}