--- loncom/lonnet/perl/lonnet.pm	2009/07/25 14:44:55	1.1006
+++ loncom/lonnet/perl/lonnet.pm	2009/08/08 00:36:10	1.1010
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1006 2009/07/25 14:44:55 raeburn Exp $
+# $Id: lonnet.pm,v 1.1010 2009/08/08 00:36:10 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1665,12 +1665,14 @@ sub userenvironment {
     }
     $items=~s/\&$//;
     my %returnhash=();
-    my @answer=split(/\&/,
-                &reply('get:'.$udom.':'.$unam.':environment:'.$items,
-                      &homeserver($unam,$udom)));
-    my $i;
-    for ($i=0;$i<=$#what;$i++) {
-	$returnhash{$what[$i]}=&unescape($answer[$i]);
+    my $uhome = &homeserver($unam,$udom);
+    unless ($uhome eq 'no_host') {
+        my @answer=split(/\&/, 
+            &reply('get:'.$udom.':'.$unam.':environment:'.$items,$uhome));
+        my $i;
+        for ($i=0;$i<=$#what;$i++) {
+	    $returnhash{$what[$i]}=&unescape($answer[$i]);
+        }
     }
     return %returnhash;
 }
@@ -2968,7 +2970,7 @@ sub courseidput {
 sub courseiddump {
     my ($domfilter,$descfilter,$sincefilter,$instcodefilter,$ownerfilter,
         $coursefilter,$hostidflag,$hostidref,$typefilter,$regexp_ok,
-        $selfenrollonly,$catfilter,$showhidden,$caller)=@_;
+        $selfenrollonly,$catfilter,$showhidden,$caller,$cloner,$cc_clone,$cloneonly)=@_;
     my $as_hash = 1;
     my %returnhash;
     if (!$domfilter) { $domfilter=''; }
@@ -2987,7 +2989,8 @@ sub courseiddump {
                          ':'.&escape($coursefilter).':'.&escape($typefilter).
                          ':'.&escape($regexp_ok).':'.$as_hash.':'.
                          &escape($selfenrollonly).':'.&escape($catfilter).':'.
-                         $showhidden.':'.$caller,$tryserver);
+                         $showhidden.':'.$caller.':'.&escape($cloner).':'.
+                         &escape($cc_clone).':'.$cloneonly,$tryserver);
                 my @pairs=split(/\&/,$rep);
                 foreach my $item (@pairs) {
                     my ($key,$value)=split(/\=/,$item,2);
@@ -3002,7 +3005,7 @@ sub courseiddump {
                         for (my $i=0; $i<@responses; $i++) {
                             $returnhash{$key}{$items[$i]} = &unescape($responses[$i]);
                         }
-                    } 
+                    }
                 }
             }
         }
@@ -5507,11 +5510,21 @@ sub auto_run {
 
 sub auto_get_sections {
     my ($cnum,$cdom,$inst_coursecode) = @_;
-    my $homeserver = &homeserver($cnum,$cdom);
-    my @secs = ();
-    my $response=&unescape(&reply('autogetsections:'.$inst_coursecode.':'.$cdom,$homeserver));
-    unless ($response eq 'refused') {
-        @secs = split(/:/,$response);
+    my $homeserver;
+    if (($cdom =~ /^$match_domain$/) && ($cnum =~ /^$match_courseid$/)) { 
+        $homeserver = &homeserver($cnum,$cdom);
+    }
+    if (!defined($homeserver)) { 
+        if ($cdom =~ /^$match_domain$/) {
+            $homeserver = &domain($cdom,'primary');
+        }
+    }
+    my @secs;
+    if (defined($homeserver)) {
+        my $response=&unescape(&reply('autogetsections:'.$inst_coursecode.':'.$cdom,$homeserver));
+        unless ($response eq 'refused') {
+            @secs = split(/:/,$response);
+        }
     }
     return @secs;
 }
@@ -5530,6 +5543,22 @@ sub auto_validate_courseID {
     return $response;
 }
 
+sub auto_validate_instcode {
+    my ($cnum,$cdom,$instcode,$owner) = @_;
+    my ($homeserver,$response);
+    if (($cdom =~ /^$match_domain$/) && ($cnum =~ /^$match_courseid$/)) {
+        $homeserver = &homeserver($cnum,$cdom);
+    }
+    if (!defined($homeserver)) {
+        if ($cdom =~ /^$match_domain$/) {
+            $homeserver = &domain($cdom,'primary');
+        }
+    }
+    my $response=&unescape(&reply('autovalidateinstcode:'.$cdom.':'.
+                           &escape($instcode).':'.&escape($owner),$homeserver));
+    return $response;
+}
+
 sub auto_create_password {
     my ($cnum,$cdom,$authparam,$udom) = @_;
     my ($homeserver,$response);
@@ -5704,7 +5733,11 @@ sub auto_instcode_defaults {
 }
 
 sub auto_possible_instcodes {
-    my ($domain,$codetitles,$cat_titles,$cat_orders) = @_;
+    my ($domain,$codetitles,$cat_titles,$cat_orders,$code_order) = @_;
+    unless ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') && 
+            (ref($cat_orders) eq 'HASH') && (ref($code_order) eq 'ARRAY')) {
+        return;
+    }
     my (@homeservers,$uhome);
     if (defined(&domain($domain,'primary'))) {
         $uhome=&domain($domain,'primary');
@@ -5721,8 +5754,10 @@ sub auto_possible_instcodes {
     foreach my $server (@homeservers) {
         $response=&reply('autopossibleinstcodes:'.$domain,$server);
         next if ($response =~ /(con_lost|error|no_such_host|refused)/);
-        my ($codetitlestr,$cat_title,$cat_order) = split(':',$response);
-        @{$codetitles} = map { &unescape($_); } (split('&',$codetitlestr));  
+        my ($codetitlestr,$codeorderstr,$cat_title,$cat_order) = 
+            split(':',$response);
+        @{$codetitles} = map { &unescape($_); } (split('&',$codetitlestr));
+        @{$code_order} = map { &unescape($_); } (split('&',$codeorderstr));
         foreach my $item (split('&',$cat_title)) {   
             my ($name,$value)=split('=',$item);
             $cat_titles->{&unescape($name)}=&thaw_unescape($value);
@@ -5736,6 +5771,12 @@ sub auto_possible_instcodes {
     return $response;
 }
 
+sub auto_courserequest_checks {
+    my ($dom) = @_;
+    my %validations;
+    return %validations; 
+}
+
 sub auto_validate_class_sec {
     my ($cdom,$cnum,$owners,$inst_class) = @_;
     my $homeserver = &homeserver($cnum,$cdom);
@@ -5902,8 +5943,8 @@ sub plaintext {
         }
     }
     my %rolenames = (
-                      Course => 'std',
-                      Group => 'alt1',
+                      Course    => 'std',
+                      Community => 'alt1',
                     );
     if (defined($type) && 
          defined($rolenames{$type}) && 
@@ -9662,7 +9703,7 @@ and course level
 
 plaintext($short,$type,$cid,$forcedefault) : return value in %prp hash 
 (rolesplain.tab); plain text explanation of a user role term.
-$type is Course (default) or Group.
+$type is Course (default) or Community.
 If $forcedefault evaluates to true, text returned will be default 
 text for $type. Otherwise, if this is a course, the text returned 
 will be a custom name for the role (if defined in the course's