--- loncom/interface/lonrequestcourse.pm 2009/08/23 03:51:53 1.24 +++ loncom/interface/lonrequestcourse.pm 2019/01/27 15:46:26 1.106 @@ -1,7 +1,7 @@ # The LearningOnline Network # Request a course # -# $Id: lonrequestcourse.pm,v 1.24 2009/08/23 03:51:53 raeburn Exp $ +# $Id: lonrequestcourse.pm,v 1.106 2019/01/27 15:46:26 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -44,24 +44,28 @@ described at http://www.lon-capa.org. =item handler() +=item get_breadcrumbs() + =item header() =item form_elements() =item onload_action() -=item check_can_request() - -=item course_types() - =item print_main_menu() =item request_administration() +=item close_popup_form() + +=item get_instcode() + =item print_request_form() =item print_enrollment_menu() +=item show_invalid_crosslists() + =item inst_section_selector() =item date_setting_table() @@ -90,16 +94,16 @@ described at http://www.lon-capa.org. =item print_request_outcome() -=item get_processtype() - =item check_autolimit() -=item build_batchcreatehash() - =item retrieve_settings() =item get_request_settings() +=item extract_instcode() + +=item generate_date_items() + =back =cut @@ -112,6 +116,7 @@ use Apache::lonnet; use Apache::loncommon; use Apache::lonlocal; use Apache::loncoursequeueadmin; +use Apache::lonuserutils; use LONCAPA qw(:DEFAULT :match); sub handler { @@ -122,40 +127,101 @@ sub handler { return OK; } + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, + ['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 %stored; - my $jscript; - if ((defined($state)) && (defined($action))) { - if (($action eq 'view') && ($state eq 'details')) { - if ((defined($env{'form.showdom'})) && (defined($env{'form.cnum'}))) { - my $result = &retrieve_settings($env{'form.showdom'},$env{'form.cnum'}); - } - } - my %elements = &form_elements($dom); - my $elementsref = {}; - if (ref($elements{$action}) eq 'HASH') { - if (ref($elements{$action}{$state}) eq 'HASH') { - $elementsref = $elements{$action}{$state}; + my (%states,%stored); + 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 (($state eq 'courseinfo') && ($env{'form.clonedom'} eq '')) { - $env{'form.clonedom'} = $dom; - } - $jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored); } - if ($state eq 'personnel') { - $jscript .= "\n".&Apache::loncommon::userbrowser_javascript(); + 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.').'
'. + ''.&mt('Review the details of the course request before submission.').'
'. - &print_review($formname,$dom,\@codetitles,\%cat_titles,\%cat_order, - \@code_order). + if ($crstype eq 'community') { + $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).'')); + } + } + 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'); } - $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).''); - &display_navbuttons($r,$formname,$prev,$navtxt{'prev'},$next,$navtxt{'next'},$state); + if ($state eq 'review') { + if (@disallowed > 0) { + my @items = qw(uname dom lastname firstname emailaddr hidedom role newsec); + my @currsecs = ¤t_lc_sections(); + if (@currsecs) { + push(@items,'sec'); + } + my $count = 0; + for (my $i=0; $i<$env{'form.persontotal'}; $i++) { + unless ($env{'form.person_'.$i.'_uname'} eq '') { + if (grep(/^$i$/,@disallowed)) { + foreach my $item (@items) { + $env{'form.person_'.$i.'_'.$item} = ''; + } + } else { + foreach my $item (@items) { + $env{'form.person_'.$count.'_'.$item} = $env{'form.person_'.$i.'_'.$item}; + } + } + } + $count ++; + } + $env{'form.persontotal'} = $count; + } + } + if ($state eq 'enrollment') { + 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); + } return; } +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('Username').' '.$uname_form.' | '."\n".
- ''.&mt('Domain').' '.$udom_form.' | |||||||||||||||||||||||||||||||||||||||||||||||||||
'.$usersrchlink.' | '."\n". + ''.
+ &mt('Username').': '.$uname_form.' '.$userchklink.' '."\n". + ''.&mt('Domain').': '.$udom_form.' | '.
+ '|
'.&mt('First Name').' '.$form_elems{'firstname'}.' | '."\n".
''.&mt('Last Name').' '.$form_elems{'lastname'}.' | '."\n".
''.&mt('E-mail').' '.$form_elems{'emailaddr'}.' |
'.&mt('Role').' '.$roleselector.' | '."\n".
- ''.&mt('Section(s)').' '.$sectionselector.' | '."\n".
+ '|
'.&Apache::loncommon::help_open_topic('Course_Roles').' '.&mt('Role').' '.$roleselector.' | '."\n".
+ ''.
+ &Apache::loncommon::help_open_topic('Course_Request_Rolesection').' '.&mt('LON-CAPA Section(s)').' '.$sectionselector.' | '."\n".
'
'.&mt('You may also add users later, once the community has been created, by using the "Manage community users" link, accessible from the "Main Menu".').'
'; + } else { + $output .= ''.&mt('You may also add users later, once the course has been created, by using the "Manage course users" link, accessible from the "Main Menu".').'
'; + } return $output; } -sub print_request_status { - my ($dom) = @_; +sub current_lc_sections { + my @currsecs; + if ($env{'form.sectotal'}) { + for (my $i=0; $i<$env{'form.sectotal'}; $i++) { + if ($env{'form.sec_'.$i}) { + if (defined($env{'form.loncapasec_'.$i})) { + my $lcsec = $env{'form.loncapasec_'.$i}; + unless (grep(/^\Q$lcsec\E$/,@currsecs)) { + push(@currsecs,$lcsec); + } + } + } + } + } + return @currsecs; +} + +sub sorted_request_history { + my ($dom,$action,$curr_req) = @_; + my ($after,$before,$statusfilter,$crstypefilter); + if ($env{'form.status'} ne '') { + $statusfilter = $env{'form.status'}; + } + if ($env{'form.crstype'} ne '') { + $crstypefilter = $env{'form.crstype'}; + } + if (ref($curr_req) eq 'HASH') { + $after = $curr_req->{'requested_after_date'}, + $before = $curr_req->{'requested_before_date'}; + $statusfilter = $curr_req->{'status'}; + $crstypefilter = $curr_req->{'crstype'}; + } my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'}, $env{'user.name'},'^status:'.$dom); - my ($output,$formname,%queue_by_date,%typenames); - if ($env{'form.crstype'} eq 'any') { - %typenames = &Apache::lonlocal::texthash ( - official => 'Official course', - unofficial => 'Unofficial course', - community => 'Community', - ); - } + my %queue_by_date; + my ($types,$typenames) = &Apache::loncommon::course_types(); foreach my $key (keys(%statusinfo)) { - if (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending')) { - (undef,my($cdom,$cnum)) = split(':',$key); - next if ($cdom ne $dom); - my $requestkey = $cdom.'_'.$cnum; - if ($requestkey =~ /^($match_domain)_($match_courseid)$/) { - my %history = &Apache::lonnet::restore($requestkey,'courserequests', - $env{'user.domain'},$env{'user.name'}); - my $entry; - my $timestamp = $history{'reqtime'}; - my $crstype = $history{'crstype'}; - my $disposition = $history{'disposition'}; + if ($action eq 'view') { + next unless (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending')); + } else { + next unless (($statusfilter eq 'any') || + ($statusfilter eq $statusinfo{$key})); + } + (undef,my($cdom,$cnum)) = split(':',$key); + next if ($cdom ne $dom); + my $requestkey = $cdom.'_'.$cnum; + if ($requestkey =~ /^($match_domain)_($match_courseid)$/) { + my %history = &Apache::lonnet::restore($requestkey,'courserequests', + $env{'user.domain'},$env{'user.name'}); + my $entry; + my $reqtime = $history{'reqtime'}; + my $lastupdate = $history{'timestamp'}; + my $crstype = $history{'crstype'}; + my $disposition = $history{'disposition'}; + my $status = $history{'status'}; + my $uniquecode = $history{'code'}; + if ($action eq 'view') { next if ((exists($history{'status'})) && ($history{'status'} eq 'created')); - next unless (($env{'form.crstype'} eq 'any') || - ($env{'form.crstype'} eq $crstype)); + } else { + next if (($reqtime < $after) || ($reqtime > $before)); + } + next unless (($crstypefilter eq 'any') || + ($crstypefilter eq $crstype)); + if ($action eq 'view') { next unless (($disposition eq 'approval') || ($disposition eq 'pending')); - if (ref($history{'details'}) eq 'HASH') { - $entry = $requestkey.':'.$crstype.':'. - &escape($history{'details'}{'cdescr'}); - if ($crstype eq 'official') { - $entry .= ':'.&escape($history{'details'}{'instcode'}); + } + if (ref($history{'details'}) eq 'HASH') { + $entry = $requestkey.':'.$crstype.':'. + &escape($history{'details'}{'cdescr'}); + if ($action eq 'log') { + $entry .= ':'.$uniquecode.':'.$lastupdate.':'; + if ($statusinfo{$key} ne '') { + $entry .= $statusinfo{$key}; + } elsif ($status ne '') { + $entry .= $status; + } else { + $entry .= $disposition; } } - if ($entry ne '') { - if (exists($queue_by_date{$timestamp})) { - if (ref($queue_by_date{$timestamp}) eq 'ARRAY') { - push(@{$queue_by_date{$timestamp}},$entry); - } - } else { - @{$queue_by_date{$timestamp}} = ($entry); + if ($crstype eq 'official') { + $entry .= ':'.&escape($history{'details'}{'instcode'}); + } + } + if ($entry ne '') { + if (exists($queue_by_date{$reqtime})) { + if (ref($queue_by_date{$reqtime}) eq 'ARRAY') { + push(@{$queue_by_date{$reqtime}},$entry); } + } else { + @{$queue_by_date{$reqtime}} = ($entry); } } } } - $formname = 'requestcrs'; + return %queue_by_date; +} + +sub print_request_status { + my ($dom,$action) = @_; + my %queue_by_date = &sorted_request_history($dom,$action); my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date)); - $output = ''."\n". + my $formname = 'requestcrs'; + my ($types,$typenames) = &Apache::loncommon::course_types(); + my $output = ''."\n". ''."\n". ''."\n". ''."\n". ''."\n"; if (@sortedtimes > 0) { + my $desctitle; + if ($env{'form.crstype'} eq 'any') { + $desctitle = &mt('Course/Community Description') + } elsif ($env{'form.crstype'} eq 'community') { + $desctitle = &mt('Community Description') + } else { + $desctitle = &mt('Course Description'); + } $output .= &Apache::loncommon::start_data_table(). &Apache::loncommon::start_data_table_header_row(). ''.&mt('Previous [_1] changes',$curr{'show'}).' | '); + } + if ($more_records) { + $r->print(''.&mt('Next [_1] changes',$curr{'show'}).' | '); + } + $r->print('
'. + &mt('There are no records to display'). + '
'); + } + if ($usetabs) { + $r->print(''); + } + $r->print(''.
+ ''.&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('Not all requested personnel could be included.').'
'.&mt('Name').' | '. @@ -1589,7 +3099,7 @@ sub print_review { '
---|
'.&mt('Include?').' '. @@ -1769,6 +3334,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). + '
'.$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();
+ 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';
- $output = &mt('Your course request has been processed and the course has been created.').
- ''. - &mt('You will need to logout and log-in again to be able to select a role in the course.'); - } 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.'). + my $role_result = &update_requestors_roles($dom,$cnum,$crstype,$details, + \%longroles); + 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'});
+ }
+ }
+ }
+ unless ($customized) {
+ $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'}); if ($userreqhash{$statuskey} ne '') { $modified = 1; - my %queuehash = &Apache::lonnet::get_dom('courserequestqueue', - [$cnum.'_approval', - $cnum.'_pending'],$dom); + my $uname = &Apache::lonnet::get_domainconfiguser($dom); + my %queuehash = &Apache::lonnet::get('courserequestqueue', + [$cnum.'_approval', + $cnum.'_pending'],$dom,$uname); 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; @@ -2135,39 +3960,230 @@ sub print_request_outcome { } } } - my ($storeresult,$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); + $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'}; + } } - } 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 ($validationerror ne '') { + $output .= ' '.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).' '; } - if ($modified && $queued && $storeresult eq 'ok') { - $output .= ''.&mt('Your course request has been updated').' '. - ¬ification_information($disposition,$req_notifylist,$cnum,$now); + if ($updateresult) { + $output .= $updateresult; } - if ($validationerror ne '') { - $output .= ''.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).''; + } + if ($creationresult ne '') { + return ($creationresult,$output,$customized); + } else { + 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; + } + } } } +} + +sub update_requestors_roles { + my ($dom,$cnum,$crstype,$details,$longroles) = @_; + my $now = time; + my ($active,$future,$numactive,$numfuture,$output); + my $owner = $env{'user.name'}.':'.$env{'user.domain'}; + if (ref($details) eq 'HASH') { + if (ref($details->{'personnel'}) eq 'HASH') { + 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); + } + } 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\//) { + $showrole = &Apache::lonnet::plaintext($role,$crstype); + } elsif (ref($longroles) eq 'HASH') { + if ($longroles->{$role} ne '') { + $showrole = $longroles->{$role}; + } + } + if ($start <= $now) { + $active .= '
'; + } + if ($future) { + 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 .= '
'.
+ 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 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 .= ''.&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'; } @@ -2326,11 +4382,14 @@ sub check_autolimit { } sub retrieve_settings { - my ($dom,$cnum) = @_; - my ($result,%reqinfo) = &get_request_settings($dom,$cnum); + my ($dom,$cnum,$udom,$uname) = @_; + if ($udom eq '' || $uname eq '') { + $udom = $env{'user.domain'}; + $uname = $env{'user.name'}; + } + my ($result,%reqinfo) = &get_request_settings($dom,$cnum,$udom,$uname); if ($result eq 'ok') { - if (($env{'user.name'} eq $reqinfo{'owner'}) && - ($env{'user.domain'} eq $reqinfo{'domain'})) { + if (($udom eq $reqinfo{'domain'}) && ($uname eq $reqinfo{'owner'})) { $env{'form.chome'} = $reqinfo{'coursehome'}; $env{'form.cdescr'} = $reqinfo{'cdescr'}; $env{'form.crstype'} = $reqinfo{'crstype'}; @@ -2345,18 +4404,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') { @@ -2432,12 +4504,11 @@ sub retrieve_settings { } sub get_request_settings { - my ($dom,$cnum) = @_; + my ($dom,$cnum,$udom,$uname) = @_; my $requestkey = $dom.'_'.$cnum; my ($result,%reqinfo); if ($requestkey =~ /^($match_domain)_($match_courseid)$/) { - my %history = &Apache::lonnet::restore($requestkey,'courserequests', - $env{'user.domain'},$env{'user.name'}); + my %history = &Apache::lonnet::restore($requestkey,'courserequests',$udom,$uname); my $disposition = $history{'disposition'}; if (($disposition eq 'approval') || ($disposition eq 'pending')) { if (ref($history{'details'}) eq 'HASH') { @@ -2488,5 +4559,796 @@ 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(' ');
+ }
+ }
+
+#
+# Course request form
+#
+
+#
+# Course Title
+#
+ $r->print(' '.
+ ''.
+ ' ');
+
+#
+# Content source selection, if more than one available
+#
+ if (keys(%cloneable) || keys(%ordered) || keys(%domcloneable)) {
+ $r->print(''.
+ ' ');
+ }
+
+ my %accesstitles = (
+ 'start' => 'Default start access',
+ 'end' => 'Default end access',
+ );
+ my %help_item = (
+ start => 'Course_Request_Access_Start',
+ end => 'Course_Request_Access_End',
+ );
+ my $starttime = time;
+ my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
+ my $startform = &Apache::lonhtmlcommon::date_setter('requestcourse','accessstart',
+ $starttime,'','','',1,'','','',1);
+ my $endform = &Apache::lonhtmlcommon::date_setter('requestcourse','accessend',
+ $endtime,'','','',1,'','','',1);
+#
+# Set default start and end dates for student access
+#
+ $r->print(''.
+ ' ');
+
+#
+# Display any custom fields for this course type
+#
+ if (ref($postprocess) eq 'HASH') {
+ if ($postprocess->{'reviewweb'}) {
+ $r->print($postprocess->{'reviewweb'});
+ }
+ }
+
+#
+# Submit button
+#
+ $r->print(''.
+ ''.
+ '');
+
+#
+# End request form
+#
+
+ if (($crstype eq 'lti') && (ref($formhash) eq 'HASH')) {
+ foreach my $item (keys(%{$formhash})) {
+ $r->print(''."\n");
+ }
+ }
+
+ $r->print(''.
+ ' | '.$namestr.' | '.
+ &Apache::loncommon::end_data_table_row();
+ }
+ }
+ }
+ if ($output) {
+ return &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row().
+ ''.&mt('Title').' | '.
+ ''.&mt('Owner/co-owner(s)').' | '.
+ &Apache::loncommon::end_data_table_header_row().
+ $output.
+ &Apache::loncommon::end_data_table();
+ }
+ return;
+}
+
+sub process_textbook_request {
+ my ($r,$dom,$action,$domdefs,$domconfig,$can_request,$crstype) = @_;
+ my ($uniquecode,$req_notifylist);
+ if ($crstype eq '') {
+ $crstype = 'textbook';
+ }
+ if (ref($domconfig) eq 'HASH') {
+ 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};
+ }
+ }
+ }
+ my $now = time;
+ my $reqtype = $env{'form.cloning'};
+ my (@inststatuses,$storeresult,$creationresult);
+ my $cnum = &Apache::lonnet::generate_coursenum($dom,'Course');
+ my ($clonefrom,$clonedom,$clonecrs);
+ if ($reqtype eq 'textbook') {
+ $clonefrom = $env{'form.book'};
+ } elsif ($reqtype eq 'template') {
+ $clonefrom = $env{'form.template'};
+ } elsif ($reqtype eq 'existing') {
+ $clonefrom = $env{'form.owned'};
+ } elsif ($reqtype eq 'colleague') {
+ $clonefrom = $env{'form.colleague'};
+ }
+ my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
+ if ($clonefrom) {
+ ($clonedom,$clonecrs) = split(/_/,$clonefrom);
+ if (&Apache::lonnet::homeserver($clonecrs,$clonedom) ne 'no_host') {
+ my $canclone =
+ &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
+ $env{'user.domain'},$clonecrs,$clonedom,$crstype,$dom);
+ unless ($canclone) {
+ undef($clonecrs);
+ undef($clonedom);
+ }
+ } else {
+ undef($clonecrs);
+ undef($clonedom);
+ }
+ }
+ my $js = &processing_javascript();
+ my ($loaditems,$args);
+ $loaditems = {
+ onload => 'javascript:hideProcessing();',
+ };
+ if ($crstype eq 'lti') {
+ $args = { 'only_body' => 1};
+ }
+ $r->print(&header('Course Creation',$js,$loaditems,undef,$args));
+
+ unless ($crstype eq 'lti') {
+ 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(
+ { href => '/adm/requestcourse',
+ text => "Create Course",
+ }
+ );
+ &Apache::lonhtmlcommon::add_breadcrumb({text=>'Request Processed'});
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests'));
+ &startContentScreen($r,'textbookrequests');
+ }
+
+ my $details = {
+ owner => $env{'user.name'},
+ domain => $env{'user.domain'},
+ cdom => $dom,
+ cnum => $cnum,
+ coursehome => $env{'form.chome'},
+ cdescr => $env{'form.cdescr'},
+ crstype => $crstype,
+ uniquecode => $uniquecode,
+ clonedom => $clonedom,
+ clonecrs => $clonecrs,
+ accessstart => $accessstart,
+ accessend => $accessend,
+ personnel => {},
+ };
+ if (($clonecrs ne '') && ($clonedom ne '')) {
+ if ($reqtype eq 'existing') {
+ $details->{datemode} = $env{'form.owndatemode'};
+ if ($details->{datemode} eq 'shift') {
+ $details->{dateshift} = $env{'form.owndateshift'};
+ } else {
+ $details->{dateshift} = '';
+ }
+ } elsif ($reqtype eq 'colleague') {
+ $details->{datemode} = $env{'form.colldatemode'};
+ if ($details->{datemode} eq 'shift') {
+ $details->{dateshift} = $env{'form.colldateshift'};
+ } else {
+ $details->{dateshift} = '';
+ }
+ } elsif (($reqtype eq 'textbook') || ($reqtype eq 'template')) {
+ $details->{datemode} = 'delete';
+ $details->{dateshift} = '';
+ }
+ if ($details->{dateshift} ne '') {
+ $details->{dateshift} =~ s/[^\d\.]+//g;
+ }
+ } else {
+ $details->{datemode} = '';
+ $details->{dateshift} = '';
+ }
+ my $lonhost = $r->dir_config('lonHostID');
+ $r->rflush();
+ my ($result,$output,$customized) = &process_request($r,$lonhost,$dom,$cnum,$crstype,$now,$details,
+ '',$req_notifylist,[],$domconfig);
+ $r->print($output);
+ if ($crstype eq 'lti') {
+ my %consumers = &Apache::lonnet::get_dom('lticonsumers',[$env{'form.sourcecrs'}],$dom);
+ if (($env{'form.lti.sourcecrs'} ne '') && ($consumers{$env{'form.lti.sourcecrs'}} eq '') && ($cnum ne '')) {
+ &Apache::lonnet::put_dom('lticonsumers',{ $env{'form.lti.sourcecrs'} => $cnum },$dom);
+ }
+ } elsif (&Apache::loncoursequeueadmin::author_prompt()) {
+ unless ($customized) {
+ &print_author_prompt($r,$action,$cnum,$dom,$crstype,$result);
+ }
+ } elsif ($result eq 'created') {
+ unless ($customized) {
+ $r->print(''.&mt('Create another course').' '); + } + } + unless ($crstype eq 'lti') { + &endContentScreen($r); + } + $r->print(&Apache::loncommon::end_page()); +} + +sub textbook_request_javascript { + my ($numprefab,$numcurrent,$numcolleague,$customvalidationjs) = @_; + return unless (ref($numprefab) eq 'HASH'); + return if (!$numprefab->{'textbooks'} && !$numprefab->{'templates'} && !$numcurrent && !$numcolleague); + my %js_lt = &Apache::lonlocal::texthash( + choose => 'Please select a content option.', + textbook => 'Please select a textbook, or choose a different option.', + template => 'Please select a template, or choose a different option.', + existing => 'Please select one of your existing courses to copy, or choose a different option.', + colleague => "Please select a colleague's course to copy, or choose a different option.", + title => 'Please enter a course title.', + ); + &js_escape(\%js_lt); + return <<"ENDSCRIPT"; +function cloneChoice() { + if (document.requestcourse.cloning) { + var radioLength = document.requestcourse.cloning.length; + if (radioLength == undefined) { + var val = document.requestcourse.cloning.value; + if ((val == 'textbook') || (val == 'template') || (val == 'existing') || (val == 'colleague')) { + var elem = document.getElementById('show'+val); + if (document.requestcourse.cloning.checked) { + elem.style.display = 'block'; + } else { + uncheckRadio(val); + elem.style.display = 'none'; + } + } + } else { + for (var i=0; i'.
+ ' '.
+ &Apache::loncommon::end_page());
+ return;
+}
+
+sub startContentScreen {
+ my ($r,$mode)=@_;
+ $r->print("\n".''.&mt('You do not have privileges to request creation of textbook courses.').' '); + if (ref($can_request) eq 'HASH') { + if (scalar(keys(%{$can_request})) > 1) { + $r->print(''.&mt('Go back').''); + } + } + $r->print('
');
+}
+
+sub endContentScreen {
+ my ($r)=@_;
+ $r->print(' |