1 package com.dotmarketing.portlets.events.action; 2 3 import java.util.Random ; 4 5 import javax.servlet.http.HttpServletRequest ; 6 import javax.servlet.http.HttpServletResponse ; 7 import javax.servlet.http.HttpSession ; 8 9 import org.apache.commons.beanutils.BeanUtils; 10 import org.apache.struts.action.ActionError; 11 import org.apache.struts.action.ActionErrors; 12 import org.apache.struts.action.ActionForm; 13 import org.apache.struts.action.ActionForward; 14 import org.apache.struts.action.ActionMapping; 15 import org.apache.struts.actions.DispatchAction; 16 17 import com.dotmarketing.factories.HostFactory; 18 import com.dotmarketing.factories.InodeFactory; 19 import com.dotmarketing.portlets.events.model.Event; 20 import com.dotmarketing.portlets.events.model.EventRegistration; 21 import com.dotmarketing.portlets.events.struts.EventRegistrationForm; 22 import com.dotmarketing.util.Mailer; 23 import com.dotmarketing.util.UtilMethods; 24 25 32 public class EventRegistrationAction extends DispatchAction { 33 34 public ActionForward unspecified(ActionMapping mapping, ActionForm lf, HttpServletRequest request, 35 HttpServletResponse response) throws Exception { 36 37 EventRegistrationForm form = (EventRegistrationForm) lf; 38 form.setRegistationRandomId(new Random ().nextInt()); 39 40 String event_inode = request.getParameter("event_inode"); 41 Event e = (Event) InodeFactory.getInode(event_inode, Event.class); 42 request.setAttribute("event", e); 43 44 form.setEventInode(e.getInode()); 45 request.setAttribute("eventRegistrationForm", form); 46 47 if (e.isRegistration()) { 48 ActionForward af = (mapping.findForward("eventRegistrationPage")); 49 return af; 50 } else { 51 return null; 52 } 53 } 54 55 public ActionForward list(ActionMapping mapping, ActionForm lf, HttpServletRequest request, 56 HttpServletResponse response) throws Exception { 57 ActionForward af = (mapping.findForward("eventRegistrationListPage")); 58 return af; 59 } 60 61 public ActionForward save(ActionMapping mapping, ActionForm lf, HttpServletRequest request, 62 HttpServletResponse response) throws Exception { 63 64 EventRegistrationForm form = (EventRegistrationForm) lf; 66 long event_inode = form.getEventInode(); 67 68 Event e = (Event) InodeFactory.getInode(event_inode, Event.class); 69 70 request.setAttribute("eventRegistrationForm", form); 71 request.setAttribute("event", e); 72 73 if (e==null || e.getInode()==0) { 74 ActionErrors errors = new ActionErrors(); 75 errors.add(ActionErrors.GLOBAL_ERROR,new ActionError("There was an error with your registration.")); 76 saveErrors(request, errors); 77 return mapping.getInputForward(); 78 } 79 80 ActionErrors aes = form.validate(mapping, request); 82 if(aes != null && aes.size() > 0){ 83 saveErrors(request, aes); 84 return mapping.getInputForward(); 85 } 86 87 HttpSession s = request.getSession(); 89 EventRegistrationForm lastReg = (EventRegistrationForm) s.getAttribute("lastEventRegistrationForm"); 90 if (lastReg != null && form.getRegistationRandomId() == lastReg.getRegistationRandomId()) 91 { 92 return mapping.findForward("registrationSuccessfulPage"); 93 } 94 s.setAttribute("lastEventRegistrationForm", form); 95 96 EventRegistration registration = (EventRegistration) InodeFactory.getInode(0, EventRegistration.class); 98 BeanUtils.copyProperties(registration, form); 99 InodeFactory.saveInode(registration); 100 101 e.addChild(registration); 103 InodeFactory.saveInode(e); 104 105 String fromEmail = request.getParameter("fromEmail"); 107 Mailer mailer = new Mailer(); 108 mailer.setFromEmail(fromEmail); 109 mailer.setToEmail(form.getEmail()); 110 mailer.setBcc(fromEmail); 111 mailer.setSubject("Registration for the event: " + e.getTitle()); 112 mailer.setHTMLAndTextBody(_buildEmailBody(e, registration)); 113 mailer.sendMessage(); 114 115 ActionForward af = mapping.findForward("registrationSuccessfulPage"); 117 118 return af; 119 } 120 121 private String _buildEmailBody (Event e, EventRegistration reg) { 122 StringBuffer sb = new StringBuffer (); 123 sb.append("<html><link rel=\"stylesheet\" HREF=\"http://" + HostFactory.getDefaultHost().getHostname() + "/global/css/masterStyle.css\" type=\"text/css\"><body bgcolor=\"white\">"); 124 sb.append("<div id=\"bodyArea\"><table border=\"1\" id=\"bodyID\" bgcolor=\"#ffffff\" cellpadding=\"4\" cellspacing=\"2\">"); 125 sb.append("<img SRC=\"http://" + HostFactory.getDefaultHost().getHostname() + "/global/images/logo.gif\"><BR>"); 126 sb.append("<h2>You have been successfully registered to Event: " + (e.getTitle()==null?"":e.getTitle()) + ".<br></h2>"); 127 sb.append("<br>Here is your registration information:<br>"); 128 sb.append("<B>Registration Date:</B> "); 129 sb.append(UtilMethods.dateToPrettyHTMLDate(reg.getRegistrationDate())); 130 sb.append("<br>"); 131 sb.append("<B>Name:</B> " + reg.getFullName()); 132 sb.append("<br>"); 133 sb.append("<B>Registration Comments:</B><br>"); 134 sb.append(reg.getComments()); 135 sb.append("<br>"); 136 sb.append("</td></tr></table></div></body></html>"); 139 return sb.toString(); 140 } 141 } 142 | Popular Tags |