I tried writing this code, but something isn't working: I see the appgini layout with links, header, and footer, but the content page is completely blank.
I believe the page view permissions are working correctly, because if I'm not logged in as the Admins or allprivileges group, I see the message that I'm not logged in to the site.
Here is my user_manager.php page:
Code: Select all
<?php
define('PREPEND_PATH', '../');
include_once(PREPEND_PATH . 'lib.php');
include_once(PREPEND_PATH . 'incCommon.php');
include_once(PREPEND_PATH . 'header.php');
// 💡 RIGA DA RIMUOVERE: AppGini non ne ha bisogno
// include_once('__global.php');
// Inizializza l’array error options
$eo = [];
// 🔐 Accesso consentito solo ai gruppi specifici
$allowedGroups = ['allprivileges', 'Admins'];
$targetGroup = 'beneficiari';
// **Il problema era qui:** la verifica dei permessi deve includere la stampa dell'intero form.
if (!in_array(getLoggedGroup(), $allowedGroups)) {
echo "<div class='alert alert-danger'>Accesso non autorizzato.</div>";
include_once(PREPEND_PATH . 'footer.php');
exit;
}
// 🔍 Recupera utenti del gruppo beneficiari
$filteredUsers = [];
$gid = sqlValue("SELECT groupID FROM membership_groups WHERE name='{$targetGroup}'", $eo);
if ($gid) {
$res = sql("SELECT memberID FROM membership_users WHERE groupID='{$gid}'", $eo);
while ($row = db_fetch_assoc($res)) {
$filteredUsers[] = $row['memberID'];
}
}
// 📥 Creazione utente (forzato al gruppo beneficiari)
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['create_user'])) {
$username = makeSafe($_POST['username']);
$password = $_POST['password'];
$confirm = $_POST['confirm_password'];
// 🔎 Controllo username duplicato
$exists = sqlValue("SELECT COUNT(*) FROM membership_users WHERE memberID='{$username}'", $eo);
if ($password !== $confirm) {
echo "<div class='alert alert-warning'>Le password non coincidono.</div>";
} elseif ($exists > 0) {
echo "<div class='alert alert-danger'>Errore: lo username <b>{$username}</b> esiste già.</div>";
} elseif (!$gid) {
echo "<div class='alert alert-danger'>Errore: gruppo beneficiari non trovato.</div>";
} else {
$userCreated = sql("INSERT INTO membership_users
SET
memberID = '{$username}',
passMD5 = '" . md5($password) . "',
groupID = '{$gid}',
signupDate = NOW(),
isApproved = 1", $eo);
if ($userCreated) {
echo "<div class='alert alert-success'>Utente <b>{$username}</b> creato con successo e assegnato al gruppo {$targetGroup}!</div>";
} else {
echo "<div class='alert alert-danger'>Errore nella creazione utente.</div>";
}
}
}
// 🔄 Cambio password (solo utenti beneficiari)
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['change_password'])) {
$targetUser = makeSafe($_POST['target_user']);
$newPassword = $_POST['new_password'];
$confirmPassword = $_POST['confirm_password'];
if ($newPassword !== $confirmPassword) {
echo "<div class='alert alert-warning'>Le password non coincidono.</div>";
} elseif (!in_array($targetUser, $filteredUsers)) {
echo "<div class='alert alert-danger'>Utente non autorizzato o non trovato.</div>";
} else {
sql("UPDATE membership_users
SET passMD5 = '" . md5($newPassword) . "'
WHERE memberID = '{$targetUser}'", $eo);
echo "<div class='alert alert-success'>Password aggiornata per {$targetUser}.</div>";
}
}
?>
<div class="container mt-5">
<h2>Gestione Utenti (solo gruppo beneficiari)</h2>
<form method="POST">
<input type="hidden" name="create_user" value="1">
<div class="form-group">
<label>Username</label>
<input name="username" class="form-control" required>
</div>
<div class="form-group">
<label>Password</label>
<input name="password" type="password" class="form-control" required>
</div>
<div class="form-group">
<label>Conferma Password</label>
<input name="confirm_password" type="password" class="form-control" required>
</div>
<button class="btn btn-primary mt-3">Crea Utente</button>
</form>
<hr class="my-5">
<h3>Cambia Password Utente (beneficiari)</h3>
<form method="POST">
<input type="hidden" name="change_password" value="1">
<div class="form-group">
<label>Seleziona Utente</label>
<select name="target_user" class="form-control" required>
<?php foreach ($filteredUsers as $user): ?>
<option value="<?= $user ?>"><?= $user ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label>Nuova Password</label>
<input name="new_password" type="password" class="form-control" required>
</div>
<div class="form-group">
<label>Conferma Password</label>
<input name="confirm_password" type="password" class="form-control" required>
</div>
<button class="btn btn-warning mt-3">Aggiorna Password</button>
</form>
</div>
<?php include_once(PREPEND_PATH . 'footer.php'); ?>I hope someone can help me.
Thanks!
