From 8fa2c69094fdee546227569cc0dcc52f56f4275a Mon Sep 17 00:00:00 2001 From: James Richie Date: Wed, 29 Jul 2026 20:41:49 -0400 Subject: [PATCH] added report for All Users Login Activity --- reports/Print_UserLoginActivity.php | 179 ++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 reports/Print_UserLoginActivity.php diff --git a/reports/Print_UserLoginActivity.php b/reports/Print_UserLoginActivity.php new file mode 100644 index 0000000..c5bc43b --- /dev/null +++ b/reports/Print_UserLoginActivity.php @@ -0,0 +1,179 @@ +output_type = $output_type; + + ob_clean(); + + if ($output_type == "string") { + return $report->render(); + } else { + $report->render(); + } + } +} + +// ========================== +// Class to Generate the .pdf +// ========================== + +class User_LoginActivity extends TCPDF { + + // Variables + + public $user_serial = 0; + public $first_page = true; + public $output_type = "normal"; + + // ================ + // Debug an Object. + // ================ + + public function debug($object = "") { + + echo "
";
+        print_r($object);
+        exit();
+    }
+
+    // =================
+    // Render the Report
+    // =================
+
+    public function render() {
+
+        set_time_limit(0);
+
+        // Get the data for the report
+
+        $users = (new Users())->getUsers();
+
+        // Set report defaults
+
+        $this->title = "All Users Login Activity";
+
+        $this->SetFont("Calibri");
+        $this->SetMargins(10, 30, 10);
+        $this->SetHeaderMargin(10);
+        $this->SetFooterMargin(10);
+        $this->setCellPaddings(0, 0, 0, 0);
+        $this->setCellMargins(2, 0, 0, 0);
+
+        $this->addPage("P", "LETTER");
+
+        // ------------------------
+        // Print the Users Activity
+        // ------------------------
+
+        $this->SetFont("Calibri", "B", 10);
+
+        $rowCount = 0;
+
+        foreach ($users as $user) {
+
+            $this->stripeLine($rowCount, 60);
+
+            $rowCount++;
+
+            $user_name = (string) $user->user_name;
+            $users_login = (string) $user->user_login_verbose ?: 'Never Logged In';
+
+            $this->Cell(20, 0, $user_name, 0, 0, "C", false, "", 0);
+            $this->Cell(20, 0, $users_login, 0, 0, "L", false, "", 0);
+            $this->Ln();
+        }
+
+        // --------------
+        // Return the pdf
+        // --------------
+
+        if ($this->output_type == "string") {
+            return $this->Output("UserLoginActivity.pdf", "S");
+        } else {
+            $this->Output("UserLoginActivity.pdf");
+        }
+    }
+
+    // ======
+    // Header
+    // ======
+
+    public function Header() {
+
+        $this->setCellPaddings(0, 0, 0, 0);
+        $this->setCellMargins(2, 0, 0, 0);
+
+        $this->Image('images/dec-international-logo.png', 10, 7, 25, 10);
+
+        $this->SetFont("Calibri", "B", 16);
+
+        $this->Cell(0, 6, "Users Login Activity", 0, 1, "C");
+
+        $this->Ln(5);
+
+        $this->SetFont("Calibri", "B", 12);
+
+        $this->Cell(20, 0, "User Name", "B", 0, "C", false, "", 3);
+        $this->Cell(50, 0, "Last Login", "B", 0, "L", false, "", 3);
+
+        $this->SetFont("Calibri", "B", 10);
+    }
+
+    // ======
+    // Footer
+    // ======
+
+    public function Footer() {
+
+        $this->SetFont("Calibri", "I", 8);
+
+        $X = $this->GetX();
+
+        $this->Cell(0, 10, "DEC-International, LLC", 0, false, "C");
+
+        $this->SetX($X);
+
+        $this->Cell(40, 10, "Page " . $this->getAliasNumPage() . "/" . $this->getAliasNbPages(), 0, false, "L");
+        $this->Cell(0, 10, date("Y-m-d g:i A"), 0, false, "R");
+    }
+
+    // =======================
+    // Stripe the printed line
+    // =======================
+
+    private function stripeLine($pRowCount = 0, $pRowWidth = 0) {
+
+        $this->SetFillColor(($pRowCount % 2) ? 220 : 255);
+        $X = $this->GetX();
+        $this->Cell($pRowWidth, 0, "", 0, 0, "L", true);
+        $this->SetX($X);
+    }
+}
+
+?>