<?
// command_html.inc - HTML specific command page code
//
// 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.
//
// -------------------------------------------------------------------
//
// ******************** Display Functions ********************

// Display shell output and scrolling buttons as appropriate
//
function displayShellOutputWindow($printableNextBlock, $outputBufLen, 
	$outputPos, $lastOutputBlockSize, $outputWindowSize, $srchStr) {
?>
    <table border="1" width="100%" cellspacing="0">
    <tr>
        <td bgcolor="#80FF80">
	<font size="+1">
	<strong>Shell output</strong>
	</font>
	
        </td>
    </tr>
<?
    if (strlen($printableNextBlock) > 0) {
?>
    <tr>
        <td bgcolor="#B0FFB0">
	
<?	
            echo '<strong><font face="courier" color="#600060">' . 
                nl2br(escBrowserSpecialChars($printableNextBlock)) .  
		"</font></strong>";
?>
        </td>
    </tr>
<?
    } // if 
?>
    <tr>
        <td bgcolor="#D0FFF0">
<?
            $charsRemaining = $outputBufLen - $outputPos - $lastOutputBlockSize;
            echo "<p>" .  $charsRemaining .
	            " chars remaining, [total: " . $outputBufLen .
	            ", current: " . $outputPos . 
	            ", this screen: " . $lastOutputBlockSize . "]" .  "</p>";
?>
            <form action="command.php" method="post" name="scrollForm"
	    	onsubmit="return scrollFormValidator(this)">
	        <input type="hidden" name="scrForm" value="y">

	        <p>
<?
                    if ($outputPos > 0) 
	                echo '<input type="submit" name="scrPrev" value="<"' .
			    'onclick="javascript:checkSS=0;"> ';
                    if ($outputPos + $lastOutputBlockSize < $outputBufLen) 
	                echo '<input type="submit" name="scrNext" value=">"' .
			    'onclick="javascript:checkSS=0;"> ';
                    if ($outputPos > $outputWindowSize) 
	                echo '<input type="submit" name="scrTop" value="<<"' .
			    'onclick="javascript:checkSS=0;"> ';
                    if ($outputPos + $lastOutputBlockSize + $outputWindowSize 
			    	< $outputBufLen) 
	                echo '<input type="submit" name="scrBot" value=">>"' .
			    'onclick="javascript:checkSS=0;">';
?>
<?
	if ($charsRemaining > 0 || $outputPos > 0) {
?>
	            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
	            <strong>Search: </strong>
	            <input size="20" type="text" name="srchStr" 
		            value="<? if (isset($srchStr))
			    echo escBrowserSpecialChars($srchStr); ?>">
<?
	    if ($charsRemaining > 0) {
?>
	            <input type="submit" name="fwdSrch" value="Forward"
		    	onclick="javascript:checkSS=1;">
<?
	    } // if 
?>
<?
	    if ($outputPos > 0) {
?>
	            <input type="submit" name="backSrch" value="Backward"
		    	onclick="javascript:checkSS=1;">
<?
	    } // if 
?>
<?
	} // if 
?>
	        </p>
            </form>
<script language="JavaScript">
<!--
function scrollFormValidator(theForm)
{
    if (checkSS == 1 && theForm.srchStr.value == "") {
	alert("Please supply a search string");
	theForm.srchStr.focus();
	return false;
    }
    return true;
}
//-->
</script>
        </td>
    </tr>

    </tr>
</table>
<?
} // displayShellOutputWindow
?>



<?

// Create the shell input form


function displayShellInputForm($setOptions, $cmdNum, $numSc, $scName)
{
?>
    <form action="command.php" method="post" name="shellInput">
        <input type="hidden" name="cmdForm" value="y">

        <table bgcolor="#FFCCCC" border="1" width="100%" cellspacing="0" 
			cellpadding="3">
        <tr>
            <td colspan="2" bgcolor="#FFAAAA">
	    	<font size="+1"> <strong> Shell input</strong> </font>
            </td>
        </tr>
<?
if (($setOptions & (OPT_ALLOWSHELLCMD | OPT_ALLOWCONTROLCHARS)) != 0) {
?>
<?
    if (($setOptions & OPT_ALLOWSHELLCMD) != 0) {
?>
        <tr>
	    <td colspan="2">
	        <table border="0">
                <tr>
                    <td>
	                <textarea name="shCmd" cols="<? echo SHELL_INPUT_COLS; ?>" rows="3"></textarea>
			<br>
	                <input type="checkbox" value="y" name="addNl"	
			    	checked
		                <? // Make checkbox "sticky"
		                   // if (isset($addNl)) echo "checked"; ?>
	                > 
		        Add trailing newline
<?
        if ($setOptions & OPT_ALLOWSILENT) {
?>
	                &nbsp; &nbsp; 
	                <input type="checkbox" value="y" 
			    	name="silent"> &gt; /dev/null
<?
        } // if 
?>
			&nbsp; &nbsp; &nbsp; &nbsp; 
    			Hidden input 
			<input type="password" name="shPwd" size="15">
			<br>
    		    <br>
	                <input type="submit" name="sendCmd" value="Send">
<?
        if ($cmdNum >= 1 && ($setOptions & OPT_HISTORY)) {
?>
			&nbsp; &nbsp; &nbsp; &nbsp; 
			&nbsp; &nbsp; &nbsp; &nbsp; 
			&nbsp; &nbsp; &nbsp; &nbsp; 
			&nbsp; &nbsp; &nbsp; &nbsp; 
			&nbsp; &nbsp; &nbsp; &nbsp; 
    			<input type="submit" name="repPrev" 
				value="Repeat previous input">
		        &nbsp; &nbsp; &nbsp; 
                        <a href="history_html.php">History (<? echo $cmdNum?>)</a>
<?
       } // if 
?>
    		    <br>
	            </td>
	        </tr>
	    </table>
        </td>
<?
    } // if 
?>

<!--
        <p>Send signal:
            <input type="submit" name="sigint" value="Interrupt (^C)">
            <input type="submit" name="sigquit" value="Quit (^\)">
            <input type="submit" name="sigstop" value="Suspend (^Z)">
        </p>
-->
<?
    if (($setOptions & OPT_ALLOWCONTROLCHARS) != 0) {
	
?>
    	<tr>
        <td valign="top" colspan="2">
	    <table border="0">
	        <tr>
	            <td> 
		    <strong>Control chars:</strong>
                        <input type="submit" name="eofChar" value="^D">
			&nbsp;
                        <input type="submit" name="intChar" value="^C">
			&nbsp;
                        <input type="submit" name="quitChar" value="^\">
			&nbsp;
                        <input type="submit" name="suspChar" value="^Z">
			&nbsp;
                        <input type="submit" name="escChar" value="Escape">
			&nbsp; 
                        <input type="submit" name="sendCtrl" 
				value="Ctrl-"><input type="text" size="1" 
				maxlength="1" name="ctrlChar">
	            </td>
	        </tr>
	        </table>
            </td>
    	</tr>
<?
    } // if 
?>
<?
} // if
?>
	    <tr>
<?
    if (($setOptions & OPT_DISPLAYMENU) && $numSc > 0) {
	$menuDisplayed= true;
?>
	    <td>
            <strong>Shortcuts:</strong>
	        <select name="shortcutCmd">
<?	
	        print "<option value=\"\">" . "</option>";
	        for ($j = 0; $j < $numSc; $j++)
	            print "<option value=\"$j\">" . $scName[$j] . "</option>";
?>
	        </select>
	
	        <input type="submit" name="doShCut" value="Do it">
	        </td>
<?
    } // if 
?>
	        <td <? if (!$menuDisplayed) echo 'colspan="2" align="right"'; ?>> 
		    <input type="submit" name="chkOut" value="Check output"> 
		    &nbsp;
	            <input type="submit" name="logout" value="Logout"> 
		</td>
	    </tr>
	
        </table>
	    
    </form>
<?
}  // displayShellInputForm
?>
