<%@  page pageEncoding="utf-8" contentType="text/html;charset=utf-8"
   import="com.novell.webaccess.common.JSPConduit,
           com.novell.emframe.dev.eMFrameUtils,
           com.novell.emframe.dev.DirUtils,
           com.novell.emframe.fw.FwUtils,
           java.util.Hashtable,
           java.util.Enumeration,
           org.jdom.Document,
           com.novell.emframe.dev.config.SystemConfig,
           com.novell.emframe.fw.EmailEventService" %>

<%
   JSPConduit c = JSPConduit.getJSPConduit(request);
   c.stringTable("DevResources");
   c.stringTable("FwResources");
%>

<%@ taglib uri="/WEB-INF/iman.tld" prefix="iman" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/x.tld" prefix="x" %>

<iman:stringtable bundle="FwResources"/>
<iman:stringtable bundle="DevResources"/>

<HTML>
<HEAD>
   <LINK rel="stylesheet" href="<c:out value="${ContextPath}" />/portal/modules/dev/css/hf_style.css">
   <iman:eMFrameScripts/>

      <SCRIPT>

   /*******************
    * FUNCTION HEADER *
    *******************/
   function onExit()
   {
      window.location = "webacc?NPService=fw.LaunchService&NPAction=Return&returnID=<c:out value="${GI_ID}"/>";
   }

   function onSubmitAndExit()
   {

      var form = document.EmailConfigForm;
      form.submit();
   }


   function testEvent(eventID)
   {
        if (confirm('<%=c.string("Task.Event.TestEvent")%>' +  " " + eventID))
        {
            var form = document.EmailConfigForm;
            form.TestEvent.value=eventID;
            form.EmailAction.value = "FireTestEvent";
            form.submit();
            form.TextEvent="";
        }

        return false;
   }

   </SCRIPT>
   </HEAD>
   <BODY>
      <FORM name="EmailConfigForm" method="POST" action="webacc">
         <INPUT type="hidden" name="nextState">
         <INPUT type="hidden" name="taskId" value="<c:out value="${taskId}"/>">
         <INPUT type="hidden" name="TestEvent" value="" />
         <INPUT type="hidden" name="EmailAction" value="UpdateList" />

         <% c.set("TaskHeader.title", c.toHTML(c.string("Task.Event.ConfigHeader")));
            c.set("TaskHeader.iconUrl", "dev/bullet_default_16.gif");
            c.set("TaskHeader.helpFile", "base/taskeventnotification.html"); 
	         c.set("TaskHeader.HelpWindowWidth", "500");
	         c.set("TaskHeader.HelpWindowHeight", "500"); %>
         <jsp:include page='<%= c.getPath("dev/TaskHeader_inc.jsp") %>' flush="true" />

          <div class="formdescriptextml0"  style="width: 70%"><%= c.toHTML(c.string("Task.Event.ConfigInstructions")) %></div>

            <table border="0" cellspacing="5" cellpadding="0">
				<tr>
					<td class="smalltext" valign="middle"><%= c.toHTML(c.string("Task.Event.ConfigToAddr")) %></td>
					<td class="smalltext">
						<div><input type="text" name="EmailAddress" size="60" value="<%=request.getAttribute(EmailEventService.EVENT_ADMIN_ADDRS)%>"></div>
					</td>
				</tr>
				<tr>
					<td class="smalltext" valign="middle"></td>
					<td class="smalltext">
						<div class="textblue1"><%= c.toHTML(c.string("Task.Event.ConfigAddrInstruction")) %></div>
					</td>
				</tr>
            </table>

            <br/>

            <table border="0" cellspacing="0" cellpadding="3" width="100%">
            	<TR class="tablehead1">
                  <td>&nbsp;</td>
                  <td><%= c.toHTML(c.string("Task.Event.TaskEvent")) %></td>
                  <td align="center"><%= c.toHTML(c.string("Task.Event.Notify")) %></td>
                  <td align="center"><%= c.toHTML(c.string("Task.Event.Override")) %></td>
                  <td><%= c.toHTML(c.string("Task.Event.Description")) %></td>
                  <td><%= c.toHTML(c.string("Task.Event.Test")) %></td>
		   		</TR>
        <%  SystemConfig sc = (SystemConfig) request.getAttribute("System.Config");
            Hashtable htEvents = (Hashtable)request.getAttribute("System.Email.Events");
            Enumeration keys = htEvents.keys();
            int i=0;
            while (keys.hasMoreElements())
            {
                String eventID = (String) keys.nextElement();
                Document jdom2 = (Document) htEvents.get(eventID);
                String sID = jdom2.getRootElement().getChild("id").getText();
                String sIDDisplay = jdom2.getRootElement().getChild("display-name-key").getText();
                String sIDDesc = jdom2.getRootElement().getChild("description-key").getText();

                if (i%2 == 0) {
                %>
                    <tr class="smalltext">
                <%
                }
                else
                {
                %>
                    <tr class="smalltext" style="background-color: efeee9">
                <%
                }
                %>
                    <td><img src="/nps/portal/modules/fw/images/tasks.gif" alt="<%= c.string("Task.Event.TaskEvent") %>" title="<%= c.string("Task.Event.TaskEvent") %>" height="16" width="16" border="0"></td>
                    <td><a href="?taskId=<%=request.getAttribute("taskId")%>&EmailAction=EditEvent&EventID=<%=sID%>"><%=sIDDisplay%></a></td>
                    <% if (request.getAttribute(sID) != null) { %>
                        <td align="center"><input type="checkbox" name="SelectedEvents" value="<%=sID%>" checked> </td>
                    <% } else { %>
                        <td align="center"><input type="checkbox" name="SelectedEvents" value="<%=sID%>"> </td>
                    <% } %>

                    <% String sOverrideAdmin = sc.getSetting(EmailEventService.EVENT_ADDR_OVERRIDE + "." + eventID, "false");
                        if (sOverrideAdmin.equalsIgnoreCase("false"))
                        {   %>
                            <td align="center"><input type="checkbox" disabled></td>
                        <% } else { %>
                            <td align="center"><input type="checkbox" checked disabled></td>
                        <% }
                    %>

					<td style="white-space: normal"><%=sIDDesc%></td>
                    <td><a href="#" onClick="testEvent( '<%=sID%>'); return false;"/>Test</a></td>
                </tr>
                <%
                i++;
            }
            %>
        </table>

         <iman:bar/>
         <div id="buttondiv" style="display: block">
            <iman:button key="OK" onClick="onSubmitAndExit();"/>
            <iman:button key="Cancel" onClick="onExit();"/>
         </div>
    </FORM>
   </BODY>
</HTML>
