--- loncom/interface/lonrequestcourse.pm 2014/04/16 14:40:17 1.78 +++ loncom/interface/lonrequestcourse.pm 2015/03/26 14:16:11 1.86 @@ -1,7 +1,7 @@ # The LearningOnline Network # Request a course # -# $Id: lonrequestcourse.pm,v 1.78 2014/04/16 14:40:17 raeburn Exp $ +# $Id: lonrequestcourse.pm,v 1.86 2015/03/26 14:16:11 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -172,13 +172,29 @@ sub handler { if ($can_request{'textbook'}) { &process_textbook_request($r,$dom,$action,\%domdefs,\%domconfig,\%can_request); } else { - &textbook_request_disabled($r,$dom,\%can_request); + &textbook_request_disabled($r,$dom,$action,\%can_request); + } + } elsif ($action eq 'display') { + my ($uname,$udom,$result,$warning) = &domcoord_display($dom); + if ($warning ne '') { + my $args = { only_body => 1 }; + $r->print(&header('Course/Community Requests','','' ,'',$args). + '

'.&mt('Course/Community Request Details').'

'. + '
'.$warning.'
'. + &close_popup_form()); + } else { + $states{'display'} = ['details']; + my $loaditems = &onload_action($action,$state); + my $page = 0; + &request_administration($r,$action,$state,$page,\%states,$dom,$jscript, + $loaditems,'','','','','',$showcredits,'','', + $uname,$udom); } } else { if ($can_request{'textbook'}) { &print_textbook_form($r,$dom,\@incdoms,\%domdefs,$domconfig{'requestcourses'},\%can_request); } else { - &textbook_request_disabled($r,$dom,\%can_request); + &textbook_request_disabled($r,$dom,$action,\%can_request); } } return OK; @@ -232,46 +248,7 @@ sub handler { my ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description) = &get_breadcrumbs($dom,$action,\$state,\%states,\%trail); if ($action eq 'display') { - if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) { - if ($env{'form.cnum'} ne '') { - my $cnum = $env{'form.cnum'}; - my $queue = $env{'form.queue'}; - my $reqkey = $cnum.'_'.$queue; - my $namespace = 'courserequestqueue'; - my $domconfig = &Apache::lonnet::get_domainconfiguser($dom); - my %queued = - &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig); - if (ref($queued{$reqkey}) eq 'HASH') { - $uname = $queued{$reqkey}{'ownername'}; - $udom = $queued{$reqkey}{'ownerdom'}; - if (($udom =~ /^$match_domain$/) && ($uname =~ /^$match_username$/)) { - $result = &retrieve_settings($dom,$cnum,$udom,$uname); - } else { - if ($env{'form.crstype'} eq 'community') { - $warning = &mt('Invalid username or domain for community requestor'); - } else { - $warning = &mt('Invalid username or domain for course requestor'); - } - } - } else { - if ($env{'form.crstype'} eq 'community') { - $warning = &mt('No information was found for this community request.'); - } else { - $warning = &mt('No information was found for this course request.'); - } - } - } else { - $warning = &mt('No course request ID provided.'); - } - } else { - if ($env{'form.crstype'} eq 'any') { - $warning = &mt('You do not have rights to view course or community request information.'); - } elsif ($env{'form.crstype'} eq 'community') { - $warning = &mt('You do not have rights to view community request information.'); - } else { - $warning = &mt('You do not have rights to view course request information.'); - } - } + ($uname,$udom,$result,$warning) = &domcoord_display($dom); } elsif ((defined($state)) && (defined($action))) { if (($action eq 'view') && ($state eq 'details')) { if ((defined($env{'form.showdom'})) && (defined($env{'form.cnum'}))) { @@ -334,6 +311,8 @@ sub handler { $jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored); if ($state eq 'courseinfo') { $jscript .= &cloning_javascript(); + } elsif ($state eq 'process') { + $jscript .= &processing_javascript(); } } } @@ -436,7 +415,7 @@ function setCloneDisplay(courseForm) { for (var i=0; i{$action}}; $i++) { - if ($$state eq $states->{$action}[$i]) { - &Apache::lonhtmlcommon::add_breadcrumb( - {text=>"$trail->{$$state}"}); - $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests'); - last; - } else { - if (($$state eq 'process') || ($$state eq 'removal') || ($$state eq 'reqauthor')) { + if (ref($states->{$action}) eq 'ARRAY') { + for (my $i=0; $i<@{$states->{$action}}; $i++) { + if ($$state eq $states->{$action}[$i]) { &Apache::lonhtmlcommon::add_breadcrumb( - { href => '/adm/requestcourse', - text => "$trail->{$states->{$action}[$i]}", - } - ); + {text=>"$trail->{$$state}"}); + $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests'); + last; } else { - &Apache::lonhtmlcommon::add_breadcrumb( + if (($$state eq 'process') || ($$state eq 'removal') || ($$state eq 'reqauthor')) { + &Apache::lonhtmlcommon::add_breadcrumb( + { href => '/adm/requestcourse', + text => "$trail->{$states->{$action}[$i]}", + } + ); + } else { + &Apache::lonhtmlcommon::add_breadcrumb( { href => "javascript:backPage(document.requestcrs,'$states->{$action}[$i]')", text => "$trail->{$states->{$action}[$i]}", } - ); - } - } - } + ); + } + } + } + } } else { &Apache::lonhtmlcommon::add_breadcrumb( {text=>'Pick Action'}); @@ -720,6 +712,9 @@ sub onload_action { if ($state eq 'courseinfo') { $loaditems{'onload'} .= 'javascript:setCloneDisplay(document.requestcrs);'; } + if ($state eq 'process') { + $loaditems{'onload'} .= 'javascript:hideProcessing();'; + } } return \%loaditems; } @@ -1129,6 +1124,52 @@ END return; } +sub domcoord_display { + my ($dom) = @_; + my ($uname,$udom,$result,$warning); + if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) { + if ($env{'form.cnum'} ne '') { + my $cnum = $env{'form.cnum'}; + my $queue = $env{'form.queue'}; + my $reqkey = $cnum.'_'.$queue; + my $namespace = 'courserequestqueue'; + my $domconfig = &Apache::lonnet::get_domainconfiguser($dom); + my %queued = + &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig); + if (ref($queued{$reqkey}) eq 'HASH') { + $uname = $queued{$reqkey}{'ownername'}; + $udom = $queued{$reqkey}{'ownerdom'}; + if (($udom =~ /^$match_domain$/) && ($uname =~ /^$match_username$/)) { + $result = &retrieve_settings($dom,$cnum,$udom,$uname); + } else { + if ($env{'form.crstype'} eq 'community') { + $warning = &mt('Invalid username or domain for community requestor'); + } else { + $warning = &mt('Invalid username or domain for course requestor'); + } + } + } else { + if ($env{'form.crstype'} eq 'community') { + $warning = &mt('No information was found for this community request.'); + } else { + $warning = &mt('No information was found for this course request.'); + } + } + } else { + $warning = &mt('No course request ID provided.'); + } + } else { + if ($env{'form.crstype'} eq 'any') { + $warning = &mt('You do not have rights to view course or community request information.'); + } elsif ($env{'form.crstype'} eq 'community') { + $warning = &mt('You do not have rights to view community request information.'); + } else { + $warning = &mt('You do not have rights to view course request information.'); + } + } + return ($uname,$udom,$result,$warning); +} + sub enrollment_lcsec_js { my %alerts = §ion_check_alerts(); my $secname = $alerts{'badsec'}; @@ -1527,7 +1568,7 @@ sub print_request_form { \%cat_order,\@code_order); } my $lonhost = $r->dir_config('lonHostID'); - my ($storeresult,$result) = &print_request_outcome($lonhost,$dom,\@codetitles, + my ($storeresult,$result) = &print_request_outcome($r,$lonhost,$dom,\@codetitles, \@code_order,$instcredits); $r->print($result); if (($storeresult eq 'ok') || ($storeresult eq 'created')) { @@ -3336,7 +3377,7 @@ sub display_navbuttons { } sub print_request_outcome { - my ($lonhost,$dom,$codetitles,$code_order,$instcredits) = @_; + my ($r,$lonhost,$dom,$codetitles,$code_order,$instcredits) = @_; my ($output,$cnum,$now,$req_notifylist,$crstype,$enrollstart,$enrollend, %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig, $uniquecode); @@ -3581,13 +3622,13 @@ sub print_request_outcome { accessend => $accessend, personnel => \%personnel, }; - my ($result,$output) = &process_request($lonhost,$dom,$cnum,$crstype,$now,$details,$instcode, + my ($result,$output) = &process_request($r,$lonhost,$dom,$cnum,$crstype,$now,$details,$instcode, $req_notifylist,\@instsections,\%domconfig); return ($result,$output); } sub process_request { - my ($lonhost,$dom,$cnum,$crstype,$now,$details,$instcode,$req_notifylist,$instsections, + my ($r,$lonhost,$dom,$cnum,$crstype,$now,$details,$instcode,$req_notifylist,$instsections, $domconfig) = @_; my (@inststatuses,$storeresult,$creationresult,$output); my $val = @@ -3629,6 +3670,11 @@ sub process_request { $dom,$crstype,$limit,\$message); } elsif ($val eq 'validate') { my ($inststatuslist,$validationchk,$validation,%custominfo); + if (ref($details) eq 'HASH') { + if ($details->{'clonecrs'}) { + $custominfo{'_LC_clonefrom'} = $details->{'clonedom'}.'_'.$details->{'clonecrs'}; + } + } if (@inststatuses > 0) { $inststatuslist = join(',',@inststatuses); } @@ -3717,6 +3763,15 @@ sub process_request { foreach my $role (@roles) { $longroles{$role}=&Apache::lonnet::plaintext($role,$type); } + $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'}; + } + } my ($result,$postprocess) = &Apache::loncoursequeueadmin::course_creation($dom,$cnum, 'autocreate',$details,\$logmsg,\$newusermsg,\$addresult, \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles, @@ -3739,6 +3794,14 @@ sub process_request { if ($code) { $reqhash{'code'} = $code; } + if (ref($postprocess) eq 'HASH') { + if (ref($postprocess->{'createdactions'}) eq 'HASH') { + if (ref($postprocess->{'createdactions'}{'environment'}) eq 'HASH') { + &Apache::loncoursequeueadmin::postprocess_crsenv($dom,$cnum, + $postprocess->{'createdactions'}{'environment'}); + } + } + } $output .= '
'.$role_result.'

'; $creationresult = 'created'; } else { @@ -4385,25 +4448,26 @@ sub generate_date_items { sub print_textbook_form { my ($r,$dom,$incdoms,$domdefs,$settings,$can_request) = @_; - my ($bookshash,%ordered); + my (%prefab,%ordered,%numprefab); my $crstype = 'textbook'; # -# Retrieve list of textbook courses cloneable by user +# Retrieve list of prefabricated courses (textbook courses and templates) cloneable by user # - my $numbook; - if (ref($settings) eq 'HASH') { - $bookshash = $settings->{'textbooks'}; - if (ref($bookshash) eq 'HASH') { - foreach my $item (keys(%{$bookshash})) { - my ($clonedom,$clonecrs) = split(/_/,$item); - if (ref($bookshash->{$item}) eq 'HASH') { + 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 (&Apache::loncoursequeueadmin::can_clone_course($env{'user.name'}, - $env{'user.domain'},$clonecrs,$clonedom,$crstype)) { - - my $num = $bookshash->{$item}{'order'}; - $ordered{$num} = $item; - $numbook ++; + if (ref($prefab{$type}{$item}) eq 'HASH') { + if (&Apache::loncoursequeueadmin::can_clone_course($env{'user.name'}, + $env{'user.domain'},$clonecrs,$clonedom,$crstype)) { + + my $num = $prefab{$type}{$item}{'order'}; + $ordered{$type}{$num} = $item; + $numprefab{$type} ++; + } } } } @@ -4439,7 +4503,7 @@ sub print_textbook_form { my $numcurrent = scalar(keys(%cloneable)); - my $jscript = &textbook_request_javascript($numbook,$numcurrent); + my $jscript = &textbook_request_javascript(\%numprefab,$numcurrent); my %loaditems; $loaditems{'onload'} = 'javascript:uncheckAllRadio();'; $r->print(&header('Course Request',$jscript,\%loaditems)); @@ -4490,9 +4554,16 @@ sub print_textbook_form { $r->print('
'. '
'.&mt('Course Content').''); if (keys(%ordered)) { - $r->print(''.(' 'x2).' '); + if (ref($ordered{'textbooks'}) eq 'HASH') { + $r->print(''.(' 'x2).' '); + } + if (ref($ordered{'templates'}) eq 'HASH') { + $r->print(''.(' 'x2).' '); + } } if (keys(%cloneable)) { $r->print('