--- loncom/interface/lonmenu.pm 2008/09/20 17:01:48 1.239.2.1 +++ loncom/interface/lonmenu.pm 2009/06/02 17:25:03 1.269 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.239.2.1 2008/09/20 17:01:48 raeburn Exp $ +# $Id: lonmenu.pm,v 1.269 2009/06/02 17:25:03 droeschl Exp $ # # Copyright Michigan State University Board of Trustees # @@ -26,15 +26,107 @@ # http://www.lon-capa.org/ # # -# There are two parameters controlling the action of this module: -# -# browser.interface - if this is 'textual', it overrides the second parameter -# and goes to screen reader PDA mode +# There is one parameter controlling the action of this module: # # environment.remote - if this is 'on', the routines controll the remote -# control, otherwise they render the main window controls; ignored it -# browser.interface is 'textual' -# +# control, otherwise they render the main window controls; + +=head1 NAME + +Apache::lonmenu + +=head1 SYNOPSIS + +Coordinates the response to clicking an image. + +This is part of the LearningOnline Network with CAPA project +described at http://www.lon-capa.org. + +=head1 SUBROUTINES + +=over + +Little texts + +=item initlittle() + +=item menubuttons() + +This gets called at the top of the body section + +=item show_return_link() + +=item registerurl() + +This gets called in the header section + +=item innerregister() + +This gets called in order to register a URL, both with the Remote +and in the body of the document + +=item loadevents() + +=item unloadevents() + +=item startupremote() + +=item setflags() + +=item maincall() + +=item load_remote_msg() + +=item get_menu_name() + +=item reopenmenu() + +=item open() + +Open the menu + +=item clear() + +=item switch() + +Switch a button or create a link +Switch acts on the javascript that is executed when a button is clicked. +The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)". + +=item secondlevel() + +=item openmenu() + +=item inlinemenu() + +=item rawconfig() + +=item close() + +=item footer() + +=item utilityfunctions() + +=item serverform() + +=item constspaceform() + +=item get_nav_status() + +=item convert_menu_function() + +FIXME this needs to move into mydesktab and the other locations +the text is generated + +=item hidden_button_check() + +=item roles_selector() + +=item jump_to_role() + +=back + +=cut package Apache::lonmenu; @@ -51,32 +143,15 @@ use vars qw(@desklines %category_names % my @inlineremote; - - -# ================================================================ Little texts -sub show_course { - my $course = !$env{'user.adv'}; - if (!$env{'user.adv'}) { - foreach my $env (keys(%env)) { - next if ($env !~ m/^user\.priv\./); - if ($env !~ m/^user\.priv\.(?:st|cm)/) { - $course = 0; - last; - } - } - } - return $course; -} - sub initlittle { return &Apache::lonlocal::texthash('ret' => 'Return to Last Location', 'nav' => 'Navigate Contents', 'main' => 'Main Menu', - 'roles' => (&show_course()? + 'roles' => (&Apache::loncommon::show_course()? 'Courses':'Roles'), 'other' => 'Other Roles', 'docs' => 'Edit Course', - 'exit' => 'Exit', + 'exit' => 'Logout', 'login' => 'Log In', 'launch' => 'Launch Remote Control', 'groups' => 'Groups', @@ -84,8 +159,6 @@ sub initlittle { ); } -# ============================= This gets called at the top of the body section - sub menubuttons { my $forcereg=shift; my $registration=shift; @@ -110,8 +183,8 @@ sub menubuttons { my $escsymb=&escape(&Apache::lonenc::check_encrypt($env{'request.symb'})); my $logo=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/minilogo.gif"); - $logo = 'LON-CAPA Logo'; + $logo = 'LON-CAPA Logo'; if ($env{'request.state'} eq 'construct') { if (($env{'request.noversionuri'} eq '') || (!defined($env{'request.noversionuri'}))) { @@ -138,75 +211,32 @@ sub menubuttons { } } - if ($env{'browser.interface'} eq 'textual') { -# Textual display only - if ($env{'request.course.id'}) { - $navmaps=(<$lt{'nav'} -ENDNAV - if (&show_return_link()) { - my $escreload=&escape('return:'); - $reloadlink=(<$lt{'ret'} -ENDRELOAD - } - if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) { - $docs=(<$lt{'docs'} -ENDDOCS - } - if ($showgroups) { - $groups =(<$lt{'groups'} -ENDGROUPS - } - } - my $form=&serverform(); - my $utility=&utilityfunctions(); - my $output=(< -// BEGIN LON-CAPA Internal -$utility - -
-$lt{'main'} -$reloadlink $navmaps $docs $groups $roles -$lt{'exit'} -
-
- -$form -ENDMAINMENU - if ($registration) { $output.=&innerregister($forcereg); } - return $output."
"; - } elsif ($env{'environment.remote'} eq 'off') { + if ($env{'environment.remote'} eq 'off') { # Remote Control is switched off # figure out colors - my %lt=&initlittle(); + my %lt=&initlittle(); my $domain=&Apache::loncommon::determinedomain(); - my $function =&Apache::loncommon::get_users_function(); + 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 + $logo $lt{'login'} - ENDINLINEMENU } - $roles = ''.$lt{'roles'}.''; + $roles = ''.$lt{'roles'}.''; # Do we have a NAV link? if ($env{'request.course.id'}) { my $link='/adm/navmaps?postdata='.$escurl.'&postsymb='. @@ -215,34 +245,35 @@ ENDINLINEMENU $link="javascript:gonav('".$link."')"; } $navmaps=(<$lt{'nav'} +
  • $lt{'nav'}
  • ENDNAV my $is_group = (&Apache::loncommon::course_type() eq 'Group'); if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) { my $text = ($is_group) ? $lt{'gdoc'} : $lt{'docs'}; $docs=(<$text +
  • $text
  • ENDDOCS } if ($showgroups) { $groups =(<$lt{'groups'} +
  • $lt{'groups'}
  • ENDGROUPS } if (&show_return_link()) { my $escreload=&escape('return:'); $reloadlink=(<$lt{'ret'} +
  • $lt{'ret'}
  • ENDRELOAD } if ($role_selector) { - $roles = ''.$role_selector.''.$lt{'other'}.''; + #$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'} +
  • $lt{'ret'}
  • ENDCRELOAD } my $reg=''; @@ -252,6 +283,12 @@ ENDCRELOAD my $form=&serverform(); my $utility=&utilityfunctions(); + my $messagelink = ""; + if(&Apache::lonmsg::mynewmail()){ + $messagelink = 'Message(new)' + }else{ + $messagelink = 'Message' + } my $helplink=&Apache::loncommon::top_nav_help('Help'); return (< @@ -260,19 +297,21 @@ ENDCRELOAD $utility // ]]> - - -$logo - +
      +
    1. $logo
    2. +
    3. $messagelink
    4. +
    5. $roles
    6. +
    7. $helplink
    8. +
    9. $lt{'exit'}
    10. +
    +
      +
    • $lt{'main'}
    • $reloadlink $navmaps $docs $groups -$roles -
    - - -
    $lt{'main'}$helplink$lt{'exit'}
    +$role_selector + $form $timesync +$breadcrumb $tablestart $inlinebuttons $tableend @@ -663,9 +727,9 @@ ENDREGTHIS # ============================================================================= } else { # ========================================== This can or will not be registered - if ($textual) { -# Not registered, textual - $result= (<&'); + } + } + return $cfile; +} + sub loadevents() { if ($env{'request.state'} eq 'construct' || $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; } @@ -716,12 +816,10 @@ sub unloadevents() { return 'LONCAPAstale();'; } -# ============================================================= Start up remote sub startupremote { my ($lowerurl)=@_; - if (($env{'browser.interface'} eq 'textual') || - ($env{'environment.remote'} eq 'off')) { + if ($env{'environment.remote'} eq 'off') { return (''); } # @@ -796,8 +894,7 @@ ENDSETFLAGS } sub maincall() { - if (($env{'browser.interface'} eq 'textual') || - ($env{'environment.remote'} eq 'off')) { return ''; } + if ($env{'environment.remote'} eq 'off') { return ''; } return(< main(); @@ -808,12 +905,12 @@ ENDMAINCALL sub load_remote_msg { my ($lowerurl)=@_; - if (($env{'browser.interface'} eq 'textual') || - ($env{'environment.remote'} eq 'off')) { return ''; } + if ($env{'environment.remote'} eq 'off') { return ''; } my $esclowerurl=&escape($lowerurl); - my $link=&mt('Continue on in Inline Menu mode', - "/adm/remote?action=collapse&url=$esclowerurl"); + my $link=&mt('[_1]Continue[_2] on in Inline Menu mode' + ,'' + ,''); return(<
    @@ -830,22 +927,18 @@ sub get_menu_name { return 'LCmenu'.$hostid; } -# ================================================================= Reopen menu sub reopenmenu { - if (($env{'browser.interface'} eq 'textual') || - ($env{'environment.remote'} eq 'off')) { return ''; } + if ($env{'environment.remote'} eq 'off') { return ''; } my $menuname = &get_menu_name(); my $nothing = &Apache::lonhtmlcommon::javascript_nothing(); return('window.open('.$nothing.',"'.$menuname.'","",false);'); } -# =============================================================== Open the menu sub open { my $returnval=''; - if (($env{'browser.interface'} eq 'textual') || - ($env{'environment.remote'} eq 'off')) { + if ($env{'environment.remote'} eq 'off') { return ''; } my $menuname = &get_menu_name(); @@ -873,8 +966,7 @@ ENDOPEN sub clear { my ($row,$col)=@_; - unless (($env{'browser.interface'} eq 'textual') || - ($env{'environment.remote'} eq 'off')) { + unless ($env{'environment.remote'} eq 'off') { return "\n".qq(window.status+='.';swmenu.clearbut($row,$col);); } else { $inlineremote[10*$row+$col]=''; @@ -899,23 +991,10 @@ sub switch { my $idx=10*$row+$col; $category_members{$cat}.=':'.$idx; - unless (($env{'browser.interface'} eq 'textual') || - ($env{'environment.remote'} eq 'off')) { + unless ($env{'environment.remote'} eq 'off') { # Remote return "\n". qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc");); - } elsif ($env{'browser.interface'} eq 'textual') { -# Accessibility - if ($nobreak==2) { return ''; } - my $text=$top.' '.$bot; - $text=~s/\s*\-\s*//gs; - if ($nobreak) { - $inlineremote[$idx]= - ''.$text.''; - } else { - $inlineremote[$idx]="\n
    ". - $desc.' '.$text.''; - } } else { # Inline Remote if ($env{'environment.icons'} ne 'classic') { @@ -928,22 +1007,22 @@ sub switch { my $pic= ''.$text.''; + '" align="'.($nobreak==3?'right':'left').'" class="LC_noBorder" />'; if ($env{'browser.interface'} eq 'faketextual') { # Accessibility if ($nobreak==3) { $inlineremote[$idx]="\n". ''.$text. - ''. + ''. ''.$pic.''; } elsif ($nobreak) { $inlineremote[$idx]="\n". - ''. + ''. ''.$pic.' '.$text.''; } else { $inlineremote[$idx]="\n". - ''. + ''. ''.$pic. ''. ''.$desc.''; @@ -978,8 +1057,7 @@ sub secondlevel { sub openmenu { my $menuname = &get_menu_name(); - if (($env{'browser.interface'} eq 'textual') || - ($env{'environment.remote'} eq 'off')) { return ''; } + if ($env{'environment.remote'} eq 'off') { return ''; } my $nothing = &Apache::lonhtmlcommon::javascript_nothing(); return "window.open(".$nothing.",'".$menuname."');"; } @@ -990,11 +1068,14 @@ sub inlinemenu { &rawconfig(1); my $output=''; for (my $col=1; $col<=2; $col++) { - $output.='"; @@ -1016,8 +1098,7 @@ sub inlinemenu { sub rawconfig { my $textualoverride=shift; my $output=''; - unless (($env{'browser.interface'} eq 'textual') || - ($env{'environment.remote'} eq 'off')) { + unless ($env{'environment.remote'} eq 'off') { $output.= "window.status='Opening Remote Control';var swmenu=".&openmenu(). "\nwindow.status='Configuring Remote Control ';"; @@ -1027,7 +1108,7 @@ sub rawconfig { my $uname=$env{'user.name'}; my $udom=$env{'user.domain'}; my $adv=$env{'user.adv'}; - my $show_course=&show_course(); + my $show_course=&Apache::loncommon::show_course(); my $author=$env{'user.author'}; my $crs=''; if ($env{'request.course.id'}) { @@ -1121,10 +1202,36 @@ sub rawconfig { } } } + } elsif ($pro eq 'tools') { + my @tools = ('aboutme','blog','portfolio'); + if (grep(/^\Q$prt\E$/,@tools)) { + if (!&Apache::lonnet::usertools_access($env{'user.name'}, + $env{'user.domain'}, + $prt,undef,'tools')) { + $output.=&clear($row,$col); + next; + } + } elsif ($prt eq 'reqcrs') { + my $showreqcrs = 0; + foreach my $type ('official','unofficial') { + if (&Apache::lonnet::usertools_access($env{'user.name'}, + $env{'user.domain'}, + $type,undef,'requestcourses')) { + $showreqcrs = 1; + last; + } + } + if (!$showreqcrs) { + $output.=&clear($row,$col); + next; + } + } + $prt='any'; + $output.=&secondlevel( + $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat); } } - unless (($env{'browser.interface'} eq 'textual') || - ($env{'environment.remote'} eq 'off')) { + unless ($env{'environment.remote'} eq 'off') { $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';"; if (&Apache::lonmsg::newmail()) { $output.='swmenu.setstatus("you have","messages");'; @@ -1137,8 +1244,7 @@ sub rawconfig { # ======================================================================= Close sub close { - if (($env{'browser.interface'} eq 'textual') || - ($env{'environment.remote'} eq 'off')) { return ''; } + if ($env{'environment.remote'} eq 'off') { return ''; } my $menuname = &get_menu_name(); return(< @@ -1180,8 +1286,10 @@ NAVCONTROL sub utilityfunctions { my $caller = shift; - unless (($env{'browser.interface'} eq 'textual') || - ($env{'environment.remote'} eq 'off') || ($caller eq '/adm/menu')) { return ''; } + unless ($env{'environment.remote'} eq 'off' || + $caller eq '/adm/menu') { + return ''; } + my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0])); $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl)); @@ -1337,16 +1445,16 @@ function set_bookmark() { bmquery=window.open('','bmquery','width=365,height=165,scrollbars=0'); bmquery.document.write( '$start_page_bookmark' - +"
    \\n
    '; + $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.='
    '; + $output.='

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

    '; + $output.='
    '.&mt($category_names{$cat}).'
    '; my %active=(); foreach my $menu_item (split(/\:/,$category_members{$cat})) { if ($inlineremote[$menu_item]) { @@ -1005,6 +1086,7 @@ sub inlinemenu { $output.=$inlineremote[$item]; } $output.='
    '; + $output.=''; } } $output.="
    Link Name:
    " - +"
    Address:

    <\\/center><\\/td>" - +"<\\/tr><\\/table><\\/form><\\/center>" + +'
    ' + +'
    Link Name:
    ' + +'
    Address:

    ' +'$end_page_bookmark' ); bmquery.document.close(); } @@ -1422,7 +1530,7 @@ sub hidden_button_check { sub roles_selector { my ($cdom,$cnum) = @_; my $now = time; - my (%courseroles,%seccount,%gotnosection); + my (%courseroles,%seccount); my $is_cc; my $role_selector; if ($env{'user.role.cc./'.$cdom.'/'.$cnum}) { @@ -1437,35 +1545,9 @@ sub roles_selector { } } if ($is_cc) { - my %adv_roles = - &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1); - foreach my $role (keys(%adv_roles)) { - my ($urole,$usec) = split(/:/,$role); - if (!$gotnosection{$urole}) { - $seccount{$urole} ++; - $gotnosection{$urole} = 1; - } - if (ref($courseroles{$urole}) eq 'ARRAY') { - if ($usec ne '') { - if (!grep(/^Q$usec\E$/,@{$courseroles{$urole}})) { - push(@{$courseroles{$urole}},$usec); - $seccount{$urole} ++; - } - } - } else { - @{$courseroles{$urole}} = (); - if ($usec ne '') { - $seccount{$urole} ++; - push(@{$courseroles{$urole}},$usec); - } - } - } - my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum); - @{$courseroles{'st'}} = (); - if (keys(%sections_count) > 0) { - push(@{$courseroles{'st'}},keys(%sections_count)); - } + &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount); } else { + my %gotnosection; foreach my $item (keys(%env)) { if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) { my $role = $1; @@ -1481,7 +1563,7 @@ sub roles_selector { } if (ref($courseroles{$role}) eq 'ARRAY') { if ($sec ne '') { - if (!grep(/^Q$sec\E$/,@{$courseroles{$role}})) { + if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) { push(@{$courseroles{$role}},$sec); $seccount{$role} ++; } @@ -1523,6 +1605,61 @@ sub roles_selector { return $role_selector; } +sub get_all_courseroles { + my ($cdom,$cnum,$courseroles,$seccount) = @_; + unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH')) { + return; + } + my ($result,$cached) = + &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum); + if (defined($cached)) { + if (ref($result) eq 'HASH') { + if ((ref($result->{'roles'}) eq 'HASH') && + (ref($result->{'seccount'}) eq 'HASH')) { + %{$courseroles} = %{$result->{'roles'}}; + %{$seccount} = %{$result->{'seccount'}}; + return; + } + } + } + my %gotnosection; + my %adv_roles = + &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1); + foreach my $role (keys(%adv_roles)) { + my ($urole,$usec) = split(/:/,$role); + if (!$gotnosection{$urole}) { + $seccount->{$urole} ++; + $gotnosection{$urole} = 1; + } + if (ref($courseroles->{$urole}) eq 'ARRAY') { + if ($usec ne '') { + if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) { + push(@{$courseroles->{$urole}},$usec); + $seccount->{$urole} ++; + } + } + } else { + @{$courseroles->{$urole}} = (); + if ($usec ne '') { + $seccount->{$urole} ++; + push(@{$courseroles->{$urole}},$usec); + } + } + } + my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']); + @{$courseroles->{'st'}} = (); + if (keys(%sections_count) > 0) { + push(@{$courseroles->{'st'}},keys(%sections_count)); + $seccount->{'st'} = scalar(keys(%sections_count)); + } + my $rolehash = { + 'roles' => $courseroles, + 'seccount' => $seccount, + }; + &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash); + return; +} + sub jump_to_role { my ($cdom,$cnum,$seccount,$courseroles) = @_; my %lt = &Apache::lonlocal::texthash(