Пример #1
0
		$form_content['answers'][0] = 1;
		$form_content['answers'][1] = 2;
		$form_content['answers'][2] = 3;
		$form_content['answers'][3] = 4;
		$form_content['answers'][4] = 5;

		$form_content['values'][0] = 0;
		$form_content['values'][1] = 0;
		$form_content['values'][2] = 1;
		$form_content['values'][3] = 2;
		$form_content['values'][4] = 3;
	}

	// We are editing a question
	if (isset($_GET['question_id']) && !empty($_GET['question_id'])) {
		$form_content = survey_manager::get_question($_GET['question_id']);
	}

	// An action has been performed (for instance adding a possible answer, moving an answer, ...)
	if ($_POST) {
		$form_content = $_POST;
		$form_content = $form->handle_action(
            $survey_data,
            $form_content
        );
	}

	if ($error_message != '') {
		$form_content['question'] = $_SESSION['temp_user_message'];
		$form_content['answers'] = $_SESSION['temp_answers'];
		$form_content['values'] = $_SESSION['temp_values'];
Пример #2
0
 /**
  * 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
  */
 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 = survey_manager::get_questions($_GET['survey_id']);
     // Actions bar
     echo '<div class="actions">';
     echo '<a href="reporting.php?survey_id=' . Security::remove_XSS($_GET['survey_id']) . '">' . 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=' . Security::remove_XSS($_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="' . Security::remove_XSS($_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['xaxis']) && $_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 = survey_manager::get_question($_GET['xaxis']);
     }
     // Getting all the information of the y axis
     if (isset($_GET['yaxis']) && is_numeric($_GET['yaxis'])) {
         $question_y = survey_manager::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
         echo '<table border="1" class="data_table">';
         // The header
         echo '	<tr>';
         for ($ii = 0; $ii <= count($question_x['answers']); $ii++) {
             if ($ii == 0) {
                 echo '		<th>&nbsp;</th>';
             } else {
                 if ($question_x['type'] == 'score') {
                     for ($x = 1; $x <= $question_x['maximum_score']; $x++) {
                         echo '		<th>' . $question_x['answers'][$ii - 1] . '<br />' . $x . '</th>';
                     }
                     $x = '';
                 } else {
                     echo '		<th>' . $question_x['answers'][$ii - 1] . '</th>';
                 }
             }
         }
         echo '	</tr>';
         // The main part
         for ($ij = 0; $ij < count($question_y['answers']); $ij++) {
             // 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++) {
                     echo '	<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) {
                                     echo '		<th>' . $question_y['answers'][$ij] . ' ' . $y . '</th>';
                                     break;
                                 } else {
                                     echo '		<td align="center">';
                                     echo SurveyUtil::comparative_check($answers_x, $answers_y, $question_x['answersid'][$ii - 1], $question_y['answersid'][$ij], $x, $y);
                                     echo '</td>';
                                 }
                             }
                         } else {
                             if ($ii == 0) {
                                 echo '		<th>' . $question_y['answers'][$ij] . ' ' . $y . '</th>';
                             } else {
                                 echo '		<td align="center">';
                                 echo SurveyUtil::comparative_check($answers_x, $answers_y, $question_x['answersid'][$ii - 1], $question_y['answersid'][$ij], 0, $y);
                                 echo '</td>';
                             }
                         }
                     }
                     echo '	</tr>';
                 }
             } else {
                 echo '	<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) {
                                 echo '		<th>' . $question_y['answers'][$ij] . '</th>';
                                 break;
                             } else {
                                 echo '		<td align="center">';
                                 echo SurveyUtil::comparative_check($answers_x, $answers_y, $question_x['answersid'][$ii - 1], $question_y['answersid'][$ij], $x, 0);
                                 echo '</td>';
                             }
                         }
                     } else {
                         if ($ii == 0) {
                             echo '		<th>' . $question_y['answers'][$ij] . '</th>';
                         } else {
                             echo '		<td align="center">';
                             echo SurveyUtil::comparative_check($answers_x, $answers_y, $question_x['answersid'][$ii - 1], $question_y['answersid'][$ij]);
                             echo '</td>';
                         }
                     }
                 }
                 echo '	</tr>';
             }
         }
         echo '</table>';
     }
 }