From 21916796b4245666fcea9583884505952a906aff Mon Sep 17 00:00:00 2001 From: James Richie Date: Wed, 29 Jul 2026 21:04:03 -0400 Subject: [PATCH] added Active User Subscription report --- classes/Users.php | 13 + reports/Print_ActiveUserSubscriptions.php | 279 ++++++++++++++++++++++ reports/Print_UserLoginActivity.php | 2 +- 3 files changed, 293 insertions(+), 1 deletion(-) create mode 100644 reports/Print_ActiveUserSubscriptions.php diff --git a/classes/Users.php b/classes/Users.php index a703e67..db6a83e 100644 --- a/classes/Users.php +++ b/classes/Users.php @@ -757,6 +757,19 @@ class Users extends Base { return $this->getTable("loginactivity", $SQL); } + + // ==================== + // Return a User Object + // ==================== + + public function getActiveUsers() { + + $SQL = "select view_users.* + from view_users + where view_users.user_active = true"; + + return $this->getTable("activeusers", $SQL); + } } ?> diff --git a/reports/Print_ActiveUserSubscriptions.php b/reports/Print_ActiveUserSubscriptions.php new file mode 100644 index 0000000..0dffcdd --- /dev/null +++ b/reports/Print_ActiveUserSubscriptions.php @@ -0,0 +1,279 @@ +output_type = $output_type; + + ob_clean(); + + if ($output_type == "string") { + return $report->render(); + } else { + $report->render(); + } + } +} + +// ========================== +// Class to Generate the .pdf +// ========================== + +class ActiveUserSubscriptions 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())->getActiveUsers();
+
+        // Set report defaults
+
+        $this->title = "Active User Subscriptions";
+
+        $this->SetFont("Calibri");
+        $this->SetMargins(10, 25, 10);
+        $this->SetHeaderMargin(10);
+        $this->SetFooterMargin(10);
+        $this->setCellPaddings(0, 0, 0, 0);
+        $this->setCellMargins(2, 0, 0, 0);
+
+        $this->addPage("P", "LETTER");
+
+        // --------------------------
+        // Active Users Subscriptions
+        // --------------------------
+
+        $this->SetFont("Calibri", "B", 10);
+
+        foreach ($users as $user) {
+
+            $user_serial = (integer) $user->user_serial;
+            $user_name = (string) $user->user_name;
+            $users_login = (string) $user->user_login_verbose ?: 'Never Logged In';
+
+            $subscriptions = (new Subscriptions())->getUsersActiveSubscriptions($user_serial);
+            $this->SetFont("Calibri", "B", 10);
+            $this->Cell(25, 0, "Name:", 0, 0, "L", false, "", 3);
+            $this->SetFont("Calibri", "", 10);
+            $this->Cell(80, 0, $user->user_client_name, 0, 0, "L", false, "", 3);
+            $this->SetFont("Calibri", "B", 10);
+            $this->Cell(25, 0, "Created:", 0, 0, "L", false, "", 3);
+            $this->SetFont("Calibri", "", 10);
+            $this->Cell(80, 0, $user->user_created_verbose, 0, 1, "L", false, "", 3);
+
+            $this->SetFont("Calibri", "B", 10);
+            $this->Cell(25, 0, "Main Email:", 0, 0, "L", false, "", 3);
+            $this->SetFont("Calibri", "", 10);
+            $this->Cell(80, 0, $user->user_email, 0, 0, "L", false, "", 3);
+            $this->SetFont("Calibri", "B", 10);
+            $this->Cell(25, 0, "Created By:", 0, 0, "L", false, "", 3);
+            $this->SetFont("Calibri", "", 10);
+            $this->Cell(80, 0, $user->user_creator, 0, 1, "L", false, "", 3);
+
+            $this->SetFont("Calibri", "B", 10);
+            $this->Cell(25, 0, "User Name:", 0, 0, "L", false, "", 3);
+            $this->SetFont("Calibri", "", 10);
+            $this->Cell(80, 0, $user->user_name, 0, 0, "L", false, "", 3);
+            $this->SetFont("Calibri", "B", 10);
+            $this->Cell(25, 0, "Changed", 0, 0, "L", false, "", 3);
+            $this->SetFont("Calibri", "", 10);
+            $this->Cell(80, 0, $user->user_changed_verbose, 0, 1, "L", false, "", 3);
+
+            $this->SetFont("Calibri", "B", 10);
+            $this->Cell(25, 0, "Roll:", 0, 0, "L", false, "", 3);
+            $this->SetFont("Calibri", "", 10);
+            $this->Cell(80, 0, $user->user_role, 0, 0, "L", false, "", 3);
+            $this->SetFont("Calibri", "B", 10);
+            $this->Cell(25, 0, "Changed By:", 0, 0, "L", false, "", 3);
+            $this->SetFont("Calibri", "", 10);
+            $this->Cell(80, 0, $user->user_changer, 0, 1, "L", false, "", 3);
+
+            $this->SetFont("Calibri", "B", 10);
+            $this->Cell(25, 0, "Change Password:", 0, 0, "L", false, "", 3);
+            $this->SetFont("Calibri", "", 10);
+
+            $user_change_password = ($user->user_change_password == 1) ? "Yes" : "No";
+
+            $this->Cell(80, 0, $user_change_password, 0, 0, "L", false, "", 3);
+            $this->SetFont("Calibri", "B", 10);
+            $this->Cell(25, 0, "Last Login:", 0, 0, "L", false, "", 3);
+            $this->SetFont("Calibri", "", 10);
+            $this->Cell(80, 0, $user->user_login_verbose, 0, 1, "L", false, "", 3);
+
+            $this->SetFont("Calibri", "B", 10);
+            $this->Cell(25, 0, "", 0, 0, "L", false, "", 3);
+            $this->SetFont("Calibri", "", 10);
+            $this->Cell(80, 0, "", 0, 0, "L", false, "", 3);
+            $this->SetFont("Calibri", "B", 10);
+            $this->Cell(25, 0, "Active Status:", 0, 0, "L", false, "", 3);
+            $this->SetFont("Calibri", "", 10);
+
+            $user_active = ($user->user_active == 1) ? "Active" : "Inactive";
+            $this->Cell(80, 0, $user_active, 0, 1, "L", false, "", 3);
+
+            // ----------------------------------
+            // Rectangle around the Users Details
+            // ----------------------------------
+
+            $this->RoundedRect(10, 23, 190, $this->GetY() - 21, 1.50, "1111");
+
+            // -------------
+            // Subscriptions
+            // -------------
+            $this->Ln(7);
+
+            $this->SetFont("Calibri", "B", 12);
+            $this->Cell(0, 0, "Subscriptions", 0, 1, "L", false, "", 3);
+            $this->Ln(3);
+            $this->SetFont("Calibri", "B", 10);
+
+            $this->Cell(75, 0, "Description", "B", 0, "L", false, "", 3);
+            $this->Cell(20, 0, "End Date", "B", 0, "L", false, "", 3);
+            $this->Cell(10, 0, "Status", "B", 0, "L", false, "", 3);
+
+            $this->SetFont("Calibri", "", 10);
+
+            $this->Ln(6);
+
+            if ($subscriptions->count() == 0) {
+
+                $this->Cell(0, 0, "There are no Active Subscriptions...", 0, 1, "L", false, "", 3);
+            } else {
+
+                foreach ($subscriptions as $subscription) {
+
+                    $this->Cell(75, 0, $subscription->subscription_title . " " . $subscription->subscription_description, 0, 0, "L", false, "", 3);
+                    $this->Cell(20, 0, $subscription->usersubscription_stop_date_verbose, 0, 0, "L", false, "", 3);
+                    $this->Cell(10, 0, $subscription->usersubscription_status, 0, 0, "L", false, "", 3);
+
+                    $this->Ln(4);
+
+                    if ($this->GetY() > 265) {
+
+                        $this->AddPage("P", "LETTER");
+
+                        $this->SetFont("Calibri", "B", 10);
+
+                        $this->Cell(75, 0, "Description", "B", 0, "L", false, "", 3);
+                        $this->Cell(20, 0, "End Date", "B", 0, "L", false, "", 3);
+                        $this->Cell(10, 0, "Status", "B", 0, "L", false, "", 3);
+
+                        $this->SetFont("Calibri", "", 10);
+
+                        $this->Ln(6);
+                    }
+                }
+            }
+
+            $this->addPage("P", "LETTER");
+        }
+
+        // --------------
+        // Return the pdf
+        // --------------
+
+        if ($this->output_type == "string") {
+            return $this->Output("ActiveUserSubscriptions.pdf", "S");
+        } else {
+            $this->Output("ActiveUserSubscriptions.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, "Active Users Subscriptions", 0, 1, "C");
+
+        $this->Ln(5);
+    }
+
+    // ======
+    // 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);
+    }
+}
+
+?>
diff --git a/reports/Print_UserLoginActivity.php b/reports/Print_UserLoginActivity.php
index c5bc43b..a550eca 100644
--- a/reports/Print_UserLoginActivity.php
+++ b/reports/Print_UserLoginActivity.php
@@ -23,7 +23,7 @@ class Print_UserLoginActivity extends Base {
     // Print the Report
     // ================
 
-    public function print($user_serial = 0, $output_type = "normal") {
+    public function print($output_type = "normal") {
 
         $report = new User_LoginActivity();