Added a validation for the foreach in group with the tests CT#191

skala
Arthur Portugal 16 years ago
parent 01c0043d7e
commit abace4f499
  1. 174
      main/survey/survey.lib.php

@ -1686,23 +1686,26 @@ class yesno extends question
*/ */
function render_question($form_content, $answers=array()) function render_question($form_content, $answers=array())
{ {
foreach ($form_content['options'] as $key=>$value)
{ if (is_array($form_content['options'])) { // check if data is correct
$this->html .= '<label><input name="question'.$form_content['question_id'].'" type="radio" value="'.$key.'"'; foreach ($form_content['options'] as $key=>$value)
if (is_array($answers))
{ {
if (in_array($key,$answers)) $this->html .= '<label><input name="question'.$form_content['question_id'].'" type="radio" value="'.$key.'"';
if (is_array($answers))
{ {
$this->html .= 'checked="checked"'; if (in_array($key,$answers))
{
$this->html .= 'checked="checked"';
}
} }
} if (substr_count($value,"<p>")==1) {
if (substr_count($value,"<p>")==1) { $this->html .= '/>'.substr($value,3,(strlen($value)-7)).'</label>';
$this->html .= '/>'.substr($value,3,(strlen($value)-7)).'</label>'; if ($form_content['display'] == 'vertical') {
if ($form_content['display'] == 'vertical') { $this->html .= '<br />';
$this->html .= '<br />'; }
} else {
$this->html .= '/>'.$value.'</label>';
} }
} else {
$this->html .= '/>'.$value.'</label>';
} }
} }
echo '<div class="survey_question_wrapper">'; echo '<div class="survey_question_wrapper">';
@ -1755,24 +1758,26 @@ class multiplechoice extends question
$this->html .= ' </div>'; $this->html .= ' </div>';
$this->html .= ' <div class="formw">'; $this->html .= ' <div class="formw">';
$total_number_of_answers = count($form_content['answers']); $total_number_of_answers = count($form_content['answers']);
$this->html .= ' <table>'; $this->html .= ' <table>';
foreach ($form_content['answers'] as $key=>$value) { if (is_array($form_content['answers'])) { // check if data is correct
$this->html .= ' <tr>'; foreach ($form_content['answers'] as $key=>$value) {
$this->html .= ' <td align="right"><label for="answers['.$key.']">'.($key+1).'</label></td>'; $this->html .= ' <tr>';
//$this->html .= ' <td><input type="text" name="answers['.$key.']" id="answers['.$key.']" value="'.$form_content['answers'][$key].'" /></td>'; $this->html .= ' <td align="right"><label for="answers['.$key.']">'.($key+1).'</label></td>';
$this->html .= ' <td width="550">'.api_return_html_area('answers['.$key.']', api_html_entity_decode(stripslashes($form_content['answers'][$key]), ENT_QUOTES, $charset), '', '', null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120')).'</td>'; //$this->html .= ' <td><input type="text" name="answers['.$key.']" id="answers['.$key.']" value="'.$form_content['answers'][$key].'" /></td>';
$this->html .= ' <td>'; $this->html .= ' <td width="550">'.api_return_html_area('answers['.$key.']', api_html_entity_decode(stripslashes($form_content['answers'][$key]), ENT_QUOTES, $charset), '', '', null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120')).'</td>';
if ($key<$total_number_of_answers-1) { $this->html .= ' <td>';
$this->html .= ' <input type="image" src="../img/down.gif" value="move_down['.$key.']" name="move_down['.$key.']"/>'; if ($key<$total_number_of_answers-1) {
} $this->html .= ' <input type="image" src="../img/down.gif" value="move_down['.$key.']" name="move_down['.$key.']"/>';
if ($key>0) { }
$this->html .= ' <input type="image" src="../img/up.gif" value="move_up['.$key.']" name="move_up['.$key.']"/>'; if ($key>0) {
} $this->html .= ' <input type="image" src="../img/up.gif" value="move_up['.$key.']" name="move_up['.$key.']"/>';
if ($total_number_of_answers> 2) { }
$this->html .= ' <input type="image" src="../img/delete.gif" value="delete_answer['.$key.']" name="delete_answer['.$key.']"/>'; if ($total_number_of_answers> 2) {
$this->html .= ' <input type="image" src="../img/delete.gif" value="delete_answer['.$key.']" name="delete_answer['.$key.']"/>';
}
$this->html .= ' </td>';
$this->html .= ' </tr>';
} }
$this->html .= ' </td>';
$this->html .= ' </tr>';
} }
// The buttons for adding or removing // The buttons for adding or removing
$this->html .= ' </table>'; $this->html .= ' </table>';
@ -1847,45 +1852,44 @@ class personality extends question
$question_values=array(); $question_values=array();
// values of question options // values of question options
foreach ($form_content['values'] as $key=>$value) if(is_array($form_content['values'])) { // check if data is correct
{ foreach ($form_content['values'] as $key=>$value) {
$question_values [] = '<input size="3" type="text" id="values['.$key.']" name="values['.$key.']" value="'.$value.'" />'; $question_values [] = '<input size="3" type="text" id="values['.$key.']" name="values['.$key.']" value="'.$value.'" />';
} }
}
$count=0; $count=0;
if(is_array($form_content['answers'])) {
foreach ($form_content['answers'] as $key=>$value) foreach ($form_content['answers'] as $key=>$value) {
{ $this->html .= ' <tr>';
$this->html .= ' <tr>'; $this->html .= ' <td align="right"><label for="answers['.$key.']">'.($key+1).'</label></td>';
$this->html .= ' <td align="right"><label for="answers['.$key.']">'.($key+1).'</label></td>'; //$this->html .= ' <td><input type="text" name="answers['.$key.']" id="answers['.$key.']" value="'.$form_content['answers'][$key].'" /></td>';
//$this->html .= ' <td><input type="text" name="answers['.$key.']" id="answers['.$key.']" value="'.$form_content['answers'][$key].'" /></td>'; $this->html .= ' <td width="550">'.api_return_html_area('answers['.$key.']', api_html_entity_decode(stripslashes($form_content['answers'][$key])), '', '', null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120')).'</td>';
$this->html .= ' <td width="550">'.api_return_html_area('answers['.$key.']', api_html_entity_decode(stripslashes($form_content['answers'][$key])), '', '', null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120')).'</td>'; $this->html .= ' <td>';
$this->html .= ' <td>';
if ($total_number_of_answers> 2)
if ($total_number_of_answers> 2) {
{ $this->html .=$question_values[$count];
$this->html .=$question_values[$count]; }
}
if ($key<$total_number_of_answers-1)
if ($key<$total_number_of_answers-1) {
{ $this->html .= ' <input type="image" src="../img/down.gif" value="move_down['.$key.']" name="move_down['.$key.']"/>';
$this->html .= ' <input type="image" src="../img/down.gif" value="move_down['.$key.']" name="move_down['.$key.']"/>'; }
} if ($key>0)
if ($key>0) {
{ $this->html .= ' <input type="image" src="../img/up.gif" value="move_up['.$key.']" name="move_up['.$key.']"/>';
$this->html .= ' <input type="image" src="../img/up.gif" value="move_up['.$key.']" name="move_up['.$key.']"/>'; }
} if ($total_number_of_answers> 2)
if ($total_number_of_answers> 2) {
{ $this->html .= ' <input type="image" src="../img/delete.gif" value="delete_answer['.$key.']" name="delete_answer['.$key.']"/>';
$this->html .= ' <input type="image" src="../img/delete.gif" value="delete_answer['.$key.']" name="delete_answer['.$key.']"/>'; }
$this->html .= ' </td>';
$this->html .= ' </tr>';
$count++;
} }
$this->html .= ' </td>';
$this->html .= ' </tr>';
$count++;
} }
// The buttons for adding or removing // The buttons for adding or removing
//$this->html .= parent :: add_remove_buttons($form_content); //$this->html .= parent :: add_remove_buttons($form_content);
} }
@ -1949,25 +1953,27 @@ class multipleresponse extends question
$this->html .= ' <div class="formw">'; $this->html .= ' <div class="formw">';
$total_number_of_answers = count($form_content['answers']); $total_number_of_answers = count($form_content['answers']);
$this->html .= ' <table>'; $this->html .= ' <table>';
foreach ($form_content['answers'] as $key=>$value) { if(is_array($form_content['answers'])) { // values of question options
$this->html .= ' <tr>'; foreach ($form_content['answers'] as $key=>$value) {
$this->html .= ' <td align="right"><label for="answers['.$key.']">'.($key+1).'</label></td>'; $this->html .= ' <tr>';
//$this->html .= ' <td><input type="text" name="answers['.$key.']" id="answers['.$key.']" value="'.$form_content['answers'][$key].'" /></td>'; $this->html .= ' <td align="right"><label for="answers['.$key.']">'.($key+1).'</label></td>';
$this->html .= ' <td width="550">'.api_return_html_area('answers['.$key.']', api_html_entity_decode(stripslashes($form_content['answers'][$key]), ENT_QUOTES, $charset), '', '', null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120')).'</td>'; //$this->html .= ' <td><input type="text" name="answers['.$key.']" id="answers['.$key.']" value="'.$form_content['answers'][$key].'" /></td>';
$this->html .= ' <td>'; $this->html .= ' <td width="550">'.api_return_html_area('answers['.$key.']', api_html_entity_decode(stripslashes($form_content['answers'][$key]), ENT_QUOTES, $charset), '', '', null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120')).'</td>';
if ($key<$total_number_of_answers-1) { $this->html .= ' <td>';
$this->html .= ' <input type="image" src="../img/down.gif" value="move_down['.$key.']" name="move_down['.$key.']"/>'; if ($key<$total_number_of_answers-1) {
} $this->html .= ' <input type="image" src="../img/down.gif" value="move_down['.$key.']" name="move_down['.$key.']"/>';
}
if ($key>0) {
$this->html .= ' <input type="image" src="../img/up.gif" value="move_up['.$key.']" name="move_up['.$key.']"/>'; if ($key>0) {
} $this->html .= ' <input type="image" src="../img/up.gif" value="move_up['.$key.']" name="move_up['.$key.']"/>';
}
if ($total_number_of_answers> 2) {
$this->html .= ' <input type="image" src="../img/delete.gif" value="delete_answer['.$key.']" name="delete_answer['.$key.']"/>'; if ($total_number_of_answers> 2) {
$this->html .= ' <input type="image" src="../img/delete.gif" value="delete_answer['.$key.']" name="delete_answer['.$key.']"/>';
}
$this->html .= ' </td>';
$this->html .= ' </tr>';
} }
$this->html .= ' </td>';
$this->html .= ' </tr>';
} }
// The buttons for adding or removing // The buttons for adding or removing
$this->html .= ' </table>'; $this->html .= ' </table>';

Loading…
Cancel
Save