[LON-CAPA-cvs] cvs: loncom /interface domainprefs.pm
raeburn
lon-capa-cvs-allow@mail.lon-capa.org
Fri, 15 Feb 2008 17:02:33 -0000
raeburn Fri Feb 15 12:02:33 2008 EDT
Modified files:
/loncom/interface domainprefs.pm
Log:
Eliminate code duplication for login screen settings with radio button type selections.
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.41 loncom/interface/domainprefs.pm:1.42
--- loncom/interface/domainprefs.pm:1.41 Wed Jan 16 15:42:48 2008
+++ loncom/interface/domainprefs.pm Fri Feb 15 12:02:31 2008
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set domain-wide configuration settings
#
-# $Id: domainprefs.pm,v 1.41 2008/01/16 20:42:48 raeburn Exp $
+# $Id: domainprefs.pm,v 1.42 2008/02/15 17:02:31 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -568,10 +568,22 @@
sub print_login {
my ($dom,$confname,$phase,$settings,$rowtotal) = @_;
my %choices = &login_choices();
- my ($catalogon,$catalogoff,$adminmailon,$adminmailoff,$loginheader);
- $catalogon = ' checked="checked" ';
- $adminmailoff = ' checked="checked" ';
- $loginheader = 'image';
+ my %defaultchecked = (
+ 'coursecatalog' => 'on',
+ 'adminmail' => 'off',
+ );
+ my @toggles = ('coursecatalog','adminmail');
+ my (%checkedon,%checkedoff);
+ foreach my $item (@toggles) {
+ if ($defaultchecked{$item} eq 'on') {
+ $checkedon{$item} = ' checked="checked" ';
+ $checkedoff{$item} = ' ';
+ } elsif ($defaultchecked{$item} eq 'off') {
+ $checkedoff{$item} = ' checked="checked" ';
+ $checkedon{$item} = ' ';
+ }
+ }
+ my $loginheader = 'image';
my @images = ('img','logo','domlogo','login');
my @logintext = ('textcol','bgcol');
my @bgs = ('pgbg','mainbg','sidebg');
@@ -595,13 +607,14 @@
$defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
}
if (ref($settings) eq 'HASH') {
- if ($settings->{'coursecatalog'} eq '0') {
- $catalogoff = $catalogon;
- $catalogon = ' ';
- }
- if ($settings->{'adminmail'} eq '1') {
- $adminmailon = $adminmailoff;
- $adminmailoff = ' ';
+ foreach my $item (@toggles) {
+ if ($settings->{$item} eq '1') {
+ $checkedon{$item} = ' checked="checked" ';
+ $checkedoff{$item} = ' ';
+ } elsif ($settings->{$item} eq '0') {
+ $checkedoff{$item} = ' checked="checked" ';
+ $checkedon{$item} = ' ';
+ }
}
foreach my $item (@images) {
if ($settings->{$item} ne '') {
@@ -663,25 +676,19 @@
domlogo => 'Domain Logo',
login => 'Login box');
my $itemcount = 1;
- my $css_class = $itemcount%2?' class="LC_odd_row"':'';
- my $datatable =
- '<tr'.$css_class.'><td colspan="2">'.$choices{'coursecatalog'}.
- '</td><td>'.
- '<span class="LC_nobreak"><label><input type="radio" name="coursecatalog"'.
- $catalogon.' value="1" />'.&mt('Yes').'</label> '.
- '<label><input type="radio" name="coursecatalog"'.
- $catalogoff.'value="0" />'.&mt('No').'</label></span></td>'.
- '</tr>';
- $itemcount ++;
- $css_class = $itemcount%2?' class="LC_odd_row"':'';
- $datatable .= '<tr'.$css_class.'>'.
- '<td colspan="2">'.$choices{'adminmail'}.'</td>'.
- '<td><span class="LC_nobreak">'.
- '<label><input type="radio" name="adminmail"'.
- $adminmailon.' value="1" />'.&mt('Yes').'</label> '.
- '<label><input type="radio" name="adminmail"'.
- $adminmailoff.'value="0" />'.&mt('No').'</label></span></td></tr>';
- $itemcount ++;
+ my ($css_class,$datatable);
+ foreach my $item (@toggles) {
+ $css_class = $itemcount%2?' class="LC_odd_row"':'';
+ $datatable .=
+ '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
+ '</td><td>'.
+ '<span class="LC_nobreak"><label><input type="radio" name="'.
+ $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
+ '</label> <label><input type="radio" name="'.$item.'"'.
+ $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
+ '</tr>';
+ $itemcount ++;
+ }
$datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext,$loginheader);
$datatable .= '</tr></table></td></tr>';
return $datatable;
@@ -1906,8 +1913,10 @@
my %loginhash;
($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
\%domconfig,\%loginhash);
- $loginhash{login}{coursecatalog} = $env{'form.coursecatalog'};
- $loginhash{login}{adminmail} = $env{'form.adminmail'};
+ my @toggles = ('coursecatalog','adminmail');
+ foreach my $item (@toggles) {
+ $loginhash{login}{$item} = $env{'form.'.$item};
+ }
$loginhash{login}{loginheader} = $env{'form.loginheader'};
if (ref($colchanges{'login'}) eq 'HASH') {
$colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
@@ -1916,21 +1925,31 @@
my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
$dom);
if ($putresult eq 'ok') {
- if (($domconfig{'login'}{'coursecatalog'} eq '0') &&
- ($env{'form.coursecatalog'} eq '1')) {
- $changes{'coursecatalog'} = 1;
- } elsif (($domconfig{'login'}{'coursecatalog'} eq '' ||
- $domconfig{'login'}{'coursecatalog'} eq '1') &&
- ($env{'form.coursecatalog'} eq '0')) {
- $changes{'coursecatalog'} = 1;
- }
- if (($domconfig{'login'}{'adminmail'} eq '1') &&
- ($env{'form.adminmail'} eq '0')) {
- $changes{'adminmail'} = 1;
- } elsif (($domconfig{'login'}{'adminmail'} eq '' ||
- $domconfig{'login'}{'adminmail'} eq '0') &&
- ($env{'form.adminmail'} eq '1')) {
- $changes{'adminmail'} = 1;
+ my @toggles = ('coursecatalog','adminmail');
+ my %defaultchecked = (
+ 'coursecatalog' => 'on',
+ 'adminmail' => 'off',
+ );
+ foreach my $item (@toggles) {
+ if ($defaultchecked{$item} eq 'on') {
+ if (($domconfig{'login'}{$item} eq '0') &&
+ ($env{'form.'.$item} eq '1')) {
+ $changes{$item} = 1;
+ } elsif (($domconfig{'login'}{$item} eq '' ||
+ $domconfig{'login'}{$item} eq '1') &&
+ ($env{'form.'.$item} eq '0')) {
+ $changes{$item} = 1;
+ }
+ } elsif ($defaultchecked{$item} eq 'off') {
+ if (($domconfig{'login'}{$item} eq '1') &&
+ ($env{'form.'.$item} eq '0')) {
+ $changes{$item} = 1;
+ } elsif (($domconfig{'login'}{$item} eq '' ||
+ $domconfig{'login'}{$item} eq '0') &&
+ ($env{'form.'.$item} eq '1')) {
+ $changes{$item} = 1;
+ }
+ }
}
if (($domconfig{'login'}{'loginheader'} eq 'text') &&
($env{'form.loginheader'} eq 'image')) {