$msg = 'error_user_not_created';
            } else {
                SimpleSAML_Utilities::redirect(SimpleSAML_Utilities::selfURLNoQuery(), array('selectedtab' => $selectedtab));
            }
        }
    }
}
if (isset($_POST['submit'])) {
    if (!empty($_POST['entityid'])) {
        if (check_uri($_POST['entityid'])) {
            if (!isset($_POST['entityid']) || empty($_POST['entitytype'])) {
                $msg = 'error_no_type';
                $old_entityid = $_POST['entityid'];
                $old_entitytype = $_POST['entitytype'];
            } else {
                $msg = $mcontrol->createNewEntity($_POST['entityid'], $_POST['entitytype']);
                if (is_int($msg)) {
                    $entity = new sspmod_janus_Entity($janus_config);
                    $pm->subscribe($user->getUid(), 'ENTITYUPDATE-' . $msg);
                    $directlink = SimpleSAML_Module::getModuleURL('janus/editentity.php', array('eid' => $msg));
                    $pm->post('New entity created', 'Permalink: <a href="' . $directlink . '">' . $directlink . '</a><br /><br />A new entity has been created.<br />Entityid: ' . $_POST['entityid'] . '<br />Entity type: ' . $_POST['entitytype'], 'ENTITYCREATE', $user->getUid());
                    SimpleSAML_Utilities::redirect(SimpleSAML_Module::getModuleURL('janus/editentity.php'), array('eid' => $msg));
                }
            }
        } else {
            $msg = 'error_entity_not_url';
            $old_entityid = $_POST['entityid'];
            $old_entitytype = $_POST['entitytype'];
        }
    } else {
        if (!empty($_POST['metadata_xml'])) {
    if (!isset($attributes[$useridattr])) {
        throw new Exception('User ID is missing');
    }
    $userid = $attributes[$useridattr][0];
} else {
    $session->setData('string', 'refURL', SimpleSAML_Utilities::selfURL());
    SimpleSAML_Utilities::redirect(SimpleSAML_Module::getModuleURL('janus/index.php'));
}
$mcontrol = new sspmod_janus_UserController($janus_config);
if (!($user = $mcontrol->setUser($userid))) {
    throw new SimpleSAML_Error_Exception('Error in setUser');
}
echo '<h1>SAML20 IdP</h1>';
include 'saml20-idp-remote.php';
foreach ($metadata as $key => $val) {
    $msg = $mcontrol->createNewEntity($key, 'saml20-idp');
    echo "Id: " . $msg . '<br />';
    if (is_int($msg)) {
        $econtroller = new sspmod_janus_EntityController($janus_config);
        $econtroller->setEntity((string) $msg);
        $econtroller->loadEntity();
        foreach ($val as $k => $v) {
            if ($k == 'name') {
                $k = 'entity:name';
            }
            if ($k == 'description') {
                $k = 'entity:description';
            }
            echo '<br>Key: ' . $k . '<br>';
            if (is_string($v)) {
                echo '<br/>Insert ' . $v . '<br/>';