<%!

/**********************************************************************
**
**     SAP AG Walldorf
**     (C) Copyright SAP AG 1999-2010
**
***********************************************************************/

#include "publicincl/tools.inc"

struct wdisp_session_info_type
{
  boolean store_hash;
  int	  max_logon_groups;
  int    entry_timeout;
  int    entry_count;
  int    peek_count;
  int    max_count;
  int    mem_usage;
  boolean overflow_flag;
};
struct wdisp_session_entry_type
{
  string sid;
  string logon_group;
  int    sessionid;
  string server_inst;
  string last_used;
  int    use_count;
  string is_default_server;
};
struct wdisp_logon_group_entry_type
{
  int	 group_index;
  string sid;
  string group_name;
  string default_server_inst;
  string default_server_last_used;
};
%>

<%
  int count, rc, dir;
  string browser, sstr;
  string tabsel;
  int i, nr;
  struct wdisp_session_info_type wdisp_session_info;
  struct wdisp_session_entry_type wdisp_session_entry[];
  struct wdisp_logon_group_entry_type wdisp_logon_group_entry[];
  struct icm_sort_type sort_tab[];

  const string ssort = "../public/images/sort.gif";
  const string sasc = "../public/images/sortasc.gif";
  const string sdesc = "../public/images/sortdesc.gif";

  string tab_header[3];
  string tab_content[3];
  string tab_tabsel[3];

  tab_header[0] = "Show session dispatching info";
  tab_header[1] = "Show logon groups";
  tab_header[2] = "Show contents of dispatching table";

  tab_tabsel[0] = "tab0";
  tab_tabsel[1] = "tab1";
  tab_tabsel[2] = "tab2";

  browser = __icm_get_browser_type();
  dir  = __icm_get_form_field ("dir");
  sstr = __icm_get_form_field ("sstr");

  tabsel = anumenc(__icm_get_form_field ("tabsel"));
  if (tabsel == "")
    tabsel = "tab0";
 
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  <html>
    <head>
      <link rel=stylesheet type="text/css" href="../public/css/controls_<%=browser%>.css">
      <link rel=stylesheet type="text/css" href="../public/css/sapbsp.css">
      <title> Table test </title>
      <script language="JavaScript" type="text/javascript">
      <!--
      function callSubmitAction(form,value)
      {
      var Form = document[form];
      Form.tabsel.value = value;
      Form.submit();
      }
      function callSortAction(form,tabsel,dir,sstr)
      {
      var Form = document[form];
      Form.tabsel.value = tabsel;
      Form.dir.value = dir;
      Form.sstr.value = sstr;
      Form.submit();
      }
      //-->
      </script>
    </head>
    <body class="sapBdy">
    <table border="0" cellspacing="0" cellpadding="0" class="sapTbvAlt" width="100%">
    <tr>
      <td class="sapTbvCellAlt">
	<b><i>Session Dispatching Monitor</i></b>
      </td>
      <td class="sapTbvCellAlt" align="right">
	<nobr></nobr>
      </td>
      <td class="sapTbvCellAlt" align="right">
	<a href="javascript:location.reload()" class="sapBtnEmph" title="refresh page"><nobr>Refresh</nobr></a>
      </td>
    </tr>
    <tr>
    <td class="sapTbvCellStd" Colspan="3">
    <form action="" method="GET" name="FormTabStrip">
      <input type="hidden" name="tabsel" value="">
      <input type="hidden" name="sstr" value="">
      <input type="hidden" name="dir" value="">
	<table border="0" cellpadding="0" cellspacing="0" width="100%">
	  <tr>
	    <td valign="top">
	      <br>
		<table border="0" cellpadding="0" cellspacing="0" width="100%">
		  <tr valign="top">
		    <td>
		      <!--HEADERS-->
		      <table border="0" cellpadding="0" cellspacing="0">
			<tr>
			  <!--HEADER ITEM-->
			  <td nowrap></td>
<%
    for (nr = 0; nr < 3; nr++) {
%>
			  <td nowrap
<%
      if (tab_tabsel[nr] == tabsel)
      {
%>
			    class="sapTbsTabSel">
			    <a name="page_top"></a>
			    <a title="<%=tab_header[nr]%>" class="sapLnk" OnMouseOver="window.status = '<%= tab_header[nr] %>'; return true;"
			     style="text-decoration:none">
			     <b>
				<%=tab_header[nr]%>
			      </b>

<%    } 
      else
      {
%>
			    class="sapTbsTab">
			    <a title="<%=tab_header[nr]%>" class="sapLnk" OnMouseOver="window.status = '<%= tab_header[nr] %>'; return true;"
			    href="javascript:callSubmitAction('FormTabStrip',
			       '<%= tab_tabsel[nr] %>')"
			     style="text-decoration:none">
				<%=tab_header[nr]%>
<%    }
%>
			    </a>
			  </td>
<%
   }
%>
			  <!--HEADER ITEM END-->
			  <td nowrap class="sapTbsTabBlk"> </td>
			</tr>
		      </table>
		      <!--HEADER END-->
		      <!--CONTENTS-->
		      <table class="sapTbsWhl" border="0" cellspacing="0" cellpadding="0"
			width="100%">
			<tr>
			  <td align="left" valign="top">
<%
    if (tabsel == "tab0") {
      rc = __wdisp_session_hdl (1, wdisp_session_info);
      if (rc == -1) {
%>
			    <table border="0" cellspacing="0" cellpadding="0" class="sapTbvAlt" width="100%">
			      <tr>
				<td class="sapTbvCellAlt" Colspan="2">
				  <b><i>No information available</i></b>
				</td>
			      </tr>
			    </table>
<%
      } else {
%>
			    <table border="0" cellspacing="0" cellpadding="0" class="sapTbvAlt" width="100%">
			      <tr><td class="sapTbvCellAlt" Colspan="3">&nbsp;</td></tr>
			      <tr>
				<td class="sapTbvCellStd">Max. number of logon groups:</td>
				<td class="sapTbvCellStd"><%= wdisp_session_info.max_logon_groups %></td>
				<td class="sapTbvCellStd">&nbsp;</td>
			      </tr>
			      <tr>
				<td class="sapTbvCellStd">Logon group support:</td>
				<td class="sapTbvCellStd"><%= wdisp_session_info.store_hash %></td>
				<td class="sapTbvCellStd">&nbsp;</td>
			      </tr>
			      <tr>
				<td class="sapTbvCellStd">Size of shared memory table:</td>
				<td class="sapTbvCellStd"><%= wdisp_session_info.mem_usage %> (Bytes)</td>
				<td class="sapTbvCellStd">&nbsp;</td>
			      </tr>
			      <tr>
				<td class="sapTbvCellStd">Entry timeout:</td>
				<td class="sapTbvCellStd"><%= wdisp_session_info.entry_timeout %> (sec)</td>
			  	<td class="sapTbvCellStd" align="right">
				    <a accesskey="p" onKeyUp="javascript:callUrlWithKey(event,80,'./confirm.icp?what=wdisp_session_purge&amp;timeout=<%= wdisp_session_info.entry_timeout %>')"
				       href="./confirm.icp?what=wdisp_session_purge&amp;timeout=<%= wdisp_session_info.entry_timeout %>" class="sapBtnStd">
					<nobr><u>P</u>urge outdated entries</nobr></a>
				</td>
			      </tr>
			      <tr>
				<td class="sapTbvCellStd">Max. number of entries:</td>
				<td class="sapTbvCellStd"><%= wdisp_session_info.max_count %>
<%
				  if (wdisp_session_info.overflow_flag)
				  __output (" (already reached)");
				  else
				  __output (" (not reached)");
%>
				</td>
				<td class="sapTbvCellStd">&nbsp;</td>
			      </tr>
			      <tr>
				<td class="sapTbvCellStd" width="250">
				  Current number of entries in table:
				</td>
				<td class="sapTbvCellStd"><%= wdisp_session_info.entry_count %></td>
				<td class="sapTbvCellStd" align="right">&nbsp;</td>
			      </tr>
			      <tr>
				<td class="sapTbvCellStd" width="250">
				  Peek number of entries in table:
				</td>
				<td class="sapTbvCellStd"><%= wdisp_session_info.peek_count %></td>
				<td class="sapTbvCellStd" align="right">&nbsp;</td>
			      </tr>
			      <tr>
				<td class="sapTbvCellStd">Maximum table entries reached:</td>
				<td class="sapTbvCellStd"><%= wdisp_session_info.overflow_flag %></td>
				<td class="sapTbvCellStd">&nbsp;</td>
			      </tr>
			    </table>
<%
      }
    }
    else if (tabsel == "tab1") 
    {
       count = __wdisp_session_hdl (4, wdisp_logon_group_entry);
       if (sstr != "")
         sort (wdisp_logon_group_entry, dir, sstr);

  sort_tab[0].header = "No.";
  sort_tab[0].tool = "Sort by index";
  sort_tab[0].ffield = "group_index";
  sort_tab[1].header = "SID";
  sort_tab[1].tool = "Sort by SAP System Id";
  sort_tab[1].ffield = "sid";
  sort_tab[2].header = "Logon Group Name";
  sort_tab[2].tool = "Sort by Logon Group name";
  sort_tab[2].ffield = "group_name";
  sort_tab[3].header = "Default Server Instance";
  sort_tab[3].tool = "Sort by default Server Instance";
  sort_tab[3].ffield = "default_server_inst";
  for (i=0; i<arraylen(sort_tab);i++){
   sort_tab[i].url = ssort;
   sort_tab[i].dir = 0;
  }

  for (i=0; i<arraylen(sort_tab);i++){
   if (sstr == sort_tab[i].ffield){
    if (dir == 1) { sort_tab[i].url = sdesc; sort_tab[i].dir = -1; }
    else if (dir == -1) { sort_tab[i].url = sasc; sort_tab[i].dir = 1; }
    else sort_tab[i].dir = 1;
   }
   else sort_tab[i].dir = 1;
  }
%>
    <table cellspacing=1 width="100%" class="sapTbvAlt">
      <tr>
	<td class="sapTbvCellAlt" colspan="2">
	  <b><i>Logon Groups</i></b>
	</td>
	<td class="sapTbvCellAlt" align="center" colspan="1">
	</td>
	<td class="sapTbvCellAlt" align="right" colspan="2">
	  <nobr>
	  <a href="#page_top"><nobr><img width=15 height=15 src="../public/images/tableview/top_off.gif" BORDER=0 title="Top of page"></nobr></a>
	  <a href="#page_bottom"><nobr><img width=15 height=15 src="../public/images/tableview/bottom.gif" BORDER=0 title="Bottom of page"></nobr></a>
	</td>
      </tr>
      <tr>
<%
	for (i=0;i<arraylen(sort_tab);i++) {
%>
	  <th align="left" class="sapTbvCellAlt"><nobr>
	    <i><%=sort_tab[i].header%></i>

	    <a href="javascript:callSortAction('FormTabStrip','<%=tab_tabsel[1]%>','<%=sort_tab[i].dir%>','<%=sort_tab[i].ffield%>')" class="sapBtnStd:link"><img src="<%=sort_tab[i].url%>" title="<%=sort_tab[i].tool%>" alt="" border="0"></a></nobr>
	  </th>
<%
	}
%>
	<th align="left" class="sapTbvCellAlt"><i>Last usage</i></th>
      </tr>
<%
	for (nr = 0; nr < count; nr++)
	{
%>
			      <tr>
				<td class="sapTbvCellStd"><%= wdisp_logon_group_entry[nr].group_index %></td>
				<td class="sapTbvCellStd"><%= wdisp_logon_group_entry[nr].sid %></td>
				<td class="sapTbvCellStd"><%= wdisp_logon_group_entry[nr].group_name %></td>
				<td class="sapTbvCellStd"><%= wdisp_logon_group_entry[nr].default_server_inst %></td>
				<td class="sapTbvCellStd"><%= wdisp_logon_group_entry[nr].default_server_last_used %></td>
			      </tr>
<%
	}
    	if (count > 100) {
%>
    <tr>
      <a name="page_bottom"></a>
      <td class="sapTbvCellAlt" width="150" colspan="2">
        <b><i>Table Entries</i></b>
      </td>
      <td class="sapTbvCellAlt" align="center" colspan="1"></td>
      <td class="sapTbvCellAlt" align="right" colspan="2">
        <nobr>
          <a href="#page_top"><nobr><img width=15 height=15 src="../public/images/tableview/top.gif" BORDER=0 title="Top of page"></nobr></a>
          <a href="#page_bottom"><nobr><img width=15 height=15 src="../public/images/tableview/bottom_off.gif" BORDER=0 title="Bottom of page"></nobr></a>
      </td>
    </tr>
  </table>
<%
	}
    }
    else
    {
       count = __wdisp_session_hdl (2, wdisp_session_entry);
       if (sstr != "")
         sort (wdisp_session_entry, dir, sstr);

  sort_tab[0].header = "SID";
  sort_tab[0].tool = "Sort by SAP System Id";
  sort_tab[0].ffield = "sid";
  sort_tab[1].header = "Logon Group";
  sort_tab[1].tool = "Sort by Logon Group";
  sort_tab[1].ffield = "logon_group";
  sort_tab[2].header = "Session Id Hash";
  sort_tab[2].tool = "Sort by Session Id Hash";
  sort_tab[2].ffield = "sessionid";
  sort_tab[3].header = "Destination Server";
  sort_tab[3].tool = "Sort by Destination Server name";
  sort_tab[3].ffield = "server_inst";
  sort_tab[4].header = "Dispatch Count";
  sort_tab[4].tool = "Sort by number of dispatched requests";
  sort_tab[4].ffield = "use_count";
  for (i=0; i<arraylen(sort_tab);i++){
   sort_tab[i].url = ssort;
   sort_tab[i].dir = 0;
  }

  for (i=0; i<arraylen(sort_tab);i++){
   if (sstr == sort_tab[i].ffield){
    if (dir == 1) { sort_tab[i].url = sdesc; sort_tab[i].dir = -1; }
    else if (dir == -1) { sort_tab[i].url = sasc; sort_tab[i].dir = 1; }
    else sort_tab[i].dir = 1;
   }
   else sort_tab[i].dir = 1;
  }
%>
			    <table cellspacing=1 width="100%" class="sapTbvAlt">
			      <tr>
	      		        <td class="sapTbvCellAlt" colspan="4">
        			  <b><i>Table Entries</i></b>
			        </td>
			        <td class="sapTbvCellAlt" align="center" colspan="1">
			        </td>
			        <td class="sapTbvCellAlt" align="right" colspan="3">
			          <nobr>
			          <a href="#page_top"><nobr><img width=15 height=15 src="../public/images/tableview/top_off.gif" BORDER=0 title="Top of page"></nobr></a>
			          <a href="#page_bottom"><nobr><img width=15 height=15 src="../public/images/tableview/bottom.gif" BORDER=0 title="Bottom of page"></nobr></a>
			        </td>
			      </tr>
			      <tr>
				<th align="left" class="sapTbvCellAlt"><i>No.</i></t>
<%
	for (i=0;i<arraylen(sort_tab);i++) {
%>
	  <th align="left" class="sapTbvCellAlt"><nobr>
	    <i><%=sort_tab[i].header%></i>

	    <a href="javascript:callSortAction('FormTabStrip','<%=tab_tabsel[2]%>','<%=sort_tab[i].dir%>','<%=sort_tab[i].ffield%>')" class="sapBtnStd:link"><img src="<%=sort_tab[i].url%>" title="<%=sort_tab[i].tool%>" alt="" border="0"></a></nobr>
	  </th>
<%
	}
%>
				<th align="left" class="sapTbvCellAlt"><i>Last Used</i></th>
				<th align="left" class="sapTbvCellAlt"><i>Default Server</i></th>
			      </tr>
<%
	for (nr = 0; nr < count; nr++)
	{
%>
			      <tr>
				<td class="sapTbvCellStd"><%= nr %></td>
				<td class="sapTbvCellStd"><%= wdisp_session_entry[nr].sid %></td>
				<td class="sapTbvCellStd"><%= wdisp_session_entry[nr].logon_group %></td>
				<td class="sapTbvCellStd"><%= wdisp_session_entry[nr].sessionid %></td>
				<td class="sapTbvCellStd"><%= wdisp_session_entry[nr].server_inst %></td>
				<td class="sapTbvCellStd"><%= wdisp_session_entry[nr].use_count %></td>
				<td class="sapTbvCellStd"><%= wdisp_session_entry[nr].last_used %></td>
				<td class="sapTbvCellStd"><%= wdisp_session_entry[nr].is_default_server %></td>
			      </tr>
<%
	}
    	if (count > 100) {
%>
    <tr>
      <a name="page_bottom"></a>
      <td class="sapTbvCellAlt" width="150" colspan="2">
        <b><i>Table Entries</i></b>
      </td>
      <td class="sapTbvCellAlt" align="center" colspan="1"></td>
      <td class="sapTbvCellAlt" align="right" colspan="2">
        <nobr>
          <a href="#page_top"><nobr><img width=15 height=15 src="../public/images/tableview/top.gif" BORDER=0 title="Top of page"></nobr></a>
          <a href="#page_bottom"><nobr><img width=15 height=15 src="../public/images/tableview/bottom_off.gif" BORDER=0 title="Bottom of page"></nobr></a>
      </td>
    </tr>
  </table>
<%
	}
    }
%>


			  </td>
			</tr>
		      </table>
		      <!--CONTENTS END-->
		    </td>
		  </tr>
		</table>
	    </td>
	  </tr>
	</table>
    </form>
    </td>
    </tr>
    </table>
    </body>
  </html>
