function finalize_survey() { $user = JFactory::getUser(); $app = JFactory::getApplication(); $model = $this->getModel('survey'); $id = JRequest::getInt('id', 0); $itemid = CJFunctions::get_active_menu_id(); $survey = $model->get_survey_details($id, true); if ($user->authorise('core.create', S_APP_NAME . '.category.' . $survey->catid) || $user->authorise('core.manage', S_APP_NAME)) { if ($survey->published == 3) { $status = $user->authorise('core.autoapprove', S_APP_NAME . '.category.' . $survey->catid) ? 1 : 2; if (!$model->finalize_survey($id, $status)) { $error = S_DEBUG_ENABLED ? $model->getError() : ''; $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=survey&task=list' . $itemid, false), JText::_('MSG_ERROR_PROCESSING') . $error); } else { $config = JComponentHelper::getParams(S_APP_NAME); if (!$user->authorise('core.autoapprove', S_APP_NAME . '.category.' . $survey->catid)) { if ($config->get('admin_new_survey_notification', 1) == 1) { $from = $app->getCfg('mailfrom'); $fromname = $app->getCfg('fromname'); $params = JComponentHelper::getParams(S_APP_NAME); $admin_emails = $model->get_admin_emails($params->get('admin_user_groups', 8)); if (!empty($admin_emails)) { CJFunctions::send_email($from, $fromname, $admin_emails, JText::_('MSG_MAIL_PENDING_REVIEW_SUBJECT'), JText::_('MSG_MAIL_PENDING_REVIEW_BODY'), 1); } } $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=survey&task=list' . $itemid, false), JText::_('MSG_SENT_FOR_REVIEW')); } else { if ($survey->private_survey == 0) { $link = JRoute::_('index.php?option=' . S_APP_NAME . '&view=survey&task=take_survey&id=' . $survey->id . ":" . $survey->alias . $itemid); CJFunctions::stream_activity($config->get('activity_stream_type', 'none'), $user->id, array('command' => A_APP_NAME . '.new_survey', 'component' => S_APP_NAME, 'title' => JText::sprintf('TXT_CREATED_SURVEY', $link, $survey->title), 'href' => $link, 'description' => $survey->introtext, 'length' => $config->get('stream_character_limit', 256), 'icon' => 'components/' . S_APP_NAME . '/assets/images/icon-16-survey.png', 'group' => 'Surveys')); } $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=survey&task=list' . $itemid, false), JText::_('MSG_SUCCESSFULLY_SAVED')); } } } else { $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=survey&task=list' . $itemid, false), JText::_('MSG_SUCCESSFULLY_SAVED')); } } else { $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=survey' . $survey_itemid, false), JText::_('MSG_UNAUTHORIZED')); } }
private function finalize_response($survey, $response_id, $redirect = true) { $user = JFactory::getUser(); $itemid = CJFunctions::get_active_menu_id(); $model = $this->getModel('survey'); $app = JFactory::getApplication(); if ($model->finalize_response($survey->id, $response_id)) { $params = JComponentHelper::getParams(S_APP_NAME); $userdisplayname = $params->get('user_display_name', 'name'); SurveyHelper::award_points($params, $survey->created_by, 2, $response_id, JText::sprintf('TXT_RESPONDED_SURVEY', $survey->username, $survey->title)); SurveyHelper::award_points($params, $user->id, 3, $response_id, JText::sprintf('TXT_RESPONDED_SURVEY', $user->{$userdisplayname}, $survey->title)); $menuid = CJFunctions::get_active_menu_id(true, 'index.php?option=' . S_APP_NAME . '&view=survey'); $link = $survey->private_survey == 1 ? $survey->title : JHtml::link(JRoute::_('index.php?option=' . S_APP_NAME . '&view=response&task=take_survey&id=' . $survey->id . ":" . $survey->alias . $menuid), $survey->title); CJFunctions::stream_activity($params->get('activity_stream_type', 'none'), $user->id, array('command' => 'com_communitysurveys.response', 'component' => S_APP_NAME, 'title' => JText::sprintf('TXT_RESPONDED_SURVEY', '{actor}', $link), 'description' => $survey->introtext, 'length' => $params->get('stream_character_limit', 256), 'icon' => 'components/' . S_APP_NAME . '/assets/images/icon-16-surveys.png', 'group' => 'Surveys')); if ($survey->notification == 1 && $params->get('new_response_notification', 1) == 1) { $from = $app->getCfg('mailfrom'); $fromname = $app->getCfg('fromname'); $link = JRoute::_('index.php?option=' . S_APP_NAME . '&view=reports&task=dashboard&id=' . $survey->id . ':' . $survey->alias . $itemid, false, -1); $body = ''; if ($survey->anonymous == 1) { $body = JText::sprintf('EMAIL_NEW_RESPONSE_ANONYMOUS_BODY', $survey->username, $survey->title, $link, $app->getCfg('sitename')); } else { $body = JText::sprintf('EMAIL_NEW_RESPONSE_BODY', $survey->username, $user->username, $survey->title, $link, $app->getCfg('sitename')); } if ($params->get('embed_pdf_report', 1) == 1) { // All validations done, write data now require_once JPATH_COMPONENT_SITE . '/helpers/reports.php'; $generator = new SurveyReports(); $filePath = JPATH_ROOT . '/tmp/survey_' . $survey->id . '_' . date('dmYHis') . '.pdf'; $pdfData = $model->get_reponse_data_for_csv($survey->id, array($response_id), true); $generator->generatePdfReport($pdfData, 'F', $params, $filePath); CJFunctions::send_email($from, $fromname, $survey->email, JText::_('EMAIL_NEW_RESPONSE_TITLE'), $body, 1, null, null, $filePath); } else { CJFunctions::send_email($from, $fromname, $survey->email, JText::_('EMAIL_NEW_RESPONSE_TITLE'), $body, 1, null, null); } } if ($redirect) { if (empty($survey->redirect_url)) { if ($survey->public_permissions == '1' && $user->authorise('core.results', S_APP_NAME)) { $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=response&task=view_result&id=' . $survey->id . ':' . $survey->alias . '&rid=' . $response_id . $itemid, false), JText::_('MSG_SURVEY_COMPLETE')); } else { $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=response&task=end_message&id=' . $survey->id . ':' . $survey->alias . $itemid, false), JText::_('MSG_SURVEY_COMPLETE')); } } else { $this->setRedirect($survey->redirect_url, JText::_('MSG_SURVEY_COMPLETE')); } } else { return true; } } else { $msg = S_DEBUG_ENABLED ? JText::_('MSG_ERROR_PROCESSING') . $model->getError() : JText::_('MSG_ERROR_PROCESSING'); if ($redirect) { $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=survey&task=take_survey&id=' . $survey->id . $itemid, false), $msg); } else { return false; } } }