$entity = array_pop($entities);
$metadata = $entity->getMetadata20SP();
} else {
$metadata = array('owner' => $userid);
}
$editor = new sspmod_metaedit_MetaEditor();
if (isset($_POST['submit'])) {
$editor->checkForm($_POST);
$metadata = $editor->formToMeta($_POST, array(), array('owner' => $userid));
if (isset($_REQUEST['was-entityid']) && $_REQUEST['was-entityid'] !== $metadata['entityid']) {
$premetadata = $mdh->getMetadata($_REQUEST['was-entityid'], 'saml20-sp-remote');
requireOwnership($premetadata, $userid);
$mdh->deleteMetadata($_REQUEST['was-entityid'], 'saml20-sp-remote');
}
$testmetadata = NULL;
try {
$testmetadata = $mdh->getMetadata($metadata['entityid'], 'saml20-sp-remote');
} catch (Exception $e) {
}
if ($testmetadata) {
requireOwnership($testmetadata, $userid);
}
$mdh->saveMetadata($metadata['entityid'], 'saml20-sp-remote', $metadata);
$template = new SimpleSAML_XHTML_Template($config, 'metaedit:saved.php');
$template->show();
exit;
}
$form = $editor->metaToForm($metadata);
$template = new SimpleSAML_XHTML_Template($config, 'metaedit:formedit.php');
$template->data['form'] = $form;
$template->show();