--- loncom/auth/lonroles.pm 2015/06/09 21:22:44 1.312 +++ loncom/auth/lonroles.pm 2016/10/05 13:30:16 1.315 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.312 2015/06/09 21:22:44 damieng Exp $ +# $Id: lonroles.pm,v 1.315 2016/10/05 13:30:16 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -140,6 +140,7 @@ 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; @@ -263,8 +264,15 @@ sub handler { my $locknum=&Apache::lonnet::get_locks(); if ($locknum) { return 409; } + my $custom_adhoc; if ($env{'form.newrole'}) { $env{'form.'.$env{'form.newrole'}}=1; +# 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 (&Apache::lonnet::allowed('rar',$1)) { + $custom_adhoc = 1; + } + } } if ($env{'request.course.id'}) { # Check if user is CC trying to select a course role @@ -295,8 +303,26 @@ sub handler { "request.role" => 'cm', "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)$}) { + my $cdom = $1; + my $rolename = $2; + my $cnum = $3; + if ($custom_adhoc) { + 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)) { + &Apache::lonnet::appenv({"environment.internal.$cdom.$cnum.cr/$cdom/$cdom".'-domainconfig'."$rolename.adhoc" => time}); + } + } + } + } + } elsif ($numdc > 0) { # 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)) { # Is this an ad-hoc Coordinator role? if (my ($ccrole,$domain,$coursenum) = @@ -588,6 +614,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'}; @@ -704,6 +741,12 @@ ENDENTERKEY $redirect_url); return OK; } + if ($role eq 'dh') { + my $redirect_url = '/adm/menu/'; + &redirect_user($r,&mt('Loading Domain Helpdesk Menu'), + $redirect_url); + return OK; + } if ($role eq 'sc') { my $redirect_url = '/adm/grades?command=scantronupload'; &redirect_user($r,&mt('Loading Data Upload Page'), @@ -740,13 +783,45 @@ ENDENTERKEY my $showcount = &roles_from_env(\%roles_in_env,$update); my $swinfo=&Apache::lonmenu::rawconfig(); - my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum}); my %domdefs=&Apache::lonnet::get_domain_defaults($env{'user.domain'}); my $cattype = 'std'; if ($domdefs{'catauth'}) { $cattype = $domdefs{'catauth'}; } - my $funcs = &get_roles_functions($showcount,$cattype); + 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}); + } &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.').'

'; @@ -889,7 +964,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'},'"<>&'); @@ -942,6 +1031,16 @@ 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 @@ -1143,6 +1242,7 @@ sub gather_roles { $trole=Apache::lonnet::plaintext($role); my $ttype; my $twhere; + my $skipcal; my ($tdom,$trest,$tsection)= split(/\//,Apache::lonnet::declutter($where)); # First, Co-Authorship roles @@ -1232,8 +1332,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; } @@ -1250,7 +1354,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; @@ -1322,7 +1427,7 @@ sub roletable_headers { my $doheaders; if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) { $r->print('
' - .&Apache::loncommon::start_data_table() + .&Apache::loncommon::start_data_table('LC_textsize_mobile') .&Apache::loncommon::start_data_table_header_row() ); if (!$nochoose) { $r->print(' '); } @@ -1348,7 +1453,7 @@ 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; } @@ -1544,7 +1649,8 @@ 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 ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere, + $tpstart,$tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning,$skipcal) = @_; my ($roletext,$roletext_end); my $is_dc=($trolecode =~ m/^dc\./); my $rowspan=($is_dc) ? '' @@ -1600,7 +1706,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)); } @@ -1823,6 +1929,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) { @@ -1834,10 +1941,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); @@ -1846,7 +1954,7 @@ sub display_cc_role { sub adhoc_roles_row { my ($dcdom,$rowtype) = @_; my $output = &Apache::loncommon::continue_data_table_row() - .' ' + .' ' .&mt('[_1]Ad hoc[_2] roles in domain [_3] --' ,'','',$dcdom) .' '; @@ -2688,15 +2796,30 @@ sub get_roles_functions { unless ($cattype eq 'none') { push(@links,['/adm/coursecatalog','ccat-22x22',&mt('Course catalog')]); } - my $funcs = &Apache::lonhtmlcommon::start_funclist(); - foreach my $link (@links) { - $funcs .= &Apache::lonhtmlcommon::add_item_funclist( - ''. - ''.$link->[2].''. - $link->[2].''); + my $funcs; + if ($env{'browser.mobile'}) { + my @functions; + foreach my $link (@links) { + push(@functions,[$link->[0],$link->[2]]); + } + my $title = 'Display options'; + if ($env{'user.adv'}) { + $title = 'Roles options'; + } + $funcs = &Apache::lonmenu::create_submenu('','',$title,\@functions,1,'LC_breadcrumbs_hoverable'); + $funcs = '
    '.$funcs.'
'; + } else { + $funcs = &Apache::lonhtmlcommon::start_funclist(); + foreach my $link (@links) { + $funcs .= &Apache::lonhtmlcommon::add_item_funclist( + ''. + ''.$link->[2].''. + $link->[2].''); + } + $funcs .= &Apache::lonhtmlcommon::end_funclist(); + $funcs = &Apache::loncommon::head_subbox($funcs); } - $funcs .= &Apache::lonhtmlcommon::end_funclist(); - return &Apache::loncommon::head_subbox($funcs); + return $funcs; } sub get_queued {