Diff for /loncom/interface/loncreateuser.pm between versions 1.217 and 1.221

version 1.217, 2007/12/21 15:33:32 version 1.221, 2007/12/21 20:34:26
Line 809  ENDNOPORTPRIV Line 809  ENDNOPORTPRIV
             &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses);              &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses);
         }          }
     } ## End of new user/old user logic      } ## End of new user/old user logic
     my $addrolesdisplay = 0;  
     $r->print('<h3>'.&mt('Add Roles').'</h3>');      if ($env{'form.action'} eq 'singlestudent') {
 #          $r->print('<br /><input type="button" value="'.&mt('Enroll Student').'" onClick="setSections(this.form)" />'."\n");
 # Co-Author      } else {
 #           $r->print('<h3>'.&mt('Add Roles').'</h3>');
     if (&Apache::lonuserutils::authorpriv($env{'user.name'},          my $addrolesdisplay = 0;
                                           $env{'request.role.domain'}) &&          if ($context eq 'domain' || $context eq 'author') {
         ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {              $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
         # No sense in assigning co-author role to yourself          }
         $addrolesdisplay = 1;          if ($context eq 'domain') {
  my $cuname=$env{'user.name'};              my $add_domainroles = &new_domain_roles($r);
         my $cudom=$env{'request.role.domain'};              if (!$addrolesdisplay) {
    my %lt=&Apache::lonlocal::texthash(                  $addrolesdisplay = $add_domainroles;
     'cs'   => "Construction Space",  
                     'act'  => "Activate",                      
                     'rol'  => "Role",  
                     'ext'  => "Extent",  
                     'sta'  => "Start",  
                     'end'  => "End",  
                     'cau'  => "Co-Author",  
                     'caa'  => "Assistant Co-Author",  
                     'ssd'  => "Set Start Date",  
                     'sed'  => "Set End Date"  
        );  
        $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".   
            &Apache::loncommon::start_data_table()."\n".  
            &Apache::loncommon::start_data_table_header_row()."\n".  
            '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.  
            '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.  
            '<th>'.$lt{'end'}.'</th>'."\n".  
            &Apache::loncommon::end_data_table_header_row()."\n".  
            &Apache::loncommon::start_data_table_row()."\n".  
            '<td>  
             <input type=checkbox name="act_'.$cudom.'_'.$cuname.'_ca" />  
            </td>  
            <td>'.$lt{'cau'}.'</td>  
            <td>'.$cudom.'_'.$cuname.'</td>  
            <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />  
              <a href=  
 "javascript:pjump('."'date_start','Start Date Co-Author',document.cu.start_$cudom\_$cuname\_ca.value,'start_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>  
 <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />  
 <a href=  
 "javascript:pjump('."'date_end','End Date Co-Author',document.cu.end_$cudom\_$cuname\_ca.value,'end_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".  
           &Apache::loncommon::end_data_table_row()."\n".  
           &Apache::loncommon::start_data_table_row()."\n".  
 '<td><input type=checkbox name="act_'.$cudom.'_'.$cuname.'_aa" /></td>  
 <td>'.$lt{'caa'}.'</td>  
 <td>'.$cudom.'_'.$cuname.'</td>  
 <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />  
 <a href=  
 "javascript:pjump('."'date_start','Start Date Assistant Co-Author',document.cu.start_$cudom\_$cuname\_aa.value,'start_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>  
 <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />  
 <a href=  
 "javascript:pjump('."'date_end','End Date Assistant Co-Author',document.cu.end_$cudom\_$cuname\_aa.value,'end_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".  
          &Apache::loncommon::end_data_table_row()."\n".  
          &Apache::loncommon::end_data_table());  
     } elsif ($env{'request.role'} =~ /^au\./) {  
         if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},  
                                                 $env{'request.role.domain'}))) {  
             $r->print('<span class="LC_error">'.  
                       &mt('You do not have privileges to assign co-author roles.').  
                       '</span>');  
         } elsif (($env{'user.name'} eq $ccuname) &&   
              ($env{'user.domain'} eq $ccdomain)) {  
            $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Construction Space is not permitted'));  
         }  
     }  
 #  
 # Domain level  
 #  
     my $num_domain_level = 0;  
     my $domaintext =   
     '<h4>'.&mt('Domain Level').'</h4>'.  
     &Apache::loncommon::start_data_table().  
     &Apache::loncommon::start_data_table_header_row().  
     '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.  
     &mt('Extent').'</th>'.  
     '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.  
     &Apache::loncommon::end_data_table_header_row();  
     foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {  
         foreach my $role ('dc','li','dg','au','sc') {  
             if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {  
                my $plrole=&Apache::lonnet::plaintext($role);  
        my %lt=&Apache::lonlocal::texthash(  
                     'ssd'  => "Set Start Date",  
                     'sed'  => "Set End Date"  
        );  
                $num_domain_level ++;  
                $domaintext .=   
 &Apache::loncommon::start_data_table_row().  
 '<td><input type=checkbox name="act_'.$thisdomain.'_'.$role.'" /></td>  
 <td>'.$plrole.'</td>  
 <td>'.$thisdomain.'</td>  
 <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />  
 <a href=  
 "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>  
 <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />  
 <a href=  
 "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.  
 &Apache::loncommon::end_data_table_row();  
             }              }
         }               $r->print(&course_level_dc($env{'request.role.domain'},'Course'));
     }              $r->print('<br /><input type="button" value="'.&mt('Modify User').'" onClick="setCourse()" />'."\n");
     $domaintext.= &Apache::loncommon::end_data_table();          } elsif ($context eq 'author') {
     if ($num_domain_level > 0) {              if ($addrolesdisplay) {
         $r->print($domaintext);                  $r->print('<br /><input type="button" value="'.&mt('Modify User').'"');
         $addrolesdisplay = 1;                  if ($newuser) {
     }                      $r->print(' onClick="verify_message(this.form)" \>'."\n");
 #                  } else {
 # Course level                      $r->print('onClick="this.form.submit()" \>'."\n");
 #                  }
   
     if ($env{'request.role'} =~ m{^dc\./($match_domain)/$}) {  
         $r->print(&course_level_dc($1,'Course'));  
         $r->print('<br /><input type="button" value="'.&mt('Modify User').'" onClick="setCourse()" />'."\n");  
     } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/$}) {  
         if ($addrolesdisplay) {  
             $r->print('<br /><input type="button" value="'.&mt('Modify User').'"');  
             if ($newuser) {  
                 $r->print(' onClick="verify_message(this.form)" \>'."\n");  
             } else {              } else {
                 $r->print('onClick="this.form.submit()" \>'."\n");                   $r->print('<br /><a href="javascript:backPage(document.cu)">'.
                             &mt('Back to previous page').'</a>');
             }              }
         } else {          } else {
             $r->print('<br /><a href="javascript:backPage(document.cu)">'.              $r->print(&course_level_table(%inccourses));
                       &mt('Back to previous page').'</a>');              $r->print('<br /><input type="button" value="'.&mt('Modify User').'" onClick="setSections(this.form)" />'."\n");
         }          }
     } else {  
         $r->print(&course_level_table(%inccourses));  
         $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="" />');
     $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" />');      $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" />');
     $r->print("</form>".&Apache::loncommon::end_page());      $r->print("</form>".&Apache::loncommon::end_page());
       return;
 }  }
   
 sub singleuser_breadcrumb {  sub singleuser_breadcrumb {
Line 1208  sub display_existing_roles { Line 1111  sub display_existing_roles {
     return;      return;
 }  }
   
   sub new_coauthor_roles {
       my ($r,$ccuname,$ccdomain) = @_;
       my $addrolesdisplay = 0;
       #
       # Co-Author
       #
       if (&Apache::lonuserutils::authorpriv($env{'user.name'},
                                             $env{'request.role.domain'}) &&
           ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
           # No sense in assigning co-author role to yourself
           $addrolesdisplay = 1;
           my $cuname=$env{'user.name'};
           my $cudom=$env{'request.role.domain'};
           my %lt=&Apache::lonlocal::texthash(
                       'cs'   => "Construction Space",
                       'act'  => "Activate",
                       'rol'  => "Role",
                       'ext'  => "Extent",
                       'sta'  => "Start",
                       'end'  => "End",
                       'cau'  => "Co-Author",
                       'caa'  => "Assistant Co-Author",
                       'ssd'  => "Set Start Date",
                       'sed'  => "Set End Date"
                                          );
           $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
                     &Apache::loncommon::start_data_table()."\n".
                     &Apache::loncommon::start_data_table_header_row()."\n".
                     '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
                     '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
                     '<th>'.$lt{'end'}.'</th>'."\n".
                     &Apache::loncommon::end_data_table_header_row()."\n".
                     &Apache::loncommon::start_data_table_row().'
              <td>
               <input type=checkbox name="act_'.$cudom.'_'.$cuname.'_ca" />
              </td>
              <td>'.$lt{'cau'}.'</td>
              <td>'.$cudom.'_'.$cuname.'</td>
              <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
                <a href=
   "javascript:pjump('."'date_start','Start Date Co-Author',document.cu.start_$cudom\_$cuname\_ca.value,'start_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
   <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
   <a href=
   "javascript:pjump('."'date_end','End Date Co-Author',document.cu.end_$cudom\_$cuname\_ca.value,'end_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".
                 &Apache::loncommon::end_data_table_row()."\n".
                 &Apache::loncommon::start_data_table_row()."\n".
   '<td><input type=checkbox name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
   <td>'.$lt{'caa'}.'</td>
   <td>'.$cudom.'_'.$cuname.'</td>
   <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
   <a href=
   "javascript:pjump('."'date_start','Start Date Assistant Co-Author',document.cu.start_$cudom\_$cuname\_aa.value,'start_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
   <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
   <a href=
   "javascript:pjump('."'date_end','End Date Assistant Co-Author',document.cu.end_$cudom\_$cuname\_aa.value,'end_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".
                &Apache::loncommon::end_data_table_row()."\n".
                &Apache::loncommon::end_data_table());
       } elsif ($env{'request.role'} =~ /^au\./) {
           if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
                                                   $env{'request.role.domain'}))) {
               $r->print('<span class="LC_error">'.
                         &mt('You do not have privileges to assign co-author roles.').
                         '</span>');
           } elsif (($env{'user.name'} eq $ccuname) &&
                ($env{'user.domain'} eq $ccdomain)) {
               $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Construction Space is not permitted'));
           }
       }
       return $addrolesdisplay;;
   }
   
   sub new_domain_roles {
       my ($r) = @_;
       my $addrolesdisplay = 0;
       #
       # Domain level
       #
       my $num_domain_level = 0;
       my $domaintext =
       '<h4>'.&mt('Domain Level').'</h4>'.
       &Apache::loncommon::start_data_table().
       &Apache::loncommon::start_data_table_header_row().
       '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
       &mt('Extent').'</th>'.
       '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
       &Apache::loncommon::end_data_table_header_row();
       foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
           foreach my $role ('dc','li','dg','au','sc') {
               if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
                  my $plrole=&Apache::lonnet::plaintext($role);
                  my %lt=&Apache::lonlocal::texthash(
                       'ssd'  => "Set Start Date",
                       'sed'  => "Set End Date"
                                          );
                  $num_domain_level ++;
                  $domaintext .=
   &Apache::loncommon::start_data_table_row().
   '<td><input type=checkbox name="act_'.$thisdomain.'_'.$role.'" /></td>
   <td>'.$plrole.'</td>
   <td>'.$thisdomain.'</td>
   <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
   <a href=
   "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
   <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
   <a href=
   "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
   &Apache::loncommon::end_data_table_row();
               }
           }
       }
       $domaintext.= &Apache::loncommon::end_data_table();
       if ($num_domain_level > 0) {
           $r->print($domaintext);
           $addrolesdisplay = 1;
       }
       return $addrolesdisplay;
   }
   
 sub user_authentication {  sub user_authentication {
     my ($ccuname,$ccdomain,$krbdefdom,$abv_auth) = @_;      my ($ccuname,$ccdomain,$krbdefdom,$abv_auth) = @_;
     my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);      my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
Line 1376  sub modify_login_block { Line 1397  sub modify_login_block {
   
 sub personal_data_display {  sub personal_data_display {
     my ($ccuname,$ccdomain,$newuser,$context,$inst_results) = @_;      my ($ccuname,$ccdomain,$newuser,$context,$inst_results) = @_;
     my ($output,$showforceid,%userenv,%domconfig);      my ($output,$showforceid,%userenv,%canmodify);
       my @userinfo = ('firstname','middlename','lastname','generation',
                       'permanentemail','id');
     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 =          %canmodify =
             &Apache::lonnet::get_dom('configuration',['usermodification'],              &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
                                      $ccdomain);                                                         \@userinfo);
     }      }
     my %lt=&Apache::lonlocal::texthash(      my %lt=&Apache::lonlocal::texthash(
                 'pd'             => "Personal Data",                  'pd'             => "Personal Data",
Line 1396  sub personal_data_display { Line 1419  sub personal_data_display {
                 'id'             => "ID/Student Number",                  'id'             => "ID/Student Number",
                 'lg'             => "Login Data"                  'lg'             => "Login Data"
     );      );
     my @userinfo = ('firstname','middlename','lastname','generation',  
                     'permanentemail','id');  
     my %textboxsize = (      my %textboxsize = (
                        firstname      => '15',                         firstname      => '15',
                        middlename     => '15',                         middlename     => '15',
Line 1426  sub personal_data_display { Line 1447  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 ($canmodify{$item}) {
             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') {              if ($item eq 'id') {
                 $showforceid = $canmodify;                   $showforceid = $canmodify{$item};
             }               }
         }          }
         $output .= &Apache::lonhtmlcommon::row_closure(1);          $output .= &Apache::lonhtmlcommon::row_closure(1);
     }      }
Line 1474  sub update_user_data { Line 1476  sub update_user_data {
     my $end       = '</span><br /><br />';      my $end       = '</span><br /><br />';
     my $rtnlink   = '<a href="javascript:backPage(document.userupdate,'.      my $rtnlink   = '<a href="javascript:backPage(document.userupdate,'.
                     "'$env{'form.prevphase'}','modify')".'" />'.                      "'$env{'form.prevphase'}','modify')".'" />'.
                     &mt('Return to previous page').'</a>'.&Apache::loncommon::end_page();                      &mt('Return to previous page').'</a>'.
                       &Apache::loncommon::end_page();
       my $now = time;
     my $title;      my $title;
     if (exists($env{'form.makeuser'})) {      if (exists($env{'form.makeuser'})) {
  $title='Set Privileges for New User';   $title='Set Privileges for New User';
Line 1499  sub update_user_data { Line 1503  sub update_user_data {
     }      }
     &Apache::lonhtmlcommon::add_breadcrumb      &Apache::lonhtmlcommon::add_breadcrumb
        ({href=>"javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",         ({href=>"javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
          text=>"Set user role",           text=>$breadcrumb_text{'modify'},
          faq=>282,bug=>'Instructor Interface',},           faq=>282,bug=>'Instructor Interface',},
         {href=>"/adm/createuser",          {href=>"/adm/createuser",
          text=>"Result",           text=>"Result",
          faq=>282,bug=>'Instructor Interface',});           faq=>282,bug=>'Instructor Interface',});
     $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));      $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
   
     my %disallowed;  
     $r->print(&update_result_form($uhome));      $r->print(&update_result_form($uhome));
     # Check Inputs      # Check Inputs
     if (! $env{'form.ccuname'} ) {      if (! $env{'form.ccuname'} ) {
Line 1531  sub update_user_data { Line 1533  sub update_user_data {
   $end.$rtnlink);    $end.$rtnlink);
  return;   return;
     }      }
       if ($uhome eq 'no_host') {
           $newuser = 1;
       }
     if (! exists($env{'form.makeuser'})) {      if (! exists($env{'form.makeuser'})) {
         # Modifying an existing user, so check the validity of the name          # Modifying an existing user, so check the validity of the name
         if ($uhome eq 'no_host') {          if ($uhome eq 'no_host') {
Line 1568  sub update_user_data { Line 1573  sub update_user_data {
     return;      return;
     }      }
   
   
     $r->print('<h3>'.&mt('User [_1] in domain [_2]',      $r->print('<h3>'.&mt('User [_1] in domain [_2]',
  $env{'form.ccuname'}, $env{'form.ccdomain'}).'</h3>');   $env{'form.ccuname'}, $env{'form.ccdomain'}).'</h3>');
     my (%alerts,%rulematch,%inst_results,%curr_rules);      my (%alerts,%rulematch,%inst_results,%curr_rules);
Line 1595  sub update_user_data { Line 1599  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'}}} = (
             'newuser' => 1,               'newuser' => $newuser, 
             'id' => $env{'form.cid'},              'id' => $env{'form.cid'},
         );          );
         if ($env{'form.cid'} ne '') {          if ($env{'form.cid'} ne '') {
Line 1629  sub update_user_data { Line 1633  sub update_user_data {
              $env{'form.cgeneration'},undef,$desiredhost,               $env{'form.cgeneration'},undef,$desiredhost,
              $env{'form.cpermanentemail'});               $env{'form.cpermanentemail'});
  $r->print(&mt('Generating user').': '.$result);   $r->print(&mt('Generating user').': '.$result);
         my $home = &Apache::lonnet::homeserver($env{'form.ccuname'},          $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
                                                $env{'form.ccdomain'});                                                 $env{'form.ccdomain'});
         $r->print('<br />'.&mt('Home server').': '.$home.' '.          $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
                   &Apache::lonnet::hostname($home));                    &Apache::lonnet::hostname($uhome));
     } elsif (($env{'form.login'} ne 'nochange') &&      } elsif (($env{'form.login'} ne 'nochange') &&
              ($env{'form.login'} ne ''        )) {               ($env{'form.login'} ne ''        )) {
  # Modify user privileges   # Modify user privileges
Line 1676  sub update_user_data { Line 1680  sub update_user_data {
         my @statuses = ('active','future');          my @statuses = ('active','future');
         my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});          my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
         my ($auname,$audom);          my ($auname,$audom);
         if ($context eq 'course') {          if ($context eq 'author') {
             $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'};              $auname = $env{'user.name'};
             $audom = $env{'user.domain'};                   $audom = $env{'user.domain'};     
         }          }
         foreach my $item (keys(%roles)) {          foreach my $item (keys(%roles)) {
             my ($rolenum,$roledom,$role) = split(/:/,$item);              my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
             if ($context eq 'course') {              if ($context eq 'course') {
                 if ($cnum ne '' && $cdom ne '') {                  if ($cnum ne '' && $cdom ne '') {
                     if ($rolenum eq $cnum && $roledom eq $cdom) {                      if ($rolenum eq $cnum && $roledom eq $cdom) {
Line 1708  sub update_user_data { Line 1702  sub update_user_data {
                 }                  }
             }              }
         }          }
         # Check for course or co-author roles being activated or re-enabled          if ($env{'form.action'} eq 'singlestudent') {
         if ($context eq 'author' || $context eq 'course') {              if (!grep(/^st$/,@userroles)) {
             foreach my $key (keys(%env)) {                  push(@userroles,'st');
                 if ($context eq 'author') {              }
                     if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {          } else {
                         if (!grep(/^\Q$1\E$/,@userroles)) {              # Check for course or co-author roles being activated or re-enabled
                             push(@userroles,$1);              if ($context eq 'author' || $context eq 'course') {
                         }                  foreach my $key (keys(%env)) {
                     } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {                      if ($context eq 'author') {
                         if (!grep(/^\Q$1\E$/,@userroles)) {                          if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
                             push(@userroles,$1);                              if (!grep(/^\Q$1\E$/,@userroles)) {
                         }                                  push(@userroles,$1);
                     }                              }
                 } elsif ($context eq 'course') {                          } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
                     if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {                              if (!grep(/^\Q$1\E$/,@userroles)) {
                         if (!grep(/^\Q$1\E$/,@userroles)) {                                  push(@userroles,$1);
                             push(@userroles,$1);                              }
                         }                          }
                     } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {                      } elsif ($context eq 'course') {
                         if (!grep(/^\Q$1\E$/,@userroles)) {                          if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
                             push(@userroles,$1);                              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);
                               }
                         }                          }
                     }                      }
                 }                  }
Line 1743  sub update_user_data { Line 1743  sub update_user_data {
                 push(@longroles,&Apache::lonnet::plaintext($role));                   push(@longroles,&Apache::lonnet::plaintext($role)); 
             }              }
         }          }
         foreach my $item ('firstname','middlename','lastname','generation','permanentemail','id') {          my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
             my $canmodify = 0;          my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
             if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {          foreach my $item (@userinfo) {
                 $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 (!$canmodify{$item}) {
                 if (defined($env{'form.c'.$item})) {                  if (defined($env{'form.c'.$item})) {
                     if ($env{'form.c'.$item} ne $userenv{$item}) {                      if ($env{'form.c'.$item} ne $userenv{$item}) {
                         push(@mod_disallowed,$item);                          push(@mod_disallowed,$item);
Line 1781  sub update_user_data { Line 1760  sub update_user_data {
         # 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'};
         my $recurseid = $env{'form.recurseid'};          my $recurseid = $env{'form.recurseid'};
         my $newuser = 0;  
         my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);          my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
         my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},          my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
                                             $env{'form.ccuname'});                                              $env{'form.ccuname'});
Line 1813  sub update_user_data { Line 1791  sub update_user_data {
             $newdefquotatext);              $newdefquotatext);
         my ($defquota,$settingstatus) =           my ($defquota,$settingstatus) = 
             &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);              &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
           my $showquota;
           if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
               $showquota = 1;
           }
         my %changeHash;          my %changeHash;
         $changeHash{'portfolioquota'} = $userenv{'portfolioquota'};          $changeHash{'portfolioquota'} = $userenv{'portfolioquota'};
         if ($userenv{'portfolioquota'} ne '') {          if ($userenv{'portfolioquota'} ne '') {
Line 1883  sub update_user_data { Line 1865  sub update_user_data {
                         $changeHash{'firstname'},$changeHash{'middlename'},                          $changeHash{'firstname'},$changeHash{'middlename'},
                         $changeHash{'lastname'},$changeHash{'generation'},                          $changeHash{'lastname'},$changeHash{'generation'},
                         $changeHash{'id'},undef,$changeHash{'permanentemail'});                          $changeHash{'id'},undef,$changeHash{'permanentemail'});
                   %userupdate = (
                                  lastname   => $env{'form.clastname'},
                                  middlename => $env{'form.cmiddlename'},
                                  firstname  => $env{'form.cfirstname'},
                                  generation => $env{'form.cgeneration'},
                                  id         => $env{'form.cid'},
                                );
             }              }
             if (($namechanged && $namechgresult eq 'ok') ||               if (($namechanged && $namechgresult eq 'ok') || 
                 ($quotachanged && $quotachgresult eq 'ok')) {                  ($quotachanged && $quotachgresult eq 'ok')) {
Line 1910  sub update_user_data { Line 1899  sub update_user_data {
     <th>$lt{'gen'}</th>      <th>$lt{'gen'}</th>
     <th>$lt{'id'}</th>      <th>$lt{'id'}</th>
     <th>$lt{'mail'}</th>      <th>$lt{'mail'}</th>
     <th>$lt{'disk'}</th>  
 END  END
                   if ($showquota) {
                       $r->print("
       <th>$lt{'disk'}</th>\n");
                   }
                 $r->print(&Apache::loncommon::end_data_table_header_row().                  $r->print(&Apache::loncommon::end_data_table_header_row().
                           &Apache::loncommon::start_data_table_row());                            &Apache::loncommon::start_data_table_row());
                 $r->print(<<"END");                  $r->print(<<"END");
Line 1922  END Line 1914  END
     <td>$userenv{'generation'} </td>      <td>$userenv{'generation'} </td>
     <td>$userenv{'id'}</td>      <td>$userenv{'id'}</td>
     <td>$userenv{'permanentemail'} </td>      <td>$userenv{'permanentemail'} </td>
     <td>$oldportfolioquota Mb $olddefquotatext </td>  
 END  END
                   if ($showquota) {
                       $r->print("
       <td>$oldportfolioquota Mb $olddefquotatext </td>\n");
                   }
                 $r->print(&Apache::loncommon::end_data_table_row().                  $r->print(&Apache::loncommon::end_data_table_row().
                           &Apache::loncommon::start_data_table_row());                            &Apache::loncommon::start_data_table_row());
                 $r->print(<<"END");                  $r->print(<<"END");
Line 1934  END Line 1929  END
     <td>$env{'form.cgeneration'} </td>      <td>$env{'form.cgeneration'} </td>
     <td>$env{'form.cid'} </td>      <td>$env{'form.cid'} </td>
     <td>$env{'form.cpermanentemail'} </td>      <td>$env{'form.cpermanentemail'} </td>
     <td>$newportfolioquota Mb $newdefquotatext </td>  
 END  END
                   if ($showquota) {
                       $r->print("
       <td>$newportfolioquota Mb $newdefquotatext </td>\n");
                   }
                 $r->print(&Apache::loncommon::end_data_table_row().                  $r->print(&Apache::loncommon::end_data_table_row().
                           &Apache::loncommon::end_data_table().'<br />');                            &Apache::loncommon::end_data_table().'<br />');
                 if ($env{'form.cid'} ne $userenv{'id'}) {                  if ($env{'form.cid'} ne $userenv{'id'}) {
Line 1943  END Line 1941  END
                          ($env{'form.ccuname'} => $env{'form.cid'}));                           ($env{'form.ccuname'} => $env{'form.cid'}));
                     if (($recurseid) &&                      if (($recurseid) &&
                         (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {                          (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
                         %userupdate = (  
                                   lastname   => $env{'form.clasaname'},  
                                   middlename => $env{'form.cmiddlename'},  
                                   firstname  => $env{'form.cfirstname'},  
                                   generation => $env{'fora.cgeneration'},  
                                   id         => $env{'form.cid'},  
                              );  
                         my $idresult =                           my $idresult = 
                             &Apache::lonuserutils::propagate_id_change(                              &Apache::lonuserutils::propagate_id_change(
                                 $env{'form.ccuname'},$env{'form.ccdomain'},                                  $env{'form.ccuname'},$env{'form.ccdomain'},
Line 1985  END Line 1976  END
                 $r->print('<br />['.$lt{'mail'}.': '.                  $r->print('<br />['.$lt{'mail'}.': '.
                           $userenv{'permanentemail'}.']');                            $userenv{'permanentemail'}.']');
             }              }
             $r->print('<br />['.$lt{'disk'}.': '.$oldportfolioquota.' Mb '.               if ($showquota) {
                  $olddefquotatext.']</h4>');                  $r->print('<br />['.$lt{'disk'}.': '.$oldportfolioquota.' Mb '. 
                             $olddefquotatext.']');
               }
               $r->print('</h4>');
         }          }
         if (@mod_disallowed) {          if (@mod_disallowed) {
             my ($rolestr,$contextname);              my ($rolestr,$contextname);
Line 2017  END Line 2011  END
         $r->print($no_forceid_alert.          $r->print($no_forceid_alert.
                   &Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts, \%curr_rules));                    &Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts, \%curr_rules));
     }      }
     ##      if ($env{'form.action'} eq 'singlestudent') {
           &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser);
       } else {
           my $rolechanges = &update_roles($r);
           if (!$rolechanges && $namechanged) {
               if ($context eq 'course') {
                   if (@userroles > 0) {
                       if (grep(/^st$/,@userroles)) {
                           my $classlistupdated =
                               &Apache::lonuserutils::update_classlist($cdom,
                                                 $cnum,$env{'form.ccdomain'},
                                          $env{'form.ccuname'},\%userupdate);
                       }
                   }
               }
           }
       }
       $r->print(&Apache::loncommon::end_page());
   }
   
   sub update_roles {
       my ($r) = @_;
     my $now=time;      my $now=time;
     my $rolechanges = 0;      my $rolechanges = 0;
       my %disallowed;
     $r->print('<h3>'.&mt('Modifying Roles').'</h3>');      $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
     foreach my $key (keys (%env)) {      foreach my $key (keys (%env)) {
  next if (! $env{$key});   next if (! $env{$key});
Line 2092  END Line 2108  END
                 if ($role eq 'st') {                  if ($role eq 'st') {
                     if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {                      if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
                         my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);                          my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
                         if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {                          if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
                             $output = "Error: $result\n";                              $output = "Error: $result\n";
                         } else {                          } else {
                             $output = &mt('Assigning').' '.$role.' in '.$url.                              $output = &mt('Assigning').' '.$role.' in '.$url.
Line 2240  END Line 2256  END
     if (!$rolechanges) {      if (!$rolechanges) {
         $r->print(&mt('No roles to modify'));          $r->print(&mt('No roles to modify'));
     }      }
     $r->print(&Apache::loncommon::end_page());      return $rolechanges;
   }
   
   sub enroll_single_student {
       my ($r,$uhome,$amode,$genpwd,$now,$newuser) = @_;
       $r->print('<h3>'.&mt('Enrolling Student').'</h3>');
   
       # Remove non alphanumeric values from section
       $env{'form.sections'}=~s/\W//g;
   
       # Clean out any old student roles the user has in this class.
       &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
            $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
       my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
       my $enroll_result =
           &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
               $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
               $env{'form.cmiddlename'},$env{'form.clastname'},
               $env{'form.generation'},$env{'form.sections'},$enddate,
               $startdate,'manual',undef,$env{'request.course.id'});
       if ($enroll_result =~ /^ok/) {
           $r->print(&mt('<b>[_1]</b> enrolled',$env{'form.ccuname'}.':'.$env{'form.ccdomain'}));
           if ($env{'form.sections'} ne '') {
               $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
           }
           my ($showstart,$showend);
           if ($startdate <= $now) {
               $showstart = &mt('Access starts immediately');
           } else {
               $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
           }
           if ($enddate == 0) {
               $showend = &mt('ends: no ending date');
           } else {
               $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
           }
           $r->print('.<br />'.$showstart.'; '.$showend);
           if ($startdate <= $now && !$newuser) {
               $r->print("<p> ".&mt('If the student is currently logged-in to LON-CAPA, the new role will be available when the student next logs in.')."</p>");
           }
       } else {
           $r->print(&mt('unable to enroll').": ".$enroll_result);
       }
       return;
 }  }
   
 sub get_defaultquota_text {  sub get_defaultquota_text {
Line 2280  sub update_result_form { Line 2339  sub update_result_form {
     }      }
     $outcome .= '<input type="hidden" name="phase" value="" />'."\n".      $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
                 '<input type ="hidden" name="currstate" value="" />'."\n".                  '<input type ="hidden" name="currstate" value="" />'."\n".
                 '<input type ="hidden" name="action" value="singleuser" />'."\n".                  '<input type ="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
                 '</form>';                  '</form>';
     return $outcome;      return $outcome;
 }  }
Line 2671  sub handler { Line 2730  sub handler {
         if (! exists($env{'form.state'})) {          if (! exists($env{'form.state'})) {
             &Apache::lonuserutils::print_first_users_upload_form($r,$context);              &Apache::lonuserutils::print_first_users_upload_form($r,$context);
         } elsif ($env{'form.state'} eq 'got_file') {          } elsif ($env{'form.state'} eq 'got_file') {
             &Apache::lonuserutils::print_upload_manager_form($r,$context);              &Apache::lonuserutils::print_upload_manager_form($r,$context,
                                                                $permission);
         } elsif ($env{'form.state'} eq 'enrolling') {          } elsif ($env{'form.state'} eq 'enrolling') {
             if ($env{'form.datatoken'}) {              if ($env{'form.datatoken'}) {
                 &Apache::lonuserutils::upfile_drop_add($r,$context);                  &Apache::lonuserutils::upfile_drop_add($r,$context,$permission);
             }              }
         } else {          } else {
             &Apache::lonuserutils::print_first_users_upload_form($r,$context);              &Apache::lonuserutils::print_first_users_upload_form($r,$context);
Line 2696  sub handler { Line 2756  sub handler {
                 my $response;                  my $response;
                 if ($env{'form.srchterm'} !~ /^$match_username$/) {                  if ($env{'form.srchterm'} !~ /^$match_username$/) {
                     my $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');                      my $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
                       $env{'form.phase'} = '';
                     &print_username_entry_form($r,$context,$response,$srch);                      &print_username_entry_form($r,$context,$response,$srch);
                 } else {                  } else {
                     my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});                      my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
                     my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});                      my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
                     &print_user_modification_page($r,$ccuname,$ccdomain,                      &print_user_modification_page($r,$ccuname,$ccdomain,
                                                   $srch,$response,$context);                                                    $srch,$response,$context,
                                                     $permission);
                 }                  }
             } elsif ($env{'form.phase'} eq 'get_user_info') {              } elsif ($env{'form.phase'} eq 'get_user_info') {
                 my ($currstate,$response,$forcenewuser,$results) =                   my ($currstate,$response,$forcenewuser,$results) = 
                     &user_search_result($srch);                      &user_search_result($context,$srch);
                 if ($env{'form.currstate'} eq 'modify') {                  if ($env{'form.currstate'} eq 'modify') {
                     $currstate = $env{'form.currstate'};                      $currstate = $env{'form.currstate'};
                 }                  }
Line 2734  sub handler { Line 2796  sub handler {
                         $response = '';                          $response = '';
                     }                      }
                     &print_user_modification_page($r,$ccuname,$ccdomain,                      &print_user_modification_page($r,$ccuname,$ccdomain,
                                                   $srch,$response,$context);                                                    $srch,$response,$context,
                                                     $permission);
                 } elsif ($currstate eq 'query') {                  } elsif ($currstate eq 'query') {
                     &print_user_query_page($r,'createuser');                      &print_user_query_page($r,'createuser');
                 } else {                  } else {
Line 2745  sub handler { Line 2808  sub handler {
                 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);                                                $context,$permission);
             }              }
         } elsif ($env{'form.phase'} eq 'update_user_data') {          } elsif ($env{'form.phase'} eq 'update_user_data') {
             &update_user_data($r,$context);              &update_user_data($r,$context);
Line 2762  sub handler { Line 2825  sub handler {
              ($permission->{'view'} || $permission->{'cusr'})) {               ($permission->{'view'} || $permission->{'cusr'})) {
         if ($env{'form.phase'} eq 'bulkchange') {          if ($env{'form.phase'} eq 'bulkchange') {
             &Apache::lonhtmlcommon::add_breadcrumb              &Apache::lonhtmlcommon::add_breadcrumb
                 ({href=>'backPage(document.studentform)',                  ({href=>'/adm/createuser?action=listusers',
                   text=>"List Users"});                    text=>"List Users"},
                   {href=>"/adm/createuser",
                     text=>"Result"});
             my $setting = $env{'form.roletype'};              my $setting = $env{'form.roletype'};
             my $choice = $env{'form.bulkaction'};              my $choice = $env{'form.bulkaction'};
             $r->print(&header());              $r->print(&header());
             $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",              $r->print(&Apache::lonhtmlcommon::breadcrumbs("Update Users",
                                                           'User_Management_List'));                                                            'User_Management_List'));
             if ($permission->{'cusr'}) {              if ($permission->{'cusr'}) {
                 &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice);                  &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice);
                   $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
                   $r->print(&Apache::loncommon::end_page());
               } else {
                   $r->print(&mt('You are not authorized to make bulk changes to user roles'));
                   $r->print(&Apache::loncommon::end_page());
             }              }
         } else {          } else {
             &Apache::lonhtmlcommon::add_breadcrumb              &Apache::lonhtmlcommon::add_breadcrumb
Line 2823  sub handler { Line 2893  sub handler {
     } elsif ($env{'form.action'} eq 'dateselect') {      } elsif ($env{'form.action'} eq 'dateselect') {
         if ($permission->{'cusr'}) {          if ($permission->{'cusr'}) {
             $r->print(&header(undef,undef,{'no_nav_bar' => 1}).              $r->print(&header(undef,undef,{'no_nav_bar' => 1}).
                       &Apache::lonuserutils::date_section_selector($context).                        &Apache::lonuserutils::date_section_selector($context,
                                                                      $permission).
                       &Apache::loncommon::end_page());                        &Apache::loncommon::end_page());
         } else {          } else {
             $r->print(&header().              $r->print(&header().
Line 2877  sub print_main_menu { Line 2948  sub print_main_menu {
     my %links = (      my %links = (
                        domain => {                         domain => {
                                    upload => 'Upload a File of Users',                                     upload => 'Upload a File of Users',
                                    singleuser => 'Add/Manage a Single User',                                     singleuser => 'Add/Modify a Single User',
                                    listusers => 'Manage Multiple Users',                                     listusers => 'Manage Multiple Users',
                                  },                                   },
                        author => {                         author => {
                                    upload => 'Upload a File of Co-authors',                                     upload => 'Upload a File of Co-authors',
                                    singleuser => 'Add/Manage a Single Co-author',                                     singleuser => 'Add/Modify a Single Co-author',
                                    listusers => 'Display Co-authors and Manage Multiple Users',                                     listusers => 'Display Co-authors and Manage Multiple Users',
                                  },                                   },
                        course => {                         course => {
                                    upload => 'Upload a File of Course Users',                                     upload => 'Upload a File of Course Users',
                                    singleuser => 'Add/Manage a Single Course User',                                     singleuser => 'Add/Modify a Single Course User',
                                    listusers => 'Display Class Lists and Manage Multiple Users',                                     listusers => 'Display Class Lists and Manage Multiple Users',
                                  },                                   },
                      );                       );
Line 2981  sub restore_prev_selections { Line 3052  sub restore_prev_selections {
   
 #-------------------------------------------------- functions for &phase_two  #-------------------------------------------------- functions for &phase_two
 sub user_search_result {  sub user_search_result {
     my ($srch) = @_;      my ($context,$srch) = @_;
     my %allhomes;      my %allhomes;
     my %inst_matches;      my %inst_matches;
     my %srch_results;      my %srch_results;
Line 3050  sub user_search_result { Line 3121  sub user_search_result {
                         my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});                          my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
                         if ($uhome eq 'no_host') {                          if ($uhome eq 'no_host') {
                             ($currstate,$response,$forcenewuser) =                              ($currstate,$response,$forcenewuser) =
                                 &build_search_response($srch,%srch_results);                                  &build_search_response($context,$srch,%srch_results);
                         } else {                          } else {
                             $currstate = 'modify';                              $currstate = 'modify';
                         }                          }
                     } else {                      } else {
                         %srch_results = &Apache::lonnet::usersearch($srch);                          %srch_results = &Apache::lonnet::usersearch($srch);
                         ($currstate,$response,$forcenewuser) =                          ($currstate,$response,$forcenewuser) =
                             &build_search_response($srch,%srch_results);                              &build_search_response($context,$srch,%srch_results);
                     }                      }
                 } else {                  } else {
                     my $courseusers = &get_courseusers();                      my $courseusers = &get_courseusers();
Line 3066  sub user_search_result { Line 3137  sub user_search_result {
                             $currstate = 'modify';                              $currstate = 'modify';
                         } else {                          } else {
                             ($currstate,$response,$forcenewuser) =                              ($currstate,$response,$forcenewuser) =
                                 &build_search_response($srch,%srch_results);                                  &build_search_response($context,$srch,%srch_results);
                         }                          }
                     } else {                      } else {
                         foreach my $user (keys(%$courseusers)) {                          foreach my $user (keys(%$courseusers)) {
Line 3093  sub user_search_result { Line 3164  sub user_search_result {
                             }                              }
                         }                          }
                         ($currstate,$response,$forcenewuser) =                          ($currstate,$response,$forcenewuser) =
                             &build_search_response($srch,%srch_results);                              &build_search_response($context,$srch,%srch_results);
                     }                      }
                 }                  }
             }              }
Line 3103  sub user_search_result { Line 3174  sub user_search_result {
             ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);              ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
             if ($dirsrchres eq 'ok') {              if ($dirsrchres eq 'ok') {
                 ($currstate,$response,$forcenewuser) =                   ($currstate,$response,$forcenewuser) = 
                     &build_search_response($srch,%srch_results);                      &build_search_response($context,$srch,%srch_results);
             } else {              } else {
                 my $showdom = &display_domain_info($srch->{'srchdomain'});                  my $showdom = &display_domain_info($srch->{'srchdomain'});
                 $response = '<span class="LC_warning">'.                  $response = '<span class="LC_warning">'.
Line 3117  sub user_search_result { Line 3188  sub user_search_result {
         if ($srch->{'srchin'} eq 'dom') {          if ($srch->{'srchin'} eq 'dom') {
             %srch_results = &Apache::lonnet::usersearch($srch);              %srch_results = &Apache::lonnet::usersearch($srch);
             ($currstate,$response,$forcenewuser) =               ($currstate,$response,$forcenewuser) = 
                 &build_search_response($srch,%srch_results);                   &build_search_response($context,$srch,%srch_results); 
         } elsif ($srch->{'srchin'} eq 'crs') {          } elsif ($srch->{'srchin'} eq 'crs') {
             my $courseusers = &get_courseusers();               my $courseusers = &get_courseusers(); 
             foreach my $user (keys(%$courseusers)) {              foreach my $user (keys(%$courseusers)) {
Line 3169  sub user_search_result { Line 3240  sub user_search_result {
                 }                  }
             }              }
             ($currstate,$response,$forcenewuser) =               ($currstate,$response,$forcenewuser) = 
                 &build_search_response($srch,%srch_results);                   &build_search_response($context,$srch,%srch_results); 
         } elsif ($srch->{'srchin'} eq 'alc') {          } elsif ($srch->{'srchin'} eq 'alc') {
             $currstate = 'query';              $currstate = 'query';
         } elsif ($srch->{'srchin'} eq 'instd') {          } elsif ($srch->{'srchin'} eq 'instd') {
             ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);               ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch); 
             if ($dirsrchres eq 'ok') {              if ($dirsrchres eq 'ok') {
                 ($currstate,$response,$forcenewuser) =                   ($currstate,$response,$forcenewuser) = 
                     &build_search_response($srch,%srch_results);                      &build_search_response($context,$srch,%srch_results);
             } else {              } else {
                 my $showdom = &display_domain_info($srch->{'srchdomain'});                $response = '<span class="LC_warning">'.                  my $showdom = &display_domain_info($srch->{'srchdomain'});                $response = '<span class="LC_warning">'.
                     &mt('Institutional directory search is not available in domain: [_1]',$showdom).                      &mt('Institutional directory search is not available in domain: [_1]',$showdom).
Line 3282  sub get_courseusers { Line 3353  sub get_courseusers {
 }  }
   
 sub build_search_response {  sub build_search_response {
     my ($srch,%srch_results) = @_;      my ($context,$srch,%srch_results) = @_;
     my ($currstate,$response,$forcenewuser);      my ($currstate,$response,$forcenewuser);
     my %names = (      my %names = (
           'uname' => 'username',            'uname' => 'username',
Line 3341  sub build_search_response { Line 3412  sub build_search_response {
                 }                  }
             }              }
             if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $env{'request.role.domain'})) {              if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $env{'request.role.domain'})) {
                 my $showdom = &display_domain_info($env{'request.role.domain'});                   my $cancreate =
                       &Apache::lonuserutils::can_create_user($env{'request.role.domain'},$context);
                   if ($cancreate) {
                       my $showdom = &display_domain_info($env{'request.role.domain'}); 
                 $response .= '<br /><br />'.&mt("<b>To add a new user</b> (you can only create new users in your current role's domain - <span class=\"LC_cusr_emph\">[_1]</span>):",$env{'request.role.domain'}).'<ul><li>'.&mt("Set 'Domain/institution to search' to: <span class=\"LC_cusr_emph\">[_1]</span>",$showdom).'<li>'.&mt("Set 'Search criteria' to: <span class=\"LC_cusr_emph\">'username is ...... in selected LON-CAPA domain'").'</span></li><li>'.&mt('Provide the proposed username').'</li><li>'.&mt('Search').'</li></ul><br />';                  $response .= '<br /><br />'.&mt("<b>To add a new user</b> (you can only create new users in your current role's domain - <span class=\"LC_cusr_emph\">[_1]</span>):",$env{'request.role.domain'}).'<ul><li>'.&mt("Set 'Domain/institution to search' to: <span class=\"LC_cusr_emph\">[_1]</span>",$showdom).'<li>'.&mt("Set 'Search criteria' to: <span class=\"LC_cusr_emph\">'username is ...... in selected LON-CAPA domain'").'</span></li><li>'.&mt('Provide the proposed username').'</li><li>'.&mt('Search').'</li></ul><br />';
                   } else {
                       my $helplink = ' href="javascript:helpMenu('."'display'".')"';
                       $response .= '<br /><br />'.&mt("You are not authorized to create new users in your current role's domain - <span class=\"LC_cusr_emph\">[_1]</span>.",$env{'request.role.domain'}).'<br />'.&mt('Contact the <a[_1]>helpdesk</a> if you need to create a new user.',$helplink).'<br /><br />';
                   }
             }              }
         }          }
     }      }
Line 3444  sub course_level_table { Line 3522  sub course_level_table {
         }          }
         my @roles = &Apache::lonuserutils::roles_by_context('course');          my @roles = &Apache::lonuserutils::roles_by_context('course');
  foreach my $role (@roles) {   foreach my $role (@roles) {
               my $plrole=&Apache::lonnet::plaintext($role);
     if (&Apache::lonnet::allowed('c'.$role,$thiscourse)) {      if (&Apache::lonnet::allowed('c'.$role,$thiscourse)) {
  my $plrole=&Apache::lonnet::plaintext($role);                  $table .= &course_level_row($protectedcourse,$role,$area,$domain,
  $table .= &Apache::loncommon::start_data_table_row().                                              $plrole,\%sections_count,\%lt);    
 '<td><input type="checkbox" name="act_'.$protectedcourse.'_'.$role.'" /></td>              } elsif ($env{'request.course.sec'} ne '') {
 <td>'.$plrole.'</td>                  if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
 <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";                                               $env{'request.course.sec'})) {
         if ($role ne 'cc') {                      $table .= &course_level_row($protectedcourse,$role,$area,$domain,
                     if (%sections_count) {                                                  $plrole,\%sections_count,\%lt);
                         my $currsec =   
                             &Apache::lonuserutils::course_sections(\%sections_count,  
                                                         $protectedcourse.'_'.$role);  
                         $table .=   
                     '<td><table class="LC_createuser">'.  
                      '<tr class="LC_section_row">  
                         <td valign="top">'.$lt{'exs'}.'<br />'.  
                         $currsec.'</td>'.  
                      '<td>&nbsp;&nbsp;</td>'.  
                      '<td valign="top">&nbsp;'.$lt{'new'}.'<br />'.  
                      '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.'" value="" />'.  
                      '<input type="hidden" '.  
                      'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'.  
                      '</tr></table></td>';  
                     } else {  
                         $table .= '<td><input type="text" size="10" '.  
                      'name="sec_'.$protectedcourse.'_'.$role.'" /></td>';  
                     }  
                 } else {   
     $table .= '<td>&nbsp</td>';  
                 }                  }
  $table .= <<ENDTIMEENTRY;  
 <td><input type="hidden" name="start_$protectedcourse\_$role" value='' />  
 <a href=  
 "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$role.value,'start_$protectedcourse\_$role','cu.pres','dateset')">$lt{'ssd'}</a></td>  
 <td><input type="hidden" name="end_$protectedcourse\_$role" value='' />  
 <a href=  
 "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt{'sed'}</a></td>  
 ENDTIMEENTRY  
                 $table.= &Apache::loncommon::end_data_table_row();  
             }              }
         }          }
         foreach my $cust (sort keys %customroles) {          if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
     if (&Apache::lonnet::allowed('ccr',$thiscourse)) {              foreach my $cust (sort keys %customroles) {
  my $plrole=$cust;                  my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
                 my $customrole=$protectedcourse.'_cr_cr_'.$env{'user.domain'}.                  $table .= &course_level_row($protectedcourse,$role,$area,$domain,
     '_'.$env{'user.name'}.'_'.$plrole;                                              $cust,\%sections_count,\%lt);
  $table .= &Apache::loncommon::start_data_table_row().              }
 '<td><input type="checkbox" name="act_'.$customrole.'" /></td>  
 <td>'.$plrole.'</td>  
 <td>'.$area.'</td>'."\n";  
                 if (%sections_count) {  
                     my $currsec =   
                         &Apache::lonuserutils::course_sections(\%sections_count,  
                                                                $customrole);  
                     $table.=  
                    '<td><table class="LC_createuser">'.  
                    '<tr class="LC_section_row"><td valign="top">'.  
                    $lt{'exs'}.'<br />'.$currsec.'</td>'.  
                    '<td>&nbsp;&nbsp;</td>'.  
                    '<td valign="top">&nbsp;'.$lt{'new'}.'<br />'.  
                    '<input type="text" name="newsec_'.$customrole.'" value="" /></td>'.  
                    '<input type="hidden" '.  
                    'name="sec_'.$customrole.'" /></td>'.  
                    '</tr></table></td>';  
                 } else {  
                     $table .= '<td><input type="text" size="10" '.  
                      'name="sec_'.$customrole.'" /></td>';  
                 }  
                 $table .= <<ENDENTRY;  
 <td><input type="hidden" name="start_$customrole" value='' />  
 <a href=  
 "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$customrole.value,'start_$customrole','cu.pres','dateset')">$lt{'ssd'}</a></td>  
 <td><input type="hidden" name="end_$customrole" value='' />  
 <a href=  
 "javascript:pjump('date_end','End Date $plrole',document.cu.end_$customrole.value,'end_$customrole','cu.pres','dateset')">$lt{'sed'}</a></td>  
 ENDENTRY  
                $table .= &Apache::loncommon::end_data_table_row();  
            }  
  }   }
     }      }
     return '' if ($table eq ''); # return nothing if there is nothing       return '' if ($table eq ''); # return nothing if there is nothing 
Line 3540  $table. Line 3559  $table.
     return $result;      return $result;
 }  }
   
   sub course_level_row {
       my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,$lt) = @_;
       my $table = &Apache::loncommon::start_data_table_row().
                   ' <td><input type="checkbox" name="act_'.
                   $protectedcourse.'_'.$role.'" /></td>'."\n".
                   ' <td>'.$plrole.'</td>'."\n".
                   '<td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
       if ($role eq 'cc') {
           $table .= '<td>&nbsp</td>';
       } elsif ($env{'request.course.sec'} ne '') {
           $table .= ' <td><input type="hidden" value="'.
                     $env{'request.course.sec'}.'" '.
                     'name="sec_'.$protectedcourse.'_'.$role.'" />'.
                     $env{'request.course.sec'}.'</td>';
       } else {
           if (ref($sections_count) eq 'HASH') {
               my $currsec = 
                   &Apache::lonuserutils::course_sections($sections_count,
                                                          $protectedcourse.'_'.$role);
               $table .= '<td><table class="LC_createuser">'.
                         '<tr class="LC_section_row">
                           <td valign="top">'.$lt->{'exs'}.'<br />'.
                           $currsec.'</td>
                           <td>&nbsp;&nbsp;</td>
                           <td valign="top">&nbsp;'.$lt->{'new'}.'<br />'.
                        '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
                        '" value="" />'.
                        '<input type="hidden" '.
                        'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
                        '</tr></table></td>';
           } else {
               $table .= '<td><input type="text" size="10" '.
                         'name="sec_'.$protectedcourse.'_'.$role.'" /></td>';
           }
       }
       $table .= <<ENDTIMEENTRY;
   <td><input type="hidden" name="start_$protectedcourse\_$role" value='' />
   <a href=
   "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$role.value,'start_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'ssd'}</a></td>
   <td><input type="hidden" name="end_$protectedcourse\_$role" value='' />
   <a href=
   "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
   ENDTIMEENTRY
       $table.= &Apache::loncommon::end_data_table_row();
   }
   
 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();
Line 3586  sub course_level_dc { Line 3651  sub course_level_dc {
                      '<td>&nbsp;&nbsp;</td>'.                       '<td>&nbsp;&nbsp;</td>'.
                      '<td valign="top">&nbsp;<b>'.$lt{'new'}.'</b><br />'.                       '<td valign="top">&nbsp;<b>'.$lt{'new'}.'</b><br />'.
                      '<input type="text" name="newsec" value="" />'.                       '<input type="text" name="newsec" value="" />'.
                        '<input type="hidden" name="sections" value="" />'.
                      '<input type="hidden" name="groups" value="" /></td>'.                       '<input type="hidden" name="groups" value="" /></td>'.
                      '</tr></table></td>';                       '</tr></table></td>';
     $otheritems .= <<ENDTIMEENTRY;      $otheritems .= <<ENDTIMEENTRY;

Removed from v.1.217  
changed lines
  Added in v.1.221


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