--- loncom/interface/lonmenu.pm 2010/09/03 19:20:47 1.309.2.15 +++ loncom/interface/lonmenu.pm 2010/12/07 04:33:49 1.309.2.24 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.309.2.15 2010/09/03 19:20:47 raeburn Exp $ +# $Id: lonmenu.pm,v 1.309.2.24 2010/12/07 04:33:49 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -151,7 +151,10 @@ sub prep_menuitem { } else { # textual Link $link = &mt($$menuitem[3]); } - return '
  • '.$link.'
  • '; + return '
  • $link
  • |; } # primary_menu() evaluates @primary_menu and returns XHTML for the menu @@ -162,8 +165,17 @@ sub prep_menuitem { sub primary_menu { my $menu; my $custommenu = &Apache::loncommon::needs_gci_custom(); + my $numdc = &Apache::loncommon::check_for_gci_dc(); + my %allnums = &Apache::loncommon::get_faculty_cnums(); # each element of @primary contains following array: # (link url, icon path, alt text, link text, condition) + my ($public,$faculty); + if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) + || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) { + $public = 1; + } elsif (ref($allnums{$env{'user.domain'}}) eq 'HASH') { + $faculty = 1; + } foreach my $menuitem (@primary_menu) { # evaluate conditions next if ref($menuitem) ne 'ARRAY'; # @@ -172,11 +184,18 @@ sub primary_menu { next if $$menuitem[4] eq 'newmsg' # arrived or not && !&Apache::lonmsg::mynewmail(); # next if $$menuitem[4] !~ /public/ ##we've a public user, - && $env{'user.name'} eq 'public' ##who should not see all - && $env{'user.domain'} eq 'public'; ##links + && $public; ##who should not see all + ##links 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 + && !$public; # only visible to public + # users + next if $$menuitem[4] eq 'ci' + && (!$custommenu || $env{'request.role'} =~ m{^st\./\w+citest/}); + next if $$menuitem[4] eq 'home' + && (($custommenu) || ($env{'user.domain'} =~ /^\w+citest$/) || + ($faculty && !$numdc)); + next if $$menuitem[4] eq 'citest' + && ($faculty || ($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 @@ -188,11 +207,20 @@ sub primary_menu { if ($$menuitem[3] eq 'Help') { # special treatment for helplink - $menu .= '
  • '.&Apache::loncommon::top_nav_help('Help').'
  • '; + if ($public) { + my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'}; + my $defdom = &Apache::lonnet::default_login_domain(); + my $to = &Apache::loncommon::build_recipient_list(undef, + 'helpdeskmail', + $defdom,$origmail); + if ($to ne '') { + $menu .= &prep_menuitem($menuitem); + } + } else { + $menu .= '
  • '.&Apache::loncommon::top_nav_help('Help').'
  • '; + } } else { - my @items = @{$menuitem}; - $items[0] = 'javascript:'.$menuitem->[0].';'; - $menu .= &prep_menuitem(\@items); + $menu .= &prep_menuitem($menuitem); } } @@ -213,10 +241,16 @@ 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] ne 'always' + next if $$menuitem[4] eq 'showmenu' + && ($custommenu || (!$numdc && $role eq 'cm')); + next if $$menuitem[4] ne 'showmenu' + && $$menuitem[4] ne 'author' && !$env{'request.course.id'}; next if $$menuitem[4] eq 'showreturn' && !$showlink @@ -238,8 +272,9 @@ sub secondary_menu { next if $$menuitem[4] =~ /showgroups$/ && !$canviewgrps && !%groups; - - if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) { + 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) { # special treatment for role selector my $roles_selector = &roles_selector( $env{'course.' . $env{'request.course.id'} . '.domain'}, @@ -284,40 +319,63 @@ sub secondary_menu { } sub gci_secondary_menu { - my %courses = ( - 'review' => 'gci_9615072b469884921gcil1', - 'submit' => 'gci_1H96711d710194bfegcil1', - 'tutorial' => 'gci_5422913620b814c90gcil1', - ); + my %courses; + my $inventory; + if ($env{'user.domain'} =~ /^(\w+ci)test$/) { + $inventory = $1; + } else { + $inventory = $env{'user.domain'}; + } + my %allnums = &Apache::loncommon::get_faculty_cnums(); + if (($inventory ne '') && (ref($allnums{$inventory}) eq 'HASH')) { + foreach my $key (keys(%{$allnums{$inventory}})) { + $courses{$key} = $inventory.'_'.$allnums{$inventory}->{$key}; + } + } + 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') { + my (%links,@menutabs,$current,%can_request,%request_domains); + my %concepttests = &Apache::loncommon::existing_gcitest_courses('cc'); + my $canreq = &Apache::lonnet::check_can_request($env{'user.domain'}.'test', + \%can_request,\%request_domains); + if (($canreq) || (keys(%concepttests) > 0)) { + %links = ( + 'managetest' => '/adm/menu', + ); + $current = 'managetest'; + } + if ($env{'form.destinationurl'} eq '/adm/ci_info') { undef($current); } foreach my $key (keys(%courses)) { $links{$key} = "javascript:switchpage('$key');"; if ($env{'request.course.id'} eq $courses{$key}) { - $links{$key} = '/adm/navmaps'; + 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'; + if (($canreq) || (keys(%concepttests) > 0) { + $links{'managetest'} = '/adm/roles?selectrole=1&cm=1&orgurl=%2fadm%2fmenu'; + } } } - my @menutabs = ('review','submit','managetest','tutorial'); + my @posstabs = ('review','submit','managetest','tutorial'); my $tabs; - foreach my $item (@menutabs) { + foreach my $item (@posstabs) { + next if ($links{$item} eq ''); + push(@menutabs,$item); if ($item eq $current) { - $tabs .= '
  • '. + $tabs .= '
  • '. $linktext{$item}.'
  • '; } else { - $tabs .= '
  • '. + $tabs .= '
  • '. $linktext{$item}.'
  • '; } } @@ -517,6 +575,11 @@ ENDINLINEMENU } 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 '') || @@ -525,7 +588,7 @@ sub show_return_link { (($env{'request.noversionuri'}=~/^\/adm\//) && ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) && ($env{'request.noversionuri'}!~ - m[^/adm/.*/(smppg|bulletinboard|aboutme)($|\?)]) + m[^/adm/.*/(smppg|bulletinboard)($|\?)]) )); } @@ -598,9 +661,17 @@ sub innerregister { } else { $contentstext = &mt('Course Contents'); } - my @crumbs = ({text => $contentstext, - href => "Javascript:gonav('/adm/navmaps')"}); - + 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}); + } if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) { push(@crumbs, {text => '...', no_mt => 1}); @@ -844,7 +915,7 @@ $menuitems.="Make notes and annotations "&go('/adm/requestcourse')&Course requests\n"; } } - unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) { + unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|portfolio)(\?|$)/) { if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/})) { $menuitems.=(<'. - '
    '. - '

    '.&mt('Utilities').'

    '. - ''; - if ($context eq 'gcicustom') { - my $createtext = &mt('Create Concept Test'); - if ($switcher) { - $createtext = &mt('Create New Test'); + 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 } - $output .= ''; + $switcher = $switcher_js.$switcher; } - if ($switcher) { - $output .= ''; + if ($env{'user.domain'} !~ /^\w+citest$/) { + $canreq = + &Apache::lonnet::check_can_request($env{'user.domain'}.'test',\%can_request,\%request_domains); + $createtext = &mt('Create Concept Test'); + if ($numcourses) { + $createtext = &mt('Create New Test'); + } } - $output .= ''. -''; if ($env{'request.course.id'}) { - if (($context eq 'gcicustom') && (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) { - $output.= '
    choose role'.$createtext.'
    choose role'.$switcher.'
    communication'.&mt('Send/Display Messages').'
    user preferences'.&mt('Set my user preferences').'
    '. - ''. - '
    '. - '

    '.&mt('Test Management').'

    '. - ''."\n". - ''."\n". - ''."\n". - ''. - ''. - '
    course contentsConcept Test Contents
    assemble testAssemble Concept Test
    user privs'.&mt('Enrollment and Student Activity').'
    what is new'.&mt("What's New?").'
    print concept test'.&mt("Prepare Printable Concept Test").'
    Test Statistics'.&mt("Concept Test Statistics").'
    '; + 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 .= + '

    '. + '

    '.&mt('Management').'

    '. + ''. + '

    '; } else { my $navtext = &mt('Table of Contents'); - if ($env{'request.role.domain'} eq 'gcitest') { + my $navdesc = &mt('Display Table of Contents for Geoscience Concept Inventory'); + if ($env{'request.role.domain'} =~ /^\w+citest$/) { $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 .= '
    '. + '
    '; } - $output .= 'course contents'.$navtext.'
    '; } - } else { - $output.='
    '; - } - if ($context eq 'gcinorole') { - my $queued = &Apache::loncoursequeueadmin::queued_selfenrollment('notitle'); - if ($queued) { - $output .= ''. - '
    '. - '

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

    '. - $queued. - '
    '; + 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. + '
    '; } - $output.=''; } else { # calling rawconfig with "1" will evaluate mydesk.tab, # even if there is no active remote control @@ -1767,45 +1909,54 @@ sub utilityfunctions { my $gcimenujs; if ($custommenu) { my %concepttests = &Apache::loncommon::existing_gcitest_courses('cc'); - my $managetesturl = '/adm/menu'; - my $createtesturl = '/adm/requestcourse'; + my (@calls,%switchpage_call,%canrequest,%request_domains); + my $canreq = &Apache::lonnet::check_can_request($env{'user.domain'}.'test', + \%canrequest,\%request_domains); + if ($canreq) { + foreach my $call ('createtest','managetest') { + push(@calls,$call); + } + $switchpage_call{'managetest'} = '/adm/menu'; + $switchpage_call{'createtest'} = '/adm/requestcourse'; + if ($env{'request.course.id'}) { + $switchpage_call{'createtest'} = '/adm/roles?selectrole=1&cm=1&orgurl=%2fadm%2frequestcourse'; + } + } if (($env{'request.course.id'}) && - ($env{'course.'.$env{'request.course.id'}.'.domain'} eq 'gci')) { + ($env{'course.'.$env{'request.course.id'}.'.domain'} !~ /^\w+citest$/)) { my @items = keys(%concepttests); - if (@items== 1) { + if (@items==1) { my $newrole = $items[0]; $newrole =~ s{_}{/}; - $managetesturl = '/adm/roles?selectrole=1&cc./'.$newrole.'=1'; + $switchpage_call{'managetest'} = '/adm/roles?selectrole=1&cc./'.$newrole.'=1'; } else { - $managetesturl = '/adm/roles?selectrole=1&cm=1&orgurl=%2fadm%2fmenu'; + $switchpage_call{'managetest'} = '/adm/roles?selectrole=1&cm=1&orgurl=%2fadm%2fmenu'; } } - if ($env{'request.course.id'}) { - $createtesturl = '/adm/roles?selectrole=1&cm=1&orgurl=%2fadm%2frequestcourse'; + my %allnums = &Apache::loncommon::get_faculty_cnums(); + my $udom = $env{'user.domain'}; + if (ref($allnums{$udom}) eq 'HASH') { + foreach my $key (keys(%{$allnums{$udom}})) { + $switchpage_call{$key} = '/adm/roles?selectrole=1&'. + 'st./'.$udom.'/'.$allnums{$udom}->{$key}.'=1'; + push(@calls,$key); + } } - $gcimenujs = <<"ENDCUSTOM"; - + if (@calls > 0) { + $gcimenujs = ' 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'; - } - +'; + foreach my $call (@calls) { + $gcimenujs .= " + if (caller == '$call') { + document.location.href = '$switchpage_call{$call}'; + }"; + } + $gcimenujs .= ' return; } - -ENDCUSTOM +'; + } } my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0])); @@ -1865,12 +2016,6 @@ function go(url) { } } -function gotop(url) { - if (url!='' && url!= null) { - top.location.href = url; - } -} - function gopost(url,postdata) { if (url!='') { this.document.server.action=url;