--- loncom/interface/lonmenu.pm 2009/11/10 13:58:55 1.301 +++ 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.301 2009/11/10 13:58:55 droeschl Exp $ +# $Id: lonmenu.pm,v 1.309.2.24 2010/12/07 04:33:49 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -131,6 +131,7 @@ use Apache::lonhtmlcommon(); use Apache::loncommon(); use Apache::lonenc(); use Apache::lonlocal; +use Apache::loncoursequeueadmin; use LONCAPA qw(:DEFAULT :match); use HTML::Entities(); @@ -150,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 @@ -160,8 +164,18 @@ 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(); + 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'; # @@ -170,11 +184,22 @@ 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 + && $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 @@ -182,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); } } @@ -207,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 @@ -232,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'}, @@ -277,6 +318,70 @@ sub secondary_menu { return ""; } +sub gci_secondary_menu { + 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,@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}) { + if ($env{'environment.remotenavmap'} eq 'on') { + $links{$key} = "javascript:gonav('/adm/navmaps')"; + } else { + $links{$key} = '/adm/navmaps'; + } + $current = $key; + if (($canreq) || (keys(%concepttests) > 0) { + $links{'managetest'} = '/adm/roles?selectrole=1&cm=1&orgurl=%2fadm%2fmenu'; + } + } + } + my @posstabs = ('review','submit','managetest','tutorial'); + my $tabs; + foreach my $item (@posstabs) { + next if ($links{$item} eq ''); + push(@menutabs,$item); + 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 @@ -470,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 '') || @@ -478,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)($|\?)]) )); } @@ -512,7 +622,7 @@ sub registerurl { } sub innerregister { - my ($forcereg, $titletable) = @_; + my ($forcereg,$titletable,$bread_crumbs) = @_; my $result = ''; my ($uname,$thisdisfn); my $const_space = ($env{'request.state'} eq 'construct'); @@ -551,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}); @@ -689,10 +807,22 @@ sub innerregister { } # Finally, turn the button on or off if ($cfile && !$const_space) { - $editbutton=&switch - ('','',6,1,'pcstr.gif','edit[_1]','resource[_2]', + my $nocrsedit; + # Suppress display where CC has switched to student role. + if ($env{'request.course.id'}) { + unless(&Apache::lonnet::allowed('mdc', + $env{'request.course.id'})) { + $nocrsedit = 1; + } + } + if ($nocrsedit) { + $editbutton=&clear(6,1); + } else { + $editbutton=&switch + ('','',6,1,'pcstr.gif','edit[_1]','resource[_2]', "go('".$cfile."');","Edit this resource"); - $noeditbutton = 0; + $noeditbutton = 0; + } } elsif ($editbutton eq '') { $editbutton=&clear(6,1); } @@ -741,6 +871,14 @@ s&7&1&del.gif&delete[_1]&resource[_2]&go s&7&2&prt.gif&prepare[_1]&printout[_1]&gocstr('/adm/printout','/~$uname/$cleandisfn')&Prepare a printable document ENDMENUITEMS } + if ($noremote) { + if (ref($bread_crumbs) eq 'ARRAY') { + &Apache::lonhtmlcommon::clear_breadcrumbs(); + foreach my $crumb (@{$bread_crumbs}){ + &Apache::lonhtmlcommon::add_breadcrumb($crumb); + } + } + } } elsif ( defined($env{'request.course.id'}) && $env{'request.symb'} ne '' ) { # @@ -777,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.=(< $timesync $breadcrumb - - - + + + $newmail - + @@ -1255,7 +1385,7 @@ sub switch { my $pic= ''.$text.''; + '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />'; if ($env{'browser.interface'} eq 'faketextual') { # Main Menu if ($nobreak==3) { @@ -1311,36 +1441,172 @@ sub openmenu { } sub inlinemenu { + my ($context) = @_; undef(@inlineremote); undef(%category_members); -# 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.='"; + $switcher = $switcher_js.$switcher; + } + 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'); + } + } + 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 .= + '

    '. + '

    '.&mt('Management').'

    '. + ''. + '

    '; + } else { + my $navtext = &mt('Table of Contents'); + 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 .= '
    '. + '
    '; + } + } + 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 $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.=''; + 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 } - } - $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; } @@ -1440,15 +1706,31 @@ sub rawconfig { } } elsif ($pro =~ /^courseenv_(.*)$/) { my $key = $1; - if (($env{'course.'.$env{'request.course.id'}.'.'.$key}) && - ($crstype ne 'Community')) { - $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat); + if ($crstype ne 'Community') { + my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key}; + if ($key eq 'canuse_pdfforms') { + if ($env{'request.course.id'} && $coursepref eq '') { + my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'}); + $coursepref = $domdefs{'canuse_pdfforms'}; + } + } + if ($coursepref) { + $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat); + } } } elsif ($pro =~ /^communityenv_(.*)$/) { my $key = $1; - if (($env{'course.'.$env{'request.course.id'}.'.'.$key}) && - ($crstype eq 'Community')) { - $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat); + if ($crstype eq 'Community') { + my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key}; + if ($key eq 'canuse_pdfforms') { + if ($env{'request.course.id'} && $coursepref eq '') { + my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'}); + $coursepref = $domdefs{'canuse_pdfforms'}; + } + } + if ($coursepref) { + $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat); + } } } elsif ($pro =~ /^course_(.*)$/) { # Check for permissions inside of a course @@ -1593,12 +1875,90 @@ function gonav(url) { NAVCONTROL } +sub dc_popup_js { + my %lt = &Apache::lonlocal::texthash( + more => '(More ...)', + less => '(Less ...)', + ); + return <<"END"; + +function showCourseID() { + document.getElementById('dccid').style.display='block'; + document.getElementById('dccid').style.textAlign='left'; + document.getElementById('dccid').style.textFace='normal'; + document.getElementById('dccidtext').innerHTML ='$lt{'less'}'; + return; +} + +function hideCourseID() { + document.getElementById('dccid').style.display='none'; + document.getElementById('dccidtext').innerHTML ='$lt{'more'}'; + return; +} + +END + +} + sub utilityfunctions { - my $caller = shift; + my ($caller,$custommenu) = @_; unless ($env{'environment.remote'} eq 'off' || $caller eq '/adm/menu') { return ''; } - + + my $gcimenujs; + if ($custommenu) { + my %concepttests = &Apache::loncommon::existing_gcitest_courses('cc'); + 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'} !~ /^\w+citest$/)) { + my @items = keys(%concepttests); + if (@items==1) { + my $newrole = $items[0]; + $newrole =~ s{_}{/}; + $switchpage_call{'managetest'} = '/adm/roles?selectrole=1&cc./'.$newrole.'=1'; + } else { + $switchpage_call{'managetest'} = '/adm/roles?selectrole=1&cm=1&orgurl=%2fadm%2fmenu'; + } + } + 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); + } + } + if (@calls > 0) { + $gcimenujs = ' +function switchpage(caller) { +'; + foreach my $call (@calls) { + $gcimenujs .= " + if (caller == '$call') { + document.location.href = '$switchpage_call{$call}'; + }"; + } + $gcimenujs .= ' + return; +} +'; + } + } + my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0])); if ($currenturl =~ m{^/adm/wrapper/ext/}) { if ($env{'request.external.querystring'}) { @@ -1610,6 +1970,13 @@ sub utilityfunctions { my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'}); my $nav_control=&nav_control_js(); + my $dc_popup_cid; + if ($env{'user.adv'} && exists($env{'user.role.dc./'. + $env{'course.'.$env{'request.course.id'}. + '.domain'}.'/'})) { + $dc_popup_cid = &dc_popup_js(); + } + my $start_page_annotate = &Apache::loncommon::start_page('Annotator',undef, {'only_body' => 1, @@ -1637,6 +2004,9 @@ return (<