--- loncom/interface/lonrequestcourse.pm 2009/08/31 14:57:06 1.27 +++ loncom/interface/lonrequestcourse.pm 2009/09/05 20:24:15 1.28 @@ -1,7 +1,7 @@ # The LearningOnline Network # Request a course # -# $Id: lonrequestcourse.pm,v 1.27 2009/08/31 14:57:06 raeburn Exp $ +# $Id: lonrequestcourse.pm,v 1.28 2009/09/05 20:24:15 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -102,8 +102,6 @@ described at http://www.lon-capa.org. =item check_autolimit() -=item build_batchcreatehash() - =item retrieve_settings() =item get_request_settings() @@ -1264,14 +1262,13 @@ sub print_personnel_menu { $type = 'Community'; } foreach my $role (@roles) { - my $plrole=&Apache::lonnet::plaintext($role,$type); + my $plrole = &Apache::lonnet::plaintext($role,$type); $roleoptions .= ' '."\n"; } my %customroles=&Apache::lonuserutils::my_custom_roles(); if (keys(%customroles) > 0) { foreach my $cust (sort(keys(%customroles))) { - my $custrole='cr_cr_'.$env{'user.domain'}. - '_'.$env{'user.name'}.'_'.$cust; + my $custrole="cr/$env{'user.domain'}/$env{'user.name'}/$cust"; $roleoptions .= ' '."\n"; } } @@ -1778,13 +1775,13 @@ sub print_review { if ($env{'form.person_'.$i.'_role'} eq 'cc') { $showsec = &mt('None'); } + my $role = $env{'form.person_'.$i.'_role'}; $personnel_values .= ''.$env{'form.person_'.$i.'_firstname'}.' '. $env{'form.person_'.$i.'_lastname'}.''. ''.$env{'form.person_'.$i.'_uname'}.':'. $env{'form.person_'.$i.'_dom'}.''. - ''.&Apache::lonnet::plaintext($env{'form.person_'.$i.'_role'}, - $container).''. + ''.&Apache::lonnet::plaintext($role,$container).''. ''.$showsec.''; } } @@ -2324,9 +2321,10 @@ sub print_request_outcome { if ($result eq 'created') { $disposition = 'created'; $reqstatus = 'created'; - $output = &mt('Your course request has been processed and the course has been created.'). - '
'. - &mt('You will need to logout and log-in again to be able to select a role in the course.'); + my $role_result = &update_requestors_roles($dom,$cnum,$crstype,$details, + \%longroles); + $output = '

'.&mt('Your course request has been processed and the course has been created.'). + '
'.$role_result.'

'; $creationresult = 'created'; } else { $output = ''. @@ -2393,7 +2391,7 @@ sub print_request_outcome { $output .= ''.&mt('An error occurred saving a record of the details of your request: [_1].',$storeresult).'
'; &Apache::lonnet::logthis("Error saving course request - $requestkey for $env{'user.name'}:$env{'user.domain'} - $storeresult"); } elsif ($statusresult ne 'ok') { - $output .= ''.&mt('An error occurred saving a record of the status of your request: [_1].',$statusresult).'
'; + $output .= ''.&mt('An error occurred saving a record of the status of your request: [_1].',$statusresult).'
'; &Apache::lonnet::logthis("Error saving course request status for $requestkey (for $env{'user.name'}:$env{'user.domain'}) - $statusresult"); } if ($modified && $queued && $storeresult eq 'ok') { @@ -2411,6 +2409,113 @@ sub print_request_outcome { } } +sub update_requestors_roles { + my ($dom,$cnum,$crstype,$details,$longroles) = @_; + my $now = time; + my ($active,$future,$numactive,$numfuture,$output); + my $owner = $env{'user.name'}.':'.$env{'user.domain'}; + if (ref($details) eq 'HASH') { + if (ref($details->{'personnel'}) eq 'HASH') { + if (ref($details->{'personnel'}{$owner}) eq 'HASH') { + my @roles; + if (ref($details->{'personnel'}{$owner}{'roles'}) eq 'ARRAY') { + @roles = sort(@{$details->{'personnel'}{$owner}{'roles'}}); + unless (grep(/^cc$/,@roles)) { + push(@roles,'cc'); + } + } else { + @roles = ('cc'); + } + foreach my $role (@roles) { + my $start = $now; + my $end = '0'; + if ($role eq 'st') { + if ($details->{'accessstart'} ne '') { + $start = $details->{'accessstart'}; + } + if ($details->{'accessend'} ne '') { + $end = $details->{'accessend'}; + } + } + my @usecs; + if ($role ne 'cc') { + if (ref($details->{'personnel'}{$owner}{$role}{'usec'}) eq 'ARRAY') { + @usecs = @{$details->{'personnel'}{$owner}{$role}{'usec'}}; + } + } + if ($role eq 'st') { + if (@usecs > 1) { + my $firstsec = $usecs[0]; + @usecs = ($firstsec); + } + } + if (@usecs == 0) { + push(@usecs,''); + } + foreach my $usec (@usecs) { + my (%userroles,%newrole,%newgroups,$spec,$area); + my $area = '/'.$dom.'/'.$cnum; + my $spec = $role.'.'.$area; + if ($usec ne '') { + $spec .= '/'.$usec; + $area .= '/'.$usec; + } + if ($role =~ /^cr\//) { + &Apache::lonnet::custom_roleprivs(\%newrole,$role,$dom, + $cnum,$spec,$area); + } else { + &Apache::lonnet::standard_roleprivs(\%newrole,$role,$dom, + $spec,$cnum,$area); + } + &Apache::lonnet::set_userprivs(\%userroles,\%newrole, + \%newgroups); + $userroles{'user.role.'.$spec} = $start.'.'.$end; + &Apache::lonnet::appenv(\%userroles,[$role,'cm']); + if (($end == 0) || ($end > $now)) { + my $showrole = $role; + if ($role =~ /^cr\//) { + $showrole = &Apache::lonnet::plaintext($role,$crstype); + } elsif (ref($longroles) eq 'HASH') { + if ($longroles->{$role} ne '') { + $showrole = $longroles->{$role}; + } + } + if ($start <= $now) { + $active .= '
  • '.$showrole; + if ($usec ne '') { + $active .= ' - '.&mt('section:').' '.$usec; + } + $active .= '
  • '; + $numactive ++; + } else { + $future .= '
  • '.$showrole; + if ($usec ne '') { + $future .= ' - '.&mt('section:').' '.$usec; + } + $future .= '
  • '; + $numfuture ++; + } + } + } + } + } + } + } + if ($active) { + if ($numactive == 1) { + $output = &mt('Use the following link to enter the course:'); + } else { + $output = &mt('Use the following links to your new roles to enter the course:'); + } + $output .= '
    '; + } + if ($future) { + $output .= &mt('The following course [quant,_1,role] will become available for selection from your [_2]roles page[_3], once the default student access start date - [_4] - has been reached:',$numfuture,'','',&Apache::lonlocal::locallocaltime($details->{'accessstart'})). + ' '; + } + return $output; +} + sub notification_information { my ($disposition,$req_notifylist,$cnum,$now) = @_; my %emails = &Apache::loncommon::getemails();