<%@ page language="java" buffer="100kb" errorPage="/common/error.jsp"%>
<%@ page import="vkc.db.entities.VKCDocument" %>
<%@ page import="vkc.view.*" %>

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

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

    <title><vkc:message key="vkc.string.historyList"/></title>

	<vkc:cssinclude />

    <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
    <meta HTTP-EQUIV="cache"        CONTENT="no-cache">
    <meta HTTP-EQUIV="expires"      CONTENT="0">

    <script type="text/javascript" src="<vkc:rewrite page='/common/utils.js'/>"></script>

    <script type="text/javascript">
	window.name = "MAINVIEW";
	var associatedTabId = <%=TabId.HISTORY_TAB%>;

  	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.HISTORY_TAB%>"
          						   + "&lastCategoryId=" + tabViewForm.lastCategoryId.value
          						   + "&lastFunctionalId=" + tabViewForm.lastFunctionalId.value
          						   + "&lastProjectId=" + tabViewForm.lastProjectId.value);
      	}
      	
      	setAnchor();
  	}

	function setAnchor() {
		<logic:present parameter="anchor">
			<bean:parameter id="anchor2" name="anchor"/>
			this.location.hash = '<%=anchor2%>';
		</logic:present>
	}

    function openUserInfoWindow( id ) {
        var w = 800;
        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';
        var win = window.open( '<vkc:rewrite page="/displayUserInfo.do"/>?userId=' + id, 'USERINFO_MAINVIEW', settings );
        win.focus();                              
    }

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

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

        form.submit();
    }

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

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

        form.submit();
    }

    function deleteDocumentHistory(elem) {
        var form = document.forms[0];	        

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

        disableAllButtons(elem);
        form.submit();
    }
    
    </script>

</head>

<body onload="init();" marginwidth="5" marginheight="0" topmargin="0" bottommargin="5" leftmargin="5" rightmargin="5">
<html:form action="/showHistory" method="post">
<bean:define id="form" name="showHistoryForm" type="vkc.profile.form.ShowHistoryForm" toScope="request"/>
<logic:notEmpty name="form" property="documents">
  <html:hidden property="selectedId" />
  <logic:iterate id="id" name="form" property="showDocumentDetails" type="java.lang.Integer">
    <html:hidden property="showDocumentDetails" name="form" value='<%=String.valueOf(id.toString())%>'/>
  </logic:iterate>
  
  <bean:define id="userDocumentViewSettings" name="documentViewSettings" type="vkc.view.bean.DocumentViewSettings" toScope="request" />
  
  <logic:iterate id="udh" name="form" property="documents" type="vkc.db.entities.VKCUserDocHistory" indexId="index">
    <bean:define id="doc" name="udh" property="document" type="vkc.db.entities.VKCDocument"/>
    <logic:equal name="doc" property="flag" value="<%=String.valueOf(VKCDocument.FLAG_PUBLISHED)%>">
    <bean:define id="documentId" name="doc" property="documentId" type="java.lang.Integer"/>
    <table width="100%" cellspacing="0" cellpadding="0" border="0">
      <tr>
        <td>
          <table width="100%" cellspacing="0" cellpadding="0" border="0">
            <tr>
		      <a name='doc<vkc:write name="doc" property="documentId"/>'></a>
              <td>
                <table width="100%" cellspacing="0" cellpadding="1" border="0">
                  <tbody>
                    <tr class="color_doctitle">					  
					  <logic:equal name="form" property='<%= "showDocDetails[" + documentId + "]" %>' value="false">
					  <td><vkc:link href='<%= "javascript:showDocumentDetails(" + documentId + ");" %>'><vkc:img page="/templates/${template.name}/gfx/plus.gif" border="0" titleKey="vkc.tooltip.show.document.details"/></vkc:link>&nbsp;</td>
					  </logic:equal>          

					  <logic:equal name="form" property='<%= "showDocDetails[" + documentId + "]" %>' value="true">
					  <td><vkc:link href='<%= "javascript:hideDocumentDetails(" + documentId + ");" %>'><vkc:img page="/templates/${template.name}/gfx/minus.gif" border="0" titleKey="vkc.tooltip.hide.document.details"/></vkc:link>&nbsp;</td>
					  </logic:equal>          

                      <bean:define id="documentIcon" name="doc" property="documentIcon" type="java.lang.String"/>
                      <td><vkc:img page='<%="/templates/${template.name}" + documentIcon%>' alt=""/></td>
					  <td><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="2" height="10"/></td>
                      <td align="left" width="100%"><b><vkc:write name="doc" property="title"/></b></td>
					  <td nowrap><b>[&nbsp;<vkc:message key="vkc.lastaccessed_individual"/>:</b>&nbsp;<vkc:write name="udh" property="lastAccessed" formatKey="date.medium.format"/>&nbsp;<b>]</b></td>
                    </tr>
                  </tbody>
                </table>
              </td>
            </tr>

	        <bean:define id="displayCategoryPath" type="java.lang.String" value="true" toScope="request"/>
	        <bean:define id="document" name="doc" type="vkc.db.entities.VKCDocument" toScope="request" />
      	    <bean:define id="currentUser" name="form" property="user" type="vkc.db.entities.VKCUser" toScope="request"/>

		    <logic:equal name="form" property='<%= "showDocDetails[" + documentId + "]" %>' value="true">
	        <bean:define id="documentViewSettings" name="documentViewSettings" property="fullviewDocumentViewSettings" type="vkc.view.bean.DocumentViewSettings" toScope="request" />
		    </logic:equal>          
		    <logic:equal name="form" property='<%= "showDocDetails[" + documentId + "]" %>' value="false">
	        <bean:define id="documentViewSettings" name="userDocumentViewSettings" type="vkc.view.bean.DocumentViewSettings" toScope="request" />
		    </logic:equal>          
      
    		<jsp:include page='<%="/templates/" + template + "/common/DocumentView.jsp"%>'/>
            <tr><td><vkc:img page="/templates/${template.name}/gfx/trans.gif" width="10" height="10" alt=""/></td></tr>
          </table>
        </td>
      </tr>
    </table>
    </logic:equal>
  </logic:iterate>
  <table width="100%" cellspacing="0" cellpadding="0" border="0">
    <tr><td align="center"><hr></td></tr>
    <tr>
      <td align="center"><vkc:button property="deleteButton" onclick="javascript:deleteDocumentHistory(this);"><vkc:message key="button.history.deleteHistory"/></vkc:button></td>
    </tr>
  </table>
</logic:notEmpty>
<logic:empty name="form" property="documents">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
  <tr><td width="100%" align="center"><br><br><b><vkc:message key="vkc.search.historyDocuments.empty"/></b></td></tr>
</table>    
</logic:empty>
</html:form>
</body>
</html:html>