1 package com.dotmarketing.portlets.event_registrations.action; 2 3 import java.net.URLDecoder ; 4 import java.util.ArrayList ; 5 import java.util.HashMap ; 6 import java.util.Iterator ; 7 import java.util.List ; 8 9 import javax.portlet.ActionRequest; 10 import javax.portlet.ActionResponse; 11 import javax.portlet.PortletConfig; 12 import javax.servlet.http.HttpServletRequest ; 13 14 import org.apache.commons.beanutils.BeanUtils; 15 import org.apache.struts.action.ActionForm; 16 import org.apache.struts.action.ActionMapping; 17 18 import com.dotmarketing.beans.UserProxy; 19 import com.dotmarketing.db.DotHibernate; 20 import com.dotmarketing.factories.HostFactory; 21 import com.dotmarketing.factories.InodeFactory; 22 import com.dotmarketing.factories.UserProxyFactory; 23 import com.dotmarketing.portal.struts.DotPortletAction; 24 import com.dotmarketing.util.Config; 25 import com.dotmarketing.util.Mailer; 26 import com.dotmarketing.util.UtilMethods; 27 import com.dotmarketing.util.Validator; 28 import com.dotmarketing.util.WebKeys; 29 import com.liferay.portal.ejb.UserLocalManagerUtil; 30 import com.liferay.portal.model.User; 31 import com.liferay.portal.struts.ActionException; 32 import com.liferay.portal.util.Constants; 33 import com.liferay.portlet.ActionRequestImpl; 34 import com.liferay.util.servlet.SessionMessages; 35 import com.dotmarketing.portlets.event_registrations.factories.WebEventAttendeeFactory; 36 import com.dotmarketing.portlets.event_registrations.factories.WebEventRegistrationFactory; 37 import com.dotmarketing.portlets.event_registrations.model.WebEventAttendee; 38 import com.dotmarketing.portlets.event_registrations.model.WebEventRegistration; 39 import com.dotmarketing.portlets.event_registrations.struts.WebEventAttendeeForm; 40 import com.dotmarketing.portlets.event_registrations.struts.WebEventRegistrationForm; 41 import com.dotmarketing.portlets.webevents.factories.WebEventFactory; 42 import com.dotmarketing.portlets.webevents.model.WebEvent; 43 import com.dotmarketing.portlets.organization.factories.OrganizationFactory; 44 import com.dotmarketing.portlets.organization.model.Organization; 45 46 47 51 public class EditRegistrationAction extends DotPortletAction { 52 53 public void processAction( 54 ActionMapping mapping, ActionForm form, PortletConfig config, 55 ActionRequest req, ActionResponse res) 56 throws Exception { 57 58 String cmd = (req.getParameter(Constants.CMD)!=null)? req.getParameter(Constants.CMD) : Constants.EDIT; 59 String referer = req.getParameter("referer"); 60 61 65 DotHibernate.startTransaction(); 66 User user = _getUser(req); 67 68 try { 69 _retrieveEventRegistration(req, res, config, form, user); 70 71 } catch (ActionException ae) { 72 _handleException(ae, req); 73 } 74 75 78 if ((cmd != null) && cmd.equals(Constants.EDIT)) { 79 try { 80 _editEventRegistration(req, res, config, form); 81 setForward(req,"portlet.ext.webevents_registration.edit_registration"); 82 } catch (ActionException ae) { 83 _handleException(ae, req); 84 } 85 } 86 89 if ((cmd != null) && cmd.equals("add_attendee")) { 90 try { 91 _addAttendee(req, res, config, form, mapping, user); 92 _editEventRegistration(req, res, config, form); 93 setForward(req,"portlet.ext.webevents_registration.edit_registration"); 94 } catch (ActionException ae) { 95 _handleException(ae, req); 96 } 97 } 98 101 if ((cmd != null) && cmd.equals("delete_attendee")) { 102 try { 103 _deleteAttendee(req, res, config, form, user); 104 _editEventRegistration(req, res, config, form); 105 setForward(req,"portlet.ext.webevents_registration.edit_registration"); 106 } catch (ActionException ae) { 107 _handleException(ae, req); 108 } 109 } 110 111 114 else if ((cmd != null) && cmd.equals(Constants.SAVE)) { 115 try { 116 117 if (Validator.validate(req,form,mapping)) { 118 _saveEventRegistration(req, res, config, form, user); 119 _editEventRegistration(req, res, config, form); 120 setForward(req,"portlet.ext.webevents_registration.edit_registration"); 122 } else { 123 setForward(req,"portlet.ext.webevents_registration.edit_registration"); 124 } 125 126 } catch (ActionException ae) { 127 _handleException(ae, req); 128 } 129 } 130 else if ((cmd != null) && cmd.equals("sendInvoice")) { 131 try { 132 _sendInvoice(mapping, req, res, config, form); 133 _editEventRegistration(req, res, config, form); 134 } catch (Exception ae) { 135 _handleException(ae, req); 136 } 137 setForward(req,"portlet.ext.webevents_registration.edit_registration"); 138 } 139 144 else if ((cmd != null) && cmd.equals(Constants.DELETE)) { 145 try { 146 _deleteEventRegistration(req, res, config, form, user); 147 148 } catch (ActionException ae) { 149 _handleException(ae, req); 150 } 151 _sendToReferral(req,res,referer); 152 } 153 DotHibernate.commitTransaction(); 154 155 } 156 157 158 private void _sendInvoice(ActionMapping mapping, ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form) 160 throws Exception { 161 WebEventRegistration registration = ( WebEventRegistration ) req.getAttribute(WebKeys.WEBEVENTS_REG_EDIT); 162 UserProxy proxy = UserProxyFactory.getUserProxy(registration.getUserInode()); 163 User user = com.dotmarketing.cms.factories.PublicUserFactory.getUserByUserId(proxy.getUserId()); 164 String path = ""; 165 166 WebEvent event = WebEventFactory.getWebEvent(registration.getEventInode()); 167 168 if (event.isInstitute()) { 169 if (registration.getPaymentType() == 1) 170 path = mapping.findForward("portlet.ext.webevents_registration.add_registration.creditCardConfirmationEmail").getPath(); 171 else 172 path = mapping.findForward("portlet.ext.webevents_registration.add_registration.checkConfirmationEmail").getPath(); 173 } else { 174 if (registration.getRegistrationStatus() == 1) 176 path = mapping.findForward("portlet.ext.webevents_registration.add_registration.webinarConfirmationEmail").getPath(); 177 else 178 path = mapping.findForward("portlet.ext.webevents_registration.add_registration.webinarCheckConfirmationEmail").getPath(); 179 } 180 181 try { 182 StringBuffer writer = UtilMethods.getURL("http://" 183 + HostFactory.getCurrentHost(req).getHostname() + path 184 + "?registrationInode=" + registration.getInode()); 185 186 String [] reportEmails = Config.getStringArrayProperty("BCCEMAIL_REGISTRATION_ADDRESSES"); 187 188 StringBuffer bcc = new StringBuffer (); 189 for (String email : reportEmails) { 190 if (bcc.toString().length() > 0) 191 bcc.append(", "); 192 bcc.append(email); 193 } 194 195 Mailer m = new Mailer(); 196 m.setToEmail(user.getEmailAddress()); 197 m.setSubject(Config.getStringProperty("WEB_EVENT_REGISTRATION_EMAIL_TITLE")); 198 m.setHTMLBody(writer.toString().trim()); 199 m.setFromEmail(Config.getStringProperty("EMAIL_REGISTRATION_ADDRESS")); 200 m.setBcc(bcc.toString()); 201 m.sendMessage(); 202 203 ActionRequestImpl reqImpl = (ActionRequestImpl)req; 205 HttpServletRequest httpReq = reqImpl.getHttpServletRequest(); 206 SessionMessages.add(httpReq, "message", "message.webevent_registration.email_sent"); 208 } catch (Exception e) { 209 e.printStackTrace(System.out); 210 } 211 212 } 213 214 private void _retrieveEventRegistration(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, User user) 215 throws Exception { 216 217 String inode = (req.getParameter("inode")!=null) ? req.getParameter("inode") : "0"; 218 WebEventRegistration e = null; 219 if(inode.equals("0")){ 220 e = WebEventRegistrationFactory.newInstance(); 221 } else { 222 e = WebEventRegistrationFactory.getWebEventRegistration(inode); 223 } 224 req.setAttribute(WebKeys.WEBEVENTS_REG_FORM, form); 225 req.setAttribute(WebKeys.WEBEVENTS_REG_EDIT, e); 226 } 227 228 private void _editEventRegistration(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form) 229 throws Exception { 230 231 WebEventRegistrationForm formBean = ( WebEventRegistrationForm ) form; 232 WebEventRegistration e = ( WebEventRegistration ) req.getAttribute(WebKeys.WEBEVENTS_REG_EDIT); 233 BeanUtils.copyProperties(formBean, e); 234 235 236 List <HashMap > statuses = new ArrayList <HashMap >(); 238 String [] statusesArray = Config.getStringArrayProperty("EREG_STATUSES"); 239 for (int i=0;i<statusesArray.length;i++) { 240 HashMap <String , String > hs = new HashMap <String , String >(); 241 String status = statusesArray[i]; 242 hs.put("statusName",Config.getStringProperty(status + "_FN")); 243 hs.put("statusValue",Config.getStringProperty(status)); 244 statuses.add(hs); 245 } 246 req.setAttribute("registrationStatuses",statuses.iterator()); 247 248 List <HashMap > paymentTypes = new ArrayList <HashMap >(); 250 String [] paymentTypesArray = Config.getStringArrayProperty("EREG_PAYMENT_TYPES"); 251 for (int i=0;i<paymentTypesArray.length;i++) { 252 String pType = paymentTypesArray[i]; 253 HashMap <String , String > hs = new HashMap <String , String >(); 254 hs.put("paymentTypeName",Config.getStringProperty(pType + "_FN")); 255 hs.put("paymentTypeValue",Config.getStringProperty(pType)); 256 paymentTypes.add(hs); 257 } 258 259 req.setAttribute("paymentTypes",paymentTypes.iterator()); 260 261 if (e.getUserInode() > 0){ 263 UserProxy registrantUser = UserProxyFactory.getUserProxy(e.getUserInode()); 264 User user = com.dotmarketing.cms.factories.PublicUserFactory.getUserByUserId(registrantUser.getUserId()); 265 266 formBean.setRegistrantFirstName(user.getFirstName()); 267 formBean.setRegistrantLastName(user.getLastName()); 268 formBean.setRegistrantEmail(user.getEmailAddress()); 269 formBean.setUserId(user.getUserId()); 270 if (registrantUser.getInode()>0) { 271 Organization organization = (Organization) InodeFactory.getParentOfClass(registrantUser,Organization.class); 272 if (organization.getInode()>0) { 273 formBean.setRegistrantFacility(organization.getTitle().trim()); 274 formBean.setRegistrantFacilityInode(organization.getInode()); 275 276 Organization parentSystem = OrganizationFactory.getParentOrganization(organization); 277 if (parentSystem.getInode()>0) { 278 formBean.setRegistrantSystem(parentSystem.getTitle().trim()); 279 formBean.setRegistrantSystemInode(parentSystem.getInode()); 280 } 281 } 282 } 283 } 284 else{ 285 formBean.setRegistrantFirstName(""); 286 formBean.setRegistrantLastName(""); 287 formBean.setRegistrantEmail(""); 288 } 289 List <WebEventAttendee> attendees = WebEventRegistrationFactory.getEventAttendees(e); 291 req.setAttribute(WebKeys.WEBEVENT_REG_ATTENDEES, attendees); 292 293 WebEventAttendee attendee = WebEventAttendeeFactory.getWebEventAttendee(formBean.getCurrentAttendeeInode()); 294 WebEventAttendeeForm attendeeForm = new WebEventAttendeeForm(); 295 296 if (attendee.getInode() > 0) { 297 BeanUtils.copyProperties(attendeeForm,attendee); 298 req.setAttribute("WebEventAttendeeForm",attendeeForm); 299 } 300 } 301 302 303 private void _saveEventRegistration(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, User user) 304 throws Exception { 305 306 WebEventRegistrationForm formBean = ( WebEventRegistrationForm ) form; 307 WebEventRegistration e = ( WebEventRegistration ) req.getAttribute(WebKeys.WEBEVENTS_REG_EDIT); 308 boolean runAutoStatus = ((e.getTotalPaid() != formBean.getTotalPaid()) ? true : false); 309 e.setTotalPaid(formBean.getTotalPaid()); 310 e.setCheckBankName(formBean.getCheckBankName()); 311 e.setCheckNumber(formBean.getCheckNumber()); 312 e.setPoNumber(formBean.getPoNumber()); 313 e.setBillingAddress1(formBean.getBillingAddress1()); 314 e.setBillingAddress2(formBean.getBillingAddress2()); 315 e.setBillingCity(formBean.getBillingCity()); 316 e.setBillingContactEmail(formBean.getBillingContactEmail()); 317 e.setBillingContactName(formBean.getBillingContactName()); 318 e.setBillingContactPhone(formBean.getBillingContactPhone()); 319 e.setBillingState(formBean.getBillingState()); 320 e.setBillingZip(formBean.getBillingZip()); 321 e.setRegistrationStatus(formBean.getRegistrationStatus()); 322 e.setPaymentType(formBean.getPaymentType()); 323 e.setInvoiceNumber(formBean.getInvoiceNumber()); 324 java.util.List attendees = WebEventRegistrationFactory.getEventAttendees(e); 326 int total = 0; 327 Iterator attendeesIter = attendees.iterator(); 328 while (attendeesIter.hasNext()) { 329 WebEventAttendee attendee = (WebEventAttendee) attendeesIter.next(); 330 total += attendee.getRegistrationPrice(); 331 } 332 e.setTotalDue(total - e.getTotalPaid()); 334 e.setTotalRegistration(total); 335 formBean.setTotalDue(e.getTotalDue()); 336 if(runAutoStatus) 337 { 338 _setRegistrationStatus(formBean); 339 e.setRegistrationStatus(formBean.getRegistrationStatus()); 340 } 341 e.setModified_QB(true); 342 WebEventRegistrationFactory.saveWebEventRegistration(e); 343 req.setAttribute(WebKeys.WEBEVENTS_REG_EDIT, e); 344 345 ActionRequestImpl reqImpl = (ActionRequestImpl)req; 347 HttpServletRequest httpReq = reqImpl.getHttpServletRequest(); 348 SessionMessages.add(httpReq, "message", "message.webevent_registration.saved"); 350 351 } 352 353 private void _deleteEventRegistration(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, User user) 354 throws Exception { 355 356 WebEventRegistration e = ( WebEventRegistration ) req.getAttribute(WebKeys.WEBEVENTS_REG_EDIT); 357 358 java.util.List attendees = WebEventRegistrationFactory.getEventAttendees(e); 360 Iterator attendeesIter = attendees.iterator(); 361 while (attendeesIter.hasNext()) { 362 WebEventAttendee attendee = (WebEventAttendee) attendeesIter.next(); 363 WebEventAttendeeFactory.deleteWebEventAttendee(attendee); 364 } 365 WebEventRegistrationFactory.deleteWebEventRegistration(e); 367 SessionMessages.add(req, "message", "message.webevent_registration.deleted"); 368 369 } 370 private void _deleteAttendee(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, User user) 371 throws Exception { 372 373 WebEventRegistrationForm registrationForm = (WebEventRegistrationForm) form; 374 WebEventAttendee attendee = WebEventAttendeeFactory.getWebEventAttendee(registrationForm.getCurrentAttendeeInode()); 376 WebEventAttendeeFactory.deleteWebEventAttendee(attendee); 377 registrationForm.setCurrentAttendeeInode(0); 378 379 req.setAttribute("WebEventAttendeeForm",new WebEventAttendeeForm()); 380 SessionMessages.add(req, "message", "message.webevent_registration.delete_attendee"); 381 382 } 383 384 private void _setRegistrationStatus(WebEventRegistrationForm registrationForm) { 385 if (registrationForm.getTotalDue() > 0) { 386 registrationForm.setRegistrationStatus(Config.getIntProperty("EREG_WAITING")); 387 } 388 else if (registrationForm.getTotalDue() < 0) { 389 registrationForm.setRegistrationStatus(Config.getIntProperty("EREG_REIMBURSEMENT")); 390 } 391 else { 392 registrationForm.setRegistrationStatus(Config.getIntProperty("EREG_PAID")); 393 } 394 } 395 396 private void _addAttendee(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, ActionMapping mapping, User user) 397 throws Exception { 398 399 WebEventRegistration e = ( WebEventRegistration ) req.getAttribute(WebKeys.WEBEVENTS_REG_EDIT); 401 402 ActionRequestImpl reqImpl = (ActionRequestImpl)req; 404 HttpServletRequest httpReq = reqImpl.getHttpServletRequest(); 405 406 WebEventRegistrationForm registrationForm = (WebEventRegistrationForm) form; 407 WebEventAttendeeForm attendeeForm = new WebEventAttendeeForm(); 412 attendeeForm.setFirstName(registrationForm.getCurrentAttendeeFirstName()); 413 attendeeForm.setLastName(registrationForm.getCurrentAttendeeLastName()); 414 attendeeForm.setTitle(registrationForm.getCurrentAttendeeTitle()); 415 attendeeForm.setBadgeName(registrationForm.getCurrentAttendeeBadgeName()); 416 attendeeForm.setEmail(registrationForm.getCurrentAttendeeEmail()); 417 attendeeForm.setRegistrationPrice(registrationForm.getCurrentAttendeePrice()); 418 419 if (Validator.validate(req, form, mapping)) { 421 422 WebEventAttendee attendee = WebEventAttendeeFactory.getWebEventAttendee(registrationForm.getCurrentAttendeeInode()); 424 if (attendee.getInode()>0) { 425 registrationForm.setTotalDue(registrationForm.getTotalDue() - attendee.getRegistrationPrice()); 427 registrationForm.setTotalDue(registrationForm.getTotalDue() + registrationForm.getCurrentAttendeePrice()); 428 _setRegistrationStatus(registrationForm); 429 430 attendee.setFirstName(registrationForm.getCurrentAttendeeFirstName()); 432 attendee.setLastName(registrationForm.getCurrentAttendeeLastName()); 433 attendee.setTitle(registrationForm.getCurrentAttendeeTitle()); 434 attendee.setBadgeName(registrationForm.getCurrentAttendeeBadgeName()); 435 attendee.setEmail(registrationForm.getCurrentAttendeeEmail()); 436 attendee.setRegistrationPrice(registrationForm.getCurrentAttendeePrice()); 437 WebEventAttendeeFactory.saveWebEventAttendee(attendee); 438 req.setAttribute("WebEventAttendeeForm",new WebEventAttendeeForm()); 439 registrationForm.setCurrentAttendeeInode(0); 440 SessionMessages.add(httpReq, "message", "message.webevent_registration.update_attendee"); 441 } 442 else { 443 java.util.List currentAttendees = WebEventRegistrationFactory.getEventAttendeesByEmail(e,registrationForm.getCurrentAttendeeEmail()); 445 450 registrationForm.setTotalDue(registrationForm.getTotalDue() + registrationForm.getCurrentAttendeePrice()); 452 _setRegistrationStatus(registrationForm); 453 454 attendee.setFirstName(registrationForm.getCurrentAttendeeFirstName()); 455 attendee.setLastName(registrationForm.getCurrentAttendeeLastName()); 456 attendee.setTitle(registrationForm.getCurrentAttendeeTitle()); 457 attendee.setBadgeName(registrationForm.getCurrentAttendeeBadgeName()); 458 attendee.setEmail(registrationForm.getCurrentAttendeeEmail()); 459 attendee.setRegistrationPrice(registrationForm.getCurrentAttendeePrice()); 460 attendee.setEventRegistrationInode(e.getInode()); 461 WebEventAttendeeFactory.saveWebEventAttendee(attendee); 462 req.setAttribute("WebEventAttendeeForm",new WebEventAttendeeForm()); 463 registrationForm.setCurrentAttendeeInode(0); 464 SessionMessages.add(httpReq, "message", "message.webevent_registration.add_attendee"); 465 } 467 java.util.List attendees = WebEventRegistrationFactory.getEventAttendees(e); 469 int total = 0; 470 Iterator attendeesIter = attendees.iterator(); 471 while (attendeesIter.hasNext()) { 472 WebEventAttendee attendee2 = (WebEventAttendee) attendeesIter.next(); 473 total += attendee2.getRegistrationPrice(); 474 } 475 e.setTotalDue(total - e.getTotalPaid()); 477 e.setTotalRegistration(total); 478 e.setModified_QB(true); 479 registrationForm.setTotalDue(e.getTotalDue()); 480 } else { 482 req.setAttribute("WebEventAttendeeForm",attendeeForm); 483 } 484 } 485 486 487 } 488 489 | Popular Tags |