« Back to History
license_status.php
|
20260920_164915.php
Initial Domain Snapshot
Copy Code
<?php /* ============================================================================= File: /erp/license_status.php Purpose: Show current company's License status fetched directly from Admin DB ============================================================================= */ declare(strict_types=1); error_reporting(E_ALL); ini_set('display_errors', '1'); require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('license_status_view'); $company_id = (int)($ctx['company_id'] ?? 0); if ($company_id <= 0) { http_response_code(400); exit('Company ID missing from session context.'); } require_once __DIR__ . '/core/admin_db.php'; function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } $license = null; $dbError = ''; try { $adminPdo = getAdminDBConnection(); // 1️⃣ Try fetching license directly by company_id $stmt = $adminPdo->prepare(" SELECT l.*, c.company_name, c.company_code, p.plan_name FROM company_master c LEFT JOIN license_master l ON l.company_id = c.id LEFT JOIN plans p ON p.id = l.plan_id WHERE c.id = :cid LIMIT 1 "); $stmt->execute([':cid' => $company_id]); $license = $stmt->fetch(PDO::FETCH_ASSOC); // 2️⃣ Fallback: If no direct license found for this company_id, fetch any active default license if (!$license || empty($license['license_key'])) { $fallbackStmt = $adminPdo->prepare(" SELECT l.*, c.company_name, c.company_code, p.plan_name FROM license_master l JOIN company_master c ON c.id = l.company_id LEFT JOIN plans p ON p.id = l.plan_id ORDER BY l.id DESC LIMIT 1 "); $fallbackStmt->execute(); $license = $fallbackStmt->fetch(PDO::FETCH_ASSOC); } } catch (Throwable $e) { $dbError = 'Unable to connect to Central License Manager: ' . $e->getMessage(); } /* -------------------- Calculations & States -------------------- */ $daysRemaining = 0; $isExpired = false; $features = []; if ($license && !empty($license['license_key'])) { if (!empty($license['features_json'])) { $decoded = json_decode($license['features_json'], true); if (json_last_error() === JSON_ERROR_NONE && is_array($decoded)) { $features = $decoded; } } if (!empty($license['end_date'])) { try { $today = new DateTime(); $endDate = new DateTime($license['end_date']); $interval = $today->diff($endDate); $daysRemaining = (int)$interval->format("%r%a"); if ($license['license_type'] !== 'LIFETIME' && $daysRemaining < 0) { $isExpired = true; } } catch (Exception $e) { $daysRemaining = 0; } } } /* -------------------- Render -------------------- */ $PAGE_TITLE = 'ERP License & Subscription Details'; require_once __DIR__ . '/partials/header.php'; ?> <div class="container my-4" style="max-width: 900px;"> <div class="d-flex justify-content-between align-items-center mb-3"> <h4 class="m-0 fw-bold text-dark">📜 License & Subscription Status</h4> <button class="btn btn-sm btn-outline-secondary" onclick="window.location.reload();">🔄 Refresh Status</button> </div> <?php if ($dbError): ?> <div class="alert alert-danger shadow-sm" role="alert"> <strong>Connection Warning:</strong> <?= h($dbError) ?> </div> <?php endif; ?> <?php if ((!$license || empty($license['license_key'])) && !$dbError): ?> <div class="card shadow-sm border-0 text-center py-5"> <div class="card-body"> <h5 class="text-muted">No License Node Associated</h5> <p class="small text-secondary mb-0">Your company profile (ID: <?= $company_id ?>) does not have an active registered license entry in the system.</p> </div> </div> <?php else: ?> <!-- Main Status Overview Card --> <div class="card border-0 shadow-sm mb-4"> <div class="card-body p-4"> <div class="row align-items-center g-3"> <div class="col-md-8"> <span class="text-uppercase text-muted fw-bold small">Registered Company</span> <h3 class="fw-bold mb-1 text-dark"><?= h($license['company_name']) ?> <span class="fs-6 text-muted">(<?= h($license['company_code']) ?>)</span></h3> <p class="mb-0 text-secondary"> Plan: <strong class="text-dark"><?= h($license['plan_name'] ?? 'Custom Enterprise Plan') ?></strong> </p> </div> <div class="col-md-4 text-md-end"> <?php if ($license['status'] === 'ACTIVE' && !$isExpired): ?> <span class="badge bg-success fs-6 px-3 py-2">ACTIVE LICENSE</span> <?php elseif ($isExpired): ?> <span class="badge bg-danger fs-6 px-3 py-2">LICENSE EXPIRED</span> <?php else: ?> <span class="badge bg-warning text-dark fs-6 px-3 py-2"><?= h($license['status']) ?></span> <?php endif; ?> </div> </div> </div> </div> <!-- Metrics Grid --> <div class="row g-3 mb-4"> <div class="col-md-6 col-lg-3"> <div class="card border-0 shadow-sm h-100 bg-light"> <div class="card-body"> <div class="text-muted small fw-bold mb-1">LICENSE KEY</div> <code class="fs-6 fw-bold text-primary"><?= h($license['license_key']) ?></code> </div> </div> </div> <div class="col-md-6 col-lg-3"> <div class="card border-0 shadow-sm h-100 bg-light"> <div class="card-body"> <div class="text-muted small fw-bold mb-1">LICENSE TYPE</div> <?php $typeBadge = 'bg-dark'; if ($license['license_type'] === 'PAID') $typeBadge = 'bg-primary'; if ($license['license_type'] === 'TRIAL') $typeBadge = 'bg-warning text-dark'; if ($license['license_type'] === 'LIFETIME') $typeBadge = 'bg-info text-dark'; ?> <span class="badge <?= $typeBadge ?>"><?= h($license['license_type']) ?></span> </div> </div> </div> <div class="col-md-6 col-lg-3"> <div class="card border-0 shadow-sm h-100 bg-light"> <div class="card-body"> <div class="text-muted small fw-bold mb-1">REMAINING VALIDITY</div> <?php if ($license['license_type'] === 'LIFETIME' || empty($license['end_date'])): ?> <span class="fw-bold text-success fs-6">Lifetime Access</span> <?php elseif ($isExpired): ?> <span class="fw-bold text-danger fs-6">0 Days (Expired)</span> <?php else: ?> <span class="fw-bold text-dark fs-5"><?= $daysRemaining ?></span> <span class="small text-muted">Days Left</span> <?php endif; ?> </div> </div> </div> <div class="col-md-6 col-lg-3"> <div class="card border-0 shadow-sm h-100 bg-light"> <div class="card-body"> <div class="text-muted small fw-bold mb-1">MAX USERS ALLOWED</div> <span class="fw-bold fs-5 text-dark"><?= !is_null($license['max_users']) ? (int)$license['max_users'] : 'Unlimited' ?></span> </div> </div> </div> </div> <!-- Detailed Specifications Card --> <div class="card border-0 shadow-sm mb-4"> <div class="card-header bg-white border-bottom py-3"> <h6 class="mb-0 fw-bold text-dark">📋 Subscription Validity Period</h6> </div> <div class="card-body"> <div class="row text-center text-md-start"> <div class="col-md-4 mb-3 mb-md-0"> <span class="text-muted small d-block">Start Date</span> <strong class="text-dark"><?= h($license['start_date']) ?></strong> </div> <div class="col-md-4 mb-3 mb-md-0"> <span class="text-muted small d-block">End Date</span> <strong class="text-dark"><?= h($license['end_date'] ?? 'Lifetime / Indefinite') ?></strong> </div> <div class="col-md-4"> <span class="text-muted small d-block">Last System Verification</span> <span class="text-secondary small"><?= h($license['last_verified_at'] ?? 'Just now') ?></span> </div> </div> </div> </div> <?php endif; ?> </div> <?php require_once __DIR__ . '/partials/footer.php'; ?>