--- loncom/interface/lonmenu.pm 2012/12/27 05:52:00 1.369.2.30
+++ loncom/interface/lonmenu.pm 2013/08/08 02:24:02 1.369.2.44
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the menu
#
-# $Id: lonmenu.pm,v 1.369.2.30 2012/12/27 05:52:00 raeburn Exp $
+# $Id: lonmenu.pm,v 1.369.2.44 2013/08/08 02:24:02 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()
@@ -223,15 +224,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 ''))) {
@@ -256,6 +258,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 '') {
@@ -268,7 +274,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],
@@ -276,9 +281,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
@@ -289,19 +294,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:
@@ -338,6 +341,9 @@ sub secondary_menu {
: '');
my $canedit = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
my $canviewroster = $env{'course.'.$env{'request.course.id'}.'.student_classlist_view'};
+ if ($canviewroster eq 'disabled') {
+ undef($canviewroster);
+ }
my $canviewgrps = &Apache::lonnet::allowed('vcg', $crs_sec);
my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec);
my $canviewwnew = &Apache::lonnet::allowed('whn', $crs_sec);
@@ -346,6 +352,34 @@ sub secondary_menu {
my $canmgr = &Apache::lonnet::allowed('mgr', $crs_sec);
my $author = &getauthor();
+ my ($cdom,$cnum,$showsyllabus,$showfeeds);
+ if ($env{'request.course.id'}) {
+ $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ unless ($canedit) {
+ 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;
+ }
+ }
+ }
+
+ 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'},
@@ -357,7 +391,7 @@ sub 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;
@@ -383,8 +417,14 @@ sub secondary_menu {
&& !$canmodpara;
next if $$menuitem[4] eq 'nvcg'
&& ($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;
my $title = $menuitem->[3];
if (defined($secondary_submenu{$title})) {
@@ -395,7 +435,7 @@ sub secondary_menu {
} else {
$link = '#';
}
- my @scndsub;
+ my @scndsub;
if (ref($secondary_submenu{$title}) eq 'ARRAY') {
foreach my $item (@{$secondary_submenu{$title}}) {
if (ref($item) eq 'ARRAY') {
@@ -404,12 +444,13 @@ sub secondary_menu {
next if ($item->[2] eq 'cst' && !$canmodifyuser);
next if ($item->[2] eq 'mgr' && !$canmgr);
next if ($item->[2] eq 'vcg' && !$canviewgrps);
+ next if ($item->[2] eq 'mdc' && !$canedit);
push(@scndsub,$item);
}
}
if (@scndsub > 0) {
$menu .= &create_submenu($link,$target,$title,\@scndsub);
- } elsif ($link) {
+ } elsif ($link ne '#') {
$menu .= ''.&mt($title).'';
}
}
@@ -422,6 +463,17 @@ sub secondary_menu {
);
$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);
}
}
@@ -445,6 +497,10 @@ sub secondary_menu {
}
$menu =~ s/\[uname\]/$$author{user}/g;
$menu =~ s/\[udom\]/$$author{dom}/g;
+ if ($env{'request.course.id'}) {
+ $menu =~ s/\[cnum\]/$cnum/g;
+ $menu =~ s/\[cdom\]/$cdom/g;
+ }
if ($menu) {
$menu = "";
}
@@ -461,9 +517,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.
''.
' ▼'.
'';
@@ -472,12 +538,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]).'
';
}
}
@@ -594,6 +666,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();
@@ -626,6 +706,9 @@ sub innerregister {
$forceview,$editbutton);
if (($resurl =~ m{^/adm/($match_domain)/($match_username)/aboutme$}) ||
($env{'request.role'} !~/^(aa|ca|au)/)) {
+ if (($env{'environment.remote'} eq 'on') && ($env{'request.symb'})) {
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
+ }
$editbutton = &prepare_functions($resurl,$forcereg,$group);
}
if ($editbutton eq '') {
@@ -1210,15 +1293,31 @@ sub get_editbutton {
$icon = 'tolastloc.png';
$label = 'Exit Editing';
}
- &switch('','',6,1,$icon,$label,'resource[_2]',
- $jscall,"Edit this resource");
- return 1;
+ my $infunc = 1;
+ my $clearbutton;
+ if ($env{'environment.remote'} eq 'on') {
+ if ($cfile =~ m{^/priv/}) {
+ undef($infunc);
+ $label = 'edit';
+ } else {
+ $clearbutton = 1;
+ }
+ }
+ my $editor = &switch('','',6,1,$icon,$label,'resource[_2]',
+ $jscall,"Edit this resource",'','',$infunc);
+ if ($infunc) {
+ return 1;
+ } elsif ($clearbutton) {
+ return &clear(6,1);
+ } else {
+ return $editor;
+ }
}
return;
}
sub prepare_functions {
- my ($resurl,$forcereg,$group,$bread_crumbs,$advtools,$docscrumbs) = @_;
+ my ($resurl,$forcereg,$group,$bread_crumbs,$advtools,$docscrumbs,$forbodytag) = @_;
unless ($env{'request.registered'}) {
undef(@inlineremote);
}
@@ -1263,24 +1362,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) =
@@ -1291,7 +1384,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) =
@@ -1313,8 +1414,8 @@ 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')",
- 'Send message to specific user');
+ "go('/adm/email?compose=individual&recname=$sname&recdom=$sdom')",
+ 'Send message to specific user','','',1);
}
my $hideprivileged = 1;
if (&Apache::lonnet::in_course($sdom,$sname,$cdom,$cnum,undef,
@@ -1330,29 +1431,21 @@ sub prepare_functions {
&switch('','',6,5,'trck-22x22.png','Activity',
'',
"go('/adm/trackstudent?selected_student=$sname:$sdom')",
- 'View recent activity by this person');
+ 'View recent activity by this person','','',1);
}
if ($perms{'vgr'}) {
&switch('','',6,6,'rsrv-22x22.png','Reservations',
'',
- "go('/adm/slotrequest?command=showresv&origin=aboutme&uname=$sname&udom=$sdom')",
- 'Slot reservation history');
+ "go('/adm/slotrequest?command=showresv&origin=aboutme&uname=$sname&udom=$sdom')",
+ 'Slot reservation history','','',1);
}
if ($perms{'srm'}) {
&switch('','',6,7,'contact-new-22x22.png','Records',
'',
- "go('/adm/email?recordftf=retrieve&recname=$sname&recdom=$sdom')",
- 'Add records');
+ "go('/adm/email?recordftf=retrieve&recname=$sname&recdom=$sdom')",
+ 'Add records','','',1);
}
}
- } 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'})) &&
@@ -1365,8 +1458,8 @@ 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'",
- 'Folder/Page Content');
+ "location.href='/adm/coursedocs?command=direct&forcesupplement=1&supppath=$esc_path'",
+ 'Folder/Page Content','','',1);
}
}
}
@@ -1376,7 +1469,7 @@ sub prepare_functions {
&Apache::lonhtmlcommon::clear_breadcrumb_tools();
&advtools_crumbs(@inlineremote);
return $editbutton;
- } elsif ($env{'request.registered'}) {
+ } elsif (($env{'request.registered'}) && (!ref($forbodytag))) {
return $editbutton;
} else {
if (ref($bread_crumbs) eq 'ARRAY') {
@@ -1389,9 +1482,13 @@ sub prepare_functions {
} elsif (@inlineremote > 0) {
&Apache::lonhtmlcommon::clear_breadcrumb_tools();
&advtools_crumbs(@inlineremote);
- return &Apache::lonhtmlcommon::scripttag('', 'start')
- . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
- . &Apache::lonhtmlcommon::scripttag('', 'end');
+ if (ref($forbodytag)) {
+ $$forbodytag =
+ &Apache::lonhtmlcommon::scripttag('', 'start')
+ .&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
+ .&Apache::lonhtmlcommon::scripttag('', 'end');
+ }
+ return;
}
}
}
@@ -1406,7 +1503,7 @@ 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]);
}
}
@@ -1428,7 +1525,7 @@ sub clear {
# The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
sub switch {
- my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
+ my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak,$infunc)=@_;
$act=~s/\$uname/$uname/g;
$act=~s/\$udom/$udom/g;
$top=&mt($top);
@@ -1437,7 +1534,7 @@ sub switch {
my $idx=10*$row+$col;
$category_members{$cat}.=':'.$idx;
- if ($env{'environment.remote'} eq 'on') {
+ if (($env{'environment.remote'} eq 'on') && (!$infunc)) {
if (($row<1) || ($row>13)) { return ''; }
if ($env{'request.state'} eq 'construct') {
my $text = $top.' '.$bot;
@@ -2171,12 +2268,7 @@ sub roles_selector {
}
}
}
- my $switchtext;
- if ($crstype eq 'Community') {
- $switchtext = &mt('Switch community role')
- } else {
- $switchtext = &mt('Switch course role')
- }
+ $switchtext = &mt('Switch role');
my @roles_order = ($ccrole,'in','ta','ep','ad','st');
my $numdiffsec;
if (keys(%seccount) == 1) {
@@ -2298,6 +2390,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,
@@ -2503,7 +2596,6 @@ sub countdown_timer {
}
my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
my @interval=&Apache::lonnet::EXT("resource.0.interval");
- my $hastimeleft;
if (@interval > 1) {
my $first_access=&Apache::lonnet::get_first_access($interval[1]);
if ($first_access > 0) {
@@ -2561,7 +2653,7 @@ BEGIN {
$category_positions{$entries[2]}=$entries[1];
$category_names{$entries[2]}=$entries[3];
} elsif ($configline=~/^prim\:/) {
- my @entries = (split(/\:/, $configline))[1..5];
+ my @entries = (split(/\:/, $configline))[1..6];
push(@primary_menu,\@entries);
} elsif ($configline=~/^primsub\:/) {
my ($parent,@entries) = (split(/\:/, $configline))[1..4];