--- loncom/interface/lonrequestcourse.pm 2016/04/02 04:30:21 1.96 +++ loncom/interface/lonrequestcourse.pm 2020/02/12 22:15:40 1.108 @@ -1,7 +1,7 @@ # The LearningOnline Network # Request a course # -# $Id: lonrequestcourse.pm,v 1.96 2016/04/02 04:30:21 raeburn Exp $ +# $Id: lonrequestcourse.pm,v 1.108 2020/02/12 22:15:40 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,6 +131,10 @@ 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','queue','tabs']); &Apache::lonhtmlcommon::clear_breadcrumbs(); @@ -155,6 +163,23 @@ sub handler { } 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.').'

'. + '
'. + &Apache::loncommon::end_page()); + } + } + return OK; + } if (($env{'form.crstype'} eq 'textbook') || (scalar(keys(%can_request)) == 1) && ($can_request{'textbook'})) { my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom); @@ -192,7 +217,8 @@ sub handler { } } else { if ($can_request{'textbook'}) { - &print_textbook_form($r,$dom,\@incdoms,\%domdefs,$domconfig{'requestcourses'},\%can_request); + &print_textbook_form($r,$dom,\@incdoms,\%domdefs,$domconfig{'requestcourses'}, + \%can_request,'textbook'); } else { &textbook_request_disabled($r,$dom,$action,\%can_request); } @@ -2109,14 +2135,27 @@ sub print_personnel_menu { $output .= &Apache::lonhtmlcommon::row_headline(). '

'.&Apache::loncommon::help_open_topic('Course_Request_Personnel').' '.$lt{$crstype}.' '.&mt('Include other personnel?').'

'; } - for (my $i=0; $i<$persontotal; $i++) { + my $cansearch = 1; + my @alldoms = &Apache::lonnet::all_domains(); + if (@alldoms == 1) { + my %domsrch = &Apache::lonnet::get_dom('configuration', + ['directorysrch'],$alldoms[0]); + if (ref($domsrch{'directorysrch'}) eq 'HASH') { + if ((!$domsrch{'directorysrch'}{'available'}) && + ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) { + $cansearch = 0; + } + } + } + my ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$dom); + for (my $i=0; $i<$persontotal; $i++) { my @linkargs = map { 'person_'.$i.'_'.$_ } (@items); my $linkargstr = join("','",@linkargs); my $uname_form = ''; my $onchange = 'javascript:fix_domain('."'$formname','person_".$i."_dom',". "'person_".$i."_hidedom','person_".$i."_uname'".');'; my $udom_form = &Apache::loncommon::select_dom_form($dom,'person_'.$i.'_dom','', - 1,$onchange). + 1,$onchange,undef,$trusted,$untrusted). ''; my %form_elems; foreach my $item (@items) { @@ -2133,9 +2172,14 @@ sub print_personnel_menu { } $sectionselector .= $newtitle. ''."\n"; - my $usersrchlinktxt = &mt('Search for user'); - my $usersrchlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom, - $usersrchlinktxt); + my $usersrchlink; + if ($cansearch) { + my $usersrchlinktxt = &mt('Search for user'); + $usersrchlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom, + $usersrchlinktxt); + } else { + $usersrchlink = ' '; + } my $userchklinktxt = &mt('Check username'); my $userchklink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom, $userchklinktxt,'checkusername'); @@ -3168,6 +3212,8 @@ sub clone_form { my $type = 'Course'; if ($crstype eq 'community') { $type = 'Community'; + } elsif ($crstype eq 'placement') { + $type = 'Placement'; } my %lt = &clone_text(); my $output .= @@ -3175,7 +3221,7 @@ sub clone_form { &Apache::loncommon::select_dom_form($dom,'clonedom').''. &Apache::lonhtmlcommon::row_closure(1). &Apache::lonhtmlcommon::row_title($lt{'cid'}).' '. &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type). &Apache::lonhtmlcommon::row_closure(1). @@ -3225,7 +3271,7 @@ sub coursecode_form { } if (@{$codetitles} > 0) { my $lastitem = pop(@{$codetitles}); - my $lastinput = ''; + my $lastinput = ''; if (@{$codetitles} > 0) { my $helplink; if (defined($helpitem{$context})) { @@ -3333,18 +3379,23 @@ sub get_course_dom { return $env{'user.domain'}; } } - my @possible_doms; + my (@possible_doms,%willtrust); foreach my $type (@{$types}) { my $dom_str = $env{'environment.reqcrsotherdom.'.$type}; if ($dom_str ne '') { my @domains = split(',',$dom_str); foreach my $entry (@domains) { my ($extdom,$extopt) = split(':',$entry); - if ($extdom eq $env{'request.role.domain'}) { - return $extdom; - } - unless(grep(/^\Q$extdom\E$/,@possible_doms)) { - push(@possible_doms,$extdom); + unless (exists($willtrust{$extdom})) { + $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$env{'user.domain'},$extdom); + } + if ($willtrust{$extdom}) { + if ($extdom eq $env{'request.role.domain'}) { + return $extdom; + } + unless(grep(/^\Q$extdom\E$/,@possible_doms)) { + push(@possible_doms,$extdom); + } } } } @@ -3844,6 +3895,24 @@ sub process_request { } $output .= '

'; $creationresult = 'created'; + # Flush the course logs so reverse user roles immediately updated + unless ($registered_flush) { + my $handlers = $r->get_handlers('PerlCleanupHandler'); + $r->set_handlers('PerlCleanupHandler' => [\&Apache::lonnet::flushcourselogs,@{$handlers}]); + $registered_flush=1; + } + if ($instcode ne '') { + &Apache::lonnet::devalidate_cache_new('instcats',$dom); + # Update cache of self-cataloging courses on institution's server(s). + if (&Apache::lonnet::shared_institution($dom)) { + unless ($registered_instcats) { + my $handlers = $r->get_handlers('PerlCleanupHandler'); + $r->set_handlers('PerlCleanupHandler' => [\&devalidate_remote_instcats,@{$handlers}]); + $registered_instcats=1; + $modified_dom = $dom; + } + } + } } else { $output = ''; if ($crstype eq 'community') { @@ -3979,6 +4048,22 @@ sub process_request { } } +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')); @@ -4287,9 +4372,10 @@ sub pending_validation_form { $buttontext = &mt('Create course'); } } + my $hostname = &Apache::lonnet::hostname($lonhost); my $protocol = $Apache::lonnet::protocol{$lonhost}; $protocol = 'http' if ($protocol ne 'https'); - my $crscreator = $protocol.'://'.&Apache::lonnet::hostname($lonhost).'/cgi-bin/createpending.pl'; + my $crscreator = $protocol.'://'.$hostname.'/cgi-bin/createpending.pl'; $output .= ''."\n". ''."\n". ''."\n". @@ -4516,9 +4602,11 @@ sub generate_date_items { } sub print_textbook_form { - my ($r,$dom,$incdoms,$domdefs,$settings,$can_request) = @_; + my ($r,$dom,$incdoms,$domdefs,$settings,$can_request,$crstype,$formhash) = @_; my (%prefab,%ordered,%numprefab); - my $crstype = 'textbook'; + if ($crstype eq '') { + $crstype = 'textbook'; + } # # Retrieve list of prefabricated courses (textbook courses and templates) cloneable by user # @@ -4578,7 +4666,7 @@ sub print_textbook_form { owner => $courseinfo{'internal.courseowner'}, releaserequired => $courseinfo{'internal.releaserequired'}, type => $courseinfo{'type'}, - }; + }; } } @@ -4635,31 +4723,37 @@ sub print_textbook_form { my $jscript = &textbook_request_javascript(\%numprefab,$numcurrent,$numdomcourses,$customvalidationjs); $jscript .= $customjs; - my %loaditems; + my (%loaditems,$args); $loaditems{'onload'} = 'javascript:uncheckAllRadio();'.$customonload; - $r->print(&header('Course Request',$jscript,\%loaditems)); + 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'})) { + unless (((scalar(keys(%{$can_request})) == 1) && ($can_request->{'textbook'})) || + ($crstype eq 'lti')) { &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')); + unless ($crstype eq 'lti') { + &Apache::lonhtmlcommon::add_breadcrumb({text=>'Course Request'}); + $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests')); - &startContentScreen($r,'textbookrequests'); + &startContentScreen($r,'textbookrequests'); # # Show domain selector form, if required. # - if (@{$incdoms} > 1) { - my $onchange = 'this.form.submit()'; - $r->print('
'. - '
'.&mt('Domain').''. - &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange,$incdoms). - '
'); + if (@{$incdoms} > 1) { + my $onchange = 'this.form.submit()'; + $r->print('
'. + '
'.&mt('Domain').''. + &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange,$incdoms). + '
'); + } } # @@ -4839,15 +4933,24 @@ sub print_textbook_form { # # Submit button # - $r->print(''. + $r->print(''. ''. ''); # # End request form # + + if (($crstype eq 'lti') && (ref($formhash) eq 'HASH')) { + foreach my $item (keys(%{$formhash})) { + $r->print(''."\n"); + } + } + $r->print(''); - &endContentScreen($r). + unless ($crstype eq 'lti') { + &endContentScreen($r); + } $r->print(&Apache::loncommon::end_page()); return; } @@ -4934,9 +5037,11 @@ sub clone_selection_table { } sub process_textbook_request { - my ($r,$dom,$action,$domdefs,$domconfig,$can_request) = @_; + my ($r,$dom,$action,$domdefs,$domconfig,$can_request,$crstype) = @_; my ($uniquecode,$req_notifylist); - my $crstype = 'textbook'; + if ($crstype eq '') { + $crstype = 'textbook'; + } if (ref($domconfig) eq 'HASH') { if (ref($domconfig->{'requestcourses'}) eq 'HASH') { if (ref($domconfig->{'requestcourses'}{'notify'}) eq 'HASH') { @@ -4978,27 +5083,33 @@ sub process_textbook_request { } } my $js = &processing_javascript(); - my $loaditems = { - onload => 'javascript:hideProcessing();', - }; - $r->print(&header('Course Creation',$js,$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', - }); + 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'); } - &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'}, @@ -5030,6 +5141,9 @@ sub process_textbook_request { } else { $details->{dateshift} = ''; } + } elsif (($reqtype eq 'textbook') || ($reqtype eq 'template')) { + $details->{datemode} = 'delete'; + $details->{dateshift} = ''; } if ($details->{dateshift} ne '') { $details->{dateshift} =~ s/[^\d\.]+//g; @@ -5043,7 +5157,12 @@ sub process_textbook_request { my ($result,$output,$customized) = &process_request($r,$lonhost,$dom,$cnum,$crstype,$now,$details, '',$req_notifylist,[],$domconfig); $r->print($output); - if (&Apache::loncoursequeueadmin::author_prompt()) { + 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); } @@ -5052,7 +5171,9 @@ sub process_textbook_request { $r->print('

'.&mt('Create another course').'

'); } } - &endContentScreen($r); + unless ($crstype eq 'lti') { + &endContentScreen($r); + } $r->print(&Apache::loncommon::end_page()); }