--- loncom/interface/lonrequestcourse.pm	2021/12/14 02:54:52	1.95.2.7
+++ loncom/interface/lonrequestcourse.pm	2017/08/11 15:26:38	1.102
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Request a course
 #
-# $Id: lonrequestcourse.pm,v 1.95.2.7 2021/12/14 02:54:52 raeburn Exp $
+# $Id: lonrequestcourse.pm,v 1.102 2017/08/11 15:26:38 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -119,10 +119,6 @@ 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');
@@ -131,10 +127,6 @@ 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();
@@ -768,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})) {
@@ -781,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.',
     ); 
@@ -810,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;
+                        }
                     }
                 }
             }
@@ -823,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.');
@@ -1000,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'); 
             }
@@ -2101,7 +2104,8 @@ sub print_personnel_menu {
             official => 'Requestor is automatically assigned Course Coordinator role.',
         );
         $lt{'unofficial'} = $lt{'official'};
-        $lt{'textbook'} = $lt{'textbook'};
+        $lt{'textbook'} = $lt{'official'};
+        $lt{'placement'} = $lt{'official'};
         $output .= &Apache::lonhtmlcommon::row_headline().
                   '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Personnel').'&nbsp;'.$lt{$crstype}.' '.&mt('Include other personnel?').'</h3>';
     }
@@ -2117,14 +2121,15 @@ sub print_personnel_menu {
             }
         }
     }
-    for (my $i=0; $i<$persontotal; $i++) { 
+    my ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$dom);
+    for (my $i=0; $i<$persontotal; $i++) {
         my @linkargs = map { 'person_'.$i.'_'.$_ } (@items);
         my $linkargstr = join("','",@linkargs);
         my $uname_form = '<input type="text" name="person_'.$i.'_uname" value="" size="20" />';
         my $onchange = 'javascript:fix_domain('."'$formname','person_".$i."_dom',".
                        "'person_".$i."_hidedom','person_".$i."_uname'".');';
         my $udom_form = &Apache::loncommon::select_dom_form($dom,'person_'.$i.'_dom','',
-                                                            1,$onchange).
+                                                            1,$onchange,undef,$trusted,$untrusted).
                         '<input type="hidden" name="person_'.$i.'_hidedom" value="" />';
         my %form_elems;
         foreach my $item (@items) {
@@ -2395,7 +2400,7 @@ sub print_cancel_request {
                       &Apache::loncommon::start_data_table_row().
                       '<td>'.$history{details}{'cdescr'}.'</td><td>'.
                       &Apache::lonlocal::locallocaltime($timestamp).'</td>'.
-                      '<td>'.&mt($showtype).'</td>'.
+                      '<td>'.$showtype.'</td>'.
                       &Apache::loncommon::end_data_table_row().
                       &Apache::loncommon::end_data_table().
                       '<br /><div class="LC_warning">';
@@ -2529,7 +2534,7 @@ sub print_request_logs {
         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
             if (ref($domconfig{'requestcourses'}{'uniquecode'}) eq 'HASH') {
                 if ($curr{'crstype'} eq 'any') {
-                    my @types = qw(official unofficial community textbook);
+                    my @types = qw(official unofficial community textbook placement);
                     foreach my $type (@types) {
                         if ($domconfig{'requestcourses'}{'uniquecode'}{$type}) {
                             $showuniquecode = 1;
@@ -2697,7 +2702,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');
@@ -2749,7 +2754,7 @@ sub requestlog_display_filter {
                         $typename = $typenames->{$crstype};
                     }
                 }
-                $output .= '<option value="'.$crstype.'"'.$selstr.'>'.&mt($typename).'</option>'."\n";
+                $output .= '<option value="'.$crstype.'"'.$selstr.'>'.$typename.'</option>'."\n";
             }
             $output .= '</select></td>';
         }
@@ -3101,6 +3106,7 @@ sub courseinfo_form {
     &js_escape(\%js_lt);
     $js_lt{'unofficial'} = $js_lt{'official'};
     $js_lt{'textbook'} = $js_lt{'official'};
+    $js_lt{'placement'} = $js_lt{'official'};
     my $js_validate = <<"ENDJS";
 <script type="text/javascript">
 // <![CDATA['
@@ -3180,6 +3186,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 .= 
@@ -3198,7 +3206,7 @@ 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="364" />'.
+        '<input type="text" size="5" name="dateshift" value="365" />'.
         &Apache::lonhtmlcommon::row_closure(1);
     return $output;
 }
@@ -3237,7 +3245,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})) {
@@ -3345,18 +3353,23 @@ sub get_course_dom {
                     return $env{'user.domain'};
                 }
             }
-            my @possible_doms;
+            my (@possible_doms,%willtrust,%trustchecked);
             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 ($trustchecked{$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);
+                            }
                         }
                     }
                 }
@@ -3669,7 +3682,7 @@ sub print_request_outcome {
                                                         $instcode,$req_notifylist,\@instsections,\%domconfig);
     return ($result,$output,$customized);
 }
-    
+
 sub process_request {
     my ($r,$lonhost,$dom,$cnum,$crstype,$now,$details,$instcode,$req_notifylist,$instsections,
         $domconfig) = @_; 
@@ -3687,6 +3700,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);
         }
@@ -3854,24 +3869,6 @@ sub process_request {
                 }
                 $output .= '</p>';
                 $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') {
@@ -3980,7 +3977,7 @@ sub process_request {
             } elsif ($disposition eq 'pending') {
                 my $pendingform;
                 if ($crstype ne 'official') {
-                    $pendingform = &pending_validation_form($r,$dom,$cnum,$crstype,$now,$token,
+                    $pendingform = &pending_validation_form($dom,$cnum,$crstype,$now,$token,
                                                             $lonhost,$env{'form.cdescr'});
                 }
                 if ($pendingform) {
@@ -4007,22 +4004,6 @@ sub process_request {
     }
 }
 
-sub devalidate_remote_instcats {
-    if ($modified_dom ne '') {
-        my %servers = &Apache::lonnet::internet_dom_servers($modified_dom);
-        my %thismachine;
-        map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
-        if (keys(%servers)) {
-            foreach my $server (keys(%servers)) {
-                next if ($thismachine{$server});
-                &Apache::lonnet::remote_devalidate_cache($server,['instcats:'.$modified_dom]);
-            }
-        }
-        $modified_dom = '';
-    }
-    return;
-}
-
 sub custom_formitems {
     my ($preprocess,$customhash) = @_;
     return unless ((ref($preprocess) eq 'HASH') && (ref($customhash) eq 'HASH'));  
@@ -4298,7 +4279,7 @@ sub notification_information {
 }
 
 sub pending_validation_form {
-    my ($r,$cdom,$cnum,$crstype,$now,$token,$lonhost,$cdesc) = @_;
+    my ($cdom,$cnum,$crstype,$now,$token,$lonhost,$cdesc) = @_;
     my $output;
     my %postvalues = (
                       'owner'      => $env{'user.name'}.':'.$env{'user.domain'},
@@ -4331,12 +4312,9 @@ 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 $alias = &Apache::lonnet::use_proxy_alias($r,$lonhost);
-                $hostname = $alias if ($alias ne '');
-                my $crscreator = $protocol.'://'.$hostname.'/cgi-bin/createpending.pl';
+                my $crscreator = $protocol.'://'.&Apache::lonnet::hostname($lonhost).'/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".
@@ -4361,7 +4339,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 ++;
             }
@@ -4625,7 +4603,7 @@ sub print_textbook_form {
                                                owner => $courseinfo{'internal.courseowner'},
                                                releaserequired => $courseinfo{'internal.releaserequired'},
                                                type  => $courseinfo{'type'},
-                                           };
+                                          };
         }
     }
 
@@ -4824,7 +4802,7 @@ sub print_textbook_form {
                   '</label><br /><label>'.
                   '<input type="radio" name="owndatemode" value="shift" checked="checked" /> '.
                   $lt{'shd'}.'</label>'.
-                  '<input type="text" size="5" name="owndateshift" value="364" />'.
+                  '<input type="text" size="5" name="owndateshift" value="365" />'.
                   '</div>');
     }
 #
@@ -4839,7 +4817,7 @@ sub print_textbook_form {
                   '</label><br /><label>'.
                   '<input type="radio" name="colldatemode" value="shift" checked="checked" /> '.
                   $lt{'shd'}.'</label>'.
-                  '<input type="text" size="5" name="colldateshift" value="364" />'.
+                  '<input type="text" size="5" name="colldateshift" value="365" />'.
                   '</div>');
     }
 
@@ -5077,9 +5055,6 @@ sub process_textbook_request {
             } else {
                 $details->{dateshift} = '';
             }
-        } elsif (($reqtype eq 'textbook') || ($reqtype eq 'template')) {
-            $details->{datemode} = 'delete';
-            $details->{dateshift} = '';
         }
         if ($details->{dateshift} ne '') {
             $details->{dateshift} =~ s/[^\d\.]+//g;