/** * This function displays the comparative report which allows you to compare two questions * A comparative report creates a table where one question is on the x axis and a second question is on the y axis. * In the intersection is the number of people who have answerd positive on both options. * * @return string HTML code * * @author Patrick Cool <*****@*****.**>, Ghent University * @version February 2007 */ public static function display_comparative_report() { // Allowed question types for comparative report $allowed_question_types = array('yesno', 'multiplechoice', 'multipleresponse', 'dropdown', 'percentage', 'score'); // Getting all the questions $questions = SurveyManager::get_questions($_GET['survey_id']); // Actions bar echo '<div class="actions">'; echo '<a href="' . api_get_path(WEB_CODE_PATH) . 'survey/reporting.php?survey_id=' . intval($_GET['survey_id']) . '&' . api_get_cidreq() . '">' . Display::return_icon('back.png', get_lang('BackTo') . ' ' . get_lang('ReportingOverview'), '', ICON_SIZE_MEDIUM) . '</a>'; echo '</div>'; // Displaying an information message that only the questions with predefined answers can be used in a comparative report Display::display_normal_message(get_lang('OnlyQuestionsWithPredefinedAnswers'), false); // The form for selecting the axis of the table echo '<form id="form1" name="form1" method="get" action="' . api_get_self() . '?action=' . Security::remove_XSS($_GET['action']) . '&survey_id=' . intval($_GET['survey_id']) . '&xaxis=' . Security::remove_XSS($_GET['xaxis']) . '&y=' . Security::remove_XSS($_GET['yaxis']) . '">'; // Survey_id echo '<input type="hidden" name="action" value="' . Security::remove_XSS($_GET['action']) . '"/>'; echo '<input type="hidden" name="survey_id" value="' . intval($_GET['survey_id']) . '"/>'; // X axis echo get_lang('SelectXAxis') . ': '; echo '<select name="xaxis">'; echo '<option value="">---</option>'; foreach ($questions as $key => &$question) { if (is_array($allowed_question_types)) { if (in_array($question['type'], $allowed_question_types)) { echo '<option value="' . $question['question_id'] . '"'; if (isset($_GET['xaxis']) && $_GET['xaxis'] == $question['question_id']) { echo ' selected="selected"'; } echo '">' . api_substr(strip_tags($question['question']), 0, 50) . '</option>'; } } } echo '</select><br /><br />'; // Y axis echo get_lang('SelectYAxis') . ': '; echo '<select name="yaxis">'; echo '<option value="">---</option>'; foreach ($questions as $key => &$question) { if (in_array($question['type'], $allowed_question_types)) { echo '<option value="' . $question['question_id'] . '"'; if (isset($_GET['yaxis']) && $_GET['yaxis'] == $question['question_id']) { echo ' selected="selected"'; } echo '">' . api_substr(strip_tags($question['question']), 0, 50) . '</option>'; } } echo '</select><br /><br />'; echo '<button class="save" type="submit" name="Submit" value="Submit">' . get_lang('CompareQuestions') . '</button>'; echo '</form>'; // Getting all the information of the x axis if (isset($_GET['xaxis']) && is_numeric($_GET['xaxis'])) { $question_x = SurveyManager::get_question($_GET['xaxis']); } // Getting all the information of the y axis if (isset($_GET['yaxis']) && is_numeric($_GET['yaxis'])) { $question_y = SurveyManager::get_question($_GET['yaxis']); } if (isset($_GET['xaxis']) && is_numeric($_GET['xaxis']) && isset($_GET['yaxis']) && is_numeric($_GET['yaxis'])) { // Getting the answers of the two questions $answers_x = SurveyUtil::get_answers_of_question_by_user($_GET['survey_id'], $_GET['xaxis']); $answers_y = SurveyUtil::get_answers_of_question_by_user($_GET['survey_id'], $_GET['yaxis']); // Displaying the table $tableHtml = '<table border="1" class="data_table">'; $xOptions = array(); // The header $tableHtml .= ' <tr>'; for ($ii = 0; $ii <= count($question_x['answers']); $ii++) { if ($ii == 0) { $tableHtml .= ' <th> </th>'; } else { if ($question_x['type'] == 'score') { for ($x = 1; $x <= $question_x['maximum_score']; $x++) { $tableHtml .= ' <th>' . $question_x['answers'][$ii - 1] . '<br />' . $x . '</th>'; } $x = ''; } else { $tableHtml .= ' <th>' . $question_x['answers'][$ii - 1] . '</th>'; } $optionText = strip_tags($question_x['answers'][$ii - 1]); $optionText = html_entity_decode($optionText); array_push($xOptions, trim($optionText)); } } $tableHtml .= ' </tr>'; $chartData = array(); // The main part for ($ij = 0; $ij < count($question_y['answers']); $ij++) { $currentYQuestion = strip_tags($question_y['answers'][$ij]); $currentYQuestion = html_entity_decode($currentYQuestion); // The Y axis is a scoring question type so we have more rows than the options (actually options * maximum score) if ($question_y['type'] == 'score') { for ($y = 1; $y <= $question_y['maximum_score']; $y++) { $tableHtml .= ' <tr>'; for ($ii = 0; $ii <= count($question_x['answers']); $ii++) { if ($question_x['type'] == 'score') { for ($x = 1; $x <= $question_x['maximum_score']; $x++) { if ($ii == 0) { $tableHtml .= ' <th>' . $question_y['answers'][$ij] . ' ' . $y . '</th>'; break; } else { $tableHtml .= ' <td align="center">'; $votes = SurveyUtil::comparative_check($answers_x, $answers_y, $question_x['answersid'][$ii - 1], $question_y['answersid'][$ij], $x, $y); $tableHtml .= $votes; array_push($chartData, array('serie' => array($currentYQuestion, $xOptions[$ii - 1]), 'option' => $x, 'votes' => $votes)); $tableHtml .= '</td>'; } } } else { if ($ii == 0) { $tableHtml .= '<th>' . $question_y['answers'][$ij] . ' ' . $y . '</th>'; } else { $tableHtml .= '<td align="center">'; $votes = SurveyUtil::comparative_check($answers_x, $answers_y, $question_x['answersid'][$ii - 1], $question_y['answersid'][$ij], 0, $y); $tableHtml .= $votes; array_push($chartData, array('serie' => array($currentYQuestion, $xOptions[$ii - 1]), 'option' => $y, 'votes' => $votes)); $tableHtml .= '</td>'; } } } $tableHtml .= ' </tr>'; } } else { $tableHtml .= ' <tr>'; for ($ii = 0; $ii <= count($question_x['answers']); $ii++) { if ($question_x['type'] == 'score') { for ($x = 1; $x <= $question_x['maximum_score']; $x++) { if ($ii == 0) { $tableHtml .= ' <th>' . $question_y['answers'][$ij] . '</th>'; break; } else { $tableHtml .= ' <td align="center">'; $votes = SurveyUtil::comparative_check($answers_x, $answers_y, $question_x['answersid'][$ii - 1], $question_y['answersid'][$ij], $x, 0); $tableHtml .= $votes; array_push($chartData, array('serie' => array($currentYQuestion, $xOptions[$ii - 1]), 'option' => $x, 'votes' => $votes)); $tableHtml .= '</td>'; } } } else { if ($ii == 0) { $tableHtml .= ' <th>' . $question_y['answers'][$ij] . '</th>'; } else { $tableHtml .= ' <td align="center">'; $votes = SurveyUtil::comparative_check($answers_x, $answers_y, $question_x['answersid'][$ii - 1], $question_y['answersid'][$ij]); $tableHtml .= $votes; array_push($chartData, array('serie' => $xOptions[$ii - 1], 'option' => $currentYQuestion, 'votes' => $votes)); $tableHtml .= '</td>'; } } } $tableHtml .= ' </tr>'; } } $tableHtml .= '</table>'; echo '<div id="chartContainer" class="col-md-12">'; echo self::drawChart($chartData, true); echo '</div>'; echo $tableHtml; } }
if ($_GET['type'] == 'yesno') { $formData['answers'][0] = get_lang('Yes'); $formData['answers'][1] = get_lang('No'); } if ($_GET['type'] == 'personality') { $formData['answers'][0] = 1; $formData['answers'][1] = 2; $formData['answers'][2] = 3; $formData['answers'][3] = 4; $formData['answers'][4] = 5; $formData['values'][0] = 0; $formData['values'][1] = 0; $formData['values'][2] = 1; $formData['values'][3] = 2; $formData['values'][4] = 3; } // We are editing a question if (isset($_GET['question_id']) && !empty($_GET['question_id'])) { $formData = SurveyManager::get_question($_GET['question_id']); } $formData = $surveyQuestion->preSave($formData); $surveyQuestion->createForm($surveyData, $formData); $surveyQuestion->getForm()->setDefaults($formData); $surveyQuestion->renderForm(); if ($surveyQuestion->getForm()->validate()) { $values = $surveyQuestion->getForm()->getSubmitValues(); $surveyQuestion->save($surveyData, $values); } Display::display_header($tool_name, 'Survey'); echo $surveyQuestion->getForm()->returnForm(); Display::display_footer();