--- loncom/interface/portfolio.pm 2006/11/21 21:38:44 1.173
+++ loncom/interface/portfolio.pm 2007/07/10 20:51:46 1.186
@@ -1,7 +1,7 @@
# The LearningOnline Network
# portfolio browser
#
-# $Id: portfolio.pm,v 1.173 2006/11/21 21:38:44 raeburn Exp $
+# $Id: portfolio.pm,v 1.186 2007/07/10 20:51:46 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -101,7 +101,6 @@ sub display_common {
# 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");
@@ -148,12 +147,12 @@ TABLE
);
$r->print(''.&make_anchor($url,\%anchor_fields,$port_path).'/');
if (@tree > 1){
- my $newCurrentPath = '';
+ my $newCurrentPath = '/';
for (my $i = 1; $i< @tree; $i++){
$newCurrentPath .= $tree[$i].'/';
my %anchor_fields = (
'selectfile' => $tree[$i],
- 'currentpath' => '/',
+ 'currentpath' => $newCurrentPath,
'mode' => $env{"form.mode"},
'fieldname' => $env{"form.fieldname"},
'continue' => $env{"form.continue"}
@@ -290,8 +289,6 @@ sub display_directory {
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(/\&/,$dir_line,16);
$filename =~ s/\s+$//;
my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($filename);
@@ -568,7 +565,7 @@ sub delete_confirmed {
$delete_file);
if ($result ne 'ok') {
$r->print(''.
- &mt('An error occured ([_1]) while trying to delete
+ &mt('An error occurred ([_1]) while trying to delete
[_2].',$result,&display_file(undef, $delete_file)).
'
');
} else {
@@ -589,7 +586,7 @@ sub delete_confirmed {
&Apache::lonnet::modify_access_controls($file_name,\%changes,
$udom,$uname);
if ($outcome ne 'ok') {
- $r->print(' '.&mt("An error occured ([_1]) while ".
+ $r->print(' '.&mt("An error occurred ([_1]) while ".
"trying to delete access controls for the file.",$outcome).
'
');
} else {
@@ -597,7 +594,7 @@ sub delete_confirmed {
$r->print(' '.&mt('Access controls also deleted for the file.').'
');
} else {
$r->print(''.' '.
- &mt("An error occured ([_1]) while ".
+ &mt("An error occurred ([_1]) while ".
"trying to delete access controls for the file.",$deloutcome).
'
');
}
@@ -627,15 +624,12 @@ sub delete_dir_confirmed {
$directory_name);
if ($result ne 'ok') {
- $r->print(' An error occured (dir) ('.$result.
+ $r->print(' An error occurred (dir) ('.$result.
') while trying to delete '.$directory_name.' ');
} else {
# now remove from recent
-# $r->print(' removing '.$directory_name.' print(''.
- &mt('An error occured ([_1]) while trying to rename [_2]'
+ &mt('An error occurred ([_1]) while trying to rename [_2]'
.' to [_3]',$result,&display_file(),
&display_file('',$filenewname)).' ');
return;
@@ -719,13 +713,13 @@ sub access_for_renamed {
&Apache::lonnet::modify_access_controls($oldfile,\%change_old,
$udom,$uname);
if ($outcome ne 'ok') {
- $chg_text ='
'.&mt("An error occured ([_1]) while ".
+ $chg_text ='
'.&mt("An error occurred ([_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 ".
+ &mt("An error occurred ([_1]) while ".
"trying to delete access control records for the old name.",$deloutcome).
' ';
}
@@ -735,7 +729,7 @@ sub access_for_renamed {
$udom,$uname);
if ($outcome ne 'ok') {
$chg_text .= '
'.
- &mt("An error occured ([_1]) while ".
+ &mt("An error occurred ([_1]) while ".
"trying to update access control records for the new name.",$outcome).
' ';
}
@@ -762,9 +756,16 @@ sub display_access {
$info .= '
'.&mt('Public files are available to anyone without the need for login.');
$info .= '
'.&mt('Passphrase-protected files do not require log-in, but will require the viewer to enter the passphrase you set.');
$info .= '
'.&explain_conditionals();
- $info .= '
';
+ $info .= ''.
+ &mt('A listing of files viewable without log-in is available at: ')."http://$ENV{'SERVER_NAME'}/adm/$udom/$uname/aboutme/portfolio. ";
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 "));
+ $info .= &mt("For logged in users a 'Display file listing' link will also appear (when there are viewable files) on your personal information page:");
+ } else {
+ $info .= &mt("For logged in users a 'Display file listing' link will also appear (when there are viewable files) on the course information page:");
+ }
+ $info .= " http://$ENV{'SERVER_NAME'}/adm/$udom/$uname/aboutme ";
+ if ($group ne '') {
+ $info .= &mt("Users with privileges to edit course contents may add a course information page to a course using the 'Course Info' button in DOCS").' ';
}
} else {
$header = '
'.&mt('Conditional access controls for file: [_1]',$port_path.$env{'form.currentpath'}.$env{'form.access'}).'
- Check as many as you wish in response to the problem. ");
+ $r->print("
".&mt('Select portfolio files')."
".
+ &mt('Check as many as you wish in response to the problem.')." ");
my @otherfiles=&Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
if (@otherfiles) {
- $r->print("Files selected from other directories: ");
+ $r->print("".&mt('Files selected from other directories:')." ");
foreach my $file (@otherfiles) {
$r->print($file." ");
}
}
}
-sub upload {
- my ($r,$url,$group)=@_;
- my $fname=$env{'form.uploaddoc.filename'};
- my $filesize = (length($env{'form.uploaddoc'})) / 1000; #express in k (1024?)
- my $disk_quota;
- if (defined($group)) {
- my $grp_quota = &get_group_quota($group); # quota expressed in k
- if ($grp_quota ne '') {
- $disk_quota = $grp_quota;
- } else {
- $disk_quota = 0;
- }
- } else {
- $disk_quota = &Apache::loncommon::get_user_quota($env{'user.name'},
- $env{'user.domain'}); #expressed in Mb
- $disk_quota = 1000 * $disk_quota; # convert from Mb to kb
- }
- $fname=&Apache::lonnet::clean_filename($fname);
- my $portfolio_root=&get_portfolio_root();
- my ($uname,$udom) = &get_name_dom();
+sub check_for_upload {
+ my ($path,$fname,$group,$element) = @_;
+ my $disk_quota = &get_quota($group);
+ my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
+
+ my $portfolio_root = &get_portfolio_root();
my $port_path = &get_port_path();
+ my ($uname,$udom) = &get_name_dom();
# Fixme --- Move the checking for existing file to LOND error return
- my @dir_list=&get_dir_list($portfolio_root);
+ my @dir_list=&get_dir_list($portfolio_root,$path);
my $found_file = 0;
my $locked_file = 0;
foreach my $line (@dir_list) {
my ($file_name)=split(/\&/,$line,2);
if ($file_name eq $fname){
- $file_name = $env{'form.currentpath'}.$file_name;
+ $file_name = $path.$file_name;
$file_name = &prepend_group($file_name);
$found_file = 1;
if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
@@ -1782,34 +1771,125 @@ sub upload {
}
}
my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$portfolio_root);
+
if (($current_disk_usage + $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',$url));
- }
- elsif ($found_file){
- if ($locked_file){
- $r->print(''.'Unable to upload '.$fname.', a locked file by that name was found in '.$port_path.$env{'form.currentpath'}.''.
- ' You will be able to rename or delete existing '.$fname.' after a grade has been assigned.');
- $r->print(&done('Back',$url));
- } else {
- $r->print(''.'Unable to upload '.$fname.', a file by that name was found in '.$port_path.$env{'form.currentpath'}.''.
- ' To upload, rename or delete existing '.$fname.' in '.$port_path.$env{'form.currentpath'});
- $r->print(&done('Back',$url));
- }
- } else {
- my $result=&Apache::lonnet::userfileupload('uploaddoc','',
- $port_path.$env{'form.currentpath'});
- if ($result !~ m|^/uploaded/|) {
- $r->print(''.'An errror occured ('.$result.
- ') while trying to upload '.&display_file().' ');
- $r->print(&done('Back',$url));
- } else {
- $r->print(&done(undef,$url));
- }
+ my $msg = ''.
+ &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.',''.$fname.'',$filesize).''.
+ ' '.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
+ return ('will_exceed_quota',$msg);
+ } elsif ($found_file) {
+ if ($locked_file) {
+ my $msg = '';
+ $msg .= &mt('Unable to upload [_1] a locked file by that name was found in [_2].',''.$fname.'',''.$port_path.$env{'form.currentpath'}.'');
+ $msg .= ' ';
+ $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.',''.$fname.'');
+ return ('file_locked',$msg);
+ } else {
+ my $msg = '';
+ $msg .= &mt('Unable to upload [_1]. A file by that name was found in [_2].',''.$fname.'',$port_path.$env{'form.currentpath'});
+ $msg .= '';
+ $msg .= ' ';
+ $msg .= &mt('To upload, rename or delete existing [_1] in [_2].',''.$fname.'', $port_path.$env{'form.currentpath'});
+ return ('file_exists',$msg);
+ }
}
}
+sub upload {
+ my ($r,$url,$group)=@_;
+ my $fname=&Apache::lonnet::clean_filename($env{'form.uploaddoc.filename'});
+
+ my ($state,$msg) = &check_for_upload($env{'form.currentpath'},
+ $fname,$group,'uploaddoc');
+
+ if ($state eq 'will_exceed_quota'
+ || $state eq 'file_locked'
+ || $state eq 'file_exists' ) {
+ $r->print($msg.&done('Back',$url));
+ return;
+ }
+
+ my $port_path = &get_port_path();
+ my (%allfiles,%codebase,$mode);
+ if ($env{'form.uploaddoc.filename'} =~ m/(\.htm|\.html|\.shtml)$/i) {
+ $mode = 'parse';
+
+ }
+ my $result=
+ &Apache::lonnet::userfileupload('uploaddoc','',
+ $port_path.$env{'form.currentpath'},
+ $mode,\%allfiles,\%codebase);
+ if ($result !~ m|^/uploaded/|) {
+ $r->print(''.'An error occurred ('.$result.
+ ') while trying to upload '.&display_file().' ');
+ $r->print(&done('Back',$url));
+ } else {
+ if (%allfiles) {
+ my $state = <
+
+
+
+STATE
+ $r->print("
".&mt("Reference Warning")."
");
+ $r->print("
".&mt("Completed upload of the file. This file contained references to other files. You must upload the referenced files or else the uploaded file may not work properly.")."
");
+ $r->print("
".&mt("Please select the locations from which the referenced files are to be uploaded.")."
');
+ }
+ }
+ $r->print(&done(undef,$url));
+}
+
sub lock_info {
my ($r,$url,$group) = @_;
my ($uname,$udom) = &get_name_dom();
@@ -1850,7 +1930,7 @@ sub lock_info {
}
}
}
- $r->print(&done('Back',$url));
+ $r->print(&done(&mt('Back'),$url));
return 'ok';
}
@@ -1874,20 +1954,20 @@ sub createdir {
}
}
if ($found_file){
- $r->print(''.'Unable to create a directory named '.$newdir.
- ' a file or directory by that name already exists. ');
+ $r->print(''.&mt('Unable to create a directory named').' '.$newdir.
+ ' '.&mt('a file or directory by that name already exists.').' ');
} else {
my ($uname,$udom) = &get_name_dom();
my $port_path = &get_port_path();
my $result=&Apache::lonnet::mkdiruserfile($uname,$udom,
$port_path.$env{'form.currentpath'}.$newdir);
if ($result ne 'ok') {
- $r->print(''.'An errror occured ('.$result.
+ $r->print(''.'An error occurred ('.$result.
') 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(&mt("The new directory name was changed from: ").$env{'form.newdir'}." ".&mt('to')." $newdir ");
}
$r->print(&done(undef,$url));
}
@@ -1927,10 +2007,10 @@ sub get_group_quota {
}
sub get_dir_list {
- my ($portfolio_root) = @_;
+ my ($portfolio_root,$path) = @_;
+ $path ||= $env{'form.currentpath'};
my ($uname,$udom) = &get_name_dom();
- return &Apache::lonnet::dirlist($env{'form.currentpath'},
- $udom,$uname,$portfolio_root);
+ return &Apache::lonnet::dirlist($path,$udom,$uname,$portfolio_root);
}
sub get_name_dom {
@@ -2026,6 +2106,23 @@ sub coursegrp_portfolio_header {
return $output;
}
+sub get_quota {
+ my ($group) = @_;
+ my $disk_quota;
+ if (defined($group)) {
+ my $grp_quota = &get_group_quota($group); # quota expressed in k
+ if ($grp_quota ne '') {
+ $disk_quota = $grp_quota;
+ } else {
+ $disk_quota = 0;
+ }
+ } else {
+ $disk_quota = &Apache::loncommon::get_user_quota($env{'user.name'},
+ $env{'user.domain'}); #expressed in Mb
+ $disk_quota = 1000 * $disk_quota; # convert from Mb to kb
+ }
+ return $disk_quota;
+}
sub handler {
# this handles file management
@@ -2065,16 +2162,16 @@ sub handler {
$env{'request.course.id'}.'/'.$group))) {
$portfolio_root = &get_portfolio_root();
} else {
- $r->print('You do not have the privileges required to access the shared files space for this group.');
+ $r->print(&mt('You do not have the privileges required to access the shared files space for this group.'));
$earlyout = 1;
}
} else {
- $r->print('Not a valid group for this course');
+ $r->print(&mt('Not a valid group for this course'));
$earlyout = 1;
}
$title = &mt('Group files').' for '.$group;
} else {
- $r->print('Invalid group');
+ $r->print(&mt('Invalid group'));
$earlyout = 1;
}
if ($earlyout) { return OK; }
@@ -2122,17 +2219,22 @@ sub handler {
$r->print(&Apache::loncommon::start_page($title));
}
$r->rflush();
+ my ($blocked,$blocktext) =
+ &Apache::loncommon::blocking_status('port',$uname,$udom);
+ if ($blocked) {
+ $r->print($blocktext);
+ $r->print(&Apache::loncommon::end_page());
+ return OK;
+ }
if (($env{'form.storeupl'}) & (!$env{'form.uploaddoc.filename'})){
- $r->print(''.
- 'No file was selected to upload.'.
- 'To upload a file, click Browse...'.
- ', select a file, then click Upload.'.
- '');
+ $r->print('');
+ $r->print(&mt('No file was selected to upload. '));
+ $r->print(&mt('To upload a file, click Browse... select a file, then click Upload.'));
+ $r->print('');
}
if ($env{'form.meta'}) {
&open_form($r,$url);
-# $r->print(&edit_meta_data($r, $env{'form.currentpath'}.$env{'form.selectfile'}));
- $r->print('Edit the meta data ');
+ $r->print(&mt('Edit the meta data').' ');
&close_form($r,$url);
}
if ($env{'form.store'}) {
@@ -2144,6 +2246,12 @@ sub handler {
} else {
&missing_priv($r,$url,'upload');
}
+ } elsif ($env{'form.action'} eq 'upload_embedded') {
+ if ($can_upload) {
+ &upload_embedded($r,$url,$group);
+ } else {
+ &missing_priv($r,$url,'upload');
+ }
} elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {
if ($can_delete) {
&delete_confirmed($r,$url,$group);