I'm defining global vars and assigning them for use later in my script.
This works fine in my first code section, which is a heredoc.
But any other time, I try to access the global vars, I get nothing,
it's like they aren't even set.
This script creates dynamic VXML for two environments, Voxeo and Visibridge.
I ned the <voice...> tag for Visibridge and not for Voxeo. I don't want to have to
check the UA each time I want to separate code based on the UA.
Where am I going wrong? Maybe I can't see the forest for the trees or don't
understand the global scope as well as I should.
I shortened the script so I could post here. If you need the whole script, it can be
obtained here: http://www.austinmetrobaseball.com/vxml/amblvxml.txt
<?
header('Cache-Control: no-cache');
header("content-type: text/xml");
global $UA;
global $vtag;
global $vtagend;
$UA = $_SERVER['HTTP_USER_AGENT'];
if (strpos($UA, 'VoxGateway') > 0) {
$vtag = "";$vtagend = "";
} else {
$vtag = "<voice name=\"'Microsoft Mary'\">";
$vtagend = "</voice>";
}
echo <<<MAIN
<?xml version="1.0" encoding="UTF-8"?>
<vxml version="2.0" xmlns="http://www.w3.org/2001/vxml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2001/vxml
http://www.w3.org/TR/voicexml20/vxml.xsd">
<meta name="maintainer" content="eshipman@yahoo.com" />
<!-- http://webhosting.voxeo.net/15417/www/ambl2.vxml -->
<var name="teamid" expr="0" />
<var name="team_name" />
<var name="team_pin" />
<var name="retrievedpin" />
<var name="gamenum" />
<var name="hometeam" />
<var name="homeid" />
<var name="homescore" />
<var name="visitteam" />
<var name="visitid" />
<var name="visitorscore" />
<var name="dow" />
<var name="month" />
<var name="day" />
<var name="time" />
<var name="fld" />
<form id="welcome">
<!--
**************
Play welcome message...
**************
-->
<block>
<prompt>$vtag Welcome to the Austin Metro Baseball League's Scores Reporting System. $vtagend </prompt>
<goto next="#team_info" />
</block>
</form>
<form id="team_info">
<field name="team_id">
<prompt count="1">$vtag Please say your team name or key in your Team I D. $vtagend </prompt>
<prompt count="2">$vtag Your Team Name or ID, please. $vtagend </prompt>
<!--
**************
This is an inline grammar of team names and IDs.
**************
-->
MAIN;
$UA = $_SERVER['HTTP_USER_AGENT'];
if (strpos($UA, 'VoxGateway') > 0)
{
// Voxeo
echo "\n";
echo ' <grammar type="application/srgs+xml" src="http://www.austinmetrobaseball.com/vxml/grammar/team2.grxml"/>';
echo "\n";
} else {
// Visibridge
echo "\n";
echo ' <grammar type="application/srgs+xml" src="http://www.austinmetrobaseball.com/vxml/grammar/team1.grxml"/>'."\n";
echo ' <grammar src="builtin:dtmf/digits"/>';
echo "\n";
}
echo <<<MAIN2
<help> Please say your team name or key in your Team ID.</help>
</field>
<!--
**************
Retrieve Team details from teamdetails.php so we can
check to see if the entered PIN matches
**************
-->
MAIN2;
$UA = $_SERVER['HTTP_USER_AGENT'];
if (strpos($UA, 'VoxGateway') > 0)
{
// Voxeo
echo "\n";
echo <<<EOT1
<filled>
<assign name="teamid" expr="team_id.id" />
<data name="domTeam" src="http://www.austinmetrobaseball.com/vxml/teamdetails.php" namelist="teamid" />
<assign name="document.retrievedpin" expr="domTeam.documentElement.getElementsByTagName('pin').item(0).firstChild.data" />
<assign name="document.team_name" expr="domTeam.documentElement.getElementsByTagName('name').item(0).firstChild.data" />
<goto next="#get_pin" />
</filled>
EOT1;
echo "\n";
} else {
// Visibridge
echo "\n";
echo <<<EOT1
<filled>
<log label="ID entered" expr="team_id" />
<assign name="teamid" expr="team_id" />
<assign name="document.teamid" expr="team_id" />
<data name="domTeam" src="http://www.austinmetrobaseball.com/vxml/teamdetails.php" namelist="teamid" />
<assign name="document.retrievedpin" expr="domTeam.pin[0]._text" />
<assign name="document.team_name" expr="domTeam.name[0]._text" />
<goto next="#get_pin" />
</filled>
EOT1;
echo "\n";
}
?>
</form>
<!-- Script shortened here...-->
<form id="enter_vscore">
<disconnect />
<!--
**************
Confirm the entered game details
**************
-->
<!--
<value expr="session.callerid " />
<prompt>
<? $vtag ?>
You have entered <value expr="visitteam"/> <value expr="visitscore"/> and
<value expr="hometeam"/> <value expr="homescore"/>
Is this correct?
<? $vtagend ?>
</prompt>
-->
</form>
</vxml>