
<%
/**
 *	$RCSfile: editWatches.jsp,v $
 *	$Revision: 1.1.1.1 $
 *	$Date: 2002/09/09 13:50:26 $
 */
%>

<%@ page import="java.util.*,
				 java.text.*,
                 java.sql.*,
				 com.jivesoftware.util.*,
                 com.jivesoftware.forum.*,
				 com.jivesoftware.forum.database.*,
				 com.jivesoftware.forum.util.*"
    errorPage="error.jsp"
%>

<%@ include file="include/global.jsp" %>
 
<%	// get parameters
	int maxPoints = ParamUtils.getIntParameter(request,"maxPoints",-1);
    boolean setProp = ParamUtils.getBooleanParameter(request,"setProp");
    boolean emailNotify = ParamUtils.getBooleanParameter(request,"emailNotify");
    String fromName = ParamUtils.getParameter(request,"fromName",true);
    String fromEmail = ParamUtils.getParameter(request,"fromEmail",true);
    String subject = ParamUtils.getParameter(request,"subject",true);
    String body = ParamUtils.getParameter(request,"body",true);
    String smtpHost = ParamUtils.getParameter(request,"smtpHost",true);
    boolean saveEmailSettings = ParamUtils.getBooleanParameter(request,"saveEmailSettings");
    boolean saveEmailProps = ParamUtils.getBooleanParameter(request,"saveEmailProps");
    
    // Get the watch manager
    WatchManager watchManager = forumFactory.getWatchManager();
    
    // save the email settings if requested
    if (saveEmailSettings) {
        watchManager.setEmailNotifyEnabled(emailNotify);
        if (smtpHost != null) {
            JiveGlobals.setJiveProperty("mail.smtp.host", smtpHost);
        }
        response.sendRedirect("editWatches.jsp");
        return;
    }
    
    if (saveEmailProps) {
        if (fromName != null) {
            watchManager.setEmailFromName(fromName);
        }
        if (fromEmail != null) {
            watchManager.setEmailFromEmail(fromEmail);
        }
        if (subject != null) {
            watchManager.setEmailSubject(subject);
        }
        if (body != null) {
            watchManager.setEmailBody(body);
        }
        response.sendRedirect("editWatches.jsp");
        return;
    }
    fromName = watchManager.getEmailFromName();
    fromEmail = watchManager.getEmailFromEmail();
    subject = watchManager.getEmailSubject();
    body = watchManager.getEmailBody();
    smtpHost = JiveGlobals.getJiveProperty("mail.smtp.host");
    
    boolean errors = false;
    String errorMessage = "";
    
    boolean isEmailNotifyEnabled = watchManager.isEmailNotifyEnabled();
%>

<%@ include file="include/header.jsp" %>

<p>

<%  // Title of this page and breadcrumbs
    String title = "Configure Watches";
    String[][] breadcrumbs = {
        {"Main", "main.jsp"},
        {"Configure Watches", "editWatches.jsp"}
    };
%>
<%@ include file="include/title.jsp" %>

<font size="-1">
Watches allow users to track the threads that they're intersted in following
and can be configured to send email notifications when there are updates.
Use the settings below to turn email notifications on or off and to customize
the message that is sent.
</font>

<p>

<form action="editWatches.jsp" name="f">
<input type="hidden" name="saveEmailSettings" value="true">
<font size="-1"><b>Email Watch Settings</b></font>
<ul>
    <table cellpadding="2" cellspacing="0" border="0">
    <tr>
    	<td width="1%"><input type="radio" name="emailNotify" value="true"<%= (isEmailNotifyEnabled?" checked":"") %> id="rb01"></td>
    	<td><font size="-1"><label for="rb01">Email Watch Notification Enabled</label></font></td>
    </tr>
    <tr>
    	<td width="1%"><input type="radio" name="emailNotify" value="false"<%= (!isEmailNotifyEnabled?" checked":"") %> id="rb02"></td>
    	<td><font size="-1"><label for="rb02">Email Watch Notification Disabled</label></font></td>
    </tr>
    <tr>
    	<td colspan="2">
            <font size="-1">
            SMTP Host: 
            </font>
            <input type="text" name="smtpHost" value="<%= (smtpHost!=null)?smtpHost:"" %>" size="30" maxlength="100">
        </td>
    </tr>
    <tr>
    	<td colspan="2">
            <br><input type="submit" value="Save Settings">
        </td>
    </tr>
    </table>
</ul>
</form>

<form action="editWatches.jsp" name="f">
<input type="hidden" name="saveEmailProps" value="true">
<font size="-1"><b>Email Properties</b></font>
<ul>
    <font size="-1">
    You can insert the following tokens into the subject or body of the
    email message and they'll be dynamically replaced with the appropriate
    values when the email is sent.
    <br>
    </font>
    <font color="#006600">
    <tt>
    {username}
    {email}
    {name}
    {userID}
    {threadID}
    {threadName}
    {threadModifiedDate}
    {threadCreationDate}
    {forumID}
    {forumName}
    </tt>
    </font>
    <p>
    <table cellpadding="2" cellspacing="0" border="0">
    <tr>
    	<td nowrap><font size="-1">From Name:</font></td>
    	<td><input type="text" name="fromName" size="30" value="<%= ((fromName!=null)?fromName:"") %>"></td>
    </tr>
    <tr>
    	<td nowrap><font size="-1">From Email:</font></td>
    	<td><input type="text" name="fromEmail" size="30" value="<%= ((fromEmail!=null)?fromEmail:"") %>"></td>
    </tr>
    <tr>
    	<td nowrap><font size="-1">Subject:</font></td>
    	<td><input type="text" name="subject" size="40" value="<%= ((subject!=null)?subject:"") %>"></td>
    </tr>
    <tr>
    	<td valign="top" nowrap><font size="-1">Body of email:</font></td>
    	<td>
        <textarea name="body" cols="40" rows="6" wrap="virtual"><%= ((body!=null)?body:"") %></textarea>
        </td>
    </tr>
    <tr>
        <td>&nbsp;</td>
    	<td><br><input type="submit" value="Save Settings"></td>
    </tr>
    </table>
</ul>
</form>

<%@ include file="include/footer.jsp" %>