--- loncom/interface/lonrequestcourse.pm 2010/01/14 20:08:13 1.43 +++ loncom/interface/lonrequestcourse.pm 2021/08/31 17:21:24 1.112 @@ -1,7 +1,7 @@ # The LearningOnline Network # Request a course # -# $Id: lonrequestcourse.pm,v 1.43 2010/01/14 20:08:13 raeburn Exp $ +# $Id: lonrequestcourse.pm,v 1.112 2021/08/31 17:21:24 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -119,6 +119,10 @@ use Apache::loncoursequeueadmin; use Apache::lonuserutils; use LONCAPA qw(:DEFAULT :match); +my $registered_flush; +my $registered_instcats; +my $modified_dom; + sub handler { my ($r) = @_; &Apache::loncommon::content_type($r,'text/html'); @@ -127,18 +131,105 @@ sub handler { return OK; } + $registered_flush = 0; + $registered_instcats = 0; + $modified_dom = ''; + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['action','showdom','cnum','state','crstype']); + ['action','showdom','cnum','state','crstype','queue','tabs']); &Apache::lonhtmlcommon::clear_breadcrumbs(); my $dom = &get_course_dom(); my $action = $env{'form.action'}; my $state = $env{'form.state'}; my (%states,%stored); - my ($jscript,$uname,$udom,$result,$warning); + my ($jscript,$uname,$udom,$result,$warning,$showcredits,$instcredits,%can_request, + %request_domains,@incdoms); + my %domdefs = &Apache::lonnet::get_domain_defaults($dom); + if ($domdefs{'officialcredits'} || $domdefs{'unofficialcredits'} || $domdefs{'textbookcredits'}) { + $showcredits = 1; + } + + my $canreq = + &Apache::lonnet::check_can_request($dom,\%can_request,\%request_domains); + + foreach my $item (keys(%request_domains)) { + if (ref($request_domains{$item}) eq 'ARRAY') { + foreach my $possdom (@{$request_domains{$item}}) { + unless(grep(/^\Q$possdom\E$/,@incdoms)) { + push(@incdoms,$possdom); + } + } + } + } + + if ($canreq) { + if (($env{'form.crstype'} eq 'lti') && ($env{'request.lti.login'}) && + ($env{'form.lti.reqrole'} eq 'cc') && ($env{'form.lti.reqcrs'}) && + ($env{'form.lti.sourcecrs'} ne '')) { + if ($action eq 'process') { + if ($can_request{'lti'}) { + my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom); + &process_textbook_request($r,$dom,$action,\%domdefs,\%domconfig,\%can_request,'lti'); + } else { + $r->print(&header('Course Request','','','',{ 'only_body' => 1}). + '
'.&mt('You do not have privileges to request creation of LTI courses.').'
'. + ''.$pageinfo.'
'. - ''.$pageinfo.'
'); + if ($earlyout) { + $r->print(&Apache::loncommon::end_page()); + return; + } + $r->print(''); if ($storeresult eq 'ok') { - $r->print(''. - &mt('Modify this request').''.(' 'x4)); + $r->print('
'. + &mt('Modify this request').''.(' 'x4). + ''.&mt('Make another request').'
'); + } + if (&Apache::loncoursequeueadmin::author_prompt()) { + unless ($customized) { + &print_author_prompt($r,$env{'form.action'},$env{'form.cnum'},$env{'form.showdom'}, + $env{'form.crstype'},$storeresult); + } + } elsif ($storeresult eq 'created') { + unless ($customized) { + $r->print(''.&mt('Make another request').'
'); + } + } + } + } elsif ($state eq 'reqauthor') { + my ($result,@links); + if ($env{'form.requestauthor'}) { + $r->print(&Apache::loncoursequeueadmin::process_reqauthor(\$result)); + if ($result eq 'created') { + my $role = 'au'; + my $spec = "$role./$env{'form.showdom'}/"; + push(@links,&mt('Enter your Authoring Space with role: [_1]', + ''. + &Apache::lonnet::plaintext($role).'')); } - $r->print(''.&mt('Make another request').''); - return; + } + if (($env{'form.disposition'} eq 'created') && + ($env{'form.cnum'} =~ /^$match_courseid$/) && + ($env{'form.showdom'} =~ /^$match_domain$/)) { + my ($spec,$area,$role,$type); + my $role = 'cc'; + my $spec = "$role./$env{'form.showdom'}/$env{'form.cnum'}"; + my $type = 'Course'; + if ($env{'form.crstype'} eq 'community') { + $type = 'Community'; + } + my $showrole = &Apache::lonnet::plaintext($role,$type); + unshift(@links,&mt('Enter new course with role: [_1]', + ''.$showrole.'')); + } + if (@links > 1) { + $r->print(&mt('New roles will be listed on your [_1]Roles[_2] page.', + '','').' '.&mt('Choose a role:'). + ''.$links[0].'
'); } } - my @excluded = &get_excluded_elements($dom,$states,$action,$state); + my @excluded = &get_excluded_elements($dom,$states,$action,$state,$showcredits); if ($state eq 'personnel') { push(@excluded,'persontotal'); } @@ -1403,25 +1697,51 @@ sub print_request_form { $count ++; } $env{'form.persontotal'} = $count; - } } if ($state eq 'enrollment') { - push(@excluded,'crosslisttotal'); + push(@excluded,('sectotal','crosslisttotal')); + } + if (($state eq 'process') || ($state eq 'reqauthor')) { + $r->print(''); + } else { + $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).''); + &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next, + $navtxt{'next'},$state); } - $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).''); - &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next, - $navtxt{'next'},$state); return; } -sub get_cancreate_status { - my ($persondom,$personname,$dom) = @_; +sub print_author_prompt { + my ($r,$action,$cnum,$showdom,$crstype,$storeresult) = @_; + $r->print(''.
+ &mt('Although assessment items can be created directly inside a course, such items only use part of the assessment capabilities of LON-CAPA.').
+ '
'.
+ &mt('By contrast, items created in Authoring Space, then imported into a course, can use all of the features of the assessment engine.').'
'.&mt('Request Authoring Space access now?'). + ' '. + ''. + (' 'x2). + ''. + '
'. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''.
+ ''.&mt('Records/page:').' '. + &Apache::lonmeta::selectbox('show',$curr->{'show'},undef, + (&mt('all'),5,10,20,50,100,1000,10000)). + ' | '; + my $startform = + &Apache::lonhtmlcommon::date_setter($formname,'requested_after_date', + $curr->{'requested_after_date'},undef, + undef,undef,undef,undef,undef,undef,$nolink); + my $endform = + &Apache::lonhtmlcommon::date_setter($formname,'requested_before_date', + $curr->{'requested_before_date'},undef, + undef,undef,undef,undef,undef,undef,$nolink); + $output .= ' | '.&mt('Window during which course/community was requested:').' '. + '
| '.
+ ''; + my ($types,$typenames) = &Apache::loncommon::course_types(); + if (ref($types) eq 'ARRAY') { + if (@{$types} > 1) { + $output .= ' | '.
+ &mt('Course Type:').' | ';
+ }
+ }
+ my ($statuses,$statusnames) = &reqstatus_names($curr->{'crstype'});
+ if (ref($statuses) eq 'ARRAY') {
+ if (@{$statuses} > 1) {
+ $output .= ''.
+ &mt('Request Status:').' | ';
+ }
+ }
+ $output .= '
'. + ''. + '
'.&mt('Include?').' '. @@ -2513,6 +3370,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). + '
'."\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,$clonemsg,\$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,8 +3905,59 @@ sub print_request_outcome {
} else {
$output = ''.&mt('Your course request has been processed and the course has been created.');
}
- $output .= ' '.$role_result; + } + $output .= ''; + if ($logmsg) { + $output .= ' '.$logmsg.' '; + } + if ((ref($clonemsg) eq 'ARRAY') && (@{$clonemsg})) { + $output .= '';
+ my $user_lh = &Apache::loncommon::user_lang($env{'user.name'},$env{'user.domain'});
+ foreach my $item (@{$clonemsg}) {
+ if (ref($item) eq 'HASH') {
+ $output .= &mt_user($user_lh,$item->{mt},
+ @{$item->{args}}).' '. - ¬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 +4031,106 @@ 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($r,$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 devalidate_remote_instcats { + if ($modified_dom ne '') { + my %servers = &Apache::lonnet::internet_dom_servers($modified_dom); + my %thismachine; + map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids(); + if (keys(%servers)) { + foreach my $server (keys(%servers)) { + next if ($thismachine{$server}); + &Apache::lonnet::remote_devalidate_cache($server,['instcats:'.$modified_dom]); + } + } + $modified_dom = ''; + } + return; +} + +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 +4270,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 +4288,147 @@ 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 = ' ';
+ 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('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.'). - ' '.
+ &mt('Students can automatically select your course by entering this code: [_1].',''.$code.'').
+ ' '.
- &mt('Your request status is: [_1].',$disposition).
- ' '
+ &mt('Your request status is: [_1].',$disposition).
+ '';
+ }
+ return $output;
+}
+
+sub pending_validation_form {
+ my ($r,$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 +4447,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 +4493,32 @@ 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);
+ $env{'form.tinyurls'} = $reqinfo{'tinyurls'};
+ 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 +4649,816 @@ sub generate_date_items {
return;
}
+sub print_textbook_form {
+ my ($r,$dom,$incdoms,$domdefs,$settings,$can_request,$crstype,$formhash) = @_;
+ my (%prefab,%ordered,%numprefab);
+ if ($crstype eq '') {
+ $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,$args); + $loaditems{'onload'} = 'javascript:uncheckAllRadio();'.$customonload; + if ($crstype eq 'lti') { + $args = { 'only_body' => 1}; + } + $r->print(&header('Course Request',$jscript,\%loaditems,undef,$args)); + + if (ref($can_request) eq 'HASH') { + unless (((scalar(keys(%{$can_request})) == 1) && ($can_request->{'textbook'})) || + ($crstype eq 'lti')) { + &Apache::lonhtmlcommon::add_breadcrumb( + { href => '/adm/requestcourse', + text => 'Pick action', + }); + } + } + unless ($crstype eq 'lti') { + &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(' |