<?PHP
//
// -----------------------------------------------------
// copyright 2000 by voxeo corporation. (see LGPL.txt)
//
// -----------------------------------------------------
//
// v1.0 Coded in Active Server Pages and PHP
// v1.0 Coded by David Grobleski
//
// This application contains both a Web Browser and a phone 
// interface to a consumer poll application similar to those 
// found on CNN.com or other news portals.
// The user is presented with a poll question, and a series 
// of possible responses.  When the user chooses a response, 
// he/she is given the complete poll results.
// Written in ASP as sample code on how to use CallXML and 
// backend scripting languages.  
//
// This zip file contains the following files:				 
//     consumerpoll.mdb		<---- The actual database file itself
//     dbInclude.inc		<---- abstracted ODBC database constants (ASP)
//     LGPL.txt				<---- opensource license agreement
//     readme.txt			<---- Readme file
//     consumerpoll.css		<---- Client side style sheet for web interface
//     default.php			<---- PHP version for introductory web interface
//     voxeo.php			<---- This file. PHP version for introductory phone interface
//     gatherpoll.php		<---- PHP version that gathers consumer inputs for
//								  both web and phone versions
//     default.asp			<---- ASP version for introductory web interface
//     voxeo.asp			<---- ASP version for introductory phone interface
//     gatherpoll.asp		<---- ASP version that gathers consumer inputs for
//								  both web and phone versions
//     consumerPoll.sql		<---- SQL Scripts to create SQL Version of Database
//								  if desired
//
//     Please ensure that IUSR_Webserver has Read/Write permissions 
//     on the Access Database (if you are using access).  If not, you will 
//     get an error similar to "The operation must be an updatable query".
//
//
// There is one image file that is used to build the graph for the results 
// screen on the web based interface.  It should be placed in a subfolder 
// called "images":
//
// Several audio files are associated with this application.  They 
// should be placed in a subfolder called "voice":
//
//     ad1.wav
//     herestheresults.wav
//     percent.wav
//     q2_options.wav
//     q2_question.wav
//     q2option1.wav
//     q2option2.wav
//     q2option3.wav
//     q2option4.wav
//     q2option5.wav
//     questionheader.wav
//     received.wav
//     represents.wav
//     resultsfooter.wav
//     resultsheader.wav
//     staytuned.wav
//     votes.wav
//
// All audio files are PCM format, 8-bit, mono, unsigned.
//
//------------------------------------------------------------------------

//------------------------------------------------------------------------
// Include file for DataBase constants 
//------------------------------------------------------------------------

include('database-win32.inc');

//----------------------------------------------------------------------
// database access routines for retreiving the question and corresponding
// answers out of the ODBC database
//----------------------------------------------------------------------

$sqlPoll = "select * from question Q left join answer A on Q.ID=A.QuestionID order by A.answerID";

$connPoll = OpenDatabase("ConsumerPoll");
$rsPoll = ReadDatabase($connPoll, $sqlPoll);

echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" .
"<callxml>" . 
"<assign var=\"audiourl\" value=\"http://orlweb1.voxeo.com/applications/consumerpoll/voice/\"/>";

//----------------------------------------------------------------------
// Loop through the recordset and dynamically build the html table to 
// display the questions and answers
//----------------------------------------------------------------------

  while ( $rsRow = FetchRowFromDatabase( $rsPoll ) ) {
    $Loopy++;
	if ($Loopy == 1) {  // Only display the question once

	echo "<playAudio format=\"audio/wav\" " .
				  "value=\"\$audiourl;questionheader.wav\" " .
				  "termDigits=\"\" " .
				  "clearDigits=\"TRUE\"/>";
				  
	echo "<playAudio format=\"audio/wav\" " .
				  "value=\"\$audiourl;" . GetResultFromRow( "voicequestion",   $rsRow, $rsPoll ) . "\" " .
				  "termDigits=\"\" " .
				  "clearDigits=\"TRUE\"/>";
	
	echo "<menu label=\"options_menu\" " .
				"repeat=\"1\" " .
				"format=\"audio/wav\" " .
				"value=\"\$audiourl;" . GetResultFromRow( "voiceoptions",   $rsRow, $rsPoll ) . "\" " .
				"maxTime=\"45s\" " .
				"termDigits=\"" . 
				$Loopy . "#\" " .
				"clearDigits=\"TRUE\">";
	} //end if
	
	echo "<onTermDigit value=\"" . $Loopy . "\">";
	echo "	<goto value=\"gatherpoll.asp?Presentation=callXML&amp;Answer=" . GetResultFromRow( "AnswerID",   $rsRow, $rsPoll ) . "\"/>";
	echo "</onTermDigit>";
	
	echo"<onTermDigit value=\"#\">" .
	"<goto value=\"#options_menu\"/>" .
	"</onTermDigit>";
}

echo "</menu></callxml>";

?>
