<?
// displayfuncs.inc
//
// Some display functions that should work for WML and HTML.  These are mainly
// used in command.php in common logic shared by HTML and WML
//
// Copyright, Exolution GmbH / Michael Kerrisk, Sep 2000
// http://www.exolution.com/wapsh   mailto:wapsh@exolution.de
//
// This software is Open Source licensed under the terms of the Trolltech QPL
// version 1.0.  See http://www.exolution.de/wapsh for further information.
//
// ---------------------------------------------------------------------
//
    function sParaBlk($s) {
	return "<p>" . $s . "</p>";
    }
    
    function sBoldBlk($s) {
	global $clientType;

	if ($clientType == "http")
	    return "<strong>" . $s . "</strong>";
	else
	    return $s;
    }
    
    function sEmphBlk($s) {
	global $clientType;

	if ($clientType == "http")
	    return "<em>" . $s . "</em>";
	else
	    return $s;
    }
 
    function sFontBlk($fontOpts, $s) {
	global $clientType;

	if ($clientType == "http")
	    return "<font " . $fontOpts . ">" . $s . "</font>";
	else
	    return $s;
    }

    function sBreak() {
	global $clientType;

	if ($clientType == "http")
	    return "<br>";
	else
	    return "<br/>";
    }


    // Create a hyperlink (anchor)

    function sAnchor($target, $label) {
	global $clientType;

	if ($clientType == "http")
	    return '<a href="' . $target . '">' . $label . '</a>';
	else
	    return '<anchor>' . $label . '<go href="' . $target . 
		'" method="get"></go></anchor>';
    }
    
    function newline2break($str) {
	global $clientType;

	if ($clientType == "http")
	    return nl2br($str);
	else
	    return str_replace("\n", "<br/>", $str);
    }


    // Escape characters which have special meaning in the browser

    function escBrowserSpecialChars($str) {
	global $clientType;

	if ($clientType == "http")
	    return htmlspecialchars($str);
	else
	    return str_replace("<", "&lt;", 
	    	 str_replace(">", "&gt;", 
	    	 str_replace("&", "&amp;", 
	    	 str_replace("$", "$$", 
		    $str))));
    }



    // Create a navigation link, either as a softkey menu item or as a
    // hyperlink, depending on the phone type

    function wmlSoftkeyItem($name, $label, $target, $method, $postfields) {

	if (isUpPhone()) {
	    echo '<p>';
	    echo '<anchor>' . $label;
	} else {
	    echo '<do name="' . $name . '" type="accept" label="' . 
		$label .'">';
	} // if
	
	// XXX Temporary hack for broken Siemens phone FIXME 
	//echo '<go href="' . $target . '" method="' . $method . '">';
	echo '<go href="' . $target . '" method="get">';
	echo $postfields;
	echo '</go>';
	
	if (isUpPhone()) {
	    echo '</anchor>';
	    echo '</p>';
	} else {
	    echo '</do>';
	} // if
    } // wmlSoftkeyItem


    // Create a "submit" hyperlink

    function wmlSubmitAnchor($label, $target, $method, $postfields) {
	echo '<anchor>' . $label;
	// XXX Temporary hack for broken Siemens phone FIXME 
	//echo '<go href="' . $target . '" method="' . $method . '">';
	echo '<go href="' . $target . '" method="get">';
	echo $postfields;
	echo '</go>';
	echo '</anchor>';
    } // SubmitAnchor


    // Create link(s) to command page.  If we have a UP phone
    // then make links to all three cards
    
    function wmlSoftkeyHomeLink() {
	global $commFields;

	wmlSoftkeyItem("toHtsh", "To " . SYSTEM_NAME . " " . 
		(isUpPhone() ? "output" : "main"), 
		"command.php", "post", $commFields);

	if (isUpPhone()) {
	    wmlSoftkeyItem("toHtsh", "To " . SYSTEM_NAME . " input",
		"command.php#input", "post", $commFields);

	    wmlSoftkeyItem("toHtsh", "To " . SYSTEM_NAME . " menu",
		"command.php#menu", "post", $commFields);

	} // if
    } // wmlSoftkeyHomeLink



    // Create a selct list offering two options YES or NO

    function wmlYesNoSelect($fieldName, $value, $title) {
        echo '<select name="' . $fieldName. '" value="' . $value . 
	    '" title="' . $title . '">';
	echo '<option value="n">No</option>';
	echo '<option value="y">Yes</option>';
	echo '</select>';
    }
?>
