/**
 * request the status of multiple envelopes in a single call. Up to 200
 * envelopes can be retrieved
 * @return RequestStatusesExResponse
 */
function requestStatusesExSample()
{
    global $api;
    global $AccountID;
    // Create and send an envelope
    $env1 = createBasicEnvelope($AccountID, "request statuses 1 sample");
    $env1 = createEnvelopeWithDocumentAndTabs($env1);
    $createAndSendEnvelopeparams1 = new CreateAndSendEnvelope();
    $createAndSendEnvelopeparams1->Envelope = $env1;
    $createResult1 = $api->CreateAndSendEnvelope($createAndSendEnvelopeparams1)->CreateAndSendEnvelopeResult;
    // Create, send, and void another envelope
    $env2 = createBasicEnvelope($AccountID, "request status sample");
    $env2 = createEnvelopeWithDocumentAndTabs($env2);
    $createAndSendEnvelopeparams2 = new CreateAndSendEnvelope();
    $createAndSendEnvelopeparams2->Envelope = $env2;
    $createResult2 = $api->CreateAndSendEnvelope($createAndSendEnvelopeparams2)->CreateAndSendEnvelopeResult;
    $voidEnvelopeparams = new VoidEnvelope();
    $voidEnvelopeparams->EnvelopeID = $createResult2->EnvelopeID;
    $voidEnvelopeparams->Reason = "void envelope for PurgeDocuments sample";
    $voidResult = $api->VoidEnvelope($voidEnvelopeparams);
    // Create a filter using account ID and today as a start time
    $envStatusFilter = new EnvelopeStatusFilter();
    $envStatusFilter->AccountId = $AccountID;
    $beginDateTime = new EnvelopeStatusFilterBeginDateTime();
    $beginDateTime->_ = todayXsdDate();
    $envStatusFilter->BeginDateTime = $beginDateTime;
    // Send
    $requestStatusesExparams = new RequestStatusesEx();
    $requestStatusesExparams->EnvelopeStatusFilter = $envStatusFilter;
    $response = $api->RequestStatusesEx($requestStatusesExparams);
    return $response;
}
function getToken($status, $clientID)
{
    global $_oneSigner;
    $token = null;
    $_SESSION["embedToken"];
    // get recipient token
    $assertion = new RequestRecipientTokenAuthenticationAssertion();
    $assertion->AssertionID = guid();
    $assertion->AuthenticationInstant = todayXsdDate();
    $assertion->AuthenticationMethod = RequestRecipientTokenAuthenticationAssertionAuthenticationMethod::Password;
    $assertion->SecurityDomain = "DocuSign2011Q1Sample";
    // Get Recipient fro ClientID
    $recipient = false;
    foreach ($status->RecipientStatuses->RecipientStatus as $rs) {
        if ($rs->ClientUserId == $clientID) {
            $recipient = $rs;
        }
    }
    if ($recipient == false) {
        $_SESSION["errorMessage"] = "Unable to find Recipient";
        header("Location: error.php");
    }
    $urls = new RequestRecipientTokenClientURLs();
    $urlbase = getCallbackURL("pop.html") . "?source=Embedded";
    $urls->OnAccessCodeFailed = $urlbase . "&event=AccessCodeFailed&uname=" . $recipient->UserName;
    $urls->OnCancel = $urlbase . "&event=Cancel&uname=" . $recipient->UserName;
    $urls->OnDecline = $urlbase . "&event=Decline&uname=" . $recipient->UserName;
    $urls->OnException = $urlbase . "&event=Exception&uname=" . $recipient->UserName;
    $urls->OnFaxPending = $urlbase . "&event=FaxPending&uname=" . $recipient->UserName;
    $urls->OnIdCheckFailed = $urlbase . "&event=IdCheckFailed&uname=" . $recipient->UserName;
    $urls->OnSessionTimeout = $urlbase . "&event=SessionTimeout&uname=" . $recipient->UserName;
    $urls->OnTTLExpired = $urlbase . "&event=TTLExpired&uname=" . $recipient->UserName;
    $urls->OnViewingComplete = $urlbase . "&event=ViewingComplete&uname=" . $recipient->UserName;
    if ($_oneSigner) {
        $urls->OnSigningComplete = $urlbase . "&event=SigningComplete&uname=" . $recipient->UserName;
    } else {
        $urls->OnSigningComplete = getCallbackURL("pop2.html") . "?envelopeID=" . $status->EnvelopeID;
    }
    $api = getAPI();
    $rrtParams = new RequestRecipientToken();
    $rrtParams->AuthenticationAssertion = $assertion;
    $rrtParams->ClientURLs = $urls;
    $rrtParams->ClientUserID = $recipient->ClientUserId;
    $rrtParams->Email = $recipient->Email;
    $rrtParams->EnvelopeID = $status->EnvelopeID;
    $rrtParams->Username = $recipient->UserName;
    try {
        $token = $api->RequestRecipientToken($rrtParams)->RequestRecipientTokenResult;
    } catch (SoapFault $e) {
        $_SESSION["errorMessage"] = $e;
        header("Location: error.php");
    }
    $_SESSION["embedToken"] = $token;
}