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

<%@ 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>

	<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" src="<vkc:rewrite page='/common/calendar.js'/>"></script>

    <script type="text/javascript">

    window.name = "MAINVIEW";
    var currentCalendar = null;

    function init(){
        setAnchor();
    }

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

    function confirmRecoverDocument( id ) {
        var form  = document.forms[ 0 ];
           form.recoverDocumentId.value = id;
        return confirm('<vkc:message javascript="true" filter="false" key="vkc.string.confirm.recover.document"/>');
    }

    function confirmDeleteDocument( id ) {
        var form  = document.forms[ 0 ];
           form.deleteDocumentId.value = id;
        return confirm('<vkc:message javascript="true" filter="false" key="vkc.string.confirm.delete.document"/>');
    }

    function checkAll( mForm ){
        for(var i=0 ; i<mForm.elements.length ; i++){
            var elem = mForm.elements[i];
            if(elem.name!='allItems') {
                elem.checked=mForm.allItems.checked;
            }
        }
    }

    function getNumberOfCheckedEntries() {
        var form  = document.forms[ 0 ];
        var field = form.selectedIds;

        if ( !field )
            return 0;

        if ( !field.length ) {

            <%-- nur eine Checkbox auf der Seite --%>
            if ( field.checked ) {
                return 1;
            } else {
                return 0;
            }
        }

        var checked = 0;

        for ( var i=0 ; i<field.length ; i++ ) {
            if ( field[i].checked ) {
                checked++;
            }
        }
        return checked;
    }

    function deleteDocuments(elem) {
        var numChecked = getNumberOfCheckedEntries();

        if ( numChecked == 0 ) {
            alert( '<vkc:message javascript="true" filter="false" key="error.noitem_checked"/>' );
            return;
        }

        if ( numChecked==1 ) {
            if ( !confirm( '<vkc:message javascript="true" filter="false" key="vkc.string.confirmation"/>' ) )
                return;
        } else {
            if ( !confirm( '<vkc:message javascript="true" filter="false" key="vkc.string.confirmation"/>' ) )
                return;
        }

        var form  = document.forms[0];

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

        disableAllButtons(elem);
        form.submit();
    }

    function recoverDocuments(elem) {
        var numChecked = getNumberOfCheckedEntries();

        if ( numChecked == 0 ) {
            alert( '<vkc:message javascript="true" filter="false" key="error.noitem_checked"/>' );
            return;
        }

        if ( numChecked==1 ) {
            if ( !confirm( '<vkc:message javascript="true" filter="false" key="vkc.string.confirmation"/>' ) )
                return;
        } else {
            if ( !confirm( '<vkc:message javascript="true" filter="false" key="vkc.string.confirmation"/>' ) )
                return;
        }

        var form  = document.forms[0];

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

        disableAllButtons(elem);
        form.submit();
    }

    function modifyDocuments(elem) {
        var form = document.forms[ 0 ];
        var field = form.selectedCmdAction.value;

        if ( field == "noaction" || field == "noaction1" ) {
               alert( '<vkc:message javascript="true" filter="false" key="error.noaction_choosen"/>' );
        }

        if ( field == "delete.documents" ) {
            deleteDocuments(elem);
        }

        if ( field == "recover.documents" ) {
            recoverDocuments(elem);
        }
    }

    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 showDocuments(id) {
        var form = document.forms[0];
        form.selectedId.value = id;

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

        form.submit();
    }

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

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

        form.submit();
    }

    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 unloadPage() {
        if ( currentCalendar!=null ) {
              hideCalendar();
        }
    }

    </script>
</head>

<body onload="init();" onUnload="unloadPage();" marginwidth="5" marginheight="0" topmargin="0" bottommargin="5" leftmargin="5" rightmargin="5">
<html:form action="/userExpiredDocuments" method="post">

<bean:define id="form" name="userExpiredDocumentsForm" scope="request" type="vkc.profile.form.UserExpiredDocumentsForm" toScope="request"/>
<bean:size id="docCounts" name="form" property="expiredDocuments"/>

<html:hidden property="deleteDocumentId" value="-1"/>
<html:hidden property="recoverDocumentId" value="-1"/>
<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>
<logic:iterate id="did" name="form" property="showDocuments" type="java.lang.Integer">
  <html:hidden property="showDocuments" name="form" value='<%=String.valueOf(did.toString())%>'/>
</logic:iterate>

<bean:define id="userDocumentViewSettings" name="documentViewSettings" type="vkc.view.bean.DocumentViewSettings" toScope="request" />

<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
  <logic:greaterThan name="docCounts" value="0">
  <tr><td><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="1" height="5"/></td></tr>
  <tr><td align="center" nowrap="nowrap" colspan="2"><b><vkc:message key="vkc.profile.manageUserExpiredDocuments" /></b></td></tr>
  <tr><td><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="1" height="5"/></td></tr>
  </logic:greaterThan>

  <logic:equal name="docCounts" value="0">
  <tr><td><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="1" height="5"/></td></tr>
  <tr><td align="center" nowrap="nowrap" colspan="2"><b><vkc:message key="vkc.profile.manageUserExpiredDocuments.noDocuments" /></b></td></tr>
  <tr><td><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="1" height="5"/></td></tr>
  </logic:equal>
</table>


<logic:greaterThan name="docCounts" value="0">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
  <tr>
    <td colspan="2">
      <table width="100%" cellspacing="0" cellpadding="0" border="0">
	  <logic:iterate id="doc" indexId="ctr" name="form" property="expiredDocuments" type="vkc.db.entities.VKCDocument">
	  <bean:define id="docId" name="doc" property="documentId" type="java.lang.Integer"/>
	  <tr>
	    <td width="1" valign="top"><html:multibox name="form" property="selectedIds" onfocus="this.blur();"><vkc:write name="doc" property="documentId"/></html:multibox></td>
	 
	    <logic:equal name="form" property='<%= "showDocs[" + docId + "]" %>' value="false">
	    <td width="1" valign="top"><vkc:link href='<%= "javascript:showDocuments(" + docId + ");" %>'><vkc:img page="/templates/${template.name}/gfx/plus-big.gif" border="0" titleKey="vkc.tooltip.show.documents"/></vkc:link></td>
	    <td width="1" valign="top"><vkc:img page='<%="/templates/" + template + doc.getDocumentIcon()%>' altKey='vkc.document' border='0'/></td>
	    <td width="100%" valign="top">
		  <a name='<%="doc" + doc.getDocumentId()%>'></a>
	      <table width="100%" cellspacing="0" cellpadding="1" border="0">
	        <tr>
	          <td width="100%" align="left">
		      	<table cellspacing="0" cellpadding="1" border="0">
		      	  <tr>
		      	    <td>
		              <logic:equal name="doc" property="note" value="true">
		              <span style="font-weight:bold;"><vkc:write name="doc" property="title"/></span>
		              </logic:equal>
		              <logic:equal name="doc" property="note" value="false">
		              <vkc:displaydocument name="doc" style="font-weight:bold;" target="_blank" ><vkc:write name="doc" property="title"/></vkc:displaydocument>
				      </logic:equal>
			        </td>
                    <!-- Wiederherstellen -->
                    <td align="left"><vkc:image property="btn_recover" page="/templates/${template.name}/gfx/button-newdocument.gif" alt="" titleKey="vkc.tooltip.recoverdocument" onclick='<%= "return confirmRecoverDocument(" + docId + ");" %>'/></td>
                    <!-- Löschen -->
                    <td align="left"><vkc:image property="btn_delete" page="/templates/${template.name}/gfx/button-deletedocument.gif" alt="" titleKey="vkc.tooltip.deletedocument" onclick='<%= "return confirmDeleteDocument(" + docId + ");" %>'/></td>
			      </tr>
	
	              <vkc:hline colspan="5" lineClass="hline" lineHeight="1" topSpace="5" bottomSpace="0"/>

	              <tr>
	                <td>
	                  <table width="100%" cellspacing="5" cellpadding="0" border="0">
	                    <tr>
	                      <td valign="top" nowrap="nowrap" colspan="1"><b><vkc:message key="vkc.profile.manageUserExpiredDocuments.documentExpires"/></b></td>
	                      <td width="100%" valign="top" nowrap="nowrap" colspan="3">
	                        <table>
	                          <tr>
	                            <td><html:text name="form" property='<%= String.valueOf( "dynaValue(expiredId_" + docId + ")" )%>' maxlength="10" size="10" styleClass="dateField"/></td>
	                            <td><vkc:calendarbutton buttonName='<%= String.valueOf( "btn_dynaValue(expiredId_" + docId + ")" )%>'/></td>
	                            <td>[<vkc:message key="vkc.profile.date_format"/>]</td>
	                          </tr>
	                        </table>
	                      </td>
	                    </tr>
	                    <tr>
	                      <td valign="top" nowrap="nowrap" colspan="1"></td>
	                      <td width="100%" valign="top" nowrap="nowrap" colspan="3">
	                        <table>
	                          <tr>
	                              <td><font color="red"><vkc:errors property='<%= "illegal_operation[" + docId + "]" %>' /></font></td>
	                              <td><font color="red"><vkc:errors property='<%= "invalid_date[" + docId + "]" %>' /></font></td>
	                          </tr>
	                        </table>
	                      </td>
	                    </tr>
	                  </table>
	                </td>
	              </tr>
	
			    </table>
	          </td>
	        </tr>
	      </table>
	    </td>
	    </logic:equal>
	
	    <logic:equal name="form" property='<%= "showDocs[" + docId + "]" %>' value="true">
	    <td width="1" valign="top"><vkc:link href='<%= "javascript:hideDocuments(" + docId + ");" %>'><vkc:img page="/templates/${template.name}/gfx/minus-big.gif" border="0" titleKey="vkc.tooltip.hide.documents"/></vkc:link></td>
		<td width="1" valign="top"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="24"/></td>
	    <td width="100%" valign="top">
		  <a name='<%="doc" + doc.getDocumentId()%>'></a>
	      <table width="100%" cellspacing="0" cellpadding="0" border="0">
	        <tr>
	          <td>
	            <table width="100%" cellspacing="0" cellpadding="0" border="0">
	              <tr>
	                <td>
	                  <table width="100%" cellspacing="0" cellpadding="0" border="0">
	                    <tbody>
	                      <tr class="color_doctitle">
	                        <logic:equal name="form" property='<%= "showDocDetails[" + docId + "]" %>' value="false">
	                        <td><vkc:link href='<%= "javascript:showDocumentDetails(" + docId + ");" %>'><vkc:img page="/templates/${template.name}/gfx/plus.gif" border="0" titleKey="vkc.tooltip.show.document.details"/></vkc:link></td>
	                        </logic:equal>
	
	                        <logic:equal name="form" property='<%= "showDocDetails[" + docId + "]" %>' value="true">
	                        <td><vkc:link href='<%= "javascript:hideDocumentDetails(" + docId + ");" %>'><vkc:img page="/templates/${template.name}/gfx/minus.gif" border="0" titleKey="vkc.tooltip.hide.document.details"/></vkc:link></td>
	                        </logic:equal>
	                        <td><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="4" height="10"/></td>
	                        <td><vkc:img page='<%="/templates/${template.name}" + doc.getDocumentIcon()%>' alt='' border='0'/></td>
	                        <td><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="2" height="10"/></td>
	                        <td width="100%" align="left"><b><vkc:write name="doc" property="title"/></b></td>
	
	                        <!-- Wiederherstellen -->
	                        <td><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="5" height="10"/></td>
	                        <td><vkc:image property="btn_recover" page="/templates/${template.name}/gfx/button-newdocument.gif" alt="" titleKey="vkc.tooltip.recoverdocument" onclick='<%= "return confirmRecoverDocument(" + docId + ");" %>'/></td>
	
	                        <!-- Löschen -->
	                        <td><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="5" height="10"/></td>
	                        <td><vkc:image property="btn_delete" page="/templates/${template.name}/gfx/button-deletedocument.gif" alt="" titleKey="vkc.tooltip.deletedocument" onclick='<%= "return confirmDeleteDocument(" + docId + ");" %>'/></td>
	
	                        <td><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="5" height="10"/></td>
	                        <td><vkc:img page="/templates/${template.name}/gfx/border.gif" alt="|" width="2" height="24"/></td>
	                        <td><a href="#top" onclick="this.blur();" onfocus="this.blur();"><vkc:img page="/templates/${template.name}/gfx/button-top.gif" border="0" alt="" titleKey="vkc.tooltip.gototop"/></a></td>
	                        <td><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="5" height="10"/></td>
	                      </tr>
	                    </tbody>
	                  </table>
	                </td>
	              </tr>
	
	              <bean:define id="displayCategoryPath" type="java.lang.String" value="true" toScope="request"/>
	              <bean:define id="refuseDocumentEditing" type="java.lang.String" value="true" toScope="request"/>
	              <bean:define id="document" name="doc" toScope="request"/>
	      	      <bean:define id="currentUser" name="form" property="user" type="vkc.db.entities.VKCUser" toScope="request"/>
	
	              <logic:equal name="form" property='<%= "showDocDetails[" + docId + "]" %>' 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[" + docId + "]" %>' 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>
	                  <table width="100%" cellspacing="5" cellpadding="0" border="0">
	                    <tr>
	                      <vkc:hline colspan="5" lineClass="hline" lineHeight="1" topSpace="0" bottomSpace="5"/>
	                      <td valign="top" nowrap="nowrap" colspan="1"><b><vkc:message key="vkc.profile.manageUserExpiredDocuments.documentExpires"/></b></td>
	                      <td width="100%" valign="top" nowrap="nowrap" colspan="3">
	                        <table>
	                          <tr>
	                            <td><html:text name="form" property='<%= String.valueOf( "dynaValue(expiredId_" + docId + ")" )%>' maxlength="10" size="10" styleClass="dateField"/></td>
	                            <td><vkc:calendarbutton buttonName='<%= String.valueOf( "btn_dynaValue(expiredId_" + docId + ")" )%>'/></td>
	                            <td>[<vkc:message key="vkc.profile.date_format"/>]</td>
	                          </tr>
	                        </table>
	                      </td>
	                    </tr>
	                    <tr>
	                      <td valign="top" nowrap="nowrap" colspan="1"></td>
	                      <td width="100%" valign="top" nowrap="nowrap" colspan="3">
	                        <table>
	                          <tr>
	                              <td><font color="red"><vkc:errors property='<%= "illegal_operation[" + docId + "]" %>' /></font></td>
	                              <td><font color="red"><vkc:errors property='<%= "invalid_date[" + docId + "]" %>' /></font></td>
	                          </tr>
	                        </table>
	                      </td>
	                    </tr>
	                  </table>
	                </td>
	              </tr>
	            </table>
	          </td>
	        </tr>
	      </table>
	    </td> 
	    </logic:equal>
	  </tr>
	  </logic:iterate>
	  </table>
    </td>
  </tr>

  <tr><td colspan="2"><input type="checkbox" name="allItems" value="allItems" onclick="javascript:checkAll(this.form);">&nbsp;<vkc:message key="vkc.string.checkAll"/></td></tr>
  <tr><td align="center"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="10" height="10" border="0"/></td></tr>
  <tr>
    <td>
      <vkc:img page="/templates/${template.name}/gfx/function-arrow.gif" alt="-->" align="texttop" border="0"/>
      <html:select name="form" property="selectedCmdAction">
        <html:option value="noaction"><vkc:message key="vkc.string.chooseFunction"/></html:option>
        <html:option value="noaction1">------------------------------------</html:option>
        <html:option value="delete.documents"><vkc:message key="button.delete"/></html:option>
        <html:option value="recover.documents"><vkc:message key="button.recover"/></html:option>
      </html:select>&nbsp;
      <vkc:button property="action.execute" onclick="modifyDocuments(this);"><vkc:message key="button.execute"/></vkc:button>
    </td>
  </tr>
</table>
</logic:greaterThan>

<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
  <logic:greaterThan name="docCounts" value="0">
  <vkc:hline colspan="5" lineClass="hline" lineHeight="1" topSpace="0" bottomSpace="5"/>
  </logic:greaterThan>
  <tr>
    <td align="center" colspan="2">
      <vkc:button property="action.back" onclick="javascript:disableAllButtonsAndSubmit(this);"><vkc:message key="button.back"/></vkc:button>
    </td>
  </tr>
</table>
</html:form>
</body>
</html:html>