<%
const 
  RefreshTime = 5;

var
  i: integer;
  j: integer;
  classsuff: string;
  id: integer;
  aComponent: TnxComponent;
  aValue: variant;
  Names: TStringlist;
  Values: TStringlist;
  refreshvalue: integer;
  help: TStringlist;
  aname: string;
begin
  id:=strtointdef(Request('Index'), -1);
  Server.SetVar('Refresh', inttostr(RefreshTime));
  Server.SetVar('Previous', 'Test');
%>

<!--#INCLUDE FILE="header.nxscript"-->

<!-- Write the left menu component list -->

<div id=leftmenu>
<div class=innertube>
<%
  NXServer.RefreshComponents;

(*  aComponent:=NXServer.GetComponent(8);   
  if (aComponent is TnxStateComponent) then
    if NXServer.SettingValueFromName(NXServer.ComponentID(8), 'Active', 0)=1 then
      classsuff:='Active'
    else
      classsuff:='InActive';*)


  output.Write('<h3>Statistics</h3><br>');
  For i:=0 To NXServer.ComponentCount-1 do
  begin
    classsuff:='';
    aComponent:=NXServer.GetComponent(i);   
    if (aComponent.UiStatsVisible) then
    begin
      if (aComponent is TnxStateComponent) then
        if NXServer.SettingValueFromName(NXServer.ComponentID(i), 'Active', 0)=1  then
          classsuff:='Active'
        else
          classsuff:='InActive';
      output.Write('<a class="'+classsuff+'" href="stats.nxscript?index='+inttostr(i)+'">'+NXServer.ComponentDisplayName(i)+'</a><br>');
    end;
  end;
%>
</div>
</div>

<!-- CSS Main Content Wrapper -->

<div id=maincontent>  
<div class=innertube>

<!-- actual content start --> 



<%
  // print status/errors of the last action
  if copy(Server.GetVar('Error'), 1, 3)='OK:' then
    Output.Writeln('<p class=error>'+Server.GetVar('Error')+'</p>')
  else if Trim(Server.GetVar('Error'))<>'' then
    Output.Writeln('<p class=error>Error: '+Server.GetVar('Error')+'</p>');
  Server.SetVar('Error', ' ');

  if id<0 then
  begin
%>
    <!--#INCLUDE FILE="startpage.nxscript"-->
<%
    exit;
  end;

  i:=id;  // set i to the current requested component id
  if NXServer.SettingValueFromName(NXServer.ComponentID(i), 'Active', 0)=1 then
    classsuff:='Active'
  else
    classsuff:='InActive';

  aName:=NXServer.ComponentCategory(i);
%>

  
  <h3 class="ComponentHeader<%=classsuff%>" ><%=NXServer.ComponentDisplayName(i)%> Statistics</h3>

  <form id="changecomponent" action="changesettings.nxscript" method="POST">

  <!-- Component ID and Category 
  
  <table class=componentinfo align=left>
    <tr>
		  <td class=identifier width="20%">Component ID</td>
			<td class=value width="90%"><%=NXServer.ComponentID(i)%></td>
		</tr>

    <tr>
		  <td class=identifier >Category</td>
			<td class=value><% Output.WriteLn(aName); %>
      </td>
		</tr>
	</table>
	
	only needed for debug purposes -->

  <!-- set the hidden fields needed to change components -->

  <input type=hidden name="ComponentID" value="<%=NXServer.ComponentID(i)%>"></input>
  <input type=hidden name="ComponentDisplayName" value="<%=NXServer.ComponentDisplayName(i)%>"></input>
  <input type=hidden name="SettingCount" value="<%=NXServer.SettingCount(NXServer.ComponentID(i))%>"></input>
  <input type=hidden name="Index" value="<%=inttostr(i)%>"></input>

	<p>

  <!-- Component settings table --> 

  <table class=propertytable align=left>
    <tr class=header>
      <td class=header width="60%">Statistics Name</td>
      <td class=header width="40%">Value</td>
    </tr>

  <%
    Names:=TStringlist.Create;
    Values:=TStringlist.Create;
    try
      NXServer.GetComponent(i).GetStatsCaptions(Names);
      NXServer.GetComponent(i).GetStatsValues(Values);
      For j:=0 To Names.Count-1 do
      begin
  %>
        <tr>
          <td class=identifier><%=Names[j]%></td>
          <td class=newvalue><%=Values[j]%></td>
        </tr>
  <%
      end;
    finally
      Names.free;
      Values.Free;
    end;
  %>

  </table>

  <!-- Action buttons -->

  <small>This page refreshes automatically every <%=inttostr(RefreshTime)%> seconds.</small>
  </form>

<!-- actual content end --> 

<!-- help content start -->
<div id=help>
<h3>Help for <%=NXServer.ComponentDisplayName(i)%></h3>

<%
  help:=TStringlist.Create;
  try
    aname:='Adminroot\'+NXServer.ComponentName(i)+'_stats.help';
    if fileexists(aName) then
    begin
      help.LoadFromFile(aName);
      for i:=0 to help.count-1 do
        Output.Writeln(help[i]);
    end
    else
      Output.Writeln('Sorry no help for this page. (File "'+aName+'" does not exist.)');
  finally
    help.free;
  end;
%>
</div>

</div>
</div>

</div>
</div>
</html>

<%
end.
%>

