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

raeburn raeburn@source.lon-capa.org
Sun, 21 Mar 2010 20:33:47 -0000


raeburn		Sun Mar 21 20:33:47 2010 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm 
  Log:
  - Autoupdate configuration.
    - consistent naming for generation field.
    - report change if an additional field was enabled for updates
    - sanity checking of institutional status types and field names
      from form elements.
  
  
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.131 loncom/interface/domainprefs.pm:1.132
--- loncom/interface/domainprefs.pm:1.131	Fri Mar 12 15:01:36 2010
+++ loncom/interface/domainprefs.pm	Sun Mar 21 20:33:47 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.131 2010/03/12 15:01:36 raeburn Exp $
+# $Id: domainprefs.pm,v 1.132 2010/03/21 20:33:47 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1825,7 +1825,7 @@
         $$rowtotal ++;
     } else {
         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
-        my @fields = ('lastname','firstname','middlename','gen',
+        my @fields = ('lastname','firstname','middlename','generation',
                       'permanentemail','id');
         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
         my $numrows = 0;
@@ -4767,7 +4767,7 @@
                         lastname => 'Last Name',
                         firstname => 'First Name',
                         middlename => 'Middle Name',
-                        gen => 'Generation',
+                        generation => 'Generation',
                       );
     my $othertitle = &mt('All users');
     if (keys(%{$usertypes}) >  0) {
@@ -4775,7 +4775,16 @@
     }
     foreach my $key (keys(%env)) {
         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
-            push(@{$fields{$1}},$2);
+            my ($usertype,$item) = ($1,$2);
+            if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
+                if ($usertype eq 'default') {   
+                    push(@{$fields{$1}},$2);
+                } elsif (ref($types) eq 'ARRAY') {
+                    if (grep(/^\Q$usertype\E$/,@{$types})) {
+                        push(@{$fields{$1}},$2);
+                    }
+                }
+            }
         }
     }
     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
@@ -4812,9 +4821,11 @@
                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                             if (!exists($fields{$item})) {
                                 $change = 1;
+                                last;
                             } elsif (ref($fields{$item}) eq 'ARRAY') {
                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
                                     $change = 1;
+                                    last;
                                 }
                             }
                         }
@@ -4845,7 +4856,20 @@
     foreach my $item (@{$types},'default') {
         if (defined($fields{$item})) {
             if (ref($currautoupdate{'fields'}) eq 'HASH') {
-                if (!exists($currautoupdate{'fields'}{$item})) {
+                if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
+                    my $change = 0;
+                    if (ref($fields{$item}) eq 'ARRAY') {
+                        foreach my $type (@{$fields{$item}}) {
+                            if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
+                                $change = 1;
+                                last;
+                            }
+                        }
+                    }
+                    if ($change) {
+                        push(@{$changes{'fields'}},$item);
+                    }
+                } else {
                     push(@{$changes{'fields'}},$item);
                 }
             } else {