Update to mailstats panel

This commit is contained in:
2025-04-06 20:32:49 +01:00
parent 7fcdfccfa6
commit a58191f667
4 changed files with 61 additions and 5 deletions

View File

@@ -13,6 +13,8 @@ use esmith::AccountsDB;
use esmith::NetworksDB;
use esmith::DomainsDB;
use POSIX 'strftime';
use constant FALSE => 0;
use constant TRUE => 1;
@@ -291,4 +293,29 @@ sub get_URIBL_list{
"white.uribl.com" # Verified safe URI list
);}
sub get_mailstat_dates {
my ($directory) = '/opt/mailstats/html';
my @date_pairs;
# Find all matching files in directory
opendir(my $dh, $directory) or die "Can't open directory: $!";
while (my $file = readdir($dh)) {
next unless $file =~ /mailstats_for_(\d{4}-\d{2}-\d{2})\.html$/;
my $date = $1;
if ($date =~ /^(\d{4})-(\d{2})-(\d{2})$/) {
my $formatted_date = strftime("%B %-d %Y", 0, 0, 0, $3, $2-1, $1-1900);
push @date_pairs, [$formatted_date, $date];
}
}
closedir($dh);
# Sort dates chronologically
@date_pairs = sort { $a->[1] cmp $b->[1] } @date_pairs;
return \@date_pairs;
}
1;

View File

@@ -37,4 +37,30 @@ document.addEventListener('DOMContentLoaded', () => {
// Add change listener to multiselect
document.getElementById('CountrySelect_select')
.addEventListener('click', updateTextInput);
});
// Initialize select with current object content
document.addEventListener('DOMContentLoaded', () => {
const objectElement = document.getElementById('mailstats_object');
const selectElement = document.getElementById('StatsDate_select');
// Extract current date from object's data URL
const currentDate = objectElement.data.match(/mailstats_for_(\d{4}-\d{2}-\d{2})\.html/)?.[1];
if (currentDate) {
selectElement.value = currentDate;
}
});
// Update object content when selection changes
document.getElementById('StatsDate_select').addEventListener('change', function() {
const selectedDate = this.value;
const objectElement = document.getElementById('mailstats_object');
// Update object's data source
objectElement.data = `mailstats_for_${selectedDate}.html`;
// Force refresh using clone method (cross-browser workaround)
const clone = objectElement.cloneNode(true);
objectElement.replaceWith(clone);
});

View File

@@ -39,12 +39,12 @@
<p><span class=label>
%=l('mst_Date_for_Stats_display')
</span><span class=data>
% my @StatsDate_options = [['$c->get_StatsDate()' => '$c->get_StatsDate()']];
% my @StatsDate_options = $c->get_mailstat_dates();
% param 'StatsDate' => $mst_data->{StatsDate} unless param 'StatsDate';
%= select_field 'StatsDate' => @StatsDate_options, class => 'input', id => 'StatsDate_select'
<br></span> </p>
<object data="<%='mailstats/$c-&gt;stash(&quot;url&quot;)' %>" title="<%= $c->stash('title') %>" type="text/html" ><%= $c->stash('title') %> not found</object>
<object id = 'mailstats_object' data="<%='mailstats/$c-&gt;stash(&quot;url&quot;)' %>" title="<%= $c->stash('title') %>" type="text/html" ><%= $c->stash('title') %> not found</object>
%# Probably finally by a submit.