--- loncom/interface/domainprefs.pm 2007/12/11 00:44:23 1.33 +++ loncom/interface/domainprefs.pm 2008/01/16 20:42:48 1.41 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set domain-wide configuration settings # -# $Id: domainprefs.pm,v 1.33 2007/12/11 00:44:23 raeburn Exp $ +# $Id: domainprefs.pm,v 1.41 2008/01/16 20:42:48 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -127,8 +127,10 @@ sub handler { 'usercreation' => { text => 'User creation', help => 'Domain_User_Creation', - header => [{col1 => 'Setting', - col2 => 'Value',}, + header => [{col1 => 'Format Rule Type', + col2 => 'Format Rules in force'}, + {col1 => 'User account creation', + col2 => 'Usernames which may be created',}, {col1 => 'Context', col2 => 'Assignable Authentication Types'}], }, @@ -245,7 +247,7 @@ sub handler { my @ids=&Apache::lonnet::current_machine_ids(); if (!grep(/^\Q$primarylibserv\E$/,@ids)) { my %designhash = &Apache::loncommon::get_domainconf($dom); - my @loginimages = ('img','logo','domlogo'); + my @loginimages = ('img','logo','domlogo','login'); my $custom_img_count = 0; foreach my $img (@loginimages) { if ($designhash{$dom.'.login.'.$img} ne '') { @@ -279,11 +281,24 @@ sub handler { ' />  '. '

'); + ' />

'); + my ($numitems,$midpoint,$seconddiv,$count); + $numitems = @prefs_order; + $midpoint = int($numitems/2); + if ($numitems%2) { + $midpoint ++; + } + $count = 0; foreach my $item (@prefs_order) { - $r->print('

'); + $r->print('

'); + $count ++; + if ((!$seconddiv) && ($count >= $midpoint)) { + $r->print('
'."\n".'
'."\n"); + $seconddiv = 1; + } } - $r->print('

'.&mt('Display options').'

'."\n". + $r->print('

'. + &mt('Display options').'

'."\n". '

'.&mt('Display using: ')."\n". '  '. @@ -372,7 +387,18 @@ sub print_config_box { if ($action eq 'autoupdate') { $output .= &print_autoupdate('bottom',$dom,$settings,\$rowtotal); } elsif ($action eq 'usercreation') { - $output .= &print_usercreation('bottom',$dom,$settings,\$rowtotal); + $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).' + + + + + + + + + '. + &print_usercreation('bottom',$dom,$settings,\$rowtotal); + $rowtotal ++; } elsif ($action eq 'usermodification') { $output .= &print_usermodification('bottom',$dom,$settings,\$rowtotal); } else { @@ -542,10 +568,12 @@ sub print_footer { sub print_login { my ($dom,$confname,$phase,$settings,$rowtotal) = @_; my %choices = &login_choices(); - my ($catalogon,$catalogoff,$adminmailon,$adminmailoff); + my ($catalogon,$catalogoff,$adminmailon,$adminmailoff,$loginheader); $catalogon = ' checked="checked" '; $adminmailoff = ' checked="checked" '; - my @images = ('img','logo','domlogo'); + $loginheader = 'image'; + my @images = ('img','logo','domlogo','login'); + my @logintext = ('textcol','bgcol'); my @bgs = ('pgbg','mainbg','sidebg'); my @links = ('link','alink','vlink'); my %designhash = &Apache::loncommon::get_domainconf($dom); @@ -560,6 +588,9 @@ sub print_login { foreach my $item (@bgs) { $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item}; } + foreach my $item (@logintext) { + $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item}; + } foreach my $item (@links) { $defaults{'links'}{$item} = $defaultdesign{'login.'.$item}; } @@ -578,6 +609,15 @@ sub print_login { $is_custom{$item} = 1; } } + foreach my $item (@logintext) { + if ($settings->{$item} ne '') { + $designs{'logintext'}{$item} = $settings->{$item}; + $is_custom{$item} = 1; + } + } + if ($settings->{'loginheader'} ne '') { + $loginheader = $settings->{'loginheader'}; + } if ($settings->{'font'} ne '') { $designs{'font'} = $settings->{'font'}; $is_custom{'font'} = 1; @@ -620,7 +660,8 @@ sub print_login { } my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner', logo => 'Institution Logo', - domlogo => 'Domain Logo'); + domlogo => 'Domain Logo', + login => 'Login box'); my $itemcount = 1; my $css_class = $itemcount%2?' class="LC_odd_row"':''; my $datatable = @@ -641,7 +682,7 @@ sub print_login { ''; $itemcount ++; - $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal); + $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext,$loginheader); $datatable .= '
'.$item->{'header'}->[2]->{'col1'}.''.$item->{'header'}->[2]->{'col2'}.'
'; return $datatable; } @@ -654,6 +695,9 @@ sub login_choices { img => "Header", logo => "Main Logo", domlogo => "Domain Logo", + login => "Log-in Header", + textcol => "Text color", + bgcol => "Box color", bgs => "Background colors", links => "Link colors", font => "Font color", @@ -741,7 +785,7 @@ sub print_rolecolors { sub display_color_options { my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs, - $images,$bgs,$links,$alt_text,$rowtotal) = @_; + $images,$bgs,$links,$alt_text,$rowtotal,$logintext,$loginheader) = @_; my $css_class = $itemcount%2?' class="LC_odd_row"':''; my $datatable = ''. ''.$choices->{'font'}.''; @@ -763,13 +807,19 @@ sub display_color_options { $css_class = $itemcount%2?' class="LC_odd_row"':''; $datatable .= ''. ''.$choices->{$img}.''; - my ($imgfile, $img_import); + my ($imgfile,$img_import,$login_hdr_pick,$logincolors); if ($designs->{$img} ne '') { $imgfile = $designs->{$img}; $img_import = ($imgfile =~ m{^/adm/}); } else { $imgfile = $defaults->{$img}; } + if ($img eq 'login') { + $login_hdr_pick = &login_header_options($img,$role,$defaults,$is_custom,$choices, + $loginheader); + $logincolors = + &login_text_colors($img,$role,$logintext,$phase,$choices,$designs); + } if ($imgfile) { my ($showfile,$fullsize); if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) { @@ -810,25 +860,32 @@ sub display_color_options { } } if ($showfile) { - $showfile = &Apache::loncommon::lonhttpdurl($showfile); - $fullsize = &Apache::loncommon::lonhttpdurl($imgfile); - $datatable.= ''; - if (!$is_custom->{$img}) { - $datatable .= &mt('Default in use:').'
'; - } - if ($img_import) { - $datatable.= ''; - } - $datatable.= ''.$alt_text->{$img}.
-                             ''; - if ($is_custom->{$img}) { - $datatable.=' '.&mt('Replace:').'
'; - } else { - $datatable.=''.&mt('Upload:').'
'; + if ($showfile =~ m{^/(adm|res)/}) { + if ($showfile =~ m{^/res/}) { + my $local_showfile = + &Apache::lonnet::filelocation('',$showfile); + &Apache::lonnet::repcopy($local_showfile); + } + $showfile = &Apache::loncommon::lonhttpdurl($showfile); + } + if ($imgfile) { + if ($imgfile =~ m{^/(adm|res)/}) { + if ($imgfile =~ m{^/res/}) { + my $local_imgfile = + &Apache::lonnet::filelocation('',$imgfile); + &Apache::lonnet::repcopy($local_imgfile); + } + $fullsize = &Apache::loncommon::lonhttpdurl($imgfile); + } else { + $fullsize = $imgfile; + } } + $datatable .= ''; + if ($img eq 'login') { + $datatable .= $login_hdr_pick; + } + $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import, + $showfile,$fullsize,$role,$img,$imgfile,$logincolors); } else { $datatable .= '
'. &mt('Upload:'); @@ -868,7 +925,7 @@ sub display_color_options { $datatable .= '    '; } $datatable .= '
'; + '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" />'; } $datatable .= ''; $itemcount ++; @@ -902,6 +959,79 @@ sub display_color_options { return $datatable; } +sub login_header_options { + my ($img,$role,$defaults,$is_custom,$choices,$loginheader) = @_; + my $image_checked = ' checked="checked" '; + my $text_checked = ' '; + if ($loginheader eq 'text') { + $image_checked = ' '; + $text_checked = ' checked="checked" '; + } + my $output = '   '. + '
'."\n"; + if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) { + $output .= &mt('Text default(s)').':
'; + if (!$is_custom->{'textcol'}) { + $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}. + '   '; + } + if (!$is_custom->{'bgcol'}) { + $output .= $choices->{'bgcol'}.': '. + '   '; + } + $output .= '
'; + } + $output .='
'; + return $output; +} + +sub login_text_colors { + my ($img,$role,$logintext,$phase,$choices,$designs) = @_; + my $color_menu = ''; + foreach my $item (@{$logintext}) { + my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item}); + $color_menu .= ''. + ''; + } + $color_menu .= '
'.$link; + if ($designs->{'logintext'}{$item}) { + $color_menu .= '    '; + } + $color_menu .= '
 

'; + return $color_menu; +} + +sub image_changes { + my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_; + my $output; + if (!$is_custom) { + if ($img eq 'login') { + $output .= &mt('Default image:').'
'; + } else { + $output .= &mt('Default in use:').'
'; + } + } + if ($img_import) { + $output .= ''; + } + $output .= ''.$alt_text.''; + if ($is_custom) { + $output .= ''.$logincolors.' '.&mt('Replace:').'
'; + } else { + $output .= ''.$logincolors.&mt('Upload:').'
'; + } + return $output; +} + sub color_pick { my ($phase,$role,$item,$desc,$curcol) = @_; my $link = '{'sender_uname'}; + } my $datatable=''. ''.&mt('Auto-enrollment active?').''. '

'; } else { @@ -1767,6 +1992,7 @@ sub modify_rolecolors { $dom); if ($putresult eq 'ok') { if (keys(%changes) > 0) { + &Apache::loncommon::devalidate_domconfig_cache($dom); $resulttext = &display_colorchgs($dom,\%changes,$roles, $rolehash{'rolecolors'}); } else { @@ -1788,22 +2014,24 @@ sub modify_colors { my (%changes,%choices); my @bgs = ('pgbg','mainbg','sidebg'); my @links = ('link','alink','vlink'); + my @logintext; my @images; my $servadm = $r->dir_config('lonAdmEMail'); my $errors; foreach my $role (@{$roles}) { if ($role eq 'login') { %choices = &login_choices(); + @logintext = ('textcol','bgcol'); } else { %choices = &color_font_choices(); } if ($role eq 'login') { - @images = ('img','logo','domlogo'); + @images = ('img','logo','domlogo','login'); } else { @images = ('img'); } $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'}; - foreach my $item (@bgs,@links) { + foreach my $item (@bgs,@links,@logintext) { $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item}; } my ($configuserok,$author_ok,$switchserver,%currroles); @@ -1817,6 +2045,9 @@ sub modify_colors { } } my ($width,$height) = &thumb_dimensions(); + if (ref($domconfig->{$role}) ne 'HASH') { + $domconfig->{$role} = {}; + } foreach my $img (@images) { if ( ! $env{'form.'.$role.'_'.$img.'.filename'} && !defined($domconfig->{$role}{$img}) @@ -1924,20 +2155,31 @@ sub modify_colors { } } } + foreach my $item (@logintext) { + if ($domconfig->{$role}{$item} ne '') { + if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) { + $changes{$role}{'logintext'}{$item} = 1; + } + } else { + if ($confhash->{$role}{$item}) { + $changes{$role}{'logintext'}{$item} = 1; + } + } + } } else { &default_change_checker($role,\@images,\@links,\@bgs, - $confhash,\%changes); + \@logintext,$confhash,\%changes); } } else { &default_change_checker($role,\@images,\@links,\@bgs, - $confhash,\%changes); + \@logintext,$confhash,\%changes); } } return ($errors,%changes); } sub default_change_checker { - my ($role,$images,$links,$bgs,$confhash,$changes) = @_; + my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_; foreach my $item (@{$links}) { if ($confhash->{$role}{$item}) { $changes->{$role}{'links'}{$item} = 1; @@ -1948,6 +2190,11 @@ sub default_change_checker { $changes->{$role}{'bgs'}{$item} = 1; } } + foreach my $item (@{$logintext}) { + if ($confhash->{$role}{$item}) { + $changes->{$role}{'logintext'}{$item} = 1; + } + } foreach my $img (@{$images}) { if ($env{'form.'.$role.'_del_'.$img}) { $confhash->{$role}{$img} = ''; @@ -1962,7 +2209,6 @@ sub default_change_checker { sub display_colorchgs { my ($dom,$changes,$roles,$confhash) = @_; my (%choices,$resulttext); - &Apache::loncommon::devalidate_domconfig_cache($dom); if (!grep(/^login$/,@{$roles})) { $resulttext = &mt('Changes made:').'
'; } @@ -2820,7 +3066,7 @@ sub modify_contacts { } $resulttext .= ''; } else { - $resulttext = &mt('No changes made to contact information.'); + $resulttext = &mt('No changes made to contact information'); } } else { $resulttext = ''. @@ -2831,7 +3077,7 @@ sub modify_contacts { sub modify_usercreation { my ($dom,%domconfig) = @_; - my ($resulttext,%curr_usercreation,%changes,%authallowed); + my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate); if (ref($domconfig{'usercreation'}) eq 'HASH') { foreach my $key (keys(%{$domconfig{'usercreation'}})) { $curr_usercreation{$key} = $domconfig{'usercreation'}{$key}; @@ -2843,21 +3089,34 @@ sub modify_usercreation { ); my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule'); my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule'); - my @cancreate = &Apache::loncommon::get_env_multiple('form.can_createuser'); - if (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') { - foreach my $type (@{$curr_usercreation{'cancreate'}}) { - if (!grep(/^\Q$type\E$/,@cancreate)) { - push(@{$changes{'cancreate'}},$type); - } + my @contexts = ('author','course'); + foreach my $item(@contexts) { + $cancreate{$item} = $env{'form.can_createuser_'.$item}; + } + if (ref($curr_usercreation{'cancreate'}) eq 'HASH') { + foreach my $item (@contexts) { + if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) { + push(@{$changes{'cancreate'}},$item); + } } - foreach my $type (@cancreate) { - if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'cancreate'}})) { - push(@{$changes{'cancreate'}},$type); + } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') { + foreach my $item (@contexts) { + if (grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) { + if ($cancreate{$item} ne 'any') { + push(@{$changes{'cancreate'}},$item); + } + } else { + if ($cancreate{$item} ne 'none') { + push(@{$changes{'cancreate'}},$item); + } } } } else { - push(@{$changes{'cancreate'}},@cancreate); + foreach my $item ('author','course') { + push(@{$changes{'cancreate'}},$item); + } } + if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') { foreach my $type (@{$curr_usercreation{'username_rule'}}) { if (!grep(/^\Q$type\E$/,@username_rule)) { @@ -2920,7 +3179,7 @@ sub modify_usercreation { my %usercreation_hash = ( usercreation => { - cancreate => \@cancreate, + cancreate => \%cancreate, username_rule => \@username_rule, id_rule => \@id_rule, authtypes => \%authhash, @@ -2933,15 +3192,19 @@ sub modify_usercreation { if (keys(%changes) > 0) { $resulttext = &mt('Changes made:').'