[LON-CAPA-cvs] cvs: loncom /interface domainprefs.pm

raeburn raeburn@source.lon-capa.org
Wed, 22 Apr 2009 14:09:14 -0000


raeburn		Wed Apr 22 14:09:14 2009 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm 
  Log:
  - Domain setting for institutional affiliation(s) required for user to create his/her own account (applies to institutional login/SSO only).
   - users_cansearch_row() renamed insttypes_row() added arg - $context.
        generates table of checkboxes of institutional types 
        (defined in inst_usertypes() in localenroll.pm).
  
  
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.92 loncom/interface/domainprefs.pm:1.93
--- loncom/interface/domainprefs.pm:1.92	Wed Apr 22 12:42:16 2009
+++ loncom/interface/domainprefs.pm	Wed Apr 22 14:09:13 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.92 2009/04/22 12:42:16 raeburn Exp $
+# $Id: domainprefs.pm,v 1.93 2009/04/22 14:09:13 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1299,8 +1299,8 @@
     $$rowtotal += 2;
     if (ref($usertypes) eq 'HASH') {
         if (keys(%{$usertypes}) > 0) {
-            $datatable .= &users_cansearch_row($settings,$types,$usertypes,$dom,
-                                               $numinrow,$othertitle);
+            $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
+                                         $numinrow,$othertitle,'cansearch');
             $cansrchrow = 1;
         }
     }
@@ -1315,7 +1315,7 @@
     foreach my $title (@{$titleorder}) {
         if (defined($searchtitles->{$title})) {
             my $check = ' ';
-            if (ref($settings) eq 'HASH') { 
+            if (ref($settings) eq 'HASH') {
                 if (ref($settings->{'searchby'}) eq 'ARRAY') {
                     if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
                         $check = ' checked="checked" ';
@@ -1570,6 +1570,16 @@
             }
             $datatable .= '</td></tr>';
         }
+        my ($othertitle,$usertypes,$types) =
+            &Apache::loncommon::sorted_inst_types($dom);
+        if (ref($usertypes) eq 'HASH') {
+            if (keys(%{$usertypes}) > 0) {
+                $datatable .= &insttypes_row($settings->{cancreate},$types,$usertypes,
+                                             $dom,$numinrow,$othertitle,
+                                             'statustocreate');
+                $$rowtotal ++;
+            }
+        }
     } else {
         my @contexts = ('author','course','domain');
         my @authtypes = ('int','krb4','krb5','loc');
@@ -2460,10 +2470,18 @@
     return $output;
 }
 
-sub users_cansearch_row {
-    my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle) = @_;
+sub insttypes_row {
+    my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
+    my %lt = &Apache::lonlocal::texthash (
+                      cansearch => 'Users allowed to search',
+                      statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
+             );
+    my $showdom;
+    if ($context eq 'cansearch') {
+        $showdom = ' ('.$dom.')';
+    }
     my $output =  '<tr class="LC_odd_row">'.
-                  '<td>'.&mt('Users allowed to search').' ('.$dom.')'.
+                  '<td>'.$lt{$context}.$showdom.
                   '</td><td class="LC_left_item" colspan="2"><table>';
     my $rem;
     if (ref($types) eq 'ARRAY') {
@@ -2477,14 +2495,16 @@
                     $output .= '<tr>';
                 }
                 my $check = ' ';
-                if (ref($settings->{'cansearch'}) eq 'ARRAY') {
-                    if (grep(/^\Q$types->[$i]\E$/,@{$settings->{'cansearch'}})) {
+                if (ref($settings->{$context}) eq 'ARRAY') {
+                    if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
                         $check = ' checked="checked" ';
                     }
+                } elsif ($context eq 'statustocreate') {
+                    $check = ' checked="checked" ';
                 }
                 $output .= '<td class="LC_left_item">'.
                            '<span class="LC_nobreak"><label>'.
-                           '<input type="checkbox" name="cansearch" '.
+                           '<input type="checkbox" name="'.$context.'" '.
                            'value="'.$types->[$i].'"'.$check.'/>'.
                            $usertypes->{$types->[$i]}.'</label></span></td>';
             }
@@ -2499,13 +2519,15 @@
         $output .= '<td class="LC_left_item">';
     }
     my $defcheck = ' ';
-    if (ref($settings->{'cansearch'}) eq 'ARRAY') {
-        if (grep(/^default$/,@{$settings->{'cansearch'}})) {
+    if (ref($settings->{$context}) eq 'ARRAY') {
+        if (grep(/^default$/,@{$settings->{$context}})) {
             $defcheck = ' checked="checked" ';
         }
+    } elsif ($context eq 'statustocreate') {
+        $defcheck = ' checked="checked" ';
     }
     $output .= '<span class="LC_nobreak"><label>'.
-               '<input type="checkbox" name="cansearch" '.
+               '<input type="checkbox" name="'.$context.'" '.
                'value="default"'.$defcheck.'/>'.
                $othertitle.'</label></span></td>'.
                '</tr></table></td></tr>';
@@ -3978,10 +4000,19 @@
             $cancreate{$item} = $env{'form.can_createuser_'.$item};
         }
     }
+    my ($othertitle,$usertypes,$types) = 
+        &Apache::loncommon::sorted_inst_types($dom);
+    if (ref($types) eq 'ARRAY') {
+        if (@{$types} > 0) {
+            @{$cancreate{'statustocreate'}} = 
+                &Apache::loncommon::get_env_multiple('form.statustocreate');
+        }
+        push(@contexts,'statustocreate');
+    }
     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
         foreach my $item (@contexts) {
-            if ($item eq 'selfcreate') {
-                if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') { 
+            if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
+                if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                     foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
                         if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
@@ -4168,6 +4199,26 @@
                             }
                             $chgtext .= '</ul>';
                         }
+                    } elsif ($type eq 'statustocreate') {
+                        if (@{$cancreate{'selfcreate'}} > 0) {
+                            if (@{$cancreate{$type}} == 0) {
+                                if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
+                                    $chgtext .= &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.");
+                                }
+                            } elsif (ref($usertypes) eq 'HASH') {
+                                if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
+                                    $chgtext .= &mt('creation of a new account for an institutional user is restricted to the following institutional affiliation(s):').'<ul>';
+                                    foreach my $case (@{$cancreate{$type}}) {
+                                        if ($case eq 'default') {
+                                            $chgtext .= '<li>'.$othertitle.'</li>';
+                                        } else {
+                                            $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
+                                        }
+                                    }
+                                    $chgtext .= '</ul>';
+                                }
+                            }
+                        }
                     } else {
                         if ($cancreate{$type} eq 'none') {
                             $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');