1 |
<?php |
2 |
|
3 |
// HAWHAW: HTML and WML hybrid adapted webserver |
4 |
// PHP class library |
5 |
// Copyright (C) 2004 Norbert Huffschmid |
6 |
// Last modified: 18. August 2004 |
7 |
// |
8 |
// This library is free software; you can redistribute it and/or modify it under the |
9 |
// terms of the GNU Library General Public License as published by the Free Software |
10 |
// Foundation; either version 2 of the License, or (at your option) any later |
11 |
// version. |
12 |
// |
13 |
// This library is distributed in the hope that it will be useful, but WITHOUT ANY |
14 |
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
15 |
// PARTICULAR PURPOSE. See the GNU Library General Public License for more details. |
16 |
// http://www.gnu.org/copyleft/lgpl.html |
17 |
// |
18 |
// If you modify this library, you have to make sure that the "powered by HAWHAW" |
19 |
// copyright link below the display area is kept unchanged. |
20 |
// |
21 |
// For further information about this library and its license terms please visit: |
22 |
// http://www.hawhaw.de/ |
23 |
|
24 |
// miscellaneous constants |
25 |
define("HAW_VERSION", "HAWHAW V5.7"); |
26 |
define("HAW_COPYRIGHT", "(C) Norbert Huffschmid"); |
27 |
|
28 |
// constants for markup languages |
29 |
define("HAW_HTML", 1); |
30 |
define("HAW_WML", 2); |
31 |
define("HAW_HDML", 3); |
32 |
define("HAW_VXML", 4); |
33 |
|
34 |
// constants for forced markup output |
35 |
define("HAW_OUTPUT_AUTOMATIC", "automatic"); |
36 |
define("HAW_OUTPUT_BIGSCREEN", "bigscreen"); |
37 |
define("HAW_OUTPUT_WAP", "wap"); |
38 |
define("HAW_OUTPUT_HDML", "hdml"); |
39 |
define("HAW_OUTPUT_PDA", "pda"); |
40 |
define("HAW_OUTPUT_IMODE", "imode"); |
41 |
define("HAW_OUTPUT_MML", "mml"); |
42 |
define("HAW_OUTPUT_VOICEXML", "voicexml"); |
43 |
define("HAW_OUTPUT_XHTML", "xhtml"); |
44 |
define("HAW_OUTPUT_LYNX", "lynx"); |
45 |
// ----- proprietary output types (for debugging purposes only) ------ |
46 |
define("HAW_OUTPUT_UP", "up"); // UP browser |
47 |
define("HAW_OUTPUT_OWGUI", "owgui");// Openwave GUI |
48 |
define("HAW_OUTPUT_PVX", "pvx"); // PublicVoiceXML |
49 |
|
50 |
// constants for page elements |
51 |
define("HAW_PLAINTEXT", 1); |
52 |
define("HAW_IMAGE", 2); |
53 |
define("HAW_TABLE", 3); |
54 |
define("HAW_FORM", 4); |
55 |
define("HAW_LINK", 5); |
56 |
define("HAW_PHONE", 6); |
57 |
define("HAW_LINKSET", 7); |
58 |
define("HAW_INPUT", 8); |
59 |
define("HAW_TEXTAREA", 9); |
60 |
define("HAW_BANNER", 10); |
61 |
define("HAW_SELECT", 11); |
62 |
define("HAW_CHECKBOX", 12); |
63 |
define("HAW_RADIO", 13); |
64 |
define("HAW_HIDDEN", 14); |
65 |
define("HAW_SUBMIT", 15); |
66 |
define("HAW_RAW", 16); |
67 |
define("HAW_RULE", 17); |
68 |
define("HAW_VOICERECORDER", 18); |
69 |
define("HAW_USERDEFINED", 19); |
70 |
|
71 |
// constants for page setup |
72 |
define("HAW_ALIGN_LEFT", 1); |
73 |
define("HAW_ALIGN_RIGHT", 2); |
74 |
define("HAW_ALIGN_CENTER", 3); |
75 |
define("HAW_NOTITLE", -1); |
76 |
|
77 |
// constants for text formatting |
78 |
define("HAW_TEXTFORMAT_NORMAL", 0); |
79 |
define("HAW_TEXTFORMAT_BOLD", 1); |
80 |
define("HAW_TEXTFORMAT_UNDERLINE", 2); |
81 |
define("HAW_TEXTFORMAT_ITALIC", 4); |
82 |
define("HAW_TEXTFORMAT_BIG", 8); |
83 |
define("HAW_TEXTFORMAT_SMALL", 16); |
84 |
define("HAW_TEXTFORMAT_BOXED", 32); |
85 |
|
86 |
// constants for input treatment |
87 |
define("HAW_INPUT_TEXT", 0); |
88 |
define("HAW_INPUT_PASSWORD", 1); |
89 |
|
90 |
// constants for select treatment |
91 |
define("HAW_NOTSELECTED", 0); |
92 |
define("HAW_SELECTED", 1); |
93 |
define("HAW_SELECT_POPUP", 0); |
94 |
define("HAW_SELECT_SPIN", 1); |
95 |
|
96 |
// constants for radio and checkbox treatment |
97 |
define("HAW_NOTCHECKED", 0); |
98 |
define("HAW_CHECKED", 1); |
99 |
|
100 |
// constants for link treatment |
101 |
define("HAW_NO_ACCESSKEY", -1); |
102 |
|
103 |
// constants for HDML card types |
104 |
define("HAW_HDML_DISPLAY", 0); |
105 |
define("HAW_HDML_ENTRY", 1); |
106 |
define("HAW_HDML_CHOICE", 2); |
107 |
define("HAW_HDML_NODISPLAY", 3); |
108 |
|
109 |
// constants for banners |
110 |
define("HAW_TOP", 0); |
111 |
define("HAW_BOTTOM", 1); |
112 |
define("HAW_NOLINK", -1); |
113 |
|
114 |
// constants for MML input modes |
115 |
define("HAW_INPUT_HIRAGANA", 1); // values correspond to according cHTML values! |
116 |
define("HAW_INPUT_KATAKANA", 2); |
117 |
define("HAW_INPUT_ALPHABET", 3); |
118 |
define("HAW_INPUT_NUMERIC", 4); |
119 |
|
120 |
// constants for VoiceXML |
121 |
define("HAW_VOICE_PAUSE", 300); // pause after text output |
122 |
define("HAW_VOICE_ENUMERATE", 1); // activate enumeration |
123 |
|
124 |
// constants for bigscreen default display |
125 |
define("HAW_DISP_BGCOLOR", "#00BB77"); // green HAWHAW display |
126 |
define("HAW_DISP_LINKCOLOR", "#004411"); // dark green |
127 |
define("HAW_DISP_VLINKCOLOR", "#006633"); // lighter green |
128 |
define("HAW_DISP_FACE", "Arial,Times"); |
129 |
|
130 |
function HAW_specchar($input, $deck) |
131 |
{ |
132 |
// convert special characters |
133 |
|
134 |
$temp = htmlspecialchars($input); // translate &"<> to HTML entities |
135 |
$output = ""; |
136 |
|
137 |
if ($deck->ml == HAW_WML) |
138 |
$temp = str_replace("$", "$$", $temp); // escape $ character in WML |
139 |
elseif ($deck->ml == HAW_HDML) |
140 |
$temp = str_replace("$", "&dol;", $temp); // escape $ character in HDML |
141 |
|
142 |
if (strstr($deck->charset,"iso-8859-1")) |
143 |
{ |
144 |
// character set iso-8859-1 (trivial mapping 1:1) |
145 |
|
146 |
for ($i=0; $i<strlen($temp); $i++) |
147 |
{ |
148 |
// do for each character of $temp |
149 |
|
150 |
if (ord(substr($temp, $i, 1)) > 127) |
151 |
// translate character into &#...; sequence |
152 |
$output .= "&#" . ord(substr($temp, $i, 1)) . ";"; |
153 |
else |
154 |
// copy character unchanged |
155 |
$output .= substr($temp, $i, 1); |
156 |
} |
157 |
} |
158 |
else |
159 |
{ |
160 |
// other character set than iso-8859-1 |
161 |
|
162 |
if ($deck->unicodearray) |
163 |
{ |
164 |
// array with mapping rules was prepared earlier |
165 |
|
166 |
if(!trim($temp)) |
167 |
return $temp; |
168 |
|
169 |
while($temp!="") |
170 |
{ |
171 |
// do for each character in string |
172 |
|
173 |
if (ord(substr($temp,0,1))>127) |
174 |
{ |
175 |
$index = ord(substr($temp, 0, 1)); // ASCII value of first character from $temp |
176 |
|
177 |
if ($deck->unicodearray[$index]) |
178 |
{ |
179 |
// unicode stored for this one byte code |
180 |
// insert unicode and go 1 byte further |
181 |
|
182 |
$output .= "&#" . $deck->unicodearray[$index] . ";"; |
183 |
$temp = substr($temp, 1, strlen($temp)); |
184 |
} |
185 |
else |
186 |
{ |
187 |
// check if there's a unibyte code stored for 1st two bytes |
188 |
|
189 |
$index = $index * 256 + ord(substr($temp, 1, 1)); |
190 |
|
191 |
if ($deck->unicodearray[$index]) |
192 |
{ |
193 |
// unicode stored for this 2-byte code! |
194 |
// insert unicode and go 2 bytes further |
195 |
|
196 |
$output .= "&#" . $deck->unicodearray[$index] . ";"; |
197 |
$temp = substr($temp, 2, strlen($temp)); |
198 |
} |
199 |
else |
200 |
{ |
201 |
// no mapping info for 1st 2 bytes available ==> leave it as it is |
202 |
|
203 |
$output .= substr($temp, 0, 1); |
204 |
$temp = substr($temp, 1, strlen($temp)); |
205 |
} |
206 |
} |
207 |
} |
208 |
else |
209 |
{ |
210 |
// character <= 127 ==> leave it as it is |
211 |
$output .= substr($temp, 0, 1); |
212 |
$temp = substr($temp, 1, strlen($temp)); |
213 |
} |
214 |
} |
215 |
} |
216 |
|
217 |
else |
218 |
$output = $temp; // no mapping to unicode required |
219 |
} |
220 |
|
221 |
return($output); |
222 |
} |
223 |
|
224 |
|
225 |
function HAW_voice_audio($text, $audio_src, $pause, $deck) |
226 |
{ |
227 |
// print VoiceXML tags for audio output |
228 |
|
229 |
if ($audio_src) |
230 |
// play audio file if possible |
231 |
printf("<audio src=\"%s\">%s</audio>", $audio_src, $text); |
232 |
else |
233 |
// speak text only |
234 |
echo $text; |
235 |
|
236 |
if (($pause > 0) && $deck->supportsVXMLBreakTag) |
237 |
printf("<break time=\"%dms\"/>", $pause); |
238 |
} |
239 |
|
240 |
|
241 |
function HAW_voice_eventhandler($handler, $audio_array, $deck) |
242 |
{ |
243 |
// create VoiceXML event handler, e.g. "help", "nomatch", "noinput" |
244 |
|
245 |
if (count($audio_array) > 0) |
246 |
{ |
247 |
while (list($key, $val) = each($audio_array)) |
248 |
{ |
249 |
if ($key > 0) |
250 |
$count = sprintf(" count=\"%d\"", $key+1); |
251 |
else |
252 |
$count = ""; |
253 |
|
254 |
printf("<catch%s event=\"%s\">", $count, $handler); |
255 |
|
256 |
HAW_voice_audio(HAW_specchar($val["text"], $deck), $val["src"], 0, $deck); |
257 |
|
258 |
if ($val["url"]) |
259 |
printf("<goto next=\"%s\"/>", $val["url"]); |
260 |
|
261 |
echo "</catch>\n"; |
262 |
} |
263 |
} |
264 |
} |
265 |
|
266 |
|
267 |
function HAW_handle_forced_output(&$url, $hawoutput) |
268 |
{ |
269 |
// add hawoutput query parameter to url in order to force special HAWHAW output type |
270 |
|
271 |
if ($hawoutput) |
272 |
{ |
273 |
// hawoutput parameter to be added |
274 |
|
275 |
if (strchr($url, '?')) |
276 |
$url .= "&hawoutput=" . $hawoutput; |
277 |
else |
278 |
$url .= "?hawoutput=" . $hawoutput; |
279 |
} |
280 |
} |
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
class HAW_hdmlcardset |
288 |
{ |
289 |
var $number_of_cards; |
290 |
var $card; // array of cards |
291 |
var $title; |
292 |
var $final_action = ""; // action of last card |
293 |
var $defaults; // default values of variables |
294 |
var $disable_cache; |
295 |
var $debug; |
296 |
var $charset; |
297 |
|
298 |
|
299 |
function HAW_hdmlcardset($title, $defaults, $disable_cache, $debug, $charset) |
300 |
{ |
301 |
$this->title = $title; |
302 |
$this->defaults = $defaults; |
303 |
$this->disable_cache = $disable_cache; |
304 |
$this->debug = $debug; |
305 |
$this->charset = $charset; |
306 |
|
307 |
// initialize first card of cardset as DISPLAY card |
308 |
|
309 |
$this->card[0]["type"] = HAW_HDML_DISPLAY; |
310 |
|
311 |
$this->card[0]["options"] = " name=\"1\""; |
312 |
|
313 |
if ($title) |
314 |
$this->card[0]["options"] .= " title=\"$title\""; |
315 |
|
316 |
$this->number_of_cards = 1; |
317 |
} |
318 |
|
319 |
|
320 |
function add_display_content($display_content) |
321 |
{ |
322 |
// enhance the display content of the current card with the received content |
323 |
|
324 |
// number_of_cards-1 is the index of the current card, i.e. the last card |
325 |
|
326 |
if ($this->card[$this->number_of_cards-1]["type"] == HAW_HDML_DISPLAY) |
327 |
{ |
328 |
// current card is display card ==> continue with content |
329 |
|
330 |
if (isset($this->card[$this->number_of_cards-1]["display_content"])) |
331 |
$this->card[$this->number_of_cards-1]["display_content"] .= $display_content; |
332 |
else |
333 |
$this->card[$this->number_of_cards-1]["display_content"] = $display_content; |
334 |
} |
335 |
else |
336 |
{ |
337 |
// current card is entry or choice card |
338 |
// ==> create new display card to display received content |
339 |
// ==> link current card to this new display card |
340 |
|
341 |
$this->card[$this->number_of_cards]["type"] = HAW_HDML_DISPLAY; |
342 |
|
343 |
$cardname = sprintf(" name=\"%d\"", $this->number_of_cards+1); |
344 |
$this->card[$this->number_of_cards]["options"] .= $cardname; |
345 |
|
346 |
if ($this->title) |
347 |
$this->card[$this->number_of_cards]["options"] .= " title=\"$this->title\""; |
348 |
|
349 |
$this->card[$this->number_of_cards]["display_content"] = $display_content; |
350 |
|
351 |
$action = sprintf("<action type=\"accept\" task=\"go\" dest=\"#%d\">\n", |
352 |
$this->number_of_cards+1); |
353 |
$this->card[$this->number_of_cards-1]["action"] = $action; |
354 |
|
355 |
$this->number_of_cards++; |
356 |
} |
357 |
} |
358 |
|
359 |
|
360 |
function make_ui_card($options, $generic_content, $cardtype) |
361 |
{ |
362 |
// make user interactive card (ENTRY or CHOICE card) |
363 |
|
364 |
if ($this->card[$this->number_of_cards-1]["type"] == HAW_HDML_DISPLAY) |
365 |
{ |
366 |
// current card is display card |
367 |
|
368 |
// ==> make an entry/choice card out of it |
369 |
$this->card[$this->number_of_cards-1]["type"] = $cardtype; |
370 |
|
371 |
// append options to the already existing ones |
372 |
if (!isset($this->card[$this->number_of_cards-1]["options"])) |
373 |
$this->card[$this->number_of_cards-1]["options"] = ""; |
374 |
|
375 |
$this->card[$this->number_of_cards-1]["options"] .= $options; |
376 |
|
377 |
// append received content to the already existing one |
378 |
if (!isset($this->card[$this->number_of_cards-1]["display_content"])) |
379 |
$this->card[$this->number_of_cards-1]["display_content"] = ""; |
380 |
|
381 |
$this->card[$this->number_of_cards-1]["display_content"] .= $generic_content; |
382 |
} |
383 |
else |
384 |
{ |
385 |
// current card is already entry or choice card |
386 |
// ==> create new entry/choice card |
387 |
// ==> link current card to this new entry/choice card |
388 |
|
389 |
$this->card[$this->number_of_cards]["type"] = $cardtype; |
390 |
|
391 |
$cardname = sprintf(" name=\"%d\"", $this->number_of_cards+1); |
392 |
|
393 |
if (!isset($this->card[$this->number_of_cards]["options"])) |
394 |
$this->card[$this->number_of_cards]["options"] = ""; |
395 |
|
396 |
$this->card[$this->number_of_cards]["options"] .= $cardname; |
397 |
|
398 |
if ($this->title) |
399 |
$this->card[$this->number_of_cards]["options"] .= " title=\"$this->title\""; |
400 |
|
401 |
$this->card[$this->number_of_cards]["options"] .= $options; |
402 |
|
403 |
$this->card[$this->number_of_cards]["display_content"] = $generic_content; |
404 |
|
405 |
$action = sprintf("<action type=\"accept\" task=\"go\" dest=\"#%d\">\n", |
406 |
$this->number_of_cards+1); |
407 |
$this->card[$this->number_of_cards-1]["action"] = $action; |
408 |
|
409 |
$this->number_of_cards++; |
410 |
} |
411 |
} |
412 |
|
413 |
|
414 |
function set_final_action($action) |
415 |
{ |
416 |
$this->final_action = $action; |
417 |
} |
418 |
|
419 |
|
420 |
function create_hdmldeck() |
421 |
{ |
422 |
if (!$this->debug) |
423 |
{ |
424 |
$ct = sprintf("content-type: text/x-hdml;charset=%s", $this->charset); |
425 |
header($ct); |
426 |
} |
427 |
|
428 |
$ttl = ($this->disable_cache ? " TTL=\"0\"" : ""); |
429 |
|
430 |
printf("<hdml version=\"3.0\" public=\"true\"%s>\n", $ttl); |
431 |
printf("<!-- Generated by %s %s -->\n", HAW_VERSION, HAW_COPYRIGHT); |
432 |
|
433 |
// create NODISPLAY card if it's necessary to initialize variables |
434 |
if ($this->defaults) |
435 |
{ |
436 |
$vars = ""; |
437 |
|
438 |
while (list($d_key, $d_val) = each($this->defaults)) |
439 |
$vars .= sprintf("%s=%s&", $d_val['name'], $d_val['value']); |
440 |
|
441 |
// strip terminating '&' |
442 |
$vars = substr($vars, 0, -5); |
443 |
|
444 |
echo "<nodisplay>\n"; |
445 |
printf("<action type=\"accept\" task=\"go\" dest=\"#1\" vars=\"%s\">\n", $vars); |
446 |
echo "</nodisplay>\n"; |
447 |
} |
448 |
|
449 |
// set action of last card |
450 |
$this->card[$this->number_of_cards-1]["action"] = $this->final_action; |
451 |
|
452 |
// create all cards of card set |
453 |
$i = 0; |
454 |
while ( $i < $this->number_of_cards ) |
455 |
{ |
456 |
if ($this->card[$i]["type"] == HAW_HDML_DISPLAY) |
457 |
$cardtype = "display"; |
458 |
elseif ($this->card[$i]["type"] == HAW_HDML_ENTRY) |
459 |
$cardtype = "entry"; |
460 |
elseif ($this->card[$i]["type"] == HAW_HDML_CHOICE) |
461 |
$cardtype = "choice"; |
462 |
|
463 |
printf("<%s%s>\n", $cardtype, $this->card[$i]["options"]); |
464 |
printf("%s", $this->card[$i]["action"]); |
465 |
printf("%s", $this->card[$i]["display_content"]); |
466 |
printf("</%s>\n", $cardtype); |
467 |
|
468 |
$i++; |
469 |
} |
470 |
|
471 |
echo "</hdml>\n"; |
472 |
} |
473 |
}; |
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 |
|
480 |
/** |
481 |
This class is the top level class of all HAWHAW classes. Your page should consist |
482 |
of exactly one HAW_deck object. For WML browsers one deck with one card will be |
483 |
generated. For HDML browsers one deck including as much cards as necessary will |
484 |
generated. HTML browsers will receive a normal HTML page, PDA browsers will |
485 |
receive handheldfriendly HTML etc. |
486 |
<p>Do not overload HAW_deck objects! Remember that a lot of older WAP devices can not |
487 |
handle more than about 1400 byte of compiled data. |
488 |
<p><b>Examples:</b><p> |
489 |
$myPage = new HAW_deck();<br> |
490 |
$myPage = new HAW_deck("My WAP page");<br> |
491 |
$myPage = new HAW_deck("", HAW_ALIGN_CENTER);<br> |
492 |
$myPage = new HAW_deck("PDA edition", HAW_ALIGN_CENTER, HAW_OUTPUT_PDA);<br> |
493 |
...<br> |
494 |
$myPage->set_bgcolor("blue");<br> |
495 |
...<br> |
496 |
$myPage->add_text($myText);<br> |
497 |
...<br> |
498 |
$myPage->create_page(); |
499 |
*/ |
500 |
class HAW_deck |
501 |
{ |
502 |
var $title; |
503 |
var $alignment; |
504 |
var $output; |
505 |
var $timeout; |
506 |
var $red_url; |
507 |
var $disable_cache = false; |
508 |
var $ml; |
509 |
var $element; |
510 |
var $number_of_elements; |
511 |
var $number_of_forms; |
512 |
var $number_of_linksets; |
513 |
var $number_of_links; |
514 |
var $number_of_phones; |
515 |
var $top_banners; |
516 |
var $number_of_top_banners = 0; |
517 |
var $bottom_banners; |
518 |
var $number_of_bottom_banners = 0; |
519 |
var $display_banners = true; |
520 |
var $waphome; |
521 |
var $hdmlcardset; |
522 |
|
523 |
// browser dependent properties |
524 |
var $pureHTML = true; // Big-screen-HTML-code (default) |
525 |
var $PDAstyle = false; // PDA browsers needs special HTML code |
526 |
var $iModestyle = false; // cHTML too |
527 |
var $upbrowser = false; // UP browser |
528 |
var $owgui_1_3 = false; // Openwave GUI Extensions for WML 1.3 |
529 |
var $MMLstyle = false; // Mobile Markup Language |
530 |
var $lynx = false; // Lynx text browser |
531 |
var $xhtml = false; // XHTML MP (mobile profile) |
532 |
var $gif_enabled = false; // browser can not deal with GIF images |
533 |
var $submitViaLink = false; // use link instead of <do> |
534 |
var $supportsVXMLBreakTag = true; // false for PublicVoiceXML browser only |
535 |
var $css_enabled = false; // support of cascading style sheets (HTML) |
536 |
var $debug = false; // HAWHAW debugger off |
537 |
var $hawoutput = ""; // no forced output |
538 |
|
539 |
// device simulator properies |
540 |
var $use_simulator = false; // decide whether default simulator device is to be used |
541 |
var $skin = ""; // contains css url, where skinning is defined |
542 |
|
543 |
// character set properties |
544 |
var $charset = "iso-8859-1"; // default charset |
545 |
var $unicodemaptab; // filename of cross mapping table to map country |
546 |
// specific character code into unicode |
547 |
var $unicodearray; // array containing cross mapping table |
548 |
|
549 |
// language properties |
550 |
var $language = ""; |
551 |
|
552 |
|
553 |
// display properties for HTML |
554 |
|
555 |
// page background properties |
556 |
var $bgcolor = ""; |
557 |
var $background = ""; |
558 |
|
559 |
// display (table) properties |
560 |
var $border = 8; |
561 |
var $disp_bgcolor = ""; |
562 |
var $disp_background = ""; |
563 |
var $width = 200; |
564 |
var $height = 200; |
565 |
|
566 |
// text properties |
567 |
var $size = ""; |
568 |
var $color = ""; |
569 |
var $link_color = ""; |
570 |
var $vlink_color = ""; |
571 |
var $face = ""; |
572 |
var $fontstyle_attrbs = ""; |
573 |
|
574 |
// voice properties |
575 |
var $voice_links = ""; |
576 |
var $voice_timeout = 0; |
577 |
var $voice_text = ""; |
578 |
var $voice_audio_src = ""; |
579 |
var $voice_jingle = ""; |
580 |
var $voice_help = array(); |
581 |
var $voice_noinput = array(); |
582 |
var $voice_nomatch = array(); |
583 |
var $voice_property = array(); |
584 |
var $voice_navigator = array(); |
585 |
|
586 |
/** |
587 |
Constructor |
588 |
@param title (optional, default: HAW_NOTITLE) <br> |
589 |
If a string is provided here, it will be displayed |
590 |
in the HTML title bar, respectively somewhere on the WAP display. Using a |
591 |
title you will normally have to spend one of your few lines on your WAP |
592 |
display. Consider that some WAP phones/SDK's and handheld devices don't |
593 |
display the title at all. |
594 |
@param alignment (optional, default: HAW_ALIGN_LEFT) <br> |
595 |
You can enter HAW_ALIGN_CENTER |
596 |
or HAW_ALIGN_RIGHT to modify the alignment of the whole page. |
597 |
@param output (optional, default: HAW_OUTPUT_AUTOMATIC) <br> |
598 |
You can override HAWHAW's automatic browser detection and force a certain |
599 |
output type.<br> |
600 |
Possible value are:<br> |
601 |
<ul> |
602 |
<li>HAW_OUTPUT_AUTOMATIC (default)</li> |
603 |
<li>HAW_OUTPUT_BIGSCREEN</li> |
604 |
<li>HAW_OUTPUT_WAP</li> |
605 |
<li>HAW_OUTPUT_HDML</li> |
606 |
<li>HAW_OUTPUT_PDA</li> |
607 |
<li>HAW_OUTPUT_IMODE</li> |
608 |
<li>HAW_OUTPUT_MML</li> |
609 |
<li>HAW_OUTPUT_VOICEXML</li> |
610 |
<li>HAW_OUTPUT_XHTML</li> |
611 |
<li>HAW_OUTPUT_LYNX</li> |
612 |
</ul><br> |
613 |
With this parameter you can offer dedicated links for PC's, WAP phones, PDA's, |
614 |
XHTML phones etc. |
615 |
*/ |
616 |
function HAW_deck($title=HAW_NOTITLE, $alignment=HAW_ALIGN_LEFT, $output=HAW_OUTPUT_AUTOMATIC) |
617 |
{ |
618 |
// determine environment variables |
619 |
if (isset($_SERVER['HTTP_USER_AGENT'])) |
620 |
$HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT']; |
621 |
else |
622 |
$HTTP_USER_AGENT = ""; |
623 |
|
624 |
if (isset($_SERVER['HTTP_ACCEPT'])) |
625 |
$HTTP_ACCEPT = $_SERVER['HTTP_ACCEPT']; |
626 |
else |
627 |
$HTTP_ACCEPT = ""; |
628 |
|
629 |
if (isset($_SERVER['HTTP_HOST'])) |
630 |
$HTTP_HOST = $_SERVER['HTTP_HOST']; |
631 |
else |
632 |
$HTTP_HOST = ""; |
633 |
|
634 |
if (isset($_SERVER['SCRIPT_NAME'])) |
635 |
$SCRIPT_NAME = $_SERVER['SCRIPT_NAME']; |
636 |
else |
637 |
$SCRIPT_NAME = ""; |
638 |
|
639 |
if ($title != HAW_NOTITLE) |
640 |
$this->title = $title; |
641 |
|
642 |
if ($alignment == HAW_ALIGN_CENTER) |
643 |
$this->alignment = "center"; |
644 |
elseif ($alignment == HAW_ALIGN_RIGHT) |
645 |
$this->alignment = "right"; |
646 |
else |
647 |
$this->alignment = "left"; |
648 |
|
649 |
$this->timeout = 0; |
650 |
$this->red_url = ""; |
651 |
|
652 |
$this->waphome = "http://" . $HTTP_HOST . $SCRIPT_NAME; |
653 |
|
654 |
// query parameter "hawdebug" can be used to debug hawhaw output |
655 |
// enter http://wap.yourdomain.com/yourscript.php?hawdebug=wap |
656 |
// resp. other value defined above for HAW_OUTPUT_... |
657 |
// query parameter "hawoutput" can be used for overwrite output type |
658 |
// enter http://wap.yourdomain.com/yourscript.php?hawoutput=wap |
659 |
global $HTTP_GET_VARS; |
660 |
$forced_output = ""; |
661 |
|
662 |
if (isset ($HTTP_GET_VARS["hawdebug"])) |
663 |
{ |
664 |
$forced_output = $HTTP_GET_VARS["hawdebug"]; |
665 |
$this->debug = true; |
666 |
} |
667 |
elseif (isset ($HTTP_GET_VARS["hawoutput"])) |
668 |
{ |
669 |
$forced_output = $HTTP_GET_VARS["hawoutput"]; |
670 |
$this->hawoutput = $HTTP_GET_VARS["hawoutput"]; |
671 |
} |
672 |
elseif ($output != HAW_OUTPUT_AUTOMATIC) |
673 |
$forced_output = $output; |
674 |
|
675 |
// manipulate HTTP environment variables in case of forced output |
676 |
if ($forced_output) |
677 |
{ |
678 |
if ($forced_output == HAW_OUTPUT_BIGSCREEN) |
679 |
{ |
680 |
$HTTP_ACCEPT = ""; |
681 |
$HTTP_USER_AGENT = "MSIE"; |
682 |
} |
683 |
elseif ($forced_output == HAW_OUTPUT_WAP) |
684 |
{ |
685 |
$HTTP_ACCEPT = "text/vnd.wap.wml"; |
686 |
$HTTP_USER_AGENT = ""; |
687 |
} |
688 |
elseif ($forced_output == HAW_OUTPUT_HDML) |
689 |
{ |
690 |
$HTTP_ACCEPT = "hdml;version=3.0"; |
691 |
$HTTP_USER_AGENT = ""; |
692 |
} |
693 |
elseif ($forced_output == HAW_OUTPUT_PDA) |
694 |
{ |
695 |
$HTTP_ACCEPT = ""; |
696 |
$HTTP_USER_AGENT = "avantgo"; |
697 |
} |
698 |
elseif ($forced_output == HAW_OUTPUT_IMODE) |
699 |
{ |
700 |
$HTTP_ACCEPT = ""; |
701 |
$HTTP_USER_AGENT = "DoCoMo"; |
702 |
} |
703 |
elseif ($forced_output == HAW_OUTPUT_MML) |
704 |
{ |
705 |
$HTTP_ACCEPT = ""; |
706 |
$HTTP_USER_AGENT = "J-"; |
707 |
} |
708 |
elseif ($forced_output == HAW_OUTPUT_VOICEXML) |
709 |
{ |
710 |
$HTTP_ACCEPT = "text/x-vxml"; |
711 |
$HTTP_USER_AGENT = "Tellme"; |
712 |
} |
713 |
elseif ($forced_output == HAW_OUTPUT_XHTML) |
714 |
{ |
715 |
$HTTP_ACCEPT = "application/vnd.wap.xhtml+xml"; |
716 |
$HTTP_USER_AGENT = ""; |
717 |
} |
718 |
elseif ($forced_output == HAW_OUTPUT_LYNX) |
719 |
{ |
720 |
$HTTP_ACCEPT = ""; |
721 |
$HTTP_USER_AGENT = "Lynx"; |
722 |
} |
723 |
elseif ($forced_output == HAW_OUTPUT_UP) |
724 |
{ |
725 |
$HTTP_ACCEPT = "text/vnd.wap.wml"; |
726 |
$HTTP_USER_AGENT = "UP.Browser"; |
727 |
} |
728 |
elseif ($forced_output == HAW_OUTPUT_OWGUI) |
729 |
{ |
730 |
$HTTP_ACCEPT = "text/vnd.wap.wml"; |
731 |
$HTTP_USER_AGENT = "UP/GUI...UP.Link "; |
732 |
} |
733 |
elseif ($forced_output == HAW_OUTPUT_PVX) |
734 |
{ |
735 |
$HTTP_ACCEPT = ""; |
736 |
$HTTP_USER_AGENT = "publicVoiceXML"; // user agent header of PublicVoiceXML browser |
737 |
} |
738 |
} |
739 |
|
740 |
// determine markup language to create |
741 |
|
742 |
if (strstr(strtolower($HTTP_USER_AGENT), "docomo") || |
743 |
strstr(strtolower($HTTP_USER_AGENT), "portalmmm") || |
744 |
strstr(strtolower($HTTP_USER_AGENT), "opera ") || |
745 |
strstr(strtolower($HTTP_USER_AGENT), "reqwirelessweb") || |
746 |
strstr(strtolower($HTTP_ACCEPT), "vnd.wap.xhtml")) |
747 |
{ |
748 |
$this->ml = HAW_HTML; // create HTML (even when device accepts text/vnd.wap.wml too!) |
749 |
} |
750 |
elseif (strstr(strtolower($HTTP_ACCEPT), "text/vnd.wap.wml")) |
751 |
{ |
752 |
$this->ml = HAW_WML; // create WML |
753 |
|
754 |
if (strstr($HTTP_USER_AGENT, "UP/") || |
755 |
strstr($HTTP_USER_AGENT, "UP.B")) |
756 |
$this->upbrowser = true; // UP browser |
757 |
|
758 |
if ((strstr($HTTP_USER_AGENT, "UP/") || |
759 |
strstr($HTTP_USER_AGENT, "UP.B")) && |
760 |
strstr($HTTP_USER_AGENT, "GUI") && |
761 |
strstr($HTTP_USER_AGENT, "UP.Link")) // Non-UP.Link gateways sometimes have problems! |
762 |
$this->owgui_1_3 = true; // device accepts Openwave GUI extensions for WML 1.3 |
763 |
} |
764 |
elseif (strstr(strtolower($HTTP_ACCEPT), "hdml;version=3.")) // HDML 3.0 and 3.1 |
765 |
$this->ml = HAW_HDML; // create HDML |
766 |
elseif (strstr(strtolower($HTTP_ACCEPT), "vxml") || // VoiceXML signalled in accept header |
767 |
strstr(strtolower($HTTP_ACCEPT), "voicexml") || // alternative accept header |
768 |
strstr($HTTP_USER_AGENT, "OpenVXI") || // Speechworks OpenVXI |
769 |
strstr(strtolower($HTTP_USER_AGENT), "publicvoicexml") || // PublicVoiceXML voice browser |
770 |
strstr($HTTP_USER_AGENT, "Tellme")) // Tellme studio voice browser |
771 |
{ |
772 |
$this->ml = HAW_VXML; // create VoiceXML |
773 |
|
774 |
// PublicVoiceXML browser cannot handle <break> elements!!! |
775 |
if (strstr(strtolower($HTTP_USER_AGENT), "publicvoicexml")) |
776 |
{ |
777 |
$this->supportsVXMLBreakTag = false; |
778 |
} |
779 |
} |
780 |
else |
781 |
{ |
782 |
if (strstr($HTTP_USER_AGENT, "Mozilla") || |
783 |
strstr($HTTP_USER_AGENT, "MSIE") || |
784 |
strstr(strtolower($HTTP_USER_AGENT), "lynx") || |
785 |
strstr(strtolower($HTTP_USER_AGENT), "avantgo") || |
786 |
strstr(strtolower($HTTP_USER_AGENT), "pendragonweb") || |
787 |
strstr(strtolower($HTTP_USER_AGENT), "j-")) |
788 |
$this->ml = HAW_HTML; // HTML-based browser |
789 |
else |
790 |
$this->ml = HAW_WML; // try it with WML |
791 |
} |
792 |
|
793 |
$this->number_of_elements = 0; |
794 |
$this->number_of_forms = 0; |
795 |
$this->number_of_linksets = 0; |
796 |
$this->number_of_links = 0; |
797 |
$this->number_of_phones = 0; |
798 |
|
799 |
if (strstr(strtolower($HTTP_ACCEPT), "vnd.wap.xhtml")) |
800 |
{ |
801 |
// XHTML device detected |
802 |
$this->xhtml = true; |
803 |
$this->pureHTML = false; |
804 |
$this->display_banners = false; |
805 |
$this->gif_enabled = true; |
806 |
$this->css_enabled = true; |
807 |
} |
808 |
elseif ( strstr(strtolower($HTTP_USER_AGENT), "avantgo") || |
809 |
strstr(strtolower($HTTP_USER_AGENT), "reqwirelessweb") || |
810 |
strstr(strtolower($HTTP_USER_AGENT), "pendragonweb") || |
811 |
strstr(strtolower($HTTP_USER_AGENT), "palmos") || |
812 |
strstr(strtolower($HTTP_USER_AGENT), "windows ce") || |
813 |
strstr($HTTP_USER_AGENT, "Mozilla/4.7")) |
814 |
{ |
815 |
// PDA browser detected (or poor old Netscape 4.7x which messes with CSS) |
816 |
$this->PDAstyle = true; |
817 |
$this->pureHTML = false; |
818 |
$this->display_banners = false; |
819 |
} |
820 |
elseif (strstr(strtolower($HTTP_USER_AGENT), "docomo") || |
821 |
strstr(strtolower($HTTP_USER_AGENT), "portalmmm")) |
822 |
{ |
823 |
// i-mode browser detected |
824 |
$this->iModestyle = true; |
825 |
$this->pureHTML = false; |
826 |
$this->display_banners = false; |
827 |
} |
828 |
elseif (strstr(strtolower($HTTP_USER_AGENT), "j-")) |
829 |
{ |
830 |
// MML browser detected |
831 |
$this->MMLstyle = true; |
832 |
$this->pureHTML = false; |
833 |
$this->display_banners = false; |
834 |
} |
835 |
elseif (strstr(strtolower($HTTP_USER_AGENT), "lynx")) |
836 |
{ |
837 |
// text browser detected |
838 |
$this->lynx = true; |
839 |
$this->css_enabled = true; // enabled in the meaning of silently discarding it ... |
840 |
$this->pureHTML = true; |
841 |
$this->display_banners = false; |
842 |
} |
843 |
|
844 |
// determine if browser is CSS-enbled |
845 |
if (($this->ml == HAW_HTML) && |
846 |
(strstr($HTTP_USER_AGENT, "MSIE") || |
847 |
strstr($HTTP_USER_AGENT, "Mozilla") || |
848 |
strstr($HTTP_USER_AGENT, "Opera"))) |
849 |
$this->css_enabled = true; |
850 |
|
851 |
// determine if browser is able to display GIF images |
852 |
if (($this->ml == HAW_HTML) || |
853 |
(strstr(strtolower($HTTP_ACCEPT), "image/gif")) || |
854 |
(strstr(strtolower($HTTP_USER_AGENT), "T68"))) |
855 |
$this->gif_enabled = true; // browsers can display GIF |
856 |
|
857 |
// determine how forms are to be transmitted |
858 |
if (strstr(strtolower($HTTP_USER_AGENT), "ericsson")) |
859 |
$this->submitViaLink = true; // with Ericsson WAP devices it's quite difficult to submit WML forms |
860 |
} |
861 |
|
862 |
|
863 |
/** |
864 |
Adds a HAW_text object to HAW_deck. |
865 |
@param text Some HAW_text object. |
866 |
@see HAW_text |
867 |
*/ |
868 |
function add_text($text) |
869 |
{ |
870 |
if (!is_object($text)) |
871 |
die("invalid argument in add_text()"); |
872 |
|
873 |
$this->element[$this->number_of_elements] = $text; |
874 |
|
875 |
$this->number_of_elements++; |
876 |
} |
877 |
|
878 |
|
879 |
/** |
880 |
Adds a HAW_image object to HAW_deck. |
881 |
@param image Some HAW_image object. |
882 |
@see HAW_image |
883 |
*/ |
884 |
function add_image($image) |
885 |
{ |
886 |
if (!is_object($image)) |
887 |
die("invalid argument in add_image()"); |
888 |
|
889 |
$this->element[$this->number_of_elements] = $image; |
890 |
|
891 |
$this->number_of_elements++; |
892 |
} |
893 |
|
894 |
|
895 |
/** |
896 |
Adds a HAW_table object to HAW_deck. |
897 |
@param table Some HAW_table object. |
898 |
@see HAW_table |
899 |
*/ |
900 |
function add_table($table) |
901 |
{ |
902 |
if (!is_object($table)) |
903 |
die("invalid argument in add_table()"); |
904 |
|
905 |
$this->element[$this->number_of_elements] = $table; |
906 |
|
907 |
$this->number_of_elements++; |
908 |
} |
909 |
|
910 |
|
911 |
/** |
912 |
Adds a HAW_form object to HAW_deck. |
913 |
@param form Some HAW_form object. |
914 |
@see HAW_form |
915 |
*/ |
916 |
function add_form($form) |
917 |
{ |
918 |
if (!is_object($form)) |
919 |
die("invalid argument in add_form()"); |
920 |
|
921 |
if ($this->number_of_forms > 0) |
922 |
die("only one form per deck allowed!"); |
923 |
|
924 |
$this->element[$this->number_of_elements] = $form; |
925 |
|
926 |
$this->number_of_elements++; |
927 |
$this->number_of_forms++; |
928 |
} |
929 |
|
930 |
|
931 |
/** |
932 |
Adds a HAW_link object to HAW_deck. |
933 |
@param link Some HAW_link object. |
934 |
@see HAW_link |
935 |
*/ |
936 |
function add_link($link) |
937 |
{ |
938 |
if (!is_object($link)) |
939 |
die("invalid argument in add_link()"); |
940 |
|
941 |
$this->element[$this->number_of_elements] = $link; |
942 |
|
943 |
$this->number_of_elements++; |
944 |
$this->number_of_links++; |
945 |
} |
946 |
|
947 |
|
948 |
/** |
949 |
Adds a HAW_phone object to HAW_deck. |
950 |
@param phone Some HAW_phone object. |
951 |
@see HAW_phone |
952 |
*/ |
953 |
function add_phone($phone) |
954 |
{ |
955 |
if (!is_object($phone)) |
956 |
die("invalid argument in add_phone()"); |
957 |
|
958 |
$this->element[$this->number_of_elements] = $phone; |
959 |
|
960 |
$this->number_of_elements++; |
961 |
$this->number_of_phones++; |
962 |
} |
963 |
|
964 |
|
965 |
/** |
966 |
Adds a HAW_linkset object to HAW_deck. |
967 |
@param linkset Some HAW_linkset object. |
968 |
@see HAW_linkset |
969 |
*/ |
970 |
function add_linkset($linkset) |
971 |
{ |
972 |
if (!is_object($linkset)) |
973 |
die("invalid argument in add_linkset()"); |
974 |
|
975 |
if ($this->number_of_linksets > 0) |
976 |
die("only one linkset per deck allowed!"); |
977 |
|
978 |
$this->element[$this->number_of_elements] = $linkset; |
979 |
|
980 |
$this->number_of_elements++; |
981 |
$this->number_of_linksets++; |
982 |
} |
983 |
|
984 |
|
985 |
/* |
986 |
Adds a HAW_raw object to HAW_deck. (undocumented feature - for test only!) |
987 |
@param raw Some HAW_raw object. |
988 |
@see HAW_raw |
989 |
*/ |
990 |
function add_raw($raw) |
991 |
{ |
992 |
if (!is_object($raw)) |
993 |
die("invalid argument in add_raw()"); |
994 |
|
995 |
$this->element[$this->number_of_elements] = $raw; |
996 |
|
997 |
$this->number_of_elements++; |
998 |
} |
999 |
|
1000 |
|
1001 |
/* |
1002 |
Adds some user-defined HAWHAW object to HAW_deck (undocumented feature)<br> |
1003 |
For skilled HAWHAW programmers only! |
1004 |
@param udef Some user-defined object. |
1005 |
*/ |
1006 |
function add_userdefined($udef) |
1007 |
{ |
1008 |
/* A user-defined HAWHAW class definition MUST look like this: |
1009 |
|
1010 |
class HAW_foo // some class name of your choice |
1011 |
{ |
1012 |
var $bar; // some class variable declarations of your choice |
1013 |
|
1014 |
function HAW_foo(...) |
1015 |
{ |
1016 |
// some constructor code of your choice |
1017 |
} |
1018 |
|
1019 |
function HAW_boobaz(...) |
1020 |
{ |
1021 |
// as many user-defined functions as needed |
1022 |
} |
1023 |
|
1024 |
// this member function is called by HAWHAW and MUST NOT be changed! |
1025 |
function get_elementtype() |
1026 |
{ |
1027 |
return HAW_USERDEFINED; |
1028 |
} |
1029 |
|
1030 |
function create($deck) |
1031 |
{ |
1032 |
// this member function is called by HAWHAW and MUST be present! |
1033 |
// it is in the programmers responsibility what kind of markup is created here! |
1034 |
// you have access to all HAW_deck properties by evaluating $deck |
1035 |
} |
1036 |
} ; |
1037 |
|
1038 |
You have to define this class somewhere after your require("hawhaw.inc") statement |
1039 |
|
1040 |
Usage: ... |
1041 |
$myText = new HAW_text("Classic text"); |
1042 |
$myDeck->add_text($myText); |
1043 |
$myClass = new HAW_foo("Cool output"); |
1044 |
$myClass->boobaz($ringtone, $sms, $userposition); |
1045 |
$myDeck->add_userdefined($myClass); |
1046 |
... |
1047 |
*/ |
1048 |
|
1049 |
if (!is_object($udef)) |
1050 |
die("invalid argument in add_userdefined()"); |
1051 |
|
1052 |
$this->element[$this->number_of_elements] = $udef; |
1053 |
|
1054 |
$this->number_of_elements++; |
1055 |
} |
1056 |
|
1057 |
|
1058 |
/** |
1059 |
Adds a HAW_banner object to HAW_deck. <br> |
1060 |
Note: Has no effect on WML/handheld pages. |
1061 |
@param banner Some HAW_banner object. |
1062 |
@param position (optional)<br> |
1063 |
HAW_TOP: above HAW_deck<br> |
1064 |
HAW_BOTTOM: beneath HAW_deck (default) |
1065 |
@see HAW_banner |
1066 |
*/ |
1067 |
function add_banner($banner, $position=HAW_BOTTOM) |
1068 |
{ |
1069 |
if (!is_object($banner)) |
1070 |
die("invalid argument in add_banner()"); |
1071 |
|
1072 |
if ($position == HAW_TOP) |
1073 |
{ |
1074 |
$this->top_banners[$this->number_of_top_banners] = $banner; |
1075 |
$this->number_of_top_banners++; |
1076 |
} |
1077 |
else |
1078 |
{ |
1079 |
$this->bottom_banners[$this->number_of_bottom_banners] = $banner; |
1080 |
$this->number_of_bottom_banners++; |
1081 |
} |
1082 |
} |
1083 |
|
1084 |
|
1085 |
/** |
1086 |
Adds a HAW_rule object to HAW_deck. |
1087 |
@param rule Some HAW_rule object. |
1088 |
@see HAW_rule |
1089 |
*/ |
1090 |
function add_rule($rule) |
1091 |
{ |
1092 |
if (!is_object($rule)) |
1093 |
die("invalid argument in add_rule()"); |
1094 |
|
1095 |
$this->element[$this->number_of_elements] = $rule; |
1096 |
|
1097 |
$this->number_of_elements++; |
1098 |
} |
1099 |
|
1100 |
|
1101 |
/** |
1102 |
Adds a HAW_voicerecorder object to HAW_deck. |
1103 |
@param voicerecorder Some HAW_voicerecorder object. |
1104 |
@see HAW_voicerecorder |
1105 |
*/ |
1106 |
function add_voicerecorder($voicerecorder) |
1107 |
{ |
1108 |
if (!is_object($voicerecorder)) |
1109 |
die("invalid argument in add_voicerecorder()"); |
1110 |
|
1111 |
$this->element[$this->number_of_elements] = $voicerecorder; |
1112 |
|
1113 |
$this->number_of_elements++; |
1114 |
} |
1115 |
|
1116 |
|
1117 |
/** |
1118 |
Redirects automatically after timeout to another URL. <br> |
1119 |
Note: This feature can not be supported for HDML browsers, due to HDML's missing |
1120 |
timer functionality. If you intend to serve HDML users, you should consider this |
1121 |
by creating an additional link to <i>red_url</i>. |
1122 |
@param timeout Some timeout value in seconds. |
1123 |
@param red_url Some URL string. |
1124 |
*/ |
1125 |
function set_redirection($timeout, $red_url) |
1126 |
{ |
1127 |
$this->timeout = $timeout; |
1128 |
$this->red_url = $red_url; |
1129 |
} |
1130 |
|
1131 |
|
1132 |
/** |
1133 |
Disables deck caching in the users client. <br> |
1134 |
Note: Use this object function, if you intend to provide changing content under |
1135 |
the same URL. |
1136 |
*/ |
1137 |
function disable_cache() |
1138 |
{ |
1139 |
$this->disable_cache = true; |
1140 |
} |
1141 |
|
1142 |
|
1143 |
/** |
1144 |
Enables mobile specific session support. <br> |
1145 |
Note: Applications for mobile devices require special session handling: As cookies |
1146 |
are often not supported, URL rewriting has to be done. As XML does not allow unescaped |
1147 |
'&' characters, the arg-separator has to be modified. And as WML/VoiceXML defines tags |
1148 |
which are not defined in HTML, the PHP predefined url_rewriter tags have to be adapted.<br> |
1149 |
Important: This function has be called before any session handling is done! Due to some |
1150 |
bugs in previous PHP versions, it is highly recommended to use PHP version 4.1.1 or |
1151 |
higher. |
1152 |
*/ |
1153 |
function enable_session() |
1154 |
{ |
1155 |
// set session server options |
1156 |
ini_set('session.use_cookies', 0); // do not use cookies |
1157 |
ini_set('session.use_trans_sid', 1); // use transient sid support |
1158 |
ini_set('arg_separator.output', '&'); // '&' is not allowed in WML (XML) |
1159 |
|
1160 |
// url rewriter tags are dependent from markup language |
1161 |
|
1162 |
switch ($this->ml) |
1163 |
{ |
1164 |
case HAW_HTML: |
1165 |
{ |
1166 |
ini_set('url_rewriter.tags', 'a=href,form=option'); |
1167 |
break; |
1168 |
} |
1169 |
|
1170 |
case HAW_WML: |
1171 |
{ |
1172 |
ini_set('url_rewriter.tags', 'a=href,go=href,option=onpick'); |
1173 |
break; |
1174 |
} |
1175 |
|
1176 |
case HAW_HDML: |
1177 |
{ |
1178 |
ini_set('url_rewriter.tags', 'a=href'); |
1179 |
break; |
1180 |
} |
1181 |
|
1182 |
case HAW_VXML: |
1183 |
{ |
1184 |
ini_set('url_rewriter.tags', 'submit=next,link=next,goto=next'); |
1185 |
break; |
1186 |
} |
1187 |
} |
1188 |
} |
1189 |
|
1190 |
|
1191 |
/** |
1192 |
Sets a given character set. <br> |
1193 |
Note: For the iso-8859-1 character set all characters with value greater |
1194 |
127 are automatically transformed into a "&#dec;" sequence (unicode). |
1195 |
For all other character sets a specific cross mapping table is |
1196 |
required for the conversion into unicode. Usage of unicode cross |
1197 |
mapping tables is optional for non-iso-8859-1 character sets. |
1198 |
Mapping tables are available at: |
1199 |
<a href="http://www.unicode.org/Public/MAPPINGS/" target="_blank"> |
1200 |
http://www.unicode.org/Public/MAPPINGS/</a> |
1201 |
@param charset Character set that is used in your country.<br>Default: iso-8859-1 |
1202 |
@param unicodemaptab (optional)<br> |
1203 |
Cross mapping table from country specific character coding to |
1204 |
unicode (default: no mapping to unicode activated).<br> |
1205 |
With this parameter you specify where HAWHAW will find the conversion table |
1206 |
with the mapping rules. It is recommended to store the cross mapping table |
1207 |
in the same directory where hawhaw.inc is located.<br> |
1208 |
format: [PATH][Filename].[EXT] e.g. "../GB2312.TXT" |
1209 |
*/ |
1210 |
function set_charset($charset, $unicodemaptab="") |
1211 |
{ |
1212 |
$this->charset = $charset; |
1213 |
$this->unicodemaptab = $unicodemaptab; |
1214 |
|
1215 |
if ($unicodemaptab) |
1216 |
{ |
1217 |
// cross mapping table is to be used |
1218 |
|
1219 |
if(!file_exists($unicodemaptab)) |
1220 |
{ |
1221 |
$errormsg = "HAWHAW!<br>Cross mapping table \"$unicodemaptab\" not found!<br>"; |
1222 |
$errormsg .= "Please download your country-specific unicode cross mapping table from:<br>"; |
1223 |
$errormsg .= "<a href=http://www.unicode.org/Public/MAPPINGS/>http://www.unicode.org/Public/MAPPINGS/</a>"; |
1224 |
die("$errormsg"); |
1225 |
} |
1226 |
|
1227 |
// open cross mapping table file and create array with mapping info |
1228 |
|
1229 |
$filename = $unicodemaptab; |
1230 |
$line=file($filename); |
1231 |
|
1232 |
while(list($key,$value)=each($line)) |
1233 |
{ |
1234 |
if (substr($value, 0, 2) == "0x") // skip comment lines |
1235 |
{ |
1236 |
$pair = explode(" ", $value); // tab separates code and unicode |
1237 |
|
1238 |
if ((strlen($pair[0]) == 6) && ($pair[0] < 0x8080)) |
1239 |
$this->unicodearray[hexdec($pair[0]) + 0x8080] = hexdec($pair[1]); // offset EUC |
1240 |
else |
1241 |
$this->unicodearray[hexdec($pair[0])] = hexdec($pair[1]); |
1242 |
} |
1243 |
} |
1244 |
} |
1245 |
} |
1246 |
|
1247 |
|
1248 |
/** |
1249 |
Sets a given language. <br> |
1250 |
Note: Specifies the main language of the deck, as e.g. english, german, |
1251 |
japanese or whatever. Language declaration is highly recommended in order |
1252 |
to provide barrierfree content and as is required to validate a deck as |
1253 |
Bobby AAA approved! |
1254 |
@param language Language code according ISO 639, e.g. "en", "de", etc. |
1255 |
*/ |
1256 |
function set_language($language) |
1257 |
{ |
1258 |
$this->language = $language; |
1259 |
} |
1260 |
|
1261 |
|
1262 |
/** |
1263 |
Sets the window background color for a HTML (big-screen browser) page. |
1264 |
Has no effect on WML/handheld pages. |
1265 |
@param bgcolor See HTML specification for possible values (e.g. "#CCFFFF", |
1266 |
"red", ...). |
1267 |
*/ |
1268 |
function set_bgcolor($bgcolor) |
1269 |
{ |
1270 |
$this->bgcolor = $bgcolor; |
1271 |
} |
1272 |
|
1273 |
|
1274 |
/** |
1275 |
Sets a window wallpaper for a HTML (big-screen browser) page. |
1276 |
Has no effect on WML/handheld pages. |
1277 |
@param background e.g. "backgrnd.gif" |
1278 |
*/ |
1279 |
function set_background($background) |
1280 |
{ |
1281 |
$this->background = $background; |
1282 |
} |
1283 |
|
1284 |
|
1285 |
/** |
1286 |
Sets the thickness of the HTML display frame. Has no effect on WML/handheld pages. |
1287 |
@param border Thickness is pixels (default: 8) |
1288 |
*/ |
1289 |
function set_border($border) |
1290 |
{ |
1291 |
$this->border = $border; |
1292 |
} |
1293 |
|
1294 |
|
1295 |
/** |
1296 |
Sets the display background color for a (X)HTML page. Has no effect on |
1297 |
WML pages. |
1298 |
@param disp_bgcolor See HTML specification for possible values (e.g. "#CCFFFF", |
1299 |
"red", ...). |
1300 |
*/ |
1301 |
function set_disp_bgcolor($disp_bgcolor) |
1302 |
{ |
1303 |
$this->disp_bgcolor = $disp_bgcolor; |
1304 |
} |
1305 |
|
1306 |
|
1307 |
/** |
1308 |
Sets a display wallpaper for a (X)HTML page. Has no effect on WML |
1309 |
pages. |
1310 |
@param background e.g. "backgrnd.gif" |
1311 |
*/ |
1312 |
function set_disp_background($background) |
1313 |
{ |
1314 |
$this->disp_background = $background; |
1315 |
} |
1316 |
|
1317 |
|
1318 |
/** |
1319 |
Sets the display width for a HTML page. Has no effect on WML/handheld |
1320 |
pages. |
1321 |
@param width See HTML specification for possible values (e.g. "200", "50%", ...). |
1322 |
*/ |
1323 |
function set_width($width) |
1324 |
{ |
1325 |
$this->width = $width; |
1326 |
} |
1327 |
|
1328 |
|
1329 |
/** |
1330 |
Sets the display height for a HTML page. Has no effect on WML/handheld |
1331 |
pages. |
1332 |
@param height See HTML specification for possible values (e.g. "200", "50%", ...). |
1333 |
*/ |
1334 |
function set_height($height) |
1335 |
{ |
1336 |
$this->height = $height; |
1337 |
} |
1338 |
|
1339 |
|
1340 |
/** |
1341 |
Sets the font size for all characters in a (X)HTML page. Has no effect on |
1342 |
WML pages. |
1343 |
@param size See HTML specification for possible values (e.g. "12pt", ...). |
1344 |
*/ |
1345 |
function set_size($size) |
1346 |
{ |
1347 |
$this->size = $size; |
1348 |
} |
1349 |
|
1350 |
|
1351 |
/** |
1352 |
Sets the color for all characters in a (X)HTML page. Has no effect on WML pages. |
1353 |
Nevertheless, HAW_text objects can overwrite this value by defining their own color |
1354 |
attributes. |
1355 |
@param color See HTML specification for possible values (e.g. "#CCFFFF", "red", |
1356 |
...). |
1357 |
@see HAW_text |
1358 |
*/ |
1359 |
function set_color($color) |
1360 |
{ |
1361 |
$this->color = $color; |
1362 |
} |
1363 |
|
1364 |
|
1365 |
/** |
1366 |
Sets the color of links in a (X)HTML page. Has no effect on |
1367 |
WML pages. |
1368 |
@param link_color See HTML specification for possible values (e.g. "#CCFFFF", "red", |
1369 |
...). |
1370 |
*/ |
1371 |
function set_link_color($link_color) |
1372 |
{ |
1373 |
$this->link_color = $link_color; |
1374 |
} |
1375 |
|
1376 |
|
1377 |
/** |
1378 |
Sets the color of visited links in a (X)HTML page. Has no effect on |
1379 |
WML pages. |
1380 |
@param vlink_color See HTML specification for possible values (e.g. "#CCFFFF", "red", |
1381 |
...). |
1382 |
*/ |
1383 |
function set_vlink_color($vlink_color) |
1384 |
{ |
1385 |
$this->vlink_color = $vlink_color; |
1386 |
} |
1387 |
|
1388 |
|
1389 |
/** |
1390 |
Sets the font for all characters in a (X)HTML page. Has no effect on |
1391 |
WML pages. |
1392 |
@param face See HTML specification for possible values (e.g. "Avalon", |
1393 |
"Wide Latin"). |
1394 |
*/ |
1395 |
function set_face($face) |
1396 |
{ |
1397 |
$this->face = $face; |
1398 |
} |
1399 |
|
1400 |
|
1401 |
/** |
1402 |
Sets the URL of a website, a bigscreen-browsing user is invited to visit via WAP. <br> |
1403 |
Note: On bigscreen browsers a small copyright link to the |
1404 |
HAWHAW information page will be created automatically by HAWHAW. The information |
1405 |
page invites the user to visit your site with a WAP phone. |
1406 |
Therefore by default your hostname and your refering script will be part of this |
1407 |
copyright link. You can modify this value, e.g. if your application leads the |
1408 |
user across different pages, but you want to make visible the entry page only. |
1409 |
@param waphome Some URL string. |
1410 |
*/ |
1411 |
function set_waphome($waphome) |
1412 |
{ |
1413 |
$this->waphome = $waphome; |
1414 |
} |
1415 |
|
1416 |
|
1417 |
/** |
1418 |
Activates the device simulator on bigscreen browsers. <br> |
1419 |
Note: If no skin is specified, the HAWHAW default skin is used. |
1420 |
HAWHAW output can be displayed in any kind of user-defined skin. |
1421 |
See <a href="http://skin.hawhaw.de/skin.css" target="_blank"> |
1422 |
CSS file</a> of the HAWHAW default skin for more info. |
1423 |
@param skin URL of CSS file, where skin is defined (optional) |
1424 |
*/ |
1425 |
function use_simulator($skin="http://skin.hawhaw.de/skin.css") |
1426 |
{ |
1427 |
$this->use_simulator = true; |
1428 |
$this->skin = $skin; |
1429 |
} |
1430 |
|
1431 |
|
1432 |
/** |
1433 |
Sets deck-related text to be spoken by voice browsers. <br> |
1434 |
@param text Some introducing text that will be spoken before any other dialog or |
1435 |
text output is started. |
1436 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
1437 |
*/ |
1438 |
function set_voice_text($text, $audio_src="") |
1439 |
{ |
1440 |
if (!is_string($text)) |
1441 |
die("invalid argument in set_voice_text()"); |
1442 |
|
1443 |
$this->voice_text = $text; |
1444 |
$this->voice_audio_src = $audio_src; |
1445 |
} |
1446 |
|
1447 |
|
1448 |
/** |
1449 |
Play jingle before link <label>s are spoken. <br> |
1450 |
Note: Voice users can not distinguish between plain text and link text. Playing |
1451 |
a short jingle before each link will make voice navigation easier. |
1452 |
@param url Some wav-file. |
1453 |
*/ |
1454 |
function set_voice_jingle($url) |
1455 |
{ |
1456 |
if (!is_string($url)) |
1457 |
die("invalid argument in set_voice_jingle()"); |
1458 |
|
1459 |
$this->voice_jingle = $url; |
1460 |
} |
1461 |
|
1462 |
|
1463 |
/** |
1464 |
Sets help text for voice browsers. <br> |
1465 |
@param text Some helpful information concerning this deck. |
1466 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
1467 |
@param url Some other voice deck to go to (optional). |
1468 |
*/ |
1469 |
function set_voice_help($text, $audio_src="", $url="") |
1470 |
{ |
1471 |
if (!is_string($text)) |
1472 |
die("invalid argument in set_voice_help()"); |
1473 |
|
1474 |
$arr["text"] = $text; |
1475 |
$arr["src"] = $audio_src; |
1476 |
$arr["url"] = $url; |
1477 |
|
1478 |
$this->voice_help[] = $arr; |
1479 |
} |
1480 |
|
1481 |
|
1482 |
/** |
1483 |
Sets noinput text for voice browsers. <br> |
1484 |
@param text Some text to inform the user that no input has been received. |
1485 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
1486 |
@param url Some other voice deck to go to (optional). |
1487 |
*/ |
1488 |
function set_voice_noinput($text, $audio_src="", $url="") |
1489 |
{ |
1490 |
if (!is_string($text)) |
1491 |
die("invalid argument in set_voice_noinput()"); |
1492 |
|
1493 |
$arr["text"] = $text; |
1494 |
$arr["src"] = $audio_src; |
1495 |
$arr["url"] = $url; |
1496 |
|
1497 |
$this->voice_noinput[] = $arr; |
1498 |
} |
1499 |
|
1500 |
|
1501 |
/** |
1502 |
Sets nomatch text for voice browsers. <br> |
1503 |
@param text Some text to complain that user input was not recognized. |
1504 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
1505 |
@param url Some other voice deck to go to (optional). |
1506 |
*/ |
1507 |
function set_voice_nomatch($text, $audio_src="", $url="") |
1508 |
{ |
1509 |
if (!is_string($text)) |
1510 |
die("invalid argument in set_voice_nomatch()"); |
1511 |
|
1512 |
$arr["text"] = $text; |
1513 |
$arr["src"] = $audio_src; |
1514 |
$arr["url"] = $url; |
1515 |
|
1516 |
$this->voice_nomatch[] = $arr; |
1517 |
} |
1518 |
|
1519 |
|
1520 |
/** |
1521 |
Sets a name/value property pair for VoiceXML decks. <br> |
1522 |
Attention: This function should be used by experienced VoiceXML developers |
1523 |
only! name/value combinations which are not compliant to the VoiceXML |
1524 |
standard or are not supported by the voice platform, will throw an |
1525 |
semantic error and terminate voice output. Please refer to the |
1526 |
<a href="http://www.w3.org/TR/voicexml20/#dml6.3" target="_blank"> |
1527 |
W3C VoiceXML Recommendation (chapter 6.3)</a> |
1528 |
for detailled info about valid name/value combinations. |
1529 |
@param name Name of property (e.g. "bargein", "timeout", etc.) |
1530 |
@param value Value of property (e.g. "false", "10s", etc.) |
1531 |
*/ |
1532 |
function set_voice_property($name, $value) |
1533 |
{ |
1534 |
$arr["name"] = $name; |
1535 |
$arr["value"] = $value; |
1536 |
|
1537 |
$this->voice_property[] = $arr; |
1538 |
} |
1539 |
|
1540 |
|
1541 |
/** |
1542 |
Defines a DTMF/voice grammar to repeat or skip voice output. <br> |
1543 |
This function enables voice users to repeat or skip voice output which |
1544 |
has been created by means of HAW_text objects. |
1545 |
For both <i>repeat</i> and <i>forward</i> at least one trigger criteria (DTMF or voice) |
1546 |
has to be defined. |
1547 |
HAW_text objects where user navigation should apply have to call <i>set_voice_navigation()</i>. |
1548 |
@param repeat_dtmf DTMF key that triggers the repetition of the current output (e.g. "1", "2", "", etc.) |
1549 |
@param repeat_voice What the user has to say to repeat the current output (e.g. "repeat", "") |
1550 |
@param forward_dtmf DTMF key that terminates the current output (e.g. "0", "*", "", etc.) |
1551 |
@param forward_voice What the user has to say to continue with the next output (e.g. "forward", "") |
1552 |
@see HAW_text |
1553 |
*/ |
1554 |
function set_voice_navigator($repeat_dtmf, $repeat_voice, $forward_dtmf, $forward_voice) |
1555 |
{ |
1556 |
$repeat_dtmf = (string) $repeat_dtmf; |
1557 |
$forward_dtmf = (string) $forward_dtmf; |
1558 |
|
1559 |
if (!ereg("^[0-9#\*]$", $repeat_dtmf) && !$repeat_voice) |
1560 |
die("at least one repeat indication required in set_voice_navigator()"); |
1561 |
|
1562 |
if (!ereg("^[0-9#\*]$", $forward_dtmf) && !$forward_voice) |
1563 |
die("at least one forward indication required in set_voice_navigator()"); |
1564 |
|
1565 |
$this->voice_navigator["repeat_dtmf"] = $repeat_dtmf; |
1566 |
$this->voice_navigator["repeat_voice"] = $repeat_voice; |
1567 |
$this->voice_navigator["forward_dtmf"] = $forward_dtmf; |
1568 |
$this->voice_navigator["forward_voice"] = $forward_voice; |
1569 |
} |
1570 |
|
1571 |
|
1572 |
/** |
1573 |
Smooth contiguous text sections. <br> |
1574 |
Note: This function affects VoiceXML output only.<br> |
1575 |
Voice decks often are assembled by some HAW_text objects. Each HAW_text |
1576 |
object creates a VoiceXML <block> element. On some voice browsers this |
1577 |
results in an interruptive speech synthesis. This function coalesces directly |
1578 |
neighbored HAW_text objects to one single HAW_text object and thus results in |
1579 |
a smoothed voice perception. |
1580 |
*/ |
1581 |
function smooth_voice() |
1582 |
{ |
1583 |
if ($this->ml == HAW_VXML) |
1584 |
{ |
1585 |
// this function make sense for VoiceXML output only |
1586 |
|
1587 |
$i = 0; |
1588 |
|
1589 |
while (isset($this->element[$i])) |
1590 |
{ |
1591 |
$current_element = $this->element[$i]; |
1592 |
|
1593 |
if (isset($this->element[$i+1])) |
1594 |
{ |
1595 |
$next_element = $this->element[$i+1]; |
1596 |
|
1597 |
if (($current_element->get_elementtype() == HAW_PLAINTEXT) && |
1598 |
($current_element->get_br() == 0) && |
1599 |
($next_element->get_elementtype() == HAW_PLAINTEXT) && |
1600 |
($next_element->get_br() == 0) && |
1601 |
($current_element->get_attrib() == $next_element->get_attrib())) |
1602 |
{ |
1603 |
// create single HAW_text object containing both text sections |
1604 |
$merged_text = new HAW_text($current_element->get_text() . " " . $next_element->get_text(), |
1605 |
$current_element->get_attrib()); |
1606 |
|
1607 |
// adopt line breaks from next element |
1608 |
$merged_text->set_br($next_element->get_br()); |
1609 |
|
1610 |
// replace old two objects with new object |
1611 |
array_splice($this->element, $i, 2, array($merged_text)); |
1612 |
$this->number_of_elements--; |
1613 |
|
1614 |
$i--; // continue with merged element |
1615 |
} |
1616 |
} |
1617 |
|
1618 |
$i++; |
1619 |
} |
1620 |
} |
1621 |
} |
1622 |
|
1623 |
|
1624 |
/** |
1625 |
Creates the page in the according markup language. Depending on the clients |
1626 |
browser type, HTML (pure HTML, handheldfriendly HTML, XHTML, i-mode cHTML, MML), |
1627 |
WML, HDML or VoiceXML is thrown out. |
1628 |
*/ |
1629 |
function create_page() |
1630 |
{ |
1631 |
global $haw_license_holder; |
1632 |
global $haw_license_domain; |
1633 |
global $haw_signature; |
1634 |
global $haw_sig_text; |
1635 |
global $haw_sig_link; |
1636 |
|
1637 |
// add hawoutput query parameter to redirection url, if required |
1638 |
HAW_handle_forced_output($this->red_url, $this->hawoutput); |
1639 |
|
1640 |
if ($this->debug) |
1641 |
header("content-type: text/plain"); |
1642 |
|
1643 |
if ($this->disable_cache) |
1644 |
header("cache-control: no-cache"); |
1645 |
|
1646 |
if ($this->ml == HAW_HTML) |
1647 |
{ |
1648 |
// create HTML page header |
1649 |
|
1650 |
if (!$this->debug) |
1651 |
{ |
1652 |
if ($this->xhtml) |
1653 |
{ |
1654 |
if ($this->lynx) |
1655 |
$ct = "content-type: text/html"; |
1656 |
else |
1657 |
$ct = "content-type: application/vnd.wap.xhtml+xml"; |
1658 |
} |
1659 |
else |
1660 |
$ct = sprintf("content-type: text/html;charset=%s", $this->charset); |
1661 |
|
1662 |
header($ct); |
1663 |
} |
1664 |
|
1665 |
if ($this->xhtml) |
1666 |
{ |
1667 |
printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", $this->charset); |
1668 |
|
1669 |
if ($this->lynx) |
1670 |
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\" >\n"; |
1671 |
else |
1672 |
echo "<!DOCTYPE html PUBLIC \"-//WAPFORUM//DTD XHTML Mobile 1.0//EN\" \"http://www.wapforum.org/DTD/xhtml-mobile10.dtd\" >\n"; |
1673 |
} |
1674 |
elseif ($this->css_enabled) |
1675 |
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n"; |
1676 |
|
1677 |
if ($this->language) |
1678 |
{ |
1679 |
if ($this->xhtml) |
1680 |
$language = sprintf(" xml:lang=\"%s\"", $this->language); |
1681 |
else |
1682 |
$language = sprintf(" lang=\"%s\"", $this->language); |
1683 |
} |
1684 |
else |
1685 |
$language = ""; |
1686 |
|
1687 |
printf("<html%s>\n", $language); |
1688 |
echo "<head>\n"; |
1689 |
|
1690 |
// validation issue: HTML does not allow XHTML-stylish "/>" within <head> part |
1691 |
// HTML has set option SHORTTAG=YES in SGML declaration |
1692 |
// ==> "/" closes the tag and ">" will be treated as text |
1693 |
// <body> allows text, but <head> does not! |
1694 |
if ($this->xhtml) |
1695 |
$endtag = "/>"; |
1696 |
else |
1697 |
$endtag = ">"; |
1698 |
|
1699 |
if (!$this->iModestyle && !$this->MMLstyle) |
1700 |
{ |
1701 |
// cHTML and MML don't support meta tags |
1702 |
|
1703 |
if ($haw_license_domain) |
1704 |
$license = " - registered for $haw_license_domain"; |
1705 |
else |
1706 |
$license = ""; |
1707 |
|
1708 |
printf("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\" %s\n", |
1709 |
$this->charset, $endtag); |
1710 |
printf("<meta name=\"GENERATOR\" content=\"%s (PHP) %s%s\" %s\n", |
1711 |
HAW_VERSION, HAW_COPYRIGHT, $license, $endtag); |
1712 |
|
1713 |
if ($this->timeout > 0) |
1714 |
{ |
1715 |
printf("<meta http-equiv=\"refresh\" content=\"%d; URL=%s\" %s\n", |
1716 |
$this->timeout, HAW_specchar($this->red_url, $this), $endtag); |
1717 |
} |
1718 |
|
1719 |
if ($this->disable_cache) |
1720 |
{ |
1721 |
echo "<meta http-equiv=\"Cache-Control\" content=\"must-revalidate\" $endtag\n"; |
1722 |
echo "<meta http-equiv=\"Cache-Control\" content=\"no-cache\" $endtag\n"; |
1723 |
echo "<meta http-equiv=\"Cache-Control\" content=\"max-age=0\" $endtag\n"; |
1724 |
echo "<meta http-equiv=\"Expires\" content=\"0\" $endtag\n"; |
1725 |
} |
1726 |
} |
1727 |
|
1728 |
if ($this->PDAstyle) |
1729 |
{ |
1730 |
echo "<meta name=\"HandheldFriendly\" content=\"True\" $endtag\n"; |
1731 |
} |
1732 |
|
1733 |
// init style properties |
1734 |
$bgcolor = ""; |
1735 |
$background = ""; |
1736 |
$disp_background = ""; |
1737 |
$size = ""; |
1738 |
$color = ""; |
1739 |
$link_color = ""; |
1740 |
$vlink_color = ""; |
1741 |
$face = ""; |
1742 |
$bodystyle = "text-align: center; "; |
1743 |
$css_style = ""; |
1744 |
|
1745 |
if ($this->pureHTML || $this->PDAstyle || $this->xhtml) |
1746 |
{ |
1747 |
if ($this->pureHTML) |
1748 |
{ |
1749 |
// big-screen browser |
1750 |
|
1751 |
if ($this->bgcolor) |
1752 |
{ |
1753 |
// set background color (=window background color) |
1754 |
$bgcolor = " bgcolor=\"" . $this->bgcolor . "\""; |
1755 |
$bodystyle .= sprintf("background-color:%s; ", $this->bgcolor); |
1756 |
} |
1757 |
|
1758 |
if ($this->background) |
1759 |
{ |
1760 |
// set wallpaper (=window wallpaper) |
1761 |
$background = " background=\"" . $this->background . "\""; |
1762 |
$bodystyle .= sprintf("background-image:url(%s); ", $this->background); |
1763 |
} |
1764 |
|
1765 |
// set display defaults, if not assigned by yet |
1766 |
if (!$this->disp_bgcolor) |
1767 |
$this->disp_bgcolor = HAW_DISP_BGCOLOR; |
1768 |
if (!$this->link_color) |
1769 |
$this->link_color = HAW_DISP_LINKCOLOR; |
1770 |
if (!$this->vlink_color) |
1771 |
$this->vlink_color = HAW_DISP_VLINKCOLOR; |
1772 |
if (!$this->face) |
1773 |
$this->face = HAW_DISP_FACE; |
1774 |
} |
1775 |
else |
1776 |
{ |
1777 |
// XHTML or PDA |
1778 |
|
1779 |
if ($this->disp_bgcolor) |
1780 |
{ |
1781 |
// set background color of mobile device |
1782 |
$bgcolor = " bgcolor=\"" . $this->disp_bgcolor . "\""; |
1783 |
$bodystyle .= sprintf("background-color:%s; ", $this->disp_bgcolor); |
1784 |
} |
1785 |
|
1786 |
if ($this->disp_background) |
1787 |
{ |
1788 |
// set wallpaper of mobile device |
1789 |
$background = " background=\"" . $this->disp_background . "\""; |
1790 |
$bodystyle .= sprintf("background-image:url(%s); ", $this->disp_background); |
1791 |
} |
1792 |
} |
1793 |
|
1794 |
if ($this->size) |
1795 |
{ |
1796 |
// set the font size for all characters in a HTML created page |
1797 |
$size = " size=\"" . $this->size . "\""; |
1798 |
$bodystyle .= sprintf("font-size:%s; ", $this->size); |
1799 |
} |
1800 |
|
1801 |
if ($this->color) |
1802 |
{ |
1803 |
// set the color for all characters in a HTML created page |
1804 |
$color = " color=\"" . $this->color . "\""; |
1805 |
$bodystyle .= sprintf("color:%s; ", $this->color); |
1806 |
} |
1807 |
|
1808 |
if ($this->link_color) |
1809 |
{ |
1810 |
// set the color of links in a HTML created page |
1811 |
$link_color = " link=\"" . $this->link_color . "\""; |
1812 |
$css_style .= sprintf("a:link { color:%s; }\n", $this->link_color); |
1813 |
} |
1814 |
|
1815 |
if ($this->vlink_color) |
1816 |
{ |
1817 |
// set the color of visited links in a HTML created page |
1818 |
$vlink_color = " vlink=\"" . $this->vlink_color . "\""; |
1819 |
$css_style .= sprintf("a:visited { color:%s; }\n", $this->vlink_color); |
1820 |
} |
1821 |
|
1822 |
if ($this->face) |
1823 |
{ |
1824 |
// set the font for all characters in a HTML created page |
1825 |
$face = " face=\"" . $this->face . "\""; |
1826 |
$bodystyle .= sprintf("font-family:%s; ", $this->face); |
1827 |
} |
1828 |
|
1829 |
$this->fontstyle_attrbs = $size . $color . $face; |
1830 |
} |
1831 |
|
1832 |
printf("<title>%s</title>\n", HAW_specchar($this->title, $this)); |
1833 |
|
1834 |
if ($this->pureHTML && $this->use_simulator && $this->css_enabled) |
1835 |
// use HAWHAW default- or user-defined skin |
1836 |
printf("<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\" $endtag\n", $this->skin); |
1837 |
|
1838 |
if ($this->css_enabled) |
1839 |
printf("<style type=\"text/css\">\n<!--\nbody { %s}\n%s-->\n</style>\n", $bodystyle, $css_style); |
1840 |
|
1841 |
echo "</head>\n"; |
1842 |
|
1843 |
if ($this->css_enabled) |
1844 |
echo "<body>\n"; |
1845 |
else |
1846 |
printf("<body%s%s%s%s>\n", $bgcolor, $background, $link_color, $vlink_color); |
1847 |
|
1848 |
if ($this->display_banners) |
1849 |
{ |
1850 |
if ($this->number_of_top_banners > 0) |
1851 |
{ |
1852 |
echo "<center>\n"; |
1853 |
|
1854 |
for ($i=0; $i<$this->number_of_top_banners; $i++) |
1855 |
{ |
1856 |
// display banners at the top of the HTML page |
1857 |
$banner = $this->top_banners[$i]; |
1858 |
$banner->create(); |
1859 |
} |
1860 |
|
1861 |
echo "</center>\n"; |
1862 |
} |
1863 |
} |
1864 |
|
1865 |
if ($this->pureHTML) |
1866 |
{ |
1867 |
if ($this->css_enabled && $this->use_simulator) |
1868 |
{ |
1869 |
// use simulator design |
1870 |
echo "<div id=\"skin\">\n"; |
1871 |
echo "<div id=\"display\">\n"; |
1872 |
} |
1873 |
else |
1874 |
{ |
1875 |
// use classic HAWHAW design |
1876 |
printf("<div style=\"background-color: %s; background-image: url(%s); border: %dpx solid #aaa; padding: 8px; width: %spx; margin: 0px auto;\">\n", |
1877 |
$this->disp_bgcolor, $this->disp_background, $this->border, $this->width); |
1878 |
} |
1879 |
} |
1880 |
|
1881 |
if (!$this->css_enabled && $this->fontstyle_attrbs) |
1882 |
{ |
1883 |
// write style attributes, if any |
1884 |
printf("<font%s>\n", $this->fontstyle_attrbs); |
1885 |
} |
1886 |
} |
1887 |
else |
1888 |
{ |
1889 |
// determine default values for WML, HDML and VXML form elements |
1890 |
|
1891 |
while (list($e_key, $e_val) = each($this->element)) |
1892 |
{ |
1893 |
if ($e_val->get_elementtype() == HAW_FORM) |
1894 |
{ |
1895 |
// one (and only one!) form exists |
1896 |
|
1897 |
$form = $e_val; |
1898 |
$defaults = $form->get_defaults(); |
1899 |
} |
1900 |
} |
1901 |
|
1902 |
if ($this->ml == HAW_WML) |
1903 |
{ |
1904 |
// create WML page header |
1905 |
if (!$this->debug) |
1906 |
{ |
1907 |
$ct = sprintf("content-type: text/vnd.wap.wml"); |
1908 |
header($ct); |
1909 |
} |
1910 |
|
1911 |
if ($this->disable_cache) |
1912 |
{ |
1913 |
// not all WAP clients interprete meta directives! |
1914 |
// disable caching by sending HTTP content-location header with unique value |
1915 |
|
1916 |
if (isset($_SERVER['REQUEST_URI'])) |
1917 |
$request_uri = $_SERVER['REQUEST_URI']; |
1918 |
else |
1919 |
$request_uri = ""; |
1920 |
|
1921 |
if (strchr($request_uri, "?")) |
1922 |
// request URI already contains parameter(s) |
1923 |
$header= sprintf("content-location: %s&hawcid=%s", $request_uri, date("U")); |
1924 |
else |
1925 |
// no parameters in URI |
1926 |
$header= sprintf("content-location: %s?hawcid=%s", $request_uri, date("U")); |
1927 |
|
1928 |
header($header); |
1929 |
} |
1930 |
|
1931 |
echo "<?xml version=\"1.0\"?" . ">\n"; |
1932 |
|
1933 |
if ($this->owgui_1_3) |
1934 |
echo "<!DOCTYPE wml PUBLIC \"-//OPENWAVE.COM//DTD WML 1.3//EN\" \"http://www.openwave.COM/dtd/wml13.dtd\" >\n"; |
1935 |
else |
1936 |
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" \"http://www.wapforum.org/DTD/wml_1.1.xml\">\n"; |
1937 |
|
1938 |
printf("<!-- Generated by %s %s -->\n", HAW_VERSION, HAW_COPYRIGHT); |
1939 |
|
1940 |
if ($this->language) |
1941 |
$language = sprintf(" xml:lang=\"%s\"", $this->language); |
1942 |
else |
1943 |
$language = ""; |
1944 |
|
1945 |
printf("<wml%s>\n", $language); |
1946 |
|
1947 |
if ($this->disable_cache) |
1948 |
{ |
1949 |
echo "<head>\n"; |
1950 |
echo "<meta http-equiv=\"Cache-Control\" content=\"must-revalidate\" forua=\"true\"/>\n"; |
1951 |
echo "<meta http-equiv=\"Cache-Control\" content=\"no-cache\" forua=\"true\"/>\n"; |
1952 |
echo "<meta http-equiv=\"Cache-Control\" content=\"max-age=0\" forua=\"true\"/>\n"; |
1953 |
echo "<meta http-equiv=\"Expires\" content=\"0\" forua=\"true\"/>\n"; |
1954 |
echo "<meta http-equiv=\"Pragma\" content=\"no-cache\" forua=\"true\"/>\n"; |
1955 |
echo "</head>\n"; |
1956 |
} |
1957 |
|
1958 |
if ($this->title) |
1959 |
$title = " title=\"" . HAW_specchar($this->title,$this) . "\""; |
1960 |
else |
1961 |
$title = ""; |
1962 |
|
1963 |
printf("<card%s>\n", $title); |
1964 |
|
1965 |
if (isset ($defaults) && $defaults) |
1966 |
{ |
1967 |
// default values exist |
1968 |
|
1969 |
// set variables each time the card is enter in forward direction ... |
1970 |
|
1971 |
echo "<onevent type=\"onenterforward\">\n"; |
1972 |
echo "<refresh>\n"; |
1973 |
|
1974 |
// initialize all WML variables with their default values |
1975 |
while (list($d_key, $d_val) = each($defaults)) |
1976 |
printf("<setvar name=\"%s\" value=\"%s\"/>\n", |
1977 |
$d_val['name'], HAW_specchar($d_val['value'], $this)); |
1978 |
|
1979 |
reset($defaults); |
1980 |
|
1981 |
echo "</refresh>\n"; |
1982 |
echo "</onevent>\n"; |
1983 |
|
1984 |
// ... and backward direction |
1985 |
|
1986 |
echo "<onevent type=\"onenterbackward\">\n"; |
1987 |
echo "<refresh>\n"; |
1988 |
|
1989 |
while (list($d_key, $d_val) = each($defaults)) |
1990 |
printf("<setvar name=\"%s\" value=\"%s\"/>\n", $d_val['name'], $d_val['value']); |
1991 |
|
1992 |
echo "</refresh>\n"; |
1993 |
echo "</onevent>\n"; |
1994 |
} |
1995 |
|
1996 |
// set redirection timeout |
1997 |
if ($this->timeout > 0) |
1998 |
{ |
1999 |
echo "<onevent type=\"ontimer\">\n"; |
2000 |
printf("<go href=\"%s\"/>\n", HAW_specchar($this->red_url, $this)); |
2001 |
echo "</onevent>\n"; |
2002 |
printf("<timer value=\"%d\"/>\n", $this->timeout*10); |
2003 |
} |
2004 |
|
2005 |
// define <back> softkey |
2006 |
echo "<do type=\"prev\" label=\"Back\">\n"; |
2007 |
echo "<prev/>\n"; |
2008 |
echo "</do>\n"; |
2009 |
} |
2010 |
elseif ($this->ml == HAW_HDML) |
2011 |
{ |
2012 |
// create HDML card set structure |
2013 |
|
2014 |
if (!isset($defaults)) |
2015 |
$defaults = array(); |
2016 |
|
2017 |
$this->hdmlcardset = new HAW_hdmlcardset(HAW_specchar($this->title, $this), |
2018 |
$defaults, $this->disable_cache, |
2019 |
$this->debug, $this->charset); |
2020 |
} |
2021 |
elseif ($this->ml == HAW_VXML) |
2022 |
{ |
2023 |
// create VXML page header |
2024 |
if (!$this->debug) |
2025 |
{ |
2026 |
$ct = sprintf("content-type: application/vxml+xml"); |
2027 |
header($ct); |
2028 |
} |
2029 |
|
2030 |
echo "<?xml version=\"1.0\"?" . ">\n"; |
2031 |
|
2032 |
printf("<!-- Generated by %s %s -->\n", HAW_VERSION, HAW_COPYRIGHT); |
2033 |
|
2034 |
if ($this->language) |
2035 |
$language = sprintf(" xml:lang=\"%s\"", $this->language); |
2036 |
else |
2037 |
$language = ""; |
2038 |
|
2039 |
printf("<vxml%s version=\"2.0\">\n", $language); |
2040 |
|
2041 |
if ($this->disable_cache) |
2042 |
echo "<meta http-equiv=\"Expires\" content=\"0\"/>\n"; |
2043 |
|
2044 |
// define voice deck properties |
2045 |
while (list($key, $val) = each($this->voice_property)) |
2046 |
printf("<property name=\"%s\" value=\"%s\"/>\n", $val["name"], $val["value"]); |
2047 |
|
2048 |
echo "<form>\n"; |
2049 |
|
2050 |
if (count($this->voice_navigator) > 0) |
2051 |
{ |
2052 |
// allow user navigation in dedicated prompts |
2053 |
|
2054 |
echo "<var name=\"nav_counter\"/>\n"; |
2055 |
|
2056 |
if (strlen($this->voice_navigator["repeat_dtmf"]) > 0) |
2057 |
$dtmf = sprintf(" dtmf=\"%s\"", $this->voice_navigator["repeat_dtmf"]); |
2058 |
else |
2059 |
$dtmf = ""; |
2060 |
|
2061 |
if ($this->voice_navigator["repeat_voice"]) |
2062 |
$voice_grammar = sprintf("<grammar>[%s]</grammar>", $this->voice_navigator["repeat_voice"]); |
2063 |
else |
2064 |
$voice_grammar = ""; |
2065 |
|
2066 |
printf("<link%s event=\"repeat\">%s</link>\n", $dtmf, $voice_grammar); // define repeat link |
2067 |
|
2068 |
if (strlen($this->voice_navigator["forward_dtmf"]) > 0) |
2069 |
$dtmf = sprintf(" dtmf=\"%s\"", $this->voice_navigator["forward_dtmf"]); |
2070 |
else |
2071 |
$dtmf = ""; |
2072 |
|
2073 |
if ($this->voice_navigator["forward_voice"]) |
2074 |
$voice_grammar = sprintf("<grammar>[%s]</grammar>", $this->voice_navigator["forward_voice"]); |
2075 |
else |
2076 |
$voice_grammar = ""; |
2077 |
|
2078 |
printf("<link%s event=\"forward\">%s</link>\n", $dtmf, $voice_grammar); // define forward link |
2079 |
|
2080 |
// define catch handler for links |
2081 |
echo "<catch event=\"repeat\"><goto expritem=\"'block' + nav_counter\"/></catch>\n"; |
2082 |
echo "<catch event=\"forward\"><goto expritem=\"'block' + nav_counter + 'end'\"/></catch>\n"; |
2083 |
} |
2084 |
|
2085 |
if ($this->voice_text || $this->voice_audio_src) |
2086 |
{ |
2087 |
// create introducing audio output for VoiceXML deck |
2088 |
|
2089 |
echo "<block><prompt>"; |
2090 |
|
2091 |
HAW_voice_audio(HAW_specchar($this->voice_text, $this), |
2092 |
$this->voice_audio_src, HAW_VOICE_PAUSE, $this); |
2093 |
|
2094 |
echo "</prompt></block>\n"; |
2095 |
} |
2096 |
} |
2097 |
} |
2098 |
|
2099 |
// position:relative is needed to work-around MSIE's Peekaboo bug ... |
2100 |
// text-align aligns left, centered or right |
2101 |
$divstyle = sprintf("text-align:%s; position:relative;", $this->alignment); |
2102 |
|
2103 |
if ($this->ml == HAW_HTML) |
2104 |
{ |
2105 |
if ($this->css_enabled) |
2106 |
printf("<div style=\"%s\">\n", $divstyle); |
2107 |
else |
2108 |
printf("<div align=\"%s\">\n", $this->alignment); |
2109 |
} |
2110 |
elseif ($this->ml == HAW_WML) |
2111 |
printf("<p align=\"%s\">\n", $this->alignment); |
2112 |
|
2113 |
$i = 0; |
2114 |
while (isset($this->element[$i])) |
2115 |
{ |
2116 |
$page_element = $this->element[$i]; |
2117 |
switch ($page_element->get_elementtype()) |
2118 |
{ |
2119 |
case HAW_PLAINTEXT: |
2120 |
case HAW_IMAGE: |
2121 |
case HAW_TABLE: |
2122 |
case HAW_FORM: |
2123 |
case HAW_LINK: |
2124 |
case HAW_PHONE: |
2125 |
case HAW_LINKSET: |
2126 |
case HAW_RAW: |
2127 |
case HAW_USERDEFINED: |
2128 |
case HAW_RULE: |
2129 |
case HAW_VOICERECORDER: |
2130 |
{ |
2131 |
$element = $this->element[$i]; |
2132 |
$element->create($this); |
2133 |
|
2134 |
break; |
2135 |
} |
2136 |
} |
2137 |
|
2138 |
$i++; |
2139 |
} |
2140 |
|
2141 |
if ($this->ml == HAW_HTML) |
2142 |
{ |
2143 |
// create HTML page end |
2144 |
|
2145 |
// ATTENTION! |
2146 |
// |
2147 |
// DO NOT REMOVE THE COPYRIGHT LINK WITHOUT PERMISSION! |
2148 |
// IF YOU DO SO, YOU ARE VIOLATING THE LICENSE TERMS |
2149 |
// OF THIS SOFTWARE! YOU HAVE TO PAY NOTHING FOR THIS |
2150 |
// SOFTWARE, SO PLEASE BE SO FAIR TO ACCEPT THE RULES. |
2151 |
// IF YOU DON'T, YOUR WEBSITE WILL AT LEAST BE LISTED IN |
2152 |
// THE HAWHAW HALL OF SHAME! |
2153 |
// PLEASE REFER TO THE LIBRARY HEADER AND THE HAWHAW |
2154 |
// HOMEPAGE FOR MORE INFORMATION. |
2155 |
|
2156 |
echo "</div>\n"; |
2157 |
|
2158 |
if (!$this->css_enabled && $this->fontstyle_attrbs) |
2159 |
echo "</font>\n"; |
2160 |
|
2161 |
if ($this->pureHTML) |
2162 |
{ |
2163 |
if ($this->css_enabled && $this->use_simulator) |
2164 |
// terminate display div |
2165 |
echo "</div>\n"; |
2166 |
|
2167 |
echo "</div>\n"; // terminate skin/classic div |
2168 |
|
2169 |
if (!$this->lynx) |
2170 |
{ |
2171 |
if ($haw_license_holder && $haw_signature) |
2172 |
{ |
2173 |
if ($haw_signature == 1) |
2174 |
$signature = "<small>Powered by HAWHAW (C)</small>\n"; |
2175 |
else |
2176 |
if ($haw_sig_text) |
2177 |
if ($haw_sig_link) |
2178 |
$signature = sprintf("<a href=\"%s\" target=\"_blank\"><small>%s</small></a>\n", $haw_sig_link, $haw_sig_text); |
2179 |
else |
2180 |
$signature = sprintf("<small>%s</small>\n", $haw_sig_text); |
2181 |
} |
2182 |
else |
2183 |
$signature = sprintf("<a href=\"http://info.hawhaw.de/index.htm?host=%s\" target=\"_blank\"><small>Powered by HAWHAW (C)</small></a>\n", $this->waphome); |
2184 |
|
2185 |
echo $signature; |
2186 |
} |
2187 |
} |
2188 |
|
2189 |
if ($this->display_banners) |
2190 |
{ |
2191 |
if ($this->number_of_bottom_banners > 0) |
2192 |
{ |
2193 |
echo "<center>\n"; |
2194 |
|
2195 |
for ($i=0; $i<$this->number_of_bottom_banners; $i++) |
2196 |
{ |
2197 |
// display banners at the bottom of the HTML page |
2198 |
$banner = $this->bottom_banners[$i]; |
2199 |
$banner->create(); |
2200 |
} |
2201 |
|
2202 |
echo "</center>\n"; |
2203 |
} |
2204 |
} |
2205 |
|
2206 |
echo "</body>\n"; |
2207 |
echo "</html>\n"; |
2208 |
} |
2209 |
elseif ($this->ml == HAW_WML) |
2210 |
{ |
2211 |
// create WML page end |
2212 |
echo "</p>\n"; |
2213 |
echo "</card>\n"; |
2214 |
echo "</wml>\n"; |
2215 |
} |
2216 |
elseif ($this->ml == HAW_HDML) |
2217 |
{ |
2218 |
// create HDML page from hdml card set structure |
2219 |
$cardset = $this->hdmlcardset; |
2220 |
$cardset->create_hdmldeck(); |
2221 |
} |
2222 |
elseif ($this->ml == HAW_VXML) |
2223 |
{ |
2224 |
// create VoiceXML page end |
2225 |
|
2226 |
// set redirection timeout |
2227 |
if ($this->timeout > 0) |
2228 |
{ |
2229 |
// redirect after <timout> to another URL |
2230 |
// (define dummy grammar in case that no other grammar is active) |
2231 |
printf("<field><grammar>[(hawhaw really rocks)]</grammar><prompt timeout=\"%ds\"/><noinput><goto next=\"%s\"/></noinput></field>\n", |
2232 |
$this->timeout, $this->red_url); |
2233 |
} |
2234 |
elseif($this->voice_timeout > 0) |
2235 |
{ |
2236 |
// there is at least one voice link active |
2237 |
// wait longest link timeout value until disconnect is forced |
2238 |
|
2239 |
printf("<field><prompt timeout=\"%ds\"/>", $this->voice_timeout); |
2240 |
|
2241 |
// test for user-defined noinput event handler |
2242 |
if (!isset($this->voice_noinput) || (count($this->voice_noinput) == 0)) |
2243 |
echo "<noinput><exit/></noinput>"; // terminate in case of no input |
2244 |
|
2245 |
echo "</field>\n"; |
2246 |
} |
2247 |
|
2248 |
echo "</form>\n"; |
2249 |
|
2250 |
if ($this->voice_links) |
2251 |
echo $this->voice_links; |
2252 |
|
2253 |
// create event handlers |
2254 |
HAW_voice_eventhandler("help", $this->voice_help, $this); |
2255 |
HAW_voice_eventhandler("noinput", $this->voice_noinput, $this); |
2256 |
HAW_voice_eventhandler("nomatch", $this->voice_nomatch, $this); |
2257 |
|
2258 |
echo "</vxml>\n"; |
2259 |
} |
2260 |
} |
2261 |
}; |
2262 |
|
2263 |
|
2264 |
|
2265 |
|
2266 |
|
2267 |
|
2268 |
/** |
2269 |
This class defines a form with various possible input elements. The input elements |
2270 |
have to be defined as separate objects and are linked to the form with a special |
2271 |
"add" function. One HAW_deck object can contain only one HAW_form object. |
2272 |
<p><b>Examples:</b><p> |
2273 |
$myPage = new HAW_deck(...);<br> |
2274 |
...<br> |
2275 |
$myForm = new HAW_form("/mynextpage.php");<br> |
2276 |
$myText = new HAW_text(...);<br> |
2277 |
$myForm->add_text($myText);<br> |
2278 |
$myInput = new HAW_input(...);<br> |
2279 |
$myForm->add_input($myInput);<br> |
2280 |
$mySubmit = new HAW_submit(...);<br> |
2281 |
$myForm->add_submit($mySubmit);<br> |
2282 |
...<br> |
2283 |
$myPage->add_form($myForm);<br> |
2284 |
...<br> |
2285 |
$myPage->create_page(); |
2286 |
@see HAW_text |
2287 |
@see HAW_image |
2288 |
@see HAW_table |
2289 |
@see HAW_input |
2290 |
@see HAW_textarea |
2291 |
@see HAW_select |
2292 |
@see HAW_radio |
2293 |
@see HAW_checkbox |
2294 |
@see HAW_hidden |
2295 |
@see HAW_submit |
2296 |
@see HAW_rule |
2297 |
*/ |
2298 |
class HAW_form |
2299 |
{ |
2300 |
var $url; |
2301 |
var $element; |
2302 |
var $number_of_elements = 0; |
2303 |
var $number_of_submitobjects = 0; |
2304 |
var $voice_text = ""; |
2305 |
var $voice_audio_src = ""; |
2306 |
|
2307 |
/** |
2308 |
Constructor |
2309 |
@param url Address where the user input is sent to.<br> |
2310 |
Note: Currently only the GET method is supported. |
2311 |
*/ |
2312 |
function HAW_form($url) |
2313 |
{ |
2314 |
$this->url = $url; |
2315 |
} |
2316 |
|
2317 |
|
2318 |
/** |
2319 |
Adds a HAW_text object to HAW_form. |
2320 |
@param text Some HAW_text object. |
2321 |
@see HAW_text |
2322 |
*/ |
2323 |
function add_text($text) |
2324 |
{ |
2325 |
if (!is_object($text)) |
2326 |
die("invalid argument in add_text()"); |
2327 |
|
2328 |
$this->element[$this->number_of_elements] = $text; |
2329 |
|
2330 |
$this->number_of_elements++; |
2331 |
} |
2332 |
|
2333 |
|
2334 |
/** |
2335 |
Adds a HAW_image object to HAW_form. |
2336 |
@param image Some HAW_image object. |
2337 |
@see HAW_image |
2338 |
*/ |
2339 |
function add_image($image) |
2340 |
{ |
2341 |
if (!is_object($image)) |
2342 |
die("invalid argument in add_image()"); |
2343 |
|
2344 |
$this->element[$this->number_of_elements] = $image; |
2345 |
|
2346 |
$this->number_of_elements++; |
2347 |
} |
2348 |
|
2349 |
|
2350 |
/** |
2351 |
Adds a HAW_table object to HAW_form. |
2352 |
@param table Some HAW_table object. |
2353 |
@see HAW_table |
2354 |
*/ |
2355 |
function add_table($table) |
2356 |
{ |
2357 |
if (!is_object($table)) |
2358 |
die("invalid argument in add_table()"); |
2359 |
|
2360 |
$this->element[$this->number_of_elements] = $table; |
2361 |
|
2362 |
$this->number_of_elements++; |
2363 |
} |
2364 |
|
2365 |
|
2366 |
/** |
2367 |
Adds a HAW_input object to HAW_form. |
2368 |
@param input Some HAW_input object. |
2369 |
@see HAW_input |
2370 |
*/ |
2371 |
function add_input($input) |
2372 |
{ |
2373 |
if (!is_object($input)) |
2374 |
die("invalid argument in add_input()"); |
2375 |
|
2376 |
$this->element[$this->number_of_elements] = $input; |
2377 |
|
2378 |
$this->number_of_elements++; |
2379 |
} |
2380 |
|
2381 |
|
2382 |
/** |
2383 |
Adds a HAW_textarea object to HAW_form. |
2384 |
@param textarea Some HAW_textarea object. |
2385 |
@see HAW_textarea |
2386 |
*/ |
2387 |
function add_textarea($textarea) |
2388 |
{ |
2389 |
if (!is_object($textarea)) |
2390 |
die("invalid argument in add_textarea()"); |
2391 |
|
2392 |
$this->element[$this->number_of_elements] = $textarea; |
2393 |
|
2394 |
$this->number_of_elements++; |
2395 |
} |
2396 |
|
2397 |
|
2398 |
/** |
2399 |
Adds a HAW_select object to HAW_form. |
2400 |
@param select Some HAW_select object. |
2401 |
@see HAW_select |
2402 |
*/ |
2403 |
function add_select($select) |
2404 |
{ |
2405 |
if (!is_object($select)) |
2406 |
die("invalid argument in add_select()"); |
2407 |
|
2408 |
$this->element[$this->number_of_elements] = $select; |
2409 |
|
2410 |
$this->number_of_elements++; |
2411 |
} |
2412 |
|
2413 |
|
2414 |
/** |
2415 |
Adds a HAW_radio object to HAW_form. |
2416 |
@param radio Some HAW_radio object. |
2417 |
@see HAW_radio |
2418 |
*/ |
2419 |
function add_radio($radio) |
2420 |
{ |
2421 |
if (!is_object($radio)) |
2422 |
die("invalid argument in add_radio()"); |
2423 |
|
2424 |
$this->element[$this->number_of_elements] = $radio; |
2425 |
|
2426 |
$this->number_of_elements++; |
2427 |
} |
2428 |
|
2429 |
|
2430 |
/** |
2431 |
Adds a HAW_checkbox object to HAW_form. |
2432 |
@param checkbox Some HAW_checkbox object. |
2433 |
@see HAW_checkbox |
2434 |
*/ |
2435 |
function add_checkbox($checkbox) |
2436 |
{ |
2437 |
if (!is_object($checkbox)) |
2438 |
die("invalid argument in add_checkbox()"); |
2439 |
|
2440 |
$this->element[$this->number_of_elements] = $checkbox; |
2441 |
|
2442 |
$this->number_of_elements++; |
2443 |
} |
2444 |
|
2445 |
|
2446 |
/** |
2447 |
Adds a HAW_hidden object to HAW_form. |
2448 |
@param hidden Some HAW_hidden object. |
2449 |
@see HAW_hidden |
2450 |
*/ |
2451 |
function add_hidden($hidden) |
2452 |
{ |
2453 |
if (!is_object($hidden)) |
2454 |
die("invalid argument in add_hidden()"); |
2455 |
|
2456 |
$this->element[$this->number_of_elements] = $hidden; |
2457 |
|
2458 |
$this->number_of_elements++; |
2459 |
} |
2460 |
|
2461 |
|
2462 |
/** |
2463 |
Adds a HAW_submit object to HAW_form. |
2464 |
@param submit Some HAW_submit object. |
2465 |
@see HAW_submit |
2466 |
*/ |
2467 |
function add_submit($submit) |
2468 |
{ |
2469 |
if (!is_object($submit)) |
2470 |
die("invalid argument in add_submit()"); |
2471 |
|
2472 |
if ($this->number_of_submitobjects > 0) |
2473 |
die("only one HAW_submit object per form allowed!"); |
2474 |
|
2475 |
$this->element[$this->number_of_elements] = $submit; |
2476 |
|
2477 |
$this->number_of_elements++; |
2478 |
$this->number_of_submitobjects++; |
2479 |
} |
2480 |
|
2481 |
|
2482 |
/* |
2483 |
Adds a HAW_raw object to HAW_form. (undocumented feature - for test only!) |
2484 |
@param raw_markup_object Some HAW_raw object. |
2485 |
@see HAW_raw |
2486 |
*/ |
2487 |
function add_raw($raw) |
2488 |
{ |
2489 |
if (!is_object($raw)) |
2490 |
die("invalid argument in add_raw()"); |
2491 |
|
2492 |
$this->element[$this->number_of_elements] = $raw; |
2493 |
|
2494 |
$this->number_of_elements++; |
2495 |
} |
2496 |
|
2497 |
|
2498 |
/* |
2499 |
Adds some user-defined HAWHAW object to HAW_form (undocumented feature)<br> |
2500 |
For skilled HAWHAW programmers only! |
2501 |
@param udef Some user-defined object. |
2502 |
*/ |
2503 |
function add_userdefined($udef) |
2504 |
{ |
2505 |
// see HAW_deck->add_userdefined($def) for documentation |
2506 |
|
2507 |
if (!is_object($udef)) |
2508 |
die("invalid argument in add_userdefined()"); |
2509 |
|
2510 |
$this->element[$this->number_of_elements] = $udef; |
2511 |
|
2512 |
$this->number_of_elements++; |
2513 |
} |
2514 |
|
2515 |
|
2516 |
/** |
2517 |
Adds a HAW_rule object to HAW_form. |
2518 |
@param rule Some HAW_rule object. |
2519 |
@see HAW_rule |
2520 |
*/ |
2521 |
function add_rule($rule) |
2522 |
{ |
2523 |
if (!is_object($rule)) |
2524 |
die("invalid argument in add_rule()"); |
2525 |
|
2526 |
$this->element[$this->number_of_elements] = $rule; |
2527 |
|
2528 |
$this->number_of_elements++; |
2529 |
} |
2530 |
|
2531 |
|
2532 |
/** |
2533 |
Sets form-related text to be spoken by voice browsers. <br> |
2534 |
@param text Some introducing text that will be spoken before any dialog |
2535 |
is started. |
2536 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
2537 |
*/ |
2538 |
function set_voice_text($text, $audio_src="") |
2539 |
{ |
2540 |
if (!is_string($text)) |
2541 |
die("invalid argument in set_voice_text()"); |
2542 |
|
2543 |
$this->voice_text = $text; |
2544 |
$this->voice_audio_src = $audio_src; |
2545 |
} |
2546 |
|
2547 |
|
2548 |
function get_defaults() |
2549 |
{ |
2550 |
$defaults = array(); |
2551 |
|
2552 |
$i = 0; |
2553 |
while (list($key, $val) = each($this->element)) |
2554 |
{ |
2555 |
switch ($val->get_elementtype()) |
2556 |
{ |
2557 |
case HAW_CHECKBOX: |
2558 |
{ |
2559 |
$checkbox = $val; |
2560 |
|
2561 |
if ($checkbox->is_checked()) |
2562 |
{ |
2563 |
$defaults[$i]["name"] = $checkbox->get_name(); |
2564 |
$defaults[$i]["value"] = $checkbox->get_value(); |
2565 |
$i++; |
2566 |
} |
2567 |
|
2568 |
break; |
2569 |
} |
2570 |
|
2571 |
case HAW_INPUT: |
2572 |
case HAW_TEXTAREA: |
2573 |
case HAW_SELECT: |
2574 |
case HAW_RADIO: |
2575 |
case HAW_HIDDEN: |
2576 |
{ |
2577 |
$element = $val; |
2578 |
|
2579 |
$defaults[$i]["name"] = $element->get_name(); |
2580 |
$defaults[$i]["value"] = $element->get_value(); |
2581 |
$i++; |
2582 |
|
2583 |
break; |
2584 |
} |
2585 |
} |
2586 |
} |
2587 |
|
2588 |
return $defaults; |
2589 |
} |
2590 |
|
2591 |
function get_elementtype() |
2592 |
{ |
2593 |
return HAW_FORM; |
2594 |
} |
2595 |
|
2596 |
function create(&$deck) |
2597 |
{ |
2598 |
// add hawoutput query parameter to form, if required |
2599 |
if ($deck->hawoutput) |
2600 |
{ |
2601 |
$hidden_hawoutput = new HAW_hidden("hawoutput", $deck->hawoutput); |
2602 |
$this->add_hidden($hidden_hawoutput); |
2603 |
} |
2604 |
|
2605 |
// determine all elements that have to be submitted |
2606 |
|
2607 |
$i = 0; |
2608 |
while (list($key, $val) = each($this->element)) |
2609 |
{ |
2610 |
switch ($val->get_elementtype()) |
2611 |
{ |
2612 |
case HAW_INPUT: |
2613 |
case HAW_TEXTAREA: |
2614 |
case HAW_SELECT: |
2615 |
case HAW_CHECKBOX: |
2616 |
case HAW_RADIO: |
2617 |
case HAW_HIDDEN: |
2618 |
{ |
2619 |
$element = $val; |
2620 |
$getvar[$i] = $element->get_name(); |
2621 |
$i++; |
2622 |
} |
2623 |
} |
2624 |
} |
2625 |
|
2626 |
if ($deck->ml == HAW_HTML) |
2627 |
{ |
2628 |
// start tag of HTML form |
2629 |
printf("<form action=\"%s\" method=\"get\">\n", $this->url); |
2630 |
|
2631 |
if ($deck->xhtml) |
2632 |
echo "<div>\n"; // needed for validation |
2633 |
} |
2634 |
// not necessary in WML, HDML and VoiceXML! |
2635 |
|
2636 |
if ($deck->ml == HAW_VXML) |
2637 |
{ |
2638 |
if ($this->voice_text || $this->voice_audio_src) |
2639 |
{ |
2640 |
// create introducing audio output for VoiceXML form |
2641 |
|
2642 |
echo "<block><prompt>"; |
2643 |
|
2644 |
HAW_voice_audio(HAW_specchar($this->voice_text, $deck), |
2645 |
$this->voice_audio_src, HAW_VOICE_PAUSE, $deck); |
2646 |
|
2647 |
echo "</prompt></block>\n"; |
2648 |
} |
2649 |
} |
2650 |
|
2651 |
$i = 0; |
2652 |
while (isset($this->element[$i])) |
2653 |
{ |
2654 |
$form_element = $this->element[$i]; |
2655 |
switch ($form_element->get_elementtype()) |
2656 |
{ |
2657 |
case HAW_PLAINTEXT: |
2658 |
case HAW_IMAGE: |
2659 |
case HAW_TABLE: |
2660 |
case HAW_INPUT: |
2661 |
case HAW_TEXTAREA: |
2662 |
case HAW_SELECT: |
2663 |
case HAW_RADIO: |
2664 |
case HAW_CHECKBOX: |
2665 |
case HAW_HIDDEN: |
2666 |
case HAW_RAW: |
2667 |
case HAW_RULE: |
2668 |
case HAW_USERDEFINED: |
2669 |
{ |
2670 |
$form_element->create($deck); |
2671 |
break; |
2672 |
} |
2673 |
|
2674 |
case HAW_SUBMIT: |
2675 |
{ |
2676 |
$submit = $this->element[$i]; |
2677 |
$submit->create($deck, $getvar, $this->url); |
2678 |
break; |
2679 |
} |
2680 |
|
2681 |
} |
2682 |
|
2683 |
$i++; |
2684 |
} |
2685 |
|
2686 |
if ($deck->ml == HAW_HTML) |
2687 |
{ |
2688 |
if ($deck->xhtml) |
2689 |
echo "</div>\n"; |
2690 |
|
2691 |
// terminate HTML form |
2692 |
echo "</form>\n"; |
2693 |
} |
2694 |
} |
2695 |
}; |
2696 |
|
2697 |
|
2698 |
|
2699 |
|
2700 |
|
2701 |
|
2702 |
/** |
2703 |
This class allows to insert plain text into a HAW_deck, HAW_form or HAW_table object. |
2704 |
<p><b>Examples:</b><p> |
2705 |
$myText1 = new HAW_text("Hello WAP!");<br> |
2706 |
$myText2 = new HAW_text("Welcome to HAWHAW", HAW_TEXTFORMAT_BOLD);<br> |
2707 |
$myText3 = new HAW_text("Good Morning", HAW_TEXTFORMAT_BOLD | HAW_TEXTFORMAT_BIG);<br> |
2708 |
<br> |
2709 |
$myText3->set_br(2);<br> |
2710 |
@see HAW_deck |
2711 |
@see HAW_form |
2712 |
@see HAW_row |
2713 |
*/ |
2714 |
class HAW_text |
2715 |
{ |
2716 |
var $text; |
2717 |
var $attrib; |
2718 |
var $color; |
2719 |
var $boxcolor; |
2720 |
var $br; |
2721 |
var $voice_text; |
2722 |
var $voice_audio_src; |
2723 |
var $voice_navigation; |
2724 |
|
2725 |
/** |
2726 |
Constructor |
2727 |
@param text Some string you want to display |
2728 |
@param attrib (optional)<br> |
2729 |
HAW_TEXTFORMAT_NORMAL (default)<br> |
2730 |
HAW_TEXTFORMAT_BOLD<br> |
2731 |
HAW_TEXTFORMAT_UNDERLINE<br> |
2732 |
HAW_TEXTFORMAT_ITALIC<br> |
2733 |
HAW_TEXTFORMAT_BIG<br> |
2734 |
HAW_TEXTFORMAT_SMALL<br> |
2735 |
HAW_TEXTFORMAT_BOXED (text in a colored box for headings etc.) |
2736 |
*/ |
2737 |
function HAW_text($text, $attrib=HAW_TEXTFORMAT_NORMAL) |
2738 |
{ |
2739 |
$this->text = $text; |
2740 |
$this->attrib = $attrib; |
2741 |
$this->color = ""; |
2742 |
$this->boxcolor = ""; |
2743 |
$this->br = 1; // default: 1 line break after text |
2744 |
$this->voice_text = $text; |
2745 |
$this->voice_audio_src = ""; |
2746 |
$this->voice_navigation = false; |
2747 |
} |
2748 |
|
2749 |
/** |
2750 |
Sets the color of this object in a (X)HTML page. |
2751 |
@param color See HTML specification for possible values (e.g. "#CCFFFF", "red", |
2752 |
...). |
2753 |
@param boxcolor (optional)<br> |
2754 |
box background for attribute HAW_TEXTFORMAT_BOXED |
2755 |
*/ |
2756 |
function set_color($color, $boxcolor="") |
2757 |
{ |
2758 |
$this->color = $color; |
2759 |
$this->boxcolor = $boxcolor; |
2760 |
} |
2761 |
|
2762 |
/** |
2763 |
Sets the number of line breaks (CRLF) after text. (default: 1) |
2764 |
@param br Some number of line breaks. |
2765 |
*/ |
2766 |
function set_br($br) |
2767 |
{ |
2768 |
if (!is_int($br) || ($br < 0)) |
2769 |
die("invalid argument in set_br()"); |
2770 |
|
2771 |
$this->br = $br; |
2772 |
} |
2773 |
|
2774 |
/** |
2775 |
Sets text to be spoken by voice browsers. <br> |
2776 |
@param text Some alternative text that replaces original <text>. |
2777 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
2778 |
*/ |
2779 |
function set_voice_text($text, $audio_src="") |
2780 |
{ |
2781 |
if (!is_string($text)) |
2782 |
die("invalid argument in set_voice_text()"); |
2783 |
|
2784 |
$this->voice_text = $text; |
2785 |
$this->voice_audio_src = $audio_src; |
2786 |
} |
2787 |
|
2788 |
/** |
2789 |
Turns on the voice navigation capability for this object. <br> |
2790 |
Note: See <i>set_voice_navigator(...)</i> in class HAW_deck. |
2791 |
@see HAW_deck |
2792 |
*/ |
2793 |
function set_voice_navigation() |
2794 |
{ |
2795 |
$this->voice_navigation = true; |
2796 |
} |
2797 |
|
2798 |
function get_text() |
2799 |
{ |
2800 |
return $this->text; |
2801 |
} |
2802 |
|
2803 |
function get_color() |
2804 |
{ |
2805 |
return $this->color; |
2806 |
} |
2807 |
|
2808 |
function get_br() |
2809 |
{ |
2810 |
return $this->br; |
2811 |
} |
2812 |
|
2813 |
function get_attrib() |
2814 |
{ |
2815 |
return $this->attrib; |
2816 |
} |
2817 |
|
2818 |
function get_elementtype() |
2819 |
{ |
2820 |
return HAW_PLAINTEXT; |
2821 |
} |
2822 |
|
2823 |
function create(&$deck) |
2824 |
{ |
2825 |
if ($deck->ml == HAW_HDML) |
2826 |
{ |
2827 |
// HDML |
2828 |
|
2829 |
$deck->hdmlcardset->add_display_content("<" . $deck->alignment . ">\n"); |
2830 |
|
2831 |
// print text |
2832 |
if ($this->text) |
2833 |
{ |
2834 |
$content = sprintf("%s\n", HAW_specchar($this->text, $deck)); |
2835 |
$deck->hdmlcardset->add_display_content($content); |
2836 |
} |
2837 |
|
2838 |
// create required amount of carriage return's |
2839 |
$br = ""; |
2840 |
for ($i=0; $i < $this->br; $i++) |
2841 |
$br .= "<br>\n"; |
2842 |
|
2843 |
$deck->hdmlcardset->add_display_content($br); |
2844 |
} |
2845 |
elseif(($deck->ml == HAW_HTML) || ($deck->ml == HAW_WML)) |
2846 |
{ |
2847 |
// HTML or WML |
2848 |
|
2849 |
if (($this->attrib & HAW_TEXTFORMAT_BOXED) && ($deck->ml == HAW_HTML)) |
2850 |
{ |
2851 |
// determine text and background color, if not already assigned |
2852 |
|
2853 |
if (!$this->color) |
2854 |
$this->color = $deck->disp_bgcolor; |
2855 |
if (!$this->color) |
2856 |
$this->color = "#FFFFFF"; // default: white text |
2857 |
|
2858 |
if (!$this->boxcolor) |
2859 |
$this->boxcolor = $deck->color; |
2860 |
if (!$this->boxcolor) |
2861 |
$this->boxcolor = "#000000"; // default: on black background |
2862 |
|
2863 |
if ($deck->css_enabled) |
2864 |
printf("<div style=\"background-color:%s; margin:0px;\">\n", $this->boxcolor); |
2865 |
else |
2866 |
{ |
2867 |
printf("<table border=\"0\" bgcolor=\"%s\" width=\"100%%\"><tr><td><font%s>\n", |
2868 |
$this->boxcolor, $deck->fontstyle_attrbs); |
2869 |
|
2870 |
// align text in (table-)box |
2871 |
printf("<div align=\"%s\">\n", $deck->alignment); |
2872 |
} |
2873 |
|
2874 |
// decrement line breaks because div/table already causes 1 br |
2875 |
if ($this->br >= 1) |
2876 |
$this->br--; |
2877 |
} |
2878 |
|
2879 |
if ($this->attrib & HAW_TEXTFORMAT_BOLD) |
2880 |
echo "<b>\n"; |
2881 |
|
2882 |
if ($this->attrib & HAW_TEXTFORMAT_UNDERLINE) |
2883 |
{ |
2884 |
if ($deck->css_enabled) |
2885 |
echo "<span style=\"text-decoration:underline;\">\n"; |
2886 |
else |
2887 |
echo "<u>\n"; |
2888 |
} |
2889 |
|
2890 |
if ($this->attrib & HAW_TEXTFORMAT_ITALIC) |
2891 |
echo "<i>\n"; |
2892 |
|
2893 |
if ($this->attrib & HAW_TEXTFORMAT_BIG) |
2894 |
echo "<big>\n"; |
2895 |
|
2896 |
if ($this->attrib & HAW_TEXTFORMAT_SMALL) |
2897 |
echo "<small>\n"; |
2898 |
|
2899 |
if (($deck->ml == HAW_HTML) && $this->color) |
2900 |
{ |
2901 |
if ($deck->css_enabled) |
2902 |
printf("<span style=\"color:%s;\">\n", $this->color); |
2903 |
else |
2904 |
printf("<font color=\"%s\">", $this->color); |
2905 |
} |
2906 |
|
2907 |
// print text |
2908 |
if (isset($this->text)) |
2909 |
printf("%s\n", HAW_specchar($this->text, $deck)); |
2910 |
|
2911 |
if (($deck->ml == HAW_HTML) && $this->color) |
2912 |
{ |
2913 |
if ($deck->css_enabled) |
2914 |
echo "</span>"; |
2915 |
else |
2916 |
echo "</font>"; |
2917 |
} |
2918 |
|
2919 |
if ($this->attrib & HAW_TEXTFORMAT_SMALL) |
2920 |
echo "</small>\n"; |
2921 |
|
2922 |
if ($this->attrib & HAW_TEXTFORMAT_BIG) |
2923 |
echo "</big>\n"; |
2924 |
|
2925 |
if ($this->attrib & HAW_TEXTFORMAT_ITALIC) |
2926 |
echo "</i>\n"; |
2927 |
|
2928 |
if ($this->attrib & HAW_TEXTFORMAT_UNDERLINE) |
2929 |
{ |
2930 |
if ($deck->css_enabled) |
2931 |
echo "</span>\n"; |
2932 |
else |
2933 |
echo "</u>\n"; |
2934 |
} |
2935 |
|
2936 |
if ($this->attrib & HAW_TEXTFORMAT_BOLD) |
2937 |
echo "</b>\n"; |
2938 |
|
2939 |
if (($this->attrib & HAW_TEXTFORMAT_BOXED) && ($deck->ml == HAW_HTML)) |
2940 |
{ |
2941 |
if ($deck->css_enabled) |
2942 |
echo "</div>\n"; |
2943 |
else |
2944 |
echo "</div></font></td></tr></table>\n"; |
2945 |
} |
2946 |
|
2947 |
// create required amount of carriage return's |
2948 |
for ($i=0; $i < $this->br; $i++) |
2949 |
echo "<br />\n"; |
2950 |
} |
2951 |
elseif($deck->ml == HAW_VXML) |
2952 |
{ |
2953 |
// VoiceXML |
2954 |
|
2955 |
if ($this->voice_navigation) |
2956 |
{ |
2957 |
// enable navigation (repeat/forward) |
2958 |
static $block_counter = 0; |
2959 |
printf("<block name=\"block%d\"><assign name=\"nav_counter\" expr=\"%d\"/><prompt>", |
2960 |
$block_counter, $block_counter); |
2961 |
} |
2962 |
else |
2963 |
echo "<block><prompt>"; |
2964 |
|
2965 |
$pause = $this->br * HAW_VOICE_PAUSE; // short pause for each break |
2966 |
|
2967 |
// remove leading commas, dots etc. which may appear after link objects |
2968 |
HAW_voice_audio(ereg_replace("^[\?!,;.]", " ", HAW_specchar($this->voice_text, $deck)), |
2969 |
$this->voice_audio_src, $pause, $deck); |
2970 |
|
2971 |
echo "</prompt></block>\n"; |
2972 |
|
2973 |
if ($this->voice_navigation) |
2974 |
{ |
2975 |
// create artificial field to control VoiceXML sequencing |
2976 |
printf("<field name=\"dummy%d\">\n", $block_counter); |
2977 |
echo "<property name=\"timeout\" value=\"0.5s\"/>\n"; |
2978 |
echo "<grammar>[(hawhaw really rocks)]</grammar>\n"; |
2979 |
printf("<noinput><assign name=\"dummy%d\" expr=\"true\"/></noinput>\n", $block_counter); |
2980 |
echo "</field>\n"; |
2981 |
|
2982 |
// create block end where forward will go to |
2983 |
printf("<block name=\"block%dend\"/>\n", $block_counter++); |
2984 |
} |
2985 |
} |
2986 |
} |
2987 |
}; |
2988 |
|
2989 |
|
2990 |
|
2991 |
|
2992 |
|
2993 |
|
2994 |
/** |
2995 |
This class allows to insert bitmap images into a HAW_deck, HAW_form or HAW_table |
2996 |
object. |
2997 |
<p><b>Examples:</b><p> |
2998 |
$myImage1 = new HAW_image("my_image.wbmp", "my_image.gif", ":-)");<br> |
2999 |
$myImage2 = new HAW_image("my_image.wbmp", "my_image.gif", ":-)", "my_image.bmp");<br> |
3000 |
$myImage2->set_br(1);<br> |
3001 |
@see HAW_deck |
3002 |
@see HAW_form |
3003 |
@see HAW_row |
3004 |
*/ |
3005 |
class HAW_image |
3006 |
{ |
3007 |
var $src_wbmp; |
3008 |
var $src_html; |
3009 |
var $alt; |
3010 |
var $src_bmp; |
3011 |
var $br; |
3012 |
var $localsrc; |
3013 |
var $chtml_icon; |
3014 |
var $mml_icon; |
3015 |
var $voice_text; |
3016 |
var $voice_audio_src; |
3017 |
|
3018 |
/** |
3019 |
Constructor |
3020 |
@param src_wbmp Your bitmap in WAP-conform .wbmp format. |
3021 |
@param src_html Your bitmap in .gif, .jpg or any other HTML compatible format. |
3022 |
@param alt Alternative text for your bitmap. Will be displayed if the client can |
3023 |
display none of your graphic formats. |
3024 |
@param src_bmp (optional)<br>your bitmap in monochrome .bmp format. If the |
3025 |
browser signals in the HTTP request header, that he's only able to display |
3026 |
image/bmp and not image/vnd.wap.wbmp (e.g. the UPSim 3.2 did so), this image |
3027 |
will be sent. |
3028 |
*/ |
3029 |
function HAW_image($src_wbmp, $src_html, $alt, $src_bmp="") |
3030 |
{ |
3031 |
$this->src_wbmp = $src_wbmp; |
3032 |
$this->src_html = $src_html; |
3033 |
$this->alt = $alt; |
3034 |
$this->src_bmp = $src_bmp; |
3035 |
$this->br = 0; // default: no line break after image |
3036 |
$this->localsrc = ""; // no localsrc attribute |
3037 |
$this->chtml_icon = 0; // no cHTML icon |
3038 |
$this->mml_icon = 0; // no MML icon |
3039 |
$this->voice_text = ""; |
3040 |
$this->voice_audio_src = ""; |
3041 |
} |
3042 |
|
3043 |
/** |
3044 |
Sets the number of line breaks (CRLF) after the image. (default: 0) |
3045 |
@param br Some number of line breaks. |
3046 |
*/ |
3047 |
function set_br($br) |
3048 |
{ |
3049 |
if (!is_int($br) || ($br < 0)) |
3050 |
die("invalid argument in set_br()"); |
3051 |
|
3052 |
$this->br = $br; |
3053 |
} |
3054 |
|
3055 |
/** |
3056 |
Use localsrc attribute on WAP/HDML devices. <br> |
3057 |
Using built-in icons, mobile devices don't have to download |
3058 |
bitmap images. If the device can not render the specified icon, |
3059 |
it will download the according bitmap as specified in the HAW_image |
3060 |
constructor. |
3061 |
@param icon Device-internal representation of the image, e.g. "heart". |
3062 |
*/ |
3063 |
function use_localsrc($icon) |
3064 |
{ |
3065 |
if (!is_string($icon)) |
3066 |
die("invalid argument in use_localsrc()"); |
3067 |
|
3068 |
$this->localsrc = $icon; |
3069 |
} |
3070 |
|
3071 |
/** |
3072 |
Use cHTML icon instead of HTML bitmap on i-mode devices. <br> |
3073 |
Using built-in icons, mobile devices don't have to download |
3074 |
bitmap images. Has no effect on non-i-mode devices. |
3075 |
@param icon cHTML icon code, e.g. 63889 for the "heart" icon. |
3076 |
*/ |
3077 |
function use_chtml_icon($icon) |
3078 |
{ |
3079 |
if (!is_int($icon) || ($icon < 1)) |
3080 |
die("invalid argument in use_chtml_icon()"); |
3081 |
|
3082 |
$this->chtml_icon = $icon; |
3083 |
} |
3084 |
|
3085 |
/** |
3086 |
Use MML icon instead of HTML bitmap on MML devices. <br> |
3087 |
Using built-in icons, mobile devices don't have to download |
3088 |
bitmap images. Has no effect on non-MML devices. |
3089 |
@param icon MML icon code, e.g. "GB" for the "heart" icon. |
3090 |
*/ |
3091 |
function use_mml_icon($icon) |
3092 |
{ |
3093 |
if (!is_string($icon) || (strlen($icon) != 2)) |
3094 |
die("invalid argument in use_mml_icon()"); |
3095 |
|
3096 |
$this->mml_icon = $icon; |
3097 |
} |
3098 |
|
3099 |
/** |
3100 |
Sets text to be spoken by voice browsers. <br> |
3101 |
@param text Some text that represents the image for voice users. |
3102 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
3103 |
*/ |
3104 |
function set_voice_text($text, $audio_src="") |
3105 |
{ |
3106 |
if (!is_string($text)) |
3107 |
die("invalid argument in set_voice_text()"); |
3108 |
|
3109 |
$this->voice_text = $text; |
3110 |
$this->voice_audio_src = $audio_src; |
3111 |
} |
3112 |
|
3113 |
function get_elementtype() |
3114 |
{ |
3115 |
return HAW_IMAGE; |
3116 |
} |
3117 |
|
3118 |
function create(&$deck) |
3119 |
{ |
3120 |
if (isset($_SERVER['HTTP_ACCEPT'])) |
3121 |
$HTTP_ACCEPT = $_SERVER['HTTP_ACCEPT']; |
3122 |
else |
3123 |
$HTTP_ACCEPT = ""; |
3124 |
|
3125 |
if ($deck->ml == HAW_HDML) |
3126 |
{ |
3127 |
// HDML |
3128 |
|
3129 |
$deck->hdmlcardset->add_display_content("<" . $deck->alignment . ">\n"); |
3130 |
|
3131 |
if ($this->localsrc) |
3132 |
$icon = sprintf(" icon=\"%s\"", $this->localsrc); |
3133 |
else |
3134 |
$icon = ""; |
3135 |
|
3136 |
$content = sprintf("<img src=\"%s\" alt=\"%s\"%s>\n", |
3137 |
$this->src_bmp, |
3138 |
HAW_specchar($this->alt, $deck), $icon); |
3139 |
|
3140 |
$deck->hdmlcardset->add_display_content($content); |
3141 |
|
3142 |
// create required amount of carriage return's |
3143 |
$br = ""; |
3144 |
for ($i=0; $i < $this->br; $i++) |
3145 |
$br .= "<br>\n"; |
3146 |
|
3147 |
$deck->hdmlcardset->add_display_content($br); |
3148 |
} |
3149 |
elseif (($deck->ml == HAW_HTML) || ($deck->ml == HAW_WML)) |
3150 |
{ |
3151 |
// HTML or WML |
3152 |
|
3153 |
if ($deck->ml == HAW_HTML) |
3154 |
{ |
3155 |
// HTML |
3156 |
|
3157 |
if ($deck->iModestyle && $this->chtml_icon) |
3158 |
{ |
3159 |
// cHTML icon available ==> use this icon instead of bitmap |
3160 |
printf("&#%d;", $this->chtml_icon); |
3161 |
} |
3162 |
elseif ($deck->MMLstyle && $this->mml_icon) |
3163 |
{ |
3164 |
// MML icon available ==> use this icon instead of bitmap |
3165 |
echo CHR(27) . "$" . $this->mml_icon . CHR(15); |
3166 |
} |
3167 |
else |
3168 |
{ |
3169 |
// use HTML bitmap |
3170 |
|
3171 |
printf("<img src=\"%s\" alt=\"%s\" />\n", |
3172 |
$this->src_html, HAW_specchar($this->alt, $deck)); |
3173 |
} |
3174 |
|
3175 |
// evaluate HTML break instruction |
3176 |
if ($deck->MMLstyle) |
3177 |
$br_command = "<br>\n"; // MML has problems with clear attribute |
3178 |
elseif ($deck->xhtml) |
3179 |
$br_command = "<br style=\"clear:both;\" />\n"; // XHTML does not know clear attribute |
3180 |
else |
3181 |
$br_command = "<br clear=\"all\" />\n"; |
3182 |
} |
3183 |
else |
3184 |
{ |
3185 |
// WML |
3186 |
|
3187 |
if ($this->localsrc) |
3188 |
$localsrc = sprintf(" localsrc=\"%s\"", $this->localsrc); |
3189 |
else |
3190 |
$localsrc = ""; |
3191 |
|
3192 |
if ($deck->gif_enabled && (substr(strtolower($this->src_html), -4) == ".gif")) |
3193 |
// user agent is able to display the provided GIF image |
3194 |
printf("<img src=\"%s\" alt=\"%s\"%s/>\n", $this->src_html, |
3195 |
HAW_specchar($this->alt, $deck), $localsrc); |
3196 |
|
3197 |
elseif (strstr(strtolower($HTTP_ACCEPT), "image/vnd.wap.wbmp")) |
3198 |
// user agent is able to display .wbmp image |
3199 |
printf("<img src=\"%s\" alt=\"%s\"%s/>\n", $this->src_wbmp, |
3200 |
HAW_specchar($this->alt, $deck), $localsrc); |
3201 |
|
3202 |
elseif (strstr(strtolower($HTTP_ACCEPT), "image/bmp") && $this->src_bmp) |
3203 |
// user agent is able to display .bmp and .bmp image is available |
3204 |
printf("<img src=\"%s\" alt=\"%s\"%s/>\n", $this->src_bmp, |
3205 |
HAW_specchar($this->alt, $deck), $localsrc); |
3206 |
|
3207 |
else |
3208 |
// hope that the user agent makes the best of it! |
3209 |
printf("<img src=\"%s\" alt=\"%s\"%s/>\n", $this->src_wbmp, |
3210 |
HAW_specchar($this->alt, $deck), $localsrc); |
3211 |
|
3212 |
// break instruction in WML |
3213 |
$br_command = "<br/>\n"; |
3214 |
} |
3215 |
|
3216 |
// create required amount of carriage return's |
3217 |
for ($i=0; $i < $this->br; $i++) |
3218 |
echo $br_command; |
3219 |
} |
3220 |
elseif ($deck->ml == HAW_VXML) |
3221 |
{ |
3222 |
// VoiceXML |
3223 |
|
3224 |
if ($this->voice_text || $this->voice_audio_src) |
3225 |
{ |
3226 |
// create image-related audio output for VoiceXML images |
3227 |
|
3228 |
echo "<block><prompt>"; |
3229 |
|
3230 |
HAW_voice_audio(HAW_specchar($this->voice_text, $deck), |
3231 |
$this->voice_audio_src, HAW_VOICE_PAUSE, $deck); |
3232 |
|
3233 |
echo "</prompt></block>\n"; |
3234 |
} |
3235 |
} |
3236 |
} |
3237 |
}; |
3238 |
|
3239 |
|
3240 |
|
3241 |
|
3242 |
|
3243 |
|
3244 |
/** |
3245 |
This class allows to insert tables into a HAW_deck or HAW_form object. |
3246 |
<p>Note: Not all WAP clients are able to display tables properly! HDML is not |
3247 |
supporting tables at all. For HDML users the table's content will be generated |
3248 |
column-by-column, respectively row-by-row, where each table cell will result in |
3249 |
one separate line on the display. |
3250 |
<p><b>Examples:</b><p> |
3251 |
...<br> |
3252 |
$myTable = new HAW_table();<br> |
3253 |
$row1 = new HAW_row();<br> |
3254 |
$row1->add_column($image1);<br> |
3255 |
$row1->add_column($text1);<br> |
3256 |
$myTable->add_row($row1);<br> |
3257 |
$row2 = new HAW_row();<br> |
3258 |
$row2->add_column($image2);<br> |
3259 |
$row2->add_column($text2);<br> |
3260 |
$myTable->add_row($row2);<br> |
3261 |
$myDeck->add_table($myTable);<br> |
3262 |
... |
3263 |
@see HAW_deck |
3264 |
@see HAW_form |
3265 |
@see HAW_row |
3266 |
*/ |
3267 |
class HAW_table |
3268 |
{ |
3269 |
var $row; |
3270 |
var $number_of_rows; |
3271 |
var $voice_text; |
3272 |
var $voice_audio_src; |
3273 |
|
3274 |
/** |
3275 |
Constructor |
3276 |
*/ |
3277 |
function HAW_table() |
3278 |
{ |
3279 |
$this->number_of_rows = 0; |
3280 |
$this->voice_text = ""; |
3281 |
$this->voice_audio_src = ""; |
3282 |
} |
3283 |
|
3284 |
|
3285 |
/** |
3286 |
Adds a HAW_row object to HAW_table. |
3287 |
@param row Some HAW_row object. |
3288 |
*/ |
3289 |
function add_row($row) |
3290 |
{ |
3291 |
if (!is_object($row)) |
3292 |
die("invalid argument in add_row()"); |
3293 |
|
3294 |
$this->row[$this->number_of_rows] = $row; |
3295 |
|
3296 |
$this->number_of_rows++; |
3297 |
} |
3298 |
|
3299 |
/** |
3300 |
Sets text to be spoken by voice browsers. <br> |
3301 |
Note: Tables should be avoided whenever voice users are targeted. |
3302 |
Anyway, the HAWHAW API allows to assign voice output to HAW_table objects in order |
3303 |
to say some introducing words before the table content is spoken. |
3304 |
@param text Some helpful text. |
3305 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
3306 |
*/ |
3307 |
function set_voice_text($text, $audio_src="") |
3308 |
{ |
3309 |
if (!is_string($text)) |
3310 |
die("invalid argument in set_voice_text()"); |
3311 |
|
3312 |
$this->voice_text = $text; |
3313 |
$this->voice_audio_src = $audio_src; |
3314 |
} |
3315 |
|
3316 |
function get_elementtype() |
3317 |
{ |
3318 |
return HAW_TABLE; |
3319 |
} |
3320 |
|
3321 |
function create(&$deck) |
3322 |
{ |
3323 |
// HDML does not support tables ==> skip all table tags for HDML |
3324 |
|
3325 |
if ($deck->ml == HAW_HTML) |
3326 |
{ |
3327 |
// HTML |
3328 |
if ($deck->xhtml) |
3329 |
// border attribute is not allowed in XHTML |
3330 |
echo "<table style=\"border-width:1px; border-style:solid;\">\n"; |
3331 |
else |
3332 |
printf("<table border=\"1\" align=\"%s\">\n", $deck->alignment); |
3333 |
} |
3334 |
elseif ($deck->ml == HAW_WML) |
3335 |
{ |
3336 |
// WML |
3337 |
|
3338 |
// evaluate maximum number of columns in table |
3339 |
|
3340 |
$max_columns = 0; |
3341 |
for ($i = 0; $i < $this->number_of_rows; $i++) |
3342 |
{ |
3343 |
$row = $this->row[$i]; |
3344 |
$columns = $row->get_number_of_columns(); |
3345 |
|
3346 |
if ($columns > $max_columns) |
3347 |
$max_columns = $columns; |
3348 |
} |
3349 |
|
3350 |
printf("<table columns=\"%d\">\n", $max_columns); |
3351 |
} |
3352 |
elseif ($deck->ml == HAW_VXML) |
3353 |
{ |
3354 |
if ($this->voice_text || $this->voice_audio_src) |
3355 |
{ |
3356 |
// create introducing audio output for VoiceXML table |
3357 |
|
3358 |
echo "<block><prompt>"; |
3359 |
|
3360 |
HAW_voice_audio(HAW_specchar($this->voice_text, $deck), |
3361 |
$this->voice_audio_src, HAW_VOICE_PAUSE, $deck); |
3362 |
|
3363 |
echo "</prompt></block>\n"; |
3364 |
} |
3365 |
} |
3366 |
|
3367 |
for ($i = 0; $i < $this->number_of_rows; $i++) |
3368 |
{ |
3369 |
$row = $this->row[$i]; |
3370 |
$row->create($deck); |
3371 |
} |
3372 |
|
3373 |
//terminate table |
3374 |
if ($deck->ml == HAW_HTML) |
3375 |
{ |
3376 |
// make new line in HTML |
3377 |
if ($deck->MMLstyle) |
3378 |
echo "</table><br>\n"; // MML has problems with clear attribute |
3379 |
elseif ($deck->xhtml) |
3380 |
echo "</table><br style=\"clear:both;\" />\n"; // XHTML does not know clear attribute |
3381 |
else |
3382 |
echo "</table><br clear=\"all\" />\n"; |
3383 |
} |
3384 |
elseif ($deck->ml == HAW_WML) |
3385 |
{ |
3386 |
// make new line in WML |
3387 |
echo "</table><br/>\n"; |
3388 |
} |
3389 |
} |
3390 |
}; |
3391 |
|
3392 |
|
3393 |
|
3394 |
|
3395 |
|
3396 |
|
3397 |
/** |
3398 |
This class defines the rows, a HAW_table object consists of. |
3399 |
<p><b>Examples:</b><p> |
3400 |
...<br> |
3401 |
$image1 = new HAW_image("my_image.wbmp", "my_image.gif", ":-)");<br> |
3402 |
$text1 = new HAW_text("my text");<br> |
3403 |
$row1 = new HAW_row();<br> |
3404 |
$row1->add_column($image1);<br> |
3405 |
$row1->add_column();<br> |
3406 |
$row1->add_column($text1);<br> |
3407 |
... |
3408 |
@see HAW_table |
3409 |
@see HAW_text |
3410 |
@see HAW_image |
3411 |
@see HAW_link |
3412 |
*/ |
3413 |
class HAW_row |
3414 |
{ |
3415 |
var $column; |
3416 |
var $number_of_columns; |
3417 |
|
3418 |
/** |
3419 |
Constructor |
3420 |
*/ |
3421 |
function HAW_row() |
3422 |
{ |
3423 |
$this->number_of_columns = 0; |
3424 |
} |
3425 |
|
3426 |
|
3427 |
/** |
3428 |
Adds a cell element to a HAW_row object. |
3429 |
@param cell_element (optional)<br>Can be a HAW_text object, a HAW_image object, |
3430 |
a HAW_link object or the NULL pointer (default). |
3431 |
The latter results in an empty cell element. |
3432 |
*/ |
3433 |
function add_column($cell_element=NULL) |
3434 |
{ |
3435 |
$this->column[$this->number_of_columns] = $cell_element; |
3436 |
|
3437 |
if (is_object($cell_element)) |
3438 |
{ |
3439 |
if (($cell_element->get_elementtype() != HAW_PLAINTEXT) && |
3440 |
($cell_element->get_elementtype() != HAW_IMAGE) && |
3441 |
($cell_element->get_elementtype() != HAW_LINK)) |
3442 |
die("invalid argument in add_column()"); |
3443 |
} |
3444 |
|
3445 |
$this->number_of_columns++; |
3446 |
} |
3447 |
|
3448 |
function get_number_of_columns() |
3449 |
{ |
3450 |
return $this->number_of_columns; |
3451 |
} |
3452 |
|
3453 |
function create(&$deck) |
3454 |
{ |
3455 |
// HDML and VXML do not support tables ==> skip all table tags for HDML and VXML |
3456 |
|
3457 |
if (($deck->ml != HAW_HDML) && ($deck->ml != HAW_VXML)) |
3458 |
echo "<tr>\n"; // start of row |
3459 |
|
3460 |
for ($i = 0; $i < $this->number_of_columns; $i++) |
3461 |
{ |
3462 |
if (($deck->ml != HAW_HDML) && ($deck->ml != HAW_VXML)) |
3463 |
echo "<td>\n"; // start of column |
3464 |
|
3465 |
// call create function for each cellelement that is a HAWHAW object |
3466 |
$column = $this->column[$i]; |
3467 |
if (is_object($column)) |
3468 |
$column->create($deck); |
3469 |
|
3470 |
if (($deck->ml != HAW_HDML) && ($deck->ml != HAW_VXML)) |
3471 |
echo "</td>\n"; // end of column |
3472 |
} |
3473 |
|
3474 |
if (($deck->ml != HAW_HDML) && ($deck->ml != HAW_VXML)) |
3475 |
echo "</tr>\n"; // end of row |
3476 |
} |
3477 |
}; |
3478 |
|
3479 |
|
3480 |
|
3481 |
|
3482 |
|
3483 |
|
3484 |
/** |
3485 |
This class provides a text input field in a HAW_form object. |
3486 |
<p><b>Examples:</b><p> |
3487 |
$myInput1 = new HAW_input("cid", "", "Customer ID");<br> |
3488 |
<br> |
3489 |
$myInput2 = new HAW_input("cid", "", "Customer ID", "*N");<br> |
3490 |
$myInput2->set_size(6);<br> |
3491 |
$myInput2->set_maxlength(6);<br> |
3492 |
<br> |
3493 |
$myInput3 = new HAW_input("pw", "", "Password", "*N");<br> |
3494 |
$myInput3->set_size(8);<br> |
3495 |
$myInput3->set_maxlength(8);<br> |
3496 |
$myInput3->set_type(HAW_INPUT_PASSWORD);<br> |
3497 |
@see HAW_form |
3498 |
*/ |
3499 |
class HAW_input |
3500 |
{ |
3501 |
var $name; |
3502 |
var $value; |
3503 |
var $label; |
3504 |
var $size; |
3505 |
var $maxlength; |
3506 |
var $type; |
3507 |
var $format; |
3508 |
var $mode; |
3509 |
var $br; |
3510 |
var $voice_text; |
3511 |
var $voice_audio_src; |
3512 |
var $voice_type; |
3513 |
var $voice_grammar; |
3514 |
var $voice_help; |
3515 |
var $voice_noinput; |
3516 |
var $voice_nomatch; |
3517 |
|
3518 |
/** |
3519 |
Constructor |
3520 |
@param name Variable in which the input is sent to the destination URL. |
3521 |
@param value Initial value (string!) that will be presented in the input field. |
3522 |
@param label Describes your input field on the surfer's screen/display. |
3523 |
@param format (optional, default: "*M")<br> |
3524 |
Input format code according to the WAP standard. |
3525 |
Allows the WAP user client e.g. to input only digits and no characters. |
3526 |
*/ |
3527 |
function HAW_input($name, $value, $label, $format="*M") |
3528 |
{ |
3529 |
$this->name = $name; |
3530 |
$this->value = $value; |
3531 |
$this->label = $label; |
3532 |
$this->format = $format; |
3533 |
$this->type = HAW_INPUT_TEXT; |
3534 |
$this->mode = HAW_INPUT_ALPHABET; |
3535 |
$this->br = 1; |
3536 |
$this->voice_text = $label; |
3537 |
$this->voice_audio_src = ""; |
3538 |
$this->voice_type = "digits"; |
3539 |
$this->voice_grammar = ""; |
3540 |
$this->voice_help = array(); |
3541 |
$this->voice_noinput = array(); |
3542 |
$this->voice_nomatch = array(); |
3543 |
} |
3544 |
|
3545 |
/** |
3546 |
Set size of the input field. <br> |
3547 |
Note: Will be ignored in case of HDML/VoiceXML output. |
3548 |
@param size Number of characters fitting into the input field. |
3549 |
*/ |
3550 |
function set_size($size) |
3551 |
{ |
3552 |
$this->size = $size; |
3553 |
} |
3554 |
|
3555 |
/** |
3556 |
Set maximum of allowed characters in the input field. <br> |
3557 |
Note: Will be ignored in case of HDML output. |
3558 |
@param maxlength Maximum number of characters the user can enter. |
3559 |
*/ |
3560 |
function set_maxlength($maxlength) |
3561 |
{ |
3562 |
$this->maxlength = $maxlength; |
3563 |
} |
3564 |
|
3565 |
/** |
3566 |
Set input type |
3567 |
@param type Allowed values: HAW_INPUT_TEXT (default) or HAW_INPUT_PASSWORD. |
3568 |
*/ |
3569 |
function set_type($type) |
3570 |
{ |
3571 |
$this->type = $type; |
3572 |
} |
3573 |
|
3574 |
/** |
3575 |
Set input mode/istyle for japanese MML/i-mode devices |
3576 |
@param mode input mode<br> |
3577 |
HAW_INPUT_ALPHABET (default)<br> |
3578 |
HAW_INPUT_KATAKANA<br> |
3579 |
HAW_INPUT_HIRAGANA<br> |
3580 |
HAW_INPUT_NUMERIC |
3581 |
*/ |
3582 |
function set_mode($mode) |
3583 |
{ |
3584 |
$this->mode = $mode; |
3585 |
|
3586 |
// input mode can be mapped into a format string, used from WML and HDML |
3587 |
// ==> set format string |
3588 |
// (if a format string was provided during object initiation, this value |
3589 |
// will be overwritten) |
3590 |
|
3591 |
switch ($mode) |
3592 |
{ |
3593 |
case HAW_INPUT_HIRAGANA: { $this->format = "*M"; break; } |
3594 |
case HAW_INPUT_KATAKANA: { $this->format = "*M"; break; } |
3595 |
case HAW_INPUT_ALPHABET: { $this->format = "*m"; break; } |
3596 |
case HAW_INPUT_NUMERIC: { $this->format = "*N"; break; } |
3597 |
} |
3598 |
} |
3599 |
|
3600 |
/** |
3601 |
Sets the number of line breaks (CRLF) after input field (default: 1). <br> |
3602 |
Note: Has no effect in WML/HDML. |
3603 |
@param br Some number of line breaks. |
3604 |
*/ |
3605 |
function set_br($br) |
3606 |
{ |
3607 |
if (!is_int($br) || ($br < 0)) |
3608 |
die("invalid argument in set_br()"); |
3609 |
|
3610 |
$this->br = $br; |
3611 |
} |
3612 |
|
3613 |
/** |
3614 |
Sets text to be spoken by voice browsers. <br> |
3615 |
@param text Some alternative text that replaces <label>. |
3616 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
3617 |
*/ |
3618 |
function set_voice_text($text, $audio_src="") |
3619 |
{ |
3620 |
if (!is_string($text)) |
3621 |
die("invalid argument in set_voice_text()"); |
3622 |
|
3623 |
$this->voice_text = $text; |
3624 |
$this->voice_audio_src = $audio_src; |
3625 |
} |
3626 |
|
3627 |
/** |
3628 |
Sets the type of the input field in voice decks (default: "digits"). <br> |
3629 |
Note: Support of builtin grammar types is platform specific. |
3630 |
The W3C VoiceXML Version 2.0 recommendation defines these grammar types: |
3631 |
<ul> |
3632 |
<li>boolean</li> |
3633 |
<li>date</li> |
3634 |
<li>digits (default)</li> |
3635 |
<li>currency</li> |
3636 |
<li>number</li> |
3637 |
<li>phone</li> |
3638 |
<li>time</li> |
3639 |
</ul> |
3640 |
@param type String with grammar type. |
3641 |
*/ |
3642 |
function set_voice_type($type) |
3643 |
{ |
3644 |
if (!is_string($type)) |
3645 |
die("invalid argument in set_voice_type()"); |
3646 |
|
3647 |
$this->voice_type = $type; |
3648 |
} |
3649 |
|
3650 |
/** |
3651 |
Defines an external grammar for an input field in voice decks. <br> |
3652 |
Attention: This function should be used by experienced VoiceXML developers |
3653 |
only! Please refer to the W3C VoiceXML Recommendation for detailled info |
3654 |
about grammar definitions. |
3655 |
@param src URL specifying the location of the grammar, e.g. "http://www.foo.com/myinput.grxml". |
3656 |
@param type Media type of the grammar, e.g. "application/srgs+xml (optional)". |
3657 |
*/ |
3658 |
function set_voice_grammar($src, $type="") |
3659 |
{ |
3660 |
if (!is_string($src)) |
3661 |
die("invalid argument in set_voice_grammar()"); |
3662 |
|
3663 |
$this->voice_grammar["src"] = $src; |
3664 |
$this->voice_grammar["type"] = $type; |
3665 |
|
3666 |
$this->voice_type = ""; // external grammar overrides builtin grammar |
3667 |
} |
3668 |
|
3669 |
/** |
3670 |
Sets help text for voice browsers. <br> |
3671 |
@param text Some helpful information concerning this input. |
3672 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
3673 |
@param url Some other voice deck to go to (optional). |
3674 |
*/ |
3675 |
function set_voice_help($text, $audio_src="", $url="") |
3676 |
{ |
3677 |
if (!is_string($text)) |
3678 |
die("invalid argument in set_voice_help()"); |
3679 |
|
3680 |
$arr["text"] = $text; |
3681 |
$arr["src"] = $audio_src; |
3682 |
$arr["url"] = $url; |
3683 |
|
3684 |
$this->voice_help[] = $arr; |
3685 |
} |
3686 |
|
3687 |
/** |
3688 |
Sets noinput text for voice browsers. <br> |
3689 |
@param text Some text to inform the user that no input has been received. |
3690 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
3691 |
@param url Some other voice deck to go to (optional). |
3692 |
*/ |
3693 |
function set_voice_noinput($text, $audio_src="", $url="") |
3694 |
{ |
3695 |
if (!is_string($text)) |
3696 |
die("invalid argument in set_voice_noinput()"); |
3697 |
|
3698 |
$arr["text"] = $text; |
3699 |
$arr["src"] = $audio_src; |
3700 |
$arr["url"] = $url; |
3701 |
|
3702 |
$this->voice_noinput[] = $arr; |
3703 |
} |
3704 |
|
3705 |
/** |
3706 |
Sets nomatch text for voice browsers. <br> |
3707 |
@param text Some text to complain that user input was not recognized. |
3708 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
3709 |
@param url Some other voice deck to go to (optional). |
3710 |
*/ |
3711 |
function set_voice_nomatch($text, $audio_src="", $url="") |
3712 |
{ |
3713 |
if (!is_string($text)) |
3714 |
die("invalid argument in set_voice_nomatch()"); |
3715 |
|
3716 |
$arr["text"] = $text; |
3717 |
$arr["src"] = $audio_src; |
3718 |
$arr["url"] = $url; |
3719 |
|
3720 |
$this->voice_nomatch[] = $arr; |
3721 |
} |
3722 |
|
3723 |
function get_name() |
3724 |
{ |
3725 |
return $this->name; |
3726 |
} |
3727 |
|
3728 |
function get_value() |
3729 |
{ |
3730 |
return $this->value; |
3731 |
} |
3732 |
|
3733 |
function get_label() |
3734 |
{ |
3735 |
return $this->label; |
3736 |
} |
3737 |
|
3738 |
function get_size() |
3739 |
{ |
3740 |
return $this->size; |
3741 |
} |
3742 |
|
3743 |
function get_maxlength() |
3744 |
{ |
3745 |
return $this->maxlength; |
3746 |
} |
3747 |
|
3748 |
function get_type() |
3749 |
{ |
3750 |
return $this->type; |
3751 |
} |
3752 |
|
3753 |
function get_mode() |
3754 |
{ |
3755 |
return $this->mode; |
3756 |
} |
3757 |
|
3758 |
function get_format() |
3759 |
{ |
3760 |
return $this->format; |
3761 |
} |
3762 |
|
3763 |
function get_elementtype() |
3764 |
{ |
3765 |
return HAW_INPUT; |
3766 |
} |
3767 |
|
3768 |
function create(&$deck) |
3769 |
{ |
3770 |
if ($this->type == HAW_INPUT_PASSWORD) |
3771 |
$type = "type=\"password\""; |
3772 |
else |
3773 |
$type = "type=\"text\""; |
3774 |
|
3775 |
if ($this->size) |
3776 |
$size = sprintf("size=\"%d\"", $this->size); |
3777 |
else |
3778 |
$size = ""; |
3779 |
|
3780 |
if ($this->maxlength) |
3781 |
$maxlength = sprintf("maxlength=\"%d\"", $this->maxlength); |
3782 |
else |
3783 |
$maxlength = ""; |
3784 |
|
3785 |
if ($deck->ml == HAW_HTML) |
3786 |
{ |
3787 |
if ($deck->iModestyle) |
3788 |
$mode = sprintf(" istyle=\"%d\"", $this->mode); |
3789 |
else |
3790 |
$mode = ""; |
3791 |
|
3792 |
if ($deck->MMLstyle) |
3793 |
{ |
3794 |
switch ($this->mode) |
3795 |
{ |
3796 |
case HAW_INPUT_ALPHABET: { $mode = " mode=\"alphabet\""; break; } |
3797 |
case HAW_INPUT_KATAKANA: { $mode = " mode=\"katakana\""; break; } |
3798 |
case HAW_INPUT_HIRAGANA: { $mode = " mode=\"hiragana\""; break; } |
3799 |
case HAW_INPUT_NUMERIC: { $mode = " mode=\"numeric\""; break; } |
3800 |
default: { $mode = " mode=\"alphabet\""; break; } |
3801 |
} |
3802 |
} |
3803 |
|
3804 |
// create HTML input |
3805 |
if ($deck->xhtml || $deck->pureHTML) |
3806 |
{ |
3807 |
printf("<label for=\"%s\">%s</label>\n", |
3808 |
$this->name, HAW_specchar($this->label, $deck)); |
3809 |
printf("<input %s name=\"%s\" id=\"%s\" value=\"%s\" %s %s%s /> ", |
3810 |
$type, $this->name, |
3811 |
$this->name, $this->value, $size, $maxlength, $mode); |
3812 |
} |
3813 |
else |
3814 |
printf("%s <input %s name=\"%s\" value=\"%s\" %s %s%s /> ", |
3815 |
HAW_specchar($this->label, $deck), $type, |
3816 |
$this->name, $this->value, $size, $maxlength, $mode); |
3817 |
|
3818 |
for ($i=0; $i < $this->br; $i++) |
3819 |
echo "<br />\n"; |
3820 |
} |
3821 |
elseif ($deck->ml == HAW_WML) |
3822 |
{ |
3823 |
// create WML input |
3824 |
printf("%s<input emptyok=\"true\" format=\"%s\" %s name=\"%s\" value=\"%s\" %s %s/>\n", |
3825 |
HAW_specchar($this->label, $deck), $this->format, |
3826 |
$type, $this->name, $this->value, $size, $maxlength); |
3827 |
} |
3828 |
elseif ($deck->ml == HAW_HDML) |
3829 |
{ |
3830 |
// create HDML input |
3831 |
|
3832 |
$options = " format=\"$this->format\""; |
3833 |
$options .= " key=\"$this->name\""; |
3834 |
|
3835 |
if ($this->type == HAW_INPUT_PASSWORD) |
3836 |
$options .= " NOECHO=\"true\""; |
3837 |
|
3838 |
$display_content = "<" . $deck->alignment . ">\n"; |
3839 |
|
3840 |
$display_content .= HAW_specchar($this->label, $deck); |
3841 |
$display_content .= "\n"; |
3842 |
|
3843 |
// make user interactive entry card |
3844 |
$deck->hdmlcardset->make_ui_card($options, $display_content, HAW_HDML_ENTRY); |
3845 |
} |
3846 |
elseif ($deck->ml == HAW_VXML) |
3847 |
{ |
3848 |
// create VoiceXML input |
3849 |
|
3850 |
if ($this->voice_type) |
3851 |
{ |
3852 |
if (($this->voice_type == "digits") && $this->maxlength) |
3853 |
$type = sprintf(" type=\"digits?maxlength=%d\"", $this->maxlength); |
3854 |
else |
3855 |
$type = sprintf(" type=\"%s\"", $this->voice_type); |
3856 |
} |
3857 |
else |
3858 |
$type = ""; |
3859 |
|
3860 |
printf("<field%s name=\"%s\">\n", $type, $this->name); |
3861 |
|
3862 |
if ($this->voice_grammar) |
3863 |
{ |
3864 |
// external grammar has been defined |
3865 |
|
3866 |
if ($this->voice_grammar["type"]) |
3867 |
$grammar_type = sprintf(" type=\"%s\"", $this->voice_grammar["type"]); |
3868 |
else |
3869 |
$grammar_type = ""; // let the interpreter context determine the grammar type |
3870 |
|
3871 |
printf("<grammar src=\"%s\"%s/>\n", |
3872 |
$this->voice_grammar["src"], $grammar_type); |
3873 |
} |
3874 |
|
3875 |
if ($this->voice_text || $this->voice_audio_src) |
3876 |
{ |
3877 |
echo "<prompt>"; |
3878 |
|
3879 |
HAW_voice_audio(HAW_specchar($this->voice_text, $deck), |
3880 |
$this->voice_audio_src, 0, $deck); |
3881 |
|
3882 |
echo "</prompt>\n"; |
3883 |
} |
3884 |
|
3885 |
// create event handlers |
3886 |
HAW_voice_eventhandler("help", $this->voice_help, $deck); |
3887 |
HAW_voice_eventhandler("noinput", $this->voice_noinput, $deck); |
3888 |
HAW_voice_eventhandler("nomatch", $this->voice_nomatch, $deck); |
3889 |
|
3890 |
echo "</field>\n"; |
3891 |
} |
3892 |
} |
3893 |
}; |
3894 |
|
3895 |
|
3896 |
|
3897 |
|
3898 |
|
3899 |
|
3900 |
/** |
3901 |
This class provides a input textarea in a HAW_form object.<br> |
3902 |
Note: Creates no output for VoiceXML. Voice applications can use class |
3903 |
HAW_voicerecorder instead. |
3904 |
<p><b>Examples:</b><p> |
3905 |
$myArea1 = new HAW_textarea("fb", "", "Feedback");<br> |
3906 |
<br> |
3907 |
$myArea2 = new HAW_textarea("msg", "Enter message here ...", "Message", 40 , 5);<br> |
3908 |
$myArea2->set_br(2);<br> |
3909 |
@see HAW_form |
3910 |
@see HAW_voicerecorder |
3911 |
*/ |
3912 |
class HAW_textarea |
3913 |
{ |
3914 |
var $name; |
3915 |
var $value; |
3916 |
var $label; |
3917 |
var $rows; |
3918 |
var $cols; |
3919 |
var $mode; |
3920 |
var $br; |
3921 |
|
3922 |
/** |
3923 |
Constructor |
3924 |
@param name Variable in which the input is sent to the destination URL. |
3925 |
@param value Initial value (string!) that will be presented in the textarea. |
3926 |
@param label Describes your textarea on the surfer's screen/display. |
3927 |
@param rows Rows (optional, default: 3) |
3928 |
@param cols Columns (optional, default: 16) |
3929 |
*/ |
3930 |
function HAW_textarea($name, $value, $label, $rows=3, $cols=16) |
3931 |
{ |
3932 |
$this->name = $name; |
3933 |
$this->value = $value; |
3934 |
$this->label = $label; |
3935 |
$this->rows = $rows; |
3936 |
$this->cols = $cols; |
3937 |
$this->mode = HAW_INPUT_ALPHABET; |
3938 |
$this->br = 1; |
3939 |
} |
3940 |
|
3941 |
|
3942 |
/** |
3943 |
Set input mode/istyle for japanese MML/i-mode devices |
3944 |
@param mode input mode<br> |
3945 |
HAW_INPUT_ALPHABET (default)<br> |
3946 |
HAW_INPUT_KATAKANA<br> |
3947 |
HAW_INPUT_HIRAGANA<br> |
3948 |
HAW_INPUT_NUMERIC |
3949 |
*/ |
3950 |
function set_mode($mode) |
3951 |
{ |
3952 |
$this->mode = $mode; |
3953 |
} |
3954 |
|
3955 |
/** |
3956 |
Sets the number of line breaks (CRLF) after textarea. (default: 1)<br> |
3957 |
Note: Has no effect in WML/HDML. |
3958 |
@param br Some number of line breaks. |
3959 |
*/ |
3960 |
function set_br($br) |
3961 |
{ |
3962 |
if (!is_int($br) || ($br < 0)) |
3963 |
die("invalid argument in set_br()"); |
3964 |
|
3965 |
$this->br = $br; |
3966 |
} |
3967 |
|
3968 |
function get_name() |
3969 |
{ |
3970 |
return $this->name; |
3971 |
} |
3972 |
|
3973 |
function get_value() |
3974 |
{ |
3975 |
return $this->value; |
3976 |
} |
3977 |
|
3978 |
function get_label() |
3979 |
{ |
3980 |
return $this->label; |
3981 |
} |
3982 |
|
3983 |
function get_mode() |
3984 |
{ |
3985 |
return $this->mode; |
3986 |
} |
3987 |
|
3988 |
function get_elementtype() |
3989 |
{ |
3990 |
return HAW_TEXTAREA; |
3991 |
} |
3992 |
|
3993 |
function create(&$deck) |
3994 |
{ |
3995 |
if ($deck->ml == HAW_HTML) |
3996 |
{ |
3997 |
if ($deck->iModestyle) |
3998 |
$mode = sprintf(" istyle=\"%d\"", $this->mode); |
3999 |
|
4000 |
if ($deck->MMLstyle) |
4001 |
{ |
4002 |
switch ($this->mode) |
4003 |
{ |
4004 |
case HAW_INPUT_ALPHABET: { $mode = " mode=\"alphabet\""; break; } |
4005 |
case HAW_INPUT_KATAKANA: { $mode = " mode=\"katakana\""; break; } |
4006 |
case HAW_INPUT_HIRAGANA: { $mode = " mode=\"hiragana\""; break; } |
4007 |
case HAW_INPUT_NUMERIC: { $mode = " mode=\"numeric\""; break; } |
4008 |
default: { $mode = " mode=\"alphabet\""; break; } |
4009 |
} |
4010 |
} |
4011 |
|
4012 |
if (!$deck->iModestyle && !$deck->MMLstyle) |
4013 |
$wrap = sprintf(" wrap=\"virtual\""); |
4014 |
|
4015 |
// create HTML input |
4016 |
printf("%s<br /><textarea name=\"%s\" rows=\"%s\" cols=\"%s\"%s%s>%s</textarea> ", |
4017 |
HAW_specchar($this->label, $deck), $this->name, $this->rows, |
4018 |
$this->cols, $mode, $wrap, $this->value); |
4019 |
|
4020 |
for ($i=0; $i < $this->br; $i++) |
4021 |
echo "<br />\n"; |
4022 |
} |
4023 |
elseif ($deck->ml == HAW_WML) |
4024 |
{ |
4025 |
// create WML input |
4026 |
printf("%s<input emptyok=\"true\" name=\"%s\" value=\"%s\"/>\n", |
4027 |
HAW_specchar($this->label, $deck), |
4028 |
$this->name, $this->value); |
4029 |
} |
4030 |
elseif ($deck->ml == HAW_HDML) |
4031 |
{ |
4032 |
// create HDML input |
4033 |
|
4034 |
$options = " key=\"$this->name\""; |
4035 |
|
4036 |
$display_content = "<" . $deck->alignment . ">\n"; |
4037 |
|
4038 |
$display_content .= HAW_specchar($this->label, $deck); |
4039 |
$display_content .= "\n"; |
4040 |
|
4041 |
// make user interactive entry card |
4042 |
$deck->hdmlcardset->make_ui_card($options, $display_content, HAW_HDML_ENTRY); |
4043 |
} |
4044 |
elseif ($deck->ml == HAW_VXML) |
4045 |
{ |
4046 |
// no output for VoiceXML possible |
4047 |
} |
4048 |
} |
4049 |
}; |
4050 |
|
4051 |
|
4052 |
|
4053 |
|
4054 |
|
4055 |
|
4056 |
/** |
4057 |
This class provides a select element in a HAW_form object. |
4058 |
It allows to create optimized WML for WAP devices which |
4059 |
are capable to interprete the Openwave GUI extensions for WML 1.3. All other |
4060 |
WAP devices receive WML 1.1 compatible markup code, which is quite similar to |
4061 |
the markup code created by the HAW_radio class. |
4062 |
<p><b>Examples:</b><p> |
4063 |
$mySelect = new HAW_select("color");<br> |
4064 |
$mySelect->add_option("Blue", "b");<br> |
4065 |
$mySelect->add_option("Red", "r", HAW_SELECTED);<br> |
4066 |
$mySelect->add_option("Yellow", "y"); |
4067 |
@see HAW_form |
4068 |
*/ |
4069 |
class HAW_select |
4070 |
{ |
4071 |
var $name; |
4072 |
var $type; |
4073 |
var $value; |
4074 |
var $options; |
4075 |
var $number_of_options; |
4076 |
var $voice_text; |
4077 |
var $voice_audio_src; |
4078 |
var $voice_help; |
4079 |
var $voice_noinput; |
4080 |
var $voice_nomatch; |
4081 |
|
4082 |
|
4083 |
/** |
4084 |
Constructor |
4085 |
@param name Variable in which the information about the selected option is sent to |
4086 |
the destination URL. |
4087 |
@param type (optional)<br> |
4088 |
Type of select area:<br> |
4089 |
HAW_SELECT_POPUP: popup the whole selection list (default)<br> |
4090 |
HAW_SELECT_SPIN: rotate options on a WAP device screen<br> |
4091 |
*/ |
4092 |
function HAW_select($name, $type=HAW_SELECT_POPUP) |
4093 |
{ |
4094 |
$this->name = $name; |
4095 |
$this->type = $type; |
4096 |
$this->value = false; |
4097 |
$this->number_of_options = 0; |
4098 |
$this->voice_text = HAW_VOICE_ENUMERATE; |
4099 |
$this->voice_audio_src = ""; |
4100 |
$this->voice_help = array(); |
4101 |
$this->voice_noinput = array(); |
4102 |
$this->voice_nomatch = array(); |
4103 |
} |
4104 |
|
4105 |
/** |
4106 |
Adds one option to a HAW_select object. |
4107 |
@param label Describes the option on the surfer's screen/display. |
4108 |
@param value Value (string!) sent in the "name" variable, if this option is selected. |
4109 |
@param is_selected (optional)<br>Allowed values are HAW_SELECTED or HAW_NOTSELECTED |
4110 |
(default).<br>Note: Setting to "selected" will overwrite previous "selected" |
4111 |
options of this HAW_select object. |
4112 |
*/ |
4113 |
function add_option($label, $value, $is_selected=HAW_NOTSELECTED) |
4114 |
{ |
4115 |
if (!$label || !$value) |
4116 |
die("invalid argument in add_option()"); |
4117 |
|
4118 |
$this->options[$this->number_of_options]["label"] = $label; |
4119 |
$this->options[$this->number_of_options]["value"] = $value; |
4120 |
|
4121 |
if (!$this->value || ($is_selected == HAW_SELECTED)) |
4122 |
$this->value = $value; |
4123 |
|
4124 |
$this->number_of_options++; |
4125 |
} |
4126 |
|
4127 |
/** |
4128 |
Sets text to be spoken by voice browsers. <br> |
4129 |
@param text Some alternative text that replaces the enumeration of select options. |
4130 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
4131 |
*/ |
4132 |
function set_voice_text($text, $audio_src="") |
4133 |
{ |
4134 |
if (!is_string($text)) |
4135 |
die("invalid argument in set_voice_text()"); |
4136 |
|
4137 |
$this->voice_text = $text; |
4138 |
$this->voice_audio_src = $audio_src; |
4139 |
} |
4140 |
|
4141 |
/** |
4142 |
Sets help text for voice browsers. <br> |
4143 |
@param text Some helpful information concerning this select element. |
4144 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
4145 |
@param url Some other voice deck to go to (optional). |
4146 |
*/ |
4147 |
function set_voice_help($text, $audio_src="", $url="") |
4148 |
{ |
4149 |
if (!is_string($text)) |
4150 |
die("invalid argument in set_voice_help()"); |
4151 |
|
4152 |
$arr["text"] = $text; |
4153 |
$arr["src"] = $audio_src; |
4154 |
$arr["url"] = $url; |
4155 |
|
4156 |
$this->voice_help[] = $arr; |
4157 |
} |
4158 |
|
4159 |
/** |
4160 |
Sets noinput text for voice browsers. <br> |
4161 |
@param text Some text to inform the user that no input has been received. |
4162 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
4163 |
@param url Some other voice deck to go to (optional). |
4164 |
*/ |
4165 |
function set_voice_noinput($text, $audio_src="", $url="") |
4166 |
{ |
4167 |
if (!is_string($text)) |
4168 |
die("invalid argument in set_voice_noinput()"); |
4169 |
|
4170 |
$arr["text"] = $text; |
4171 |
$arr["src"] = $audio_src; |
4172 |
$arr["url"] = $url; |
4173 |
|
4174 |
$this->voice_noinput[] = $arr; |
4175 |
} |
4176 |
|
4177 |
/** |
4178 |
Sets nomatch text for voice browsers. <br> |
4179 |
@param text Some text to complain that user input was not recognized. |
4180 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
4181 |
@param url Some other voice deck to go to (optional). |
4182 |
*/ |
4183 |
function set_voice_nomatch($text, $audio_src="", $url="") |
4184 |
{ |
4185 |
if (!is_string($text)) |
4186 |
die("invalid argument in set_voice_nomatch()"); |
4187 |
|
4188 |
$arr["text"] = $text; |
4189 |
$arr["src"] = $audio_src; |
4190 |
$arr["url"] = $url; |
4191 |
|
4192 |
$this->voice_nomatch[] = $arr; |
4193 |
} |
4194 |
|
4195 |
function get_name() |
4196 |
{ |
4197 |
return $this->name; |
4198 |
} |
4199 |
|
4200 |
function get_value() |
4201 |
{ |
4202 |
return $this->value; |
4203 |
} |
4204 |
|
4205 |
function get_elementtype() |
4206 |
{ |
4207 |
return HAW_SELECT; |
4208 |
} |
4209 |
|
4210 |
function create(&$deck) |
4211 |
{ |
4212 |
if ($deck->ml == HAW_HTML) |
4213 |
{ |
4214 |
// create HTML select |
4215 |
|
4216 |
if ($deck->xhtml || $deck->pureHTML) |
4217 |
{ |
4218 |
// dummy label for select element (needed for Bobby approval) |
4219 |
// object to be enhanced in future versions ... |
4220 |
printf("<label for=\"%s\">%s</label>\n", $this->name, " "); |
4221 |
printf("<select name=\"%s\" id=\"%s\" size=\"1\">\n", $this->name, $this->name); |
4222 |
} |
4223 |
else |
4224 |
printf("<select name=\"%s\" size=\"1\">\n", $this->name); |
4225 |
|
4226 |
for ($i=0; $i < $this->number_of_options; $i++) |
4227 |
{ |
4228 |
if ($this->options[$i]["value"] == $this->value) |
4229 |
$state = " selected=\"selected\""; |
4230 |
else |
4231 |
$state = ""; |
4232 |
|
4233 |
echo "<option" . $state . " value=\"" . $this->options[$i]["value"] . "\">" |
4234 |
. HAW_specchar($this->options[$i]["label"], $deck) . "</option>\n"; |
4235 |
} |
4236 |
|
4237 |
echo "</select>\n"; |
4238 |
} |
4239 |
elseif ($deck->ml == HAW_WML) |
4240 |
{ |
4241 |
// create WML select |
4242 |
|
4243 |
if ($deck->owgui_1_3) |
4244 |
{ |
4245 |
// Openwave GUI extensions for WML 1.3 |
4246 |
|
4247 |
switch ($this->type) |
4248 |
{ |
4249 |
case HAW_SELECT_POPUP: { $type_option = "type=\"popup\""; break; } |
4250 |
case HAW_SELECT_SPIN: { $type_option = "type=\"spin\""; break; } |
4251 |
default: { $type_option = "type=\"popup\""; break; } |
4252 |
} |
4253 |
|
4254 |
echo "<select " . $type_option . " name=\"" . $this->name . "\">\n"; |
4255 |
} |
4256 |
else |
4257 |
// conventional WML (similar as for HAW_radio) |
4258 |
echo "<select name=\"" . $this->name . "\">\n"; |
4259 |
|
4260 |
for ($i=0; $i < $this->number_of_options; $i++) |
4261 |
{ |
4262 |
echo "<option value=\"" . $this->options[$i]["value"] . "\">" |
4263 |
. HAW_specchar($this->options[$i]["label"], $deck) . "</option>\n"; |
4264 |
} |
4265 |
|
4266 |
echo "</select>\n"; |
4267 |
} |
4268 |
elseif ($deck->ml == HAW_HDML) |
4269 |
{ |
4270 |
// create HDML select (similar as for HAW_radio) |
4271 |
|
4272 |
$options = " key=\"$this->name\""; |
4273 |
$ce_area = ""; |
4274 |
|
4275 |
while (list($key, $val) = each($this->options)) |
4276 |
{ |
4277 |
// create one <ce> statement for each option |
4278 |
$ce_area .= sprintf("<ce value=\"%s\">%s\n", |
4279 |
$val["value"], |
4280 |
HAW_specchar($val["label"], $deck)); |
4281 |
} |
4282 |
|
4283 |
// make user interactive choice card |
4284 |
$deck->hdmlcardset->make_ui_card($options, $ce_area, HAW_HDML_CHOICE); |
4285 |
} |
4286 |
elseif ($deck->ml == HAW_VXML) |
4287 |
{ |
4288 |
// create VoiceXML select |
4289 |
|
4290 |
printf("<field name=\"%s\">\n", $this->name); |
4291 |
|
4292 |
if ($this->voice_text || $this->voice_audio_src) |
4293 |
{ |
4294 |
if ($this->voice_text != HAW_VOICE_ENUMERATE) |
4295 |
{ |
4296 |
echo "<prompt>"; |
4297 |
|
4298 |
HAW_voice_audio(HAW_specchar($this->voice_text, $deck), |
4299 |
$this->voice_audio_src, 0, $deck); |
4300 |
|
4301 |
echo "</prompt>\n"; |
4302 |
} |
4303 |
} |
4304 |
|
4305 |
while (list($key, $val) = each($this->options)) |
4306 |
{ |
4307 |
if ($key < 9) |
4308 |
$dtmf = sprintf(" dtmf=\"%d\"", $key+1); |
4309 |
else |
4310 |
$dtmf = ""; |
4311 |
|
4312 |
if ($deck->supportsVXMLBreakTag) |
4313 |
$breakTag = sprintf("<break time=\"%dms\"/>", HAW_VOICE_PAUSE); |
4314 |
else |
4315 |
$breakTag = ""; |
4316 |
|
4317 |
printf("<prompt>%s%s</prompt>\n", HAW_specchar($val["label"], $deck), $breakTag); |
4318 |
|
4319 |
printf("<option%s value=\"%s\">%s</option>\n", $dtmf, $val["value"], |
4320 |
ereg_replace("[\?!]"," ",strtolower(HAW_specchar($val["label"], $deck)))); |
4321 |
} |
4322 |
|
4323 |
// create event handlers |
4324 |
HAW_voice_eventhandler("help", $this->voice_help, $deck); |
4325 |
HAW_voice_eventhandler("noinput", $this->voice_noinput, $deck); |
4326 |
HAW_voice_eventhandler("nomatch", $this->voice_nomatch, $deck); |
4327 |
|
4328 |
echo "</field>\n"; |
4329 |
} |
4330 |
} |
4331 |
}; |
4332 |
|
4333 |
|
4334 |
|
4335 |
|
4336 |
|
4337 |
|
4338 |
/** |
4339 |
This class provides a radio button element in a HAW_form object. |
4340 |
<p><b>Examples:</b><p> |
4341 |
$myRadio = new HAW_radio("country");<br> |
4342 |
$myRadio->add_button("Finland", "F");<br> |
4343 |
$myRadio->add_button("Germany", "G", HAW_CHECKED);<br> |
4344 |
$myRadio->add_button("Sweden", "S"); |
4345 |
@see HAW_form |
4346 |
*/ |
4347 |
class HAW_radio |
4348 |
{ |
4349 |
var $name; |
4350 |
var $value; |
4351 |
var $buttons; |
4352 |
var $number_of_buttons; |
4353 |
var $voice_text; |
4354 |
var $voice_audio_src; |
4355 |
var $voice_help; |
4356 |
var $voice_noinput; |
4357 |
var $voice_nomatch; |
4358 |
|
4359 |
/** |
4360 |
Constructor |
4361 |
@param name Variable in which the information about the pressed button is sent to |
4362 |
the destination URL. |
4363 |
*/ |
4364 |
function HAW_radio($name) |
4365 |
{ |
4366 |
$this->name = $name; |
4367 |
$this->value = ""; |
4368 |
$this->number_of_buttons = 0; |
4369 |
$this->voice_text = HAW_VOICE_ENUMERATE; |
4370 |
$this->voice_audio_src = ""; |
4371 |
$this->voice_help = array(); |
4372 |
$this->voice_noinput = array(); |
4373 |
$this->voice_nomatch = array(); |
4374 |
} |
4375 |
|
4376 |
/** |
4377 |
Adds one radio button to a HAW_radio object. |
4378 |
@param label Describes the radiobutton on the surfer's screen/display. |
4379 |
@param value Value (string!) sent in the "name" variable, if this button is selected. |
4380 |
@param is_checked (optional)<br>Allowed values are HAW_CHECKED or HAW_NOTCHECKED |
4381 |
(default).<br>Note: Setting to "checked" will overwrite previous "checked" |
4382 |
radiobuttons of this HAW_radio object. |
4383 |
*/ |
4384 |
function add_button($label, $value, $is_checked=HAW_NOTCHECKED) |
4385 |
{ |
4386 |
if (!$label || !$value) |
4387 |
die("invalid argument in add_button()"); |
4388 |
|
4389 |
$this->buttons[$this->number_of_buttons]["label"] = $label; |
4390 |
$this->buttons[$this->number_of_buttons]["value"] = $value; |
4391 |
|
4392 |
if (!$this->value || ($is_checked == HAW_CHECKED)) |
4393 |
$this->value = $value; |
4394 |
|
4395 |
$this->number_of_buttons++; |
4396 |
} |
4397 |
|
4398 |
/** |
4399 |
Sets text to be spoken by voice browsers. <br> |
4400 |
@param text Some alternative text that replaces the enumeration of buttons. |
4401 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
4402 |
*/ |
4403 |
function set_voice_text($text, $audio_src="") |
4404 |
{ |
4405 |
if (!is_string($text)) |
4406 |
die("invalid argument in set_voice_text()"); |
4407 |
|
4408 |
$this->voice_text = $text; |
4409 |
$this->voice_audio_src = $audio_src; |
4410 |
} |
4411 |
|
4412 |
/** |
4413 |
Sets help text for voice browsers. <br> |
4414 |
@param text Some helpful information concerning this radio button element. |
4415 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
4416 |
@param url Some other voice deck to go to (optional). |
4417 |
*/ |
4418 |
function set_voice_help($text, $audio_src="", $url="") |
4419 |
{ |
4420 |
if (!is_string($text)) |
4421 |
die("invalid argument in set_voice_help()"); |
4422 |
|
4423 |
$arr["text"] = $text; |
4424 |
$arr["src"] = $audio_src; |
4425 |
$arr["url"] = $url; |
4426 |
|
4427 |
$this->voice_help[] = $arr; |
4428 |
} |
4429 |
|
4430 |
/** |
4431 |
Sets noinput text for voice browsers. <br> |
4432 |
@param text Some text to inform the user that no input has been received. |
4433 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
4434 |
@param url Some other voice deck to go to (optional). |
4435 |
*/ |
4436 |
function set_voice_noinput($text, $audio_src="", $url="") |
4437 |
{ |
4438 |
if (!is_string($text)) |
4439 |
die("invalid argument in set_voice_noinput()"); |
4440 |
|
4441 |
$arr["text"] = $text; |
4442 |
$arr["src"] = $audio_src; |
4443 |
$arr["url"] = $url; |
4444 |
|
4445 |
$this->voice_noinput[] = $arr; |
4446 |
} |
4447 |
|
4448 |
/** |
4449 |
Sets nomatch text for voice browsers. <br> |
4450 |
@param text Some text to complain that user input was not recognized. |
4451 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
4452 |
@param url Some other voice deck to go to (optional). |
4453 |
*/ |
4454 |
function set_voice_nomatch($text, $audio_src="", $url="") |
4455 |
{ |
4456 |
if (!is_string($text)) |
4457 |
die("invalid argument in set_voice_nomatch()"); |
4458 |
|
4459 |
$arr["text"] = $text; |
4460 |
$arr["src"] = $audio_src; |
4461 |
$arr["url"] = $url; |
4462 |
|
4463 |
$this->voice_nomatch[] = $arr; |
4464 |
} |
4465 |
|
4466 |
function get_name() |
4467 |
{ |
4468 |
return $this->name; |
4469 |
} |
4470 |
|
4471 |
function get_value() |
4472 |
{ |
4473 |
return $this->value; |
4474 |
} |
4475 |
|
4476 |
function get_elementtype() |
4477 |
{ |
4478 |
return HAW_RADIO; |
4479 |
} |
4480 |
|
4481 |
function create(&$deck) |
4482 |
{ |
4483 |
if ($deck->ml == HAW_HTML) |
4484 |
{ |
4485 |
// create HTML radio |
4486 |
|
4487 |
while (list($key, $val) = each($this->buttons)) |
4488 |
{ |
4489 |
if ($val["value"] == $this->value) |
4490 |
$state = "checked=\"checked\""; |
4491 |
else |
4492 |
$state = ""; |
4493 |
|
4494 |
if ($deck->xhtml || $deck->pureHTML) |
4495 |
{ |
4496 |
printf("<input type=\"radio\" name=\"%s\" id=\"%s\" %s value=\"%s\" />", |
4497 |
$this->name, $this->name . $key, $state, $val["value"]); |
4498 |
|
4499 |
printf(" <label for=\"%s\">%s</label><br />\n", |
4500 |
$this->name . $key, HAW_specchar($val["label"], $deck)); |
4501 |
} |
4502 |
else |
4503 |
printf("<input type=\"radio\" name=\"%s\" %s value=\"%s\" /> %s<br />\n", |
4504 |
$this->name, $state, $val["value"], |
4505 |
HAW_specchar($val["label"], $deck)); |
4506 |
} |
4507 |
} |
4508 |
elseif ($deck->ml == HAW_WML) |
4509 |
{ |
4510 |
// create WML radio |
4511 |
|
4512 |
if ($deck->owgui_1_3) |
4513 |
// Openwave GUI extensions for WML 1.3 |
4514 |
printf("<select type=\"radio\" name=\"%s\">\n", $this->name); |
4515 |
else |
4516 |
// conventional WML (similar as for HAW_select) |
4517 |
printf("<select name=\"%s\">\n", $this->name); |
4518 |
|
4519 |
while (list($key, $val) = each($this->buttons)) |
4520 |
{ |
4521 |
printf("<option value=\"%s\">%s</option>\n", |
4522 |
$val["value"], HAW_specchar($val["label"], $deck)); |
4523 |
} |
4524 |
|
4525 |
echo "</select>\n"; |
4526 |
} |
4527 |
elseif ($deck->ml == HAW_HDML) |
4528 |
{ |
4529 |
// create HDML radio (similar as for HAW_select) |
4530 |
|
4531 |
$options = " key=\"$this->name\""; |
4532 |
$ce_area = ""; |
4533 |
|
4534 |
while (list($key, $val) = each($this->buttons)) |
4535 |
{ |
4536 |
// create one <ce> statement for each button |
4537 |
$ce_area .= sprintf("<ce value=\"%s\">%s\n", |
4538 |
$val["value"], |
4539 |
HAW_specchar($val["label"], $deck)); |
4540 |
} |
4541 |
|
4542 |
// make user interactive choice card |
4543 |
$deck->hdmlcardset->make_ui_card($options, $ce_area, HAW_HDML_CHOICE); |
4544 |
} |
4545 |
elseif ($deck->ml == HAW_VXML) |
4546 |
{ |
4547 |
// create VoiceXML radio |
4548 |
|
4549 |
printf("<field name=\"%s\">\n", $this->name); |
4550 |
|
4551 |
if ($this->voice_text || $this->voice_audio_src) |
4552 |
{ |
4553 |
if ($this->voice_text != HAW_VOICE_ENUMERATE) |
4554 |
{ |
4555 |
echo "<prompt>"; |
4556 |
|
4557 |
HAW_voice_audio(HAW_specchar($this->voice_text, $deck), |
4558 |
$this->voice_audio_src, 0, $deck); |
4559 |
|
4560 |
echo "</prompt>\n"; |
4561 |
} |
4562 |
} |
4563 |
|
4564 |
while (list($key, $val) = each($this->buttons)) |
4565 |
{ |
4566 |
if ($key < 9) |
4567 |
$dtmf = sprintf(" dtmf=\"%d\"", $key+1); |
4568 |
else |
4569 |
$dtmf = ""; |
4570 |
|
4571 |
if ($deck->supportsVXMLBreakTag) |
4572 |
$breakTag = sprintf("<break time=\"%dms\"/>", HAW_VOICE_PAUSE); |
4573 |
else |
4574 |
$breakTag = ""; |
4575 |
|
4576 |
printf("<prompt>%s%s</prompt>\n", HAW_specchar($val["label"], $deck), $breakTag); |
4577 |
|
4578 |
printf("<option%s value=\"%s\">%s</option>\n", $dtmf, $val["value"], |
4579 |
ereg_replace("[\?!]"," ",strtolower(HAW_specchar($val["label"], $deck)))); |
4580 |
} |
4581 |
|
4582 |
// create event handlers |
4583 |
HAW_voice_eventhandler("help", $this->voice_help, $deck); |
4584 |
HAW_voice_eventhandler("noinput", $this->voice_noinput, $deck); |
4585 |
HAW_voice_eventhandler("nomatch", $this->voice_nomatch, $deck); |
4586 |
|
4587 |
echo "</field>\n"; |
4588 |
} |
4589 |
} |
4590 |
}; |
4591 |
|
4592 |
|
4593 |
|
4594 |
|
4595 |
|
4596 |
|
4597 |
/** |
4598 |
This class provides a single checkbox element in a HAW_form object. |
4599 |
<p><b>Examples:</b><p> |
4600 |
$myCheckbox = new HAW_checkbox("agmt", "yes", "I agree");<br> |
4601 |
$myCheckbox = new HAW_checkbox("agmt", "yes", "I agree", HAW_NOTCHECKED);<br> |
4602 |
$myCheckbox = new HAW_checkbox("agmt", "yes", "I agree", HAW_CHECKED);<br> |
4603 |
<br> |
4604 |
Note: The first and the second example are identical. |
4605 |
@see HAW_form |
4606 |
*/ |
4607 |
class HAW_checkbox |
4608 |
{ |
4609 |
var $name; |
4610 |
var $value; |
4611 |
var $state; |
4612 |
var $voice_text; |
4613 |
var $voice_audio_src; |
4614 |
var $voice_help; |
4615 |
var $voice_noinput; |
4616 |
var $voice_nomatch; |
4617 |
|
4618 |
/** |
4619 |
Constructor |
4620 |
@param name Variable in which "value" is sent to the destination URL, in case that |
4621 |
the box is checked. |
4622 |
@param value See name. |
4623 |
@param label Describes the checkbox on the surfer's screen/display. |
4624 |
@param state (optional)<br>Allowed values are HAW_CHECKED or HAW_NOTCHECKED |
4625 |
(default). |
4626 |
*/ |
4627 |
function HAW_checkbox($name, $value, $label, $state=HAW_NOTCHECKED) |
4628 |
{ |
4629 |
$this->name = $name; |
4630 |
$this->value = $value; |
4631 |
$this->label = $label; |
4632 |
$this->state = $state; |
4633 |
$this->voice_text = $label; |
4634 |
$this->voice_audio_src = ""; |
4635 |
$this->voice_help = array(); |
4636 |
$this->voice_noinput = array(); |
4637 |
$this->voice_nomatch = array(); |
4638 |
} |
4639 |
|
4640 |
/** |
4641 |
Sets text to be spoken by voice browsers. <br> |
4642 |
@param text Some alternative text that replaces <label>. |
4643 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
4644 |
*/ |
4645 |
function set_voice_text($text, $audio_src="") |
4646 |
{ |
4647 |
if (!is_string($text)) |
4648 |
die("invalid argument in set_voice_text()"); |
4649 |
|
4650 |
$this->voice_text = $text; |
4651 |
$this->voice_audio_src = $audio_src; |
4652 |
} |
4653 |
|
4654 |
/** |
4655 |
Sets help text for voice browsers. <br> |
4656 |
@param text Some helpful information concerning this checkbox. |
4657 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
4658 |
@param url Some other voice deck to go to (optional). |
4659 |
*/ |
4660 |
function set_voice_help($text, $audio_src="", $url="") |
4661 |
{ |
4662 |
if (!is_string($text)) |
4663 |
die("invalid argument in set_voice_help()"); |
4664 |
|
4665 |
$arr["text"] = $text; |
4666 |
$arr["src"] = $audio_src; |
4667 |
$arr["url"] = $url; |
4668 |
|
4669 |
$this->voice_help[] = $arr; |
4670 |
} |
4671 |
|
4672 |
/** |
4673 |
Sets noinput text for voice browsers. <br> |
4674 |
@param text Some text to inform the user that no input has been received. |
4675 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
4676 |
@param url Some other voice deck to go to (optional). |
4677 |
*/ |
4678 |
function set_voice_noinput($text, $audio_src="", $url="") |
4679 |
{ |
4680 |
if (!is_string($text)) |
4681 |
die("invalid argument in set_voice_noinput()"); |
4682 |
|
4683 |
$arr["text"] = $text; |
4684 |
$arr["src"] = $audio_src; |
4685 |
$arr["url"] = $url; |
4686 |
|
4687 |
$this->voice_noinput[] = $arr; |
4688 |
} |
4689 |
|
4690 |
/** |
4691 |
Sets nomatch text for voice browsers. <br> |
4692 |
@param text Some text to complain that user input (typically "yes" or "no") was not recognized. |
4693 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
4694 |
@param url Some other voice deck to go to (optional). |
4695 |
*/ |
4696 |
function set_voice_nomatch($text, $audio_src="", $url="") |
4697 |
{ |
4698 |
if (!is_string($text)) |
4699 |
die("invalid argument in set_voice_nomatch()"); |
4700 |
|
4701 |
$arr["text"] = $text; |
4702 |
$arr["src"] = $audio_src; |
4703 |
$arr["url"] = $url; |
4704 |
|
4705 |
$this->voice_nomatch[] = $arr; |
4706 |
} |
4707 |
|
4708 |
function is_checked() |
4709 |
{ |
4710 |
return $this->state; |
4711 |
} |
4712 |
|
4713 |
function get_name() |
4714 |
{ |
4715 |
return $this->name; |
4716 |
} |
4717 |
|
4718 |
function get_value() |
4719 |
{ |
4720 |
return $this->value; |
4721 |
} |
4722 |
|
4723 |
function get_label() |
4724 |
{ |
4725 |
return $this->label; |
4726 |
} |
4727 |
|
4728 |
function get_elementtype() |
4729 |
{ |
4730 |
return HAW_CHECKBOX; |
4731 |
} |
4732 |
|
4733 |
function create(&$deck) |
4734 |
{ |
4735 |
if ($deck->ml == HAW_HTML) |
4736 |
{ |
4737 |
// create HTML checkbox |
4738 |
|
4739 |
$state = ($this->is_checked() ? "checked=\"checked\"" : ""); |
4740 |
|
4741 |
if ($deck->xhtml || $deck->pureHTML) |
4742 |
{ |
4743 |
printf("<input type=\"checkbox\" name=\"%s\" id=\"%s\" %s value=\"%s\" />", |
4744 |
$this->name, $this->name, $state, $this->value); |
4745 |
|
4746 |
printf(" <label for=\"%s\">%s</label><br />\n", |
4747 |
$this->name, HAW_specchar($this->label, $deck)); |
4748 |
} |
4749 |
else |
4750 |
printf("<input type=\"checkbox\" name=\"%s\" %s value=\"%s\" /> %s<br />\n", |
4751 |
$this->name, $state, $this->value, |
4752 |
HAW_specchar($this->label, $deck)); |
4753 |
} |
4754 |
elseif ($deck->ml == HAW_WML) |
4755 |
{ |
4756 |
// create WML checkbox |
4757 |
printf("<select name=\"%s\" multiple=\"true\">\n", $this->name); |
4758 |
printf("<option value=\"%s\">%s</option>\n", |
4759 |
$this->value, HAW_specchar($this->label, $deck)); |
4760 |
printf("</select>\n"); |
4761 |
} |
4762 |
elseif ($deck->ml == HAW_HDML) |
4763 |
{ |
4764 |
// create HDML checkbox |
4765 |
// HDML does not support the multiple option feature! |
4766 |
// ==> trick: simulate checkbox by creating radio buttons [x] and [ ] |
4767 |
|
4768 |
$options = " key=\"$this->name\""; |
4769 |
|
4770 |
// create label above the radio buttons |
4771 |
$cb = sprintf("%s\n", HAW_specchar($this->label, $deck)); |
4772 |
|
4773 |
// create "checked" radio button |
4774 |
$cb .= sprintf("<ce value=\"%s\">[x]\n", $this->value); |
4775 |
|
4776 |
// create "not checked" radio button |
4777 |
$cb .= "<ce value=\"\">[ ]\n"; |
4778 |
|
4779 |
// make user interactive choice card |
4780 |
$deck->hdmlcardset->make_ui_card($options, $cb, HAW_HDML_CHOICE); |
4781 |
} |
4782 |
elseif ($deck->ml == HAW_VXML) |
4783 |
{ |
4784 |
// create VoiceXML checkbox (field with boolean grammar type) |
4785 |
|
4786 |
printf("<field type=\"boolean\" name=\"%s\">\n", $this->name); |
4787 |
|
4788 |
if ($this->voice_text || $this->voice_audio_src) |
4789 |
{ |
4790 |
echo "<prompt>"; |
4791 |
|
4792 |
HAW_voice_audio(HAW_specchar($this->voice_text, $deck), |
4793 |
$this->voice_audio_src, 0, $deck); |
4794 |
|
4795 |
echo "</prompt>\n"; |
4796 |
} |
4797 |
|
4798 |
printf("<filled><if cond=\"%s\"><assign name=\"%s\" expr=\"'%s'\"/><else/><assign name=\"%s\" expr=\"''\"/></if></filled>\n", |
4799 |
$this->name, $this->name, $this->value, $this->name); |
4800 |
|
4801 |
// create event handlers |
4802 |
HAW_voice_eventhandler("help", $this->voice_help, $deck); |
4803 |
HAW_voice_eventhandler("noinput", $this->voice_noinput, $deck); |
4804 |
HAW_voice_eventhandler("nomatch", $this->voice_nomatch, $deck); |
4805 |
|
4806 |
echo "</field>\n"; |
4807 |
} |
4808 |
} |
4809 |
}; |
4810 |
|
4811 |
|
4812 |
|
4813 |
|
4814 |
|
4815 |
|
4816 |
/** |
4817 |
This class provides a "hidden" element in a HAW_form object. |
4818 |
<p><b>Examples:</b><p> |
4819 |
$myHiddenElement = new HAW_hidden("internal_reference", "08154711"); |
4820 |
@see HAW_form |
4821 |
*/ |
4822 |
class HAW_hidden |
4823 |
{ |
4824 |
var $name; |
4825 |
var $value; |
4826 |
|
4827 |
/** |
4828 |
Constructor |
4829 |
@param name Variable in which "value" sent to the destination URL. |
4830 |
@param value See name. |
4831 |
*/ |
4832 |
function HAW_hidden($name, $value) |
4833 |
{ |
4834 |
$this->name = $name; |
4835 |
$this->value = $value; |
4836 |
} |
4837 |
|
4838 |
function get_name() |
4839 |
{ |
4840 |
return $this->name; |
4841 |
} |
4842 |
|
4843 |
function get_value() |
4844 |
{ |
4845 |
return $this->value; |
4846 |
} |
4847 |
|
4848 |
function get_elementtype() |
4849 |
{ |
4850 |
return HAW_HIDDEN; |
4851 |
} |
4852 |
|
4853 |
function create(&$deck) |
4854 |
{ |
4855 |
if ($deck->ml == HAW_HTML) |
4856 |
{ |
4857 |
// create hidden HTML field |
4858 |
|
4859 |
printf("<input type=\"hidden\" name=\"%s\" value=\"%s\" />\n", |
4860 |
$this->name, HAW_specchar($this->value, $deck)); |
4861 |
} |
4862 |
elseif ($deck->ml == HAW_VXML) |
4863 |
{ |
4864 |
// create hidden field in VoiceXML |
4865 |
|
4866 |
printf("<field name=\"%s\" expr=\"'%s'\"/>\n", |
4867 |
$this->name, HAW_specchar($this->value, $deck)); |
4868 |
} |
4869 |
|
4870 |
// not necessary in WML and HDML! |
4871 |
} |
4872 |
}; |
4873 |
|
4874 |
|
4875 |
|
4876 |
|
4877 |
|
4878 |
|
4879 |
/** |
4880 |
This class provides a submit button in a HAW_form object. |
4881 |
One HAW_form object can contain only one HAW_submit object. |
4882 |
<p><b>Examples:</b><p> |
4883 |
$mySubmit = new HAW_submit("Submit");<br> |
4884 |
$mySubmit = new HAW_submit("Submit", "user_pressed"); |
4885 |
@see HAW_form |
4886 |
*/ |
4887 |
class HAW_submit |
4888 |
{ |
4889 |
var $label; |
4890 |
var $name; |
4891 |
|
4892 |
/** |
4893 |
Constructor |
4894 |
@param label What's written on the button. |
4895 |
@param name (optional)<br> |
4896 |
Variable in which "label" is sent to the destination URL. |
4897 |
*/ |
4898 |
function HAW_submit($label, $name="") |
4899 |
{ |
4900 |
$this->label = $label; |
4901 |
$this->name = $name; |
4902 |
} |
4903 |
|
4904 |
function get_name() |
4905 |
{ |
4906 |
return $this->name; |
4907 |
} |
4908 |
|
4909 |
function get_label() |
4910 |
{ |
4911 |
return $this->label; |
4912 |
} |
4913 |
|
4914 |
function get_elementtype() |
4915 |
{ |
4916 |
return HAW_SUBMIT; |
4917 |
} |
4918 |
|
4919 |
function create(&$deck, $getvar, $url) |
4920 |
{ |
4921 |
if ($deck->ml == HAW_HTML) |
4922 |
{ |
4923 |
// create submit button in HTML |
4924 |
|
4925 |
$name = ($this->name ? "name=\"" . "$this->name" ."\"" : ""); |
4926 |
|
4927 |
printf("<input type=\"submit\" %s value=\"%s\" /><br />\n", $name, |
4928 |
HAW_specchar($this->label, $deck)); |
4929 |
|
4930 |
} |
4931 |
elseif (($deck->ml == HAW_WML) || ($deck->ml == HAW_HDML)) |
4932 |
{ |
4933 |
// determine querystring for both WML and HDML |
4934 |
|
4935 |
$query_string = ""; |
4936 |
|
4937 |
if ($getvar) // safety check for "empty" forms |
4938 |
{ |
4939 |
while (list($key, $val) = each($getvar)) |
4940 |
$query_string .= $val . "=$(" . $val . ")&"; |
4941 |
} |
4942 |
|
4943 |
if ($this->name != "") |
4944 |
$query_string .= $this->name . "=" . urlencode($this->label); |
4945 |
|
4946 |
if (substr($query_string, -5) == "&") |
4947 |
$query_string = substr($query_string, 0, strlen($query_string)-5); |
4948 |
|
4949 |
// replace '&' character in URL with '&' |
4950 |
$url = ereg_replace("&", "&", $url); |
4951 |
|
4952 |
if ($deck->ml == HAW_WML) |
4953 |
{ |
4954 |
if ($deck->submitViaLink) |
4955 |
{ |
4956 |
// special handling for devices which have problems with <do> construct |
4957 |
|
4958 |
printf("<anchor>%s\n", HAW_specchar($this->label, $deck)); |
4959 |
|
4960 |
if (strchr($url,"?")) |
4961 |
printf("<go href=\"%s&%s\"/>\n", $url, $query_string); |
4962 |
else |
4963 |
printf("<go href=\"%s?%s\"/>\n", $url, $query_string); |
4964 |
|
4965 |
echo "</anchor><br/>\n"; |
4966 |
} |
4967 |
else |
4968 |
{ |
4969 |
// normal WML style |
4970 |
|
4971 |
if ($deck->owgui_1_3) |
4972 |
// create <do type="button"> sequence for Openwave GUI extensions WML 1.3 |
4973 |
printf("<do type=\"button\" label=\"%s\">\n", |
4974 |
HAW_specchar($this->label, $deck)); |
4975 |
else |
4976 |
// create <do type="accept"> sequence in normal WML |
4977 |
printf("<do type=\"accept\" label=\"%s\">\n", |
4978 |
HAW_specchar($this->label, $deck)); |
4979 |
|
4980 |
if (strchr($url,"?")) |
4981 |
printf("<go href=\"%s&%s\">\n", $url, $query_string); |
4982 |
else |
4983 |
printf("<go href=\"%s?%s\">\n", $url, $query_string); |
4984 |
|
4985 |
echo "</go>\n"; |
4986 |
echo "</do>\n"; |
4987 |
} |
4988 |
} |
4989 |
elseif ($deck->ml == HAW_HDML) |
4990 |
{ |
4991 |
// store info for final card in HDML card set |
4992 |
|
4993 |
if (strchr($url,"?")) |
4994 |
$action = sprintf("<action type=\"accept\" label=\"%s\" task=\"go\" dest=\"%s&%s\">\n", |
4995 |
HAW_specchar($this->label, $deck), |
4996 |
$url, $query_string); |
4997 |
else |
4998 |
$action = sprintf("<action type=\"accept\" label=\"%s\" task=\"go\" dest=\"%s?%s\">\n", |
4999 |
HAW_specchar($this->label, $deck), |
5000 |
$url, $query_string); |
5001 |
|
5002 |
$deck->hdmlcardset->set_final_action($action); |
5003 |
} |
5004 |
} |
5005 |
elseif ($deck->ml == HAW_VXML) |
5006 |
{ |
5007 |
// determine filled tag for VoiceXML |
5008 |
|
5009 |
$namelist = " namelist=\""; // init namelist attribute |
5010 |
|
5011 |
if ($getvar) // safety check for "empty" forms |
5012 |
{ |
5013 |
// created namelist attribute with form fields |
5014 |
|
5015 |
while (list($key, $val) = each($getvar)) |
5016 |
$namelist .= $val . " "; |
5017 |
} |
5018 |
|
5019 |
if ($this->name != "") |
5020 |
{ |
5021 |
// create special field for submit info |
5022 |
printf("<field name=\"%s\" expr=\"'%s'\"/>\n", |
5023 |
$this->name, HAW_specchar($this->label, $deck)); |
5024 |
|
5025 |
// add submit field to namelist |
5026 |
$namelist .= $this->name . " "; |
5027 |
} |
5028 |
|
5029 |
// remove last blank character in namelist |
5030 |
if (substr($namelist, -1) == " ") |
5031 |
$namelist = substr($namelist, 0, strlen($namelist)-1); |
5032 |
|
5033 |
// complete namelist attribute |
5034 |
$namelist .= "\""; |
5035 |
|
5036 |
// replace '&' character in URL with '&' |
5037 |
$url = ereg_replace("&", "&", $url); |
5038 |
|
5039 |
printf("<filled><submit next=\"%s\"%s method=\"get\"/></filled>\n", |
5040 |
$url, $namelist); |
5041 |
} |
5042 |
} |
5043 |
}; |
5044 |
|
5045 |
|
5046 |
|
5047 |
|
5048 |
|
5049 |
|
5050 |
/** |
5051 |
This class provides a link in a HAW_deck, HAW_linkset or HAW_table object. |
5052 |
<p><b>Examples:</b><p> |
5053 |
$myPage = new HAW_deck(...);<br> |
5054 |
...<br> |
5055 |
$myLink = new HAW_link("Continue","/mynextpage.php");<br> |
5056 |
$myPage->add_link($myLink); |
5057 |
@see HAW_deck |
5058 |
@see HAW_linkset |
5059 |
@see HAW_table |
5060 |
*/ |
5061 |
class HAW_link |
5062 |
{ |
5063 |
var $label; |
5064 |
var $url; |
5065 |
var $title; |
5066 |
var $accesskey; // "1", "2", ... "0", "*", "#" |
5067 |
var $br; |
5068 |
var $voice_text; |
5069 |
var $voice_audio_src; |
5070 |
var $voice_timeout; |
5071 |
|
5072 |
/** |
5073 |
Constructor |
5074 |
@param label Describes the link on the surfer's screen/display. |
5075 |
@param url Next destination address. |
5076 |
@param title (optional)<br>If a string is provided here, it will be displayed |
5077 |
in the HTML browser status bar during "MouseOver", respectively somewhere |
5078 |
on the WAP/XHTML display. In order to work well with a broad range of user agents, |
5079 |
keep your title under 6 characters. |
5080 |
*/ |
5081 |
function HAW_link($label, $url, $title="") |
5082 |
{ |
5083 |
$this->label = $label; |
5084 |
$this->url = $url; |
5085 |
$this->title = $title; |
5086 |
$this->accesskey = HAW_NO_ACCESSKEY; // no accesskey assigned |
5087 |
// can be assigned later e.g. from HAW_linkset object if required |
5088 |
$this->br = 1; // default: 1 line break after text |
5089 |
$this->voice_text = $label; |
5090 |
$this->voice_audio_src = ""; |
5091 |
$this->voice_timeout = 10; // voice decks with text and links only terminate after 10 sec |
5092 |
} |
5093 |
|
5094 |
/** |
5095 |
Sets the number of line breaks (CRLF) after link. (default: 1) |
5096 |
@param br Some number of line breaks. |
5097 |
*/ |
5098 |
function set_br($br) |
5099 |
{ |
5100 |
if (!is_int($br) || ($br < 0)) |
5101 |
die("invalid argument in set_br()"); |
5102 |
|
5103 |
$this->br = $br; |
5104 |
} |
5105 |
|
5106 |
/** |
5107 |
Sets link text to be spoken by voice browsers. <br> |
5108 |
@param text Some alternative text that replaces <label>. |
5109 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
5110 |
*/ |
5111 |
function set_voice_text($text, $audio_src="") |
5112 |
{ |
5113 |
if (!is_string($text)) |
5114 |
die("invalid argument in set_voice_text()"); |
5115 |
|
5116 |
$this->voice_text = $text; |
5117 |
$this->voice_audio_src = $audio_src; |
5118 |
} |
5119 |
|
5120 |
/** |
5121 |
Sets the link timeout for voice browsers (default: 10 sec). <br> |
5122 |
Note: Voice decks with text only will force a disconnect immediately after the |
5123 |
complete text has been spoken. |
5124 |
Voice decks with text and links will wait some time for user voice input and will |
5125 |
initiate the disconnect too, if no user input is received. |
5126 |
For each link it is possible to specify an individual timeout value, i.e. a voice |
5127 |
deck does not disconnect before the longest timeout of all active links expires. |
5128 |
@param timeout Timeout in seconds. |
5129 |
*/ |
5130 |
function set_voice_timeout($timeout) |
5131 |
{ |
5132 |
if (!is_int($timeout) || ($timeout < 1)) |
5133 |
die("invalid argument in set_voice_timeout()"); |
5134 |
|
5135 |
$this->voice_timeout = $timeout; |
5136 |
} |
5137 |
|
5138 |
/** |
5139 |
Sets a DTMF key as link trigger for voice browsers. |
5140 |
@param key "1", "2", ..., "9", "0", "*", "#" |
5141 |
*/ |
5142 |
function set_voice_dtmf($key) |
5143 |
{ |
5144 |
if (!ereg("[0-9#\*]", $key)) |
5145 |
die("invalid argument in set_voice_dtmf()"); |
5146 |
|
5147 |
$this->set_accesskey($key); |
5148 |
} |
5149 |
|
5150 |
function get_url() |
5151 |
{ |
5152 |
return $this->url; |
5153 |
} |
5154 |
|
5155 |
function get_label() |
5156 |
{ |
5157 |
return $this->label; |
5158 |
} |
5159 |
|
5160 |
function get_title() |
5161 |
{ |
5162 |
return $this->title; |
5163 |
} |
5164 |
|
5165 |
function get_accesskey() |
5166 |
{ |
5167 |
return $this->accesskey; |
5168 |
} |
5169 |
|
5170 |
function get_elementtype() |
5171 |
{ |
5172 |
return HAW_LINK; |
5173 |
} |
5174 |
|
5175 |
function set_accesskey($accesskey) |
5176 |
{ |
5177 |
$this->accesskey = $accesskey; |
5178 |
} |
5179 |
|
5180 |
function create(&$deck) |
5181 |
{ |
5182 |
// add hawoutput query parameter to url, if required |
5183 |
HAW_handle_forced_output($this->url, $deck->hawoutput); |
5184 |
|
5185 |
if ($this->url) |
5186 |
{ |
5187 |
// inhibit "empty" links |
5188 |
|
5189 |
if ($deck->ml == HAW_HTML) |
5190 |
{ |
5191 |
// create link in HTML |
5192 |
|
5193 |
$title_option = ""; |
5194 |
|
5195 |
if ($this->title && $deck->pureHTML) |
5196 |
$title_option = sprintf(" onmouseover=\"self.status='%s';return true;\"", |
5197 |
HAW_specchar($this->title, $deck)); |
5198 |
|
5199 |
if ($this->title && ($deck->xhtml || $deck->lynx)) |
5200 |
$title_option = sprintf(" title=\"%s\"", HAW_specchar($this->title, $deck)); |
5201 |
|
5202 |
$accesskey_option = ""; |
5203 |
|
5204 |
if (($this->accesskey != HAW_NO_ACCESSKEY) && |
5205 |
($deck->iModestyle || $deck->xhtml)) |
5206 |
$accesskey_option = sprintf(" accesskey=\"%s\"", $this->accesskey); |
5207 |
|
5208 |
if ($deck->MMLstyle && ($this->accesskey != HAW_NO_ACCESSKEY)) |
5209 |
$accesskey_option = sprintf(" directkey=\"%s\"", $this->accesskey); |
5210 |
|
5211 |
// create required amount of carriage return's |
5212 |
$br = ""; |
5213 |
for ($i=0; $i < $this->br; $i++) |
5214 |
$br .= "<br />"; |
5215 |
|
5216 |
printf("<a href=\"%s\"%s%s>%s</a>%s\n", |
5217 |
HAW_specchar($this->url, $deck), $title_option, $accesskey_option, |
5218 |
HAW_specchar($this->label, $deck), $br); |
5219 |
} |
5220 |
|
5221 |
elseif ($deck->ml == HAW_WML) |
5222 |
{ |
5223 |
// create link in WML |
5224 |
|
5225 |
if ($this->title) |
5226 |
$title_option = sprintf(" title=\"%s\"", |
5227 |
HAW_specchar($this->title, $deck)); |
5228 |
else |
5229 |
$title_option = ""; |
5230 |
|
5231 |
// create required amount of carriage return's |
5232 |
$br = ""; |
5233 |
for ($i=0; $i < $this->br; $i++) |
5234 |
$br .= "<br/>"; |
5235 |
|
5236 |
printf("<a%s href=\"%s\">%s</a>%s\n", |
5237 |
$title_option, HAW_specchar($this->url, $deck), |
5238 |
HAW_specchar($this->label, $deck), $br); |
5239 |
} |
5240 |
|
5241 |
elseif ($deck->ml == HAW_HDML) |
5242 |
{ |
5243 |
// create link in HDML |
5244 |
|
5245 |
if ($this->title) |
5246 |
$title_option = sprintf(" label=\"%s\"", |
5247 |
HAW_specchar($this->title, $deck)); |
5248 |
else |
5249 |
$title_option = ""; |
5250 |
|
5251 |
if ($this->accesskey != HAW_NO_ACCESSKEY) |
5252 |
$accesskey_option = sprintf(" accesskey=\"%s\"", $this->accesskey); |
5253 |
else |
5254 |
$accesskey_option = ""; |
5255 |
|
5256 |
// create required amount of carriage return's |
5257 |
$br = ""; |
5258 |
for ($i=0; $i < $this->br; $i++) |
5259 |
$br .= "<br>"; |
5260 |
|
5261 |
$content = sprintf("<a task=\"go\" dest=\"%s\"%s%s>%s</a>%s\n", |
5262 |
HAW_specchar($this->url, $deck), |
5263 |
$title_option, $accesskey_option, |
5264 |
HAW_specchar($this->label, $deck), $br); |
5265 |
|
5266 |
$deck->hdmlcardset->add_display_content($content); |
5267 |
} |
5268 |
|
5269 |
elseif ($deck->ml == HAW_VXML) |
5270 |
{ |
5271 |
// remove http:// from link label, as voice browsers complain about : |
5272 |
// (and users can't speak complete url anyway) |
5273 |
$label = ereg_replace("^http://", "", strtolower(HAW_specchar($this->label, $deck))); |
5274 |
|
5275 |
// * is not allowed in GSL grammar??? |
5276 |
$label = ereg_replace("\*", "", $label); |
5277 |
|
5278 |
if ($this->accesskey != HAW_NO_ACCESSKEY) |
5279 |
$dtmf = sprintf(" dtmf=\"%s\"", $this->accesskey); |
5280 |
else |
5281 |
$dtmf = ""; |
5282 |
|
5283 |
// prepare tag for VoiceXML link (will be written at form end) |
5284 |
$deck->voice_links .= sprintf("<link next=\"%s\"%s><grammar>[%s]</grammar></link>\n", |
5285 |
HAW_specchar($this->url, $deck), $dtmf, $label); |
5286 |
|
5287 |
if ($this->voice_text || $this->voice_audio_src) |
5288 |
{ |
5289 |
// create audio output for VoiceXML link |
5290 |
|
5291 |
echo "<block><prompt>"; |
5292 |
|
5293 |
if ($deck->voice_jingle) |
5294 |
{ |
5295 |
// play jingle before link label is spoken |
5296 |
printf("<audio src=\"%s\"></audio>", $deck->voice_jingle); |
5297 |
} |
5298 |
|
5299 |
$pause = $this->br * HAW_VOICE_PAUSE; // short pause for each break |
5300 |
|
5301 |
HAW_voice_audio(HAW_specchar($this->voice_text, $deck), |
5302 |
$this->voice_audio_src, $pause, $deck); |
5303 |
|
5304 |
echo "</prompt></block>\n"; |
5305 |
} |
5306 |
|
5307 |
// update deck timeout |
5308 |
if ($deck->voice_timeout < $this->voice_timeout) |
5309 |
$deck->voice_timeout = $this->voice_timeout; |
5310 |
} |
5311 |
} |
5312 |
} |
5313 |
}; |
5314 |
|
5315 |
|
5316 |
|
5317 |
|
5318 |
|
5319 |
|
5320 |
/** |
5321 |
This class provides a phone number in a HAW_deck object. If supported by their |
5322 |
mobile device, users can establish a voice connection to the specified number. |
5323 |
<p><b>Examples:</b><p> |
5324 |
$myPage = new HAW_deck(...);<br> |
5325 |
...<br> |
5326 |
$myPhone = new HAW_phone("123-45678", "CALL");<br> |
5327 |
$myPage->add_phone($myPhone); |
5328 |
@see HAW_deck |
5329 |
*/ |
5330 |
class HAW_phone |
5331 |
{ |
5332 |
var $label; |
5333 |
var $number; |
5334 |
var $title; |
5335 |
var $voice_text; |
5336 |
var $voice_audio_src; |
5337 |
|
5338 |
/** |
5339 |
Constructor |
5340 |
@param phone_number Phone number to dial. |
5341 |
@param title (optional)<br>If a string is provided here, the call button on a |
5342 |
WAP/HDML/XHTML device will be entitled. In order to work well with a broad range |
5343 |
of user agents, keep your title under 6 characters. |
5344 |
*/ |
5345 |
function HAW_phone($phone_number, $title="") |
5346 |
{ |
5347 |
$this->label = $phone_number; |
5348 |
$this->number = ereg_replace("[^+0-9]", "", $phone_number); |
5349 |
$this->title = $title; |
5350 |
$this->voice_text = $phone_number; |
5351 |
$this->voice_audio_src = ""; |
5352 |
} |
5353 |
|
5354 |
/** |
5355 |
Sets text to be spoken by voice browsers. <br> |
5356 |
@param text Some alternative text that replaces <phone_number>. |
5357 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
5358 |
*/ |
5359 |
function set_voice_text($text, $audio_src="") |
5360 |
{ |
5361 |
if (!is_string($text)) |
5362 |
die("invalid argument in set_voice_text()"); |
5363 |
|
5364 |
$this->voice_text = $text; |
5365 |
$this->voice_audio_src = $audio_src; |
5366 |
} |
5367 |
|
5368 |
function get_elementtype() |
5369 |
{ |
5370 |
return HAW_PHONE; |
5371 |
} |
5372 |
|
5373 |
function create($deck) |
5374 |
{ |
5375 |
if ($deck->ml == HAW_HTML) |
5376 |
{ |
5377 |
if ($this->title) |
5378 |
$title_option = sprintf(" title=\"%s\"", HAW_specchar($this->title, $deck)); |
5379 |
else |
5380 |
$title_option = ""; |
5381 |
|
5382 |
if ($deck->iModestyle) |
5383 |
// create phoneto: link for i-Mode |
5384 |
printf("<a href=\"phoneto:%s\">%s</a><br>\n", |
5385 |
$this->number, HAW_specchar($this->label, $deck)); |
5386 |
elseif ($deck->MMLstyle) |
5387 |
// create tel: link for MML |
5388 |
printf("<a href=\"tel:%s\">%s</a><br>\n", |
5389 |
$this->number, HAW_specchar($this->label, $deck)); |
5390 |
elseif ($deck->xhtml && !$deck->lynx) |
5391 |
// create wtai: link for XHTML Mobile |
5392 |
printf("<a href=\"wtai://wp/mc;%s\"%s>%s</a><br />\n", |
5393 |
$this->number, $title_option, HAW_specchar($this->label, $deck)); |
5394 |
else |
5395 |
// create phone number as plain text |
5396 |
printf("<code><big>%s</big></code><br />\n", HAW_specchar($this->label, $deck)); |
5397 |
} |
5398 |
elseif ($deck->ml == HAW_WML) |
5399 |
{ |
5400 |
// create phone number in WML |
5401 |
|
5402 |
if ($this->title) |
5403 |
$title_option = sprintf(" title=\"%s\"", HAW_specchar($this->title, $deck)); |
5404 |
else |
5405 |
$title_option = ""; |
5406 |
|
5407 |
printf("<a%s href=\"wtai://wp/mc;%s\">%s</a><br/>\n", $title_option, |
5408 |
ereg_replace("[+]", "%2B", $this->number), HAW_specchar($this->label, $deck)); |
5409 |
} |
5410 |
elseif ($deck->ml == HAW_HDML) |
5411 |
{ |
5412 |
// create phone number in HDML |
5413 |
|
5414 |
if ($this->title) |
5415 |
$title_option = sprintf(" label=\"%s\"", HAW_specchar($this->title, $deck)); |
5416 |
else |
5417 |
$title_option = ""; |
5418 |
|
5419 |
$content = sprintf("<a task=\"call\" number=\"%s\"%s>%s</a><br>\n", |
5420 |
$this->number, $title_option, HAW_specchar($this->label, $deck)); |
5421 |
|
5422 |
$deck->hdmlcardset->add_display_content($content); |
5423 |
} |
5424 |
elseif ($deck->ml == HAW_VXML) |
5425 |
{ |
5426 |
// create phone number in VXML |
5427 |
// VoiceXML transfer is not supported yet |
5428 |
|
5429 |
if ($this->voice_text || $this->voice_audio_src) |
5430 |
{ |
5431 |
// create audio output for VoiceXML text |
5432 |
|
5433 |
echo "<block><prompt>"; |
5434 |
|
5435 |
HAW_voice_audio(HAW_specchar($this->voice_text, $deck), |
5436 |
$this->voice_audio_src, HAW_VOICE_PAUSE, $deck); |
5437 |
|
5438 |
echo "</prompt></block>\n"; |
5439 |
} |
5440 |
} |
5441 |
} |
5442 |
}; |
5443 |
|
5444 |
|
5445 |
|
5446 |
|
5447 |
|
5448 |
|
5449 |
/** |
5450 |
This class defines a set of links. It should be preferably used for all kinds of menus. |
5451 |
The links have to be defined as separate HAW_link objects and are attached to the |
5452 |
linkset with a special "add_link" function. |
5453 |
For WAP devices browser-dependent WML code will be created. On all UP-browser-based |
5454 |
WAP devices linksets allow easier navigation through WML decks by using the "onpick" |
5455 |
WML option and therefore are improving the "usability" of an application. Instead of |
5456 |
painfully navigating through the links "sports->football->results->today" the mobile |
5457 |
user e.g. can press "2431" on the keypad to enter his favorite deck. For all other |
5458 |
WAP devices normal <a> tags are created. One HAW_deck object can contain only |
5459 |
one linkset object. |
5460 |
<p><b>Examples:</b><p> |
5461 |
$myPage = new HAW_deck(...);<br> |
5462 |
...<br> |
5463 |
$myLinkset = new HAW_linkset();<br> |
5464 |
$myLink1 = new HAW_link("Phonebook", "/wap/phonebook.php");<br> |
5465 |
$myLinkset->add_link($myLink1);<br> |
5466 |
$myLink2 = new HAW_link("DateBook", "/wap/datebook.php");<br> |
5467 |
$myLinkset->add_link($myLink2);<br> |
5468 |
...<br> |
5469 |
$myPage->add_linkset($myLinkset);<br> |
5470 |
...<br> |
5471 |
$myPage->create_page(); |
5472 |
@see HAW_link |
5473 |
@see HAW_deck |
5474 |
*/ |
5475 |
class HAW_linkset |
5476 |
{ |
5477 |
var $element; |
5478 |
var $number_of_elements; |
5479 |
var $voice_text; |
5480 |
var $voice_audio_src; |
5481 |
var $voice_help; |
5482 |
var $voice_noinput; |
5483 |
var $voice_nomatch; |
5484 |
|
5485 |
|
5486 |
/** |
5487 |
Constructor |
5488 |
*/ |
5489 |
function HAW_linkset() |
5490 |
{ |
5491 |
$this->number_of_elements = 0; |
5492 |
$this->voice_text = HAW_VOICE_ENUMERATE; |
5493 |
$this->voice_audio_src = ""; |
5494 |
$this->voice_help = array(); |
5495 |
$this->voice_noinput = array(); |
5496 |
$this->voice_nomatch = array(); |
5497 |
} |
5498 |
|
5499 |
|
5500 |
/** |
5501 |
Adds a HAW_link object to HAW_linkset |
5502 |
@param link Some HAW_link object. |
5503 |
@see HAW_link |
5504 |
*/ |
5505 |
function add_link(&$link) |
5506 |
{ |
5507 |
if (!is_object($link)) |
5508 |
die("invalid argument in add_link()"); |
5509 |
|
5510 |
if ($this->number_of_elements < 12) |
5511 |
{ |
5512 |
// number of possible access keys not exhausted |
5513 |
|
5514 |
$accesskey = $this->number_of_elements + 1; // start with key 1 |
5515 |
|
5516 |
if ($accesskey == 12) |
5517 |
$accesskey = "#"; |
5518 |
elseif ($accesskey == 11) |
5519 |
$accesskey = "*"; |
5520 |
elseif ($accesskey == 10) |
5521 |
$accesskey = "0"; |
5522 |
|
5523 |
$link->set_accesskey($accesskey); |
5524 |
} |
5525 |
|
5526 |
$this->element[$this->number_of_elements] = $link; |
5527 |
|
5528 |
$this->number_of_elements++; |
5529 |
} |
5530 |
|
5531 |
/** |
5532 |
Sets text to be spoken by voice browsers. <br> |
5533 |
@param text Some alternative text that replaces the enumeration of link <label>s. |
5534 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
5535 |
*/ |
5536 |
function set_voice_text($text, $audio_src="") |
5537 |
{ |
5538 |
if (!is_string($text)) |
5539 |
die("invalid argument in set_voice_text()"); |
5540 |
|
5541 |
$this->voice_text = $text; |
5542 |
$this->voice_audio_src = $audio_src; |
5543 |
} |
5544 |
|
5545 |
/** |
5546 |
Sets help text for voice browsers. <br> |
5547 |
@param text Some helpful information concerning this linkset. |
5548 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
5549 |
@param url Some other voice deck to go to (optional). |
5550 |
*/ |
5551 |
function set_voice_help($text, $audio_src="", $url="") |
5552 |
{ |
5553 |
if (!is_string($text)) |
5554 |
die("invalid argument in set_voice_help()"); |
5555 |
|
5556 |
$arr["text"] = $text; |
5557 |
$arr["src"] = $audio_src; |
5558 |
$arr["url"] = $url; |
5559 |
|
5560 |
$this->voice_help[] = $arr; |
5561 |
} |
5562 |
|
5563 |
/** |
5564 |
Sets noinput text for voice browsers. <br> |
5565 |
@param text Some text to inform the user that no input has been received. |
5566 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
5567 |
@param url Some other voice deck to go to (optional). |
5568 |
*/ |
5569 |
function set_voice_noinput($text, $audio_src="", $url="") |
5570 |
{ |
5571 |
if (!is_string($text)) |
5572 |
die("invalid argument in set_voice_noinput()"); |
5573 |
|
5574 |
$arr["text"] = $text; |
5575 |
$arr["src"] = $audio_src; |
5576 |
$arr["url"] = $url; |
5577 |
|
5578 |
$this->voice_noinput[] = $arr; |
5579 |
} |
5580 |
|
5581 |
/** |
5582 |
Sets nomatch text for voice browsers. <br> |
5583 |
@param text Some text to complain that user input was not recognized. |
5584 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
5585 |
@param url Some other voice deck to go to (optional). |
5586 |
*/ |
5587 |
function set_voice_nomatch($text, $audio_src="", $url="") |
5588 |
{ |
5589 |
if (!is_string($text)) |
5590 |
die("invalid argument in set_voice_nomatch()"); |
5591 |
|
5592 |
$arr["text"] = $text; |
5593 |
$arr["src"] = $audio_src; |
5594 |
$arr["url"] = $url; |
5595 |
|
5596 |
$this->voice_nomatch[] = $arr; |
5597 |
} |
5598 |
|
5599 |
function get_elementtype() |
5600 |
{ |
5601 |
return HAW_LINKSET; |
5602 |
} |
5603 |
|
5604 |
function create(&$deck) |
5605 |
{ |
5606 |
if ($this->number_of_elements > 0) |
5607 |
{ |
5608 |
if ($deck->ml == HAW_HTML) |
5609 |
{ |
5610 |
// create linkset in HTML |
5611 |
|
5612 |
if ($deck->css_enabled) |
5613 |
{ |
5614 |
// create links inside a frame |
5615 |
|
5616 |
echo "<div style=\"border: solid 1px; margin: 5px; padding: 5px;\">\n"; |
5617 |
|
5618 |
if ($deck->lynx) |
5619 |
{ |
5620 |
// create link list to avoid whitespace between links |
5621 |
echo "<ul>\n"; |
5622 |
while (list($key, $val) = each($this->element)) |
5623 |
{ |
5624 |
echo "<li>\n"; |
5625 |
$val->create($deck); // create one list element for each link |
5626 |
echo "</li>\n"; |
5627 |
} |
5628 |
echo "</ul>\n"; |
5629 |
} |
5630 |
else |
5631 |
{ |
5632 |
while (list($key, $val) = each($this->element)) |
5633 |
$val->create($deck); |
5634 |
} |
5635 |
|
5636 |
echo "</div>\n"; |
5637 |
} |
5638 |
else |
5639 |
// create normal links for the small devices |
5640 |
while (list($key, $val) = each($this->element)) |
5641 |
$val->create($deck); |
5642 |
} |
5643 |
|
5644 |
elseif ($deck->ml == HAW_WML) |
5645 |
{ |
5646 |
// create linkset in WML |
5647 |
|
5648 |
if ($deck->upbrowser && |
5649 |
($deck->number_of_forms == 0) && |
5650 |
($deck->number_of_links == 0) && |
5651 |
($deck->number_of_phones == 0)) |
5652 |
{ |
5653 |
echo "<select>\n"; |
5654 |
|
5655 |
while (list($key, $val) = each($this->element)) |
5656 |
{ |
5657 |
if ($val->get_title()) |
5658 |
$title = " title=\"" . HAW_specchar($val->get_title(), $deck) . "\""; |
5659 |
|
5660 |
printf("<option onpick=\"%s\"%s>%s</option>\n", |
5661 |
HAW_specchar($val->get_url(), $deck), $title, |
5662 |
HAW_specchar($val->get_label(), $deck)); |
5663 |
} |
5664 |
|
5665 |
echo "</select>\n"; |
5666 |
} |
5667 |
else |
5668 |
// create normal WML links |
5669 |
while (list($key, $val) = each($this->element)) |
5670 |
$val->create($deck); |
5671 |
} |
5672 |
|
5673 |
elseif ($deck->ml == HAW_HDML) |
5674 |
{ |
5675 |
// create linkset in HDML |
5676 |
|
5677 |
while (list($key, $val) = each($this->element)) |
5678 |
$val->create($deck); |
5679 |
} |
5680 |
|
5681 |
elseif ($deck->ml == HAW_VXML) |
5682 |
{ |
5683 |
// create linkset for VoiceXML |
5684 |
|
5685 |
echo "<field name=\"haw_menu_item\">\n"; |
5686 |
|
5687 |
if ($this->voice_text || $this->voice_audio_src) |
5688 |
{ |
5689 |
if ($this->voice_text != HAW_VOICE_ENUMERATE) |
5690 |
{ |
5691 |
echo "<prompt>"; |
5692 |
|
5693 |
HAW_voice_audio(HAW_specchar($this->voice_text, $deck), |
5694 |
$this->voice_audio_src, 0, $deck); |
5695 |
|
5696 |
echo "</prompt>\n"; |
5697 |
} |
5698 |
} |
5699 |
|
5700 |
while (list($key, $val) = each($this->element)) |
5701 |
{ |
5702 |
if ($val->get_url()) |
5703 |
{ |
5704 |
// inhibit "empty" links |
5705 |
|
5706 |
if ($val->get_accesskey() != HAW_NO_ACCESSKEY) |
5707 |
$dtmf = sprintf(" dtmf=\"%s\"", $val->get_accesskey()); |
5708 |
else |
5709 |
$dtmf = ""; |
5710 |
|
5711 |
if ($deck->supportsVXMLBreakTag) |
5712 |
$breakTag = sprintf("<break time=\"%dms\"/>", HAW_VOICE_PAUSE); |
5713 |
else |
5714 |
$breakTag = ""; |
5715 |
|
5716 |
printf("<prompt>%s%s</prompt>\n", HAW_specchar($val->get_label(), $deck), $breakTag); |
5717 |
|
5718 |
printf("<option%s value=\"%s\">%s</option>\n", |
5719 |
$dtmf, HAW_specchar($val->get_url(), $deck), |
5720 |
ereg_replace("[\?!]"," ",strtolower(HAW_specchar($val->get_label(), $deck)))); |
5721 |
} |
5722 |
} |
5723 |
|
5724 |
// create event handlers |
5725 |
HAW_voice_eventhandler("help", $this->voice_help, $deck); |
5726 |
HAW_voice_eventhandler("noinput", $this->voice_noinput, $deck); |
5727 |
HAW_voice_eventhandler("nomatch", $this->voice_nomatch, $deck); |
5728 |
|
5729 |
echo "</field>\n"; |
5730 |
echo "<filled><submit expr=\"haw_menu_item\"/></filled>\n"; |
5731 |
} |
5732 |
} |
5733 |
} |
5734 |
}; |
5735 |
|
5736 |
|
5737 |
|
5738 |
|
5739 |
|
5740 |
|
5741 |
/* |
5742 |
Undocumented class for raw markup insertion - For test only! |
5743 |
*/ |
5744 |
class HAW_raw |
5745 |
{ |
5746 |
var $ml; |
5747 |
var $code; |
5748 |
|
5749 |
/** |
5750 |
Constructor |
5751 |
@param ml Markup language (HAW_HTML, HAW_WML, HAW_HDML). |
5752 |
@param code Some markup code to be inserted for the selected markup language<br> |
5753 |
Note: Using this class is for meant for test purposes only. Inproper usage |
5754 |
can result in highly incompatible applications. |
5755 |
*/ |
5756 |
function HAW_raw($ml,$code) |
5757 |
{ |
5758 |
$this->ml = $ml; |
5759 |
$this->code = $code; |
5760 |
} |
5761 |
|
5762 |
function get_elementtype() |
5763 |
{ |
5764 |
return HAW_RAW; |
5765 |
} |
5766 |
|
5767 |
function create($deck) |
5768 |
{ |
5769 |
if ($deck->ml == $this->ml) |
5770 |
echo($this->code); |
5771 |
} |
5772 |
}; |
5773 |
|
5774 |
|
5775 |
|
5776 |
|
5777 |
|
5778 |
|
5779 |
/** |
5780 |
This class provides a banner in a HAW_deck object (HTML only). |
5781 |
<p><b>Examples:</b><p> |
5782 |
$myPage = new HAW_deck(...);<br> |
5783 |
...<br> |
5784 |
$myBanner1 = new HAW_banner("http://wwww.adpartner1.org/images/adp1.gif", "http://www.adpartner1.org/", "Welcome at adpartner1!");<br> |
5785 |
$myPage->add_banner($myBanner1);<br> |
5786 |
...<br> |
5787 |
$myBanner2 = new HAW_banner("http://wwww.adpartner2.org/images/adp2.gif", HAW_NOLINK, "Buy products of adpartner2!");<br> |
5788 |
$myBanner2->set_size(300,50);<br> |
5789 |
$myBanner2->set_br(0);<br> |
5790 |
$myPage->add_banner($myBanner2,HAW_TOP); |
5791 |
@see HAW_deck |
5792 |
*/ |
5793 |
class HAW_banner |
5794 |
{ |
5795 |
var $image; |
5796 |
var $url; |
5797 |
var $alt; |
5798 |
var $width = -1; |
5799 |
var $height = -1; |
5800 |
var $br = 1; |
5801 |
|
5802 |
/** |
5803 |
Constructor |
5804 |
@param image Your ad-partners banner in .gif, .jpg or any other HTML compatible format. |
5805 |
@param url Link to your ad-partner (or HAW_NOLINK if no link available) |
5806 |
@param alt Alternative text for the banner |
5807 |
*/ |
5808 |
function HAW_banner($image, $url, $alt) |
5809 |
{ |
5810 |
$this->image = $image; |
5811 |
$this->url = $url; |
5812 |
$this->alt = $alt; |
5813 |
} |
5814 |
|
5815 |
/** |
5816 |
Sets explicitely the size of a banner<br> |
5817 |
Note: Use of this function is not mandatory but will accelerate page set-up |
5818 |
@param width Width of banner in pixels. |
5819 |
@param height Height of banner in pixels. |
5820 |
*/ |
5821 |
function set_size($width, $height) |
5822 |
{ |
5823 |
if (!is_int($width) || ($width < 1) || !is_int($height) || ($height < 1)) |
5824 |
die("invalid argument in set_size()"); |
5825 |
|
5826 |
$this->width = $width; |
5827 |
$this->height = $height; |
5828 |
} |
5829 |
|
5830 |
/** |
5831 |
Sets the number of line breaks (CRLF) after banner. (default: 1) |
5832 |
@param br Some number of line breaks. |
5833 |
*/ |
5834 |
function set_br($br) |
5835 |
{ |
5836 |
if (!is_int($br) || ($br < 0)) |
5837 |
die("invalid argument in set_br()"); |
5838 |
|
5839 |
$this->br = $br; |
5840 |
} |
5841 |
|
5842 |
|
5843 |
function create() |
5844 |
{ |
5845 |
if ($this->url != HAW_NOLINK) |
5846 |
// banner links to url |
5847 |
echo "<a href=\"$this->url\" target=\"_blank\">"; |
5848 |
|
5849 |
if (($this->width>0) && ($this->height>0)) |
5850 |
// prepare this variable only if size info available |
5851 |
$size = sprintf(" width=\"%d\" height=\"%d\"", $this->width, $this->height); |
5852 |
|
5853 |
printf("<img src=\"%s\" alt=\"%s\"%s hspace=\"10\" vspace=\"10\" border=\"0\" />", |
5854 |
$this->image, $this->alt, $size); |
5855 |
|
5856 |
if ($this->url != HAW_NOLINK) |
5857 |
// close <a> tag |
5858 |
echo "</a>\n"; |
5859 |
|
5860 |
for ($i=0; $i<$this->br; $i++) |
5861 |
// create required number of line breaks |
5862 |
echo "<br />\n"; |
5863 |
} |
5864 |
}; |
5865 |
|
5866 |
|
5867 |
|
5868 |
|
5869 |
|
5870 |
|
5871 |
/** |
5872 |
This class will cause a (hawrizontal) rule to be drawn across the screen. |
5873 |
You can use it to separate text paragraphs in HAW_deck or HAW_form objects. |
5874 |
<p><b>Examples:</b><p> |
5875 |
$myDefaultRule = new HAW_rule();<br> |
5876 |
$mySpecialRule = new HAW_rule("60%", 4);<br> |
5877 |
...<br> |
5878 |
$myPage->add_rule($myDefaultRule)<br>; |
5879 |
...<br> |
5880 |
$myPage->add_rule($mySpecialRule); |
5881 |
@see HAW_deck |
5882 |
@see HAW_form |
5883 |
*/ |
5884 |
class HAW_rule |
5885 |
{ |
5886 |
var $width; |
5887 |
var $size; |
5888 |
|
5889 |
|
5890 |
/** |
5891 |
Constructor |
5892 |
@param width (optional)<br>Percentage of screen width or absolute value in |
5893 |
number of pixels (e.g. "50%", 100). |
5894 |
@param size (optional)<br>Height of the line to be drawn in pixels. |
5895 |
*/ |
5896 |
function HAW_rule($width="", $size="") |
5897 |
{ |
5898 |
$this->width = $width; |
5899 |
$this->size = $size; |
5900 |
} |
5901 |
|
5902 |
|
5903 |
function get_elementtype() |
5904 |
{ |
5905 |
return HAW_RULE; |
5906 |
} |
5907 |
|
5908 |
|
5909 |
function create(&$deck) |
5910 |
{ |
5911 |
$width_option = ($this->width ? " width=\"" . $this->width . "\"" : ""); |
5912 |
$size_option = ($this->size ? " size=\"" . $this->size . "\"" : ""); |
5913 |
|
5914 |
if ($deck->ml == HAW_HTML) |
5915 |
// draw horizontal row in HTML |
5916 |
echo "<hr" . $width_option . $size_option . " />\n"; |
5917 |
|
5918 |
elseif ($deck->ml == HAW_WML) |
5919 |
{ |
5920 |
if ($deck->owgui_1_3) |
5921 |
// WAP device accepts Openwave GUI extensions for WML 1.3 |
5922 |
echo "<hr" . $width_option . $size_option . "/>\n"; |
5923 |
else |
5924 |
// WAP device does not understand <hr> tags |
5925 |
// ==> draw some number of hyphens to create a rule |
5926 |
echo "----------<br/>\n"; |
5927 |
} |
5928 |
elseif ($deck->ml == HAW_HDML) |
5929 |
{ |
5930 |
// HDML devices doesn't understand <hr> |
5931 |
// ==> draw some number of hyphens to create a rule |
5932 |
|
5933 |
$deck->hdmlcardset->add_display_content("<" . $deck->alignment . ">\n"); |
5934 |
|
5935 |
$deck->hdmlcardset->add_display_content("----------\n<br>\n"); |
5936 |
} |
5937 |
elseif ($deck->ml == HAW_VXML) |
5938 |
{ |
5939 |
// make a longer speech pause |
5940 |
if ($deck->supportsVXMLBreakTag) |
5941 |
printf("<block><prompt><break time=\"%dms\"/></prompt></block>\n", |
5942 |
3 * HAW_VOICE_PAUSE); |
5943 |
} |
5944 |
} |
5945 |
}; |
5946 |
|
5947 |
|
5948 |
|
5949 |
|
5950 |
|
5951 |
|
5952 |
/** |
5953 |
This class provides a voice recorder in a HAW_deck object.<br><br> |
5954 |
Voice recording is feature for voice browsers only (VoiceXML). |
5955 |
The recorded voice input will be sent encrypted as multipart/form-data |
5956 |
to some other url, which normally will be another PHP/HAWHAW script. Here you can |
5957 |
store the received data as .wav file on your server, play it to the user, or do whatever |
5958 |
you want. Saving of the received voice data is similar to normal PHP file upload handling. |
5959 |
<br><br> |
5960 |
Voice recording is a very powerful feature which offers many oportunities to |
5961 |
create high-sophisticated voice applications.<br><br> |
5962 |
<p><b>Examples:</b><p> |
5963 |
$myRecorder = new HAW_voicerecorder("http://www.foo.com/script.php", "Please speak after the tone");<br> |
5964 |
<br> |
5965 |
$myRecorder = new HAW_voicerecorder("http://www.foo.com/script.php", "You have 2 minutes from now");<br> |
5966 |
$myRecorder->make_beep(false);<br> |
5967 |
$myRecorder->set_maxtime(120);<br><br> |
5968 |
// ... and in http://www.foo.com/script.php we store the received wav file like this:<br> |
5969 |
move_uploaded_file($_FILES['haw_recording']['tmp_name'], "/voice/message.wav"); |
5970 |
@see HAW_deck |
5971 |
*/ |
5972 |
class HAW_voicerecorder |
5973 |
{ |
5974 |
var $url; |
5975 |
var $label; |
5976 |
var $beep; |
5977 |
var $maxtime; |
5978 |
var $finalsilence; |
5979 |
var $type; |
5980 |
var $voice_text; |
5981 |
var $voice_audio_src; |
5982 |
var $voice_noinput; |
5983 |
|
5984 |
/** |
5985 |
Constructor |
5986 |
@param url Address where the recorded file is sent to. |
5987 |
@param label Some introducing words before the recording starts. |
5988 |
*/ |
5989 |
function HAW_voicerecorder($url, $label) |
5990 |
{ |
5991 |
$this->url = $url; |
5992 |
$this->label = $label; |
5993 |
$this->beep = true; |
5994 |
$this->maxtime = ""; |
5995 |
$this->finalsilence = ""; |
5996 |
$this->type = ""; |
5997 |
$this->voice_text = $label; |
5998 |
$this->voice_audio_src = ""; |
5999 |
$this->voice_noinput = array(); |
6000 |
} |
6001 |
|
6002 |
/** |
6003 |
Sets text to be spoken by voice browsers. |
6004 |
@param text Some alternative text that replaces <label>. |
6005 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
6006 |
*/ |
6007 |
function set_voice_text($text, $audio_src="") |
6008 |
{ |
6009 |
if (!is_string($text)) |
6010 |
die("invalid argument in set_voice_text()"); |
6011 |
|
6012 |
$this->voice_text = $text; |
6013 |
$this->voice_audio_src = $audio_src; |
6014 |
} |
6015 |
|
6016 |
/** |
6017 |
Sets noinput text for voice browsers. <br> |
6018 |
@param text Some text to inform the user that no input has been received. |
6019 |
@param audio_src Some audio file (e.g. *.wav file) to play (optional). |
6020 |
@param url Some other voice deck to go to (optional). |
6021 |
*/ |
6022 |
function set_voice_noinput($text, $audio_src="", $url="") |
6023 |
{ |
6024 |
if (!is_string($text)) |
6025 |
die("invalid argument in set_voice_noinput()"); |
6026 |
|
6027 |
$arr["text"] = $text; |
6028 |
$arr["src"] = $audio_src; |
6029 |
$arr["url"] = $url; |
6030 |
|
6031 |
$this->voice_noinput[] = $arr; |
6032 |
} |
6033 |
|
6034 |
/** |
6035 |
Activates/deactivates beep before recording starts. |
6036 |
@param beep_indicator: true (default) or false. |
6037 |
*/ |
6038 |
function make_beep($beep_indicator) |
6039 |
{ |
6040 |
if ($beep_indicator == false) |
6041 |
$this->beep = false; |
6042 |
} |
6043 |
|
6044 |
/** |
6045 |
Sets maximum duration of recording. |
6046 |
@param maxtime Duration of record in seconds |
6047 |
*/ |
6048 |
function set_maxtime($maxtime) |
6049 |
{ |
6050 |
$this->maxtime = $maxtime; |
6051 |
} |
6052 |
|
6053 |
/** |
6054 |
Sets interval of silence that indicates end of speech. |
6055 |
@param finalsilence Silence duration (in seconds) |
6056 |
*/ |
6057 |
function set_finalsilence($finalsilence) |
6058 |
{ |
6059 |
$this->finalsilence = $finalsilence; |
6060 |
} |
6061 |
|
6062 |
/** |
6063 |
Sets media format of recording. |
6064 |
@param type e.g. "audio/x-wav" |
6065 |
*/ |
6066 |
function set_type($type) |
6067 |
{ |
6068 |
$this->type = $type; |
6069 |
} |
6070 |
|
6071 |
function get_elementtype() |
6072 |
{ |
6073 |
return HAW_VOICERECORDER; |
6074 |
} |
6075 |
|
6076 |
function create(&$deck) |
6077 |
{ |
6078 |
if ($deck->ml == HAW_VXML) |
6079 |
{ |
6080 |
// VoiceXML (no output for non-voice browsers) |
6081 |
|
6082 |
if ($this->maxtime) |
6083 |
$maxtime = sprintf(" maxtime=\"%ds\"", $this->maxtime); |
6084 |
else |
6085 |
$maxtime = ""; |
6086 |
|
6087 |
if ($this->finalsilence) |
6088 |
$finalsilence = sprintf(" finalsilence=\"%ds\"", $this->finalsilence); |
6089 |
else |
6090 |
$finalsilence = ""; |
6091 |
|
6092 |
if ($this->type) |
6093 |
$type = sprintf(" type=\"%s\"", $this->type); |
6094 |
else |
6095 |
$type = ""; |
6096 |
|
6097 |
if ($this->beep) |
6098 |
$beep = "true"; |
6099 |
else |
6100 |
$beep = "false"; |
6101 |
|
6102 |
printf("<record name=\"haw_recording\" beep=\"%s\"%s%s%s>\n", |
6103 |
$beep, $maxtime, $finalsilence, $type); |
6104 |
|
6105 |
if ($this->voice_text || $this->voice_audio_src) |
6106 |
{ |
6107 |
echo "<prompt>"; |
6108 |
|
6109 |
HAW_voice_audio(HAW_specchar($this->voice_text, $deck), |
6110 |
$this->voice_audio_src, 0, $deck); |
6111 |
|
6112 |
echo "</prompt>\n"; |
6113 |
} |
6114 |
|
6115 |
// replace '&' character in URL with '&' |
6116 |
$this->url = ereg_replace("&", "&", $this->url); |
6117 |
|
6118 |
printf("<filled><submit next=\"%s\" enctype=\"multipart/form-data\" method=\"post\" namelist=\"haw_recording\"/></filled>\n", |
6119 |
$this->url); |
6120 |
|
6121 |
// create event handler for noinput |
6122 |
HAW_voice_eventhandler("noinput", $this->voice_noinput, $deck); |
6123 |
|
6124 |
// create catch handler for disconnect |
6125 |
printf("<catch event=\"connection.disconnect.hangup\"><submit next=\"%s\" enctype=\"multipart/form-data\" method=\"post\" namelist=\"haw_recording\"/></catch>\n", |
6126 |
$this->url); |
6127 |
|
6128 |
echo "</record>\n"; |
6129 |
} |
6130 |
} |
6131 |
}; |
6132 |
|
6133 |
?> |