private function send_invitations($sid, $contacts, $remaining = 0) { if (!empty($contacts)) { $app = JFactory::getApplication(); $user = JFactory::getUser(); $model = JModelLegacy::getInstance('survey', 'CommunitySurveysModel'); $params = JComponentHelper::getParams(S_APP_NAME); $itemid = CJFunctions::get_active_menu_id(true, 'index.php?option=' . S_APP_NAME . '&view=surveys'); $editor = $user->authorise('core.wysiwyg', S_APP_NAME) ? $params->get('default_editor', 'bbcode') : 'none'; $subject = $app->input->getString('invitation-subject', JText::_('TXT_INVITE_DEFAULT_SUB')); $default_body = $editor == 'wysiwyg' ? str_replace("\n", '<br>', JText::_('TXT_INVITE_DEFAULT_BODY')) : JText::_('TXT_INVITE_DEFAULT_BODY'); $body = CJFunctions::get_clean_var('invitation-body', true, $default_body); $body = CJFunctions::process_html($body, $editor == 'bbcode'); $messageid = $app->input->getInt('messageid', 0); $count = count($contacts); $keys = $model->create_survey_keys($sid, $count); $survey = $model->get_survey_details($sid, 0, false, false, false); if (!empty($keys) && count($keys) > 0) { $emails = array(); foreach ($keys as $i => $key) { $link = str_replace('/administrator/', '/', JRoute::_('index.php?option=' . S_APP_NAME . '&view=response&task=take_survey&key=' . $key . $itemid, false, -1)); $link = '<a href="' . $link . '">' . CjFunctions::escape($survey->title) . '</a>'; $email = new stdClass(); $email->name = $contacts[$i]->name; $email->subid = 0; $email->link = $link; $email->email = $contacts[$i]->email; $emails[] = $email; $contacts[$i]->key = $key; $i++; } $template = $params->get('mail-tpl-newanswer', 'mail-blue.tpl'); $sent = $model->add_messages_to_queue($sid, $subject, $body, $emails, $template, $messageid); $model->update_key_userids($sid, $contacts); if ($sent === false) { echo json_encode(array('error' => JText::_('MSG_ERROR_PROCESSING') . (S_DEBUG_ENABLED ? $model->getError() : ''))); } else { echo json_encode(array('message' => JText::sprintf('MSG_INVITATIONS_ADDED_TO_QUEUE', $sent), 'remaining' => $remaining)); } } else { echo json_encode(array('error' => JText::_('MSG_NO_CREDITS') . (S_DEBUG_ENABLED ? $model->getError() : ''))); } } else { echo json_encode(array('error' => JText::_('MSG_NO_CONTACTS_SELECTED'))); } }