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

<%@ page import="vkc.view.WebShare" %>
<%@ page import="vkc.view.TabId" %>
<%@ page import="org.apache.struts.Globals" %>

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

  	<vkc:cssinclude />

    <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 associatedTabId = <%=TabId.ADMIN_SENDEMAIL_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_SENDEMAIL_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 openGroupInfoWindow( 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="/displayGroupInfo.do"/>?groupId=' + id, 'GROUPINFO_MAINVIEW', settings );
		win.focus();							  
	}
	
	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 toggleTinyMCEToolbar() {
        var form = document.forms[0];
    	<logic:equal name="sendEmailForm" property="showTinyMCEToolbar" value="true">
    	form.showTinyMCEToolbar.value = 'false';
    	</logic:equal>
    	<logic:equal name="sendEmailForm" 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();
    }

    </script>
</head>
<body onload="init();" topmargin="0" marginheight="0">
<table width="100%" align="left" cellspacing="5" cellpadding="0" border="0">
  <html:form action="/sendEmail" method="post">

  <bean:define id="form" name="sendEmailForm" scope="request" type="vkc.administration.form.SendEmailForm"/>

  <logic:iterate id="uid" name="form" property="sendUserIds" type="java.lang.Integer">
    <html:hidden property="sendUserIds" name="form" value='<%=String.valueOf(uid.toString())%>'/>
  </logic:iterate>
  <logic:iterate id="gid" name="form" property="sendGroupIds" type="java.lang.Integer">
    <html:hidden property="sendGroupIds" name="form" value='<%=String.valueOf(gid.toString())%>'/>
  </logic:iterate>

  <vkc:hidden property="showTinyMCEToolbar"/>

  <logic:present name="<%=Globals.ERROR_KEY%>">
  <tr><td align="left" nowrap="nowrap" colspan="2"><font color="red"><b><vkc:errors/></b></font></td></tr>
  </logic:present>

  <logic:equal name="form" property="tinyMCECompatible" value="true">
  <logic:equal name="form" property="showTinyMCEToolbar" value="false">
  <style type="text/css">
  .mceToolbar {
      display:none;
  }
  </style>
  </logic:equal>
  </logic:equal>

  <tr>
	<td align="center" colspan="2">
	  <table width="100%" align="center" cellpadding="0" cellspacing="0" border="0">
	    <tr>
		  <td width="50%" align="left" nowrap="nowrap"><b>&nbsp;<vkc:message key="vkc.groups"/>:</b></td>
		  <td width="1" align="center" nowrap="nowrap"></td>
		  <td width="50%" align="left" nowrap="nowrap"><b>&nbsp;<vkc:message key="vkc.administration.grouplist"/>:</b></td>
		</tr>
	    <tr>
		  <td width="50%" align="center" nowrap="nowrap">
			<bean:define id="addGroups" name="form" property="addGroups" type="java.util.List"/>
			<html:select name="form" property="selectedRemoveGroupIds" multiple="true" size="10" style="width:99%;">
			  <vkc:options collection="addGroups" property="groupId" labelProperty="name"/>
			</html:select>
		  </td>
          <td width="1" align="center" nowrap="nowrap">
            <table width="1" align="center" cellpadding="0" cellspacing="0" border="0">
              <tr>
                <td align="center" nowrap="nowrap">&nbsp;<vkc:button property="action.add.groups" onclick="javascript:disableAllButtonsAndSubmit(this);">&lt;&lt;</vkc:button>&nbsp;</td>
              </tr>
              <tr><td align="center">&nbsp;</td></tr>
              <tr>
                <td align="center" nowrap="nowrap">&nbsp;<vkc:button property="action.remove.groups" onclick="javascript:disableAllButtonsAndSubmit(this);">&gt;&gt;</vkc:button>&nbsp;</td>
              </tr>
            </table>
          </td>
		  <td width="50%" align="center" nowrap="nowrap">
			<bean:define id="removeGroups" name="form" property="removeGroups" type="java.util.List"/>
			<html:select name="form" property="selectedAddGroupIds" multiple="true" size="10" style="width:99%;">
			  <vkc:options collection="removeGroups" property="groupId" labelProperty="name"/>
			</html:select>
		  </td>
		</tr>
	  </table>
	</td>
  </tr>

  <tr>
	<td align="center" colspan="2">
	  <table width="100%" align="center" cellpadding="0" cellspacing="0" border="0">
	    <tr>
		  <td width="50%" align="left" nowrap="nowrap"><b>&nbsp;<vkc:message key="vkc.users"/>:</b></td>
		  <td width="1" align="center" nowrap="nowrap"></td>
		  <td width="50%" align="left" nowrap="nowrap"><b>&nbsp;<vkc:message key="vkc.administration.userlist"/>:</b></td>
		</tr>
	    <tr>
		  <td width="50%" align="center" nowrap="nowrap">
			<bean:define id="addUsers" name="form" property="addUsers" type="java.util.List"/>
			<html:select name="form" property="selectedRemoveUserIds" multiple="true" size="10" style="width:99%;">
			  <vkc:options collection="addUsers" property="userId" labelProperty="lastnameLabel"/>
			</html:select>
		  </td>
          <td width="1" align="center" nowrap="nowrap">
            <table width="1" align="center" cellpadding="0" cellspacing="0" border="0">
              <tr>
                <td align="center" nowrap="nowrap">&nbsp;<vkc:button property="action.add.users" onclick="javascript:disableAllButtonsAndSubmit(this);">&lt;&lt;</vkc:button>&nbsp;</td>
              </tr>
              <tr><td align="center">&nbsp;</td></tr>
              <tr>
                <td align="center" nowrap="nowrap">&nbsp;<vkc:button property="action.remove.users" onclick="javascript:disableAllButtonsAndSubmit(this);">&gt;&gt;</vkc:button>&nbsp;</td>
              </tr>
            </table>
          </td>
		  <td width="50%" align="center" nowrap="nowrap">
			<bean:define id="removeUsers" name="form" property="removeUsers" type="java.util.List"/>
			<html:select name="form" property="selectedAddUserIds" multiple="true" size="10" style="width:99%;">
			  <vkc:options collection="removeUsers" property="userId" labelProperty="lastnameLabel"/>
			</html:select>
		  </td>
		</tr>
	  </table>
	</td>
  </tr>

  <tr><td align="center" colspan="2"><vkc:button property="action.add.activUsers" onclick="javascript:disableAllButtonsAndSubmit(this);"><vkc:message key="button.addActivUsers"/></vkc:button></td></tr>
  <tr><td colspan="2"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="1" height="5"/></td></tr>
  <tr>
    <td colspan="2">
  	  <table>
	    <tr>
	      <td align="left" valign="top"><b><vkc:message key="vkc.administration.sendEmail.recipients" /></b>&nbsp;&nbsp;</td>
		  <td align="left">
		  <logic:iterate id="aGroup" name="form" property="addGroups" type="vkc.view.bean.GroupInfo">
		    <bean:define id="groupId" name="aGroup" property="groupId" type="java.lang.Integer"/>
		    <vkc:link href='<%="javascript:openGroupInfoWindow(" + groupId.intValue() + ");"%>'><span style="text-decoration:underline"><font color="blue"><vkc:write name="aGroup" property="name"/></font></span></vkc:link>,&nbsp;
		  </logic:iterate>
		  <logic:iterate id="aUser" name="form" property="addUsersSortedByUsername" type="vkc.view.bean.UserInfo">
		    <bean:define id="userId" name="aUser" property="userId" type="java.lang.Integer"/>
		    <vkc:link href='<%="javascript:openUserInfoWindow(" + userId.intValue() + ");"%>'><span style="text-decoration:underline"><vkc:write name="aUser" property="username"/></span></vkc:link>,&nbsp;
		  </logic:iterate>
		  </td>
	    </tr>
	  </table>
    </td>
  </tr>
  
  <tr>
    <td colspan="2">
  	  <table width="100%">
	    <tr><td align="left" nowrap="nowrap"><b><vkc:message key="vkc.administration.sendEmail.sender" /></b></td><td></td></tr>
		<tr><td width="100%" align="left"><vkc:text name="form" property="sender" style="width:100%;" /></td><td></td></tr>
	    <tr><td align="left" nowrap="nowrap"><b><vkc:message key="vkc.administration.sendEmail.subject" /></b></td><td></td></tr>
		<tr><td width="100%" align="left"><vkc:text name="form" property="subject" style="width:100%;" /></td><td></td></tr>
		<tr><td align="left" nowrap="nowrap"><b><vkc:message key="vkc.administration.sendEmail.content" /></b></td><td></td></tr>
		<tr>
		  <td width="100%" align="left">
	    	<logic:equal name="form" property="tinyMCECompatible" value="true">
	    	<logic:equal name="form" property="showTinyMCEToolbar" value="true">
			<vkc:link href="javascript:toggleTinyMCEToolbar();"><vkc:img page="/templates/${template.name}/gfx/minus-big.gif" border="0" titleKey="vkc.string.htmleditor"/></vkc:link>
	    	</logic:equal>
	    	<logic:equal name="form" property="showTinyMCEToolbar" value="false">
			<vkc:link href="javascript:toggleTinyMCEToolbar();"><vkc:img page="/templates/${template.name}/gfx/plus-big.gif" border="0" titleKey="vkc.string.htmleditor"/></vkc:link>
	    	</logic:equal>
	    	</logic:equal>
		    <vkc:textarea name="form" property="content" rows="10" style="width:100%;" />
		  </td>
		  <td>
		  </td>
		</tr>
	  </table>
    </td>
  </tr>
 
  <tr>
    <td align="center" colspan="2">
      <vkc:button property="action.send.email" onclick="javascript:disableAllButtonsAndSubmit(this);"><vkc:message key="button.send"/></vkc:button>
    </td>
  </tr>
  </html:form>
</table>
</body>
</html:html>
