<%!

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

#include "publicincl/tools.inc"

struct icm_conn_info_type
{
  string role;
  string protocol;
  string status;
  int port_local;
  int port_peer;
  string addr_local;
  string addr_peer;
  int nihdl;
  int conn;
  int guid;
  string conn_time;
  int proc_timeout;
  int keep_alive_timeout;
};
%>
<%
int    i, nr, dir, max;
int    rc;
string browser, appl;
string sstr;

struct icm_sort_type sort_tab[];
struct icm_conn_info_type icm_conn_tab[];

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

sort_tab[0].header = "Conn ID";
sort_tab[0].tool = "Sort by unique connection identifier";
sort_tab[0].ffield = "conn";
sort_tab[1].header = "Protocol";
sort_tab[1].tool = "Sort by used protocol";
sort_tab[1].ffield = "protocol";
sort_tab[2].header =  "Role";
sort_tab[2].tool = "Sort by incoming (server) or outgoing (client) connection";
sort_tab[2].ffield = "role";
sort_tab[3].header = "Request Type";
sort_tab[3].tool = "Sort by currently executed operation";
sort_tab[3].ffield = "status";
sort_tab[4].header = "Peer Addr:Port";
sort_tab[4].tool = "Sort by peer IP address";
sort_tab[4].ffield = "addr_peer";
sort_tab[5].header = "Local Addr:Port";
sort_tab[5].tool = "Sort by local IP address";
sort_tab[5].ffield = "addr_local";
sort_tab[6].header = "Proc Timeout";
sort_tab[6].tool = "Sort by maximum request processing timeout in the server";
sort_tab[6].ffield = "proc_timeout";
sort_tab[7].header = "KA Timeout";
sort_tab[7].tool = "Sort by maximum keep alive timeout of unused connection";
sort_tab[7].ffield = "keep_alive_timeout";
sort_tab[8].header = "Connection Time";
sort_tab[8].tool = "Sort by connection establishing time";
sort_tab[8].ffield = "conn_time";
sort_tab[9].header = "NI";
sort_tab[9].tool = "Sort by internal Network Interface Identifier for this connection";
sort_tab[9].ffield = "nihdl";
max = arraylen(sort_tab);
for (i=0; i < max; i++){
  sort_tab[i].url = ssort;
  sort_tab[i].dir = 0;
}

browser = __icm_get_browser_type();
appl    = __icm_get_system_property ("app_name");
dir  = __icm_get_form_field ("dir");
sstr = __icm_get_form_field ("sstr");

__icm_get_conn_info (icm_conn_tab);
if (sstr != "")
  sort (icm_conn_tab, dir, sstr);

max = arraylen(sort_tab);
for (i=0; i < max; 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;
}
%>
<!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><%=appl%> Used Connections</title>
      <script language="JavaScript" type="text/javascript">
        <!--
        function callSubmitAction(dir,sstr)
        {
          document.sortForm.dir.value = dir;
          document.sortForm.sstr.value = sstr;
          document.sortForm.submit();
        }
        -->
      </script>
    </head>
    <body class="sapBdy">
      <form action="" name="sortForm" method="GET">
      <input type="hidden" name="dir" value="">
      <input type="hidden" name="sstr" value="">
      <table border=0 cellspacing=1 cellpadding=0 class="sapTbvAlt">
	<tr>
	  <td class="sapTbvCellAlt" Colspan="10">
	    <b><i><%=appl%> Active Connections </i></b>
	  </td>
	  <td class="sapTbvCellAlt" align="right">
	    <a href="javascript:parent.frames['main'].location.reload()" class="sapBtnEmph" title="refresh page"><nobr>Refresh</nobr></a>
	  </td>
	</tr>
	<tr>
	  <th align="left" class="sapTbvCellAlt">
	    <i>No.</i>
	  </th>
<%
        max = arraylen(sort_tab);
	for (i=0;i < max; i++) {
%>
	  <th align="left" class="sapTbvCellAlt"><nobr>
	    <i><%=sort_tab[i].header%></i>
	    <a href="javascript:callSubmitAction('<%=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>
<%
	}
%>
	</tr>
<%
        max = arraylen(icm_conn_tab);
	for (nr = 0; nr < max; nr++) {
%>
	<tr>
	  <td class="sapTbvCellStd"><%= nr %></td>
	  <td class="sapTbvCellStd">
	    (<%= icm_conn_tab[nr].conn %>/<%= icm_conn_tab[nr].guid %>)
	  </td>
	  <td class="sapTbvCellStd"><%= icm_conn_tab[nr].protocol %></td>
	  <td class="sapTbvCellStd"><%= icm_conn_tab[nr].role %></td>
	  <td class="sapTbvCellStd"><%= icm_conn_tab[nr].status %></td>
	  <td class="sapTbvCellStd">
	    <%= icm_conn_tab[nr].addr_peer %>:<%= icm_conn_tab[nr].port_peer %>
	  </td>
	  <td class="sapTbvCellStd">
	    <%= icm_conn_tab[nr].addr_local %>:<%= icm_conn_tab[nr].port_local %>
	  </td>
	  <td class="sapTbvCellStd"><%= icm_conn_tab[nr].proc_timeout %></td>
	  <td class="sapTbvCellStd"><%= icm_conn_tab[nr].keep_alive_timeout %></td>
	  <td class="sapTbvCellStd"><%= icm_conn_tab[nr].conn_time %></td>
	  <td class="sapTbvCellStd"><%= icm_conn_tab[nr].nihdl %></td>
	</tr>
<%
	}
%>
      </table>
     </form>
    </body>
  </html>
