';
if ($context eq 'crosslist') {
$output .= ''.&mt('Include?').' '.
@@ -2395,7 +2919,7 @@ sub get_course_dom {
}
}
if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
- my ($types,$typename) = &course_types();
+ my ($types,$typename) = &Apache::loncommon::course_types();
if (ref($types) eq 'ARRAY') {
foreach my $type (@{$types}) {
if (&Apache::lonnet::usertools_access($env{'user.name'},
@@ -2498,6 +3022,10 @@ sub print_request_outcome {
}
$now = time;
$crstype = $env{'form.crstype'};
+ my $ccrole = 'cc';
+ if ($crstype eq 'community') {
+ $ccrole = 'co';
+ }
my @instsections;
if ($crstype eq 'official') {
if (&Apache::lonnet::auto_run('',$dom)) {
@@ -2559,7 +3087,7 @@ sub print_request_outcome {
} else {
@{$personnel{$uname.':'.$udom}{'roles'}} = ($role);
}
- if ($role eq 'cc') {
+ if ($role eq $ccrole) {
@{$personnel{$uname.':'.$udom}{$role}{'usec'}} = ();
} else {
my @currsec = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
@@ -2611,14 +3139,16 @@ sub print_request_outcome {
}
my $clonecrs = '';
my $clonedom = '';
- if (($env{'form.clonecrs'} =~ /^($match_courseid)$/) &&
+ if (($env{'form.cloning'}) &&
+ ($env{'form.clonecrs'} =~ /^($match_courseid)$/) &&
($env{'form.clonedom'} =~ /^($match_domain)$/)) {
my $clonehome = &Apache::lonnet::homeserver($env{'form.clonecrs'},
$env{'form.clonedom'});
if ($clonehome ne 'no_host') {
my $canclone =
&Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
- $env{'user.domain'},$env{'form.clonecrs'}, $env{'form.clonedom'});
+ $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'},
+ $crstype);
if ($canclone) {
$clonecrs = $env{'form.clonecrs'};
$clonedom = $env{'form.clonedom'};
@@ -2651,7 +3181,9 @@ sub print_request_outcome {
personnel => \%personnel,
};
my (@inststatuses,$storeresult,$creationresult);
- my $val = &get_processtype($dom,$crstype,\@inststatuses,\%domconfig);
+ my $val =
+ &Apache::loncoursequeueadmin::get_processtype($env{'user.name'},$env{'user.domain'},
+ $env{'user.adv'},$dom,$crstype,\@inststatuses,\%domconfig);
if ($val eq '') {
if ($crstype eq 'official') {
$output = &mt('You are not permitted to request creation of official courses.');
@@ -2709,7 +3241,11 @@ sub print_request_outcome {
$reqstatus = $disposition;
my ($modified,$queued);
if ($disposition eq 'rejected') {
- $output = &mt('Your course request was rejected.');
+ if ($crstype eq 'community') {
+ $output = &mt('Your community request was rejected.');
+ } else {
+ $output = &mt('Your course request was rejected.');
+ }
if ($message) {
$output .= ''.$message.' ';
}
@@ -2717,11 +3253,11 @@ sub print_request_outcome {
} elsif ($disposition eq 'process') {
my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles);
- my @roles = &Apache::lonuserutils::roles_by_context('course');
my $type = 'Course';
if ($crstype eq 'community') {
$type = 'Community';
}
+ my @roles = &Apache::lonuserutils::roles_by_context('course','',$type);
foreach my $role (@roles) {
$longroles{$role}=&Apache::lonnet::plaintext($role,$type);
}
@@ -2733,14 +3269,22 @@ sub print_request_outcome {
$reqstatus = 'created';
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.' ';
+ if ($crstype eq 'community') {
+ $output = ''.&mt('Your community request has been processed and the community has been created.');
+ } else {
+ $output = ' '.&mt('Your course request has been processed and the course has been created.');
+ }
+ $output .= ' '.$role_result.' ';
$creationresult = 'created';
} else {
- $output = ''.
- &mt('An error occurred when processing your course request.').
- ' '.
- &mt('You may want to review the request details and submit the request again.').
+ $output = '';
+ if ($crstype eq 'community') {
+ $output .= &mt('An error occurred when processing your community request.');
+ } else {
+ $output .= &mt('An error occurred when processing your course request.');
+ }
+ $output .= ' '.
+ &mt('You may want to review the request details and submit the request again.').
'';
$creationresult = 'error';
}
@@ -2755,6 +3299,9 @@ sub print_request_outcome {
description => $env{'form.cdescr'},
},
};
+ if ($crstype eq 'official') {
+ $request->{$requestid}->{'instcode'} = $instcode;
+ }
my $statuskey = 'status:'.$dom.':'.$cnum;
my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
$env{'user.domain'},$env{'user.name'});
@@ -2773,7 +3320,12 @@ sub print_request_outcome {
my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,
$dom);
if ($putresult eq 'ok') {
- $output = &mt('Your course request has been recorded.').' '.
+ if ($crstype eq 'community') {
+ $output .= &mt('Your community request has been recorded.');
+ } else {
+ $output .= &mt('Your course request has been recorded.')
+ }
+ $output .= ' '.
¬ification_information($disposition,$req_notifylist,
$cnum,$now);
} else {
@@ -2784,32 +3336,22 @@ sub print_request_outcome {
}
}
}
- my ($statusresult);
- if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
- $storeresult = &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
- 'courserequests');
- if ($storeresult eq 'ok') {
- my %status = (
- 'status:'.$dom.':'.$cnum => $reqstatus,
- );
- $statusresult = &Apache::lonnet::put('courserequests',\%status);
- }
- } else {
- $storeresult = 'error: invalid requestkey format';
- }
- if ($storeresult ne 'ok') {
- $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).' ';
- &Apache::lonnet::logthis("Error saving course request status for $requestkey (for $env{'user.name'}:$env{'user.domain'}) - $statusresult");
- }
+ ($storeresult,my $updateresult) =
+ &Apache::loncoursequeueadmin::update_coursereq_status(\%reqhash,$dom,
+ $cnum,$reqstatus,'request');
if ($modified && $queued && $storeresult eq 'ok') {
- $output .= ''.&mt('Your course request has been updated').' '.
- ¬ification_information($disposition,$req_notifylist,$cnum,$now);
+ if ($crstype eq 'community') {
+ $output .= ''.&mt('Your community request has been updated').' ';
+ } else {
+ $output .= ''.&mt('Your course request has been updated').' ';
+ }
+ $output .= ¬ification_information($disposition,$req_notifylist,$cnum,$now);
}
if ($validationerror ne '') {
- $output .= ''.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'';
+ $output .= ''.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).' ';
+ }
+ if ($updateresult) {
+ $output .= $updateresult;
}
}
if ($creationresult ne '') {
@@ -2826,85 +3368,101 @@ sub update_requestors_roles {
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');
+ my $ccrole = 'cc';
+ if ($crstype eq 'community') {
+ $ccrole = 'co';
+ }
+ unless (ref($details->{'personnel'}{$owner}) eq 'HASH') {
+ $details->{'personnel'}{$owner} = {
+ 'roles' => [$ccrole],
+ $ccrole => { 'usec' => [] },
+ };
+ }
+ my @roles;
+ if (ref($details->{'personnel'}{$owner}{'roles'}) eq 'ARRAY') {
+ @roles = sort(@{$details->{'personnel'}{$owner}{'roles'}});
+ unless (grep(/^\Q$ccrole\E$/,@roles)) {
+ push(@roles,$ccrole);
}
- 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;
- }
+ } else {
+ @roles = ($ccrole);
+ }
+ foreach my $role (@roles) {
+ my $refresh=$env{'user.refresh.time'};
+ if ($refresh eq '') {
+ $refresh = $env{'user.login.time'};
+ }
+ if ($refresh eq '') {
+ $refresh = $now;
+ }
+ my $start = $refresh-1;
+ 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 $ccrole) {
+ 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\//) {
- &Apache::lonnet::custom_roleprivs(\%newrole,$role,$dom,
- $cnum,$spec,$area);
- } else {
- &Apache::lonnet::standard_roleprivs(\%newrole,$role,$dom,
- $spec,$cnum,$area);
+ $showrole = &Apache::lonnet::plaintext($role,$crstype);
+ } elsif (ref($longroles) eq 'HASH') {
+ if ($longroles->{$role} ne '') {
+ $showrole = $longroles->{$role};
+ }
}
- &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;
}
- 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 ++;
+ $active .= '';
+ $numactive ++;
+ } else {
+ $future .= ''.$showrole;
+ if ($usec ne '') {
+ $future .= ' - '.&mt('section:').' '.$usec;
}
+ $future .= '';
+ $numfuture ++;
}
}
}
@@ -2913,15 +3471,27 @@ sub update_requestors_roles {
}
if ($active) {
if ($numactive == 1) {
- $output = &mt('Use the following link to enter the course:');
+ if ($crstype eq 'Community') {
+ $output = &mt('Use the following link to enter the community:');
+ } else {
+ $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:');
+ if ($crstype eq 'Community') {
+ $output = &mt('Use the following links to your new roles to enter the community:');
+ } 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'})).
- ' ';
+ if ($crstype eq 'Community') {
+ $output .= &mt('The following community [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'}))
+ } else {
+ $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'}));
+ }
+ $output .= ' ';
}
return $output;
}
@@ -2957,128 +3527,43 @@ sub notification_information {
'';
} else {
$output .= ''.
- &mt('Your request status is: [_1].',$disposition).
- ' '
+ &mt('Your request status is: [_1].',$disposition).
+ '';
}
return $output;
}
-sub get_processtype {
- my ($dom,$crstype,$inststatuses,$domconfig) = @_;
- return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
- my (%userenv,%settings,$val);
- my @options = ('autolimit','validate','approval');
- if ($dom eq $env{'user.domain'}) {
- %userenv =
- &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
- 'requestcourses.'.$crstype,'inststatus');
- if ($userenv{'requestcourses.'.$crstype}) {
- $val = $userenv{'requestcourses.'.$crstype};
- @{$inststatuses} = ('_custom_');
- } else {
- my ($task,%alltasks);
- if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
- %settings = %{$domconfig->{'requestcourses'}};
- if (ref($settings{$crstype}) eq 'HASH') {
- if (($env{'user.adv'}) && ($settings{$crstype}{'_LC_adv'} ne '')) {
- $val = $settings{$crstype}{'_LC_adv'};
- @{$inststatuses} = ('_LC_adv_');
- } else {
- if ($userenv{'inststatus'} ne '') {
- @{$inststatuses} = split(',',$userenv{'inststatus'});
- } else {
- @{$inststatuses} = ('default');
- }
- foreach my $status (@{$inststatuses}) {
- if (exists($settings{$crstype}{$status})) {
- my $value = $settings{$crstype}{$status};
- next unless ($value);
- unless (exists($alltasks{$value})) {
- if (ref($alltasks{$value}) eq 'ARRAY') {
- unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
- push(@{$alltasks{$value}},$status);
- }
- } else {
- @{$alltasks{$value}} = ($status);
- }
- }
- }
- }
- my $maxlimit = 0;
-
- foreach my $key (sort(keys(%alltasks))) {
- if ($key =~ /^autolimit=(\d*)$/) {
- if ($1 eq '') {
- $val ='autolimit=';
- last;
- } elsif ($1 > $maxlimit) {
- $maxlimit = $1;
- }
- }
- }
- if ($maxlimit) {
- $val = 'autolimit='.$maxlimit;
- } else {
- foreach my $option (@options) {
- if ($alltasks{$option}) {
- $val = $option;
- last;
- }
- }
- }
- }
- }
- }
- }
- } else {
- %userenv = &Apache::lonnet::userenvironment($env{'user.domain'},
- $env{'user.name'},'reqcrsotherdom.'.$env{'form.crstype'});
- if ($userenv{'reqcrsotherdom.'.$crstype}) {
- my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype});
- my $optregex = join('|',@options);
- foreach my $item (@doms) {
- my ($extdom,$extopt) = split(':',$item);
- if ($extdom eq $dom) {
- if ($extopt =~ /^($optregex)(=?\d*)$/) {
- $val = $1.$2;
- }
- last;
- }
- }
- @{$inststatuses} = ('_external_');
- }
- }
- return $val;
-}
-
sub check_autolimit {
my ($uname,$udom,$dom,$crstype,$limit,$message) = @_;
my %crsroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},
- 'userroles',['active','future'],['cc'],[$dom]);
- my ($types,$typename) = &course_types();
+ 'userroles',['active','future'],['cc','co'],[$dom]);
+ my ($types,$typename) = &Apache::loncommon::course_types();
my %requests = &Apache::lonnet::dumpstore('courserequests',$udom,$uname);
- my %count;
- if (ref($types) eq 'ARRAY') {
- foreach my $type (@{$types}) {
- $count{$type} = 0;
- }
- }
+ my $count = 0;
foreach my $key (keys(%requests)) {
my ($cdom,$cnum) = split('_',$key);
- if (exists($crsroles{$cnum.':'.$cdom.':cc'})) {
- if (ref($requests{$key}) eq 'HASH') {
- my $type = $requests{$key}{'crstype'};
- if ($type =~ /^official|unofficial|community$/) {
- $count{$type} ++;
- }
+ if (ref($requests{$key}) eq 'HASH') {
+ next if ($requests{$key}{'crstype'} ne $crstype);
+ if (($crstype eq 'community') &&
+ (exists($crsroles{$cnum.':'.$cdom.':co'}))) {
+ $count ++;
+ } elsif ((($crstype eq 'official') || ($crstype eq 'unofficial')) &&
+ (exists($crsroles{$cnum.':'.$cdom.':cc'}))) {
+ $count ++;
}
}
}
- if ($count{$crstype} < $limit) {
+ if ($count < $limit) {
return 'process';
} else {
if (ref($typename) eq 'HASH') {
- $$message = &mt('Your request has not been processed because you have reached the limit for the number of courses of this type.').' '.&mt("Your $typename->{$crstype} limit is [_1].",$limit);
+ if ($crstype eq 'community') {
+ $$message = &mt('Your request has not been processed because you have reached the limit for the number of communities.').
+ ' '.&mt("Your limit is [_1].",$limit);
+ } else {
+ $$message = &mt('Your request has not been processed because you have reached the limit for the number of courses of this type.').
+ ' '.&mt("Your $typename->{$crstype} limit is [_1].",$limit);
+ }
}
return 'rejected';
}
|