Don't display an empty table

tags/smeserver-expire-accounts-0.1.7-1
Daniel Berteaud 9 years ago
parent f9c6658139
commit 841c1c0fed
  1. 181
      root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/expireaccounts.pm

@ -63,102 +63,101 @@ sub print_user_table {
my @users = $a->users;
unless ( scalar @users ) {
if ( scalar @users < 1) {
print $q->Tr($q->td($self->localise('NO_USER_ACCOUNTS')));
return "";
}
print " <tr><td colspan=\"2\">";
print $q->start_table ({-CLASS => "sme-border"});
print $q->Tr(
esmith::cgi::genSmallCell($q, $self->localise('ACTIVE_ACCOUNT'), "header"),
esmith::cgi::genSmallCell($q, $self->localise('USER_NAME'), "header"),
esmith::cgi::genSmallCell($q, $self->localise('FORWARD'), "header"),
esmith::cgi::genSmallCell($q, $self->localise('DAYS_BEFORE_LOCK'), "header"),
esmith::cgi::genSmallCell($q, $self->localise('ACTION'), "header")
);
my $scriptname = basename($0);
my $now = DateTime->now;
foreach my $u (@users) {
my $username = $u->key();
next unless (($u->prop('PasswordSet') || 'no') eq 'yes');
my $first = $u->prop('FirstName') || '';
my $last = $u->prop('LastName') || '';
my $lock_date = $u->prop('ExpireLockOn') || '';
my $delivery = $u->prop('EmailForward') || 'local';
my $fwd = $u->prop('ForwardAddress') || '';
my $action = "<a href=\"$scriptname?page=0&page_stack=&acctName=$username&wherenext=ModifyActive\">" .
$self->localise('MODIFY') . "</a>";
my $days_left = '';
if ($lock_date =~ m/^(\d{4})\-(\d{1,2})\-(\d{1,2})$/){
my $lock_on = eval {
DateTime->new(
year => $1,
month => $2,
day => $3
);
};
$days_left = ($lock_on - $now)->in_units('days') if ($lock_on);
}
my $addr = ($delivery eq 'local') ? '' : $fwd;
if (_count_active_users() > 0){
print " <tr><td colspan=\"2\">";
print $q->start_table ({-CLASS => "sme-border"});
print $q->Tr(
esmith::cgi::genSmallCell($q, $username, "normal"),
esmith::cgi::genSmallCell($q, "$first $last", "normal"),
esmith::cgi::genSmallCell($q, $addr, "normal"),
esmith::cgi::genSmallCell($q, $days_left, "normal"),
esmith::cgi::genSmallCell($q, $action, "normal")
esmith::cgi::genSmallCell($q, $self->localise('ACTIVE_ACCOUNT'), "header"),
esmith::cgi::genSmallCell($q, $self->localise('USER_NAME'), "header"),
esmith::cgi::genSmallCell($q, $self->localise('FORWARD'), "header"),
esmith::cgi::genSmallCell($q, $self->localise('DAYS_BEFORE_LOCK'), "header"),
esmith::cgi::genSmallCell($q, $self->localise('ACTION'), "header")
);
}
# Now, same for locked accounts
print $q->Tr(
esmith::cgi::genSmallCell($q, $self->localise('INACTIVE_ACCOUNT'), "header"),
esmith::cgi::genSmallCell($q, $self->localise('USER_NAME'), "header"),
esmith::cgi::genSmallCell($q, $self->localise('FORWARD'), "header"),
esmith::cgi::genSmallCell($q, $self->localise('DAYS_BEFORE_DELETE'), "header"),
esmith::cgi::genSmallCell($q, $self->localise('ACTION'), "header")
);
foreach my $u (@users) {
my $username = $u->key();
next unless (($u->prop('PasswordSet') || 'no') ne 'yes');
my $first = $u->prop('FirstName') || '';
my $last = $u->prop('LastName') || '';
my $delete_in = $u->prop('ExpireDeleteAfterLock') || '';
my $locked_on = $u->prop('ExpireLockedOn') || '';
my $delivery = $u->prop('EmailForward') || '';
my $fwd = $u->prop('ForwardAddress') || '';
my $action = "<a href=\"$scriptname?page=0&page_stack=&acctName=$username&wherenext=ModifyLocked\">" .
$self->localise('MODIFY') . "</a>";
my $days_left = '';
if ($delete_in =~ m/^\d+$/ && $locked_on =~ m/^(\d{4})\-(\d{1,2})\-(\d{1,2})$/){
my $locked_date = eval {
DateTime->new(
year => $1,
month => $2,
day => $3
my $scriptname = basename($0);
my $now = DateTime->now;
foreach my $u (@users) {
my $username = $u->key();
next unless (($u->prop('PasswordSet') || 'no') eq 'yes');
my $first = $u->prop('FirstName') || '';
my $last = $u->prop('LastName') || '';
my $lock_date = $u->prop('ExpireLockOn') || '';
my $delivery = $u->prop('EmailForward') || 'local';
my $fwd = $u->prop('ForwardAddress') || '';
my $action = "<a href=\"$scriptname?page=0&page_stack=&acctName=$username&wherenext=ModifyActive\">" .
$self->localise('MODIFY') . "</a>";
my $days_left = '';
if ($lock_date =~ m/^(\d{4})\-(\d{1,2})\-(\d{1,2})$/){
my $lock_on = eval {
DateTime->new(
year => $1,
month => $2,
day => $3
);
};
$days_left = ($lock_on - $now)->in_units('days') if ($lock_on);
}
my $addr = ($delivery eq 'local') ? '' : $fwd;
print $q->Tr(
esmith::cgi::genSmallCell($q, $username, "normal"),
esmith::cgi::genSmallCell($q, "$first $last", "normal"),
esmith::cgi::genSmallCell($q, $addr, "normal"),
esmith::cgi::genSmallCell($q, $days_left, "normal"),
esmith::cgi::genSmallCell($q, $action, "normal")
);
};
if ($locked_date){
my $delete_on = $locked_date->add(days => $delete_in);
$days_left = ($delete_on - $now)->in_units('days');
}
}
my $addr = ($delivery eq 'local') ? '' : $fwd;
}
if (_count_inactive_users() > 0){
# Now, same for locked accounts
print $q->Tr(
esmith::cgi::genSmallCell($q, $username, "normal"),
esmith::cgi::genSmallCell($q, "$first $last", "normal"),
esmith::cgi::genSmallCell($q, $addr, "normal"),
esmith::cgi::genSmallCell($q, $days_left, "normal"),
esmith::cgi::genSmallCell($q, $action, "normal")
esmith::cgi::genSmallCell($q, $self->localise('INACTIVE_ACCOUNT'), "header"),
esmith::cgi::genSmallCell($q, $self->localise('USER_NAME'), "header"),
esmith::cgi::genSmallCell($q, $self->localise('FORWARD'), "header"),
esmith::cgi::genSmallCell($q, $self->localise('DAYS_BEFORE_DELETE'), "header"),
esmith::cgi::genSmallCell($q, $self->localise('ACTION'), "header")
);
foreach my $u (@users) {
my $username = $u->key();
next unless (($u->prop('PasswordSet') || 'no') ne 'yes');
my $first = $u->prop('FirstName') || '';
my $last = $u->prop('LastName') || '';
my $delete_in = $u->prop('ExpireDeleteAfterLock') || '';
my $locked_on = $u->prop('ExpireLockedOn') || '';
my $delivery = $u->prop('EmailForward') || '';
my $fwd = $u->prop('ForwardAddress') || '';
my $action = "<a href=\"$scriptname?page=0&page_stack=&acctName=$username&wherenext=ModifyLocked\">" .
$self->localise('MODIFY') . "</a>";
my $days_left = '';
if ($delete_in =~ m/^\d+$/ && $locked_on =~ m/^(\d{4})\-(\d{1,2})\-(\d{1,2})$/){
my $locked_date = eval {
DateTime->new(
year => $1,
month => $2,
day => $3
);
};
if ($locked_date){
my $delete_on = $locked_date->add(days => $delete_in);
$days_left = ($delete_on - $now)->in_units('days');
}
}
my $addr = ($delivery eq 'local') ? '' : $fwd;
print $q->Tr(
esmith::cgi::genSmallCell($q, $username, "normal"),
esmith::cgi::genSmallCell($q, "$first $last", "normal"),
esmith::cgi::genSmallCell($q, $addr, "normal"),
esmith::cgi::genSmallCell($q, $days_left, "normal"),
esmith::cgi::genSmallCell($q, $action, "normal")
);
}
}
print qq(</table></td></tr>\n);
return "";
}
@ -265,6 +264,22 @@ sub modify_user {
$self->success('USER_MODIFIED');
}
sub _count_active_users{
my $users = 0;
foreach my $user ($a->users){
$users++ if ($user->prop('PasswordSet') || 'no') eq 'yes';
}
return $users;
}
sub _count_inactive_users{
my $users = 0;
foreach my $user ($a->users){
$users++ unless ($user->prop('PasswordSet') || 'no') eq 'yes';
}
return $users;
}
# Validation routines
# Number must be int and positive

Loading…
Cancel
Save