--- loncom/interface/lonrequestcourse.pm	2015/08/24 14:50:22	1.93
+++ loncom/interface/lonrequestcourse.pm	2016/09/05 01:46:08	1.99
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Request a course
 #
-# $Id: lonrequestcourse.pm,v 1.93 2015/08/24 14:50:22 raeburn Exp $
+# $Id: lonrequestcourse.pm,v 1.99 2016/09/05 01:46:08 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -760,6 +760,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 +774,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 +804,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 +824,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 +1001,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'); 
             }
@@ -2093,10 +2104,23 @@ 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>';
     }
+    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;
+            }
+        }
+    }
     for (my $i=0; $i<$persontotal; $i++) { 
         my @linkargs = map { 'person_'.$i.'_'.$_ } (@items);
         my $linkargstr = join("','",@linkargs);
@@ -2121,9 +2145,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');
@@ -2504,7 +2533,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;
@@ -2672,7 +2701,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');
@@ -3076,6 +3105,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['
@@ -3155,6 +3185,8 @@ sub clone_form {
     my $type = 'Course';
     if ($crstype eq 'community') {
         $type = 'Community';
+    } elsif ($crstype eq 'placement') {
+        $type = 'Placement'; 
     }
     my %lt = &clone_text();
     my $output .= 
@@ -3162,7 +3194,7 @@ sub clone_form {
         &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).
@@ -3644,7 +3676,7 @@ sub print_request_outcome {
                                                         $instcode,$req_notifylist,\@instsections,\%domconfig);
     return ($result,$output,$customized);
 }
-    
+
 sub process_request {
     my ($r,$lonhost,$dom,$cnum,$crstype,$now,$details,$instcode,$req_notifylist,$instsections,
         $domconfig) = @_; 
@@ -3662,6 +3694,8 @@ sub process_request {
             $output = &mt('You are not permitted to request creation of communities');
         } elsif ($crstype eq 'textbook') {
             $output = &mt('You are not permitted to request creation of textbook courses');
+        } elsif ($crstype eq 'placement') {
+            $output = &mt('You are not permitted to request creation of placement tests');
         } else {
             $output = &mt('Unrecognized course type: [_1]',$crstype);
         }
@@ -4299,7 +4333,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 ++;
             }
@@ -4554,7 +4588,16 @@ sub print_textbook_form {
         $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'},
+                                           };
         }
     }
 
@@ -4850,11 +4893,14 @@ sub clone_selection_table {
                 $cleantitle=~s/'/\\'/g;
                 $cleantitle =~ s/^\s+//;
                 my ($namestr,@owners,%ownernames);
-                my $singleowner = $cloneableref->{$cid}{'internal.courseowner'};
-                push(@owners,$singleowner);
+                if ($cloneableref->{$cid}{'owner'} ne '') {
+                    push(@owners,$cloneableref->{$cid}{'owner'});
+                }
                 if ($cloneableref->{$cid}{'co-owners'} ne '') {
-                    foreach my $item (split(/,/,$cloneableref->{$cid}{'internal.co-owners'})) {
-                        push(@owners,$item);
+                    foreach my $item (split(/,/,$cloneableref->{$cid}{'co-owners'})) {
+                        if (($item ne '') && (!grep(/^\Q$item\E$/,@owners))) {
+                            push(@owners,$item);
+                        }
                     }
                 }
                 foreach my $owner (@owners) {