--- loncom/interface/lonrequestcourse.pm	2015/06/09 21:22:57	1.89
+++ 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.89 2015/06/09 21:22:57 damieng Exp $
+# $Id: lonrequestcourse.pm,v 1.118 2025/01/10 22:45:55 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}).
+                              '<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);
@@ -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);
                 }
@@ -311,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();
             }
         }
     }
@@ -424,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);
@@ -551,6 +564,7 @@ sub form_elements {
                 clonedom         => 'selectbox',
                 datemode         => 'radio',
                 dateshift        => 'text',
+                tinyurls         => 'radio',
             },
             enrollment  => {
                 accessstart_month  => 'selectbox',
@@ -712,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;
 }
@@ -760,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})) {
@@ -773,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.',
     ); 
@@ -802,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;
+                        }
                     }
                 }
             }
@@ -815,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.');
@@ -992,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'); 
             }
@@ -1574,8 +1596,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') {
@@ -1584,10 +1606,14 @@ sub print_request_form {
                           '<a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
             }
             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('<p><a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
+                unless ($customized) {
+                    $r->print('<p><a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
+                }
             }
         }
     } elsif ($state eq 'reqauthor') {
@@ -2089,18 +2115,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().
                   '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Personnel').'&nbsp;'.$lt{$crstype}.' '.&mt('Include other personnel?').'</h3>';
     }
-    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 = '<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) {
@@ -2117,9 +2157,14 @@ sub print_personnel_menu {
         }
         $sectionselector .= $newtitle.
             '<input type="text" name="person_'.$i.'_newsec" size="15" value="" />'."\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 = '&nbsp;';
+        }
         my $userchklinktxt = &mt('Check username');
         my $userchklink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
                             $userchklinktxt,'checkusername');
@@ -2366,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">';
@@ -2500,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;
@@ -2668,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');
@@ -2681,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 =
@@ -2720,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>';
         }
@@ -2896,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$/) && 
@@ -2908,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 '') {
@@ -2924,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>';
@@ -3072,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['
@@ -3151,14 +3206,16 @@ 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>'.
         &Apache::lonhtmlcommon::row_closure(1).
         &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
-        '<input type="text" size="25" name="clonecrs" value="" onfocus="this.blur();opencrsbrowser('."'$formname','clonecrs','clonedom','','','','','$type'".')" />'.
+        '<input type="text" size="25" name="clonecrs" value="" onfocus="this.blur();opencrsbrowser('."'$formname','clonecrs','clonedom','','','','$type'".')" />'.
         '</label>&nbsp;'.
         &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type).
         &Apache::lonhtmlcommon::row_closure(1).
@@ -3169,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 {
@@ -3208,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})) {
@@ -3316,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);
+                            }
                         }
                     }
                 }
@@ -3609,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'}, 
@@ -3624,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,
@@ -3636,15 +3730,15 @@ sub print_request_outcome {
                     accessend      => $accessend,
                     personnel      => \%personnel,
                   };
-    my ($result,$output) = &process_request($r,$lonhost,$dom,$cnum,$crstype,$now,$details,$instcode,
-                                            $req_notifylist,\@instsections,\%domconfig);
-    return ($result,$output);
+    my ($result,$output,$customized) = &process_request($r,$lonhost,$dom,$cnum,$crstype,$now,$details,
+                                                        $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) = @_; 
-    my (@inststatuses,$storeresult,$creationresult,$output);
+    my (@inststatuses,$storeresult,$creationresult,$output,$customized);
     my $val = 
         &Apache::loncoursequeueadmin::get_processtype('course',$env{'user.name'},
                                                       $env{'user.domain'},$env{'user.adv'},
@@ -3658,12 +3752,14 @@ 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);
         }
         $storeresult = 'notpermitted'; 
     } else {
-        my ($disposition,$message,$reqstatus,$coursedesc);
+        my ($disposition,$message,$reqstatus,$coursedesc,$accessstart,$accessend,%customvalidation);
         my %reqhash = (
                         reqtime   => $now,
                         crstype   => $crstype,
@@ -3675,6 +3771,8 @@ sub process_request {
                                                      $env{'user.domain'});
         if (ref($details) eq 'HASH') {
             $coursedesc = $details->{'cdescr'};
+            $accessstart = $details->{'accessstart'};
+            $accessend = $details->{'accessend'};
         }
         if ($val eq 'autolimit=') {
             $disposition = 'process';
@@ -3683,10 +3781,10 @@ sub process_request {
             $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
                                             $dom,$crstype,$limit,\$message);
         } elsif ($val eq 'validate') {
-            my ($inststatuslist,$validationchk,$validation,%custominfo);
+            my ($inststatuslist,$validationchk,$validation);
             if (ref($details) eq 'HASH') {
                 if ($details->{'clonecrs'}) {
-                    $custominfo{'_LC_clonefrom'} = $details->{'clonedom'}.'_'.$details->{'clonecrs'};
+                    $customvalidation{'_LC_clonefrom'} = $details->{'clonedom'}.'_'.$details->{'clonecrs'};
                 }
             }
             if (@inststatuses > 0) {
@@ -3698,27 +3796,18 @@ sub process_request {
                     $instseclist = join(',',@{$instsections});
                 }
             }
+#
+# Retrieve any custom form information used for validation 
+#
             my $preprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'prevalidate',$env{'user.name'},
                                                                  $env{'user.domain'},$fullname,$coursedesc);
             if (ref($preprocess) eq 'HASH') {
-                if (ref($preprocess->{'formitems'}) eq 'HASH') {
-                    foreach my $key (keys(%{$preprocess->{'formitems'}})) {
-                        if ($preprocess->{'formitems'}->{$key} eq 'multiple') {
-                            if (exists($env{'form.'.$key})) {
-                                @{$custominfo{$key}} = &Apache::loncommon::get_env_multiple($env{'form.'.$key});
-                            }
-                        } else {
-                            if (exists($env{'form.'.$key})) {
-                                $custominfo{$key} = $env{'form.'.$key};
-                            }
-                        }
-                    }
-                }
+                &custom_formitems($preprocess,\%customvalidation);
             }
             $validationchk = 
                 &Apache::lonnet::auto_courserequest_validation($dom,
                     $env{'user.name'}.':'.$env{'user.domain'},$crstype,
-                    $inststatuslist,$instcode,$instseclist,\%custominfo);
+                    $inststatuslist,$instcode,$instseclist,\%customvalidation);
             if ($validationchk =~ /:/) {
                 ($validation,$message) = split(':',$validationchk);
             } else {
@@ -3735,24 +3824,18 @@ sub process_request {
         }
         $reqhash{'disposition'} = $disposition;
         $reqstatus = $disposition;
-        my ($modified,$queued,$coursedesc,$token,%customitems);
+        my ($modified,$queued,$token,%customitems);
         unless ($disposition eq 'rejected') {
             my $inprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'process',$env{'user.name'},
-                                                                $env{'user.domain'},$fullname,$coursedesc);
+                                                                $env{'user.domain'},$fullname,$coursedesc,undef,
+                                                                undef,undef,\%customvalidation);
+#
+# Retrieve any custom form information submitted with review page and include in request details.
+#
             if (ref($inprocess) eq 'HASH') {
-                if (ref($inprocess->{'formitems'}) eq 'HASH') {
-                    foreach my $key (keys(%{$inprocess->{'formitems'}})) {
-                        if ($inprocess->{'formitems'}->{$key} eq 'multiple') {
-                            if (exists($env{'form.'.$key})) {
-                                @{$customitems{$key}} = &Apache::loncommon::get_env_multiple($env{'form.'.$key});
-                            }
-                        } else {
-                            if (exists($env{'form.'.$key})) {
-                                $customitems{$key} = $env{'form.'.$key};
-                                $reqhash{'custom'}{$key} = $customitems{$key};
-                            }
-                        }
-                    }
+                &custom_formitems($inprocess,\%customitems);
+                foreach my $key (keys(%customitems)) {
+                    $reqhash{'custom'}{$key} = $customitems{$key};
                 }
             }
         }
@@ -3768,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';
@@ -3777,19 +3862,50 @@ 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'}) {
                     $customitems{'_LC_clonefrom'} = $details->{'clonedom'}.'_'.$details->{'clonecrs'};
                 }
             }
+            $customitems{'_LC_ownerfullname'} = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'},'first');
+            my $owneremail;
+            my %emails = &Apache::loncommon::getemails();
+            foreach my $email ('permanentemail','critnotification','notification') {
+                $owneremail = $emails{$email};
+                last if ($owneremail ne '');
+            }
+            if ($owneremail ne '') {
+                $customitems{'_LC_owneremail'} = $owneremail;
+            }
+            $customitems{'_LC_coursedomainname'} = &Apache::lonnet::domain($dom,'description');
+            $customitems{'_LC_coursedescription'} = $coursedesc;
+            $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'};
+            }
             if ($result eq 'created') {
                 $disposition = 'created';
                 $reqstatus = 'created';
@@ -3803,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;
@@ -3816,8 +3932,43 @@ sub process_request {
                         }
                     }
                 }
-                $output .= '<br />'.$role_result.'</p>';
+                unless ($customized) { 
+                    $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') {
@@ -3881,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';
@@ -3914,24 +4065,28 @@ 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'};
                 }
             }
         }
@@ -3943,9 +4098,50 @@ sub process_request {
         }
     }
     if ($creationresult ne '') {
-        return ($creationresult,$output);
+        return ($creationresult,$output,$customized);
     } else {
-        return ($storeresult,$output);
+        return ($storeresult,$output,$customized);
+    }
+}
+
+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'));  
+    if (ref($preprocess->{'formitems'}) eq 'HASH') {
+        foreach my $key (keys(%{$preprocess->{'formitems'}})) {
+            if ($preprocess->{'formitems'}->{$key} eq 'multiple') {
+                if (exists($env{'form.'.$key})) {
+                    my @items = &Apache::loncommon::get_env_multiple($env{'form.'.$key});
+                    foreach my $item (@items) {
+                        $item =~ s/(`)/'/g;
+                        $item =~ s/\$/\(\$\)/g;
+                        push(@{$customhash->{$key}},$item);
+                    }
+                }
+            } else {
+                if (exists($env{'form.'.$key})) {
+                    $customhash->{$key} = $env{'form.'.$key};
+                    $customhash->{$key} =~ s/(`)/'/g;
+                    $customhash->{$key} =~ s/\$/\(\$\)/g;
+                }
+            }
+        }
     }
 }
 
@@ -4085,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 '')) {
@@ -4101,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') {
@@ -4187,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 {
@@ -4198,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'},
@@ -4232,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".
@@ -4259,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 ++;
             }
@@ -4310,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'};
@@ -4461,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
 #
@@ -4499,50 +4781,118 @@ sub print_textbook_form {
     }
 
 #
-# Retrieve information about courses owned by user, or in which user has an active or future 
-# Course Coordinator role 
+# Retrieve information about courses owned by user, or in which user has an active
+# Course Coordinator role
 #
     my $numcurrent;
     my %cloneable = &Apache::lonnet::courseiddump($dom,'.',1,'.',$env{'user.name'}.':'.$env{'user.domain'},
-                                              undef,undef,undef,'Course');
+                                                  '.',undef,undef,'Course');
     my %ccroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
-                                                ['active','future'],['cc']);
+                                                ['active'],['cc']);
+
+    my $cc_clone = '';
     foreach my $role (keys(%ccroles)) {
         my ($cnum,$cdom,$rest) = split(/:/,$role,3);
+        $cc_clone .= $cdom.':'.$cnum.'&';
         unless (exists($cloneable{$cdom.'_'.$cnum})) {
             my %courseinfo = &Apache::lonnet::coursedescription($cdom.'_'.$cnum,{'one_time' => 1});
-            $cloneable{$cdom.'_'.$cnum} = \%courseinfo;
+            $cloneable{$cdom.'_'.$cnum} = {
+                                               context => $courseinfo{'internal.creationcontext'},
+                                               created => $courseinfo{'internal.created'},
+                                               creator => $courseinfo{'internal.creator'},
+                                               description => $courseinfo{'description'},
+                                               inst_code => $courseinfo{'coursecode'},
+                                               owner => $courseinfo{'internal.courseowner'},
+                                               releaserequired => $courseinfo{'internal.releaserequired'},
+                                               type  => $courseinfo{'type'},
+                                          };
         }
     }
 
     my $numcurrent = scalar(keys(%cloneable));
 
-    my $jscript = &textbook_request_javascript(\%numprefab,$numcurrent);
-    my %loaditems;
-    $loaditems{'onload'} = 'javascript:uncheckAllRadio();';
-    $r->print(&header('Course Request',$jscript,\%loaditems));
+#
+# Retrieve information about courses from user's domain which user can clone, but which not owned
+# or cloneable based on Course Coordinator role.
+#
+    my ($numdomcourses,%domcloneable);
+    my %allcloneable = &Apache::lonnet::courseiddump($dom,'.',1,'.','.','.',undef,undef,'Course',
+                                                     undef,undef,undef,undef,undef,
+                                                     $env{'user.name'}.':'.$env{'user.domain'},
+                                                     $cc_clone,1);
+    foreach my $cid (keys(%allcloneable)) {
+        unless (exists($cloneable{$cid})) {
+            $domcloneable{$cid} = $allcloneable{$cid};
+        }
+    }
+    $numdomcourses = scalar(keys(%domcloneable));
+
+    my $fullname = &Apache::loncommon::plainname($env{'user.name'},
+                                                 $env{'user.domain'});
+
+#
+# Retrieve any custom form information prior to rendering page
+#
+
+    my $initprocess = &Apache::lonnet::auto_crsreq_update($dom,undef,$crstype,'initializereview',$env{'user.name'},
+                                                         $env{'user.domain'},$fullname);
+    my %custominit;
+    if (ref($initprocess) eq 'HASH') {
+        &custom_formitems($initprocess,\%custominit);
+    }
+
+#
+# Retrieve any custom onload actions or javascript used for page before rendering
+#
+
+    my ($customonload,$customjs,$customvalidationjs);
+    my $inprocess = &Apache::lonnet::auto_crsreq_update($dom,undef,$crstype,'prereview',$env{'user.name'},
+                                                        $env{'user.domain'},$fullname,undef,undef,
+                                                        undef,undef,\%custominit);
+    if (ref($inprocess) eq 'HASH') {
+        $customonload = $inprocess->{'onload'};
+        $customjs = $inprocess->{'javascript'};
+        $customvalidationjs = $inprocess->{'validationjs'};
+    }
+
+    my $postprocess = &Apache::lonnet::auto_crsreq_update($dom,undef,$crstype,'review',
+                                                          $env{'user.name'},
+                                                          $env{'user.domain'},$fullname,undef,undef,
+                                                          undef,undef,\%custominit);
+
+    my $jscript = &textbook_request_javascript(\%numprefab,$numcurrent,$numdomcourses,$customvalidationjs);
+    $jscript .= $customjs;
+    my (%loaditems,$args);
+    $loaditems{'onload'} = 'javascript:uncheckAllRadio();'.$customonload;
+    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>');
+        }
     }
 
 #
@@ -4564,7 +4914,7 @@ sub print_textbook_form {
 #
 # Content source selection, if more than one available
 #
-    if (keys(%cloneable) || keys(%ordered)) {
+    if (keys(%cloneable) || keys(%ordered) || keys(%domcloneable)) {
         $r->print('<div>'. 
                   '<fieldset><legend>'.&mt('Course Content').'</legend>');
         if (keys(%ordered)) {
@@ -4584,6 +4934,11 @@ sub print_textbook_form {
                       '<input type="radio" name="cloning" value="existing" onclick="javascript:cloneChoice();" />'.
                       &mt('Copy one of your courses').'</label></span>'.('&nbsp;'x2).' ');
         }
+        if (keys(%domcloneable)) {
+            $r->print('<span class="LC_nobreak"><label>'.
+                      '<input type="radio" name="cloning" value="colleague" onclick="javascript:cloneChoice();" />'.
+                      &mt("Copy a colleague's course").'</label></span>'.('&nbsp;'x2).' ');
+        }
         $r->print('<span class="LC_nobreak"><label>'.
                   '<input type="radio" name="cloning" value="none" checked="checked" onclick="javascript:cloneChoice();" />'.
                   &mt('Empty course shell').'</label></span>');
@@ -4645,90 +5000,55 @@ sub print_textbook_form {
 #
 # Table of user's current courses (owner and/or course coordinator)
 #
+    my %lt = &clone_text('Course');
     if (keys(%cloneable)) {
-        my %lt = &clone_text();
         $r->print('<div id="showexisting" style="display:none">'.
-                  &Apache::loncommon::start_data_table().
-                  &Apache::loncommon::start_data_table_header_row().
-                  '<th>'.&mt('Title').'</th>'.
-                  '<th>'.&mt('Owner/co-owner(s)').'</th>'.
-                  &Apache::loncommon::end_data_table_header_row());
-        my %allownernames;
-        my %sortbytitle; 
-        foreach my $cid (sort(keys(%cloneable))) {
-            if (ref($cloneable{$cid}) eq 'HASH') {
-                my $cdesc = $cloneable{$cid}{'description'};
-                $cdesc =~ s/`/'/g;
-                if ($cdesc ne '') {
-                    push(@{$sortbytitle{$cdesc}},$cid);
-                }
-            }
-         }
-         foreach my $title (sort(keys(%sortbytitle))) {
-             if (ref($sortbytitle{$title}) eq 'ARRAY') {
-                foreach my $cid (sort(@{$sortbytitle{$title}})) {
-                    my $cleantitle=&HTML::Entities::encode($title,'<>&"');
-                    $cleantitle=~s/'/\\'/g;
-                    $cleantitle =~ s/^\s+//;
-                    my ($namestr,@owners,%ownernames);
-                    my $singleowner = $cloneable{$cid}{'internal.courseowner'};
-                    push(@owners,$singleowner);
-                    if ($cloneable{$cid}{'co-owners'} ne '') {
-                        foreach my $item (split(/,/,$cloneable{$cid}{'internal.co-owners'})) {
-                            push(@owners,$item);
-                        }
-                    }
-                    foreach my $owner (@owners) {
-                        my ($ownername,$ownerdom);
-                        if ($owner =~ /:/) {
-                            ($ownername,$ownerdom) = split(/:/,$owner);
-                        } else {
-                            $ownername = $owner;
-                            if ($owner ne '') {
-                                $ownerdom = $dom;
-                            }
-                        }
-                        if ($ownername ne '' && $ownerdom ne '') {
-                            if (exists($allownernames{$ownername.':'.$ownerdom})) {
-                                $ownernames{$ownername.':'.$ownerdom} = $allownernames{$ownername.':'.$ownerdom}; 
-                            } else {
-                                my %namehash=&Apache::loncommon::getnames($ownername,$ownerdom);
-                                $ownernames{$ownername.':'.$ownerdom} = \%namehash;
-                                $allownernames{$ownername.':'.$ownerdom} = $ownernames{$ownername.':'.$ownerdom};
-                            }
-                        }
-                    }
-                    my @lastnames;
-                    foreach my $owner (keys(%ownernames)) {
-                        if (ref($ownernames{$owner}) eq 'HASH') {
-                            push(@lastnames,$ownernames{$owner}{'lastname'});
-                        }
-                    }
-                    if (@lastnames) {
-                        $namestr = join(', ',sort(@lastnames));
-                    }
-                    $r->print(&Apache::loncommon::start_data_table_row().
-                              '<td><label><input type="radio" name="owned" value="'.$cid.'" />'.
-                              '&nbsp'.$cleantitle.'</label></td>'.
-                              '<td>'.$namestr.'</td>'.
-                              &Apache::loncommon::end_data_table_row());
-                }
-            }
-        }
-        $r->print(&Apache::loncommon::end_data_table().
-              '<p><input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
-              '</label><br /><label>'.
-              '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
-              '</label><br /><label>'.
-              '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
-              $lt{'shd'}.'</label>'.
-              '<input type="text" size="5" name="dateshift" value="365" />'.
-              '</div>');
+                  &clone_selection_table($dom,'owned',\%cloneable).
+                  '<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>');
     }
 #
+# Table of other cloneable courses from user's domain (exclude own courses)
+#
+    if (keys(%domcloneable)) {
+        $r->print('<div id="showcolleague" style="display:none">'.
+                  &clone_selection_table($dom,'colleague',\%domcloneable).
+                  '<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>');
+    }
+
+#
 # End of content selector
 #
-    if (keys(%cloneable) || keys(%ordered)) {
+    if (keys(%cloneable) || keys(%domcloneable) || keys(%ordered)) {
         $r->print('</fieldset></div>');
     }
 
@@ -4759,11 +5079,6 @@ sub print_textbook_form {
 #
 # Display any custom fields for this course type
 #
-    my $fullname = &Apache::loncommon::plainname($env{'user.name'},
-                                                 $env{'user.domain'});
-    my $postprocess = &Apache::lonnet::auto_crsreq_update($dom,undef,$crstype,'review',
-                                                          $env{'user.name'},
-                                                          $env{'user.domain'},$fullname);
     if (ref($postprocess) eq 'HASH') {
         if ($postprocess->{'reviewweb'}) {
             $r->print($postprocess->{'reviewweb'});
@@ -4773,23 +5088,115 @@ 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;
 }
 
+sub clone_selection_table {
+    my ($dom,$name,$cloneableref) = @_;
+    return unless ((ref($cloneableref) eq 'HASH') && (($name eq 'owned') || ($name eq 'colleague')));
+    my %allownernames;
+    my %sortbytitle;
+    my $output;
+    foreach my $cid (sort(keys(%{$cloneableref}))) {
+        if (ref($cloneableref->{$cid}) eq 'HASH') {
+            my $cdesc = $cloneableref->{$cid}{'description'};
+            $cdesc =~ s/`/'/g;
+            if ($cdesc ne '') {
+                push(@{$sortbytitle{$cdesc}},$cid);
+            }
+        }
+    }
+    foreach my $title (sort(keys(%sortbytitle))) {
+         if (ref($sortbytitle{$title}) eq 'ARRAY') {
+            foreach my $cid (sort(@{$sortbytitle{$title}})) {
+                my $cleantitle=&HTML::Entities::encode($title,'<>&"');
+                $cleantitle=~s/'/\\'/g;
+                $cleantitle =~ s/^\s+//;
+                my ($namestr,@owners,%ownernames);
+                if ($cloneableref->{$cid}{'owner'} ne '') {
+                    push(@owners,$cloneableref->{$cid}{'owner'});
+                }
+                if ($cloneableref->{$cid}{'co-owners'} ne '') {
+                    foreach my $item (split(/,/,$cloneableref->{$cid}{'co-owners'})) {
+                        if (($item ne '') && (!grep(/^\Q$item\E$/,@owners))) {
+                            push(@owners,$item);
+                        }
+                    }
+                }
+                foreach my $owner (@owners) {
+                    my ($ownername,$ownerdom);
+                    if ($owner =~ /:/) {
+                        ($ownername,$ownerdom) = split(/:/,$owner);
+                    } else {
+                        $ownername = $owner;
+                        if ($owner ne '') {
+                            $ownerdom = $dom;
+                        }
+                    }
+                    if ($ownername ne '' && $ownerdom ne '') {
+                        if (exists($allownernames{$ownername.':'.$ownerdom})) {
+                            $ownernames{$ownername.':'.$ownerdom} = $allownernames{$ownername.':'.$ownerdom};
+                        } else {
+                            my %namehash=&Apache::loncommon::getnames($ownername,$ownerdom);
+                            $ownernames{$ownername.':'.$ownerdom} = \%namehash;
+                            $allownernames{$ownername.':'.$ownerdom} = $ownernames{$ownername.':'.$ownerdom};
+                        }
+                    }
+                }
+                my @lastnames;
+                foreach my $owner (keys(%ownernames)) {
+                    if (ref($ownernames{$owner}) eq 'HASH') {
+                        push(@lastnames,$ownernames{$owner}{'lastname'});
+                    }
+                }
+                if (@lastnames) {
+                    $namestr = join(', ',sort(@lastnames));
+                }
+                $output .= &Apache::loncommon::start_data_table_row().
+                           '<td><label><input type="radio" name="'.$name.'" value="'.$cid.'" />'.
+                           '&nbsp;'.$cleantitle.'</label></td>'.
+                           '<td>'.$namestr.'</td>'.
+                           &Apache::loncommon::end_data_table_row();
+            }
+        }
+    }
+    if ($output) {
+        return &Apache::loncommon::start_data_table().
+               &Apache::loncommon::start_data_table_header_row().
+               '<th>'.&mt('Title').'</th>'.
+               '<th>'.&mt('Owner/co-owner(s)').'</th>'.
+               &Apache::loncommon::end_data_table_header_row().
+               $output.
+               &Apache::loncommon::end_data_table();
+    }
+    return;
+}
+
 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') {
@@ -4811,6 +5218,8 @@ sub process_textbook_request {
         $clonefrom = $env{'form.template'};
     } elsif ($reqtype eq 'existing') {
         $clonefrom = $env{'form.owned'};
+    } elsif ($reqtype eq 'colleague') {
+        $clonefrom = $env{'form.colleague'};
     }
     my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
     if ($clonefrom) {
@@ -4828,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'},
@@ -4866,34 +5277,81 @@ sub process_textbook_request {
                     accessend      => $accessend,
                     personnel      => {},
                   };
-    if ($reqtype eq 'existing') {
-        $details->{datemode} = $env{'form.datemode'};
-        $details->{dateshift} = $env{'form.dateshift'};
+    if (($clonecrs ne '') && ($clonedom ne '')) {
+        if ($reqtype eq 'existing') {
+            $details->{datemode} = $env{'form.owndatemode'};
+            if ($details->{datemode} eq 'shift') {
+                $details->{dateshift} = $env{'form.owndateshift'};
+            } else {
+                $details->{dateshift} = '';
+            }
+            $details->{tinyurls} = $env{'form.owntinyurls'};
+        } elsif ($reqtype eq 'colleague') {
+            $details->{datemode} = $env{'form.colldatemode'};
+            if ($details->{datemode} eq 'shift') {
+                $details->{dateshift} = $env{'form.colldateshift'};
+            } 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;
+        }
+    } else {
+        $details->{datemode} = '';
+        $details->{dateshift} = '';
+        $details->{tinyurls} = '';
     }
     my $lonhost = $r->dir_config('lonHostID');
     $r->rflush();
-    my ($result,$output) = &process_request($r,$lonhost,$dom,$cnum,$crstype,$now,$details,'',
-                                            $req_notifylist,[],$domconfig);
+    my ($result,$output,$customized) = &process_request($r,$lonhost,$dom,$cnum,$crstype,$now,$details,
+                                                        '',$req_notifylist,[],$domconfig);
     $r->print($output);
-    if (&Apache::loncoursequeueadmin::author_prompt()) {
-        &print_author_prompt($r,$action,$cnum,$dom,$crstype,$result);
+    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);
+        }
     } elsif ($result eq 'created') {
-        $r->print('<p><a href="/adm/requestcourse">'.&mt('Create another course').'</a></p>');
+        unless ($customized) {
+            $r->print('<p><a href="/adm/requestcourse">'.&mt('Create another course').'</a></p>');
+        }
+    }
+    unless ($crstype eq 'lti') {
+        &endContentScreen($r);
     }
-    &endContentScreen($r);
     $r->print(&Apache::loncommon::end_page());
 }
 
 sub textbook_request_javascript {
-    my ($numprefab,$numcurrent) = @_;
+    my ($numprefab,$numcurrent,$numcolleague,$customvalidationjs) = @_;
     return unless (ref($numprefab) eq 'HASH');
-    return if (!$numprefab->{'textbooks'} && !$numprefab->{'templates'} && !$numcurrent);
+    return if (!$numprefab->{'textbooks'} && !$numprefab->{'templates'} && !$numcurrent && !$numcolleague);
     my %js_lt = &Apache::lonlocal::texthash(
-                 choose   => 'Please select a content option.',
-                 textbook => 'Please select a textbook, or choose a different option.',
-                 template => 'Please select a template, or choose a different option.',        
-                 existing => 'Please select one of your existing courses to copy, or choose a different option.',
-                 title    => 'Please enter a course title.',
+                 choose    => 'Please select a content option.',
+                 textbook  => 'Please select a textbook, or choose a different option.',
+                 template  => 'Please select a template, or choose a different option.',        
+                 existing  => 'Please select one of your existing courses to copy, or choose a different option.',
+                 colleague => "Please select a colleague's course to copy, or choose a different option.", 
+                 title     => 'Please enter a course title.',
              );
     &js_escape(\%js_lt);
     return <<"ENDSCRIPT";
@@ -4902,7 +5360,7 @@ function cloneChoice() {
         var radioLength = document.requestcourse.cloning.length;
         if (radioLength == undefined) {
             var val = document.requestcourse.cloning.value;
-            if ((val == 'textbook') || (val == 'template') || (val == 'existing')) {
+            if ((val == 'textbook') || (val == 'template') || (val == 'existing') || (val == 'colleague')) {
                 var elem = document.getElementById('show'+val);
                 if (document.requestcourse.cloning.checked) {
                     elem.style.display = 'block';
@@ -4914,7 +5372,7 @@ function cloneChoice() {
         } else {
             for (var i=0; i<radioLength; i++) {
                 var val = document.requestcourse.cloning[i].value;
-                if ((val == 'textbook') || (val == 'template') || (val == 'existing')) {
+                if ((val == 'textbook') || (val == 'template') || (val == 'existing') || (val == 'colleague')) {
                     var elem = document.getElementById('show'+val);
                     if (document.requestcourse.cloning[i].checked) {
                         elem.style.display = 'block';
@@ -4928,6 +5386,9 @@ function cloneChoice() {
                         if (val == 'existing') {
                             uncheckRadio('owned');
                         }
+                        if (val == 'colleague') {
+                            uncheckRadio('colleague');
+                        }
                         elem.style.display = 'none';
                     }
                 }
@@ -4955,6 +5416,7 @@ function uncheckAllRadio() {
     var numbook = $numprefab->{'textbooks'};
     var numtemplate = $numprefab->{'templates'};
     var numcurrent = $numcurrent;
+    var numcolleague = $numcolleague;
     if (numbook > 0) {
         uncheckRadio('textbook'); 
     }
@@ -4964,6 +5426,9 @@ function uncheckAllRadio() {
     if (numcurrent > 0) {
         uncheckRadio('existing');
     }
+    if (numcolleague > 0) {
+        uncheckRadio('colleague');
+    }
     return;
 }
 
@@ -4991,7 +5456,7 @@ function validTextbookReq() {
             }
         }
         var group;
-        if ((cloneChoice == 'textbook') || (cloneChoice == 'template') || (cloneChoice == 'existing')) {
+        if ((cloneChoice == 'textbook') || (cloneChoice == 'template') || (cloneChoice == 'existing') || (cloneChoice == 'colleague')) {
             var group;
             if (cloneChoice == 'textbook') {
                 group = document.getElementsByName('book');
@@ -4999,7 +5464,11 @@ function validTextbookReq() {
                 if (cloneChoice == 'template') {
                     group = document.getElementsByName('template');
                 } else {
-                    group = document.getElementsByName('owned');
+                    if (cloneChoice == 'existing') {
+                        group = document.getElementsByName('owned');
+                    } else {
+                        group = document.getElementsByName('colleague');
+                    }
                 }
             }
             var groupLength = group.length;
@@ -5023,7 +5492,11 @@ function validTextbookReq() {
                    if (cloneChoice == 'template') {
                        alert("$js_lt{'template'}");
                    } else {
-                       alert("$js_lt{'existing'}");
+                       if (cloneChoice == 'existing') {
+                           alert("$js_lt{'existing'}");
+                       } else {
+                           alert("$js_lt{'colleague'}");
+                       }
                    }
                }
                return false;
@@ -5034,6 +5507,7 @@ function validTextbookReq() {
         alert("$js_lt{'title'}");
         return false;
     }
+    $customvalidationjs
     return true;
 }