if (isset($_POST['arp_edit'])) {
    $arp = new sspmod_janus_ARP();
    if (isset($_POST['arp_id'])) {
        $arp->setAid((int) $_POST['arp_id']);
    }
    if (isset($_POST['arp_name'])) {
        $arp->setName($_POST['arp_name']);
    }
    if (isset($_POST['arp_description'])) {
        $arp->setDescription($_POST['arp_description']);
    }
    if (isset($_POST['arp_is_default'])) {
        $arp->setDefault();
    }
    if (isset($_POST['arp_attributes'])) {
        $arp->setAttributes($_POST['arp_attributes']);
    }
    $arp->save();
}
$subscriptions = $pm->getSubscriptions($user->getUid());
$subscriptionList = $pm->getSubscriptionList();
if (isset($_GET['page'])) {
    $page = $_GET['page'];
    $messages = $pm->getMessages($user->getUid(), $page);
} else {
    $page = 1;
    $messages = $pm->getMessages($user->getUid());
}
$messages_total = $pm->countMessages($user->getUid());
// Entity filter
$entity_filter = null;
    }
}
echo '<h1>SAML20 SP</h1>';
include 'saml20-sp-remote.php';
foreach ($metadata as $key => $val) {
    $msg = $mcontrol->createNewEntity($key, 'saml20-sp');
    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 == 'attributes') {
                $arp = new sspmod_janus_ARP();
                $arp->setName($key);
                $arp->setAttributes($v);
                $arp->save();
                $econtroller->setArp($arp->getAid());
            }
            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/>';
                if (!$econtroller->addMetadata($k, $v)) {
                    $econtroller->updateMetadata($k, $v);
                    echo 'Updated<br>';