--- loncom/interface/lonmenu.pm 2012/12/07 17:15:56 1.398 +++ loncom/interface/lonmenu.pm 2012/12/28 17:12:49 1.405 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.398 2012/12/07 17:15:56 raeburn Exp $ +# $Id: lonmenu.pm,v 1.405 2012/12/28 17:12:49 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -326,16 +326,27 @@ sub secondary_menu { my $canmgr = &Apache::lonnet::allowed('mgr', $crs_sec); my $author = &getauthor(); + my ($canmodifycoauthor); + if ($env{'request.role'} eq "au./$env{'user.domain'}/") { + my $extent = "$env{'user.domain'}/$env{'user.name'}"; + if ((&Apache::lonnet::allowed('cca',$extent)) || + (&Apache::lonnet::allowed('caa',$extent))) { + $canmodifycoauthor = 1; + } + } + my %groups = &Apache::lonnet::get_active_groups( $env{'user.domain'}, $env{'user.name'}, $env{'course.' . $env{'request.course.id'} . '.domain'}, $env{'course.' . $env{'request.course.id'} . '.num'}); + my ($roleswitcher_js,$roleswitcher_form); + foreach my $menuitem (@secondary_menu) { # evaluate conditions next if ref($menuitem) ne 'ARRAY'; next if $$menuitem[4] ne 'always' - && $$menuitem[4] ne 'author' + && ($$menuitem[4] ne 'author' && $$menuitem[4] ne 'cca') && !$env{'request.course.id'}; next if $$menuitem[4] =~ /^mdc/ && !$canedit; @@ -360,15 +371,17 @@ sub secondary_menu { && !%groups; next if $$menuitem[4] eq 'author' && !$author; + next if $$menuitem[4] eq 'cca' + && !$canmodifycoauthor; if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) { # special treatment for role selector - my $roles_selector = &roles_selector( + ($roleswitcher_js,$roleswitcher_form,my $switcher) = + &roles_selector( $env{'course.' . $env{'request.course.id'} . '.domain'}, - $env{'course.' . $env{'request.course.id'} . '.num'} ); - - $menu .= $roles_selector ? "<li>$roles_selector</li>" - : ''; + $env{'course.' . $env{'request.course.id'} . '.num'} + ); + $menu .= $switcher; } else { $menu .= &prep_menuitem(\@$menuitem); } @@ -396,6 +409,9 @@ sub secondary_menu { if ($menu) { $menu = "<ul id=\"LC_secondary_menu\">$menu</ul>"; } + if ($roleswitcher_form) { + $menu .= "\n$roleswitcher_js\n$roleswitcher_form"; + } return $menu; } @@ -487,8 +503,7 @@ sub innerregister { } my $trail; if ($env{'form.folderpath'}) { - my $editbutton = - &prepare_functions($resurl,$forcereg,$group,undef,undef,1); + &prepare_functions($resurl,$forcereg,$group,undef,undef,1); ($trail) = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1); } else { @@ -525,7 +540,7 @@ sub innerregister { $editbutton = &prepare_functions($resurl,$forcereg,$group); } if ($editbutton eq '') { - &clear(6,1); + $editbutton = &clear(6,1); } # @@ -860,7 +875,8 @@ sub prepare_functions { $forceedit,$forceview,$forcereg, $env{'form.title'},$env{'form.suppurl'}); } - } elsif ($resurl !~ m{^adm/($match_domain)/($match_username)/aboutme$}) { + } elsif (($resurl !~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) && + ($resurl ne '/cgi-bin/printout.pl')) { if ($env{'request.filename'}) { my $file=&Apache::lonnet::declutter($env{'request.filename'}); ($cfile,$home,$switchserver,$forceedit,$forceview) = @@ -1570,7 +1586,7 @@ sub roles_selector { my $now = time; my (%courseroles,%seccount,%courseprivs); my $is_cc; - my $role_selector; + my ($js,$form,$switcher,$switchtext); my $ccrole; if ($crstype eq 'Community') { $ccrole = 'co'; @@ -1658,42 +1674,70 @@ sub roles_selector { } } } - my $switchtext; if ($crstype eq 'Community') { - $switchtext = &mt('Switch community role to...') + $switchtext = &mt('Switch community role') } else { - $switchtext = &mt('Switch course role to...') + $switchtext = &mt('Switch course role') } my @roles_order = ($ccrole,'in','ta','ep','ad','st'); - if (keys(%courseroles) > 1) { - $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,$priv); - $role_selector .= '<form name="rolechooser" method="post" action="/adm/roles"> - <select name="switchrole" onchange="javascript:adhocRole('."'switchrole'".')">'; - $role_selector .= '<option value="">'.$switchtext.'</option>'; + my $numdiffsec; + if (keys(%seccount) == 1) { + foreach my $key (keys(%seccount)) { + $numdiffsec = $seccount{$key}; + } + } + if ((keys(%seccount) > 1) || ($numdiffsec > 1)) { + my @submenu; + $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,$priv); + $form = + '<form name="rolechooser" method="post" action="/adm/roles">'."\n". + ' <input type="hidden" name="destinationurl" value="'. + &HTML::Entities::encode($destinationurl).'" />'."\n". + ' <input type="hidden" name="gotorole" value="1" />'."\n". + ' <input type="hidden" name="selectrole" value="" />'."\n". + ' <input type="hidden" name="switchrole" value="" />'."\n"; + if ($destsymb ne '') { + $form .= ' <input type="hidden" name="destsymb" value="'. + &HTML::Entities::encode($destsymb).'" />'."\n"; + } + $form .= '</form>'."\n"; foreach my $role (@roles_order) { + my $include; if (defined($courseroles{$role})) { - $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role,$crstype).'</option>'; + if ($env{'request.role'} =~ m{^\Q$role\E}) { + if ($seccount{$role} > 1) { + $include = 1; + } + } else { + $include = 1; + } + } + if ($include) { + push(@submenu,['javascript:adhocRole('."'$role'".')', + &Apache::lonnet::plaintext($role,$crstype)]); } } foreach my $role (sort(keys(%courseroles))) { if ($role =~ /^cr/) { - $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>'; + my $include; + if ($env{'request.role'} =~ m{^\Q$role\E}) { + if ($seccount{$role} > 1) { + $include = 1; + } + } else { + $include = 1; + } + if ($include) { + push(@submenu,['javascript:adhocRole('."'$role'".')', + &Apache::lonnet::plaintext($role)]); + } } } - $role_selector .= '</select>'."\n"; - if ($destsymb ne '') { - $role_selector .= '<input type="hidden" name="destsymb" value="'. - &HTML::Entities::encode($destsymb).'" />'."\n"; + if (@submenu > 0) { + $switcher = &create_submenu('','',$switchtext,\@submenu); } - $role_selector .= - '<input type="hidden" name="destinationurl" value="'. - &HTML::Entities::encode($destinationurl).'" />'."\n". - '<input type="hidden" name="gotorole" value="1" />'."\n". - '<input type="hidden" name="selectrole" value="" />'."\n". - '<input type="hidden" name="switch" value="1" />'."\n". - '</form>'; } - return $role_selector; + return ($js,$form,$switcher); } sub get_all_courseroles { @@ -1832,9 +1876,8 @@ sub jump_to_role { return <<"END"; <script type="text/javascript"> //<![CDATA[ -function adhocRole(roleitem) { +function adhocRole(newrole) { $js - var newrole = document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value; if (newrole == '') { return; } @@ -1851,7 +1894,6 @@ function adhocRole(roleitem) { if (confirm("$lt{'role'}\\n$lt{'swit'}")) { document.rolechooser.destinationurl.value = '/adm/menu'; } else { - document.rolechooser.elements[roleitem].selectedIndex = 0; return; } } @@ -1887,21 +1929,19 @@ function adhocRole(roleitem) { fullrole += '/'+secchoice; } } else { - document.rolechooser.elements[roleitem].selectedIndex = 0; if (secchoice != null) { alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}"); } return; } if (fullrole == "$env{'request.role'}") { - document.rolechooser.elements[roleitem].selectedIndex = 0; return; } itemid = retrieveIndex('gotorole'); if (itemid != -1) { document.rolechooser.elements[itemid].name = fullrole; } - document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value = fullrole; + document.rolechooser.switchrole.value = fullrole; document.rolechooser.selectrole.value = '1'; document.rolechooser.submit(); return; @@ -2023,13 +2063,13 @@ BEGIN { $category_names{$entries[2]}=$entries[3]; } elsif ($configline=~/^prim\:/) { my @entries = (split(/\:/, $configline))[1..5]; - push @primary_menu, \@entries; + push(@primary_menu,\@entries); } elsif ($configline=~/^primsub\:/) { my ($parent,@entries) = (split(/\:/, $configline))[1..4]; - push (@{$primary_submenu{$parent}},\@entries); + push(@{$primary_submenu{$parent}},\@entries); } elsif ($configline=~/^scnd\:/) { my @entries = (split(/\:/, $configline))[1..5]; - push @secondary_menu, \@entries; + push(@secondary_menu,\@entries); } elsif ($configline) { push(@desklines,$configline); }