--- loncom/interface/loncommon.pm 2012/06/01 12:02:10 1.1075.2.7 +++ loncom/interface/loncommon.pm 2012/08/03 17:35:32 1.1075.2.12 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.1075.2.7 2012/06/01 12:02:10 raeburn Exp $ +# $Id: loncommon.pm,v 1.1075.2.12 2012/08/03 17:35:32 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -4954,6 +4954,9 @@ Inputs: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value +=item * $no_inline_link, if true and in remote mode, don't show the + 'Switch To Inline Menu' link + =item * $args, optional argument valid values are no_auto_mt_title -> prevents &mt()ing the title arg inherit_jsmath -> when creating popup window in a page, @@ -4971,7 +4974,7 @@ other decorations will be returned. sub bodytag { my ($title,$function,$addentries,$bodyonly,$domain,$forcereg, - $no_nav_bar,$bgcolor,$args)=@_; + $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_; my $public; if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) @@ -5013,6 +5016,8 @@ sub bodytag { } if (!$realm) { $realm=' '; } +# Set messages + my $messages=&domainlogo($domain); my $extra_body_attr = &make_attr_string($forcereg,\%design); @@ -5047,6 +5052,7 @@ sub bodytag { $role = '('.$role.')' if $role; &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']); + unless ($env{'environment.remote'} eq 'on') { if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') { return $bodytag; } @@ -5103,6 +5109,42 @@ sub bodytag { } return $bodytag; + } + +# +# Top frame rendering, Remote is up +# + + my $imgsrc = $img; + if ($img =~ /^\/adm/) { + $imgsrc = &lonhttpdurl($img); + } + my $upperleft=''.$function.''; + + # Explicit link to get inline menu + my $menu= ($no_inline_link?'' + :''.&mt('Switch to Inline Menu Mode').''); + + if ($dc_info) { + $dc_info = qq|($dc_info)|; + } + + unless ($env{'form.inhibitmenu'}) { + $bodytag .= qq|
$name $role
+
    +
  1. $menu
  2. +
$realm $dc_info
|; + } + return(< +$upperleft + $messages  + +$titleinfo $dc_info $menu + + +ENDBODY } sub dc_courseid_toggle { @@ -5134,8 +5176,15 @@ sub make_attr_string { delete($attr_ref->{$key}); } } - $attr_ref->{'onload'} = $on_load; - $attr_ref->{'onunload'}= $on_unload; + if ($env{'environment.remote'} eq 'on') { + $attr_ref->{'onload'} = + &Apache::lonmenu::loadevents(). $on_load; + $attr_ref->{'onunload'}= + &Apache::lonmenu::unloadevents().$on_unload; + } else { + $attr_ref->{'onload'} = $on_load; + $attr_ref->{'onunload'}= $on_unload; + } } my $attr_string; @@ -6586,6 +6635,7 @@ ul#LC_secondary_menu li:hover ul, ul#LC_ float: none; background-color: $data_table_light; z-index: 2; + margin-left: -1px; } ul#LC_secondary_menu li ul li { @@ -6939,6 +6989,7 @@ ul#LC_toolbar { list-style:none; position:relative; background-color:white; + overflow: auto; } ul#LC_toolbar li { @@ -6948,6 +6999,7 @@ ul#LC_toolbar li { float: left; display:inline; vertical-align:middle; + white-space: nowrap; } @@ -7097,8 +7149,8 @@ sub headtag { if (!$args->{'frameset'}) { $result .= &Apache::lonhtmlcommon::htmlareaheaders(); } - if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) { - $result .= Apache::lonxml::display_title(); + if ($args->{'force_register'}) { + $result .= &Apache::lonmenu::registerurl(1); } if (!$args->{'no_nav_bar'} && !$args->{'only_body'} @@ -7307,6 +7359,8 @@ $args - additional optional args support skip_phases -> hash ref of head -> skip the generation body -> skip all generation + no_inline_link -> if true and in remote mode, don't show the + 'Switch To Inline Menu' link no_auto_mt_title -> prevent &mt()ing the title arg inherit_jsmath -> when creating popup window in a page, should it have jsmath forced on by the @@ -7342,7 +7396,8 @@ sub start_page { $args->{'function'}, $args->{'add_entries'}, $args->{'only_body'}, $args->{'domain'}, $args->{'force_register'}, $args->{'no_nav_bar'}, - $args->{'bgcolor'}, $args); + $args->{'bgcolor'}, $args->{'no_inline_link'}, + $args); } } @@ -9353,7 +9408,7 @@ sub get_env_multiple { sub ask_for_embedded_content { my ($actionurl,$state,$allfiles,$codebase,$args)=@_; my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges, - %currsubfile,%unused); + %currsubfile,%unused,$rem); my $counter = 0; my $numnew = 0; my $numremref = 0; @@ -9366,6 +9421,10 @@ sub ask_for_embedded_content { my $heading = &mt('Upload embedded files'); my $buttontext = &mt('Upload'); + my $navmap; + if ($env{'request.course.id'}) { + $navmap = Apache::lonnavmaps::navmap->new(); + } if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) { my $current_path='/'; if ($env{'form.currentpath'}) { @@ -9395,6 +9454,13 @@ sub ask_for_embedded_content { if (ref($args) eq 'HASH') { $url = $args->{'docs_url'}; $toplevel = $url; + if ($args->{'context'} eq 'paste') { + ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/}); + ($path) = + ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/}); + $fileloc = &Apache::lonnet::filelocation('',$toplevel); + $fileloc =~ s{^/}{}; + } } } elsif ($actionurl eq '/adm/dependencies') { if ($env{'request.course.id'} ne '') { @@ -9404,6 +9470,7 @@ sub ask_for_embedded_content { $url = $args->{'docs_url'}; $title = $args->{'docs_title'}; $toplevel = "/$url"; + ($rem) = ($toplevel =~ m{^(.+/)[^/]+$}); ($path) = ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/}); $fileloc = &Apache::lonnet::filelocation('',$toplevel); @@ -9466,7 +9533,9 @@ sub ask_for_embedded_content { my @subdir_list = grep(!/^\./,readdir($dir)); map {$currsubfile{$path}{$_} = 1;} @subdir_list; } - } elsif ($actionurl eq '/adm/dependencies') { + } elsif (($actionurl eq '/adm/dependencies') || + (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') && + ($args->{'context'} eq 'paste'))) { if ($env{'request.course.id'} ne '') { my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$}); if ($dir ne '') { @@ -9502,6 +9571,12 @@ sub ask_for_embedded_content { if (ref($currsubfile{$path}) eq 'HASH') { foreach my $file (keys(%{$currsubfile{$path}})) { unless ($subdependencies{$path}{$file}) { + next if (($rem ne '') && + (($env{"httpref.$rem"."$path/$file"} ne '') || + (ref($navmap) && + (($navmap->getResourceByUrl($rem."$path/$file") ne '') || + (($file =~ /^(.*\.s?html?)\.bak$/i) && + ($navmap->getResourceByUrl($rem."$path/$1"))))))); $unused{$path.'/'.$file} = 1; } } @@ -9524,7 +9599,9 @@ sub ask_for_embedded_content { my @dir_list = grep(!/^\./,readdir($dir)); map {$currfile{$_} = 1;} @dir_list; } - } elsif ($actionurl eq '/adm/dependencies') { + } elsif (($actionurl eq '/adm/dependencies') || + (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') && + ($args->{'context'} eq 'paste'))) { if ($env{'request.course.id'} ne '') { my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$}); if ($dir ne '') { @@ -9558,9 +9635,23 @@ sub ask_for_embedded_content { unless (($file eq $filename) || ($file eq $filename.'.bak') || ($dependencies{$file})) { + if ($actionurl eq '/adm/dependencies') { + next if (($rem ne '') && + (($env{"httpref.$rem".$file} ne '') || + (ref($navmap) && + (($navmap->getResourceByUrl($rem.$file) ne '') || + (($file =~ /^(.*\.s?html?)\.bak$/i) && + ($navmap->getResourceByUrl($rem.$1))))))); + } $unused{$file} = 1; } } + if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') && + ($args->{'context'} eq 'paste')) { + $counter = scalar(keys(%existing)); + $numpathchg = scalar(keys(%pathchanges)); + return ($output,$counter,$numpathchg,\%existing); + } foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) { if ($actionurl eq '/adm/dependencies') { next if ($embed_file =~ m{^\w+://}); @@ -9577,7 +9668,6 @@ sub ask_for_embedded_content { $numremref++; } elsif ($args->{'error_on_invalid_names'} && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) { - $upload_output.=''.&mt('Invalid characters').''; $numinvalid++; } else { @@ -11065,7 +11155,10 @@ function dependencyCheck(form,count,offs document.getElementById('arc_depon_'+count).style.display='block'; form.elements[depitem].options.length = 0; form.elements[depitem].options[0] = new Option('Select','',true,true); - for (var i=1; i'."\n"; @@ -11289,7 +11383,7 @@ sub process_extracted_files { my ($outtext,$errtext)= &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'. $docuname.'/'.$folders{$outer}. - '.'.$containers{$outer},1); + '.'.$containers{$outer},1,1); unless ($errtext) { if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") { $result .= '
  • '.&mt('File: [_1] added to course',$docstitle).'
  • '."\n"; @@ -11297,87 +11391,93 @@ sub process_extracted_files { } } } - } elsif ($env{'form.archive_'.$i} eq 'dependency') { - my ($title) = ($path =~ m{/([^/]+)$}); - $referrer{$i} = $env{'form.archive_dependent_on_'.$i}; - if ($env{'form.archive_'.$referrer{$i}} eq 'display') { - if (ref($dirorder{$i}) eq 'ARRAY') { - my ($itemidx,$fullpath,$relpath); + } + } else { + $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'
    '; + } + } + for (my $i=1; $i<=$numitems; $i++) { + next unless ($env{'form.archive_'.$i} eq 'dependency'); + my $path = $env{'form.archive_content_'.$i}; + if ($path =~ /^\Q$pathtocheck\E/) { + my ($title) = ($path =~ m{/([^/]+)$}); + $referrer{$i} = $env{'form.archive_dependent_on_'.$i}; + if ($env{'form.archive_'.$referrer{$i}} eq 'display') { + if (ref($dirorder{$i}) eq 'ARRAY') { + my ($itemidx,$fullpath,$relpath); + if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') { + my $container = $dirorder{$referrer{$i}}->[-1]; for (my $j=0; $j<@{$dirorder{$i}}; $j++) { - if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') { - my $container = $dirorder{$referrer{$i}}->[-1]; - for (my $j=0; $j<@{$dirorder{$i}}; $j++) { - if ($dirorder{$i}->[$j] eq $container) { - $itemidx = $j; - } - } + if ($dirorder{$i}->[$j] eq $container) { + $itemidx = $j; } } - if ($itemidx ne '') { - if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) { - if ($mapinner{$referrer{$i}}) { - $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}"; - for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) { - if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) { - unless (defined($newseqid{$dirorder{$i}->[$j]})) { - $fullpath .= '/'.$titles{$dirorder{$i}->[$j]}; - $relpath .= '/'.$titles{$dirorder{$i}->[$j]}; - if (!-e $fullpath) { - mkdir($fullpath,0755); - } - } - } else { - last; + } + if ($itemidx eq '') { + $itemidx = 0; + } + if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) { + if ($mapinner{$referrer{$i}}) { + $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}"; + for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) { + if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) { + unless (defined($newseqid{$dirorder{$i}->[$j]})) { + $fullpath .= '/'.$titles{$dirorder{$i}->[$j]}; + $relpath .= '/'.$titles{$dirorder{$i}->[$j]}; + if (!-e $fullpath) { + mkdir($fullpath,0755); } } + } else { + last; } - } elsif ($newdest{$referrer{$i}}) { - $fullpath = $newdest{$referrer{$i}}; - for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) { - if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') { - $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]}; - last; - } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) { - unless (defined($newseqid{$dirorder{$i}->[$j]})) { - $fullpath .= '/'.$titles{$dirorder{$i}->[$j]}; - $relpath .= '/'.$titles{$dirorder{$i}->[$j]}; - if (!-e $fullpath) { - mkdir($fullpath,0755); - } - } - } else { - last; + } + } + } elsif ($newdest{$referrer{$i}}) { + $fullpath = $newdest{$referrer{$i}}; + for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) { + if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') { + $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]}; + last; + } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) { + unless (defined($newseqid{$dirorder{$i}->[$j]})) { + $fullpath .= '/'.$titles{$dirorder{$i}->[$j]}; + $relpath .= '/'.$titles{$dirorder{$i}->[$j]}; + if (!-e $fullpath) { + mkdir($fullpath,0755); } } + } else { + last; } - if ($fullpath ne '') { - if (-e "$prefix$path") { - system("mv $prefix$path $fullpath/$title"); - } - if (-e "$fullpath/$title") { - my $showpath; - if ($relpath ne '') { - $showpath = "$relpath/$title"; - } else { - $showpath = "/$title"; - } - $result .= '
  • '.&mt('[_1] included as a dependency',$showpath).'
  • '."\n"; - } - unless ($ishome) { - my $fetch = "$fullpath/$title"; - $fetch =~ s/^\Q$prefix$dir\E//; - $prompttofetch{$fetch} = 1; - } + } + } + if ($fullpath ne '') { + if (-e "$prefix$path") { + system("mv $prefix$path $fullpath/$title"); + } + if (-e "$fullpath/$title") { + my $showpath; + if ($relpath ne '') { + $showpath = "$relpath/$title"; + } else { + $showpath = "/$title"; } + $result .= '
  • '.&mt('[_1] included as a dependency',$showpath).'
  • '."\n"; + } + unless ($ishome) { + my $fetch = "$fullpath/$title"; + $fetch =~ s/^\Q$prefix$dir\E//; + $prompttofetch{$fetch} = 1; } } - } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') { - $warning .= &mt('[_1] is a dependency of [_2], which was discarded.', - $path,$env{'form.archive_content_'.$referrer{$i}}).'
    '; } + } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') { + $warning .= &mt('[_1] is a dependency of [_2], which was discarded.', + $path,$env{'form.archive_content_'.$referrer{$i}}).'
    '; } } else { - $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'
    '; + $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'
    '; } } if (keys(%todelete)) { @@ -13884,6 +13984,66 @@ sub build_release_hashes { return; } +sub update_content_constraints { + my ($cdom,$cnum,$chome,$cid) = @_; + my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired'); + my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'}); + my %checkresponsetypes; + foreach my $key (keys(%Apache::lonnet::needsrelease)) { + my ($item,$name,$value) = split(/:/,$key); + if ($item eq 'resourcetag') { + if ($name eq 'responsetype') { + $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key} + } + } + } + my $navmap = Apache::lonnavmaps::navmap->new(); + if (defined($navmap)) { + my %allresponses; + foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) { + my %responses = $res->responseTypes(); + foreach my $key (keys(%responses)) { + next unless(exists($checkresponsetypes{$key})); + $allresponses{$key} += $responses{$key}; + } + } + foreach my $key (keys(%allresponses)) { + my ($major,$minor) = split(/\./,$checkresponsetypes{$key}); + if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) { + ($reqdmajor,$reqdminor) = ($major,$minor); + } + } + undef($navmap); + } + unless (($reqdmajor eq '') && ($reqdminor eq '')) { + &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid); + } + return; +} + +sub parse_supplemental_title { + my ($title) = @_; + + my ($foldertitle,$renametitle); + if ($title =~ /&&&/) { + $title = &HTML::Entites::decode($title); + } + if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) { + $renametitle=$4; + my ($time,$uname,$udom) = ($1,$2,$3); + $foldertitle=&Apache::lontexconvert::msgtexconverted($4); + my $name = &plainname($uname,$udom); + $name = &HTML::Entities::encode($name,'"<>&\''); + $renametitle = &HTML::Entities::encode($renametitle,'"<>&\''); + $title=''.&Apache::lonlocal::locallocaltime($time).' '. + $name.':
    '.$foldertitle; + } + if (wantarray) { + return ($title,$foldertitle,$renametitle); + } + return $title; +} + =pod =back