<?
// history_html.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.
//
// -------------------------------------------------------------------
//
// HTML History browsing and editing page
//
    require("common.inc");
    require("common_html.inc");
    require("displayfuncs.inc");
?>
<html>
<head>
    <title><?echo SYSTEM_NAME; ?> Shell Input History</title>
</head>

<body bgcolor="<? echo BODY_BGCOLOR; ?>">
<p><font size="+1"><strong><? echo SYSTEM_NAME; ?> history</strong></font></p>
<p><a href="command.php">Return to <? echo SYSTEM_NAME; ?> main page</a></p>

<?
    //echo "<P>cmdStart=$cmdStart cmdNum=$cmdNum</P>";

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

    $cmdEnd = $cmdStart + $historyBlockSize - 1;
    if ($cmdEnd > $cmdNum) 
        $cmdEnd = $cmdNum;
    

    //echo "<P>cmdStart=$cmdStart cmdNum=$cmdNum</P>";

    if (($setOptions & OPT_HISTORY) == 0) {
	echo $sParaBlk(sEmphBlk("Perhaps, if the future was something " . 
		    "that could be perceived concretely and individually, " .
		    "the past would not be so seductive"));
	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++) {
?>
	    <form method="post" action="command.php">
		<table>
		<tr>
		<td valign="top">
		<Strong>Command <? echo $j ?>:</strong>
		<br>
		<input type="hidden" name="cmdForm" value="y">
		<textarea name="shCmd"  cols="<? echo SHELL_INPUT_COLS; ?>" 
		rows="<? echo strlen(ereg_replace("[^\n]", "", 
			$histCmd[$j])) + 2; ?>"><? echo escBrowserSpecialChars($histCmd[$j]) ?></textarea>
		<br>
		<input type="checkbox" name="addNl" value="y"
			<? if (isset($histAddNl[$j])) echo "checked"; ?>
			> Add trailing newline
<?
	    if ($setOptions & OPT_ALLOWSILENT) {
?>
		&nbsp;
		<input type="checkbox" name="silent" value="y"
			<? if (isset($histSilent[$j])) echo "checked"; ?>
		> &gt; /dev/null
<?
	    } // if 
?>
		<br>
	    	<input type=submit name="sendCmd" 
			value="Execute command <? echo $j ?>">
		</td>
		</tr>
		</table>
	    </form>
<?
	} // for */
?>
        <form action="history_html.php" method="post">
            <input type="hidden" name="cmdStart" value="<? echo $cmdStart ?>">
<?
            if ($cmdStart > 1) {
?>
                <input type="submit" value="Previous" name="prevHist">
<?
            } // if 
?>
<?
            if ($cmdStart + $historyBlockSize <= $cmdNum) {
?>
                <input type="submit" value="Next" name="nextHist">
<?
            } // if 
?>
	</form>

	<form action="command.php" method="post">
	    <input type="submit" name="clrHist" value="Clear history">
	</form>
<?
    } // if
?>
</body>

</html>
