--- loncom/interface/lonmenu.pm 2012/12/06 13:38:25 1.395
+++ loncom/interface/lonmenu.pm 2013/05/05 00:15:02 1.412
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the menu
#
-# $Id: lonmenu.pm,v 1.395 2012/12/06 13:38:25 raeburn Exp $
+# $Id: lonmenu.pm,v 1.412 2013/05/05 00:15:02 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -248,7 +248,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],
@@ -326,16 +325,27 @@ sub secondary_menu {
my $canmgr = &Apache::lonnet::allowed('mgr', $crs_sec);
my $author = &getauthor();
+ 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;
@@ -360,15 +370,17 @@ sub secondary_menu {
&& !%groups;
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 {
$menu .= &prep_menuitem(\@$menuitem);
}
@@ -396,6 +408,9 @@ sub secondary_menu {
if ($menu) {
$menu = "";
}
+ if ($roleswitcher_form) {
+ $menu .= "\n$roleswitcher_js\n$roleswitcher_form";
+ }
return $menu;
}
@@ -487,8 +502,7 @@ sub innerregister {
}
my $trail;
if ($env{'form.folderpath'}) {
- my $editbutton =
- &prepare_functions($resurl,$forcereg,$group,undef,undef,1);
+ &prepare_functions($resurl,$forcereg,$group,undef,undef,1);
($trail) =
&Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
} else {
@@ -500,6 +514,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();
@@ -525,7 +547,7 @@ sub innerregister {
$editbutton = &prepare_functions($resurl,$forcereg,$group);
}
if ($editbutton eq '') {
- &clear(6,1);
+ $editbutton = &clear(6,1);
}
#
@@ -578,7 +600,7 @@ sub innerregister {
my $text = 'Edit Folder';
if (($mapurl =~ /\.page$/) ||
($env{'request.symb'}=~
- /^uploaded/$cdom/$cnum/default_\d+\.page$/)) {
+ m{uploaded/$cdom/$cnum/default_\d+\.page$})) {
$text = 'Edit Page';
}
&switch('','',7,4,'docs-22x22.png',$text,'parms[_2]',
@@ -754,12 +776,24 @@ ENDMENUITEMS
sub get_editbutton {
my ($cfile,$home,$switchserver,$forceedit,$forceview,$forcereg) = @_;
- my $jscall =
- &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
+ my $jscall;
+ if (($forceview) && ($env{'form.todocs'})) {
+ my ($folderpath,$command);
+ if ($env{'request.symb'}) {
+ $folderpath = &Apache::loncommon::symb_to_docspath($env{'request.symb'});
+ } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
+ $folderpath = $env{'form.folderpath'};
+ $command = '&forcesupplement=1';
+ }
+ $folderpath = &escape(&HTML::Entities::encode(&escape($folderpath),'<>&"'));
+ $jscall = "go('/adm/coursedocs?folderpath=$folderpath$command')";
+ } else {
+ $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
$forceedit,$forcereg,$env{'request.symb'},
&escape($env{'form.folderpath'}),
&escape($env{'form.title'}),$env{'form.idx'},
- &escape($env{'form.suppurl'}));
+ &escape($env{'form.suppurl'},$env{'form.todocs'}));
+ }
if ($jscall) {
my $icon = 'pcstr.png';
my $label = 'Edit';
@@ -820,24 +854,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) =
@@ -848,7 +876,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) =
@@ -902,20 +938,14 @@ sub prepare_functions {
'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'})) &&
(($resurl =~ m{^/adm/wrapper/ext/}) ||
($resurl =~ m{^/uploaded/$cdom/$cnum/supplemental/}) ||
- ($resurl eq '/adm/supplemental'))) {
+ ($resurl eq '/adm/supplemental') ||
+ ($resurl =~ m{^/public/$cdom/$cnum/syllabus$}) ||
+ ($resurl =~ m{^/adm/$match_domain/$match_username/aboutme$}))) {
my @folders=split('&',$env{'form.folderpath'});
if ((@folders > 2) || ($resurl ne '/adm/supplemental')) {
my $esc_path=&escape(&HTML::Entities::encode(&escape($env{'form.folderpath'}),'<>&"'));
@@ -961,8 +991,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
@@ -1556,7 +1587,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';
@@ -1644,42 +1675,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 {
@@ -1742,6 +1797,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,
@@ -1818,9 +1874,8 @@ sub jump_to_role {
return <<"END";