From e35045acf461b9f2a51f278fd1a5a7c0a394dae6 Mon Sep 17 00:00:00 2001 From: "Eric J. Bowersox" Date: Tue, 4 Dec 2001 19:17:00 +0000 Subject: [PATCH] added community admin "Send E-Mail To All Members" menu option --- etc/venice-config.xml | 1 + .../venice/core/CommunityContext.java | 4 + .../venice/core/impl/CommunityCoreData.java | 45 +++++++ .../core/impl/CommunityUserContextImpl.java | 27 ++++ .../venice/core/internals/CommunityData.java | 2 + .../venice/servlets/CommunityAdmin.java | 54 ++++++++ .../servlets/format/CommunityAdminTop.java | 1 + .../servlets/format/CommunityEMail.java | 115 ++++++++++++++++++ web/format/comm_email.jsp | 57 +++++++++ web/format/conf_email.jsp | 2 +- 10 files changed, 307 insertions(+), 1 deletion(-) create mode 100644 src/com/silverwrist/venice/servlets/format/CommunityEMail.java create mode 100644 web/format/comm_email.jsp diff --git a/etc/venice-config.xml b/etc/venice-config.xml index e531ade..fb14b57 100644 --- a/etc/venice-config.xml +++ b/etc/venice-config.xml @@ -184,6 +184,7 @@ + diff --git a/src/com/silverwrist/venice/core/CommunityContext.java b/src/com/silverwrist/venice/core/CommunityContext.java index 2e5daec..d60aec9 100644 --- a/src/com/silverwrist/venice/core/CommunityContext.java +++ b/src/com/silverwrist/venice/core/CommunityContext.java @@ -179,4 +179,8 @@ public interface CommunityContext extends SearchMode public abstract SecurityInfo getSecurityInfo(); + public abstract boolean canMassMail(); + + public abstract void massMail(String subject, String text) throws AccessError, DataException; + } // end interface CommunityContext diff --git a/src/com/silverwrist/venice/core/impl/CommunityCoreData.java b/src/com/silverwrist/venice/core/impl/CommunityCoreData.java index a9bc786..b1e4fbf 100644 --- a/src/com/silverwrist/venice/core/impl/CommunityCoreData.java +++ b/src/com/silverwrist/venice/core/impl/CommunityCoreData.java @@ -1821,6 +1821,51 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end setProperties + public List getMassMailList() throws DataException + { + if (logger.isDebugEnabled()) + logger.debug("getMassMailList() for community " + cid); + if (deleted) + throw new DataException("This community has been deleted."); + + Connection conn = null; // database connection + ArrayList rc = new ArrayList(); // return from this function + + try + { // get a database connection + conn = env.getConnection(); + Statement stmt = conn.createStatement(); + + // create the SQL statement + StringBuffer sql = + new StringBuffer("SELECT c.email FROM contacts c, users u, sigmember m " + + "WHERE c.contactid = u.contactid AND u.uid = m.uid AND m.sigid = "); + sql.append(cid).append(" AND u.is_anon = 0;"); + if (logger.isDebugEnabled()) + logger.debug("SQL: " + sql.toString()); + + // execute the query and copy the results to the ArrayList + ResultSet rs = stmt.executeQuery(sql.toString()); + while (rs.next()) + rc.add(rs.getString(1)); + + } // end try + catch (SQLException e) + { // database error - this is a DataException + logger.error("DB error getting mailing list: " + e.getMessage(),e); + throw new DataException("unable to get community mailing list: " + e.getMessage(),e); + + } // end catch + finally + { // make sure the connection is released before we go + env.releaseConnection(conn); + + } // end finally + + return rc; + + } // end getMassMailList + /*-------------------------------------------------------------------------------- * Implementations from interface CommunityDataBackend *-------------------------------------------------------------------------------- diff --git a/src/com/silverwrist/venice/core/impl/CommunityUserContextImpl.java b/src/com/silverwrist/venice/core/impl/CommunityUserContextImpl.java index 0360504..8bd397d 100644 --- a/src/com/silverwrist/venice/core/impl/CommunityUserContextImpl.java +++ b/src/com/silverwrist/venice/core/impl/CommunityUserContextImpl.java @@ -1360,6 +1360,33 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end getSecurityInfo + public boolean canMassMail() + { + return env.testPermission("Community.MassMail"); + + } // end canMassMail + + public void massMail(String subject, String text) throws AccessError, DataException + { + if (!(env.testPermission("Community.MassMail"))) + { // no can do, man! + logger.error("user not permitted to modify the community's information"); + throw new AccessError("You are not permitted to send E-mail to all community members."); + + } // end if + + // get the mailing list + List mail_list = getData().getMassMailList(); + if (mail_list.size()>0) + { // send the mail in the background! + MailerAgent agent = new MailerAgent(env,env.getUser().realUserName(),env.getUser().realEmailAddress(), + mail_list,subject,text); + agent.start(); + + } // end if + + } // end massMail + /*-------------------------------------------------------------------------------- * Implementations from interface CommunityBackend *-------------------------------------------------------------------------------- diff --git a/src/com/silverwrist/venice/core/internals/CommunityData.java b/src/com/silverwrist/venice/core/internals/CommunityData.java index 3e1903f..5ab9ba7 100644 --- a/src/com/silverwrist/venice/core/internals/CommunityData.java +++ b/src/com/silverwrist/venice/core/internals/CommunityData.java @@ -158,4 +158,6 @@ public interface CommunityData public abstract void setProperties(CommunityProperties props) throws DataException; + public abstract List getMassMailList() throws DataException; + } // end interface CommunityData diff --git a/src/com/silverwrist/venice/servlets/CommunityAdmin.java b/src/com/silverwrist/venice/servlets/CommunityAdmin.java index a8f14e2..ff82171 100644 --- a/src/com/silverwrist/venice/servlets/CommunityAdmin.java +++ b/src/com/silverwrist/venice/servlets/CommunityAdmin.java @@ -96,6 +96,15 @@ public class CommunityAdmin extends VeniceServlet *-------------------------------------------------------------------------------- */ + /* Command values for CommunityAdmin: + * A = Display Audit Records + * DEL = Delete Community + * F = Set Features/Services (not implemented yet) + * I = E-Mail to All Members + * M = Membership Control + * P = Edit Profile + * T = Set Category + */ protected VeniceContent doVeniceGet(HttpServletRequest request, VeniceEngine engine, UserContext user, RenderData rdat) throws ServletException, IOException, VeniceServletResult @@ -302,6 +311,20 @@ public class CommunityAdmin extends VeniceServlet } // end if ("A" command) + if (cmd.equals("I")) + { // "I" = "Send E-Mail To All Members" + if (!(comm.canMassMail())) + { // we can't send mass mail to the community, so what are we doing here? + logger.error("you can't mass-mail the community - not gonna do it, wouldn't be prudent"); + return new ErrorBox("Access Error","You do not have permission to sent mass mail to this community.", + on_error); + + } // end if + + return new CommunityEMail(comm); // return the view object + + } // end if ("I" command) + if (cmd.equals("DEL")) { // "DEL" = "Delete Community" (requires a confirmation) if (!(comm.canDelete())) @@ -587,6 +610,37 @@ public class CommunityAdmin extends VeniceServlet } // end if ("M" command) + if (cmd.equals("I")) + { // "I" - "Send E-Mail To Community" + if (!(comm.canMassMail())) + { // we can't send mass mail to the community, so what are we doing here? + logger.error("you can't mass-mail the community - not gonna do it, wouldn't be prudent"); + return new ErrorBox("Access Error","You do not have permission to sent mass mail to this community.", + on_error); + + } // end if + + try + { // attempt to do the mass mailing! + comm.massMail(request.getParameter("subj"),request.getParameter("pb")); + + } // end try + catch (AccessError ae) + { // some sort of access error - display an error dialog + return new ErrorBox("Access Error",ae.getMessage(),on_error); + + } // end catch + catch (DataException de) + { // database error creating the conference + return new ErrorBox("Database Error","Database error getting mailing list: " + de.getMessage(), + on_error); + + } // end catch + + throw new RedirectResult(on_error); // bounce back to the menu + + } // end if ("I" command) + // on unknown command, redirect to the GET function return doVeniceGet(request,engine,user,rdat); diff --git a/src/com/silverwrist/venice/servlets/format/CommunityAdminTop.java b/src/com/silverwrist/venice/servlets/format/CommunityAdminTop.java index d3dc7f9..dbdfdfa 100644 --- a/src/com/silverwrist/venice/servlets/format/CommunityAdminTop.java +++ b/src/com/silverwrist/venice/servlets/format/CommunityAdminTop.java @@ -36,6 +36,7 @@ public class CommunityAdminTop extends ContentMenuPanel addChoice("Set Community Category","sigadmin?sig=$s&cmd=T"); addChoice("Set Community Features","sigadmin?sig=$s&cmd=F"); addChoice("Membership Control","sigadmin?sig=$s&cmd=M"); + addChoice("E-Mail To All Members","sigadmin?sig=$s&cmd=I"); addChoice("Display Audit Records","sigadmin?sig=$s&cmd=A"); // TODO: More options addChoice("Delete Community","sigadmin?sig=$s&cmd=DEL"); diff --git a/src/com/silverwrist/venice/servlets/format/CommunityEMail.java b/src/com/silverwrist/venice/servlets/format/CommunityEMail.java new file mode 100644 index 0000000..a4d6786 --- /dev/null +++ b/src/com/silverwrist/venice/servlets/format/CommunityEMail.java @@ -0,0 +1,115 @@ +/* + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * (the "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at . + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + * WARRANTY OF ANY KIND, either express or implied. See the License for the specific + * language governing rights and limitations under the License. + * + * The Original Code is the Venice Web Communities System. + * + * The Initial Developer of the Original Code is Eric J. Bowersox , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.venice.servlets.format; + +import java.util.*; +import javax.servlet.*; +import com.silverwrist.venice.core.*; +import com.silverwrist.venice.except.*; + +public class CommunityEMail implements JSPRender +{ + /*-------------------------------------------------------------------------------- + * Static data members + *-------------------------------------------------------------------------------- + */ + + // Attribute name for request attribute + protected static final String ATTR_NAME = "com.silverwrist.venice.content.CommunityEMail"; + + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private CommunityContext comm; // the community we're in + + /*-------------------------------------------------------------------------------- + * Constructors + *-------------------------------------------------------------------------------- + */ + + public CommunityEMail(CommunityContext comm) + { + this.comm = comm; + + } // end constructor + + /*-------------------------------------------------------------------------------- + * External static functions + *-------------------------------------------------------------------------------- + */ + + public static CommunityEMail retrieve(ServletRequest request) + { + return (CommunityEMail)(request.getAttribute(ATTR_NAME)); + + } // end retrieve + + /*-------------------------------------------------------------------------------- + * Implementations from interface VeniceContent + *-------------------------------------------------------------------------------- + */ + + public String getPageTitle(RenderData rdat) + { + return "Community E-Mail: " + comm.getName(); + + } // end getPageTitle + + public String getPageQID() + { + return null; + + } // end getPageQID + + /*-------------------------------------------------------------------------------- + * Implementations from interface JSPRender + *-------------------------------------------------------------------------------- + */ + + public void store(ServletRequest request) + { + request.setAttribute(ATTR_NAME,this); + + } // end store + + public String getTargetJSPName() + { + return "comm_email.jsp"; + + } // end getTargetJSPName + + /*-------------------------------------------------------------------------------- + * External operations + *-------------------------------------------------------------------------------- + */ + + public final int getCommunityID() + { + return comm.getCommunityID(); + + } // end getCommunityID + + public final String getCommunityName() + { + return comm.getName(); + + } // end getCommunityName + +} // end class CommunityEMail diff --git a/web/format/comm_email.jsp b/web/format/comm_email.jsp new file mode 100644 index 0000000..0051be2 --- /dev/null +++ b/web/format/comm_email.jsp @@ -0,0 +1,57 @@ +<%-- + The contents of this file are subject to the Mozilla Public License Version 1.1 + (the "License"); you may not use this file except in compliance with the License. + You may obtain a copy of the License at . + + Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + WARRANTY OF ANY KIND, either express or implied. See the License for the specific + language governing rights and limitations under the License. + + The Original Code is the Venice Web Communities System. + + The Initial Developer of the Original Code is Eric J. Bowersox , + for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + + Contributor(s): +--%> +<%@ page import = "java.util.*" %> +<%@ page import = "com.silverwrist.util.StringUtil" %> +<%@ page import = "com.silverwrist.venice.core.*" %> +<%@ page import = "com.silverwrist.venice.servlets.Variables" %> +<%@ page import = "com.silverwrist.venice.servlets.format.*" %> +<% + CommunityEMail data = CommunityEMail.retrieve(request); + Variables.failIfNull(data); + RenderData rdat = RenderConfig.createRenderData(application,request,response); +%> +<% if (rdat.useHTMLComments()) { %><% } %> +<% rdat.writeContentHeader(out,"Community E-Mail:",data.getCommunityName()); %> + +
">
+ + + + + + + + + + + + + + +
<%= rdat.getStdFontTag(ColorSelectors.CONTENT_FOREGROUND,2) %> + Send E-mail to all members of the community: +
+ <%= rdat.getStdFontTag(ColorSelectors.CONTENT_FOREGROUND,2) %>Subject: +
+ " NAME="send" + ALT="Send E-Mail" WIDTH=80 HEIGHT=24 BORDER=0>  + " NAME="cancel" + ALT="Cancel" WIDTH=80 HEIGHT=24 BORDER=0> +
+
diff --git a/web/format/conf_email.jsp b/web/format/conf_email.jsp index 1db20b1..7d09b62 100644 --- a/web/format/conf_email.jsp +++ b/web/format/conf_email.jsp @@ -70,4 +70,4 @@ ALT="Cancel" WIDTH=80 HEIGHT=24 BORDER=0> - \ No newline at end of file +