1 package com.dotmarketing.portlets.event_registrations.action; 2 3 import java.net.URLDecoder ; 4 import java.text.DateFormatSymbols ; 5 import java.util.ArrayList ; 6 import java.util.Calendar ; 7 import java.util.Date ; 8 import java.util.GregorianCalendar ; 9 import java.util.HashMap ; 10 import java.util.Iterator ; 11 import java.util.List ; 12 13 import javax.portlet.ActionRequest; 14 import javax.portlet.ActionResponse; 15 import javax.portlet.PortletConfig; 16 import javax.portlet.WindowState; 17 import javax.servlet.http.HttpServletRequest ; 18 19 import org.apache.commons.beanutils.BeanUtils; 20 import org.apache.struts.Globals; 21 import org.apache.struts.action.ActionForm; 22 import org.apache.struts.action.ActionMapping; 23 import org.apache.struts.action.ActionMessage; 24 import org.apache.struts.action.ActionMessages; 25 26 import com.dotmarketing.beans.UserProxy; 27 import com.dotmarketing.cms.factories.PublicAddressFactory; 28 import com.dotmarketing.db.DotHibernate; 29 import com.dotmarketing.factories.HostFactory; 30 import com.dotmarketing.factories.InodeFactory; 31 import com.dotmarketing.factories.UserProxyFactory; 32 import com.dotmarketing.portal.struts.DotPortletAction; 33 import com.dotmarketing.util.Config; 34 import com.dotmarketing.util.CreditCardProcessor; 35 import com.dotmarketing.util.CreditCardProcessorException; 36 import com.dotmarketing.util.CreditCardProcessorResponse; 37 import com.dotmarketing.util.Logger; 38 import com.dotmarketing.util.Mailer; 39 import com.dotmarketing.util.UtilMethods; 40 import com.dotmarketing.util.Validator; 41 import com.dotmarketing.util.WebKeys; 42 import com.liferay.portal.ejb.UserLocalManagerUtil; 43 import com.liferay.portal.model.Address; 44 import com.liferay.portal.model.User; 45 import com.liferay.portal.struts.ActionException; 46 import com.liferay.portal.util.Constants; 47 import com.liferay.portlet.ActionRequestImpl; 48 import com.liferay.util.servlet.SessionMessages; 49 import com.dotmarketing.portlets.event_registrations.factories.WebEventRegistrationFactory; 50 import com.dotmarketing.portlets.event_registrations.model.WebEventAttendee; 51 import com.dotmarketing.portlets.event_registrations.model.WebEventRegistration; 52 import com.dotmarketing.portlets.event_registrations.struts.WebEventAttendeeForm; 53 import com.dotmarketing.portlets.event_registrations.struts.WebEventRegistrationForm; 54 import com.dotmarketing.portlets.webevents.factories.WebEventFactory; 55 import com.dotmarketing.portlets.webevents.factories.WebEventLocationFactory; 56 import com.dotmarketing.portlets.webevents.model.WebEvent; 57 import com.dotmarketing.portlets.webevents.model.WebEventLocation; 58 import com.dotmarketing.portlets.organization.factories.OrganizationFactory; 59 import com.dotmarketing.portlets.organization.model.Organization; 60 61 62 66 public class AddRegistrationAction extends DotPortletAction { 67 68 public void processAction( 69 ActionMapping mapping, ActionForm form, PortletConfig config, 70 ActionRequest req, ActionResponse res) 71 throws Exception { 72 73 String cmd = (req.getParameter(Constants.CMD)!=null)? req.getParameter(Constants.CMD) : Constants.EDIT; 74 String referer = req.getParameter("referer"); 75 if ((referer!=null) && (referer.length()!=0)) { 77 referer = URLDecoder.decode(referer,"UTF-8"); 78 } 79 80 DotHibernate.startTransaction(); 81 User user = _getUser(req); 82 83 try { 84 _retrieveEventRegistration(req, res, config, form, user); 85 86 } catch (ActionException ae) { 87 _handleException(ae, req); 88 } 89 90 93 if ((cmd != null) && cmd.equals("step4")) { 94 try { 95 String forward = _addEventRegistrationStep4(req, res, config, form, mapping, user); 96 if (!forward.startsWith("step")) { 97 setForward(req,forward); 98 } 99 else { 100 cmd = forward; 101 } 102 } catch (ActionException ae) { 103 _handleException(ae, req); 104 } 105 } 106 109 if ((cmd != null) && cmd.equals("step1")) { 110 try { 111 _addEventRegistrationStep1(req, res, config, form, user); 112 setForward(req,"portlet.ext.webevents_registration.add_registration.step1"); 113 } catch (ActionException ae) { 114 _handleException(ae, req); 115 } 116 } 117 120 if ((cmd != null) && cmd.equals("add_attendee")) { 121 try { 122 _addAttendee(req, res, config, form, mapping, user); 123 setForward(req,"portlet.ext.webevents_registration.add_registration.step2"); 124 } catch (ActionException ae) { 125 _handleException(ae, req); 126 } 127 } 128 131 if ((cmd != null) && cmd.equals("delete_attendee")) { 132 try { 133 _deleteAttendee(req, res, config, form, user); 134 setForward(req,"portlet.ext.webevents_registration.add_registration.step2"); 135 } catch (ActionException ae) { 136 _handleException(ae, req); 137 } 138 } 139 142 if ((cmd != null) && (cmd.equals("step2") || cmd.equals("edit_attendee"))) { 143 try { 144 145 WebEventRegistrationForm registrationForm = (WebEventRegistrationForm) form; 146 if(registrationForm.getEventLocationInode() == 0){ 147 SessionMessages.add(req, "message", "error.webregistration.location"); 148 _addEventRegistrationStep1(req, res, config, form, user); 149 setForward(req,"portlet.ext.webevents_registration.add_registration.step1"); 150 } else { 151 if (cmd.equals("edit_attendee")) { 152 _addEventRegistrationStep2(req, res, config, form, user); 153 } 154 WebEvent event = WebEventFactory.getWebEvent(registrationForm.getEventInode()); 155 if (event.isInstitute()) { 156 setForward(req,"portlet.ext.webevents_registration.add_registration.step2"); 157 } 158 else { 159 cmd = "register_user"; 160 } 161 } 162 } catch (ActionException ae) { 163 _handleException(ae, req); 164 } 165 } 166 if ((cmd != null) && cmd.equals("register_user")) { 167 WebEventRegistrationForm registrationForm = (WebEventRegistrationForm) form; 168 WebEvent event = WebEventFactory.getWebEvent(registrationForm.getEventInode()); 169 170 if (!UtilMethods.isSet(registrationForm.getUserId())) { 172 173 List <WebEventAttendeeForm> currentAttendees = registrationForm.getEventAttendees(); 174 if (currentAttendees.size()>0 || !event.isInstitute()) { 175 176 ActionRequestImpl reqImpl = (ActionRequestImpl)req; 178 HttpServletRequest httpReq = reqImpl.getHttpServletRequest(); 179 180 if (!UtilMethods.isSet(referer)) { 181 java.util.Map <String ,String []> params2 = new java.util.HashMap <String ,String []>(); 182 params2.put("struts_action",new String [] {"/ext/event_registration/add_registration"}); 183 params2.put("cmd",new String [] { "step3" }); 184 referer = com.dotmarketing.util.PortletURLUtil.getActionURL(httpReq,WindowState.MAXIMIZED.toString(),params2); 185 } 186 187 java.util.Map <String ,String []> params = new java.util.HashMap <String ,String []>(); 188 params.put("struts_action",new String [] {"/ext/usermanager/register_user"}); 189 params.put("referer",new String [] { referer }); 190 params.put("without_password",new String [] {"1"}); 191 String af = com.dotmarketing.util.PortletURLUtil.getActionURL(httpReq,WindowState.MAXIMIZED.toString(),params); 192 193 _sendToReferral(req, res, af); 194 return; 195 } 196 else { 197 SessionMessages.add(req, "message", "message.webevent_registration.attendees_required"); 198 } 199 setForward(req,"portlet.ext.webevents_registration.add_registration.step2"); 200 } 201 else { 202 cmd = "step3"; 204 } 205 } 206 209 if ((cmd != null) && cmd.equals("step3")) { 210 try { 211 _addEventRegistrationStep3(req, res, config, form, user); 212 setForward(req,"portlet.ext.webevents_registration.add_registration.step3"); 213 } catch (ActionException ae) { 214 _handleException(ae, req); 215 } 216 } 217 218 DotHibernate.commitTransaction(); 219 220 } 221 222 223 private void _retrieveEventRegistration(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, User user) 225 throws Exception { 226 227 String inode = (req.getParameter("inode")!=null) ? req.getParameter("inode") : "0"; 228 WebEventRegistration e = null; 229 if(inode.equals("0")){ 230 e = WebEventRegistrationFactory.newInstance(); 231 } else { 232 e = WebEventRegistrationFactory.getWebEventRegistration(inode); 233 } 234 req.setAttribute(WebKeys.WEBEVENTS_REG_FORM, form); 235 req.setAttribute(WebKeys.WEBEVENTS_REG_EDIT, e); 236 } 237 private void _addAttendee(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, ActionMapping mapping, User user) 238 throws Exception { 239 240 ActionRequestImpl reqImpl = (ActionRequestImpl)req; 242 HttpServletRequest httpReq = reqImpl.getHttpServletRequest(); 243 244 WebEventRegistrationForm registrationForm = (WebEventRegistrationForm) form; 245 246 WebEventAttendeeForm attendeeForm = new WebEventAttendeeForm(); 247 attendeeForm.setFirstName(registrationForm.getCurrentAttendeeFirstName()); 248 attendeeForm.setLastName(registrationForm.getCurrentAttendeeLastName()); 249 attendeeForm.setTitle(registrationForm.getCurrentAttendeeTitle()); 250 attendeeForm.setBadgeName(registrationForm.getCurrentAttendeeBadgeName()); 251 attendeeForm.setEmail(registrationForm.getCurrentAttendeeEmail()); 252 attendeeForm.setInode(registrationForm.getCurrentAttendeeInode()); 253 254 if (Validator.validate(req, form, mapping)) { 256 257 WebEventLocation loc = WebEventLocationFactory.getWebEventLocation(registrationForm.getEventLocationInode()); 258 259 if (httpReq.getSession().getAttribute("isPartner") != null 261 && httpReq.getSession().getAttribute("isPartner").equals("true")){ 262 Organization organization = (Organization)httpReq.getSession().getAttribute("userOrganization"); 263 if (organization.getInstitute_price() > 0) 264 attendeeForm.setRegistrationPrice(organization.getInstitute_price()); 265 else 266 attendeeForm.setRegistrationPrice(loc.getPartnerPrice()); 267 } 268 else 269 attendeeForm.setRegistrationPrice(loc.getNonPartnerPrice()); 270 271 272 List <WebEventAttendeeForm> currentAttendees = registrationForm.getEventAttendees(); 273 274 if (req.getParameter("isnew") != null 275 && req.getParameter("isnew").equals("true")) { 276 if (currentAttendees.contains(attendeeForm)) { 277 SessionMessages.add(httpReq, "message", "error.attendee.already.registered"); 278 req.setAttribute("WebEventAttendeeForm",attendeeForm); 279 } else { 280 currentAttendees.add(attendeeForm); 281 req.setAttribute("WebEventAttendeeForm",new WebEventAttendeeForm()); 282 } 283 } else { 284 WebEventAttendeeForm lastAttendeeForm = new WebEventAttendeeForm(); 285 lastAttendeeForm.setEmail(registrationForm.getCurrentAttendeeLastEmail()); 286 lastAttendeeForm.setFirstName(registrationForm.getCurrentAttendeeLastFirstName()); 287 lastAttendeeForm.setLastName(registrationForm.getCurrentAttendeeLastLastName()); 288 289 if (currentAttendees!=null && currentAttendees.contains(lastAttendeeForm)) { 290 currentAttendees.remove(lastAttendeeForm); 291 currentAttendees.add(attendeeForm); 292 } else { 293 currentAttendees.add(attendeeForm); 294 } 295 req.setAttribute("WebEventAttendeeForm",new WebEventAttendeeForm()); 296 } 297 } else { 298 req.setAttribute("WebEventAttendeeForm",attendeeForm); 300 } 301 } 302 private void _deleteAttendee(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, User user) 303 throws Exception { 304 305 WebEventRegistrationForm registrationForm = (WebEventRegistrationForm) form; 306 307 WebEventAttendeeForm attendeeForm = new WebEventAttendeeForm(); 308 attendeeForm.setEmail(registrationForm.getCurrentAttendeeEmail()); 309 attendeeForm.setFirstName(registrationForm.getCurrentAttendeeLastFirstName()); 310 attendeeForm.setLastName(registrationForm.getCurrentAttendeeLastLastName()); 311 312 List currentAttendees = registrationForm.getEventAttendees(); 313 currentAttendees.remove(attendeeForm); 314 315 req.setAttribute("WebEventAttendeeForm",new WebEventAttendeeForm()); 316 SessionMessages.add(req, "message", "message.webevent_registration.delete_attendee"); 317 318 } 319 320 private void _addEventRegistrationStep1(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, User user) 321 throws Exception { 322 323 WebEventRegistrationForm vForm = (WebEventRegistrationForm) form; 324 long eventInode = vForm.getEventInode(); 325 boolean showPastEvents = false; 326 String showPastEventsParam = req.getParameter("showPastEventsCheck"); 327 if (showPastEventsParam != null) 328 if (showPastEventsParam.equals("true")) 329 showPastEvents = true; 330 331 List events; 333 if (showPastEvents) 334 events = WebEventFactory.getAllWebEvents(); 335 else 336 events = WebEventFactory.getUpcomingWebEvents(); 337 338 339 Iterator eventsIter = events.iterator(); 340 req.setAttribute("events", eventsIter); 341 342 List locations = new ArrayList (); 344 345 if (eventInode > 0) { 346 if (showPastEvents) 347 locations = WebEventLocationFactory.getWebEventLocationsPerEvent(eventInode,"start_date"); 348 else 349 locations = WebEventLocationFactory.getUpcomingWebEventLocationsPerEvent(eventInode,"start_date"); 350 } 351 352 Iterator locationsIter = locations.iterator(); 353 List <HashMap > finalLocations = new ArrayList <HashMap >(); 354 while (locationsIter.hasNext()) { 355 WebEventLocation location = (WebEventLocation) locationsIter.next(); 356 String locationStr = location.toString(); 357 HashMap <String ,String > hs = new HashMap <String ,String >(); 358 hs.put("optionName", locationStr); 359 hs.put("optionValue", String.valueOf(location.getInode())); 360 finalLocations.add(hs); 361 } 362 req.setAttribute("locations", finalLocations.iterator()); 363 364 365 } 366 367 private Address retrieveAddress(String userID) throws Exception { 368 String companyId = com.dotmarketing.cms.factories.PublicCompanyFactory.getDefaultCompany().getCompanyId(); 369 370 Address address = null; 371 if (UtilMethods.isSet(userID)) { 372 List addresses = PublicAddressFactory.getAddressesByUserId(userID); 373 if (addresses.size() == 0) { 374 address = PublicAddressFactory.getInstance(); 375 address.setCompanyId(companyId); 376 address.setUserId(userID); 377 } else { 378 address = (Address) addresses.get(0); 379 } 380 } else { 381 address = PublicAddressFactory.getInstance(); 382 address.setCompanyId(companyId); 383 address.setUserId(userID); 384 } 385 return address; 386 } 387 388 private void _addEventRegistrationStep2(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, User user) 389 throws Exception { 390 391 WebEventRegistrationForm registrationForm = (WebEventRegistrationForm) form; 392 393 WebEventAttendeeForm attendeeForm = new WebEventAttendeeForm(); 394 attendeeForm.setEmail(registrationForm.getCurrentAttendeeEmail()); 395 396 List <WebEventAttendeeForm> currentAttendees = registrationForm.getEventAttendees(); 397 if (currentAttendees.indexOf(attendeeForm) >= 0) { 398 attendeeForm = currentAttendees.get(currentAttendees.indexOf(attendeeForm)); 399 req.setAttribute("WebEventAttendeeForm",attendeeForm); 400 } 401 402 } 403 404 private void _addEventRegistrationStep3(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, User user) 405 throws Exception { 406 WebEventRegistrationForm registrationForm = (WebEventRegistrationForm) form; 407 ActionRequestImpl reqImpl = (ActionRequestImpl)req; 409 HttpServletRequest httpReq = reqImpl.getHttpServletRequest(); 410 411 List <HashMap > paymentTypes = new ArrayList <HashMap >(); 413 String [] paymentTypesArray = Config.getStringArrayProperty("EREG_PAYMENT_TYPES"); 414 for (int i=0;i<paymentTypesArray.length;i++) { 415 String pType = paymentTypesArray[i]; 416 HashMap <String , String > hs = new HashMap <String , String >(); 417 hs.put("paymentTypeName",Config.getStringProperty(pType + "_FN")); 418 hs.put("paymentTypeValue",Config.getStringProperty(pType)); 419 paymentTypes.add(hs); 420 } 421 req.setAttribute("paymentTypes",paymentTypes.iterator()); 422 423 List <HashMap > cardTypes = new ArrayList <HashMap >(); 425 String [] cardTypesArray = Config.getStringArrayProperty("EREG_CREDIT_CARD_TYPES"); 426 427 for (int i=0;i<cardTypesArray.length;i++) { 428 String cType = cardTypesArray[i]; 429 HashMap <String , String > hs = new HashMap <String , String >(); 430 hs.put("cardTypeName",cType); 431 hs.put("cardTypeValue",cType); 432 cardTypes.add(hs); 433 } 434 435 req.setAttribute("cardTypes",cardTypes.iterator()); 436 437 List <HashMap > cardExpYears = new ArrayList <HashMap >(); 439 Calendar today = new GregorianCalendar (); 440 int thisYear = today.get(Calendar.YEAR); 441 for (int i=0;i<=10;i++) { 442 HashMap <String , String > hs = new HashMap <String , String >(); 443 hs.put("yearName",String.valueOf(thisYear)); 444 hs.put("yearValue",String.valueOf(thisYear++)); 445 cardExpYears.add(hs); 446 } 447 req.setAttribute("cardExpYears",cardExpYears.iterator()); 448 449 List <HashMap > cardExpMonths = new ArrayList <HashMap >(); 451 int thisMonth = 0; 452 DateFormatSymbols dfs = new DateFormatSymbols (); 453 String [] months = dfs.getMonths(); 454 455 for (int i=0;i<12;i++) { 456 HashMap <String , String > hs = new HashMap <String , String >(); 457 hs.put("monthName",months[thisMonth]); 458 hs.put("monthValue",String.valueOf(i+1)); 459 thisMonth++; 460 cardExpMonths.add(hs); 461 } 462 req.setAttribute("cardExpMonths",cardExpMonths.iterator()); 463 464 String companyId = com.dotmarketing.cms.factories.PublicCompanyFactory.getDefaultCompany().getCompanyId(); 466 String userId = registrationForm.getUserId(); 467 user = UserLocalManagerUtil.getUserById(companyId, userId); 468 UserProxy userProxy = UserProxyFactory.getUserProxy(user); 469 registrationForm.setUserInode(userProxy.getInode()); 470 Address address = retrieveAddress(userId); 471 registrationForm.setBillingAddress1(address.getStreet1()); 472 registrationForm.setBillingAddress2(address.getStreet2()); 473 registrationForm.setBillingCity(address.getCity()); 474 registrationForm.setBillingContactEmail(user.getEmailAddress()); 475 registrationForm.setBillingContactName(user.getFullName()); 476 registrationForm.setBillingContactPhone(address.getPhone()); 477 registrationForm.setBillingState(address.getState()); 478 registrationForm.setBillingZip(address.getZip()); 479 480 WebEvent event = WebEventFactory.getWebEvent(registrationForm.getEventInode()); 481 if (!event.isInstitute()) { 482 483 WebEventAttendeeForm attendeeForm = new WebEventAttendeeForm(); 484 attendeeForm.setEmail(user.getEmailAddress()); 485 attendeeForm.setFirstName(user.getFirstName()); 486 attendeeForm.setLastName(user.getLastName()); 487 attendeeForm.setTitle(""); 488 attendeeForm.setBadgeName(""); 489 490 WebEventLocation loc = WebEventLocationFactory.getWebEventLocation(registrationForm.getEventLocationInode()); 491 492 if (httpReq.getSession().getAttribute("isPartner") != null && httpReq.getSession().getAttribute("isPartner").equals("true")){ 494 495 Organization organization = (Organization)httpReq.getSession().getAttribute("userOrganization"); 496 if (organization.getInstitute_price() > 0) 497 attendeeForm.setRegistrationPrice(organization.getInstitute_price()); 498 else 499 attendeeForm.setRegistrationPrice(loc.getPartnerPrice()); 500 } 501 else 502 attendeeForm.setRegistrationPrice(loc.getNonPartnerPrice()); 503 504 505 List <WebEventAttendeeForm> currentAttendees = registrationForm.getEventAttendees(); 506 if (!currentAttendees.contains(attendeeForm)) { 507 currentAttendees.add(attendeeForm); 508 } 509 } 510 Organization org = (Organization) InodeFactory.getParentOfClass(userProxy, Organization.class); 511 boolean isPartner = false; 512 if (org.getInode() > 0){ 513 isPartner = ((org.getPartnerKey() != null && !org.getPartnerKey().equals("") )? true : false); 514 } 515 WebEventLocation loc = WebEventLocationFactory.getWebEventLocation(registrationForm.getEventLocationInode()); 516 List <WebEventAttendeeForm> currentAttendees = registrationForm.getEventAttendees(); 517 for (int i=0;i < currentAttendees.size();i++){ 518 WebEventAttendeeForm attendeeForm = (WebEventAttendeeForm)currentAttendees.get(i); 519 if (isPartner){ 520 if (loc.isDefaultContractPartnerPrice()){ 521 attendeeForm.setRegistrationPrice(org.getInstitute_price()); 522 } 523 else{ 524 attendeeForm.setRegistrationPrice(loc.getPartnerPrice()); 525 } 526 } 527 else 528 attendeeForm.setRegistrationPrice(loc.getNonPartnerPrice()); 529 } 530 generateToken(httpReq); 532 saveToken(httpReq); 533 } 534 535 private String _addEventRegistrationStep4(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, ActionMapping mapping, User user) 536 throws Exception { 537 538 ActionRequestImpl reqImpl = (ActionRequestImpl)req; 540 HttpServletRequest httpReq = reqImpl.getHttpServletRequest(); 541 try { 542 if (!isTokenValid(httpReq)) { 543 544 for (int i = 0; i < 120; i++) { 547 if (SessionMessages.size(req) > 0) { 548 generateToken(httpReq); 550 saveToken(httpReq); 551 return "portlet.ext.webevents_registration.add_registration.step3"; 552 } else { 553 WebEventRegistration registration = (WebEventRegistration) httpReq.getSession().getAttribute(WebKeys.WEBEVENTS_REG_BEAN); 554 if (registration != null) { 555 SessionMessages.add(req, "message", "error.web_event.registration.already.processed2"); 556 if (registration.getPaymentType() == 1) 557 return "portlet.ext.webevents_registration.add_registration.creditCardConfirmation"; 558 else 559 return "portlet.ext.webevents_registration.add_registration.checkConfirmation"; 560 } 561 Thread.sleep(1000); 562 } 563 } 564 565 SessionMessages.add(req, "message", "error.web_event.registration.already.processed"); 567 return "step1"; 568 } 569 resetToken(httpReq); 570 httpReq.getSession().removeAttribute(WebKeys.WEBEVENTS_REG_BEAN); 571 572 WebEventRegistrationForm registrationForm = (WebEventRegistrationForm) form; 573 574 if (!Validator.validate(req, registrationForm, mapping)) { 575 generateToken(httpReq); 576 saveToken(httpReq); 577 return "step3"; 578 } 579 580 DotHibernate.startTransaction(); 582 583 WebEventRegistration registration = new WebEventRegistration(); 585 BeanUtils.copyProperties(registration, registrationForm); 586 registration.setDatePosted(new Date ()); 587 registration.setLastModDate(new Date ()); 588 registration.setCardNumber(UtilMethods.obfuscateCreditCard(registrationForm.getCardNumber())); 589 registration.setCardVerificationValue(""); 590 InodeFactory.saveInode(registration); 591 592 int registrationAmount = 0; 594 List <WebEventAttendeeForm> attendeesForms = registrationForm.getEventAttendees(); 595 for (WebEventAttendeeForm attendeeForm : attendeesForms) { 596 WebEventAttendee attendee = new WebEventAttendee(); 597 BeanUtils.copyProperties(attendee, attendeeForm); 598 attendee.setEventRegistrationInode(registration.getInode()); 599 InodeFactory.saveInode(attendee); 600 registrationAmount += attendee.getRegistrationPrice(); 601 } 602 603 if (registrationForm.getPaymentType() == 1) { 604 605 try { 606 registration.setTotalDue(0); 608 registration.setTotalPaid(registrationAmount); 609 registration.setTotalRegistration(registrationAmount); 610 registration.setRegistrationStatus(Config.getIntProperty("EREG_PAID")); 611 InodeFactory.saveInode(registration); 612 613 String companyId = com.dotmarketing.cms.factories.PublicCompanyFactory.getDefaultCompany().getCompanyId(); 615 String userId = registrationForm.getUserId(); 616 user = UserLocalManagerUtil.getUserById(companyId, userId); 617 UserProxy up = UserProxyFactory.getUserProxy(userId); 618 Organization organization = (Organization) InodeFactory.getParentOfClass(up, Organization.class); 619 String organizationName = "Doesn't belong to an Organization"; 620 if (organization.getInode() > 0) { 621 organizationName = organization.getTitle(); 622 } 623 624 625 CreditCardProcessorResponse ccResponse = CreditCardProcessor.processCreditCardOrderInstitutes(registration.getInode(), 628 null, true, req.getRemoteUser(), null, null, 629 null, (float)registration.getTotalPaid(), registrationForm.getCardNumber(), 630 Integer.parseInt(registration.getCardExpMonth()), Integer.parseInt(registration.getCardExpYear()), 631 registrationForm.getCardVerificationValue(), registration.getCardName(), 632 organizationName, registration.getBillingAddress1(), registration.getBillingAddress2(), 633 registration.getBillingCity(), registration.getBillingState(), 634 registration.getBillingZip(), Config.getStringProperty("US_COUNTRY_CODE"), 635 registration.getBillingContactPhone(), null, registration.getBillingContactEmail(), 636 Config.getStringProperty("WEB_EVENT_REGISTRATION_COMMENTS"), ""); 637 638 if (!ccResponse.orderApproved()) { 639 DotHibernate.rollbackTransaction(); 640 ActionMessages ae = new ActionMessages(); 641 ae.add(Globals.ERROR_KEY, new ActionMessage( 642 "error.cc_processing.card.denied", ccResponse.getError())); 643 saveErrors(httpReq, ae); 644 generateToken(httpReq); 645 saveToken(httpReq); 646 return "step3"; 647 } 648 649 650 } catch (CreditCardProcessorException e) { 651 Logger.warn(this,"Credit card processor exception placing a credit card order: " + e.getMessage(), e); 652 DotHibernate.rollbackTransaction(); 653 switch (e.getCode()) { 654 case CreditCardProcessorException.COMMUNICATION_ERROR: 655 SessionMessages.add(req, "message", "error.cc_processing.communication.error"); 656 break; 657 case CreditCardProcessorException.DATA_MISSING: 658 SessionMessages.add(req, "message", "error.cc_processing.invalid.card.data"); 659 break; 660 default: 661 SessionMessages.add(req, "message", "error.cc_processing.unknown"); 662 } 663 generateToken(httpReq); 664 saveToken(httpReq); 665 return "step3"; 666 } catch (Exception e) { 667 Logger.error(this,"Unknown Error placing a credit card order: "+ e.getMessage(), e); 668 DotHibernate.rollbackTransaction(); 669 SessionMessages.add(req, "message", "error.cc_processing.unknown"); 670 generateToken(httpReq); 671 saveToken(httpReq); 672 return "step3"; 673 } 674 675 } else { 676 registration.setTotalDue(registrationAmount); 678 registration.setTotalPaid(0); 679 registration.setTotalRegistration(registrationAmount); 680 registration.setRegistrationStatus(Config.getIntProperty("EREG_WAITING")); 681 InodeFactory.saveInode(registration); 682 } 683 684 DotHibernate.commitTransaction(); 686 687 httpReq.getSession().setAttribute(WebKeys.WEBEVENTS_REG_BEAN, registration); 689 690 registrationForm.resetAllForm(); 692 httpReq.getSession().removeAttribute("WebEventRegistrationForm"); 693 694 try { 696 sendRegistrationReceipt(mapping, form, httpReq); 697 } catch (Exception e) { 698 Logger.warn(this,"An error ocurred triying to send the confirmation email.",e); 699 } 700 WebEvent event = WebEventFactory.getWebEvent(registration.getEventInode()); 701 if (event.isInstitute()) { 702 if (registration.getPaymentType() == 1) 703 return "portlet.ext.webevents_registration.add_registration.creditCardConfirmation"; 704 else 705 return "portlet.ext.webevents_registration.add_registration.checkConfirmation"; 706 } 707 else { 708 if (registration.getPaymentType() == 1) 709 return "portlet.ext.webevents_registration.add_registration.webinarConfirmation"; 710 else 711 return "portlet.ext.webevents_registration.add_registration.webinarCheckConfirmation"; 712 713 } 714 715 } catch (Exception e) { Logger.error(this, "Unknown Error placing an order: "+ e.getMessage(), e); 717 DotHibernate.rollbackTransaction(); 718 SessionMessages.add(req, "message", "error.cc_processing.unknown"); 719 generateToken(httpReq); 720 saveToken(httpReq); 721 return "step3"; 722 } 723 } 724 public static boolean sendRegistrationReceipt(ActionMapping mapping,ActionForm lf, HttpServletRequest request) { 725 726 WebEventRegistration registration = (WebEventRegistration) request.getSession().getAttribute(WebKeys.WEBEVENTS_REG_BEAN); 727 728 UserProxy proxy = UserProxyFactory.getUserProxy(registration.getUserInode()); 729 User user = com.dotmarketing.cms.factories.PublicUserFactory.getUserByUserId(proxy.getUserId()); 730 731 String path = ""; 732 733 WebEvent event = WebEventFactory.getWebEvent(registration.getEventInode()); 734 if (event.isInstitute()) { 735 if (registration.getPaymentType() == 1) 736 path = mapping.findForward("portlet.ext.webevents_registration.add_registration.creditCardConfirmationEmail").getPath(); 737 else 738 path = mapping.findForward("portlet.ext.webevents_registration.add_registration.checkConfirmationEmail").getPath(); 739 } else { 740 if (registration.getPaymentType() == 1) 741 path = mapping.findForward("portlet.ext.webevents_registration.add_registration.webinarConfirmationEmail").getPath(); 742 else 743 path = mapping.findForward("portlet.ext.webevents_registration.add_registration.webinarCheckConfirmationEmail").getPath(); 744 } 745 746 try { 747 StringBuffer writer = UtilMethods.getURL("http://" 748 + HostFactory.getCurrentHost(request).getHostname() + path 749 + "?registrationInode=" + registration.getInode()); 750 751 String [] reportEmails = Config.getStringArrayProperty("BCCEMAIL_REGISTRATION_ADDRESSES"); 752 753 StringBuffer bcc = new StringBuffer (); 754 for (String email : reportEmails) { 755 if (bcc.toString().length() > 0) 756 bcc.append(", "); 757 bcc.append(email); 758 } 759 760 Mailer m = new Mailer(); 761 m.setToEmail(user.getEmailAddress()); 762 m.setSubject(Config.getStringProperty("WEB_EVENT_REGISTRATION_EMAIL_TITLE")); 763 m.setHTMLBody(writer.toString().trim()); 764 m.setFromEmail(Config.getStringProperty("EMAIL_REGISTRATION_ADDRESS")); 765 m.setBcc(bcc.toString()); 766 m.sendMessage(); 767 768 return true; 769 } catch (Exception e) { 770 e.printStackTrace(System.out); 771 return false; 772 } 773 774 } 775 776 } 777 778 | Popular Tags |