--- loncom/interface/lonmenu.pm 2008/09/20 17:01:48 1.239.2.1 +++ loncom/interface/lonmenu.pm 2010/01/18 20:47:57 1.244.2.9 @@ -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.244.2.9 2010/01/18 20:47:57 raeburn 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; @@ -45,6 +144,7 @@ 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); @@ -53,7 +153,6 @@ my @inlineremote; -# ================================================================ Little texts sub show_course { my $course = !$env{'user.adv'}; if (!$env{'user.adv'}) { @@ -72,20 +171,18 @@ 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', - 'gdoc' => 'Group Documents', + 'gdoc' => 'Community Documents', ); } -# ============================= This gets called at the top of the body section - sub menubuttons { my $forcereg=shift; my $registration=shift; @@ -150,9 +247,12 @@ ENDNAV $lt{'ret'} ENDRELOAD } - if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) { - $docs=(<$lt{'docs'} + my $is_community = + (&Apache::loncommon::course_type() eq 'Community'); + if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) { + my $text = ($is_community) ? $lt{'gdoc'} : $lt{'docs'}; + $docs=(<$text ENDDOCS } if ($showgroups) { @@ -217,9 +317,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 @@ -255,8 +356,8 @@ ENDCRELOAD my $helplink=&Apache::loncommon::top_nav_help('Help'); return (< -// BEGIN LON-CAPA Internal // @@ -297,7 +398,6 @@ sub show_return_link { )); } -# ====================================== This gets called in the header section sub registerurl { my ($forcereg) = @_; @@ -314,7 +414,9 @@ sub registerurl { &unescape($env{'request.noversionuri'})))) && (!$forcereg))) { return $result. - ''.$force_title; + ''.$force_title; } # Graphical display after login only if ($env{'request.registered'} && !$forcereg) { return ''; } @@ -322,9 +424,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 +500,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 +521,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 +554,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,6 +563,7 @@ 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/; @@ -477,10 +584,27 @@ sub innerregister { $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 +622,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"; + + 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.=(< +// ENDREGTHIS } @@ -672,6 +816,7 @@ ENDDONOTREGTEXT $result = (< +// ENDDONOTREGTHIS } @@ -704,6 +850,42 @@ ENDDONOTREGTHIS return $result; } +sub is_course_upload { + my ($file,$cnum,$cdom) = @_; + my $uploadpath = &LONCAPA::propath($cdom,$cnum); + $uploadpath =~ s{^\/}{}; + if (($file =~ m{^\Q$uploadpath\E/userfiles/docs/}) || + ($file =~ m{^userfiles/\Q$cdom\E/\Q$cnum\E/docs/})) { + return 1; + } + return; +} + +sub edit_course_upload { + my ($file,$cnum,$cdom) = @_; + my $cfile; + if ($file =~/\.(htm|html|css|js|txt)$/) { + my $ext = $1; + my $url = &Apache::lonnet::hreflocation('',$file); + my $home = &Apache::lonnet::homeserver($cnum,$cdom); + my @ids=&Apache::lonnet::current_machine_ids(); + my $dest; + if ($home && grep(/^\Q$home\E$/,@ids)) { + $dest = $url.'?forceedit=1'; + } else { + unless (&Apache::lonnet::get_locks()) { + $dest = '/adm/switchserver?otherserver='. + $home.'&role='.$env{'request.role'}. + '&url='.$url.'&forceedit=1'; + } + } + if ($dest) { + $cfile = &HTML::Entities::encode($dest,'"<>&'); + } + } + return $cfile; +} + sub loadevents() { if ($env{'request.state'} eq 'construct' || $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; } @@ -716,7 +898,6 @@ sub unloadevents() { return 'LONCAPAstale();'; } -# ============================================================= Start up remote sub startupremote { my ($lowerurl)=@_; @@ -732,6 +913,7 @@ sub startupremote { my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited'); return(< +// ENDREMOTESTARTUP } @@ -789,8 +971,10 @@ ENDREMOTESTARTUP sub setflags() { return(< +// ENDSETFLAGS } @@ -800,7 +984,9 @@ sub maincall() { ($env{'environment.remote'} eq 'off')) { return ''; } return(< +// ENDMAINCALL } @@ -812,8 +998,9 @@ sub load_remote_msg { ($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,7 +1017,6 @@ sub get_menu_name { return 'LCmenu'.$hostid; } -# ================================================================= Reopen menu sub reopenmenu { if (($env{'browser.interface'} eq 'textual') || @@ -840,13 +1026,17 @@ sub reopenmenu { return('window.open('.$nothing.',"'.$menuname.'","",false);'); } -# =============================================================== Open the menu sub open { my $returnval=''; if (($env{'browser.interface'} eq 'textual') || ($env{'environment.remote'} eq 'off')) { - return ''; + return + ''; } my $menuname = &get_menu_name(); @@ -859,11 +1049,13 @@ sub open { #} #ENDRESIZE # } - $returnval.=(< ENDOPEN return ''; } @@ -990,11 +1182,14 @@ sub inlinemenu { &rawconfig(1); my $output=''; for (my $col=1; $col<=2; $col++) { - $output.='"; @@ -1027,7 +1223,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,6 +1317,32 @@ 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 '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; + } + } + $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') || @@ -1134,6 +1356,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 { @@ -1142,6 +1386,7 @@ sub close { my $menuname = &get_menu_name(); return(< +// ENDCLOSE } @@ -1337,16 +1583,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 +1200,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(); } @@ -1421,13 +1667,18 @@ sub hidden_button_check { sub roles_selector { my ($cdom,$cnum) = @_; + my $crstype = &Apache::loncommon::course_type(); my $now = time; - my (%courseroles,%seccount,%gotnosection); + my (%courseroles,%seccount); my $is_cc; my $role_selector; - if ($env{'user.role.cc./'.$cdom.'/'.$cnum}) { - my ($start,$end) = split(/\./,$env{'user.role.cc./'.$cdom.'/'.$cnum}); - + if ($crstype eq 'Community') { + $ccrole = 'co'; + } else { + $ccrole = 'cc'; + } + if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) { + my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}); if ((($start) && ($start<0)) || (($end) && ($end<$now)) || (($start) && ($now<$start))) { @@ -1437,35 +1688,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; @@ -1496,15 +1721,22 @@ sub roles_selector { } } } - my @roles_order = ('cc','in','ta','ep','ad','st'); + my $switchtext; + if ($crstype eq 'Community') { + $switchtext = &mt('Switch community role to...') + } else { + $switchtext = &mt('Switch course role to...') + } + + my @roles_order = ($ccrole,'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". @@ -1523,6 +1755,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( @@ -1554,8 +1841,9 @@ sub jump_to_role { ' numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n"; } } - my $output = <<"END"; + return <<"END"; END - return $output; }