Diff for /loncom/interface/loncreateuser.pm between versions 1.26 and 1.27

version 1.26, 2002/02/11 21:25:07 version 1.27, 2002/02/12 21:42:18
Line 70  BEGIN { Line 70  BEGIN {
     $krbdefdom=~tr/a-z/A-Z/;      $krbdefdom=~tr/a-z/A-Z/;
     $authformnop=(<<END);      $authformnop=(<<END);
 <p>  <p>
 <input type=radio name=login value=nop checked='checked'  <input type="radio" name="login" value="" checked="checked"
 onClick="clicknop(this.form);">  onClick="clicknop(this.form);">
 Do not change login data  Do not change login data
 </p>  </p>
Line 344  ENDCHANGEUSER Line 344  ENDCHANGEUSER
  }   }
                  $area=$carea;                   $area=$carea;
       } else {        } else {
    # Determine if current user is able to revoke privileges
                  if ($area=~/^\/(\w+)\//) {                   if ($area=~/^\/(\w+)\//) {
                      if (&Apache::lonnet::allowed('c'.$role_code,$1)) {                       if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
  $allows=1;   $allows=1;
Line 358  ENDCHANGEUSER Line 359  ENDCHANGEUSER
               $r->print('<tr bgcolor=#"'.$bgcol.'"><td>');                $r->print('<tr bgcolor=#"'.$bgcol.'"><td>');
               my $active=1;                my $active=1;
               if (($role_end_time) && ($now>$role_end_time)) { $active=0; }                if (($role_end_time) && ($now>$role_end_time)) { $active=0; }
               if (!($active) && ($allows)) {                if (($active) && ($allows)) {
   $r->print('<input type=checkbox name="rev:'.$thisrole.'">');    $r->print('<input type="checkbox" name="rev:'
       .$thisrole.'">');
               } else {                } else {
                   $r->print('&nbsp;');                    $r->print('&nbsp;');
               }                }
Line 543  ENDDROW Line 545  ENDDROW
 # ================================================================= Phase Three  # ================================================================= Phase Three
 sub phase_three {  sub phase_three {
     my $r=shift;      my $r=shift;
       # Error messages
       my $error     = '<font color="#ff0000">Error:</font>';
       my $end       = '</body></html>';
       # Print header
     $r->print(<<ENDTHREEHEAD);      $r->print(<<ENDTHREEHEAD);
 <html>  <html>
 <head>  <head>
 <title>The LearningOnline Network with CAPA</title>  <title>The LearningOnline Network with CAPA</title>
 </head>  </head>
 <body bgcolor="#FFFFFF">  <body bgcolor="#FFFFFF">
 <img align=right src=/adm/lonIcons/lonlogos.gif>  <img align="right" src="/adm/lonIcons/lonlogos.gif">
 <h1>Create User, Change User Privileges</h1>  
 ENDTHREEHEAD  ENDTHREEHEAD
    $r->print('<h2>'.$ENV{'form.cuname'}.' at '.$ENV{'form.cdomain'}.'</h2>');      # Check Inputs
    if ($ENV{'form.makeuser'}) {      if (! $ENV{'form.cuname'} ) {
     $r->print('<h3>Creating User</h3>');   $r->print($error.'No login name specified.'.$end);
     if (($ENV{'form.cuname'})&&($ENV{'form.cuname'}!~/\W/)&&   return;
         ($ENV{'form.cdomain'})&&($ENV{'form.cdomain'}!~/\W/)) {      }
  my $amode='';      if (  $ENV{'form.cuname'}  =~/\W/) {
         my $genpwd='';   $r->print($error.'Invalid login name.  '.
         if ($ENV{'form.login'} eq 'krb') {    'Only letters, numbers, and underscores are valid.'.
            $amode='krb4';    $end);
            $genpwd=$ENV{'form.krbdom'};   return;
         } elsif ($ENV{'form.login'} eq 'int') {      }
            $amode='internal';      if (! $ENV{'form.cdomain'}       ) {
            $genpwd=$ENV{'form.intpwd'};   $r->print($error.'No domain specified.'.$end);
         } elsif ($ENV{'form.login'} eq 'fsys') {   return;
            $amode='unix';      }
            $genpwd=$ENV{'form.fsyspwd'};      if (  $ENV{'form.cdomain'} =~/\W/) {
         } elsif ($ENV{'form.login'} eq 'loc') {   $r->print($error.'Invalid domain name.  '.
     $amode='localauth';    'Only letters, numbers, and underscores are valid.'.
     $genpwd=$ENV{'form.locarg'};    $end);
     if (!$genpwd) { $genpwd=" "; }   return;
       }
       # Determine authentication method and password for the user being modified
       my $amode='';
       my $genpwd='';
       if ($ENV{'form.login'} eq 'krb') {
    $amode='krb4';
    $genpwd=$ENV{'form.krbdom'};
       } elsif ($ENV{'form.login'} eq 'int') {
    $amode='internal';
    $genpwd=$ENV{'form.intpwd'};
       } elsif ($ENV{'form.login'} eq 'fsys') {
    $amode='unix';
    $genpwd=$ENV{'form.fsyspwd'};
       } elsif ($ENV{'form.login'} eq 'loc') {
    $amode='localauth';
    $genpwd=$ENV{'form.locarg'};
    $genpwd=" " if (!$genpwd);
       }
       if ($ENV{'form.makeuser'}) {
           # Create a new user
    $r->print(<<ENDNEWUSERHEAD);
   <h1>Create User</h1>
   <h3>Creating user "$ENV{'form.cuname'}" in domain "$ENV{'form.cdomain'}"</h2>
   ENDNEWUSERHEAD
           # Check for the authentication mode and password
           if (! $amode || ! $genpwd) {
       $r->print($error.'Invalid login mode or password'.$end);    
       return;
  }   }
         if (($amode) && ($genpwd)) {   # Call modifyuser
           $r->print('Generating user: '.&Apache::lonnet::modifyuser(   my $result = &Apache::lonnet::modifyuser
                       $ENV{'form.cdomain'},$ENV{'form.cuname'},      ($ENV{'form.cdomain'},$ENV{'form.cuname'},
                       $ENV{'form.cstid'},$amode,$genpwd,       $ENV{'form.cstid'},$amode,$genpwd,
                $ENV{'form.cfirst'},$ENV{'form.cmiddle'},       $ENV{'form.cfirst'},$ENV{'form.cmiddle'},
                       $ENV{'form.clast'},$ENV{'form.cgen'}));       $ENV{'form.clast'},$ENV{'form.cgen'}
           $r->print('<br>Home server: '.&Apache::lonnet::homeserver       );
                       ($ENV{'form.cuname'},$ENV{'form.cdomain'}));   $r->print('Generating user: '.$result);
    $r->print('<br>Home server: '.&Apache::lonnet::homeserver
  } else {    ($ENV{'form.cuname'},$ENV{'form.cdomain'}));
            $r->print('Invalid login mode or password');          } elsif ($ENV{'form.login'} ne '') {
         }             # Modify user privileges
     } else {   $r->print(<<ENDMODIFYUSERHEAD);
         $r->print('Invalid username or domain');  <h1>Change User Privileges</h1>
     }  <h2>User "$ENV{'form.cuname'}" in domain "$ENV{'form.cdomain'}"</h2>
    }  ENDMODIFYUSERHEAD
    if (!$ENV{'form.makeuser'} and $ENV{'form.login'} ne 'nop') {          if (! $amode || ! $genpwd) {
     $r->print('<h3>Changing User Login Data</h3>');      $r->print($error.'Invalid login mode or password'.$end);    
     if (($ENV{'form.cuname'})&&($ENV{'form.cuname'}!~/\W/)&&      return;
         ($ENV{'form.cdomain'})&&($ENV{'form.cdomain'}!~/\W/)) {  
  my $amode='';  
         my $genpwd='';  
         if ($ENV{'form.login'} eq 'krb') {  
            $amode='krb4';  
            $genpwd=$ENV{'form.krbdom'};  
         } elsif ($ENV{'form.login'} eq 'int') {  
            $amode='internal';  
            $genpwd=$ENV{'form.intpwd'};  
         } elsif ($ENV{'form.login'} eq 'fsys') {  
            $amode='unix';  
            $genpwd=$ENV{'form.fsyspwd'};  
         } elsif ($ENV{'form.login'} eq 'loc') {  
     $amode='localauth';  
     $genpwd=$ENV{'form.locarg'};  
     if (!$genpwd) { $genpwd=" "; }  
  }   }
         if (($amode) && ($genpwd)) {   # Only allow authentification modification if the person has authority
    if (&Apache::lonnet::allowed('mau',$ENV{'user.domain'})) {
     $r->print('Modifying authentication: '.      $r->print('Modifying authentication: '.
  &Apache::lonnet::modifyuserauth(    &Apache::lonnet::modifyuserauth(
        $ENV{'form.cdomain'},$ENV{'form.cuname'},         $ENV{'form.cdomain'},$ENV{'form.cuname'},
                        $amode,$genpwd));                         $amode,$genpwd));
             $r->print('<br>Home server: '.&Apache::lonnet::homeserver              $r->print('<br>Home server: '.&Apache::lonnet::homeserver
                       ($ENV{'form.cuname'},$ENV{'form.cdomain'}));    ($ENV{'form.cuname'},$ENV{'form.cdomain'}));
   
  } else {   } else {
            $r->print('Invalid login mode or password');          # Okay, this is a non-fatal error.
         }                $r->print($error.'You do not have the authority to modify '.
     } else {        'this users authentification information.');    
         $r->print('Invalid username or domain');   }
     }      }
    }      ##
     my $now=time;      my $now=time;
     $r->print('<h3>Modifying Roles</h3>');      $r->print('<h3>Modifying Roles</h3>');
     foreach (keys (%ENV)) {      foreach (keys (%ENV)) {
  if (($_=~/^form\.rev\:([^\_]+)\_([^\_]+)$/) && ($ENV{$_})) {   next if (! $ENV{$_});
            $r->print('Revoking '.$2.' in '.$1.': '.   # Revoke roles
           &Apache::lonnet::assignrole($ENV{'form.cdomain'},$ENV{'form.cuname'},   if ($_=~/^form\.rev/) {
                                       $1,$2,$now).'<br>');      if ($_=~/^form\.rev\:([^\_]+)\_([^\_]+)$/) {
            if ($2 eq 'st') {          $r->print('Revoking '.$2.' in '.$1.': '.
                $1=~/^\/(\w+)\/(\w+)/;                       &Apache::lonnet::assignrole($ENV{'form.cdomain'},
                my $cid=$1.'_'.$2;                       $ENV{'form.cuname'},$1,$2,$now).'<br>');
        $r->print('Drop from classlist: '.   if ($2 eq 'st') {
           &Apache::lonnet::critical('put:'.$ENV{'course.'.$cid.'.domain'}.':'.      $1=~/^\/(\w+)\/(\w+)/;
               $ENV{'course.'.$cid.'.num'}.':classlist:'.      my $cid=$1.'_'.$2;
                       &Apache::lonnet::escape($ENV{'form.cuname'}.':'.      $r->print('Drop from classlist: '.
                                               $ENV{'form.cdomain'}).'='.   &Apache::lonnet::critical('put:'.
                       &Apache::lonnet::escape($now.':'),                               $ENV{'course.'.$cid.'.domain'}.':'.
               $ENV{'course.'.$cid.'.home'}).'<br>');                       $ENV{'course.'.$cid.'.num'}.':classlist:'.
            }                           &Apache::lonnet::escape($ENV{'form.cuname'}.':'.
  }                               $ENV{'form.cdomain'}).'='.
     }                            &Apache::lonnet::escape($now.':'),
     foreach (keys(%ENV)) {                       $ENV{'course.'.$cid.'.home'}).'<br>');
  if (($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) && ($ENV{$_})) {   }
             my $url='/'.$1.'/'.$2;      } 
             if ($ENV{'form.sec_'.$1.'_'.$2.'_'.$3}) {   } elsif ($_=~/^form\.act/) {
  $url.='/'.$ENV{'form.sec_'.$1.'_'.$2.'_'.$3};      if ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) {
             }   # Activate roles for sections with 3 id numbers
             my $start=$now;   # set start, end times, and the url for the class
             if ($ENV{'form.start_'.$1.'_'.$2.'_'.$3}) {   my $start = ( $ENV{'form.start_'.$1.'_'.$2} ? 
  $start=$ENV{'form.start_'.$1.'_'.$2.'_'.$3};        $ENV{'form.start_'.$1.'_'.$2} : 
             }        $now );
             my $end=0;   my $end   = ( $ENV{'form.end_'.$1.'_'.$2} ? 
             if ($ENV{'form.end_'.$1.'_'.$2.'_'.$3}) {        $ENV{'form.end_'.$1.'_'.$2} :
  $end=$ENV{'form.end_'.$1.'_'.$2.'_'.$3};        0 );
             }   my $url='/'.$1.'/'.$2;
             $r->print('Assigning: '.$3.' in '.$url.': '.   if ($ENV{'form.sec_'.$1.'_'.$2.'_'.$3}) {
           &Apache::lonnet::assignrole($ENV{'form.cdomain'},$ENV{'form.cuname'},      $url.='/'.$ENV{'form.sec_'.$1.'_'.$2.'_'.$3};
                                       $url,$3,$end,$start).'<br>');   }
             if ($3 eq 'st') {   # Assign the role and report it
  $url=~/^\/(\w+)\/(\w+)/;   $r->print('Assigning: '.$3.' in '.$url.': '.
                 my $cid=$1.'_'.$2;                            &Apache::lonnet::assignrole(
                $r->print('Add to classlist: '.                                $ENV{'form.cdomain'},$ENV{'form.cuname'},
           &Apache::lonnet::critical('put:'.$ENV{'course.'.$cid.'.domain'}.':'.                                $url,$3,$end,$start).
               $ENV{'course.'.$cid.'.num'}.':classlist:'.    '<br>');
                       &Apache::lonnet::escape($ENV{'form.cuname'}.':'.   # Handle students differently
                                               $ENV{'form.cdomain'}).'='.   if ($3 eq 'st') {
                       &Apache::lonnet::escape($end.':'.$start),      $url=~/^\/(\w+)\/(\w+)/;
               $ENV{'course.'.$cid.'.home'}).'<br>');      my $cid=$1.'_'.$2;
       $r->print('Add to classlist: '.
         &Apache::lonnet::critical(
     'put:'.$ENV{'course.'.$cid.'.domain'}.':'.
                              $ENV{'course.'.$cid.'.num'}.':classlist:'.
                                      &Apache::lonnet::escape(
                                          $ENV{'form.cuname'}.':'.
                                          $ENV{'form.cdomain'} ).'='.
                                      &Apache::lonnet::escape($end.':'.$start),
          $ENV{'course.'.$cid.'.home'})
         .'<br>');
    }
       } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
    # Activate roles for sections with two id numbers
    # set start, end times, and the url for the class
    my $start = ( $ENV{'form.start_'.$1.'_'.$2} ? 
         $ENV{'form.start_'.$1.'_'.$2} : 
         $now );
    my $end   = ( $ENV{'form.end_'.$1.'_'.$2} ? 
         $ENV{'form.end_'.$1.'_'.$2} :
         0 );
    my $url='/'.$1.'/';
    # Assign the role and report it.
    $r->print('Assigning: '.$2.' in '.$url.': '.
                             &Apache::lonnet::assignrole(
                                 $ENV{'form.cdomain'},$ENV{'form.cuname'},
                                 $url,$2,$end,$start)
     .'<br>');
     }      }
  } elsif (($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) && ($ENV{$_})) {   } 
             my $url='/'.$1.'/';      } # End of foreach (keys(%ENV))
             my $start=$now;  
             if ($ENV{'form.start_'.$1.'_'.$2}) {  
  $start=$ENV{'form.start_'.$1.'_'.$2};  
             }  
             my $end=0;  
             if ($ENV{'form.end_'.$1.'_'.$2}) {  
  $end=$ENV{'form.end_'.$1.'_'.$2};  
             }  
             $r->print('Assigning: '.$2.' in '.$url.': '.  
           &Apache::lonnet::assignrole($ENV{'form.cdomain'},$ENV{'form.cuname'},  
                                       $url,$2,$end,$start).'<br>');  
         }  
     }  
     $r->print('</body></html>');      $r->print('</body></html>');
 }  }
   
Line 724  sub handler { Line 755  sub handler {
    return OK;     return OK;
 }   } 
   
   #-------------------------------------------------- functions for &phase_two
 sub course_level_table {  sub course_level_table {
     my %inccourses = @_;      my %inccourses = @_;
     my $table = '';      my $table = '';
Line 778  $table Line 809  $table
 ENDTABLE  ENDTABLE
     return $result;      return $result;
 }  }
   #---------------------------------------------- end functions for &phase_two
   
 1;  1;
 __END__  __END__

Removed from v.1.26  
changed lines
  Added in v.1.27


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