<?php include __DIR__ . '/../includes/header.php'; require_admin();
if (is_post()) {
  $stmt = db()->prepare("INSERT INTO users (full_name, email, password, role, status, created_at) VALUES (?, ?, ?, ?, ?, ?)");
  $stmt->execute([trim($_POST['full_name']), trim($_POST['email']), password_hash($_POST['password'], PASSWORD_DEFAULT), $_POST['role'], $_POST['status'], now()]);
  audit_log('create', 'users', db()->lastInsertId(), 'Alta usuario');
  set_flash('success','Usuario creado.');
  redirect('users/index.php');
}
$item = [];
?>
<div class="form-wrap"><h4>Nuevo usuario</h4><form method="post"><?php include __DIR__ . '/form.php'; ?><button class="btn btn-primary">Guardar</button> <a class="btn btn-secondary" href="<?= e(base_url('users/index.php')) ?>">Volver</a></form></div>
<?php include __DIR__ . '/../includes/footer.php'; ?>
