--- loncom/interface/loncommon.pm 2007/09/07 19:51:41 1.580 +++ loncom/interface/loncommon.pm 2007/09/25 22:58:48 1.588 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.580 2007/09/07 19:51:41 raeburn Exp $ +# $Id: loncommon.pm,v 1.588 2007/09/25 22:58:48 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1094,30 +1094,58 @@ function init_geometry() { if (Geometry.init) { return }; Geometry.init=1; if (window.innerHeight) { - Geometry.getViewportHeight = function() { return window.innerHeight; }; + Geometry.getViewportHeight = function() { return window.innerHeight; }; + Geometry.getHorizontalScroll = function() { return window.pageXOffset; }; + Geometry.getVerticalScroll = function() { return window.pageYOffset; }; } else if (document.documentElement && document.documentElement.clientHeight) { Geometry.getViewportHeight = function() { return document.documentElement.clientHeight; }; + Geometry.getHorizontalScroll = + function() { return document.documentElement.scrollLeft; }; + Geometry.getVerticalScroll = + function() { return document.documentElement.scrollTop; }; } else if (document.body.clientHeight) { Geometry.getViewportHeight = function() { return document.body.clientHeight; }; + Geometry.getHorizontalScroll = + function() { return document.body.scrollLeft; }; + Geometry.getVerticalScroll = + function() { return document.body.scrollTop; }; } } +function getX(element) { + var x = 0; + while (element) { + x += element.offsetLeft; + element = element.offsetParent; + } + return x; +} +function getY(element) { + var y = 0; + while (element) { + y += element.offsetTop; + element = element.offsetParent; + } + return y; +} + + function resize_textarea(textarea_id,bottom_id) { init_geometry(); var textarea = document.getElementById(textarea_id); //alert(textarea); - var textarea_top = textarea.offsetTop; + var textarea_top = getY(textarea); var textarea_height = textarea.offsetHeight; var bottom = document.getElementById(bottom_id); - var bottom_top = bottom.offsetTop; + var bottom_top = getY(bottom); var bottom_height = bottom.offsetHeight; var window_height = Geometry.getViewportHeight(); - var fudge = 23; + var fudge = 23; var new_height = window_height-fudge-textarea_top-bottom_height; if (new_height < 300) { new_height = 300; @@ -1332,8 +1360,6 @@ sub domain_select { =over 4 -=cut - =item * multiple_select_form($name,$value,$size,$hash,$order) Returns a string containing a form input. See loncreateuser.pm for an example. +input: 4 arguments (two required, two optional) - + $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) + form item if there are multiple library servers in $domain, or + (ii) an 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 #------------------------------------------- -sub home_server_option_list { - my $domain = shift; +sub home_server_form_item { + my ($domain,$name,$default,$hide) = @_; my %servers = &Apache::lonnet::get_servers($domain,'library'); - my $result = ''; - foreach my $hostid (sort(keys(%servers))) { - $result.= - '\n"; + my $result; + my $numlib = keys(%servers); + if ($numlib > 1) { + $result .= ''."\n"; + } elsif ($numlib == 1) { + my $hostid; + foreach my $item (keys(%servers)) { + $hostid = $item; + } + $result .= ''; + if (!$hide) { + $result .= $hostid.' '.$servers{$hostid}; + } + $result .= "\n"; + } elsif ($default) { + $result .= ''; + if (!$hide) { + $result .= &mt('default'); + } + $result .= "\n"; } - return $result; + return ($result,$numlib); } =pod @@ -1776,11 +1846,17 @@ sub authform_nochange{ kerb_def_dom => 'MSU.EDU', @_, ); - my $result = ''; + } return $result; } @@ -1791,64 +1867,148 @@ sub authform_kerberos{ 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') { - $check5 = " checked=\"on\""; + $check5 = ' checked="on"'; } else { - $check4 = " checked=\"on\""; + $check4 = ' checked="on"'; } $krbarg = $in{'kerb_def_dom'}; - - my $krbcheck = ""; - if ( grep/^curr_authtype$/,(keys %in) ) { - if ($in{'curr_authtype'} =~ m/^krb/) { - $krbcheck = " checked=\"on\""; - if ( grep/^curr_autharg$/,(keys %in) ) { + if (grep(/^curr_authtype$/,(keys(%in)))) { + if ($in{'curr_authtype'} =~ m/^krb(\d+)$/) { + $krbver = $1; + $krbcheck = ' checked="on"'; + if ($krbver eq '5') { + $check5 = ' checked="on"'; + $check4 = ''; + } else { + $check4 = ' checked="on"'; + $check5 = ''; + } + if (grep(/^curr_autharg$/,(keys(%in)))) { $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 = ''; } } - - my $jscall = "javascript:changed_radio('krb',$in{'formname'});"; - my $result .= &mt + if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) { + return; + } elsif ($authtype eq '') { + if (grep(/^mode$/,(keys(%in)))) { + if ($in{'mode'} eq 'modifycourse') { + if ($authnum == 1) { + $authtype = ''; + } + } + } + } + $jscall = "javascript:changed_radio('krb',$in{'formname'});"; + if ($authtype eq '') { + $authtype = ''; + } + 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] '. '[_3] Version 4 [_4] Version 5 [_5]', - '