';
if ($numremref) {
$output .= '- '.&mt('reference is to a URL which points to another server').'
'."\n";
@@ -8685,7 +8851,7 @@ sub ask_for_embedded_content {
$embed_file,\%mapping,
$allfiles,$codebase);
} else {
- $pathchange_output .=
+ $pathchange_output .=
&start_data_table_row().
' | '.
@@ -8704,7 +8870,7 @@ sub ask_for_embedded_content {
$output .= ''."\n";
}
- if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
+ if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
($actionurl eq '/adm/imsimport')) {
$output .= ''."\n";
} elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
@@ -8716,8 +8882,8 @@ sub ask_for_embedded_content {
my %pathchange = ();
$output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
- $output .= ''.&mt('or').'
';
- }
+ $output .= ''.&mt('or').'
';
+ }
}
return ($output,$num,$numpathchg);
}
@@ -8732,7 +8898,7 @@ sub embedded_file_element {
}
$output .= '';
- unless (($context eq 'upload_embedded') &&
+ unless (($context eq 'upload_embedded') &&
($mapping->{$embed_file} eq $embed_file)) {
$output .='
';
@@ -8833,7 +8999,7 @@ sub upload_embedded {
next;
} else {
$output .= &mt('Uploaded [_1]',''.
- $path.$fname.'').'
';
+ $path.$fname.'').'
';
}
}
} elsif ($context eq 'coursedoc') {
@@ -8856,12 +9022,12 @@ sub upload_embedded {
my $fullpath = $dir_root.$dirpath.'/'.$path;
my $dest = $fullpath.$fname;
my $url = $url_root.$dirpath.'/'.$path.$fname;
- my @parts=split(/\//,$fullpath);
+ my @parts=split(/\//,"$dirpath/$path");
my $count;
my $filepath = $dir_root;
- for ($count=4;$count<=$#parts;$count++) {
- $filepath .= "/$parts[$count]";
- if ((-e $filepath)!=1) {
+ foreach my $subdir (@parts) {
+ $filepath .= "/$subdir";
+ if (!-e $filepath) {
mkdir($filepath,0770);
}
}
@@ -8940,7 +9106,7 @@ sub modify_html_form {
''.
&end_data_table_row();
- }
+ }
}
} else {
$modifyform = $pathchgtable;
@@ -8980,8 +9146,7 @@ sub modify_html_refs {
} elsif ($context eq 'coursedoc') {
$container = $env{'form.primaryurl'};
} else {
- $container = $env{'form.filename'};
- $container =~ s{^/priv/(\Q$uname\E)/(.*)}{/home/$1/public_html/$2};
+ $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
}
my (%allfiles,%codebase,$output,$content);
my @changes = &get_env_multiple('form.namechange');
@@ -8991,7 +9156,7 @@ sub modify_html_refs {
$content = &Apache::lonnet::getfile($container);
return if ($content eq '-1');
} else {
- return unless ($container =~ /^\Q$dir_root\E/);
+ return unless ($container =~ /^\Q$dir_root\E/);
if (open(my $fh,"<$container")) {
$content = join('', <$fh>);
close($fh);
@@ -9003,7 +9168,7 @@ sub modify_html_refs {
my $mm = new File::MMagic;
my $mime_type = $mm->checktype_contents($content);
if ($mime_type eq 'text/html') {
- my $parse_result =
+ my $parse_result =
&Apache::lonnet::extract_embedded_items($container,\%allfiles,
\%codebase,\$content);
if ($parse_result eq 'ok') {
@@ -9013,7 +9178,7 @@ sub modify_html_refs {
if ($allfiles{$ref}) {
my $newname = $orig;
my ($attrib_regexp,$codebase);
- my $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
+ $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
if ($attrib_regexp =~ /:/) {
$attrib_regexp =~ s/\:/|/g;
}
@@ -9022,7 +9187,7 @@ sub modify_html_refs {
$count += $numchg;
}
if ($env{'form.embedded_codebase_'.$i} ne '') {
- my $codebase = &unescape($env{'form.embedded_codebase_'.$i});
+ $codebase = &unescape($env{'form.embedded_codebase_'.$i});
my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
$codebasecount ++;
}
@@ -9036,7 +9201,7 @@ sub modify_html_refs {
my ($fname) = ($container =~ m{/([^/]+)$});
$output = ''.&mt('Updated [quant,_1,reference] in [_2].',
$count,''.
- $fname.'').'
';
+ $fname.'').'';
} else {
$output = ''.
&mt('Error: update failed for: [_1].',
@@ -9088,17 +9253,17 @@ sub check_for_upload {
my $filesize = length($env{'form.'.$element});
if (!$filesize) {
my $msg = ''.
- &mt('Unable to upload [_1]. (size = [_2] bytes)',
+ &mt('Unable to upload [_1]. (size = [_2] bytes)',
''.$fname.'',
$filesize).'
'.
- &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'
';
+ &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'
'.
'';
return ('zero_bytes',$msg);
}
$filesize = $filesize/1000; #express in k (1024?)
my $getpropath = 1;
- my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
- $getpropath);
+ my ($dirlistref,$listerror) =
+ &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
my $found_file = 0;
my $locked_file = 0;
my @lockers;
@@ -9106,48 +9271,50 @@ sub check_for_upload {
if ($env{'request.course.id'}) {
$navmap = Apache::lonnavmaps::navmap->new();
}
- foreach my $line (@dir_list) {
- my ($file_name,$rest)=split(/\&/,$line,2);
- if ($file_name eq $fname){
- $file_name = $path.$file_name;
- if ($group ne '') {
- $file_name = $group.$file_name;
- }
- $found_file = 1;
- if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
- foreach my $lock (@lockers) {
- if (ref($lock) eq 'ARRAY') {
- my ($symb,$crsid) = @{$lock};
- if ($crsid eq $env{'request.course.id'}) {
- if (ref($navmap)) {
- my $res = $navmap->getBySymb($symb);
- foreach my $part (@{$res->parts()}) {
- my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
- unless (($slot_status == $res->RESERVED) ||
- ($slot_status == $res->RESERVED_LOCATION)) {
- $locked_file = 1;
+ if (ref($dirlistref) eq 'ARRAY') {
+ foreach my $line (@{$dirlistref}) {
+ my ($file_name,$rest)=split(/\&/,$line,2);
+ if ($file_name eq $fname){
+ $file_name = $path.$file_name;
+ if ($group ne '') {
+ $file_name = $group.$file_name;
+ }
+ $found_file = 1;
+ if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
+ foreach my $lock (@lockers) {
+ if (ref($lock) eq 'ARRAY') {
+ my ($symb,$crsid) = @{$lock};
+ if ($crsid eq $env{'request.course.id'}) {
+ if (ref($navmap)) {
+ my $res = $navmap->getBySymb($symb);
+ foreach my $part (@{$res->parts()}) {
+ my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
+ unless (($slot_status == $res->RESERVED) ||
+ ($slot_status == $res->RESERVED_LOCATION)) {
+ $locked_file = 1;
+ }
}
+ } else {
+ $locked_file = 1;
}
} else {
$locked_file = 1;
}
- } else {
- $locked_file = 1;
}
- }
- }
- } else {
- my @info = split(/\&/,$rest);
- my $currsize = $info[6]/1000;
- if ($currsize < $filesize) {
- my $extra = $filesize - $currsize;
- if (($current_disk_usage + $extra) > $disk_quota) {
- my $msg = ''.
- &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded if existing (smaller) file with same name (size = [_3] kilobytes) is replaced.',
- ''.$fname.'',$filesize,$currsize).''.
- '
'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
- $disk_quota,$current_disk_usage);
- return ('will_exceed_quota',$msg);
+ }
+ } else {
+ my @info = split(/\&/,$rest);
+ my $currsize = $info[6]/1000;
+ if ($currsize < $filesize) {
+ my $extra = $filesize - $currsize;
+ if (($current_disk_usage + $extra) > $disk_quota) {
+ my $msg = ''.
+ &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded if existing (smaller) file with same name (size = [_3] kilobytes) is replaced.',
+ ''.$fname.'',$filesize,$currsize).''.
+ '
'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
+ $disk_quota,$current_disk_usage);
+ return ('will_exceed_quota',$msg);
+ }
}
}
}
@@ -9219,6 +9386,113 @@ sub check_for_traversal {
=pod
+=item * &get_turnedin_filepath()
+
+Determines path in a user's portfolio file for storage of files uploaded
+to a specific essayresponse or dropbox item.
+
+Inputs: 3 required + 1 optional.
+$symb is symb for resource, $uname and $udom are for current user (required).
+$caller is optional (can be "submission", if routine is called when storing
+an upoaded file when "Submit Answer" button was pressed).
+
+Returns array containing $path and $multiresp.
+$path is path in portfolio. $multiresp is 1 if this resource contains more
+than one file upload item. Callers of routine should append partid as a
+subdirectory to $path in cases where $multiresp is 1.
+
+Called by: homework/essayresponse.pm and homework/structuretags.pm
+
+=cut
+
+sub get_turnedin_filepath {
+ my ($symb,$uname,$udom,$caller) = @_;
+ my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
+ my $turnindir;
+ my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
+ $turnindir = $userhash{'turnindir'};
+ my ($path,$multiresp);
+ if ($turnindir eq '') {
+ if ($caller eq 'submission') {
+ $turnindir = &mt('turned in');
+ $turnindir =~ s/\W+/_/g;
+ my %newhash = (
+ 'turnindir' => $turnindir,
+ );
+ &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
+ }
+ }
+ if ($turnindir ne '') {
+ $path = '/'.$turnindir.'/';
+ my ($multipart,$turnin,@pathitems);
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ if (defined($navmap)) {
+ my $mapres = $navmap->getResourceByUrl($map);
+ if (ref($mapres)) {
+ my $pcslist = $mapres->map_hierarchy();
+ if ($pcslist ne '') {
+ foreach my $pc (split(/,/,$pcslist)) {
+ my $res = $navmap->getByMapPc($pc);
+ if (ref($res)) {
+ my $title = $res->compTitle();
+ $title =~ s/\W+/_/g;
+ if ($title ne '') {
+ push(@pathitems,$title);
+ }
+ }
+ }
+ }
+ my $maptitle = $mapres->compTitle();
+ $maptitle =~ s/\W+/_/g;
+ if ($maptitle ne '') {
+ push(@pathitems,$maptitle);
+ }
+ unless ($env{'request.state'} eq 'construct') {
+ my $res = $navmap->getBySymb($symb);
+ if (ref($res)) {
+ my $partlist = $res->parts();
+ my $totaluploads = 0;
+ if (ref($partlist) eq 'ARRAY') {
+ foreach my $part (@{$partlist}) {
+ my @types = $res->responseType($part);
+ my @ids = $res->responseIds($part);
+ for (my $i=0; $i < scalar(@ids); $i++) {
+ if ($types[$i] eq 'essay') {
+ my $partid = $part.'_'.$ids[$i];
+ if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
+ $totaluploads ++;
+ }
+ }
+ }
+ }
+ if ($totaluploads > 1) {
+ $multiresp = 1;
+ }
+ }
+ }
+ }
+ } else {
+ return;
+ }
+ } else {
+ return;
+ }
+ my $restitle=&Apache::lonnet::gettitle($symb);
+ $restitle =~ s/\W+/_/g;
+ if ($restitle eq '') {
+ $restitle = ($resurl =~ m{/[^/]+$});
+ if ($restitle eq '') {
+ $restitle = time;
+ }
+ }
+ push(@pathitems,$restitle);
+ $path .= join('/',@pathitems);
+ }
+ return ($path,$multiresp);
+}
+
+=pod
+
=back
=head1 CSV Upload/Handling functions
@@ -11138,6 +11412,8 @@ sub construct_course {
############################################################
############################################################
+#SD
+# only Community and Course, or anything else?
sub course_type {
my ($cid) = @_;
if (!defined($cid)) {
@@ -11303,15 +11579,12 @@ sub init_user_environment {
my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
my ($tmp) = keys(%userenv);
if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
- # default remote control to off
- if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
} else {
undef(%userenv);
}
if (($userenv{'interface'}) && (!$form->{'interface'})) {
$form->{'interface'}=$userenv{'interface'};
}
- $env{'environment.remote'}=$userenv{'remote'};
if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
# --------------- Do not trust query string to be put directly into environment
@@ -11343,16 +11616,17 @@ sub init_user_environment {
$initial_env{"browser.localres"} = $form->{'localres'};
}
- if ($public) {
- $initial_env{"environment.remote"} = "off";
- }
if ($form->{'interface'}) {
$form->{'interface'}=~s/\W//gs;
$initial_env{"browser.interface"} = $form->{'interface'};
$env{'browser.interface'}=$form->{'interface'};
}
+
my %is_adv = ( is_adv => $env{'user.adv'} );
- my %domdef = &Apache::lonnet::get_domain_defaults($domain);
+ my %domdef;
+ unless ($domain eq 'public') {
+ %domdef = &Apache::lonnet::get_domain_defaults($domain);
+ }
foreach my $tool ('aboutme','blog','portfolio') {
$userenv{'availabletools.'.$tool} =