Diff for /loncom/interface/loncreateuser.pm between versions 1.138 and 1.148

version 1.138, 2006/11/23 00:53:19 version 1.148, 2007/03/12 17:06:59
Line 66  use Apache::loncommon; Line 66  use Apache::loncommon;
 use Apache::lonlocal;  use Apache::lonlocal;
 use Apache::longroup;  use Apache::longroup;
 use lib '/home/httpd/lib/perl/';  use lib '/home/httpd/lib/perl/';
 use LONCAPA;  use LONCAPA qw(:DEFAULT :match);
   
 my $loginscript; # piece of javascript used in two separate instances  my $loginscript; # piece of javascript used in two separate instances
 my $generalrule;  my $generalrule;
Line 135  sub portfolio_quota { Line 135  sub portfolio_quota {
 sub print_username_entry_form {  sub print_username_entry_form {
     my ($r) = @_;      my ($r) = @_;
     my $defdom=$env{'request.role.domain'};      my $defdom=$env{'request.role.domain'};
     my @domains = &Apache::loncommon::get_domains();  
     my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');      my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
     my $selscript=&Apache::loncommon::studentbrowser_javascript();      my $selscript=&Apache::loncommon::studentbrowser_javascript();
     my $start_page =      my $start_page =
Line 251  sub print_user_modification_page { Line 250  sub print_user_modification_page {
         $groupslist = '"'.$groupslist.'"';             $groupslist = '"'.$groupslist.'"';   
     }      }
   
     if ($env{'request.role'} =~ m-^dc\./(\w+)/$-) {      if ($env{'request.role'} =~ m-^dc\./($match_domain)/$-) {
         my $dcdom = $1;          my $dcdom = $1;
         $loaditem{'onload'} = "document.cu.coursedesc.value='';";          $loaditem{'onload'} = "document.cu.coursedesc.value='';";
         my @rolevals = ('st','ta','ep','in','cc');          my @rolevals = ('st','ta','ep','in','cc');
Line 358  sub print_user_modification_page { Line 357  sub print_user_modification_page {
         }          }
         return -1;          return -1;
     }      }
   
     function setType() {  
         var crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value;  
         rolevals = new Array("$rolevalslist");  
         if (crstype == 'Group') {  
             if (document.cu.currsec.options[0].text == "$pickcrsfirst") {  
                 document.cu.currsec.options[0].text = "$pickgrpfirst";  
             }   
             grprolenames = new Array("$grprolenameslist");  
             for (var i=0; i<rolevals.length; i++) {  
                 if (document.cu.role.selectedIndex == i) {  
                     document.cu.role.options[i] = new Option(grprolenames[i],rolevals[i],true,false);  
                 } else {  
                     document.cu.role.options[i] = new Option(grprolenames[i],rolevals[i],false,false);  
                 }  
             }  
         } else {  
             if (document.cu.currsec.options[0].text == "$pickgrpfirst") {  
                 document.cu.currsec.options[0].text = "$pickcrsfirst";  
             }  
             crsrolenames = new Array("$crsrolenameslist");  
             for (var i=0; i<rolevals.length; i++) {  
                 if (document.cu.role.selectedIndex == i) {  
                     document.cu.role.options[i] = new Option(crsrolenames[i],rolevals[i],true,false);  
                 } else {  
                     document.cu.role.options[i] = new Option(crsrolenames[i],rolevals[i],false,false);  
                 }  
             }  
         }  
     }  
 ENDSCRIPT  ENDSCRIPT
     } else {      } else {
         $nondc_setsection_code = <<"ENDSECCODE";          $nondc_setsection_code = <<"ENDSECCODE";
Line 484  ENDSECCODE Line 453  ENDSECCODE
 <input type="hidden" name="pres_marker" value="" >  <input type="hidden" name="pres_marker" value="" >
 ENDFORMINFO  ENDFORMINFO
     my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);      my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
     my %incdomains;   
     my %inccourses;      my %inccourses;
     foreach my $item (values(%Apache::lonnet::hostdom)) {  
        $incdomains{$item}=1;  
     }  
     foreach my $key (keys(%env)) {      foreach my $key (keys(%env)) {
  if ($key=~/^user\.priv\.cm\.\/(\w+)\/(\w+)/) {   if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
     $inccourses{$1.'_'.$2}=1;      $inccourses{$1.'_'.$2}=1;
         }          }
     }      }
Line 619  END Line 584  END
                    split(/_/,$role);                     split(/_/,$role);
 # Is this a custom role? Get role owner and title.  # Is this a custom role? Get role owner and title.
        my ($croleudom,$croleuname,$croletitle)=         my ($croleudom,$croleuname,$croletitle)=
            ($role_code=~/^cr\/(\w+)\/(\w+)\/(\w+)$/);             ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
                my $allowed=0;                 my $allowed=0;
                my $delallowed=0;                 my $delallowed=0;
        my $sortkey=$role_code;         my $sortkey=$role_code;
        my $class='Unknown';         my $class='Unknown';
                if ($area =~ /^\/(\w+)\/(\d\w+)/ ) {                 if ($area =~ m{^/($match_domain)/($match_courseid)} ) {
    $class='Course';     $class='Course';
                    my ($coursedom,$coursedir) = ($1,$2);                     my ($coursedom,$coursedir) = ($1,$2);
    $sortkey.="\0$coursedom";     $sortkey.="\0$coursedom";
Line 660  END Line 625  END
        }         }
    }     }
                    # Compute the background color based on $area                     # Compute the background color based on $area
                    if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) {                     if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) {
                        $carea.='<br />Section: '.$3;                         $carea.='<br />Section: '.$3;
        $sortkey.="\0$3";         $sortkey.="\0$3";
                    }                     }
Line 668  END Line 633  END
                } else {                 } else {
    $sortkey.="\0".$area;     $sortkey.="\0".$area;
                    # Determine if current user is able to revoke privileges                     # Determine if current user is able to revoke privileges
                    if ($area=~ /^\/(\w+)\//) {                     if ($area=~m{^/($match_domain)/}) {
                        if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||                         if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
                        (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {                         (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
                            $allowed=1;                             $allowed=1;
Line 692  END Line 657  END
    }     }
                }                 }
                if (($role_code eq 'ca') || ($role_code eq 'aa')) {                 if (($role_code eq 'ca') || ($role_code eq 'aa')) {
                    $area=~/\/(\w+)\/(\w+)/;                     $area=~m{/($match_domain)/($match_username)};
    if (&authorpriv($2,$1)) {     if (&authorpriv($2,$1)) {
        $allowed=1;         $allowed=1;
                    } else {                     } else {
Line 962  ENDNOPRIV Line 927  ENDNOPRIV
     &mt('Extent').'</th>'.      &mt('Extent').'</th>'.
     '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.      '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
     &Apache::loncommon::end_data_table_header_row();      &Apache::loncommon::end_data_table_header_row();
     foreach my $thisdomain ( sort( keys(%incdomains))) {      foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
         foreach my $role ('dc','li','dg','au','sc') {          foreach my $role ('dc','li','dg','au','sc') {
             if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {              if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
                my $plrole=&Apache::lonnet::plaintext($role);                 my $plrole=&Apache::lonnet::plaintext($role);
Line 994  ENDNOPRIV Line 959  ENDNOPRIV
 # Course and group levels  # Course and group levels
 #  #
   
     if ($env{'request.role'} =~ m-^dc\./(\w+)/$-) {      if ($env{'request.role'} =~ m{^dc\./($match_domain)/$}) {
         $r->print(&course_level_dc($1,'Course'));          $r->print(&course_level_dc($1,'Course'));
         $r->print('<hr /><input type="button" value="'.&mt('Modify User').'" onClick="setCourse()">'."\n");          $r->print('<hr /><input type="button" value="'.&mt('Modify User').'" onClick="setCourse()">'."\n");
     } else {      } else {
Line 1099  ENDNEWUSERHEAD Line 1064  ENDNEWUSERHEAD
         if (lc($desiredhost) eq 'default') {          if (lc($desiredhost) eq 'default') {
             $desiredhost = undef;              $desiredhost = undef;
         } else {          } else {
             my %home_servers = &Apache::loncommon::get_library_servers              my %home_servers = 
                 ($env{'form.ccdomain'});     &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
             if (! exists($home_servers{$desiredhost})) {              if (! exists($home_servers{$desiredhost})) {
                 $r->print($error.&mt('Invalid home server specified'));                  $r->print($error.&mt('Invalid home server specified'));
                 return;                  return;
Line 1117  ENDNEWUSERHEAD Line 1082  ENDNEWUSERHEAD
         my $home = &Apache::lonnet::homeserver($env{'form.ccuname'},          my $home = &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').': '.$home.' '.
                   $Apache::lonnet::libserv{$home});                    &Apache::lonnet::hostname($home));
     } 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 1174  ENDMODIFYUSERHEAD Line 1139  ENDMODIFYUSERHEAD
                 }                  }
             }              }
         } else {          } else {
             $oldportfolioquota = &default_quota($env{'form.ccdomain'});              $oldportfolioquota = 
                     &Apache::loncommon::default_quota($env{'form.ccdomain'});
         }          }
         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'}  ||
Line 1273  END Line 1239  END
                      &Apache::lonnet::revokerole($env{'form.ccdomain'},                       &Apache::lonnet::revokerole($env{'form.ccdomain'},
                      $env{'form.ccuname'},$1,$2).'</b><br />');                       $env{'form.ccuname'},$1,$2).'</b><br />');
  if ($2 eq 'st') {   if ($2 eq 'st') {
     $1=~/^\/(\w+)\/(\w+)/;      $1=~m{^/($match_domain)/($match_courseid)};
     my $cid=$1.'_'.$2;      my $cid=$1.'_'.$2;
     $r->print(&mt('Drop from classlist').': <b>'.      $r->print(&mt('Drop from classlist').': <b>'.
  &Apache::lonnet::critical('put:'.   &Apache::lonnet::critical('put:'.
Line 1285  END Line 1251  END
                      $env{'course.'.$cid.'.home'}).'</b><br />');                       $env{'course.'.$cid.'.home'}).'</b><br />');
  }   }
     }       } 
     if ($key=~/^form\.rev\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {      if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
 # 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>'.
                       &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},                        &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
   $env{'form.ccuname'},$1,$2,$3,$4).    $env{'form.ccuname'},$1,$2,$3,$4).
  '</b><br />');   '</b><br />');
Line 1300  END Line 1266  END
                      &Apache::lonnet::assignrole($env{'form.ccdomain'},                       &Apache::lonnet::assignrole($env{'form.ccdomain'},
                      $env{'form.ccuname'},$1,$2,$now,0,1).'<br />');                       $env{'form.ccuname'},$1,$2,$now,0,1).'<br />');
  if ($2 eq 'st') {   if ($2 eq 'st') {
     $1=~/^\/(\w+)\/(\w+)/;      $1=~m{^/($match_domain)/($match_courseid)};
     my $cid=$1.'_'.$2;      my $cid=$1.'_'.$2;
     $r->print(&mt('Drop from classlist').': <b>'.      $r->print(&mt('Drop from classlist').': <b>'.
  &Apache::lonnet::critical('put:'.   &Apache::lonnet::critical('put:'.
Line 1312  END Line 1278  END
                      $env{'course.'.$cid.'.home'}).'</b><br />');                       $env{'course.'.$cid.'.home'}).'</b><br />');
  }   }
             }              }
             if ($key=~/^form\.del\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {      if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
                 my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);                  my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
 # Delete custom role  # Delete custom role
                 $r->print(&mt('Deleting custom role [_1] by [_2]@[_3] in [_4]',                  $r->print(&mt('Deleting custom role [_1] by [_2]@[_3] in [_4]',
Line 1331  END Line 1297  END
                 my $logmsg;                  my $logmsg;
                 my $output;                  my $output;
                 if ($role eq 'st') {                  if ($role eq 'st') {
                     if ($url =~ m-^/(\w+)/(\w+)/?(\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')) {
                             $output = "Error: $result\n";                              $output = "Error: $result\n";
Line 1351  END Line 1317  END
                 $r->print($output);                  $r->print($output);
     }      }
 # Re-enable custom role  # Re-enable custom role
             if ($key=~/^form\.ren\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {      if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
                 my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);                  my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
                 my $result = &Apache::lonnet::assigncustomrole(                  my $result = &Apache::lonnet::assigncustomrole(
                                $env{'form.ccdomain'}, $env{'form.ccuname'},                                 $env{'form.ccdomain'}, $env{'form.ccuname'},
Line 1362  END Line 1328  END
  } elsif ($key=~/^form\.act/) {   } elsif ($key=~/^form\.act/) {
             my $udom = $env{'form.ccdomain'};              my $udom = $env{'form.ccdomain'};
             my $uname = $env{'form.ccuname'};              my $uname = $env{'form.ccuname'};
     if ($key=~/^form\.act\_([^\_]+)\_([^\_]+)\_cr_cr_([^\_]+)_(\w+)_([^\_]+)$/) {      if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
                 # Activate a custom role                  # Activate a custom role
  my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);   my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
  my $url='/'.$one.'/'.$two;   my $url='/'.$one.'/'.$two;
Line 1393  END Line 1359  END
         $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));          $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));
                     }                      }
                 }                  }
     } elsif ($key=~/^form\.act\_([^\_]+)\_(\w+)\_([^\_]+)$/) {      } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
  # Activate roles for sections with 3 id numbers   # Activate roles for sections with 3 id numbers
  # set start, end times, and the url for the class   # set start, end times, and the url for the class
  my ($one,$two,$three)=($1,$2,$3);   my ($one,$two,$three)=($1,$2,$3);
Line 1867  sub course_sections { Line 1833  sub course_sections {
         $output = '<select name="currsec_'.$role.'" ';          $output = '<select name="currsec_'.$role.'" ';
         my $multiple = 4;          my $multiple = 4;
         if (scalar(@sections) < 4) { $multiple = scalar(@sections); }          if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
         $output .= '"multiple" size="'.$multiple.'">'."\n";          $output .= 'multiple="multiple" size="'.$multiple.'">'."\n";
         foreach my $sec (@sections) {          foreach my $sec (@sections) {
             $output .= '<option value="'.$sec.'">'.$sec."</option>\n";              $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
         }          }
Line 1886  sub course_level_dc { Line 1852  sub course_level_dc {
             ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course').'</b>';              ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Course').'</b>';
     my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu');      my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu');
     my %lt=&Apache::lonlocal::texthash(      my %lt=&Apache::lonlocal::texthash(
                     'typ' => "Type",  
                     'rol'  => "Role",                      'rol'  => "Role",
                     'grs'  => "Section",                      'grs'  => "Section",
                     'exs'  => "Existing sections",                      'exs'  => "Existing sections",
Line 1899  sub course_level_dc { Line 1864  sub course_level_dc {
     my $header = '<h4>'.&mt('Course Level').'</h4>'.      my $header = '<h4>'.&mt('Course Level').'</h4>'.
                  &Apache::loncommon::start_data_table().                   &Apache::loncommon::start_data_table().
                  &Apache::loncommon::start_data_table_header_row().                   &Apache::loncommon::start_data_table_header_row().
                  '<th>'.$lt{'typ'}.'</th><th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.                   '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
                  &Apache::loncommon::end_data_table_header_row();                   &Apache::loncommon::end_data_table_header_row();
     my $otheritems = &Apache::loncommon::start_data_table_row().      my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
                      '<td><select name="crstype" onChange="javascript:setType();">'."\n".  
                      ' <option value="">'.&mt('Please select')."\n".  
                      ' <option value="Course">'.&mt('Course')."\n".  
                      ' <option value="Non-standard course">'.&mt('Non-standard course')."\n".  
                      '</select>'."\n".  
                      '<td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".                       '<td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".
                      '<td><select name="role">'."\n";                       '<td><select name="role">'."\n";
     foreach  my $role ('st','ta','ep','in','cc') {      foreach  my $role ('st','ta','ep','in','cc') {

Removed from v.1.138  
changed lines
  Added in v.1.148


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