<% 
' Copyright 2000 Phone.com, Inc.  All rights reserved.
'
'   Subject to the terms and conditions of the SDK License Agreement,
'   Phone.com, Inc. hereby grants you the right to use the UP.SDK
'   software and its related documentation.
'
'   The Phone.com name and logo and the family of terms carrying the "UP."
'   prefix are trademarks of Phone.com, Inc. All other brands and product
'   names may be trademarks of the respective companies with which they
'   are associated.
'
' sendFax.asp
'
'   One  of a pair of examples to illustrate sending a FAX 
'   using the COM Object FAX library.
'
'   This example retieves information posted from the postFaxInfo.asp
'   example, containing the values to be included in a FAX request.

'   It then adds FAX content, text retrieved from a local file
'   to a digest using the FaxAddContentFromFile method.
'
'   Finally it presents a card to the user advising that it
'   dispatched the FAX in a digest.
'
' Declarations
Dim postString, myDigest, myFax, faxContentFile, aDeck
Dim RecipientFax, RecipientName, RecipientTel
Dim SenderName, SenderTel, SenderFax
Dim upFaxLimit, upFaxEncodings, upFaxAccepts

' Constants
'
' A newline (linefeed) is appended to each line of WML to
' aid legibility of source dumped to the Sim Info Window.
' 
nl              = Chr(10)

' Retrieve the server environment FAX variables; to later examine
' UP_FAX_ACCEPTS and confirm that the FAX Manager is available.
'
upFaxLimit      = Request.ServerVariables("HTTP_X_UP_FAX_LIMIT")
upFaxEncodings  = Request.ServerVariables("HTTP_X_UP_FAX_ENCODINGS")
upFaxAccepts    = Request.ServerVariables("HTTP_X_UP_FAX_ACCEPTS")

' Create a new COM Digest object.
'
set myDigest    = Server.CreateObject("PDCDigestUtils.CPDCDigest")

' Retrieve info posted from postFaxInfo earlier
'
If "POST" = Request.ServerVariables("REQUEST_METHOD") Then
    RecipientFax    = Request.Form("RecipientFax")
    RecipientName   = Request.Form("RecipientName")
    RecipientTel    = Request.Form("RecipientTel")
    SenderName      = Request.Form("SenderName")
    SenderTel       = Request.Form("SenderTel")
    SenderFax       = Request.Form("SenderFax")
    fdata           = "RecipientFax: 1-"  & RecipientFax  & "<br/>"   & nl
    fdata = fdata   & "RecipientName: "   & RecipientName & "<br/>"   & nl
    fdata = fdata   & "RecipientTel: "    & RecipientTel  & "<br/>"   & nl
    fdata = fdata   & "SenderName: "      & SenderName    & "<br/>"   & nl
    fdata = fdata   & "SenderTel: "       & SenderTel     & "<br/>"   & nl
    fdata = fdata   & "SenderFax: "       & SenderFax     & "<br/>"   & nl

    If Len(upFaxAccepts) > 0 AND upFaxAccepts <> "none" Then
    ' Confirmed a connection with an UPLink which accepts FAX.
    '
        Set myFax               = Server.CreateObject("PDCDigestUtils.CPDCFax")
        faxContentFile          = Server.MapPath("../scripts/fax.txt")

        ' Prepend "1" to the area code when dialing FAX number"
        myFax.RecipientFax      = "1" & RecipientFax

        myFax.RecipientName     = RecipientName
        myFax.RecipientTel      = RecipientTel
        myFax.SenderName        = SenderName
        myFax.SenderTel         = SenderTel
        myFax.SenderFax         = SenderFax
        myFax.FaxAddContentFromFile "text/plain", faxContentFile
        myFax.FaxSetCoverComments   "Fax cover sheet comments."
        myFax.FaxEnableCoverPage    1
        msg = "Dispatched a FAX in a digest at: "
        msg = msg & " " & Now()
        msg = msg & "<br/>" & fdata
    Else
        msg =       "The FAX Manager is not available. "    & nl
        msg = msg & "Is this connection using an UPLink "   & nl
        msg = msg & "which has a Fax Manager installed?"    & nl
        msg = msg & "<br/>" & fdata
    End If
Else
        msg = "No POST data received" & nl
End If

' A small WML deck.
'
aDeck   =         "<wml>" & nl
aDeck   = aDeck & "  <card>" & nl
aDeck   = aDeck & "    <p>" & nl
aDeck   = aDeck & "      " & msg & nl
aDeck   = aDeck & "    </p>" & nl
aDeck   = aDeck & "  </card>" & nl
aDeck   = aDeck & "</wml>" & nl

' Specify a deck of type WML to the digest object.
'
myDigest.DeckType       = 1

' Add the deck to the digest object.
'
myDigest.DigestAddDeck  "?", aDeck

If Len(upFaxAccepts) > 0 AND upFaxAccepts <> "none" Then
    myDigest.DigestAddFax    myFax
End If

' Suppress content type output within the digest to prevent a 
' server from encapsulating WML content within a second boundary.
'
myDigest.DigestSuppressContentType 1

' Serialize the digest into a single output buffer, digestString.
'
digestString            = myDigest.DigestSerialize(0)

' Specify content type through the server response, 
' rather than within the digest.
'
Response.ContentType    = myDigest.DigestGetContentType

' Write the response buffer to the client.
'
Response.BinaryWrite(digestString)

%>
