--- loncom/interface/lonrequestcourse.pm	2018/08/17 23:19:03	1.104
+++ loncom/interface/lonrequestcourse.pm	2025/03/18 19:32:43	1.119
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Request a course
 #
-# $Id: lonrequestcourse.pm,v 1.104 2018/08/17 23:19:03 raeburn Exp $
+# $Id: lonrequestcourse.pm,v 1.119 2025/03/18 19:32:43 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();
@@ -329,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();
             }
         }
     }
@@ -442,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);
@@ -569,6 +564,7 @@ sub form_elements {
                 clonedom         => 'selectbox',
                 datemode         => 'radio',
                 dateshift        => 'text',
+                tinyurls         => 'radio',
             },
             enrollment  => {
                 accessstart_month  => 'selectbox',
@@ -730,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;
 }
@@ -2418,7 +2411,7 @@ sub print_cancel_request {
                       &Apache::loncommon::start_data_table_row().
                       '<td>'.$history{details}{'cdescr'}.'</td><td>'.
                       &Apache::lonlocal::locallocaltime($timestamp).'</td>'.
-                      '<td>'.$showtype.'</td>'.
+                      '<td>'.&mt($showtype).'</td>'.
                       &Apache::loncommon::end_data_table_row().
                       &Apache::loncommon::end_data_table().
                       '<br /><div class="LC_warning">';
@@ -2733,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>&nbsp;&nbsp;</td>';
     my $startform =
@@ -2772,7 +2765,7 @@ sub requestlog_display_filter {
                         $typename = $typenames->{$crstype};
                     }
                 }
-                $output .= '<option value="'.$crstype.'"'.$selstr.'>'.$typename.'</option>'."\n";
+                $output .= '<option value="'.$crstype.'"'.$selstr.'>'.&mt($typename).'</option>'."\n";
             }
             $output .= '</select></td>';
         }
@@ -2948,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$/) && 
@@ -2960,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'}.'&nbsp;';
                 my $cloneinst = $courseenv{'internal.coursecode'};
                 if ($cloneinst ne '') {
@@ -2976,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>';
@@ -3207,7 +3209,7 @@ sub clone_form {
     } 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>'.
@@ -3224,20 +3226,38 @@ sub clone_form {
         '</label><br /><label>'.
         '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
         $lt{'shd'}.'</label>'.
-        '<input type="text" size="5" name="dateshift" value="365" />'.
+        '<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 {
@@ -3263,7 +3283,7 @@ sub coursecode_form {
         }
         if (@{$codetitles} > 0) {
             my $lastitem = pop(@{$codetitles});
-            my $lastinput = '<input type="text" size="5" name="'.$sel.'_'.                                            $lastitem.'" />';
+            my $lastinput = '<input type="text" size="5" name="'.$sel.'_'.$lastitem.'" />';
             if (@{$codetitles} > 0) {
                 my $helplink;
                 if (defined($helpitem{$context})) {
@@ -3371,14 +3391,14 @@ sub get_course_dom {
                     return $env{'user.domain'};
                 }
             }
-            my (@possible_doms,%willtrust,%trustchecked);
+            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);
-                        unless ($trustchecked{$extdom}) {
+                        unless (exists($willtrust{$extdom})) {
                             $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$env{'user.domain'},$extdom);
                         }
                         if ($willtrust{$extdom}) {
@@ -3669,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'}, 
@@ -3684,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,
@@ -3817,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';
@@ -3826,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'}) {
@@ -3850,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'};
             }
@@ -3869,7 +3919,7 @@ sub process_request {
                 if (($code) || ((ref($postprocess) eq 'HASH') && 
                                 (($postprocess->{'createdweb'}) || ($postprocess->{'createdmsg'})))) {
                     $output .= &notification_information($disposition,$env{'user.name'}.':'.$env{'user.domain'},
-                                                         $dom,$cnum,$now,$code,$postprocess);
+                                                         $dom,$cnum,$now,$code,$postprocess,$crstype);
                 }
                 if ($code) {
                     $reqhash{'code'} = $code;
@@ -3886,7 +3936,39 @@ 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) {
+                    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 = '<span class="LC_error">';
                 if ($crstype eq 'community') {
@@ -3950,7 +4032,7 @@ sub process_request {
                     unless ($disposition eq 'pending') { 
                         $output .= '<br />'.
                                    &notification_information($disposition,$req_notifylist,
-                                                             $dom,$cnum,$now);
+                                                             $dom,$cnum,$now,'','',$crstype);
                     }
                 } else {
                     $reqstatus = 'domainerror';
@@ -3983,25 +4065,25 @@ sub process_request {
                     $output .= '<p>'.&mt('Your course request has been updated').'</p>';
                 }
                 if ($disposition eq 'approval') {
-                    $output .= &notification_information($disposition,$req_notifylist,$dom,$cnum,$now);
+                    $output .= &notification_information($disposition,$req_notifylist,$dom,$cnum,$now,'','',$crstype);
                 }
             }
             if ($disposition eq 'approval') {
                 if ((ref($postprocess) eq 'HASH') && 
                     ((ref($postprocess->{'queuedmsg'}) eq 'HASH') || ($postprocess->{'queuedweb'}))) { 
-                    &notification_information($disposition,undef,$dom,$cnum,$now,undef,$postprocess);
+                    &notification_information($disposition,undef,$dom,$cnum,$now,undef,$postprocess,$crstype);
                     $customized = $postprocess->{'createdcustomized'};
                 }
             } elsif ($disposition eq 'pending') {
                 my $pendingform;
                 if ($crstype ne 'official') {
-                    $pendingform = &pending_validation_form($dom,$cnum,$crstype,$now,$token,
+                    $pendingform = &pending_validation_form($r,$dom,$cnum,$crstype,$now,$token,
                                                             $lonhost,$env{'form.cdescr'});
                 }
                 if ($pendingform) {
                     $output .= $pendingform;
                 } else { 
-                    $output .= &notification_information($disposition,undef,$dom,$cnum,$now,undef,$postprocess);
+                    $output .= &notification_information($disposition,undef,$dom,$cnum,$now,undef,$postprocess,$crstype);
                 }
                 if (ref($postprocess) eq 'HASH') {
                     $customized = $postprocess->{'createdcustomized'};
@@ -4022,6 +4104,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'));  
@@ -4183,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 '')) {
@@ -4199,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)) {
+            &notify_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') {
@@ -4285,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 {
@@ -4296,8 +4428,54 @@ 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 ($cdom,$cnum,$crstype,$now,$token,$lonhost,$cdesc) = @_;
+    my ($r,$cdom,$cnum,$crstype,$now,$token,$lonhost,$cdesc) = @_;
     my $output;
     my %postvalues = (
                       'owner'      => $env{'user.name'}.':'.$env{'user.domain'},
@@ -4330,9 +4508,12 @@ 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 $alias = &Apache::lonnet::use_proxy_alias($r,$lonhost);
+                $hostname = $alias if ($alias ne '');
+                my $crscreator = $protocol.'://'.$hostname.'/cgi-bin/createpending.pl';
                 $output .= '<input type="hidden" name="crscreator" value="'.$crscreator.'" />'."\n".
                            '<input type="hidden" name="token" value="'.$token.'" />'."\n".
                            '<input type="submit" name="validate" value="'.$buttontext.'" />'."\n".
@@ -4408,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'};
@@ -4818,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="365" />'.
+                  '<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>');
     }
 #
@@ -4837,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="365" />'.
+                  '<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>');
     }
 
@@ -5039,15 +5237,11 @@ sub process_textbook_request {
             undef($clonedom);
         }
     }
-    my $js = &processing_javascript();
-    my ($loaditems,$args);
-    $loaditems = {
-                   onload => 'javascript:hideProcessing();',
-                 };
+    my $args;
     if ($crstype eq 'lti') {
        $args = { 'only_body' => 1};
     }
-    $r->print(&header('Course Creation',$js,$loaditems,undef,$args));
+    $r->print(&header('Course Creation','','',undef,$args));
 
     unless ($crstype eq 'lti') {
         if (ref($can_request) eq 'HASH') {
@@ -5091,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') {
@@ -5098,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;
@@ -5108,6 +5305,7 @@ sub process_textbook_request {
     } else {
         $details->{datemode} = '';
         $details->{dateshift} = '';
+        $details->{tinyurls} = '';
     }
     my $lonhost = $r->dir_config('lonHostID');
     $r->rflush();
@@ -5115,9 +5313,18 @@ sub process_textbook_request {
                                                         '',$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);
+        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) {