}
if (!is_object($pae)) {
    $pae = false;
}
$pd = false;
if ($_REQUEST['pdID']) {
    $pd = PermissionDuration::getByID($_REQUEST['pdID']);
}
if (!is_object($pd)) {
    $pd = false;
}
if ($_POST['task'] == 'save_permissions') {
    $js = Loader::helper('json');
    $r = new stdClass();
    if (is_object($pae)) {
        $pd = PermissionDuration::translateFromRequest();
    } else {
        $r->error = true;
        $r->message = t('You must choose who this permission is for.');
    }
    if (!$r->error) {
        $r->peID = $pae->getAccessEntityID();
        if (is_object($pd)) {
            $r->pdID = $pd->getPermissionDurationID();
        } else {
            $r->pdID = 0;
        }
    }
    print $js->encode($r);
    exit;
}