--- loncom/interface/lonmenu.pm 2012/12/26 23:50:26 1.400
+++ loncom/interface/lonmenu.pm 2013/07/03 16:44:20 1.417
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the menu
#
-# $Id: lonmenu.pm,v 1.400 2012/12/26 23:50:26 raeburn Exp $
+# $Id: lonmenu.pm,v 1.417 2013/07/03 16:44:20 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -106,10 +106,11 @@ secondary_menu().
=item primary_menu()
-This routine evaluates @primary_menu and returns XHTML for the menu
-that contains following links: About, Message, Roles, Help, Logout
+This routine evaluates @primary_menu and returns a two item array,
+with the array elements containing XHTML for the left and right sides of
+the menu that contains the following links: About, Message, Roles, Help, Logout
@primary_menu is filled within the BEGIN block of this module with
-entries from mydesk.tab
+entries from mydesk.tab
=item secondary_menu()
@@ -203,15 +204,16 @@ sub prep_menuitem {
. qq| href="$$menuitem[0]" target="_top">$link|;
}
-# primary_menu() evaluates @primary_menu and returns XHTML for the menu
-# that contains following links:
-# About, Message, Personal, Roles, Help, Logout
+# primary_menu() evaluates @primary_menu and returns a two item array,
+# with the array elements containing XHTML for the left and right sides of
+# the menu that contains the following links:
+# Personal, 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;
+ my (%menu);
# each element of @primary contains following array:
- # (link url, icon path, alt text, link text, condition)
+ # (link url, icon path, alt text, link text, condition, position)
my $public;
if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
|| (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
@@ -236,6 +238,10 @@ sub primary_menu {
&& !&Apache::loncommon::show_course(); ##
my $title = $menuitem->[3];
+ my $position = $menuitem->[5];
+ if ($position eq '') {
+ $position = 'right';
+ }
if (defined($primary_submenu{$title})) {
my ($link,$target);
if ($menuitem->[0] ne '') {
@@ -248,7 +254,6 @@ sub primary_menu {
if (ref($primary_submenu{$title}) eq 'ARRAY') {
foreach my $item (@{$primary_submenu{$title}}) {
next if (($item->[2] eq 'wishlist') && (!$env{'user.adv'}));
- next if (($item->[2] eq 'reqcrs') && (!&check_for_rcrs()));
next if ((($item->[2] eq 'portfolio') ||
($item->[2] eq 'blog')) &&
(!&Apache::lonnet::usertools_access('','',$item->[2],
@@ -256,9 +261,9 @@ sub primary_menu {
push(@primsub,$item);
}
if (@primsub > 0) {
- $menu .= &create_submenu($link,$target,$title,\@primsub);
+ $menu{$position} .= &create_submenu($link,$target,$title,\@primsub);
} elsif ($link) {
- $menu .= '
'.&mt($title).'';
+ $menu{$position} .= ''.&mt($title).'';
}
}
} elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
@@ -269,19 +274,17 @@ sub primary_menu {
'helpdeskmail',
$defdom,$origmail);
if ($to ne '') {
- $menu .= &prep_menuitem($menuitem);
+ $menu{$position} .= &prep_menuitem($menuitem);
}
} else {
- $menu .= ''.&Apache::loncommon::top_nav_help('Help').'';
+ $menu{$position} .= ''.&Apache::loncommon::top_nav_help('Help').'';
}
} else {
- $menu .= prep_menuitem($menuitem);
+ $menu{$position} .= prep_menuitem($menuitem);
}
}
- $menu =~ s/\[domain\]/$env{'user.domain'}/g;
- $menu =~ s/\[user\]/$env{'user.name'}/g;
-
- return "";
+ return ("",
+ "");
}
#returns hashref {user=>'',dom=>''} containing:
@@ -326,16 +329,55 @@ sub secondary_menu {
my $canmgr = &Apache::lonnet::allowed('mgr', $crs_sec);
my $author = &getauthor();
+ my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv);
+ if ($env{'request.course.id'}) {
+ $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ if ($canedit) {
+ $showsyllabus = 1;
+ $showfeeds = 1;
+ } else {
+ unless (&Apache::lonnet::is_on_map("public/$cdom/$cnum/syllabus")) {
+ if (($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'}) ||
+ ($env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) ||
+ ($env{'course.'.$env{'request.course.id'}.'.updatedsyllabus'}) ||
+ ($env{'request.course.syllabustime'})) {
+ $showsyllabus = 1;
+ }
+ }
+ if ($env{'request.course.feeds'}) {
+ $showfeeds = 1;
+ }
+ }
+ unless ($canmgr) {
+ my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
+ if (keys(%slots) > 0) {
+ $showresv = 1;
+ }
+ }
+ }
+
+ my ($canmodifycoauthor);
+ if ($env{'request.role'} eq "au./$env{'user.domain'}/") {
+ my $extent = "$env{'user.domain'}/$env{'user.name'}";
+ if ((&Apache::lonnet::allowed('cca',$extent)) ||
+ (&Apache::lonnet::allowed('caa',$extent))) {
+ $canmodifycoauthor = 1;
+ }
+ }
+
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'});
+ my ($roleswitcher_js,$roleswitcher_form);
+
foreach my $menuitem (@secondary_menu) {
# evaluate conditions
next if ref($menuitem) ne 'ARRAY';
next if $$menuitem[4] ne 'always'
- && $$menuitem[4] ne 'author'
+ && ($$menuitem[4] ne 'author' && $$menuitem[4] ne 'cca')
&& !$env{'request.course.id'};
next if $$menuitem[4] =~ /^mdc/
&& !$canedit;
@@ -349,8 +391,8 @@ sub secondary_menu {
&& ($canmodifyuser || !$canviewroster);
next if $$menuitem[4] eq 'mgr'
&& !$canmgr;
- next if $$menuitem[4] eq 'nmgr'
- && $canmgr;
+ next if $$menuitem[4] eq 'showresv'
+ && !$showresv;
next if $$menuitem[4] eq 'whn'
&& !$canviewwnew;
next if $$menuitem[4] eq 'opa'
@@ -358,18 +400,35 @@ sub secondary_menu {
next if $$menuitem[4] =~ /showgroups$/
&& !$canviewgrps
&& !%groups;
+ next if $$menuitem[4] eq 'showsyllabus'
+ && !$showsyllabus;
+ next if $$menuitem[4] eq 'showfeeds'
+ && !$showfeeds;
next if $$menuitem[4] eq 'author'
&& !$author;
+ next if $$menuitem[4] eq 'cca'
+ && !$canmodifycoauthor;
if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
# special treatment for role selector
- my $roles_selector = &roles_selector(
+ ($roleswitcher_js,$roleswitcher_form,my $switcher) =
+ &roles_selector(
$env{'course.' . $env{'request.course.id'} . '.domain'},
- $env{'course.' . $env{'request.course.id'} . '.num'} );
-
- $menu .= $roles_selector ? "$roles_selector"
- : '';
+ $env{'course.' . $env{'request.course.id'} . '.num'}
+ );
+ $menu .= $switcher;
} else {
+ if ($$menuitem[3] eq 'Syllabus' && $env{'request.course.id'}) {
+ my $url = $$menuitem[0];
+ $url =~ s{\[cdom\]/\[cnum\]}{$cdom/$cnum};
+ if (&Apache::lonnet::is_on_map($url)) {
+ unless ($$menuitem[0] =~ /\?register=1/) {
+ $$menuitem[0] .= '?register=1';
+ }
+ } else {
+ $$menuitem[0] =~ s{\?register=1}{};
+ }
+ }
$menu .= &prep_menuitem(\@$menuitem);
}
}
@@ -393,9 +452,16 @@ sub secondary_menu {
}
$menu =~ s/\[uname\]/$$author{user}/g;
$menu =~ s/\[udom\]/$$author{dom}/g;
+ if ($showsyllabus || $showfeeds) {
+ $menu =~ s/\[cnum\]/$cnum/g;
+ $menu =~ s/\[cdom\]/$cdom/g;
+ }
if ($menu) {
$menu = "";
}
+ if ($roleswitcher_form) {
+ $menu .= "\n$roleswitcher_js\n$roleswitcher_form";
+ }
return $menu;
}
@@ -406,9 +472,19 @@ sub create_submenu {
if ($target ne '') {
$disptarget = ' target="'.$target.'"';
}
+ my $name;
+ if ($title eq 'Personal') {
+ if ($env{'user.name'} && $env{'user.domain'}) {
+ $name = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
+ } else {
+ $name = &mt($title);
+ }
+ } else {
+ $name = &mt($title);
+ }
my $menu = ''.
''.
- ''.&mt($title).
+ ''.$name.
''.
' ▼'.
'';
@@ -417,12 +493,18 @@ sub create_submenu {
foreach my $item (@{$submenu}) {
$count ++;
if (ref($item) eq 'ARRAY') {
+ my $href = $item->[0];
+ if ($href =~ /(aboutme|rss\.html)$/) {
+ next unless (($env{'user.name'} ne '') && ($env{'user.domain'} ne ''));
+ $href =~ s/\[domain\]/$env{'user.domain'}/g;
+ $href =~ s/\[user\]/$env{'user.name'}/g;
+ }
my $borderbot;
if ($count == $numsub) {
$borderbot = 'border-bottom:1px solid black;';
}
$menu .= '- '.
+ $borderbot.'">'.
&mt($item->[1]).'
';
}
}
@@ -499,6 +581,14 @@ sub innerregister {
&Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
}
return $trail;
+ } elsif ($resurl =~ m{^\Q/uploaded$courseurl/portfolio/syllabus/}) {
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
+ &prepare_functions('/public'.$courseurl."/syllabus",
+ $forcereg,$group,undef,undef,1);
+ $title = &mt('Syllabus File');
+ my ($trail) =
+ &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
+ return $trail;
}
unless ($env{'request.state'} eq 'construct') {
&Apache::lonhtmlcommon::clear_breadcrumbs();
@@ -831,24 +921,18 @@ sub prepare_functions {
#
# This applies in course context
#
- if (($resurl eq "/public/$cdom/$cnum/syllabus") && ($perms{'mdc'})) {
- if ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ /\w/) {
- &switch('','',6,1,'pcstr.png','Edit',
- 'resource[_2]',
- "go('/adm/courseprefs?phase=display&actions=courseinfo')",
- 'Edit this resource');
- $editbutton = 1;
+ if (($perms{'mdc'}) &&
+ (($resurl eq "/public/$cdom/$cnum/syllabus") ||
+ ($resurl =~ m{^/uploaded/$cdom/$cnum/portfolio/syllabus/}))) {
+ $cfile = $resurl;
+ $home = &Apache::lonnet::homeserver($cnum,$cdom);
+ if ($env{'form.forceedit'}) {
+ $forceview = 1;
} else {
- $cfile = $resurl;
- $home = &Apache::lonnet::homeserver($cnum,$cdom);
- if ($env{'form.forceedit'}) {
- $forceview = 1;
- } else {
- $forceedit = 1;
- }
- $editbutton = &get_editbutton($cfile,$home,$switchserver,
- $forceedit,$forceview,$forcereg);
+ $forceedit = 1;
}
+ $editbutton = &get_editbutton($cfile,$home,$switchserver,
+ $forceedit,$forceview,$forcereg);
} elsif (($resurl eq '/adm/extresedit') &&
(($env{'form.symb'}) || ($env{'form.folderpath'}))) {
($cfile,$home,$switchserver,$forceedit,$forceview) =
@@ -859,7 +943,15 @@ sub prepare_functions {
$forceedit,$forceview,$forcereg,
$env{'form.title'},$env{'form.suppurl'});
}
- } elsif ($resurl !~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
+ } elsif (($resurl =~ m{^/?adm/viewclasslist$}) &&
+ (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) {
+ ($cfile,$home,$switchserver,$forceedit,$forceview) =
+ &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
+ $env{'form.symb'});
+ $editbutton = &get_editbutton($cfile,$home,$switchserver,
+ $forceedit,$forceview,$forcereg);
+ } elsif (($resurl !~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) &&
+ ($resurl ne '/cgi-bin/printout.pl')) {
if ($env{'request.filename'}) {
my $file=&Apache::lonnet::declutter($env{'request.filename'});
($cfile,$home,$switchserver,$forceedit,$forceview) =
@@ -881,7 +973,7 @@ sub prepare_functions {
unless (&Apache::lonnet::is_course($sdom,$sname)) {
&switch('','',6,4,'mail-message-new-22x22.png','Message to user',
'',
- "go('/adm/email?compose=individual&recname=$sname&recdom=$sdom')",
+ "go('/adm/email?compose=individual&recname=$sname&recdom=$sdom')",
'Send message to specific user');
}
my $hideprivileged = 1;
@@ -903,24 +995,16 @@ sub prepare_functions {
if ($perms{'vgr'}) {
&switch('','',6,6,'rsrv-22x22.png','Reservations',
'',
- "go('/adm/slotrequest?command=showresv&origin=aboutme&uname=$sname&udom=$sdom')",
+ "go('/adm/slotrequest?command=showresv&origin=aboutme&uname=$sname&udom=$sdom')",
'Slot reservation history');
}
if ($perms{'srm'}) {
&switch('','',6,7,'contact-new-22x22.png','Records',
'',
- "go('/adm/email?recordftf=retrieve&recname=$sname&recdom=$sdom')",
+ "go('/adm/email?recordftf=retrieve&recname=$sname&recdom=$sdom')",
'Add records');
}
}
- } elsif ($resurl =~ m{^/?adm/viewclasslist}) {
-# This applies to viewclasslist page for users in a course
- if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
- &switch('','',6,4,'pparm.png','Settings',
- '',
- "go('/adm/courseprefs?actions=classlists&phase=display')",
- 'Student-viewable classlist options');
- }
}
if (($env{'form.folderpath'} =~ /^supplemental/) &&
(&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
@@ -933,7 +1017,7 @@ sub prepare_functions {
if ((@folders > 2) || ($resurl ne '/adm/supplemental')) {
my $esc_path=&escape(&HTML::Entities::encode(&escape($env{'form.folderpath'}),'<>&"'));
&switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
- "location.href='/adm/coursedocs?command=direct&forcesupplement=1&supppath=$esc_path'",
+ "location.href='/adm/coursedocs?command=direct&forcesupplement=1&supppath=$esc_path'",
'Folder/Page Content');
}
}
@@ -974,8 +1058,9 @@ sub advtools_crumbs {
'advtools', @funcs[61,71,72,73,74,92]);
} elsif ($env{'request.noversionuri'} eq '/adm/viewclasslist') {
&Apache::lonhtmlcommon::add_breadcrumb_tool(
- 'advtools', @funcs[64]);
+ 'advtools', $funcs[61]);
}
+ return;
}
# ================================================================== Raw Config
@@ -1569,7 +1654,7 @@ sub roles_selector {
my $now = time;
my (%courseroles,%seccount,%courseprivs);
my $is_cc;
- my $role_selector;
+ my ($js,$form,$switcher,$switchtext);
my $ccrole;
if ($crstype eq 'Community') {
$ccrole = 'co';
@@ -1657,42 +1742,66 @@ sub roles_selector {
}
}
}
- my $switchtext;
- if ($crstype eq 'Community') {
- $switchtext = &mt('Switch community role to...')
- } else {
- $switchtext = &mt('Switch course role to...')
- }
+ $switchtext = &mt('Switch role');
my @roles_order = ($ccrole,'in','ta','ep','ad','st');
- if (keys(%courseroles) > 1) {
- $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,$priv);
- $role_selector .= '
';
}
- return $role_selector;
+ return ($js,$form,$switcher);
}
sub get_all_courseroles {
@@ -1755,6 +1864,7 @@ sub get_all_courseroles {
push(@{$courseroles->{'st'}},keys(%sections_count));
$seccount->{'st'} = scalar(keys(%sections_count));
}
+ $seccount->{'st'} ++; # Increment for a section-less student role.
my $rolehash = {
'roles' => $courseroles,
'seccount' => $seccount,
@@ -1831,9 +1941,8 @@ sub jump_to_role {
return <<"END";