--- loncom/interface/lonmenu.pm 2016/02/26 21:44:39 1.439 +++ loncom/interface/lonmenu.pm 2018/12/30 19:47:02 1.495 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.439 2016/02/26 21:44:39 raeburn Exp $ +# $Id: lonmenu.pm,v 1.495 2018/12/30 19:47:02 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -99,7 +99,7 @@ It gets filled in the BEGIN block of thi =over -=item prep_menuitems(\@menuitem) +=item prep_menuitems(\@menuitem,$ltitarget) This routine wraps a menuitem in proper HTML. It is used by primary_menu() and secondary_menu(). @@ -124,9 +124,13 @@ dropdown list when mouse hovers over top (no hover psuedo class) via LC_hoverable class for
  • tag for top- level item, which employs jQuery to handle behavior on mouseover. -Inputs: 4 - (a) link and (b) target for anchor href in top level item, - (c) title for text wrapped by anchor tag in top level item. - (d) reference to array of arrays of sub-menu items. +Inputs: 6 - (a) link and (b) target for anchor href in top level item, + (c) title for text wrapped by anchor tag in top level item, + (d) reference to array of arrays of sub-menu items, + (e) boolean to indicate whether to call &mt() to translate + name of menu item, + (f) optional class for
  • element in primary menu, for which + sub menu is being generated. The underlying datastructure used in (d) contains data from mydesk.tab. It consists of an array which has an array for each item appearing in @@ -206,16 +210,17 @@ use Apache::lonenc(); use Apache::lonlocal; use Apache::lonmsg(); use LONCAPA qw(:DEFAULT :match); +use LONCAPA::ltiutils; use HTML::Entities(); use Apache::lonwishlist(); use vars qw(@desklines %category_names %category_members %category_positions - $readdesk @primary_menu %primary_submenu @secondary_menu); + $readdesk @primary_menu %primary_submenu @secondary_menu %secondary_submenu); my @inlineremote; sub prep_menuitem { - my ($menuitem) = @_; + my ($menuitem,$ltitarget) = @_; return '' unless(ref($menuitem) eq 'ARRAY'); my $link; if ($$menuitem[1]) { # graphical Link @@ -225,10 +230,14 @@ sub prep_menuitem { } else { # textual Link $link = &mt($$menuitem[3]); } + my $target = ' target="_top"'; + if ($ltitarget eq 'iframe') { + $target =''; + } return '
  • $link
  • |; + . qq| href="$$menuitem[0]"$target>$link|; } # primary_menu() evaluates @primary_menu and returns a two item array, @@ -238,7 +247,8 @@ sub prep_menuitem { # @primary_menu is filled within the BEGIN block of this module with # entries from mydesk.tab sub primary_menu { - my (%menu); + my ($crstype,$ltimenu) = @_; + my (%menu,%ltiexc); # each element of @primary contains following array: # (link url, icon path, alt text, link text, condition, position) my $public; @@ -246,6 +256,27 @@ sub primary_menu { || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) { $public = 1; } + my $rolecount; + if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) { + my $update=$env{'user.update.time'}; + if (!$update) { + $update = $env{'user.login.time'}; + } + my %roles_in_env; + $rolecount = &Apache::lonroles::roles_from_env(\%roles_in_env,$update); + } + my ($lti,$ltitarget); + if ($env{'request.lti.login'}) { + $lti = 1; + $ltitarget = $env{'request.lti.target'}; + if (ref($ltimenu) eq 'HASH') { + foreach my $item ('fullname','logout') { + unless ($ltimenu->{$item}) { + $ltiexc{$item} = 1; + } + } + } + } foreach my $menuitem (@primary_menu) { # evaluate conditions next if ref($menuitem) ne 'ARRAY'; # @@ -260,11 +291,23 @@ sub primary_menu { && !$public; # only visible to public # users next if $$menuitem[4] eq 'roles' ##show links depending on - && &Apache::loncommon::show_course(); ##term 'Courses' or - next if $$menuitem[4] eq 'courses' ##'Roles' wanted - && !&Apache::loncommon::show_course(); ## - + && (&Apache::loncommon::show_course() ##term 'Courses' or + || $env{'request.lti.login'}); ##'Roles' wanted + next if $$menuitem[4] eq 'courses' ##and not LTI access + && (!&Apache::loncommon::show_course() + || !$env{'request.lti.login'}); + next if $$menuitem[4] eq 'notlti' + && $lti; + next if $$menuitem[4] eq 'ltiexc' + && exists($ltiexc{lc($menuitem->[3])}); my $title = $menuitem->[3]; + if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) { + if ($menuitem->[4] eq 'courses') { + next unless ($rolecount>1); + } else { + next unless (($title eq 'Personal') || ($title eq 'Logout')); + } + } my $position = $menuitem->[5]; if ($position eq '') { $position = 'right'; @@ -273,13 +316,16 @@ sub primary_menu { my ($link,$target); if ($menuitem->[0] ne '') { $link = $menuitem->[0]; - $target = '_top'; + unless ($ltitarget eq 'iframe') { + $target = '_top'; + } } else { $link = '#'; } my @primsub; if (ref($primary_submenu{$title}) eq 'ARRAY') { foreach my $item (@{$primary_submenu{$title}}) { + next if (($crstype eq 'Placement') && (!$env{'request.role.adv'})); next if (($item->[2] eq 'wishlist') && (!$env{'user.adv'})); next if ((($item->[2] eq 'portfolio') || ($item->[2] eq 'blog')) && @@ -287,18 +333,21 @@ sub primary_menu { undef,'tools'))); push(@primsub,$item); } - if (@primsub > 0) { - if ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'} ) { + if ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'} ) { + unless ($ltiexc{'fullname'}) { $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}); - } else { - $title = &mt($title); } + } else { + $title = &mt($title); + } + if (@primsub > 0) { $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1); } elsif ($link) { - $menu{$position} .= '
  • '.&mt($title).'
  • '; + $menu{$position} .= '
  • '.$title.'
  • '; } } } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink + next if ($crstype eq 'Placement'); if ($public) { my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'}; my $defdom = &Apache::lonnet::default_login_domain(); @@ -306,13 +355,13 @@ sub primary_menu { 'helpdeskmail', $defdom,$origmail); if ($to ne '') { - $menu{$position} .= &prep_menuitem($menuitem); + $menu{$position} .= &prep_menuitem($menuitem,$ltitarget); } } else { $menu{$position} .= '
  • '.&Apache::loncommon::top_nav_help('Help').'
  • '; } } else { - $menu{$position} .= prep_menuitem($menuitem); + $menu{$position} .= prep_menuitem($menuitem,$ltitarget); } } my @output = ('',''); @@ -351,7 +400,7 @@ sub getauthor{ } sub secondary_menu { - my ($httphost) = @_; + my ($httphost,$ltiscope,$ltimenu,$noprimary) = @_; my $menu; my $crstype = &Apache::loncommon::course_type(); @@ -359,27 +408,28 @@ sub secondary_menu { ? "/$env{'request.course.sec'}" : ''); my $canedit = &Apache::lonnet::allowed('mdc', $env{'request.course.id'}); + my $canvieweditor = &Apache::lonnet::allowed('cev', $env{'request.course.id'}); my $canviewroster = $env{'course.'.$env{'request.course.id'}.'.student_classlist_view'}; if ($canviewroster eq 'disabled') { undef($canviewroster); } my $canviewgrps = &Apache::lonnet::allowed('vcg', $crs_sec); - my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec); + my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec); + my $canviewusers = &Apache::lonnet::allowed('vcl', $crs_sec); my $canviewwnew = &Apache::lonnet::allowed('whn', $crs_sec); + my $canviewpara = &Apache::lonnet::allowed('vpa', $crs_sec); my $canmodpara = &Apache::lonnet::allowed('opa', $crs_sec); my $canvgr = &Apache::lonnet::allowed('vgr', $crs_sec); my $canmgr = &Apache::lonnet::allowed('mgr', $crs_sec); + my $canplc = &Apache::lonnet::allowed('plc', $crs_sec); my $author = &getauthor(); - my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv,$grouptools); + my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv,$grouptools,$lti,$ltimapres,%ltiexc); $grouptools = 0; if ($env{'request.course.id'}) { $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; - if ($canedit) { - $showsyllabus = 1; - $showfeeds = 1; - } else { + unless ($canedit || $canvieweditor) { unless (&Apache::lonnet::is_on_map("public/$cdom/$cnum/syllabus")) { if (($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'}) || ($env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) || @@ -392,7 +442,7 @@ sub secondary_menu { $showfeeds = 1; } } - unless ($canmgr) { + unless ($canmgr || $canvgr) { my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom); if (keys(%slots) > 0) { $showresv = 1; @@ -409,6 +459,19 @@ sub secondary_menu { } } } + if ($env{'request.lti.login'}) { + $lti = 1; + if (ref($ltimenu) eq 'HASH') { + foreach my $item ('fullname','coursetitle','role','logout','grades') { + unless ($ltimenu->{$item}) { + $ltiexc{$item} = 1; + } + } + } + if (($ltiscope eq 'map') || ($ltiscope eq 'resource')) { + $ltimapres = 1; + } + } } my ($canmodifycoauthor); @@ -419,66 +482,142 @@ sub secondary_menu { $canmodifycoauthor = 1; } } - my ($roleswitcher_js,$roleswitcher_form); + + my ($roleswitcher_js,$roleswitcher_form,$ltitarget); + if ($env{'request.lti.login'}) { + $ltitarget = $env{'request.lti.target'}; + } foreach my $menuitem (@secondary_menu) { # evaluate conditions next if ref($menuitem) ne 'ARRAY'; + next if (($crstype eq 'Placement') && ($$menuitem[3] ne 'Roles') && (!$env{'request.role.adv'})); next if $$menuitem[4] ne 'always' && ($$menuitem[4] ne 'author' && $$menuitem[4] ne 'cca') && !$env{'request.course.id'}; - next if $$menuitem[4] =~ /^mdc/ - && !$canedit; + next if $$menuitem[4] =~ /^crsedit/ + && (!$canedit && !$canvieweditor); next if $$menuitem[4] eq 'nvgr' - && $canvgr; + && ($canvgr || $ltiexc{'grades'}); next if $$menuitem[4] eq 'vgr' && !$canvgr; - next if $$menuitem[4] eq 'cst' - && !$canmodifyuser; - next if $$menuitem[4] eq 'ncst' - && ($canmodifyuser || !$canviewroster); + next if $$menuitem[4] eq 'viewusers' + && !$canmodifyuser && !$canviewusers; + next if $$menuitem[4] eq 'noviewusers' + && ($canmodifyuser || $canviewusers || !$canviewroster); next if $$menuitem[4] eq 'mgr' && !$canmgr; next if $$menuitem[4] eq 'showresv' && !$showresv; next if $$menuitem[4] eq 'whn' && !$canviewwnew; - next if $$menuitem[4] eq 'opa' - && !$canmodpara; - next if $$menuitem[4] =~ /showgroups$/ - && !$canviewgrps - && !$grouptools; + next if $$menuitem[4] eq 'params' + && (!$canmodpara && !$canviewpara); + next if $$menuitem[4] eq 'showgroups' + && ($canviewgrps || !$grouptools); next if $$menuitem[4] eq 'showsyllabus' && !$showsyllabus; next if $$menuitem[4] eq 'showfeeds' && !$showfeeds; + next if $$menuitem[4] eq 'plc' + && !$canplc; next if $$menuitem[4] eq 'author' && !$author; next if $$menuitem[4] eq 'cca' && !$canmodifycoauthor; + next if $$menuitem[4] eq 'notltimapres' + && $ltimapres; + next if $$menuitem[4] eq 'notlti' + && $lti; + next if $$menuitem[4] eq 'lti' + && (!$lti || !$noprimary); + next if $$menuitem[3] eq 'Logout' + && $ltiexc{'logout'}; - if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) { + my $title = $menuitem->[3]; + if (defined($secondary_submenu{$title})) { + my ($link,$target); + if ($menuitem->[0] ne '') { + $link = $menuitem->[0]; + unless ($ltitarget eq 'iframe') { + $target = '_top'; + } + } else { + $link = '#'; + } + my @scndsub; + if (ref($secondary_submenu{$title}) eq 'ARRAY') { + foreach my $item (@{$secondary_submenu{$title}}) { + if (ref($item) eq 'ARRAY') { + next if ($item->[2] eq 'vgr' && !$canvgr); + next if ($item->[2] eq 'opa' && !$canmodpara); + next if ($item->[2] eq 'vpa' && !$canviewpara); + next if ($item->[2] eq 'viewusers' && !($canmodifyuser || $canviewusers)); + 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); + next if ($item->[2] eq 'lti' && !$lti); + if ($item->[2] =~ /^lti(portfolio|wishlist|blog)$/) { + my $tool = $1; + next if !$lti; + next if (!&Apache::lonnet::usertools_access('','',$tool, + undef,'tools')); + } + push(@scndsub,$item); + } + } + if ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'} ) { + unless ($ltiexc{'fullname'}) { + $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}); + } + } + if (@scndsub > 0) { + $menu .= &create_submenu($link,$target,$title,\@scndsub,1); + } elsif ($link ne '#') { + $menu .= '
  • '.&mt($title).'
  • '; + } + } + } elsif ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) { # special treatment for role selector ($roleswitcher_js,$roleswitcher_form,my $switcher) = &roles_selector( - $env{'course.' . $env{'request.course.id'} . '.domain'}, - $env{'course.' . $env{'request.course.id'} . '.num'}, - $httphost + $env{'course.' . $env{'request.course.id'} . '.domain'}, + $env{'course.' . $env{'request.course.id'} . '.num'}, + $httphost,$ltitarget ); $menu .= $switcher; + } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink + next if ($crstype eq 'Placement'); + $menu .= '
  • '.&Apache::loncommon::top_nav_help('Help').'
  • '; } else { if ($$menuitem[3] eq 'Syllabus' && $env{'request.course.id'}) { my $url = $$menuitem[0]; $url =~ s{\[cdom\]/\[cnum\]}{$cdom/$cnum}; if (&Apache::lonnet::is_on_map($url)) { - unless ($$menuitem[0] =~ /\?register=1/) { - $$menuitem[0] .= '?register=1'; + unless ($$menuitem[0] =~ /(\?|\&)register=1/) { + $$menuitem[0] .= (($$menuitem[0]=~/\?/)? '&' : '?').'register=1'; } } else { - $$menuitem[0] =~ s{\?register=1}{}; + $$menuitem[0] =~ s{\&?register=1}{}; } + if ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://}) { + if (($ENV{'SERVER_PORT'} == 443) || ($env{'request.use_absolute'} =~ m{^https://})) { + unless (&Apache::lonnet::uses_sts()) { + unless ($$menuitem[0] =~ m{^https?://}) { + $$menuitem[0] = 'http://'.$ENV{'SERVER_NAME'}.$$menuitem[0]; + } + unless ($$menuitem[0] =~ /(\&|\?)usehttp=1/) { + $$menuitem[0] .= (($$menuitem[0]=~/\?/) ? '&' : '?').'usehttp=1'; + } + } + } + } + $$menuitem[0] = &HTML::Entities::encode($$menuitem[0],'&<>"'); } - $menu .= &prep_menuitem(\@$menuitem); + $menu .= &prep_menuitem(\@$menuitem,$ltitarget); } } if ($menu =~ /\[url\].*\[symb\]/) { @@ -495,13 +634,14 @@ 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; } $menu =~ s/\[uname\]/$$author{user}/g; $menu =~ s/\[udom\]/$$author{dom}/g; - if ($showsyllabus || $showfeeds) { + $menu =~ s/\[javascript\]/javascript:/g; + if ($env{'request.course.id'}) { $menu =~ s/\[cnum\]/$cnum/g; $menu =~ s/\[cdom\]/$cdom/g; } @@ -515,13 +655,13 @@ sub secondary_menu { } sub create_submenu { - my ($link,$target,$title,$submenu,$translate) = @_; + my ($link,$target,$title,$submenu,$translate,$addclass) = @_; return unless (ref($submenu) eq 'ARRAY'); my $disptarget; if ($target ne '') { $disptarget = ' target="'.$target.'"'; } - my $menu = '
  • '. + my $menu = '
  • '. ''. ''.$title. ''. @@ -541,7 +681,7 @@ sub create_submenu { # see perldoc create_submenu documentation for further information sub build_submenu { my ($target, $submenu, $translate, $first_level) = @_; - if (!defined(@{$submenu})) { + unless (@{$submenu}) { return ''; } @@ -584,9 +724,25 @@ 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"'; + if ($target eq '_top') { + $target = ' target="_top"'; + } } $menu .= '
  • '; @@ -599,7 +755,7 @@ sub build_submenu { } sub innerregister { - my ($forcereg,$bread_crumbs,$group) = @_; + my ($forcereg,$bread_crumbs,$group,$pagebuttonshide,$hostname,$ltiscope,$ltiuri) = @_; my $const_space = ($env{'request.state'} eq 'construct'); my $is_const_dir = 0; @@ -609,37 +765,65 @@ sub innerregister { undef(@inlineremote); - my ($mapurl,$resurl); + my ($mapurl,$resurl,$crstype,$navmap); if ($env{'request.course.id'}) { +# +#course_type: Course, Community, or Placement +# + $crstype = &Apache::loncommon::course_type(); if ($env{'request.symb'}) { - ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread()); + my $ignorenull; + unless ($env{'request.noversionuri'} eq '/adm/navmaps') { + $ignorenull = 1; + } + my $symb = &Apache::lonnet::symbread('','',$ignorenull); + ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb($symb); my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'}; my $maptitle = &Apache::lonnet::gettitle($mapurl); - my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread()); - -#SD -#course_type only Course and Community? -# - my @crumbs; + my $restitle = &Apache::lonnet::gettitle($symb); + my (@crumbs,@mapcrumbs); + if (($env{'request.noversionuri'} ne '/adm/navmaps') && ($mapurl ne '') && + (!(($crstype eq 'Placement') && !$env{'request.role.adv'}))) { + unless ($ltiscope eq 'resource') { + if (($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) && + !(($ltiscope eq 'map') && (&Apache::lonnet::clutter($resurl) eq $ltiuri))) { + $navmap = Apache::lonnavmaps::navmap->new(); + if (ref($navmap)) { + @mapcrumbs = $navmap->recursed_crumbs($mapurl,$restitle); + } + } + } + } unless (($forcereg) && ($env{'request.noversionuri'} eq '/adm/navmaps') && - ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) { - @crumbs = ({text => Apache::loncommon::course_type() - . ' Contents', + ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'}) || + (($crstype eq 'Placement') && (!$env{'request.role.adv'})) || + ($ltiscope eq 'map') || ($ltiscope eq 'resource')) { + @crumbs = ({text => $crstype.' Contents', href => "Javascript:gopost('/adm/navmaps','')"}); } if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) { - push(@crumbs, {text => '...', - no_mt => 1}); + if (@mapcrumbs) { + push(@crumbs,@mapcrumbs); + } elsif (!(($crstype eq 'Placement') && (!$env{'request.role.adv'})) && + ($ltiscope ne 'map') && ($ltiscope ne 'resource')) { + push(@crumbs, {text => '...', + no_mt => 1}); + } } - push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle - && $maptitle ne 'default.sequence' - && $maptitle ne $coursetitle); - - push @crumbs, {text => $restitle, no_mt => 1} if $restitle; + unless ((($crstype eq 'Placement') && (!$env{'request.role.adv'})) || (@mapcrumbs) || + (!$maptitle) || ($maptitle eq 'default.sequence') || + ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'}) || + ($ltiscope eq 'resource')) { + push @crumbs, {text => $maptitle, no_mt => 1, + href => &Apache::lonnet::clutter($mapurl).'?navmap=1'}; + } + if ($restitle && !@mapcrumbs) { + push(@crumbs,{text => $restitle, no_mt => 1}); + } my @tools; if ($env{'request.filename'} =~ /\.page$/) { my %breadcrumb_tools = &Apache::lonhtmlcommon::current_breadcrumb_tools(); @@ -655,7 +839,6 @@ sub innerregister { } else { $resurl = $env{'request.noversionuri'}; my $courseurl = &Apache::lonnet::courseid_to_courseurl($env{'request.course.id'}); - my $crstype = &Apache::loncommon::course_type(); my $title = &mt('View Resource'); if ($resurl =~ m{^\Q/uploaded$courseurl/supplemental/\E(default|\d+)/}) { &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folderpath','title']); @@ -665,7 +848,7 @@ sub innerregister { } my $trail; if ($env{'form.folderpath'}) { - &prepare_functions($resurl,$forcereg,$group,undef,undef,1); + &prepare_functions($resurl,$forcereg,$group,undef,undef,1,$hostname); ($trail) = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1); } else { @@ -680,10 +863,10 @@ sub innerregister { } elsif ($resurl =~ m{^\Q/uploaded$courseurl/portfolio/syllabus/}) { &Apache::lonhtmlcommon::clear_breadcrumbs(); &prepare_functions('/public'.$courseurl."/syllabus", - $forcereg,$group,undef,undef,1); + $forcereg,$group,undef,undef,1,$hostname); $title = &mt('Syllabus File'); my ($trail) = - &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1); + &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,$hostname); return $trail; } unless ($env{'request.state'} eq 'construct') { @@ -707,7 +890,7 @@ sub innerregister { $forceview,$editbutton); if (($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) || ($env{'request.role'} !~/^(aa|ca|au)/)) { - $editbutton = &prepare_functions($resurl,$forcereg,$group); + $editbutton = &prepare_functions($resurl,$forcereg,$group,'','','',$hostname); } if ($editbutton eq '') { $editbutton = &clear(6,1); @@ -720,12 +903,19 @@ sub innerregister { $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'}); + $perms{'cev'} = &Apache::lonnet::allowed('cev',$env{'request.course.id'}); my @privs; + my $gradable_exttool; if ($env{'request.symb'} ne '') { - if ($env{'request.filename'}=~/$LONCAPA::assess_re/) { + if ($env{'request.noversionuri'} =~ m{^/adm/$cdom/$cnum/(\d+)/ext\.tool$}) { + if (&Apache::lonnet::EXT('resource.0.gradable') =~ /^yes$/i) { + $gradable_exttool = 1; + push(@privs,('mgr','vgr')); + } + } elsif ($env{'request.filename'}=~/$LONCAPA::assess_re/) { push(@privs,('mgr','vgr')); } - push(@privs,'opa'); + push(@privs,('opa','vpa')); } foreach my $priv (@privs) { $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'}); @@ -737,8 +927,8 @@ sub innerregister { # # Determine whether or not to show Grades and Submissions buttons # - if ($env{'request.symb'} ne '' && - $env{'request.filename'}=~/$LONCAPA::assess_re/) { + if (($env{'request.symb'} ne '') && + (($env{'request.filename'}=~/$LONCAPA::assess_re/) || ($gradable_exttool))) { if ($perms{'mgr'}) { &switch('','',7,2,'pgrd.png','Content Grades','grades[_4]', "gocmd('/adm/grades','gradingmenu')", @@ -749,7 +939,7 @@ sub innerregister { 'Content Submissions'); } } - if (($env{'request.symb'} ne '') && ($perms{'opa'})) { + if (($env{'request.symb'} ne '') && (($perms{'opa'}) || ($perms{'vpa'}))) { &switch('','',7,3,'pparm.png','Content Settings','parms[_2]', "gocmd('/adm/parmset','set')", 'Content Settings'); @@ -759,7 +949,7 @@ sub innerregister { # # This applies to items inside a folder/page modifiable in the course. # - if (($env{'request.symb'}=~/^uploaded/) && ($perms{'mdc'})) { + if (($env{'request.symb'}=~/^uploaded/) && (($perms{'mdc'}) || ($perms{'cev'}))) { my $text = 'Edit Folder'; if (($mapurl =~ /\.page$/) || ($env{'request.symb'}=~ @@ -788,7 +978,11 @@ sub innerregister { if ($currdir =~ m-/$-) { $is_const_dir = 1; if ($thisdisfn eq '') { - $is_const_dir = 2; + unless (($env{'request.course.id'}) && + ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) && + ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) { + $is_const_dir = 2; + } } } else { $currdir =~ s|[^/]+$||; @@ -817,10 +1011,58 @@ ENDMENUITEMS # We are in a course and looking at a registered URL # Should probably be in mydesk.tab # - $menuitems=(<new(); + if (ref($navmap)) { + my $mapres = $navmap->getResourceByUrl($ltiuri); + if (ref($mapres)) { + if ($navmap->isLastResource($mapres,$env{'request.symb'})) { + $showforw = 0; + } + if ($navmap->isFirstResource($mapres,$env{'request.symb'})) { + $showback = 0; + } + } + } + if ($showback) { + $menuitems.=" +s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1"; + } + if ($showforw) { + $menuitems.=" +s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3"; + } + } elsif (($crstype ne 'Placement') || ($env{'request.role.adv'})) { + $menuitems.=" s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1 -s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3 +s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3"; + } else { +# Suppress display of backward arrow for Placement Tests +# Suppress display of forward arrow for Placement Tests if this is the last resource. + my $showforw = 1; + if ($env{'request.symb'}) { + my $navmap = Apache::lonnavmaps::navmap->new(); + if (ref($navmap)) { + if (&Apache::lonplacementtest::is_lastres($env{'request.symb'},$navmap)) { + $showforw = 0; + } + } + } + if ($showforw) { + $menuitems.=" +s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3"; + } + } + $menuitems .= (<[0]; } + $buttonshide = $pagebuttonshide; } else { $countdown = &countdown_timer(); + $buttonshide = &hidden_button_check(); } &Apache::lonhtmlcommon::clear_breadcrumb_tools(); &Apache::lonhtmlcommon::add_breadcrumb_tool( 'navigation', @inlineremote[21,23]); - if (&hidden_button_check() eq 'yes') { + if ($buttonshide eq 'yes') { if ($countdown) { &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$countdown); } + if ($showprogress) { + &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$showprogress); + } } else { my @tools = @inlineremote[93,91,81,82,83]; if ($countdown) { @@ -947,6 +1203,10 @@ ENDMENUITEMS } &advtools_crumbs(@inlineremote); } + } else { + if ($showprogress) { + &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$showprogress); + } } my ($topic_help,$topic_help_text); if ($is_const_dir == 2) { @@ -964,12 +1224,12 @@ ENDMENUITEMS } sub get_editbutton { - my ($cfile,$home,$switchserver,$forceedit,$forceview,$forcereg) = @_; + my ($cfile,$home,$switchserver,$forceedit,$forceview,$forcereg,$hostname) = @_; my $jscall; if (($forceview) && ($env{'form.todocs'})) { - my ($folderpath,$command); + my ($folderpath,$command,$navmap); if ($env{'request.symb'}) { - $folderpath = &Apache::loncommon::symb_to_docspath($env{'request.symb'}); + $folderpath = &Apache::loncommon::symb_to_docspath($env{'request.symb'},\$navmap); } elsif ($env{'form.folderpath'} =~ /^supplemental/) { $folderpath = $env{'form.folderpath'}; $command = '&forcesupplement=1'; @@ -977,11 +1237,16 @@ sub get_editbutton { $folderpath = &escape(&HTML::Entities::encode(&escape($folderpath),'<>&"')); $jscall = "go('/adm/coursedocs?folderpath=$folderpath$command')"; } else { + my $suppanchor; + if ($env{'form.folderpath'}) { + $suppanchor = $env{'form.anchor'}; + } $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver, $forceedit,$forcereg,$env{'request.symb'}, &escape($env{'form.folderpath'}), - &escape($env{'form.title'}),$env{'form.idx'}, - &escape($env{'form.suppurl'},$env{'form.todocs'})); + &escape($env{'form.title'}),$hostname, + $env{'form.idx'},&escape($env{'form.suppurl'}), + $env{'form.todocs'},$suppanchor); } if ($jscall) { my $icon = 'pcstr.png'; @@ -998,7 +1263,7 @@ sub get_editbutton { } sub prepare_functions { - my ($resurl,$forcereg,$group,$bread_crumbs,$advtools,$docscrumbs) = @_; + my ($resurl,$forcereg,$group,$bread_crumbs,$advtools,$docscrumbs,$hostname) = @_; unless ($env{'request.registered'}) { undef(@inlineremote); } @@ -1012,8 +1277,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'}); @@ -1044,17 +1310,31 @@ 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/}) || + (($resurl =~ m{^/?uploaded/$cdom/$cnum/default_\d+\.sequence$}) && ($env{'form.navmap'})))) { + if ($resurl =~ m{^/}) { + $cfile = $resurl; + } else { + $cfile = "/$resurl"; + } $home = &Apache::lonnet::homeserver($cnum,$cdom); if ($env{'form.forceedit'}) { $forceview = 1; } else { $forceedit = 1; } - $editbutton = &get_editbutton($cfile,$home,$switchserver, - $forceedit,$forceview,$forcereg); + if ($cfile =~ m{^/uploaded/$cdom/$cnum/default_\d+\.sequence$}) { + my $text = 'Edit Folder'; + &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]', + "gocmd('/adm/coursedocs','direct')", + 'Folder/Page Content'); + $editbutton = 1; + } else { + $editbutton = &get_editbutton($cfile,$home,$switchserver, + $forceedit,$forceview,$forcereg, + $hostname); + } } elsif (($resurl eq '/adm/extresedit') && (($env{'form.symb'}) || ($env{'form.folderpath'}))) { ($cfile,$home,$switchserver,$forceedit,$forceview) = @@ -1062,8 +1342,7 @@ sub prepare_functions { $env{'form.symb'}); if ($cfile ne '') { $editbutton = &get_editbutton($cfile,$home,$switchserver, - $forceedit,$forceview,$forcereg, - $env{'form.title'},$env{'form.suppurl'}); + $forceedit,$forceview,$forcereg); } } elsif (($resurl =~ m{^/?adm/viewclasslist$}) && (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) { @@ -1081,7 +1360,31 @@ sub prepare_functions { &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group); if ($cfile ne '') { $editbutton = &get_editbutton($cfile,$home,$switchserver, - $forceedit,$forceview,$forcereg); + $forceedit,$forceview,$forcereg, + $hostname); + } + 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'); + } } } } @@ -1131,17 +1434,25 @@ sub prepare_functions { if (($env{'form.folderpath'} =~ /^supplemental/) && (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) && (($resurl =~ m{^/adm/wrapper/ext/}) || - ($resurl =~ m{^/adm/$cdom/$cnum/\d+/exttools?$}) || + ($resurl =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) || ($resurl =~ m{^/uploaded/$cdom/$cnum/supplemental/}) || ($resurl eq '/adm/supplemental') || ($resurl =~ m{^/public/$cdom/$cnum/syllabus$}) || ($resurl =~ m{^/adm/$match_domain/$match_username/aboutme$}))) { my @folders=split('&',$env{'form.folderpath'}); if ((@folders > 2) || ($resurl ne '/adm/supplemental')) { + my $suppanchor; + if ($resurl =~ m{^/adm/wrapper/ext/}) { + $suppanchor = $env{'form.anchor'}; + } my $esc_path=&escape(&HTML::Entities::encode(&escape($env{'form.folderpath'}),'<>&"')); + my $link = '/adm/coursedocs?command=direct&forcesupplement=1&supppath='. + "$esc_path&anchor=$suppanchor"; + if ($env{'request.use_absolute'} ne '') { + $link = $env{'request.use_absolute'}.$link; + } &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]', - "location.href='/adm/coursedocs?command=direct&forcesupplement=1&supppath=$esc_path'", - 'Folder/Page Content'); + "location.href='$link'",'Folder/Page Content'); } } } @@ -1152,7 +1463,7 @@ sub prepare_functions { &advtools_crumbs(@inlineremote); return $editbutton; } elsif ($env{'request.registered'}) { - return $editbutton; + return $editbutton || $viewsrcbutton; } else { if (ref($bread_crumbs) eq 'ARRAY') { if (@inlineremote > 0) { @@ -1242,7 +1553,8 @@ sub switch { unless ($env{'request.state'} eq 'construct') { push(@tools,63); } - if (($env{'environment.icons'} eq 'iconsonly') && + if ((($env{'environment.icons'} eq 'iconsonly') || + ($env{'environment.icons'} eq '') && ($env{'request.lti.login'})) && (grep(/^$idx$/,@tools))) { $inlineremote[$idx] = ''.$pic.''; @@ -1501,7 +1813,7 @@ sub rawconfig { sub check_for_rcrs { my $showreqcrs = 0; - my @reqtypes = ('official','unofficial','community','textbook'); + my @reqtypes = ('official','unofficial','community','textbook','placement'); foreach my $type (@reqtypes) { if (&Apache::lonnet::usertools_access($env{'user.name'}, $env{'user.domain'}, @@ -1568,36 +1880,175 @@ END } # This creates a "done button" for timed events. The confirmation box is a jQuery -# dialog widget. Clicking OK will set (LC_interval_done = 'true') which is checked in -# lonhomework.pm. +# dialog widget. If the interval parameter requires a proctor key for the timed +# event to be marked done, there will also be a textbox where that can be entered. +# Clicking OK will set the value of LC_interval_done to 'true', and, if needed will +# set the value of LC_interval_done_proctorpass to the text entered in that box, +# and submit the corresponding form. +# +# The &zero_time() routine in lonhomework.pm is called when a page is rendered if +# LC_interval_done is true. +# sub done_button_js { - my ($type,$height) = @_; - if ($height !~ /^\d+$/) { - $height = 320; - } + my ($type,$width,$height,$proctor,$donebuttontext) = @_; + return unless (($type eq 'map') || ($type eq 'resource')); my %lt = &Apache::lonlocal::texthash( title => 'WARNING!', - button => 'Done', preamble => 'You are trying to end this timed event early.', map => 'Confirming that you are done will cause the time to expire and prevent you from changing any answers in the current folder.', resource => 'Confirming that you are done will cause the time to expire for this question, and prevent you from changing your answer(s).', - ok => 'Click "OK" if you are completely finished.', + okdone => 'Click "OK" if you are completely finished.', cancel => 'Click "Cancel" to continue working.', + proctor => 'Ask a proctor to enter the key, then click "OK" if you are completely finished.', + ok => 'OK', + exit => 'Cancel', + key => 'Key:', + nokey => 'A proctor key is required', ); - my $confirm; - if (($type eq 'map') || ($type eq 'resource')) { - $confirm = $lt{'preamble'}.' '.$lt{$type}.' '.$lt{'ok'}.' '.$lt{'cancel'}; + my $navmap = Apache::lonnavmaps::navmap->new(); + my ($missing,$tried) = (0,0); + if (ref($navmap)) { + my @resources=(); + if ($type eq 'map') { + my ($mapurl,$rid,$resurl)=&Apache::lonnet::decode_symb($env{'request.symb'}); + @resources=$navmap->retrieveResources($mapurl,sub { $_[0]->is_problem() }); + } else { + my $res = $navmap->getBySymb($env{'request.symb'}); + if (ref($res)) { + if ($res->is_problem()) { + push(@resources,$res); + } + } + } + foreach my $res (@resources) { + if (ref($res->parts()) eq 'ARRAY') { + foreach my $part (@{$res->parts()}) { + if (!$res->tries($part)) { + $missing++; + } else { + $tried++; + } + } + } + } } - if ($confirm) { + if ($missing) { + $lt{'miss'} .= '

    '; + if ($type eq 'map') { + $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,question part,question parts] in this folder.',$missing); + } else { + $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,part] in this question.',$missing); + } + if ($missing > 1) { + $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit answers for them.').''; + } else { + $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit an answer for it.').'

    '; + } + } + $donebuttontext = &HTML::Entities::encode($donebuttontext,'<>&"'); + if ($proctor) { + if ($height !~ /^\d+$/) { + $height = 400; + if ($missing) { + $height += 60; + } + } + if ($width !~ /^\d+$/) { + $width = 400; + if ($missing) { + $width += 60; + } + } + return < + + + + + +
    +

    $lt{'preamble'} $lt{$type}

    + $lt{'miss'} +

    $lt{'proctor'}

    +
    + + +
    +

    $lt{'cancel'}

    +
    + + + +END + } else { + if ($height !~ /^\d+$/) { + $height = 320; + if ($missing) { + $height += 60; + } + } + if ($width !~ /^\d+$/) { + $width = 320; + if ($missing) { + $width += 60; + } + } + if ($missing) { + $lt{'miss'} = '

    '.$lt{'miss'}.'

    '; + } return < - +

    -

    $confirm

    +

    $lt{'preamble'} $lt{$type} $lt{'miss'} $lt{'okdone'} $lt{'cancel'}

    END - } else { - return; } } sub utilityfunctions { my ($httphost) = @_; my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0])); - if ($currenturl =~ m{^/adm/wrapper/ext/} - && $env{'request.external.querystring'} ) { + my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'}); + if ($currenturl =~ m{^/adm/wrapper/ext/}) { + if ($env{'request.external.querystring'}) { $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'}; + } + my ($anchor) = ($env{'request.symb'} =~ /(\#[^\#]+)$/); + if (($anchor) && ($currenturl !~ /\Q$anchor\E$/)) { + $currenturl .= $1; + } } $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl)); - - my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'}); my $dc_popup_cid; if ($env{'user.adv'} && exists($env{'user.role.dc./'. @@ -1666,6 +2126,15 @@ sub utilityfunctions { my $countdown = &countdown_toggle_js(); + my $ltitarget; + if ($env{'request.lti.login'}) { + $ltitarget = $env{'request.lti.target'}; + } + + my $annotateurl = '/adm/annotation'; + if ($httphost) { + $annotateurl = '/adm/annotations'; + } my $hostvar = ' function setLCHost() { var lcHostname=""; @@ -1762,7 +2231,12 @@ function golist(url) { currentURL = null; currentSymb= null; var lcHostname = setLCHost(); - top.location.href=lcHostname+url; + var ltitarget = '$ltitarget'; + if (ltitarget == 'iframe') { + document.location.href=lcHostname+url; + } else { + top.location.href=lcHostname+url; + } } } @@ -1794,7 +2268,7 @@ function annotate() { annotator.document.write( '$start_page_annotate' +"
    " + +"action='$annotateurl'>" +"" +"<\\/form>" +'$end_page_annotate'); @@ -1815,6 +2289,24 @@ function open_StoredLinks_Import(rat) { newWin.focus(); } +function open_source() { + var url = escape(window.location.pathname); + sourcewin=window.open('/adm/source?inhibitmenu=yes&viewonly=1&filename='+url,'LONsource', + 'height=500,width=600,resizable=yes,location=no,menubar=no,toolbar=no,scrollbars=yes'); +} + +function open_aboutLC() { + var isMobile = "$env{'browser.mobile'}"; + var url = '/adm/about.html'; + if (isMobile == 1) { + openMyModal(url,600,400,'yes'); + } else { + window.open(url,"aboutLONCAPA","height=400,width=600,scrollbars=1,resizable=1,menubar=0,location=1"); + } + return; +} + + (function (\$) { \$(document).ready(function () { \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1])); @@ -1835,8 +2327,12 @@ ENDUTILITY } sub serverform { + my $target; + unless (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) { + $target = ' target="_top"'; + } return(< + @@ -1846,15 +2342,20 @@ ENDSERVERFORM } sub constspaceform { + my ($target,$printtarget); + unless (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) { + $target = ' target="_top"'; + $printtarget = ' target="_parent"'; + } return(< + -
    +
    -
    + @@ -1874,10 +2375,10 @@ sub hidden_button_check { } sub roles_selector { - my ($cdom,$cnum,$httphost) = @_; + my ($cdom,$cnum,$httphost,$ltitarget) = @_; my $crstype = &Apache::loncommon::course_type(); my $now = time; - my (%courseroles,%seccount,%courseprivs); + my (%courseroles,%seccount,%courseprivs,%roledesc); my $is_cc; my ($js,$form,$switcher); my $ccrole; @@ -1886,13 +2387,13 @@ sub roles_selector { } else { $ccrole = 'cc'; } - my ($priv,$gotsymb,$destsymb); + my ($privref,$gotsymb,$destsymb); my $destinationurl = $ENV{'REQUEST_URI'}; - if ($destinationurl =~ /\?symb=/) { + if ($destinationurl =~ /(\?|\&)symb=/) { $gotsymb = 1; } elsif ($destinationurl =~ m{^/enc/}) { my $plainurl = &Apache::lonenc::unencrypted($destinationurl); - if ($plainurl =~ /\?symb=/) { + if ($plainurl =~ /(\?|\&)symb=/) { $gotsymb = 1; } } @@ -1907,12 +2408,15 @@ sub roles_selector { my $destination = $destinationurl; $destination =~ s/(\?.*)$//; if (exists($reqprivs->{$destination})) { - $priv = $reqprivs->{$destination}; + if ($reqprivs->{$destination} =~ /,/) { + @{$privref} = split(/,/,$reqprivs->{$destination}); + } else { + $privref = [$reqprivs->{$destination}]; + } } } if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) { my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}); - if ((($start) && ($start<0)) || (($end) && ($end<$now)) || (($start) && ($now<$start))) { @@ -1922,7 +2426,9 @@ sub roles_selector { } } if ($is_cc) { - &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,$priv); + &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs); + } elsif ($env{'request.role'} =~ m{^\Qcr/$cdom/$cdom-domainconfig/\E(\w+)\.\Q/$cdom/$cnum\E}) { + &get_customadhoc_roles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,\%roledesc,$privref); } else { my %gotnosection; foreach my $item (keys(%env)) { @@ -1938,7 +2444,7 @@ sub roles_selector { $gotnosection{$role} = 1; } } - if ($priv ne '') { + if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0)) { my $cnumsec = $cnum; if ($sec ne '') { $cnumsec .= "/$sec"; @@ -1976,7 +2482,7 @@ sub roles_selector { } if ((keys(%seccount) > 1) || ($numdiffsec > 1)) { my @submenu; - $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,$priv); + $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,\%roledesc,$privref); $form = ''."\n". ' 0) { - $switcher = &create_submenu('','',&mt('Switch role'),\@submenu); + $switcher = &create_submenu('','',&mt('Switch role'),\@submenu,'','',$ltitarget); } } return ($js,$form,$switcher); @@ -2098,8 +2613,101 @@ sub get_all_courseroles { return; } +sub get_customadhoc_roles { + my ($cdom,$cnum,$courseroles,$seccount,$courseprivs,$roledesc,$privref) = @_; + unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') && + (ref($courseprivs) eq 'HASH') && (ref($roledesc) eq 'HASH')) { + return; + } + 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); + } + } 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; + } + ($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; + } + } + } + } + } + return; +} + sub jump_to_role { - my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$priv) = @_; + my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$roledesc,$privref) = @_; my %lt = &Apache::lonlocal::texthash( this => 'This role has section(s) associated with it.', ente => 'Enter a specific section.', @@ -2132,29 +2740,26 @@ sub jump_to_role { } } my $checkroles = 0; - if ($priv && ref($courseprivs) eq 'HASH') { - my (%disallowed,%allowed,@disallow); + if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0) && (ref($courseprivs) eq 'HASH')) { + my %disallowed; foreach my $role (sort(keys(%{$courseprivs}))) { my $trole; if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) { $trole = $1; } if (($trole ne '') && ($trole ne 'cm')) { - if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) { - $allowed{$trole} = 1; - } else { - $disallowed{$trole} = 1; + $disallowed{$trole} = 1; + foreach my $priv (@{$privref}) { + if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) { + delete($disallowed{$trole}); + last; + } } } } - foreach my $trole (keys(%disallowed)) { - unless ($allowed{$trole}) { - push(@disallow,$trole); - } - } - if (@disallow > 0) { + if (keys(%disallowed) > 0) { $checkroles = 1; - $js .= " var disallow = new Array('".join("','",@disallow)."');\n". + $js .= " var disallow = new Array('".join("','",keys(%disallowed))."');\n". " var rolecheck = 1;\n"; } } @@ -2251,13 +2856,13 @@ END sub required_privs { my $privs = { - '/adm/parmset' => 'opa', - '/adm/courseprefs' => 'opa', + '/adm/parmset' => 'opa,vpa', + '/adm/courseprefs' => 'opa,vpa', '/adm/whatsnew' => 'whn', - '/adm/populate' => 'cst', + '/adm/populate' => 'cst,vpa,vcl', '/adm/trackstudent' => 'vsa', - '/adm/statistics' => 'vgr', - '/adm/setblock' => 'dcm', + '/adm/statistics' => 'mgr,vgr', + '/adm/setblock' => 'dcm,vcb', '/adm/coursedocs' => 'mdc', }; unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') { @@ -2270,16 +2875,26 @@ sub required_privs { sub countdown_timer { if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') && - ($env{'request.filename'}=~/$LONCAPA::assess_re/)) { + (($env{'request.filename'}=~/$LONCAPA::assess_re/) || + (($env{'request.symb'} =~ /ext\.tool$/) && + (&Apache::lonnet::EXT('resource.0.gradable',$env{'request.symb'}) =~ /^yes$/i)))) { my ($type,$hastimeleft,$slothastime); my $now = time; if ($env{'request.filename'} =~ /\.task$/) { $type = 'Task'; + } elsif ($env{'request.symb'} =~ /ext\.tool$/) { + $type = 'tool'; } else { $type = 'problem'; } - my ($status,$accessmsg,$slot_name,$slot) = - &Apache::lonhomework::check_slot_access('0',$type); + my ($status,$accessmsg,$slot_name,$slot); + if ($type eq 'tool') { + ($status,$accessmsg,$slot_name,$slot) = + &Apache::lonhomework::check_slot_access('0',$type,$env{'request.symb'},['0']); + } else { + ($status,$accessmsg,$slot_name,$slot) = + &Apache::lonhomework::check_slot_access('0',$type); + } if ($slot_name ne '') { if (ref($slot) eq 'HASH') { if (($slot->{'starttime'} < $now) && @@ -2293,9 +2908,17 @@ sub countdown_timer { } my $duedate = &Apache::lonnet::EXT("resource.0.duedate"); my @interval=&Apache::lonnet::EXT("resource.0.interval"); - my ($timelimit,$usesdone); + my ($timelimit,$usesdone,$donebuttontext,$proctor,$secret); if (@interval > 1) { - ($timelimit,$usesdone) = split(/_/,$interval[0]); + ($timelimit,my $donesuffix) = split(/_/,$interval[0],2); + if ($donesuffix =~ /^done\:([^\:]+)\:(.*)$/) { + $usesdone = 'done'; + $donebuttontext = $1; + (undef,$proctor,$secret) = split(/_/,$2); + } elsif ($donesuffix =~ /^done(|_.+)$/) { + $donebuttontext = &mt('Done'); + ($usesdone,$proctor,$secret) = split(/_/,$donesuffix); + } my $first_access=&Apache::lonnet::get_first_access($interval[1]); if ($first_access > 0) { if ($first_access+$timelimit > time) { @@ -2313,7 +2936,7 @@ sub countdown_timer { $collapse = '► '; if ((@interval > 1) && ($hastimeleft)) { if ($usesdone eq 'done') { - $donebutton = &done_button_js($interval[1]); + $donebutton = &done_button_js($interval[1],'','',$proctor,$donebuttontext); } } } else { @@ -2342,6 +2965,13 @@ END return; } +sub placement_progress { + my ($totalpoints,$incomplete) = &Apache::lonplacementtest::check_completion(undef,undef,1); + my $complete = 100 - $incomplete; + return ''. + &mt('Test is [_1]% complete',$complete).''; +} + # ================================================================ Main Program BEGIN { @@ -2366,6 +2996,9 @@ BEGIN { } elsif ($configline=~/^scnd\:/) { my @entries = (split(/\:/, $configline))[1..5]; push(@secondary_menu,\@entries); + } elsif ($configline=~/^scndsub\:/) { + my ($parent,@entries) = (split(/\:/, $configline))[1..4]; + push(@{$secondary_submenu{$parent}},\@entries); } elsif ($configline) { push(@desklines,$configline); }