--- loncom/interface/lonrequestcourse.pm 2021/12/14 02:54:52 1.95.2.7 +++ loncom/interface/lonrequestcourse.pm 2025/01/10 22:45:55 1.118 @@ -1,7 +1,7 @@ # The LearningOnline Network # Request a course # -# $Id: lonrequestcourse.pm,v 1.95.2.7 2021/12/14 02:54:52 raeburn Exp $ +# $Id: lonrequestcourse.pm,v 1.118 2025/01/10 22:45:55 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -163,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}). + '<div>'. + '<p class="LC_info">'.&mt('You do not have privileges to request creation of LTI courses.').'</p>'. + '</div>'. + &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); @@ -200,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); } @@ -319,8 +337,6 @@ sub handler { $jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored); if ($state eq 'courseinfo') { $jscript .= &cloning_javascript(); - } elsif ($state eq 'process') { - $jscript .= &processing_javascript(); } } } @@ -432,17 +448,6 @@ function setCloneDisplay(courseForm) { END } -sub processing_javascript { - return <<"END"; -function hideProcessing() { - if (document.getElementById('processing')) { - document.getElementById('processing').style.display="none"; - } -} - -END -} - sub get_breadcrumbs { my ($dom,$action,$state,$states,$trail) = @_; my ($crumb,$newinstcode,$codechk,$checkedcode,$numtitles,$description); @@ -559,6 +564,7 @@ sub form_elements { clonedom => 'selectbox', datemode => 'radio', dateshift => 'text', + tinyurls => 'radio', }, enrollment => { accessstart_month => 'selectbox', @@ -720,9 +726,6 @@ sub onload_action { if ($state eq 'courseinfo') { $loaditems{'onload'} .= 'javascript:setCloneDisplay(document.requestcrs);'; } - if ($state eq 'process') { - $loaditems{'onload'} .= 'javascript:hideProcessing();'; - } } return \%loaditems; } @@ -768,6 +771,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})) { @@ -781,6 +785,7 @@ END 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.', ); @@ -810,9 +815,16 @@ END return false; } } else { - if (actionchoice == 'new') { - alert('$js_lt{'all'}'+'\\n'+'$js_lt{'allt'}'); - return false; + if (crschoice == 'placement') { + if (placement != 1) { + alert("$js_lt{'placement'}"); + return false; + } + } else { + if (actionchoice == 'new') { + alert('$js_lt{'all'}'+'\\n'+'$js_lt{'allt'}'); + return false; + } } } } @@ -823,7 +835,7 @@ END END my ($pagetitle,$pageinfo,$domaintitle,$earlyout); if (ref($can_request) eq 'HASH') { - if (($can_request->{'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.'); @@ -1000,6 +1012,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'); } @@ -2101,7 +2115,8 @@ 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(). '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Personnel').' '.$lt{$crstype}.' '.&mt('Include other personnel?').'</h3>'; } @@ -2117,14 +2132,15 @@ sub print_personnel_menu { } } } - for (my $i=0; $i<$persontotal; $i++) { + 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 = '<input type="text" name="person_'.$i.'_uname" value="" size="20" />'; 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). '<input type="hidden" name="person_'.$i.'_hidedom" value="" />'; my %form_elems; foreach my $item (@items) { @@ -2529,7 +2545,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; @@ -2697,7 +2713,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'); @@ -2710,7 +2726,7 @@ sub requestlog_display_filter { my $nolink = 1; my $output = '<table><tr><td valign="top">'. '<span class="LC_nobreak"><b>'.&mt('Records/page:').'</b></span><br />'. - &Apache::lonmeta::selectbox('show',$curr->{'show'},undef, + &Apache::lonmeta::selectbox('show',$curr->{'show'},'',undef, (&mt('all'),5,10,20,50,100,1000,10000)). '</td><td> </td>'; my $startform = @@ -2925,7 +2941,7 @@ sub print_review { $inst_values .= '<td>'.$env{'form.coursecredits'}.'</td>'; } - my %ctxt = &clone_text(); + my %ctxt = &clone_text($env{'form.crstype'}); $inst_headers .= '<th>'.&mt('Clone From').'</th>'; if (($env{'form.cloning'}) && ($env{'form.clonecrs'} =~ /^$match_name$/) && @@ -2937,7 +2953,8 @@ sub print_review { my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'}, $env{'form.clonecrs'},('description','internal.coursecode')); if (keys(%courseenv) > 0) { - $inst_headers .= '<th>'.$ctxt{'dsh'}.'</th>'; + $inst_headers .= '<th>'.$ctxt{'dsh'}.'</th>'. + '<th>'.$ctxt{'dpl'}.'</th>'; $inst_values .= '<td>'.$courseenv{'description'}.' '; my $cloneinst = $courseenv{'internal.coursecode'}; if ($cloneinst ne '') { @@ -2953,6 +2970,14 @@ sub print_review { } else { $inst_values .= $ctxt{'ncd'}; } + $inst_values .= '</td><td>'; + if ($env{'form.tinyurls'} eq 'delete') { + $inst_values .= $ctxt{'nsl'}; + } elsif ($env{'form.tinyurls'} eq 'transfer') { + $inst_values .= $ctxt{'tsl'}; + } else { + $inst_values .= $ctxt{'csl'}; + } $inst_values .= '</td>'; } else { $inst_values .= '<td>'.&mt('Unknown').'</td>'; @@ -3101,6 +3126,7 @@ sub courseinfo_form { &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"; <script type="text/javascript"> // <![CDATA[' @@ -3180,8 +3206,10 @@ sub clone_form { my $type = 'Course'; if ($crstype eq 'community') { $type = 'Community'; + } elsif ($crstype eq 'placement') { + $type = 'Placement'; } - my %lt = &clone_text(); + my %lt = &clone_text($crstype); my $output .= &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'<label>'. &Apache::loncommon::select_dom_form($dom,'clonedom').'</label>'. @@ -3199,19 +3227,37 @@ sub clone_form { '<input type="radio" name="datemode" value="shift" checked="checked" /> '. $lt{'shd'}.'</label>'. '<input type="text" size="5" name="dateshift" value="364" />'. + &Apache::lonhtmlcommon::row_closure(1). + &Apache::lonhtmlcommon::row_title($lt{'dpl'}).'<label>'. + '<input type="radio" name="tinyurls" value="delete" /> '.$lt{'nsl'}. + '</label><br /><label>'. + '<input type="radio" name="tinyurls" value="transfer" /> '.$lt{'tsl'}. + '</label><br /><label>'. + '<input type="radio" name="tinyurls" value="create" checked="checked" /> '.$lt{'csl'}. + '</label>'. &Apache::lonhtmlcommon::row_closure(1); return $output; } sub clone_text { - return &Apache::lonlocal::texthash( + my ($crstype) = @_; + my %lt = &Apache::lonlocal::texthash( 'cid' => 'Course ID', 'dmn' => 'Domain', 'dsh' => 'Date Shift', 'ncd' => 'Do not clone date parameters', 'prd' => 'Clone date parameters as-is', 'shd' => 'Shift date parameters by number of days', - ); + 'dpl' => 'URL shortcuts (for deep linking)', + 'nsl' => 'Do not clone URL shortcuts', + 'tsl' => 'Transfer URL shortcuts from existing course to new course', + 'csl' => 'Create new URL shortcuts in new course', + ); + if ($crstype eq 'Community') { + $lt{'tsl'} = &mt('Transfer URL shortcuts from existing course to new community'); + $lt{'csl'} = &mt('Create new URL shortcuts in new course'); + } + return %lt; } sub coursecode_form { @@ -3345,18 +3391,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); + } } } } @@ -3638,6 +3689,19 @@ sub print_request_outcome { } } } + if ($env{'form.chome'} eq 'default') { + my %servers = &Apache::lonnet::get_servers($dom,'library'); + my $numlib = keys(%servers); + if ($numlib) { + my $loadm=10000000; + my $chome; + foreach my $tryserver (keys(%servers)) { + ($chome,$loadm) = + &Apache::lonnet::compare_server_load($tryserver,$chome,$loadm); + } + $env{'form.chome'} = $chome; + } + } my $details = { owner => $env{'user.name'}, domain => $env{'user.domain'}, @@ -3653,6 +3717,7 @@ sub print_request_outcome { clonecrs => $clonecrs, datemode => $env{'form.datemode'}, dateshift => $env{'form.dateshift'}, + tinyurls => $env{'form.tinyurls'}, sectotal => $sectotal, sections => \%sections, crosslisttotal => $crosslisttotal, @@ -3669,7 +3734,7 @@ sub print_request_outcome { $instcode,$req_notifylist,\@instsections,\%domconfig); return ($result,$output,$customized); } - + sub process_request { my ($r,$lonhost,$dom,$cnum,$crstype,$now,$details,$instcode,$req_notifylist,$instsections, $domconfig) = @_; @@ -3687,6 +3752,8 @@ sub process_request { $output = &mt('You are not permitted to request creation of communities'); } elsif ($crstype eq 'textbook') { $output = &mt('You are not permitted to request creation of textbook courses'); + } elsif ($crstype eq 'placement') { + $output = &mt('You are not permitted to request creation of placement tests'); } else { $output = &mt('Unrecognized course type: [_1]',$crstype); } @@ -3784,7 +3851,9 @@ sub process_request { $storeresult = 'rejected'; } elsif ($disposition eq 'process') { my %domdefs = &Apache::lonnet::get_domain_defaults($dom); - my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles,$code); + my ($logmsg,$newusermsg,$addresult,$enrollcount,$response, + $keysmsg,%longroles,$code); + my $clonemsg = []; my $type = 'Course'; if ($crstype eq 'community') { $type = 'Community'; @@ -3793,9 +3862,20 @@ sub process_request { foreach my $role (@roles) { $longroles{$role}=&Apache::lonnet::plaintext($role,$type); } - $r->print('<div id="processing" style="display:block;">'."\n". - &mt('Your request is being processed; this page will update when processing is complete.'). - '</div>'); + my $preamble = '<div id="LC_update" class="LC_info">'. + '<br />'. + &mt("Please be patient while your request is processed"). + '<br /></div>'. + '<div style="padding:0;clear:both;margin:0;border:0"></div>'; + my $closure = <<ENDCLOSE; +<script type="text/javascript"> +// <![CDATA[ +\$("#LC_update").hide('slow'); +// ]]> +</script> +ENDCLOSE + my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,undef,$preamble); + &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Processing ...')); $r->rflush(); if (ref($details) eq 'HASH') { if ($details->{'clonecrs'}) { @@ -3817,9 +3897,12 @@ sub process_request { $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); + 'autocreate',$details,\$logmsg,$clonemsg,\$newusermsg, + \$addresult,\$enrollcount,\$response,\$keysmsg,\%domdefs, + \%longroles,\$code,\%customitems); + &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Finished!')); + &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state); + $r->print($closure); if (ref($postprocess) eq 'HASH') { $customized = $postprocess->{'createdcustomized'}; } @@ -3836,7 +3919,7 @@ sub process_request { 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); + $dom,$cnum,$now,$code,$postprocess,$crstype); } if ($code) { $reqhash{'code'} = $code; @@ -3853,6 +3936,20 @@ sub process_request { $output .= '<br />'.$role_result; } $output .= '</p>'; + if ($logmsg) { + $output .= '<p>'.$logmsg.'</p>'; + } + if ((ref($clonemsg) eq 'ARRAY') && (@{$clonemsg})) { + $output .= '<p class="LC_info">'; + 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}}).'<br />'."\n"; + } + } + $output .= '</p>'."\n"; + } $creationresult = 'created'; # Flush the course logs so reverse user roles immediately updated unless ($registered_flush) { @@ -3935,7 +4032,7 @@ sub process_request { unless ($disposition eq 'pending') { $output .= '<br />'. ¬ification_information($disposition,$req_notifylist, - $dom,$cnum,$now); + $dom,$cnum,$now,'','',$crstype); } } else { $reqstatus = 'domainerror'; @@ -3968,13 +4065,13 @@ sub process_request { $output .= '<p>'.&mt('Your course request has been updated').'</p>'; } if ($disposition eq 'approval') { - $output .= ¬ification_information($disposition,$req_notifylist,$dom,$cnum,$now); + $output .= ¬ification_information($disposition,$req_notifylist,$dom,$cnum,$now,'','',$crstype); } } 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); + ¬ification_information($disposition,undef,$dom,$cnum,$now,undef,$postprocess,$crstype); $customized = $postprocess->{'createdcustomized'}; } } elsif ($disposition eq 'pending') { @@ -3986,7 +4083,7 @@ sub process_request { if ($pendingform) { $output .= $pendingform; } else { - $output .= ¬ification_information($disposition,undef,$dom,$cnum,$now,undef,$postprocess); + $output .= ¬ification_information($disposition,undef,$dom,$cnum,$now,undef,$postprocess,$crstype); } if (ref($postprocess) eq 'HASH') { $customized = $postprocess->{'createdcustomized'}; @@ -4184,7 +4281,7 @@ sub update_requestors_roles { } sub notification_information { - my ($disposition,$req_notifylist,$dom,$cnum,$now,$code,$postprocess) = @_; + my ($disposition,$req_notifylist,$dom,$cnum,$now,$code,$postprocess,$crstype) = @_; my %emails = &Apache::loncommon::getemails(); my $address; if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) { @@ -4200,12 +4297,46 @@ sub notification_information { if ($address ne '') { $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />'; } + my %possemails; + my $fullname = &Apache::loncommon::plainname($env{'user.name'}, + $env{'user.domain'}); + my $emailto = &Apache::loncommon::build_recipient_list(undef,'requestsmail',$dom); + if ($emailto) { + map { $possemails{$_} = 1; } (split(/,/,$emailto)); + } if ($req_notifylist) { - my $fullname = &Apache::loncommon::plainname($env{'user.name'}, - $env{'user.domain'}); + if ($emailto) { + foreach my $recip (split(/,/,$req_notifylist)) { + my ($uname,$udom) = split(/:/,$recip); + my %emails = &Apache::loncommon::getemails($uname,$udom); + foreach my $type ('permanentemail','notification') { + if ((exists($emails{$type})) && ($emails{$type} ne '')) { + my @to = split(/,/,$emails{$type}); + foreach my $addr (@to) { + if (($addr ne '') && ($addr =~ m/\@/)) { + if (exists($possemails{$addr})) { + delete($possemails{$addr}); + } + } + } + } + } + } + } my $sender = $env{'user.name'}.':'.$env{'user.domain'}; &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})", - 'undef',$env{'form.cdescr'},$now,'coursereq',$sender); + undef,$env{'form.cdescr'},$now,'coursereq',$sender,'','',$crstype); + } +# +# If domain configuration for "E-mail addresses and helpform" has values set +# for "E-mail from course requests requiring approval", send email to those +# addresse(es) when a course request is queued, pending approval, unless +# the email address will already receive a notification email, because of +# values set for "Receive notification of course requests requiring approval" +# in "Request creation of courses" configuration item. +# + if ($emailto && keys(%possemails)) { + ¬ify_admin($dom,$crstype,$env{'form.cdescr'},"$fullname ($env{'user.name'}:$env{'user.domain'})",$now,\%possemails); } if (ref($postprocess) eq 'HASH') { if (ref($postprocess->{'queuedmsg'}) eq 'ARRAY') { @@ -4286,7 +4417,7 @@ sub notification_information { $type = 'uniquecode'; } &Apache::loncoursequeueadmin::send_selfserve_notification($recipient,$addmsg,$dom.'_'.$cnum,$env{'form.cdescr'}, - $now,$type,$sender); + $now,$type,$sender,'','',$crstype); } } } else { @@ -4297,6 +4428,52 @@ sub notification_information { return $output; } +sub notify_admin { + my ($dom,$crstype,$contextdesc,$textstr,$timestamp,$emailsref) = @_; + if ((ref($emailsref) eq 'HASH') && (keys(%{$emailsref}))) { + my $emailto = join(',',sort(keys(%{$emailsref}))); + my (@rawmsg,$rawsubj,$msgtxt); + if ($crstype eq 'community') { + $rawsubj = 'Community request to review'; + $msgtxt = 'Creation of the following community: [_1]was requested by [_2] on [_3].'; + } else { + $rawsubj = 'Course request to review'; + $msgtxt = 'Creation of the following course: [_1]was requested by [_2] on [_3].'; + } + $timestamp =&Apache::lonlocal::locallocaltime($timestamp); + push(@rawmsg,{ + mt => $msgtxt, + args => ["\n $contextdesc\n",$textstr,$timestamp], + }, + { + mt =>'[_1]A Domain Coordinator will use: [_2]Main Menu -> Course and community creation -> Approve or reject requests[_3]to display a list of pending requests, which can either be approved or rejected.', + args => ["\n","\n\n","\n\n"], + }); + + my $sender_lh = &Apache::loncommon::user_lang($env{'user.name'},$env{'user.domain'}); + my $subject = &mt_user($sender_lh,$rawsubj); + my $message = ''; + foreach my $item (@rawmsg) { + if (ref($item) eq 'HASH') { + if (ref($item->{args}) eq 'ARRAY') { + $message .= &mt_user($sender_lh,$item->{mt},@{$item->{args}})."\n"; + } else { + $message .= &mt_user($sender_lh,$item->{mt})."\n"; + } + } + } + my $chgmail = "To: $emailto\n". + "Subject: $subject\n". + "Content-type: text/plain\; charset=UTF-8\n". + "MIME-Version: 1.0\n\n". + "$message\n\n"; + if (open(my $mailh, "|/usr/lib/sendmail -oi -t -odb")) { + print $mailh $chgmail; + close($mailh); + } + } +} + sub pending_validation_form { my ($r,$cdom,$cnum,$crstype,$now,$token,$lonhost,$cdesc) = @_; my $output; @@ -4361,7 +4538,7 @@ sub check_autolimit { if (($crstype eq 'community') && (exists($crsroles{$cnum.':'.$cdom.':co'}))) { $count ++; - } elsif ((($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'textbook')) && + } elsif ((($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'textbook') || ($crstype eq 'placement')) && (exists($crsroles{$cnum.':'.$cdom.':cc'}))) { $count ++; } @@ -4412,6 +4589,7 @@ sub retrieve_settings { } $env{'form.datemode'} = $reqinfo{'datemode'}; $env{'form.dateshift'} = $reqinfo{'dateshift'}; + $env{'form.tinyurls'} = $reqinfo{'tinyurls'}; if ($reqinfo{'crstype'} eq 'official') { $env{'form.autoadds'} = $reqinfo{'autoadds'}; $env{'form.autodrops'} = $reqinfo{'autodrops'}; @@ -4563,9 +4741,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 # @@ -4625,7 +4805,7 @@ sub print_textbook_form { owner => $courseinfo{'internal.courseowner'}, releaserequired => $courseinfo{'internal.releaserequired'}, type => $courseinfo{'type'}, - }; + }; } } @@ -4682,31 +4862,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('<form name="domforcourse" method="post" action="/adm/requestcourse">'. - '<div><fieldset><legend>'.&mt('Domain').'</legend>'. - &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange,$incdoms). - '</fieldset></form>'); + if (@{$incdoms} > 1) { + my $onchange = 'this.form.submit()'; + $r->print('<form name="domforcourse" method="post" action="/adm/requestcourse">'. + '<div><fieldset><legend>'.&mt('Domain').'</legend>'. + &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange,$incdoms). + '</fieldset></form>'); + } } # @@ -4814,17 +5000,26 @@ sub print_textbook_form { # # Table of user's current courses (owner and/or course coordinator) # - my %lt = &clone_text(); + my %lt = &clone_text('Course'); if (keys(%cloneable)) { $r->print('<div id="showexisting" style="display:none">'. &clone_selection_table($dom,'owned',\%cloneable). - '<p><input type="radio" name="owndatemode" value="delete" /> '.$lt{'ncd'}. + '<fieldset style="display:inline-block"><legend>'.$lt{'dsh'}.'</legend><label>'. + '<input type="radio" name="owndatemode" value="delete" /> '.$lt{'ncd'}. '</label><br /><label>'. '<input type="radio" name="owndatemode" value="preserve" /> '.$lt{'prd'}. '</label><br /><label>'. '<input type="radio" name="owndatemode" value="shift" checked="checked" /> '. $lt{'shd'}.'</label>'. '<input type="text" size="5" name="owndateshift" value="364" />'. + '</fieldset><fieldset style="display:inline-block">'. + '<legend>'.$lt{'dpl'}.'</legend><label>'. + '<input type="radio" name="owntinyurls" value="delete" />'.$lt{'nsl'}. + '</label><br /><label>'. + '<input type="radio" name="owntinyurls" value="transfer" />'.$lt{'tsl'}. + '</label><br /><label>'. + '<input type="radio" name="owntinyurls" value="create" checked="checked" />'.$lt{'csl'}. + '</label></fieldset>'. '</div>'); } # @@ -4833,13 +5028,20 @@ sub print_textbook_form { if (keys(%domcloneable)) { $r->print('<div id="showcolleague" style="display:none">'. &clone_selection_table($dom,'colleague',\%domcloneable). - '<p><input type="radio" name="colldatemode" value="delete" /> '.$lt{'ncd'}. + '<fieldset style="display:inline-block"><legend>'.$lt{'dsh'}.'</legend><label>'. + '<input type="radio" name="colldatemode" value="delete" /> '.$lt{'ncd'}. '</label><br /><label>'. '<input type="radio" name="colldatemode" value="preserve" /> '.$lt{'prd'}. '</label><br /><label>'. '<input type="radio" name="colldatemode" value="shift" checked="checked" /> '. $lt{'shd'}.'</label>'. '<input type="text" size="5" name="colldateshift" value="364" />'. + '</fieldset><fieldset style="display:inline-block">'. + '<legend>'.$lt{'dpl'}.'</legend><label>'. + '<input type="radio" name="colltinyurls" value="delete" />'.$lt{'nsl'}. + '</label><br /><label>'. + '<input type="radio" name="colltinyurls" value="create" checked="checked" />'.$lt{'csl'}. + '</label></fieldset>'. '</div>'); } @@ -4886,15 +5088,24 @@ sub print_textbook_form { # # Submit button # - $r->print('<input type="hidden" name="crstype" value="textbook" />'. + $r->print('<input type="hidden" name="crstype" value="'.$crstype.'" />'. '<input type="hidden" name="action" value="process" />'. '<input type="submit" value="'.&mt('Create course').'" />'); # # End request form # + + if (($crstype eq 'lti') && (ref($formhash) eq 'HASH')) { + foreach my $item (keys(%{$formhash})) { + $r->print('<input type="hidden" name="'.$item.'" value="'.$formhash->{$item}.'" />'."\n"); + } + } + $r->print('</form>'); - &endContentScreen($r). + unless ($crstype eq 'lti') { + &endContentScreen($r); + } $r->print(&Apache::loncommon::end_page()); return; } @@ -4981,9 +5192,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') { @@ -5024,28 +5237,30 @@ sub process_textbook_request { undef($clonedom); } } - 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 $args; + if ($crstype eq 'lti') { + $args = { 'only_body' => 1}; + } + $r->print(&header('Course Creation','','',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'}, @@ -5070,6 +5285,7 @@ sub process_textbook_request { } else { $details->{dateshift} = ''; } + $details->{tinyurls} = $env{'form.owntinyurls'}; } elsif ($reqtype eq 'colleague') { $details->{datemode} = $env{'form.colldatemode'}; if ($details->{datemode} eq 'shift') { @@ -5077,9 +5293,11 @@ sub process_textbook_request { } else { $details->{dateshift} = ''; } + $details->{tinyurls} = $env{'form.colltinyurls'}; } elsif (($reqtype eq 'textbook') || ($reqtype eq 'template')) { $details->{datemode} = 'delete'; $details->{dateshift} = ''; + $details->{tinyurls} = ''; } if ($details->{dateshift} ne '') { $details->{dateshift} =~ s/[^\d\.]+//g; @@ -5087,13 +5305,28 @@ sub process_textbook_request { } else { $details->{datemode} = ''; $details->{dateshift} = ''; + $details->{tinyurls} = ''; } 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 (&Apache::loncoursequeueadmin::author_prompt()) { + if ($crstype eq 'lti') { + my $storecrs; + if ($env{'request.lti.login'}) { + my %lti = &Apache::lonnet::get_domain_lti($dom,'provider'); + if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') { + $storecrs = $lti{$env{'request.lti.login'}}{'storecrs'}; + } + if ($storecrs) { + 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'} => $env{'request.lti.login'}.':'.$cnum },$dom); + } + } + } + } elsif (&Apache::loncoursequeueadmin::author_prompt()) { unless ($customized) { &print_author_prompt($r,$action,$cnum,$dom,$crstype,$result); } @@ -5102,7 +5335,9 @@ sub process_textbook_request { $r->print('<p><a href="/adm/requestcourse">'.&mt('Create another course').'</a></p>'); } } - &endContentScreen($r); + unless ($crstype eq 'lti') { + &endContentScreen($r); + } $r->print(&Apache::loncommon::end_page()); }