version 1.123, 2017/01/02 19:44:06
|
version 1.125, 2017/01/05 16:17:11
|
Line 44 sub handler {
|
Line 44 sub handler {
|
if ($env{'form.context'} eq 'adhoc') { |
if ($env{'form.context'} eq 'adhoc') { |
&Apache::loncommon::content_type($r,'application/json'); |
&Apache::loncommon::content_type($r,'application/json'); |
$r->send_http_header; |
$r->send_http_header; |
my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($env{'form.cid'}); |
my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($env{'form.cid'},1); |
if ((ref($possroles) eq 'ARRAY') && (ref($description) eq 'HASH')) { |
if ((ref($possroles) eq 'ARRAY') && (ref($description) eq 'HASH')) { |
my $response = []; |
my $response = []; |
if (@{$possroles}) { |
if (@{$possroles}) { |
Line 440 sub display_matched_courses {
|
Line 440 sub display_matched_courses {
|
$action = '/adm/portfolio'; |
$action = '/adm/portfolio'; |
} |
} |
my $numcourses = keys(%courses); |
my $numcourses = keys(%courses); |
$r->print('<form name="courselist" method="post" action="'.$action.'">'); |
$r->print('<form name="courselist" method="post" action="'.$action.'" id="LCcoursepicker">'); |
if ($env{'form.form'} eq 'modifycourse') { |
if ($env{'form.form'} eq 'modifycourse') { |
if ($numcourses > 0) { |
if ($numcourses > 0) { |
my $ccrole = 'cc'; |
my $ccrole = 'cc'; |
Line 469 sub display_matched_courses {
|
Line 469 sub display_matched_courses {
|
$r->print(&mt('Enter the course with the role of [_1].',$cctitle)); |
$r->print(&mt('Enter the course with the role of [_1].',$cctitle)); |
} |
} |
} elsif (&Apache::lonnet::allowed('rar',$crsdom)) { |
} elsif (&Apache::lonnet::allowed('rar',$crsdom)) { |
my %adhocroles = &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'}, |
my ($roles_by_num,$description,$accessref,$accessinfo) = &Apache::lonnet::get_all_adhocroles($crsdom); |
'adhocroles.'.$crsdom); |
if ((ref($roles_by_num) eq 'ARRAY') && (ref($description) eq 'HASH')) { |
if ($adhocroles{'adhocroles.'.$crsdom} ne '') { |
if (@{$roles_by_num} > 1) { |
$possrole = 1; |
$r->print($roleradio); |
$r->print($roleradio); |
|
my @adhoc = split(/,/,$adhocroles{'adhocroles.'.$crsdom}); |
|
if (@adhoc > 1) { |
|
my %adhochash; |
|
map { $adhochash{$_} = $_; } @adhoc; |
|
my $selector = &Apache::loncommon::select_form($adhoc[0],'adhocrole',\%adhochash); |
|
if ($type eq 'Community') { |
if ($type eq 'Community') { |
$r->print(&mt('Enter the community with one of the available ad hoc roles: [_1].', |
$r->print(&mt('Enter the community with one of the available ad hoc roles.')); |
$selector)); |
|
} elsif ($type eq 'Placement') { |
} elsif ($type eq 'Placement') { |
$r->print(&mt('Enter the placement test with one of the available ad hoc roles: [_1].', |
$r->print(&mt('Enter the placement test with one of the available ad hoc roles.')); |
$selector)); |
|
} else { |
} else { |
$r->print(&mt('Enter the course with one of the available ad hoc roles: [_1].', |
$r->print(&mt('Enter the course with one of the available ad hoc roles.')); |
$selector)); |
|
} |
} |
} else { |
$possrole = 1; |
|
} elsif (@{$roles_by_num} == 1) { |
|
$r->print($roleradio); |
|
my $rolename = $description->{$roles_by_num->[0]}; |
if ($type eq 'Community') { |
if ($type eq 'Community') { |
$r->print(&mt('Enter the community with the ad hoc role of: [_1]',$adhoc[0])); |
$r->print(&mt('Enter the community with the ad hoc role of: [_1]',$rolename)); |
} elsif ($type eq 'Placement') { |
} elsif ($type eq 'Placement') { |
$r->print(&mt('Enter the placement test with the ad hoc role of: [_1]',$adhoc[0])); |
$r->print(&mt('Enter the placement test with the ad hoc role of: [_1]',$rolename)); |
} else { |
} else { |
$r->print(&mt('Enter the course with the ad hoc role of: [_1]',$adhoc[0])); |
$r->print(&mt('Enter the course with the ad hoc role of: [_1]',$rolename)); |
} |
} |
$r->print('<input type="hidden" name="adhocrole" value="'.$adhoc[0].'" />'); |
$possrole = 1; |
|
} |
|
if ($possrole) { |
|
$r->print('<input type="hidden" name="adhocrole" value="" />'); |
} |
} |
} |
} |
} |
} |
if ($possrole) { |
if ($possrole) { |
$r->print('</label></span><br />'); |
$r->print('</label></span><br />'); |
} |
} |
$r->print('<span class="LC_nobreak"><label>' |
$r->print('<span class="LC_nobreak"><label>' |
Line 766 sub display_matched_courses {
|
Line 763 sub display_matched_courses {
|
$r->print('<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />'); |
$r->print('<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />'); |
$r->print('<input type="hidden" name="action" value="rolepicker" />'); |
$r->print('<input type="hidden" name="action" value="rolepicker" />'); |
} elsif ($env{'form.form'} eq 'modifycourse') { |
} elsif ($env{'form.form'} eq 'modifycourse') { |
$r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','pickedcourse','type','form','numtitles','state'])); |
$r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','pickedcourse','type','form','numtitles','state','adhocrole'])); |
} else { |
} else { |
$r->print('<input type="hidden" name="cnumelement" value="'. |
$r->print('<input type="hidden" name="cnumelement" value="'. |
$env{'form.cnumelement'}.'" />'."\n". |
$env{'form.cnumelement'}.'" />'."\n". |
Line 872 sub gochoose_javascript {
|
Line 869 sub gochoose_javascript {
|
my $output; |
my $output; |
if ($rolechooser) { |
if ($rolechooser) { |
$output .= qq| |
$output .= qq| |
\$( "#LC_adhocrole_chooser" ).dialog({ autoOpen: false }); |
\$(document).ready(function(){ |
|
\$( "#LC_adhocrole_chooser" ).dialog({ autoOpen: false }); |
|
}); |
|; |
|; |
} |
} |
$output .= qq| |
$output .= qq| |
Line 1030 ENDJS
|
Line 1029 ENDJS
|
return $rolechooser.&Apache::lonhtmlcommon::scripttag($output); |
return $rolechooser.&Apache::lonhtmlcommon::scripttag($output); |
} |
} |
|
|
sub get_my_adhocroles { |
|
my (@okroles,%description); |
|
if ($env{'form.cid'} =~ /^($match_domain)_($match_courseid)$/) { |
|
my $cdom = $1; |
|
my $cnum = $2; |
|
if ($env{"user.role.dh./$cdom/"}) { |
|
my $then=$env{'user.login.time'}; |
|
my $update=$env{'user.update.time'}; |
|
my $liverole = 1; |
|
my ($tstart,$tend)=split(/\./,$env{'user.role.dh./'.$cdom}); |
|
my $limit = $update; |
|
if ($env{'request.role'} eq 'dh./'.$cdom.'/') { |
|
$limit = $then; |
|
} |
|
if ($tstart && $tstart>$limit) { $liverole = 0; } |
|
if ($tend && $tend <$limit) { $liverole = 0; } |
|
if ($liverole) { |
|
if (&Apache::lonnet::homeserver($cnum,$cdom) ne 'no_host') { |
|
my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom); |
|
if (ref($domdefaults{'adhocroles'}) eq 'HASH') { |
|
my $count = 0; |
|
my %domcurrent = %{$domdefaults{'adhocroles'}}; |
|
my (%ordered,%access_in_dom); |
|
foreach my $role (sort(keys(%{$domdefaults{'adhocroles'}}))) { |
|
my ($order,$desc,$access_in_dom); |
|
if (ref($domcurrent{$role}) eq 'HASH') { |
|
$order = $domcurrent{$role}{'order'}; |
|
$desc = $domcurrent{$role}{'desc'}; |
|
$access_in_dom{$role} = $domcurrent{$role}{'access'}; |
|
} |
|
if ($order eq '') { |
|
$order = $count; |
|
} |
|
$ordered{$order} = $role; |
|
if ($desc ne '') { |
|
$description{$role} = $desc; |
|
} else { |
|
$description{$role}= $role; |
|
} |
|
$count++; |
|
} |
|
my @roles_by_num = (); |
|
foreach my $item (sort {$a <=> $b } (keys(%ordered))) { |
|
push(@roles_by_num,$ordered{$item}); |
|
} |
|
if (@roles_by_num) { |
|
my %settings = &Apache::lonnet::dump('environment',$cdom,$cnum,'internal\.adhoc'); |
|
my %setincrs; |
|
if ($settings{'internal.adhocaccess'}) { |
|
map { $setincrs{$_} = 1; } split(/,/,$settings{'internal.adhocaccess'}); |
|
} |
|
my @statuses; |
|
if ($env{'environment.inststatus'}) { |
|
@statuses = split(/,/,$env{'environment.inststatus'}); |
|
} |
|
my $user = $env{'user.name'}.':'.$env{'user.domain'}; |
|
foreach my $role (@roles_by_num) { |
|
my ($curraccess,@okstatus,@personnel); |
|
if ($setincrs{$role}) { |
|
($curraccess,my $rest) = split(/=/,$settings{'internal.adhoc.'.$role}); |
|
if ($curraccess eq 'none') { |
|
next; |
|
} elsif ($curraccess eq 'all') { |
|
push(@okroles,$role); |
|
} elsif ($curraccess eq 'status') { |
|
@okstatus = split(/\&/,$rest); |
|
} elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) { |
|
@personnel = split(/\&/,$rest); |
|
} |
|
} else { |
|
$curraccess = $access_in_dom{$role}; |
|
if ($curraccess eq 'status') { |
|
if (ref($domcurrent{$role}{$curraccess}) eq 'ARRAY') { |
|
@okstatus = @{$domcurrent{$role}{$curraccess}}; |
|
} |
|
} elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) { |
|
if (ref($domcurrent{$role}{$curraccess}) eq 'ARRAY') { |
|
@personnel = @{$domcurrent{$role}{$curraccess}}; |
|
} |
|
} |
|
} |
|
if ($curraccess eq 'none') { |
|
next; |
|
} elsif ($curraccess eq 'all') { |
|
push(@okroles,$role); |
|
} elsif ($curraccess eq 'status') { |
|
if (@okstatus) { |
|
if (!@statuses) { |
|
if (grep(/^default$/,@okstatus)) { |
|
push(@okroles,$role); |
|
} |
|
} else { |
|
foreach my $status (@okstatus) { |
|
if (grep(/^\Q$status\E$/,@statuses)) { |
|
push(@okroles,$role); |
|
last; |
|
} |
|
} |
|
} |
|
} |
|
} elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) { |
|
if (grep(/^\Q$user\E$/,@personnel)) { |
|
if ($curraccess eq 'exc') { |
|
push(@okroles,$role); |
|
} |
|
} elsif ($curraccess eq 'inc') { |
|
push(@okroles,$role); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
my $response = []; |
|
if (@okroles) { |
|
foreach my $role (@okroles) { |
|
push(@{$response}, |
|
{ name => $role, |
|
desc => $description{$role}, |
|
}); |
|
} |
|
} |
|
my $json = JSON::DWIW->to_json({roles => $response}); |
|
return $json; |
|
} |
|
|
|
1; |
1; |
__END__ |
__END__ |
|
|