<%@ page language="java" buffer="64kb" %>

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

<%@ page import="vkc.db.entities.VKCCategory" %>
<%@ page import="vkc.view.WebShare" %>
<%@ page import="vkc.procoba.project.ProjectViewForm"%>

<vkc:checkLogin />

<vkc:init/>

<html:html locale="true">
<bean:define id="form" name="projectViewForm" type="vkc.procoba.project.ProjectViewForm" toScope="request"/>

<head>
  <meta http-equiv="Content-Type"        content="text/html; charset=iso-8859-1">
  <meta http-equiv="Content-Script-Type" content="text/javascript">
  <meta http-equiv="Content-Style-Type"  content="text/css">
  <meta http-equiv="cache"               content="no-cache">
  <meta http-equiv="cache-control"       content="no-cache">
  <meta http-equiv="pragma"              content="no-cache">
  <meta http-equiv="expires"             content="0">

  <vkc:cssinclude />

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

  <script type="text/javascript">
  window.name = "MAINVIEW";
  initTinyMCE("<vkc:write name='user' property='language.shortName'/>", "<vkc:rewrite page='/templates/${template.name}/tiny_mce.css'/>");
  var viewId = <%=vkc.view.PageId.PROJECT_VIEW.toString()%>;
  var selectedTabId = <vkc:write name="form" property="projectId"/>;
  var selectedViewId = <%=vkc.view.PageId.PROJECT_VIEW.toString()%>;
  var currentCalendar = null;
  var markedDoc = 0;

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

  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 init() {
      var tabView = getTabView();
      var systemviewtype = "procobaview";

      if (tabView && tabView.systemviewtype == "procobaview" && tabView.selectedTabId == selectedTabId) {
          tabView.lastProjectId = '<vkc:write name="form" property="projectId"/>';
          var tabViewForm = tabView.document.forms[0];
          tabViewForm.lastProjectId.value = tabView.lastProjectId;
      }

      if (tabView && tabView.systemviewtype == "procobaview" && tabView.selectedTabId != selectedTabId) {
          tabView.lastProjectId = '<vkc:write name="form" property="projectId"/>';
          var tabViewForm = tabView.document.forms[0];
          tabViewForm.lastProjectId.value = tabView.lastProjectId;
          tabView.location.replace("<%=ctxPath%>/procobaTab.do?viewId=" + viewId
          						 + "&selectedTabId=<vkc:write name="form" property="projectId"/>&selectedViewId=" + selectedViewId
          						 + "&lastCategoryId=" + tabViewForm.lastCategoryId.value
          						 + "&lastFunctionalId=" + tabViewForm.lastFunctionalId.value
          						 + "&lastProjectId=" + tabViewForm.lastProjectId.value);
      }

      <logic:equal name="form" property="reloadTab" value="true">
	      var form = document.forms[0];
	      form.selectedId.value = '0';
	      
	      if (tabView && tabView.systemviewtype == "procobaview") {
	          tabView.location.replace("<%=ctxPath%>/procobaTab.do?viewId=" + viewId 
	          						 + "&selectedTabId=<vkc:write name="form" property="projectId"/>&selectedViewId=" + selectedViewId
          						     + "&lastCategoryId=" + tabViewForm.lastCategoryId.value
          						     + "&lastFunctionalId=" + tabViewForm.lastFunctionalId.value
          						     + "&lastProjectId=" + tabViewForm.lastProjectId.value);
	      }
      </logic:equal>

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

      <logic:present name="<%=org.apache.struts.Globals.MESSAGE_KEY%>">
	      <html:messages id="message" property="info" message="true">
	          alert('<vkc:write name="message" javascript="true" filter="false"/>');
	      </html:messages>
	      <%request.getSession().removeAttribute(org.apache.struts.Globals.MESSAGE_KEY);%>
      </logic:present>

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

      setAnchor();
  }

  function setAnchor() {
      <logic:present parameter="anchor">
          <bean:parameter id="anchor2" name="anchor"/>
          this.location.hash = '<%=anchor2%>';
          Mark("#" + '<%=anchor2%>');
      </logic:present>
        
      <logic:notPresent parameter="anchor">
      var anchorValue = this.location.hash;  
       
      if (anchorValue != '') {
          Mark(anchorValue);
      }
      </logic:notPresent>
  }

  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 deleteDocument(id) {
      if ( !confirm('<vkc:message javascript="true" filter="false" key="vkc.string.confirm.delete.document"/>') ) {
          return;
      } else {
          var form = document.forms[0];
          form.selectedId.value = id;

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

          form.submit();
      }
  }

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

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

      form.submit();
  }

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

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

      form.submit();
  }

  function confirmDeleteCategory() {
      return confirm('<vkc:message javascript="true" filter="false" key="vkc.string.confirm.delete.category"/>');
  }

  function toggleTinyMCEToolbar() {
      var form = document.forms[0];
  	  <logic:equal name="form" property="showTinyMCEToolbar" value="true">
      form.showTinyMCEToolbar.value = 'false';
      </logic:equal>
      <logic:equal name="form" property="showTinyMCEToolbar" value="false">
      form.showTinyMCEToolbar.value = 'true';
      </logic:equal>

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

      form.submit();
  }

  function Mark(id) {
	  var c1 = null;
	  var c2 = null;
	  var c3 = null;

	  if (markedDoc != 0) {
		  if (markedDoc.substring(1,4) == "doc") {
			  c1 = document.getElementById(markedDoc.substring(4));
			  c2 = document.getElementById(markedDoc.substring(4) + "a");
			  c3 = document.getElementById(markedDoc.substring(4) + "alt");

			  if (c1) {
				  c1.className = "unselecteddocument";	
			  }
				
			  if (c2) {
				  c2.className = "unselecteddocumentheader";
			  }
				
			  if (c3) {
				  c3.className = "unselecteddocumentalternate";
			  }
		  }
			
		  if (markedDoc.substring(1,4) == "tbp") {
			  c1 = document.getElementById(markedDoc.substring(4));
			  c2 = document.getElementById(markedDoc.substring(4) + "a");
			  c3 = document.getElementById(markedDoc.substring(4) + "alt");

			  if (c1) {
			      c1.className = "unselecteddocument";	
			  }
				
			  if (c2) {
				  c2.className = "unselecteddocumentheader";
			  }
				
			  if (c3) {
				  c3.className = "unselecteddocumentalternate";
			  }
		  }
	  }
		
	  if (id != "#top") {
		  markedDoc = id;

		  c1 = document.getElementById(markedDoc.substring(4));
		  c2 = document.getElementById(markedDoc.substring(4) + "a");
		  c3 = document.getElementById(markedDoc.substring(4) + "alt");

		  if (c1) {
			  c1.className = "selecteddocument";	
		  }
			
		  if (c2) {
			  c2.className = "selecteddocumentheader";
		  }
			
		  if (c3) {
			  c3.className = "selecteddocumentalternate";
		  }
	  }
  }
	
  </script>
</head>

<body onload="init();" onUnload="unloadPage();" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0">
<html:form action="/projectView" method="post">
  <html:hidden property="projectId"  />
  <html:hidden property="subfolderId"/>
  <html:hidden property="selectedId" />
  <html:hidden property="categorySortMode" />
  <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:present name="<%=org.apache.struts.Globals.ERROR_KEY%>">
  <html:messages id="error" message="false">
  <tr><td nowrap="nowrap" colspan="1" align="left" valign="top"><span class="error"><b><vkc:write name="error"/></b></span></td></tr>
  </html:messages>
  <tr><td colspan="1"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" height="5" border="0"/></td></tr>
  </logic:present>

  <logic:notEmpty name="form" property="project">
  <logic:equal name="form" property="userIsMember" value="true">
    <bean:define id="project"       name="form"    property="project"             type="vkc.procoba.project.entities.VKCProject"/>
    <bean:define id="projectId"     name="project" property="categoryId"          type="java.lang.Integer"/>

    <tr>
      <td height="100%" valign="top">
        <table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0">
          <tr>
            <td valign="top" width="100%" height="100%" class="projectView" >
              <table width="100%" cellpadding="0" cellspacing="0" height="100%">
                <tr>
                  <td height="100%" valign="top" class="projectView">
                    <table width="100%" cellspacing="0" cellpadding="0" border="0">
                      <%-- Metainformationen etc. --%>
                      <tr>
                        <td nowrap="nowrap" valign="top" width="100%">
                          <table width="100%" cellpadding="0" cellspacing="5" border="0">
                            <tr><td nowrap="nowrap"><b><vkc:message key="project.label.description" />:</b></td></tr>
                            <tr>
                              <td>
                              <font class="smallFont">
					          <logic:equal name="form" property="tinyMCECompatible" value="true">
					          <vkc:write name="project" property="description" displayAsHTML="true" renderNewLine="true"/>
					          </logic:equal>
					          <logic:equal name="form" property="tinyMCECompatible" value="false">
					          <vkc:write name="project" property="description" stripHTML="true" renderNewLine="true"/>
					          </logic:equal>
                              </font>
                              </td>
                            </tr>
                          </table>
                        </td>

                        <td background="<vkc:rewrite page='/templates/${template.name}/gfx/dotted-line-v.gif'/>"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="1"/></td>

                        <td nowrap="nowrap" valign="top">
                          <table cellpadding="0" cellspacing="5" border="0">
                            <tr><td nowrap="nowrap"><vkc:link page="<%=form.getProjectContactsViewLink()%>" paramId="projectId" paramName="projectId" titleKey="project.label.view.contactlist" ><vkc:message key="project.label.contacts" />:</vkc:link></td></tr>
                            <tr>
                              <td nowrap="nowrap">
                                <vkc:link page="<%=form.getProjectContactsViewLink()%>" anchor="projectLeaders" paramId="projectId" paramName="projectId" styleClass="smallFont" style="font-weight:normal;"><vkc:message key="project.label.leader" /></vkc:link><br>
                                <vkc:link page="<%=form.getProjectContactsViewLink()%>" anchor="internalContacts" paramId="projectId" paramName="projectId" styleClass="smallFont" style="font-weight:normal;"><vkc:message key="project.label.internal.contacts" /></vkc:link><br>
                                <vkc:link page="<%=form.getProjectContactsViewLink()%>" anchor="externalContacts" paramId="projectId" paramName="projectId" styleClass="smallFont" style="font-weight:normal;"><vkc:message key="project.label.external.contacts" /></vkc:link><br>
                              </td>
                            </tr>
                          </table>
                        </td>

                        <td background="<vkc:rewrite page='/templates/${template.name}/gfx/dotted-line-v.gif'/>"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="1"/></td>

                        <td nowrap="nowrap" valign="top">
                          <table cellpadding="0" cellspacing="5" border="0">
                            <tr><td nowrap="nowrap"><vkc:link page="<%=form.getProjectEditStepsViewLink()%>"><vkc:message key="project.label.state.project" />:</vkc:link></td></tr>
                            <logic:empty name="form" property="project.projectSteps">
                            <tr>
                              <td nowrap="nowrap">
                                <font class="smallFont">
                                  <logic:equal value="<%=VKCCategory.FLAG_CLOSED.toString()%>" name="form" property="project.flag">
                                  <span style="color:blue"><vkc:message key="project.label.state.closed" /></span><br>
                                  </logic:equal>
                                  <vkc:write name="form" property="projectStepsSize"/>&nbsp;<vkc:message key="project.label.edit.steps.no.activesteps"/>
                                </font>
                              </td>
                            </tr>
                            </logic:empty>
                            <logic:notEmpty name="form" property="project.projectSteps">
                            <tr>
                              <td nowrap="nowrap" >
                                <font class="smallFont">
                                  <logic:equal value="<%=VKCCategory.FLAG_CLOSED.toString()%>" name="form" property="project.flag">
                                  <span style="color:blue"><vkc:message key="project.label.state.closed" /></span><br>
                                  </logic:equal>
                                  <vkc:write name="form" property="activeProjectStepsSize"/>&nbsp;<vkc:message key="string.of" />&nbsp;<vkc:write name="form" property="projectStepsSize"/>&nbsp;<vkc:message key="project.label.edit.steps.state.running" /><br>
                                  <vkc:write name="form" property="activeProjectStepsProcessedSize"/>&nbsp;<vkc:message key="string.of" />&nbsp;<vkc:write name="form" property="activeProjectStepsSize"/>&nbsp;<vkc:message key="project.label.edit.steps.state.processed" /><br>
                                  <vkc:write name="form" property="activeProjectStepsCheckedSize"/>&nbsp;<vkc:message key="string.of" />&nbsp;<vkc:write name="form" property="activeProjectStepsSize"/>&nbsp;<vkc:message key="project.label.edit.steps.state.checked" /><br>
                                </font>
                              </td>
                            </tr>
                            </logic:notEmpty>
                          </table>
                        </td>

                        <td background="<vkc:rewrite page='/templates/${template.name}/gfx/dotted-line-v.gif'/>"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="1"/></td>

                        <td nowrap="nowrap" valign="top">
                          <table cellpadding="0" cellspacing="5" border="0">
                            <tr><td nowrap="nowrap"><vkc:link page="<%=form.getProjectMessagesViewLink()%>"><vkc:message key="project.label.messages" />:</vkc:link></td></tr>
                            <logic:notEmpty name="form" property="mostRecentMessages">
                            <bean:define id="messages" name="form" property="mostRecentMessages"/>
                            <tr>
                              <td nowrap="nowrap">
                                <logic:iterate name="messages" id="message" type="vkc.procoba.project.entities.VKCProjectMessage">
                                <vkc:link styleClass="smallFont" style="font-weight:normal;" page='<%=form.getProjectMessagesViewLink()%>' anchor='<%=String.valueOf( "msg" + message.getMessageId() )%>'><vkc:write name="message" property="cuttedText"/></vkc:link><br>
                                </logic:iterate>
                              </td>
                            </tr>
                            </logic:notEmpty>
                          </table>
                        </td>
                      </tr>
                    </table>

                    <table width="100%" cellspacing="0" cellpadding="0" border="0">
                      <tr><td valign="top" width="100%" background="<vkc:rewrite page='/templates/${template.name}/gfx/dotted-line-h.gif'/>"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" height="1"/></td></tr>
                      <tr>
                        <td valign="top" width="100%">
                          <logic:equal name="form" property="viewMode" value='<%=String.valueOf(ProjectViewForm.VIEW_MODE_FOLDER)%>'>
                            <jsp:include page="ProjectFolderView.jsp" flush="true" />
                          </logic:equal>

                          <logic:equal name="form" property="viewMode" value='<%=String.valueOf(ProjectViewForm.VIEW_MODE_MESSAGES)%>'>
                            <jsp:include page="ProjectMessageView.jsp" flush="true" />
                          </logic:equal>

                          <logic:equal name="form" property="viewMode" value='<%=String.valueOf(ProjectViewForm.VIEW_MODE_CONTACTS)%>'>
                            <jsp:include page="ProjectContactView.jsp" flush="true" />
                          </logic:equal>

                          <logic:equal name="form" property="viewMode" value='<%=String.valueOf(ProjectViewForm.VIEW_MODE_NEW_MESSAGE)%>'>
                            <jsp:include page="ProjectNewMessageView.jsp" flush="true" />
                          </logic:equal>

                          <logic:equal name="form" property="viewMode" value='<%=String.valueOf(ProjectViewForm.VIEW_MODE_EDIT_STEPS)%>'>
                            <jsp:include page="ProjectEditStepsView.jsp" flush="true" />
                          </logic:equal>
                        </td>
                      </tr>
                    </table>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </logic:equal>
  </logic:notEmpty>
</html:form>
</table>
</body>
</html:html>