--- loncom/auth/lonroles.pm 2006/06/02 13:58:37 1.153
+++ loncom/auth/lonroles.pm 2014/05/05 11:44:18 1.269.2.19
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.153 2006/06/02 13:58:37 raeburn Exp $
+# $Id: lonroles.pm,v 1.269.2.19 2014/05/05 11:44:18 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -27,6 +27,102 @@
#
###
+=pod
+
+=head1 NAME
+
+Apache::lonroles - User Roles Screen
+
+=head1 SYNOPSIS
+
+Invoked by /etc/httpd/conf/srm.conf:
+
+ $msg '.&mt('The following problems occurred:').
+ # Breadcrumbs
+ my $brcrum = [{'href' => $dest,
+ 'text' => 'Problems during Course Initialization'},];
+ $r->print(&Apache::loncommon::start_page('Problems during Course Initialization',
+ undef,
+ {'bread_crumbs' => $brcrum,})
+ );
+ $r->print(
+ ''.
+ ' '.&mt('The following problems occurred:').
+ ' ');
+ if ($switchwarning) {
+ $r->print($switchwarning.' '
+ .&mt('This LON-CAPA server is version [_1]',$r->dir_config('lonVersion'))
+ .' '.&mt('The [_1]Course/Community Catalog[_2] provides information about all [_3] classes for which LON-CAPA courses have been created, as well as any communities in the domain.','','',$domdesc).' '.&mt('You have rights to request the creation of courses and/or communities in the following domain(s):').'$msg
+
'.
$error.
- '
'.&mt('Continue').''
+ );
+ $r->print(&Apache::loncommon::end_page());
}
sub handler {
@@ -98,50 +210,205 @@ sub handler {
my $now=time;
my $then=$env{'user.login.time'};
+ my $refresh=$env{'user.refresh.time'};
+ my $update=$env{'user.update.time'};
+ if (!$refresh) {
+ $refresh = $then;
+ }
+ if (!$update) {
+ $update = $then;
+ }
+
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
+
+# -------------------------------------------------- Check if setting hot list
+ my $hotlist;
+ if ($env{'form.action'} eq 'verify_and_change_rolespref') {
+ $hotlist = &Apache::lonpreferences::verify_and_change_rolespref($r);
+ }
+
+# -------------------------------------------------------- Check for new roles
+ my $updateresult;
+ if ($env{'form.state'} eq 'doupdate') {
+ my $show_course=&Apache::loncommon::show_course();
+ my $checkingtxt;
+ if ($show_course) {
+ $checkingtxt = &mt('Checking for new courses ...');
+ } else {
+ $checkingtxt = &mt('Checking for new roles ...');
+ }
+ $updateresult = $checkingtxt;
+ $updateresult .= &update_session_roles();
+ &Apache::lonnet::appenv({'user.update.time' => $now});
+ $update = $now;
+ &Apache::loncoursequeueadmin::reqauthor_check();
+ }
+
+# -------------------------------------------------- Check for author requests
+ my $reqauthor;
+ if ($env{'form.state'} eq 'requestauthor') {
+ $reqauthor = &Apache::loncoursequeueadmin::process_reqauthor(\$update);
+ }
+
my $envkey;
my %dcroles = ();
- my $numdc = &check_fordc(\%dcroles,$then);
- &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
+ my $numdc = &check_fordc(\%dcroles,$update,$then);
+ my $loncaparev = $Apache::lonnet::perlvar{'lonVersion'};
# ================================================================== Roles Init
if ($env{'form.selectrole'}) {
+
+ my $locknum=&Apache::lonnet::get_locks();
+ if ($locknum) { return 409; }
+
if ($env{'form.newrole'}) {
$env{'form.'.$env{'form.newrole'}}=1;
}
if ($env{'request.course.id'}) {
+ # Check if user is CC trying to select a course role
+ if ($env{'form.switchrole'}) {
+ my $switch_is_active;
+ if (defined($env{'user.role.'.$env{'form.switchrole'}})) {
+ my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
+ if (!$end || $end > $now) {
+ if (!$start || $start < $update) {
+ $switch_is_active = 1;
+ }
+ }
+ }
+ unless ($switch_is_active) {
+ &adhoc_course_role($refresh,$update,$then);
+ }
+ }
my %temp=('logout_'.$env{'request.course.id'} => time);
&Apache::lonnet::put('email_status',\%temp);
&Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
}
- &Apache::lonnet::appenv("request.course.id" => '',
- "request.course.fn" => '',
- "request.course.uri" => '',
- "request.course.sec" => '',
- "request.role" => 'cm',
- "request.role.adv" => $env{'user.adv'},
- "request.role.domain" => $env{'user.domain'});
-
-# Check if user is a DC trying to enter a course and needs privs to be created
+ &Apache::lonnet::appenv({"request.course.id" => '',
+ "request.course.fn" => '',
+ "request.course.uri" => '',
+ "request.course.sec" => '',
+ "request.course.tied" => '',
+ "request.role" => 'cm',
+ "request.role.adv" => $env{'user.adv'},
+ "request.role.domain" => $env{'user.domain'}});
+# Check if user is a DC trying to enter a course or author space and needs privs to be created
if ($numdc > 0) {
- foreach my $envkey (keys %env) {
- if (my ($domain,$coursenum) =
- ($envkey =~ m-^form\.cc\./(\w+)/(\w+)$-)) {
+ foreach my $envkey (keys(%env)) {
+# Is this an ad-hoc Coordinator role?
+ if (my ($ccrole,$domain,$coursenum) =
+ ($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) {
if ($dcroles{$domain}) {
- &check_privs($domain,$coursenum,$then,$now);
+ if (&Apache::lonnet::check_adhoc_privs($domain,$coursenum,
+ $update,$refresh,$now,$ccrole)) {
+ &Apache::lonnet::appenv({"environment.internal.$domain.$coursenum.$ccrole.adhoc" => time});
+ }
+ }
+ last;
+ }
+# Is this an ad-hoc CA-role?
+ if (my ($domain,$user) =
+ ($envkey =~ m-^form\.ca\./($match_domain)/($match_username)$-)) {
+ if (($domain eq $env{'user.domain'}) && ($user eq $env{'user.name'})) {
+ delete($env{$envkey});
+ $env{'form.au./'.$domain.'/'} = 1;
+ my ($server_status,$home) = &check_author_homeserver($user,$domain);
+ if ($server_status eq 'switchserver') {
+ my $trolecode = 'au./'.$domain.'/';
+ my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
+ $r->internal_redirect($switchserver);
+ return OK;
+ }
+ last;
+ }
+ if (my ($castart,$caend) = ($env{'user.role.ca./'.$domain.'/'.$user} =~ /^(\d*)\.(\d*)$/)) {
+ if (((($castart) && ($castart < $now)) || !$castart) &&
+ ((!$caend) || (($caend) && ($caend > $now)))) {
+ my ($server_status,$home) = &check_author_homeserver($user,$domain);
+ if ($server_status eq 'switchserver') {
+ my $trolecode = 'ca./'.$domain.'/'.$user;
+ my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
+ $r->internal_redirect($switchserver);
+ return OK;
+ }
+ last;
+ }
+ }
+ # Check if author blocked ca-access
+ my %blocked=&Apache::lonnet::get('environment',['domcoord.author'],$domain,$user);
+ if ($blocked{'domcoord.author'} eq 'blocked') {
+ delete($env{$envkey});
+ $env{'user.error.msg'}=':::1:User '.$user.' in domain '.$domain.' blocked domain coordinator access';
+ last;
+ }
+ if ($dcroles{$domain}) {
+ my ($server_status,$home) = &check_author_homeserver($user,$domain);
+ if (($server_status eq 'ok') || ($server_status eq 'switchserver')) {
+ &Apache::lonnet::check_adhoc_privs($domain,$user,$update,
+ $refresh,$now,'ca');
+ if ($server_status eq 'switchserver') {
+ my $trolecode = 'ca./'.$domain.'/'.$user;
+ my $switchserver = '/adm/switchserver?'
+ .'otherserver='.$home.'&role='.$trolecode;
+ $r->internal_redirect($switchserver);
+ return OK;
+ }
+ } else {
+ delete($env{$envkey});
+ }
+ } else {
+ delete($env{$envkey});
}
last;
}
}
}
- foreach $envkey (keys %env) {
+ foreach $envkey (keys(%env)) {
next if ($envkey!~/^user\.role\./);
my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
- &role_status($envkey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
+ &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
+ \$trolecode,\$tstatus,\$tstart,\$tend);
if ($env{'form.'.$trolecode}) {
if ($tstatus eq 'is') {
$where=~s/^\///;
my ($cdom,$cnum,$csec)=split(/\//,$where);
+ if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
+ my $home = $env{'course.'.$cdom.'_'.$cnum.'.home'};
+ my @ids = &Apache::lonnet::current_machine_ids();
+ unless ($loncaparev eq '' && $home && grep(/^\Q$home\E$/,@ids)) {
+ my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
+ if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
+ my ($switchserver,$switchwarning) =
+ &check_release_required($loncaparev,$cdom.'_'.$cnum,$trolecode,$curr_reqd_hash{'internal.releaserequired'});
+ if ($switchwarning ne '' || $switchserver ne '') {
+ &Apache::loncommon::content_type($r,'text/html');
+ &Apache::loncommon::no_cache($r);
+ $r->send_http_header;
+ my $end_page=&Apache::loncommon::end_page();
+ $r->print(&Apache::loncommon::start_page('Selected course unavailable on this server').
+ '
');
+ if (&Apache::loncommon::show_course()) {
+ $r->print(&mt('Display courses'));
+ } else {
+ $r->print(&mt('Display roles'));
+ }
+ $r->print('');
+ } elsif ($switchserver) {
+ $r->print(&mt('This course requires a newer version of LON-CAPA than is installed on this server.').
+ '
'.
+ ''.
+ &mt('Switch Server').
+ '');
+ }
+ $r->print(' '
+ .''
+ .&mt('No role specified')
+ .' '
+ .''.$tremark.' '
+ .&Apache::loncommon::end_data_table_row()
+ );
+
+ $r->print(&Apache::loncommon::end_data_table());
+ }
+ $r->print(&Apache::loncommon::end_page());
+ return OK;
+ }
+# ----------------------------------------------------------------------- Table
+
+ if ($numdc > 0) {
+ $r->print(&coursepick_jscript());
+ $r->print(&Apache::loncommon::coursebrowser_javascript().
+ &Apache::loncommon::authorbrowser_javascript());
+ }
+
+ unless ((!&Apache::loncommon::show_course()) || ($nochoose) || ($countactive==1)) {
+ $r->print("".&mt('Select a Course to Enter')."
\n");
+ }
+ if ($env{'form.destinationurl'}) {
+ $r->print('');
+ if ($env{'form.destsymb'} ne '') {
+ $r->print('');
+ }
+ }
+
+ my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose);
+ if ($env{'environment.recentroles'}) {
+ my %recent_roles =
+ &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
+ my $output='';
+ foreach my $role (sort(keys(%recent_roles))) {
+ if (ref($roletext{'user.role.'.$role}) eq 'ARRAY') {
+ $output.= &Apache::loncommon::start_data_table_row().
+ $roletext{'user.role.'.$role}->[0].
+ &Apache::loncommon::end_data_table_row();
+ if ($roletext{'user.role.'.$role}->[1] ne '') {
+ $output .= &Apache::loncommon::continue_data_table_row().
+ $roletext{'user.role.'.$role}->[1].
+ &Apache::loncommon::end_data_table_row();
+ }
+ if ($role =~ m{dc\./($match_domain)/}
+ && $dcroles{$1}) {
+ $output .= &adhoc_roles_row($1,'recent');
+ }
+ } elsif ($numdc > 0) {
+ unless ($role =~/^error\:/) {
+ my ($roletext,$role_text_end) = &display_cc_role('user.role.'.$role);
+ if ($roletext) {
+ $output.= &Apache::loncommon::start_data_table_row().
+ $roletext.
+ &Apache::loncommon::end_data_table_row();
+ if ($role_text_end) {
+ $output .= &Apache::loncommon::continue_data_table_row().
+ $role_text_end.
+ &Apache::loncommon::end_data_table_row();
+ }
+ }
+ }
+ }
+ }
+ if ($output) {
+ $r->print(&Apache::loncommon::start_data_table_empty_row()
+ .''
+ .$recent
+ .' '
+ .&Apache::loncommon::end_data_table_empty_row()
+ );
+ $r->print($output);
+ $doheaders ++;
+ }
+ }
+ &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext);
+ if ($countactive > 1) {
+ my $tremark='';
+ my $tbg;
+ if ($env{'request.role'} eq 'cm') {
+ $tbg="LC_roles_selected";
+ $tremark=&mt('Currently selected.').' ';
+ } else {
+ $tbg="LC_roles_is";
+ }
+ $r->print(&Apache::loncommon::start_data_table_row());
+ unless ($nochoose) {
+ if ($env{'request.role'} ne 'cm') {
+ $r->print('');
+ } else {
+ $r->print(' ');
+ }
+ }
+ $r->print(''
+ .&mt('No role specified')
+ .' '
+ .''.$tremark.' '
+ .&Apache::loncommon::end_data_table_row()
+ );
+ }
+ $r->print(&Apache::loncommon::end_data_table());
+ unless ($nochoose) {
+ $r->print("\n");
+ }
+# ------------------------------------------------------------ Privileges Info
+ if (($advanced) && (($env{'user.error.msg'}) || ($error))) {
+ $r->print(''.&mt('Current Privileges').'
');
+ $r->print(&privileges_info());
+ }
+ my $announcements = &Apache::lonnet::getannounce();
+ $r->print(
+ '
'.
+ ''.&mt('Announcements').'
'.
+ $announcements
+ ) unless (!$announcements);
+ if ($advanced) {
+ my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
+ $r->print('
'
+ .''.&mt('Logout').' '
+ .''
+ .&mt('Course/Community Catalog')
+ .'
'; }
- $tremark.=&mt('Defined by ').$rauthor.
- &mt(' at ').$rdomain.'.';
- $trole=$rrole;
- } else {
- $trole=Apache::lonnet::plaintext($role);
+ if ($tremark) { $tremark.='
'; }
+ $tremark.=&mt('Custom role defined by [_1].',$rauthor.':'.$rdomain);
}
+ $trole=Apache::lonnet::plaintext($role);
my $ttype;
my $twhere;
my ($tdom,$trest,$tsection)=
@@ -529,300 +1168,392 @@ ENDHEADER
# First, Co-Authorship roles
if (($role eq 'ca') || ($role eq 'aa')) {
my $home = &Apache::lonnet::homeserver($trest,$tdom);
- my $allowed=0;
- my @ids=&Apache::lonnet::current_machine_ids();
- foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
+ my $allowed=0;
+ foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
if (!$allowed) {
- $button=0;
- $switchserver='otherserver='.$home.'&role='.$trolecode;
+ $button=0;
+ $switchserver='otherserver='.$home.'&role='.$trolecode;
}
#next if ($home eq 'no_host');
- $home = $Apache::lonnet::hostname{$home};
- $ttype='Construction Space';
+ $home = &Apache::lonnet::hostname($home);
+ $ttype='Authoring Space';
$twhere=&mt('User').': '.$trest.'
'.&mt('Domain').
- ': '.$tdom.'
'.
+ ': '.$tdom.'
'.
' '.&mt('Server').': '.$home;
$env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
- $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
- $sortkey=$role."$trest:$tdom";
+ $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/');
+ $sortkey=$role."$trest:$tdom";
} elsif ($role eq 'au') {
# Authors
my $home = &Apache::lonnet::homeserver
($env{'user.name'},$env{'user.domain'});
- my $allowed=0;
- my @ids=&Apache::lonnet::current_machine_ids();
- foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
+ my $allowed=0;
+ foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
if (!$allowed) {
- $button=0;
- $switchserver='otherserver='.$home.'&role='.$trolecode;
+ $button=0;
+ $switchserver='otherserver='.$home.'&role='.$trolecode;
}
#next if ($home eq 'no_host');
- $home = $Apache::lonnet::hostname{$home};
- $ttype='Construction Space';
+ $home = &Apache::lonnet::hostname($home);
+ $ttype='Authoring Space';
$twhere=&mt('Domain').': '.$tdom.'
'.&mt('Server').
- ': '.$home;
+ ': '.$home;
$env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
- $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
- $sortkey=$role;
+ $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
+ $sortkey=$role;
} elsif ($trest) {
my $tcourseid=$tdom.'_'.$trest;
$ttype = &Apache::loncommon::course_type($tcourseid);
- $trole = &Apache::lonnet::plaintext($role,$ttype);
+ $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
if ($env{'course.'.$tcourseid.'.description'}) {
+ my $home=$env{'course.'.$tcourseid.'.home'};
$twhere=$env{'course.'.$tcourseid.'.description'};
- $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
+ $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
+ $twhere = &HTML::Entities::encode($twhere,'"<>&');
unless ($twhere eq &mt('Currently not available')) {
- $twhere.=' '.
- &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
- '';
- }
+ $twhere.=' '.
+ &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
+ '';
+ unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
+ my $required = $env{'course.'.$tcourseid.'.internal.releaserequired'};
+ if ($required ne '') {
+ ($switchserver,$switchwarning) =
+ &check_release_required($loncaparev,$tcourseid,$trolecode,$required);
+ if ($switchserver || $switchwarning) {
+ $button = 0;
+ }
+ }
+ }
+ }
} else {
my %newhash=&Apache::lonnet::coursedescription($tcourseid);
if (%newhash) {
- $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
- "\0".$envkey;
- $twhere=$newhash{'description'}.
- ' '.
- &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
- '';
+ $sortkey=$role."\0".$tdom."\0".$newhash{'description'}.
+ "\0".$envkey;
+ $twhere=&HTML::Entities::encode($newhash{'description'},'"<>&').
+ ' '.
+ &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
+ '';
$ttype = $newhash{'type'};
- $trole = &Apache::lonnet::plaintext($role,$ttype);
+ $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
+ my $home = $newhash{'home'};
+ unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
+ my $required = $newhash{'internal.releaserequired'};
+ if ($required ne '') {
+ ($switchserver,$switchwarning) =
+ &check_release_required($loncaparev,$tcourseid,$trolecode,$required);
+ if ($switchserver || $switchwarning) {
+ $button = 0;
+ }
+ }
+ }
} else {
$twhere=&mt('Currently not available');
$env{'course.'.$tcourseid.'.description'}=$twhere;
- $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
+ $sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
$ttype = 'Unavailable';
}
}
if ($tsection) {
- $twhere.='
'.&mt('Section/Group').': '.$tsection;
- }
- if ($role ne 'st') { $twhere.="
".&mt('Domain').":".$tdom; }
+ $twhere.='
'.&mt('Section').': '.$tsection;
+ }
+ if ($role ne 'st') { $twhere.="
".&mt('Domain').":".$tdom; }
} elsif ($tdom) {
$ttype='Domain';
$twhere=$tdom;
- $sortkey=$role.$twhere;
+ $sortkey=$role.$twhere;
} else {
$ttype='System';
$twhere=&mt('system wide');
- $sortkey=$role.$twhere;
+ $sortkey=$role.$twhere;
}
- $roletext.=&build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$tfont,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver);
- $roletext{$envkey}=$roletext;
- if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
- $sortrole{$sortkey}=$envkey;
- $roleclass{$envkey}=$ttype;
- }
+ ($role_text,$role_text_end) =
+ &build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,
+ $advanced,$tremark,$tbg,$trole,$twhere,$tpstart,
+ $tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning);
+ $roletext->{$envkey}=[$role_text,$role_text_end];
+ if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
+ $sortrole->{$sortkey}=$envkey;
+ $roleclass->{$envkey}=$ttype;
+ }
}
}
-# No active roles
- if ($countactive==0) {
- if ($inrole) {
- $r->print(''.&mt('Currently no additional roles or courses').'
');
- } else {
- $r->print(''.&mt('Currently no active roles or courses').'
');
- }
- $r->print(''.&Apache::loncommon::end_page());
- return OK;
-# Is there only one choice?
- } elsif (($countactive==1) && ($env{'request.role'} eq 'cm')) {
- $r->print(''.&mt('Please stand by.').'
'.
- '');
- $r->print("\n");
- $r->rflush();
- $r->print('');
- $r->print(&Apache::loncommon::end_page());
- return OK;
- }
-# More than one possible role
-# ----------------------------------------------------------------------- Table
- unless (($advanced) || ($nochoose)) {
- $r->print("".&mt('Select a Course/Group to Enter')."
\n");
- }
- $r->print('
');
- unless ($nochoose) {
- $r->print("\n");
+sub requestcourse_advice {
+ my ($r,$cattype) = @_;
+ my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
+ my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
+ my (%can_request,%request_doms);
+ &Apache::lonnet::check_can_request($env{'user.domain'},\%can_request,\%request_doms);
+ if (keys(%request_doms) > 0) {
+ my ($types,$typename) = &Apache::loncommon::course_types();
+ if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
+ $r->print('');
- unless ($nochoose) { $r->print(' '."\n");
- my $doheaders=-1;
- foreach my $type ('Domain','Construction Space','Course','Group','Unavailable','System') {
- my $haverole=0;
- foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
- if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) {
- $haverole=1;
- }
- }
- if ($haverole) { $doheaders++; }
- }
+ return ($countactive,$countfuture,$inrole,$possiblerole);
+}
- if ($env{'environment.recentroles'}) {
- my %recent_roles =
- &Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
- my $output='';
- foreach (sort(keys(%recent_roles))) {
- if (defined($roletext{'user.role.'.$_})) {
- $output.=$roletext{'user.role.'.$_};
- if ($_ =~ m-dc\./(\w+)/- && $dcroles{$1}) {
- $output .= &allcourses_row($1,'recent');
+sub role_timezone {
+ my ($where,$timezones) = @_;
+ my $timezone;
+ if (ref($timezones) eq 'HASH') {
+ if ($where =~ m{^/($match_domain)/($match_courseid)}) {
+ my $cdom = $1;
+ my $cnum = $2;
+ if ($cdom && $cnum) {
+ if (!exists($timezones->{$cdom.'_'.$cnum})) {
+ my $tz;
+ if ($env{'course.'.$cdom.'_'.$cnum.'.description'}) {
+ $tz = $env{'course.'.$cdom.'_'.$cnum.'.timezone'};
+ } else {
+ my %timehash =
+ &Apache::lonnet::get('environment',['timezone'],$cdom,$cnum);
+ $tz = $timehash{'timezone'};
+ }
+ if ($tz eq '') {
+ if (!exists($timezones->{$cdom})) {
+ my %domdefaults =
+ &Apache::lonnet::get_domain_defaults($cdom);
+ if ($domdefaults{'timezone_def'} eq '') {
+ $timezones->{$cdom} = 'local';
+ } else {
+ $timezones->{$cdom} = $domdefaults{'timezone_def'};
+ }
+ }
+ $timezones->{$cdom.'_'.$cnum} = $timezones->{$cdom};
+ } else {
+ $timezones->{$cdom.'_'.$cnum} =
+ &Apache::lonlocal::gettimezone($tz);
+ }
}
- } elsif ($numdc > 0) {
- unless ($_ =~/^error\:/) {
- $output.=&display_cc_role('user.role.'.$_);
+ $timezone = $timezones->{$cdom.'_'.$cnum};
+ }
+ } else {
+ my ($tdom) = ($where =~ m{^/($match_domain)});
+ if ($tdom) {
+ if (!exists($timezones->{$tdom})) {
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($tdom);
+ if ($domdefaults{'timezone_def'} eq '') {
+ $timezones->{$tdom} = 'local';
+ } else {
+ $timezones->{$tdom} = $domdefaults{'timezone_def'};
+ }
}
- }
- }
- if ($output) {
- $r->print(" '); }
- $r->print(''.&mt('User Role').' '.&mt('Extent').
- ' '.&mt('Start').' '.&mt('End').' ");
- $doheaders ++;
- }
+ $timezone = $timezones->{$tdom};
+ }
+ }
+ if ($timezone eq 'local') {
+ $timezone = undef;
+ }
}
+ return $timezone;
+}
- if ($numdc > 0) {
- $r->print(&coursepick_jscript());
- $r->print(&Apache::loncommon::coursebrowser_javascript());
+sub roletable_headers {
+ my ($r,$roleclass,$sortrole,$nochoose) = @_;
+ my $doheaders;
+ if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
+ $r->print('".
- &mt('Recent Roles')." ");
- $r->print($output);
- $r->print("
'
+ .&Apache::loncommon::start_data_table()
+ .&Apache::loncommon::start_data_table_header_row()
+ );
+ if (!$nochoose) { $r->print(' '); }
+ $r->print(''.&mt('User Role').' '
+ .''.&mt('Extent').' '
+ .''.&mt('Start').' '
+ .''.&mt('End').' '
+ .&Apache::loncommon::end_data_table_header_row()
+ );
+ $doheaders=-1;
+ my @roletypes = &roletypes();
+ foreach my $type (@roletypes) {
+ my $haverole=0;
+ foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
+ if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
+ $haverole=1;
+ }
+ }
+ if ($haverole) { $doheaders++; }
+ }
}
- foreach my $type ('Construction Space','Domain','Course','Group','Unavailable','System') {
- my $output;
- foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
- if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) {
- $output.=$roletext{$sortrole{$which}};
- if ($sortrole{$which} =~ m-dc\./(\w+)/-) {
- if ($dcroles{$1}) {
- $output .= &allcourses_row($1,'');
+ return $doheaders;
+}
+
+sub roletypes {
+ my @types = ('Domain','Authoring Space','Course','Community','Unavailable','System');
+ return @types;
+}
+
+sub print_rolerows {
+ my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext) = @_;
+ if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) {
+ my @types = &roletypes();
+ foreach my $type (@types) {
+ my $output;
+ foreach my $which (sort {uc($a) cmp uc($b)} (keys(%{$sortrole}))) {
+ if ($roleclass->{$sortrole->{$which}} =~ /^\Q$type\E/) {
+ if (ref($roletext) eq 'HASH') {
+ if (ref($roletext->{$sortrole->{$which}}) eq 'ARRAY') {
+ $output.= &Apache::loncommon::start_data_table_row().
+ $roletext->{$sortrole->{$which}}->[0].
+ &Apache::loncommon::end_data_table_row();
+ if ($roletext->{$sortrole->{$which}}->[1] ne '') {
+ $output .= &Apache::loncommon::continue_data_table_row().
+ $roletext->{$sortrole->{$which}}->[1].
+ &Apache::loncommon::end_data_table_row();
+ }
+ }
+ if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) {
+ if (ref($dcroles) eq 'HASH') {
+ if ($dcroles->{$1}) {
+ $output .= &adhoc_roles_row($1,'');
+ }
+ }
+ }
}
}
- }
- }
- if ($output) {
- if ($doheaders > 0) {
- $r->print("".
- " ");
- }
- $r->print($output);
- }
+ }
+ if ($output) {
+ if ($doheaders > 0) {
+ $r->print(&Apache::loncommon::start_data_table_empty_row()
+ .'".&mt($type)." '
+ .&mt($type)
+ .' '
+ .&Apache::loncommon::end_data_table_empty_row()
+ );
+ }
+ $r->print($output);
+ }
+ }
}
- my $tremark='';
- my $tfont='#003300';
- if ($env{'request.role'} eq 'cm') {
- $r->print('');
- $tremark=&mt('Currently selected. ');
- $tfont='#002200';
+}
+
+sub findcourse_advice {
+ my ($r,$cattype) = @_;
+ my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
+ my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
+ if (&Apache::lonnet::auto_run(undef,$env{'user.domain'})) {
+ $r->print(&mt('If you were expecting to see an active role listed for a particular course in the [_1] domain, it may be missing for one of the following reasons:',$domdesc).'
+
+
');
} else {
- $r->print('');
+ $r->print(&mt('If you were expecting to see an active role listed for a particular course, that course may not have been created yet.').' '."\n");
+ return;
+}
- $r->print('
');
}
- unless ($nochoose) {
- if ($env{'request.role'} ne 'cm') {
- $r->print('');
- } else {
- $r->print(' ');
- }
+ if (($cattype eq 'std') || ($cattype eq 'domonly')) {
+ $r->print(''.&mt('Self-Enrollment').'
'.
+ '
');
+ $r->print(&mt('You can search for courses and communities which permit self-enrollment, if you would like to enroll in one.').''.&mt('No role specified').
- ' '.$tremark.
- ' '.&mt('Request creation of a course or community').'
'.
+ '');
+ my (@reqdoms,@reqtypes);
+ foreach my $type (sort(keys(%request_doms))) {
+ push(@reqtypes,$type);
+ if (ref($request_doms{$type}) eq 'ARRAY') {
+ my $domstr = join(', ',map { &Apache::lonnet::domain($_) } sort(@{$request_doms{$type}}));
+ $r->print(
+ '
'.&mt('Use the [_1]request form[_2] to submit a request for creation of a new course or community.','','').'
This is LON-CAPA '.
- $r->dir_config('lonVersion').'
'.
- ''.&mt('Logout').'
'.&mt('The section has changed for your current role. Log-out and log-in again to select a role for the new section.').'
'; + } else { + my $newrole = $env{'request.role'}; + if ($newsec[0] eq 'none') { + $newrole =~ s{(/[^/])$}{}; + } elsif ($oldsec eq 'none') { + $newrole .= '/'.$newsec[0]; + } else { + $newrole =~ s{([^/]+)$}{$newsec[0]}; + } + my $coursedesc = $env{'course.'.$env{'request.course.id'}.'.description'}; + my ($curr_role) = ($env{'request.role'} =~ m{^(\w+)\./$match_domain/$match_courseid}); + my %temp=('logout_'.$env{'request.course.id'} => time); + &Apache::lonnet::put('email_status',\%temp); + &Apache::lonnet::delenv('user.state.'.$env{'request.course.id'}); + &Apache::lonnet::appenv({"request.course.id" => '', + "request.course.fn" => '', + "request.course.uri" => '', + "request.course.sec" => '', + "request.role" => 'cm', + "request.role.adv" => $env{'user.adv'}, + "request.role.domain" => $env{'user.domain'}}); + my $rolename = &Apache::loncommon::plainname($curr_role); + $msg = ''. + ''. + ''. + ''. + &mt('Your section has changed for your current [_1] role in [_2].',$rolename,$coursedesc).'';
+ if (&Apache::loncommon::show_course()) {
+ $msg .= &mt('Your role in the current course has expired.');
+ } else {
+ $msg .= &mt('Your current role has expired.');
+ }
+ $msg .= '
'.&mt('However you can continue to use this role until you logout, click the "Re-Select" button, or your session has been idle for more than 24 hours.').'
'.&mt('Course/Community requests').'
'.
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row().
+ '
'.&mt('Enrollment requests').'
'.
+ $queuedselfenroll.'
'.&mt('Author role request').'
';
+ if ($status eq 'approval') {
+ $output .= &mt('A request for Authoring Space submitted on [_1] is awaiting approval',
+ &Apache::lonlocal::locallocaltime($timestamp));
+ } elsif ($status eq 'approved') {
+ my %roleshash =
+ &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
+ ['active'],['au'],[$env{'user.domain'}]);
+ if (keys(%roleshash)) {
+ $output .= ''.
+ &mt('Your request for an author role has been approved.').'
'.
+ &mt('Use the "Check for changes" link to update your list of roles.').
+ '';
+ }
+ }
+ $output .= '