// Revisin id has been set. Fetch the correct version of the entity
if ($revisionid > -1) {
    if (!($entity = $mcontroller->setEntity($eid, $revisionid))) {
        throw new SimpleSAML_Error_Exception('Error in setEntity');
    }
} else {
    // Revision not set, get latest
    if (!($entity = $mcontroller->setEntity($eid))) {
        throw new SimpleSAML_Error_Exception('Error in setEntity');
    }
}
// load entity
$mcontroller->loadEntity();
// Check if user is allowed to se entity
$guard = new sspmod_janus_UIguard($janus_config->getArray('access', array()));
$allowedUsers = $mcontroller->getUsers();
if (!(array_key_exists($userid, $allowedUsers) || $guard->hasPermission('allentities', null, $user->getType(), TRUE))) {
    SimpleSAML_Utilities::redirect(SimpleSAML_Module::getModuleURL('janus/index.php'));
}
$et = new SimpleSAML_XHTML_Template($config, 'janus:editentity.php', 'janus:editentity');
$language = $et->getLanguage();
$update = FALSE;
$note = '';
if (!empty($_POST)) {
    // Array for collecting addresses to notify
    $addresses = array();
    // Change entityID
    if (isset($_POST['entityid']) && $guard->hasPermission('changeentityid', $entity->getWorkflow(), $user->getType())) {
        if (check_uri($_POST['entityid']) || true) {
            # HACK: For SURFnetGuests : https://espee-test.surfnet.nl/federate/metadata/saml20/SURFnetGuests
            $entityIdNeedsUpdating = $_POST['entityid'] != $entity->getEntityid();