db = $db; } public function index() { $this->checkLogin(); $this->checkAdmin(); $service = new FollowPlanService($this->db); $plans = $service->getAllPlans(); $games = $this->db->select('games', ['id', 'name', 'code'], ['status' => 1]); $this->render('Admin/follow_plans.php', compact('plans', 'games')); } public function save() { $this->checkLogin(); $this->checkAdmin(); header('Content-Type: application/json'); $data = json_decode(file_get_contents('php://input'), true) ?: $_POST; $data['created_by'] = $_SESSION['admin_id'] ?? 0; $service = new FollowPlanService($this->db); echo json_encode($service->savePlan($data)); } public function delete() { $this->checkLogin(); $this->checkAdmin(); header('Content-Type: application/json'); $data = json_decode(file_get_contents('php://input'), true) ?: $_POST; $id = intval($data['id'] ?? 0); if ($id <= 0) { echo json_encode(['success' => false, 'message' => 'ID invalid']); return; } $service = new FollowPlanService($this->db); echo json_encode($service->deletePlan($id)); } public function toggle() { $this->checkLogin(); $this->checkAdmin(); header('Content-Type: application/json'); $data = json_decode(file_get_contents('php://input'), true) ?: $_POST; $id = intval($data['id'] ?? 0); $plan = $this->db->get('follow_plans', '*', ['id' => $id]); if (!$plan) { echo json_encode(['success' => false, 'message' => 'Not found']); return; } $newStatus = $plan['status'] ? 0 : 1; $this->db->update('follow_plans', ['status' => $newStatus], ['id' => $id]); echo json_encode(['success' => true, 'status' => $newStatus]); } }