--- loncom/interface/loncommon.pm 2012/01/16 18:00:24 1.1053
+++ loncom/interface/loncommon.pm 2012/01/31 23:47:15 1.1055
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.1053 2012/01/16 18:00:24 raeburn Exp $
+# $Id: loncommon.pm,v 1.1055 2012/01/31 23:47:15 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -9735,6 +9735,9 @@ sub decompress_form {
}
$output .= '
';
$output .= <<"START";
+
+$lt{'this'} $lt{'youm'}
+
';
+}
+
+sub archive_javascript {
+ my ($startcount,$numitems,%children) = @_;
+ my $scripttag = <
+// 0) {
+ var startelement = $startcount + (count-1) * 5;
+ for (var j=1; j<4; j++) {
+ var item = startelement + j;
+ if (form.elements[item].type == 'radio') {
+ if (form.elements[item].checked) {
+ containerCheck(form,count,j);
+ break;
+ }
+ }
+ }
+ }
+}
+
+numitems = $numitems
+var parents = new Array(numitems)
+for (var i=0; i $b } (keys(%children))) {
+ my @contents = split(/:/,$children{$container});
+ for (my $i=0; $i<@contents; $i ++) {
+ $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
+ }
+ }
+
+ $scripttag .= < 0) {
+ var item = $startcount + ((count-1) * 5) + offset;
+ form.elements[item].checked = true;
+ if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
+ if (parents[count].length > 0) {
+ for (var j=0; j
+
+END
+ return $scripttag;
+}
+
+sub process_extracted_files {
+ my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
+ my $numitems = $env{'form.archive_count'};
+ return unless ($numitems);
+ my @ids=&Apache::lonnet::current_machine_ids();
+ my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
+ %folders,%containers,%mapinner);
+ my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
+ if (grep(/^\Q$docuhome\E$/,@ids)) {
+ $prefix = &LONCAPA::propath($docudom,$docuname);
+ $pathtocheck = "$dir_root/$destination";
+ $dir = $dir_root;
+ $ishome = 1;
+ } else {
+ $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
+ $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
+ $dir = "$dir_root/$docudom/$docuname";
+ }
+ my $currdir = "$dir_root/$destination";
+ (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
+ if ($env{'form.folderpath'}) {
+ my @items = split('&',$env{'form.folderpath'});
+ $folders{'0'} = $items[-2];
+ $containers{'0'}='sequence';
+ } elsif ($env{'form.pagepath'}) {
+ my @items = split('&',$env{'form.pagepath'});
+ $folders{'0'} = $items[-2];
+ $containers{'0'}='page';
+ }
+ my @archdirs = &get_env_multiple('form.archive_directory');
+ if ($numitems) {
+ for (my $i=1; $i<=$numitems; $i++) {
+ my $path = $env{'form.archive_content_'.$i};
+ if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
+ my $item = $1;
+ $toplevelitems{$item} = $i;
+ if (grep(/^\Q$i\E$/,@archdirs)) {
+ $is_dir{$item} = 1;
+ }
+ }
+ }
+ }
+ my ($output,%children,%parent);
+ if (keys(%toplevelitems) > 0) {
+ my @contents = sort(keys(%toplevelitems));
+ my ($count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,
+ \%children,\%parent,\@contents);
+ }
+ my (@above,%hierarchy,%referrer,%orphaned,%todelete);
+ foreach my $depth (sort { $a <=> $b } keys(%parent)) {
+ push(@above,$parent{$depth});
+ foreach my $item (split(/:/,$children{$parent{$depth}})) {
+ $hierarchy{$item} = \@above;
+ }
+ }
+ if ($numitems) {
+ for (my $i=1; $i<=$numitems; $i++) {
+ my $path = $env{'form.archive_content_'.$i};
+ if ($path =~ /^\Q$pathtocheck\E/) {
+ if ($env{'form.archive_'.$i} eq 'discard') {
+ if ($prefix ne '' && $path ne '') {
+ if (-e $prefix.$path) {
+ $todelete{$prefix.$path} = 1;
+ }
+ }
+ } elsif ($env{'form.archive_'.$i} eq 'display') {
+ my ($title,$url,$outer);
+ ($title) = ($path =~ m{/([^/]+)$});
+ $outer = 0;
+ if (ref($hierarchy{$i}) eq 'ARRAY') {
+ if (@{$hierarchy{$i}} > 0) {
+ foreach my $item (reverse(@{$hierarchy{$i}})) {
+ if ($env{'form.archive_'.$item} eq 'display') {
+ $outer = $item;
+ last;
+ }
+ }
+ }
+ }
+ my ($errtext,$fatal) =
+ &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
+ '/'.$folders{$outer}.'.'.
+ $containers{$outer});
+ next if ($fatal);
+ if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
+ if ($context eq 'coursedocs') {
+ $mapinner{$i} = time;
+ $folders{$i} = 'default_'.$mapinner{$i};
+ $containers{$i} = 'sequence';
+ my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
+ $folders{$i}.'.'.$containers{$i};
+ my $newidx = &LONCAPA::map::getresidx();
+ $LONCAPA::map::resources[$newidx]=
+ $title.':'.$url.':false:normal:res';
+ push(@LONCAPA::map::order,$newidx);
+ my ($outtext,$errtext) =
+ &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
+ $docuname.'/'.$folders{$outer}.
+ '.'.$containers{$outer},1);
+ }
+ } else {
+ if ($context eq 'coursedocs') {
+ my $newidx=&LONCAPA::map::getresidx();
+ my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
+ $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
+ $title;
+ if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
+ mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
+ }
+ if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
+ mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
+ }
+ if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
+ system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
+ }
+ $LONCAPA::map::resources[$newidx]=
+ $title.':'.$url.':false:normal:res';
+ push(@LONCAPA::map::order, $newidx);
+ my ($outtext,$errtext)=
+ &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
+ $docuname.'/'.$folders{$outer}.
+ '.'.$containers{$outer},1);
+ }
+ }
+ } elsif ($env{'form.archive_'.$i} eq 'dependency') {
+ if (ref($hierarchy{$i}) eq 'ARRAY') {
+ foreach my $item (reverse(@{$hierarchy{$i}})) {
+ if ($env{'form.archive_'.$item} eq 'display') {
+ $referrer{$i} = $item;
+ last;
+ #FIXME identify as dependency in db file
+ #FIXME need to move item to referrer location
+ #FIXME need to setup httprefs so access allowed
+ } elsif ($env{'form.archive_'.$item} eq 'discard') {
+ $orphaned{$i} = $item;
+ last;
+ }
+ }
+ }
+ }
+ } else {
+ $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'
';
+ }
+ }
+ if (keys(%todelete)) {
+ foreach my $key (keys(%todelete)) {
+ unlink($key);
+ unless ($ishome) {
+ #FIXME Need to notify homeserver to delete files.
+ }
+ }
+ }
+ } else {
+ $warning = &mt('No items found in archive.');
+ }
+ if ($error) {
+ $output .= ''.&mt('Not extracted.').'
'.
+ $error.'
'."\n";
+ }
+ if ($warning) {
+ $output .= ''.$warning.'
'."\n";
+ }
+ return $output;
+}
+
=pod
=item * &get_turnedin_filepath()