1 package org.paneris.jammyjoes.controller; 2 3 import org.melati.Melati; 4 import org.melati.servlet.Form; 5 import org.melati.template.ServletTemplateContext; 6 import org.melati.util.Email; 7 import org.paneris.jammyjoes.model.JammyjoesDatabase; 8 import org.paneris.jammyjoes.model.User; 9 import org.paneris.jammyjoes.servlet.JammyJoesMelatiServlet; 10 11 public class Competition extends JammyJoesMelatiServlet { 12 13 private static final long serialVersionUID = 1L; 14 15 protected String jammyjoesRequest(Melati melati, ServletTemplateContext context) 16 throws Exception { 17 18 JammyjoesDatabase db = (JammyjoesDatabase) melati.getDatabase(); 19 ServletTemplateContext tc = melati.getServletTemplateContext(); 20 String template = "view/CompetitionSuccess.wm"; 21 String email = Form.getFormNulled(tc,"email"); 22 String wantspam = Form.getFormNulled(tc,"wantspam"); 23 User admin = (User)db.getUserTable().administratorUser(); 24 String message = email + " would like to be entered for the competition.\n\n"; 25 String custMessage = "Thank you for entering the competition to win a Zingy Pingy Bee."; 26 custMessage += " You will be notified if you have won in early August.\n\n"; 27 if (wantspam != null) { 28 message += "They would also like to receive occasional emails from JammyJoes.\n"; 29 custMessage += "You will also receive occasional emails from JammyJoes.\n"; 30 } else { 31 message += "They would NOT like to receive occasional emails from JammyJoes.\n"; 32 custMessage += "You will NOT receive any further emails from JammyJoes (unless you win :).\n"; 33 } 34 custMessage += "\nGood luck.\n\nJenny and Dee\n"; 35 try { 36 Email.send(db.getSettingTable().get(Email.SMTPSERVER), email, admin.getEmail(), "", "JammyJoes Competition", message); 37 Email.send(db.getSettingTable().get(Email.SMTPSERVER), admin.getEmail(), email, "", "JammyJoes Competition", custMessage); 38 } catch (Exception e) { 39 context.put("error","Sorry! I couldn't send this email because: " + e); 40 } 41 return template; 42 } 43 }