--- loncom/interface/lonmenu.pm 2008/12/30 18:39:03 1.239.4.3 +++ loncom/interface/lonmenu.pm 2009/04/17 15:54:59 1.259 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.239.4.3 2008/12/30 18:39:03 raeburn Exp $ +# $Id: lonmenu.pm,v 1.259 2009/04/17 15:54:59 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -36,6 +36,105 @@ # browser.interface is 'textual' # +=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 + +=item show_course() + +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; use strict; @@ -53,7 +152,6 @@ my @inlineremote; -# ================================================================ Little texts sub show_course { my $course = !$env{'user.adv'}; if (!$env{'user.adv'}) { @@ -76,7 +174,7 @@ sub initlittle { 'Courses':'Roles'), 'other' => 'Other Roles', 'docs' => 'Edit Course', - 'exit' => 'Exit', + 'exit' => 'Logout', 'login' => 'Log In', 'launch' => 'Launch Remote Control', 'groups' => 'Groups', @@ -84,8 +182,6 @@ sub initlittle { ); } -# ============================= This gets called at the top of the body section - sub menubuttons { my $forcereg=shift; my $registration=shift; @@ -110,8 +206,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'}))) { @@ -196,17 +292,16 @@ ENDMAINMENU 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 +310,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 +348,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,23 +362,26 @@ ENDCRELOAD $utility // ]]> - - -$logo - +
      +
    1. $logo
    2. +
    3. $messagelink
    4. +
    5. $roles
    6. +
    7. $helplink
    8. +
    9. $lt{'exit'}
    10. +
    +
      +
    1. $lt{'main'}
    2. $reloadlink $navmaps $docs $groups -$roles -
    - - -
    $lt{'main'}$helplink$lt{'exit'}
    +$role_selector + $form +
    $reg ENDINLINEMENU } else { @@ -297,7 +402,6 @@ sub show_return_link { )); } -# ====================================== This gets called in the header section sub registerurl { my ($forcereg) = @_; @@ -322,9 +426,6 @@ sub registerurl { return $result.$force_title; } -# =========== This gets called in order to register a URL, both with the Remote -# =========== and in the body of the document - sub innerregister { my ($forcereg, $titletable) = @_; my $result = ''; @@ -401,7 +502,7 @@ sub innerregister { if ($env{'request.symb'} ne '' && $env{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form|task)$/) { if (&Apache::lonnet::allowed('mgr',$crs)) { - $hwkadd.=&switch('','',7,2,'pgrd.gif','problem[_1]','grades[_3]', + $hwkadd.=&switch('','',7,2,'pgrd.gif','problem[_1]','grades[_4]', "gocmd('/adm/grades','gradingmenu')", 'Modify user grades for this assessment resource'); } elsif (&Apache::lonnet::allowed('vgr',$crs)) { @@ -422,6 +523,12 @@ sub innerregister { ### resource ### my $editbutton = ''; + my $noeditbutton = 1; + my ($cnum,$cdom); + if ($env{'request.course.id'}) { + $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + } if ($env{'user.author'}) { if ($env{'request.role'}=~/^(aa|ca|au)/) { # Set defaults for authors @@ -449,6 +556,7 @@ sub innerregister { foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } } if (!$allowed) { $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc); + $noeditbutton = 0; } } ## @@ -457,30 +565,53 @@ sub innerregister { my $cfile=''; my $cfuname=''; my $cfudom=''; + my $uploaded; if ($env{'request.filename'}) { my $file=&Apache::lonnet::declutter($env{'request.filename'}); - $file=~s/^($match_domain)\/($match_username)/\/priv\/$2/; - # Check that the user has permission to edit this resource - ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1); - if (defined($cfudom)) { - my $home=&Apache::lonnet::homeserver($cfuname,$cfudom); - my $allowed=0; - my @ids=&Apache::lonnet::current_machine_ids(); - foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } } - if ($allowed) { - $cfile=$file; + if (defined($cnum) && defined($cdom)) { + $uploaded = &is_course_upload($file,$cnum,$cdom); + } + if (!$uploaded) { + $file=~s/^($match_domain)\/($match_username)/\/priv\/$2/; + # Check that the user has permission to edit this resource + ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1); + if (defined($cfudom)) { + my $home=&Apache::lonnet::homeserver($cfuname,$cfudom); + my $allowed=0; + my @ids=&Apache::lonnet::current_machine_ids(); + foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } } + if ($allowed) { + $cfile=$file; + } } } - } + } # Finally, turn the button on or off if ($cfile && !$const_space) { $editbutton=&switch ('','',6,1,'pcstr.gif','edit[_1]','resource[_2]', "go('".$cfile."');","Edit this resource"); + $noeditbutton = 0; } elsif ($editbutton eq '') { $editbutton=&clear(6,1); } } + if (($noeditbutton) && ($env{'request.filename'})) { + if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) { + my $file=&Apache::lonnet::declutter($env{'request.filename'}); + if (defined($cnum) && defined($cdom)) { + if (&is_course_upload($file,$cnum,$cdom)) { + my $cfile = &edit_course_upload($file,$cnum,$cdom); + if ($cfile) { + $editbutton=&switch + ('','',6,1,'pcstr.gif','edit[_1]', + 'resource[_2]',"go('".$cfile."');", + 'Edit this resource'); + } + } + } + } + } ### ### # Prepare the rest of the buttons @@ -498,7 +629,7 @@ sub innerregister { $menuitems=(< 0){ - $menuitems.="anot2.gif"; - } else { - $menuitems.="anot.gif"; - } - $menuitems.="&anno-[_1]&tations[_1]&annotate()&"; - $menuitems.="Make notes and annotations about this resource&&1\n"; + +my $currentURL = &Apache::loncommon::get_symb(); +my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL); +my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc); +$menuitems.="s&9&3&"; +if(length($annotation) > 0){ + $menuitems.="anot2.gif"; +}else{ + $menuitems.="anot.gif"; +} +$menuitems.="&anno-[_1]&tations[_1]&annotate()&"; +$menuitems.="Make notes and annotations about this resource&&1\n"; unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) { if (!$env{'request.enc'}) { $menuitems.=(<&'); + } + } + return $cfile; +} + sub loadevents() { if ($env{'request.state'} eq 'construct' || $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; } @@ -726,7 +894,6 @@ sub unloadevents() { return 'LONCAPAstale();'; } -# ============================================================= Start up remote sub startupremote { my ($lowerurl)=@_; @@ -840,7 +1007,6 @@ sub get_menu_name { return 'LCmenu'.$hostid; } -# ================================================================= Reopen menu sub reopenmenu { if (($env{'browser.interface'} eq 'textual') || @@ -850,7 +1016,6 @@ sub reopenmenu { return('window.open('.$nothing.',"'.$menuname.'","",false);'); } -# =============================================================== Open the menu sub open { my $returnval=''; @@ -938,22 +1103,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.''; @@ -1000,11 +1165,14 @@ sub inlinemenu { &rawconfig(1); my $output=''; for (my $col=1; $col<=2; $col++) { - $output.='"; @@ -1135,7 +1304,22 @@ sub rawconfig { my @tools = ('aboutme','blog','portfolio'); if (grep(/^\Q$prt\E$/,@tools)) { if (!&Apache::lonnet::usertools_access($env{'user.name'}, - $env{'user.domain'},$prt)) { + $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; } @@ -1366,7 +1550,7 @@ function set_bookmark() { +"type='text' name='title' size=45 value='"+clienttitle+"' />" +"
    Address:

    <\\/center><\\/td>" +"<\\/tr><\\/table><\\/form><\\/center>" +'$end_page_bookmark' );
    '; + $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]) { @@ -1015,6 +1183,7 @@ sub inlinemenu { $output.=$inlineremote[$item]; } $output.='
    '; + $output.=''; } } $output.="