/** * Returns a reference to the global User object, only creating it if it * doesn't already exist. * * * @param int $form_id the form to use - Can be an integer or string - If string, it is converted to ID automatically. * * @return RedFormCore The object. * * @since 1.5 */ public static function &getInstance($form_id = 0) { static $instances; if (!isset($instances)) { $instances = array(); } if (empty($instances[$form_id])) { $inst = new RedFormCore(); $inst->setFormId($form_id); $instances[$form_id] = $inst; } return $instances[$form_id]; }
/** * send email to submitter on payment received */ function _notifySubmitter() { $mainframe =& JFactory::getApplication(); $mailer =& JFactory::getMailer(); $mailer->From = $mainframe->getCfg('mailfrom'); $mailer->FromName = $mainframe->getCfg('sitename'); $mailer->AddReplyTo(array($mainframe->getCfg('mailfrom'), $mainframe->getCfg('sitename'))); $mailer->IsHTML(true); $form = $this->getForm(); // set the email subject $subject = empty($form->submitterpaymentnotificationsubject) ? JText::_('COM_REDFORM_PAYMENT_SUBMITTER_NOTIFICATION_EMAIL_SUBJECT_DEFAULT') : $form->submitterpaymentnotificationsubject; $body = empty($form->submitterpaymentnotificationbody) ? JText::_('COM_REDFORM_PAYMENT_SUBMITTER_NOTIFICATION_EMAIL_SUBJECT_DEFAULT') : $form->submitterpaymentnotificationbody; $mailer->setSubject(JText::sprintf($subject, $form->formname)); $link = JRoute::_(JURI::root() . 'administrator/index.php?option=com_redform&view=submitters&form_id=' . $form->id); $mailer->setBody(JText::sprintf($body, $form->formname, $link)); $core = new RedFormCore(); $emails = $core->getSubmissionContactEmail($this->_submit_key); if (!$emails) { return false; } foreach ((array) $emails as $sid) { foreach ((array) $sid as $email) { $mailer->addRecipient($email['email']); } } if (!$mailer->send()) { return false; } return true; }
function getEmails($cids = null) { $where = array('r.xref = ' . $this->_xref); if (is_array($cids) && !empty($cids)) { $where[] = ' r.id IN (' . implode(',', $cids) . ')'; } else { $where[] = ' r.confirmed = 1 '; } // need to get sids for redform core $query = ' SELECT r.sid ' . ' FROM #__redevent_register AS r ' . ' INNER JOIN #__rwf_submitters AS s ON s.id = r.sid ' . ' WHERE ' . implode(' AND ', $where); $this->_db->setQuery($query); $sids = $this->_db->loadResultArray(); if (empty($sids)) { return false; } $rfcore = new RedFormCore(); $answers = $rfcore->getSidsFieldsAnswers($sids); $emails = array(); foreach ($answers as $fields) { $res = array(); foreach ($fields as $field) { switch ($field->fieldtype) { case 'username': $res['username'] = $field->answer; break; case 'fullname': $res['fullname'] = $field->answer; break; case 'email': $res['email'] = $field->answer; break; } } if (!isset($res['email'])) { JError::raiseWarning(0, JText::_('COM_REDEVENT_EMAIL_ATTENDEES_NO_EMAIL_FIELD')); return false; } if ((!isset($res['fullname']) || empty($res['fullname'])) && isset($res['username'])) { $res['fullname'] = $res['username']; } $emails[] = $res; } // echo '<pre>';print_r($emails); echo '</pre>';exit; return $emails; }
/** * send email to form maintaineers or/and selected recipients * @param array $allanswers */ function notifymaintainer($allanswers, $new = true) { $mainframe =& JFactory::getApplication(); $params = JComponentHelper::getParams('com_redform'); $form = $this->getForm(); /* Inform contact person if need */ // form recipients $recipients = $allanswers[0]->getRecipients(); $cond_recipients = RedFormCore::getConditionalRecipients($form, $allanswers[0]); if ($cond_recipients) { foreach ($cond_recipients as $c) { $recipients[] = $c[0]; } } if ($form->contactpersoninform || !empty($recipients)) { // init mailer $mailer =& JFactory::getMailer(); $mailer->isHTML(true); if ($form->contactpersoninform) { if (strstr($form->contactpersonemail, ';')) { $addresses = explode(";", $form->contactpersonemail); } else { $addresses = explode(",", $form->contactpersonemail); } foreach ($addresses as $a) { $a = trim($a); if (JMailHelper::isEmailAddress($a)) { $mailer->addRecipient($a); } } } if (!empty($recipients)) { foreach ($recipients as $r) { $mailer->addRecipient($r); } } if (!empty($xref_group_recipients)) { foreach ($xref_group_recipients as $r) { $mailer->addRecipient($r); } } // we put the submitter as the email 'from' and reply to. $user =& JFactory::getUser(); if ($params->get('allow_email_aliasing', 1)) { if ($user->get('id')) { $sender = array($user->email, $user->name); } else { if ($allanswers[0]->getSubmitterEmails()) { if ($allanswers[0]->getFullname()) { $sender = array(reset($allanswers[0]->getSubmitterEmails()), $allanswers[0]->getFullname()); } else { $sender = array(reset($allanswers[0]->getSubmitterEmails()), null); } } else { // default to site settings $sender = array($mainframe->getCfg('mailfrom'), $mainframe->getCfg('sitename')); } } } else { // default to site settings $sender = array($mainframe->getCfg('mailfrom'), $mainframe->getCfg('sitename')); } $mailer->setSender($sender); $mailer->addReplyTo($sender); // set the email subject if ($new) { $mailer->setSubject(str_replace('[formname]', $form->formname, JText::_('COM_REDFORM_CONTACT_NOTIFICATION_EMAIL_SUBJECT'))); } else { $mailer->setSubject(str_replace('[formname]', $form->formname, JText::_('COM_REDFORM_CONTACT_NOTIFICATION_UPDATE_EMAIL_SUBJECT'))); } // Mail body $htmlmsg = '<html><head><title></title></title></head><body>'; if ($new) { $htmlmsg .= JText::sprintf('COM_REDFORM_MAINTAINER_NOTIFICATION_EMAIL_BODY', $form->formname); } else { $htmlmsg .= JText::sprintf('COM_REDFORM_MAINTAINER_NOTIFICATION_UPDATE_EMAIL_BODY', $form->formname); } /* Add user submitted data if set */ if ($form->contactpersonfullpost) { foreach ($allanswers as $answers) { $rows = $answers->getAnswers(); $patterns[0] = '/\\r\\n/'; $patterns[1] = '/\\r/'; $patterns[2] = '/\\n/'; $replacements[2] = '<br />'; $replacements[1] = '<br />'; $replacements[0] = '<br />'; $htmlmsg .= '<br /><table border="1">'; foreach ($rows as $key => $answer) { switch ($answer['type']) { case 'recipients': break; case 'email': $htmlmsg .= '<tr><td>' . $answer['field'] . '</td><td>'; $htmlmsg .= '<a href="mailto:' . $answer['value'] . '">' . $answer['value'] . '</a>'; $htmlmsg .= ' '; $htmlmsg .= '</td></tr>' . "\n"; break; case 'text': $userinput = preg_replace($patterns, $replacements, $answer['value']); $htmlmsg .= '<tr><td>' . $answer['field'] . '</td><td>'; if (strpos($answer['value'], 'http://') === 0) { $htmlmsg .= '<a href="' . $answer['value'] . '">' . $answer['value'] . '</a>'; } else { $htmlmsg .= $answer['value']; } $htmlmsg .= ' '; $htmlmsg .= '</td></tr>' . "\n"; break; case 'file': $userinput = preg_replace($patterns, $replacements, $answer['value']); $htmlmsg .= '<tr><td>' . $answer['field'] . '</td><td>'; $htmlmsg .= $answer['value'] && file_exists($answer['value']) ? basename($answer['value']) : ''; $htmlmsg .= '</td></tr>' . "\n"; // attach to mail if ($answer['value'] && file_exists($answer['value'])) { $mailer->addAttachment($answer['value']); } break; default: $userinput = preg_replace($patterns, $replacements, $answer['value']); $htmlmsg .= '<tr><td>' . $answer['field'] . '</td><td>'; $htmlmsg .= str_replace('~~~', '<br />', $userinput); $htmlmsg .= ' '; $htmlmsg .= '</td></tr>' . "\n"; break; } } if ($p = $answers->getPrice()) { $htmlmsg .= '<tr><td>' . JText::_('COM_REDFORM_TOTAL_PRICE') . '</td><td>'; $htmlmsg .= $p; $htmlmsg .= '</td></tr>' . "\n"; } $htmlmsg .= "</table><br />"; } } $htmlmsg .= '</body></html>'; $mailer->setBody($htmlmsg); // send the mail if (!$mailer->Send()) { RedformHelperLog::simpleLog(JText::_('COM_REDFORM_NO_MAIL_SEND') . ' (contactpersoninform): ' . $mailer->error); } } }
/** * return array of attendees emails indexed by sid * * @param int $xref * @param int $include_wl include waiting list * @return array */ function getAttendeesEmails($xref, $include_wl) { $query = ' SELECT r.sid ' . ' FROM #__redevent_register AS r ' . ' WHERE r.xref = ' . $xref . ' AND r.confirmed = 1 ' . ($include_wl == 0 ? ' AND r.waitinglist = 0 ' : '') . ' AND r.cancelled = 0 '; $this->_db->setQuery($query); $res = $this->_db->loadResultArray(); if (!count($res)) { return false; } $emails = array(); $rfcore = new RedFormCore(); $answers = $rfcore->getSidsFieldsAnswers($res); foreach ($answers as $sid => $a) { foreach ($a as $field) { if ($field->fieldtype == 'email') { $emails[$sid] = $field->answer; break; } } } return $emails; }
/** * Send e-mail confirmations */ public function sendNotificationEmail() { $mainframe = JFactory::getApplication(); $eventsettings = $this->getSessionDetails(); /** * Send a submission mail to the attendee and/or contact person * This will only work if the contact person has an e-mail address **/ if (isset($eventsettings->notify) && $eventsettings->notify) { /* Load the mailer */ $mailer = JFactory::getMailer(); $mailer->isHTML(true); $mailer->From = $mainframe->getCfg('mailfrom'); $mailer->FromName = $mainframe->getCfg('sitename'); $mailer->AddReplyTo(array($mainframe->getCfg('mailfrom'), $mainframe->getCfg('sitename'))); $tags = new redEVENT_tags(); $tags->setXref($this->getXref()); $tags->addOptions(array('sids' => array($this->load()->sid))); $rfcore = new RedFormCore(); $emails = $rfcore->getSidContactEmails($this->load()->sid); /* build activation link */ // TODO: use the route helper ! $url = JRoute::_(JURI::root() . 'index.php?option=com_redevent&controller=registration&task=activate' . '&confirmid=' . str_replace(".", "_", $this->_data->uip) . 'x' . $this->_data->xref . 'x' . $this->_data->uid . 'x' . $this->_data->id . 'x' . $this->_data->submit_key); $activatelink = '<a href="' . $url . '">' . JText::_('COM_REDEVENT_Activate') . '</a>'; $cancellink = JRoute::_(JURI::root() . 'index.php?option=com_redevent&task=cancelreg' . '&rid=' . $this->_data->id . '&xref=' . $this->_data->xref . '&submit_key=' . $this->_data->submit_key); /* Mail attendee */ $htmlmsg = '<html><head><title></title></title></head><body>'; $htmlmsg .= $eventsettings->notify_body; $htmlmsg .= '</body></html>'; $htmlmsg = $tags->ReplaceTags($htmlmsg); $htmlmsg = str_replace('[activatelink]', $activatelink, $htmlmsg); $htmlmsg = str_replace('[cancellink]', $cancellink, $htmlmsg); $htmlmsg = str_replace('[fullname]', $this->getFullname(), $htmlmsg); // convert urls $htmlmsg = REOutput::ImgRelAbs($htmlmsg); $mailer->setBody($htmlmsg); $subject = $tags->ReplaceTags($eventsettings->notify_subject); $mailer->setSubject($subject); foreach ($emails as $email) { /* Add the email address */ $mailer->AddAddress($email['email'], $email['fullname']); } /* send */ if (!$mailer->Send()) { RedeventHelperLog::simpleLog('Error sending notify message to submitted attendants'); return false; } } return true; }
/** * Method to get the registered users * * @access public * @return object * @since 0.9 * @todo Complete CB integration */ function getRegisters($form_id, $events = null, $category_id = 0, $venue_id = 0, $state_filter = 0, $filter_attending = 0) { // first, get all submissions $query = ' SELECT e.title, e.course_code, x.id as xref, x.dates, v.venue, ' . ' r.*, r.waitinglist, r.confirmed, r.confirmdate, r.submit_key, u.name, pg.name as pricegroup ' . ' FROM #__redevent_register AS r ' . ' INNER JOIN #__rwf_submitters AS s ON s.id = r.sid ' . ' INNER JOIN #__redevent_event_venue_xref AS x ON x.id = r.xref ' . ' INNER JOIN #__redevent_events AS e ON e.id = x.eventid ' . ' INNER JOIN #__redevent_event_category_xref AS xcat ON xcat.event_id = e.id ' . ' INNER JOIN #__redevent_venues AS v ON v.id = x.venueid ' . ' LEFT JOIN #__redevent_pricegroups AS pg ON pg.id = r.pricegroup_id ' . ' LEFT JOIN #__users AS u ON r.uid = u.id '; $where = array(); $where[] = ' r.confirmed = 1 '; $where[] = ' r.cancelled = 0 '; $where[] = ' s.form_id = ' . $form_id; if ($events && count($events)) { $where[] = 'e.id in (' . implode(',', $events) . ')'; } if ($category_id) { $where[] = ' xcat.category_id = ' . $category_id; } if ($venue_id) { $where[] = ' x.venueid = ' . $venue_id; } switch ($state_filter) { case 0: $where[] = ' x.published = 1 '; break; case 1: $where[] = ' x.published = -1 '; break; case 2: $where[] = ' x.published <> 0 '; break; } switch ($filter_attending) { case 1: $where[] = ' r.waitinglist = 0 '; break; case 2: $where[] = ' r.waitinglist = 1 '; break; } $query .= ' WHERE ' . implode(' AND ', $where); $query .= ' GROUP BY r.id '; $query .= ' ORDER BY e.title, x.dates '; $this->_db->setQuery($query); $submitters = $this->_db->loadObjectList(); // get answers $sids = array(); if (count($submitters)) { foreach ($submitters as $s) { $sids[] = $s->sid; } } $rfcore = new RedFormCore(); $answers = $rfcore->getSidsAnswers($sids); // add answers to registers foreach ($submitters as $k => $s) { if (isset($answers[$s->sid])) { $submitters[$k]->answers = $answers[$s->sid]; } else { $submitters[$k]->answers = null; } } return $submitters; }
function save() { $form_id = JRequest::getVar('form_id', 0); $xref = JRequest::getVar('xref', 0); $integration = JRequest::getVar('integration', ''); $rfcore = new RedFormCore(); $res = $rfcore->saveAnswers($integration); if ($res) { $msg = JText::_('COM_REDFORM_Submission_updated'); $type = 'message'; } else { $msg = JText::_('COM_REDFORM_Submission_update_failed'); $type = 'error'; } $url = 'index.php?option=com_redform&controller=submitters&task=submitters'; if ($form_id) { $url .= '&form_id=' . $form_id; } if ($integration) { $url .= '&integration=' . $integration; } if ($xref) { $url .= '&xref=' . $xref; } $this->setRedirect($url, $msg, $type); }
/** * Confirms the users request */ function activate() { $mainframe =& JFactory::getApplication(); $msgtype = 'message'; /* Get the confirm ID */ $confirmid = JRequest::getVar('confirmid', '', 'get'); /* Get the details out of the confirmid */ list($uip, $xref, $uid, $register_id, $submit_key) = explode("x", $confirmid); /* Confirm sign up via mail */ $model = $this->getModel('Registration', 'RedEventModel'); $model->setXref($xref); $eventdata = $model->getSessionDetails(); /* This loads the tags replacer */ JRequest::setVar('xref', $xref); require_once JPATH_COMPONENT_SITE . DS . 'helpers' . DS . 'tags.php'; $tags = new redEVENT_tags(); $tags->setXref($xref); $tags->setSubmitkey($submit_key); /* Check the db if this entry exists */ $db = JFactory::getDBO(); $q = ' SELECT r.confirmed ' . ' FROM #__redevent_register r ' . ' WHERE r.uid = ' . $db->Quote($uid) . ' AND r.submit_key = ' . $db->Quote($submit_key) . ' AND r.xref = ' . $db->Quote($xref) . ' AND r.id = ' . $db->Quote($register_id); $db->setQuery($q); $regdata = $db->loadObject(); if ($regdata && $regdata->confirmed == 0) { $model->confirm($register_id); // send activation confirmation email if activated if ($eventdata->enable_activation_confirmation) { $this->_Mailer(); $rfcore = new RedFormCore(); $addresses = $rfcore->getSubmissionContactEmail($submit_key); /* Check if there are any addresses to be mailed */ if (count($addresses) > 0) { /* Start mailing */ foreach ($addresses as $key => $sid) { foreach ($sid as $email) { /* Send a off mailinglist mail to the submitter if set */ /* Add the email address */ $this->mailer->AddAddress($email['email']); /* Mail submitter */ $htmlmsg = '<html><head><title></title></title></head><body>' . $tags->ReplaceTags($eventdata->notify_confirm_body) . '</body></html>'; // convert urls $htmlmsg = REOutput::ImgRelAbs($htmlmsg); $this->mailer->setBody($htmlmsg); $this->mailer->setSubject($tags->ReplaceTags($eventdata->notify_confirm_subject)); /* Send the mail */ if (!$this->mailer->Send()) { $mainframe->enqueueMessage(JText::_('COM_REDEVENT_THERE_WAS_A_PROBLEM_SENDING_MAIL')); RedeventHelperLog::simpleLog('Error sending confirm email' . ': ' . $this->mailer->error); } /* Clear the mail details */ $this->mailer->ClearAddresses(); } } } } $msg = JText::_('COM_REDEVENT_REGISTRATION_ACTIVATION_SUCCESSFULL'); } else { if ($regdata && $regdata->confirmed == 1) { $msg = JText::_('COM_REDEVENT_YOUR_SUBMISSION_HAS_ALREADY_BEEN_CONFIRMED'); $msgtype = 'error'; } else { $msg = JText::_('COM_REDEVENT_YOUR_SUBMISSION_CANNOT_BE_CONFIRMED'); $msgtype = 'error'; } } $this->setRedirect(JRoute::_(RedeventHelperRoute::getDetailsRoute($eventdata->did, $xref)), $msg, $msgtype); }