to HTML entities
$output = "";
if ($deck->ml == HAW_WML)
$temp = str_replace("$", "$$", $temp); // escape $ character in WML
elseif ($deck->ml == HAW_HDML)
$temp = str_replace("$", "&dol;", $temp); // escape $ character in HDML
if (strstr($deck->charset,"iso-8859-1"))
{
// character set iso-8859-1 (trivial mapping 1:1)
for ($i=0; $i 127)
// translate character into ...; sequence
$output .= "" . ord(substr($temp, $i, 1)) . ";";
else
// copy character unchanged
$output .= substr($temp, $i, 1);
}
}
else
{
// other character set than iso-8859-1
if ($deck->unicodearray)
{
// array with mapping rules was prepared earlier
if(!trim($temp))
return $temp;
while($temp!="")
{
// do for each character in string
if (ord(substr($temp,0,1))>127)
{
$index = ord(substr($temp, 0, 1)); // ASCII value of first character from $temp
if ($deck->unicodearray[$index])
{
// unicode stored for this one byte code
// insert unicode and go 1 byte further
$output .= "" . $deck->unicodearray[$index] . ";";
$temp = substr($temp, 1, strlen($temp));
}
else
{
// check if there's a unibyte code stored for 1st two bytes
$index = $index * 256 + ord(substr($temp, 1, 1));
if ($deck->unicodearray[$index])
{
// unicode stored for this 2-byte code!
// insert unicode and go 2 bytes further
$output .= "" . $deck->unicodearray[$index] . ";";
$temp = substr($temp, 2, strlen($temp));
}
else
{
// no mapping info for 1st 2 bytes available ==> leave it as it is
$output .= substr($temp, 0, 1);
$temp = substr($temp, 1, strlen($temp));
}
}
}
else
{
// character <= 127 ==> leave it as it is
$output .= substr($temp, 0, 1);
$temp = substr($temp, 1, strlen($temp));
}
}
}
else
$output = $temp; // no mapping to unicode required
}
return($output);
}
function HAW_voice_audio($text, $audio_src, $pause, $deck)
{
// print VoiceXML tags for audio output
if ($audio_src)
// play audio file if possible
printf("", $audio_src, $text);
else
// speak text only
echo $text;
if (($pause > 0) && $deck->supportsVXMLBreakTag)
printf("", $pause);
}
function HAW_voice_eventhandler($handler, $audio_array, $deck)
{
// create VoiceXML event handler, e.g. "help", "nomatch", "noinput"
if (count($audio_array) > 0)
{
while (list($key, $val) = each($audio_array))
{
if ($key > 0)
$count = sprintf(" count=\"%d\"", $key+1);
else
$count = "";
printf("", $count, $handler);
HAW_voice_audio(HAW_specchar($val["text"], $deck), $val["src"], 0, $deck);
if ($val["url"])
printf("", $val["url"]);
echo "\n";
}
}
}
function HAW_handle_forced_output(&$url, $hawoutput)
{
// add hawoutput query parameter to url in order to force special HAWHAW output type
if ($hawoutput)
{
// hawoutput parameter to be added
if (strchr($url, '?'))
$url .= "&hawoutput=" . $hawoutput;
else
$url .= "?hawoutput=" . $hawoutput;
}
}
class HAW_hdmlcardset
{
var $number_of_cards;
var $card; // array of cards
var $title;
var $final_action = ""; // action of last card
var $defaults; // default values of variables
var $disable_cache;
var $debug;
var $charset;
function HAW_hdmlcardset($title, $defaults, $disable_cache, $debug, $charset)
{
$this->title = $title;
$this->defaults = $defaults;
$this->disable_cache = $disable_cache;
$this->debug = $debug;
$this->charset = $charset;
// initialize first card of cardset as DISPLAY card
$this->card[0]["type"] = HAW_HDML_DISPLAY;
$this->card[0]["options"] = " name=\"1\"";
if ($title)
$this->card[0]["options"] .= " title=\"$title\"";
$this->number_of_cards = 1;
}
function add_display_content($display_content)
{
// enhance the display content of the current card with the received content
// number_of_cards-1 is the index of the current card, i.e. the last card
if ($this->card[$this->number_of_cards-1]["type"] == HAW_HDML_DISPLAY)
{
// current card is display card ==> continue with content
if (isset($this->card[$this->number_of_cards-1]["display_content"]))
$this->card[$this->number_of_cards-1]["display_content"] .= $display_content;
else
$this->card[$this->number_of_cards-1]["display_content"] = $display_content;
}
else
{
// current card is entry or choice card
// ==> create new display card to display received content
// ==> link current card to this new display card
$this->card[$this->number_of_cards]["type"] = HAW_HDML_DISPLAY;
$cardname = sprintf(" name=\"%d\"", $this->number_of_cards+1);
$this->card[$this->number_of_cards]["options"] .= $cardname;
if ($this->title)
$this->card[$this->number_of_cards]["options"] .= " title=\"$this->title\"";
$this->card[$this->number_of_cards]["display_content"] = $display_content;
$action = sprintf("\n",
$this->number_of_cards+1);
$this->card[$this->number_of_cards-1]["action"] = $action;
$this->number_of_cards++;
}
}
function make_ui_card($options, $generic_content, $cardtype)
{
// make user interactive card (ENTRY or CHOICE card)
if ($this->card[$this->number_of_cards-1]["type"] == HAW_HDML_DISPLAY)
{
// current card is display card
// ==> make an entry/choice card out of it
$this->card[$this->number_of_cards-1]["type"] = $cardtype;
// append options to the already existing ones
if (!isset($this->card[$this->number_of_cards-1]["options"]))
$this->card[$this->number_of_cards-1]["options"] = "";
$this->card[$this->number_of_cards-1]["options"] .= $options;
// append received content to the already existing one
if (!isset($this->card[$this->number_of_cards-1]["display_content"]))
$this->card[$this->number_of_cards-1]["display_content"] = "";
$this->card[$this->number_of_cards-1]["display_content"] .= $generic_content;
}
else
{
// current card is already entry or choice card
// ==> create new entry/choice card
// ==> link current card to this new entry/choice card
$this->card[$this->number_of_cards]["type"] = $cardtype;
$cardname = sprintf(" name=\"%d\"", $this->number_of_cards+1);
if (!isset($this->card[$this->number_of_cards]["options"]))
$this->card[$this->number_of_cards]["options"] = "";
$this->card[$this->number_of_cards]["options"] .= $cardname;
if ($this->title)
$this->card[$this->number_of_cards]["options"] .= " title=\"$this->title\"";
$this->card[$this->number_of_cards]["options"] .= $options;
$this->card[$this->number_of_cards]["display_content"] = $generic_content;
$action = sprintf("\n",
$this->number_of_cards+1);
$this->card[$this->number_of_cards-1]["action"] = $action;
$this->number_of_cards++;
}
}
function set_final_action($action)
{
$this->final_action = $action;
}
function create_hdmldeck()
{
if (!$this->debug)
{
$ct = sprintf("content-type: text/x-hdml;charset=%s", $this->charset);
header($ct);
}
$ttl = ($this->disable_cache ? " TTL=\"0\"" : "");
printf("\n", $ttl);
printf("\n", HAW_VERSION, HAW_COPYRIGHT);
// create NODISPLAY card if it's necessary to initialize variables
if ($this->defaults)
{
$vars = "";
while (list($d_key, $d_val) = each($this->defaults))
$vars .= sprintf("%s=%s&", $d_val['name'], $d_val['value']);
// strip terminating '&'
$vars = substr($vars, 0, -5);
echo "\n";
printf("\n", $vars);
echo "\n";
}
// set action of last card
$this->card[$this->number_of_cards-1]["action"] = $this->final_action;
// create all cards of card set
$i = 0;
while ( $i < $this->number_of_cards )
{
if ($this->card[$i]["type"] == HAW_HDML_DISPLAY)
$cardtype = "display";
elseif ($this->card[$i]["type"] == HAW_HDML_ENTRY)
$cardtype = "entry";
elseif ($this->card[$i]["type"] == HAW_HDML_CHOICE)
$cardtype = "choice";
printf("<%s%s>\n", $cardtype, $this->card[$i]["options"]);
printf("%s", $this->card[$i]["action"]);
printf("%s", $this->card[$i]["display_content"]);
printf("%s>\n", $cardtype);
$i++;
}
echo "\n";
}
};
/**
This class is the top level class of all HAWHAW classes. Your page should consist
of exactly one HAW_deck object. For WML browsers one deck with one card will be
generated. For HDML browsers one deck including as much cards as necessary will
generated. HTML browsers will receive a normal HTML page, PDA browsers will
receive handheldfriendly HTML etc.
Do not overload HAW_deck objects! Remember that a lot of older WAP devices can not
handle more than about 1400 byte of compiled data.
Examples:
$myPage = new HAW_deck();
$myPage = new HAW_deck("My WAP page");
$myPage = new HAW_deck("", HAW_ALIGN_CENTER);
$myPage = new HAW_deck("PDA edition", HAW_ALIGN_CENTER, HAW_OUTPUT_PDA);
...
$myPage->set_bgcolor("blue");
...
$myPage->add_text($myText);
...
$myPage->create_page();
*/
class HAW_deck
{
var $title;
var $alignment;
var $output;
var $timeout;
var $red_url;
var $disable_cache = false;
var $ml;
var $element = array();
var $number_of_elements;
var $number_of_forms;
var $number_of_linksets;
var $number_of_links;
var $number_of_phones;
var $top_banners;
var $number_of_top_banners = 0;
var $bottom_banners;
var $number_of_bottom_banners = 0;
var $display_banners = true;
var $waphome;
var $hdmlcardset;
// browser dependent properties
var $pureHTML = true; // Big-screen-HTML-code (default)
var $PDAstyle = false; // PDA browsers needs special HTML code
var $iModestyle = false; // cHTML too
var $upbrowser = false; // UP browser
var $owgui_1_3 = false; // Openwave GUI Extensions for WML 1.3
var $MMLstyle = false; // Mobile Markup Language
var $lynx = false; // Lynx text browser
var $xhtml = false; // XHTML MP (mobile profile)
var $gif_enabled = false; // browser can not deal with GIF images
var $submitViaLink = false; // use link instead of
var $supportsVXMLBreakTag = true; // false for PublicVoiceXML browser only
var $MotorolaVoiceXML = false; // for Motorola VoiceXML specifics
var $css_enabled = false; // support of cascading style sheets (HTML)
var $debug = false; // HAWHAW debugger off
var $hawoutput = ""; // no forced output
// device simulator properies
var $use_simulator = false; // decide whether default simulator device is to be used
var $skin = ""; // contains css url, where skinning is defined
// character set properties
var $charset = "iso-8859-1"; // default charset
var $unicodemaptab; // filename of cross mapping table to map country
// specific character code into unicode
var $unicodearray; // array containing cross mapping table
// language properties
var $language = "";
// display properties for HTML
// page background properties
var $bgcolor = "";
var $background = "";
// display (table) properties
var $border = 8;
var $disp_bgcolor = "";
var $disp_background = "";
var $width = "200px";
var $height = "200px";
// text properties
var $size = "";
var $color = "";
var $link_color = "";
var $vlink_color = "";
var $face = "";
var $fontstyle_attrbs = "";
// voice properties
var $voice_links = "";
var $voice_timeout = 0;
var $voice_text = "";
var $voice_audio_src = "";
var $voice_jingle = "";
var $voice_help = array();
var $voice_noinput = array();
var $voice_nomatch = array();
var $voice_property = array();
var $voice_navigator = array();
/**
Constructor
@param title (optional, default: HAW_NOTITLE)
If a string is provided here, it will be displayed
in the HTML title bar, respectively somewhere on the WAP display. Using a
title you will normally have to spend one of your few lines on your WAP
display. Consider that some WAP phones/SDK's and handheld devices don't
display the title at all.
@param alignment (optional, default: HAW_ALIGN_LEFT)
You can enter HAW_ALIGN_CENTER
or HAW_ALIGN_RIGHT to modify the alignment of the whole page.
@param output (optional, default: HAW_OUTPUT_AUTOMATIC)
You can override HAWHAW's automatic browser detection and force a certain
output type.
Possible value are:
HAW_OUTPUT_AUTOMATIC (default)
HAW_OUTPUT_BIGSCREEN
HAW_OUTPUT_WAP
HAW_OUTPUT_HDML
HAW_OUTPUT_PDA
HAW_OUTPUT_IMODE
HAW_OUTPUT_MML
HAW_OUTPUT_VOICEXML
HAW_OUTPUT_XHTML
HAW_OUTPUT_LYNX
With this parameter you can offer dedicated links for PC's, WAP phones, PDA's,
XHTML phones etc.
*/
function HAW_deck($title=HAW_NOTITLE, $alignment=HAW_ALIGN_LEFT, $output=HAW_OUTPUT_AUTOMATIC)
{
// determine environment variables
if (isset($_SERVER['HTTP_USER_AGENT']))
$HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
else
$HTTP_USER_AGENT = "";
if (isset($_SERVER['HTTP_ACCEPT']))
$HTTP_ACCEPT = $_SERVER['HTTP_ACCEPT'];
else
$HTTP_ACCEPT = "";
if (isset($_SERVER['HTTP_HOST']))
$HTTP_HOST = $_SERVER['HTTP_HOST'];
else
$HTTP_HOST = "";
if (isset($_SERVER['SCRIPT_NAME']))
$SCRIPT_NAME = $_SERVER['SCRIPT_NAME'];
else
$SCRIPT_NAME = "";
$this->set_title($title);
$this->set_alignment($alignment);
$this->timeout = 0;
$this->red_url = "";
$this->waphome = "http://" . $HTTP_HOST . $SCRIPT_NAME;
// query parameter "hawdebug" can be used to debug hawhaw output
// enter http://wap.yourdomain.com/yourscript.php?hawdebug=wap
// resp. other value defined above for HAW_OUTPUT_...
// query parameter "hawoutput" can be used for overwrite output type
// enter http://wap.yourdomain.com/yourscript.php?hawoutput=wap
global $HTTP_GET_VARS;
$forced_output = "";
if (isset ($HTTP_GET_VARS["hawdebug"]))
{
$forced_output = $HTTP_GET_VARS["hawdebug"];
$this->debug = true;
}
elseif (isset ($HTTP_GET_VARS["hawoutput"]))
{
$forced_output = $HTTP_GET_VARS["hawoutput"];
$this->hawoutput = $HTTP_GET_VARS["hawoutput"];
}
elseif ($output != HAW_OUTPUT_AUTOMATIC)
$forced_output = $output;
// manipulate HTTP environment variables in case of forced output
if ($forced_output)
{
if ($forced_output == HAW_OUTPUT_BIGSCREEN)
{
$HTTP_ACCEPT = "";
$HTTP_USER_AGENT = "MSIE";
}
elseif ($forced_output == HAW_OUTPUT_WAP)
{
$HTTP_ACCEPT = "text/vnd.wap.wml";
$HTTP_USER_AGENT = "";
}
elseif ($forced_output == HAW_OUTPUT_HDML)
{
$HTTP_ACCEPT = "hdml;version=3.0";
$HTTP_USER_AGENT = "";
}
elseif ($forced_output == HAW_OUTPUT_PDA)
{
$HTTP_ACCEPT = "";
$HTTP_USER_AGENT = "avantgo";
}
elseif ($forced_output == HAW_OUTPUT_IMODE)
{
$HTTP_ACCEPT = "";
$HTTP_USER_AGENT = "DoCoMo";
}
elseif ($forced_output == HAW_OUTPUT_MML)
{
$HTTP_ACCEPT = "";
$HTTP_USER_AGENT = "J-";
}
elseif ($forced_output == HAW_OUTPUT_VOICEXML)
{
$HTTP_ACCEPT = "text/x-vxml";
$HTTP_USER_AGENT = "Motorola VoxGateway/2.0";
}
elseif ($forced_output == HAW_OUTPUT_XHTML)
{
$HTTP_ACCEPT = "application/vnd.wap.xhtml+xml";
$HTTP_USER_AGENT = "";
}
elseif ($forced_output == HAW_OUTPUT_LYNX)
{
$HTTP_ACCEPT = "";
$HTTP_USER_AGENT = "Lynx";
}
elseif ($forced_output == HAW_OUTPUT_UP)
{
$HTTP_ACCEPT = "text/vnd.wap.wml";
$HTTP_USER_AGENT = "UP.Browser";
}
elseif ($forced_output == HAW_OUTPUT_OWGUI)
{
$HTTP_ACCEPT = "text/vnd.wap.wml";
$HTTP_USER_AGENT = "UP/GUI...UP.Link ";
}
elseif ($forced_output == HAW_OUTPUT_PVX)
{
$HTTP_ACCEPT = "";
$HTTP_USER_AGENT = "publicVoiceXML"; // user agent header of PublicVoiceXML browser
}
}
// determine markup language to create
if (strstr(strtolower($HTTP_USER_AGENT), "docomo") ||
strstr(strtolower($HTTP_USER_AGENT), "portalmmm") ||
strstr(strtolower($HTTP_USER_AGENT), "o2imode") ||
strstr(strtolower($HTTP_USER_AGENT), "opera ") ||
strstr(strtolower($HTTP_USER_AGENT), "reqwirelessweb") ||
strstr(strtolower($HTTP_ACCEPT), "vnd.wap.xhtml"))
{
$this->ml = HAW_HTML; // create HTML (even when device accepts text/vnd.wap.wml too!)
}
elseif (strstr(strtolower($HTTP_ACCEPT), "text/vnd.wap.wml"))
{
$this->ml = HAW_WML; // create WML
if (strstr($HTTP_USER_AGENT, "UP/") ||
strstr($HTTP_USER_AGENT, "UP.B"))
$this->upbrowser = true; // UP browser
if ((strstr($HTTP_USER_AGENT, "UP/") ||
strstr($HTTP_USER_AGENT, "UP.B")) &&
strstr($HTTP_USER_AGENT, "GUI") &&
strstr($HTTP_USER_AGENT, "UP.Link")) // Non-UP.Link gateways sometimes have problems!
$this->owgui_1_3 = true; // device accepts Openwave GUI extensions for WML 1.3
}
elseif (strstr(strtolower($HTTP_ACCEPT), "hdml;version=3.")) // HDML 3.0 and 3.1
$this->ml = HAW_HDML; // create HDML
elseif (strstr(strtolower($HTTP_ACCEPT), "vxml") || // VoiceXML signalled in accept header
strstr(strtolower($HTTP_ACCEPT), "voicexml") || // alternative accept header
strstr($HTTP_USER_AGENT, "OpenVXI") || // Speechworks OpenVXI
strstr(strtolower($HTTP_USER_AGENT), "publicvoicexml") || // PublicVoiceXML voice browser
strstr($HTTP_USER_AGENT, "Tellme")) // Tellme studio voice browser
{
$this->ml = HAW_VXML; // create VoiceXML
// PublicVoiceXML browser cannot handle elements!!!
if (strstr(strtolower($HTTP_USER_AGENT), "publicvoicexml"))
{
$this->supportsVXMLBreakTag = false;
}
// detect Motorola VoiceXML platform
if (strstr(strtolower($HTTP_USER_AGENT), "motorola"))
{
$this->MotorolaVoiceXML = true;
}
}
else
{
if (strstr($HTTP_USER_AGENT, "Mozilla") ||
strstr($HTTP_USER_AGENT, "MSIE") ||
strstr(strtolower($HTTP_USER_AGENT), "lynx") ||
strstr(strtolower($HTTP_USER_AGENT), "avantgo") ||
strstr(strtolower($HTTP_USER_AGENT), "pendragonweb") ||
strstr(strtolower($HTTP_USER_AGENT), "j-"))
$this->ml = HAW_HTML; // HTML-based browser
else
$this->ml = HAW_WML; // try it with WML
}
$this->number_of_elements = 0;
$this->number_of_forms = 0;
$this->number_of_linksets = 0;
$this->number_of_links = 0;
$this->number_of_phones = 0;
if (strstr(strtolower($HTTP_ACCEPT), "vnd.wap.xhtml"))
{
// XHTML device detected
$this->xhtml = true;
$this->pureHTML = false;
$this->display_banners = false;
$this->gif_enabled = true;
$this->css_enabled = true;
}
elseif ( strstr(strtolower($HTTP_USER_AGENT), "avantgo") ||
strstr(strtolower($HTTP_USER_AGENT), "reqwirelessweb") ||
strstr(strtolower($HTTP_USER_AGENT), "pendragonweb") ||
strstr(strtolower($HTTP_USER_AGENT), "palmos") ||
strstr(strtolower($HTTP_USER_AGENT), "windows ce") ||
strstr($HTTP_USER_AGENT, "Mozilla/4.7"))
{
// PDA browser detected (or poor old Netscape 4.7x which messes with CSS)
$this->PDAstyle = true;
$this->pureHTML = false;
$this->display_banners = false;
}
elseif (strstr(strtolower($HTTP_USER_AGENT), "docomo") ||
strstr(strtolower($HTTP_USER_AGENT), "portalmmm") ||
strstr(strtolower($HTTP_USER_AGENT), "o2imode"))
{
// i-mode browser detected
$this->iModestyle = true;
$this->pureHTML = false;
$this->display_banners = false;
}
elseif (strstr(strtolower($HTTP_USER_AGENT), "j-"))
{
// MML browser detected
$this->MMLstyle = true;
$this->pureHTML = false;
$this->display_banners = false;
}
elseif (strstr(strtolower($HTTP_USER_AGENT), "lynx"))
{
// text browser detected
$this->lynx = true;
$this->css_enabled = true; // enabled in the meaning of silently discarding it ...
$this->pureHTML = true;
$this->display_banners = false;
}
// determine if browser is CSS-enbled
if (($this->ml == HAW_HTML) &&
(strstr($HTTP_USER_AGENT, "MSIE") ||
strstr($HTTP_USER_AGENT, "Mozilla") ||
strstr($HTTP_USER_AGENT, "Opera")))
$this->css_enabled = true;
// determine if browser is able to display GIF images
if (($this->ml == HAW_HTML) ||
(strstr(strtolower($HTTP_ACCEPT), "image/gif")) ||
(strstr(strtolower($HTTP_USER_AGENT), "t68")))
$this->gif_enabled = true; // browsers can display GIF
// determine how forms are to be transmitted
if (strstr(strtolower($HTTP_USER_AGENT), "ericsson"))
$this->submitViaLink = true; // with Ericsson WAP devices it's quite difficult to submit WML forms
}
/**
Adds a HAW_text object to HAW_deck.
@param text Some HAW_text object.
@see HAW_text
*/
function add_text($text)
{
if (!is_object($text))
die("invalid argument in add_text()");
$this->element[$this->number_of_elements] = $text;
$this->number_of_elements++;
}
/**
Adds a HAW_image object to HAW_deck.
@param image Some HAW_image object.
@see HAW_image
*/
function add_image($image)
{
if (!is_object($image))
die("invalid argument in add_image()");
$this->element[$this->number_of_elements] = $image;
$this->number_of_elements++;
}
/**
Adds a HAW_table object to HAW_deck.
@param table Some HAW_table object.
@see HAW_table
*/
function add_table($table)
{
if (!is_object($table))
die("invalid argument in add_table()");
$this->element[$this->number_of_elements] = $table;
$this->number_of_elements++;
}
/**
Adds a HAW_form object to HAW_deck.
@param form Some HAW_form object.
@see HAW_form
*/
function add_form($form)
{
if (!is_object($form))
die("invalid argument in add_form()");
if ($this->number_of_forms > 0)
die("only one form per deck allowed!");
$this->element[$this->number_of_elements] = $form;
$this->number_of_elements++;
$this->number_of_forms++;
}
/**
Adds a HAW_link object to HAW_deck.
@param link Some HAW_link object.
@see HAW_link
*/
function add_link($link)
{
if (!is_object($link))
die("invalid argument in add_link()");
$this->element[$this->number_of_elements] = $link;
$this->number_of_elements++;
$this->number_of_links++;
}
/**
Adds a HAW_phone object to HAW_deck.
@param phone Some HAW_phone object.
@see HAW_phone
*/
function add_phone($phone)
{
if (!is_object($phone))
die("invalid argument in add_phone()");
$this->element[$this->number_of_elements] = $phone;
$this->number_of_elements++;
$this->number_of_phones++;
}
/**
Adds a HAW_linkset object to HAW_deck.
@param linkset Some HAW_linkset object.
@see HAW_linkset
*/
function add_linkset($linkset)
{
if (!is_object($linkset))
die("invalid argument in add_linkset()");
if ($this->number_of_linksets > 0)
die("only one linkset per deck allowed!");
$this->element[$this->number_of_elements] = $linkset;
$this->number_of_elements++;
$this->number_of_linksets++;
}
/*
Adds a HAW_raw object to HAW_deck. (undocumented feature - for test only!)
@param raw Some HAW_raw object.
@see HAW_raw
*/
function add_raw($raw)
{
if (!is_object($raw))
die("invalid argument in add_raw()");
$this->element[$this->number_of_elements] = $raw;
$this->number_of_elements++;
}
/*
Adds some user-defined HAWHAW object to HAW_deck (undocumented feature)
For skilled HAWHAW programmers only!
@param udef Some user-defined object.
*/
function add_userdefined($udef)
{
/* A user-defined HAWHAW class definition MUST look like this:
class HAW_foo // some class name of your choice
{
var $bar; // some class variable declarations of your choice
function HAW_foo(...)
{
// some constructor code of your choice
}
function HAW_boobaz(...)
{
// as many user-defined functions as needed
}
// this member function is called by HAWHAW and MUST NOT be changed!
function get_elementtype()
{
return HAW_USERDEFINED;
}
function create($deck)
{
// this member function is called by HAWHAW and MUST be present!
// it is in the programmers responsibility what kind of markup is created here!
// you have access to all HAW_deck properties by evaluating $deck
}
} ;
You have to define this class somewhere after your require("hawhaw.inc") statement
Usage: ...
$myText = new HAW_text("Classic text");
$myDeck->add_text($myText);
$myClass = new HAW_foo("Cool output");
$myClass->boobaz($ringtone, $sms, $userposition);
$myDeck->add_userdefined($myClass);
...
*/
if (!is_object($udef))
die("invalid argument in add_userdefined()");
$this->element[$this->number_of_elements] = $udef;
$this->number_of_elements++;
}
/**
Adds a HAW_banner object to HAW_deck.
Note: Has no effect on WML/handheld pages.
@param banner Some HAW_banner object.
@param position (optional)
HAW_TOP: above HAW_deck
HAW_BOTTOM: beneath HAW_deck (default)
@see HAW_banner
*/
function add_banner($banner, $position=HAW_BOTTOM)
{
if (!is_object($banner))
die("invalid argument in add_banner()");
if ($position == HAW_TOP)
{
$this->top_banners[$this->number_of_top_banners] = $banner;
$this->number_of_top_banners++;
}
else
{
$this->bottom_banners[$this->number_of_bottom_banners] = $banner;
$this->number_of_bottom_banners++;
}
}
/**
Adds a HAW_rule object to HAW_deck.
@param rule Some HAW_rule object.
@see HAW_rule
*/
function add_rule($rule)
{
if (!is_object($rule))
die("invalid argument in add_rule()");
$this->element[$this->number_of_elements] = $rule;
$this->number_of_elements++;
}
/**
Adds a HAW_voicerecorder object to HAW_deck.
@param voicerecorder Some HAW_voicerecorder object.
@see HAW_voicerecorder
*/
function add_voicerecorder($voicerecorder)
{
if (!is_object($voicerecorder))
die("invalid argument in add_voicerecorder()");
$this->element[$this->number_of_elements] = $voicerecorder;
$this->number_of_elements++;
}
/**
Redirects automatically after timeout to another URL.
Note: This feature can not be supported for HDML browsers, due to HDML's missing
timer functionality. If you intend to serve HDML users, you should consider this
by creating an additional link to red_url.
@param timeout Some timeout value in seconds.
@param red_url Some URL string.
*/
function set_redirection($timeout, $red_url)
{
$this->timeout = $timeout;
$this->red_url = $red_url;
}
/**
Disables deck caching in the users client.
Note: Use this object function, if you intend to provide changing content under
the same URL.
*/
function disable_cache()
{
$this->disable_cache = true;
}
/**
Enables mobile specific session support.
Note: Session handling for mobile devices is a little bit tricky. Cookies sometimes are
not supported by devices/gateways and transient session ID's are to be considered as
potential security issue. It is up to the programmer to decide which way to go by setting
the according control flags in php.ini.
This function is helpful in case that trans_sid session handling applies:
As XML does not allow unescaped '&' characters, the arg-separator has to be modified.
And as WML/VoiceXML defines tags which are not defined in HTML, the PHP predefined
url_rewriter tags have to be adapted.
Important: This function has be called before any session handling is done! Due to some
bugs in previous PHP versions, it is highly recommended to use PHP version 4.1.1 or
higher.
*/
function enable_session()
{
// set session server options
//ini_set('session.use_cookies', 0); // do not use cookies
//ini_set('session.use_trans_sid', 1); // use transient sid support
ini_set('arg_separator.output', '&'); // '&' is not allowed in WML (XML)
// url rewriter tags are dependent from markup language
switch ($this->ml)
{
case HAW_HTML:
{
ini_set('url_rewriter.tags', 'a=href,form=option');
break;
}
case HAW_WML:
{
ini_set('url_rewriter.tags', 'a=href,go=href,option=onpick');
break;
}
case HAW_HDML:
{
ini_set('url_rewriter.tags', 'a=href');
break;
}
case HAW_VXML:
{
ini_set('url_rewriter.tags', 'submit=next,link=next,goto=next');
break;
}
}
}
/**
Sets a given character set.
Note: For the iso-8859-1 character set all characters with value greater
127 are automatically transformed into a "&#dec;" sequence (unicode).
For all other character sets a specific cross mapping table is
required for the conversion into unicode. Usage of unicode cross
mapping tables is optional for non-iso-8859-1 character sets.
Mapping tables are available at:
http://www.unicode.org/Public/MAPPINGS/
@param charset Character set that is used in your country. Default: iso-8859-1
@param unicodemaptab (optional)
Cross mapping table from country specific character coding to
unicode (default: no mapping to unicode activated).
With this parameter you specify where HAWHAW will find the conversion table
with the mapping rules. It is recommended to store the cross mapping table
in the same directory where hawhaw.inc is located.
format: [PATH][Filename].[EXT] e.g. "../GB2312.TXT"
*/
function set_charset($charset, $unicodemaptab="")
{
$this->charset = $charset;
$this->unicodemaptab = $unicodemaptab;
if ($unicodemaptab)
{
// cross mapping table is to be used
if(!file_exists($unicodemaptab))
{
$errormsg = "HAWHAW! Cross mapping table \"$unicodemaptab\" not found! ";
$errormsg .= "Please download your country-specific unicode cross mapping table from: ";
$errormsg .= "http://www.unicode.org/Public/MAPPINGS/";
die("$errormsg");
}
// open cross mapping table file and create array with mapping info
$filename = $unicodemaptab;
$line=file($filename);
while(list($key,$value)=each($line))
{
if (substr($value, 0, 2) == "0x") // skip comment lines
{
$pair = explode(" ", $value); // tab separates code and unicode
if ((strlen($pair[0]) == 6) && ($pair[0] < 0x8080))
$this->unicodearray[hexdec($pair[0]) + 0x8080] = hexdec($pair[1]); // offset EUC
else
$this->unicodearray[hexdec($pair[0])] = hexdec($pair[1]);
}
}
}
}
/**
Sets a given language.
Note: Specifies the main language of the deck, as e.g. english, german,
japanese or whatever. Language declaration is highly recommended in order
to provide barrierfree content and as is required to validate a deck as
Bobby AAA approved!
@param language Language code according ISO 639, e.g. "en", "de", etc.
*/
function set_language($language)
{
$this->language = $language;
}
/**
Sets the window background color for a HTML (big-screen browser) page.
Has no effect on WML/handheld pages.
@param bgcolor See HTML specification for possible values (e.g. "#CCFFFF",
"red", ...).
*/
function set_bgcolor($bgcolor)
{
$this->bgcolor = $bgcolor;
}
/**
Sets a window wallpaper for a HTML (big-screen browser) page.
Has no effect on WML/handheld pages.
@param background e.g. "backgrnd.gif"
*/
function set_background($background)
{
$this->background = $background;
}
/**
Sets the thickness of the HTML display frame. Has no effect on WML/handheld pages.
@param border Thickness is pixels (default: 8)
*/
function set_border($border)
{
$this->border = $border;
}
/**
Sets the display background color for a (X)HTML page. Has no effect on
WML pages.
@param disp_bgcolor See HTML specification for possible values (e.g. "#CCFFFF",
"red", ...).
*/
function set_disp_bgcolor($disp_bgcolor)
{
$this->disp_bgcolor = $disp_bgcolor;
}
/**
Sets a display wallpaper for a (X)HTML page. Has no effect on WML
pages.
@param background e.g. "backgrnd.gif"
*/
function set_disp_background($background)
{
$this->disp_background = $background;
}
/**
Sets the display width for a HTML page. Has no effect on WML/handheld
pages.
@param width See HTML specification for possible values (e.g. "200px", "50%", ...).
*/
function set_width($width)
{
if (is_int($width))
$this->width = $width . "px"; // for compatibility reasons (until V5.10 HAWHAW interpreted int as px)
else
$this->width = $width;
}
/**
Sets the display height for a HTML page. Has no effect on WML/handheld
pages.
@param height See HTML specification for possible values (e.g. "200px", "50%", ...).
*/
function set_height($height)
{
if (is_int($height))
$this->height = $height . "px";
else
$this->height = $height;
}
/**
Sets the font size for all characters in a (X)HTML page. Has no effect on
WML pages.
@param size See HTML specification for possible values (e.g. "12pt", ...).
*/
function set_size($size)
{
$this->size = $size;
}
/**
Sets the color for all characters in a (X)HTML page. Has no effect on WML pages.
Nevertheless, HAW_text objects can overwrite this value by defining their own color
attributes.
@param color See HTML specification for possible values (e.g. "#CCFFFF", "red",
...).
@see HAW_text
*/
function set_color($color)
{
$this->color = $color;
}
/**
Sets the color of links in a (X)HTML page. Has no effect on
WML pages.
@param link_color See HTML specification for possible values (e.g. "#CCFFFF", "red",
...).
*/
function set_link_color($link_color)
{
$this->link_color = $link_color;
}
/**
Sets the color of visited links in a (X)HTML page. Has no effect on
WML pages.
@param vlink_color See HTML specification for possible values (e.g. "#CCFFFF", "red",
...).
*/
function set_vlink_color($vlink_color)
{
$this->vlink_color = $vlink_color;
}
/**
Sets the font for all characters in a (X)HTML page. Has no effect on
WML pages.
@param face See HTML specification for possible values (e.g. "Avalon",
"Wide Latin").
*/
function set_face($face)
{
$this->face = $face;
}
/**
Sets the deck title (see also HAW_deck constructor).
@param title deck title
*/
function set_title($title)
{
$this->title = $title;
}
/**
Sets the text alignment for the whole deck.
@param alignment text alignment
HAW_ALIGN_LEFT (default)
HAW_ALIGN_CENTER
HAW_ALIGN_RIGHT
*/
function set_alignment($alignment)
{
if ($alignment == HAW_ALIGN_CENTER)
$this->alignment = "center";
elseif ($alignment == HAW_ALIGN_RIGHT)
$this->alignment = "right";
else
$this->alignment = "left";
}
/**
Sets the URL of a website, a bigscreen-browsing user is invited to visit via WAP.
Note: On bigscreen browsers a small copyright link to the
HAWHAW information page will be created automatically by HAWHAW. The information
page invites the user to visit your site with a WAP phone.
Therefore by default your hostname and your refering script will be part of this
copyright link. You can modify this value, e.g. if your application leads the
user across different pages, but you want to make visible the entry page only.
@param waphome Some URL string.
*/
function set_waphome($waphome)
{
$this->waphome = $waphome;
}
/**
Activates the device simulator on bigscreen browsers.
Note: If no skin is specified, the HAWHAW default skin is used.
HAWHAW output can be displayed in any kind of user-defined skin.
See
CSS file of the HAWHAW default skin for more info.
@param skin URL of CSS file, where skin is defined (optional)
*/
function use_simulator($skin="http://skin.hawhaw.de/skin.css")
{
$this->use_simulator = true;
$this->skin = $skin;
}
/**
Sets deck-related text to be spoken by voice browsers.
@param text Some introducing text that will be spoken before any other dialog or
text output is started.
@param audio_src Some audio file (e.g. *.wav file) to play (optional).
*/
function set_voice_text($text, $audio_src="")
{
if (!is_string($text))
die("invalid argument in set_voice_text()");
$this->voice_text = $text;
$this->voice_audio_src = $audio_src;
}
/**
Play jingle before link <label>s are spoken.
Note: Voice users can not distinguish between plain text and link text. Playing
a short jingle before each link will make voice navigation easier.
@param url Some wav-file.
*/
function set_voice_jingle($url)
{
if (!is_string($url))
die("invalid argument in set_voice_jingle()");
$this->voice_jingle = $url;
}
/**
Sets help text for voice browsers.
@param text Some helpful information concerning this deck.
@param audio_src Some audio file (e.g. *.wav file) to play (optional).
@param url Some other voice deck to go to (optional).
*/
function set_voice_help($text, $audio_src="", $url="")
{
if (!is_string($text))
die("invalid argument in set_voice_help()");
$arr["text"] = $text;
$arr["src"] = $audio_src;
$arr["url"] = $url;
$this->voice_help[] = $arr;
}
/**
Sets noinput text for voice browsers.
@param text Some text to inform the user that no input has been received.
@param audio_src Some audio file (e.g. *.wav file) to play (optional).
@param url Some other voice deck to go to (optional).
*/
function set_voice_noinput($text, $audio_src="", $url="")
{
if (!is_string($text))
die("invalid argument in set_voice_noinput()");
$arr["text"] = $text;
$arr["src"] = $audio_src;
$arr["url"] = $url;
$this->voice_noinput[] = $arr;
}
/**
Sets nomatch text for voice browsers.
@param text Some text to complain that user input was not recognized.
@param audio_src Some audio file (e.g. *.wav file) to play (optional).
@param url Some other voice deck to go to (optional).
*/
function set_voice_nomatch($text, $audio_src="", $url="")
{
if (!is_string($text))
die("invalid argument in set_voice_nomatch()");
$arr["text"] = $text;
$arr["src"] = $audio_src;
$arr["url"] = $url;
$this->voice_nomatch[] = $arr;
}
/**
Sets a name/value property pair for VoiceXML decks.
Attention: This function should be used by experienced VoiceXML developers
only! name/value combinations which are not compliant to the VoiceXML
standard or are not supported by the voice platform, will throw an
semantic error and terminate voice output. Please refer to the
W3C VoiceXML Recommendation (chapter 6.3)
for detailled info about valid name/value combinations.
@param name Name of property (e.g. "bargein", "timeout", etc.)
@param value Value of property (e.g. "false", "10s", etc.)
*/
function set_voice_property($name, $value)
{
$arr["name"] = $name;
$arr["value"] = $value;
$this->voice_property[] = $arr;
}
/**
Defines a DTMF/voice grammar to repeat or skip voice output.
This function enables voice users to repeat or skip voice output which
has been created by means of HAW_text objects.
For both repeat and forward at least one trigger criteria (DTMF or voice)
has to be defined.
HAW_text objects where user navigation should apply have to call set_voice_navigation().
@param repeat_dtmf DTMF key that triggers the repetition of the current output (e.g. "1", "2", "", etc.)
@param repeat_voice What the user has to say to repeat the current output (e.g. "repeat", "")
@param forward_dtmf DTMF key that terminates the current output (e.g. "0", "*", "", etc.)
@param forward_voice What the user has to say to continue with the next output (e.g. "forward", "")
@see HAW_text
*/
function set_voice_navigator($repeat_dtmf, $repeat_voice, $forward_dtmf, $forward_voice)
{
$repeat_dtmf = (string) $repeat_dtmf;
$forward_dtmf = (string) $forward_dtmf;
if (!ereg("^[0-9#\*]$", $repeat_dtmf) && !$repeat_voice)
die("at least one repeat indication required in set_voice_navigator()");
if (!ereg("^[0-9#\*]$", $forward_dtmf) && !$forward_voice)
die("at least one forward indication required in set_voice_navigator()");
$this->voice_navigator["repeat_dtmf"] = $repeat_dtmf;
$this->voice_navigator["repeat_voice"] = $repeat_voice;
$this->voice_navigator["forward_dtmf"] = $forward_dtmf;
$this->voice_navigator["forward_voice"] = $forward_voice;
}
/**
Smooth contiguous text sections.
Note: This function affects VoiceXML output only.
Voice decks often are assembled by some HAW_text objects. Each HAW_text
object creates a VoiceXML <block> element. On some voice browsers this
results in an interruptive speech synthesis. This function coalesces directly
neighbored HAW_text objects to one single HAW_text object and thus results in
a smoothed voice perception.
*/
function smooth_voice()
{
if ($this->ml == HAW_VXML)
{
// this function make sense for VoiceXML output only
$i = 0;
while (isset($this->element[$i]))
{
$current_element = $this->element[$i];
if (isset($this->element[$i+1]))
{
$next_element = $this->element[$i+1];
if (($current_element->get_elementtype() == HAW_PLAINTEXT) &&
($current_element->get_br() == 0) &&
($next_element->get_elementtype() == HAW_PLAINTEXT) &&
($next_element->get_br() == 0) &&
($current_element->get_attrib() == $next_element->get_attrib()))
{
// create single HAW_text object containing both text sections
$merged_text = new HAW_text($current_element->get_text() . " " . $next_element->get_text(),
$current_element->get_attrib());
// adopt line breaks from next element
$merged_text->set_br($next_element->get_br());
// replace old two objects with new object
array_splice($this->element, $i, 2, array($merged_text));
$this->number_of_elements--;
$i--; // continue with merged element
}
}
$i++;
}
}
}
/**
Get markup language evaluated for the detected browser.
(returns int and not void. Must update this documentation tool ...)
Example:
...
$myDeck = new HAW_deck();
if ($myDeck->get_markup_language() == HAW_VXML) {
// some VoiceXML stuff
}
else {
// some visual stuff
}
*/
function get_markup_language()
{
return $this->ml;
}
/**
Creates the page in the according markup language. Depending on the clients
browser type, HTML (pure HTML, handheldfriendly HTML, XHTML, i-mode cHTML, MML),
WML, HDML or VoiceXML is thrown out.
*/
function create_page()
{
global $haw_license_holder;
global $haw_license_domain;
global $haw_signature;
global $haw_sig_text;
global $haw_sig_link;
// add hawoutput query parameter to redirection url, if required
HAW_handle_forced_output($this->red_url, $this->hawoutput);
if ($this->debug)
header("content-type: text/plain");
if ($this->disable_cache)
header("cache-control: no-cache");
if ($this->ml == HAW_HTML)
{
// create HTML page header
if (!$this->debug)
{
if ($this->xhtml)
{
if ($this->lynx)
$ct = "content-type: text/html";
else
$ct = "content-type: application/vnd.wap.xhtml+xml";
}
else
$ct = sprintf("content-type: text/html;charset=%s", $this->charset);
header($ct);
}
if ($this->xhtml)
{
printf("\n", $this->charset);
if ($this->lynx)
echo "\n";
else
echo "\n";
}
elseif ($this->css_enabled)
echo "\n";
if ($this->language)
{
if ($this->xhtml)
$language = sprintf(" xml:lang=\"%s\"", $this->language);
else
$language = sprintf(" lang=\"%s\"", $this->language);
}
else
$language = "";
printf("\n", $language);
echo "\n";
// validation issue: HTML does not allow XHTML-stylish "/>" within part
// HTML has set option SHORTTAG=YES in SGML declaration
// ==> "/" closes the tag and ">" will be treated as text
// allows text, but does not!
if ($this->xhtml)
$endtag = "/>";
else
$endtag = ">";
if (!$this->iModestyle && !$this->MMLstyle)
{
// cHTML and MML don't support meta tags
if ($haw_license_domain)
$license = " - registered for $haw_license_domain";
else
$license = "";
printf("charset, $endtag);
printf("timeout > 0)
{
printf("timeout, HAW_specchar($this->red_url, $this), $endtag);
}
if ($this->disable_cache)
{
echo "PDAstyle)
{
echo "pureHTML || $this->PDAstyle || $this->xhtml)
{
if ($this->pureHTML)
{
// big-screen browser
if ($this->bgcolor)
{
// set background color (=window background color)
$bgcolor = " bgcolor=\"" . $this->bgcolor . "\"";
$bodystyle .= sprintf("background-color:%s; ", $this->bgcolor);
}
if ($this->background)
{
// set wallpaper (=window wallpaper)
$background = " background=\"" . $this->background . "\"";
$bodystyle .= sprintf("background-image:url(%s); ", $this->background);
}
// set display defaults, if not assigned by yet
if (!$this->disp_bgcolor)
$this->disp_bgcolor = HAW_DISP_BGCOLOR;
if (!$this->link_color)
$this->link_color = HAW_DISP_LINKCOLOR;
if (!$this->vlink_color)
$this->vlink_color = HAW_DISP_VLINKCOLOR;
if (!$this->face)
$this->face = HAW_DISP_FACE;
}
else
{
// XHTML or PDA
if ($this->disp_bgcolor)
{
// set background color of mobile device
$bgcolor = " bgcolor=\"" . $this->disp_bgcolor . "\"";
$bodystyle .= sprintf("background-color:%s; ", $this->disp_bgcolor);
}
if ($this->disp_background)
{
// set wallpaper of mobile device
$background = " background=\"" . $this->disp_background . "\"";
$bodystyle .= sprintf("background-image:url(%s); ", $this->disp_background);
}
}
if ($this->size)
{
// set the font size for all characters in a HTML created page
$size = " size=\"" . $this->size . "\"";
$bodystyle .= sprintf("font-size:%s; ", $this->size);
}
if ($this->color)
{
// set the color for all characters in a HTML created page
$color = " color=\"" . $this->color . "\"";
$bodystyle .= sprintf("color:%s; ", $this->color);
}
if ($this->link_color)
{
// set the color of links in a HTML created page
$link_color = " link=\"" . $this->link_color . "\"";
$css_style .= sprintf("a:link { color:%s; }\n", $this->link_color);
}
if ($this->vlink_color)
{
// set the color of visited links in a HTML created page
$vlink_color = " vlink=\"" . $this->vlink_color . "\"";
$css_style .= sprintf("a:visited { color:%s; }\n", $this->vlink_color);
}
if ($this->face)
{
// set the font for all characters in a HTML created page
$face = " face=\"" . $this->face . "\"";
$bodystyle .= sprintf("font-family:%s; ", $this->face);
}
$this->fontstyle_attrbs = $size . $color . $face;
}
printf("%s\n", HAW_specchar($this->title, $this));
if ($this->pureHTML && $this->use_simulator && $this->css_enabled)
// use HAWHAW default- or user-defined skin
printf("skin);
if ($this->css_enabled)
printf("\n", $bodystyle, $css_style);
echo "\n";
if ($this->css_enabled)
echo "\n";
else
printf("\n", $bgcolor, $background, $link_color, $vlink_color);
if ($this->display_banners)
{
if ($this->number_of_top_banners > 0)
{
echo "
\n";
for ($i=0; $i<$this->number_of_top_banners; $i++)
{
// display banners at the top of the HTML page
$banner = $this->top_banners[$i];
$banner->create();
}
echo "
\n";
}
}
if ($this->pureHTML)
{
if ($this->css_enabled && $this->use_simulator)
{
// use simulator design
echo "
\n";
echo "
\n";
}
else
{
// use classic HAWHAW design
printf("
\n",
$this->disp_bgcolor, $this->disp_background, $this->border, $this->width, $this->height);
}
}
if (!$this->css_enabled && $this->fontstyle_attrbs)
{
// write style attributes, if any
printf("\n", $this->fontstyle_attrbs);
}
}
else
{
// determine default values for WML, HDML and VXML form elements
while (list($e_key, $e_val) = each($this->element))
{
if ($e_val->get_elementtype() == HAW_FORM)
{
// one (and only one!) form exists
$form = $e_val;
$defaults = $form->get_defaults();
}
}
if ($this->ml == HAW_WML)
{
// create WML page header
if (!$this->debug)
{
$ct = sprintf("content-type: text/vnd.wap.wml");
header($ct);
}
if ($this->disable_cache)
{
// not all WAP clients interprete meta directives!
// disable caching by sending HTTP content-location header with unique value
if (isset($_SERVER['REQUEST_URI']))
$request_uri = $_SERVER['REQUEST_URI'];
else
$request_uri = "";
if (strchr($request_uri, "?"))
// request URI already contains parameter(s)
$header= sprintf("content-location: %s&hawcid=%s", $request_uri, date("U"));
else
// no parameters in URI
$header= sprintf("content-location: %s?hawcid=%s", $request_uri, date("U"));
header($header);
}
echo "\n";
if ($this->owgui_1_3)
echo "\n";
else
echo "\n";
printf("\n", HAW_VERSION, HAW_COPYRIGHT);
if ($this->language)
$language = sprintf(" xml:lang=\"%s\"", $this->language);
else
$language = "";
printf("\n", $language);
if ($this->disable_cache)
{
echo "\n";
echo "\n";
echo "\n";
echo "\n";
echo "\n";
echo "\n";
echo "\n";
}
if ($this->title)
$title = " title=\"" . HAW_specchar($this->title,$this) . "\"";
else
$title = "";
printf("\n", $title);
if (isset ($defaults) && $defaults)
{
// default values exist
// set variables each time the card is enter in forward direction ...
echo "\n";
echo "\n";
// initialize all WML variables with their default values
while (list($d_key, $d_val) = each($defaults))
printf("\n",
$d_val['name'], HAW_specchar($d_val['value'], $this));
reset($defaults);
echo "\n";
echo "\n";
// ... and backward direction
echo "\n";
echo "\n";
while (list($d_key, $d_val) = each($defaults))
printf("\n", $d_val['name'], $d_val['value']);
echo "\n";
echo "\n";
}
// set redirection timeout
if ($this->timeout > 0)
{
echo "\n";
printf("\n", HAW_specchar($this->red_url, $this));
echo "\n";
printf("\n", $this->timeout*10);
}
// define softkey
echo "\n";
echo "\n";
echo "\n";
}
elseif ($this->ml == HAW_HDML)
{
// create HDML card set structure
if (!isset($defaults))
$defaults = array();
$this->hdmlcardset = new HAW_hdmlcardset(HAW_specchar($this->title, $this),
$defaults, $this->disable_cache,
$this->debug, $this->charset);
}
elseif ($this->ml == HAW_VXML)
{
// create VXML page header
if (!$this->debug)
{
$ct = sprintf("content-type: application/vxml+xml");
header($ct);
}
printf("\n", $this->charset);
printf("\n", HAW_VERSION, HAW_COPYRIGHT);
// language declaration breaks Voxeo Motorola voice browser!!!
if ($this->language && !$this->MotorolaVoiceXML)
$language = sprintf(" xml:lang=\"%s\"", $this->language);
else
$language = "";
printf("\n", $language);
if ($this->disable_cache)
echo "\n";
// define voice deck properties
while (list($key, $val) = each($this->voice_property))
printf("\n", $val["name"], $val["value"]);
// Voxeo-specific TTS settings
if ($this->MotorolaVoiceXML)
{
if ($this->language == "fr")
echo "\n";
if ($this->language == "es")
echo "\n";
}
echo "
\n"; // terminate skin/classic div
if (!$this->lynx)
{
if ($haw_license_holder && $haw_signature)
{
if ($haw_signature == 1)
$signature = "Powered by HAWHAW (C)\n";
else
if ($haw_sig_text)
if ($haw_sig_link)
$signature = sprintf("%s\n", $haw_sig_link, $haw_sig_text);
else
$signature = sprintf("%s\n", $haw_sig_text);
}
else
$signature = sprintf("Powered by HAWHAW (C)\n", $this->waphome);
echo $signature;
}
}
if ($this->display_banners)
{
if ($this->number_of_bottom_banners > 0)
{
echo "
\n";
for ($i=0; $i<$this->number_of_bottom_banners; $i++)
{
// display banners at the bottom of the HTML page
$banner = $this->bottom_banners[$i];
$banner->create();
}
echo "
\n";
}
}
echo "\n";
echo "\n";
}
elseif ($this->ml == HAW_WML)
{
// create WML page end
echo "\n";
echo "\n";
echo "\n";
}
elseif ($this->ml == HAW_HDML)
{
// create HDML page from hdml card set structure
$cardset = $this->hdmlcardset;
$cardset->create_hdmldeck();
}
elseif ($this->ml == HAW_VXML)
{
// create VoiceXML page end
// set redirection timeout
if ($this->red_url && ($this->timeout == 0))
{
// special handling for timeout value 0 in VoiceXML:
// go immediately to next page after all text has been spoken
// should be used for pure voice apps only!!!
printf("\n", HAW_specchar($this->red_url, $this));
}
elseif ($this->timeout > 0)
{
// redirect after to another URL
// (define dummy grammar in case that no other grammar is active)
printf("[(hawhaw really rocks)]\n",
$this->timeout, HAW_specchar($this->red_url, $this));
}
elseif($this->voice_timeout > 0)
{
// there is at least one voice link active
// wait longest link timeout value until disconnect is forced
printf("", $this->voice_timeout);
// test for user-defined noinput event handler
if (!isset($this->voice_noinput) || (count($this->voice_noinput) == 0))
echo ""; // terminate in case of no input
echo "\n";
}
echo "\n";
if ($this->voice_links)
echo $this->voice_links;
// create event handlers
HAW_voice_eventhandler("help", $this->voice_help, $this);
HAW_voice_eventhandler("noinput", $this->voice_noinput, $this);
HAW_voice_eventhandler("nomatch", $this->voice_nomatch, $this);
echo "\n";
}
}
};
/**
This class defines a form with various possible input elements. The input elements
have to be defined as separate objects and are linked to the form with a special
"add" function. One HAW_deck object can contain only one HAW_form object.
Examples:
$myPage = new HAW_deck(...);
...
$myForm = new HAW_form("/mynextpage.php");
$myText = new HAW_text(...);
$myForm->add_text($myText);
$myInput = new HAW_input(...);
$myForm->add_input($myInput);
$mySubmit = new HAW_submit(...);
$myForm->add_submit($mySubmit);
...
$myPage->add_form($myForm);
...
$myPage->create_page();
@see HAW_text
@see HAW_image
@see HAW_table
@see HAW_input
@see HAW_textarea
@see HAW_select
@see HAW_radio
@see HAW_checkbox
@see HAW_hidden
@see HAW_submit
@see HAW_rule
*/
class HAW_form
{
var $url;
var $method;
var $element;
var $number_of_elements = 0;
var $number_of_submitobjects = 0;
var $voice_text = "";
var $voice_audio_src = "";
/**
Constructor
@param url Address where the user input is sent to.
@param method (optional)
HAW_METHOD_GET (default)
HAW_METHOD_POST
*/
function HAW_form($url, $method=HAW_METHOD_GET)
{
if (!is_int($method) || (($method != HAW_METHOD_GET) && ($method != HAW_METHOD_POST)))
die("invalid method in HAW_form: " . $method . " (possible values: HAW_METHOD_GET or HAW_METHOD_POST)");
$this->url = $url;
$this->method = $method;
}
/**
Adds a HAW_text object to HAW_form.
@param text Some HAW_text object.
@see HAW_text
*/
function add_text($text)
{
if (!is_object($text))
die("invalid argument in add_text()");
$this->element[$this->number_of_elements] = $text;
$this->number_of_elements++;
}
/**
Adds a HAW_image object to HAW_form.
@param image Some HAW_image object.
@see HAW_image
*/
function add_image($image)
{
if (!is_object($image))
die("invalid argument in add_image()");
$this->element[$this->number_of_elements] = $image;
$this->number_of_elements++;
}
/**
Adds a HAW_table object to HAW_form.
@param table Some HAW_table object.
@see HAW_table
*/
function add_table($table)
{
if (!is_object($table))
die("invalid argument in add_table()");
$this->element[$this->number_of_elements] = $table;
$this->number_of_elements++;
}
/**
Adds a HAW_input object to HAW_form.
@param input Some HAW_input object.
@see HAW_input
*/
function add_input($input)
{
if (!is_object($input))
die("invalid argument in add_input()");
$this->element[$this->number_of_elements] = $input;
$this->number_of_elements++;
}
/**
Adds a HAW_textarea object to HAW_form.
@param textarea Some HAW_textarea object.
@see HAW_textarea
*/
function add_textarea($textarea)
{
if (!is_object($textarea))
die("invalid argument in add_textarea()");
$this->element[$this->number_of_elements] = $textarea;
$this->number_of_elements++;
}
/**
Adds a HAW_select object to HAW_form.
@param select Some HAW_select object.
@see HAW_select
*/
function add_select($select)
{
if (!is_object($select))
die("invalid argument in add_select()");
$this->element[$this->number_of_elements] = $select;
$this->number_of_elements++;
}
/**
Adds a HAW_radio object to HAW_form.
@param radio Some HAW_radio object.
@see HAW_radio
*/
function add_radio($radio)
{
if (!is_object($radio))
die("invalid argument in add_radio()");
$this->element[$this->number_of_elements] = $radio;
$this->number_of_elements++;
}
/**
Adds a HAW_checkbox object to HAW_form.
@param checkbox Some HAW_checkbox object.
@see HAW_checkbox
*/
function add_checkbox($checkbox)
{
if (!is_object($checkbox))
die("invalid argument in add_checkbox()");
$this->element[$this->number_of_elements] = $checkbox;
$this->number_of_elements++;
}
/**
Adds a HAW_hidden object to HAW_form.
@param hidden Some HAW_hidden object.
@see HAW_hidden
*/
function add_hidden($hidden)
{
if (!is_object($hidden))
die("invalid argument in add_hidden()");
$this->element[$this->number_of_elements] = $hidden;
$this->number_of_elements++;
}
/**
Adds a HAW_submit object to HAW_form.
@param submit Some HAW_submit object.
@see HAW_submit
*/
function add_submit($submit)
{
if (!is_object($submit))
die("invalid argument in add_submit()");
if ($this->number_of_submitobjects > 0)
die("only one HAW_submit object per form allowed!");
$this->element[$this->number_of_elements] = $submit;
$this->number_of_elements++;
$this->number_of_submitobjects++;
}
/*
Adds a HAW_raw object to HAW_form. (undocumented feature - for test only!)
@param raw_markup_object Some HAW_raw object.
@see HAW_raw
*/
function add_raw($raw)
{
if (!is_object($raw))
die("invalid argument in add_raw()");
$this->element[$this->number_of_elements] = $raw;
$this->number_of_elements++;
}
/*
Adds some user-defined HAWHAW object to HAW_form (undocumented feature)
For skilled HAWHAW programmers only!
@param udef Some user-defined object.
*/
function add_userdefined($udef)
{
// see HAW_deck->add_userdefined($def) for documentation
if (!is_object($udef))
die("invalid argument in add_userdefined()");
$this->element[$this->number_of_elements] = $udef;
$this->number_of_elements++;
}
/**
Adds a HAW_rule object to HAW_form.
@param rule Some HAW_rule object.
@see HAW_rule
*/
function add_rule($rule)
{
if (!is_object($rule))
die("invalid argument in add_rule()");
$this->element[$this->number_of_elements] = $rule;
$this->number_of_elements++;
}
/**
Sets form-related text to be spoken by voice browsers.
@param text Some introducing text that will be spoken before any dialog
is started.
@param audio_src Some audio file (e.g. *.wav file) to play (optional).
*/
function set_voice_text($text, $audio_src="")
{
if (!is_string($text))
die("invalid argument in set_voice_text()");
$this->voice_text = $text;
$this->voice_audio_src = $audio_src;
}
function get_defaults()
{
$defaults = array();
$i = 0;
while (list($key, $val) = each($this->element))
{
switch ($val->get_elementtype())
{
case HAW_CHECKBOX:
{
$checkbox = $val;
if ($checkbox->is_checked())
{
$defaults[$i]["name"] = $checkbox->get_name();
$defaults[$i]["value"] = $checkbox->get_value();
$i++;
}
break;
}
case HAW_INPUT:
case HAW_TEXTAREA:
case HAW_SELECT:
case HAW_RADIO:
case HAW_HIDDEN:
{
$element = $val;
$defaults[$i]["name"] = $element->get_name();
$defaults[$i]["value"] = $element->get_value();
$i++;
break;
}
}
}
return $defaults;
}
function get_elementtype()
{
return HAW_FORM;
}
function create(&$deck)
{
// add hawoutput query parameter to form, if required
if ($deck->hawoutput)
{
$hidden_hawoutput = new HAW_hidden("hawoutput", $deck->hawoutput);
$this->add_hidden($hidden_hawoutput);
}
// determine all elements that have to be submitted
$i = 0;
$varnames = null;
reset($this->element); //set the array pointer to first element
while (list($key, $val) = each($this->element))
{
switch ($val->get_elementtype())
{
case HAW_INPUT:
case HAW_TEXTAREA:
case HAW_SELECT:
case HAW_CHECKBOX:
case HAW_RADIO:
case HAW_HIDDEN:
{
$element = $val;
$varnames[$i] = $element->get_name();
$i++;
}
}
}
if ($deck->ml == HAW_HTML)
{
// start tag of HTML form
if ($this->method == HAW_METHOD_POST)
$method = " method=\"post\"";
else
$method = " method=\"get\"";
printf("
\n";
}
}
};
/**
This class allows to insert plain text into a HAW_deck, HAW_form or HAW_table object.
Examples:
$myText1 = new HAW_text("Hello WAP!");
$myText2 = new HAW_text("Welcome to HAWHAW", HAW_TEXTFORMAT_BOLD);
$myText3 = new HAW_text("Good Morning", HAW_TEXTFORMAT_BOLD | HAW_TEXTFORMAT_BIG);
$myText3->set_br(2);
@see HAW_deck
@see HAW_form
@see HAW_row
*/
class HAW_text
{
var $text;
var $attrib;
var $color;
var $boxcolor;
var $br;
var $voice_text;
var $voice_audio_src;
var $voice_navigation;
/**
Constructor
@param text Some string you want to display
@param attrib (optional)
HAW_TEXTFORMAT_NORMAL (default)
HAW_TEXTFORMAT_BOLD
HAW_TEXTFORMAT_UNDERLINE
HAW_TEXTFORMAT_ITALIC
HAW_TEXTFORMAT_BIG
HAW_TEXTFORMAT_SMALL
HAW_TEXTFORMAT_BOXED (text in a colored box for headings etc.)
*/
function HAW_text($text, $attrib=HAW_TEXTFORMAT_NORMAL)
{
$this->text = $text;
$this->attrib = $attrib;
$this->color = "";
$this->boxcolor = "";
$this->br = 1; // default: 1 line break after text
$this->voice_text = $text;
$this->voice_audio_src = "";
$this->voice_navigation = false;
}
/**
Sets the color of this object in a (X)HTML page.
@param color See HTML specification for possible values (e.g. "#CCFFFF", "red",
...).
@param boxcolor (optional)
box background for attribute HAW_TEXTFORMAT_BOXED
*/
function set_color($color, $boxcolor="")
{
$this->color = $color;
$this->boxcolor = $boxcolor;
}
/**
Sets the number of line breaks (CRLF) after text. (default: 1)
@param br Some number of line breaks.
*/
function set_br($br)
{
if (!is_int($br) || ($br < 0))
die("invalid argument in set_br()");
$this->br = $br;
}
/**
Sets text to be spoken by voice browsers.
@param text Some alternative text that replaces original <text>.
@param audio_src Some audio file (e.g. *.wav file) to play (optional).
*/
function set_voice_text($text, $audio_src="")
{
if (!is_string($text))
die("invalid argument in set_voice_text()");
$this->voice_text = $text;
$this->voice_audio_src = $audio_src;
}
/**
Turns on the voice navigation capability for this object.
Note: See set_voice_navigator(...) in class HAW_deck.
@see HAW_deck
*/
function set_voice_navigation()
{
$this->voice_navigation = true;
}
function get_text()
{
return $this->text;
}
function get_color()
{
return $this->color;
}
function get_br()
{
return $this->br;
}
function get_attrib()
{
return $this->attrib;
}
function get_elementtype()
{
return HAW_PLAINTEXT;
}
function create(&$deck)
{
if ($deck->ml == HAW_HDML)
{
// HDML
$deck->hdmlcardset->add_display_content("<" . $deck->alignment . ">\n");
// print text
if ($this->text)
{
$content = sprintf("%s\n", HAW_specchar($this->text, $deck));
$deck->hdmlcardset->add_display_content($content);
}
// create required amount of carriage return's
$br = "";
for ($i=0; $i < $this->br; $i++)
$br .= " \n";
$deck->hdmlcardset->add_display_content($br);
}
elseif(($deck->ml == HAW_HTML) || ($deck->ml == HAW_WML))
{
// HTML or WML
if (($this->attrib & HAW_TEXTFORMAT_BOXED) && ($deck->ml == HAW_HTML))
{
// determine text and background color, if not already assigned
if (!$this->color)
$this->color = $deck->disp_bgcolor;
if (!$this->color)
$this->color = "#FFFFFF"; // default: white text
if (!$this->boxcolor)
$this->boxcolor = $deck->color;
if (!$this->boxcolor)
$this->boxcolor = "#000000"; // default: on black background
if ($deck->css_enabled)
printf("
\n", $this->boxcolor);
else
{
printf("
\n",
$this->boxcolor, $deck->fontstyle_attrbs);
// align text in (table-)box
printf("
\n", $deck->alignment);
}
// decrement line breaks because div/table already causes 1 br
if ($this->br >= 1)
$this->br--;
}
if ($this->attrib & HAW_TEXTFORMAT_BOLD)
echo "\n";
if ($this->attrib & HAW_TEXTFORMAT_UNDERLINE)
{
if ($deck->css_enabled)
echo "\n";
else
echo "\n";
}
if ($this->attrib & HAW_TEXTFORMAT_ITALIC)
echo "\n";
if ($this->attrib & HAW_TEXTFORMAT_BIG)
echo "\n";
if ($this->attrib & HAW_TEXTFORMAT_SMALL)
echo "\n";
if (($deck->ml == HAW_HTML) && $this->color)
{
if ($deck->css_enabled)
printf("\n", $this->color);
else
printf("", $this->color);
}
// print text
if (isset($this->text))
printf("%s\n", HAW_specchar($this->text, $deck));
if (($deck->ml == HAW_HTML) && $this->color)
{
if ($deck->css_enabled)
echo "";
else
echo "";
}
if ($this->attrib & HAW_TEXTFORMAT_SMALL)
echo "\n";
if ($this->attrib & HAW_TEXTFORMAT_BIG)
echo "\n";
if ($this->attrib & HAW_TEXTFORMAT_ITALIC)
echo "\n";
if ($this->attrib & HAW_TEXTFORMAT_UNDERLINE)
{
if ($deck->css_enabled)
echo "\n";
else
echo "\n";
}
if ($this->attrib & HAW_TEXTFORMAT_BOLD)
echo "\n";
if (($this->attrib & HAW_TEXTFORMAT_BOXED) && ($deck->ml == HAW_HTML))
{
if ($deck->css_enabled)
echo "
\n";
else
echo "
\n";
}
// create required amount of carriage return's
for ($i=0; $i < $this->br; $i++)
echo " \n";
}
elseif($deck->ml == HAW_VXML)
{
// VoiceXML
if ($this->voice_navigation)
{
// enable navigation (repeat/forward)
static $block_counter = 0;
printf("",
$block_counter, $block_counter);
}
else
echo "";
$pause = $this->br * HAW_VOICE_PAUSE; // short pause for each break
// remove leading commas, dots etc. which may appear after link objects
HAW_voice_audio(ereg_replace("^[\?!,;.]", " ", HAW_specchar($this->voice_text, $deck)),
$this->voice_audio_src, $pause, $deck);
echo "\n";
if ($this->voice_navigation)
{
// create artificial field to control VoiceXML sequencing
printf("\n", $block_counter);
echo "\n";
echo "[(hawhaw really rocks)]\n";
printf("\n", $block_counter);
echo "\n";
// create block end where forward will go to
printf("\n", $block_counter++);
}
}
}
};
/**
This class allows to insert bitmap images into a HAW_deck, HAW_form or HAW_table
object.
Examples:
$myImage1 = new HAW_image("my_image.wbmp", "my_image.gif", ":-)");
$myImage2 = new HAW_image("my_image.wbmp", "my_image.gif", ":-)", "my_image.bmp");
$myImage2->set_br(1);
@see HAW_deck
@see HAW_form
@see HAW_row
*/
class HAW_image
{
var $src_wbmp;
var $src_html;
var $alt;
var $src_bmp;
var $br;
var $localsrc;
var $chtml_icon;
var $mml_icon;
var $voice_text;
var $voice_audio_src;
/**
Constructor
@param src_wbmp Your bitmap in WAP-conform .wbmp format.
@param src_html Your bitmap in .gif, .jpg or any other HTML compatible format.
@param alt Alternative text for your bitmap. Will be displayed if the client can
display none of your graphic formats.
@param src_bmp (optional) your bitmap in monochrome .bmp format. If the
browser signals in the HTTP request header, that he's only able to display
image/bmp and not image/vnd.wap.wbmp (e.g. the UPSim 3.2 did so), this image
will be sent.
*/
function HAW_image($src_wbmp, $src_html, $alt, $src_bmp="")
{
$this->src_wbmp = $src_wbmp;
$this->src_html = $src_html;
$this->alt = $alt;
$this->src_bmp = $src_bmp;
$this->br = 0; // default: no line break after image
$this->localsrc = ""; // no localsrc attribute
$this->chtml_icon = 0; // no cHTML icon
$this->mml_icon = 0; // no MML icon
$this->voice_text = "";
$this->voice_audio_src = "";
}
/**
Sets the number of line breaks (CRLF) after the image. (default: 0)
@param br Some number of line breaks.
*/
function set_br($br)
{
if (!is_int($br) || ($br < 0))
die("invalid argument in set_br()");
$this->br = $br;
}
/**
Use localsrc attribute on WAP/HDML devices.
Using built-in icons, mobile devices don't have to download
bitmap images. If the device can not render the specified icon,
it will download the according bitmap as specified in the HAW_image
constructor.
@param icon Device-internal representation of the image, e.g. "heart".
*/
function use_localsrc($icon)
{
if (!is_string($icon))
die("invalid argument in use_localsrc()");
$this->localsrc = $icon;
}
/**
Use cHTML icon instead of HTML bitmap on i-mode devices.
Using built-in icons, mobile devices don't have to download
bitmap images. Has no effect on non-i-mode devices.
@param icon cHTML icon code, e.g. 63889 for the "heart" icon.
*/
function use_chtml_icon($icon)
{
if (!is_int($icon) || ($icon < 1))
die("invalid argument in use_chtml_icon()");
$this->chtml_icon = $icon;
}
/**
Use MML icon instead of HTML bitmap on MML devices.
Using built-in icons, mobile devices don't have to download
bitmap images. Has no effect on non-MML devices.
@param icon MML icon code, e.g. "GB" for the "heart" icon.
*/
function use_mml_icon($icon)
{
if (!is_string($icon) || (strlen($icon) != 2))
die("invalid argument in use_mml_icon()");
$this->mml_icon = $icon;
}
/**
Sets text to be spoken by voice browsers.
@param text Some text that represents the image for voice users.
@param audio_src Some audio file (e.g. *.wav file) to play (optional).
*/
function set_voice_text($text, $audio_src="")
{
if (!is_string($text))
die("invalid argument in set_voice_text()");
$this->voice_text = $text;
$this->voice_audio_src = $audio_src;
}
function get_elementtype()
{
return HAW_IMAGE;
}
function create(&$deck)
{
if (isset($_SERVER['HTTP_ACCEPT']))
$HTTP_ACCEPT = $_SERVER['HTTP_ACCEPT'];
else
$HTTP_ACCEPT = "";
if ($deck->ml == HAW_HDML)
{
// HDML
$deck->hdmlcardset->add_display_content("<" . $deck->alignment . ">\n");
if ($this->localsrc)
$icon = sprintf(" icon=\"%s\"", $this->localsrc);
else
$icon = "";
$content = sprintf("\n",
$this->src_bmp,
HAW_specchar($this->alt, $deck), $icon);
$deck->hdmlcardset->add_display_content($content);
// create required amount of carriage return's
$br = "";
for ($i=0; $i < $this->br; $i++)
$br .= " \n";
$deck->hdmlcardset->add_display_content($br);
}
elseif (($deck->ml == HAW_HTML) || ($deck->ml == HAW_WML))
{
// HTML or WML
if ($deck->ml == HAW_HTML)
{
// HTML
if ($deck->iModestyle && $this->chtml_icon)
{
// cHTML icon available ==> use this icon instead of bitmap
printf("%d;", $this->chtml_icon);
}
elseif ($deck->MMLstyle && $this->mml_icon)
{
// MML icon available ==> use this icon instead of bitmap
echo CHR(27) . "$" . $this->mml_icon . CHR(15);
}
else
{
// use HTML bitmap
printf("\n",
$this->src_html, HAW_specchar($this->alt, $deck));
}
// evaluate HTML break instruction
if ($deck->MMLstyle)
$br_command = " \n"; // MML has problems with clear attribute
elseif ($deck->xhtml)
$br_command = " \n"; // XHTML does not know clear attribute
else
$br_command = " \n";
}
else
{
// WML
if ($this->localsrc)
$localsrc = sprintf(" localsrc=\"%s\"", $this->localsrc);
else
$localsrc = "";
if ($deck->gif_enabled && (substr(strtolower($this->src_html), -4) == ".gif"))
// user agent is able to display the provided GIF image
printf("\n", $this->src_html,
HAW_specchar($this->alt, $deck), $localsrc);
elseif (strstr(strtolower($HTTP_ACCEPT), "image/vnd.wap.wbmp"))
// user agent is able to display .wbmp image
printf("\n", $this->src_wbmp,
HAW_specchar($this->alt, $deck), $localsrc);
elseif (strstr(strtolower($HTTP_ACCEPT), "image/bmp") && $this->src_bmp)
// user agent is able to display .bmp and .bmp image is available
printf("\n", $this->src_bmp,
HAW_specchar($this->alt, $deck), $localsrc);
else
// hope that the user agent makes the best of it!
printf("\n", $this->src_wbmp,
HAW_specchar($this->alt, $deck), $localsrc);
// break instruction in WML
$br_command = " \n";
}
// create required amount of carriage return's
for ($i=0; $i < $this->br; $i++)
echo $br_command;
}
elseif ($deck->ml == HAW_VXML)
{
// VoiceXML
if ($this->voice_text || $this->voice_audio_src)
{
// create image-related audio output for VoiceXML images
echo "";
HAW_voice_audio(HAW_specchar($this->voice_text, $deck),
$this->voice_audio_src, HAW_VOICE_PAUSE, $deck);
echo "\n";
}
}
}
};
/**
This class allows to insert tables into a HAW_deck or HAW_form object.
Note: Not all WAP clients are able to display tables properly! HDML is not
supporting tables at all. For HDML users the table's content will be generated
column-by-column, respectively row-by-row, where each table cell will result in
one separate line on the display.
Examples:
...
$myTable = new HAW_table();
$row1 = new HAW_row();
$row1->add_column($image1);
$row1->add_column($text1);
$myTable->add_row($row1);
$row2 = new HAW_row();
$row2->add_column($image2);
$row2->add_column($text2);
$myTable->add_row($row2);
$myDeck->add_table($myTable);
...
@see HAW_deck
@see HAW_form
@see HAW_row
*/
class HAW_table
{
var $row;
var $number_of_rows;
var $voice_text;
var $voice_audio_src;
/**
Constructor
*/
function HAW_table()
{
$this->number_of_rows = 0;
$this->voice_text = "";
$this->voice_audio_src = "";
}
/**
Adds a HAW_row object to HAW_table.
@param row Some HAW_row object.
*/
function add_row($row)
{
if (!is_object($row))
die("invalid argument in add_row()");
$this->row[$this->number_of_rows] = $row;
$this->number_of_rows++;
}
/**
Sets text to be spoken by voice browsers.
Note: Tables should be avoided whenever voice users are targeted.
Anyway, the HAWHAW API allows to assign voice output to HAW_table objects in order
to say some introducing words before the table content is spoken.
@param text Some helpful text.
@param audio_src Some audio file (e.g. *.wav file) to play (optional).
*/
function set_voice_text($text, $audio_src="")
{
if (!is_string($text))
die("invalid argument in set_voice_text()");
$this->voice_text = $text;
$this->voice_audio_src = $audio_src;
}
function get_elementtype()
{
return HAW_TABLE;
}
function create(&$deck)
{
// HDML does not support tables ==> skip all table tags for HDML
if ($deck->ml == HAW_HTML)
{
// HTML
if ($deck->xhtml)
// border attribute is not allowed in XHTML
echo "
\n";
else
printf("
\n", $deck->alignment);
}
elseif ($deck->ml == HAW_WML)
{
// WML
// evaluate maximum number of columns in table
$max_columns = 0;
for ($i = 0; $i < $this->number_of_rows; $i++)
{
$row = $this->row[$i];
$columns = $row->get_number_of_columns();
if ($columns > $max_columns)
$max_columns = $columns;
}
printf("
\n", $max_columns);
}
elseif ($deck->ml == HAW_VXML)
{
if ($this->voice_text || $this->voice_audio_src)
{
// create introducing audio output for VoiceXML table
echo "";
HAW_voice_audio(HAW_specchar($this->voice_text, $deck),
$this->voice_audio_src, HAW_VOICE_PAUSE, $deck);
echo "\n";
}
}
for ($i = 0; $i < $this->number_of_rows; $i++)
{
$row = $this->row[$i];
$row->create($deck);
}
//terminate table
if ($deck->ml == HAW_HTML)
{
// make new line in HTML
if ($deck->MMLstyle)
echo "
\n"; // MML has problems with clear attribute
elseif ($deck->xhtml)
echo "
\n"; // XHTML does not know clear attribute
else
echo "
\n";
}
elseif ($deck->ml == HAW_WML)
{
// make new line in WML
echo " \n";
}
}
};
/**
This class defines the rows, a HAW_table object consists of.
Examples:
...
$image1 = new HAW_image("my_image.wbmp", "my_image.gif", ":-)");
$text1 = new HAW_text("my text");
$row1 = new HAW_row();
$row1->add_column($image1);
$row1->add_column();
$row1->add_column($text1);
...
@see HAW_table
@see HAW_text
@see HAW_image
@see HAW_link
*/
class HAW_row
{
var $column;
var $number_of_columns;
/**
Constructor
*/
function HAW_row()
{
$this->number_of_columns = 0;
}
/**
Adds a cell element to a HAW_row object.
@param cell_element (optional) Can be a HAW_text object, a HAW_image object,
a HAW_link object, an array containing some of these three objects,
or the NULL pointer (default).
The latter results in an empty cell element.
*/
function add_column($cell_element=NULL)
{
if (is_object($cell_element))
{
if (($cell_element->get_elementtype() != HAW_PLAINTEXT) &&
($cell_element->get_elementtype() != HAW_IMAGE) &&
($cell_element->get_elementtype() != HAW_LINK))
die("invalid argument in add_column()");
}
elseif (is_array($cell_element))
{
foreach ($cell_element as $an_element)
{
if (($an_element->get_elementtype() != HAW_PLAINTEXT) &&
($an_element->get_elementtype() != HAW_IMAGE) &&
($an_element->get_elementtype() != HAW_LINK))
die("invalid argument in add_column() array");
}
}
$this->column[$this->number_of_columns] = $cell_element;
$this->number_of_columns++;
}
function get_number_of_columns()
{
return $this->number_of_columns;
}
function create(&$deck)
{
// HDML and VXML do not support tables ==> skip all table tags for HDML and VXML
if (($deck->ml != HAW_HDML) && ($deck->ml != HAW_VXML))
echo "
\n"; // start of row
for ($i = 0; $i < $this->number_of_columns; $i++)
{
if (($deck->ml != HAW_HDML) && ($deck->ml != HAW_VXML))
echo "
\n"; // start of column
// call create function for each cellelement that is a HAWHAW object
$column = $this->column[$i];
if (is_object($column))
$column->create($deck);
elseif (is_array($column))
foreach ($column as $an_element)
$an_element->create($deck);
if (($deck->ml != HAW_HDML) && ($deck->ml != HAW_VXML))
echo "
\n"; // end of column
}
if (($deck->ml != HAW_HDML) && ($deck->ml != HAW_VXML))
echo "
\n"; // end of row
}
};
/**
This class provides a text input field in a HAW_form object.
Examples:
$myInput1 = new HAW_input("cid", "", "Customer ID");
$myInput2 = new HAW_input("cid", "", "Customer ID", "*N");
$myInput2->set_size(6);
$myInput2->set_maxlength(6);
$myInput3 = new HAW_input("pw", "", "Password", "*N");
$myInput3->set_size(8);
$myInput3->set_maxlength(8);
$myInput3->set_type(HAW_INPUT_PASSWORD);
@see HAW_form
*/
class HAW_input
{
var $name;
var $value;
var $label;
var $size;
var $maxlength;
var $type;
var $format;
var $mode;
var $br;
var $voice_text;
var $voice_audio_src;
var $voice_type;
var $voice_grammar;
var $voice_help;
var $voice_noinput;
var $voice_nomatch;
/**
Constructor
@param name Variable in which the input is sent to the destination URL.
@param value Initial value (string!) that will be presented in the input field.
@param label Describes your input field on the visitors's screen/display.
@param format (optional, default: "*M")
Input format code according to the WAP standard.
Allows the WAP user client e.g. to input only digits and no characters.
*/
function HAW_input($name, $value, $label, $format="*M")
{
$this->name = $name;
$this->value = $value;
$this->label = $label;
$this->format = $format;
$this->type = HAW_INPUT_TEXT;
$this->mode = HAW_INPUT_ALPHABET;
$this->br = 1;
$this->voice_text = $label;
$this->voice_audio_src = "";
$this->voice_type = "digits";
$this->voice_grammar = "";
$this->voice_help = array();
$this->voice_noinput = array();
$this->voice_nomatch = array();
}
/**
Set size of the input field.
Note: Will be ignored in case of HDML/VoiceXML output.
@param size Number of characters fitting into the input field.
*/
function set_size($size)
{
$this->size = $size;
}
/**
Set maximum of allowed characters in the input field.
Note: Will be ignored in case of HDML output.
@param maxlength Maximum number of characters the user can enter.
*/
function set_maxlength($maxlength)
{
$this->maxlength = $maxlength;
}
/**
Set input type
@param type Allowed values: HAW_INPUT_TEXT (default) or HAW_INPUT_PASSWORD.
*/
function set_type($type)
{
$this->type = $type;
}
/**
Set input mode/istyle for japanese MML/i-mode devices
@param mode input mode
HAW_INPUT_ALPHABET (default)
HAW_INPUT_KATAKANA
HAW_INPUT_HIRAGANA
HAW_INPUT_NUMERIC
*/
function set_mode($mode)
{
$this->mode = $mode;
// input mode can be mapped into a format string, used from WML and HDML
// ==> set format string
// (if a format string was provided during object initiation, this value
// will be overwritten)
switch ($mode)
{
case HAW_INPUT_HIRAGANA: { $this->format = "*M"; break; }
case HAW_INPUT_KATAKANA: { $this->format = "*M"; break; }
case HAW_INPUT_ALPHABET: { $this->format = "*m"; break; }
case HAW_INPUT_NUMERIC: { $this->format = "*N"; break; }
}
}
/**
Sets the number of line breaks (CRLF) after input field (default: 1).
Note: Has no effect in WML/HDML.
@param br Some number of line breaks.
*/
function set_br($br)
{
if (!is_int($br) || ($br < 0))
die("invalid argument in set_br()");
$this->br = $br;
}
/**
Sets text to be spoken by voice browsers.
@param text Some alternative text that replaces <label>.
@param audio_src Some audio file (e.g. *.wav file) to play (optional).
*/
function set_voice_text($text, $audio_src="")
{
if (!is_string($text))
die("invalid argument in set_voice_text()");
$this->voice_text = $text;
$this->voice_audio_src = $audio_src;
}
/**
Sets the type of the input field in voice decks (default: "digits").
Note: Support of builtin grammar types is platform specific.
The W3C VoiceXML Version 2.0 recommendation defines these grammar types:
boolean
date
digits (default)
currency
number
phone
time
@param type String with grammar type.
*/
function set_voice_type($type)
{
if (!is_string($type))
die("invalid argument in set_voice_type()");
$this->voice_type = $type;
}
/**
Defines an external grammar for an input field in voice decks.
Attention: This function should be used by experienced VoiceXML developers
only! Please refer to the W3C VoiceXML Recommendation for detailled info
about grammar definitions.
@param src URL specifying the location of the grammar, e.g. "http://www.foo.com/myinput.grxml".
@param type Media type of the grammar, e.g. "application/srgs+xml (optional)".
*/
function set_voice_grammar($src, $type="")
{
if (!is_string($src))
die("invalid argument in set_voice_grammar()");
$this->voice_grammar["src"] = $src;
$this->voice_grammar["type"] = $type;
$this->voice_type = ""; // external grammar overrides builtin grammar
}
/**
Sets help text for voice browsers.
@param text Some helpful information concerning this input.
@param audio_src Some audio file (e.g. *.wav file) to play (optional).
@param url Some other voice deck to go to (optional).
*/
function set_voice_help($text, $audio_src="", $url="")
{
if (!is_string($text))
die("invalid argument in set_voice_help()");
$arr["text"] = $text;
$arr["src"] = $audio_src;
$arr["url"] = $url;
$this->voice_help[] = $arr;
}
/**
Sets noinput text for voice browsers.
@param text Some text to inform the user that no input has been received.
@param audio_src Some audio file (e.g. *.wav file) to play (optional).
@param url Some other voice deck to go to (optional).
*/
function set_voice_noinput($text, $audio_src="", $url="")
{
if (!is_string($text))
die("invalid argument in set_voice_noinput()");
$arr["text"] = $text;
$arr["src"] = $audio_src;
$arr["url"] = $url;
$this->voice_noinput[] = $arr;
}
/**
Sets nomatch text for voice browsers.
@param text Some text to complain that user input was not recognized.
@param audio_src Some audio file (e.g. *.wav file) to play (optional).
@param url Some other voice deck to go to (optional).
*/
function set_voice_nomatch($text, $audio_src="", $url="")
{
if (!is_string($text))
die("invalid argument in set_voice_nomatch()");
$arr["text"] = $text;
$arr["src"] = $audio_src;
$arr["url"] = $url;
$this->voice_nomatch[] = $arr;
}
function get_name()
{
return $this->name;
}
function get_value()
{
return $this->value;
}
function get_label()
{
return $this->label;
}
function get_size()
{
return $this->size;
}
function get_maxlength()
{
return $this->maxlength;
}
function get_type()
{
return $this->type;
}
function get_mode()
{
return $this->mode;
}
function get_format()
{
return $this->format;
}
function get_elementtype()
{
return HAW_INPUT;
}
function create(&$deck)
{
if ($this->type == HAW_INPUT_PASSWORD)
$type = "type=\"password\"";
else
$type = "type=\"text\"";
if ($this->size)
$size = sprintf("size=\"%d\"", $this->size);
else
$size = "";
if ($this->maxlength)
$maxlength = sprintf("maxlength=\"%d\"", $this->maxlength);
else
$maxlength = "";
if ($deck->ml == HAW_HTML)
{
if ($deck->iModestyle)
$mode = sprintf(" istyle=\"%d\"", $this->mode);
else
$mode = "";
if ($deck->MMLstyle)
{
switch ($this->mode)
{
case HAW_INPUT_ALPHABET: { $mode = " mode=\"alphabet\""; break; }
case HAW_INPUT_KATAKANA: { $mode = " mode=\"katakana\""; break; }
case HAW_INPUT_HIRAGANA: { $mode = " mode=\"hiragana\""; break; }
case HAW_INPUT_NUMERIC: { $mode = " mode=\"numeric\""; break; }
default: { $mode = " mode=\"alphabet\""; break; }
}
}
// create HTML input
if ($deck->xhtml || $deck->pureHTML)
{
printf("\n",
$this->name, HAW_specchar($this->label, $deck));
printf(" ",
$type, $this->name,
$this->name, $this->value, $size, $maxlength, $mode);
}
else
printf("%s ",
HAW_specchar($this->label, $deck), $type,
$this->name, $this->value, $size, $maxlength, $mode);
for ($i=0; $i < $this->br; $i++)
echo " \n";
}
elseif ($deck->ml == HAW_WML)
{
// create WML input
printf("%s\n",
HAW_specchar($this->label, $deck), $this->format,
$type, $this->name, $this->value, $size, $maxlength);
}
elseif ($deck->ml == HAW_HDML)
{
// create HDML input
$options = " format=\"$this->format\"";
$options .= " key=\"$this->name\"";
if ($this->type == HAW_INPUT_PASSWORD)
$options .= " NOECHO=\"true\"";
$display_content = "<" . $deck->alignment . ">\n";
$display_content .= HAW_specchar($this->label, $deck);
$display_content .= "\n";
// make user interactive entry card
$deck->hdmlcardset->make_ui_card($options, $display_content, HAW_HDML_ENTRY);
}
elseif ($deck->ml == HAW_VXML)
{
// create VoiceXML input
if ($this->voice_type)
{
if (($this->voice_type == "digits") && $this->maxlength)
$type = sprintf(" type=\"digits?maxlength=%d\"", $this->maxlength);
else
$type = sprintf(" type=\"%s\"", $this->voice_type);
}
else
$type = "";
printf("\n", $type, $this->name);
if ($this->voice_grammar)
{
// external grammar has been defined
if ($this->voice_grammar["type"])
$grammar_type = sprintf(" type=\"%s\"", $this->voice_grammar["type"]);
else
$grammar_type = ""; // let the interpreter context determine the grammar type
printf("\n",
$this->voice_grammar["src"], $grammar_type);
}
if ($this->voice_text || $this->voice_audio_src)
{
echo "";
HAW_voice_audio(HAW_specchar($this->voice_text, $deck),
$this->voice_audio_src, 0, $deck);
echo "\n";
}
// create event handlers
HAW_voice_eventhandler("help", $this->voice_help, $deck);
HAW_voice_eventhandler("noinput", $this->voice_noinput, $deck);
HAW_voice_eventhandler("nomatch", $this->voice_nomatch, $deck);
echo "\n";
}
}
};
/**
This class provides a input textarea in a HAW_form object.
Note: Creates no output for VoiceXML. Voice applications can use class
HAW_voicerecorder instead.
Examples:
$myArea1 = new HAW_textarea("fb", "", "Feedback");
$myArea2 = new HAW_textarea("msg", "Enter message here ...", "Message", 40 , 5);
$myArea2->set_br(2);
@see HAW_form
@see HAW_voicerecorder
*/
class HAW_textarea
{
var $name;
var $value;
var $label;
var $rows;
var $cols;
var $mode;
var $br;
/**
Constructor
@param name Variable in which the input is sent to the destination URL.
@param value Initial value (string!) that will be presented in the textarea.
@param label Describes your textarea on the visitor's screen/display.
@param rows Rows (optional, default: 3)
@param cols Columns (optional, default: 16)
*/
function HAW_textarea($name, $value, $label, $rows=3, $cols=16)
{
$this->name = $name;
$this->value = $value;
$this->label = $label;
$this->rows = $rows;
$this->cols = $cols;
$this->mode = HAW_INPUT_ALPHABET;
$this->br = 1;
}
/**
Set input mode/istyle for japanese MML/i-mode devices
@param mode input mode
HAW_INPUT_ALPHABET (default)
HAW_INPUT_KATAKANA
HAW_INPUT_HIRAGANA
HAW_INPUT_NUMERIC
*/
function set_mode($mode)
{
$this->mode = $mode;
}
/**
Sets the number of line breaks (CRLF) after textarea. (default: 1)
Note: Has no effect in WML/HDML.
@param br Some number of line breaks.
*/
function set_br($br)
{
if (!is_int($br) || ($br < 0))
die("invalid argument in set_br()");
$this->br = $br;
}
function get_name()
{
return $this->name;
}
function get_value()
{
return $this->value;
}
function get_label()
{
return $this->label;
}
function get_mode()
{
return $this->mode;
}
function get_elementtype()
{
return HAW_TEXTAREA;
}
function create(&$deck)
{
if ($deck->ml == HAW_HTML)
{
if ($deck->iModestyle)
$mode = sprintf(" istyle=\"%d\"", $this->mode);
else
$mode = "";
if ($deck->MMLstyle)
{
switch ($this->mode)
{
case HAW_INPUT_ALPHABET: { $mode = " mode=\"alphabet\""; break; }
case HAW_INPUT_KATAKANA: { $mode = " mode=\"katakana\""; break; }
case HAW_INPUT_HIRAGANA: { $mode = " mode=\"hiragana\""; break; }
case HAW_INPUT_NUMERIC: { $mode = " mode=\"numeric\""; break; }
default: { $mode = " mode=\"alphabet\""; break; }
}
}
if (!$deck->iModestyle && !$deck->MMLstyle)
$wrap = sprintf(" wrap=\"virtual\"");
else
$wrap = "";
// create HTML input
printf("%s ",
HAW_specchar($this->label, $deck), $this->name, $this->rows,
$this->cols, $mode, $wrap, $this->value);
for ($i=0; $i < $this->br; $i++)
echo " \n";
}
elseif ($deck->ml == HAW_WML)
{
// create WML input
printf("%s\n",
HAW_specchar($this->label, $deck),
$this->name, $this->value);
}
elseif ($deck->ml == HAW_HDML)
{
// create HDML input
$options = " key=\"$this->name\"";
$display_content = "<" . $deck->alignment . ">\n";
$display_content .= HAW_specchar($this->label, $deck);
$display_content .= "\n";
// make user interactive entry card
$deck->hdmlcardset->make_ui_card($options, $display_content, HAW_HDML_ENTRY);
}
elseif ($deck->ml == HAW_VXML)
{
// no output for VoiceXML possible
}
}
};
/**
This class provides a select element in a HAW_form object.
It allows to create optimized WML for WAP devices which
are capable to interprete the Openwave GUI extensions for WML 1.3. All other
WAP devices receive WML 1.1 compatible markup code, which is quite similar to
the markup code created by the HAW_radio class.
Examples:
$mySelect = new HAW_select("color");
$mySelect->add_option("Blue", "b");
$mySelect->add_option("Red", "r", HAW_SELECTED);
$mySelect->add_option("Yellow", "y");
@see HAW_form
*/
class HAW_select
{
var $name;
var $type;
var $value;
var $options;
var $number_of_options;
var $voice_text;
var $voice_audio_src;
var $voice_help;
var $voice_noinput;
var $voice_nomatch;
/**
Constructor
@param name Variable in which the information about the selected option is sent to
the destination URL.
@param type (optional)
Type of select area:
HAW_SELECT_POPUP: popup the whole selection list (default)
HAW_SELECT_SPIN: rotate options on a WAP device screen
*/
function HAW_select($name, $type=HAW_SELECT_POPUP)
{
$this->name = $name;
$this->type = $type;
$this->value = false;
$this->number_of_options = 0;
$this->voice_text = HAW_VOICE_ENUMERATE;
$this->voice_audio_src = "";
$this->voice_help = array();
$this->voice_noinput = array();
$this->voice_nomatch = array();
}
/**
Adds one option to a HAW_select object.
@param label Describes the option on the visitor's screen/display.
@param value Value (string!) sent in the "name" variable, if this option is selected.
@param is_selected (optional) Allowed values are HAW_SELECTED or HAW_NOTSELECTED
(default). Note: Setting to "selected" will overwrite previous "selected"
options of this HAW_select object.
*/
function add_option($label, $value, $is_selected=HAW_NOTSELECTED)
{
if (!$label || !$value)
die("invalid argument in add_option()");
$this->options[$this->number_of_options]["label"] = $label;
$this->options[$this->number_of_options]["value"] = $value;
if (!$this->value || ($is_selected == HAW_SELECTED))
$this->value = $value;
$this->number_of_options++;
}
/**
Sets text to be spoken by voice browsers.
@param text Some alternative text that replaces the enumeration of select options.
@param audio_src Some audio file (e.g. *.wav file) to play (optional).
*/
function set_voice_text($text, $audio_src="")
{
if (!is_string($text))
die("invalid argument in set_voice_text()");
$this->voice_text = $text;
$this->voice_audio_src = $audio_src;
}
/**
Sets help text for voice browsers.
@param text Some helpful information concerning this select element.
@param audio_src Some audio file (e.g. *.wav file) to play (optional).
@param url Some other voice deck to go to (optional).
*/
function set_voice_help($text, $audio_src="", $url="")
{
if (!is_string($text))
die("invalid argument in set_voice_help()");
$arr["text"] = $text;
$arr["src"] = $audio_src;
$arr["url"] = $url;
$this->voice_help[] = $arr;
}
/**
Sets noinput text for voice browsers.
@param text Some text to inform the user that no input has been received.
@param audio_src Some audio file (e.g. *.wav file) to play (optional).
@param url Some other voice deck to go to (optional).
*/
function set_voice_noinput($text, $audio_src="", $url="")
{
if (!is_string($text))
die("invalid argument in set_voice_noinput()");
$arr["text"] = $text;
$arr["src"] = $audio_src;
$arr["url"] = $url;
$this->voice_noinput[] = $arr;
}
/**
Sets nomatch text for voice browsers.
@param text Some text to complain that user input was not recognized.
@param audio_src Some audio file (e.g. *.wav file) to play (optional).
@param url Some other voice deck to go to (optional).
*/
function set_voice_nomatch($text, $audio_src="", $url="")
{
if (!is_string($text))
die("invalid argument in set_voice_nomatch()");
$arr["text"] = $text;
$arr["src"] = $audio_src;
$arr["url"] = $url;
$this->voice_nomatch[] = $arr;
}
function get_name()
{
return $this->name;
}
function get_value()
{
return $this->value;
}
function get_elementtype()
{
return HAW_SELECT;
}
function create(&$deck)
{
if ($deck->ml == HAW_HTML)
{
// create HTML select
if ($deck->xhtml || $deck->pureHTML)
{
// dummy label for select element (needed for Bobby approval)
// object to be enhanced in future versions ...
printf("\n", $this->name, " ");
printf("