--- loncom/interface/lonmodifycourse.pm	2007/01/15 01:08:53	1.30
+++ loncom/interface/lonmodifycourse.pm	2007/12/14 00:24:11	1.36
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # handler for DC-only modifiable course settings
 #
-# $Id: lonmodifycourse.pm,v 1.30 2007/01/15 01:08:53 raeburn Exp $
+# $Id: lonmodifycourse.pm,v 1.36 2007/12/14 00:24:11 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -33,7 +33,7 @@ use Apache::lonnet;
 use Apache::loncommon;
 use Apache::lonhtmlcommon;
 use Apache::lonlocal;
-use Apache::londropadd;
+use Apache::lonuserutils;
 use Apache::lonpickcourse;
 use LONCAPA::Enrollment;
 use lib '/home/httpd/lib/perl';
@@ -313,7 +313,7 @@ all settings except course code, course
             'usrd' => 'Use the radio buttons to select a different course owner.',
             'deam' => "Default Authentication method",
             'deus' => "The default authentication method, and default authentication parameter (domain, initial password or argument) are used when automatic enrollment of students in a course requires addition of new user accounts in your domain, and the class list file contains empty entries for the <authtype> and <autharg> properties for the new student. If you choose 'internally authenticated', and leave the initial password field empty, the automated enrollment process will create a randomized password for each new student account that it adds to your LON-CAPA domain.",
-            'gobt' => "Modify settings",
+            'gobt' => "Save",
     );
     my @bgcolors = ('#eeeeee','#cccccc');
 
@@ -368,19 +368,24 @@ all settings except course code, course
     }
     unless ($curr_authtype eq '') {
         $curr_authfield = $curr_authtype.'arg';
-    } 
-    my $javascript_validations=&Apache::londropadd::javascript_validations('modifycourse',$krbdefdom,$curr_authtype,$curr_authfield);
-    my %param = ( formname => 'document.cmod',
+    }
+    my $javascript_validations=&Apache::lonuserutils::javascript_validations('modifycourse',$krbdefdom,$curr_authtype,$curr_authfield);
+    my %param = ( formname => 'document.'.$env{'form.phase'},
 	   kerb_def_dom => $krbdefdom,
 	   kerb_def_auth => $krbdef,
            mode => 'modifycourse',
            curr_authtype => $curr_authtype,
            curr_autharg => $enrollvar{'autharg'} 
 	);
-    my $krbform = &Apache::loncommon::authform_kerberos(%param);
-    my $intform = &Apache::loncommon::authform_internal(%param);
-    my $locform = &Apache::loncommon::authform_local(%param);
-
+    my (%authform,$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') {
+        if ($authform{$item} ne '') {
+            $authenitems .= $authform{$item}.'<br />';
+        }
+    } 
     if ($numlocalcc == 0) {
         $ownertable = $lt{'nocc'};
     }
@@ -432,12 +437,12 @@ all settings except course code, course
     my $mainheader = &mt('Course settings modifiable by [_1] only.',$dctitle);
     my $hidden_elements = &hidden_form_elements();
     $r->print(<<ENDDOCUMENT);
-<form action="/adm/modifycourse" method="post" name="setparms">
+<form action="/adm/modifycourse" method="post" name="$env{'form.phase'}">
 <h3>$mainheader</h3>
 </p><p>
 <table width="100%" cellspacing="6" cellpadding="6">
  <tr>
-  <td colspan="2">Use the appropriate text boxes and radio buttons below to change some or all of the four automated enrollment settings that may only be changed by a Domain Coordinator. Click the <b>"$lt{'gobt'}"</b> button to save your changes.</td>
+  <td colspan="2">Use the appropriate text boxes and radio buttons below to change some or all of the four automated enrollment settings that may only be changed by a Domain Coordinator.
  </tr>
  <tr>
   <td width="50%" valign="top">
@@ -455,12 +460,7 @@ all settings except course code, course
  <tr>
   <td width="50%" valign="top">
    <b>$lt{'deam'}:</b><br/><br/>
-   $krbform
-   <br/>
-   $intform
-   <br/>
-   $locform
-   <br/>
+   $authenitems
    <br/>
    $lt{'deus'}.
    </td>
@@ -561,9 +561,17 @@ sub modify_course {
     }
     if ($changeowner == 1 || $changecode == 1) {
         my $courseid_entry = &escape($cdom.'_'.$cnum).'='.&escape($description).':'.&escape($env{'form.coursecode'}).':'.&escape($env{'form.courseowner'}).':'.&escape($type);
-        &Apache::lonnet::courseidput($cdom,$courseid_entry,&Apache::lonnet::homeserver($cnum,$cdom));
+        my %courseid_entry = (
+             $cdom.'_'.$cnum => {
+                                description => $description,
+                                inst_code   => $env{'form.coursecode'},
+                                owner       => $env{'form.courseowner'},
+                                type        => $type,
+                               },
+        );
+        &Apache::lonnet::courseidput($cdom,\%courseid_entry,
+                                     &Apache::lonnet::homeserver($cnum,$cdom),'notime');
     }
-
     foreach my $param (@modifiable_params) {
         if ($currattr{$param} eq $newattr{$param}) {
             push(@nochanges,$param);
@@ -573,17 +581,16 @@ sub modify_course {
             push(@changes,$param);
         }
     }
-
     if (@changes > 0) {
         $chgresponse = &mt("The following automated enrollment parameters have been changed:<br/><ul>");
     }
     if (@nochanges > 0) { 
         $nochgresponse = &mt("The following automated enrollment parameters remain unchanged:<br/><ul>");
     }
-    if (@changes > 0) { 
+    if (@changes > 0) {
         my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
         if ($putreply !~ /^ok$/) {
-            $response = &mt("There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>");
+            $response = &mt("There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>").&mt('Error: ').$putreply;
         } else {
             foreach my $attr (@modifiable_params) {
                 if (grep/^$attr$/,@changes) {
@@ -800,28 +807,36 @@ sub print_footer {
 sub check_course {
     my ($r,$dom,$domdesc) = @_;
     my ($ok_course,$description,$instcode,$owner);
-    if (defined($env{'form.pickedcourse'})) {
-        my ($cdom,$cnum) = split(/_/,$env{'form.pickedcourse'});
-        if ($cdom eq $dom) {
-            my %courseIDs = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
-                                                          $cnum,undef,undef,'.');
-            if (keys(%courseIDs) > 0) {
-                $ok_course = 'ok';
+    my %args = (
+                 one_time => 1,
+               );
+    my %coursehash = 
+        &Apache::lonnet::coursedescription($env{'form.pickedcourse'},\%args);
+    my $cnum = $coursehash{'num'};
+    my $cdom = $coursehash{'domain'};
+    if ($cdom eq $dom) {
+        my $description;
+        my %courseIDs = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
+                                           $cnum,undef,undef,'.');
+        if (keys(%courseIDs) > 0) {
+            $ok_course = 'ok';
+            my ($instcode,$owner);
+            if (ref($courseIDs{$cdom.'_'.$cnum}) eq 'HASH') {
+                $description = $courseIDs{$cdom.'_'.$cnum}{'description'};
+                $instcode = $courseIDs{$cdom.'_'.$cnum}{'inst_code'};
+                $owner = $courseIDs{$cdom.'_'.$cnum}{'owner'};          
+            } else {
                 ($description,$instcode,$owner) = 
-                                       split(/:/,$courseIDs{$cdom.'_'.$cnum});
-                $description = &unescape($description);
-                $instcode = &unescape($instcode);
-                if ($instcode) {
-                    $description .= " ($instcode)";
-                } 
+                                   split(/:/,$courseIDs{$cdom.'_'.$cnum});
             }
+            $description = &unescape($description);
+            $instcode = &unescape($instcode);
+            if ($instcode) {
+                $description .= " ($instcode)";
+            }
+            return ($ok_course,$description);
         }
     }
-
-    if ($ok_course ne 'ok') {
-        $r->print('<br/>'.&mt('The LON-CAPA course selected was not a valid course for the [_1] domain',$domdesc));
-    }
-    return ($ok_course,$description);
 }
 
 sub course_settings_descrip {
@@ -859,7 +874,7 @@ sub handler {
         return OK;
     }
     my $dom = $env{'request.role.domain'};
-    my $domdesc = $Apache::lonnet::domaindescription{$dom}; 
+    my $domdesc = &Apache::lonnet::domain($dom,'description');
     if (&Apache::lonnet::allowed('ccc',$dom)) {
         &Apache::loncommon::content_type($r,'text/html');
         $r->send_http_header;
@@ -926,7 +941,7 @@ sub handler {
                         }
                     }
                 } else {
-                    $r->print(&mt('The course you selected is not a valid course in this domain')." ($domdesc)"); 
+                    $r->print('<span class="LC_error">'.&mt('The course you selected is not a valid course in this domain')." ($domdesc)".'</span>'); 
                 }
             }
         }