feat: admin app version mgmt + notification system

- New tables: app_config, notifications
- Admin views: App Version editor, Notification sender
- API: GET /api/notifications, POST /api/notifications/:id/read, POST /api/notifications/read-all
- App version now stored in DB, editable by super admin
- Notifications: send to all users or specific user
- Android notification models + API client
- Sidebar: App Version + Notifications links for super_admin
This commit is contained in:
2026-06-09 17:06:22 -04:00
parent 3a4e8eb52c
commit 53e9b92a8d
12 changed files with 567 additions and 4 deletions

View File

@@ -5,8 +5,10 @@ declare(strict_types=1);
namespace ServerManager\Controllers;
use ServerManager\Core\App;
use ServerManager\Core\Database;
use ServerManager\Core\Session;
use ServerManager\Core\Validator;
use ServerManager\Models\Notification;
use ServerManager\Models\User;
use ServerManager\Services\AuditService;
@@ -210,4 +212,79 @@ class AdminController
'title' => 'Security Settings - ServerManager',
]);
}
public function appVersion(): void
{
$this->requireSuperAdmin();
$db = Database::getInstance();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$fields = ['app_version', 'apk_url', 'force_update', 'release_notes'];
foreach ($fields as $field) {
if (isset($_POST[$field])) {
$db->update('app_config', ['value' => $_POST[$field]], '`key` = ?', [$field]);
}
}
$this->auditService->log('app_version_updated', 'App version config updated');
$this->view->json(['success' => true, 'message' => 'App version updated successfully.']);
return;
}
$configs = $db->fetchAll('SELECT * FROM app_config');
$config = [];
foreach ($configs as $row) {
$config[$row['key']] = $row['value'];
}
$this->view->display('admin.app_version', [
'title' => 'App Version - ServerManager',
'config' => $config,
]);
}
public function notifications(): void
{
$this->requireSuperAdmin();
$notificationModel = new Notification();
$page = (int) ($_GET['page'] ?? 1);
$allNotifications = $notificationModel->getAll($page, 20);
$userModel = new User();
$users = $userModel->getAll(1, 200);
$this->view->display('admin.notifications', [
'title' => 'Notifications - ServerManager',
'notifications' => $allNotifications,
'users' => $users,
]);
}
public function sendNotification(): void
{
$this->requireSuperAdmin();
$title = $_POST['title'] ?? '';
$message = $_POST['message'] ?? '';
$type = $_POST['type'] ?? 'info';
$userId = !empty($_POST['user_id']) ? (int) $_POST['user_id'] : null;
if (empty($title) || empty($message)) {
$this->view->json(['success' => false, 'message' => 'Title and message are required.']);
return;
}
$notificationModel = new Notification();
$notificationModel->create([
'user_id' => $userId,
'title' => $title,
'message' => $message,
'type' => $type,
]);
$this->auditService->log('notification_sent', "Notification: {$title}" . ($userId ? " to user #{$userId}" : ' (all users)'));
$this->view->json(['success' => true, 'message' => 'Notification sent successfully.']);
}
}