<?xml version="1.0"?>
<%@ page contentType="text/xml" %>
  <vxml>
<!-- Reads the message header and asks what the user wants to do next. Redirects to EmailServlet with request type the user specifies. -->

    <!-- grammer for choosing help option -->
    <grammar>
      <![CDATA[[
      [help (help_me) (assist me please)] {<option "help">} ]
      ]]>
    </grammar>
    <form>
      <block>
        <% 
	int msgnum = Integer.parseInt((String)request.getAttribute("msgnum"));
	String header = (String)request.getAttribute("header");
	String readnew = (String)session.getAttribute("readnew");
	if(header != null && readnew!=null) {
	  out.println("<audio>");
	  out.println("<![CDATA["); // Read the message header
	  out.println(header);
	  out.println("]]>");
	  out.println("</audio>");
	}
	else {
	  out.println("<audio>");
	  out.println("An error has occured trying to read this header.  Please call back and try again.");
	  out.println("</audio>");
	  out.println ("<disconnect/>");
	}
        %>
	<goto next="#menu"/> 
      </block>
    </form>

    <!-- Ask what the use wants to do next -->
    <menu id="menu" dtmf="true">
      <prompt>
	<audio>
	  Say listen, reply, delete, next, or previous.  For complete menu options, say help.
	</audio>
	<audio src="http://resources.tellme.com/audio/earcons/timeout.wav"/>
      </prompt>
      <%
      // List choices
      out.println("<choice dtmf=\"3\" next=\"apps.email.EmailServlet?action=dispmsg&amp;msgnum="+msgnum+"\">([listen (dtmf-3)])</choice>");
      out.println("<choice dtmf=\"1\" next=\"apps.email.EmailServlet?action=record&amp;msgnum="+msgnum+"\">([reply (dtmf-1)])</choice>");
      out.println("<choice dtmf=\"6\" next=\"apps.email.EmailServlet?action=delmsg&amp;msgnum="+msgnum+"\">([delete (dtmf-6)])</choice>");          
      out.println("<choice dtmf=\"9\" next=\"apps.email.EmailServlet?action=disphdr&amp;msgnum="+(msgnum+1)+"\">([next (dtmf-9)])</choice>");
      out.println("<choice dtmf=\"7\" next=\"apps.email.EmailServlet?action=disphdr&amp;msgnum="+(msgnum-1)+"\">([previous (dtmf-7)])</choice>");
      if (readnew.equals("true"))
      out.println("<choice dtmf=\"2\" next=\"apps.email.EmailServlet?action=disphdr&amp;msgnum=1&amp;readnew=false\">([old (dtmf-2)])</choice>");
      else
      out.println("<choice dtmf=\"2\" next=\"apps.email.EmailServlet?action=disphdr&amp;msgnum=1&amp;readnew=true\">([new (dtmf-2)])</choice>");
      out.println("<choice dtmf=\"4\" next=\"apps.email.EmailServlet?action=compose&amp;msgnum=1\">([compose (dtmf-4)])</choice>");
      out.println("<choice dtmf=\"5\" next=\"apps.email.EmailServlet?action=forward&amp;msgnum="+msgnum+"\">([forward (dtmf-5)])</choice>");
      %>
      <!-- if chooses 8, skip to jump -->
      <choice dtmf="8" next="#jump">([jump (dtmf-8)])</choice>
      <default><reprompt/></default>
      <noinput><reprompt/></noinput>
      <!-- help option -->
      <help>
	<audio>
	  <%
	  if(readnew.equals("true"))
	  out.println("To listen to this message, say listen or press 3, to reply to this message, say reply or press 1, to delete this message, say delete or press 6, to forwrd this message, say forward or press 5, to go to the next message, say next or press 9, to go to the previous message, say previous or press 7, to jump to a specific message number, says jump or press 8, to listen to your old messages, say old or press 2, to compose a new message, say compose or press 4, or to end this session, hang up now.");
	  else 
	  out.println("To listen to this message, say listen or press 3, to reply to this message, say reply or press 1, to delete this message, say delete or press 6, to forward this message, say forward or press 5, to go to the next message, say next or press 9, to go to the previous message, say previous or press 7, to jump to a specific message number, says jump or press 8, to listen to your new messages, say new or press 2, to compose a new message, say compose or press 4, or to end this session, hang up now.");
	  %>
	</audio>
	<reprompt/>
      </help>
    </menu>
    
    <!-- option to jump to a specific message -->
    <form id="jump">
      <field name="messnum">
	<!-- Grammer for capturing any arbirary number of DTMF digits -->
	<grammar>   
	  <![CDATA[
	  TM_DTMF_DigitString
	  ]]>
	</grammar>    
	<!-- Tell the user the number of messages the user has -->
	<prompt>    
	  <%
	  if(readnew.equals("true")) 
	  out.println("<audio>You have "+session.getAttribute("newmsgnum")+" new messages.</audio>");
	  else
	  out.println("<audio>You have "+session.getAttribute("oldmsgnum")+" old messages.</audio>");
	  %>
	  <!-- Get the message number -->
	  <audio>Message Number?</audio>   
	  <audio src="http://resources.tellme.com/audio/earcons/timeout.wav"/>
	</prompt>     
	<noinput><audio>I'm sorry I didn't get that.</audio>
	  <reprompt/></noinput>
	<!-- Send the next request to EmailServlet -->
	<filled>   
	  <goto next="apps.email.EmailServlet?action=chkmsg&amp;msgnum={messnum}"/>
	</filled>
      </field>
    </form>
  </vxml>
  


