';
if ($context eq 'crosslist') {
$output .= ''.&mt('Include?').' '.
@@ -2513,6 +3296,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 '') {
@@ -2605,9 +3408,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'};
@@ -2615,15 +3419,17 @@ 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';
@@ -2642,6 +3448,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'} = '';
+ }
}
}
}
@@ -2667,6 +3477,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'};
@@ -2678,6 +3489,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 '') {
@@ -2723,6 +3584,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'}) {
@@ -2730,18 +3596,22 @@ 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'});
@@ -2749,7 +3619,7 @@ sub print_request_outcome {
my $canclone =
&Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
$env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'},
- $crstype);
+ $crstype,$dom,$instcode);
if ($canclone) {
$clonecrs = $env{'form.clonecrs'};
$clonedom = $env{'form.clonedom'};
@@ -2765,6 +3635,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'},
@@ -2781,10 +3653,19 @@ sub print_request_outcome {
accessend => $accessend,
personnel => \%personnel,
};
- my (@inststatuses,$storeresult,$creationresult);
+ my ($result,$output,$customized) = &process_request($r,$lonhost,$dom,$cnum,$crstype,$now,$details,
+ $instcode,$req_notifylist,\@instsections,\%domconfig);
+ return ($result,$output,$customized);
+}
+
+sub process_request {
+ my ($r,$lonhost,$dom,$cnum,$crstype,$now,$details,$instcode,$req_notifylist,$instsections,
+ $domconfig) = @_;
+ my (@inststatuses,$storeresult,$creationresult,$output,$customized);
my $val =
- &Apache::loncoursequeueadmin::get_processtype($env{'user.name'},$env{'user.domain'},
- $env{'user.adv'},$dom,$crstype,\@inststatuses,\%domconfig);
+ &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.');
@@ -2792,12 +3673,16 @@ 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');
+ } elsif ($crstype eq 'placement') {
+ $output = &mt('You are not permitted to request creation of placement tests');
} else {
$output = &mt('Unrecognized course type: [_1]',$crstype);
}
$storeresult = 'notpermitted';
} else {
- my ($disposition,$message,$reqstatus);
+ my ($disposition,$message,$reqstatus,$coursedesc,$accessstart,$accessend,%customvalidation);
my %reqhash = (
reqtime => $now,
crstype => $crstype,
@@ -2805,6 +3690,13 @@ 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'};
+ $accessstart = $details->{'accessstart'};
+ $accessend = $details->{'accessend'};
+ }
if ($val eq 'autolimit=') {
$disposition = 'process';
} elsif ($val =~ /^autolimit=(\d+)$/) {
@@ -2813,17 +3705,32 @@ sub print_request_outcome {
$dom,$crstype,$limit,\$message);
} elsif ($val eq 'validate') {
my ($inststatuslist,$validationchk,$validation);
+ if (ref($details) eq 'HASH') {
+ if ($details->{'clonecrs'}) {
+ $customvalidation{'_LC_clonefrom'} = $details->{'clonedom'}.'_'.$details->{'clonecrs'};
+ }
+ }
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});
+ }
+ }
+#
+# Retrieve any custom form information used for validation
+#
+ my $preprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'prevalidate',$env{'user.name'},
+ $env{'user.domain'},$fullname,$coursedesc);
+ if (ref($preprocess) eq 'HASH') {
+ &custom_formitems($preprocess,\%customvalidation);
}
$validationchk =
&Apache::lonnet::auto_courserequest_validation($dom,
$env{'user.name'}.':'.$env{'user.domain'},$crstype,
- $inststatuslist,$instcode,$instseclist);
+ $inststatuslist,$instcode,$instseclist,\%customvalidation);
if ($validationchk =~ /:/) {
($validation,$message) = split(':',$validationchk);
} else {
@@ -2840,7 +3747,21 @@ sub print_request_outcome {
}
$reqhash{'disposition'} = $disposition;
$reqstatus = $disposition;
- my ($modified,$queued);
+ my ($modified,$queued,$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,undef,
+ undef,undef,\%customvalidation);
+#
+# Retrieve any custom form information submitted with review page and include in request details.
+#
+ if (ref($inprocess) eq 'HASH') {
+ &custom_formitems($inprocess,\%customitems);
+ foreach my $key (keys(%customitems)) {
+ $reqhash{'custom'}{$key} = $customitems{$key};
+ }
+ }
+ }
if ($disposition eq 'rejected') {
if ($crstype eq 'community') {
$output = &mt('Your community request was rejected.');
@@ -2853,7 +3774,7 @@ sub print_request_outcome {
$storeresult = 'rejected';
} elsif ($disposition eq 'process') {
my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
- my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles);
+ my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles,$code);
my $type = 'Course';
if ($crstype eq 'community') {
$type = 'Community';
@@ -2862,9 +3783,36 @@ sub print_request_outcome {
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();
+ if (ref($details) eq 'HASH') {
+ if ($details->{'clonecrs'}) {
+ $customitems{'_LC_clonefrom'} = $details->{'clonedom'}.'_'.$details->{'clonecrs'};
+ }
+ }
+ $customitems{'_LC_ownerfullname'} = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'},'first');
+ my $owneremail;
+ my %emails = &Apache::loncommon::getemails();
+ foreach my $email ('permanentemail','critnotification','notification') {
+ $owneremail = $emails{$email};
+ last if ($owneremail ne '');
+ }
+ if ($owneremail ne '') {
+ $customitems{'_LC_owneremail'} = $owneremail;
+ }
+ $customitems{'_LC_coursedomainname'} = &Apache::lonnet::domain($dom,'description');
+ $customitems{'_LC_coursedescription'} = $coursedesc;
+ $customitems{'_LC_coursestartdate'} = $accessstart;
+ $customitems{'_LC_courseenddate'} = $accessend;
+ my ($result,$postprocess) = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
+ 'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
+ \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles,
+ \$code,\%customitems);
+ if (ref($postprocess) eq 'HASH') {
+ $customized = $postprocess->{'createdcustomized'};
+ }
if ($result eq 'created') {
$disposition = 'created';
$reqstatus = 'created';
@@ -2875,7 +3823,26 @@ sub print_request_outcome {
} else {
$output = ''.&mt('Your course request has been processed and the course has been created.');
}
- $output .= ' '.$role_result.' ';
+ 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'});
+ }
+ }
+ }
+ unless ($customized) {
+ $output .= ' '.$role_result;
+ }
+ $output .= '';
$creationresult = 'created';
} else {
$output = '';
@@ -2891,15 +3858,19 @@ sub print_request_outcome {
}
} 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'});
@@ -2912,9 +3883,19 @@ 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') {
@@ -2923,9 +3904,11 @@ sub print_request_outcome {
} else {
$output .= &mt('Your course request has been recorded.')
}
- $output .= ' '.
- ¬ification_information($disposition,$req_notifylist,
- $cnum,$now);
+ unless ($disposition eq 'pending') {
+ $output .= ' '.
+ ¬ification_information($disposition,$req_notifylist,
+ $dom,$cnum,$now);
+ }
} else {
$reqstatus = 'domainerror';
$reqhash{'disposition'} = $disposition;
@@ -2934,42 +3917,90 @@ 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'});
}
- } 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') {
- if ($crstype eq 'community') {
- $output .= ''.&mt('Your community request has been updated').' ';
- } else {
- $output .= ''.&mt('Your course request has been updated').' ';
+ 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);
+ $customized = $postprocess->{'createdcustomized'};
+ }
+ } 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);
+ }
+ if (ref($postprocess) eq 'HASH') {
+ $customized = $postprocess->{'createdcustomized'};
+ }
}
- $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 '') {
- return ($creationresult,$output);
+ return ($creationresult,$output,$customized);
} else {
- return ($storeresult,$output);
+ return ($storeresult,$output,$customized);
+ }
+}
+
+sub custom_formitems {
+ my ($preprocess,$customhash) = @_;
+ return unless ((ref($preprocess) eq 'HASH') && (ref($customhash) 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})) {
+ my @items = &Apache::loncommon::get_env_multiple($env{'form.'.$key});
+ foreach my $item (@items) {
+ $item =~ s/(`)/'/g;
+ $item =~ s/\$/\(\$\)/g;
+ push(@{$customhash->{$key}},$item);
+ }
+ }
+ } else {
+ if (exists($env{'form.'.$key})) {
+ $customhash->{$key} = $env{'form.'.$key};
+ $customhash->{$key} =~ s/(`)/'/g;
+ $customhash->{$key} =~ s/\$/\(\$\)/g;
+ }
+ }
+ }
}
}
@@ -3109,7 +4140,7 @@ sub update_requestors_roles {
}
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 '')) {
@@ -3127,20 +4158,144 @@ 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 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";
+ }
+ }
}
return $output;
}
@@ -3159,7 +4314,7 @@ sub check_autolimit {
if (($crstype eq 'community') &&
(exists($crsroles{$cnum.':'.$cdom.':co'}))) {
$count ++;
- } elsif ((($crstype eq 'official') || ($crstype eq 'unofficial')) &&
+ } elsif ((($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'textbook') || ($crstype eq 'placement')) &&
(exists($crsroles{$cnum.':'.$cdom.':cc'}))) {
$count ++;
}
@@ -3205,18 +4360,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') {
@@ -3347,5 +4515,761 @@ 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,$dom)) {
+
+ 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
+# Course Coordinator role
+#
+ my $numcurrent;
+ my %cloneable = &Apache::lonnet::courseiddump($dom,'.',1,'.',$env{'user.name'}.':'.$env{'user.domain'},
+ '.',undef,undef,'Course');
+ my %ccroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
+ ['active'],['cc']);
+
+ my $cc_clone = '';
+ foreach my $role (keys(%ccroles)) {
+ my ($cnum,$cdom,$rest) = split(/:/,$role,3);
+ $cc_clone .= $cdom.':'.$cnum.'&';
+ unless (exists($cloneable{$cdom.'_'.$cnum})) {
+ my %courseinfo = &Apache::lonnet::coursedescription($cdom.'_'.$cnum,{'one_time' => 1});
+ $cloneable{$cdom.'_'.$cnum} = {
+ context => $courseinfo{'internal.creationcontext'},
+ created => $courseinfo{'internal.created'},
+ creator => $courseinfo{'internal.creator'},
+ description => $courseinfo{'description'},
+ inst_code => $courseinfo{'coursecode'},
+ owner => $courseinfo{'internal.courseowner'},
+ releaserequired => $courseinfo{'internal.releaserequired'},
+ type => $courseinfo{'type'},
+ };
+ }
+ }
+
+ my $numcurrent = scalar(keys(%cloneable));
+
+#
+# Retrieve information about courses from user's domain which user can clone, but which not owned
+# or cloneable based on Course Coordinator role.
+#
+ my ($numdomcourses,%domcloneable);
+ my %allcloneable = &Apache::lonnet::courseiddump($dom,'.',1,'.','.','.',undef,undef,'Course',
+ undef,undef,undef,undef,undef,
+ $env{'user.name'}.':'.$env{'user.domain'},
+ $cc_clone,1);
+ foreach my $cid (keys(%allcloneable)) {
+ unless (exists($cloneable{$cid})) {
+ $domcloneable{$cid} = $allcloneable{$cid};
+ }
+ }
+ $numdomcourses = scalar(keys(%domcloneable));
+
+ my $fullname = &Apache::loncommon::plainname($env{'user.name'},
+ $env{'user.domain'});
+
+#
+# Retrieve any custom form information prior to rendering page
+#
+
+ my $initprocess = &Apache::lonnet::auto_crsreq_update($dom,undef,$crstype,'initializereview',$env{'user.name'},
+ $env{'user.domain'},$fullname);
+ my %custominit;
+ if (ref($initprocess) eq 'HASH') {
+ &custom_formitems($initprocess,\%custominit);
+ }
+
+#
+# Retrieve any custom onload actions or javascript used for page before rendering
+#
+
+ my ($customonload,$customjs,$customvalidationjs);
+ my $inprocess = &Apache::lonnet::auto_crsreq_update($dom,undef,$crstype,'prereview',$env{'user.name'},
+ $env{'user.domain'},$fullname,undef,undef,
+ undef,undef,\%custominit);
+ if (ref($inprocess) eq 'HASH') {
+ $customonload = $inprocess->{'onload'};
+ $customjs = $inprocess->{'javascript'};
+ $customvalidationjs = $inprocess->{'validationjs'};
+ }
+
+ my $postprocess = &Apache::lonnet::auto_crsreq_update($dom,undef,$crstype,'review',
+ $env{'user.name'},
+ $env{'user.domain'},$fullname,undef,undef,
+ undef,undef,\%custominit);
+
+ my $jscript = &textbook_request_javascript(\%numprefab,$numcurrent,$numdomcourses,$customvalidationjs);
+ $jscript .= $customjs;
+ my %loaditems;
+ $loaditems{'onload'} = 'javascript:uncheckAllRadio();'.$customonload;
+ $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(' |