<?php
require_once __DIR__ . '/../app/config/config.php';
require_once __DIR__ . '/../app/middleware/auth.php';
require_once __DIR__ . '/../app/config/db.php';

require_login();
$user = current_user();
if (($user['role'] ?? '') !== 'admin') { http_response_code(403); exit('Forbidden'); }

$id = (int)($_POST['id'] ?? 0);
$active = (int)($_POST['active'] ?? 0);

if ($id) {
  db()->prepare("UPDATE tenants SET is_active=? WHERE id=?")->execute([$active, $id]);
}

header('Location: ' . BASE_URL . '/tenants_list.php');
exit;
