[LON-CAPA-cvs] cvs: loncom /interface domainprefs.pm
raeburn
raeburn at source.lon-capa.org
Mon Feb 25 12:43:42 EST 2013
raeburn Mon Feb 25 17:43:42 2013 EDT
Modified files:
/loncom/interface domainprefs.pm
Log:
- Make &active_dc_picker() more generic so it can be used to generate a table
of active Domain Coordinators either as radio button items (pick 1 of N),
or as checkboxes (pick M of N).
- Eliminate some code by including start and end args in call to
lonnet::get_domain_roles in &get_active_dcs()
- Eliminate duplicate code in &print_requestmail() with &print_requestmail()
call.
-------------- next part --------------
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.190 loncom/interface/domainprefs.pm:1.191
--- loncom/interface/domainprefs.pm:1.190 Sat Feb 2 02:48:47 2013
+++ loncom/interface/domainprefs.pm Mon Feb 25 17:43:41 2013
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set domain-wide configuration settings
#
-# $Id: domainprefs.pm,v 1.190 2013/02/02 02:48:47 raeburn Exp $
+# $Id: domainprefs.pm,v 1.191 2013/02/25 17:43:41 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1926,35 +1926,16 @@
sub print_requestmail {
my ($dom,$action,$settings,$rowtotal) = @_;
- my ($now,$datatable,%dompersonnel, at domcoord, at currapproval,$rows);
+ my ($now,$datatable,%currapp,$rows);
$now = time;
- $rows = 0;
- %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
- foreach my $server (keys(%dompersonnel)) {
- foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
- my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
- if (!grep(/^$uname:$udom$/, at domcoord)) {
- push(@domcoord,$uname.':'.$udom);
- }
- }
- }
if (ref($settings) eq 'HASH') {
if (ref($settings->{'notify'}) eq 'HASH') {
if ($settings->{'notify'}{'approval'} ne '') {
- @currapproval = split(',',$settings->{'notify'}{'approval'});
- }
- }
- }
- if (@currapproval) {
- foreach my $dc (@currapproval) {
- unless (grep(/^\Q$dc\E$/, at domcoord)) {
- push(@domcoord,$dc);
+ map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
}
}
}
- @domcoord = sort(@domcoord);
- my $numinrow = 4;
- my $numdc = @domcoord;
+ my $numinrow = 2;
my $css_class = 'class="LC_odd_row"';
my $text;
if ($action eq 'requestcourses') {
@@ -1965,42 +1946,12 @@
$datatable = '<tr '.$css_class.'>'.
' <td>'.$text.'</td>'.
' <td class="LC_left_item">';
- if (@domcoord > 0) {
- $datatable .= '<table>';
- for (my $i=0; $i<$numdc; $i++) {
- my $rem = $i%($numinrow);
- if ($rem == 0) {
- if ($i > 0) {
- $datatable .= '</tr>';
- }
- $datatable .= '<tr>';
- $rows ++;
- }
- my $check = ' ';
- if (grep(/^\Q$domcoord[$i]\E$/, at currapproval)) {
- $check = ' checked="checked" ';
- }
- my ($uname,$udom) = split(':',$domcoord[$i]);
- my $fullname = &Apache::loncommon::plainname($uname,$udom);
- if ($i == $numdc-1) {
- my $colsleft = $numinrow-$rem;
- if ($colsleft > 1) {
- $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
- } else {
- $datatable .= '<td class="LC_left_item">';
- }
- } else {
- $datatable .= '<td class="LC_left_item">';
- }
- $datatable .= '<span class="LC_nobreak"><label>'.
- '<input type="checkbox" name="reqapprovalnotify" '.
- 'value="'.$domcoord[$i].'"'.$check.'/>'.
- $fullname.' ('.$uname.':'.$udom.')</label></span></td>';
- }
- $datatable .= '</tr></table>';
+ my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
+ 'reqapprovalnotify',%currapp);
+ if ($numdc > 0) {
+ $datatable .= $table;
} else {
$datatable .= &mt('There are no active Domain Coordinators');
- $rows ++;
}
$datatable .='</td></tr>';
$$rowtotal += $rows;
@@ -2155,8 +2106,7 @@
sub print_autocreate {
my ($dom,$settings,$rowtotal) = @_;
- my (%createon,%createoff);
- my $curr_dc;
+ my (%createon,%createoff,%currhash);
my @types = ('xml','req');
if (ref($settings) eq 'HASH') {
foreach my $item (@types) {
@@ -2169,7 +2119,9 @@
}
}
}
- $curr_dc = $settings->{'xmldc'};
+ if ($settings->{'xmldc'} ne '') {
+ $currhash{$settings->{'xmldc'}} = 1;
+ }
} else {
foreach my $item (@types) {
$createoff{$item} = ' checked="checked" ';
@@ -2177,6 +2129,7 @@
}
}
$$rowtotal += 2;
+ my $numinrow = 2;
my $datatable='<tr class="LC_odd_row">'.
'<td>'.&mt('Create pending official courses from XML files').'</td>'.
'<td class="LC_right_item"><span class="LC_nobreak"><label>'.
@@ -2191,15 +2144,16 @@
$createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
'<label><input type="radio" name="autocreate_req"'.
$createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
- my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
+ my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
+ 'autocreate_xmldc',%currhash);
if ($numdc > 1) {
$datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
&mt('Course creation processed as: (choose Dom. Coord.)').
'</td><td class="LC_left_item">'.$dctable.'</td></tr>';
- $$rowtotal ++ ;
} else {
$datatable .= $dctable.'</td></tr>';
}
+ $$rowtotal += $rows;
return $datatable;
}
@@ -8444,73 +8398,95 @@
sub get_active_dcs {
my ($dom) = @_;
- my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
+ my $now = time;
+ my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
my %domcoords;
my $numdcs = 0;
my $now = time;
foreach my $server (keys(%dompersonnel)) {
foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
- my ($end,$start) = split(':',$dompersonnel{$server}{$user});
- if (($end eq '') || ($end == 0) || ($end > $now)) {
- if ($start <= $now) {
- $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
- }
- }
+ $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
}
}
return %domcoords;
}
sub active_dc_picker {
- my ($dom,$curr_dc) = @_;
+ my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
my %domcoords = &get_active_dcs($dom);
- my @dcs = sort(keys(%domcoords));
- my $numdcs = scalar(@dcs);
- my $datatable;
- my $numinrow = 2;
+ my @domcoord = keys(%domcoords);
+ if (keys(%currhash)) {
+ foreach my $dc (keys(%currhash)) {
+ unless (exists($domcoords{$dc})) {
+ push(@domcoord,$dc);
+ }
+ }
+ }
+ @domcoord = sort(@domcoord);
+ my $numdcs = scalar(@domcoord);
+ my $rows = 0;
+ my $table;
if ($numdcs > 1) {
- $datatable = '<table>';
- for (my $i=0; $i<@dcs; $i++) {
+ $table = '<table>';
+ for (my $i=0; $i<@domcoord; $i++) {
my $rem = $i%($numinrow);
if ($rem == 0) {
if ($i > 0) {
- $datatable .= '</tr>';
+ $table .= '</tr>';
}
- $datatable .= '<tr>';
+ $table .= '<tr>';
+ $rows ++;
}
- my $check = ' ';
- if ($curr_dc eq '') {
- if (!$i) {
- $check = ' checked="checked" ';
+ my $check = '';
+ if ($inputtype eq 'radio') {
+ if (keys(%currhash) == 0) {
+ if (!$i) {
+ $check = ' checked="checked"';
+ }
+ } elsif (exists($currhash{$domcoord[$i]})) {
+ $check = ' checked="checked"';
+ }
+ } else {
+ if (exists($currhash{$domcoord[$i]})) {
+ $check = ' checked="checked"';
}
- } elsif ($dcs[$i] eq $curr_dc) {
- $check = ' checked="checked" ';
}
- if ($i == @dcs - 1) {
+ if ($i == @domcoord - 1) {
my $colsleft = $numinrow - $rem;
if ($colsleft > 1) {
- $datatable .= '<td colspan="'.$colsleft.'">';
+ $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
} else {
- $datatable .= '<td>';
+ $table .= '<td class="LC_left_item">';
}
} else {
- $datatable .= '<td>';
+ $table .= '<td class="LC_left_item">';
+ }
+ my ($dcname,$dcdom) = split(':',$domcoord[$i]);
+ my $user = &Apache::loncommon::plainname($dcname,$dcdom);
+ $table .= '<span class="LC_nobreak"><label>'.
+ '<input type="'.$inputtype.'" name="'.$name.'"'.
+ ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
+ if ($user ne $dcname.':'.$dcdom) {
+ $table .= ' ('.$dcname.':'.$dcdom.')'.
+ '</label></span></td>';
}
- my ($dcname,$dcdom) = split(':',$dcs[$i]);
- $datatable .= '<span class="LC_nobreak"><label>'.
- '<input type="radio" name="autocreate_xmldc"'.
- ' value="'.$dcs[$i].'"'.$check.'/>'.
- &Apache::loncommon::plainname($dcname,$dcdom).
- ' ('.$dcname.':'.$dcdom.')'.
- '</label></span></td>';
}
- $datatable .= '</tr></table>';
- } elsif (@dcs) {
- $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
- $dcs[0].'" />';
+ $table .= '</tr></table>';
+ } elsif ($numdcs == 1) {
+ if ($inputtype eq 'radio') {
+ $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />';
+ } else {
+ my $check;
+ if (exists($currhash{$domcoord[0]})) {
+ $check = ' checked="checked"';
+ }
+ $table .= '<input type="checkbox" name="'.$name.'" '.
+ 'value="'.$domcoord[0].'"'.$check.' />';
+ $rows ++;
+ }
}
- return ($numdcs,$datatable);
+ return ($numdcs,$table,$rows);
}
sub usersession_titles {
More information about the LON-CAPA-cvs
mailing list