--- loncom/interface/lonrequestcourse.pm 2014/05/19 15:59:55 1.84 +++ loncom/interface/lonrequestcourse.pm 2018/12/27 18:14:25 1.105 @@ -1,7 +1,7 @@ # The LearningOnline Network # Request a course # -# $Id: lonrequestcourse.pm,v 1.84 2014/05/19 15:59:55 raeburn Exp $ +# $Id: lonrequestcourse.pm,v 1.105 2018/12/27 18:14:25 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -155,6 +155,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); @@ -172,7 +189,7 @@ 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); @@ -192,9 +209,10 @@ 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,\%can_request); + &textbook_request_disabled($r,$dom,$action,\%can_request); } } return OK; @@ -476,27 +494,29 @@ sub get_breadcrumbs { } } } - for (my $i=0; $i<@{$states->{$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'}); @@ -758,6 +778,7 @@ function check_can_request(crschoice,act var unofficial = ''; var community = ''; var textbook = ''; + var placement = ''; END if (ref($can_request) eq 'HASH') { foreach my $item (keys(%{$can_request})) { @@ -766,42 +787,51 @@ END "; } } - my %lt = &Apache::lonlocal::texthash( + my %js_lt = &Apache::lonlocal::texthash( official => 'You are not permitted to request creation of an official course in this domain.', unofficial => 'You are not permitted to request creation of an unofficial course in this domain.', community => 'You are not permitted to request creation of a community in this domain.', textbook => 'You are not permitted to request creation of a textbook course in this domain', + placement => 'You are not permitted to request creation of a placement test in this domain', all => 'You must choose a specific course type when making a new course request.', allt => '"All types" is not allowed.', ); + &js_escape(\%js_lt); $js .= <{'official'}) || ($can_request->{'unofficial'}) || $can_request->{'textbook'}) { + if (($can_request->{'official'}) || ($can_request->{'unofficial'}) || ($can_request->{'textbook'}) || ($can_request->{'placement'})) { if ($can_request->{'community'}) { $pagetitle = 'Course/Community Requests'; $pageinfo = &mt('Request creation of a new course or community, or review your pending requests.'); @@ -937,7 +967,8 @@ END if ($action eq 'new') { my $jsextra; if (($state eq 'courseinfo') || ($state eq 'codepick')) { - $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom); + $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom,'','','','','', + $newinstcode); } elsif ($state eq 'enrollment') { if (($env{'form.crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) { @@ -988,6 +1019,8 @@ END $title = &mt('Pending requests for unofficial courses'); } elsif ($env{'form.crstype'} eq 'textbook') { $title = &mt('Pending requests for textbook courses'); + } elsif ($env{'form.crstype'} eq 'textbook') { + $title = &mt('Pending requests for placement tests'); } else { $title = &mt('Pending course/community requests'); } @@ -1172,6 +1205,8 @@ sub enrollment_lcsec_js { my %alerts = §ion_check_alerts(); my $secname = $alerts{'badsec'}; my $secnone = $alerts{'reserved'}; + &js_escape(\$secname); + &js_escape(\$secnone); my $output = ' function validateEnrollSections(formname,nextstate) { var badsectotal = 0; @@ -1229,8 +1264,10 @@ function validateEnrollSections(formname sub personnel_lcsec_js { my %alerts = §ion_check_alerts(); - my $secname = $alerts{'badsec'}.'\\n'.$alerts{'separate'}; + my $secname = $alerts{'badsec'}."\n".$alerts{'separate'}; my $secnone = $alerts{'reserved'}; + &js_escape(\$secname); + &js_escape(\$secnone); my $output = ' function validatePersonnelSections(formname,nextstate) { var badsectotal = 0; @@ -1566,8 +1603,8 @@ sub print_request_form { \%cat_order,\@code_order); } my $lonhost = $r->dir_config('lonHostID'); - my ($storeresult,$result) = &print_request_outcome($r,$lonhost,$dom,\@codetitles, - \@code_order,$instcredits); + my ($storeresult,$result,$customized) = &print_request_outcome($r,$lonhost,$dom,\@codetitles, + \@code_order,$instcredits); $r->print($result); if (($storeresult eq 'ok') || ($storeresult eq 'created')) { if ($storeresult eq 'ok') { @@ -1576,10 +1613,14 @@ sub print_request_form { ''.&mt('Make another request').'

'); } if (&Apache::loncoursequeueadmin::author_prompt()) { - &print_author_prompt($r,$env{'form.action'},$env{'form.cnum'},$env{'form.showdom'}, - $env{'form.crstype'},$storeresult); + unless ($customized) { + &print_author_prompt($r,$env{'form.action'},$env{'form.cnum'},$env{'form.showdom'}, + $env{'form.crstype'},$storeresult); + } } elsif ($storeresult eq 'created') { - $r->print('

'.&mt('Make another request').'

'); + unless ($customized) { + $r->print('

'.&mt('Make another request').'

'); + } } } } elsif ($state eq 'reqauthor') { @@ -2081,18 +2122,32 @@ sub print_personnel_menu { official => 'Requestor is automatically assigned Course Coordinator role.', ); $lt{'unofficial'} = $lt{'official'}; - $lt{'textbook'} = $lt{'textbook'}; + $lt{'textbook'} = $lt{'official'}; + $lt{'placement'} = $lt{'official'}; $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) { @@ -2109,9 +2164,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'); @@ -2413,8 +2473,9 @@ ENDJS } sub viewcancel_javascript { - my $alert = &mt('Are you sure you want to cancel this request?').'\\n'. + my $alert = &mt('Are you sure you want to cancel this request?')."\n". &mt('Your request will be removed.'); + &js_escape(\$alert); return << "ENDJS"; function nextPage(formname,nextstate) { if (confirm('$alert')) { @@ -2491,7 +2552,7 @@ sub print_request_logs { if (ref($domconfig{'requestcourses'}) eq 'HASH') { if (ref($domconfig{'requestcourses'}{'uniquecode'}) eq 'HASH') { if ($curr{'crstype'} eq 'any') { - my @types = qw(official unofficial community textbook); + my @types = qw(official unofficial community textbook placement); foreach my $type (@types) { if ($domconfig{'requestcourses'}{'uniquecode'}{$type}) { $showuniquecode = 1; @@ -2659,7 +2720,7 @@ sub reqstatus_names { rejected => 'Request rejected', cancelled => 'Request cancelled', ); - if (($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'textbook')) { + if (($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'textbook') || ($crstype eq 'placement')) { $statusnames{'created'} = &mt('Course created'); } elsif ($crstype eq 'community') { $statusnames{'created'} = &mt('Community created'); @@ -2786,6 +2847,7 @@ sub print_review { my $enrollrow_title = &mt('Default Access Dates').'
'. '('.&Apache::lonnet::plaintext('st',$category).')'; + my $instcode; if ($env{'form.crstype'} eq 'official') { if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH')) { foreach my $title (@{$codetitles}) { @@ -2801,6 +2863,11 @@ sub print_review { } } } + if (ref($code_order) eq 'ARRAY') { + foreach my $item (@{$code_order}) { + $instcode .= $env{'form.instcode_'.$item}; + } + } $inst_headers .= ''.&mt('Credits').''; if ($instcredits) { $inst_values .= ''.$instcredits.''; @@ -2888,7 +2955,7 @@ sub print_review { ($env{'form.clonedom'} =~ /^$match_domain$/)) { my $canclone = &Apache::loncoursequeueadmin::can_clone_course($uname, $udom,$env{'form.clonecrs'},$env{'form.clonedom'}, - $env{'form.crstype'}); + $env{'form.crstype'},$dom,$instcode); if ($canclone) { my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'}, $env{'form.clonecrs'},('description','internal.coursecode')); @@ -3050,19 +3117,21 @@ sub dates_from_form { sub courseinfo_form { my ($dom,$formname,$crstype,$next,$description) = @_; - my %lt = &Apache::lonlocal::texthash( + my %js_lt = &Apache::lonlocal::texthash( official => 'You must provide a (brief) course description.', community => 'You must provide a (brief) community description.' ); - $lt{'unofficial'} = $lt{'official'}; - $lt{'textbook'} = $lt{'official'}; + &js_escape(\%js_lt); + $js_lt{'unofficial'} = $js_lt{'official'}; + $js_lt{'textbook'} = $js_lt{'official'}; + $js_lt{'placement'} = $js_lt{'official'}; my $js_validate = <<"ENDJS";