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

<%@ page import="vkc.view.WebShare" %>
<%@ page import="vkc.view.TabId" %>
<%@ page import="vkc.messenger.form.EditMessengerForm" %>

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

<vkc:checkLogin />
<vkc:init/>
<html:html locale="true">
<head>
    <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" src="<vkc:rewrite page='/common/calendar.js'/>"></script>
    <script type="text/javascript" src="<vkc:rewrite page='/common/overlib/overlib.js'/>"><!-- overLIB (c) Erik Bosrup --></script>
    <script type="text/javascript" src="<vkc:rewrite page='/common/overlib/overlib_positioncap.js'/>"></script>

	<vkc:cssinclude />

    <script type="text/javascript">

    window.name = "MAINVIEW";
    var associatedTabId = <%=TabId.MESSENGER_TAB%>;
    var currentCalendar = null;
    var windowOpen = null;

    function init() {
        var tabView = getTabView();
        var tabViewForm = tabView.document.forms[0];

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

        <logic:present name="<%=WebShare.INFO_KEY%>" scope="request">
            <bean:define id="msg" type="java.lang.String" scope="request" name="<%=WebShare.INFO_KEY%>"/>
            alert( '<vkc:message javascript="true" filter="false" key="<%=msg%>"/>' );
        </logic:present>
    }

    function editQuery(elem, id) {
        var form = document.forms[0];
        form.selectedId.value = id;
        
        if (form.action.indexOf('?') == -1) {
          form.action = form.action + "?action.edit.searchquery=true";
        } else {
          form.action = form.action + "&action.edit.searchquery=true";
        }
        
        disableAllButtons(elem);
        form.submit();
    }

    function showExplorer() {
        var w = 200;
        var h = 600;
        var leftPosition = screen.width/2  - w/2;
        var topPosition  = screen.height/2 - h/2;
        var settings ='height=' + h + ', width=' + w + ', top=' + topPosition + ', left=' + leftPosition;
        settings += ',scrollbars=yes,resizable';
        settings += ',toolbar=no, location=no, directories=no, status=true, menubar=no';
        windowOpen = window.open( '<vkc:rewrite page="/explorerTreeView.do"/>', 'EXPLORER_MAINVIEW', settings );
        windowOpen.focus();
        return false;
    }

    function setCategoryId(id) {
        var form = document.forms[0];
        
        if (form.action.indexOf('?') == -1) {
          form.action = form.action + "?action.change.category=true" + "&selectedCategoryId=" + id;
        } else {
          form.action = form.action + "&action.change.category=true" + "&selectedCategoryId=" + id;
        }
        
        windowOpen = null;
        form.submit();
    }

    function unloadPage() {
        if (currentCalendar != null) {
              hideCalendar();
        }

        if (windowOpen != null) {
            windowOpen.close();
        }
    }

    </script>
</head>

<body onload="init();" onunload="unloadPage();" topmargin="0" marginheight="0">
<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
<html:form action="/editMessenger" method="post">
<bean:define id="form" name="editMessengerForm" scope="request" type="vkc.messenger.form.EditMessengerForm" toScope="request"/>

<html:hidden property="selectedId" />
<html:hidden property="uniqueId"/>
<logic:iterate id="qid" name="form" property="queryIds" type="java.lang.Integer">
  <html:hidden property="queryIds" name="form" value='<%=String.valueOf(qid.toString())%>'/>
  <vkc:hidden property='<%= "dynaValue(queryId_" + qid.toString() + ")" %>'/>
</logic:iterate>

<logic:equal name="form" property="editMode" value='<%=EditMessengerForm.EDITMODE_SEARCHQUERY%>'>
  <logic:iterate id="scid" name="form" property="selectedCategoryIds" type="java.lang.Integer">
    <html:hidden property="selectedCategoryIds" name="form" value='<%=String.valueOf(scid.toString())%>'/>
  </logic:iterate>
  <logic:iterate id="sdid" name="form" property="selectedDocumentIds" type="java.lang.Integer">
    <html:hidden property="selectedDocumentIds" name="form" value='<%=String.valueOf(sdid.toString())%>'/>
  </logic:iterate>
  <logic:iterate id="sqid" name="form" property="selectedQueryIds" type="java.lang.Integer">
    <html:hidden property="selectedQueryIds" name="form" value='<%=String.valueOf(sqid.toString())%>'/>
  </logic:iterate>
  <logic:iterate id="ssid" name="form" property="selectedSubDirIds" type="java.lang.Integer">
    <html:hidden property="selectedSubDirIds" name="form" value='<%=String.valueOf(ssid.toString())%>'/>
  </logic:iterate>
  <vkc:hidden property="keywordsString" name="form"/>
  <html:hidden property="selectedMessagingTimePeriod" name="form"/>
  <logic:equal name="form" property="messagingEnabled" value="true">
    <html:hidden property="messagingEnabled" name="form"/>
  </logic:equal>
  <logic:iterate id="dynaKey" name="form" property="dynaKeys" type="java.lang.String">
    <vkc:hidden property='<%= "dynaValue(" + dynaKey + ")" %>'/>
  </logic:iterate>

  <jsp:include page="../admin/EditSearchQueryView.jsp" flush="true">
      <jsp:param name="hidePubDate" value="true"/>
      <jsp:param name="hideDisplayOptions" value="true"/>
  </jsp:include>
</logic:equal>

<logic:equal name="form" property="editMode" value='<%=EditMessengerForm.EDITMODE_MESSENGER%>'>
<table width="100%" cellspacing="3" cellpadding="0" border="0">
  <tr>
    <td align="left" nowrap="nowrap"><b><vkc:message key="vkc.messenger.messaging" />:</b></td>
    <td align="left" nowrap="nowrap">&nbsp;&nbsp;&nbsp;</td>
    <td width="100%" align="left" nowrap="nowrap"><html:checkbox name="form" property="messagingEnabled" /></td>
  </tr>

  <tr>
    <td align="left" nowrap="nowrap"><b><vkc:message key="vkc.messenger.messagingTimePeriod" />:</b></td>
    <td align="left" nowrap="nowrap">&nbsp;&nbsp;&nbsp;</td>
    <td width="100%" align="left" nowrap="nowrap">
      <html:select name="form" property="selectedMessagingTimePeriod" size="1">
        <html:option value="0"><vkc:message key="vkc.messenger.messagingTimePeriod.0Minutes" /></html:option>
        <html:option value="15"><vkc:message key="vkc.messenger.messagingTimePeriod.15Minutes" /></html:option>
        <html:option value="30"><vkc:message key="vkc.messenger.messagingTimePeriod.30Minutes" /></html:option>
        <html:option value="60"><vkc:message key="vkc.messenger.messagingTimePeriod.1Hour" /></html:option>
        <html:option value="120"><vkc:message key="vkc.messenger.messagingTimePeriod.2Hours" /></html:option>
        <html:option value="240"><vkc:message key="vkc.messenger.messagingTimePeriod.4Hours" /></html:option>
        <html:option value="480"><vkc:message key="vkc.messenger.messagingTimePeriod.8Hours" /></html:option>
        <html:option value="1440"><vkc:message key="vkc.messenger.messagingTimePeriod.1Day" /></html:option>
        <html:option value="4320"><vkc:message key="vkc.messenger.messagingTimePeriod.3Days" /></html:option>
        <html:option value="10080"><vkc:message key="vkc.messenger.messagingTimePeriod.1Week" /></html:option>
        <html:option value="302400"><vkc:message key="vkc.messenger.messagingTimePeriod.1Month" /></html:option>
      </html:select>
    </td>
  </tr>

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

  <tr><td align="left" nowrap="nowrap" colspan="3"><b><vkc:message key="vkc.messenger.categories" /></b></td></tr>

  <bean:define id="registeredCategories" name="<%=WebShare.USER_KEY%>" property="registeredCategoriesSortedByPath"/>

  <logic:notEmpty name="registeredCategories" >
  <tr>
    <td nowrap="nowrap" colspan="3" class="tableLineColor">
    <table width="100%" class="tableLineColor" cellSpacing="1" cellPadding="2" border="0">
      <tr>
        <td nowrap="nowrap" class="headerUnselected">&nbsp;</td>
        <td width="100%" align="left" nowrap="nowrap" class="headerUnselected"><b><vkc:message key="vkc.messenger.category"/></b></td>
        <td nowrap="nowrap" class="headerUnselected"> <b><vkc:message key="vkc.messenger.subjectfornotification"/></b></td>
        <td align="center" nowrap="nowrap" class="headerUnselected"><b><vkc:message key="vkc.messenger.registerSubCat" /></b></td>
      </tr>

      <logic:iterate id="category" name="registeredCategories" type="vkc.view.bean.RegisteredCategory">
      <tr>
        <td align="center" nowrap="nowrap" class="columnUnselected">
          <html:multibox name="form" property="selectedCategoryIds">
            <vkc:write name="category" property="categoryId"/>
          </html:multibox>
        </td>
        <td width="100%" align="left" class="columnSelected"><b>
          <bean:define   id="absPathDescr" name="category"     property="absPathDescr" type="vkc.util.VKCCategoryAbsPath"/>
          <bean:define   id="pathNodes"    name="absPathDescr" property="pathNodes"    />
          <logic:iterate id="pathdescr"    name="pathNodes"    indexId="index" type="vkc.util.VKCCategoryPathNode">
            <logic:greaterThan name="index" value="0">
            <span dir="ltr">
            <vkc:img page="/templates/${template.name}/gfx/dot.gif" alt="" border="0"/>
            </span>
            </logic:greaterThan>

            <logic:equal value="true" name="pathdescr" property="lastNode">
            <span dir="ltr">
            <vkc:link page="/showCategory.do" paramId="categoryId" paramName="pathdescr" paramProperty="pathId" title='<%=absPathDescr.getAbsolutePathString()%>'><vkc:write name="pathdescr" property="pathName"/></vkc:link>
            </span>
            </logic:equal>

            <logic:equal value="false" name="pathdescr" property="lastNode">
            <span dir="ltr">
            <b><vkc:write name="pathdescr" property="shortPathName"/></b>
            </span>
            </logic:equal>
          </logic:iterate>
          </b>
        </td> 
        <bean:define id="selectedCategoryIds" name="form" property="selectedCategoryIds"/>
        <td width="100%" align="left" class="columnUnselected"><vkc:text name="form" property='<%= "dynaValue(categorySubjectId_" + category.getCategoryId() + ")" %>' maxlengthProperty="40"/></td>       
        <td align="center" nowrap="nowrap" class="columnUnselected"><b>
          <html:multibox name="form" property="selectedSubDirIds">
            <vkc:write name="category" property="categoryId"/>
          </html:multibox></b>
        </td> 
      </tr>
      </logic:iterate>
    </table>
    </td>
  </tr>
  </logic:notEmpty>

  <logic:empty name="registeredCategories">
  <tr><td nowrap="nowrap" colspan="3"><vkc:message key="vkc.messenger.none"/></td></tr>
  </logic:empty>

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

  <tr><td align="left" nowrap="nowrap" colspan="3"><b><vkc:message key="vkc.messenger.documents" /></b></td></tr>

  <bean:define id="registeredDocuments" name="<%=WebShare.USER_KEY%>" property="registeredDocumentsSortedByTitle"/>

  <logic:notEmpty name="registeredDocuments">
  <tr>
    <td nowrap="nowrap" colspan="3" class="tableLineColor">
    <table width="100%" class="tableLineColor" cellSpacing="1" cellPadding="2" border="0">
      <tr>
        <td nowrap="nowrap" class="headerUnselected">&nbsp;</td>
        <td width="100%" align="left" nowrap="nowrap" class="headerUnselected"><b><vkc:message key="vkc.messenger.document"/></b></td>
        <td nowrap="nowrap" class="headerUnselected"> <b><vkc:message key="vkc.messenger.subjectfornotification"/></b></td>
        <td align="center" nowrap="nowrap" class="headerUnselected"><b><vkc:message key="vkc.messenger.threshold" /></b></td>
      </tr>
      <logic:iterate id="document" name="registeredDocuments" type="vkc.view.bean.RegisteredDocument">
      <bean:define id="catAbsPath" name="document"   property="categoryAbsPath" type="vkc.util.VKCCategoryAbsPath"/>
      <bean:define id="lastNode"   name="catAbsPath" property="lastNode" 		type="vkc.util.VKCCategoryPathNode"/>
      <logic:present name="<%=org.apache.struts.Globals.ERROR_KEY%>">
        <html:messages id="msg" message="false" property='<%= String.valueOf( "thresholdId_" + document.getDocumentId() ) %>' >
          <tr><td align="right" nowrap="nowrap" colspan="3" class="columnUnselected"><b><font color="#ff0000"><vkc:write name="msg"/></font></b></td></tr>
        </html:messages>
      </logic:present>

      <tr>
        <td align="center" nowrap="nowrap" class="columnUnselected">
          <html:multibox name="form" property="selectedDocumentIds">
            <vkc:write name="document" property="documentId"/>
          </html:multibox>
        </td>
                
        <td width="100%" align="left" class="columnSelected">
          <logic:equal name="document" property="file" value="true">
            <vkc:img page="/templates/${template.name}/gfx/document.gif" altKey="vkc.document" align="texttop" border="0"/>
          </logic:equal>
          <logic:equal name="document" property="link" value="true">
            <vkc:img page="/templates/${template.name}/gfx/www-link.gif" align="texttop" border="0" alt=""/>
          </logic:equal>
          <logic:equal name="document" property="note" value="true">
            <vkc:img page="/templates/${template.name}/gfx/note.gif" align="texttop" border="0" alt=""/>
          </logic:equal>

          <vkc:link page="/showCategory.do" paramId="categoryId" paramName="document" paramProperty="categoryId" anchor='<%="doc" + document.getDocumentId()%>' title="<%=catAbsPath.getAbsolutePathString()%>">
            <logic:equal name="document" property="title" value="">
            <vkc:write name="document" property="name"/>
            </logic:equal>
            <logic:notEqual name="document" property="title" value="">
            <vkc:write name="document" property="title"/>
            </logic:notEqual>
          </vkc:link>
        </td>       
        <td width="100%" align="left" class="columnUnselected"><vkc:text name="form" property='<%= "dynaValue(documentSubjectId_" + document.getDocumentId() + ")" %>' maxlengthProperty="40"/></td>
        
        <td align="center" nowrap="nowrap" class="columnUnselected">
          <html:text property='<%= "dynaValue(thresholdId_" + document.getDocumentId() + ")" %>' maxlength="3" size="3" styleClass="dateField"/>
        </td>
        
      </tr>
      </logic:iterate>
    </table>
    </td>
  </tr>
  </logic:notEmpty>

  <logic:empty name="registeredDocuments">
  <tr><td nowrap="nowrap" colspan="3"><vkc:message key="vkc.messenger.none"/></td></tr>
  </logic:empty>

<!-- Registered Searchqueries -->
  <vkc:hline colspan="3" lineClass="hline" lineHeight="1" topSpace="5" bottomSpace="5"/>

  <tr><td align="left" nowrap="nowrap" colspan="3"><b><vkc:message key="vkc.messenger.reg.queries"/>:</b></td></tr>

  <bean:define id="registeredQueries" name="form" property="registeredQueries"/>

  <logic:notEmpty name="registeredQueries">
  <tr>
    <td nowrap="nowrap" colspan="3" class="tableLineColor">
    <table width="100%" class="tableLineColor" cellSpacing="1" cellPadding="2" border="0">
      <tr>
        <td nowrap="nowrap" class="headerUnselected">&nbsp;</td>
        <td width="100%" align="left" nowrap="nowrap" class="headerUnselected"><b><vkc:message key="vkc.messenger.query"/></b></td>
        <td nowrap="nowrap" class="headerUnselected"> <b><vkc:message key="vkc.messenger.subjectfornotification"/></b></td>
        <td align="center" nowrap="nowrap" class="headerUnselected">&nbsp;</td>
      </tr>
      <logic:iterate id="query" name="registeredQueries" type="vkc.db.entities.VKCSearchQuery">
      <tr>
        <td align="center" nowrap="nowrap" class="columnUnselected">
          <html:multibox name="form" property="selectedQueryIds">
          <vkc:write name="query" property="queryId"/>
          </html:multibox>
        </td>
        <td width="100%" align="left" nowrap="nowrap" class="columnSelected">
          <%=query.getLocalizedHTMLString( form.getResources(), form.getLocale(), false, false)%>
        </td>
        <td width="100%" align="left" class="columnUnselected"><vkc:text name="form" property='<%= "dynaValue(querySubjectId_" + query.getQueryId() + ")" %>' maxlengthProperty="40"/></td>
        <td align="center" valign="bottom" nowrap="nowrap" class="columnUnselected">
          <vkc:button property="action.edit.searchquery" onclick='<%="javascript:editQuery(this, " + query.getQueryId() + ");"%>'><vkc:message key="button.edit"/></vkc:button>
        </td>
      </tr>
      </logic:iterate>
    </table>
    </td>
  </tr>
  <tr><td nowrap="nowrap" colspan="3">&nbsp;</td></tr>
  </logic:notEmpty>

  <logic:empty name="registeredQueries">
  <tr>
      <td nowrap="nowrap" colspan="3"><vkc:message key="vkc.messenger.none"/></td>
  </tr>
  </logic:empty>

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

  <tr>
    <td align="center" colspan="3">
        <vkc:button property="action.save.messenger" onclick="javascript:disableAllButtonsAndSubmit(this);"><vkc:message key="button.update"/></vkc:button>&nbsp;
        <vkc:button property="action.create.searchquery" onclick="javascript:disableAllButtonsAndSubmit(this);"><vkc:message key="button.createQuery"/></vkc:button>
      </td>
  </tr>
</table>
</logic:equal>
</html:form>
</body>
</html:html>
