--- loncom/interface/portfolio.pm 2006/11/05 21:08:53 1.170
+++ loncom/interface/portfolio.pm 2016/08/07 23:14:30 1.254.2.1
@@ -1,7 +1,7 @@
# The LearningOnline Network
# portfolio browser
#
-# $Id: portfolio.pm,v 1.170 2006/11/05 21:08:53 raeburn Exp $
+# $Id: portfolio.pm,v 1.254.2.1 2016/08/07 23:14:30 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -38,7 +38,7 @@ use Apache::lonnet;
use Apache::longroup;
use Apache::lonhtmlcommon;
use HTML::Entities;
-use LONCAPA;
+use LONCAPA qw(:DEFAULT :match);
sub group_args {
my $output;
@@ -63,7 +63,7 @@ sub group_form_data {
return $output;
}
-# receives a file name and path stub from username/userfiles/portfolio/
+# receives a filename and path stub from username/userfiles/portfolio/
# returns an anchor tag consisting encoding filename and currentpath
sub make_anchor {
my ($url, $anchor_fields, $inner_text) = @_;
@@ -80,81 +80,96 @@ sub make_anchor {
my $dirptr=16384;
sub display_common {
- my ($r,$url,$current_path,$is_empty,$dir_list,$can_upload)=@_;
+ my ($r,$url,$current_path,$is_empty,$dir_list,$can_upload,$group)=@_;
my $namespace = &get_namespace();
my $port_path = &get_port_path();
if ($can_upload) {
my $groupitem = &group_form_data();
my $iconpath= $r->dir_config('lonIconsURL') . "/";
- my %text=&Apache::lonlocal::texthash(
- 'upload' => 'Upload',
- 'upload_label' =>
- 'Upload file to current directory:',
- 'createdir' => 'Create Subdirectory',
- 'createdir_label' =>
- 'Create subdirectory in current directory:');
+ my %lt=&Apache::lonlocal::texthash(
+ 'upload' => 'Upload',
+ 'upload_label' => 'Upload file to current directory',
+ 'createdir' => 'Create Subdirectory',
+ 'createdir_label' => 'Create subdirectory in current directory',
+ 'parse' => 'Upload embedded images/multimedia/css/linked files if HTML file',
+ );
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'));
+ my $help_portfolio = &Apache::loncommon::help_open_topic('Portfolio About', &mt('Help on the portfolio'));
+ $r->print(&display_portfolio_usage($group,$help_portfolio));
+ my $parse_check;
+ if (!&suppress_embed_prompt()) {
+ $parse_check = <<"END";
+
+
+
+
+END
+ }
+
+ # Upload File
+ $r->print('
- $text{'upload_label'} - | -- - | -
- $text{'createdir_label'} - | -- - | -
' + .&mt('The file is locked and cannot be deleted.') + .'
' + .&done(undef,$url) + ); } else { if (scalar(@files)) { &open_form($r,$url); - $r->print(''.&mt('Delete').' '.&display_file(undef,\@files).'?
'); + $r->print(''.&mt('Delete [_1]?',&display_file(undef,\@files)).'
'); &close_form($r,$url); } else { - $r->print("No file was checked to delete.'.&mt('No file was checked to delete.').'
'); $r->print(&done(undef,$url)); } } @@ -556,22 +659,25 @@ sub delete_confirmed { my ($r,$url,$group)=@_; my @files=&Apache::loncommon::get_env_multiple('form.selectfile'); my $result; - my ($uname,$udom) = &get_name_dom(); + my ($uname,$udom) = &get_name_dom($group); my $port_path = &get_port_path(); my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom, $uname); + my @msg; foreach my $delete_file (@files) { - $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path. - $env{'form.currentpath'}. - $delete_file); + $result = + &Apache::lonnet::removeuserfile( + $uname,$udom,$port_path. + $env{'form.currentpath'}. + $delete_file); if ($result ne 'ok') { - $r->print(''. - &mt('An error occured ([_1]) while trying to delete - [_2].',$result,&display_file(undef, $delete_file)). - ''.&mt('Delete').' '.&display_file().'?
'); + $r->print(''.&mt('Delete [_1]?',&display_file()).'
'); &close_form($r,$url); } sub delete_dir_confirmed { - my ($r,$url)=@_; + my ($r,$url,$group)=@_; my $directory_name = $env{'form.currentpath'}; $directory_name =~ s|/$||; # remove any trailing slash - my ($uname,$udom) = &get_name_dom(); + my ($uname,$udom) = &get_name_dom($group); my $namespace = &get_namespace(); my $port_path = &get_port_path(); my $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path. $directory_name); - + if ($result ne 'ok') { - $r->print(' An error occured (dir) ('.$result. - ') while trying to delete '.$directory_name.'' + .&mt('The file is locked and cannot be renamed.') + .'
' + ); $r->print(&done(undef,$url)); } else { &open_form($r,$url); - $r->print(''.&mt('Rename').' '.&display_file().' to - ?
'); + $r->print(''.&mt('Rename [_1] to [_2]?', &display_file() + , '').'
'); &close_form($r,$url); } } @@ -662,15 +779,34 @@ sub rename { sub rename_confirmed { my ($r,$url,$group)=@_; my $filenewname=&Apache::lonnet::clean_filename($env{'form.filenewname'}); - my ($uname,$udom) = &get_name_dom(); + my ($uname,$udom) = &get_name_dom($group); my $port_path = &get_port_path(); + + # Display warning in case of filename cleaning has changed the filename + if ($filenewname ne $env{'form.filenewname'}) { + $r->print( + ''
+ .&mt('Invalid characters')
+ .'
'
+ .&mt('The new filename was changed from [_1] to [_2].'
+ ,''.&display_file('',$env{'form.filenewname'}).''
+ ,''.&display_file('',$filenewname).'')
+ .'
'.&mt('Roles').' | '. &mt('Access').' | '. &mt('Sections').' | '); @@ -883,8 +1042,6 @@ sub build_access_summary { foreach my $item ('role','access','section','group') { $r->print('');
if ($item eq 'role') {
- my $ucscope = $scope;
- $ucscope =~ s/^(\w)/uc($1)/e;
my $role_output;
foreach my $role (@{$content->{'roles'}{$id}{$item}}) {
if ($role eq 'all') {
@@ -892,7 +1049,7 @@ sub build_access_summary {
} elsif ($role =~ /^cr/) {
$role_output .= (split('/',$role))[3].',';
} else {
- $role_output .= &Apache::lonnet::plaintext($role,$ucscope).',';
+ $role_output .= &Apache::lonnet::plaintext($role,$crstype).',';
}
}
$role_output =~ s/,$//;
@@ -910,6 +1067,9 @@ sub build_access_summary {
} elsif ($scope eq 'users') {
my $curr_user_list = &sort_users($content->{'users'});
$r->print(&mt('Users: ').$curr_user_list);
+ } elsif ($scope eq 'ip') {
+ my $curr_ips_list = &sort_ips($content->{'ip'});
+ $r->print(&mt('IP(s): ').$curr_ips_list);
} else {
$r->print(' ');
}
@@ -950,10 +1110,10 @@ sub update_access {
}
}
my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
- $r->print(''.&mt('Allowing others to retrieve file: [_1]', - $port_path.$file_name).''."\n"); + $r->print(''.&mt('Allowing others to retrieve file: [_1]', + ''.$port_path.$file_name.'').''."\n"); $file_name = &prepend_group($file_name); - my ($uname,$udom) = &get_name_dom(); + my ($uname,$udom) = &get_name_dom($group); my ($errors,$outcome,$deloutcome,$new_values,$translation); if ($totalprocessed) { ($outcome,$deloutcome,$new_values,$translation) = @@ -1006,7 +1166,7 @@ sub update_access { } else { if ((@{$processing{'activate'}} > 0) || (@{$processing{'update'}} > 0)) { $errors .= ''. - &mt('A problem occurred storing access control settings: [_1]',$outcome). + &mt('A problem occurred saving access control settings: [_1]',$outcome). ''; } } @@ -1018,26 +1178,38 @@ sub update_access { my $totalnew = 0; my $status = 'new'; my ($firstitem,$lastitem); - foreach my $newitem ('course','domains','users') { + my @types = ('course','domains','users','ip'); + foreach my $newitem (@types) { $allnew += $env{'form.new'.$newitem}; } if ($allnew > 0) { my $now = time; my $then = $now + (60*60*24*180); # six months approx. &open_form($r,$url); - foreach my $newitem ('course','domains','users') { - if ($env{'form.new'.$newitem} > 0) { - $r->print(''.&mt('Add new [_1]-based access control for portfolio file: [_2]',$newitem,$env{'form.currentpath'}.$env{'form.selectfile'}).' '); - $firstitem = $totalnew; - $lastitem = $totalnew + $env{'form.new'.$newitem}; - $totalnew = $lastitem; - my @numbers; - for (my $i=$firstitem; $i<$lastitem; $i++) { - push (@numbers,$i); - } - &display_access_row($r,$status,$newitem,\@numbers, - $access_controls{$file_name},$now,$then); + my %showtypes = ( + course => 'course/community', + domains => 'domain', + users => 'user', + ip => 'IP', + ); + foreach my $newitem (@types) { + next if ($env{'form.new'.$newitem} <= 0); + $r->print( + ' ' + .&mt('Add new [_1]'.$showtypes{$newitem}.'-based[_2] access control for portfolio file: [_3]', + '','', + '' + .$env{'form.currentpath'}.$env{'form.selectfile'}.'') + .' '); + $firstitem = $totalnew; + $lastitem = $totalnew + $env{'form.new'.$newitem}; + $totalnew = $lastitem; + my @numbers; + for (my $i=$firstitem; $i<$lastitem; $i++) { + push(@numbers,$i); } + &display_access_row($r,$status,$newitem,\@numbers, + $access_controls{$file_name},$now,$then); } &close_form($r,$url); } else { @@ -1045,9 +1217,11 @@ sub update_access { 'currentpath' => $env{'form.currentpath'}, 'access' => $env{'form.selectfile'} ); - $r->print(''.&make_anchor($url, \%anchor_fields, &mt('Display all access settings for this file'))); + my @actions; + push(@actions, &make_anchor($url, \%anchor_fields, &mt('Display all access settings for this file'))); delete $anchor_fields{'access'}; - $r->print(' '.&make_anchor($url,\%anchor_fields,&mt('Return to directory listing'))); + push(@actions, &make_anchor($url,\%anchor_fields,&mt('Return to directory'))); + $r->print(' '.&Apache::lonhtmlcommon::actionbox(\@actions)); } return; } @@ -1120,6 +1294,13 @@ sub build_access_record { 'udom' => $udom }); } + } elsif ($scope eq 'ip') { + my $ipslist = $env{'form.ips_'.$num}; + $ipslist =~ s/\s+//sg; + my %ipshash = map { ($_,1) } (split(/,/,$ipslist)); + foreach my $ip (keys(%ipshash)) { + push(@{$record->{'ip'}},$ip); + } } return $record; } @@ -1145,6 +1326,13 @@ sub sort_users { return $curr_user_list; } +sub sort_ips { + my ($ips) = @_; + if (ref($ips) eq 'ARRAY') { + return join(",\n",sort(@{$ips})); + } +} + sub access_setting_table { my ($r,$url,$filename,$access_controls,$action) = @_; my ($public,$publictext); @@ -1154,6 +1342,7 @@ sub access_setting_table { my @courses = (); my @domains = (); my @users = (); + my @ips = (); my $now = time; my $then = $now + (60*60*24*180); # six months approx. my ($num,$scope,$publicnum,$guestnum); @@ -1176,6 +1365,8 @@ sub access_setting_table { push(@domains,$key); } elsif ($scope eq 'users') { push(@users,$key); + } elsif ($scope eq 'ip') { + push(@ips,$key); } } $acl_count{$scope} ++; @@ -1187,7 +1378,7 @@ sub access_setting_table { $guesttext,$access_controls,%conditionals); } else { &condition_setting($r,$access_controls,$now,$then,\%acl_count, - \@domains,\@users,\@courses); + \@domains,\@users,\@courses,\@ips); } $r->print(' |
---|
' + .&mt('No '.$infotype.'-based conditions defined') + .'
' + .&additional_item($type) + ); } return; } @@ -1371,34 +1574,38 @@ sub display_access_row { sub course_js { return qq| |; } @@ -1421,55 +1629,78 @@ sub course_row { } my $js = &Apache::loncommon::coursebrowser_javascript($defdom) .&course_js(); - my $uctype = $type; - $uctype =~ s/^(\w)/uc($1)/e; + my $showtype = &mt('Course/Community'); + my $crstype = 'Course'; my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then, $type); $r->print(''.&mt('Action').' | '.&mt('Roles').' | '. - &mt('Access').' | '.&mt('Sections').' | '. - &mt('Groups').' | '.&dateboxes($num,$start,$end)); + my $newrole_id = 1; if ($status eq 'old') { + $r->print(' | '); my $max_id = 0; - foreach my $role_id (sort(keys(%{$content->{'roles'}}))) { - if ($role_id > $max_id) { - $max_id = $role_id; - } - $max_id ++; - my $role_selects = &role_selectors($num,$role_id,$status,$type,$content,'display'); - $r->print(' |
---|---|---|---|---|
'.&mt('Action').' | '. + ''.&mt('Roles').' | '. + ''.&mt('Access').' | '. + ''.&mt('Sections').' | '. + ''.&mt('Groups').' |
---|---|---|---|---|