<? session_start();
	$strCRLF = chr(13) . chr(10);

	if (!isset($_SESSION["SessionFilter"]))
	{
		$_SESSION["SessionFilter"] = "";
	}

	if (!isset($_SESSION["IncludeDebug"]))
	{
		$_SESSION["IncludeDebug"] = "Yes";
	}

	if (!isset($_SESSION["IncludeServer"]))
	{
		$_SESSION["IncludeServer"] = "No";
	}

//**************************************************************************************************************************************
//Event 1:  QS cmdFilter
//**************************************************************************************************************************************

	if (isset($_POST["txtFilter"]))	
	{
		if ($_POST["txtFilter"] != "") 
		{
			$_SESSION["SessionFilter"] = $_POST["txtFilter"];
		}
		else
		{
		$_SESSION["SessionFilter"] = "";
		}
	}

//**************************************************************************************************************************************
//Event 2: QS ChangeDebug: de Debug-check aangezet of niet. Mode ligt vast in Session("IncludeDebug")="Yes/No"
//**************************************************************************************************************************************

	if (isset($_POST["hiddenEventToggleDebug"]) && $_POST["hiddenEventToggleDebug"] == "Yes")	
	{
		if ($_SESSION["IncludeDebug"] == "Yes") 
		{
			$_SESSION["IncludeDebug"]="No";
		}
		else
		{
			$_SESSION["IncludeDebug"]="Yes";
		}
	}	

//**************************************************************************************************************************************
//Event 2: QS ChangeDebug: de Debug-check aangezet of niet. Mode ligt vast in Session("IncludeServer")="Yes/No"
//**************************************************************************************************************************************

	if (isset($_POST["hiddenEventToggleServer"]) && $_POST["hiddenEventToggleServer"] == "Yes")	
	{
		if ($_SESSION["IncludeServer"] == "Yes") 
		{
			$_SESSION["IncludeServer"]="No";
		}
		else
		{
			$_SESSION["IncludeServer"]="Yes";
		}
	}	


/******************************************************************************************************************************************************************/
/* frmMain POST - event handler: hiddenEventZzzz 
/******************************************************************************************************************************************************************/

	if (isset($_POST["hiddenDeleteSession"]) && $_POST["hiddenDeleteSession"]  != "")
		{
			$strSessionVar = $_POST["hiddenDeleteSession"];
			unset($_SESSION[$strSessionVar]);
		}
?>
<html>
<head>
<title>$_SESSION VARIABLES</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../CSS/IDS.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="#000000" topmargin="4">
<form name="frmMain" id="frmMain" method="post" action="session.php">
  <table width="860" border="0" cellpadding="0" cellspacing="0">
    <!--DWLayoutTable-->
    <tr>
      <td width="517" height="24" valign="top" class="N W S ">Filter:
        <input type="text" name="txtFilter" value="<?=$_SESSION["SessionFilter"]?>" onKeyPress="return handleEnter(this, event)" onMouseUp="this.select()">
        <input name="cmdFilter" type="submit" class="CmdPopUp" id="cmdFilter" value="Filter">
        <input name="cmdRefresh" type="submit" class="CmdPopUp" id="cmdRefresh" value="Refresh">
        <input type="checkbox" name="checkDebug" class="CheckZonderLabelDonker" onClick=ChangeDebug() <? if ($_SESSION["IncludeDebug"] == "Yes") {print " CHECKED";}?>>
        include debug </td>
      <td width="173"valign="top" class="N S "><input type="checkbox" name="checkServer" class="CheckZonderLabelDonker" onClick=ChangeServer() <? if ($_SESSION["IncludeServer"] == "Yes") {print " CHECKED";}?>>
      include server </td>
    <td width="170" align="right"  class="N E S ">
	<input name="cmdKillSession" type="submit" class="CmdPopUp" value="Kill session and cookie" style="width: 120px">&nbsp;
	</td>
    </tr>
  </table>
  <br>
  <?
// ======================================================================================================================================
// Debug items:
// ======================================================================================================================================
	if ($_SESSION["IncludeDebug"] == "Yes")
	{
?>
  <table width="860" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td height="9" valign="top" class="HeaderRow" colspan="3">Debug:</td>
    </tr>
    <?
	# store $_SESSION in an array and sort it
	$ArraySession = $_SESSION;
	ksort($ArraySession);

	foreach ($ArraySession as $key=>$val)
	{
		$strSessionItem = $key;
		$strSessionValue = $val;
		
		if ((strpos(strtoupper($strSessionItem),strtoupper("DEBUG")) === 0 || strtoupper($strSessionItem) == strtoupper("DEBUG")) && $strSessionItem != "IncludeDebug")
		{
?>
    <tr>
      <td width="251" height="14" valign="top" class="CellBorderSW"><?=fnNbsp($strSessionItem)?></td>
      <td width="10" height="14" valign="top" class="CellBorderS" style="cursor:pointer" onClick="Delete('<?=$strSessionItem?>')">X</td>
      <td valign="top" width="609" class="CellBorderWSE"><?=fnNbsp(str_replace($strCRLF, "<br>", $strSessionValue))?></td>
    </tr>
    <?		
		}
	}
?>
  </table>
  <br>
  <? 
	}

// ======================================================================================================================================
// Session variables
// ======================================================================================================================================
?>
<br>
  <table width="860" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td height="9" valign="top" class="HeaderRow" colspan="3">Session variables:</td>
    </tr>
    <?
	//List de session-variabelen in een tabel
	$ArraySession = $_SESSION;
	ksort($ArraySession);
	
	$iTimer = 0;
	$iTimerThis = 0;

	foreach ($ArraySession as $key=>$val)
	{
		$strSessionItem = $key;
		$strSessionValue = $val;

		if ((strpos(strtoupper($strSessionItem),strtoupper("DEBUG")) == 0 and strtoupper($strSessionItem) != strtoupper("DEBUG")) and $strSessionItem != "IncludeDebug" and $strSessionItem != "IncludeServer" && $strSessionItem != "SessionFilter")
		{
			if ($_SESSION["SessionFilter"] == "" or substr_count(strtoupper($strSessionItem),strtoupper($_SESSION["SessionFilter"])) > 0)
			{
			
			
				
?>
    <tr>
      <td width="251" height="14" valign="top" class="CellBorderSW"><?=$strSessionItem?></td>
      <td width="10" height="14" valign="top" class="CellBorderS" style="cursor:pointer" onClick="Delete('<?=$strSessionItem?>')">X</td>
<?
				if (substr($strSessionItem,0,5) == "Timer")
				{
					#0.37856200 1325578008
					$strMS = floatval(substr($strSessionValue,0,10));
					$strS  = floatval(substr($strSessionValue,11,10));
					if ($iTimer == 0)
					{
						$iTimer = $strS + $strMS;
						$iTimerStart = $strS + $strMS;
					}
					elseif ($strMS > 0 && $strS > 0)
					{
						$iTimerPrev = $iTimerThis;
						$iTimerThis = $strS + $strMS - $iTimer;
						$iTimer = $strS + $strMS;
					}
?>					
      <td valign="top" width="619" class="CellBorderWSE" style="color:#0000FF"><?=number_format($iTimer - $iTimerStart,6,'.','')?> s - <?=number_format($iTimerThis,6,'.','')?> s</td>
<?
				}
				elseif (is_array($strSessionValue))
				{
?>
      <td valign="top" width="619" class="CellBorderWSE"><? print '<pre>'.print_r($strSessionValue, 1 ).'</pre>'?></td>
<?
				}
				else
				{
?>
      <td valign="top" width="619" class="CellBorderWSE"><?=fnNbsp(str_replace($strCRLF, "<br>", $strSessionValue))?></td>
<?
				}
?>				
    </tr>
    <?	
			}	
		}
	}
?>
  </table>
  <?

// ======================================================================================================================================
// Server variables
// ======================================================================================================================================
  
	if ($_SESSION["IncludeServer"] == "Yes")
	{
?>
  <br>
  <table width="860" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td height="9" valign="top" class="HeaderRow" colspan="3">Session parameters:</td>
    </tr>
    <tr>
      <td width="251" height="14" valign="top" class="CellBorderSW">Session.SessionID</td>
      <td valign="top" width="619" class="CellBorderWSE"><?=fnNbsp(session_id())?></td>
    </tr>
    <tr>
      <td width="251" height="14" valign="top" class="CellBorderSW">Session.TimeOut</td>
      <td valign="top" width="619" class="CellBorderWSE"><?=fnNbsp(ini_get("session.gc_maxlifetime"))?></td>
    </tr>
  </table>
  <br>
  <table width="860" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td height="9" valign="top" class="HeaderRow" colspan="3">Server variables:</td>
    </tr>
    <?
		
	$serverArray = $_SERVER;
		
	foreach ($serverArray as $key=>$val)
	{
		$strSessionItem = $key;
		$strSessionValue = $val;
		
?>
    <tr>
      <td width="251" height="14" valign="top" class="CellBorderSW"><?=fnNbsp($strSessionItem)?></td>
      <td valign="top" width="619" class="CellBorderWSE"><?=fnNbsp($strSessionValue)?></td>
    </tr>
    <?
	}	#Next 
?>
  </table>
  <?
	}
?>
  <input name="hiddenEventToggleDebug" type="hidden" value="">
  <input name="hiddenEventToggleServer" type="hidden" value="">
  <input name="hiddenDeleteSession" type="hidden" value="">
  <script type="text/javascript" language="JavaScript">

	function handleEnter (field, event) 
		{
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) 
			{
			document['frmMain'].submit()
			} 
		else
		return true;
		}      

	function ChangeDebug()  
		{
		document.frmMain.hiddenEventToggleDebug.value = "Yes"
		document['frmMain'].submit()
		}

	function ChangeServer()  
		{
		document.frmMain.hiddenEventToggleServer.value = "Yes"
		document['frmMain'].submit()
		}

	function Delete(strSession)
		{
			document.frmMain.hiddenDeleteSession.value = strSession
			document['frmMain'].submit()
		}

</script>
</form>
</body>
</html>
