<%@ page language="java" buffer="100kb" errorPage="/common/error.jsp"%>

<%@ page import="vkc.db.entities.*" %>
<%@ page import="vkc.view.TabId" %>
<%@ page import="vkc.administration.form.SystemParametersForm" %>

<%@ taglib uri="struts-html" 	prefix="html" %>
<%@ taglib uri="struts-bean" 	prefix="bean" %>
<%@ taglib uri="struts-logic" 	prefix="logic" %>
<%@ taglib uri="vkc-taglib" 	prefix="vkc" %>

<vkc:checkLogin />
<vkc:init/>
<html:html locale="true">
<head>

  	<vkc:cssinclude />

    <meta http-equiv="content-type"  content="text/html; charset=iso-8859-1" />
    <script type="text/javascript" src="<vkc:rewrite page='/common/utils.js'/>"></script>

    <script type="text/javascript">
    window.name = "MAINVIEW";
    var associatedTabId = <%=TabId.ADMIN_SYSTEMPARAMETERS_TAB%>;
    	
    function init() {
      	var tabView = getTabView();
        var tabViewForm = tabView.document.forms[0];

        if (tabView && tabView.systemviewtype == "administrationview" && tabView.selectedTabId != associatedTabId) {
          	tabView.location.replace("<%=ctxPath%>/adminTabView.do?selectedTabId=<%=TabId.ADMIN_SYSTEMPARAMETERS_TAB%>"
          						   + "&lastCategoryId=" + tabViewForm.lastCategoryId.value
          						   + "&lastFunctionalId=" + tabViewForm.lastFunctionalId.value
          						   + "&lastProjectId=" + tabViewForm.lastProjectId.value);
        }
    }

    function showFile(id) {
        var form = document.forms[0];
        form.selectedParamterId.value = id;

        if (form.action.indexOf('?') == -1) {
          form.action = form.action + "?action.show.file=true";
        } else {
          form.action = form.action + "&action.show.file=true";
        }

        form.submit();
    }

    </script>

</head>
<body onload="init();" topmargin="0" marginheight="0">
<html:form action="/systemParameters" method="post">

<bean:define id="form" name="systemParametersForm" type="vkc.administration.form.SystemParametersForm" toScope="request"/>
<bean:define id="selectedContextParameters" name="form" property="selectedContextParameters" type="java.util.List"/>

<html:hidden property="viewMode"/>
<html:hidden property="selectedContext"/>
<html:hidden property="selectedParamterId"/>

<logic:present name="<%=org.apache.struts.Globals.ERROR_KEY%>">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
  <html:messages id="error" message="false">
    <tr><td align="left" nowrap="nowrap" colspan="1"><span class="error"><b><vkc:write name="error"/></b></span></td></tr>
  </html:messages>
  <vkc:hline colspan="1" lineClass="hline" lineHeight="1" topSpace="5" bottomSpace="5"/>
</table>
</logic:present>

<table width="100%" cellspacing="0" cellpadding="0" border="0">

  <tr>
    <td align="right" nowrap="nowrap" colspan="5">&nbsp;<vkc:message key="mandatory.field1"/>&nbsp;<vkc:img page="/templates/${template.name}/gfx/mandatoryField.gif" alt="*" border="0"/>&nbsp;<vkc:message key="mandatory.field2"/></td>
  </tr>

  <vkc:hline colspan="5" lineClass="hline" lineHeight="1" topSpace="5" bottomSpace="5"/>

  <tr>
	<td valign="top"><!-- Systemparameter Contexts -->
	  <table width="100%" cellpadding="2" cellspacing="0" border="0">
		<logic:iterate id="context" type="java.lang.String" name="form" property="contextNames">
		<logic:equal name="form" property='<%="showContextName(" + context + ")"%>' value="true">
		<tr>
          <logic:equal name="form" property="selectedContext" value="<%=context%>">
          <td nowrap="nowrap"><vkc:img page="/templates/${template.name}/gfx/arrow-right.gif" alt=""/></td>
          <td nowrap="nowrap"><vkc:link page="/systemParameters.do" paramId="selectedContext" paramName="context" style="font-weight:normal;text-decoration:none;"><b><vkc:message name="form" property='<%= "contextNameKey(" + context + ")" %>'/></b></vkc:link></td>  
          </logic:equal>
            
          <logic:notEqual name="form" property="selectedContext" value="<%=context%>">
          <td nowrap="nowrap"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="1" height="1"/></td>
          <td nowrap="nowrap"><vkc:link page="/systemParameters.do" paramId="selectedContext" paramName="context" style="font-weight:normal;text-decoration:none;"><vkc:message name="form" property='<%= "contextNameKey(" + context + ")" %>'/></vkc:link></td>
          </logic:notEqual>
        </tr>
        </logic:equal>
	    </logic:iterate>
  	  </table>
	</td>

    <td width="5" valign="top"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="5" height="1"/></td>
    <td width="1" valign="top" class="hline"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="1" height="1"/></td>
    <td width="5" valign="top"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="5" height="1"/></td>

	<td width="100%" align="left" valign="top"><!-- Systemparameters of the selected context -->
      <logic:equal name="form" property="viewMode" value='<%= SystemParametersForm.VIEW_MODE_PARAMETERS.toString() %>'>
	  <table width="100%" align="left" cellpadding="2" cellspacing="0" border="0">

		<tr bgcolor="#c0c0c0">
		  <td align="left" colspan="2">&nbsp;<b><vkc:message key="vkc.administration.systemparameters.parameter" /></b>&nbsp;</td>
		  <td align="left"><b><vkc:message key="vkc.administration.systemparameters.parameterdescription" /></b>&nbsp;</td>
		  <td align="right">&nbsp;</td>
		</tr>

		<logic:iterate id="parameter" indexId="index" type="vkc.db.entities.VKCSysParameter" name="selectedContextParameters">
        
        <logic:equal name="parameter" property="hide" value="0">
        <tr><td><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="1" height="1"/></td></tr>

		<tr bgcolor="#e0e0e0">
	      <td align="left" nowrap="nowrap">&nbsp;<vkc:message name="parameter" property="nameKey" />:
          <logic:notEqual name="parameter" property="readOnly" value="true">
            <logic:notEqual name="parameter" property="booleanType" value="true">
              <logic:notEqual name="parameter" property="allowNull" value="true">
              &nbsp;<vkc:img page="/templates/${template.name}/gfx/mandatoryField.gif" alt="*" border="0"/>
              </logic:notEqual>
            </logic:notEqual>
          </logic:notEqual>
          &nbsp;</td>
	      <td align="left" nowrap="nowrap">

          <logic:equal name="parameter" property="readOnly" value="true">
			<% if( parameter.getDatatype().intValue() == VKCSysParameter.BOOLEAN ){ %>
            <html:checkbox indexed="true" name="parameter" property="valuestring" disabled="true"/>
            <html:hidden indexed="true" name="parameter" property="valuestring"/>
		    <% } else { %>
		    <logic:equal name="form" property='<%= "passwordParameter(" + parameter.getName() + ")" %>' value="true">
            <html:password indexed="true" name="parameter" property="valuestring" size="50" readonly="true" disabled="true"/>
            </logic:equal>
		    <logic:equal name="form" property='<%= "passwordParameter(" + parameter.getName() + ")" %>' value="false">
			<vkc:write name="parameter" property="valuestring" />
            </logic:equal>
            <html:hidden indexed="true" name="parameter" property="valuestring"/>  
			<% } %>
            <html:hidden indexed="true" name="parameter" property="datatype"/>  
            <html:hidden indexed="true" name="parameter" property="name"/>  
            <html:hidden indexed="true" name="parameter" property="nameKey"/>  
            <html:hidden indexed="true" name="parameter" property="hide"/>  
          </logic:equal>

          <logic:equal name="parameter" property="readOnly" value="false">
            <html:hidden indexed="true" name="parameter" property="name"/>  
            <html:hidden indexed="true" name="parameter" property="nameKey"/>  
            <html:hidden indexed="true" name="parameter" property="datatype"/>  
            <html:hidden indexed="true" name="parameter" property="hide"/>  

			<% if( parameter.getDatatype().intValue() == VKCSysParameter.BOOLEAN ){ %>
              <html:checkbox indexed="true" name="parameter" property="valuestring"/>
			<% } else if( parameter.getDatatype().intValue() == VKCSysParameter.INTEGER ) { %>
   			  <html:text indexed="true" name="parameter" property="valuestring" size="20"/>
		    <% } else { %>
		      <logic:equal name="form" property='<%= "passwordParameter(" + parameter.getName() + ")" %>' value="true">
              <html:password indexed="true" name="parameter" property="valuestring" size="50"/>
              </logic:equal>
		      <logic:equal name="form" property='<%= "passwordParameter(" + parameter.getName() + ")" %>' value="false">
              <html:text indexed="true" name="parameter" property="valuestring" size="50"/>
              </logic:equal>
			<% } %>
          </logic:equal>

	      </td>

    	  <td width="100%" align="left"><vkc:message name="parameter" property="descrKey" /></td>

		  <logic:equal name="form" property='<%= "fileParameter(" + parameter.getName() + ")" %>' value="true">
    	  <td align="right"><vkc:link href='<%= "javascript:showFile(" + parameter.getSysParameterId() + ");" %>'><vkc:img page="/templates/${template.name}/gfx/note.gif" border="0" titleKey="vkc.tooltip.show.file"/></vkc:link></td>
		  </logic:equal>

		  <logic:equal name="form" property='<%= "fileParameter(" + parameter.getName() + ")" %>' value="false">
    	  <td align="right">&nbsp;</td>
		  </logic:equal>
		</tr>
        </logic:equal>

		</logic:iterate>

		<logic:equal name="form" property="selectedContextEditable" value="true">
        <vkc:hline topSpace="5" bottomSpace="2" colspan="4" lineHeight="1" lineClass="hline"/>
		<tr><td align="center" colspan="3"><vkc:button property="action.save" onclick="javascript:disableAllButtonsAndSubmit(this);"><vkc:message key="button.save"/></vkc:button></td></tr>
		</logic:equal>
 	  </table>
      </logic:equal>

      <logic:equal name="form" property="viewMode" value='<%= SystemParametersForm.VIEW_MODE_FILE.toString() %>'>
        <jsp:include page="fileView.jsp" flush="true" />
      </logic:equal>
	</td>
</tr>
</table>
</html:form>
</body>
</html:html>
