';
if ($context eq 'crosslist') {
$output .= ''.&mt('Include?').' '.
@@ -2370,6 +3265,26 @@ sub coursecode_form {
return $output;
}
+sub sections_form {
+ my ($dom,$instcode,$num) = @_;
+ my $rowtitle;
+ if ($instcode eq '') {
+ $rowtitle = &mt('Sections');
+ } else {
+ $rowtitle = &mt('Sections of [_1]',$instcode);
+ }
+ return &Apache::lonhtmlcommon::row_title($rowtitle).
+ ''.
+ &Apache::lonhtmlcommon::row_closure(1);
+}
+
sub get_course_dom {
my $codedom = &Apache::lonnet::default_login_domain();
if ($env{'form.showdom'} ne '') {
@@ -2462,9 +3377,10 @@ sub display_navbuttons {
}
sub print_request_outcome {
- my ($dom,$codetitles,$code_order) = @_;
+ my ($r,$lonhost,$dom,$codetitles,$code_order,$instcredits) = @_;
my ($output,$cnum,$now,$req_notifylist,$crstype,$enrollstart,$enrollend,
- %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,);
+ %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,
+ $uniquecode);
my $sectotal = $env{'form.sectotal'};
my $crosslisttotal = 0;
$cnum = $env{'form.cnum'};
@@ -2472,15 +3388,21 @@ sub print_request_outcome {
$output = &mt('Invalid LON-CAPA course number for the new course')."\n";
return $output;
}
-
- %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
+ $crstype = $env{'form.crstype'};
+ my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
if (ref($domconfig{'requestcourses'}) eq 'HASH') {
if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
$req_notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
}
+ if (ref($domconfig{'requestcourses'}{'uniquecode'}) eq 'HASH') {
+ $uniquecode = $domconfig{'requestcourses'}{'uniquecode'}{$crstype};
+ }
}
$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)) {
@@ -2495,6 +3417,10 @@ sub print_request_outcome {
push(@instsections,$sec);
}
$sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i};
+ $sections{$i}{'loncapa'} =~ s/\W//g;
+ if ($sections{$i}{'loncapa'} eq 'none') {
+ $sections{$i}{'loncapa'} = '';
+ }
}
}
}
@@ -2520,6 +3446,7 @@ sub print_request_outcome {
$enrollstart = '';
$enrollend = '';
}
+ my (%alerts,%rulematch,%inst_results,%curr_rules,%got_rules,%disallowmsg,%skipped);
for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
my $uname = $env{'form.person_'.$i.'_uname'};
my $udom = $env{'form.person_'.$i.'_dom'};
@@ -2531,6 +3458,56 @@ sub print_request_outcome {
lastname => $env{'form.person_'.$i.'_lastname'},
emailaddr => $env{'form.person_'.$i.'_emailaddr'},
};
+ if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
+ my $usertype = &get_usertype($udom,$uname,\%curr_rules,\%got_rules);
+ if (&Apache::lonuserutils::can_create_user($udom,'requestcrs',$usertype)) {
+ my ($allowed,$msg,$authtype,$authparam) =
+ &check_newuser_rules($udom,$uname,\%alerts,\%rulematch,
+ \%inst_results,\%curr_rules,\%got_rules);
+ if ($allowed) {
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($udom);
+ if ($usertype eq 'official') {
+ if ($authtype eq '') {
+ $authtype = $domdefaults{'auth_def'};
+ $authparam = $domdefaults{'auth_arg_def'};
+ } else {
+ if ($authtype eq 'loc') {
+ $authtype = 'localauth';
+ } elsif ($authtype eq 'int') {
+ $authtype = 'internal';
+ }
+ if ($authtype !~ /^(krb4|krb5|internal|localauth)$/) {
+ $authtype = $domdefaults{'auth_def'};
+ $authparam = $domdefaults{'auth_arg_def'};
+ }
+ }
+ } elsif ($usertype eq 'unofficial') {
+ if ($authtype eq '') {
+ $authtype = 'internal';
+ $authparam = '';
+ }
+ } else {
+ $authtype = $domdefaults{'auth_def'};
+ $authparam = $domdefaults{'auth_arg_def'};
+ }
+ if (($authtype eq '') ||
+ (($authtype =~/^krb(4|5)$/) && ($authparam eq '')) ||
+ ($authtype !~ /^(krb4|krb5|internal|localauth)$/)) {
+ $skipped{$uname.':'.$udom} = 1;
+ next;
+ } else {
+ $personnel{$uname.':'.$udom}{'authtype'} = $authtype;
+ $personnel{$uname.':'.$udom}{'autharg'} = $authparam;
+ }
+ } else {
+ $skipped{$uname.':'.$udom} = 1;
+ next;
+ }
+ } else {
+ $skipped{$uname.':'.$udom} = 1;
+ next;
+ }
+ }
}
my $role = $env{'form.person_'.$i.'_role'};
unless ($role eq '') {
@@ -2542,7 +3519,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');
@@ -2576,6 +3553,11 @@ sub print_request_outcome {
push(@baduname,$uname.':'.$udom);
}
}
+ if (keys(%skipped)) {
+ foreach my $key (keys(%skipped)) {
+ delete($personnel{$key});
+ }
+ }
my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
my $autodrops = 0;
if ($env{'form.autodrops'}) {
@@ -2583,25 +3565,30 @@ sub print_request_outcome {
}
my $autoadds = 0;
if ($env{'form.autoadds'}) {
- $autodrops = $env{'form.autoadds'};
- }
- if ($env{'form.autoadds'}) {
- $autodrops = $env{'form.autoadds'};
+ $autoadds = $env{'form.autoadds'};
}
my $instcode = '';
if (exists($env{'form.instcode'})) {
$instcode = $env{'form.instcode'};
}
+ my $credits;
+ if ($instcredits) {
+ $credits = $instcredits;
+ } elsif (exists($env{'form.coursecredits'})) {
+ $credits = $env{'form.coursecredits'};
+ }
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'};
@@ -2617,6 +3604,8 @@ sub print_request_outcome {
cdescr => $env{'form.cdescr'},
crstype => $env{'form.crstype'},
instcode => $instcode,
+ defaultcredits => $credits,
+ uniquecode => $uniquecode,
clonedom => $clonedom,
clonecrs => $clonecrs,
datemode => $env{'form.datemode'},
@@ -2633,8 +3622,19 @@ sub print_request_outcome {
accessend => $accessend,
personnel => \%personnel,
};
- my (@inststatuses,$storeresult,$creationresult);
- my $val = &get_processtype($dom,$crstype,\@inststatuses,\%domconfig);
+ my ($result,$output) = &process_request($r,$lonhost,$dom,$cnum,$crstype,$now,$details,$instcode,
+ $req_notifylist,\@instsections,\%domconfig);
+ return ($result,$output);
+}
+
+sub process_request {
+ my ($r,$lonhost,$dom,$cnum,$crstype,$now,$details,$instcode,$req_notifylist,$instsections,
+ $domconfig) = @_;
+ my (@inststatuses,$storeresult,$creationresult,$output);
+ my $val =
+ &Apache::loncoursequeueadmin::get_processtype('course',$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.');
@@ -2642,12 +3642,14 @@ sub print_request_outcome {
$output = &mt('You are not permitted to request creation of unofficial courses.');
} elsif ($crstype eq 'community') {
$output = &mt('You are not permitted to request creation of communities');
+ } elsif ($crstype eq 'textbook') {
+ $output = &mt('You are not permitted to request creation of textbook courses');
} else {
$output = &mt('Unrecognized course type: [_1]',$crstype);
}
$storeresult = 'notpermitted';
} else {
- my ($disposition,$message,$reqstatus);
+ my ($disposition,$message,$reqstatus,$coursedesc);
my %reqhash = (
reqtime => $now,
crstype => $crstype,
@@ -2655,6 +3657,11 @@ sub print_request_outcome {
);
my $requestkey = $dom.'_'.$cnum;
my $validationerror;
+ my $fullname = &Apache::loncommon::plainname($env{'user.name'},
+ $env{'user.domain'});
+ if (ref($details) eq 'HASH') {
+ $coursedesc = $details->{'cdescr'};
+ }
if ($val eq 'autolimit=') {
$disposition = 'process';
} elsif ($val =~ /^autolimit=(\d+)$/) {
@@ -2662,18 +3669,37 @@ sub print_request_outcome {
$disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
$dom,$crstype,$limit,\$message);
} elsif ($val eq 'validate') {
- my ($inststatuslist,$validationchk,$validation);
+ my ($inststatuslist,$validationchk,$validation,%custominfo);
if (@inststatuses > 0) {
$inststatuslist = join(',',@inststatuses);
}
my $instseclist;
- if (@instsections > 0) {
- $instseclist = join(',',@instsections);
+ if (ref($instsections) eq 'ARRAY') {
+ if (@{$instsections} > 0) {
+ $instseclist = join(',',@{$instsections});
+ }
+ }
+ my $preprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'prevalidate',$env{'user.name'},
+ $env{'user.domain'},$fullname,$coursedesc);
+ if (ref($preprocess) eq 'HASH') {
+ if (ref($preprocess->{'formitems'}) eq 'HASH') {
+ foreach my $key (keys(%{$preprocess->{'formitems'}})) {
+ if ($preprocess->{'formitems'}->{$key} eq 'multiple') {
+ if (exists($env{'form.'.$key})) {
+ @{$custominfo{$key}} = &Apache::loncommon::get_env_multiple($env{'form.'.$key});
+ }
+ } else {
+ if (exists($env{'form.'.$key})) {
+ $custominfo{$key} = $env{'form.'.$key};
+ }
+ }
+ }
+ }
}
$validationchk =
&Apache::lonnet::auto_courserequest_validation($dom,
$env{'user.name'}.':'.$env{'user.domain'},$crstype,
- $inststatuslist,$instcode,$instseclist);
+ $inststatuslist,$instcode,$instseclist,\%custominfo);
if ($validationchk =~ /:/) {
($validation,$message) = split(':',$validationchk);
} else {
@@ -2690,54 +3716,111 @@ sub print_request_outcome {
}
$reqhash{'disposition'} = $disposition;
$reqstatus = $disposition;
- my ($modified,$queued);
+ my ($modified,$queued,$coursedesc,$token,%customitems);
+ unless ($disposition eq 'rejected') {
+ my $inprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'process',$env{'user.name'},
+ $env{'user.domain'},$fullname,$coursedesc);
+ if (ref($inprocess) eq 'HASH') {
+ if (ref($inprocess->{'formitems'}) eq 'HASH') {
+ foreach my $key (keys(%{$inprocess->{'formitems'}})) {
+ if ($inprocess->{'formitems'}->{$key} eq 'multiple') {
+ if (exists($env{'form.'.$key})) {
+ @{$customitems{$key}} = &Apache::loncommon::get_env_multiple($env{'form.'.$key});
+ }
+ } else {
+ if (exists($env{'form.'.$key})) {
+ $customitems{$key} = $env{'form.'.$key};
+ $reqhash{'custom'}{$key} = $customitems{$key};
+ }
+ }
+ }
+ }
+ }
+ }
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.' ';
}
$storeresult = 'rejected';
} 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 ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles,$code);
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);
}
- my $result = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
- 'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
- \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles);
+ $r->print(''."\n".
+ &mt('Your request is being processed; this page will update when processing is complete.').
+ ' ');
+ $r->rflush();
+ my ($result,$postprocess) = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
+ 'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
+ \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles,
+ \$code,\%customitems);
if ($result eq 'created') {
$disposition = 'created';
$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.');
+ }
+ if (($code) || ((ref($postprocess) eq 'HASH') &&
+ (($postprocess->{'createdweb'}) || ($postprocess->{'createdmsg'})))) {
+ $output .= ¬ification_information($disposition,$env{'user.name'}.':'.$env{'user.domain'},
+ $dom,$cnum,$now,$code,$postprocess);
+ }
+ if ($code) {
+ $reqhash{'code'} = $code;
+ }
+ if (ref($postprocess) eq 'HASH') {
+ if (ref($postprocess->{'createdactions'}) eq 'HASH') {
+ if (ref($postprocess->{'createdactions'}{'environment'}) eq 'HASH') {
+ &Apache::loncoursequeueadmin::postprocess_crsenv($dom,$cnum,
+ $postprocess->{'createdactions'}{'environment'});
+ }
+ }
+ }
+ $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';
}
} else {
my $requestid = $cnum.'_'.$disposition;
- my $request = {
+ my $request = {
$requestid => {
timestamp => $now,
crstype => $crstype,
ownername => $env{'user.name'},
ownerdom => $env{'user.domain'},
- description => $env{'form.cdescr'},
+ description => $env{'form.cdescr'},
+ lonhost => $lonhost,
},
};
+ 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'});
@@ -2750,15 +3833,32 @@ sub print_request_outcome {
if (($queuehash{$cnum.'_approval'} ne '') ||
($queuehash{$cnum.'_pending'} ne '')) {
$queued = 1;
+ if (ref($queuehash{$cnum.'_pending'}) eq 'HASH') {
+ $token = $queuehash{$cnum.'_pending'}{'token'};
+ }
}
}
unless ($queued) {
+ if (($disposition eq 'pending') && ($crstype ne 'official')) {
+ my %reqinfo = (
+ $cnum.':'.$dom => $now.':'.$env{'user.name'}.':'.$env{'user.domain'},
+ );
+ $token = &Apache::lonnet::tmpput(\%reqinfo,$lonhost);
+ $request->{$requestid}->{'token'} = $token;
+ }
my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,
$dom);
if ($putresult eq 'ok') {
- $output = &mt('Your course request has been recorded.').' '.
- ¬ification_information($disposition,$req_notifylist,
- $cnum,$now);
+ if ($crstype eq 'community') {
+ $output .= &mt('Your community request has been recorded.');
+ } else {
+ $output .= &mt('Your course request has been recorded.')
+ }
+ unless ($disposition eq 'pending') {
+ $output .= ' '.
+ ¬ification_information($disposition,$req_notifylist,
+ $dom,$cnum,$now);
+ }
} else {
$reqstatus = 'domainerror';
$reqhash{'disposition'} = $disposition;
@@ -2767,32 +3867,55 @@ 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);
+ ($storeresult,my $updateresult) =
+ &Apache::loncoursequeueadmin::update_coursereq_status(\%reqhash,$dom,
+ $cnum,$reqstatus,'request',$env{'user.domain'},$env{'user.name'});
+ if ($storeresult eq 'ok') {
+ my $postprocess;
+ if (($disposition eq 'approval') || ($disposition eq 'pending')) {
+ my $updateaction = $disposition;
+ if ($disposition eq 'approval') {
+ $updateaction = 'queued';
+ }
+ my $fullname = &Apache::loncommon::plainname($env{'user.name'},
+ $env{'user.domain'});
+ $postprocess =
+ &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,$updateaction,$env{'user.name'},
+ $env{'user.domain'},$fullname,$env{'form.cdescr'});
+ }
+ if ($modified && $queued) {
+ if ($crstype eq 'community') {
+ $output .= ''.&mt('Your community request has been updated').' ';
+ } else {
+ $output .= ''.&mt('Your course request has been updated').' ';
+ }
+ if ($disposition eq 'approval') {
+ $output .= ¬ification_information($disposition,$req_notifylist,$dom,$cnum,$now);
+ }
+ }
+ if ($disposition eq 'approval') {
+ if ((ref($postprocess) eq 'HASH') &&
+ ((ref($postprocess->{'queuedmsg'}) eq 'HASH') || ($postprocess->{'queuedweb'}))) {
+ ¬ification_information($disposition,undef,$dom,$cnum,$now,undef,$postprocess);
+ }
+ } elsif ($disposition eq 'pending') {
+ my $pendingform;
+ if ($crstype ne 'official') {
+ $pendingform = &pending_validation_form($dom,$cnum,$crstype,$now,$token,
+ $lonhost,$env{'form.cdescr'});
+ }
+ if ($pendingform) {
+ $output .= $pendingform;
+ } else {
+ $output .= ¬ification_information($disposition,undef,$dom,$cnum,$now,undef,$postprocess);
+ }
}
- } 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");
- }
- if ($modified && $queued && $storeresult eq 'ok') {
- $output .= ''.&mt('Your course request has been updated').' '.
- ¬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 '') {
@@ -2809,23 +3932,34 @@ sub update_requestors_roles {
my $owner = $env{'user.name'}.':'.$env{'user.domain'};
if (ref($details) eq 'HASH') {
if (ref($details->{'personnel'}) eq 'HASH') {
+ my $ccrole = 'cc';
+ if ($crstype eq 'community') {
+ $ccrole = 'co';
+ }
unless (ref($details->{'personnel'}{$owner}) eq 'HASH') {
$details->{'personnel'}{$owner} = {
- 'roles' => ['cc'],
- 'cc' => { 'usec' => [] },
+ 'roles' => [$ccrole],
+ $ccrole => { 'usec' => [] },
};
}
my @roles;
if (ref($details->{'personnel'}{$owner}{'roles'}) eq 'ARRAY') {
@roles = sort(@{$details->{'personnel'}{$owner}{'roles'}});
- unless (grep(/^cc$/,@roles)) {
- push(@roles,'cc');
+ unless (grep(/^\Q$ccrole\E$/,@roles)) {
+ push(@roles,$ccrole);
}
} else {
- @roles = ('cc');
+ @roles = ($ccrole);
}
foreach my $role (@roles) {
- my $start = $now;
+ 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 '') {
@@ -2836,7 +3970,7 @@ sub update_requestors_roles {
}
}
my @usecs;
- if ($role ne 'cc') {
+ if ($role ne $ccrole) {
if (ref($details->{'personnel'}{$owner}{$role}{'usec'}) eq 'ARRAY') {
@usecs = @{$details->{'personnel'}{$owner}{$role}{'usec'}};
}
@@ -2901,21 +4035,33 @@ 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;
}
sub notification_information {
- my ($disposition,$req_notifylist,$cnum,$now) = @_;
+ my ($disposition,$req_notifylist,$dom,$cnum,$now,$code,$postprocess) = @_;
my %emails = &Apache::loncommon::getemails();
my $address;
if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
@@ -2933,140 +4079,179 @@ sub notification_information {
}
if ($req_notifylist) {
my $fullname = &Apache::loncommon::plainname($env{'user.name'},
- $env{'user.domain'});
+ $env{'user.domain'});
my $sender = $env{'user.name'}.':'.$env{'user.domain'};
- &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",$cnum,$env{'form.cdescr'},$now,'coursereq',$sender);
+ &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",
+ 'undef',$env{'form.cdescr'},$now,'coursereq',$sender);
+ }
+ if (ref($postprocess) eq 'HASH') {
+ if (ref($postprocess->{'queuedmsg'}) eq 'ARRAY') {
+ if (scalar(@{$postprocess->{'queuedmsg'}}) > 0) {
+ my $recipient = $env{'user.name'}.':'.$env{'user.domain'};
+ my $sender = $recipient;
+ my $addmsg = [];
+ foreach my $item (@{$postprocess->{'queuedmsg'}}) {
+ if (ref($item) eq 'HASH') {
+ if ($item->{'mt'} ne '') {
+ push(@{$addmsg},$item);
+ }
+ }
+ }
+ if (scalar(@{$addmsg}) > 0) {
+ &Apache::loncoursequeueadmin::send_selfserve_notification($recipient,$addmsg,undef,
+ $env{'form.cdescr'},$now,
+ 'queuedcrsreq',$sender);
+ }
+ }
+ }
+ if ($postprocess->{'queuedweb'}) {
+ $output .= $postprocess->{'queuedweb'};
+ }
}
} elsif ($disposition eq 'pending') {
- $output .= ''.
+ my $pending_default = ' '.
&mt('Your request has been placed in a queue pending administrative action.').' '.
&mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").' '.
&mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
- ' ';
+ ' ';
+ if (ref($postprocess) eq 'HASH') {
+ if ($postprocess->{'pendingweb'}) {
+ $output .= $postprocess->{'pendingweb'};
+ } else {
+ $output .= $pending_default;
+ }
+ } else {
+ $output .= $pending_default;
+ }
+ } elsif ($disposition eq 'created') {
+ if (($code) || ((ref($postprocess) eq 'HASH') &&
+ ((ref($postprocess->{'createdmsg'}) eq 'ARRAY') || ($postprocess->{'createdweb'})))) {
+ my $addmsg = [];
+ my $recipient = $env{'user.name'}.':'.$env{'user.domain'};
+ my $sender = $recipient;
+ if ($code) {
+ push(@{$addmsg},{
+ mt => 'Students can automatically select your course: "[_1]" by entering this code: [_2]',
+ args => [$env{'form.cdescr'},$code],
+ });
+ $output .= ''.
+ &mt('Students can automatically select your course by entering this code: [_1].',''.$code.'').
+ ' '.
+ &mt('A message has been sent to your LON-CAPA account with this information.');
+ if ($address ne '') {
+ $output.= ' '.&mt('An e-mail has also been sent to: [_1] with this code.',$address);
+ }
+ $output .= ' ';
+ }
+ if (ref($postprocess) eq 'HASH') {
+ if (ref($postprocess->{'createdmsg'}) eq 'ARRAY') {
+ foreach my $item (@{$postprocess->{'createdmsg'}}) {
+ if (ref($item) eq 'HASH') {
+ if ($item->{'mt'} ne '') {
+ push(@{$addmsg},$item);
+ }
+ }
+ }
+ }
+ if ($postprocess->{'createdweb'}) {
+ $output .= $postprocess->{'createdweb'}
+ }
+ }
+ if (scalar(@{$addmsg}) > 0) {
+ my $type = 'createdcrsreq';
+ if ($code) {
+ $type = 'uniquecode';
+ }
+ &Apache::loncoursequeueadmin::send_selfserve_notification($recipient,$addmsg,$dom.'_'.$cnum,$env{'form.cdescr'},
+ $now,$type,$sender);
+ }
+ }
} 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;
- }
- }
- }
+sub pending_validation_form {
+ my ($cdom,$cnum,$crstype,$now,$token,$lonhost,$cdesc) = @_;
+ my $output;
+ my %postvalues = (
+ 'owner' => $env{'user.name'}.':'.$env{'user.domain'},
+ 'course' => $cdom.'_'.$cnum,
+ 'coursetype' => $crstype,
+ );
+ my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$cdom);
+
+ if (ref($domconfig{'requestcourses'}) eq 'HASH') {
+ my ($url,$buttontext,$code,@fields);
+ if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
+ $postvalues{'description'} = $cdesc;
+ $url = $domconfig{'requestcourses'}{'validation'}{'url'};
+ if (ref($domconfig{'requestcourses'}{'validation'}{'fields'}) eq 'ARRAY') {
+ @fields = @{$domconfig{'requestcourses'}{'validation'}{'fields'}};
+ }
+ $buttontext = $domconfig{'requestcourses'}{'validation'}{'button'};
+ $output .= $domconfig{'requestcourses'}{'validation'}{'markup'};
+ if (($url =~ m{^(https?\://|/)}) && (@fields > 0)) {
+ $output .= ''."\n";
}
- @{$inststatuses} = ('_external_');
}
}
- return $val;
+ return $output;
}
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]);
+ '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') || ($crstype eq 'textbook')) &&
+ (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';
}
@@ -3096,18 +4281,31 @@ sub retrieve_settings {
}
$env{'form.clonecrs'} = $reqinfo{'clonecrs'};
$env{'form.clonedom'} = $reqinfo{'clonedom'};
+ if (($reqinfo{'clonecrs'} ne '') && ($reqinfo{'clonedom'} ne '')) {
+ $env{'form.cloning'} = 1;
+ }
$env{'form.datemode'} = $reqinfo{'datemode'};
$env{'form.dateshift'} = $reqinfo{'dateshift'};
- if (($reqinfo{'crstype'} eq 'official') && ($reqinfo{'instcode'} ne '')) {
- $env{'form.sectotal'} = $reqinfo{'sectotal'};
- $env{'form.crosslisttotal'} = $reqinfo{'crosslisttotal'};
- $env{'form.autoadds'} = $reqinfo{'autoadds'};
- $env{'form.autdrops'} = $reqinfo{'autodrops'};
- $env{'form.instcode'} = $reqinfo{'instcode'};
- my $crscode = {
- $cnum => $reqinfo{'instcode'},
- };
- &extract_instcode($dom,'instcode',$crscode,$cnum);
+ if ($reqinfo{'crstype'} eq 'official') {
+ $env{'form.autoadds'} = $reqinfo{'autoadds'};
+ $env{'form.autodrops'} = $reqinfo{'autodrops'};
+ if ($reqinfo{'instcode'} ne '') {
+ $env{'form.sectotal'} = $reqinfo{'sectotal'};
+ $env{'form.crosslisttotal'} = $reqinfo{'crosslisttotal'};
+ $env{'form.instcode'} = $reqinfo{'instcode'};
+ my $crscode = {
+ $cnum => $reqinfo{'instcode'},
+ };
+ &extract_instcode($dom,'instcode',$crscode,$cnum);
+ (undef,undef,my $instcredits) =
+ &Apache::lonnet::auto_validate_instcode(undef,$dom,
+ $reqinfo{'instcode'});
+ if ($instcredits ne $reqinfo{'defaultcredits'}) {
+ $env{'form.coursecredits'} = $reqinfo{'defaultcredits'};
+ }
+ }
+ } elsif (($reqinfo{'crstype'} eq 'unofficial') || ($reqinfo{'crstype'} eq 'textbook')) {
+ $env{'form.coursecredits'} = $reqinfo{'defaultcredits'};
}
my @currsec;
if (ref($reqinfo{'sections'}) eq 'HASH') {
@@ -3238,5 +4436,626 @@ sub generate_date_items {
return;
}
+sub print_textbook_form {
+ my ($r,$dom,$incdoms,$domdefs,$settings,$can_request) = @_;
+ my (%prefab,%ordered,%numprefab);
+ my $crstype = 'textbook';
+#
+# Retrieve list of prefabricated courses (textbook courses and templates) cloneable by user
+#
+ foreach my $type ('textbooks','templates') {
+ $numprefab{$type} = 0;
+ if (ref($settings) eq 'HASH') {
+ $prefab{$type} = $settings->{$type};
+ if (ref($prefab{$type}) eq 'HASH') {
+ foreach my $item (keys(%{$prefab{$type}})) {
+ my ($clonedom,$clonecrs) = split(/_/,$item);
+ if (ref($prefab{$type}{$item}) eq 'HASH') {
+ if (&Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
+ $env{'user.domain'},$clonecrs,$clonedom,$crstype)) {
+
+ my $num = $prefab{$type}{$item}{'order'};
+ $ordered{$type}{$num} = $item;
+ $numprefab{$type} ++;
+ }
+ }
+ }
+ }
+ }
+ }
+
+#
+# Check if domain has multiple library servers
+#
+ my ($home_server_pick,$numlib) =
+ &Apache::loncommon::home_server_form_item($dom,'chome',
+ 'default','hide');
+ if ($numlib > 1) {
+ $home_server_pick = &mt('Home Server for Course').': '.$home_server_pick.' ';
+ }
+
+#
+# Retrieve information about courses owned by user, or in which user has an active or future
+# Course Coordinator role
+#
+ my $numcurrent;
+ my %cloneable = &Apache::lonnet::courseiddump($dom,'.',1,'.',$env{'user.name'}.':'.$env{'user.domain'},
+ undef,undef,undef,'Course');
+ my %ccroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
+ ['active','future'],['cc']);
+ foreach my $role (keys(%ccroles)) {
+ my ($cnum,$cdom,$rest) = split(/:/,$role,3);
+ unless (exists($cloneable{$cdom.'_'.$cnum})) {
+ my %courseinfo = &Apache::lonnet::coursedescription($cdom.'_'.$cnum,{'one_time' => 1});
+ $cloneable{$cdom.'_'.$cnum} = \%courseinfo;
+ }
+ }
+
+ my $numcurrent = scalar(keys(%cloneable));
+
+ my $jscript = &textbook_request_javascript(\%numprefab,$numcurrent);
+ my %loaditems;
+ $loaditems{'onload'} = 'javascript:uncheckAllRadio();';
+ $r->print(&header('Course Request',$jscript,\%loaditems));
+
+ if (ref($can_request) eq 'HASH') {
+ unless ((scalar(keys(%{$can_request})) == 1) && ($can_request->{'textbook'})) {
+ &Apache::lonhtmlcommon::add_breadcrumb(
+ { href => '/adm/requestcourse',
+ text => 'Pick action',
+ });
+ }
+ }
+ &Apache::lonhtmlcommon::add_breadcrumb({text=>'Course Request'});
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests'));
+
+ &startContentScreen($r,'textbookrequests');
+#
+# Show domain selector form, if required.
+#
+ if (@{$incdoms} > 1) {
+ my $onchange = 'this.form.submit()';
+ $r->print(' |