/** * Start exporting by evaluating $_GET variables * @since 1.0.0 */ function export() { global $wpdb, $questions_global; if (array_key_exists('export_survey_results', $_GET) && is_array($_GET)) { $export_type = $_GET['export_survey_results']; $survey_id = $_GET['survey_id']; $survey = new Questions_Form($survey_id); $responses = new Questions_Responses($survey_id); $export_filename = sanitize_title($survey->title); $export_data = $responses->get_responses(); $content = $this->get_csv($export_data); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", FALSE); switch ($export_type) { case 'CSV': $content = $this->get_csv($export_data); $bytes = strlen($content); $charset = 'UTF-8'; header("Content-Length: " . $bytes); header("Content-Type: text/html; charset=" . $charset); header("Content-Disposition: attachment; filename=\"" . $export_filename . ".csv\";"); echo $content; break; default: echo $this->get_csv($export_data); break; } exit; } }
/** * Showing all results of a survey * @param $atts * @return string|void */ public static function survey_results($atts) { $atts = shortcode_atts(array('id' => ''), $atts); if ('' == $atts['id']) { _e('Please enter a survey id in the survey shortcode!', 'questions-locale'); return; } $responses = new Questions_Responses($atts['id']); $ordered_data = Questions_AbstractData::order_for_charting($responses->get_responses(FALSE, FALSE)); $html = ''; $count_bars = 0; foreach ($ordered_data['questions'] as $question_id => $question) { if (!array_key_exists($question_id, $ordered_data['data'])) { continue; } $html .= Questions_ChartCreator_Dimple::show_bars($question, $ordered_data['data'][$question_id]); $count_bars++; } if (0 == $count_bars) { _e('There are no results to show.', 'questions-locale'); } return $html; }