@@ -418,11 +418,11 @@ public static function displayUserReportAnswers($userId, $survey_data, $addMessa
418418 if ($ row ['type ' ] != 'pagebreak ' ) {
419419 $ questions [$ row ['sort ' ]]['question_id ' ] = $ row ['question_id ' ];
420420 $ questions [$ row ['sort ' ]]['survey_id ' ] = $ row ['survey_id ' ];
421- $ questions [$ row ['sort ' ]]['survey_question ' ] = $ row ['survey_question ' ];
421+ $ questions [$ row ['sort ' ]]['survey_question ' ] = Security:: remove_XSS ( $ row ['survey_question ' ]) ;
422422 $ questions [$ row ['sort ' ]]['display ' ] = $ row ['display ' ];
423423 $ questions [$ row ['sort ' ]]['type ' ] = $ row ['type ' ];
424424 $ questions [$ row ['sort ' ]]['maximum_score ' ] = $ row ['max_value ' ];
425- $ questions [$ row ['sort ' ]]['options ' ][$ row ['question_option_id ' ]] = $ row ['option_text ' ];
425+ $ questions [$ row ['sort ' ]]['options ' ][$ row ['question_option_id ' ]] = Security:: remove_XSS ( $ row ['option_text ' ]) ;
426426 }
427427 }
428428
@@ -615,7 +615,7 @@ public static function display_question_report($survey_data)
615615 $ row = 0 ;
616616 foreach ($ data as $ label => $ item ) {
617617 $ table ->setCellContents ($ row , 0 , $ label );
618- $ table ->setCellContents ($ row , 1 , $ item );
618+ $ table ->setCellContents ($ row , 1 , Security:: remove_XSS ( $ item) );
619619 $ row ++;
620620 }
621621
@@ -670,7 +670,7 @@ public static function display_question_report($survey_data)
670670 $ questionId = (int ) $ question ['question_id ' ];
671671
672672 echo '<div class="title-question"> ' ;
673- echo strip_tags (isset ($ question ['survey_question ' ]) ? $ question ['survey_question ' ] : null );
673+ echo Security:: remove_XSS ( strip_tags (isset ($ question ['survey_question ' ]) ? $ question ['survey_question ' ] : null ) );
674674 echo '</div> ' ;
675675
676676 if ('score ' === $ question ['type ' ]) {
@@ -729,6 +729,8 @@ public static function display_question_report($survey_data)
729729 foreach ($ options as $ option ) {
730730 $ optionText = strip_tags ($ option ['option_text ' ]);
731731 $ optionText = html_entity_decode ($ optionText );
732+ $ optionText = Security::remove_XSS ($ optionText );
733+
732734 $ votes = 0 ;
733735 if (isset ($ data [$ option ['question_option_id ' ]]['total ' ])) {
734736 $ votes = $ data [$ option ['question_option_id ' ]]['total ' ];
@@ -752,7 +754,7 @@ public static function display_question_report($survey_data)
752754
753755 // Displaying the table: the content
754756 if (is_array ($ options )) {
755- foreach ($ options as $ key => &$ value ) {
757+ foreach ($ options as &$ value ) {
756758 if ('multiplechoiceother ' === $ question ['type ' ] && 'other ' === $ value ['option_text ' ]) {
757759 $ value ['option_text ' ] = get_lang ('SurveyOtherAnswer ' );
758760 }
@@ -773,7 +775,7 @@ public static function display_question_report($survey_data)
773775 $ answers_number = $ absolute_number / $ number_of_answers [$ option ['question_id ' ]] * 100 ;
774776 }
775777 echo '<tr> ' ;
776- echo '<td> ' .$ value ['option_text ' ].'</td> ' ;
778+ echo '<td> ' .Security:: remove_XSS ( $ value ['option_text ' ]) .'</td> ' ;
777779 echo '<td> ' ;
778780 if ($ absolute_number != 0 ) {
779781 echo '<a href=" ' .api_get_path (WEB_CODE_PATH ).'survey/reporting.php?action= ' .$ action
@@ -1120,9 +1122,9 @@ class = "save"
11201122 in_array ($ row ['question_id ' ], $ _POST ['questions_filter ' ]))
11211123 ) {
11221124 // We do not show comment and pagebreak question types
1123- if ('pagebreak ' != $ row ['type ' ]) {
1125+ if ('pagebreak ' !== $ row ['type ' ]) {
11241126 $ content .= ' <th ' ;
1125- if ($ row ['number_of_options ' ] > 0 && 'percentage ' != $ row ['type ' ]) {
1127+ if ($ row ['number_of_options ' ] > 0 && 'percentage ' !== $ row ['type ' ]) {
11261128 $ content .= ' colspan=" ' .$ row ['number_of_options ' ].'" ' ;
11271129 }
11281130 $ content .= '> ' ;
@@ -1132,7 +1134,7 @@ class = "save"
11321134 type="checkbox"
11331135 name="questions_filter[]" value=" ' .$ row ['question_id ' ].'" checked="checked"/> ' ;
11341136 }
1135- $ content .= $ row ['survey_question ' ];
1137+ $ content .= Security:: remove_XSS ( $ row ['survey_question ' ]) ;
11361138 $ content .= '</label> ' ;
11371139 $ content .= '</th> ' ;
11381140 }
@@ -1189,7 +1191,7 @@ class = "save"
11891191 (is_array ($ _POST ['questions_filter ' ]) && in_array ($ row ['question_id ' ], $ _POST ['questions_filter ' ]))
11901192 ) {
11911193 // we do not show comment and pagebreak question types
1192- if ('open ' == $ row ['type ' ] || 'comment ' == $ row ['type ' ]) {
1194+ if ('open ' === $ row ['type ' ] || 'comment ' = == $ row ['type ' ]) {
11931195 $ content .= '<th> - </th> ' ;
11941196 $ possible_answers [$ row ['question_id ' ]][$ row ['question_option_id ' ]] = $ row ['question_option_id ' ];
11951197 $ display_percentage_header = 1 ;
@@ -1201,7 +1203,7 @@ class = "save"
12011203 $ possible_answers [$ row ['question_id ' ]][$ row ['question_option_id ' ]] = $ row ['question_option_id ' ];
12021204 } elseif ($ row ['type ' ] !== 'pagebreak ' && $ row ['type ' ] !== 'percentage ' ) {
12031205 $ content .= '<th> ' ;
1204- $ content .= $ row ['option_text ' ];
1206+ $ content .= Security:: remove_XSS ( $ row ['option_text ' ]) ;
12051207 $ content .= '</th> ' ;
12061208 $ possible_answers [$ row ['question_id ' ]][$ row ['question_option_id ' ]] = $ row ['question_option_id ' ];
12071209 $ display_percentage_header = 1 ;
@@ -2116,7 +2118,7 @@ public static function display_comparative_report()
21162118 $ optionsX = ['---- ' ];
21172119 $ optionsY = ['---- ' ];
21182120 $ defaults = [];
2119- foreach ($ questions as $ key => &$ question ) {
2121+ foreach ($ questions as &$ question ) {
21202122 // Ignored tagged questions
21212123 if ($ question ) {
21222124 if (strpos ($ question ['question ' ], '{{ ' ) !== false ) {
@@ -2133,6 +2135,7 @@ public static function display_comparative_report()
21332135 if (isset ($ _GET ['yaxis ' ]) && $ _GET ['yaxis ' ] == $ question ['question_id ' ]) {
21342136 $ defaults ['yaxis ' ] = $ question ['question_id ' ];
21352137 }
2138+ $ question ['question ' ] = Security::remove_XSS ($ question ['question ' ]);
21362139
21372140 $ optionsX [$ question ['question_id ' ]] = api_substr (strip_tags ($ question ['question ' ]), 0 , 90 );
21382141 $ optionsY [$ question ['question_id ' ]] = api_substr (strip_tags ($ question ['question ' ]), 0 , 90 );
@@ -2171,16 +2174,17 @@ public static function display_comparative_report()
21712174 if ($ ii == 0 ) {
21722175 $ tableHtml .= '<th> </th> ' ;
21732176 } else {
2174- if ($ question_x ['type ' ] == 'score ' ) {
2177+ if ($ question_x ['type ' ] === 'score ' ) {
21752178 for ($ x = 1 ; $ x <= $ question_x ['maximum_score ' ]; $ x ++) {
2176- $ tableHtml .= '<th> ' .$ question_x ['answers ' ][($ ii - 1 )].'<br /> ' .$ x .'</th> ' ;
2179+ $ tableHtml .= '<th> ' .Security:: remove_XSS ( $ question_x ['answers ' ][($ ii - 1 )]) .'<br /> ' .$ x .'</th> ' ;
21772180 }
21782181 $ x = '' ;
21792182 } else {
2180- $ tableHtml .= '<th> ' .$ question_x ['answers ' ][($ ii - 1 )].'</th> ' ;
2183+ $ tableHtml .= '<th> ' .Security:: remove_XSS ( $ question_x ['answers ' ][($ ii - 1 )]) .'</th> ' ;
21812184 }
21822185 $ optionText = strip_tags ($ question_x ['answers ' ][$ ii - 1 ]);
21832186 $ optionText = html_entity_decode ($ optionText );
2187+ $ optionText = Security::remove_XSS ($ optionText );
21842188 array_push ($ xOptions , trim ($ optionText ));
21852189 }
21862190 }
@@ -2198,7 +2202,7 @@ public static function display_comparative_report()
21982202 if ($ question_x ['type ' ] == 'score ' ) {
21992203 for ($ x = 1 ; $ x <= $ question_x ['maximum_score ' ]; $ x ++) {
22002204 if ($ ii == 0 ) {
2201- $ tableHtml .= '<th> ' .$ question_y ['answers ' ][($ ij )].' ' .$ y .'</th> ' ;
2205+ $ tableHtml .= '<th> ' .Security:: remove_XSS ( $ question_y ['answers ' ][($ ij )]) .' ' .$ y .'</th> ' ;
22022206 break ;
22032207 } else {
22042208 $ tableHtml .= '<td align="center"> ' ;
@@ -2224,7 +2228,7 @@ public static function display_comparative_report()
22242228 }
22252229 } else {
22262230 if ($ ii == 0 ) {
2227- $ tableHtml .= '<th> ' .$ question_y ['answers ' ][$ ij ].' ' .$ y .'</th> ' ;
2231+ $ tableHtml .= '<th> ' .Security:: remove_XSS ( $ question_y ['answers ' ][$ ij ]) .' ' .$ y .'</th> ' ;
22282232 } else {
22292233 $ tableHtml .= '<td align="center"> ' ;
22302234 $ votes = self ::comparative_check (
@@ -2257,7 +2261,7 @@ public static function display_comparative_report()
22572261 if ($ question_x ['type ' ] === 'score ' ) {
22582262 for ($ x = 1 ; $ x <= $ question_x ['maximum_score ' ]; $ x ++) {
22592263 if ($ ii == 0 ) {
2260- $ tableHtml .= '<th> ' .$ question_y ['answers ' ][$ ij ].'</th> ' ;
2264+ $ tableHtml .= '<th> ' .Security:: remove_XSS ( $ question_y ['answers ' ][$ ij ]) .'</th> ' ;
22612265 break ;
22622266 } else {
22632267 $ tableHtml .= '<td align="center"> ' ;
@@ -2283,7 +2287,7 @@ public static function display_comparative_report()
22832287 }
22842288 } else {
22852289 if ($ ii == 0 ) {
2286- $ tableHtml .= '<th> ' .$ question_y ['answers ' ][($ ij )].'</th> ' ;
2290+ $ tableHtml .= '<th> ' .Security:: remove_XSS ( $ question_y ['answers ' ][($ ij )]) .'</th> ' ;
22872291 } else {
22882292 $ tableHtml .= '<td align="center"> ' ;
22892293 $ votes = self ::comparative_check (
0 commit comments