From 11c26cd58f2619f02210cb34faceb39012717d5c Mon Sep 17 00:00:00 2001 From: Eduardo M KALINOWSKI Date: Mon, 6 Jun 2022 17:59:18 -0300 Subject: Adjust queries so they work on PostgreSQL --- dmarcts-report-viewer-report-data.php | 4 ++++ dmarcts-report-viewer-report-list.php | 4 +++- dmarcts-report-viewer.php | 8 ++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/dmarcts-report-viewer-report-data.php b/dmarcts-report-viewer-report-data.php index f60fc6a..09ea80e 100644 --- a/dmarcts-report-viewer-report-data.php +++ b/dmarcts-report-viewer-report-data.php @@ -96,6 +96,7 @@ function tmpl_reportData($reportnumber, $reports, $host_lookup = 1) { $reportdata[] = " "; $reportdata[] = " "; + global $dbtype; global $dbh; $sql = " @@ -138,6 +139,9 @@ ORDER BY if ( $row['ip'] ) { $ip = long2ip($row['ip']); } elseif ( $row['ip6'] ) { + if ( $dbtype == 'pgsql') { + $row['ip6'] = stream_get_contents($row['ip6']); + } $ip = inet_ntop($row['ip6']); } else { $ip = "-"; diff --git a/dmarcts-report-viewer-report-list.php b/dmarcts-report-viewer-report-list.php index 05e5fdf..806ed8c 100644 --- a/dmarcts-report-viewer-report-list.php +++ b/dmarcts-report-viewer-report-list.php @@ -239,7 +239,9 @@ if( $org_select <> '' ) { if( $per_select <> '' ) { $ye = substr( $per_select, 0, 4) + 0; $mo = substr( $per_select, 5, 2) + 0; - $where .= ( $where <> '' ? " AND" : " WHERE" ) . " ((year(mindate) = $ye AND month(mindate) = $mo) OR (year(maxdate) = $ye AND month(maxdate) = $mo)) "; + $where .= ( $where <> '' ? " AND" : " WHERE" ) + . " ((extract(year from mindate) = $ye AND extract(month from mindate) = $mo) " + . " OR (extract(year from maxdate) = $ye AND extract(month from maxdate) = $mo)) "; } // Include the rcount via left join, so we do not have to make an sql query diff --git a/dmarcts-report-viewer.php b/dmarcts-report-viewer.php index f060ec5..5730a3d 100644 --- a/dmarcts-report-viewer.php +++ b/dmarcts-report-viewer.php @@ -277,16 +277,16 @@ foreach($query as $row) { $sql = " ( SELECT - YEAR(mindate) AS year, - MONTH(mindate) AS month + EXTRACT(YEAR FROM mindate) AS year, + EXTRACT(MONTH FROM mindate) AS month FROM report ) UNION ( SELECT - YEAR(maxdate) AS year, - MONTH(maxdate) AS month + EXTRACT(YEAR FROM mindate) AS year, + EXTRACT(MONTH FROM mindate) AS month FROM report ) -- cgit v1.2.3