';
+ for (my $col=1; $col<=2; $col++) {
+ $output.='';
+ for (my $row=1; $row<=8; $row++) {
+ foreach my $cat (keys(%category_members)) {
+ if ($category_positions{$cat} ne "$col,$row") { next; }
+ #$output.=' ';
+ $output.='';
+ $output.=''.&mt($category_names{$cat}).' ';
+ $output.='';
+ my %active=();
+ foreach my $menu_item (split(/\:/,$category_members{$cat})) {
+ if ($inlineremote[$menu_item]) {
+ $active{$menu_item}=1;
+ }
+ }
+ foreach my $item (sort(keys(%active))) {
+ $output.=$inlineremote[$item];
+ }
+ $output.='
';
+ $output.=' ';
+ }
+ }
+ $output.="";
+ }
+ $output.="
";
+ return $output;
}
sub rawconfig {
my $textualoverride=shift;
my $output='';
- unless (($ENV{'browser.interface'} eq 'textual') ||
- ($ENV{'environment.remote'} eq 'off')) {
+ unless (($env{'browser.interface'} eq 'textual') ||
+ ($env{'environment.remote'} eq 'off')) {
$output.=
"window.status='Opening Remote Control';var swmenu=".&openmenu().
"\nwindow.status='Configuring Remote Control ';";
} else {
unless ($textualoverride) { return ''; }
}
- my $uname=$ENV{'user.name'};
- my $udom=$ENV{'user.domain'};
- my $adv=$ENV{'user.adv'};
- my $author=$ENV{'user.author'};
+ my $uname=$env{'user.name'};
+ my $udom=$env{'user.domain'};
+ my $adv=$env{'user.adv'};
+ my $show_course=&Apache::loncommon::show_course();
+ my $author=$env{'user.author'};
my $crs='';
- if ($ENV{'request.course.id'}) {
- $crs='/'.$ENV{'request.course.id'};
- if ($ENV{'request.course.sec'}) {
- $crs.='_'.$ENV{'request.course.sec'};
+ my $crstype='';
+ if ($env{'request.course.id'}) {
+ $crs='/'.$env{'request.course.id'};
+ if ($env{'request.course.sec'}) {
+ $crs.='_'.$env{'request.course.sec'};
}
$crs=~s/\_/\//g;
+ $crstype = &Apache::loncommon::course_type();
}
- my $pub=($ENV{'request.state'} eq 'published');
- my $con=($ENV{'request.state'} eq 'construct');
- my $rol=$ENV{'request.role'};
- my $requested_domain = $ENV{'request.role.domain'};
- foreach (@desklines) {
- my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc)=split(/\:/,$_);
+ my $pub=($env{'request.state'} eq 'published');
+ my $con=($env{'request.state'} eq 'construct');
+ my $rol=$env{'request.role'};
+ my $requested_domain = $env{'request.role.domain'};
+ foreach my $line (@desklines) {
+ my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
$prt=~s/\$uname/$uname/g;
$prt=~s/\$udom/$udom/g;
- $prt=~s/\$crs/$crs/g;
+ if ($prt =~ /\$crs/) {
+ next unless ($env{'request.course.id'});
+ next if ($crstype eq 'Community');
+ $prt=~s/\$crs/$crs/g;
+ } elsif ($prt =~ /\$cmty/) {
+ next unless ($env{'request.course.id'});
+ next if ($crstype ne 'Community');
+ $prt=~s/\$cmty/$crs/g;
+ }
$prt=~s/\$requested_domain/$requested_domain/g;
+ if ($category_names{$cat}!~/\w/) { $cat='oth'; }
if ($pro eq 'clear') {
$output.=&clear($row,$col);
} elsif ($pro eq 'any') {
$output.=&secondlevel(
- $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
+ $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
} elsif ($pro eq 'smp') {
unless ($adv) {
$output.=&secondlevel(
- $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
+ $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
}
} elsif ($pro eq 'adv') {
if ($adv) {
$output.=&secondlevel(
- $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
+ $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
+ }
+ } elsif ($pro eq 'shc') {
+ if ($show_course) {
+ $output.=&secondlevel(
+ $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
+ }
+ } elsif ($pro eq 'nsc') {
+ if (!$show_course) {
+ $output.=&secondlevel(
+ $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
}
} elsif (($pro=~/^p(\w+)/) && ($prt)) {
- if (&Apache::lonnet::allowed($1,$prt)) {
- $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
+ my $priv = $1;
+ if ($priv =~ /^mdc(Course|Community)/) {
+ if ($crstype eq $1) {
+ $priv = 'mdc';
+ } else {
+ next;
+ }
+ }
+ if (&Apache::lonnet::allowed($priv,$prt)) {
+ $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
+ }
+ } elsif ($pro eq 'course') {
+ if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
+ $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
+ }
+ } elsif ($pro eq 'community') {
+ if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
+ $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
}
- } elsif ($pro eq 'course') {
- if ($ENV{'request.course.fn'}) {
- $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
- }
} elsif ($pro =~ /^courseenv_(.*)$/) {
my $key = $1;
- if ($ENV{'course.'.$ENV{'request.course.id'}.'.'.$key}) {
- $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
+ if ($crstype ne 'Community') {
+ my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
+ if ($key eq 'canuse_pdfforms') {
+ if ($env{'request.course.id'} && $coursepref eq '') {
+ my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
+ $coursepref = $domdefs{'canuse_pdfforms'};
+ }
+ }
+ if ($coursepref) {
+ $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
+ }
+ }
+ } elsif ($pro =~ /^communityenv_(.*)$/) {
+ my $key = $1;
+ if ($crstype eq 'Community') {
+ my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
+ if ($key eq 'canuse_pdfforms') {
+ if ($env{'request.course.id'} && $coursepref eq '') {
+ my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
+ $coursepref = $domdefs{'canuse_pdfforms'};
+ }
+ }
+ if ($coursepref) {
+ $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
+ }
}
} elsif ($pro =~ /^course_(.*)$/) {
# Check for permissions inside of a course
- if (($ENV{'request.course.id'}) &&
- (&Apache::lonnet::allowed($1,$ENV{'request.course.id'}.
- ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))
+ if (($env{'request.course.id'}) && ($crstype ne 'Community') &&
+ (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
+ ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
)) {
- $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
- }
+ $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
+ }
+ } elsif ($pro =~ /^community_(.*)$/) {
+ # Check for permissions inside of a community
+ if (($env{'request.course.id'}) && ($crstype eq 'Community') &&
+ (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
+ ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
+ )) {
+ $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
+ }
} elsif ($pro eq 'author') {
if ($author) {
- if ((($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) ||
- (($prt eq 'rau') && ($ENV{'request.role'}=~/^au/))) {
+ if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
+ (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) ||
+ (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
# Check that we are on the correct machine
my $cadom=$requested_domain;
- my $caname=$ENV{'user.name'};
- if ($prt eq 'rca') {
+ my $caname=$env{'user.name'};
+ if (($prt eq 'rca') || ($prt eq 'raa')) {
($cadom,$caname)=
- ($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
+ ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
}
$act =~ s/\$caname/$caname/g;
my $home = &Apache::lonnet::homeserver($caname,$cadom);
@@ -908,15 +1379,41 @@ sub rawconfig {
my @ids=&Apache::lonnet::current_machine_ids();
foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
if ($allowed) {
- $output.=switch($caname,$cadom,
- $row,$col,$img,$top,$bot,$act,$desc);
+ $output.=&switch($caname,$cadom,
+ $row,$col,$img,$top,$bot,$act,$desc,$cat);
}
}
}
+ } 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') ||
- ($ENV{'environment.remote'} eq 'off')) {
+ unless (($env{'browser.interface'} eq 'textual') ||
+ ($env{'environment.remote'} eq 'off')) {
$output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
if (&Apache::lonmsg::newmail()) {
$output.='swmenu.setstatus("you have","messages");';
@@ -926,14 +1423,37 @@ 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 {
- if (($ENV{'browser.interface'} eq 'textual') ||
- ($ENV{'environment.remote'} eq 'off')) { return ''; }
- my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
+ if (($env{'browser.interface'} eq 'textual') ||
+ ($env{'environment.remote'} eq 'off')) { return ''; }
+ my $menuname = &get_menu_name();
return(<
+//
ENDCLOSE
}
@@ -954,7 +1475,7 @@ sub footer {
}
sub nav_control_js {
- my $nav=($ENV{'environment.remotenavmap'} eq 'on');
+ my $nav=($env{'environment.remotenavmap'} eq 'on');
return (< 1,
+ 'js_ready' => 1,
+ 'bgcolor' => '#BBBBBB',
+ 'add_entries' => {
+ 'onload' => 'javascript:document.goannotate.submit();'}});
+
+ my $end_page_annotate =
+ &Apache::loncommon::end_page({'js_ready' => 1});
+
+ my $start_page_bookmark =
+ &Apache::loncommon::start_page('Bookmarks',undef,
+ {'only_body' => 1,
+ 'js_ready' => 1,
+ 'bgcolor' => '#BBBBBB',});
+
+ my $end_page_bookmark =
+ &Apache::loncommon::end_page({'js_ready' => 1});
+
+ my $confirm_switch = &mt("Editing requires switching to the reource's home server.").'\n'.
+ &mt('Switch server?');
+
return (<"
+ +" "
+ +"<\\/form>"
+ +'$end_page_annotate');
+ annotator.document.close();
+}
+
+function set_bookmark() {
+ go('');
+ clienttitle=document.title;
+ clienthref=location.pathname;
+ w_bmquery_flag=1;
+ bmquery=window.open('','bmquery','width=365,height=165,scrollbars=0');
+ bmquery.document.write(
+ '$start_page_bookmark'
+ +' '
+ +'$end_page_bookmark' );
+ bmquery.document.close();
+}
+
ENDUTILITY
}
sub serverform {
return(<
@@ -1103,7 +1716,7 @@ ENDCONSTSPACEFORM
sub get_nav_status {
my $navstatus="swmenu.w_loncapanav_flag=";
- if ($ENV{'environment.remotenavmap'} eq 'on') {
+ if ($env{'environment.remotenavmap'} eq 'on') {
$navstatus.="1";
} else {
$navstatus.="-1";
@@ -1111,82 +1724,298 @@ sub get_nav_status {
return $navstatus;
}
-# ================================================ Handler when called directly
+sub hidden_button_check {
+ my $hidden;
+ if ($env{'request.course.id'} eq '') {
+ return;
+ }
+ if ($env{'request.role.adv'}) {
+ return;
+ }
+ my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
+ return $buttonshide;
+}
+
+sub roles_selector {
+ my ($cdom,$cnum) = @_;
+ my $crstype = &Apache::loncommon::course_type();
+ my $now = time;
+ my (%courseroles,%seccount);
+ my $is_cc;
+ my $role_selector;
+ my $ccrole;
+ 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))) {
+ $is_cc = 0;
+ } else {
+ $is_cc = 1;
+ }
+ }
+ if ($is_cc) {
+ &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;
+ my $sec = $2;
+ next if ($role eq 'gr');
+ my ($start,$end) = split(/\./,$env{$item});
+ next if (($start && $start > $now) || ($end && $end < $now));
+ if ($sec eq '') {
+ if (!$gotnosection{$role}) {
+ $seccount{$role} ++;
+ $gotnosection{$role} = 1;
+ }
+ }
+ if (ref($courseroles{$role}) eq 'ARRAY') {
+ if ($sec ne '') {
+ if (!grep(/^Q$sec\E$/,@{$courseroles{$role}})) {
+ push(@{$courseroles{$role}},$sec);
+ $seccount{$role} ++;
+ }
+ }
+ } else {
+ @{$courseroles{$role}} = ();
+ if ($sec ne '') {
+ $seccount{$role} ++;
+ push(@{$courseroles{$role}},$sec);
+ }
+ }
+ }
+ }
+ }
+ 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 .= '';
+ }
+ return $role_selector;
+}
-sub handler {
- my $r = shift;
- &Apache::loncommon::content_type($r,'text/html');
- $r->send_http_header;
- return OK if $r->header_only;
-
- my $form;
- if ($ENV{'environment.remote'} ne 'off' &&
- $ENV{'browser.interface'} ne 'textual') {
- $form=&serverform();
- }
- my $bodytag=&Apache::loncommon::bodytag('Main Menu');
- my $function='student';
- if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
- $function='coordinator';
- }
- if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
- $function='admin';
- }
- if (($ENV{'request.role'}=~/^(au|ca)/) ||
- ($ENV{'request.noversionuri'}=~/^(\/priv|\~)/)) {
- $function='author';
- }
- my $domain=&Apache::loncommon::determinedomain();
- $pgbg=&Apache::loncommon::designparm($function.'.pgbg',$domain);
- $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain);
- $font=&Apache::loncommon::designparm($function.'.font',$domain);
- my $script_tag;
- if ($ENV{'environment.remote'} eq 'on') {
- my $utility=&utilityfunctions('/adm/menu');
- $script_tag=(<{'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(
+ this => 'This role has section(s) associated with it.',
+ ente => 'Enter a specific section.',
+ orlb => 'Enter a specific section, or leave blank for no section.',
+ avai => 'Available sections are:',
+ youe => 'You entered an invalid section choice:',
+ plst => 'Please try again',
+ );
+ my $js;
+ if (ref($courseroles) eq 'HASH') {
+ $js = ' var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n".
+ ' var numsec = new Array();'."\n".
+ ' var rolesections = new Array();'."\n".
+ ' var rolenames = new Array();'."\n".
+ ' var roleseclist = new Array();'."\n";
+ my @items = keys(%{$courseroles});
+ for (my $i=0; $i<@items; $i++) {
+ $js .= ' rolenames['.$i.'] = "'.$items[$i].'";'."\n";
+ my ($secs,$secstr);
+ if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
+ my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
+ $secs = join('","',@sections);
+ $secstr = join(', ',@sections);
+ }
+ $js .= ' rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
+ ' roleseclist['.$i.'] = "'.$secstr.'";'."\n".
+ ' numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
+ }
+ }
+ return <<"END";
-ENDSCRIPT
+//= 0) {
+ if (numsec[selidx] > 1) {
+ secok = 0;
+ var numrolesec = rolesections[selidx].length;
+ var msgidx = numsec[selidx] - numrolesec;
+ secchoice = prompt("$lt{'this'}\\n"+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
+ if (secchoice == '') {
+ if (msgidx > 0) {
+ secok = 1;
+ }
+ } else {
+ for (var j=0; jprint(<
-LON-CAPA Main Menu
-$script_tag
-
-$bodytag
-ENDHEADER
- $r->print(''.$form);
- $r->print('