$et->data['entity_filter'] = $entity_filter;
$et->data['entity_filter_exclude'] = $entity_filter_exclude;
$et->data['query'] = isset($_GET['q']) ? $_GET['q'] : '';
$et->data['order'] = isset($_GET['order']) ? $_GET['order'] : null;
$et->data['sort'] = isset($_GET['sort']) ? $_GET['sort'] : null;
$et->data['userid'] = $userid;
$et->data['user'] = $mcontrol->getUser();
$et->data['uiguard'] = new sspmod_janus_UIguard($janus_config->getValue('access'));
$et->data['user_type'] = $user->getType();
$et->data['subscriptions'] = $subscriptions;
$et->data['subscriptionList'] = $subscriptionList;
$et->data['messages'] = $messages;
$et->data['messages_total'] = $messages_total;
$et->data['external_messengers'] = $janus_config->getArray('messenger.external');
$et->data['current_page'] = $page;
$et->data['last_page'] = ceil((double) $messages_total / $pm->getPaginationCount());
$et->data['selectedtab'] = $selectedtab;
$et->data['logouturl'] = SimpleSAML_Module::getModuleURL('core/authenticate.php') . '?logout';
$et->data['arp_attributes'] = $arp_attributes;
$et->data['arp_restricted_value_attributes'] = $janus_config->getValue('attributes.restrict_values');
$et->data['users'] = $mcontrol->getUsers();
if (isset($old_entityid)) {
    $et->data['old_entityid'] = $old_entityid;
}
if (isset($old_entitytype)) {
    $et->data['old_entitytype'] = $old_entitytype;
}
if (isset($msg)) {
    $et->data['msg'] = $msg;
}
$et->show();
$authsource = $janus_config->getValue('auth', 'login-admin');
$useridattr = $janus_config->getValue('useridattr', 'eduPersonPrincipalName');
if ($session->isValid($authsource)) {
    $attributes = $session->getAttributes();
    // Check if userid exists
    if (!isset($attributes[$useridattr])) {
        throw new Exception('User ID is missing');
    }
    $userid = $attributes[$useridattr][0];
} else {
    SimpleSAML_Utilities::redirect(SimpleSAML_Module::getModuleURL('janus/index.php'));
}
$econtroller = new sspmod_janus_UserController($janus_config);
$usertypes = $janus_config->getValue('usertypes');
$et = new SimpleSAML_XHTML_Template($config, 'janus:newuser.php', 'janus:newuser');
if (isset($_POST['submit'])) {
    $user = new sspmod_janus_User($janus_config->getValue('store'));
    $user->setUserid($_POST['userid']);
    $user->setType($_POST['type']);
    $user->setActive('yes');
    $user->save();
    $et->data['user_created'] = TRUE;
    $pm = new sspmod_janus_Postman();
    $pm->post('New user created', 'A new user has been created with username: '******'USER-NEW', $user->getUid());
}
if (isset($_GET['userid'])) {
    $et->data['userid'] = $_GET['userid'];
}
$et->data['users'] = $econtroller->getUsers();
$et->data['usertypes'] = $usertypes;
$et->show();