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

<%@ page import="vkc.view.TabId" %>

<%@ taglib uri="struts-html" 	prefix="html" %>
<%@ taglib uri="struts-bean" 	prefix="bean" %>
<%@ 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" />
  	<vkc:cssinclude />

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

    <script type="text/javascript">

    window.name = "MAINVIEW";
    var aclform = null;
    var associatedTabId = <%=TabId.ADMIN_NEWSMANAGEMENT_TAB%>;

    function init() {

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

        if (tabView && tabView.systemviewtype == "administrationview" && tabView.selectedTabId != associatedTabId) {
            tabView.location.replace("<%=ctxPath%>/adminTabView.do?selectedTabId=<%=TabId.ADMIN_NEWSMANAGEMENT_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 confirmDeleteNews(elem) {
        var form  = document.forms[ 0 ];
        var numChecked = getNumberOfCheckedEntries();

        if ( numChecked == 0 ) {
            alert( '<vkc:message javascript="true" filter="false" key="vkc.administration.select.news"/>' );
            return false;
        }
        
        if ( !confirm('<vkc:message javascript="true" filter="false" key="vkc.string.confirm.delete.selection"/>') ) {
        	return false;
        }
        
        if (form.action.indexOf('?') == -1) {
          form.action = form.action + "?action.delete.news=true";
        } else {
          form.action = form.action + "&action.delete.news=true";
        }

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

	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;
	}
	
    </script>

</head>
<body onload="init();" topmargin="0" marginheight="0">
<table align='center' width='100%' cellspacing='0' cellpadding='0' border='0'>
  <tr>
    <td nowrap width="100%" align="right"><vkc:link page="/createNews.do" style="font-weight:bold;"><vkc:message key="vkc.administration.news.createnews"/></vkc:link>&nbsp;&nbsp;</td>
  </tr>
</table>

<html:form action="/newsList" method="post">
<bean:define id="form" name="newsListForm" scope="request" type="vkc.administration.form.NewsListForm"/>

<table cellspacing="0" cellpadding="0" border="0" width="100%">
  <logic:notEmpty name="form" property="news">
  <logic:iterate id="news" name="form" property="news" type="vkc.db.entities.VKCNews">

  <logic:equal name="news" property="valid" value="true">
  <tr><td><vkc:img page="/templates/${template.name}/gfx/trans.gif" width="20" height="20" border="0" alt=""/></td></tr>
  <tr>
	<td width="100%" colspan="15">  
      <table cellspacing="3" cellpadding="0" border="0" width="100%">
        <tr>
		  <td width="1" valign="top"><html:multibox name="form" property="selectedIds" onfocus="this.blur();"><vkc:write name="news" property="newsId"/></html:multibox></td> 
		  <td width="100%" colspan="20">  
		    <table cellspacing="3" cellpadding="0" border="0" width="100%">
		      <tr>
		        <td colspan="2">
		          <table cellspacing="0" cellpadding="0" border="0" width="100%">
		            <tr class="color_doctitle">
		              <td width="97%"><b><vkc:write name="news" property="headline"/></b></td>
		              <td align="right" width="1%"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" height="24" width="1"/></td>
		              <td align="right" width="1%"><vkc:link page="/editNews.do?initialize=true" paramId="newsId" paramName="news" paramProperty="newsId"><vkc:img border="0" page="/templates/${template.name}/gfx/button-editdocument.gif" alt="" titleKey="vkc.tooltip.editnews"/></vkc:link></td>
		              <td align="right" width="1%"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" height="24" width="1"/></td>
		            </tr>
		          </table>
		        </td>
		      </tr>
		      <tr>
		        <td width="1%" nowrap="nowrap" valign="top"><b><vkc:message key="vkc.administration.news.newstext"/>:</b>&nbsp;</td>
		        <td width="99%">
		          <logic:equal name="form" property="tinyMCECompatible" value="true">
		          <vkc:write name="news" property="newsText" displayAsHTML="true" renderNewLine="true"/>
		          </logic:equal>
		          <logic:equal name="form" property="tinyMCECompatible" value="false">
		          <vkc:write name="news" property="newsText" stripHTML="true" renderNewLine="true"/>
		          </logic:equal>
		        </td>
		      </tr>
		      <tr>
		        <td width="1%" nowrap="nowrap"><b><vkc:message key="vkc.administration.news.infourl"/>:</b>&nbsp;</td>
		        <td width="99%">
		          <logic:notEmpty name="news" property="infoUrl">
		          <vkc:link href='<%=news.getInfoUrl()%>' target="_blank"><vkc:write name="news" property="infoUrl"/></vkc:link>
		          </logic:notEmpty>
		        </td>
		      </tr>
		      <logic:notEmpty name="news" property="validFrom">
		      <tr>
		        <td width="1%" nowrap="nowrap"><b><vkc:message key="vkc.administration.news.validfrom"/>:</b>&nbsp;</td>
		        <td width="99%"><vkc:write name="news" property="validFrom" formatKey="date.medium.format"/></td>
		      </tr>
		      </logic:notEmpty>
		      <logic:notEmpty name="news" property="validUntil">
		      <tr>
		        <td width="1%" nowrap="nowrap"><b><vkc:message key="vkc.administration.news.validuntil"/>:</b>&nbsp;</td>
		        <td width="99%"><vkc:write name="news" property="validUntil" formatKey="date.medium.format"/></td>
		      </tr>
		      </logic:notEmpty>
		    </table>
		  </td>
        </tr>
      </table>
	</td>
  </tr>
  </logic:equal>

  <logic:equal name="news" property="valid" value="false">
  <tr><td><vkc:img page="/templates/${template.name}/gfx/trans.gif" width="20" height="20" border="0" alt=""/></td></tr>
  <tr>
	<td width="100%" colspan="15">  
      <table cellspacing="3" cellpadding="0" border="0" width="100%">
        <tr>
		  <td width="1" valign="top"><html:multibox name="form" property="selectedIds" onfocus="this.blur();"><vkc:write name="news" property="newsId"/></html:multibox></td> 
		  <td width="100%" colspan="20">  
		    <table cellspacing="3" cellpadding="0" border="0" width="100%">
		      <tr>
		        <td colspan="2">
		          <table cellspacing="0" cellpadding="0" border="0" width="100%">
		            <tr class="headerSelected">
		              <td width="97%"><font style="color:#aaaaaa" ><b><vkc:write name="news" property="headline"/></b></font></td>
		              <td align="right" width="1%"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" height="24" width="1"/></td>
		              <td align="right" width="1%"><vkc:link page="/editNews.do?initialize=true" paramId="newsId" paramName="news" paramProperty="newsId"><vkc:img border="0" page="/templates/${template.name}/gfx/button-editdocument.gif" alt="" titleKey="vkc.tooltip.editnews"/></vkc:link></td>
		              <td align="right" width="1%"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" height="24" width="1"/></td>
		            </tr>
		          </table>
		        </td>
		      </tr>
		      <tr>
		        <td width="1%" nowrap="nowrap" valign="top"><font style="color:#aaaaaa" ><b><vkc:message key="vkc.administration.news.newstext"/>:</b>&nbsp;</font></td>
		        <td width="99%">
		        <font style="color:#aaaaaa" >
		          <logic:equal name="form" property="tinyMCECompatible" value="true">
		          <vkc:write name="news" property="newsText" displayAsHTML="true" renderNewLine="true"/>
		          </logic:equal>
		          <logic:equal name="form" property="tinyMCECompatible" value="false">
		          <vkc:write name="news" property="newsText" stripHTML="true" renderNewLine="true"/>
		          </logic:equal>
		        </font>
		        </td>
		      </tr>
		      <tr>
		        <td width="1%" nowrap="nowrap"><font style="color:#aaaaaa" ><b><vkc:message key="vkc.administration.news.infourl"/>:</b>&nbsp;</font></td>
		        <td width="99%">
		          <logic:notEmpty name="news" property="infoUrl">
		          <vkc:link href='<%=news.getInfoUrl()%>' target="_blank"><font style="color:#aaaaaa" ><vkc:write name="news" property="infoUrl"/></font></vkc:link>
		          </logic:notEmpty>
		        </td>
		      </tr>
		      <logic:notEmpty name="news" property="validFrom">
		      <tr>
		        <td width="1%" nowrap="nowrap"><font style="color:#aaaaaa" ><b><vkc:message key="vkc.administration.news.validfrom"/>:</b>&nbsp;</font></td>
		        <td width="99%"><font style="color:#aaaaaa" ><vkc:write name="news" property="validFrom" formatKey="date.medium.format"/></font></td>
		      </tr>
		      </logic:notEmpty>
		      <logic:notEmpty name="news" property="validUntil">
		      <tr>
		        <td width="1%" nowrap="nowrap"><font style="color:#aaaaaa" ><b><vkc:message key="vkc.administration.news.validuntil"/>:</b>&nbsp;</font></td>
		        <td width="99%"><font style="color:#aaaaaa" ><vkc:write name="news" property="validUntil" formatKey="date.medium.format"/></font></td>
		      </tr>
		      </logic:notEmpty>
		    </table>
		  </td>
        </tr>
      </table>
	</td>
  </tr>
  </logic:equal>

  </logic:iterate>

  <tr><td align='center'><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" border="0" width="5" height="5"/></td></tr>
  <tr><td colspan="2">&nbsp;<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="" border="0" width="5" height="5"/></td></tr>
  <vkc:hline colspan="5" lineClass="hline" lineHeight="1" topSpace="5" bottomSpace="5"/>
  <tr><td align="left"><vkc:button property="action.delete.news" onclick="javascript:confirmDeleteNews(this);"><vkc:message key="vkc.administration.button.delete.news"/></vkc:button></td></tr>
  </logic:notEmpty>

  <logic:empty name="form" property="news">
  <tr><td><b><vkc:message key="vkc.administration.news.nonews"/></b></td></tr>
  </logic:empty>
</table>

</html:form>
</body>
</html:html>
