--- loncom/interface/lonmenu.pm 2017/01/22 17:10:28 1.369.2.68 +++ loncom/interface/lonmenu.pm 2019/02/22 01:57:36 1.369.2.74 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.369.2.68 2017/01/22 17:10:28 raeburn Exp $ +# $Id: lonmenu.pm,v 1.369.2.74 2019/02/22 01:57:36 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -499,6 +499,9 @@ sub secondary_menu { next if ($item->[2] eq 'mgr' && !$canmgr); next if ($item->[2] eq 'vcg' && !$canviewgrps); next if ($item->[2] eq 'crsedit' && !$canedit && !$canvieweditor); + next if ($item->[2] eq 'params' && !$canmodpara && !$canviewpara); + next if ($item->[2] eq 'author' && !$author); + next if ($item->[2] eq 'cca' && !$canmodifycoauthor); push(@scndsub,$item); } } @@ -528,6 +531,7 @@ sub secondary_menu { } else { $$menuitem[0] =~ s{\?register=1}{}; } + $$menuitem[0] = &HTML::Entities::encode($$menuitem[0],'&<>"'); } $menu .= &prep_menuitem(\@$menuitem); } @@ -546,7 +550,7 @@ sub secondary_menu { my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'}; ($escurl = $env{'request.filename'}) =~ s{^\Q$londocroot\E}{}; $escurl = &escape($escurl); - } + } $menu =~ s/\[url\]/$escurl/g; $menu =~ s/\[symb\]/$escsymb/g; } @@ -635,6 +639,20 @@ sub build_submenu { next unless (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')); $href =~ s/\[domain\]/$env{'user.domain'}/g; $href =~ s/\[user\]/$env{'user.name'}/g; + } elsif (($href =~ m{^/adm/preferences\?}) && ($href =~ /\[returnurl\]/)) { + my $returnurl = $ENV{'REQUEST_URI'}; + if ($ENV{'REQUEST_URI'} =~ m{/adm/preferences\?action=(?:changedomcoord|authorsettings)\&returnurl=([^\&]+)$}) { + $returnurl = $1; + } + if (($returnurl =~ m{^/adm/createuser($|\?action=)}) || + ($returnurl =~ m{^/priv/$match_domain/$match_username}) || + ($returnurl =~ m{^/res(/?$|/$match_domain/$match_username)})) { + $returnurl =~ s{\?.*$}{}; + $returnurl = '&returnurl='.&HTML::Entities::encode($returnurl,'"<>&\''); + } else { + undef($returnurl); + } + $href =~ s/\[returnurl\]/$returnurl/; } unless (($href eq '') || ($href =~ /^\#/)) { $target = ' target="_top"'; @@ -1469,8 +1487,9 @@ sub prepare_functions { } my $editbutton = ''; + my $viewsrcbutton = ''; # -# Determine whether or not to display 'Edit' icon/button +# Determine whether or not to display 'Edit' or 'View Source' icon/button # if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) { my $file=&Apache::lonnet::declutter($env{'request.filename'}); @@ -1501,9 +1520,13 @@ sub prepare_functions { # This applies in course context # if (($perms{'mdc'}) && - (($resurl eq "/public/$cdom/$cnum/syllabus") || - ($resurl =~ m{^/uploaded/$cdom/$cnum/portfolio/syllabus/}))) { - $cfile = $resurl; + (($resurl =~ m{^/?public/$cdom/$cnum/syllabus}) || + ($resurl =~ m{^/?uploaded/$cdom/$cnum/portfolio/syllabus/}))) { + if ($resurl =~ m{^/}) { + $cfile = $resurl; + } else { + $cfile = "/$resurl"; + } $home = &Apache::lonnet::homeserver($cnum,$cdom); if ($env{'form.forceedit'}) { $forceview = 1; @@ -1540,6 +1563,29 @@ sub prepare_functions { $editbutton = &get_editbutton($cfile,$home,$switchserver, $forceedit,$forceview,$forcereg); } + if ((($cfile eq '') || (!$editbutton)) && + ($resurl =~ /$LONCAPA::assess_re/)) { + my $showurl = &Apache::lonnet::clutter($resurl); + if ((&Apache::lonnet::allowed('cre','/')) && + (&Apache::lonnet::metadata($resurl,'sourceavail') eq 'open')) { + $viewsrcbutton = 1; + } elsif (&Apache::lonnet::allowed('vxc',$env{'request.course.id'})) { + if ($showurl =~ m{^\Q/res/$cdom/\E($match_username)/}) { + my $auname = $1; + if (($env{'request.course.adhocsrcaccess'} ne '') && + (grep(/^\Q$auname\E$/,split(/,/,$env{'request.course.adhocsrcaccess'})))) { + $viewsrcbutton = 1; + } elsif ((&Apache::lonnet::metadata($resurl,'sourceavail') eq 'open') && + (&Apache::lonnet::allowed('bre','/'))) { + $viewsrcbutton = 1; + } + } + } + if ($viewsrcbutton) { + &switch('','',6,1,'pcstr.png','View Source','resource[_2]','open_source()', + 'View source code'); + } + } } } } @@ -2156,15 +2202,6 @@ return (<$end))) { - my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($cdom.'_'.$cnum); - my %available; - if (ref($possroles) eq 'ARRAY') { - map { $available{$_} = 1; } @{$possroles}; - } - my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom); - if (ref($domdefaults{'adhocroles'}) eq 'HASH') { - if (keys(%{$domdefaults{'adhocroles'}})) { - my $numsec = 1; - my @sections; - my ($allseclist,$cached) = - &Apache::lonnet::is_cached_new('courseseclist',$cdom.'_'.$cnum); - if (defined($cached)) { - if ($allseclist ne '') { - @sections = split(/,/,$allseclist); - $numsec += scalar(@sections); - } - } else { - my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum); - @sections = sort(keys(%sections_count)); + my $is_helpdesk = 0; + my $now = time; + foreach my $role ('dh','da') { + if ($env{"user.role.$role./$cdom/"}) { + my ($start,$end)=split(/\./,$env{"user.role.$role./$cdom/"}); + if (!($start && ($now<$start)) && !($end && ($now>$end))) { + $is_helpdesk = 1; + last; + } + } + } + if ($is_helpdesk) { + my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($cdom.'_'.$cnum); + my %available; + if (ref($possroles) eq 'ARRAY') { + map { $available{$_} = 1; } @{$possroles}; + } + my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom); + if (ref($domdefaults{'adhocroles'}) eq 'HASH') { + if (keys(%{$domdefaults{'adhocroles'}})) { + my $numsec = 1; + my @sections; + my ($allseclist,$cached) = + &Apache::lonnet::is_cached_new('courseseclist',$cdom.'_'.$cnum); + if (defined($cached)) { + if ($allseclist ne '') { + @sections = split(/,/,$allseclist); $numsec += scalar(@sections); - $allseclist = join(',',@sections); - &Apache::lonnet::do_cache_new('courseseclist',$cdom.'_'.$cnum,$allseclist); } - my (%adhoc,$gotprivs); - my $prefix = "cr/$cdom/$cdom".'-domainconfig'; - foreach my $role (keys(%{$domdefaults{'adhocroles'}})) { - next if (($role eq '') || ($role =~ /\W/)); - $seccount->{"$prefix/$role"} = $numsec; - $roledesc->{"$prefix/$role"} = $description->{$role}; - if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0)) { - if (exists($env{"user.priv.$prefix/$role./$cdom/$cnum./"})) { - $courseprivs->{"$prefix/$role./$cdom/$cnum./"} = - $env{"user.priv.$prefix/$role./$cdom/$cnum./"}; - $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/"} = - $env{"user.priv.$prefix/$role./$cdom/$cnum./$cdom/"}; - $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/$cnum"} = - $env{"user.priv.$prefix/$role./$cdom/$cnum./$cdom/$cnum"}; - } else { - unless ($gotprivs) { - my ($adhocroles,$privscached) = - &Apache::lonnet::is_cached_new('adhocroles',$cdom); - if ((defined($privscached)) && (ref($adhocroles) eq 'HASH')) { - %adhoc = %{$adhocroles}; - } else { - my $confname = &Apache::lonnet::get_domainconfiguser($cdom); - my %roledefs = &Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_'); - foreach my $key (keys(%roledefs)) { - (undef,my $rolename) = split(/_/,$key); - if ($rolename ne '') { - my ($systempriv,$domainpriv,$coursepriv) = split(/\_/,$roledefs{$key}); - $coursepriv = &Apache::lonnet::course_adhocrole_privs($rolename,$cdom,$cnum,$coursepriv); - $adhoc{$rolename} = join('_',($systempriv,$domainpriv,$coursepriv)); - } + } else { + my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum); + @sections = sort(keys(%sections_count)); + $numsec += scalar(@sections); + $allseclist = join(',',@sections); + &Apache::lonnet::do_cache_new('courseseclist',$cdom.'_'.$cnum,$allseclist); + } + my (%adhoc,$gotprivs); + my $prefix = "cr/$cdom/$cdom".'-domainconfig'; + foreach my $role (keys(%{$domdefaults{'adhocroles'}})) { + next if (($role eq '') || ($role =~ /\W/)); + $seccount->{"$prefix/$role"} = $numsec; + $roledesc->{"$prefix/$role"} = $description->{$role}; + if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0)) { + if (exists($env{"user.priv.$prefix/$role./$cdom/$cnum./"})) { + $courseprivs->{"$prefix/$role./$cdom/$cnum./"} = + $env{"user.priv.$prefix/$role./$cdom/$cnum./"}; + $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/"} = + $env{"user.priv.$prefix/$role./$cdom/$cnum./$cdom/"}; + $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/$cnum"} = + $env{"user.priv.$prefix/$role./$cdom/$cnum./$cdom/$cnum"}; + } else { + unless ($gotprivs) { + my ($adhocroles,$privscached) = + &Apache::lonnet::is_cached_new('adhocroles',$cdom); + if ((defined($privscached)) && (ref($adhocroles) eq 'HASH')) { + %adhoc = %{$adhocroles}; + } else { + my $confname = &Apache::lonnet::get_domainconfiguser($cdom); + my %roledefs = &Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_'); + foreach my $key (keys(%roledefs)) { + (undef,my $rolename) = split(/_/,$key); + if ($rolename ne '') { + my ($systempriv,$domainpriv,$coursepriv) = split(/\_/,$roledefs{$key}); + $coursepriv = &Apache::lonnet::course_adhocrole_privs($rolename,$cdom,$cnum,$coursepriv); + $adhoc{$rolename} = join('_',($systempriv,$domainpriv,$coursepriv)); } - &Apache::lonnet::do_cache_new('adhocroles',$cdom,\%adhoc); } - $gotprivs = 1; + &Apache::lonnet::do_cache_new('adhocroles',$cdom,\%adhoc); } - ($courseprivs->{"$prefix/$role./$cdom/$cnum./"}, - $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/"}, - $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/$cnum"}) = - split(/\_/,$adhoc{$role}); + $gotprivs = 1; } + ($courseprivs->{"$prefix/$role./$cdom/$cnum./"}, + $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/"}, + $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/$cnum"}) = + split(/\_/,$adhoc{$role}); } - if ($available{$role}) { - $courseroles->{"$prefix/$role"} = \@sections; - } + } + if ($available{$role}) { + $courseroles->{"$prefix/$role"} = \@sections; } } }