<%

// Provides methods to render the different types a settings value can have

const
  cssprefix = 'nx';

// makes sure that we don't have any troubles with converting variants around
function FixValue(aVariant: Variant; aType: String): Variant;
var
  aString: String;
begin
  result:=aVariant;
  aString:=aVariant;

  if aString='' then
  begin
    if (aType='nxstBoolean') or (aType='nxstInteger') or (aType='nxstMultiOption') then
      result:=0;
  end;
end;


// renders a checkbox for boolean types
procedure RenderBool(aComponent: TnxComponent; aControlID: integer; aValue: variant);
begin
  output.Write('<input name="NewValue_'+inttostr(aControlID)+'" type=checkbox value="1"');
  if AValue='1' then
    output.write(' checked');	
	output.Write('/>'#13)
end;

// renders a text line for integer types
procedure RenderInteger(aComponent: TnxComponent; aControlID: integer; aValue: variant);
begin
  output.Write('<input class="'+cssprefix+'integercontrol" name="NewValue_'+inttostr(aControlID)+'" type=text value="'+inttostr(aValue)+'"/>'+#13);
end;

// base method for rendering a dropdownlist of options
procedure RenderOptionList(aComponent: TnxComponent; aControlID: integer; aValue: variant; aOptions, aValues: string; ReturnIndex: boolean);
var
  optionlist, valuelist: TStringlist;
	i: integer;
begin
  optionlist:=TStringlist.Create;
  valuelist:=TStringlist.Create;
	optionlist.text:=stringreplace(stringreplace(trim(aOptions),';',',',[rfReplaceAll]),',',#13,[rfReplaceAll]);
	try
		output.Write('<select class="'+cssprefix+'listcontrol" name="NewValue_'+inttostr(aControlID)+'" size=1 value="'+aValue+'">'+#13);
		for i:=0 to optionlist.count-1 do
		begin
  		output.write('<option');
      if returnIndex then
      begin
  			if aValue=inttostr(i) then
      		output.write(' selected');
      end
      else
      begin
  			if SameText(aValue, optionlist[i]) then
      		output.write(' selected');
      end;
      if returnIndex then
  			output.write(' value='+inttostr(i)+'>'+optionlist[i]+'</option>')
      else
  			output.write(' value="'+optionlist[i]+'">'+optionlist[i]+'</option>')
		end;
		output.write('</select>');
	finally
    valuelist.free;
	  optionlist.free;
	end;
end;

procedure RenderMultiOption(aComponent: TnxComponent; aControlID: integer; aValue: variant; aOptions, aValues, aVisible: string);
var
  optionlist, valuelist, visiblelist: TStringlist;
	i: integer;
begin
  optionlist:=TStringlist.Create;
  valuelist:=TStringlist.Create;
  visiblelist:=TStringlist.Create;
  valuelist.text:=stringreplace(trim(aValues),',',#13,[rfReplaceAll]);
	optionlist.text:=stringreplace(trim(aOptions),',',#13,[rfReplaceAll]);
	visiblelist.text:=stringreplace(trim(aVisible),',',#13,[rfReplaceAll]);
	try
    output.Write('<input id="NewValue_'+inttostr(aControlID)+'" name="NewValue_'+inttostr(aControlID)+'" type=hidden value="'+inttostr(aValue)+'"/>');

    for i:=0 to optionlist.count-1 do
		begin
      output.Write('<input onclick="updateMulti('+inttostr(optionlist.count)+', '+inttostr(aControlID)+');" id="MultiValue_'+inttostr(aControlID)+'_'+inttostr(i)+'" name="MultiValue_'+inttostr(aControlID)+'_'+inttostr(i)+'" value="'+valuelist[i]+'"');
      if (trim(visiblelist[i]))='1' then
        output.write(' type=checkbox ')
      else
        output.write(' type=hidden ');
        
      if (AValue AND strtoint(valuelist[i]))=strtoint(valuelist[i]) then
        output.write(' checked');	
    	output.Write('/>');
      if (trim(visiblelist[i]))='1' then
        output.Write(optionlist[i]+'<BR>'+#13);
		end;
	finally
    valuelist.free;
	  optionlist.free;
    visiblelist.free;
	end;
end;

procedure RenderServerOptions(aComponent: TnxComponent; aControlID: integer; aValue: variant);
var
  Values: string;
	Options: string;
  Visible: string;
begin
	Options:='ReadOnly,ForceFailSafe,CloseInactiveFolders,CloseInactiveTables,InMemOnly,IsSecure,VerifyTableNames,CloseAllWhenInactive,KeepSessionStats';
  Values:='1,2,4,8,16,32,64,128,256';
  Visible:='1,1,0,0,1,1,1,1,1';
	RenderMultiOption(aComponent, aControlID, aValue, Options, Values, Visible);
end;

// render the thread priority dropdown list
procedure RenderThreadPriority(aComponent: TnxComponent; aControlID: integer; aValue: variant);
var
  Values: string;
	Options: string;
begin
	Options:='tpIdle,tpLowest,tpLower,tpNormal,tpHigher,tpHighest,tpTimeCritical';
  Values:='0,1,2,3,4,5,6';
	RenderOptionList(aComponent, aControlID, aValue, Options, Values, true);
end;

// renders a dynamic table to show the users and allows to add new users
procedure RenderUsers(aComponent: TnxComponent; aControlID: integer; aValue: variant);
var
  i: integer;
  valuelist: TStringlist;
begin
  // we're accessing users in any form, so force BASIC authentication by setting the error code of the returned page to 901
  Server.SetError(901, 'Authentication Required!');
 
  if aValue=UnAssigned then
    aValue:='';
  output.writeln('<table id="_DynamicTable">');
  output.writeln('<tr class="header"><td class="header" width="70%">User&nbsp;Name</td><td class="header" width="20%">Tokens</td><td class="header" width="5%">Edit</td><td class="header" width="5%">Delete</td></tr>');
  valuelist:=TStringlist.Create;
	try
  	valuelist.text:=stringreplace(NXServer.GetUsers,';',#13,[rfReplaceAll]);
    for i:=0 to valuelist.Count-1 do
    begin
      output.writeln('<tr id="DynamicRow_'+inttostr(i)+'">');
		  output.writeln('<td id="DynamicRowIdentifier_'+inttostr(i)+'">'+valuelist.names[i]+'</td>');
		  output.writeln('<td id="DynamicRowValue_'+inttostr(i)+'">'+valuelist.values[valuelist.names[i]]+'</td>');
      output.writeln('<td><input type="button" value="Edit" onclick="editRow(''DynamicRow_'+inttostr(i)+''')"/></td>');
      output.writeln('<td><input type="button" value="Delete" onclick="removeRow(''DynamicRow_'+inttostr(i)+''')"/></td></tr>');
    end;
    output.writeln('</table>');

		output.writeln('<input type="hidden" value="'+inttostr(valuelist.count)+'" id="theValue" />');
    output.WriteLn('<input class="'+cssprefix+'textcontrol" id=newvalue name="NewValue_'+inttostr(aControlID)+'" type="hidden" value="'+aValue+'"/>'+#13);

    output.writeln('<table class=newitem>');
		output.writeln('<tr class=header><td colspan=2>Add New User</td></tr>');
		output.writeln('<tr><td>Name:</td><td><input type="text" value="" id="theIdentifier" /></td></tr>');
		output.writeln('<tr><td>Tokens:</td><td><input type="text" value="" id="theIdentifierValue" /></td></tr>');
		output.writeln('<tr><td>Password:</td><td><input type="password" value="" id="theIdentifierAdditionalValue" /></td></tr>');
		output.writeln('<tr><td>&nbsp;</td><td><input type="button" value="Add User" onclick="addElement();"/></td></tr></table>');

  finally
    valuelist.free;
  end;
end;

// renders a dynamic table to show the aliases and allows to add new aliases
procedure RenderAliases(aComponent: TnxComponent; aControlID: integer; aValue: variant);
var
  valuelist: TStringlist;
	i: integer;
begin
  output.Write('<input class="'+cssprefix+'textcontrol" id=newvalue name="NewValue_'+inttostr(aControlID)+'" type=hidden value="'+aValue+'"/>'+#13);
  valuelist:=TStringlist.Create;
	try
  	valuelist.text:=stringreplace(trim(aValue),';',#13,[rfReplaceAll]);

    output.writeln('<table id="_DynamicTable">');
		output.writeln('<tr class="header"><td class="header" width="20%">Alias&nbsp;Name</td><td class="header" width="75%">Alias&nbsp;Path</td><td class="header" width="5%">Edit</td><td class="header" width="5%">Delete</td></tr>');
		for i:=0 to valuelist.count-1 do
		begin
		  output.writeln('<tr id="DynamicRow_'+inttostr(i)+'">');
		  output.writeln('<td id="DynamicRowIdentifier_'+inttostr(i)+'">'+valuelist.names[i]+'</td>');
		  output.writeln('<td id="DynamicRowValue_'+inttostr(i)+'">'+valuelist.values[valuelist.names[i]]+'</td>');
      output.writeln('<td><input type="button" value="Edit" onclick="editRow(''DynamicRow_'+inttostr(i)+''')"/></td>');
		  output.writeln('<td><input type="button" value="Delete" onclick="removeRow(''DynamicRow_'++inttostr(i)+''')"/></td></tr>');
		end;
		output.writeln('</table>');

		output.writeln('<input type="hidden" value="'+inttostr(valuelist.count)+'" id="theValue" />');

		output.writeln('<table class=newitem>');
		output.writeln('<tr class=header><td colspan=2>Add New Alias</td></tr>');
		output.writeln('<tr><td>Name:</td><td><input type="text" size=60 value="" id="theIdentifier" /></td></tr>');
		output.writeln('<tr><td>Path:</td><td><input type="text" size=60 value="" id="theIdentifierValue" />');
		output.writeln('<input type="hidden" size=100 value=''(^(([a-z]:\\)([^\"\\/?*:|\"<>\r\n]+(\\)*)*)$)|(^((\\\\)([^\"\\/?*:|\"<>\r\n]+(\\)*){2,})$)'' id="theRule" />');
		output.writeln('<input type="hidden" size=100 value=''^(?!&)([a-zA-Z0-9_ !#&%&()+-@\[\]^{}~]{1,128})$'' id="theIdentifierRule" /></td></tr>');
		output.writeln('<tr><td>&nbsp;</td><td><input type="button" value="Add Alias" onclick="addAlias();"/></td></tr></table>');
	finally
	  valuelist.free;
	end;
end;

// renders a dynamic table to show the users and allows to add new users
procedure RenderWebApps(aComponent: TnxComponent; aControlID: integer; var aValue: variant);
var
  sDB: TnxSystemDatabase;
  sCursor: TnxsdCursorWrapper;
  i: integer;
  aString: string;
begin
  output.writeln('<table id="_DynamicTable">');
  Output.Writeln('<tr class=header>');
  Output.Writeln('<td class="header">DisplayName</td>');
  Output.Writeln('<td class="header">BaseDir</td>');
  Output.Writeln('<td class="header">AuthenticationMethod</td>');
  Output.Writeln('<td class="header">Port</td>');
  Output.Writeln('<td class="header">SSL</td>');
  Output.Writeln('<td class="header">Active</td>');
  Output.Writeln('<td class="header" width="5%">Edit</td>');
  Output.Writeln('<td class="header" width="5%">Delete</td>');
  Output.Writeln('</tr>');
  i:=1;
  sDB:=SystemDB;
  if sdb.TableExists('$SERVER$WEBAPPLICATIONS') then
  begin
    sCursor:=sdb.GetTable('$SERVER$WEBAPPLICATIONS');
    try
      sCursor.First;
      while not sCursor.Eof do
      begin
        output.writeln('<tr id="DynamicRow_'+inttostr(i)+'">');
        if sCursor.GetFieldByName('Active')=true then
       	  output.writeln('<td class=active id="DynamicRowIdentifier_'+inttostr(i)+'">'+sCursor.GetFieldByName('DisplayName')+'</td>')
        else
       	  output.writeln('<td class=inactive id="DynamicRowIdentifier_'+inttostr(i)+'">'+sCursor.GetFieldByName('DisplayName')+'</td>');
	      output.writeln('<td id="DynamicRowValue_'+inttostr(i)+'">'+sCursor.GetBlob('BaseDir')+'</td>');
	      output.writeln('<td id="AddRow1_'+inttostr(i)+'">'+sCursor.GetFieldByName('AuthenticationMethod')+'</td>');
	      output.writeln('<td id="AddRow2_'+inttostr(i)+'">'+inttostr(sCursor.GetFieldByName('Port'))+'</td>');
	      output.writeln('<td id="AddRow3_'+inttostr(i)+'">'+BoolToStr(sCursor.GetFieldByName('SSL'), true)+'</td>');
	      output.writeln('<td id="AddRow4_'+inttostr(i)+'">'+BoolToStr(sCursor.GetFieldByName('Active'), true)+'</td>');
        output.writeln('<td><input type="button" value="Edit" onclick="editRow(''DynamicRow_'+inttostr(i)+''')"/></td>');
        output.writeln('<td><input type="button" value="Delete" onclick="removeRow(''DynamicRow_'+inttostr(i)+''')"/></td></tr>');
        inc(i);
        sCursor.Next;
      end;
    finally
      sCursor.free;
    end;
  end;

  aString:=trim(avalue);
  i:=length(AString);
  while (i>1) and (copy(aString, i, 1)=';') do
    dec(i);

  aValue:=copy(aString, 0, i);

  output.writeln('</table>');

	output.writeln('<input type="hidden" value="'+inttostr(i)+'" id="theValue" />');
  output.WriteLn('<input class="'+cssprefix+'textcontrol" id=newvalue name="NewValue_'+inttostr(aControlID)+'" type="hidden" value="'+aValue+'"/>'+#13);

  output.writeln('<table class=newitem>');
	output.writeln('<tr class=header><td colspan=2>Add New Application</td></tr>');
	output.writeln('<tr><td>Display Name:</td><td><input type="text" size=50 value="" id="theIdentifier" /></td></tr>');
	output.writeln('<tr><td>Base Directory:</td><td><input type="text" size=50 value="" id="theIdentifierValue" /></td></tr>');
	output.writeln('<tr><td>Authentication Method:</td><td><select name="AddRow1" id="AddRow1" /><option value="NONE">NONE</option><option value="BASIC">BASIC</option></select></td></tr>');
	output.writeln('<tr><td class="integercontrol">Port:</td><td><input type="text" value="" id="AddRow2" /></td></tr>');
	output.writeln('<tr><td>SSL:</td><td><input type="checkbox" value="True" id="AddRow3" /></td></tr>');
	output.writeln('<tr><td>Active:</td><td><input type="checkbox" value="True" id="AddRow4" /></td></tr>');
	output.writeln('<tr><td>&nbsp;</td><td><input type="button" value="Add Application" onclick="addElement();"/></td></tr></table>');
end;

// renders a dynamic table to show the users and allows to add new users
procedure RenderASPApps(aComponent: TnxComponent; aControlID: integer; var aValue: variant);
var
  sDB: TnxSystemDatabase;
  sCursor: TnxsdCursorWrapper;
  i: integer;
  aString: string;
begin
  output.writeln('<table id="_DynamicTable">');
  Output.Writeln('<tr class=header>');
  Output.Writeln('<td class="header">DisplayName</td>');
  Output.Writeln('<td class="header">BaseDir</td>');
  Output.Writeln('<td class="header">Port</td>');
  Output.Writeln('<td class="header">SSL</td>');
  Output.Writeln('<td class="header">Active</td>');
  Output.Writeln('<td class="header">NetVersion</td>');
  Output.Writeln('<td class="header">AppBase</td>');
  Output.Writeln('<td class="header" width="5%">Edit</td>');
  Output.Writeln('<td class="header" width="5%">Delete</td>');
  Output.Writeln('</tr>');
  i:=1;
  sDB:=SystemDB;
  if sdb.TableExists('$SERVER$HOSTEDASPAPPLICATIONS') then
  begin
    sCursor:=sdb.GetTable('$SERVER$HOSTEDASPAPPLICATIONS');
    try
      sCursor.First;
      while not sCursor.Eof do
      begin
        output.writeln('<tr id="DynamicRow_'+inttostr(i)+'">');
        if sCursor.GetFieldByName('Active')=true then
       	  output.writeln('<td class=active id="DynamicRowIdentifier_'+inttostr(i)+'">'+sCursor.GetFieldByName('DisplayName')+'</td>')
        else
		output.writeln('<td class=inactive id="DynamicRowIdentifier_'+inttostr(i)+'">'+sCursor.GetFieldByName('DisplayName')+'</td>');
	      output.writeln('<td id="DynamicRowValue_'+inttostr(i)+'">'+sCursor.GetBlob('BaseDir')+'</td>');
	      output.writeln('<td id="AddRow1_'+inttostr(i)+'">'+inttostr(sCursor.GetFieldByName('Port'))+'</td>');
	      output.writeln('<td id="AddRow2_'+inttostr(i)+'">'+BoolToStr(sCursor.GetFieldByName('SSL'), true)+'</td>');
	      output.writeln('<td id="AddRow3_'+inttostr(i)+'">'+BoolToStr(sCursor.GetFieldByName('Active'), true)+'</td>');
	      output.writeln('<td id="AddRow4_'+inttostr(i)+'">'+sCursor.GetFieldByName('NetVersion')+'</td>');
	      output.writeln('<td id="AddRow5_'+inttostr(i)+'">'+sCursor.GetFieldByName('AppBase')+'</td>');
              output.writeln('<td><input type="button" value="Edit" onclick="editRow(''DynamicRow_'+inttostr(i)+''')"/></td>');
              output.writeln('<td><input type="button" value="Delete" onclick="removeRow(''DynamicRow_'+inttostr(i)+''')"/></td></tr>');
        inc(i);
        sCursor.Next;
      end;
    finally
      sCursor.free;
    end;
  end;

  aString:=trim(avalue);
  i:=length(AString);
  while (i>1) and (copy(aString, i, 1)=';') do
    dec(i);

  aValue:=copy(aString, 0, i);

  output.writeln('</table>');

	output.writeln('<input type="hidden" value="'+inttostr(i)+'" id="theValue" />');
  output.WriteLn('<input class="'+cssprefix+'textcontrol" id=newvalue name="NewValue_'+inttostr(aControlID)+'" type="hidden" value="'+aValue+'"/>'+#13);

  output.writeln('<table class=newitem>');
	output.writeln('<tr class=header><td colspan=2>Add New Application</td></tr>');
	output.writeln('<tr><td>Display Name:</td><td><input type="text" size=50 value="" id="theIdentifier" /></td></tr>');
	output.writeln('<tr><td>Base Directory:</td><td><input type="text" size=50 value="" id="theIdentifierValue" /></td></tr>');
	output.writeln('<tr><td class="integercontrol">Port:</td><td><input type="text" value="" id="AddRow1" /></td></tr>');
	output.writeln('<tr><td>SSL:</td><td><input type="checkbox" value="True" id="AddRow2" /></td></tr>');
	output.writeln('<tr><td>Active:</td><td><input type="checkbox" value="True" id="AddRow3" /></td></tr>');
	output.writeln('<tr><td>.Net Version:</td><td><select id="AddRow4"><option selected value="v2.0.50727">v2.0.50727</option><option value="v4.0.30319">v4.0.30319</option></select></td></tr>');
	output.writeln('<tr><td>App Base Directory:</td><td><input type="text" size=50 value="" id="AddRow5" /></td></tr>');
	output.writeln('<tr><td>&nbsp;</td><td><input type="button" value="Add ASP/.NET Application" onclick="addElement();"/></td></tr></table>');
end;

procedure RenderNetApps(aComponent: TnxComponent; aControlID: integer; var aValue: variant);
var
  sDB: TnxSystemDatabase;
  sCursor: TnxsdCursorWrapper;
  i: integer;
  aString: string;
begin
  output.writeln('<table id="_DynamicTable">');
  Output.Writeln('<tr class=header>');
  Output.Writeln('<td class="header">DisplayName</td>');
  Output.Writeln('<td class="header">ClassFullName</td>');
  Output.Writeln('<td class="header">Assembly</td>');
  Output.Writeln('<td class="header">NetVersion</td>');
  Output.Writeln('<td class="header">Settings</td>');
  Output.Writeln('<td class="header">Active</td>');
  Output.Writeln('<td class="header" width="5%">Edit</td>');
  Output.Writeln('<td class="header" width="5%">Delete</td>');
  Output.Writeln('</tr>');
  i:=1;
  sDB:=SystemDB;
  if sdb.TableExists('$SERVER$HOSTEDNETAPPLICATIONS') then
  begin
    sCursor:=sdb.GetTable('$SERVER$HOSTEDNETAPPLICATIONS');
    try
      sCursor.First;
      while not sCursor.Eof do
      begin
        output.writeln('<tr id="DynamicRow_'+inttostr(i)+'">');
        if sCursor.GetFieldByName('Active')=true then
       	  output.writeln('<td class=active id="DynamicRowIdentifier_'+inttostr(i)+'">'+sCursor.GetFieldByName('DisplayName')+'</td>')
        else
       	  output.writeln('<td class=inactive id="DynamicRowIdentifier_'+inttostr(i)+'">'+sCursor.GetFieldByName('DisplayName')+'</td>');
	      output.writeln('<td id="DynamicRowValue_'+inttostr(i)+'">'+sCursor.GetFieldByName('ClassFullName')+'</td>');
	      output.writeln('<td id="AddRow1_'+inttostr(i)+'">'+sCursor.GetFieldByName('Assembly')+'</td>');
	      output.writeln('<td id="AddRow2_'+inttostr(i)+'">'+sCursor.GetFieldByName('NetVersion')+'</td>');
	      output.writeln('<td id="AddRow3_'+inttostr(i)+'">'+sCursor.GetBlob('Settings')+'</td>');
	      output.writeln('<td id="AddRow4_'+inttostr(i)+'">'+BoolToStr(sCursor.GetFieldByName('Active'), true)+'</td>');
        output.writeln('<td><input type="button" value="Edit" onclick="editRow(''DynamicRow_'+inttostr(i)+''')"/></td>');
        output.writeln('<td><input type="button" value="Delete" onclick="removeRow(''DynamicRow_'+inttostr(i)+''')"/></td></tr>');
        inc(i);
        sCursor.Next;
      end;
    finally
      sCursor.free;
    end;
  end;

  aString:=trim(avalue);
  i:=length(AString);
  while (i>1) and (copy(aString, i, 1)=';') do
    dec(i);

  aValue:=copy(aString, 0, i);

  output.writeln('</table>');

	output.writeln('<input type="hidden" value="'+inttostr(i)+'" id="theValue" />');
  output.WriteLn('<input class="'+cssprefix+'textcontrol" id=newvalue name="NewValue_'+inttostr(aControlID)+'" type="hidden" value="'+aValue+'"/>'+#13);

  output.writeln('<table class=newitem>');
	output.writeln('<tr class=header><td colspan=2>Add New Application</td></tr>');
	output.writeln('<tr><td>Display Name:</td><td><input type="text" size=50 value="" id="theIdentifier" /></td></tr>');
	output.writeln('<tr><td>Class Full Name:</td><td><input type="text" size=50 value="" id="theIdentifierValue" /></td></tr>');
	output.writeln('<tr><td>Assembly:</td><td><input type="text" size=50 value="" id="AddRow1" /></td></tr>');
	output.writeln('<tr><td>.Net Version:</td><td><select id="AddRow2"><option selected value="v2.0.50727">v2.0.50727</option><option value="v4.0.30319">v4.0.30319</option></select></td></tr>');
	output.writeln('<tr><td>Settings:</td><td><input type="text" size=50 value="" id="AddRow3" /></td></tr>');
	output.writeln('<tr><td>Active:</td><td><input type="checkbox" value="True" id="AddRow4" /></td></tr>');
	output.writeln('<tr><td>&nbsp;</td><td><input type="button" value="Add .NET Application" onclick="addElement();"/></td></tr></table>');
end;

// renders a dynamic table to show the server license plugin users
<!--#INCLUDE FILE="ServerLicensePlugin.nxscript"-->

procedure RenderPasswordString(aComponent: TnxComponent; aControlID: integer; aValue: variant; writeOldValue: boolean);
var
  aString: string;
begin
  output.Write('<input class="'+cssprefix+'textcontrol" name="NewValue_'+inttostr(aControlID)+'" type=password value="' + aValue + '"/>'+#13);
  if writeOldValue then
  begin
    aString:=aValue;
    output.Write('<input name="OldValue_'+inttostr(aControlID)+'" type=hidden value="'+aString+'" />'+#13);
  end;
end;

procedure RenderCaption(aComponent: TnxComponent; aControlID: integer; aValue: variant);
begin
  output.Write(aValue + #13);
end;

procedure RenderMemo(aComponent: TnxComponent; aControlID: integer; var aValue: variant; writeOldValue: boolean);
var
  aString: string;
begin
  output.Write('<input class="'+cssprefix+'textarea" name="NewValue_'+inttostr(aControlID)+'" type=text value="' + aValue + '"/>'+#13);
  if writeOldValue then
  begin
    aString:=aValue;
    output.Write('<input name="OldValue_'+inttostr(aControlID)+'" type=hidden value="'+aString+'" />'+#13);
  end;
end;

procedure RenderPasswordMemo(aComponent: TnxComponent; aControlID: integer; aValue: variant; writeOldValue: boolean);
var
  aString: string;
begin
  output.Write('<input class="'+cssprefix+'textarea" name="NewValue_'+inttostr(aControlID)+'" type=text value="' + '**********' + '"/>'+#13);
  if writeOldValue then
  begin
    aString:=aValue;
    output.Write('<input name="OldValue_'+inttostr(aControlID)+'" type=hidden value="'+aString+'" />'+#13);
  end;
end;


// the central method called from the main scripts
procedure RenderControl(aComponentID: integer; aComponent: TnxComponent; aType: String; aControlID: integer; aControlName: string; avalue: variant; writeOldValue: boolean);
var
  aString: string;
begin
  if aType='nxstBoolean' then
	  RenderBool(aComponent, aControlID, aValue)
	else if aType='nxstInteger' then
	  RenderInteger(aComponent, aControlID, aValue)
	else if aType='nxstThreadPriority' then
	  RenderThreadPriority(aComponent, aControlID, aValue)
	else if aType='nxstAliases' then
	  RenderAliases(aComponent, aControlID, aValue)
	else if aType='nxstPasswordString' then
	  RenderPasswordString(aComponent, aControlID, aValue, writeOldValue)
	else if aType='nxstCaption' then
	  RenderCaption(aComponent, aControlID, aValue)
	else if aType='nxstMemo' then
	  RenderMemo(aComponent, aControlID, aValue, writeOldValue)
	else if aType='nxstPasswordMemo' then
	  RenderPasswordMemo(aComponent, aControlID, aValue, writeOldValue)
	else if aType='nxstExtended' then
  begin
    aString:=GetClassName(aComponent);
    if uppercase(aString)=uppercase('TnxsrWebApplications') then
    begin
  	  RenderWebApps(aComponent, aControlID, aValue);
    end
    else
    if uppercase(aString)=uppercase('TnxsrHostedASPApplications') then
    begin
  	  RenderASPApps(aComponent, aControlID, aValue);
    end
    else
    if uppercase(aString)=uppercase('TnxsrHostedNETApplications') then
    begin
  	  RenderNetApps(aComponent, aControlID, aValue);
    end
    else
    if uppercase(aString)=uppercase('TnxServerLicensePlugin') then
    begin
      RenderServerLicenseUsers(aComponent, aControlID, aValue);
    end;
  end
	else if aType='nxstMultiOption' then
  begin
	  RenderServerOptions(aComponent, aControlID, aValue)
  end
	else if aType='nxstUsers' then
	  RenderUsers(aComponent, aControlID, aValue)
	else 
	begin
    // string value
    if NXServer.SettingEnforce(aComponentID, aControlID) then
      RenderOptionList(aComponent, aControlID, aValue, NXServer.SettingPossibleValuesName(aComponentID, aControlID), NXServer.SettingPossibleValuesName(aComponentID, aControlID), false)
    else
  	  output.Write('<input class="'+cssprefix+'textcontrol" name="NewValue_'+inttostr(aControlID)+'" type=text value="'+aValue+'"/>'+#13);
	end;
	if writeOldValue then
  begin
    aString:=aValue;
    output.Write('<input name="OldValue_'+inttostr(aControlID)+'" type=hidden value="'+aString+'" />'+#13);
  end;
  output.Write('<input name="Name_'+inttostr(aControlID)+'" type=hidden value="'+aControlName+'" />'+#13);
  output.Write('<input name="Type_'+inttostr(aControlID)+'" type=hidden value="'+aType+'"/>'+#13);
end;

%>
