<?
// history_wml.php
//
// 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.
//
// -------------------------------------------------------------------
//
// WML History browsing and re-execution page
//
    require("common.inc");
    require("common_wml.inc");
    header("Content-type: text/vnd.wap.wml");
    require("displayfuncs.inc");

    echo '<?xml version="1.0" encoding="iso-8859-1"?>';
?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>

<card title="<? echo SYSTEM_NAME; ?> history" newcontext="true">

<?
    //echo sParaBlk("cmdStart=$cmdStart cmdNum=$cmdNum");

    if (!isset($cmdStart)) {
    	$cmdStart = $cmdNum - $historyBlockSize + 1;
    } else {
    	if (isset($prevHist))
	    $cmdStart -= $historyBlockSize;
	else if (isset($nextHist))
	    $cmdStart += $historyBlockSize;
    } // if

    if ($cmdStart < 1) $cmdStart = 1;
    if ($cmdStart > $cmdNum) $cmdStart = $cmdNum;

    $cmdEnd = min($cmdStart + $historyBlockSize - 1, $cmdNum);

    //echo sParaBlk("cmdStart=$cmdStart cmdNum=$cmdNum");

    if (($setOptions & OPT_HISTORY) == 0) {
	echo $sParaBlk(sEmphBlk("Those who do not remember history " .
		    "cannot repeat it"));
	echo $sParaBlk("(History is not enabled for this session)");
    } else if ($cmdNum <= 0) {
	echo sParaBlk("The command history is empty");
    } else {
	//
	// Display a block of commands from history in form
	// suitable for editing and re-execution
	//
            
        for ($j = $cmdStart; $j <= $cmdEnd; $j++) {
	    echo '<p>';
	    echo "$j: ";

	    echo escBrowserSpecialChars($histCmd[$j]);
	    /*
            echo '<input type="text" name="fSh' . $j . 
	    		'" format="*M" size="20" value="' . 
			escBrowserSpecialChars($histCmd[$j]) .
			'" maxlength="100"/>';
            echo 'Newline? ';
            echo wmlYesNoSelect("fNl" . $j, 
		(isset($histAddNl[$j]) && $histAddNl[$j] == "y") ? "y" : "n", 
		"Newline?");
					
            if ($setOptions & OPT_ALLOWSILENT) {
                    echo '&gt; null? ';
                echo wmlYesNoSelect("fSil" . $j, 
		        (isset($histSilent[$j]) && $histSilent[$j] == "y") ? 
		    		"y" : "n", 
			"Null output?");
            }
	    */
	    
            echo '<br/>';
	    wmlSubmitAnchor("send", "command.php", "post", 
		    $shCommFields . 
	    	        '<postfield name="sendCmd" value="y"/>' .
	    	        '<postfield name="cmdForm" value="y"/>' .
	    	        '<postfield name="shCmd" value="' . 
		   	         escBrowserSpecialChars($histCmd[$j]) . '"/>' .
	    	        '<postfield name="addNl" value="' . 
		   	         ((isset($histAddNl[$j]) && 
			         $histAddNl[$j] == "y") ? "y" : "n") . '"/>' .
	    	        '<postfield name="silent" value="' . 
		   	         ((isset($histSilent[$j]) && 
			         $histSilent[$j] == "y") ?  "y" : "n") . '"/>');
	    if (isUpPhone()) {
                echo ' &nbsp; ';	
                echo ' &nbsp; ';
	    } // if

	    wmlSubmitAnchor("edit", "history_edit_wml.php", "post", 
		    $commFields . 
		        '<postfield name="cmdStart" value="' . 
				$cmdStart . '"/>' .  
		    	'<postfield name="cmdIdx" value="' . $j . '"/>');

            echo '</p>';

	} // for */

	if ($cmdEnd < $cmdNum)
	    echo "<p>$cmdNum cmds in history</p>";
	    
	if ($cmdStart > 1) {
            wmlSoftkeyItem("doPrevHist", "Prev history", "history_wml.php", 
		"post", 
    	        $shCommFields . 
		    '<postfield name="cmdStart" value="' . $cmdStart . '"/>' .  
		    '<postfield name="prevHist" value="y"/>');
	} // if
        
	if ($cmdStart + $historyBlockSize <= $cmdNum) {
            wmlSoftkeyItem("doNextHist", "Next history", "history_wml.php", 
		"post", 
    	        $shCommFields . 
		    '<postfield name="cmdStart" value="' . $cmdStart . '"/>' .  
		    '<postfield name="nextHist" value="y"/>');
	} // if

        wmlSoftkeyItem("doClrHist", "Clear history", "command.php", "post", 
    	    $shCommFields . '<postfield name="clrHist" value="y"/>');

    } // if

    wmlSoftkeyHomeLink();
?>

</card>
</wml>
