--- loncom/auth/lonroles.pm 2021/01/04 12:53:37 1.269.2.37.2.2 +++ loncom/auth/lonroles.pm 2016/10/27 22:51:08 1.320 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.269.2.37.2.2 2021/01/04 12:53:37 raeburn Exp $ +# $Id: lonroles.pm,v 1.320 2016/10/27 22:51:08 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -140,10 +140,11 @@ use Apache::lonnavdisplay(); use Apache::loncoursequeueadmin; use Apache::longroup; use Apache::lonrss; +use Apache::lonplacementtest; use GDBM_File; use LONCAPA qw(:DEFAULT :match); use HTML::Entities; - + sub redirect_user { my ($r,$title,$url,$msg) = @_; @@ -151,7 +152,6 @@ sub redirect_user { &Apache::loncommon::content_type($r,'text/html'); &Apache::loncommon::no_cache($r); $r->send_http_header; - my $swinfo=&Apache::lonmenu::rawconfig(); # Breadcrumbs my $brcrum = [{'href' => $url, @@ -166,11 +166,6 @@ sub redirect_user { $url=~s/ /\%20/g; $r->print(< -// -

$msg

$end_page ENDREDIR @@ -209,7 +204,7 @@ sub handler { my $r = shift; # Check for critical messages and redirect if present. - my ($redirect,$url) = &Apache::loncommon::critical_redirect(300,'roles'); + my ($redirect,$url) = &Apache::loncommon::critical_redirect(300); if ($redirect) { &Apache::loncommon::content_type($r,'text/html'); $r->header_out(Location => $url); @@ -229,7 +224,7 @@ sub handler { &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}); -# -------------------------------------------------- Check if setting hot list +# -------------------------------------------------- Check if setting hot list my $hotlist; if ($env{'form.action'} eq 'verify_and_change_rolespref') { $hotlist = &Apache::lonpreferences::verify_and_change_rolespref($r); @@ -260,9 +255,8 @@ sub handler { my $envkey; my %dcroles = (); - my %helpdeskroles = (); - my ($numdc,$numhelpdesk,$numadhoc) = - &check_for_adhoc(\%dcroles,\%helpdeskroles,$update,$then); + my %dhroles = (); + my ($numdc,$numdh,$numadhoc) = &check_for_adhoc(\%dcroles,\%dhroles,$update,$then); my $loncaparev = $r->dir_config('lonVersion'); # ================================================================== Roles Init @@ -274,9 +268,9 @@ sub handler { my $custom_adhoc; if ($env{'form.newrole'}) { $env{'form.'.$env{'form.newrole'}}=1; -# Check if this is a Domain Helpdesk or Domain Helpdesk Assistant role trying to enter a course +# Check if this is a Domain Helpdesk role trying to enter a course if ($env{'form.newrole'} =~ m{^cr/($match_domain)/\1\-domainconfig/\w+\./\1/$match_courseid$}) { - if ($helpdeskroles{$1}) { + if ($dhroles{$1}) { $custom_adhoc = 1; } } @@ -311,28 +305,29 @@ sub handler { "request.role.adv" => $env{'user.adv'}, "request.role.domain" => $env{'user.domain'}}); # Check if Domain Helpdesk role trying to enter a course needs privs to be created - if ($env{'form.newrole'} =~ m{^cr/($match_domain)/\1\-domainconfig/(\w+)\./\1/($match_courseid)(?:/(\w+)|$)}) { + if ($env{'form.newrole'} =~ m{^cr/($match_domain)/\1\-domainconfig/(\w+)\./\1/($match_courseid)$}) { my $cdom = $1; my $rolename = $2; my $cnum = $3; - my $sec = $4; if ($custom_adhoc) { - my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($cdom.'_'.$cnum,1); - if (ref($possroles) eq 'ARRAY') { - if (grep(/^\Q$rolename\E$/,@{$possroles})) { + my %adhocroles = &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'}, + 'adhocroles.'.$cdom); + if (keys(%adhocroles)) { + my @adhoc = split(',',$adhocroles{'adhocroles.'.$cdom}); + if (grep(/^\Q$rolename\E$/,@adhoc)) { if (&Apache::lonnet::check_adhoc_privs($cdom,$cnum,$update,$refresh,$now, - "cr/$cdom/$cdom".'-domainconfig/'.$rolename,undef,$sec)) { + "cr/$cdom/$cdom".'-domainconfig/'.$rolename)) { &Apache::lonnet::appenv({"environment.internal.$cdom.$cnum.cr/$cdom/$cdom".'-domainconfig/'."$rolename.adhoc" => time}); } } } } - } elsif (($numdc > 0) || ($numhelpdesk > 0)) { + } elsif (($numdc > 0) || ($numdh > 0)) { # Check if user is a DC trying to enter a course or author space and needs privs to be created -# Check if user is a DH or DA trying to enter a course and needs privs to be created +# Check if user is a DH trying to enter a course and needs privs to be created foreach my $envkey (keys(%env)) { - if ($numdc) { # Is this an ad-hoc Coordinator role? + if ($numdc) { if (my ($ccrole,$domain,$coursenum) = ($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) { if ($dcroles{$domain}) { @@ -399,16 +394,24 @@ sub handler { last; } } - if ($numhelpdesk) { + if ($numdh) { # Is this an ad hoc custom role in a course/community? - if (my ($domain,$rolename,$coursenum,$sec) = ($envkey =~ m{^form\.cr/($match_domain)/\1\-domainconfig/(\w+)\./\1/($match_courseid)(?:/(\w+)|$)})) { - if ($helpdeskroles{$domain}) { - my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($domain.'_'.$coursenum,1); - if (ref($possroles) eq 'ARRAY') { - if (grep(/^\Q$rolename\E$/,@{$possroles})) { + if (my ($domain,$rolename,$coursenum) = ($envkey =~ m{^form\.cr/($match_domain)/\1\-domainconfig/(\w+)\./\1/($match_courseid)$})) { + if ($dhroles{$domain}) { + my @adhoc; + if ($env{'environment.adhocroles.'.$domain}) { + @adhoc = split(',',$env{'environment.adhocroles.'.$domain}); + } else { + my %adhocroles = &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'}, + 'adhocroles.'.$domain); + if (keys(%adhocroles)) { + @adhoc = split(',',$adhocroles{'adhocroles.'.$domain}); + } + } + if ((@adhoc > 0) && ($rolename ne '')) { + if (grep(/^\Q$rolename\E$/,@adhoc)) { if (&Apache::lonnet::check_adhoc_privs($domain,$coursenum,$update,$refresh,$now, - "cr/$domain/$domain".'-domainconfig/'.$rolename, - undef,$sec)) { + "cr/$domain/$domain".'-domainconfig/'.$rolename)) { &Apache::lonnet::appenv({"environment.internal.$domain.$coursenum.cr/$domain/$domain". '-domainconfig/'."$rolename.adhoc" => time}); } @@ -423,10 +426,9 @@ sub handler { } last; } - } + } } } - foreach $envkey (keys(%env)) { next if ($envkey!~/^user\.role\./); my ($where,$trolecode,$role,$tstatus,$tend,$tstart); @@ -495,7 +497,6 @@ sub handler { my $end_page=&Apache::loncommon::end_page(); my $buttontext=&mt('Enter Course'); my $message=&mt('Successfully registered key'); - my $ip = &Apache::lonnet::get_requestor_ip(); my $assignresult= &Apache::lonnet::assign_access_key( $env{'form.newkey'}, @@ -504,7 +505,7 @@ sub handler { $env{'user.domain'}, $env{'user.name'}, &mt('Assigned from [_1] at [_2] for [_3]' - ,$ip + ,$ENV{'REMOTE_ADDR'} ,&Apache::lonlocal::locallocaltime() ,$trolecode) ); @@ -563,7 +564,7 @@ ENDENTERKEY $env{'user.name'}, $env{'user.home'}, "Role ".$trolecode); - + &Apache::lonnet::appenv( {'request.role' => $trolecode, 'request.role.domain' => $cdom, @@ -572,44 +573,16 @@ ENDENTERKEY my $tadv=0; if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) { - if ($role =~ m{^\Qcr/$cdom/$cdom\E\-domainconfig/(\w+)$}) { - my $rolename = $1; - my %domdef = &Apache::lonnet::get_domain_defaults($cdom); - if (ref($domdef{'adhocroles'}) eq 'HASH') { - if (ref($domdef{'adhocroles'}{$rolename}) eq 'HASH') { - &Apache::lonnet::appenv({'request.role.desc' => $domdef{'adhocroles'}{$rolename}{'desc'}}); - } - } - } my $msg; - my ($furl,$ferr)= - &Apache::lonuserstate::readmap($cdom.'/'.$cnum); + my ($furl,$ferr)= + &Apache::lonuserstate::readmap($cdom.'/'.$cnum); unless ($ferr) { - unless (($env{'form.switchrole'}) || + unless (($env{'form.switchrole'}) || ($env{"environment.internal.$cdom.$cnum.$role.adhoc"})) { &Apache::lonnet::put('nohist_crslastlogin', {$env{'user.name'}.':'.$env{'user.domain'}. ':'.$csec.':'.$role => $now},$cdom,$cnum); } - if (($env{"environment.internal.$cdom.$cnum.$role.adhoc"}) && - (&Apache::lonnet::allowed('vxc',$cdom.'_'.$cnum))) { - my $owner = $env{'course.'.$cdom.'_'.$cnum.'.internal.courseowner'}; - my @coowners = split(/,/,$env{'course.'.$env{'request.course.id'}.'.internal.co-owners'}); - my %auaccess; - foreach my $user ($owner,@coowners) { - my ($cpname,$cpdom) = split(/:/,$user); - my %auroles = &Apache::lonnet::get_my_roles($cpname,$cpdom,'userroles',undef,['au','ca','aa'],[$cdom]); - foreach my $key (keys(%auroles)) { - my ($auname,$audom,$aurole) = split(/:/,$key); - if ($aurole eq 'au') { - $auaccess{$cpname} = 1; - } else { - $auaccess{$auname} = 1; - } - } - } - &Apache::lonnet::appenv({'request.course.adhocsrcaccess' => join(',',sort(keys(%auaccess))) }); - } my ($feeds,$syllabus_time); &Apache::lonrss::advertisefeeds($cnum,$cdom,undef,\$feeds); &Apache::lonnet::appenv({'request.course.feeds' => $feeds}); @@ -627,7 +600,7 @@ ENDENTERKEY } if (($env{'form.orgurl'}) && ($env{'form.orgurl'}!~/^\/adm\/flip/) && - ($env{'form.orgurl'} ne '/adm/roles')) { + ($env{'form.orgurl'} ne '/adm/roles')) { my $dest=$env{'form.orgurl'}; if ($env{'form.symb'}) { if ($dest =~ /\?/) { @@ -677,6 +650,17 @@ ENDENTERKEY $furl = "/adm/helper/course.initialization.helper"; # Send the user to the course they selected } elsif ($env{'request.course.id'}) { + if ((&Apache::loncommon::course_type() eq 'Placement') && + (!$env{'request.role.adv'})) { + my ($score,$incomplete) = + &Apache::lonplacementtest::check_completion(undef,undef,1); + if (($incomplete) && ($incomplete < 100)) { + &redirect_user($r, &mt('Entering [_1]', + $env{'course.'.$cdom.'_'.$cnum.'.description'}), + '/adm/placement', $msg); + return OK; + } + } my ($dest,$destsymb,$checkenc); $dest = $env{'form.destinationurl'}; $destsymb = $env{'form.destsymb'}; @@ -689,22 +673,11 @@ ENDENTERKEY } } } - if (($dest =~ m{^\Q/public/$cdom/$cnum/syllabus\E.*(\?|\&)usehttp=1}) || - ($dest =~ m{^\Q/adm/wrapper/ext/\E(?!https:)})) { - if ($ENV{'SERVER_PORT'} == 443) { - unless (&Apache::lonnet::uses_sts()) { - my $hostname = $r->hostname(); - if ($hostname ne '') { - $dest = 'http://'.$hostname.$dest; - } - } - } - } if ($dest =~ m{^/enc/}) { if ($env{'request.role.adv'}) { $dest = &Apache::lonenc::unencrypted($dest); if ($destsymb eq '') { - ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]*)/); + ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]*)/); $destsymb = &unescape($destsymb); } } @@ -729,10 +702,10 @@ ENDENTERKEY } } } - unless (($dest =~ m{^/enc/}) || ($dest =~ /(\?|\&)symb=.+___\d+___.+/)) { + unless (($dest =~ m{^/enc/}) || ($dest =~ /(\?|\&)symb=.+___\d+___.+/)) { if (($destsymb ne '') && ($destsymb !~ m{^/enc/})) { my $esc_symb = &escape($destsymb); - $dest .= (($dest =~/\?/)? '&':'?').'symb='.$esc_symb; + $dest .= '?symb='.$esc_symb; } } &redirect_user($r, &mt('Entering [_1]', @@ -810,12 +783,6 @@ ENDENTERKEY $redirect_url); return OK; } - if ($role eq 'da') { - my $redirect_url = '/adm/menu/'; - &redirect_user($r,&mt('Loading Domain Helpdesk Assistant Menu'), - $redirect_url); - return OK; - } if ($role eq 'sc') { my $redirect_url = '/adm/grades?command=scantronupload'; &redirect_user($r,&mt('Loading Data Upload Page'), @@ -844,7 +811,7 @@ ENDENTERKEY $crumbtext = 'Courses'; $pagetitle = 'My Courses'; $recent = &mt('Recent Courses'); - $standby = &mt('Course selected. Please stand by.'); + $standby = &mt('Course selected. Please stand by.'); } my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}]; @@ -857,14 +824,40 @@ ENDENTERKEY if ($domdefs{'catauth'}) { $cattype = $domdefs{'catauth'}; } - my $funcs = &get_roles_functions($showcount,$cattype); - my $crumbsright; - if ($env{'browser.mobile'}) { - $crumbsright = $funcs; - undef($funcs); + my $placementonly; + if ($showcount == 1) { + if ($env{'request.course.id'}) { + if ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') { + $placementonly = 1; + } + } else { + foreach my $rolecode (keys(%roles_in_env)) { + my ($cid) = ($rolecode =~ m{^\Quser.role.st./\E($match_domain/$match_courseid)(?:/|$)}); + if ($cid) { + my %coursedescription = + &Apache::lonnet::coursedescription($cid,{'one_time' => '1'}); + if ($coursedescription{'type'} eq 'Placement') { + $placementonly = 1; + } + last; + } + } + } + } + my ($start_page,$funcs); + if ($placementonly) { + $start_page=&Apache::loncommon::start_page($pagetitle,undef, + {bread_crumbs=>$brcrum,crstype=>'Placement'}); + } else { + $funcs = &get_roles_functions($showcount,$cattype); + my $crumbsright; + if ($env{'browser.mobile'}) { + $crumbsright = $funcs; + undef($funcs); + } + $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum, + bread_crumbs_component=>$crumbsright}); } - my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum, - bread_crumbs_component=>$crumbsright}); &js_escape(\$standby); my $noscript='
'.&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.').'
'.&mt('As this is not the case, most functionality in the system will be unavailable.').'

'; @@ -898,7 +891,7 @@ function rolesView (caller) { document.rolechoice.display.value = caller; } else { if ((caller == 'doupdate') || (caller == 'requestauthor') || - (caller == 'queued')) { + (caller == 'queued')) { document.rolechoice.state.value = caller; } } @@ -982,7 +975,7 @@ ENDHEADER } if ($hotlist) { $showresult .= $hotlist; - } + } $showresult .= ''; $r->print($showresult); } elsif ($env{'form.state'} eq 'queued') { @@ -1007,7 +1000,21 @@ ENDHEADER \%sortrole,\%roleclass,\%futureroles,\%timezones,$loncaparev); $refresh = $now; &Apache::lonnet::appenv({'user.refresh.time' => $refresh}); - if ((($cattype eq 'std') || ($cattype eq 'domonly')) && (!$env{'user.adv'})) { + 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'},'"<>&'); @@ -1031,18 +1038,14 @@ ENDHEADER # No active roles if ($countactive==0) { - my $elapsed = 0; - if ($now && $update) { - $elapsed = $now - $update; - } - &requestcourse_advice($r,$cattype,$inrole,$elapsed); + &requestcourse_advice($r,$cattype,$inrole); $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); + \%roletext); my $tremark=''; my $tbg; if ($env{'request.role'} eq 'cm') { @@ -1064,15 +1067,23 @@ ENDHEADER } $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()); + if (($numdc > 0) || (($numdh > 0) && ($numadhoc > 0))) { + $r->print(&coursepick_jscript()); + $r->print(&Apache::loncommon::coursebrowser_javascript(). + &Apache::loncommon::authorbrowser_javascript()); } unless ((!&Apache::loncommon::show_course()) || ($nochoose) || ($countactive==1)) { @@ -1105,8 +1116,9 @@ ENDHEADER 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 ($role =~ m{^dh\./($match_domain)/$} + && ($env{'environment.adhocroles.'.$1} ne '')) { + $output .= &adhoc_customroles_row($1,'recent'); } } elsif ($numdc > 0) { unless ($role =~/^error\:/) { @@ -1135,7 +1147,7 @@ ENDHEADER $doheaders ++; } } - &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext,$update,$then); + &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext); if ($countactive > 1) { my $tremark=''; my $tbg; @@ -1212,7 +1224,6 @@ sub gather_roles { my $tryagain = $env{'form.tryagain'}; my @ids = &Apache::lonnet::current_machine_ids(); if (ref($roles_in_env) eq 'HASH') { - my %adhocdesc; foreach my $envkey (sort(keys(%{$roles_in_env}))) { my $button = 1; my $switchserver=''; @@ -1264,14 +1275,13 @@ sub gather_roles { 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); - } + 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 @@ -1313,32 +1323,7 @@ sub gather_roles { } 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]; - } + $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid); if ($env{'course.'.$tcourseid.'.description'}) { my $home=$env{'course.'.$tcourseid.'.home'}; $twhere=$env{'course.'.$tcourseid.'.description'}; @@ -1386,8 +1371,12 @@ sub gather_roles { $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; } @@ -1404,7 +1393,8 @@ sub gather_roles { ($role_text,$role_text_end) = &build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain, $advanced,$tremark,$tbg,$trole,$twhere,$tpstart, - $tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning); + $tpend,$nochoose,$button,$switchserver,$reinit, + $switchwarning,$skipcal); $roletext->{$envkey}=[$role_text,$role_text_end]; if (!$sortkey) {$sortkey=$twhere."\0".$envkey;} $sortrole->{$sortkey}=$envkey; @@ -1502,12 +1492,12 @@ sub roletable_headers { } sub roletypes { - my @types = ('Domain','Authoring Space','Course','Community','Unavailable','System'); + 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) = @_; + my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext) = @_; if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) { my @types = &roletypes(); foreach my $type (@types) { @@ -1531,8 +1521,9 @@ sub print_rolerows { $output .= &adhoc_roles_row($1,''); } } - } elsif ($sortrole->{$which} =~ m{^user\.role\.(dh|da)\./($match_domain)/}) { - $output .= &adhoc_customroles_row($1,$2,'',$update,$then); + } elsif (($sortrole->{$which} =~ m{^user\.role\.dh\./($match_domain)/}) && + ($env{'environment.adhocroles.'.$1} ne '')) { + $output .= &adhoc_customroles_row($1,''); } } } @@ -1553,26 +1544,20 @@ sub print_rolerows { } sub findcourse_advice { - my ($r,$cattype,$elapsed) = @_; + 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).' + $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('

'.&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.').'

'); - } + $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 (($cattype eq 'std') || ($cattype eq 'domonly')) { $r->print('

'.&mt('Self-Enrollment').'

'. @@ -1584,7 +1569,7 @@ sub findcourse_advice { } sub requestcourse_advice { - my ($r,$cattype,$inrole,$elapsed) = @_; + my ($r,$cattype,$inrole) = @_; my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description'); my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&'); my (%can_request,%request_doms,$output); @@ -1645,7 +1630,7 @@ sub requestcourse_advice { } else { $r->print('

'.&mt('Currently no active roles, courses or communities').'

'); } - &findcourse_advice($r,$cattype,$elapsed); + &findcourse_advice($r,$cattype); } return; } @@ -1707,12 +1692,10 @@ sub privileges_info { sub build_roletext { my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere, - $tpstart,$tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning) = @_; - my ($roletext,$roletext_end,$poss_adhoc); - if ($trolecode =~ m/^d(c|h|a)\./) { - $poss_adhoc = 1; - } - my $rowspan=($poss_adhoc) ? '' + $tpstart,$tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning,$skipcal) = @_; + my ($roletext,$roletext_end); + my $is_dc=($trolecode =~ m/^dc\./); + my $rowspan=($is_dc) ? '' : ' rowspan="2" '; unless ($nochoose) { @@ -1765,7 +1748,7 @@ sub build_roletext { $trolecode."','".$buttonname.'\');" />'; } } - if ($trolecode !~ m/^(dc|ca|au|aa)\./) { + if (($trolecode !~ m/^(dc|ca|au|aa)\./) && (!$skipcal)) { $tremark.=&Apache::lonannounce::showday(time,1, &Apache::lonannounce::readcalendar($tdom.'_'.$trest)); } @@ -1773,7 +1756,7 @@ sub build_roletext { .''.$twhere.'' .''.$tpstart.'' .''.$tpend.''; - unless ($poss_adhoc) { + if (!$is_dc) { $roletext_end = ''. $tremark.' '. ''; @@ -1799,20 +1782,21 @@ sub check_author_homeserver { } sub check_for_adhoc { - my ($dcroles,$helpdeskroles,$update,$then) = @_; + my ($dcroles,$dhroles,$update,$then) = @_; my $numdc = 0; - my $numhelpdesk = 0; + my $numdh = 0; my $numadhoc = 0; - my $num_custom_adhoc = 0; - if (($env{'user.adv'}) || ($env{'user.rar'})) { + my $num_custom_adhoc = 0; + if ($env{'user.adv'}) { foreach my $envkey (sort(keys(%env))) { - if ($envkey=~/^user\.role\.(dc|dh|da)\.\/($match_domain)\/$/) { + if ($envkey=~/^user\.role\.(dc|dh)\.\/($match_domain)\/$/) { my $role = $1; my $roledom = $2; my $liverole = 1; my ($tstart,$tend)=split(/\./,$env{$envkey}); my $limit = $update; - if ($env{'request.role'} eq "$role./$roledom/") { + if ((($role eq 'dc') && ($env{'request.role'} eq 'dc./'.$roledom.'/')) || + (($role eq 'dh') && ($env{'request.role'} eq 'dh./'.$roledom.'/'))) { $limit = $then; } if ($tstart && $tstart>$limit) { $liverole = 0; } @@ -1822,20 +1806,17 @@ sub check_for_adhoc { $dcroles->{$roledom} = $envkey; $numdc++; } else { - $helpdeskroles->{$roledom} = $envkey; - my %domdefaults = &Apache::lonnet::get_domain_defaults($roledom); - if (ref($domdefaults{'adhocroles'}) eq 'HASH') { - if (keys(%{$domdefaults{'adhocroles'}})) { - $numadhoc ++; - } + $dhroles->{$roledom} = $envkey; + if ($env{'environment.adhocroles.'.$roledom} ne '') { + $numadhoc ++; } - $numhelpdesk++; + $numdh++; } } } } } - return ($numdc,$numhelpdesk,$numadhoc); + return ($numdc,$numdh,$numadhoc); } sub adhoc_course_role { @@ -1876,15 +1857,9 @@ sub adhoc_course_role { my %cgroups = &Apache::lonnet::get_active_groups($env{'user.domain'}, $env{'user.name'},$cdom,$cnum); - my $ccrole; - if ($crstype eq 'Community') { - $ccrole = 'co'; - } else { - $ccrole = 'cc'; - } foreach my $group (keys(%cgroups)) { $group_privs{$group} = - $env{'user.priv.'.$ccrole.'./'.$cdom.'/'.$cnum.'./'.$cdom.'/'.$cnum.'/'.$group}; + $env{'user.priv.cc./'.$cdom.'/'.$cnum.'./'.$cdom.'/'.$cnum.'/'.$group}; } $newgroups{'/'.$cdom.'/'.$cnum} = \%group_privs; my $area = '/'.$cdom.'/'.$cnum; @@ -2010,6 +1985,7 @@ sub display_cc_role { my $trolecode = $ccrole.'./'.$tdom.'/'.$trest; my $twhere; my $ttype; + my $skipcal; my $tbg='LC_roles_is'; my %newhash=&Apache::lonnet::coursedescription($tcourseid); if (%newhash) { @@ -2021,10 +1997,11 @@ sub display_cc_role { } else { $twhere=&mt('Currently not available'); $env{'course.'.$tcourseid.'.description'}=$twhere; + $skipcal = 1; } my $trole = &Apache::lonnet::plaintext($ccrole,$ttype,$tcourseid); $twhere.="
".&mt('Domain').":".$tdom; - ($roletext,$roletext_end) = &build_roletext($trolecode,$tdom,$trest,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,''); + ($roletext,$roletext_end) = &build_roletext($trolecode,$tdom,$trest,'is',$tryagain,$advanced,'',$tbg,$trole,$twhere,'','','',1,'','','',$skipcal); } } return ($roletext,$roletext_end); @@ -2034,9 +2011,9 @@ sub adhoc_roles_row { my ($dcdom,$rowtype) = @_; my $output = &Apache::loncommon::continue_data_table_row() .' ' - .&mt('[_1]Ad hoc[_2] roles in domain [_3]' + .&mt('[_1]Ad hoc[_2] roles in domain [_3] --' ,'','',$dcdom) - .' -- '; + .' '; my $role = 'cc'; my $selectcclink = &courselink($dcdom,$rowtype,$role); my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1); @@ -2049,25 +2026,20 @@ sub adhoc_roles_row { } sub adhoc_customroles_row { - my ($role,$dhdom,$rowtype,$update,$then) = @_; - my $liverole = 1; - my ($tstart,$tend)=split(/\./,$env{"user.role.$role./$dhdom/"}); - my $limit = $update; - if (($role eq 'dh') && ($env{'request.role'} eq 'dh./'.$dhdom.'/')) { - $limit = $then; - } - if ($tstart && $tstart>$limit) { $liverole = 0; } - if ($tend && $tend <$limit) { $liverole = 0; } - return unless ($liverole); - my %domdefaults = &Apache::lonnet::get_domain_defaults($dhdom); - if (ref($domdefaults{'adhocroles'}) eq 'HASH') { - if (scalar(keys(%{$domdefaults{'adhocroles'}})) > 0) { - return &Apache::loncommon::continue_data_table_row() - .' ' - .&mt('[_1]Ad hoc[_2] course/community roles in domain [_3]', - '','',$dhdom) - .' -- '.&courselink($dhdom,$rowtype,$role); - } + my ($dhdom,$rowtype) = @_; + my $output = &Apache::loncommon::continue_data_table_row() + .' ' + .&mt('[_1]Ad hoc[_2] course/community roles in domain [_3] --', + '','',$dhdom); + my @customroles = split(/,/,$env{'environment.adhocroles.'.$dhdom}); + my $count = 0; + foreach my $role (@customroles) { + next if (($role eq '') || ($role =~ /\W/)); + $output .= ' '.$role.': '.&courselink($dhdom,$rowtype,$role).' |'; + $count ++; + } + if ($count) { + return $output; } return; } @@ -2389,7 +2361,7 @@ sub update_session_roles { &curr_role_status($currstart,$currend,$refresh,$update); my ($rolekey) = ($envkey =~ /^user\.role\.(.+)$/); my ($role,$rest)=split(m{\./},$rolekey,2); - $rest = '/'.$rest; + $rest = '/'.$rest; if (&Apache::lonnet::delenv($envkey,undef,[$role])) { if ($status_in_env eq 'active') { if ($role eq 'gr') { @@ -2589,15 +2561,15 @@ sub update_session_roles { } my $groupdesc; unless (ref($curr_groups{$cdom.'_'.$cnum}) eq 'HASH') { - %{$curr_groups{$cdom.'_'.$cnum}} = + %{$curr_groups{$cdom.'_'.$cnum}} = &Apache::longroup::coursegroups($cdom,$cnum); } unless ((ref($groupdescs{$cdom.'_'.$cnum}) eq 'HASH') && ($groupdescs{$cdom.'_'.$cnum}{$group})) { - my %groupinfo = + my %groupinfo = &Apache::longroup::get_group_settings($curr_groups{$cdom.'_'.$cnum}{$group}); - $groupdescs{$cdom.'_'.$cnum}{$group} = + $groupdescs{$cdom.'_'.$cnum}{$group} = &unescape($groupinfo{'description'}); } $groupdesc = $groupdescs{$cdom.'_'.$cnum}{$group}; @@ -2716,7 +2688,7 @@ sub update_session_roles { my $cdom = $env{'course.'.$cid.'.domain'}; my $cnum = $env{'course.'.$cid.'.num'}; my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum); - my %groupdesc; + my %groupdesc; if (ref($groupchange{$crs}) eq 'HASH') { $groupchgmsg .= '
  • '.&mt('Course/Community: [_1]',''.$crsdesc.'