133 lines
6.7 KiB
PHP
133 lines
6.7 KiB
PHP
<?php
|
|
session_start();
|
|
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'superadmin') {
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
|
|
require_once 'db/config.php';
|
|
|
|
$success = '';
|
|
$error = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
|
if ($_POST['action'] === 'update_msp') {
|
|
$msp_id = $_POST['msp_id'];
|
|
$subdomain = $_POST['subdomain'];
|
|
$custom_domain = $_POST['custom_domain'];
|
|
$plan_id = $_POST['plan_id'];
|
|
|
|
try {
|
|
$stmt = db()->prepare("UPDATE msps SET subdomain = ?, custom_domain = ?, plan_id = ? WHERE id = ?");
|
|
$stmt->execute([$subdomain ?: null, $custom_domain ?: null, $plan_id, $msp_id]);
|
|
$success = "MSP configuration updated successfully.";
|
|
} catch (PDOException $e) {
|
|
$error = "Error updating MSP: " . $e->getMessage();
|
|
}
|
|
}
|
|
}
|
|
|
|
$stmt = db()->query("SELECT m.*, p.name as plan_name FROM msps m JOIN plans p ON m.plan_id = p.id ORDER BY m.name ASC");
|
|
$msps = $stmt->fetchAll();
|
|
|
|
$stmt = db()->query("SELECT * FROM plans");
|
|
$plans = $stmt->fetchAll();
|
|
|
|
include 'header.php';
|
|
?>
|
|
|
|
<div class="container py-5">
|
|
<div class="header-section">
|
|
<h1>Manage MSPs</h1>
|
|
<p class="text-muted">Manage tenant subdomains, custom domains, and subscription plans.</p>
|
|
</div>
|
|
|
|
<?php if ($success): ?>
|
|
<div class="alert alert-success"><?php echo $success; ?></div>
|
|
<?php endif; ?>
|
|
<?php if ($error): ?>
|
|
<div class="alert alert-danger"><?php echo $error; ?></div>
|
|
<?php endif; ?>
|
|
|
|
<div class="card shadow-sm border-0">
|
|
<div class="card-body p-4">
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th>MSP Name</th>
|
|
<th>Current Plan</th>
|
|
<th>Subdomain</th>
|
|
<th>Custom Domain</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($msps as $msp): ?>
|
|
<tr>
|
|
<td class="fw-bold"><?php echo htmlspecialchars($msp['name']); ?></td>
|
|
<td><span class="badge bg-light text-dark border"><?php echo htmlspecialchars($msp['plan_name']); ?></span></td>
|
|
<td><?php echo $msp['subdomain'] ? htmlspecialchars($msp['subdomain']) . '.mspconnect.com' : 'N/A'; ?></td>
|
|
<td><?php echo $msp['custom_domain'] ? htmlspecialchars($msp['custom_domain']) : 'N/A'; ?></td>
|
|
<td>
|
|
<button type="button" class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#editMspModal<?php echo $msp['id']; ?>">
|
|
<i class="bi bi-pencil-square"></i> Edit
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
|
|
<!-- Edit MSP Modal -->
|
|
<div class="modal fade" id="editMspModal<?php echo $msp['id']; ?>" tabindex="-1">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<form method="POST">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title">Configure MSP: <?php echo htmlspecialchars($msp['name']); ?></h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<input type="hidden" name="action" value="update_msp">
|
|
<input type="hidden" name="msp_id" value="<?php echo $msp['id']; ?>">
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Subscription Plan</label>
|
|
<select name="plan_id" class="form-select">
|
|
<?php foreach ($plans as $plan): ?>
|
|
<option value="<?php echo $plan['id']; ?>" <?php echo $plan['id'] == $msp['plan_id'] ? 'selected' : ''; ?>>
|
|
<?php echo $plan['name']; ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Subdomain</label>
|
|
<div class="input-group">
|
|
<input type="text" name="subdomain" class="form-control" value="<?php echo htmlspecialchars($msp['subdomain'] ?? ''); ?>">
|
|
<span class="input-group-text">.mspconnect.com</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Custom Domain</label>
|
|
<input type="text" name="custom_domain" class="form-control" placeholder="e.g. portal.acme.com" value="<?php echo htmlspecialchars($msp['custom_domain'] ?? ''); ?>">
|
|
<small class="text-muted">Only available for Pro and Enterprise plans.</small>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
|
<button type="submit" class="btn btn-primary">Save Changes</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
<?php include 'footer.php'; ?>
|