Diff for /loncom/interface/loncreateuser.pm between versions 1.205 and 1.206

version 1.205, 2007/12/08 19:19:03 version 1.206, 2007/12/11 02:27:24
Line 707  $loginscript Line 707  $loginscript
 <input type='hidden' name='makeuser' value='1' />  <input type='hidden' name='makeuser' value='1' />
 <h2>$lt{'cnu'} "$ccuname" $lt{'ind'} $ccdomain</h2>  <h2>$lt{'cnu'} "$ccuname" $lt{'ind'} $ccdomain</h2>
 ENDTITLE  ENDTITLE
         $r->print('<div class="LC_left_float">'.          $r->print('<div class="LC_left_float">');
                   &personal_data_display($ccuname,$ccdomain,$newuser,          my $personal_table = 
                                          %inst_results));              &personal_data_display($ccuname,$ccdomain,$newuser,
                                      $context,%inst_results);
           $r->print($personal_table);
         my ($home_server_pick,$numlib) =           my ($home_server_pick,$numlib) = 
             &Apache::loncommon::home_server_form_item($ccdomain,'hserver',              &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
                                                       'default','hide');                                                        'default','hide');
Line 786  $crumbs Line 788  $crumbs
 $forminfo  $forminfo
 <h2>$lt{'cup'} "$ccuname" $lt{'id'} "$ccdomain"</h2>  <h2>$lt{'cup'} "$ccuname" $lt{'id'} "$ccdomain"</h2>
 ENDCHANGEUSER  ENDCHANGEUSER
         $r->print('<div class="LC_left_float">'.          $r->print('<div class="LC_left_float">');
                   &personal_data_display($ccuname,$ccdomain,$newuser,          my ($personal_table,$showforceid) = 
                                          %inst_results));              &personal_data_display($ccuname,$ccdomain,$newuser,
         if ($context eq 'domain') {                                     $context,%inst_results);
           $r->print($personal_table);
           if ($showforceid) {
             $r->print(&Apache::lonuserutils::forceid_change($context));              $r->print(&Apache::lonuserutils::forceid_change($context));
         }          }
         $r->print('</div>');          $r->print('</div>');
Line 1318  sub modify_login_block { Line 1322  sub modify_login_block {
 }  }
   
 sub personal_data_display {  sub personal_data_display {
     my ($ccuname,$ccdomain,$newuser,%inst_results) = @_;       my ($ccuname,$ccdomain,$newuser,$context,%inst_results) = @_; 
     my ($output,%userenv);      my ($output,$showforceid,%userenv,%domconfig);
     if (!$newuser) {      if (!$newuser) {
         # Get the users information          # Get the users information
         %userenv = &Apache::lonnet::get('environment',          %userenv = &Apache::lonnet::get('environment',
                    ['firstname','middlename','lastname','generation',                     ['firstname','middlename','lastname','generation',
                     'permanentemail','id'],$ccdomain,$ccuname);                      'permanentemail','id'],$ccdomain,$ccuname);
           %domconfig =
               &Apache::lonnet::get_dom('configuration',['usermodification'],
                                        $ccdomain);
     }      }
     my %lt=&Apache::lonlocal::texthash(      my %lt=&Apache::lonlocal::texthash(
                 'pd'             => "Personal Data",                  'pd'             => "Personal Data",
Line 1362  sub personal_data_display { Line 1369  sub personal_data_display {
                 $output .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';                  $output .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
             }              }
         } else {          } else {
               my $canmodify = 0;
             if (&Apache::lonnet::allowed('mau',$ccdomain)) {              if (&Apache::lonnet::allowed('mau',$ccdomain)) {
                   $canmodify = 1;
               } else {
                   if (ref($domconfig{'usermodification'}) eq 'HASH') {
                       if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
                           foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) {
                               if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') {
                                   if ($domconfig{'usermodification'}{$context}{$key}{$item}) { 
                                       $canmodify = 1;
                                       last;
                                   }
                               }
                           }
                       }
                   } elsif ($context eq 'course') {
                       $canmodify = 1;
                   }
               }
               if ($canmodify) {
                 $output .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';                  $output .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
             } else {              } else {
                 $output .= $userenv{$item};                  $output .= $userenv{$item};
             }              }
               if ($item eq 'id') {
                   $showforceid = $canmodify; 
               } 
         }          }
         $output .= &Apache::lonhtmlcommon::row_closure(1);          $output .= &Apache::lonhtmlcommon::row_closure(1);
     }      }
     $output .= &Apache::lonhtmlcommon::end_pick_box();      $output .= &Apache::lonhtmlcommon::end_pick_box();
     return $output;      if (wantarray) {
           return ($output,$showforceid);
       } else {
           return $output;
       }
 }  }
   
 # ================================================================= Phase Three  # ================================================================= Phase Three
 sub update_user_data {  sub update_user_data {
     my ($r) = @_;       my ($r,$context) = @_; 
     my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},      my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
                                           $env{'form.ccdomain'});                                            $env{'form.ccdomain'});
     # Error messages      # Error messages
Line 1574  sub update_user_data { Line 1607  sub update_user_data {
         if ($tmp =~ /^(con_lost|error)/i) {           if ($tmp =~ /^(con_lost|error)/i) { 
             %userenv = ();              %userenv = ();
         }          }
         # Check to see if we need to change user information          my $no_forceid_alert;
           # Check to see if user information can be changed
           my %domconfig =
               &Apache::lonnet::get_dom('configuration',['usermodification'],
                                        $env{'form.ccdomain'});
           my @roletypes = ('active','future');
           my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@roletypes,undef,$env{'request.role.domain'});
           my @userroles;
           my ($cnum,$cdom,$auname,$audom);
           if ($context eq 'course') {
               $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
               $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
               if ($cnum eq '' || $cdom eq '') {
                   my $cid = $env{'request.course.id'};
                   my %coursehash =
                        &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
                   $cdom = $coursehash{'domain'};
                   $cnum = $coursehash{'num'};
               } 
           } elsif ($context eq 'author') {
               $auname = $env{'user.name'};
               $audom = $env{'user.domain'};     
           }
           foreach my $item (keys(%roles)) {
               my ($rolenum,$roledom,$role) = split(/:/,$item);
               if ($context eq 'course') {
                   if ($cnum ne '' && $cdom ne '') {
                       if ($rolenum eq $cnum && $roledom eq $cdom) {
                           if (!grep(/^\Q$role\E$/,@userroles)) {
                               push(@userroles,$role);
                           }
                       }
                   }
               } elsif ($context eq 'author') {
                   if ($rolenum eq $auname && $roledom eq $audom) {
                       if (!grep(/^\Q$role\E$/,@userroles)) { 
                           push(@userroles,$role);
                       }
                   }
               }
           }
           # Check for course or co-author roles being activated or re-enabled
           if ($context eq 'author' || $context eq 'course') {
               foreach my $key (keys(%env)) {
                   if ($context eq 'author') {
                       if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
                           if (!grep(/^\Q$1\E$/,@userroles)) {
                               push(@userroles,$1);
                           }
                       } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
                           if (!grep(/^\Q$1\E$/,@userroles)) {
                               push(@userroles,$1);
                           }
                       }
                   } elsif ($context eq 'course') {
                       if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
                           if (!grep(/^\Q$1\E$/,@userroles)) {
                               push(@userroles,$1);
                           }
                       } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
                           if (!grep(/^\Q$1\E$/,@userroles)) {
                               push(@userroles,$1);
                           }
                       }
                   }
               }
           }
           #Check to see if we can change personal data for the user 
           my (@mod_disallowed,@longroles);
           foreach my $role (@userroles) {
               if ($role eq 'cr') {
                   push(@longroles,'Custom');
               } else {
                   push(@longroles,&Apache::lonnet::plaintext($role)); 
               }
           }
         foreach my $item ('firstname','middlename','lastname','generation','permanentemail','id') {          foreach my $item ('firstname','middlename','lastname','generation','permanentemail','id') {
               my $canmodify = 0;
               if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
                   $canmodify = 1;
               } else {
                   if ($context eq 'course' || $context eq 'author') {
                       if (ref($domconfig{'usermodification'}) eq 'HASH') {
                           if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
                               foreach my $role (@userroles) {
                                   if (ref($domconfig{'usermodification'}{$context}{$role}) eq 'HASH') {
                                       if ($domconfig{'usermodification'}{$context}{$role}{$item}) {
                                           $canmodify = 1;
                                           last;
                                       }
                                   }
                               }
                           }
                       }
                   } elsif ($context eq 'course') {
                       if (grep(/^st$/,@userroles)) {
                           $canmodify = 1;
                       }
                   }
               }
             # Strip leading and trailing whitespace              # Strip leading and trailing whitespace
             $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;              $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
               if (!$canmodify) {
                   if ($env{'form.c'.$item} ne $userenv{$item}) {
                       push(@mod_disallowed,$item);
                   }
                   $env{'form.c'.$item} = $userenv{$item};
               }
         }          }
         # Check to see if we can change the ID/student number          # Check to see if we can change the ID/student number
         my $forceid = $env{'form.forceid'};          my $forceid = $env{'form.forceid'};
Line 1591  sub update_user_data { Line 1728  sub update_user_data {
             (!$forceid)) {              (!$forceid)) {
             if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {              if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
                 $env{'form.cid'} = $userenv{'id'};                  $env{'form.cid'} = $userenv{'id'};
                   $no_forceid_alert = &mt('New student/employeeID does not match existing ID for this user.').'<br />'.&mt('Change is not permitted without checking the \'Force ID change\' checkbox on the previous page.').'<br />'."\n";        
             }              }
         }          }
         if ($env{'form.cid'} ne $userenv{'id'}) {          if ($env{'form.cid'} ne $userenv{'id'}) {
Line 1654  sub update_user_data { Line 1792  sub update_user_data {
         if ($newisdefault) {          if ($newisdefault) {
             $newdefquotatext = &get_defaultquota_text($settingstatus);              $newdefquotatext = &get_defaultquota_text($settingstatus);
         }          }
         if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}) &&           if ($env{'form.cfirstname'}  ne $userenv{'firstname'}  ||
             ($env{'form.cfirstname'}  ne $userenv{'firstname'}  ||              $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
              $env{'form.cmiddlename'} ne $userenv{'middlename'} ||              $env{'form.clastname'}   ne $userenv{'lastname'}   ||
              $env{'form.clastname'}   ne $userenv{'lastname'}   ||              $env{'form.cgeneration'} ne $userenv{'generation'} ||
              $env{'form.cgeneration'} ne $userenv{'generation'} ||              $env{'form.cid'} ne $userenv{'id'}                 ||
              $env{'form.cid'} ne $userenv{'id'}                 ||              $env{'form.cpermanentemail'} ne $userenv{'permanentemail'} ) {
              $env{'form.cpermanentemail'} ne $userenv{'permanentemail'} )) {  
             $namechanged = 1;              $namechanged = 1;
         }          }
         if ($namechanged || $quotachanged) {          if ($namechanged || $quotachanged) {
Line 1738  END Line 1875  END
     <td>$newportfolioquota Mb $newdefquotatext </td>      <td>$newportfolioquota Mb $newdefquotatext </td>
 END  END
                 $r->print(&Apache::loncommon::end_data_table_row().                  $r->print(&Apache::loncommon::end_data_table_row().
                           &Apache::loncommon::end_data_table());                            &Apache::loncommon::end_data_table().'<br />');
                 if ($env{'form.cid'} ne $userenv{'id'}) {                  if ($env{'form.cid'} ne $userenv{'id'}) {
                     &Apache::lonnet::idput($env{'form.ccdomain'},                      &Apache::lonnet::idput($env{'form.ccdomain'},
                          ($env{'form.ccuname'} => $env{'form.cid'}));                           ($env{'form.ccuname'} => $env{'form.cid'}));
Line 1769  END Line 1906  END
             } else { # error occurred              } else { # error occurred
                 $r->print('<span class="LC_error">'.&mt('Unable to successfully change environment for').' '.                  $r->print('<span class="LC_error">'.&mt('Unable to successfully change environment for').' '.
                       $env{'form.ccuname'}.' '.&mt('in domain').' '.                        $env{'form.ccuname'}.' '.&mt('in domain').' '.
                       $env{'form.ccdomain'}.'</span>');                        $env{'form.ccdomain'}.'</span><br />');
             }              }
         }  else { # End of if ($env ... ) logic          }  else { # End of if ($env ... ) logic
             # They did not want to change the users name or quota but we can              # They did not want to change the users name or quota but we can
Line 1789  END Line 1926  END
             $r->print('<br />['.$lt{'disk'}.': '.$oldportfolioquota.' Mb '.               $r->print('<br />['.$lt{'disk'}.': '.$oldportfolioquota.' Mb '. 
                  $olddefquotatext.']</h4>');                   $olddefquotatext.']</h4>');
         }          }
           if (@mod_disallowed) {
               my ($rolestr,$contextname);
               if (@longroles > 0) {
                   $rolestr = join(', ',@longroles);
               } else {
                   $rolestr = &mt('No roles');
               }
               if ($context eq 'course') {
                   $contextname = &mt('course');
               } elsif ($context eq 'author') {
                   $contextname = &mt('co-author');
               }
               $r->print(&mt('The following fields were not updated: ').'<ul>');
               my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
               foreach my $field (@mod_disallowed) {
                   $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n"); 
               }
               $r->print('</ul>'.&mt("You do not have the authority to change these fields given the user's current set of active/future [_1] roles: <span class=\"LC_cusr_emph\">[_2]</span>.",$contextname,$rolestr).'<br />'.&mt('Contact your <a href="[_1]">helpdesk</a> for more information.',"javascript:helpMenu('display')").'<br />');
           }
           $r->print($no_forceid_alert.
                     &Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts, \%curr_rules));
     }      }
     ##      ##
     my $now=time;      my $now=time;
Line 2398  sub handler { Line 2556  sub handler {
     if ($env{'request.course.id'}) {      if ($env{'request.course.id'}) {
         $context = 'course';          $context = 'course';
     } elsif ($env{'request.role'} =~ /^au\./) {      } elsif ($env{'request.role'} =~ /^au\./) {
         $context = 'construction_space';          $context = 'author';
     } else {      } else {
         $context = 'domain';          $context = 'domain';
     }      }
Line 2513  sub handler { Line 2671  sub handler {
                                               $context);                                                $context);
             }              }
         } elsif ($env{'form.phase'} eq 'update_user_data') {          } elsif ($env{'form.phase'} eq 'update_user_data') {
             &update_user_data($r);              &update_user_data($r,$context);
         } else {          } else {
             &print_username_entry_form($r,undef,$srch);              &print_username_entry_form($r,undef,$srch);
         }          }
Line 2709  sub get_permission { Line 2867  sub get_permission {
                 }                  }
             }              }
         }          }
     } elsif ($context eq 'construction_space') {      } elsif ($context eq 'author') {
         $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});          $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});
         $permission{'view'} = $permission{'cusr'};          $permission{'view'} = $permission{'cusr'};
     } else {      } else {

Removed from v.1.205  
changed lines
  Added in v.1.206


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>