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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Tue, 11 Dec 2007 00:44:23 -0000


This is a MIME encoded message

--raeburn1197333863
Content-Type: text/plain

raeburn		Mon Dec 10 19:44:23 2007 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm 
  Log:
  - Domain Coordinators can configure which types of user information can be modified for existing users via CUSR, and in which contexts (author or course), and for users with which active/future roles, applicablein the curren context.  
  - In domain context, all user information is modifiable by a Domain Coordinator via CUSR.
  
  
--raeburn1197333863
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20071210194423.txt"

Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.32 loncom/interface/domainprefs.pm:1.33
--- loncom/interface/domainprefs.pm:1.32	Fri Nov  9 22:51:46 2007
+++ loncom/interface/domainprefs.pm	Mon Dec 10 19:44:23 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.32 2007/11/10 03:51:46 raeburn Exp $
+# $Id: domainprefs.pm,v 1.33 2007/12/11 00:44:23 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -68,10 +68,10 @@
     my %domconfig =
       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
                 'quotas','autoenroll','autoupdate','directorysrch',
-                'usercreation','contacts'],$dom);
+                'usercreation','usermodification','contacts'],$dom);
     my @prefs_order = ('rolecolors','login','quotas','autoenroll',
                        'autoupdate','directorysrch','contacts',
-                       'usercreation');
+                       'usercreation','usermodification');
     my %prefs = (
         'rolecolors' =>
                    { text => 'Default color schemes',
@@ -132,6 +132,14 @@
                                {col1 => 'Context',
                                 col2 => 'Assignable Authentication Types'}],
                   },
+        'usermodification' => 
+                  { text => 'User modification',
+                    help => 'Domain_User_Modification',
+                    header => [{col1 => 'Target user has role',
+                                col2 => 'User information updateable in author context'},
+                               {col1 => 'Target user has role',
+                                col2 => 'User information updateable in course context'}],
+                  },
     );
     my @roles = ('student','coordinator','author','admin');
     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
@@ -306,6 +314,8 @@
         $output = &modify_directorysrch($dom,%domconfig);
     } elsif ($action eq 'usercreation') {
         $output = &modify_usercreation($dom,%domconfig);
+    } elsif ($action eq 'usermodification') {
+        $output = &modify_usermodification($dom,%domconfig);
     } elsif ($action eq 'contacts') {
         $output = &modify_contacts($dom,%domconfig);
     }
@@ -327,7 +337,7 @@
 #          </tr>');
     $rowtotal ++;
     if (($action eq 'autoupdate') || ($action eq 'rolecolors') || 
-        ($action eq 'usercreation')) {
+        ($action eq 'usercreation') || ($action eq 'usermodification')) {
         my $colspan = ($action eq 'rolecolors')?' colspan="2"':'';
         $output .= '
           <tr>
@@ -341,7 +351,9 @@
         if ($action eq 'autoupdate') {
             $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
         } elsif ($action eq 'usercreation') {
-            $output .= &print_usercreation('top',$dom,$settings,\$rowtotal); 
+            $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
+        } elsif ($action eq 'usermodification') {
+            $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
         } else {
             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
         }
@@ -361,6 +373,8 @@
             $output .= &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
         } elsif ($action eq 'usercreation') {
             $output .= &print_usercreation('bottom',$dom,$settings,\$rowtotal);
+        } elsif ($action eq 'usermodification') {
+            $output .= &print_usermodification('bottom',$dom,$settings,\$rowtotal);
         } else {
             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
            </table>
@@ -1056,14 +1070,7 @@
         my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
         my @fields = ('lastname','firstname','middlename','gen',
                       'permanentemail','id');
-        my %fieldtitles = &Apache::lonlocal::texthash (
-                            id => 'Student/Employee ID',
-                            permanentemail => 'E-mail address',
-                            lastname => 'Last Name',
-                            firstname => 'First Name',
-                            middlename => 'Middle Name',
-                            gen => 'Generation',
-                      );
+        my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
         my $numrows = 0;
         if (ref($types) eq 'ARRAY') {
             if (@{$types} > 0) {
@@ -1449,6 +1456,96 @@
     return %context_title;
 }
 
+sub print_usermodification {
+    my ($position,$dom,$settings,$rowtotal) = @_;
+    my $numinrow = 4;
+    my ($context,$datatable,$rowcount);
+    if ($position eq 'top') {
+        $rowcount = 0;
+        $context = 'author'; 
+        foreach my $role ('ca','aa') {
+            $datatable .= &modifiable_userdata_row($context,$role,$settings,
+                                                   $numinrow,$rowcount);
+            $$rowtotal ++;
+            $rowcount ++;
+        }
+    } else {
+        $context = 'course';
+        $rowcount = 0;
+        foreach my $role ('st','ep','ta','in','cr') {
+            $datatable .= &modifiable_userdata_row($context,$role,$settings,
+                                                   $numinrow,$rowcount);
+            $$rowtotal ++;
+            $rowcount ++;
+        }
+    }
+    return $datatable;
+}
+
+sub modifiable_userdata_row {
+    my ($context,$role,$settings,$numinrow,$rowcount) = @_;
+    my $rolename;
+    if ($role eq 'cr') {
+        $rolename = &mt('Custom role');
+    } else {
+        $rolename = &Apache::lonnet::plaintext($role);
+    }
+    my @fields = ('lastname','firstname','middlename','generation',
+                  'permanentemail','id');
+    my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
+    my $output;
+    my $css_class = $rowcount%2?' class="LC_odd_row"':'';
+    $output = '<tr '.$css_class.'>'.
+              '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
+              '<td class="LC_left_item" colspan="2"><table>';
+    my $rem;
+    my %checks;
+    if (ref($settings) eq 'HASH') {
+        if (ref($settings->{$context}) eq 'HASH') {
+            if (ref($settings->{$context}->{$role}) eq 'HASH') {
+                foreach my $field (@fields) {
+                    if ($settings->{$context}->{$role}->{$field}) {
+                        $checks{$field} = ' checked="checked" ';
+                    }
+                }
+            }
+        }
+    }
+    for (my $i=0; $i<@fields; $i++) {
+        my $rem = $i%($numinrow);
+        if ($rem == 0) {
+            if ($i > 0) {
+                $output .= '</tr>';
+            }
+            $output .= '<tr>';
+        }
+        my $check = ' ';
+        if (exists($checks{$fields[$i]})) {
+            $check = $checks{$fields[$i]}
+        } else {
+            if ($role eq 'st') {
+                if (ref($settings) ne 'HASH') {
+                    $check = ' checked="checked" '; 
+                }
+            }
+        }
+        $output .= '<td class="LC_left_item">'.
+                   '<span class="LC_nobreak"><label>'.
+                   '<input type="checkbox" name="canmodify_'.$role.'" '.
+                   'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
+                   '</label></span></td>';
+        $rem = @fields%($numinrow);
+    }
+    my $colsleft = $numinrow - $rem;
+    if ($colsleft > 1 ) {
+        $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
+                   '&nbsp;</td>';
+    } elsif ($colsleft == 1) {
+        $output .= '<td class="LC_left_item">&nbsp;</td>';
+    }
+    $output .= '</tr></table></td></tr>';
+    return $output;
+}
 
 sub users_cansearch_row {
     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle) = @_;
@@ -2882,7 +2979,6 @@
             my %authname = &authtype_names();
             my %context_title = &context_names();
             if (ref($changes{'authtypes'}) eq 'ARRAY') {
-                my @unchanged;
                 my $chgtext = '<ul>';
                 foreach my $type (@{$changes{'authtypes'}}) {
                     my @allowed;
@@ -2909,4 +3005,104 @@
     return $resulttext;
 }
 
+sub modify_usermodification {
+    my ($dom,%domconfig) = @_;
+    my ($resulttext,%curr_usermodification,%changes);
+    if (ref($domconfig{'usermodification'}) eq 'HASH') {
+        foreach my $key (keys(%{$domconfig{'usermodification'}})) {
+            $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
+        }
+    }
+    my @contexts = ('author','course');
+    my %context_title = (
+                           author => 'In author context',
+                           course => 'In course context',
+                        );
+    my @fields = ('lastname','firstname','middlename','generation',
+                  'permanentemail','id');
+    my %roles = (
+                  author => ['ca','aa'],
+                  course => ['st','ep','ta','in','cr'],
+                );
+    my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
+    my %modifyhash;
+    foreach my $context (@contexts) {
+        foreach my $role (@{$roles{$context}}) {
+            my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
+            foreach my $item (@fields) {
+                if (grep(/^\Q$item\E$/,@modifiable)) {
+                    $modifyhash{$context}{$role}{$item} = 1;
+                } else {
+                    $modifyhash{$context}{$role}{$item} = 0;
+                }
+            }
+        }
+        if (ref($curr_usermodification{$context}) eq 'HASH') {
+            foreach my $role (@{$roles{$context}}) {
+                if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
+                    foreach my $field (@fields) {
+                        if ($modifyhash{$context}{$role}{$field} ne 
+                                $curr_usermodification{$context}{$role}{$field}) {
+                            push(@{$changes{$context}},$role);
+                            last;
+                        }
+                    }
+                }
+            }
+        } else {
+            foreach my $context (@contexts) {
+                foreach my $role (@{$roles{$context}}) {
+                    push(@{$changes{$context}},$role);
+                }
+            }
+        }
+    }
+    my %usermodification_hash =  (
+                                   usermodification => \%modifyhash,
+                                 );
+    my $putresult = &Apache::lonnet::put_dom('configuration',
+                                             \%usermodification_hash,$dom);
+    if ($putresult eq 'ok') {
+        if (keys(%changes) > 0) {
+            $resulttext = &mt('Changes made: ').'<ul>';
+            foreach my $context (@contexts) {
+                if (ref($changes{$context}) eq 'ARRAY') {
+                    $resulttext .= '<li>'.$context_title{$context}.':<ul>';
+                    if (ref($changes{$context}) eq 'ARRAY') {
+                        foreach my $role (@{$changes{$context}}) {
+                            my $rolename;
+                            if ($role eq 'cr') {
+                                $rolename = &mt('Custom');
+                            } else {
+                                $rolename = &Apache::lonnet::plaintext($role);
+                            }
+                            my @modifiable;
+                            $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
+                            foreach my $field (@fields) {
+                                if ($modifyhash{$context}{$role}{$field}) {
+                                    push(@modifiable,$fieldtitles{$field});
+                                }
+                            }
+                            if (@modifiable > 0) {
+                                $resulttext .= join(', ',@modifiable);
+                            } else {
+                                $resulttext .= &mt('none'); 
+                            }
+                            $resulttext .= '</li>';
+                        }
+                        $resulttext .= '</ul></li>';
+                    }
+                }
+            }
+            $resulttext .= '</ul>';
+        } else {
+            $resulttext = &mt('No changes made to user modification settings');
+        }
+    } else {
+        $resulttext = '<span class="LC_error">'.
+            &mt('An error occurred: [_1]',$putresult).'</span>';
+    }
+    return $resulttext;
+}
+
 1;

--raeburn1197333863--