--- loncom/interface/lonmenu.pm 2010/11/08 22:51:23 1.309.2.18 +++ loncom/interface/lonmenu.pm 2010/03/03 21:33:15 1.315 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.309.2.18 2010/11/08 22:51:23 raeburn Exp $ +# $Id: lonmenu.pm,v 1.315 2010/03/03 21:33:15 droeschl Exp $ # # Copyright Michigan State University Board of Trustees # @@ -42,17 +42,72 @@ Coordinates the response to clicking an This is part of the LearningOnline Network with CAPA project described at http://www.lon-capa.org. +=head1 GLOBAL VARIABLES + +=over + +=item @desklines + +Each element of this array contains a line of mydesk.tab that doesn't start with +cat, prim or scnd. +It gets filled in the BEGIN block of this module. + +=item %category_names + +The keys of this hash are the abbreviations used in mydesk.tab in those lines that +start with cat, the values are strings representing titles. +It gets filled in the BEGIN block of this module. + +=item %category_members + +TODO + +=item %category_positions + +The keys of this hash are the abbreviations used in mydesk.tab in those lines that +start with cat, its values are position vectors (column, row). +It gets filled in the BEGIN block of this module. + +=item $readdesk + +Indicates that mydesk.tab has been read. +It is set to 'done' in the BEGIN block of this module. + +=item @primary_menu + +The elements of this array reference arrays that are made up of the components +of those lines of mydesk.tab that start with prim. +It is used by primary_menu() to generate the corresponding menu. +It gets filled in the BEGIN block of this module. + +=item @secondary_menu + +The elements of this array reference arrays that are made up of the components +of those lines of mydesk.tab that start with scnd. +It is used by secondary_menu() to generate the corresponding menu. +It gets filled in the BEGIN block of this module. + +=back + =head1 SUBROUTINES =over -Little texts +=item prep_menuitems(\@menuitem) + +This routine wraps a menuitem in proper HTML. It is used by primary_menu() and +secondary_menu(). + +=item primary_menu() -=item initlittle() +This routine evaluates @primary_menu and returns XHTML for the menu +that contains following links: About, Message, Roles, Help, Logout +@primary_menu is filled within the BEGIN block of this module with +entries from mydesk.tab -=item menubuttons() +=item secondary_menu() -This gets called at the top of the body section +Same as primary_menu() but operates on @secondary_menu. =item show_return_link() @@ -131,7 +186,6 @@ use Apache::lonhtmlcommon(); use Apache::loncommon(); use Apache::lonenc(); use Apache::lonlocal; -use Apache::loncoursequeueadmin; use LONCAPA qw(:DEFAULT :match); use HTML::Entities(); @@ -164,8 +218,6 @@ sub prep_menuitem { # entries from mydesk.tab sub primary_menu { my $menu; - my $custommenu = &Apache::loncommon::needs_gci_custom(); - my $numdc = &Apache::loncommon::check_for_gci_dc(); # each element of @primary contains following array: # (link url, icon path, alt text, link text, condition) foreach my $menuitem (@primary_menu) { @@ -181,17 +233,6 @@ sub primary_menu { next if $$menuitem[4] eq 'onlypublic'# hide links which are && $env{'user.name'} ne 'public' # only visible to public && $env{'user.domain'} ne 'public'; # users - next if $$menuitem[4] eq 'gci' - && (!$custommenu || $env{'request.role'} =~ m{^st\./gcitest/}); - next if $$menuitem[4] eq 'home' - && (($custommenu) || ($env{'user.domain'} eq 'gcitest') || - (($env{'user.domain'} eq 'gci') && !$numdc)); - next if $$menuitem[4] eq 'gcitest' - && (($env{'user.domain'} eq 'gci') || ($env{'request.role'} eq 'cm')); - next if $$menuitem[4] eq 'roles' # hide links which are - && $custommenu; # not visible when GCI - next if $$menuitem[4] eq 'courses' # tabbed interface in use - && $custommenu; # 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 @@ -224,16 +265,10 @@ sub secondary_menu { $env{'user.domain'}, $env{'user.name'}, $env{'course.' . $env{'request.course.id'} . '.domain'}, $env{'course.' . $env{'request.course.id'} . '.num'}); - my $custommenu = &Apache::loncommon::needs_gci_custom(); - my $numdc = &Apache::loncommon::check_for_gci_dc(); - my $role = $env{'request.role'}; foreach my $menuitem (@secondary_menu) { # evaluate conditions next if ref($menuitem) ne 'ARRAY'; - next if $$menuitem[4] eq 'showmenu' - && ($custommenu || (!$numdc && $role eq 'cm')); - next if $$menuitem[4] ne 'showmenu' - && $$menuitem[4] ne 'author' + next if $$menuitem[4] ne 'always' && !$env{'request.course.id'}; next if $$menuitem[4] eq 'showreturn' && !$showlink @@ -255,9 +290,8 @@ sub secondary_menu { next if $$menuitem[4] =~ /showgroups$/ && !$canviewgrps && !%groups; - next if $$menuitem[4] eq 'showroles' - && ($custommenu || !$numdc || ($numdc && $env{'request.noversionuri'} eq '/adm/roles')); - if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'} && !$custommenu) { + + if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) { # special treatment for role selector my $roles_selector = &roles_selector( $env{'course.' . $env{'request.course.id'} . '.domain'}, @@ -301,249 +335,7 @@ sub secondary_menu { return ""; } -sub gci_secondary_menu { - my %courses = ( - 'review' => 'gci_9615072b469884921gcil1', - 'submit' => 'gci_1H96711d710194bfegcil1', - 'tutorial' => 'gci_5422913620b814c90gcil1', - ); - my %linktext = ( - 'review' => 'Review Questions', - 'submit' => 'Submit Questions', - 'managetest' => 'Manage Tests', - 'tutorial' => 'Tutorials', - ); - my %links = ( - 'managetest' => '/adm/menu', - ); - my $current = 'managetest'; - if ($env{'form.destinationurl'} eq '/adm/gci_info') { - undef($current); - } - foreach my $key (keys(%courses)) { - $links{$key} = "javascript:switchpage('$key');"; - if ($env{'request.course.id'} eq $courses{$key}) { - if ($env{'environment.remotenavmap'} eq 'on') { - $links{$key} = "javascript:gonav('/adm/navmaps')"; - } else { - $links{$key} = '/adm/navmaps'; - } - $current = $key; - $links{'managetest'} = '/adm/roles?selectrole=1&cm=1&orgurl=%2fadm%2fmenu'; - } - } - my @menutabs = ('review','submit','managetest','tutorial'); - my $tabs; - foreach my $item (@menutabs) { - if ($item eq $current) { - $tabs .= '
  • '. - $linktext{$item}.'
  • '; - } else { - $tabs .= '
  • '. - $linktext{$item}.'
  • '; - } - } - return '
    '. - '

    '; -} - -# -# This routine returns a translated hash for the menu items in the top inline menu row -# Probably should be in mydesk.tab - -#SD this sub is deprecated - don't use it -sub initlittle { - return &Apache::lonlocal::texthash('ret' => 'Return to Last Location', - 'nav' => 'Course Contents', - 'main' => 'Main Menu', - 'roles' => (&Apache::loncommon::show_course()? - 'Courses':'Roles'), - 'other' => 'Other Roles', - 'docs' => 'Edit Course', - 'exit' => 'Logout', - 'login' => 'Log In', - 'launch' => 'Launch Remote Control', - 'groups' => 'Groups', - 'gdoc' => 'Community Documents', - ); -} - -#SD this sub is deprecated - don't use it -#SD functionality is covered by new loncommon::bodytag and primary_menu(), secondary_menu() -sub menubuttons { - my $forcereg=shift; - my $titletable=shift; -# -# Early-out for pages that should not have a menu, triggered by query string "inhibitmenu=yes" -# - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['inhibitmenu']); - if (($env{'form.inhibitmenu'} eq 'yes') || - ($ENV{'REQUEST_URI'} eq '/adm/logout')) { return ''; } - - if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; } - - my %lt=&initlittle(); - my $navmaps=''; - my $reloadlink=''; - my $docs=''; - my $groups=''; - my $roles=''.$lt{'roles'}.''; - my $role_selector; - my $showgroups=0; - my ($cnum,$cdom); -# -# if the URL is hidden, symbs and the non-versioned version of the URL would be encrypted -# - my $escurl=&escape(&Apache::lonenc::check_encrypt($env{'request.noversionuri'})); - my $escsymb=&escape(&Apache::lonenc::check_encrypt($env{'request.symb'})); - - my $logo=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/minilogo.gif"); - $logo = 'LON-CAPA Logo'; - - if ($env{'request.state'} eq 'construct') { -# -# We are in construction space -# - if (($env{'request.noversionuri'} eq '') || (!defined($env{'request.noversionuri'}))) { - my $returnurl = $env{'request.filename'}; - $returnurl =~ s:^/home/([^/]+)/public_html/(.*)$:/priv/$1/$2:; - $escurl = &escape($returnurl); - } - } - if ($env{'request.course.id'}) { -# -# We are in a course -# - $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; - $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; - my %coursegroups; - my $viewgrps_permission = - &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')); - if (!$viewgrps_permission) { - %coursegroups = &Apache::lonnet::get_active_groups($env{'user.domain'},$env{'user.name'},$cdom,$cnum); - } - if ((keys(%coursegroups) > 0) || ($viewgrps_permission)) { - $showgroups = 1; - } - $role_selector = &roles_selector($cdom,$cnum); - if ($role_selector) { - $roles = ''.$role_selector.'  '.$lt{'other'}.''; - } - } - - if ($env{'environment.remote'} eq 'off') { -# Remote Control is switched off -# figure out colors - my %lt=&initlittle(); - - my $domain=&Apache::loncommon::determinedomain(); - my $function=&Apache::loncommon::get_users_function(); - my $link=&Apache::loncommon::designparm($function.'.link',$domain); - my $alink=&Apache::loncommon::designparm($function.'.alink',$domain); - my $vlink=&Apache::loncommon::designparm($function.'.vlink',$domain); - my $sidebg=&Apache::loncommon::designparm($function.'.sidebg',$domain); - - if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') { - return (< -
  • $logo
  • -
  • $lt{'login'}
  • - -
    -ENDINLINEMENU - } - $roles = ''.$lt{'roles'}.''; -# Do we have a NAV link? - if ($env{'request.course.id'}) { - my $link='/adm/navmaps?postdata='.$escurl.'&postsymb='. - $escsymb; - if ($env{'environment.remotenavmap'} eq 'on') { - $link="javascript:gonav('".$link."')"; - } - $navmaps=(<$lt{'nav'} -ENDNAV - my $is_community = - (&Apache::loncommon::course_type() eq 'Community'); - if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) { - my $text = ($is_community) ? $lt{'gdoc'} : $lt{'docs'}; - $docs=(<$text -ENDDOCS - } - if ($showgroups) { - $groups =(<$lt{'groups'} -ENDGROUPS - } - if (&show_return_link()) { - my $escreload=&escape('return:'); - $reloadlink=(<$lt{'ret'} -ENDRELOAD - } - if ($role_selector) { - #$roles = ''.$role_selector.''.$lt{'other'}.''; - $role_selector = '
  • '.$role_selector.'
  • '; - } - } - if (($env{'request.state'} eq 'construct') && ($env{'request.course.id'})) { - my $escreload=&escape('return:'); - $reloadlink=(<$lt{'ret'} -ENDCRELOAD - } - my $reg = $forcereg ? &innerregister($forcereg,$titletable) : ''; - my $form = &serverform(); - my $utility = &utilityfunctions(); - - #Prepare the message link that indicates the arrival of new mail - my $messagelink = &Apache::lonmsg::mynewmail() ? "Message (new)" : "Message"; - $messagelink = '' - . mt($messagelink) .''; - - my $helplink = &Apache::loncommon::top_nav_help('Help'); - return (< -// - -
      -
    1. $logo
    2. -
    3. $messagelink
    4. -
    5. $roles
    6. -
    7. $helplink
    8. -
    9. $lt{'exit'}
    10. -
    -
      -
    • $lt{'main'}
    • -$reloadlink -$navmaps -$docs -$groups -$role_selector -
    -$form - -$reg -ENDINLINEMENU - } else { - return ''; - } -} - sub show_return_link { - return unless ($env{'request.course.id'}); - if (($env{'request.noversionuri'} =~ m{^/adm/(viewclasslist|navmaps)($|\?)}) - || ($env{'request.noversionuri'} =~ m{^/adm/.*/aboutme($|\?)})) { - return if ($env{'form.register'}); - } return (($env{'request.noversionuri'}=~m{^/(res|public)/} && $env{'request.symb'} eq '') || @@ -552,7 +344,7 @@ sub show_return_link { (($env{'request.noversionuri'}=~/^\/adm\//) && ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) && ($env{'request.noversionuri'}!~ - m[^/adm/.*/(smppg|bulletinboard)($|\?)]) + m[^/adm/.*/(smppg|bulletinboard|aboutme)($|\?)]) )); } @@ -625,17 +417,9 @@ sub innerregister { } else { $contentstext = &mt('Course Contents'); } - my @crumbs; - unless (($forcereg) && ($env{'request.noversionuri'} eq '/adm/navmaps') - && ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) { - my $link = "javascript:gopost('/adm/navmaps','')"; - if ($env{'environment.remotenavmap'} eq 'on') { - $link = "javascript:gonav('/adm/navmaps','')" - } - @crumbs = ({text => Apache::loncommon::course_type() - . ' Contents', - href => $link}); - } + my @crumbs = ({text => $contentstext, + href => "Javascript:gonav('/adm/navmaps')"}); + if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) { push(@crumbs, {text => '...', no_mt => 1}); @@ -879,7 +663,7 @@ $menuitems.="Make notes and annotations "&go('/adm/requestcourse')&Course requests\n"; } } - unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|portfolio)(\?|$)/) { + unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) { if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/})) { $menuitems.=(< @@ -1405,172 +1187,36 @@ sub openmenu { } sub inlinemenu { - my ($context) = @_; undef(@inlineremote); undef(%category_members); - my $output; - if ($context eq 'gcicustom') { - my (%can_request,%request_domains,$canreq,$createtext); - my $role = 'st'; - my $custommenu = &Apache::loncommon::needs_gci_custom(); - if ($custommenu) { - $role = 'cc'; - } - my %courses = &Apache::loncommon::existing_gcitest_courses($role); - my $numcourses = keys(%courses); - my ($switcher_js,$switcher); - my $formname = 'testpicker'; - if ($numcourses > 0) { - $switcher = &Apache::loncommon::gcitest_switcher($role,$formname,%courses); - my $current; - my $cid = $env{'request.course.id'}; - if ($cid) { - $current = $role.'./'.$env{'course.'.$cid.'.domain'}. - '/'.$env{'course.'.$cid.'.num'}; - } - $switcher_js = &Apache::loncommon::gcitest_switcher_js($current,$numcourses,$formname); - if ($switcher_js) { - $switcher_js= <<"ENDSCRIPT"; - - -ENDSCRIPT - } - $switcher = $switcher_js.$switcher; - } - if ($env{'user.domain'} eq 'gci') { - $canreq = - &Apache::lonnet::check_can_request('gcitest',\%can_request,\%request_domains); - $createtext = &mt('Create Concept Test'); - if ($numcourses) { - $createtext = &mt('Create New Test'); +# calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control + &rawconfig(1); + my $output=''; + for (my $col=1; $col<=2; $col++) { + $output.='"; } + $output.="
    '; + for (my $row=1; $row<=8; $row++) { + foreach my $cat (keys(%category_members)) { + if ($category_positions{$cat} ne "$col,$row") { next; } + #$output.=''; + $output.='
    '; + $output.='

    '.&mt($category_names{$cat}).'

    '; + $output.='
    '.&mt($category_names{$cat}).'
    '; + my %active=(); + foreach my $menu_item (split(/\:/,$category_members{$cat})) { + if ($inlineremote[$menu_item]) { + $active{$menu_item}=1; + } + } + foreach my $item (sort(keys(%active))) { + $output.=$inlineremote[$item]; + } + $output.='
    '; + $output.=''; } - } - if ($env{'request.course.id'}) { - if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) { - my $navlink; - if ($env{'environment.remotenavmap'} eq 'on') { - $navlink = "javascript:gonav('/adm/navmaps')"; - } else { - $navlink = '/adm/navmaps'; - } - $output .= - '


    '; - } else { - my $navtext = &mt('Table of Contents'); - my $navdesc = &mt('Display Table of Contents for Geoscience Concept Inventory'); - if ($env{'request.role.domain'} eq 'gcitest') { - $navtext = &mt('Display Test Contents'); - $navdesc = &mt('Display the table of contents for this Concept Test'); - } - my $navlink; - if ($env{'environment.remotenavmap'} eq 'on') { - $navlink = "javascript:gonav('/adm/navmaps');" - } else { - $navlink = '/adm/navmaps'; - } - $output .= - '
    '. - '

    '.&mt('Utilities').'

    '. - ''; - if ($canreq) { - $output .= '
    '. - '
    '. - '
    '.$createtext.'
    '. - '
    '.&mt('Create a new Concept Test Course Container').'. '.&mt('Choose GCI questions to include in the test and upload a student roster.').'
    '; - } - $output .= '

    '; - } - } elsif ($switcher || $canreq) { - $output .= '

    '. - '
    '. - '

    '.&mt('Utilities').'

    '. - ''; - if ($switcher) { - $output .= '
    '. - '
    '; - } - } - if ($switcher) { - $output .= '
    '.&mt('Select Concept Test').'
    '. - '
    '.$switcher.'

    '; - } - $output .= '

    '; - } - } elsif ($context eq 'gcinorole') { - my $queued = &Apache::loncoursequeueadmin::queued_selfenrollment('notitle'); - if ($queued) { - $output .= - '
    '. - '

    '.&mt('Pending Enrollment Requests').'

    '. - $queued. - '
    '; - } - } else { - # calling rawconfig with "1" will evaluate mydesk.tab, - # even if there is no active remote control - &rawconfig(1); - $output=''; - for (my $col=1; $col<=2; $col++) { - $output.='"; - } - $output.="
    '; - for (my $row=1; $row<=8; $row++) { - foreach my $cat (keys(%category_members)) { - if ($category_positions{$cat} ne "$col,$row") { next; } - $output.='
    '; - $output.='

    '.&mt($category_names{$cat}).'

    '; - $output.=''; - my %active=(); - foreach my $menu_item (split(/\:/,$category_members{$cat})) { - if ($inlineremote[$menu_item]) { - $active{$menu_item}=1; - } - } - foreach my $item (sort(keys(%active))) { - $output.=$inlineremote[$item]; - } - $output.='
    '; - $output.='
    '; - } - } - $output.="
    "; + } + $output.="
    "; return $output; } @@ -1865,54 +1511,11 @@ END } sub utilityfunctions { - my ($caller,$custommenu) = @_; + my $caller = shift; unless ($env{'environment.remote'} eq 'off' || $caller eq '/adm/menu') { return ''; } - - my $gcimenujs; - if ($custommenu) { - my %concepttests = &Apache::loncommon::existing_gcitest_courses('cc'); - my $managetesturl = '/adm/menu'; - my $createtesturl = '/adm/requestcourse'; - if (($env{'request.course.id'}) && - ($env{'course.'.$env{'request.course.id'}.'.domain'} eq 'gci')) { - my @items = keys(%concepttests); - if (@items== 1) { - my $newrole = $items[0]; - $newrole =~ s{_}{/}; - $managetesturl = '/adm/roles?selectrole=1&cc./'.$newrole.'=1'; - } else { - $managetesturl = '/adm/roles?selectrole=1&cm=1&orgurl=%2fadm%2fmenu'; - } - } - if ($env{'request.course.id'}) { - $createtesturl = '/adm/roles?selectrole=1&cm=1&orgurl=%2fadm%2frequestcourse'; - } - $gcimenujs = <<"ENDCUSTOM"; - -function switchpage(caller) { - if (caller == 'review') { - document.location.href = '/adm/roles?selectrole=1&st./gci/9615072b469884921gcil1=1'; - } - if (caller == 'submit') { - document.location.href = '/adm/roles?selectrole=1&st./gci/1H96711d710194bfegcil1=1'; - } - if (caller == 'createtest') { - document.location.href = '$createtesturl'; - } - if (caller == 'managetest') { - document.location.href = '$managetesturl'; - } - if (caller == 'tutorial') { - document.location.href = '/adm/roles?selectrole=1&st./gci/5422913620b814c90gcil1=1'; - } - return; -} - -ENDCUSTOM - } - + my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0])); if ($currenturl =~ m{^/adm/wrapper/ext/}) { if ($env{'request.external.querystring'}) { @@ -1960,8 +1563,6 @@ return (<