Diff for /loncom/interface/loncommon.pm between versions 1.585 and 1.586

version 1.585, 2007/09/12 23:32:59 version 1.586, 2007/09/19 06:24:26
Line 1511  sub select_dom_form { Line 1511  sub select_dom_form {
   
 =pod  =pod
   
 =item * home_server_option_list($domain)  =item * home_server_form_item($domain,$name,$defaultflag)
   
 returns a string which contains an <option> list to be used in a   input: 4 arguments (two required, two optional) - 
 <select> form input.  See loncreateuser.pm for an example.      $domain - domain of new user
       $name - name of form element
       $default - Value of 'default' causes a default item to be first 
                               option, and selected by default. 
       $hide - Value of 'hide' causes hiding of the name of the server, 
                               if 1 server found, or default, if 0 found.
   output: returns 1 items: 
   (a) form element which contains either:
      (i) <select name="$name">
           <option value="$hostid1">$hostid $servers{$hostid}</option>
           <option value="$hostid2">$hostid $servers{$hostid}</option>       
          </select>
          form item if there are multiple library servers in $domain, or
      (ii) an <input type="hidden" name="$name" value="$hostid" /> form item 
          if there is only one library server in $domain.
   
   (b) number of library servers found.
   
   See loncreateuser.pm for example of use.
   
 =cut  =cut
   
 #-------------------------------------------  #-------------------------------------------
 sub home_server_option_list {  sub home_server_form_item {
     my $domain = shift;      my ($domain,$name,$default,$hide) = @_;
     my %servers = &Apache::lonnet::get_servers($domain,'library');      my %servers = &Apache::lonnet::get_servers($domain,'library');
     my $result = '';      my $result;
     foreach my $hostid (sort(keys(%servers))) {      my $numlib = keys(%servers);
         $result.=      if ($numlib > 1) {
             '<option value="'.$hostid.'">'.          $result .= '<select name="'.$name.'" />'."\n";
     $hostid.' '.$servers{$hostid}."</option>\n";          if ($default) {
               $result .= '<option value="default" selected>'.&mt('default').
                          '</option>'."\n";
           }
           foreach my $hostid (sort(keys(%servers))) {
               $result.= '<option value="'.$hostid.'">'.
                 $hostid.' '.$servers{$hostid}."</option>\n";
           }
           $result .= '</select>'."\n";
       } elsif ($numlib == 1) {
           my $hostid;
           foreach my $item (keys(%servers)) {
               $hostid = $item;
           }
           $result .= '<input type="hidden" name="'.$name.'" value="'.
                      $hostid.'" />';
                      if (!$hide) {
                          $result .= $hostid.' '.$servers{$hostid};
                      }
                      $result .= "\n";
       } elsif ($default) {
           $result .= '<input type="hidden" name="'.$name.
                      '" value="default" />';
                      if (!$hide) {
                          $result .= &mt('default');
                      }
                      $result .= "\n";
     }      }
     return $result;      return ($result,$numlib);
 }  }
   
 =pod  =pod
Line 1776  sub authform_nochange{ Line 1820  sub authform_nochange{
               kerb_def_dom => 'MSU.EDU',                kerb_def_dom => 'MSU.EDU',
               @_,                @_,
           );            );
     my $result = '<label>'.&mt('[_1] Do not change login data',      my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'}); 
                      '<input type="radio" name="login" value="nochange" '.      my $result;
                      'checked="checked" onclick="'.      if (keys(%can_assign) == 0) {
           $result = &mt('Under you current role you are not permitted to change login settings for this user');  
       } else {
           $result = '<label>'.&mt('[_1] Do not change login data',
                     '<input type="radio" name="login" value="nochange" '.
                     'checked="checked" onclick="'.
             "javascript:changed_radio('nochange',$in{'formname'});".'" />').              "javascript:changed_radio('nochange',$in{'formname'});".'" />').
     '</label>';      '</label>';
       }
     return $result;      return $result;
 }  }
   
Line 1791  sub authform_kerberos{ Line 1841  sub authform_kerberos{
               kerb_def_auth => 'krb4',                kerb_def_auth => 'krb4',
               @_,                @_,
               );                );
     my ($check4,$check5,$krbarg);      my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
           $autharg,$jscall);
       my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
     if ($in{'kerb_def_auth'} eq 'krb5') {      if ($in{'kerb_def_auth'} eq 'krb5') {
        $check5 = " checked=\"on\"";         $check5 = ' checked="on"';
     } else {      } else {
        $check4 = " checked=\"on\"";         $check4 = ' checked="on"';
     }      }
     $krbarg = $in{'kerb_def_dom'};      $krbarg = $in{'kerb_def_dom'};
       if (grep(/^curr_authtype$/,(keys(%in)))) {
     my $krbcheck = "";          if ($in{'curr_authtype'} =~ m/^krb(\d+)$/) {
     if ( grep/^curr_authtype$/,(keys %in) ) {              $krbver = $1;
         if ($in{'curr_authtype'} =~ m/^krb/) {              $krbcheck = ' checked="on"';
             $krbcheck = " checked=\"on\"";              if ($krbver eq '5') {
             if ( grep/^curr_autharg$/,(keys %in) ) {                  $check5 = ' checked="on"';
                   $check4 = '';
               } else {
                   $check4 = ' checked="on"';
                   $check5 = '';
               }
               if (grep(/^curr_autharg$/,(keys(%in)))) {
                 $krbarg = $in{'curr_autharg'};                  $krbarg = $in{'curr_autharg'};
             }              }
               if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
                   if (grep(/^curr_autharg$/,(keys(%in)))) {
                       $result = 
       &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
           $in{'curr_autharg'},$krbver);
                   } else {
                       $result =
       &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
                   }
                   return $result; 
               }
           }
       } else {
           if ($authnum == 1) {
               $authtype = '<input type="hidden" name="login" value="krb">';
         }          }
     }      }
       if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
     my $jscall = "javascript:changed_radio('krb',$in{'formname'});";          return;
     my $result .= &mt      }
       $jscall = "javascript:changed_radio('krb',$in{'formname'});";
       if ($authtype eq '') {
           $authtype = '<input type="radio" name="login" value="krb" '.
                       'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
                       $krbcheck.' />';
       }
       if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
           ($can_assign{'krb4'} && !$can_assign{'krb5'} && 
            $in{'curr_authtype'} eq 'krb5') ||
           (!$can_assign{'krb4'} && $can_assign{'krb5'} && 
            $in{'curr_authtype'} eq 'krb4')) {
           $result .= &mt
         ('[_1] Kerberos authenticated with domain [_2] '.          ('[_1] Kerberos authenticated with domain [_2] '.
          '[_3] Version 4 [_4] Version 5 [_5]',           '[_3] Version 4 [_4] Version 5 [_5]',
          '<label><input type="radio" name="login" value="krb" '.           '<label>'.$authtype,
              'onclick="'.$jscall.'" onchange="'.$jscall.'"'.$krbcheck.' />',  
          '</label><input type="text" size="10" name="krbarg" '.           '</label><input type="text" size="10" name="krbarg" '.
              'value="'.$krbarg.'" '.               'value="'.$krbarg.'" '.
              'onchange="'.$jscall.'" />',               'onchange="'.$jscall.'" />',
          '<label><input type="radio" name="krbver" value="4" '.$check4.' />',           '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
          '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',           '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
  '</label>');   '</label>');
       } elsif ($can_assign{'krb4'}) {
           $result .= &mt
           ('[_1] Kerberos authenticated with domain [_2] '.
            '[_3] Version 4 [_4]',
            '<label>'.$authtype,
            '</label><input type="text" size="10" name="krbarg" '.
                'value="'.$krbarg.'" '.
                'onchange="'.$jscall.'" />',
            '<label><input type="hidden" name="krbver" value="4" />',
            '</label>');
       } elsif ($can_assign{'krb5'}) {
           $result .= &mt
           ('[_1] Kerberos authenticated with domain [_2] '.
            '[_3] Version 5 [_4]',
            '<label>'.$authtype,
            '</label><input type="text" size="10" name="krbarg" '.
                'value="'.$krbarg.'" '.
                'onchange="'.$jscall.'" />',
            '<label><input type="hidden" name="krbver" value="5" />',
            '</label>');
       }
     return $result;      return $result;
 }  }
   
 sub authform_internal{    sub authform_internal{  
     my %args = (      my %in = (
                 formname => 'document.cu',                  formname => 'document.cu',
                 kerb_def_dom => 'MSU.EDU',                  kerb_def_dom => 'MSU.EDU',
                 @_,                  @_,
                 );                  );
       my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
     my $intcheck = "";      my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
     my $intarg = 'value=""';      if (grep(/^curr_authtype$/,(keys(%in)))) {
     if ( grep/^curr_authtype$/,(keys %args) ) {          if ($in{'curr_authtype'} eq 'internal:') {
         if ($args{'curr_authtype'} eq 'int') {              if ($can_assign{'int'}) {
             $intcheck = " checked=\"on\"";                  $intcheck = 'checked="on" ';
             if ( grep/^curr_autharg$/,(keys %args) ) {                  if (grep(/^curr_autharg$/,(keys(%in)))) {
                 $intarg = "value=\"$args{'curr_autharg'}\"";                      $intarg = $in{'curr_autharg'};
                   }
               } else {
                   $result = &mt('Currently internally authenticated.');
                   return $result;
             }              }
         }          }
       } else {
           if ($authnum == 1) {
               $authtype = '<input type="hidden" name="login" value="int">';
           }
     }      }
       if (!$can_assign{'int'}) {
     my $jscall = "javascript:changed_radio('int',$args{'formname'});";          return;
     my $result.=&mt      }
       $jscall = "javascript:changed_radio('int',$in{'formname'});";
       if ($authtype eq '') {
           $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
                       ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
       }
       $autharg = '<input type="text" size="10" name="intarg" value="'.
                  $intarg.'" onchange="'.$jscall.'" />';
       $result = &mt
         ('[_1] Internally authenticated (with initial password [_2])',          ('[_1] Internally authenticated (with initial password [_2])',
          '<label><input type="radio" name="login" value="int" '.$intcheck.           '<label>'.$authtype,'</label>'.$autharg);
              ' onchange="'.$jscall.'" onclick="'.$jscall.'" />',  
          '</label><input type="text" size="10" name="intarg" '.$intarg.  
              ' onchange="'.$jscall.'" />');  
     return $result;      return $result;
 }  }
   
Line 1858  sub authform_local{ Line 1976  sub authform_local{
               kerb_def_dom => 'MSU.EDU',                kerb_def_dom => 'MSU.EDU',
               @_,                @_,
               );                );
       my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
     my $loccheck = "";      my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
     my $locarg = 'value=""';      if (grep(/^curr_authtype$/,(keys(%in)))) {
     if ( grep/^curr_authtype$/,(keys %in) ) {          if ($in{'curr_authtype'} eq 'localauth:') {
         if ($in{'curr_authtype'} eq 'loc') {              if ($can_assign{'loc'}) {
             $loccheck = " checked=\"on\"";                  $loccheck = 'checked="on" ';
             if ( grep/^curr_autharg$/,(keys %in) ) {                  if (grep(/^curr_autharg$/,(keys(%in)))) {
                 $locarg = "value=\"$in{'curr_autharg'}\"";                      $locarg = $in{'curr_autharg'};
                   }
               } else {
                   $result = &mt('Currently using local (institutional) authentication.');
                   return $result;
             }              }
         }          }
       } else {
           if ($authnum == 1) {
               $authtype = '<input type="hidden" name="login" value="loc">';
           }
     }      }
       if (!$can_assign{'loc'}) {
     my $jscall = "javascript:changed_radio('loc',$in{'formname'});";          return;
     my $result.=&mt('[_1] Local Authentication with argument [_2]',      }
                     '<label><input type="radio" name="login" value="loc" '.$loccheck.      $jscall = "javascript:changed_radio('loc',$in{'formname'});";
                         ' onchange="'.$jscall.'" onclick="'.$jscall.'" />',      if ($authtype eq '') {
                     '</label><input type="text" size="10" name="locarg" '.$locarg.          $authtype = '<input type="radio" name="login" value="loc" '.
                         ' onchange="'.$jscall.'" />');                      $loccheck.' onchange="'.$jscall.'" onclick="'.
                       $jscall.'" />';
       }
       $autharg = '<input type="text" size="10" name="locarg" value="'.
                  $locarg.'" onchange="'.$jscall.'" />';
       $result = &mt('[_1] Local Authentication with argument [_2]',
                     '<label>'.$authtype,'</label>'.$autharg);
     return $result;      return $result;
 }  }
   
Line 1885  sub authform_filesystem{ Line 2017  sub authform_filesystem{
               kerb_def_dom => 'MSU.EDU',                kerb_def_dom => 'MSU.EDU',
               @_,                @_,
               );                );
     my $jscall = "javascript:changed_radio('fsys',$in{'formname'});";      my ($fsyscheck,$result,$authtype,$autharg,$jscall);
     my $result.= &mt      my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
       if (grep(/^curr_authtype$/,(keys(%in)))) {
           if ($in{'curr_authtype'} eq 'unix:') {
               if ($can_assign{'fsys'}) {
                   $fsyscheck = 'checked="on" ';
               } else {
                   $result = &mt('Currently Filesystem Authenticated.');
                   return $result;
               }           
           }
       } else {
           if ($authnum == 1) {
               $authtype = '<input type="hidden" name="login" value="fsys">';
           }
       }
       if (!$can_assign{'fsys'}) {
           return;
       }
       $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
       if ($authtype eq '') {
           $authtype = '<input type="radio" name="login" value="fsys" '.
                       $fsyscheck.' onchange="'.$jscall.'" onclick="'.
                       $jscall.'" />';
       }
       $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
                  ' onchange="'.$jscall.'" />';
       $result = &mt
         ('[_1] Filesystem Authenticated (with initial password [_2])',          ('[_1] Filesystem Authenticated (with initial password [_2])',
          '<label><input type="radio" name="login" value="fsys" '.           '<label><input type="radio" name="login" value="fsys" '.
          'onchange="'.$jscall.'" onclick="'.$jscall.'" />',           $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
          '</label><input type="text" size="10" name="fsysarg" value="" '.           '</label><input type="text" size="10" name="fsysarg" value="" '.
                   'onchange="'.$jscall.'" />');                    'onchange="'.$jscall.'" />');
     return $result;      return $result;
 }  }
   
   sub get_assignable_auth {
       my ($dom) = @_;
       if ($dom eq '') {
           $dom = $env{'request.role.domain'};
       }
       my %can_assign = (
                             krb4 => 1,
                             krb5 => 1,
                             int  => 1,
                             loc  => 1,
                        );
       my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
       if (ref($domconfig{'usercreation'}) eq 'HASH') {
           if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
               my $authhash = $domconfig{'usercreation'}{'authtypes'};
               my $context;
               if ($env{'request.role'} =~ /^au/) {
                   $context = 'author';
               } elsif ($env{'request.role'} =~ /^dc/) {
                   $context = 'domain';
               } elsif ($env{'request.course.id'}) {
                   $context = 'course';
               }
               if ($context) {
                   if (ref($authhash->{$context}) eq 'HASH') {
                      %can_assign = %{$authhash->{$context}}; 
                   }
               }
           }
       }
       my $authnum = 0;
       foreach my $key (keys(%can_assign)) {
           if ($can_assign{$key}) {
               $authnum ++;
           }
       }
       if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
           $authnum --;
       }
       return ($authnum,%can_assign);
   }
   
   
 ###############################################################  ###############################################################
 ##    Get Authentication Defaults for Domain                 ##  ##    Get Authentication Defaults for Domain                 ##
 ###############################################################  ###############################################################
Line 2020  sub initialize_keywords { Line 2221  sub initialize_keywords {
     # Remove special values from %Keywords.      # Remove special values from %Keywords.
     foreach my $value ('total.count','average.count') {      foreach my $value ('total.count','average.count') {
         delete($Keywords{$value}) if (exists($Keywords{$value}));          delete($Keywords{$value}) if (exists($Keywords{$value}));
     }    }
     return 1;      return 1;
 }  }
   

Removed from v.1.585  
changed lines
  Added in v.1.586


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