<apex:page controller="InterFaxController" action="{!listAttachments}">

    <apex:pageMessages />
    <apex:pageBlock title="Content from Record"  >
        
        <apex:form >
        
            <apex:pageBlockSection title="Send Outbound Fax"  columns="1">
             <apex:pageBlockSectionItem >
                    Fax Number: <apex:inputText value="{!faxNumber}" id="test" />
             </apex:pageBlockSectionItem>
        <apex:outputLabel >Attachments</apex:outputLabel>   
        <apex:pageBlockTable value="{!attachments}" var="att">
            <apex:column headerValue="Select">
                <!-- <apex:selectRadio value="{!attachmentId}" >
                    <apex:selectOption itemValue="{!att.id}" />
                </apex:selectRadio> -->
                <input type="radio" name="Select" value="{!att.id}" onclick="changeValue(this,'{!$Component.OutboundRadioButtonValue}');" />
            </apex:column>
            <apex:column headerValue="File Name"> <a href="/servlet/servlet.FileDownload?file={!att.id}" target="_new">{!att.name} </a> </apex:column>
           <apex:column headerValue="Content Type" value="{!att.contenttype}" > </apex:column>
           
        </apex:pageBlockTable>
                    <apex:outputPanel >
            <apex:commandButton value="Send Fax" action="{!sendFaxAttachment}"/>
                </apex:outputPanel>
                <apex:outputLabel >Files</apex:outputLabel>
        <apex:pageBlockTable value="{!files}" var="file">

            <apex:column headerValue="Select">

                <input type="radio" name="Select" value="{!file.id}" onclick="changeValue(this,'{!$Component.OutboundRadioButtonValue}');" />

            </apex:column>

            <apex:column headerValue="File Name"> <a href="/sfc/servlet.shepherd/document/download/{!file.Id}" target="_new">{!file.title} </a> </apex:column>

           <apex:column headerValue="Content Type" value="{!file.FileType}" > </apex:column>

        </apex:pageBlockTable>
            <apex:outputPanel >
            <apex:commandButton value="Send Fax" action="{!sendFax}"/>
                </apex:outputPanel>
                </apex:pageBlockSection>
             <apex:pageBlockSection title="Outbound Fax Detail"  columns="1">
                 <apex:commandButton value="Get All Outbound Faxes" action="{!fetchOutboundFaxes}" />
                 
                         <apex:pageBlockTable value="{!listOutboundFaxes}" var="outboundFax" rendered="{!listOutboundFaxes.size>0}">
                             <apex:column headerValue="TransactionID" value="{!outboundFax.id1}" ></apex:column>                            
                             <apex:column headerValue="Submitted Date" value="{!outboundFax.submitTime}" ></apex:column>
                             <apex:column headerValue="Completion Time" value="{!outboundFax.completionTime}" ></apex:column>
                             <apex:column headerValue="Destination" value="{!outboundFax.destinationFax}" ></apex:column>
                             <apex:column headerValue="Pages Sent" value="{!outboundFax.pagesSent}" ></apex:column>
                             <apex:column headerValue="Subject" value="{!outboundFax.subject}" ></apex:column>
                             <apex:column headerValue="Status" value="{!outboundFax.status}" ></apex:column>
                        </apex:pageBlockTable>
            </apex:pageBlockSection>
            
                         <apex:pageBlockSection title="Inbound Fax Detail"  columns="1">
                         
                 <apex:commandButton value="Get All Inbound Faxes" action="{!fetchInboundFaxes}" />
                         <apex:outputPanel rendered="{!listInboundFaxes.size == 0}">
                             <apex:outputLabel > No Inbound Fax Details found </apex:outputLabel>
                          </apex:outputPanel>
                          
                         <apex:pageBlockTable value="{!listInboundFaxes}" var="inbound" rendered="{!listInboundFaxes.size>0}">
                            
                             <!--<apex:column headerValue="User ID" value="{!inbound.userId}" ></apex:column>-->
                             <apex:column headerValue="MessageID" value="{!inbound.messageId}" ></apex:column>
                             <apex:column headerValue="Fax Number" value="{!inbound.phoneNumber}" ></apex:column>
                             <apex:column headerValue="Receive Time" value="{!inbound.receiveTime}" ></apex:column>
                             <apex:column headerValue="Pages" value="{!inbound.pages}" ></apex:column>
                             <apex:column headerValue="Remote CSID" value="{!inbound.remoteCSID}" ></apex:column>
                             <apex:column headerValue="Caller ID" value="{!inbound.callerId}" ></apex:column>
                             <apex:column headerValue="Select">
                                 <!-- <apex:selectRadio value="{!messageId}">
                                    <apex:selectOption itemValue="{!inbound.messageId}" />
                                 </apex:selectRadio> -->
                                 <input type="radio" name="InboundSelection" value="{!inbound.messageId}" onclick="changeValue(this,'{!$Component.InboundRadioButtonValue}');" />
                             </apex:column>
                        </apex:pageBlockTable>
                        <apex:outputPanel >
                            <apex:commandButton value="Preview" action="{!getRenderPDF}"/>
                            <apex:commandButton value="Save as Attachment" action="{!getInboundImage}"/>
                            <apex:commandButton value="Save as File" action="{!getInboundContent}"/>
                        </apex:outputPanel>
                        <apex:pageBlockSection title="Fax Viewer"  columns="1">
                        <apex:outputPanel rendered="{!faxViewer}">
                            <apex:iframe src="data:application/pdf;base64,{!PDF}"/>
                        </apex:outputPanel>
                        </apex:pageBlockSection>
                </apex:pageblockSection>
            <apex:inputHidden value="{!attachmentId}" id="OutboundRadioButtonValue" />
            <apex:inputHidden value="{!messageId}" id="InboundRadioButtonValue" />

</apex:form>
    <!-- <apex:outputText value="Inbound Transaction ID #{!messageId} Saved Successfully" id="out"/> -->
    <script>
        function changeValue(input, textid) {
            document.getElementById(textid).value = input.value;
        }
    </script>
    </apex:pageBlock>
</apex:page>