--- loncom/interface/lonmodifycourse.pm	2016/11/10 21:57:10	1.79.2.4
+++ loncom/interface/lonmodifycourse.pm	2018/03/23 01:01:21	1.93
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # handler for DC-only modifiable course settings
 #
-# $Id: lonmodifycourse.pm,v 1.79.2.4 2016/11/10 21:57:10 raeburn Exp $
+# $Id: lonmodifycourse.pm,v 1.93 2018/03/23 01:01:21 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -72,6 +72,13 @@ sub catalog_settable {
             if ($confhash->{'categorizecomm'} ne 'comm') {
                 push(@settable,'categorize');
             }
+        } elsif ($type eq 'Placement') {
+            if ($confhash->{'togglecatsplace'} ne 'place') {
+                push(@settable,'togglecats');
+            }
+            if ($confhash->{'categorizeplace'} ne 'place') {
+                push(@settable,'categorize');
+            }
         } else {
             if ($confhash->{'togglecats'} ne 'crs') {
                 push(@settable,'togglecats');
@@ -167,6 +174,8 @@ sub print_course_search_page {
     $r->print(&Apache::loncommon::js_changer());
     if ($type eq 'Community') {
         $r->print('<h3>'.&mt('Search for a community in the [_1] domain',$domdesc).'</h3>');
+    } elsif ($type eq 'Placement') {
+        $r->print('<h3>'.&mt('Search for a placement test in the [_1] domain',$domdesc).'</h3>');
     } else {
         $r->print('<h3>'.&mt('Search for a course in the [_1] domain',$domdesc).'</h3>');
     }
@@ -177,6 +186,8 @@ sub print_course_search_page {
     my ($actiontext,$roleoption,$settingsoption);
     if ($type eq 'Community') {
         $actiontext = &mt('Actions available after searching for a community:');
+    } elsif ($type eq 'Placement') {
+        $actiontext = &mt('Actions available after searching for a placement test:')
     } else {
         $actiontext = &mt('Actions available after searching for a course:');
     }
@@ -184,33 +195,39 @@ sub print_course_search_page {
        if ($type eq 'Community') {
            $roleoption = &mt('Enter the community with the role of [_1]',$cctitle);
            $settingsoption = &mt('View or modify community settings which only a [_1] may modify.',$dctitle);
+       } elsif ($type eq 'Placement') {
+           $roleoption = &mt('Enter the placement test with the role of [_1]',$cctitle);
+           $settingsoption = &mt('View or modify placement test settings which only a [_1] may modify.',$dctitle);
        } else {
            $roleoption = &mt('Enter the course with the role of [_1]',$cctitle);
            $settingsoption = &mt('View or modify course settings which only a [_1] may modify.',$dctitle);
        }
     } elsif (&Apache::lonnet::allowed('rar',$dom)) {
-        my %adhocroles = &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
-                                                         'adhocroles.'.$dom);
-        if (keys(%adhocroles)) {
-            my @adhoc = split(',',$adhocroles{'adhocroles.'.$dom});
-            if (@adhoc > 1) {
+        my ($roles_by_num,$description,$accessref,$accessinfo) = &Apache::lonnet::get_all_adhocroles($dom);
+        if ((ref($roles_by_num) eq 'ARRAY') && (ref($description) eq 'HASH')) {
+            if (@{$roles_by_num} > 1) {
                 if ($type eq 'Community') {
-                    $roleoption = &mt('Enter the community with one of the available ad hoc roles: [_1].',
-                                  join(', ',@adhoc));
+                    $roleoption = &mt('Enter the community with one of the available ad hoc roles');
+                } elsif ($type eq 'Placement') {
+                    $roleoption = &mt('Enter the placement test with one of the available ad hoc roles.');
                 } else {
-                    $roleoption = &mt('Enter the course with one of the available ad hoc roles: [_1].',
-                                  join(', ',@adhoc));
+                    $roleoption = &mt('Enter the course with one of the available ad hoc roles.');
                 }
             } else {
+                my $rolename = $description->{$roles_by_num->[0]};
                 if ($type eq 'Community') {
-                    $roleoption = &mt('Enter the community with the ad hoc role of: [_1]',$adhoc[0]);
+                    $roleoption = &mt('Enter the community with the ad hoc role of: [_1]',$rolename);
+                } elsif ($type eq 'Placement') {
+                    $roleoption = &mt('Enter the placement test with the ad hoc role of: [_1]',$rolename);
                 } else {
-                    $roleoption = &mt('Enter the course with the ad hoc role of: [_1]',$adhoc[0]);
+                    $roleoption = &mt('Enter the course with the ad hoc role of: [_1]',$rolename);
                 }
             }
         }
         if ($type eq 'Community') {
             $settingsoption = &mt('View community settings which only a [_1] may modify.',$dctitle);
+        } elsif ($type eq 'Placement') {
+            $settingsoption = &mt('View placement test settings which only a [_1] may modify.',$dctitle);
         } else {
             $settingsoption = &mt('View course settings which only a [_1] may modify.',$dctitle);
         }
@@ -224,14 +241,133 @@ sub print_course_search_page {
 }
 
 sub print_course_selection_page {
-    my ($r,$dom,$domdesc) = @_;
+    my ($r,$dom,$domdesc,$permission) = @_;
     my $type = $env{'form.type'};
     if (!defined($type)) {
         $type = 'Course';
     }
     &print_header($r,$type);
 
-# Criteria for course search 
+    if ($permission->{'adhocrole'} eq 'custom') {
+        my %lt = &Apache::lonlocal::texthash(
+            title    => 'Ad hoc role selection',
+            preamble => 'Please choose an ad hoc role in the course.',
+            cancel   => 'Click "OK" to enter the course, or "Cancel" to choose a different course.',
+        );
+        my %jslt = &Apache::lonlocal::texthash (
+            none => 'You are not eligible to use an ad hoc role for the selected course',
+            ok   => 'OK',
+            exit => 'Cancel',
+        );
+        &js_escape(\%jslt);
+        $r->print(<<"END");
+<script type="text/javascript">
+// <![CDATA[
+\$(document).ready(function(){
+    \$( "#LC_adhocrole_chooser" ).dialog({ autoOpen: false });
+});
+
+function gochoose(cname,cdom,cdesc) {
+    document.courselist.pickedcourse.value = cdom+'_'+cname;
+    \$("#LC_choose_adhoc").empty();
+    var pickedaction = \$('input[name=phase]:checked', '#LCcoursepicker').val();
+    if (pickedaction == 'adhocrole') {
+        var http = new XMLHttpRequest();
+        var url = "/adm/pickcourse";
+        var params = "cid="+cdom+"_"+cname+"&context=adhoc";
+        http.open("POST", url, true);
+        http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+        http.onreadystatechange = function() {
+            if (http.readyState == 4 && http.status == 200) {
+                var data = \$.parseJSON(http.responseText);
+                var len = data.roles.length;
+                if (len == '' || len == null || len == 0) {
+                    alert('$jslt{none}');
+                } else {
+                    if (len == 1) {
+                        \$( '[name="adhocrole"]' )[0].value = data.roles[0].name;
+                        document.courselist.submit();
+                    } else {
+                        var str = '';
+                        \$("#LC_choose_adhoc").empty();
+                        for (var i=0; i<data.roles.length; i++) {
+                            \$("<label><input type='radio' value='"+data.roles[i].name+"' name='LC_get_role' id='LC_get_role_"+i+"' />"+data.roles[i].desc+"</label><span>&nbsp;&nbsp;</span>")
+                            .appendTo("#LC_choose_adhoc");
+                        }
+                        \$( "#LC_adhocrole_chooser" ).toggle( true );
+                        \$( "#LC_get_role_0").prop("checked", true);
+                        \$( "#LC_adhocrole_chooser" ).dialog({ autoOpen: false });
+                        \$( "#LC_adhocrole_chooser" ).dialog("open");
+                        \$( "#LC_adhocrole_chooser" ).dialog({
+                            height: 400,
+                            width: 500,
+                            modal: true,
+                            resizable: false,
+                            buttons: [
+                                  {
+                                   text: "$jslt{'ok'}",
+                                   click: function() {
+                                            var rolename = \$('input[name=LC_get_role]:checked', '#LChelpdeskpicker').val();
+                                            \$( '[name="adhocrole"]' )[0].value = rolename;
+                                            document.courselist.submit();
+                                        }
+                                  },
+                                  {
+                                   text: "$jslt{'exit'}",
+                                   click: function() {
+                                        \$("#LC_adhocrole_chooser").dialog( "close" );
+                                       }
+                                  }
+                            ],
+                        });
+                        \$( "#LC_adhocrole_chooser" ).find( "form" ).on( "submit", function( event ) {
+                            event.preventDefault();
+                            var rolename = \$('input[name=LC_get_role]:checked', '#LChelpdeskpicker').val()
+                            \$( '[name="adhocrole"]' )[0].value = rolename;
+                            document.courselist.submit();
+                            \$("#LC_adhocrole_chooser").dialog( "close" );
+                        });
+                    }
+                }
+            }
+        }
+        http.send(params);
+    } else {
+        document.courselist.submit();
+    }
+    return;
+}
+// ]]>
+</script>
+
+<div id="LC_adhocrole_chooser" title="$lt{'title'}" style="display:none">
+  <p>$lt{'preamble'}</p>
+  <form name="LChelpdeskadhoc" id="LChelpdeskpicker" action="">
+    <div id="LC_choose_adhoc">
+    </div>
+    <input type="hidden" name="adhocrole" id="LCadhocrole" value="" />
+    <input type="submit" tabindex="-1" style="position:absolute; top:-1000px" />
+  </form>
+  <p>$lt{'cancel'}</p>
+</div>
+END
+    } elsif ($permission->{'adhocrole'} eq 'coord') {
+        $r->print(<<"END");
+<script type="text/javascript">
+// <![CDATA[
+
+function gochoose(cname,cdom,cdesc) {
+    document.courselist.pickedcourse.value = cdom+'_'+cname;
+    document.courselist.submit();
+    return;
+}
+
+// ]]>
+</script>
+END
+    }
+
+# Criteria for course search
     my ($filterlist,$filter) = &get_filters();
     my $action = '/adm/modifycourse';
     my $dctitle = &Apache::lonnet::plaintext('dc');
@@ -296,7 +432,7 @@ sub print_modification_menu {
                     );
     }
     if ($type eq 'Community') {
-        if ($permission->{'setparms'} eq 'edit') {
+        if ($permission->{'setparms'} eq 'edit') { 
             $categorytitle = 'View/Modify Community Settings';
             $linktext{'setparms'} = 'View/Modify community owner';
             $linktext{'catsettings'} = 'View/Modify catalog settings for community';
@@ -306,7 +442,7 @@ sub print_modification_menu {
             $linktext{'catsettings'} = 'View catalog settings for community';
         }
         $setquota_text = &mt('Total disk space allocated for storage of portfolio files in all groups in a community.');
-        $setuploadquota_text = &mt('Disk space allocated for storage of content uploaded directly to a community via Content Editor.');
+        $setuploadquota_text = &mt('Disk space allocated for storage of content uploaded directly to a community via Content Editor.'); 
     } else {
         if ($permission->{'setparms'} eq 'edit') {
             $categorytitle = 'View/Modify Course Settings';
@@ -391,7 +527,7 @@ sub print_modification_menu {
             {
                 linktext => $linktext{'viewparms'},
                 url => &phaseurl('viewparms'),
-                permission => ($permission->{'viewparms'} && ($type ne 'Community')),
+                permission => ($permission->{'viewparms'} && ($type ne 'Community') && ($type ne 'Placement')),
                 #help => '',
                 icon => 'roles.png',
                 linktitle => ''
@@ -433,7 +569,7 @@ sub print_modification_menu {
     } else {
         $menu_html .=  '<li>'.&mt('Course owner (permitted to assign Course Coordinator roles in the course).').'</li>'."\n".
                        '<li>'.&mt("Institutional code and default authentication (both required for auto-enrollment of students from institutional datafeeds).").'</li>'."\n";
-        if (&showcredits($dom)) {
+        if (($type ne 'Placement') && &showcredits($dom)) {
             $menu_html .= '<li>'.&mt('Default credits earned by student on course completion.').'</li>'."\n";
         }
         $menu_html .= ' <li>'.&mt('Override defaults for who configures self-enrollment for this specific course.').'</li>'."\n";
@@ -476,29 +612,25 @@ sub print_modification_menu {
 }
 
 sub print_adhocrole_selected {
-    my ($r,$type) = @_;
+    my ($r,$type,$permission) = @_;
     &print_header($r,$type);
     my ($cdom,$cnum) = split(/_/,$env{'form.pickedcourse'});
     my ($newrole,$selectrole);
-    if (&Apache::lonnet::allowed('ccc',$cdom)) {
+    if ($permission->{'adhocrole'} eq 'coord') {
         if ($type eq 'Community') {
             $newrole = "co./$cdom/$cnum";
         } else {
             $newrole = "cc./$cdom/$cnum";
         }
         $selectrole = 1;
-    } elsif (&Apache::lonnet::allowed('rar',$cdom)) {
-        my %adhocroles = &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
-                                                         'adhocroles.'.$cdom);
-        if (keys(%adhocroles)) {
-            my $possrole = $env{'form.adhocrole'};
-            if ($possrole ne '') {
-                my @adhoc = split(',',$adhocroles{'adhocroles.'.$cdom});
-                if (grep(/^\Q$possrole\E$/,@adhoc)) {
-                    my $confname = &Apache::lonnet::get_domainconfiguser($cdom);
-                    $newrole = "cr/$cdom/$confname/$possrole./$cdom/$cnum";
-                    $selectrole = 1;
-                }
+    } elsif ($permission->{'adhocrole'} eq 'custom') {
+        my ($okroles,$description) = &Apache::lonnet::get_my_adhocroles($env{'form.pickedcourse'},1);      
+        if (ref($okroles) eq 'ARRAY') {
+            my $possrole = $env{'form.adhocrole'}; 
+            if (($possrole ne '') && (grep(/^\Q$possrole\E$/,@{$okroles}))) {
+                my $confname = &Apache::lonnet::get_domainconfiguser($cdom);
+                $newrole = "cr/$cdom/$confname/$possrole./$cdom/$cnum";
+                $selectrole = 1;
             }
         }
     }
@@ -674,7 +806,7 @@ sub print_set_anonsurvey_threshold {
     my $hidden_elements = &hidden_form_elements();
     my ($disabled,$submit);
     if ($readonly) {
-        $disabled = ' disabled="disabled"';
+        $disabled = ' disabled="disabled"'; 
     } else {
         $submit = '<input type="submit" value="'.$lt{'modi'}.'" />';
     }
@@ -768,7 +900,7 @@ sub domain_postsubtimeout {
     my ($cdom,$type,$settings) = @_;
     return unless (ref($settings) eq 'HASH'); 
     my $lctype = lc($type);
-    unless ($type eq 'Community') {
+    unless (($type eq 'Community') || ($type eq 'Placement')) {
         $lctype = 'unofficial';
         if ($settings->{'internal.coursecode'}) {
             $lctype = 'official';
@@ -831,6 +963,8 @@ sub print_catsettings {
                       '&nbsp;<label><input name="hidefromcat" type="radio" value="yes" '.$excludeon.$disabled.' />'.&mt('Yes').'</label>&nbsp;&nbsp;&nbsp;<label><input name="hidefromcat" type="radio" value="" '.$excludeoff.$disabled.' />'.&mt('No').'</label><br /><p>');
             if ($type eq 'Community') {
                 $r->print(&mt("If a community has been categorized using at least one of the categories defined for communities in the domain, it will be listed in the domain's publicly accessible Course/Community Catalog, unless excluded."));
+            } elsif ($type eq 'Placement') {
+                $r->print(&mt("If a placement test has been categorized using at least one of the categories defined for placement tests in the domain, it will be listed in the domain's publicly accessible Course/Community Catalog, unless excluded."));
             } else {
                 $r->print(&mt("Unless excluded, a course will be listed in the domain's publicly accessible Course/Community Catalog, if at least one of the following applies").':<ul>'.
                           '<li>'.&mt('Auto-cataloging is enabled and the course is assigned an institutional code.').'</li>'.
@@ -852,7 +986,7 @@ sub print_catsettings {
             } else {
                 $r->print(&mt('No categories defined for this domain'));
             }
-            unless ($type eq 'Community') { 
+            unless (($type eq 'Community') || ($type eq 'Placement')) { 
                 $r->print('<p>'.&mt('If auto-cataloging based on institutional code is enabled in the domain, a course will continue to be listed in the catalog of official courses, in addition to receiving a listing under any manually assigned categor(ies).').'</p>');
             }
         }
@@ -951,7 +1085,7 @@ sub print_course_modification_page {
         foreach my $cc (@local_ccs) {
             $ownertable .= &Apache::loncommon::start_data_table_row()."\n";
             if ($cc eq $enrollvar{'courseowner'}) {
-                  $ownertable .= '<td><input type="radio" name="courseowner" value="'.$cc.'" checked="checked"'.$disabled.' /></td>'."\n";
+                $ownertable .= '<td><input type="radio" name="courseowner" value="'.$cc.'" checked="checked"'.$disabled.' /></td>'."\n";
             } else {
                 $ownertable .= '<td><input type="radio" name="courseowner" value="'.$cc.'"'.$disabled.' /></td>'."\n";
             }
@@ -980,7 +1114,7 @@ sub print_course_modification_page {
                       '&nbsp;'.&mt('Course Code'))."\n".
                   '<input type="text" size="15" name="coursecode" value="'.$enrollvar{'coursecode'}.'"'.$disabled.' />'.
                   &Apache::lonhtmlcommon::row_closure());
-        if (&showcredits($cdom)) {
+        if (($crstype eq 'Course') && (&showcredits($cdom))) {
             $r->print(&Apache::lonhtmlcommon::row_title(
                           &Apache::loncommon::help_open_topic('Modify_Course_Credithours').
                       '&nbsp;'.&mt('Credits (students)'))."\n".
@@ -1143,6 +1277,8 @@ sub gather_authenitems {
             $curr_authtype = 'int';
         } elsif ($enrollvar->{'authtype'} eq 'localauth' ) {
             $curr_authtype = 'loc';
+        } elsif ($enrollvar->{'authtype'} eq 'lti' ) {
+            $curr_authtype = 'lti';
         }
     }
     unless ($curr_authtype eq '') {
@@ -1163,7 +1299,8 @@ sub gather_authenitems {
     $authform{'krb'} = &Apache::loncommon::authform_kerberos(%param);
     $authform{'int'} = &Apache::loncommon::authform_internal(%param);
     $authform{'loc'} = &Apache::loncommon::authform_local(%param);
-    foreach my $item ('krb','int','loc') {
+    $authform{'lti'} = &Apache::loncommon::authform_lti(%param);
+    foreach my $item ('krb','int','loc','lti') {
         if ($authform{$item} ne '') {
             $authenitems .= $authform{$item}.'<br />';
         }
@@ -1178,7 +1315,7 @@ sub modify_course {
                  'internal.pendingco-owners','internal.selfenrollmgrdc',
                  'internal.selfenrollmgrcc','internal.mysqltables');
     my ($selfenrollrows,$selfenrolltitles) = &Apache::lonuserutils::get_selfenroll_titles();
-    unless ($type eq 'Community') {
+    unless (($type eq 'Community') || ($type eq 'Placement')) {
         push(@items,('internal.coursecode','internal.authtype','internal.autharg',
                      'internal.sectionnums','internal.crosslistings'));
         if (&showcredits($cdom)) {  
@@ -1229,6 +1366,8 @@ sub modify_course {
             if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
                 $newattr{'autharg'} = $env{'form.locarg'};
             }
+        } elsif ($env{'form.login'} eq 'lti') {
+            $newattr{'authtype'} = 'lti';
         }
         if ( $newattr{'authtype'}=~ /^krb/) {
             if ($newattr{'autharg'}  eq '') {
@@ -1251,7 +1390,7 @@ sub modify_course {
             $newattr{'mysqltables'} = $env{'form.mysqltables'};
             $newattr{'mysqltables'} =~ s/\D+//g;
         }
-        if (&showcredits($cdom) && exists($env{'form.defaultcredits'})) {
+        if (($type ne 'Placement') && (&showcredits($cdom) && exists($env{'form.defaultcredits'}))) {
             $newattr{'defaultcredits'}=$env{'form.defaultcredits'};
             $newattr{'defaultcredits'} =~ s/[^\d\.]//g;
         }
@@ -1363,7 +1502,7 @@ sub modify_course {
                     $nochgresponse .= '<li>'.&mt('[_1] still set to: [_2]',$longtype{$attr},$shown).'</li>';
                 }
             }
-            if (($type ne 'Community') && ($changed{'code'} || $changed{'owner'})) {
+            if (($type ne 'Community') && ($type ne 'Placement') && ($changed{'code'} || $changed{'owner'})) {
                 if ( $newattr{'courseowner'} eq '') {
 	            push(@warnings,&mt('There is no owner associated with this LON-CAPA course.').
                                    '<br />'.&mt('If automated enrollment at your institution requires validation of course owners, automated enrollment will fail.'));
@@ -2044,13 +2183,7 @@ function changePage(formname,newphase) {
     if ($phase eq 'setparms') {
 	$js .= $javascript_validations;
     } elsif ($phase eq 'courselist') {
-        $js .= qq|
-
-function gochoose(cname,cdom,cdesc) {
-    document.courselist.pickedcourse.value = cdom+'_'+cname;
-    document.courselist.submit();
-}
-
+        $js .= <<"ENDJS";
 function hide_searching() {
     if (document.getElementById('searching')) {
         document.getElementById('searching').style.display = 'none';
@@ -2058,7 +2191,7 @@ function hide_searching() {
     return;
 }
 
-|;
+ENDJS
     } elsif ($phase eq 'setquota') {
         my $invalid = &mt('The quota you entered contained invalid characters.');
         my $alert = &mt('You must enter a number');
@@ -2202,6 +2335,8 @@ ENDSCRIPT
     my $bread_text = "View/Modify Courses/Communities";
     if ($type eq 'Community') {
         $bread_text = 'Community Settings';
+    } elsif ($type eq 'Placement') {
+        $bread_text = 'Placement Test Settings';
     } else {
         $bread_text = 'Course Settings';
     }
@@ -2322,6 +2457,7 @@ sub get_permission {
             catsettings       => 'edit',
             processcat        => 'edit',
             selfenroll        => 'edit',
+            adhocrole         => 'coord',
         );
     } elsif (&Apache::lonnet::allowed('rar',$dom)) {
         $allowed = 1;
@@ -2333,6 +2469,7 @@ sub get_permission {
             setparms      => 'view',
             catsettings   => 'view',
             selfenroll    => 'view',
+            adhocrole     => 'custom',
         );
     }
     return ($allowed,\%permission);
@@ -2376,6 +2513,8 @@ sub handler {
             }
             if ($type eq 'Community') {
                 $choose_text = "Choose a community";
+            } elsif ($type eq 'Placement') {
+                $choose_text = "Choose a placement test";
             } else {
                 $choose_text = "Choose a course";
             } 
@@ -2385,13 +2524,15 @@ sub handler {
               {href=>"javascript:changePage(document.$phase,'courselist')",
               text=>$choose_text});
             if ($phase eq 'courselist') {
-                &print_course_selection_page($r,$dom,$domdesc);
+                &print_course_selection_page($r,$dom,$domdesc,$permission);
             } else {
                 my ($checked,$cdesc,$coursehash) = &check_course($dom,$domdesc);
                 if ($checked eq 'ok') {
                     my $enter_text;
                     if ($type eq 'Community') {
                         $enter_text = 'Enter community';
+                    } elsif ($type eq 'Placement') {
+                        $enter_text = 'Enter placement test'; 
                     } else {
                         $enter_text = 'Enter course';
                     }
@@ -2406,7 +2547,7 @@ sub handler {
                         &Apache::lonhtmlcommon::add_breadcrumb
                          ({href=>"javascript:changePage(document.$phase,'adhocrole')",
                            text=>$enter_text});
-                        &print_adhocrole_selected($r,$type);
+                        &print_adhocrole_selected($r,$type,$permission);
                     } else {
                         &Apache::lonhtmlcommon::add_breadcrumb
                         ({href=>"javascript:changePage(document.$phase,'menu')",
@@ -2414,11 +2555,11 @@ sub handler {
                         my ($cdom,$cnum) = split(/_/,$env{'form.pickedcourse'});
                         my ($readonly,$linktext);
                         if ($permission->{$phase} eq 'view') {
-                           $readonly = 1;
+                           $readonly = 1; 
                         }
                         if (($phase eq 'setquota') && ($permission->{'setquota'})) {
                             if ($permission->{'setquota'} eq 'view') {
-                                $linktext = 'Set quota';
+                                $linktext = 'Set quota'; 
                             } else {
                                 $linktext = 'Display quota';
                             }
@@ -2516,6 +2657,8 @@ sub handler {
                     $r->print('<span class="LC_error">');
                     if ($type eq 'Community') {
                         $r->print(&mt('The community you selected is not a valid community in this domain'));
+                    } elsif ($type eq 'Placement') {
+                        $r->print(&mt('The course you selected is not a valid placement test in this domain'));
                     } else {
                         $r->print(&mt('The course you selected is not a valid course in this domain'));
                     }