User Role Extent '.
- 'Start End Remark '."\n");
- my $envkey;
- foreach $envkey (sort keys %ENV) {
- if ($envkey=~/^user\.role\./) {
- my ($dum1,$dum2,$role,@pwhere)=split(/\./,$envkey);
- my $where=join('.',@pwhere);
- my ($tstart,$tend)=split(/\./,$ENV{$envkey});
- my $tremark='';
- my $tstatus='is';
- my $tpstart=' ';
- my $tpend=' ';
- if ($tstart) {
- if ($tstart>$then) {
- $tstatus='future';
- if ($tstart<$now) { $tstatus='will'; }
- }
- $tpstart=localtime($tstart);
- }
- if ($tend) {
- if ($tend<$then) { $tstatus='expired'; }
- if ($tend>$now) { $tstatus='will_not'; }
- $tpend=localtime($tend);
+ my (%roletext,%sortrole,%roleclass,%futureroles,%timezones);
+ my ($countactive,$countfuture,$inrole,$possiblerole) =
+ &gather_roles($update,$refresh,$now,$reinit,$nochoose,\%roles_in_env,\%roletext,
+ \%sortrole,\%roleclass,\%futureroles,\%timezones,$loncaparev);
+ $refresh = $now;
+ &Apache::lonnet::appenv({'user.refresh.time' => $refresh});
+ if ($countactive == 1) {
+ if ($env{'request.course.id'}) {
+ if ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') {
+ $placementonly = 1;
+ }
+ } elsif ($possiblerole) {
+ if ($possiblerole =~ m{^st\./($match_domain)/($match_courseid)(?:/|$)}) {
+ if ($env{'course.'.$1.'_'.$2.'.type'} eq 'Placement') {
+ $placementonly = 1;
+ }
}
+ }
+ }
+ if ((($cattype eq 'std') || ($cattype eq 'domonly')) && (!$env{'user.adv'}) &&
+ (!$placementonly)) {
+ if ($countactive > 0) {
+ my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
+ my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
+ $r->print(
+ ''
+ .&mt('[_1]Visit the [_2]Course/Community Catalog[_3][_4]'
+ .' to view all [_5] LON-CAPA courses and communities.'
+ ,''
+ ,''
+ ,' '
+ ,' '
+ ,'"'.$domdesc.'"')
+ .' '
+ .&mt('If a course or community is [_1]not[_2] in your list of current courses and communities below,'
+ .' you may be able to enroll if self-enrollment is permitted.'
+ ,'',' ')
+ .'
'
+ );
+ }
+ }
+
+# No active roles
+ if ($countactive==0) {
+ my $elapsed = 0;
+ if ($now && $update) {
+ $elapsed = $now - $update;
+ }
+ &requestcourse_advice($r,$cattype,$inrole,$elapsed);
+ $r->print('');
+ if ($countfuture) {
+ $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture));
+ my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,
+ $nochoose);
+ &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,
+ \%roletext,$update,$then);
+ my $tremark='';
my $tbg;
- if ($tstatus eq 'is') {
- $tbg='#77FF77';
- } elsif ($tstatus eq 'future') {
- $tbg='#FFFF77';
- } elsif ($tstatus eq 'will') {
- $tbg='#FFAA77';
- $tremark.='Active at next login.';
- } elsif ($tstatus eq 'expired') {
- $tbg='#FF7777';
- } elsif ($tstatus eq 'will_not') {
- $tbg='#AAFF77';
- $tremark.='Expired after logout.';
+ if ($env{'request.role'} eq 'cm') {
+ $tbg="LC_roles_selected";
+ $tremark=&mt('Currently selected.').' ';
+ } else {
+ $tbg="LC_roles_is";
}
- my $trole;
- if ($role =~ /^cr\//) {
- my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
- $tremark.=' Defined by '.$rauthor.' at '.$rdomain.'.';
- $trole=$rrole;
+ $r->print(&Apache::loncommon::start_data_table_row()
+ .' '
+ .''
+ .&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;
+ } elsif (($placementonly) && ($env{'request.role'} eq 'cm')) {
+ $r->print(''.&mt('Please stand by.').'
+
+
+
+ ');
+ $r->rflush();
+ $r->print('');
+ $r->print(&Apache::loncommon::end_page());
+ return OK;
+ }
+# ----------------------------------------------------------------------- Table
+
+ if (($numdc > 0) || (($numhelpdesk > 0) && ($numadhoc > 0))) {
+ $r->print(&coursepick_jscript().
+ &Apache::loncommon::coursebrowser_javascript());
+ }
+ if ($numdc > 0) {
+ $r->print(&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 ($role =~ m{^(dh|da)\./($match_domain)/$}) {
+ $output .= &adhoc_customroles_row($1,$2,'recent',$update,$then);
+ }
+ } 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,$update,$then);
+ 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 {
- $trole=Apache::lonnet::plaintext($role);
+ $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('This LON-CAPA server is version [_1]',$r->dir_config('lonVersion'))
+ .'
');
+ }
+ $r->print(&Apache::loncommon::end_page());
+ return OK;
+}
+
+sub roles_from_env {
+ my ($roleshash,$update) = @_;
+ my $count = 0;
+ if (ref($roleshash) eq 'HASH') {
+ foreach my $envkey (keys(%env)) {
+ if ($envkey =~ m{^user\.role\.(\w+)[./]}) {
+ next if ($1 eq 'gr');
+ $roleshash->{$envkey} = $env{$envkey};
+ my ($start,$end) = split(/\./,$env{$envkey});
+ unless ($end && $end<$update) {
+ $count ++;
+ }
}
- my $ttype;
- my $twhere;
- my ($tres,$tdom,@trest)=split(/\//,$where);
- if ($where=~/\.course$/) {
- $ttype='Course';
- $twhere=$tdom.'/'.join('/',@trest);
- } elsif ($tdom) {
- $ttype='Domain';
- $twhere=$tdom;
- } else {
- $ttype='System';
- $twhere='/';
- }
-
- $r->print(''.$trole.' '.
- $ttype.' '.$twhere.' '.$tpstart.
- ' '.$tpend.
- ' '.$tremark.' '."\n");
}
}
+ return $count;
+}
+
+sub gather_roles {
+ my ($update,$refresh,$now,$reinit,$nochoose,$roles_in_env,$roletext,$sortrole,$roleclass,$futureroles,
+ $timezones,$loncaparev) = @_;
+ my ($countactive,$countfuture,$inrole,$possiblerole) = (0,0,0,'');
+ my $advanced = $env{'user.adv'};
+ my $tryagain = $env{'form.tryagain'};
+ my @ids = &Apache::lonnet::current_machine_ids();
+ my (%willtrust,%trustchecked);
+ if (ref($roles_in_env) eq 'HASH') {
+ my %adhocdesc;
+ foreach my $envkey (sort(keys(%{$roles_in_env}))) {
+ my $button = 1;
+ my $switchserver='';
+ my $switchwarning;
+ my ($role_text,$role_text_end,$sortkey,$role,$where,$trolecode,$tstart,
+ $tend,$tremark,$tstatus,$tpstart,$tpend);
+ &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
+ \$trolecode,\$tstatus,\$tstart,\$tend);
+ next if (!defined($role) || $role eq '' || $role =~ /^gr/);
+ $tremark='';
+ $tpstart=' ';
+ $tpend=' ';
+ if ($env{'request.role'} eq $trolecode) {
+ $tstatus='selected';
+ }
+ my $tbg;
+ if (($tstatus eq 'is')
+ || ($tstatus eq 'selected')
+ || ($tstatus eq 'future')
+ || ($env{'form.display'} eq 'showall')) {
+ my $timezone = &role_timezone($where,$timezones);
+ if ($tstart) {
+ $tpstart=&Apache::lonlocal::locallocaltime($tstart,$timezone);
+ }
+ if ($tend) {
+ $tpend=&Apache::lonlocal::locallocaltime($tend,$timezone);
+ }
+ if ($tstatus eq 'is') {
+ $tbg='LC_roles_is';
+ $possiblerole=$trolecode;
+ $countactive++;
+ } elsif ($tstatus eq 'future') {
+ $tbg='LC_roles_future';
+ $button=0;
+ $futureroles->{$trolecode} = $tstart.':'.$tend;
+ $countfuture ++;
+ } elsif ($tstatus eq 'expired') {
+ $tbg='LC_roles_expired';
+ $button=0;
+ } elsif ($tstatus eq 'will_not') {
+ $tbg='LC_roles_will_not';
+ $tremark.=&mt('Expired after logout.').' ';
+ } elsif ($tstatus eq 'selected') {
+ $tbg='LC_roles_selected';
+ $inrole=1;
+ $countactive++;
+ $tremark.=&mt('Currently selected.').' ';
+ }
+ my $trole;
+ if ($role =~ /^cr\//) {
+ my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
+ unless ($rauthor eq $rdomain.'-domainconfig') {
+ if ($tremark) { $tremark.=' '; }
+ $tremark.=&mt('Custom role defined by [_1].',$rauthor.':'.$rdomain);
+ }
+ }
+ $trole=Apache::lonnet::plaintext($role);
+ my $ttype;
+ my $twhere;
+ my $skipcal;
+ my ($tdom,$trest,$tsection)=
+ split(/\//,Apache::lonnet::declutter($where));
+ # First, Co-Authorship roles
+ if (($role eq 'ca') || ($role eq 'aa')) {
+ my $home = &Apache::lonnet::homeserver($trest,$tdom);
+ my $allowed=0;
+ my $prohibited;
+ foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
+ if (!$allowed) {
+ $button=0;
+ unless ($trustchecked{$tdom}) {
+ if ((&Apache::lonnet::will_trust('othcoau',$env{'user.domain'},$tdom)) &&
+ (&Apache::lonnet::will_trust('coaurem',$tdom,$env{'user.domain'}))) {
+ $willtrust{$tdom} = 1;
+ $trustchecked{$tdom} = 1;
+ }
+ }
+ if ($willtrust{$tdom}) {
+ $switchserver='otherserver='.$home.'&role='.$trolecode;
+ } else {
+ $prohibited = 1;
+ $tremark .= &mt('Session switch required but prohibited.');
+ }
+ }
+ #next if ($home eq 'no_host');
+ $home = &Apache::lonnet::hostname($home);
+ $ttype='Authoring Space';
+ $twhere=&mt('User').': '.$trest.' '.&mt('Domain').
+ ': '.$tdom.' '.
+ ' '.&mt('Server').': '.$home;
+ $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
+ unless ($prohibited) {
+ $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;
+ foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
+ if (!$allowed) {
+ $button=0;
+ $switchserver='otherserver='.$home.'&role='.$trolecode;
+ }
+ #next if ($home eq 'no_host');
+ $home = &Apache::lonnet::hostname($home);
+ $ttype='Authoring Space';
+ $twhere=&mt('Domain').': '.$tdom.' '.&mt('Server').
+ ': '.$home;
+ $env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
+ $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
+ $sortkey=$role;
+ } elsif ($trest) {
+ my $tcourseid=$tdom.'_'.$trest;
+ $ttype = &Apache::loncommon::course_type($tcourseid);
+ if ($role !~ /^cr/) {
+ $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid);
+ } elsif ($role =~ m{^\Qcr/$tdom/$tdom\E\-domainconfig/(\w+)$}) {
+ my $rolename = $1;
+ my $desc;
+ if (ref($adhocdesc{$tdom}) eq 'HASH') {
+ $desc = $adhocdesc{$tdom}{$rolename};
+ } else {
+ my %domdef = &Apache::lonnet::get_domain_defaults($tdom);
+ if (ref($domdef{'adhocroles'}) eq 'HASH') {
+ foreach my $rolename (sort(keys(%{$domdef{'adhocroles'}}))) {
+ if (ref($domdef{'adhocroles'}{$rolename}) eq 'HASH') {
+ $adhocdesc{$tdom}{$rolename} = $domdef{'adhocroles'}{$rolename}{'desc'};
+ $desc = $adhocdesc{$tdom}{$rolename};
+ }
+ }
+ }
+ }
+ if ($desc ne '') {
+ $trole = $desc;
+ } else {
+ $trole = &mt('Helpdesk[_1]',' '.$rolename);
+ }
+ } else {
+ $trole = (split(/\//,$role,4))[-1];
+ }
+ if ($env{'course.'.$tcourseid.'.description'}) {
+ my $home=$env{'course.'.$tcourseid.'.home'};
+ $twhere=$env{'course.'.$tcourseid.'.description'};
+ $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).
+ ' ';
+ unless ($home && grep(/^\Q$home\E$/,@ids) && $loncaparev eq '') {
+ my $required = $env{'course.'.$tcourseid.'.internal.releaserequired'};
+ if ($required ne '') {
+ ($switchserver,$switchwarning) =
+ &Apache::loncommon::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=&HTML::Entities::encode($newhash{'description'},'"<>&').
+ ' '.
+ &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom).
+ ' ';
+ $ttype = $newhash{'type'};
+ $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) =
+ &Apache::loncommon::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;
+ $ttype = 'Unavailable';
+ $skipcal = 1;
+ }
+ }
+ if ($ttype eq 'Placement') {
+ $ttype = 'Placement Test';
+ }
+ if ($tsection) {
+ $twhere.=' '.&mt('Section').': '.$tsection;
+ }
+ if ($role ne 'st') { $twhere.=" ".&mt('Domain').":".$tdom; }
+ } elsif ($tdom) {
+ $ttype='Domain';
+ $twhere=$tdom;
+ $sortkey=$role.$twhere;
+ } else {
+ $ttype='System';
+ $twhere=&mt('system wide');
+ $sortkey=$role.$twhere;
+ }
+ ($role_text,$role_text_end) =
+ &build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,
+ $advanced,$tremark,$tbg,$trole,$twhere,$tpstart,
+ $tpend,$nochoose,$button,$switchserver,$reinit,
+ $switchwarning,$skipcal);
+ $roletext->{$envkey}=[$role_text,$role_text_end];
+ if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
+ $sortrole->{$sortkey}=$envkey;
+ $roleclass->{$envkey}=$ttype;
+ }
+ }
+ }
+ return ($countactive,$countfuture,$inrole,$possiblerole);
+}
+
+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);
+ }
+ }
+ $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'};
+ }
+ }
+ $timezone = $timezones->{$tdom};
+ }
+ }
+ if ($timezone eq 'local') {
+ $timezone = undef;
+ }
+ }
+ return $timezone;
+}
+
+sub roletable_headers {
+ my ($r,$roleclass,$sortrole,$nochoose) = @_;
+ my $doheaders;
+ if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) {
+ $r->print(' '
+ .&Apache::loncommon::start_data_table('LC_textsize_mobile')
+ .&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++; }
+ }
+ }
+ return $doheaders;
+}
+
+sub roletypes {
+ my @types = ('Domain','Authoring Space','Course','Placement Test','Community','Unavailable','System');
+ return @types;
+}
+
+sub print_rolerows {
+ my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext,$update,$then) = @_;
+ 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{^user\.role\.dc\./($match_domain)/}) {
+ if (ref($dcroles) eq 'HASH') {
+ if ($dcroles->{$1}) {
+ $output .= &adhoc_roles_row($1,'');
+ }
+ }
+ } elsif ($sortrole->{$which} =~ m{^user\.role\.(dh|da)\./($match_domain)/}) {
+ $output .= &adhoc_customroles_row($1,$2,'',$update,$then);
+ }
+ }
+ }
+ }
+ if ($output) {
+ if ($doheaders > 0) {
+ $r->print(&Apache::loncommon::start_data_table_empty_row()
+ .''
+ .&mt($type)
+ .' '
+ .&Apache::loncommon::end_data_table_empty_row()
+ );
+ }
+ $r->print($output);
+ }
+ }
+ }
+}
+
+sub findcourse_advice {
+ my ($r,$cattype,$elapsed) = @_;
+ 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).'
+
+ '.&mt('The course has yet to be created.').'
+ '.&mt('Automatic enrollment of registered students has not been enabled for the course.').'
+ '.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'
+ '.&mt('The start date for automated enrollment has yet to be reached.').'
+ '.&mt('You registered for the course recently and there is a time lag between the time you register, and the time this information becomes available for the update of LON-CAPA course rosters.').'
+ '.&mt('Automated enrollment added you to the course in the time since you last logged-in.').' '.&mt('If that is the case you can use the "Check for changes" link in the gray Functions bar to update the list of your available course roles.').'
+ ');
+ } else {
+ $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.').'
');
+ if ($elapsed > 600) {
+ $r->print(''.&mt('You may also have been assigned to a course in the time since you last logged-in, or checked for changes').
+ ' '.
+ &mt('If that is the case you can use the "Check for changes" link in the gray Functions bar to update the list of your available course roles.').'
');
+ }
+ }
+ if (($cattype eq 'std') || ($cattype eq 'domonly')) {
+ $r->print(''.&mt('Self-Enrollment').' '.
+ ''.&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).' ');
+ $r->print(&mt('You can search for courses and communities which permit self-enrollment, if you would like to enroll in one.').'
'.
+ &Apache::loncoursequeueadmin::queued_selfenrollment());
+ }
+ return;
+}
+
+sub requestcourse_advice {
+ my ($r,$cattype,$inrole,$elapsed) = @_;
+ my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
+ my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
+ my (%can_request,%request_doms,$output);
+ &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')) {
+ 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}}));
+ $output .=
+ ''
+ .&mt('[_1]'.$typename->{$type}.'[_2] in domain: [_3]',
+ '',
+ ' ',
+ ''.$domstr.' ')
+ .' ';
+ foreach my $dom (@{$request_doms{$type}}) {
+ unless (grep(/^\Q$dom\E/,@reqdoms)) {
+ push(@reqdoms,$dom);
+ }
+ }
+ }
+ }
+ my @showtypes;
+ foreach my $type (@{$types}) {
+ if (grep(/^\Q$type\E$/,@reqtypes)) {
+ push(@showtypes,$type);
+ }
+ }
+ my $requrl = '/adm/requestcourse';
+ if (@reqdoms == 1) {
+ $requrl .= '?showdom='.$reqdoms[0];
+ }
+ if (@showtypes > 0) {
+ $requrl.=(($requrl=~/\?/)?'&':'?').'crstype='.$showtypes[0];
+ }
+ if (@reqdoms == 1 || @showtypes > 0) {
+ $requrl .= '&state=crstype&action=new';
+ }
+ if ($output) {
+ $r->print(''.&mt('Request creation of a course or community').' '.
+ ''.
+ &mt('You have rights to request the creation of courses and/or communities in the following domain(s):').
+ '
'.
+ &mt('Use the [_1]request form[_2] to submit a request for creation of a new course or community.',
+ '',' ').
+ '');
+ }
+ }
+ } elsif (!$env{'user.adv'}) {
+ if ($inrole) {
+ $r->print(''.&mt('Currently no additional roles, courses or communities').' ');
+ } else {
+ $r->print(''.&mt('Currently no active roles, courses or communities').' ');
+ }
+ &findcourse_advice($r,$cattype,$elapsed);
+ }
+ return;
+}
+
+sub privileges_info {
+ my ($which) = @_;
+ my $output;
+
+ $which ||= $env{'request.role'};
+
+ foreach my $envkey (sort(keys(%env))) {
+ next if ($envkey!~/^user\.priv\.\Q$which\E\.(.*)/);
+
+ my $where=$1;
+ my $ttype;
+ my $twhere;
+ my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
+ if ($trest) {
+ if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
+ $ttype='Authoring Space';
+ $twhere='User: '.$trest.', Domain: '.$tdom;
+ } else {
+ $ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
+ $twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
+ if ($tsec) {
+ my $sec_type = 'Section';
+ if (exists($env{"user.role.gr.$where"})) {
+ $sec_type = 'Group';
+ }
+ $twhere.=' ('.$sec_type.': '.$tsec.')';
+ }
+ }
+ } elsif ($tdom) {
+ $ttype='Domain';
+ $twhere=$tdom;
+ } else {
+ $ttype='System';
+ $twhere='/';
+ }
+ $output .= "\n".&mt($ttype).': '.$twhere.' '."\n";
+ foreach my $priv (sort(split(/:/,$env{$envkey}))) {
+ next if (!$priv);
+
+ my ($prv,$restr)=split(/\&/,$priv);
+ my $trestr='';
+ if ($restr ne 'F') {
+ $trestr.=' ('.
+ join(', ',
+ map { &Apache::lonnet::plaintext($_) }
+ (split('',$restr))).') ';
+ }
+ $output .= "\n\t".
+ ''.&Apache::lonnet::plaintext($prv).$trestr.' ';
+ }
+ $output .= "\n".' ';
+ }
+ return $output;
+}
+
+sub build_roletext {
+ my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere,
+ $tpstart,$tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning,$skipcal) = @_;
+ my ($roletext,$roletext_end,$poss_adhoc);
+ if ($trolecode =~ m/^d(c|h|a)\./) {
+ $poss_adhoc = 1;
+ }
+ my $rowspan=($poss_adhoc) ? ''
+ : ' rowspan="2" ';
- $r->print('
');
unless ($nochoose) {
- $r->print("