Diff for /loncom/interface/loncreateuser.pm between versions 1.194 and 1.204

version 1.194, 2007/11/12 15:37:47 version 1.204, 2007/12/07 23:09:30
Line 440  sub print_user_query_page { Line 440  sub print_user_query_page {
 }  }
   
 sub print_user_modification_page {  sub print_user_modification_page {
     my ($r,$ccuname,$ccdomain,$srch,$response) = @_;      my ($r,$ccuname,$ccdomain,$srch,$response,$context) = @_;
     if (($ccuname eq '') || ($ccdomain eq '')) {      if (($ccuname eq '') || ($ccdomain eq '')) {
         my $usermsg = &mt('No username and/or domain provided.');           my $usermsg = &mt('No username and/or domain provided.'); 
  &print_username_entry_form($r,$usermsg);   &print_username_entry_form($r,$usermsg);
Line 448  sub print_user_modification_page { Line 448  sub print_user_modification_page {
     }      }
     my %abv_auth = &auth_abbrev();      my %abv_auth = &auth_abbrev();
     my ($curr_authtype,%rulematch,%inst_results,$curr_kerb_ver,$newuser,      my ($curr_authtype,%rulematch,%inst_results,$curr_kerb_ver,$newuser,
         %alerts,%curr_rules);          %alerts,%curr_rules,%got_rules);
     my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);      my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
     if ($uhome eq 'no_host') {      if ($uhome eq 'no_host') {
         $newuser = 1;          $newuser = 1;
         my $checkhash;          my $checkhash;
         my $checks = { 'username' => 1 };          my $checks = { 'username' => 1 };
         $checkhash->{$ccuname.':'.$ccdomain} = { 'status' => 'new' };          $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
         &Apache::loncommon::user_rule_check($checkhash,$checks,          &Apache::loncommon::user_rule_check($checkhash,$checks,
                    \%alerts,\%rulematch,\%inst_results,\%curr_rules);              \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
         if (ref($alerts{$ccuname.':'.$ccdomain}) eq 'HASH') {          if (ref($alerts{'username'}) eq 'HASH') {
             if ($alerts{$ccuname.':'.$ccdomain}{'username'}) {              if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
                 my $domdesc =                   my $domdesc =
                     &Apache::lonnet::domain($ccdomain,'description');                      &Apache::lonnet::domain($ccdomain,'description');
                 my $userchkmsg;                  if ($alerts{'username'}{$ccdomain}{$ccuname}) {
                 if (ref($curr_rules{$ccdomain}) eq 'HASH') {                        my $userchkmsg;
                     $userchkmsg =                       if (ref($curr_rules{$ccdomain}) eq 'HASH') {  
                         &Apache::loncommon::instrule_disallow_msg('username',                          $userchkmsg = 
                               &Apache::loncommon::instrule_disallow_msg('username',
                                                                  $domdesc,1).                                                                   $domdesc,1).
                         &Apache::loncommon::user_rule_formats($ccdomain,                          &Apache::loncommon::user_rule_formats($ccdomain,
                             $domdesc,$curr_rules{$ccdomain}{'username'},                              $domdesc,$curr_rules{$ccdomain}{'username'},
                             'username');                              'username');
                 }                      }
                 &print_username_entry_form($r,$userchkmsg);                      &print_username_entry_form($r,$userchkmsg);
                 return;                      return;
                   } 
             }              }
         }          }
     } else {      } else {
Line 625  sub print_user_modification_page { Line 627  sub print_user_modification_page {
     }      }
 ENDSCRIPT  ENDSCRIPT
     } else {      } else {
         $nondc_setsection_code = <<"ENDSECCODE";          $nondc_setsection_code = 
     function setSections() {              &Apache::lonuserutils::setsections_javascript('cu',$groupslist);
         var re1 = /^currsec_/;  
         var groups = new Array($groupslist);  
         for (var i=0;i<document.cu.elements.length;i++) {  
             var str = document.cu.elements[i].name;  
             var checkcurr = str.match(re1);  
             if (checkcurr != null) {  
                 if (document.cu.elements[i-1].checked == true) {  
     var match = str.split('_');  
                     var role = match[3];  
                     if (role == 'cc') {  
                         alert("Section designations do not apply to Course Coordinator roles.\\nA course coordinator role will be added with access to all sections.");  
                     }  
                     else {  
                         var sections = '';  
                         var numsec = 0;  
                         var sections;  
                         for (var j=0; j<document.cu.elements[i].length; j++) {  
                             if (document.cu.elements[i].options[j].selected == true ) {  
                                 if (document.cu.elements[i].options[j].value != "") {  
                                     if (numsec == 0) {  
                                         if (document.cu.elements[i].options[j].value != "") {  
                                             sections = document.cu.elements[i].options[j].value;  
                                             numsec ++;  
                                         }  
                                     }  
                                     else {  
                                         sections = sections + "," +  document.cu.elements[i].options[j].value  
                                         numsec ++;  
                                     }  
                                 }  
                             }  
                         }  
                         if (numsec > 0) {  
                             if (document.cu.elements[i+1].value != "" && document.cu.elements[i+1].value != null) {  
                                 sections = sections + "," +  document.cu.elements[i+1].value;  
                             }  
                         }  
                         else {  
                             sections = document.cu.elements[i+1].value;  
                         }  
                         var newsecs = document.cu.elements[i+1].value;  
  var numsplit;  
                         if (newsecs != null && newsecs != "") {  
                             numsplit = newsecs.split(/,/g);  
                             numsec = numsec + numsplit.length;  
                         }  
   
                         if ((role == 'st') && (numsec > 1)) {  
                             alert("In each course, each user may only have one student role at a time. You had selected "+numsec+" sections.\\nPlease modify your selections so they include no more than one section.")  
                             return;  
                         }  
                         else if (numsplit != null) {  
                             for (var j=0; j<numsplit.length; j++) {  
                                 if ((numsplit[j] == 'all') ||  
                                     (numsplit[j] == 'none')) {  
                                     alert("'"+numsplit[j]+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");  
                                     return;  
                                 }  
                                 for (var k=0; k<groups.length; k++) {  
                                     if (numsplit[j] == groups[k]) {  
                                         alert("'"+numsplit[j]+"' may not be used as a section name, as it is the name of a course group.\\nSection names and group names must be distinct. Please choose a different section name.");  
                                         return;  
                                     }  
                                 }  
                             }  
                         }  
                         document.cu.elements[i+2].value = sections;  
                     }  
                 }  
             }  
         }  
         document.cu.submit();  
     }  
 ENDSECCODE  
     }      }
     my $js = &user_modification_js($pjump_def,$dc_setcourse_code,      my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
                                    $nondc_setsection_code,$groupslist);                                     $nondc_setsection_code,$groupslist);
Line 857  $forminfo Line 785  $forminfo
 ENDCHANGEUSER  ENDCHANGEUSER
         $r->print('<div class="LC_left_float">'.          $r->print('<div class="LC_left_float">'.
                   &personal_data_display($ccuname,$ccdomain,$newuser,                    &personal_data_display($ccuname,$ccdomain,$newuser,
                                          %inst_results).                                           %inst_results));
                   '</div>');          if ($context eq 'domain') {
               $r->print(&Apache::lonuserutils::forceid_change($context));
           }
           $r->print('</div>');
         my $user_auth_text =           my $user_auth_text = 
             &user_authentication($ccuname,$ccdomain,$krbdefdom,\%abv_auth);              &user_authentication($ccuname,$ccdomain,$krbdefdom,\%abv_auth);
         my $user_quota_text;          my $user_quota_text;
Line 1209  ENDNOPORTPRIV Line 1140  ENDNOPORTPRIV
         }          }
     } else {      } else {
         $r->print(&course_level_table(%inccourses));          $r->print(&course_level_table(%inccourses));
         $r->print('<br /><input type="button" value="'.&mt('Modify User').'" onClick="setSections()" />'."\n");          $r->print('<br /><input type="button" value="'.&mt('Modify User').'" onClick="setSections(this.form)" />'."\n");
     }      }
     $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));      $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
     $r->print('<input type="hidden" name="currstate" value="" />');      $r->print('<input type="hidden" name="currstate" value="" />');
Line 1266  $lt{'uuas'} ($currentauth). $lt{'adcs'}. Line 1197  $lt{'uuas'} ($currentauth). $lt{'adcs'}.
 ENDBADAUTH  ENDBADAUTH
         }          }
     } else { # Authentication type is valid      } else { # Authentication type is valid
         my $authformcurrent='';  
         my $authform_other='';  
         &initialize_authen_forms($ccdomain,$currentauth);          &initialize_authen_forms($ccdomain,$currentauth);
           my $authformnop_row;      
           if (&Apache::lonnet::allowed('mau',$ccdomain)) {
               $authformnop_row = &Apache::loncommon::start_data_table_row();
           }
         my ($authformcurrent,$authform_other,$can_modify) =          my ($authformcurrent,$authform_other,$can_modify) =
             &modify_login_block($ccdomain,$currentauth);              &modify_login_block($ccdomain,$currentauth);
         if (&Apache::lonnet::allowed('mau',$ccdomain)) {          if (&Apache::lonnet::allowed('mau',$ccdomain)) {
Line 1284  ENDBADAUTH Line 1217  ENDBADAUTH
                        '</script>'."\n".                         '</script>'."\n".
                        '<h3>'.$lt{'ld'}.'</h3>'.                         '<h3>'.$lt{'ld'}.'</h3>'.
                        &Apache::loncommon::start_data_table().                         &Apache::loncommon::start_data_table().
                        &Apache::loncommon::start_data_table_row().                         $authformnop_row.
                        '<td>'.$authformnop;                         '<td>'.$authformnop;
             if ($can_modify) {              if ($can_modify) {
                 $outcome .= '</td>'."\n".                  $outcome .= '</td>'."\n".
Line 1293  ENDBADAUTH Line 1226  ENDBADAUTH
                             '<td>'.$authformcurrent.'</td>'.                              '<td>'.$authformcurrent.'</td>'.
                             &Apache::loncommon::end_data_table_row()."\n";                              &Apache::loncommon::end_data_table_row()."\n";
             } else {              } else {
                 $outcome .= '&nbsp;('.$authformcurrent.')</td>';                  $outcome .= '&nbsp;('.$authformcurrent.')</td>'.
                               &Apache::loncommon::end_data_table_row()."\n";
             }              }
             if ($authform_other ne '') {              if ($authform_other ne '') {
                 $outcome .= $authform_other;                  $outcome .= $authform_other;
Line 1585  sub update_user_data { Line 1519  sub update_user_data {
         my %checkhash;          my %checkhash;
         my %checks = ('id' => 1);          my %checks = ('id' => 1);
         %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (          %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
             'status' => 'new',               'newuser' => 1, 
             'id' => $env{'form.cid'}              'id' => $env{'form.cid'},
         );          );
         &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,          if ($env{'form.cid'} ne '') {
                                       \%rulematch,\%inst_results,\%curr_rules);              &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
         if (ref($alerts{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}) eq 'HASH') {                                            \%rulematch,\%inst_results,\%curr_rules);
             if ($alerts{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}{'id'}) {              if (ref($alerts{'id'}) eq 'HASH') {
                 my $domdesc =                  if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
                     &Apache::lonnet::domain($env{'form.ccdomain'},'description');                      my $domdesc =
                 my $userchkmsg;                          &Apache::lonnet::domain($env{'form.ccdomain'},'description');
                 if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {                      if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
                     $userchkmsg  =                           my $userchkmsg;
                         &Apache::loncommon::instrule_disallow_msg('id',                          if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
                                                                   $domdesc,1).                              $userchkmsg  = 
                         &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},                                  &Apache::loncommon::instrule_disallow_msg('id',
                             $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');                                                                      $domdesc,1).
                 }                                   &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
                 $r->print($error.&mt('Invalid ID format').$end.                                      $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
                           $userchkmsg.$rtnlink);                          }
                 return;                          $r->print($error.&mt('Invalid ID format').$end.
                                     $userchkmsg.$rtnlink);
                           return;
                       }
                   }
             }              }
         }          }
  # Call modifyuser   # Call modifyuser
Line 1644  sub update_user_data { Line 1582  sub update_user_data {
         # Check for need to change          # Check for need to change
         my %userenv = &Apache::lonnet::get          my %userenv = &Apache::lonnet::get
             ('environment',['firstname','middlename','lastname','generation',              ('environment',['firstname','middlename','lastname','generation',
              'permanentemail','portfolioquota','inststatus'],               'id','permanentemail','portfolioquota','inststatus'],
               $env{'form.ccdomain'},$env{'form.ccuname'});                $env{'form.ccdomain'},$env{'form.ccuname'});
         my ($tmp) = keys(%userenv);          my ($tmp) = keys(%userenv);
         if ($tmp =~ /^(con_lost|error)/i) {           if ($tmp =~ /^(con_lost|error)/i) { 
             %userenv = ();              %userenv = ();
         }          }
         # Check to see if we need to change user information          # Check to see if we need to change user information
         foreach my $item ('firstname','middlename','lastname','generation','permanentemail') {          foreach my $item ('firstname','middlename','lastname','generation','permanentemail','id') {
             # 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;
           }
           # Check to see if we can change the ID/student number
           my $forceid = $env{'form.forceid'};
           my $recurseid = $env{'form.recurseid'};
           my $newuser = 0;
           my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
           my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
                                               $env{'form.ccuname'});
           if (($uidhash{$env{'form.ccuname'}}) && 
               ($uidhash{$env{'form.ccuname'}}!~/error\:/) && 
               (!$forceid)) {
               if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
                   $env{'form.cid'} = $userenv{'id'};
               }
           }
           if ($env{'form.cid'} ne $userenv{'id'}) {
               my $checkhash;
               my $checks = { 'id' => 1 };
               $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} = 
                      { 'newuser' => $newuser,
                        'id'  => $env{'form.cid'}, 
                      };
               &Apache::loncommon::user_rule_check($checkhash,$checks,
                   \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
               if (ref($alerts{'id'}) eq 'HASH') {
                   if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
                      $env{'form.cid'} = $userenv{'id'};
                   }
               }
         }          }
         my ($quotachanged,$namechanged,$oldportfolioquota,$newportfolioquota,          my ($quotachanged,$namechanged,$oldportfolioquota,$newportfolioquota,
             $inststatus,$isdefault,$defquotatext);              $inststatus,$oldisdefault,$newisdefault,$olddefquotatext,
               $newdefquotatext);
         my ($defquota,$settingstatus) =           my ($defquota,$settingstatus) = 
             &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);              &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
         my %changeHash;          my %changeHash;
           $changeHash{'portfolioquota'} = $userenv{'portfolioquota'};
         if ($userenv{'portfolioquota'} ne '') {          if ($userenv{'portfolioquota'} ne '') {
             $oldportfolioquota = $userenv{'portfolioquota'};              $oldportfolioquota = $userenv{'portfolioquota'};
             if ($env{'form.customquota'} == 1) {              if ($env{'form.customquota'} == 1) {
Line 1669  sub update_user_data { Line 1638  sub update_user_data {
                     $newportfolioquota = $env{'form.portfolioquota'};                      $newportfolioquota = $env{'form.portfolioquota'};
                     $newportfolioquota =~ s/[^\d\.]//g;                      $newportfolioquota =~ s/[^\d\.]//g;
                 }                  }
                 if ($newportfolioquota != $userenv{'portfolioquota'}) {                  if ($newportfolioquota != $oldportfolioquota) {
                     $quotachanged = &quota_admin($newportfolioquota,\%changeHash);                      $quotachanged = &quota_admin($newportfolioquota,\%changeHash);
                 }                  }
             } else {              } else {
                 $quotachanged = &quota_admin('',\%changeHash);                  $quotachanged = &quota_admin('',\%changeHash);
                 $newportfolioquota = $defquota;                  $newportfolioquota = $defquota;
                 $isdefault = 1;                   $newisdefault = 1; 
             }              }
         } else {          } else {
               $oldisdefault = 1;
             $oldportfolioquota = $defquota;              $oldportfolioquota = $defquota;
             if ($env{'form.customquota'} == 1) {              if ($env{'form.customquota'} == 1) {
                 if ($env{'form.portfolioquota'} eq '') {                  if ($env{'form.portfolioquota'} eq '') {
Line 1689  sub update_user_data { Line 1659  sub update_user_data {
                 $quotachanged = &quota_admin($newportfolioquota,\%changeHash);                  $quotachanged = &quota_admin($newportfolioquota,\%changeHash);
             } else {              } else {
                 $newportfolioquota = $defquota;                  $newportfolioquota = $defquota;
                 $isdefault = 1;                  $newisdefault = 1;
             }              }
         }          }
         if ($isdefault) {          if ($oldisdefault) {
             if ($settingstatus eq '') {              $olddefquotatext = &get_defaultquota_text($settingstatus);
                 $defquotatext = &mt('(default)');          }
             } else {          if ($newisdefault) {
                 my ($usertypes,$order) =               $newdefquotatext = &get_defaultquota_text($settingstatus);
                     &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});  
                 if ($usertypes->{$settingstatus} eq '') {  
                     $defquotatext = &mt('(default)');  
                 } else {   
                     $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});  
                 }  
             }  
         }          }
         if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}) &&           if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}) && 
             ($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.cpermanentemail'} ne $userenv{'permanentemail'} )) {               $env{'form.cpermanentemail'} ne $userenv{'permanentemail'} )) {
             $namechanged = 1;              $namechanged = 1;
         }          }
         if ($namechanged) {          if ($namechanged || $quotachanged) {
             # Make the change  
             $changeHash{'firstname'}  = $env{'form.cfirstname'};              $changeHash{'firstname'}  = $env{'form.cfirstname'};
             $changeHash{'middlename'} = $env{'form.cmiddlename'};              $changeHash{'middlename'} = $env{'form.cmiddlename'};
             $changeHash{'lastname'}   = $env{'form.clastname'};              $changeHash{'lastname'}   = $env{'form.clastname'};
             $changeHash{'generation'} = $env{'form.cgeneration'};              $changeHash{'generation'} = $env{'form.cgeneration'};
               $changeHash{'id'}         = $env{'form.cid'};
             $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};              $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
             my $putresult = &Apache::lonnet::put              my ($quotachgresult,$namechgresult);
                 ('environment',\%changeHash,              if ($quotachanged) {
                  $env{'form.ccdomain'},$env{'form.ccuname'});                  $quotachgresult = 
             if ($putresult eq 'ok') {                      &Apache::lonnet::put('environment',\%changeHash,
                                     $env{'form.ccdomain'},$env{'form.ccuname'});
               }
               if ($namechanged) {
               # Make the change
                   $namechgresult =
                       &Apache::lonnet::modifyuser($env{'form.ccdomain'},
                           $env{'form.ccuname'},$changeHash{'id'},undef,undef,
                           $changeHash{'firstname'},$changeHash{'middlename'},
                           $changeHash{'lastname'},$changeHash{'generation'},
                           $changeHash{'id'},undef,$changeHash{'permanentemail'});
               }
               if (($namechanged && $namechgresult eq 'ok') || 
                   ($quotachanged && $quotachgresult eq 'ok')) {
             # Tell the user we changed the name              # Tell the user we changed the name
  my %lt=&Apache::lonlocal::texthash(   my %lt=&Apache::lonlocal::texthash(
                              'uic'  => "User Information Changed",                                            'uic'  => "User Information Changed",             
Line 1731  sub update_user_data { Line 1708  sub update_user_data {
                              'mddl' => "middle",                               'mddl' => "middle",
                              'lst'  => "last",                               'lst'  => "last",
      'gen'  => "generation",       'gen'  => "generation",
                                'id'   => "ID/Student number",
                              'mail' => "permanent e-mail",                               'mail' => "permanent e-mail",
                              'disk' => "disk space allocated to portfolio files",                               'disk' => "disk space allocated to portfolio files",
                              'prvs' => "Previous",                               'prvs' => "Previous",
                              'chto' => "Changed To"                               'chto' => "Changed To"
    );     );
                   $r->print('<h4>'.$lt{'uic'}.'</h4>'.
                             &Apache::loncommon::start_data_table().
                             &Apache::loncommon::start_data_table_header_row());
                 $r->print(<<"END");                  $r->print(<<"END");
 <table border="2">      <th>&nbsp;</th>
 <caption>$lt{'uic'}</caption>  
 <tr><th>&nbsp;</th>  
     <th>$lt{'frst'}</th>      <th>$lt{'frst'}</th>
     <th>$lt{'mddl'}</th>      <th>$lt{'mddl'}</th>
     <th>$lt{'lst'}</th>      <th>$lt{'lst'}</th>
     <th>$lt{'gen'}</th>      <th>$lt{'gen'}</th>
       <th>$lt{'id'}</th>
     <th>$lt{'mail'}</th>      <th>$lt{'mail'}</th>
     <th>$lt{'disk'}</th></tr>      <th>$lt{'disk'}</th>
 <tr><td>$lt{'prvs'}</td>  END
                   $r->print(&Apache::loncommon::end_data_table_header_row().
                             &Apache::loncommon::start_data_table_row());
                   $r->print(<<"END");
       <td><b>$lt{'prvs'}</b></td>
     <td>$userenv{'firstname'}  </td>      <td>$userenv{'firstname'}  </td>
     <td>$userenv{'middlename'} </td>      <td>$userenv{'middlename'} </td>
     <td>$userenv{'lastname'}   </td>      <td>$userenv{'lastname'}   </td>
     <td>$userenv{'generation'} </td>      <td>$userenv{'generation'} </td>
       <td>$userenv{'id'}</td>
     <td>$userenv{'permanentemail'} </td>      <td>$userenv{'permanentemail'} </td>
     <td>$oldportfolioquota Mb</td>      <td>$oldportfolioquota Mb $olddefquotatext </td>
 </tr>  END
 <tr><td>$lt{'chto'}</td>                  $r->print(&Apache::loncommon::end_data_table_row().
                             &Apache::loncommon::start_data_table_row());
                   $r->print(<<"END");
       <td><b>$lt{'chto'}</b></td>
     <td>$env{'form.cfirstname'}  </td>      <td>$env{'form.cfirstname'}  </td>
     <td>$env{'form.cmiddlename'} </td>      <td>$env{'form.cmiddlename'} </td>
     <td>$env{'form.clastname'}   </td>      <td>$env{'form.clastname'}   </td>
     <td>$env{'form.cgeneration'} </td>      <td>$env{'form.cgeneration'} </td>
       <td>$env{'form.cid'} </td>
     <td>$env{'form.cpermanentemail'} </td>      <td>$env{'form.cpermanentemail'} </td>
     <td>$newportfolioquota Mb $defquotatext </td></tr>      <td>$newportfolioquota Mb $newdefquotatext </td>
 </table>  
 END  END
                   $r->print(&Apache::loncommon::end_data_table_row().
                             &Apache::loncommon::end_data_table());
                   if ($env{'form.cid'} ne $userenv{'id'}) {
                       &Apache::lonnet::idput($env{'form.ccdomain'},
                            ($env{'form.ccuname'} => $env{'form.cid'}));
                       if (($recurseid) &&
                           (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
                           my %userupdate = (
                                     lastname   => $env{'form.clasaname'},
                                     middlename => $env{'form.cmiddlename'},
                                     firstname  => $env{'form.cfirstname'},
                                     generation => $env{'fora.cgeneration'},
                                     id         => $env{'form.cid'},
                                );
                           my $idresult = 
                               &Apache::lonuserutils::propagate_id_change(
                                   $env{'form.ccuname'},$env{'form.ccdomain'},
                                   \%userupdate);
                           $r->print('<br />'.$idresult.'<br />');
                       }
                   }
                 if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&                   if (($env{'form.ccdomain'} eq $env{'user.domain'}) && 
                     ($env{'form.ccuname'} eq $env{'user.name'})) {                      ($env{'form.ccuname'} eq $env{'user.name'})) {
                     my %newenvhash;                      my %newenvhash;
Line 1777  END Line 1786  END
                       $env{'form.ccdomain'}.'</span>');                        $env{'form.ccdomain'}.'</span>');
             }              }
         }  else { # End of if ($env ... ) logic          }  else { # End of if ($env ... ) logic
             my $putresult;              # They did not want to change the users name or quota but we can
             if ($quotachanged) {              # still tell them what the name and quota are 
                 $putresult = &Apache::lonnet::put  
                                  ('environment',\%changeHash,  
                                   $env{'form.ccdomain'},$env{'form.ccuname'});  
             }  
             # They did not want to change the users name but we can  
             # still tell them what the name is  
     my %lt=&Apache::lonlocal::texthash(      my %lt=&Apache::lonlocal::texthash(
                              'id'   => "ID/Student number",
                            'mail' => "Permanent e-mail",                             'mail' => "Permanent e-mail",
                            'disk' => "Disk space allocated to user's portfolio files",                             'disk' => "Disk space allocated to user's portfolio files",
        );         );
             $r->print(<<"END");              $r->print(<<"END");
 <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}&nbsp;&nbsp;($lt{'mail'}: $userenv{'permanentemail'})</h4>  <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}
 END  END
             if ($putresult eq 'ok') {              if ($userenv{'permanentemail'} ne '') {
                 if ($oldportfolioquota != $newportfolioquota) {                  $r->print('<br />['.$lt{'mail'}.': '.
                     $r->print('<h4>'.$lt{'disk'}.': '.$newportfolioquota.' Mb '.                             $userenv{'permanentemail'}.']');
                               $defquotatext.'</h4>');  
                     &Apache::lonnet::appenv('environment.portfolioquota' => $changeHash{'portfolioquota'});  
                 }  
             }              }
               $r->print('<br />['.$lt{'disk'}.': '.$oldportfolioquota.' Mb '. 
                    $olddefquotatext.']</h4>');
         }          }
     }      }
     ##      ##
Line 1820  END Line 1823  END
         $r->print(&mt('Revoking [_1] in [_2]: [_3]',          $r->print(&mt('Revoking [_1] in [_2]: [_3]',
       $role,$scope,'<b>'.$result.'</b>').'<br />');        $role,$scope,'<b>'.$result.'</b>').'<br />');
  if ($role eq 'st') {   if ($role eq 'st') {
     my $result = &classlist_drop($scope,$env{'form.ccuname'},      my $result = 
  $env{'form.ccdomain'},$now);                          &Apache::lonuserutils::classlist_drop($scope,
                               $env{'form.ccuname'},$env{'form.ccdomain'},
       $now);
     $r->print($result);      $r->print($result);
  }   }
     }       }
     if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$ }s) {      if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
 # Revoke custom role  # Revoke custom role
  $r->print(&mt('Revoking custom role:').   $r->print(&mt('Revoking custom role:').
                       ' '.$4.' by '.$3.':'.$2.' in '.$1.': <b>'.                        ' '.$4.' by '.$3.':'.$2.' in '.$1.': <b>'.
Line 1845  END Line 1850  END
         $r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope,          $r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope,
       '<b>'.$result.'</b>').'<br />');        '<b>'.$result.'</b>').'<br />');
  if ($role eq 'st') {   if ($role eq 'st') {
     my $result = &classlist_drop($scope,$env{'form.ccuname'},      my $result = 
  $env{'form.ccdomain'},$now);                          &Apache::lonuserutils::classlist_drop($scope,
                               $env{'form.ccuname'},$env{'form.ccdomain'},
       $now);
     $r->print($result);      $r->print($result);
  }   }
             }              }
Line 2023  END Line 2030  END
     $r->print(&Apache::loncommon::end_page());      $r->print(&Apache::loncommon::end_page());
 }  }
   
   sub get_defaultquota_text {
       my ($settingstatus) = @_;
       my $defquotatext; 
       if ($settingstatus eq '') {
           $defquotatext = &mt('(default)');
       } else {
           my ($usertypes,$order) =
               &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
           if ($usertypes->{$settingstatus} eq '') {
               $defquotatext = &mt('(default)');
           } else {
               $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
           }
       }
       return $defquotatext;
   }
   
 sub update_result_form {  sub update_result_form {
     my ($uhome) = @_;      my ($uhome) = @_;
     my $outcome =       my $outcome = 
Line 2045  sub update_result_form { Line 2069  sub update_result_form {
     return $outcome;      return $outcome;
 }  }
   
 sub classlist_drop {  
     my ($scope,$uname,$udom,$now) = @_;  
     my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});  
     my $cid=$cdom.'_'.$cnum;  
     my $user = $uname.':'.$udom;  
     if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {  
  my $result =   
     &Apache::lonnet::cput('classlist',  
   { $user => $now },  
   $env{'course.'.$cid.'.domain'},  
   $env{'course.'.$cid.'.num'});  
  return &mt('Drop from classlist: [_1]',  
    '<b>'.$result.'</b>').'<br />';  
     }  
 }  
   
 sub active_student_roles {  
     my ($cnum,$cdom,$uname,$udom) = @_;  
     my %roles =   
  &Apache::lonnet::get_my_roles($uname,$udom,'userroles',  
       ['future','active'],['st']);  
     return exists($roles{"$cnum:$cdom:st"});  
 }  
   
 sub quota_admin {  sub quota_admin {
     my ($setquota,$changeHash) = @_;      my ($setquota,$changeHash) = @_;
     my $quotachanged;      my $quotachanged;
Line 2417  sub handler { Line 2417  sub handler {
         $context = 'domain';          $context = 'domain';
     }      }
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                                             ['action','state']);          ['action','state','callingform','roletype','showrole','bulkaction']);
     &Apache::lonhtmlcommon::clear_breadcrumbs();      &Apache::lonhtmlcommon::clear_breadcrumbs();
     &Apache::lonhtmlcommon::add_breadcrumb      if ($env{'form.action'} ne 'dateselect') {
         ({href=>"/adm/createuser",          &Apache::lonhtmlcommon::add_breadcrumb
           text=>"User Management"});              ({href=>"/adm/createuser",
                 text=>"User Management"});
       }
     my ($permission,$allowed) = &get_permission($context);      my ($permission,$allowed) = &get_permission($context);
     if (!$allowed) {      if (!$allowed) {
         $env{'user.error.msg'}=          $env{'user.error.msg'}=
Line 2471  sub handler { Line 2473  sub handler {
         if (! exists($env{'form.state'})) {          if (! exists($env{'form.state'})) {
             &Apache::lonuserutils::print_expire_menu($r,$context);              &Apache::lonuserutils::print_expire_menu($r,$context);
         } elsif ($env{'form.state'} eq 'done') {          } elsif ($env{'form.state'} eq 'done') {
             &Apache::lonuserutils::expire_user_list($r);              &Apache::lonuserutils::expire_user_list($r,$context);
         } else {          } else {
             &Apache::lonuserutils::print_expire_menu($r,$context);              &Apache::lonuserutils::print_expire_menu($r,$context);
         }          }
Line 2511  sub handler { Line 2513  sub handler {
                         $response = '';                          $response = '';
                     }                      }
                     &print_user_modification_page($r,$ccuname,$ccdomain,                      &print_user_modification_page($r,$ccuname,$ccdomain,
                                                   $srch,$response);                                                    $srch,$response,$context);
                 } elsif ($currstate eq 'query') {                  } elsif ($currstate eq 'query') {
                     &print_user_query_page($r,'createuser');                      &print_user_query_page($r,'createuser');
                 } else {                  } else {
Line 2521  sub handler { Line 2523  sub handler {
             } elsif ($env{'form.phase'} eq 'userpicked') {              } elsif ($env{'form.phase'} eq 'userpicked') {
                 my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});                  my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
                 my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});                  my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
                 &print_user_modification_page($r,$ccuname,$ccdomain,$srch);                  &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
                                                 $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);
Line 2535  sub handler { Line 2538  sub handler {
             &custom_role_editor($r);              &custom_role_editor($r);
         }          }
     } elsif ($env{'form.action'} eq 'listusers' && $permission->{'view'}) {      } elsif ($env{'form.action'} eq 'listusers' && $permission->{'view'}) {
         my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);          if ($env{'form.phase'} eq 'bulkchange') {
         my $formname = 'studentform';              &Apache::lonhtmlcommon::add_breadcrumb
         if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {                  ({href=>'backPage(document.studentform)',
             ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =                     text=>"List Users"});
                 &Apache::lonuserutils::courses_selector($env{'request.role.domain'},              my $setting = $env{'form.roletype'};
                                                         $formname);              my $choice = $env{'form.bulkaction'};
             my $js = &add_script($jscript).$cb_jscript;              $r->print(&header());
             my $loadcode =               $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
                 &Apache::lonuserutils::course_selector_loadcode($formname);                                                            'User_Management_List'));
             if ($loadcode ne '') {              if ($permission->{'cusr'}) {
                 $r->print(&header($js,{'onload' => $loadcode,}));                  &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice);
               }
           } else {
               &Apache::lonhtmlcommon::add_breadcrumb
                   ({href=>'/adm/createuser?action=listusers',
                     text=>"List Users"});
               my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
               my $formname = 'studentform';
               if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
                   ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) = 
                       &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
                                                               $formname);
                   $jscript .= &verify_user_display();
                   my $js = &add_script($jscript).$cb_jscript;
                   my $loadcode = 
                       &Apache::lonuserutils::course_selector_loadcode($formname);
                   if ($loadcode ne '') {
                       $r->print(&header($js,{'onload' => $loadcode,}));
                   } else {
                       $r->print(&header($js));
                   }
             } else {              } else {
                 $r->print(&header($js));                  $r->print(&header(&add_script(&verify_user_display())));
             }              }
         } else {              $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
             $r->print(&header());                                                            'User_Management_List'));
               &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
                            $formname,$totcodes,$codetitles,$idlist,$idlist_titles);
               $r->print(&Apache::loncommon::end_page());
         }          }
         &Apache::lonhtmlcommon::add_breadcrumb  
             ({href=>'/adm/createuser?action=listusers',  
               text=>"List Users"});  
         $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",  
                                                       'User_Management_List'));  
         &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,  
                      $formname,$totcodes,$codetitles,$idlist,$idlist_titles);  
         $r->print(&Apache::loncommon::end_page());  
     } elsif ($env{'form.action'} eq 'expire' && $permission->{'cusr'}) {      } elsif ($env{'form.action'} eq 'expire' && $permission->{'cusr'}) {
         $r->print(&header());          $r->print(&header());
         &Apache::lonhtmlcommon::add_breadcrumb          &Apache::lonhtmlcommon::add_breadcrumb
Line 2570  sub handler { Line 2588  sub handler {
         if (! exists($env{'form.state'})) {          if (! exists($env{'form.state'})) {
             &Apache::lonuserutils::print_expire_menu($r,$context);              &Apache::lonuserutils::print_expire_menu($r,$context);
         } elsif ($env{'form.state'} eq 'done') {          } elsif ($env{'form.state'} eq 'done') {
             &Apache::lonuserutiles::expire_user_list($r);              &Apache::lonuserutiles::expire_user_list($r,$context);
         } else {          } else {
             &print_expire_menu($r,$context);              &print_expire_menu($r,$context);
         }          }
         $r->print(&Apache::loncommon::end_page());          $r->print(&Apache::loncommon::end_page());
       } elsif ($env{'form.action'} eq 'dateselect') {
           if ($permission->{'cusr'}) {
               $r->print(&header(undef,undef,{'no_nav_bar' => 1}).
                         &Apache::lonuserutils::date_section_selector($context).
                         &Apache::loncommon::end_page());
           } else {
               $r->print(&header().
                        '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>'. 
                        &Apache::loncommon::end_page());
           }
     } else {      } else {
         $r->print(&header());          $r->print(&header());
         $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));            $r->print(&print_main_menu($permission));          $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
           $r->print(&print_main_menu($permission));
         $r->print(&Apache::loncommon::end_page());          $r->print(&Apache::loncommon::end_page());
     }      }
     return OK;      return OK;
 }  }
   
 sub header {  sub header {
     my ($jscript,$loaditems) = @_;      my ($jscript,$loaditems,$args) = @_;
     my $start_page;      my $start_page;
     if (ref($loaditems) eq 'HASH') {      if (ref($loaditems) eq 'HASH') {
         $start_page=&Apache::loncommon::start_page('User Management',$jscript,{'add_entries' => $loaditems,});          $start_page=&Apache::loncommon::start_page('User Management',$jscript,{'add_entries' => $loaditems});
     } else {      } else {
         $start_page=&Apache::loncommon::start_page('User Management',$jscript);          $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
     }      }
     return $start_page;      return $start_page;
 }  }
Line 2599  sub add_script { Line 2628  sub add_script {
     return '<script type="text/javascript">'."\n".$js."\n".'</script>';      return '<script type="text/javascript">'."\n".$js."\n".'</script>';
 }  }
   
   sub verify_user_display {
       my $output = <<"END";
   
   function display_update() {
       document.studentform.action.value = 'listusers';
       document.studentform.phase.value = 'display';
       document.studentform.submit();
   }
   
   END
       return $output;
   
   }
   
 ###############################################################  ###############################################################
 ###############################################################  ###############################################################
 #  Menu Phase One  #  Menu Phase One
Line 3173  sub course_level_table { Line 3216  sub course_level_table {
 <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";  <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
         if ($role ne 'cc') {          if ($role ne 'cc') {
                     if (%sections_count) {                      if (%sections_count) {
                         my $currsec = &course_sections(\%sections_count,$protectedcourse.'_'.$role);                          my $currsec = 
                               &Apache::lonuserutils::course_sections(\%sections_count,
                                                           $protectedcourse.'_'.$role);
                         $table .=                           $table .= 
                     '<td><table class="LC_createuser">'.                      '<td><table class="LC_createuser">'.
                      '<tr class="LC_section_row">                       '<tr class="LC_section_row">
Line 3213  ENDTIMEENTRY Line 3258  ENDTIMEENTRY
 <td>'.$plrole.'</td>  <td>'.$plrole.'</td>
 <td>'.$area.'</td>'."\n";  <td>'.$area.'</td>'."\n";
                 if (%sections_count) {                  if (%sections_count) {
                     my $currsec = &course_sections(\%sections_count,$customrole);                      my $currsec = 
                           &Apache::lonuserutils::course_sections(\%sections_count,
                                                                  $customrole);
                     $table.=                      $table.=
                    '<td><table class="LC_createuser">'.                     '<td><table class="LC_createuser">'.
                    '<tr class="LC_section_row"><td valign="top">'.                     '<tr class="LC_section_row"><td valign="top">'.
Line 3257  $table. Line 3304  $table.
     return $result;      return $result;
 }  }
   
 sub course_sections {  
     my ($sections_count,$role) = @_;  
     my $output = '';  
     my @sections = (sort {$a <=> $b} keys %{$sections_count});  
     if (scalar(@sections) == 1) {  
         $output = '<select name="currsec_'.$role.'" >'."\n".  
                   '  <option value="">Select</option>'."\n".  
                   '  <option value="">No section</option>'."\n".  
                   '  <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";  
     } else {  
         $output = '<select name="currsec_'.$role.'" ';  
         my $multiple = 4;  
         if (scalar(@sections) < 4) { $multiple = scalar(@sections); }  
         $output .= 'multiple="multiple" size="'.$multiple.'">'."\n";  
         foreach my $sec (@sections) {  
             $output .= '<option value="'.$sec.'">'.$sec."</option>\n";  
         }  
     }  
     $output .= '</select>';   
     return $output;  
 }  
   
 sub course_level_dc {  sub course_level_dc {
     my ($dcdom) = @_;      my ($dcdom) = @_;
     my %customroles=&Apache::lonuserutils::my_custom_roles();      my %customroles=&Apache::lonuserutils::my_custom_roles();

Removed from v.1.194  
changed lines
  Added in v.1.204


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