<%!
/* */
struct icm_info_type
{
  int status;
  int pid;
  int ppid;
  string uptime;
  string cputime;
  int trace_level;
  int trace_lvl;
  int cur_thr;
  int peak_thr;
  int max_thr;
  int total_thr;
  int cur_conn;
  int peak_conn;
  int max_conn;
  int total_conn;
  int cur_queue;
  int peak_queue;
  int max_queue;
  int total_queue;
};

struct icm_thr_info_type
{
  string status;
  string rq_type;
  int rq_count;
  int conn;
  int guid;
  string thr_id;
};

/* */
static string get_stat (int status)
{
  switch (status) {
    case 0: return ("none"); break;
    case 1: return ("init"); break;
    case 2: return ("running"); break;
    case 3: return ("shutdown"); break;
    case 4: return ("down"); break;
    case 5: return ("maintenance"); break;
    default: return ("unknown");
  }
}
%>

<%
int    nr, rc, refresh_rate, t,h,m,s;
string browser, appl, what, lastControlID;
boolean is_admin;
string iconname[3];
struct icm_info_type icm_info;
struct icm_thr_info_type icm_thr_info[];

browser = __icm_get_browser_type();
appl    = __icm_get_system_property ("app_name");
is_admin = __icm_get_system_property ("is_admin");
what    = htmlenc(__icm_get_form_field ("what"));
lastControlID = htmlenc(__icm_get_form_field ("lastControlID"));

for (nr=0; nr<3;nr++){
  iconname[nr] = "../public/icons/s_s_space.gif";
}
if (what == "refresh") {
  refresh_rate = __icm_get_form_field ("p1");
  if (refresh_rate == 10)
    iconname[0] = "../public/icons/s_s_okay.gif";
  else
    iconname[1] = "../public/icons/s_s_okay.gif";
}
else
  iconname[2] = "../public/icons/s_s_okay.gif";

__icm_get_info (icm_info);
__icm_get_thr_info(icm_thr_info);
%>
<!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%> Monitor</title>
<% if (refresh_rate > 0){ %>
      <META http-equiv="refresh" content="<%=refresh_rate%>">
<% } %>
	<script type="text/javascript" src="../public/js/bspMenu.js"></script>
	<script type="text/javascript">
	  <!--
          window.onload = function() {
            initializeMenu ("ProcStatMenu", "statusObj");
            initializeMenu ("PeakMenu", "peakObj");
            initializeMenu ("TotalMenu", "totObj");
            initializeMenu ("ConfMenu", "confObj");
            restoreMenuFocus('<%=lastControlID%>');
          }
	  document.onclick=bspMenuHide;
          //-->
	</script>
    </head>
    <body class="sapBdy">
      <div id="ProcStatMenu" class="bspMenuBox" onMouseover="bspMenuHighlight(event)" onMouseout="bspMenuUnHighlight(event)" onClick="bspMenuSelect(event,'ProcStatMenu')" >

<% if (icm_info.ppid != 0) { %>
      <div title="Restart" class="bspMenuItem" url="./confirm.icp?what=restart_icm">Restart <%=appl%></div>
      <div title="Shutdown" class="bspMenuItem" url="./confirm.icp?what=shutdown_wd">Shutdown <%=appl%> Watchdog</div>
<% } else { %>
      <div title="Shutdown" class="bspMenuItem" url="./confirm.icp?what=shutdown_icm">Shutdown <%=appl%></div>
<% } %>

<% if (icm_info.status == 5) { %>
      <div title="Leave maintenance mode" class="bspMenuItem" url="./confirm.icp?what=change_maint&amp;p1=0">Leave maintenance mode</div>
<% } else { %>
      <div title="Enter maintenance mode" class="bspMenuItem" url="./confirm.icp?what=change_maint&amp;p1=1">Enter maintenance mode</div>
<% } %>
      <div title="Reload configuration" class="bspMenuItem" url="./confirm.icp?what=reinit_icm">Reload configuration</div>
      <hr>
      <div title="Close Menu" class="bspMenuItem">Close Menu</div>
      </div>

      <div id="PeakMenu" class="bspMenuBox" onMouseover="bspMenuHighlight(event)" onMouseout="bspMenuUnHighlight(event)" onClick="bspMenuSelect(event,'PeakMenu')" display:none>
      <div title="Reset peak values" class="bspMenuItem" url="./confirm.icp?what=reset_peaks">Reset peak values</div>
      <hr>
      <div title="Close Menu" class="bspMenuItem">Close Menu</div>
      </div>

      <div id="ConfMenu" class="bspMenuBox" onMouseover="bspMenuHighlight(event)" onMouseout="bspMenuUnHighlight(event)" onClick="bspMenuSelect(event,'ConfMenu')" display:none>
      <div class="bspMenuItem" url="./monitor.icp?what=refresh&amp;p1=10"><img src="<%=iconname[0]%>" alt="">Auto refresh (10sec)</div>
      <div class="bspMenuItem" url="./monitor.icp?what=refresh&amp;p1=30"><img src="<%=iconname[1]%>" alt="">Auto refresh (30sec)</div>
      <div class="bspMenuItem" url="./monitor.icp?a=a"><img src="<%=iconname[2]%>" alt="">Auto refresh off</div>
      <hr>
      <div title="Close Menu" class="bspMenuItem">Close Menu</div>
      </div>

      <div id="TotalMenu" class="bspMenuBox" onMouseover="bspMenuHighlight(event)" onMouseout="bspMenuUnHighlight(event)" onClick="bspMenuSelect(event,'TotalMenu')" display:none>
      <div title="Reset total values" class="bspMenuItem" url="./confirm.icp?what=reset_tot">Reset total values</div>
      <hr>
      <div title="Close Menu" class="bspMenuItem">Close Menu</div>
      </div>

      <table border="0" cellspacing="0" cellpadding="0" class="sapTbvAlt" width="100%">
	<tr>
	  <td class="sapTbvCellAlt" Colspan="2">
	    <b><i><%=appl%> Monitor</i></b>
	  </td>
	  <!--
	  <td class="sapTbvCellAlt" Colspan="1">&nbsp;</td>
	  -->
	  <td class="sapTbvCellAlt" align="right">
	    <a id="confObj" href="javascript:location.reload()" class="sapBtnEmph" title="refresh page">Refresh&nbsp;<img border=0 src="../public/images/cmenu/Triangle.gif" border="0"></a>
	  </td>
	</tr>
	<tr>
	  <td class="sapTbvCellStd" width="100">Status:</td>
	  <td class="sapTbvCellStd">
<% if (is_admin) { %>
            <a title="Status Menu" href="javascript:void(0);" id="statusObj" class="sapBtnStd" onKeyUp="bspMenuMainAction('ProcStatMenu', event, this);" onClick="bspMenuMainAction('ProcStatMenu', event, this);">
                <%=get_stat(icm_info.status)%>&nbsp;<img border=0 src="../public/images/cmenu/Triangle.gif" alt=""></a>
            
<% } else { %>
	    <%=get_stat(icm_info.status)%>
<% } %>

<% if (icm_info.status == 2) { %>
	    <img title="green" src="../public/icons/s_s_tl_g.gif" alt="green">
<% } else { %>
	    <img title="yellow" src="../public/icons/s_s_tl_y.gif" alt="yellow">
<% } %>

	  </td>
	  <td class="sapTbvCellStd" Colspan="1">&nbsp;</td>
	</tr>
	<tr>
	  <td class="sapTbvCellStd" width="200">Trace level:</td>
	  <td class="sapTbvCellStd" align="left"><%= icm_info.trace_level %></td>
	  <td class="sapTbvCellStd" Colspan="1">&nbsp;</td>
	</tr>
	<tr>
	  <td class="sapTbvCellStd" width="200">Process Id:</td>
	  <td class="sapTbvCellStd"><%=icm_info.pid%></td>
	  <td class="sapTbvCellStd" Colspan="1">&nbsp;</td>
	</tr>
	<tr>
	  <td class="sapTbvCellStd" width="200">Elapsed Time / CPU Time:</td>
	  <td class="sapTbvCellStd"><%=icm_info.uptime%> / <%=icm_info.cputime%></td>
	  <td class="sapTbvCellStd" Colspan="1">&nbsp;</td>
	</tr>

<%   if (icm_info.ppid != 0) { %>
	<tr>
	  <td class="sapTbvCellStd" width="200">Watchdog Process Id:</td>
	  <td class="sapTbvCellStd"><%=icm_info.ppid%></td>
	  <td class="sapTbvCellStd">&nbsp;</td>
	</tr>
<%   } %>

	<tr>
	  <td class="sapTbvCellStd" Colspan="3">&nbsp;</td>
	</tr>
      </table>
      <table border="0" cellspacing="0" cellpadding="0" class="sapTbvAlt" width="100%">
	<tr>
	  <th align="left" class="sapTbvCellAlt" width="150">&nbsp;</th>
	  <th align="left" class="sapTbvCellAlt" width="50"><i>current</i></th>
	  <th align="left" class="sapTbvCellAlt" width="50">
<% if (is_admin) { %>
            <a title="Peak Values Menu" accesskey="p" href="javascript:void(0);" id="peakObj" class="sapBtnStd" onKeyUp="bspMenuMainAction('PeakMenu', event, this, 80);" onClick="bspMenuMainAction('PeakMenu', event, this, 80);"><i><u>p</u>eak</i>
	        <img border=0 src="../public/images/cmenu/Triangle.gif" alt=""></a>
<% } else { %>
	    <i>peak</i>
<% } %>
	  </th>
	  <th align="left" class="sapTbvCellAlt" width="50"><i>maximum</i></th>
	  <th align="left" class="sapTbvCellAlt" width="50">
<% if (is_admin) { %>
            <a title="Total Values Menu" accesskey="t" href="javascript:void(0);" id="totObj" class="sapBtnStd" onKeyUp="bspMenuMainAction('TotalMenu', event, this, 84);" onClick="bspMenuMainAction('TotalMenu', event, this, 84);"><i><u>t</u>otal</i>
	        <img border=0 src="../public/images/cmenu/Triangle.gif" alt=""></a>
<% } else { %>
	    <i>total</i>
<% } %>
	  </th>
	  <th align="left" class="sapTbvCellAlt" width="150">&nbsp;</th>
	</tr>
	<tr>
	  <td class="sapTbvCellStd">Created Threads:</td>
	  <td class="sapTbvCellStd"><%= icm_info.cur_thr %></td>
	  <td class="sapTbvCellStd"><%= icm_info.peak_thr %></td>
	  <td class="sapTbvCellStd"><%= icm_info.max_thr %></td>
	  <td class="sapTbvCellStd"><%= icm_info.total_thr %></td>
	  <td class="sapTbvCellStd">&nbsp;</td>
	</tr>
	<tr>
	  <td class="sapTbvCellStd">Connections used:</td>
	  <td class="sapTbvCellStd"><%= icm_info.cur_conn %></td>
	  <td class="sapTbvCellStd"><%= icm_info.peak_conn %></td>
	  <td class="sapTbvCellStd"><%= icm_info.max_conn %></td>
	  <td class="sapTbvCellStd"><%= icm_info.total_conn %></td>
	  <td class="sapTbvCellStd">&nbsp;</td>
	</tr>
	<tr>
	  <td class="sapTbvCellStd">Queue entries used:</td>
	  <td class="sapTbvCellStd"><%= icm_info.cur_queue %></td>
	  <td class="sapTbvCellStd"><%= icm_info.peak_queue %></td>
	  <td class="sapTbvCellStd"><%= icm_info.max_queue %></td>
	  <td class="sapTbvCellStd"><%= icm_info.total_queue %></td>
	  <td class="sapTbvCellStd">&nbsp;</td>
	</tr>
      </table>

      <table cellspacing=1 width="100%" class="sapTbvAlt">
	<tr>
	  <th align="left" class="sapTbvCellAlt">
	    <i>No.</i>
	  </th>
	  <th align="left" class="sapTbvCellAlt">
	    <i>Thread ID</i>
	  </th>
	  <th align="left" class="sapTbvCellAlt">
	    <i>No. of Requests</i>
	  </th>
	  <th align="left" class="sapTbvCellAlt">
	    <i>Status</i>
	  </th>
	  <th align="left" class="sapTbvCellAlt">
	    <i>Request Type</i>
	  </th>
	</tr>
<%
	for (nr = 0; nr < icm_info.cur_thr; nr++) {
%>
	<tr>
	  <td class="sapTbvCellStd"><%= nr %></td>
	  <td class="sapTbvCellStd"><%= icm_thr_info[nr].thr_id %></td>
	  <td class="sapTbvCellStd"><%= icm_thr_info[nr].rq_count %></td>
	  <td class="sapTbvCellStd"><%= icm_thr_info[nr].status %></td>
	  <td class="sapTbvCellStd"><%= icm_thr_info[nr].rq_type %></td>
	</tr>
<%
	}
%>
      </table>
    </body>
  </html>