--- loncom/interface/lonmenu.pm 2009/07/21 14:36:08 1.276 +++ loncom/interface/lonmenu.pm 2009/10/17 01:04:56 1.292 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.276 2009/07/21 14:36:08 droeschl Exp $ +# $Id: lonmenu.pm,v 1.292 2009/10/17 01:04:56 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -113,11 +113,6 @@ The javascript is usually similar to "go =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() @@ -137,19 +132,157 @@ use Apache::loncommon(); use Apache::lonenc(); use Apache::lonlocal; use LONCAPA qw(:DEFAULT :match); +use HTML::Entities(); -use vars qw(@desklines %category_names %category_members %category_positions $readdesk); - +use vars qw(@desklines %category_names %category_members %category_positions + $readdesk @primary_menu @secondary_menu); my @inlineremote; +sub prep_menuitem { + my ($menuitem) = @_; + return '' unless(ref($menuitem) eq 'ARRAY'); + my $link; + if ($$menuitem[1]) { # graphical Link + $link = "\"""; + } else { # textual Link + $link = &mt($$menuitem[3]); + } + return '
  • '.$link.'
  • '; +} + +# primary_menu() 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 +sub primary_menu { + my $menu; + # each element of @primary contains following array: + # (link url, icon path, alt text, link text, condition) + foreach my $menuitem (@primary_menu) { + # evaluate conditions + next if $$menuitem[4] eq 'nonewmsg' # show links depending on + && &Apache::lonmsg::mynewmail(); # whether a new msg + 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 + 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 'roles' ##show links depending on + && &Apache::loncommon::show_course(); ##term 'Courses' or + next if $$menuitem[4] eq 'courses' ##'Roles' wanted + && !&Apache::loncommon::show_course(); ## + + + if ($$menuitem[3] eq 'Help') { # special treatment for helplink + $menu .= '
  • '.&Apache::loncommon::top_nav_help('Help').'
  • '; + } else { + if (ref($menuitem) eq 'ARRAY') { + my @items = @{$menuitem}; + $items[0] = 'javascript:'.$menuitem->[0].';'; + $menu .= &prep_menuitem(\@items); + } + } + } + + return "
      $menu
    "; +} + + +sub secondary_menu { + my $menu; + + my $crstype = &Apache::loncommon::course_type(); + my $canedit = &Apache::lonnet::allowed('mdc', $env{'request.course.id'}); + my $canviewgrps = &Apache::lonnet::allowed('vcg', $env{'request.course.id'} + . ($env{'request.course.sec'} ? "/$env{'request.course.sec'}" + : '')); + my $showlink = &show_return_link(); + 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'}); + foreach my $menuitem (@secondary_menu) { + # evaluate conditions + next if $$menuitem[4] ne 'always' + && !$env{'request.course.id'}; + next if $$menuitem[4] eq 'showreturn' + && !$showlink + && !($env{'request.state'} eq 'construct'); + next if $$menuitem[4] =~ /^mdc/ + && !$canedit; + next if $$menuitem[4] eq 'mdcCourse' + && $crstype eq 'Community'; + next if $$menuitem[4] eq 'mdcCommunity' + && $crstype ne 'Community'; + next if $$menuitem[4] =~ /^remotenav/ + && $env{'environment.remotenavmap'} ne 'on'; + next if $$menuitem[4] =~ /noremotenav/ + && $env{'environment.remotenavmap'} eq 'on'; + next if $$menuitem[4] =~ /showgroups$/ + && $canviewgrps + && !%groups; + + 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'}, + $env{'course.' . $env{'request.course.id'} . '.num'} ); + + $menu .= $roles_selector ? "
  • $roles_selector
  • " + : ''; + } else { + if ($env{'environment.remotenavmap'} eq 'on') { + my @items = @{$menuitem}; + if ($menuitem->[4] eq 'remotenav') { + $items[0] = "javascript:gonav('$menuitem->[0]');"; + } else { + $items[0] = "javascript:go('$menuitem->[0]');"; + } + $menu .= &prep_menuitem(\@items); + } else { + $menu .= &prep_menuitem(\@$menuitem); + } + } + } + if ($menu =~ /\[url\].*\[symb\]/) { + my $escurl = &escape( &Apache::lonenc::check_encrypt( + $env{'request.noversionuri'})); + + my $escsymb = &escape( &Apache::lonenc::check_encrypt( + $env{'request.symb'})); + + if ( $env{'request.state'} eq 'construct' + and ( $env{'request.noversionuri'} eq '' + || !defined($env{'request.noversionuri'}))) + { + ($escurl = $env{'request.filename'}) =~ + s{^/home/([^/]+)/public_html/(.*)$}{/priv/$1/$2}; + + $escurl = &escape($escurl); + } + $menu =~ s/\[url\]/$escurl/g; + $menu =~ s/\[symb\]/$escsymb/g; + } + + 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' => 'Navigate Contents', + 'nav' => 'Course Contents', 'main' => 'Main Menu', 'roles' => (&Apache::loncommon::show_course()? 'Courses':'Roles'), @@ -159,10 +292,12 @@ sub initlittle { 'login' => 'Log In', 'launch' => 'Launch Remote Control', 'groups' => 'Groups', - 'gdoc' => 'Group Documents', + '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; @@ -232,7 +367,7 @@ sub menubuttons { 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); @@ -240,7 +375,7 @@ sub menubuttons { if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') { return (< +
    1. $logo
    2. $lt{'login'}
    @@ -258,9 +393,10 @@ ENDINLINEMENU $navmaps=(<$lt{'nav'} ENDNAV - my $is_group = (&Apache::loncommon::course_type() eq 'Group'); + my $is_community = + (&Apache::loncommon::course_type() eq 'Community'); if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) { - my $text = ($is_group) ? $lt{'gdoc'} : $lt{'docs'}; + my $text = ($is_community) ? $lt{'gdoc'} : $lt{'docs'}; $docs=(<$text ENDDOCS @@ -292,26 +428,26 @@ ENDCRELOAD my $utility = &utilityfunctions(); #Prepare the message link that indicates the arrival of new mail - my $messagelink = Apache::lonmsg::mynewmail() ? "Message (new)" : "Message"; + my $messagelink = &Apache::lonmsg::mynewmail() ? "Message (new)" : "Message"; $messagelink = '' . mt($messagelink) .''; my $helplink = &Apache::loncommon::top_nav_help('Help'); return (< -// BEGIN LON-CAPA Internal // -
      +
      1. $logo
      2. $messagelink
      3. $roles
      4. $helplink
      5. $lt{'exit'}
      -
        +
        • $lt{'main'}
        • $reloadlink $navmaps @@ -357,8 +493,14 @@ sub registerurl { (!&Apache::lonnet::is_on_map( &unescape($env{'request.noversionuri'})))) && (!$forcereg))) { - return $result. - ''.$force_title; + return + $result + .'' + .$force_title; } # Graphical display after login only if ($env{'request.registered'} && !$forcereg) { return ''; } @@ -390,7 +532,7 @@ sub innerregister { $newmail= 'swmenu.setstatus("you have","messages");'; } - my $breadcrumb; + my ($breadcrumb,$separator); if ($noremote && ($env{'request.symb'}) && ($env{'request.course.id'})) { @@ -400,10 +542,13 @@ sub innerregister { my $maptitle = &Apache::lonnet::gettitle($mapurl); my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread()); - my @crumbs = ({text => "Course Content", - href => "Javascript:gonav('/adm/navmaps')"}, - {text => '...', - no_mt => 1}); + my @crumbs = ({text => "Course Contents", + href => "Javascript:gonav('/adm/navmaps')"}); + + if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) { + push(@crumbs, {text => '...', + no_mt => 1}); + } push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle && $maptitle ne 'default.sequence' @@ -411,9 +556,14 @@ sub innerregister { push @crumbs, {text => $restitle, no_mt => 1} if $restitle; - Apache::lonhtmlcommon::clear_breadcrumbs(); - Apache::lonhtmlcommon::add_breadcrumb(@crumbs); - $breadcrumb .= Apache::lonhtmlcommon::breadcrumbs(undef,undef,0); + &Apache::lonhtmlcommon::clear_breadcrumbs(); + &Apache::lonhtmlcommon::add_breadcrumb(@crumbs); + $breadcrumb .= &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0); + unless (($env{'request.state'} eq 'edit') || ($newmail) || + ($env{'request.state'} eq 'construct') || + ($env{'form.register'})) { + $separator = &Apache::loncommon::head_subbox(); + } # } if ($env{'request.state'} eq 'construct') { @@ -611,6 +761,13 @@ if(length($annotation) > 0){ $menuitems.="&anno-[_1]&tations[_1]&annotate()&"; $menuitems.="Make notes and annotations about this resource&&1\n"; + unless ($noremote) { + my $showreqcrs = &check_for_rcrs(); + if ($showreqcrs) { + $menuitems.="s&8&1&rcrs.gif&request[_1]&course[_16]". + "&go('/adm/requestcourse')&Course requests\n"; + } + } unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) { if (!$env{'request.enc'}) { $menuitems.=(< // END LON-CAPA Internal @@ -712,6 +870,7 @@ ENDREGTEXT $result = (< +// ENDREGTHIS } @@ -762,6 +922,7 @@ ENDDONOTREGTEXT $result = (< +// ENDDONOTREGTHIS } @@ -856,6 +1018,7 @@ sub startupremote { my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited'); return(< +// ENDREMOTESTARTUP } @@ -913,8 +1077,10 @@ ENDREMOTESTARTUP sub setflags() { return(< +// ENDSETFLAGS } @@ -923,7 +1089,9 @@ sub maincall() { if ($env{'environment.remote'} eq 'off') { return ''; } return(< +// ENDMAINCALL } @@ -965,7 +1133,12 @@ sub reopenmenu { sub open { my $returnval=''; if ($env{'environment.remote'} eq 'off') { - return ''; + return + ''; } my $menuname = &get_menu_name(); @@ -978,11 +1151,13 @@ sub open { #} #ENDRESIZE # } - $returnval.=(< ENDOPEN return ''; } @@ -1164,12 +1339,6 @@ sub rawconfig { $prt=~s/\$requested_domain/$requested_domain/g; if ($category_names{$cat}!~/\w/) { $cat='oth'; } my $type = &Apache::loncommon::course_type(); -# -# I don't think we support this -# -# if ($type eq 'Group') { -# $desc = &convert_menu_function($desc,$type); -# } if ($pro eq 'clear') { $output.=&clear($row,$col); } elsif ($pro eq 'any') { @@ -1248,16 +1417,14 @@ sub rawconfig { $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; - } + } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) { + if (($prt eq 'reqcrsnsc') && ($show_course)) { + next; } + if (($prt eq 'reqcrsshc') && (!$show_course)) { + next; + } + my $showreqcrs = &check_for_rcrs(); if (!$showreqcrs) { $output.=&clear($row,$col); next; @@ -1278,6 +1445,28 @@ sub rawconfig { return $output; } +sub check_for_rcrs { + my $showreqcrs = 0; + my @reqtypes = ('official','unofficial','community'); + foreach my $type (@reqtypes) { + if (&Apache::lonnet::usertools_access($env{'user.name'}, + $env{'user.domain'}, + $type,undef,'requestcourses')) { + $showreqcrs = 1; + last; + } + } + if (!$showreqcrs) { + foreach my $type (@reqtypes) { + if ($env{'environment.reqcrsotherdom.'.$type} ne '') { + $showreqcrs = 1; + last; + } + } + } + return $showreqcrs; +} + # ======================================================================= Close sub close { @@ -1285,6 +1474,7 @@ sub close { my $menuname = &get_menu_name(); return(< +// ENDCLOSE } @@ -1445,7 +1636,7 @@ function catalog_info() { } function chat_win() { - lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no'); + lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no'); } function group_chat(group) { @@ -1539,22 +1730,6 @@ sub get_nav_status { return $navstatus; } -#FIXME this needs to move into mydesk.tab and the other locations -# the text is generated -# -# We currently do not support this anyway. -# -#sub convert_menu_function { -# my ($rolename,$type) = @_; -# if ($type eq 'Group') { -# $rolename =~ s/student/member/g; -# $rolename =~ s/group/team/g; -# $rolename =~ s/course/group/g; -# $rolename =~ s/Course/Group/g; -# } -# return $rolename; -#} - sub hidden_button_check { my $hidden; if ($env{'request.course.id'} eq '') { @@ -1569,6 +1744,10 @@ sub hidden_button_check { sub roles_selector { my ($cdom,$cnum) = @_; + my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'}; + if ($crstype eq '') { + $crstype = 'Course'; + } my $now = time; my (%courseroles,%seccount); my $is_cc; @@ -1618,12 +1797,18 @@ sub roles_selector { } } } + my $switchtext; + if ($crstype eq 'Community') { + $switchtext = &mt('Switch community role to...') + } else { + $switchtext = &mt('Switch course role to...') + } my @roles_order = ('cc','in','ta','ep','ad','st'); if (keys(%courseroles) > 1) { $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles); $role_selector .= '
          '."\n". ''."\n". + &HTML::Entities::encode($ENV{'REQUEST_URI'}).'" />'."\n". ''."\n". ''."\n". ''."\n". @@ -1814,34 +1999,34 @@ END BEGIN { if (! defined($readdesk)) { - { - my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab'; - if ( CORE::open( my $config,"<$tabfile") ) { - while (my $configline=<$config>) { - $configline=(split(/\#/,$configline))[0]; - $configline=~s/^\s+//; - chomp($configline); + { + my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab'; + if ( CORE::open( my $config,"<$tabfile") ) { + while (my $configline=<$config>) { + $configline=(split(/\#/,$configline))[0]; + $configline=~s/^\s+//; + chomp($configline); if ($configline=~/^cat\:/) { - my @entries=split(/\:/,$configline); - $category_positions{$entries[2]}=$entries[1]; - $category_names{$entries[2]}=$entries[3]; - } elsif ($configline) { - push(@desklines,$configline); - } - } - CORE::close($config); - } - } - $readdesk='done'; + my @entries=split(/\:/,$configline); + $category_positions{$entries[2]}=$entries[1]; + $category_names{$entries[2]}=$entries[3]; + } elsif ($configline=~/^prim\:/) { + my @entries = (split(/\:/, $configline))[1..5]; + push @primary_menu, \@entries; + } elsif ($configline=~/^scnd\:/) { + my @entries = (split(/\:/, $configline))[1..5]; + push @secondary_menu, \@entries; + } elsif ($configline) { + push(@desklines,$configline); + } + } + CORE::close($config); + } + } + $readdesk='done'; } } 1; __END__ - - - - - -