</h2> <div class="reports-wrapper margin-top-20"> <?php $class = ''; foreach ($this->item->questions as $item) { switch ($item->question_type) { case 1: echo $generator->get_page_header_question($item, $class); break; case 2: case 3: case 4: case 11: case 12: echo $generator->get_choice_question($item, $class); break; case 5: case 6: echo $generator->get_grid_question($item, $class); break; case 7: case 8: case 9: case 10: if (!$this->print) { echo $generator->get_text_question($item, $class); } break; } }
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(); } }