Fix survey's reported issues - refs BT#9068

1.10.x
Imanol Losada 10 years ago
parent 7892141e0d
commit ff966ceb46
  1. 3
      main/inc/lib/javascript/dimple.v2.1.2.min.js
  2. 2
      main/survey/create_new_survey.php
  3. 2
      main/survey/fillsurvey.php
  4. 2
      main/survey/reporting.php
  5. 121
      main/survey/survey.lib.php

File diff suppressed because one or more lines are too long

@ -149,7 +149,7 @@ $form->addElement('date_picker', 'end_date', get_lang('EndDate'));
$form->addElement('checkbox', 'anonymous', null, get_lang('Anonymous')); $form->addElement('checkbox', 'anonymous', null, get_lang('Anonymous'));
$visibleResults = array( $visibleResults = array(
SURVEY_VISIBLE_TUTOR => get_lang('Coach'), SURVEY_VISIBLE_TUTOR => get_lang('Coach'),
SURVEY_VISIBLE_TUTOR_STUDENT => get_lang('Coach').' '.get_lang('And').' '.get_lang('Student'), SURVEY_VISIBLE_TUTOR_STUDENT => get_lang('CoachAndStudent'),
SURVEY_VISIBLE_PUBLIC => get_lang('Everyone') SURVEY_VISIBLE_PUBLIC => get_lang('Everyone')
); );
$form->addElement('select', 'visible_results', get_lang('ResultsVisibility'), $visibleResults); $form->addElement('select', 'visible_results', get_lang('ResultsVisibility'), $visibleResults);

@ -338,7 +338,7 @@ if (!isset($_GET['show'])) {
$paged_questions_sec = array(); $paged_questions_sec = array();
if (!empty($survey_data['survey_introduction'])) { if (!empty($survey_data['survey_introduction'])) {
echo '<div id="survey_content" class="survey_content">'.strip_tags($survey_data['survey_introduction']).'</div>'; echo '<div id="survey_content" class="survey_content">'.$survey_data['survey_introduction'].'</div>';
} }
$limit = 0; $limit = 0;
} }

@ -17,7 +17,7 @@ $language_file = 'survey';
require_once '../inc/global.inc.php'; require_once '../inc/global.inc.php';
require_once 'survey.lib.php'; require_once 'survey.lib.php';
$this_section = SECTION_COURSES; $this_section = SECTION_COURSES;
$cidReq = Security::remove_XSS(api_get_cidreq()); $cidReq = api_get_cidreq();
$survey_id = intval($_GET['survey_id']); $survey_id = intval($_GET['survey_id']);
$survey_data = survey_manager::get_survey($survey_id); $survey_data = survey_manager::get_survey($survey_id);

@ -2897,7 +2897,6 @@ class SurveyUtil
* @todo the pagebreak and comment question types should not be shown => removed from $survey_data before * @todo the pagebreak and comment question types should not be shown => removed from $survey_data before
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version February 2007 - Updated March 2008 * @version February 2007 - Updated March 2008
* @CSS Alex Aragon <alex.aragon@beeznest.com> - update January 2015
*/ */
public static function display_question_report($survey_data) public static function display_question_report($survey_data)
{ {
@ -2909,11 +2908,13 @@ class SurveyUtil
// Determining the offset of the sql statement (the n-th question of the survey) // Determining the offset of the sql statement (the n-th question of the survey)
$offset = !isset($_GET['question']) ? 0 : intval($_GET['question']); $offset = !isset($_GET['question']) ? 0 : intval($_GET['question']);
$currentQuestion = isset($_GET['question']) ? $_GET['question'] : 0; $currentQuestion = isset($_GET['question']) ? intval($_GET['question']) : 0;
$question = array(); $question = array();
$surveyId = intval($_GET['survey_id']);
$action = Security::remove_XSS($_GET['action']);
echo '<div class="actions">'; echo '<div class="actions">';
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?survey_id='.Security::remove_XSS($_GET['survey_id']).'">'. echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?survey_id='.$surveyId.'">'.
Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('ReportingOverview'),'',ICON_SIZE_MEDIUM).'</a>'; Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('ReportingOverview'),'',ICON_SIZE_MEDIUM).'</a>';
echo '</div>'; echo '</div>';
@ -2922,12 +2923,12 @@ class SurveyUtil
/* echo '<ul><li class="disabled"><a href="#">'.get_lang('Question').'</a></li>'; */ /* echo '<ul><li class="disabled"><a href="#">'.get_lang('Question').'</a></li>'; */
if ($currentQuestion != 0 ) { if ($currentQuestion != 0 ) {
echo '<li><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action='.Security::remove_XSS($_GET['action']).'&amp;'.api_get_cidreq().'&amp;survey_id='.Security::remove_XSS($_GET['survey_id']).'&amp;question='.Security::remove_XSS($offset-1).'">'.get_lang('PreviousQuestion').'</a></li>'; echo '<li><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action='.$action.'&amp;'.api_get_cidreq().'&amp;survey_id='.$surveyId.'&amp;question='.($offset-1).'">'.get_lang('PreviousQuestion').'</a></li>';
} }
for ($i = 1; $i <= $survey_data['number_of_questions']; $i++) { for ($i = 1; $i <= $survey_data['number_of_questions']; $i++) {
if ($offset != $i - 1) { if ($offset != $i - 1) {
echo '<li><a href="' . api_get_path(WEB_CODE_PATH) . 'survey/reporting.php?action=' . Security::remove_XSS($_GET['action']) . '&amp;' . api_get_cidreq() . '&amp;survey_id=' . Security::remove_XSS($_GET['survey_id']) . '&amp;question=' . ($i - 1) . '">' . $i . '</a></li>'; echo '<li><a href="' . api_get_path(WEB_CODE_PATH) . 'survey/reporting.php?action=' . $action . '&amp;' . api_get_cidreq() . '&amp;survey_id=' . $surveyId . '&amp;question=' . ($i - 1) . '">' . $i . '</a></li>';
} else { } else {
echo '<li class="disabled"s><a href="#">' . $i . '</a></li>'; echo '<li class="disabled"s><a href="#">' . $i . '</a></li>';
} }
@ -2936,7 +2937,7 @@ class SurveyUtil
}*/ }*/
} }
if ($currentQuestion < ($survey_data['number_of_questions'] - 1)) { if ($currentQuestion < ($survey_data['number_of_questions'] - 1)) {
echo '<li><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action='.Security::remove_XSS($_GET['action']).'&amp;'.api_get_cidreq().'&amp;survey_id='.Security::remove_XSS($_GET['survey_id']).'&amp;question='.Security::remove_XSS($offset+1).'">'.get_lang('NextQuestion').'</li></a>'; echo '<li><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action='.$action.'&amp;'.api_get_cidreq().'&amp;survey_id='.$surveyId.'&amp;question='.($offset+1).'">'.get_lang('NextQuestion').'</li></a>';
} }
echo '</ul>'; echo '</ul>';
echo '</div>'; echo '</div>';
@ -3019,7 +3020,9 @@ class SurveyUtil
} }
array_push($chartData, array('option' => $optionText, 'votes' => $votes)); array_push($chartData, array('option' => $optionText, 'votes' => $votes));
} }
self::drawChart($chartData); echo '<div id="chartContainer" class="span12">';
echo self::drawChart($chartData);
echo '</div>';
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/jquery.fcbkcomplete.js" type="text/javascript" language="javascript"></script>'; $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/jquery.fcbkcomplete.js" type="text/javascript" language="javascript"></script>';
@ -3052,7 +3055,7 @@ class SurveyUtil
echo ' <td class="center">'.$value['option_text'].'</td>'; echo ' <td class="center">'.$value['option_text'].'</td>';
echo ' <td class="center">'; echo ' <td class="center">';
if ($absolute_number!=0){ if ($absolute_number!=0){
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action='.Security::remove_XSS($_GET['action']).'&amp;survey_id='.Security::remove_XSS($_GET['survey_id']).'&amp;question='.Security::remove_XSS($offset).'&amp;viewoption='.$value['question_option_id'].'">'.$absolute_number.'</a>'; echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action='.$action.'&amp;survey_id='.$surveyId.'&amp;question='.$offset.'&amp;viewoption='.$value['question_option_id'].'">'.$absolute_number.'</a>';
}else{ }else{
echo '0'; echo '0';
} }
@ -3064,7 +3067,7 @@ class SurveyUtil
if ($size > 0) { if ($size > 0) {
echo '<div style="border:1px solid #264269; background-color:#aecaf4; height:10px; width:'.$size.'px">&nbsp;</div>'; echo '<div style="border:1px solid #264269; background-color:#aecaf4; height:10px; width:'.$size.'px">&nbsp;</div>';
}else{ }else{
echo '<div style="text-align: left;">'.get_lang("NoDataRegistered").'</div>'; echo '<div style="text-align: left;">'.get_lang("NoDataAvailable").'</div>';
} }
echo ' </td>'; echo ' </td>';
echo ' </tr>'; echo ' </tr>';
@ -3096,7 +3099,7 @@ class SurveyUtil
echo '<ul>'; echo '<ul>';
while ($row = Database::fetch_array($result)) { while ($row = Database::fetch_array($result)) {
$user_info = api_get_user_info($row['user']); $user_info = api_get_user_info($row['user']);
echo '<li><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=userreport&survey_id='.Security::remove_XSS($_GET['survey_id']).'&user='.$row['user'].'">'.$user_info['complete_name'].'</a></li>'; echo '<li><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=userreport&survey_id='.$surveyId.'&user='.$row['user'].'">'.$user_info['complete_name'].'</a></li>';
} }
echo '</ul>'; echo '</ul>';
echo '</div>'; echo '</div>';
@ -3163,7 +3166,9 @@ class SurveyUtil
); );
} }
} }
self::drawChart($chartData, true); echo '<div id="chartContainer" class="span12">';
echo self::drawChart($chartData, true);
echo '</div>';
// Displaying the table: headers // Displaying the table: headers
echo '<table class="data_table">'; echo '<table class="data_table">';
@ -3181,7 +3186,7 @@ class SurveyUtil
echo ' <tr>'; echo ' <tr>';
echo ' <td>'.$value['option_text'].'</td>'; echo ' <td>'.$value['option_text'].'</td>';
echo ' <td>'.$i.'</td>'; echo ' <td>'.$i.'</td>';
echo ' <td><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action='.Security::remove_XSS($_GET['action']).'&amp;survey_id='.Security::remove_XSS($_GET['survey_id']).'&amp;question='.Security::remove_XSS($offset).'&amp;viewoption='.$value['question_option_id'].'&amp;value='.$i.'">'.$absolute_number.'</a></td>'; echo ' <td><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action='.$action.'&amp;survey_id='.Security::remove_XSS($_GET['survey_id']).'&amp;question='.Security::remove_XSS($offset).'&amp;viewoption='.$value['question_option_id'].'&amp;value='.$i.'">'.$absolute_number.'</a></td>';
echo ' <td>'.round($absolute_number/$number_of_answers*100, 2).' %</td>'; echo ' <td>'.round($absolute_number/$number_of_answers*100, 2).' %</td>';
echo ' <td>'; echo ' <td>';
$size = ($absolute_number/$number_of_answers*100*2); $size = ($absolute_number/$number_of_answers*100*2);
@ -4100,7 +4105,9 @@ class SurveyUtil
} }
} }
$tableHtml .= '</table>'; $tableHtml .= '</table>';
self::drawChart($chartData, true); echo '<div id="chartContainer" class="span12">';
echo self::drawChart($chartData, true);
echo '</div>';
echo $tableHtml; echo $tableHtml;
} }
} }
@ -5330,55 +5337,59 @@ class SurveyUtil
* @param boolean Tells if the chart has a serie. False by default * @param boolean Tells if the chart has a serie. False by default
* @return void (direct output) * @return void (direct output)
*/ */
static function drawChart($chartData, $hasSerie = false) public static function drawChart($chartData, $hasSerie = false)
{ {
$htmlChart = '<div id="chartContainer" class="span12">'. $htmlChart = '';
api_get_js("d3/d3.v3.4.8.js").' if (api_browser_support("svg")) {
<script src="http://dimplejs.org/dist/dimple.v2.1.0.min.js"></script> $htmlChart .= api_get_js("d3/d3.v3.4.8.js");
$htmlChart .= api_get_js("dimple.v2.1.2.min.js") . '
<script type="text/javascript"> <script type="text/javascript">
var svg = dimple.newSvg("#chartContainer", "100%", 400); var svg = dimple.newSvg("#chartContainer", "100%", 400);
var data = ['; var data = [';
$serie = array(); $serie = array();
$order = array(); $order = array();
foreach ($chartData as $chartDataElement) { foreach ($chartData as $chartDataElement) {
$htmlChart .= '{"'; $htmlChart .= '{"';
if (!$hasSerie) {
$htmlChart .= get_lang("Option") . '":"' . $chartDataElement['option'] . '", "';
array_push($order, $chartDataElement['option']);
} else {
if (!is_array($chartDataElement['serie'])) {
$htmlChart .= get_lang("Option") . '":"' . $chartDataElement['serie'] . '", "' .
get_lang("Score") . '":"' . $chartDataElement['option'] . '", "';
array_push($serie, $chartDataElement['serie']);
} else {
$htmlChart .= get_lang("Serie") . '":"' . $chartDataElement['serie'][0] . '", "' .
get_lang("Option") . '":"' . $chartDataElement['serie'][1] . '", "' .
get_lang("Score") . '":"' . $chartDataElement['option'] . '", "';
}
}
$htmlChart .= get_lang("Votes") . '":"' . $chartDataElement['votes'] .
'"},';
}
rtrim($htmlChart, ",");
$htmlChart .= '];
var myChart = new dimple.chart(svg, data);
myChart.addMeasureAxis("y", "' . get_lang("Votes") . '");';
if (!$hasSerie) { if (!$hasSerie) {
$htmlChart .= get_lang("Option") . '":"' . $chartDataElement['option'] . '", "'; $htmlChart .= 'var xAxisCategory = myChart.addCategoryAxis("x", "' . get_lang("Option") . '");
array_push($order, $chartDataElement['option']); xAxisCategory.addOrderRule(' . json_encode($order) . ');
} else if (!is_array($chartDataElement['serie'])) { myChart.addSeries("' . get_lang("Option") . '", dimple.plot.bar);';
$htmlChart .= get_lang("Option") . '":"' . $chartDataElement['serie'] . '", "' .
get_lang("Score") . '":"' . $chartDataElement['option'] . '", "';
array_push($serie, $chartDataElement['serie']);
} else { } else {
$htmlChart .= get_lang("Serie") . '":"' . $chartDataElement['serie'][0] . '", "' . if (!is_array($chartDataElement['serie'])) {
get_lang("Option") . '":"' . $chartDataElement['serie'][1] . '", "' . $serie = array_values(array_unique($serie));
get_lang("Score") . '":"' . $chartDataElement['option'] . '", "'; $htmlChart .= 'var xAxisCategory = myChart.addCategoryAxis("x", ["' . get_lang("Option") . '","' . get_lang("Score") . '"]);
xAxisCategory.addOrderRule(' . json_encode($serie) . ');
xAxisCategory.addGroupOrderRule("' . get_lang("Score") . '");
myChart.addSeries("' . get_lang("Option") . '", dimple.plot.bar);';
} else {
$htmlChart .= 'myChart.addCategoryAxis("x", ["' . get_lang("Option") . '","' . get_lang("Score") . '"]);
myChart.addSeries("' . get_lang("Serie") . '", dimple.plot.bar);';
}
} }
$htmlChart .= get_lang("Votes") . '":"' . $chartDataElement['votes'] . $htmlChart .= 'myChart.draw();
'"},'; </script>';
}
rtrim($htmlChart, ",");
$htmlChart .= '];
var myChart = new dimple.chart(svg, data);
myChart.addMeasureAxis("y", "'.get_lang("Votes").'");';
if (!$hasSerie) {
$htmlChart .= 'var xAxisCategory = myChart.addCategoryAxis("x", "'.get_lang("Option").'");';
$htmlChart .= 'xAxisCategory.addOrderRule('.json_encode($order).');';
$htmlChart .= 'myChart.addSeries("'.get_lang("Option").'", dimple.plot.bar);';
} else if (!is_array($chartDataElement['serie'])) {
$serie = array_values(array_unique($serie));
$htmlChart .= 'var xAxisCategory = myChart.addCategoryAxis("x", ["'.get_lang("Option").'","'.get_lang("Score").'"]);';
$htmlChart .= 'xAxisCategory.addOrderRule('.json_encode($serie).');';
$htmlChart .= 'xAxisCategory.addGroupOrderRule("'.get_lang("Score").'");';
$htmlChart .= 'myChart.addSeries("'.get_lang("Option").'", dimple.plot.bar);';
} else {
$htmlChart .= 'myChart.addCategoryAxis("x", ["'.get_lang("Option").'","'.get_lang("Score").'"]);';
$htmlChart .= 'myChart.addSeries("'.get_lang("Serie").'", dimple.plot.bar);';
} }
$htmlChart .= 'myChart.draw(); return $htmlChart;
</script>
</div>';
echo $htmlChart;
} }
} }

Loading…
Cancel
Save