* @subpackage Components.site * @copyright Copyright (C) 2009 - 2012 corejoomla.com, Inc. All rights reserved. * @author Maverick * @link http://www.corejoomla.com/ * @license License GNU General Public License version 2 or later */ defined('_JEXEC') or die; $page_id = 7; $user = JFactory::getUser(); $itemid = CJFunctions::get_active_menu_id(); CJFunctions::load_jquery(array('libs' => array('form'))); $wysiwyg = $user->authorise('core.wysiwyg', S_APP_NAME) ? true : false; $bbcode = $wysiwyg && $this->params->get('default_editor', 'bbcode') == 'bbcode'; $content = $this->params->get('process_content_plugins', 0) == 1; require_once JPATH_COMPONENT . '/helpers/reports.php'; $generator = new SurveyReports($wysiwyg, $bbcode, $content); $doc = JFactory::getDocument(); $doc->addScript('https://www.google.com/jsapi'); $doc->addCustomTag('<script type="text/javascript">google.load("visualization", "1", {packages:["corechart"]}); google.setOnLoadCallback(SurveyFactory.draw_consolidated_charts);</script>'); ?> <div id="cj-wrapper" class="container-fuild"> <?php include_once JPATH_COMPONENT . DS . 'helpers' . DS . 'header.php'; ?> <?php if (!$this->print) { ?> <div class="well">
function download_pdf_report() { $itemid = CJFunctions::get_active_menu_id(); $user = JFactory::getUser(); $app = JFactory::getApplication(); $surveyId = $app->input->getInt('id', 0); $params = JComponentHelper::getParams(S_APP_NAME); if ($user->guest) { $redirect_url = base64_encode(JRoute::_('index.php?option=' . S_APP_NAME . '&view=reports&task=dashboard&id=' . $surveyId . $itemid)); $this->setRedirect(CJFunctions::get_login_url($redirect_url, $itemid), JText::_('MSG_NOT_LOGGED_IN')); return; } if (!$user->authorise('core.create', S_APP_NAME) && !$user->authorise('core.manage', S_APP_NAME)) { $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=survey' . $itemid), JText::_('MSG_UNAUTHORIZED')); return; } if (!$surveyId) { $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=survey' . $itemid), JText::_('MSG_UNAUTHORIZED')); return; } $cids = $app->input->post->getArray(array('cid' => 'array')); JArrayHelper::toInteger($cids['cid']); if (empty($cids['cid'])) { $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=reports&task=responses&id=' . $surveyId . $itemid, false), JText::_('MSG_SELECT_ITEMS_TO_CONTINUE')); return; } $model = $this->getModel('survey'); $pdfData = $model->get_reponse_data_for_csv($surveyId, $cids['cid']); if (empty($pdfData)) { $this->setRedirect(JRoute::_('index.php?option=' . S_APP_NAME . '&view=reports&task=dashboard&id=' . $surveyId . $itemid), JText::_('MSG_ERROR_PROCESSING') . $model->getError()); return; } // All validations done, write data now require_once JPATH_COMPONENT_SITE . '/helpers/reports.php'; $generator = new SurveyReports(); $fileName = 'survey_' . $surveyId . '_' . date('dmYHis') . '.pdf'; $generator->generatePdfReport($pdfData, 'D', $params, $fileName); jexit(); }
public function download_consolidated_pdf_report() { $user = JFactory::getUser(); $app = JFactory::getApplication(); $model = $this->getModel('survey'); $params = JComponentHelper::getParams(S_APP_NAME); $id = $app->input->getInt('id', 0); if (!$id || !$model->authorize_survey($id)) { CJFunctions::throw_error(JText::_('MSG_UNAUTHORIZED'), 401); } else { $wysiwyg = $user->authorise('core.wysiwyg', S_APP_NAME) ? true : false; $bbcode = $wysiwyg && $params->get('default_editor', 'bbcode') == 'bbcode'; $content = $params->get('process_content_plugins', 0) == 1; require_once JPATH_COMPONENT . '/helpers/reports.php'; $generator = new SurveyReports($wysiwyg, $bbcode, $content); $survey = $model->get_consolidated_report($id); $headStyles = array(); $headStyles[] = CJLIB_URI . '/bootstrap/css/bootstrap.min.css'; $headStyles[] = JURI::root(true) . '/media/' . S_APP_NAME . '/css/cj.surveys.min.css'; $headScripts = array(); $headScripts[] = CJLIB_URI . '/jquery/jquery.min.js'; $headScripts[] = CJLIB_URI . '/jquery/jquery.noconflict.js'; $headScripts[] = CJLIB_URI . '/bootstrap/js/bootstrap.min.js'; $headScripts[] = 'https://www.google.com/jsapi'; $headScripts[] = JURI::root(true) . '/media/' . S_APP_NAME . '/js/cj.surveys.min.js'; $html = '<html xmlns="http://www.w3.org/1999/xhtml" dir="' . JFactory::getDocument()->direction . '"><head>'; $html = $html . '<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta http-equiv="content-type" content="text/html; charset=utf-8" />'; // foreach ($headStyles as $style) // { // $html = $html . '<link rel="stylesheet" href="'.$style.'" type="text/css" />'; // } // foreach ($headScripts as $script) // { // $html = $html . '<script src="'.$script.'" type="text/javascript"></script>'; // } // $html .= '<script type="text/javascript">google.load("visualization", "1", {packages:["corechart"]}); google.setOnLoadCallback(SurveyFactory.draw_consolidated_charts);</script>'; $html .= '</head><body><div id="cj-wrapper" class="container-fuild"><div class="reports-wrapper margin-top-20">'; $html .= '<h2 class="page-header margin-bottom-10">' . CJFunctions::escape($survey->title) . '</h2>'; foreach ($survey->questions as $item) { switch ($item->question_type) { case 1: $html .= $generator->get_page_header_question($item, ''); break; case 2: case 3: case 4: case 11: case 12: $html .= $generator->get_choice_question($item, ''); break; case 5: case 6: $html .= $generator->get_grid_question($item, ''); break; } } $html .= '</div></div></body></html>'; // All validations done, write data now $fileName = 'survey_' . $id . '_' . date('dmYHis') . '.pdf'; // create new PDF document require_once JPATH_COMPONENT_SITE . '/helpers/tcpdf.php'; $pdf = new MYPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set default header data $pdf->SetHeaderData('logo.png', PDF_HEADER_LOGO_WIDTH, $survey->title, ''); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('corejoomla.com'); $pdf->SetTitle('Survey Report'); $pdf->SetSubject('Consolidated Report'); $pdf->SetKeywords('survey, report'); // set header and footer fonts $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); //set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // --------------------------------------------------------- // set font $pdf->SetFont('freesans'); $pdf->AddPage(); $pdf->writeHTML($html, true, false, true, false, ''); $pdf->lastPage(); $pdf->Output($fileName, $mode); jexit(); } }
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; } } }