$groupToAdd = $_POST['grouptoadd'];
    //Insert group connection
    executePreparedSQLQuery($mysqlConn, 'INSERT IGNORE INTO groupconnections (userId, groupId)
												VALUES (?, ?)', 'ii', [$userId, $groupToAdd]);
    //Get group name
    $groupName = getArrayFromSQLQuery($mysqlConn, 'SELECT name FROM groups WHERE groupId = ?', 'i', [$groupToAdd])[0]['name'];
    //Create notification summary and body
    $notificationSummary = 'You are now part of "' . $groupName . '".';
    $notificationBody = 'You have been added to the group "' . $groupName . '" by an administrator.';
}
if (isset($_POST['grouptoremove'])) {
    $groupToRemove = $_POST['grouptoremove'];
    //Get group name
    $groupName = getArrayFromSQLQuery($mysqlConn, 'SELECT name FROM groups WHERE groupId = ?', 'i', [$groupToRemove])[0]['name'];
    //Remove group connection
    executePreparedSQLQuery($mysqlConn, 'DELETE FROM groupconnections
												WHERE userId = ? AND groupId = ?', 'ii', [$userId, $groupToRemove]);
    //Create notification summary and body
    $notificationSummary = 'You are no longer part of "' . $groupName . '".';
    $notificationBody = 'You have been removed from the group "' . $groupName . '" by an administrator.';
}
//Send notification if corresponding checkbox was checked
if (isset($_POST['sendnotification']) && $_POST['sendnotification'] === 'yes') {
    $notificationManager = new notification_manager($mysqlConn);
    $notificationManager->createUserNotification($userId, $notificationSummary, $notificationBody);
}
$mysqlConn->close();
unset($_SESSION['admin_userview_token' . $userId]);
unset($_SESSION['admin_users_token']);
echo 'User group settings set.';
require_once '../../common/ucpfooter.php';