parent
75087b135c
commit
6adf1811d6
@ -0,0 +1,11 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Class ch_comment |
||||
*/ |
||||
class ch_comment extends survey_question |
||||
{ |
||||
|
||||
} |
||||
|
@ -0,0 +1,68 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Class ch_dropdown |
||||
*/ |
||||
class ch_dropdown extends survey_question |
||||
{ |
||||
/** |
||||
* @param array $survey_data |
||||
* @param $formData |
||||
* @return FormValidator |
||||
*/ |
||||
public function create_form($survey_data, $formData) |
||||
{ |
||||
parent::create_form($survey_data, $formData); |
||||
|
||||
// The answers |
||||
/*$this->html .= ' <div class="row">'; |
||||
$this->html .= ' <label class="control-label">'; |
||||
$this->html .= get_lang('AnswerOptions'); |
||||
$this->html .= ' </label>'; |
||||
$this->html .= ' <div class="formw">'; |
||||
$total_number_of_answers = count($form_content['answers']); |
||||
$this->html .= ' <table>'; |
||||
foreach ($form_content['answers'] as $key => & $value) { |
||||
$this->html .= ' <tr>'; |
||||
$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="'.stripslashes($form_content['answers'][$key]).'" /></td>'; |
||||
$this->html .= ' <td>'; |
||||
if ($key < $total_number_of_answers - 1) { |
||||
$this->html .= ' <input type="image" style="width:22px" src="../img/icons/22/down.png" value="move_down['.$key.']" name="move_down['.$key.']"/>'; |
||||
} |
||||
if ($key > 0) { |
||||
$this->html .= ' <input type="image" style="width:22px" src="../img/icons/22/up.png" value="move_up['.$key.']" name="move_up['.$key.']"/>'; |
||||
} |
||||
if ($total_number_of_answers> 2) { |
||||
$this->html .= ' <input type="image" style="width:22px" src="../img/icons/22/delete.png" value="delete_answer['.$key.']" name="delete_answer['.$key.']"/>'; |
||||
} |
||||
$this->html .= ' </td>'; |
||||
$this->html .= ' </tr>'; |
||||
} |
||||
// The buttons for adding or removing |
||||
$this->html .= ' </table>'; |
||||
$this->html .= ' </div>'; |
||||
$this->html .= ' </div>';*/ |
||||
|
||||
if (is_array($formData['answers'])) { |
||||
foreach ($formData['answers'] as $key => $value) { |
||||
$this->getForm()->addText('answers['.$key.']', $key + 1); |
||||
} |
||||
} |
||||
|
||||
return parent :: add_remove_buttons($formData); |
||||
} |
||||
|
||||
/** |
||||
* @param FormValidator $form |
||||
* @param array $questionData |
||||
* @param array $answers |
||||
*/ |
||||
public function render(FormValidator $form, $questionData = array(), $answers = array()) |
||||
{ |
||||
$form->addSelect("question".$questionData['question_id'], null, $questionData['options']); |
||||
} |
||||
} |
||||
|
||||
|
@ -0,0 +1,61 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Class ch_multiplechoice |
||||
*/ |
||||
class ch_multiplechoice extends survey_question |
||||
{ |
||||
/** |
||||
* @param array $survey_data |
||||
* @param array $formData |
||||
* @return FormValidator |
||||
*/ |
||||
public function create_form($survey_data, $formData) |
||||
{ |
||||
parent::create_form($survey_data, $formData); |
||||
|
||||
$options = array( |
||||
'horizontal' => get_lang('Horizontal'), |
||||
'vertical' => get_lang('Vertical') |
||||
); |
||||
$this->getForm()->addRadio('horizontalvertical', get_lang('DisplayAnswersHorVert'), $options); |
||||
|
||||
$formData['horizontalvertical'] = isset($formData['horizontalvertical']) ? $formData['horizontalvertical'] : 'horizontal'; |
||||
|
||||
$config = array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120'); |
||||
$total = count($formData['answers']); |
||||
if (is_array($formData['answers'])) { |
||||
foreach ($formData['answers'] as $key => $value) { |
||||
|
||||
$this->getForm()->addHtmlEditor('answers['.$key.']', null, false, false, $config); |
||||
|
||||
if ($key < $total-1) { |
||||
//$this->getForm()->addButton("move_down[$key]", get_lang('Down')); |
||||
} |
||||
|
||||
if ($key > 0) { |
||||
//$this->getForm()->addButton("move_up[$key]", get_lang('Up')); |
||||
} |
||||
|
||||
if ($total> 2) { |
||||
$this->getForm()->addButton("delete_answer[$key]", get_lang('Delete')); |
||||
} |
||||
} |
||||
} |
||||
$this->getForm()->setDefaults($formData); |
||||
|
||||
return parent :: add_remove_buttons($formData); |
||||
} |
||||
|
||||
/** |
||||
* @param FormValidator $form |
||||
* @param array $questionData |
||||
* @param array $answers |
||||
*/ |
||||
public function render(FormValidator $form, $questionData = array(), $answers = array()) |
||||
{ |
||||
$question = new ch_yesno(); |
||||
$question->render($form, $questionData, $answers); |
||||
} |
||||
} |
@ -0,0 +1,103 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Class ch_multipleresponse |
||||
*/ |
||||
class ch_multipleresponse extends survey_question |
||||
{ |
||||
/** |
||||
* @param array $survey_data |
||||
* @param array $formData |
||||
*/ |
||||
public function create_form($survey_data, $formData) |
||||
{ |
||||
parent::create_form($survey_data, $formData); |
||||
$options = array( |
||||
'horizontal' => get_lang('Horizontal'), |
||||
'vertical' => get_lang('Vertical') |
||||
); |
||||
$this->getForm()->addRadio('horizontalvertical', get_lang('DisplayAnswersHorVert'), $options); |
||||
|
||||
$formData['horizontalvertical'] = isset($formData['horizontalvertical']) ? $formData['horizontalvertical'] : 'horizontal'; |
||||
|
||||
$config = array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120'); |
||||
if (is_array($formData['answers'])) { |
||||
foreach ($formData['answers'] as $key => $value) { |
||||
$this->getForm()->addHtmlEditor('answers['.$key.']', null, false, false, $config); |
||||
/* |
||||
$this->html .= ' <tr>'; |
||||
$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 width="550">'.api_return_html_area('answers['.$key.']', api_html_entity_decode(stripslashes($form_content['answers'][$key]), ENT_QUOTES), '', '', null, ).'</td>'; |
||||
$this->html .= ' <td>'; |
||||
if ($key<$total_number_of_answers-1) { |
||||
$this->html .= ' <input style="width:22px" type="image" src="../img/icons/22/down.png" value="move_down['.$key.']" name="move_down['.$key.']"/>'; |
||||
} |
||||
if ($key>0) { |
||||
$this->html .= ' <input style="width:22px" type="image" src="../img/icons/22/up.png" value="move_up['.$key.']" name="move_up['.$key.']"/>'; |
||||
} |
||||
if ($total_number_of_answers> 2) { |
||||
$this->html .= ' <input style="width:22px" type="image" src="../img/icons/22/delete.png" value="delete_answer['.$key.']" name="delete_answer['.$key.']"/>'; |
||||
} |
||||
$this->html .= ' </td>'; |
||||
$this->html .= ' </tr>';*/ |
||||
} |
||||
} |
||||
|
||||
$this->getForm()->setDefaults($formData); |
||||
|
||||
return parent :: add_remove_buttons($formData); |
||||
} |
||||
|
||||
/** |
||||
* @param FormValidator $form |
||||
* @param array $questionData |
||||
* @param array $answers |
||||
*/ |
||||
public function render(FormValidator $form, $questionData = array(), $answers = array()) |
||||
{ |
||||
if ($questionData['display'] == 'vertical') { |
||||
$class = ''; |
||||
} else { |
||||
$class = 'inline'; |
||||
} |
||||
|
||||
foreach ($questionData['options'] as $key => & $value) { |
||||
/*if ($questionData['display'] == 'vertical') { |
||||
$this->html .= '<label class="checkbox"><input name="question'.$questionData['question_id'].'[]" type="checkbox" value="'.$key.'"'; |
||||
} else { |
||||
$this->html .= '<label class="checkbox inline"><input name="question'.$questionData['question_id'].'[]" type="checkbox" value="'.$key.'"'; |
||||
} |
||||
if (is_array($answers)) { |
||||
if (in_array($key, $answers)) { |
||||
$this->html .= 'checked="checked"'; |
||||
} |
||||
} |
||||
if (substr_count($value, '<p>') == 1) { |
||||
$this->html .= '/>'.substr($value, 3, (strlen($value) - 7)).'</label>'; |
||||
if ($questionData['display'] == 'vertical') { |
||||
$this->html .= '<br />'; |
||||
} |
||||
} else { |
||||
$this->html .= '/>'.$value.'</label>'; |
||||
}*/ |
||||
|
||||
/*$form->addCheckBox( |
||||
'question'.$questionData['question_id'].'[]', |
||||
$key, |
||||
$value, |
||||
array('label-class' => $class) |
||||
);*/ |
||||
} |
||||
|
||||
$form->addCheckBoxGroup( |
||||
'question'.$questionData['question_id'].'[]', |
||||
null, |
||||
$questionData['options'], |
||||
array('label-class' => $class) |
||||
); |
||||
|
||||
|
||||
} |
||||
} |
@ -0,0 +1,21 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Class ch_open |
||||
*/ |
||||
class ch_open extends survey_question |
||||
{ |
||||
public function render(FormValidator $form, $questionData = array(), $answers = array()) |
||||
{ |
||||
if (is_array($answers)) { |
||||
$content = implode('', $answers); |
||||
} else { |
||||
$content = $answers; |
||||
} |
||||
|
||||
$form->addTextarea("question".$questionData['question_id'], null); |
||||
//<textarea name="question'.$questionData['question_id'].'" id="textarea" style="width: 400px; height: 130px;">'.$content.'</textarea>'; |
||||
|
||||
} |
||||
} |
@ -0,0 +1,12 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Class ch_pagebreak |
||||
*/ |
||||
class ch_pagebreak extends survey_question |
||||
{ |
||||
|
||||
} |
||||
|
||||
|
@ -0,0 +1,30 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Class ch_percentage |
||||
*/ |
||||
class ch_percentage extends survey_question |
||||
{ |
||||
/** |
||||
* @param FormValidator $form |
||||
* @param array $questionData |
||||
* @param array $answers |
||||
*/ |
||||
public function render(FormValidator $form, $questionData = array(), $answers = array()) |
||||
{ |
||||
$options = array( |
||||
'--' => '--' |
||||
); |
||||
|
||||
foreach ($questionData['options'] as $key => & $value) { |
||||
$options[$key] = $value; |
||||
} |
||||
|
||||
$form->addSelect( |
||||
'question'.$questionData['question_id'], null, $options |
||||
); |
||||
} |
||||
} |
||||
|
||||
|
@ -0,0 +1,100 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Class ch_personality |
||||
*/ |
||||
class ch_personality extends survey_question |
||||
{ |
||||
|
||||
/** |
||||
* This function creates the form elements for the multiple response questions |
||||
* |
||||
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University |
||||
* @version January 2007 |
||||
*/ |
||||
public function create_form($survey_data, $form_content) |
||||
{ |
||||
parent::create_form($survey_data, $form_content); |
||||
$this->html .= ' <tr>'; |
||||
$this->html .= ' <td colspan="2"><strong>'.get_lang('DisplayAnswersHorVert').'</strong></td>'; |
||||
$this->html .= ' </tr>'; |
||||
// Horizontal or vertical |
||||
$this->html .= ' <tr>'; |
||||
$this->html .= ' <td align="right" valign="top"> </td>'; |
||||
$this->html .= ' <td>'; |
||||
$this->html .= ' <input name="horizontalvertical" type="radio" value="horizontal" '; |
||||
if (empty($form_content['horizontalvertical']) || $form_content['horizontalvertical'] == 'horizontal') { |
||||
$this->html .= 'checked="checked"'; |
||||
} |
||||
$this->html .= '/>'.get_lang('Horizontal').'</label><br />'; |
||||
$this->html .= ' <input name="horizontalvertical" type="radio" value="vertical" '; |
||||
|
||||
if (isset($form_content['horizontalvertical']) && $form_content['horizontalvertical'] == 'vertical') { |
||||
$this->html .= 'checked="checked"'; |
||||
} |
||||
|
||||
$this->html .= ' />'.get_lang('Vertical').'</label>'; |
||||
$this->html .= ' </td>'; |
||||
$this->html .= ' <td> </td>'; |
||||
$this->html .= ' </tr>'; |
||||
$this->html .= ' <tr> |
||||
<td colspan=""> </td> |
||||
</tr>'; |
||||
|
||||
// The options |
||||
$this->html .= ' <tr>'; |
||||
$this->html .= ' <td colspan="3"><strong>'.get_lang('AnswerOptions').'</strong></td>'; |
||||
$this->html .= ' </tr>'; |
||||
$total_number_of_answers = count($form_content['answers']); |
||||
|
||||
$question_values = array(); |
||||
|
||||
// Values of question options |
||||
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.'" />'; |
||||
} |
||||
} |
||||
$count = 0; |
||||
if (is_array($form_content['answers'])) { |
||||
foreach ($form_content['answers'] as $key => & $value) { |
||||
$this->html .= ' <tr>'; |
||||
$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 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>'; |
||||
|
||||
if ($total_number_of_answers > 2) { |
||||
$this->html .= $question_values[$count]; |
||||
} |
||||
|
||||
if ($key < $total_number_of_answers - 1) { |
||||
$this->html .= ' <input type="image" style="width:22px" src="../img/icons/22/down.png" value="move_down['.$key.']" name="move_down['.$key.']"/>'; |
||||
} |
||||
if ($key > 0) { |
||||
$this->html .= ' <input type="image" style="width:22px" src="../img/icons/22/up.png" value="move_up['.$key.']" name="move_up['.$key.']"/>'; |
||||
} |
||||
if ($total_number_of_answers > 2) { |
||||
$this->html .= ' <input type="image" style="width:22px" src="../img/icons/22/delete.png" value="delete_answer['.$key.']" name="delete_answer['.$key.']"/>'; |
||||
} |
||||
$this->html .= ' </td>'; |
||||
$this->html .= ' </tr>'; |
||||
$count++; |
||||
} |
||||
} |
||||
// The buttons for adding or removing |
||||
//$this->html .= parent :: add_remove_buttons($form_content); |
||||
} |
||||
|
||||
/** |
||||
* @param FormValidator $form |
||||
* @param array $questionData |
||||
* @param array $answers |
||||
*/ |
||||
public function render(FormValidator $form, $questionData = array(), $answers = array()) |
||||
{ |
||||
$question = new ch_yesno(); |
||||
$question->render($form, $questionData, $answers); |
||||
} |
||||
} |
@ -0,0 +1,74 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Class ch_score |
||||
*/ |
||||
class ch_score extends survey_question |
||||
{ |
||||
/** |
||||
* @param array $survey_data |
||||
* @param $form_content |
||||
*/ |
||||
public function create_form($survey_data, $formData) |
||||
{ |
||||
parent::create_form($survey_data, $formData); |
||||
|
||||
$this->getForm()->addText('maximum_score', get_lang('MaximumScore')); |
||||
|
||||
$config = array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120'); |
||||
if (is_array($formData['answers'])) { |
||||
foreach ($formData['answers'] as $key => $value) { |
||||
$this->getForm()->addHtmlEditor('answers['.$key.']', null, false, false, $config); |
||||
/* |
||||
$this->html .= ' <tr>'; |
||||
$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 width="550">'.api_return_html_area('answers['.$key.']', api_html_entity_decode(stripslashes($form_content['answers'][$key]), ENT_QUOTES), '', '', null, ).'</td>'; |
||||
$this->html .= ' <td>'; |
||||
if ($key<$total_number_of_answers-1) { |
||||
$this->html .= ' <input style="width:22px" type="image" src="../img/icons/22/down.png" value="move_down['.$key.']" name="move_down['.$key.']"/>'; |
||||
} |
||||
if ($key>0) { |
||||
$this->html .= ' <input style="width:22px" type="image" src="../img/icons/22/up.png" value="move_up['.$key.']" name="move_up['.$key.']"/>'; |
||||
} |
||||
if ($total_number_of_answers> 2) { |
||||
$this->html .= ' <input style="width:22px" type="image" src="../img/icons/22/delete.png" value="delete_answer['.$key.']" name="delete_answer['.$key.']"/>'; |
||||
} |
||||
$this->html .= ' </td>'; |
||||
$this->html .= ' </tr>';*/ |
||||
} |
||||
} |
||||
|
||||
return parent :: add_remove_buttons($formData); |
||||
} |
||||
|
||||
/** |
||||
* @param FormValidator $form |
||||
* @param array $questionData |
||||
* @param array $answers |
||||
*/ |
||||
public function render(FormValidator $form, $questionData = array(), $answers = array()) |
||||
{ |
||||
foreach ($questionData['options'] as $key => & $value) { |
||||
$options = array(); |
||||
for ($i=1; $i <= $questionData['maximum_score']; $i++) { |
||||
$options[$i] = $i; |
||||
} |
||||
|
||||
$form->addSelect( |
||||
'question'.$questionData['question_id'].'['.$key.'].', $value, $options |
||||
); |
||||
/* |
||||
$this->html .= '<tr> |
||||
<td>'.$value.'</td>'; |
||||
$this->html .= ' <td>'; |
||||
$this->html .= '<select name="question'.$form_content['question_id'].'['.$key.']">'; |
||||
$this->html .= '<option value="--">--</option>'; |
||||
|
||||
$this->html .= '</select>'; |
||||
$this->html .= ' </td>'; |
||||
$this->html .= '</tr>';*/ |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,96 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Class ch_yesno |
||||
*/ |
||||
class ch_yesno extends survey_question |
||||
{ |
||||
/** |
||||
* @param array $survey_data |
||||
* @param array $formData |
||||
*/ |
||||
public function create_form($survey_data, $formData) |
||||
{ |
||||
parent::create_form($survey_data, $formData); |
||||
|
||||
$options = array( |
||||
'horizontal' => get_lang('Horizontal'), |
||||
'vertical' => get_lang('Vertical') |
||||
); |
||||
$this->getForm()->addRadio('horizontalvertical', get_lang('DisplayAnswersHorVert'), $options); |
||||
|
||||
$formData['horizontalvertical'] = isset($formData['horizontalvertical']) ? $formData['horizontalvertical'] : 'horizontal'; |
||||
|
||||
/*// Horizontal or vertical |
||||
$this->html .= ' <div class="control-group">'; |
||||
$this->html .= ' <label class="control-label">'; |
||||
$this->html .= get_lang('DisplayAnswersHorVert'); |
||||
$this->html .= ' </label>'; |
||||
$this->html .= ' <div class="controls">'; |
||||
$this->html .= ' <input name="horizontalvertical" type="radio" value="horizontal" '; |
||||
if (empty($form_content['horizontalvertical']) or $form_content['horizontalvertical'] == 'horizontal') { |
||||
$this->html .= 'checked="checked"'; |
||||
} |
||||
$this->html .= '/>'.get_lang('Horizontal').'<br />'; |
||||
$this->html .= ' <input name="horizontalvertical" type="radio" value="vertical" '; |
||||
if (isset($form_content['horizontalvertical']) && $form_content['horizontalvertical'] == 'vertical') { |
||||
$this->html .= 'checked="checked"'; |
||||
} |
||||
$this->html .= ' />'.get_lang('Vertical').''; |
||||
$this->html .= ' </div>'; |
||||
$this->html .= ' </div>';*/ |
||||
|
||||
// The options |
||||
$config = array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120'); |
||||
$this->getForm()->addHtmlEditor('answers[0]', get_lang('AnswerOptions'), true, false, $config); |
||||
$this->getForm()->addHtmlEditor('answers[1]', null, true, false, $config); |
||||
|
||||
$this->getForm()->setDefaults($formData); |
||||
|
||||
/*$this->html .= ' <div class="row">'; |
||||
$this->html .= ' <label class="control-label">'; |
||||
$this->html .= get_lang('AnswerOptions'); |
||||
$this->html .= ' </label>'; |
||||
$this->html .= ' <div class="formw">'; |
||||
$this->html .= ' <table>'; |
||||
$this->html .= ' <tr>'; |
||||
$this->html .= ' <td align="right"><label for="answers[0]">1</label></td>'; |
||||
|
||||
$this->html .= ' <td width="550">'.api_return_html_area('answers[0]', stripslashes($form_content['answers'][0]), '', '', null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120')).'</td>'; |
||||
$this->html .= ' <td><input style="width:22px" src="../img/icons/22/down.png" type="image" class="down" value="move_down[0]" name="move_down[0]"/></td>'; |
||||
$this->html .= ' </tr>'; |
||||
$this->html .= ' <tr>'; |
||||
$this->html .= ' <td align="right"><label for="answers[1]">2</label></td>'; |
||||
//$this->html .= ' <td><input type="text" name="answers[1]" id="answers[1]" value="'.$form_content['answers'][1].'" /></td>'; |
||||
$this->html .= ' <td width="550">'.api_return_html_area('answers[1]', stripslashes($form_content['answers'][1]), '', '', null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120')).'</td>'; |
||||
$this->html .= ' <td><input style="width:22px" type="image" src="../img/icons/22/up.png" value="move_up[1]" name="move_up[1]" /></td>'; |
||||
$this->html .= ' </tr>'; |
||||
$this->html .= ' </table>'; |
||||
$this->html .= ' </div>'; |
||||
$this->html .= ' </div>';*/ |
||||
} |
||||
|
||||
/** |
||||
* @param FormValidator $form |
||||
* @param array $questionData |
||||
* @param array $answers |
||||
*/ |
||||
public function render(FormValidator $form, $questionData = array(), $answers = array()) |
||||
{ |
||||
if (is_array($questionData['options'])) { |
||||
if ($questionData['display'] == 'vertical') { |
||||
$class = ''; |
||||
} else { |
||||
$class = 'inline'; |
||||
} |
||||
|
||||
$form->addRadio( |
||||
'question' . $questionData['question_id'], |
||||
null, |
||||
$questionData['options'], |
||||
array('label-class' => $class) |
||||
); |
||||
} |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,299 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
use ChamiloSession as Session; |
||||
|
||||
/** |
||||
* Class survey_question |
||||
*/ |
||||
class survey_question |
||||
{ |
||||
/** @var FormValidator */ |
||||
private $form; |
||||
|
||||
/** |
||||
* Generic part of any survey question: the question field |
||||
* @param array $surveyData |
||||
* @param array $formData |
||||
* |
||||
* @return FormValidator |
||||
*/ |
||||
public function create_form($surveyData, $formData) |
||||
{ |
||||
$action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null; |
||||
$questionId = isset($_GET['question_id']) ? intval($_GET['question_id']) : null; |
||||
$surveyId = isset($_GET['survey_id']) ? intval($_GET['survey_id']) : null; |
||||
|
||||
$toolName = Display::return_icon( |
||||
survey_manager::icon_question(Security::remove_XSS($_GET['type'])), |
||||
get_lang(ucfirst(Security::remove_XSS($_GET['type']))), |
||||
array('align' => 'middle', 'height' => '22px') |
||||
).' '; |
||||
|
||||
if ($action == 'add') { |
||||
$toolName .= get_lang('AddQuestion'); |
||||
} |
||||
if ($action == 'edit') { |
||||
$toolName .= get_lang('EditQuestion'); |
||||
} |
||||
|
||||
if ($_GET['type'] == 'yesno') { |
||||
$toolName .= ': '.get_lang('YesNo'); |
||||
} else if ($_GET['type'] == 'multiplechoice') { |
||||
$toolName .= ': '.get_lang('UniqueSelect'); |
||||
} else { |
||||
$toolName .= ': '.get_lang(api_ucfirst(Security::remove_XSS($_GET['type']))); |
||||
} |
||||
|
||||
$sharedQuestionId = isset($formData['shared_question_id']) ? $formData['shared_question_id'] : null; |
||||
|
||||
$url = api_get_self().'?action='.$action.'&type='.Security::remove_XSS($_GET['type']).'&survey_id='.$surveyId.'&question_id='.$questionId.'&'.api_get_cidreq(); |
||||
|
||||
$form = new FormValidator('question_form', 'post', $url); |
||||
$form->addHeader($toolName); |
||||
$form->addHidden('survey_id', $surveyId); |
||||
$form->addHidden('question_id', $questionId); |
||||
$form->addHidden('shared_question_id', Security::remove_XSS($sharedQuestionId)); |
||||
$form->addHidden('type', Security::remove_XSS($_GET['type'])); |
||||
$form->addHidden('save_question', 1); |
||||
|
||||
$config = array('ToolbarSet' => 'SurveyQuestion', 'Width' => '100%', 'Height' => '120'); |
||||
$form->addHtmlEditor('question', get_lang('Question'), true, false, $config); |
||||
|
||||
// When survey type = 1?? |
||||
if ($surveyData['survey_type'] == 1) { |
||||
$table_survey_question_group = Database::get_course_table(TABLE_SURVEY_QUESTION_GROUP); |
||||
$sql = 'SELECT id,name FROM '.$table_survey_question_group.' |
||||
WHERE survey_id = '.(int)$_GET['survey_id'].' |
||||
ORDER BY name'; |
||||
$rs = Database::query($sql); |
||||
$glist = null; |
||||
while ($row = Database::fetch_array($rs, 'NUM')) { |
||||
$glist .= '<option value="'.$row[0].'" >'.$row[1].'</option>'; |
||||
} |
||||
|
||||
$grouplist = $grouplist1 = $grouplist2 = $glist; |
||||
|
||||
if (!empty($formData['assigned'])) { |
||||
$grouplist = str_replace('<option value="'.$formData['assigned'].'"','<option value="'.$formData['assigned'].'" selected',$glist); |
||||
} |
||||
|
||||
if (!empty($formData['assigned1'])) { |
||||
$grouplist1 = str_replace('<option value="'.$formData['assigned1'].'"','<option value="'.$formData['assigned1'].'" selected',$glist); |
||||
} |
||||
|
||||
if (!empty($formData['assigned2'])) { |
||||
$grouplist2 = str_replace('<option value="'.$formData['assigned2'].'"','<option value="'.$formData['assigned2'].'" selected',$glist); |
||||
} |
||||
|
||||
$this->html .= ' <tr><td colspan=""> |
||||
<fieldset style="border:1px solid black"><legend>'.get_lang('Condition').'</legend> |
||||
|
||||
<b>'.get_lang('Primary').'</b><br /> |
||||
'.'<input type="radio" name="choose" value="1" '.(($formData['choose'] == 1) ? 'checked' : ''). |
||||
'><select name="assigned">'.$grouplist.'</select><br />'; |
||||
|
||||
$this->html .= ' |
||||
<b>'.get_lang('Secondary').'</b><br /> |
||||
'.'<input type="radio" name="choose" value="2" '.(($formData['choose']==2)?'checked':''). |
||||
'><select name="assigned1">'.$grouplist1.'</select> '. |
||||
'<select name="assigned2">'.$grouplist2.'</select>' |
||||
.'</fieldset><br />'; |
||||
|
||||
//$form->addRadio('choose', get_lang('Primary')); |
||||
//$form->addRadio('choose', get_lang('Secondary')); |
||||
} |
||||
|
||||
$form->setDefaults($formData); |
||||
$this->setForm($form); |
||||
|
||||
return $form; |
||||
} |
||||
|
||||
/** |
||||
* Adds submit button |
||||
* |
||||
*/ |
||||
public function render_form() |
||||
{ |
||||
if (isset($_GET['question_id']) and !empty($_GET['question_id'])) { |
||||
$icon = 'pencil'; |
||||
$text = get_lang('ModifyQuestionSurvey'); |
||||
} else { |
||||
$icon = 'check'; |
||||
$text = get_lang('CreateQuestionSurvey'); |
||||
} |
||||
|
||||
$this->getForm()->addButton('save', $text, $icon); |
||||
} |
||||
|
||||
/** |
||||
* @return FormValidator |
||||
*/ |
||||
public function getForm() |
||||
{ |
||||
return $this->form; |
||||
} |
||||
|
||||
/** |
||||
* @param FormValidator $form |
||||
*/ |
||||
public function setForm($form) |
||||
{ |
||||
$this->form = $form; |
||||
} |
||||
|
||||
/** |
||||
* @param array $formData |
||||
* @return mixed |
||||
*/ |
||||
public function preAction($formData) |
||||
{ |
||||
// Moving an answer up |
||||
if (isset($_POST['move_up']) && $_POST['move_up']) { |
||||
foreach ($_POST['move_up'] as $key => & $value) { |
||||
$id1 = $key; |
||||
$content1 = $formData['answers'][$id1]; |
||||
$id2 = $key - 1; |
||||
$content2 = $formData['answers'][$id2]; |
||||
$formData['answers'][$id1] = $content2; |
||||
$formData['answers'][$id2] = $content1; |
||||
} |
||||
} |
||||
|
||||
// Moving an answer down |
||||
if (isset($_POST['move_down']) && $_POST['move_down']) { |
||||
foreach ($_POST['move_down'] as $key => & $value) { |
||||
$id1 = $key; |
||||
$content1 = $formData['answers'][$id1]; |
||||
$id2 = $key + 1; |
||||
$content2 = $formData['answers'][$id2]; |
||||
$formData['answers'][$id1] = $content2; |
||||
$formData['answers'][$id2] = $content1; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* This solution is a little bit strange but I could not find a different solution. |
||||
*/ |
||||
if (isset($_POST['delete_answer'])) { |
||||
foreach ($_POST['delete_answer'] as $key => & $value) { |
||||
unset($formData['answers'][$key]); |
||||
$deleted = $key; |
||||
} |
||||
foreach ($formData['answers'] as $key => & $value) { |
||||
if ($key > $deleted) { |
||||
$formData['answers'][$key - 1] = $formData['answers'][$key]; |
||||
unset($formData['answers'][$key]); |
||||
} |
||||
} |
||||
} |
||||
|
||||
$counter = Session::read('answer_count'); |
||||
if (empty($counter)) { |
||||
$counter = count($formData['answers']) - 1; |
||||
Session::write('answer_count', $counter); |
||||
} |
||||
|
||||
// Adding an answer |
||||
if (isset($_POST['add_answer'])) { |
||||
$counter++; |
||||
Session::write('answer_count', $counter); |
||||
} |
||||
|
||||
// Removing an answer |
||||
if (isset($_POST['remove_answer'])) { |
||||
$counter--; |
||||
Session::write('answer_count', $counter); |
||||
foreach ($formData['answers'] as $index => &$data) { |
||||
if ($index > $counter) { |
||||
unset($formData['answers'][$index]); |
||||
} |
||||
} |
||||
} |
||||
|
||||
foreach ($formData['answers'] as $index => $data) { |
||||
if ($index > $counter) { |
||||
unset($formData['answers'][$index]); |
||||
} |
||||
} |
||||
|
||||
for ($i = 0; $i < $counter; $i++) { |
||||
if (!isset($formData['answers'][$i])) { |
||||
$formData['answers'][$i] = ''; |
||||
} |
||||
} |
||||
|
||||
return $formData; |
||||
} |
||||
|
||||
/** |
||||
* Handles the actions on a question and its answers |
||||
* |
||||
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University |
||||
* @version January 2007 |
||||
*/ |
||||
public function handle_action($surveyData, $formData) |
||||
{ |
||||
// Saving a question |
||||
if (isset($_POST['save_question']) && |
||||
!isset($_POST['add_answer']) && |
||||
!isset($_POST['remove_answer']) && |
||||
!isset($_POST['delete_answer']) && |
||||
!isset($_POST['move_down']) && |
||||
!isset($_POST['move_up']) |
||||
) { |
||||
Session::erase('answer_count'); |
||||
$message = survey_manager::save_question( |
||||
$surveyData, |
||||
$formData |
||||
); |
||||
|
||||
if ($message == 'QuestionAdded' || $message == 'QuestionUpdated') { |
||||
header('Location: '.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.intval($_GET['survey_id']).'&message='.$message.'&'.api_get_cidreq()); |
||||
exit; |
||||
|
||||
} else { |
||||
/*if ($message == 'PleaseEnterAQuestion' || $message == 'PleasFillAllAnswer'|| $message == 'PleaseChooseACondition'|| $message == 'ChooseDifferentCategories') { |
||||
$_SESSION['temp_user_message'] = $formData['question']; |
||||
$_SESSION['temp_horizontalvertical'] = $formData['horizontalvertical']; |
||||
$_SESSION['temp_sys_message'] = $message; |
||||
$_SESSION['temp_answers'] = $formData['answers']; |
||||
$_SESSION['temp_values'] = $formData['values']; |
||||
header('location: '.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&question_id='.intval($_GET['question_id']).'&survey_id='.intval($_GET['survey_id']).'&action='.Security::remove_XSS($_GET['action']).'&type='.Security::remove_XSS($_GET['type']).''); |
||||
exit; |
||||
}*/ |
||||
} |
||||
} |
||||
|
||||
return $formData; |
||||
} |
||||
|
||||
/** |
||||
* Adds two buttons. One to add an option, one to remove an option |
||||
* |
||||
* @param FormValidator $form |
||||
* @param array $data |
||||
* |
||||
* @return FormValidator |
||||
*/ |
||||
public function add_remove_buttons($data) |
||||
{ |
||||
$removeButton = $this->getForm()->addButton('remove_answer', get_lang('RemoveAnswer'), 'minus'); |
||||
if (count($data['answers']) <= 2) { |
||||
$removeButton->updateAttributes(array('disabled' => 'disabled')); |
||||
} |
||||
$this->getForm()->addButton('add_answer', get_lang('AddAnswer'), 'plus'); |
||||
} |
||||
|
||||
/** |
||||
* @param FormValidator $form |
||||
* @param array $questionData |
||||
* @param array $answers |
||||
*/ |
||||
public function render(FormValidator $form, $questionData = array(), $answers = array()) |
||||
{ |
||||
return null; |
||||
} |
||||
} |
||||
|
@ -0,0 +1,14 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CoreBundle\Component\Editor\CkEditor\Toolbar; |
||||
|
||||
/** |
||||
* Class Survey |
||||
* |
||||
* @package Chamilo\CoreBundle\Component\Editor\CkEditor\Toolbar |
||||
*/ |
||||
class Survey extends Basic |
||||
{ |
||||
|
||||
} |
@ -0,0 +1,14 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CoreBundle\Component\Editor\CkEditor\Toolbar; |
||||
|
||||
/** |
||||
* Class SurveyQuestion |
||||
* |
||||
* @package Chamilo\CoreBundle\Component\Editor\CkEditor\Toolbar |
||||
*/ |
||||
class SurveyQuestion extends Basic |
||||
{ |
||||
|
||||
} |
Loading…
Reference in new issue