--- loncom/auth/lonroles.pm 2016/04/02 04:31:33 1.313 +++ loncom/auth/lonroles.pm 2016/10/19 13:12:58 1.317 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.313 2016/04/02 04:31:33 raeburn Exp $ +# $Id: lonroles.pm,v 1.317 2016/10/19 13:12:58 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -255,7 +255,8 @@ sub handler { my $envkey; my %dcroles = (); - my $numdc = &check_fordc(\%dcroles,$update,$then); + my %dhroles = (); + my ($numdc,$numdh,$numadhoc) = &check_for_adhoc(\%dcroles,\%dhroles,$update,$then); my $loncaparev = $r->dir_config('lonVersion'); # ================================================================== Roles Init @@ -264,8 +265,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 ($dhroles{$1}) { + $custom_adhoc = 1; + } + } } if ($env{'request.course.id'}) { # Check if user is CC trying to select a course role @@ -296,8 +304,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) = @@ -716,6 +742,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'), @@ -782,8 +814,14 @@ ENDENTERKEY $start_page=&Apache::loncommon::start_page($pagetitle,undef, {bread_crumbs=>$brcrum,crstype=>'Placement'}); } else { - $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum}); $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.').'

'; @@ -1007,7 +1045,7 @@ ENDHEADER } # ----------------------------------------------------------------------- Table - if ($numdc > 0) { + if (($numdc > 0) || (($numdh > 0) && ($numadhoc > 0))) { $r->print(&coursepick_jscript()); $r->print(&Apache::loncommon::coursebrowser_javascript(). &Apache::loncommon::authorbrowser_javascript()); @@ -1040,9 +1078,12 @@ ENDHEADER $roletext{'user.role.'.$role}->[1]. &Apache::loncommon::end_data_table_row(); } - if ($role =~ m{dc\./($match_domain)/} + if ($role =~ m{^user\.role\.dc\./($match_domain)/} && $dcroles{$1}) { $output .= &adhoc_roles_row($1,'recent'); + } elsif ($role =~ m{^user\.role\.dh\./($match_domain)/} + && ($env{'environment.adhocroles.'.$1} ne '')) { + $output .= &adhoc_customroles_row($1,'recent'); } } elsif ($numdc > 0) { unless ($role =~/^error\:/) { @@ -1390,7 +1431,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(' '); } @@ -1439,12 +1480,15 @@ sub print_rolerows { &Apache::loncommon::end_data_table_row(); } } - if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) { + 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\./($match_domain)/}) && + ($env{'environment.adhocroles.'.$1} ne '')) { + $output .= &adhoc_customroles_row($1,''); } } } @@ -1702,29 +1746,42 @@ sub check_author_homeserver { } } -sub check_fordc { - my ($dcroles,$update,$then) = @_; +sub check_for_adhoc { + my ($dcroles,$dhroles,$update,$then) = @_; my $numdc = 0; + my $numdh = 0; + my $numadhoc = 0; + my $num_custom_adhoc = 0; if ($env{'user.adv'}) { foreach my $envkey (sort(keys(%env))) { - if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) { - my $dcdom = $1; - my $livedc = 1; + 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 'dc./'.$dcdom.'/') { + 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) { $livedc = 0; } - if ($tend && $tend <$limit) { $livedc = 0; } - if ($livedc) { - $$dcroles{$dcdom} = $envkey; - $numdc++; + if ($tstart && $tstart>$limit) { $liverole = 0; } + if ($tend && $tend <$limit) { $liverole = 0; } + if ($liverole) { + if ($role eq 'dc') { + $dcroles->{$roledom} = $envkey; + $numdc++; + } else { + $dhroles->{$roledom} = $envkey; + if ($env{'environment.adhocroles.'.$roledom} ne '') { + $numadhoc ++; + } + $numdh++; + } } } } } - return $numdc; + return ($numdc,$numdh,$numadhoc); } sub adhoc_course_role { @@ -1816,15 +1873,16 @@ sub check_forcc { } sub courselink { - my ($dcdom,$rowtype) = @_; + my ($roledom,$rowtype,$role) = @_; my $courseform=&Apache::loncommon::selectcourse_link - ('rolechoice','dccourse'.$rowtype.'_'.$dcdom, - 'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'. - $dcdom,$dcdom,undef,'Course/Community'); - my $hiddenitems = ''. - ''. - ''. - ''; + ('rolechoice','course'.$rowtype.'_'.$roledom.'_'.$role, + 'domain'.$rowtype.'_'.$roledom.'_'.$role, + 'coursedesc'.$rowtype.'_'.$roledom.'_'.$role, + $roledom.':'.$role,undef,'Course/Community'); + my $hiddenitems = ''. + ''. + ''. + ''; return $courseform.$hiddenitems; } @@ -1917,11 +1975,12 @@ 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) .' '; - my $selectcclink = &courselink($dcdom,$rowtype); + my $role = 'cc'; + my $selectcclink = &courselink($dcdom,$rowtype,$role); my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1); my $carole = &Apache::lonnet::plaintext('ca'); my $selectcalink = &coauthorlink($dcdom,$rowtype); @@ -1931,6 +1990,25 @@ sub adhoc_roles_row { return $output; } +sub adhoc_customroles_row { + 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; +} + sub recent_filename { my $area=shift; return 'nohist_recent_'.&escape($area); @@ -2759,15 +2837,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 {