Browse Source

Using FormValidator in survey (up/down button missing) BT#8968

Julio Montoya 10 years ago
parent
commit
6adf1811d6

+ 4 - 6
main/inc/lib/formvalidator/Element/HtmlEditor.php

@@ -14,9 +14,7 @@ class HtmlEditor extends HTML_QuickForm_textarea
     /**
      * Full page
      */
-    var $fullPage;
-    var $fck_editor;
-    var $content;
+    public $fullPage;
 
     /**
      * Class Constructor
@@ -40,14 +38,11 @@ class HtmlEditor extends HTML_QuickForm_textarea
         $this->_persistantFreeze = true;
         $this->_type = 'html_editor';
 
-        global $fck_attribute;
-
         //$editor = Container::getHtmlEditor();
         $editor = new CkEditor();
         if ($editor) {
             $this->editor = $editor;
             $this->editor->setName($name);
-            $this->editor->processConfig($fck_attribute);
             $this->editor->processConfig($config);
         }
     }
@@ -59,6 +54,7 @@ class HtmlEditor extends HTML_QuickForm_textarea
     public function toHtml()
     {
         $value = $this->getValue();
+
         if ($this->editor) {
             if ($this->editor->getConfigAttribute('fullPage')) {
                 if (strlen(trim($value)) == 0) {
@@ -69,6 +65,7 @@ class HtmlEditor extends HTML_QuickForm_textarea
             }
         }
 
+
         if ($this->isFrozen()) {
             return $this->getFrozenHtml();
         } else {
@@ -93,6 +90,7 @@ class HtmlEditor extends HTML_QuickForm_textarea
         $result = '';
         if ($this->editor) {
             $this->editor->value = $this->getValue();
+            //echo '----->';            var_dump($this->getValue(),$this->getName());
             $this->editor->setName($this->getName());
             $result = $this->editor->createHtml();
         }

+ 2 - 2
main/inc/lib/formvalidator/FormValidator.class.php

@@ -431,11 +431,11 @@ EOT;
      * @param string $name
      * @param string $label						The label for the form-element
      * @param bool   $required	(optional)		Is the form-element required (default=true)
-     * @param bool   $full_page (optional)		When it is true, the editor loads completed html code for a full page.
+     * @param bool   $fullPage (optional)		When it is true, the editor loads completed html code for a full page.
      * @param array  $config (optional)	Configuration settings for the online editor.
      *
      */
-    public function addHtmlEditor($name, $label, $required = true, $fullPage = false, $config = null)
+    public function addHtmlEditor($name, $label, $required = true, $fullPage = false, $config = array())
     {
         $this->addElement('html_editor', $name, $label, 'rows="15" cols="80"', $config);
         $this->applyFilter($name, 'trim');

+ 2 - 0
main/inc/lib/pear/HTML/QuickForm/element.php

@@ -410,6 +410,7 @@ class HTML_QuickForm_element extends HTML_Common
                 // constant values override both default and submitted ones
                 // default values are overriden by submitted
                 $value = $this->_findValue($caller->_constantValues);
+
                 if (null === $value) {
                     $value = $this->_findValue($caller->_submitValues);
                     if (null === $value) {
@@ -423,6 +424,7 @@ class HTML_QuickForm_element extends HTML_Common
             case 'setGroupValue':
                 $this->setValue($arg);
         }
+
         return true;
     }
 

+ 11 - 0
main/survey/ch_comment.php

@@ -0,0 +1,11 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+/**
+ * Class ch_comment
+ */
+class ch_comment extends survey_question
+{
+
+}
+

+ 68 - 0
main/survey/ch_dropdown.php

@@ -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']);
+    }
+}
+
+

+ 61 - 0
main/survey/ch_multiplechoice.php

@@ -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);
+    }
+}

+ 103 - 0
main/survey/ch_multipleresponse.php

@@ -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)
+        );
+
+
+    }
+}

+ 21 - 0
main/survey/ch_open.php

@@ -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>';
+
+    }
+}

+ 12 - 0
main/survey/ch_pagebreak.php

@@ -0,0 +1,12 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+/**
+ * Class ch_pagebreak
+ */
+class ch_pagebreak extends survey_question
+{
+
+}
+
+

+ 30 - 0
main/survey/ch_percentage.php

@@ -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
+        );
+    }
+}
+
+

+ 100 - 0
main/survey/ch_personality.php

@@ -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">&nbsp;</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>&nbsp;</td>';
+        $this->html .= '	</tr>';
+        $this->html .= '		<tr>
+								<td colspan="">&nbsp;</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);
+    }
+}

+ 74 - 0
main/survey/ch_score.php

@@ -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>';*/
+        }
+    }
+}

+ 96 - 0
main/survey/ch_yesno.php

@@ -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)
+            );
+        }
+    }
+}

+ 4 - 12
main/survey/create_new_survey.php

@@ -21,10 +21,6 @@ require_once '../inc/global.inc.php';
 $this_section = SECTION_COURSES;
 
 // Including additional libraries
-/** @todo check if these are all needed */
-/** @todo check if the starting / is needed. api_get_path probably ends with an / */
-//require_once api_get_path(LIBRARY_PATH).'survey.lib.php';
-require_once 'survey.lib.php';
 
 $htmlHeadXtra[] = '<script>
     function advanced_parameters() {
@@ -325,14 +321,10 @@ if ($form->validate()) {
         }
     }
 
-    if ($config['survey']['debug']) {
-        // Displaying a feedback message
-        Display::display_confirmation_message($return['message'], false);
-    } else {
-        // Redirecting to the survey page (whilst showing the return message)
-        header('location: '.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$return['id'].'&message='.$return['message'].'&'.api_get_cidreq());
-        exit;
-    }
+    Display::addFlash(Display::return_message($return['message'], false));
+    // Redirecting to the survey page (whilst showing the return message)
+    header('location: '.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$return['id'].'&message='.$return['message'].'&'.api_get_cidreq());
+    exit;
 } else {
     // Displaying the header
     Display::display_header($tool_name);

+ 96 - 43
main/survey/fillsurvey.php

@@ -6,7 +6,7 @@
 * @author unknown, the initial survey that did not make it in 1.8 because of bad code
 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
 * @author Julio Montoya Armas <gugli100@gmail.com>, Chamilo: Personality Test modification and rewriting large parts of the code as well
-* @todo use FormValidator for the forms
+
 * @todo check if the user already filled the survey and if this is the case then the answers have to be updated and not stored again.
 * @todo performance could be improved if not the survey_id was stored with the invitation but the survey_code
  */
@@ -39,7 +39,7 @@ $table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION)
 $table_user = Database :: get_main_table(TABLE_MAIN_USER);
 
 // Check if user is anonymous or not
-if (api_is_anonymous($_user['user_id'], true)) {
+if (api_is_anonymous(api_get_user_id(), true)) {
     $isAnonymous = true;
 } else {
     $isAnonymous = false;
@@ -66,7 +66,10 @@ if ($surveyCode != "") {
     $resultAnonymous = Database::query($sql);
     $rowAnonymous = Database::fetch_array($resultAnonymous, 'ASSOC');
     // If is anonymous and is not allowed to take the survey to anonymous users, forbid access:
-    if (!isset($rowAnonymous['anonymous']) || ($rowAnonymous['anonymous'] == 0 && api_is_anonymous()) || count($rowAnonymous) == 0) {
+    if (!isset($rowAnonymous['anonymous']) ||
+        ($rowAnonymous['anonymous'] == 0 && api_is_anonymous()) ||
+        count($rowAnonymous) == 0
+    ) {
         api_not_allowed(true);
     }
     // If is anonymous and it is allowed to take the survey as anonymous, mark survey as anonymous.
@@ -88,7 +91,7 @@ $invitationcode = $_GET['invitationcode'];
 
 // Start auto-invitation feature FS#3403 (all-users-can-do-the-survey-URL handling)
 if ($invitationcode == 'auto' && isset($_GET['scode'])) {
-    $userid = $_user['user_id'];
+    $userid = api_get_user_id();
     // Survey_code of the survey
     $surveyCode = Database::escape_string($_GET['scode']);
     if ($isAnonymous) {
@@ -99,7 +102,8 @@ if ($invitationcode == 'auto' && isset($_GET['scode'])) {
     }
 
     // The survey code must exist in this course, or the URL is invalid
-    $sql = "SELECT * FROM $table_survey WHERE c_id = $course_id AND code = '".$surveyCode."'";
+    $sql = "SELECT * FROM $table_survey
+            WHERE c_id = $course_id AND code = '".$surveyCode."'";
     $result = Database::query($sql);
     if (Database :: num_rows($result) > 0) { // Ok
         // Check availability
@@ -237,7 +241,8 @@ if (count($_POST) > 0) {
                     }
                 } else {
                     // All the other question types (open question, multiple choice, percentage, ...)
-                    if ($types[$survey_question_id] == 'percentage') {
+                    if (isset($types[$survey_question_id]) &&
+                        $types[$survey_question_id] == 'percentage') {
                         $sql = "SELECT * FROM $table_survey_question_option
                                 WHERE
                                     c_id = $course_id AND
@@ -247,15 +252,30 @@ if (count($_POST) > 0) {
                         $option_value = $row['option_text'];
                     } else {
                         $option_value = 0;
-                        if ($types[$survey_question_id] == 'open') {
+                        if (isset($types[$survey_question_id]) &&
+                            $types[$survey_question_id] == 'open'
+                        ) {
                             $option_value = $value;
-                            //$value = 0;
                         }
                     }
 
                     $survey_question_answer = $value;
-                    SurveyUtil::remove_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id, $course_id);
-                    SurveyUtil::store_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id, $value, $option_value, $survey_data);
+
+                    SurveyUtil::remove_answer(
+                        $survey_invitation['user'],
+                        $survey_invitation['survey_id'],
+                        $survey_question_id,
+                        $course_id
+                    );
+
+                    SurveyUtil::store_answer(
+                        $survey_invitation['user'],
+                        $survey_invitation['survey_id'],
+                        $survey_question_id,
+                        $value,
+                        $option_value,
+                        $survey_data
+                    );
                 }
             }
         }
@@ -291,6 +311,7 @@ if (count($_POST) > 0) {
                 $option_value = $row['value'];
                 //$option_value = 0;
                 $survey_question_answer = $value;
+
                 // We save the answer after making sure that a possible previous attempt is deleted
                 SurveyUtil::remove_answer(
                     $survey_invitation['user'],
@@ -319,7 +340,12 @@ if (count($_POST) > 0) {
 // Displaying the survey title and subtitle (appears on every page)
 echo '<div class="survey-block">';
 echo '<div id="survey_title">';
-echo Display::return_icon('statistics.png', get_lang('CreateNewSurvey'),array('style'=>'display:inline-block; margin-right:5px;'),ICON_SIZE_SMALL);
+echo Display::return_icon(
+    'statistics.png',
+    get_lang('CreateNewSurvey'),
+    array('style'=>'display:inline-block; margin-right:5px;'),
+    ICON_SIZE_SMALL
+);
 echo strip_tags($survey_data['survey_title']).'</div>';
 echo '<div id="survey_subtitle">'.strip_tags($survey_data['survey_subtitle']).'</div>';
 
@@ -421,7 +447,9 @@ if ($survey_data['form_fields'] != '' && $survey_data['anonymous'] == 0 && is_ar
             }
             $form->applyFilter('official_code', 'stripslashes');
             $form->applyFilter('official_code', 'trim');
-            if (api_get_setting('registration', 'officialcode') == 'true' && api_get_setting('profile', 'officialcode') == 'true') {
+            if (api_get_setting('registration', 'officialcode') == 'true' &&
+                api_get_setting('profile', 'officialcode') == 'true'
+            ) {
                 $form->addRule('official_code', get_lang('ThisFieldIsRequired'), 'required');
             }
         }
@@ -473,7 +501,11 @@ if ($survey_data['form_fields'] != '' && $survey_data['anonymous'] == 0 && is_ar
     $form->setDefaults($user_data);
 }
 
-if ($survey_data['form_fields'] && $survey_data['anonymous'] == 0 && is_array($user_data) && !isset($_GET['show'])) {
+if ($survey_data['form_fields'] &&
+    $survey_data['anonymous'] == 0 &&
+    is_array($user_data) &&
+    !isset($_GET['show'])
+) {
     if ($form->validate()) {
         $user_data = $form->exportValues();
         if (is_array($user_data)) {
@@ -540,7 +572,8 @@ if ($survey_data['shuffle'] == 1) {
 }
 
 if (isset($_GET['show']) || isset($_POST['personality'])) {
-    // Getting all the questions for this page and add them to a multidimensional array where the first index is the page.
+    // Getting all the questions for this page and add them to a
+    // multidimensional array where the first index is the page.
     // As long as there is no pagebreak fount we keep adding questions to the page
     $questions_displayed = array();
     $counter = 0;
@@ -594,7 +627,8 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
                             survey_question_option.sort as option_sort
                         FROM $table_survey_question survey_question
                         LEFT JOIN $table_survey_question_option survey_question_option
-                            ON survey_question.question_id = survey_question_option.question_id AND survey_question_option.c_id = $course_id
+                            ON survey_question.question_id = survey_question_option.question_id AND
+                            survey_question_option.c_id = $course_id
                         WHERE
                             survey_question.survey_id = '".Database :: escape_string($survey_invitation['survey_id'])."' AND
                             survey_question.question_id NOT IN (
@@ -621,7 +655,8 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
                             survey_question_option.sort as option_sort
                         FROM $table_survey_question survey_question
                         LEFT JOIN $table_survey_question_option survey_question_option
-                            ON survey_question.question_id = survey_question_option.question_id AND survey_question_option.c_id = $course_id
+                            ON survey_question.question_id = survey_question_option.question_id AND
+                            survey_question_option.c_id = $course_id
                         WHERE
                             survey_question.survey_id = '".intval($survey_invitation['survey_id'])."' AND
                             survey_question.question_id IN (".implode(',', $paged_questions[$_GET['show']]).") AND
@@ -675,9 +710,9 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
                     ON (survey_question.question_id = survey_answer.question_id)
                     WHERE
                         survey_answer.survey_id='".$my_survey_id."' AND
-                       survey_answer.user='".$current_user."' AND
-                       survey_answer.c_id = $course_id AND
-                       survey_question.c_id = $course_id AND
+                        survey_answer.user='".$current_user."' AND
+                        survey_answer.c_id = $course_id AND
+                        survey_question.c_id = $course_id AND
                     GROUP BY survey_group_pri
                     ORDER BY survey_group_pri
                     ";
@@ -1116,14 +1151,18 @@ $p_l = isset($_POST['language']) ? Security::remove_XSS($_POST['language']) : ''
 
 $add_parameters = isset($_GET['user_id']) ? 'user_id='.$_GET['user_id'].'&amp;' : '';
 
-echo '<form id="question" name="question" method="post" action="'.api_get_self().'?'.$add_parameters.'course='.$g_c.'&invitationcode='.$g_ic.'&show='.$show.'&cidReq='.$g_cr.'">';
-echo '<input type="hidden" name="language" value="'.$p_l.'" />';
+$url = api_get_self().'?'.$add_parameters.'course='.$g_c.'&invitationcode='.$g_ic.'&show='.$show.'&cidReq='.$g_cr;
+$form = new FormValidator('question', 'post', $url);
+$form->addHidden('language', $p_l);
 
 if (isset($questions) && is_array($questions)) {
     foreach ($questions as $key => & $question) {
         $ch_type = 'ch_'.$question['type'];
         $display = new $ch_type;
-        $display->render_question($question);
+        $form->addHtml('<div class="survey_question_wrapper"><div class="survey_question">');
+        $form->addHtml($question['survey_question']);
+        $display->render($form, $question);
+        $form->addHtml('</div></div>');
     }
 }
 
@@ -1132,13 +1171,16 @@ if ($survey_data['survey_type'] === '0') {
         // The normal survey as always
         if (($show < $numberofpages) || !$_GET['show']) { //$show = $_GET['show'] + 1
             if ($show == 0) {
-                echo '<button type="submit" name="next_survey_page" class="survey-next">'.get_lang('StartSurvey').'</button>';
+                $form->addButton('next_survey_page', get_lang('StartSurvey'), 'arrow-right', 'btn btn-success btn-large');
+//                echo '<button type="submit" name="next_survey_page" class="survey-next">'.get_lang('StartSurvey').'</button>';
             } else {
-                echo '<button type="submit" name="next_survey_page" class="survey-next">'.get_lang('Next').'</button>';
+                $form->addButton('next_survey_page', get_lang('Next'), 'arrow-right');
+                //echo '<button type="submit" name="next_survey_page" class="survey-next">'.get_lang('Next').'</button>';
             }
         }
         if ($show >= $numberofpages && $_GET['show']) {
-            echo '<button type="submit" name="finish_survey" class="survey-next">'.get_lang('FinishSurvey').'</button>';
+            $form->addButton('finish_survey', get_lang('FinishSurvey'), 'arrow-right');
+            //echo '<button type="submit" name="finish_survey" class="survey-next">'.get_lang('FinishSurvey').'</button>';
         }
     } else {
         // The normal survey as always but with the form profile
@@ -1146,14 +1188,17 @@ if ($survey_data['survey_type'] === '0') {
             $numberofpages = count($paged_questions);
             if (($show < $numberofpages) || !$_GET['show']) { //$show = $_GET['show'] + 1
                 if ($show == 0) {
-                    echo '<button type="submit" name="next_survey_page" class="next">'.get_lang('StartSurvey').'</button>';
+                    $form->addButton('next_survey_page', get_lang('StartSurvey'), 'arrow-right', 'btn btn-success btn-large');
+                    //echo '<button type="submit" name="next_survey_page" class="next">'.get_lang('StartSurvey').'</button>';
                 } else {
-                    echo '<button type="submit" name="next_survey_page" class="next">'.get_lang('Next').'</button>';
+                    $form->addButton('next_survey_page', get_lang('Next'), 'arrow-right');
+                    //echo '<button type="submit" name="next_survey_page" class="next">'.get_lang('Next').'</button>';
                 }
             }
 
             if ($show >= $numberofpages && $_GET['show']) {
-                echo '<button type="submit" name="finish_survey" class="next">'.get_lang('FinishSurvey').'</button>';
+                $form->addButton('finish_survey', get_lang('FinishSurvey'), 'arrow-right');
+                //echo '<button type="submit" name="finish_survey" class="next">'.get_lang('FinishSurvey').'</button>';
             }
         }
     }
@@ -1175,50 +1220,58 @@ if ($survey_data['survey_type'] === '0') {
 
         if ($personality == 0) {
             if (($show <= $numberofpages) || !$_GET['show']) {
-                echo '<button type="submit" name="next_survey_page" class="next">'.get_lang('Next').'</button>';
+                $form->addButton('next_survey_page', get_lang('Next'), 'arrow-right');
+                //echo '<button type="submit" name="next_survey_page" class="next">'.get_lang('Next').'</button>';
                 if ($survey_data['one_question_per_page'] == 0) {
                     if ($personality >= 0) {
-                        echo '<input type="hidden" name="personality" value="'.$personality.'">';
+                        $form->addHidden('personality', $personality);
+                        //echo '<input type="hidden" name="personality" value="'.$personality.'">';
                     }
                 } else {
                     if ($personality > 0) {
-                        echo '<input type="hidden" name="personality" value="'.$personality.'">';
+                        $form->addHidden('personality', $personality);
+                        //echo '<input type="hidden" name="personality" value="'.$personality.'">';
                     }
                 }
 
                 if ($numberofpages == $show) {
-                    echo '<input type="hidden" name="personality" value="'.$personality.'">';
+                    //echo '<input type="hidden" name="personality" value="'.$personality.'">';
+                    $form->addHidden('personality', $personality);
                 }
             }
         }
 
         if ($show > $numberofpages && $_GET['show'] && $personality == 0) {
-            echo '<input type="hidden" name="personality" value="'.$personality.'">';
+            //echo '<input type="hidden" name="personality" value="'.$personality.'">';
+            $form->addHidden('personality', $personality);
         } elseif ($personality > 0) {
             if ($survey_data['one_question_per_page'] == 1) {
                 if ($show >= $numberofpages) {
-                    echo '<button type="submit" name="finish_survey" class="next">'.get_lang('FinishSurvey').'</button>';
+                    $form->addButton('finish_survey', get_lang('FinishSurvey'), 'arrow-right');
+                    //echo '<button type="submit" name="finish_survey" class="next">'.get_lang('FinishSurvey').'</button>';
                 } else {
-                    echo '<input type="hidden" name="personality" value="'.$personality.'">';
-                    echo '<button type="submit" name="next_survey_page" class="next">'.get_lang('Next').'</button>';
+                    //echo '<input type="hidden" name="personality" value="'.$personality.'">';
+                    $form->addHidden('personality', $personality);
+                    //echo '<button type="submit" name="next_survey_page" class="next">'.get_lang('Next').'</button>';
+                    $form->addButton('next_survey_page', get_lang('Next'), 'arrow-right');
                 }
             } else {
                 // if the personality test hidden input was set.
-                echo '<button type="submit" name="finish_survey" class="next">'.get_lang('FinishSurvey').'</button>';
+                //echo '<button type="submit" name="finish_survey" class="next">'.get_lang('FinishSurvey').'</button>';
+                $form->addButton('finish_survey', get_lang('FinishSurvey'), 'arrow-right');
             }
         }
     } elseif ($survey_data['form_fields'] == '') {
         // This is the case when the show_profile_form is true but there are not form_fields
-        //echo '<input type="submit" name="next_survey_page" value="' . get_lang('Next') . ' " class="next" />';
-        echo '<button type="submit" name="next_survey_page" class="next">'.get_lang('Next').'</button>';
+        //echo '<button type="submit" name="next_survey_page" class="next">'.get_lang('Next').'</button>';
+        $form->addButton('next_survey_page', get_lang('Next'), 'arrow-right');
     } elseif (!is_array($user_data)) {
         // If the user is not registered in the platform we do not show the form to update his information
-        echo '<button type="submit" name="next_survey_page" class="next">'.get_lang('Next').'</button>';
+        //echo '<button type="submit" name="next_survey_page" class="next">'.get_lang('Next').'</button>';
+        $form->addButton('next_survey_page', get_lang('Next'), 'arrow-right');
     }
 }
-
-echo '</form>';
-echo '</div>';
+$form->display();
 
 // Footer
 Display :: display_footer();

+ 36 - 24
main/survey/preview.php

@@ -8,26 +8,23 @@
  *	@author Julio Montoya Armas <gugli100@gmail.com>, Chamilo: Personality Test modifications
  * 	@version $Id: survey_list.php 10680 2007-01-11 21:26:23Z pcool $
  *
- * 	@todo use quickforms for the forms
- * @todo security filter options better (Database::escape_string)
  */
 
 // Language file that needs to be included
 $language_file = 'survey';
 
 // Including the global initialization file
-require '../inc/global.inc.php';
-require_once 'survey.lib.php';
+require_once '../inc/global.inc.php';
 
 $this_section = SECTION_COURSES;
 
 // Database table definitions
-$table_survey 					= Database :: get_course_table(TABLE_SURVEY);
-$table_survey_question 			= Database :: get_course_table(TABLE_SURVEY_QUESTION);
-$table_survey_question_option 	= Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
-$table_course 					= Database :: get_main_table(TABLE_MAIN_COURSE);
-$table_user 					= Database :: get_main_table(TABLE_MAIN_USER);
-$table_survey_invitation        = Database :: get_course_table(TABLE_SURVEY_INVITATION);
+$table_survey = Database:: get_course_table(TABLE_SURVEY);
+$table_survey_question = Database:: get_course_table(TABLE_SURVEY_QUESTION);
+$table_survey_question_option = Database:: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
+$table_course = Database:: get_main_table(TABLE_MAIN_COURSE);
+$table_user = Database:: get_main_table(TABLE_MAIN_USER);
+$table_survey_invitation = Database:: get_course_table(TABLE_SURVEY_INVITATION);
 
 $course_id = api_get_course_int_id();
 $userId = api_get_user_id();
@@ -49,7 +46,7 @@ if (Database::num_rows($result) > 0) {
     $userInvited = 1;
 }
 
-// We exit here if ther is no valid $_GET parameter
+// We exit here if there is no valid $_GET parameter
 if (!isset($_GET['survey_id']) || !is_numeric($_GET['survey_id'])){
 	Display::display_header(get_lang('SurveyPreview'));
 	Display::display_error_message(get_lang('InvallidSurvey'), false);
@@ -70,7 +67,7 @@ if (empty($survey_data)) {
 
 $urlname = strip_tags($survey_data['title']);
 if (api_is_allowed_to_edit()) {
-        // Breadcrumbs
+	// Breadcrumbs
 	$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
 	$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id, 'name' => $urlname);
 }
@@ -99,7 +96,10 @@ if (!api_is_allowed_to_edit(false, true)) {
 
 $counter_question = 0;
 // Only a course admin is allowed to preview a survey: you are a course admin
-if (api_is_course_admin() || (api_is_course_admin() && $_GET['isStudentView'] == 'true') || api_is_allowed_to_session_edit(false, true)) {
+if (api_is_course_admin() ||
+	(api_is_course_admin() && $_GET['isStudentView'] == 'true') ||
+	api_is_allowed_to_session_edit(false, true)
+) {
 	// Survey information
 	echo '<div id="survey_title">'.$survey_data['survey_title'].'</div>';
 	echo '<div id="survey_subtitle">'.$survey_data['survey_subtitle'].'</div>';
@@ -123,7 +123,8 @@ if (api_is_course_admin() || (api_is_course_admin() && $_GET['isStudentView'] ==
     $questions = array();
 
 	if (isset($_GET['show'])) {
-		// Getting all the questions for this page and add them to a multidimensional array where the first index is the page.
+		// Getting all the questions for this page and add them to a
+		// multidimensional array where the first index is the page.
 		// as long as there is no pagebreak fount we keep adding questions to the page
 		$questions_displayed = array();
 		$paged_questions = array();
@@ -159,7 +160,9 @@ if (api_is_course_admin() || (api_is_course_admin() && $_GET['isStudentView'] ==
 						survey_question_option.sort as option_sort
 					FROM $table_survey_question survey_question
 					LEFT JOIN $table_survey_question_option survey_question_option
-					ON survey_question.question_id = survey_question_option.question_id AND survey_question_option.c_id = $course_id
+					ON
+						survey_question.question_id = survey_question_option.question_id AND
+						survey_question_option.c_id = $course_id
 					WHERE
 					    survey_question.survey_id = '".intval($survey_id)."' AND
 						survey_question.question_id IN (".Database::escape_string(implode(',',$paged_questions[$_GET['show']]), null, false).") AND
@@ -179,9 +182,8 @@ if (api_is_course_admin() || (api_is_course_admin() && $_GET['isStudentView'] ==
 					$questions[$row['sort']]['type'] = $row['type'];
 					$questions[$row['sort']]['options'][intval($row['option_sort'])] = $row['option_text'];
 					$questions[$row['sort']]['maximum_score'] = $row['max_value'];
-				}
-				// If the type is a pagebreak we are finished loading the questions for this page
-				else {
+				} else {
+					// If the type is a pagebreak we are finished loading the questions for this page
 					break;
 				}
 				$counter_question++;
@@ -197,6 +199,7 @@ if (api_is_course_admin() || (api_is_course_admin() && $_GET['isStudentView'] ==
 	            survey_id='".intval($survey_id)."'";
 	$result = Database::query($sql);
 	$numberofpages = Database::num_rows($result) + 1;
+
 	// Displaying the form with the questions
 	if (isset($_GET['show'])) {
 		$show = (int)$_GET['show'] + 1;
@@ -204,30 +207,39 @@ if (api_is_course_admin() || (api_is_course_admin() && $_GET['isStudentView'] ==
 		$show = 0;
 	}
 
-	echo '<form id="question" name="question" method="post" action="'.api_get_self().'?survey_id='.Security::remove_XSS($survey_id).'&show='.$show.'">';
+	$url = api_get_self().'?survey_id='.Security::remove_XSS($survey_id).'&show='.$show;
+	$form = new FormValidator('question', 'post', $url);
+
 
 	if (is_array($questions) && count($questions) > 0) {
 		foreach ($questions as $key => & $question) {
 			$ch_type = 'ch_'.$question['type'];
+			/** @var survey_question $display */
 			$display = new $ch_type;
-			$display->render_question($question);
+			$form->addHtml('<div class="survey_question_wrapper"><div class="survey_question">');
+			$form->addHtml($question['survey_question']);
+			$display->render($form, $question);
+			$form->addHtml('</div></div>');
 		}
 	}
 
 	if (($show < $numberofpages) || (!$_GET['show'] && count($questions) > 0)) {
         if ($show == 0) {
-            echo '<br /><button type="submit" name="next_survey_page" class="next">'.get_lang('StartSurvey').'   </button>';
+			$form->addButton('next_survey_page', get_lang('StartSurvey'), 'arrow-right', 'btn btn-success btn-large');
+            //echo '<br /><button type="submit" name="next_survey_page" class="next">'.get_lang('StartSurvey').'   </button>';
         } else {
-		    echo '<br /><button type="submit" name="next_survey_page" class="next">'.get_lang('NextQuestion').'   </button>';
+			$form->addButton('next_survey_page', get_lang('NextQuestion'), 'arrow-right');
+		    //echo '<br /><button type="submit" name="next_survey_page" class="next">'.get_lang('NextQuestion').'   </button>';
         }
 	}
 	if ($show >= $numberofpages && $_GET['show'] || (isset($_GET['show']) && count($questions) == 0)) {
 		if ($questions_exists == false) {
 			echo '<p>'.get_lang('ThereAreNotQuestionsForthisSurvey').'</p>';
 		}
-		echo '<button type="submit" name="finish_survey" class="next">'.get_lang('FinishSurvey').'  </button>';
+		$form->addButton('finish_survey', get_lang('FinishSurvey'), 'arrow-right');
+		//echo '<button type="submit" name="finish_survey" class="next">'.get_lang('FinishSurvey').'  </button>';
 	}
-	echo '</form>';
+	$form->display();
 } else {
 	Display :: display_error_message(get_lang('NotAllowed'), false);
 }

+ 72 - 84
main/survey/question.php

@@ -14,9 +14,6 @@ $language_file = 'survey';
 // Including the global initialization file
 require_once '../inc/global.inc.php';
 
-// Including additional libraries
-require_once 'survey.lib.php';
-
 $htmlHeadXtra[] = '<script>
 $(document).ready( function() {
     $("button").click(function() {
@@ -34,7 +31,7 @@ if (!api_is_allowed_to_edit(false, true)) {
 
 // Is valid request
 $is_valid_request = isset($_REQUEST['is_executable']) ? $_REQUEST['is_executable'] : null;
-if ($request_index != $is_valid_request) {
+/*if ($request_index != $is_valid_request) {
 	if ($request_index == 'save_question') {
 		unset($_POST[$request_index]);
 	} elseif ($request_index == 'add_answer') {
@@ -42,33 +39,34 @@ if ($request_index != $is_valid_request) {
 	} elseif($request_index == 'remove_answer') {
 		unset($_POST[$request_index]);
 	}
-}
+}*/
 
 // Database table definitions
-$table_survey 					= Database :: get_course_table(TABLE_SURVEY);
-$table_survey_question 			= Database :: get_course_table(TABLE_SURVEY_QUESTION);
-$table_survey_question_option 	= Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
+$table_survey = Database:: get_course_table(TABLE_SURVEY);
+$table_survey_question = Database:: get_course_table(TABLE_SURVEY_QUESTION);
+$table_survey_question_option = Database:: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
 
-$table_course 					= Database :: get_main_table(TABLE_MAIN_COURSE);
-$table_user 					= Database :: get_main_table(TABLE_MAIN_USER);
+$table_course = Database:: get_main_table(TABLE_MAIN_COURSE);
+$table_user = Database:: get_main_table(TABLE_MAIN_USER);
 
 $course_id = api_get_course_int_id();
 
 // Getting the survey information
-$survey_data = survey_manager::get_survey($_GET['survey_id']);
-if (empty($survey_data)) {
+$surveyData = survey_manager::get_survey($_GET['survey_id']);
+
+if (empty($surveyData)) {
 	Display :: display_header(get_lang('ToolSurvey'));
 	Display :: display_error_message(get_lang('InvallidSurvey'), false);
 	Display :: display_footer();
 	exit;
 }
 
-$urlname = api_substr(api_html_entity_decode($survey_data['title'], ENT_QUOTES), 0, 40);
-if (api_strlen(strip_tags($survey_data['title'])) > 40) {
+$urlname = api_substr(api_html_entity_decode($surveyData['title'], ENT_QUOTES), 0, 40);
+if (api_strlen(strip_tags($surveyData['title'])) > 40) {
 	$urlname .= '...';
 }
 
-if ($survey_data['survey_type'] == 1) {
+if ($surveyData['survey_type'] == 1) {
 	$sql = 'SELECT id FROM '.Database :: get_course_table(TABLE_SURVEY_QUESTION_GROUP).'
 	        WHERE
                 c_id = '.$course_id.' AND
@@ -108,7 +106,8 @@ $possible_types = array(
 
 // Actions
 $actions = '<div class="actions">';
-$actions .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.Security::remove_XSS($_GET['survey_id']).'">'.Display::return_icon('back.png', get_lang('BackToSurvey'),'',ICON_SIZE_MEDIUM).'</a>';
+$actions .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.Security::remove_XSS($_GET['survey_id']).'">'.
+	Display::return_icon('back.png', get_lang('BackToSurvey'),'',ICON_SIZE_MEDIUM).'</a>';
 $actions .= '</div>';
 // Checking if it is a valid type
 if (!in_array($_GET['type'], $possible_types)) {
@@ -121,82 +120,71 @@ if (!in_array($_GET['type'], $possible_types)) {
 $error_message = '';
 
 // Displaying the form for adding or editing the question
-if (empty($_POST['save_question']) && in_array($_GET['type'], $possible_types)) {
-	if (!isset($_POST['save_question'])) {
-		// Displaying the header
-		Display::display_header($tool_name, 'Survey');
-		echo $actions;
-		// Displys message if exists
-		if (isset($_SESSION['temp_sys_message'])) {
-			$error_message = $_SESSION['temp_sys_message'];
-			unset($_SESSION['temp_sys_message']);
-			if ($error_message == 'PleaseEnterAQuestion' ||
-                $error_message == 'PleasFillAllAnswer'||
-                $error_message == 'PleaseChooseACondition'||
-                $error_message == 'ChooseDifferentCategories'
-            ) {
-				Display::display_error_message(get_lang($error_message), true);
-			}
-		}
-	}
-	$ch_type = 'ch_'.$_GET['type'];
-	$form = new $ch_type;
 
-	// The defaults values for the form
-	$form_content['answers'] = array('', '');
-
-	if ($_GET['type'] == 'yesno') {
-		$form_content['answers'][0] = get_lang('Yes');
-		$form_content['answers'][1] = get_lang('No');
-	}
-
-	if ($_GET['type'] == 'personality') {
-		$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;
+/*if (!isset($_POST['save_question'])) {
+	// Displaying the header
+	Display::display_header($tool_name, 'Survey');
+	echo $actions;
+	// Displys message if exists
+	if (isset($_SESSION['temp_sys_message'])) {
+		$error_message = $_SESSION['temp_sys_message'];
+		unset($_SESSION['temp_sys_message']);
+		if ($error_message == 'PleaseEnterAQuestion' ||
+			$error_message == 'PleasFillAllAnswer'||
+			$error_message == 'PleaseChooseACondition'||
+			$error_message == 'ChooseDifferentCategories'
+		) {
+			Display::display_error_message(get_lang($error_message), true);
+		}
 	}
+}*/
+$ch_type = 'ch_'.$_GET['type'];
+/** @var survey_question $surveyQuestion */
+$surveyQuestion = new $ch_type;
+
+// The defaults values for the form
+$formData = array();
+$formData['answers'] = array('', '');
+
+if ($_GET['type'] == 'yesno') {
+	$formData['answers'][0] = get_lang('Yes');
+	$formData['answers'][1] = get_lang('No');
+}
 
-	// We are editing a question
-	if (isset($_GET['question_id']) && !empty($_GET['question_id'])) {
-		$form_content = survey_manager::get_question($_GET['question_id']);
-	}
+if ($_GET['type'] == 'personality') {
+	$formData['answers'][0] = 1;
+	$formData['answers'][1] = 2;
+	$formData['answers'][2] = 3;
+	$formData['answers'][3] = 4;
+	$formData['answers'][4] = 5;
+
+	$formData['values'][0] = 0;
+	$formData['values'][1] = 0;
+	$formData['values'][2] = 1;
+	$formData['values'][3] = 2;
+	$formData['values'][4] = 3;
+}
 
-	// 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
-        );
-	}
+// We are editing a question
+if (isset($_GET['question_id']) && !empty($_GET['question_id'])) {
+	$formData = survey_manager::get_question($_GET['question_id']);
+}
 
-	if ($error_message != '') {
-		$form_content['question'] = $_SESSION['temp_user_message'];
-		$form_content['answers'] = $_SESSION['temp_answers'];
-		$form_content['values'] = $_SESSION['temp_values'];
-		$form_content['horizontalvertical'] = $_SESSION['temp_horizontalvertical'];
+$formData = $surveyQuestion->preAction($formData);
 
-		unset($_SESSION['temp_user_message']);
-		unset($_SESSION['temp_answers']);
-		unset($_SESSION['temp_values']);
-		unset($_SESSION['temp_horizontalvertical']);
-	}
+$surveyQuestion->create_form($surveyData, $formData);
+$surveyQuestion->getForm()->setDefaults($formData);
+$surveyQuestion->render_form();
 
-	$form->create_form($survey_data, $form_content);
-	$form->render_form();
-} else {
-	$form_content = $_POST;
-	$form = new survey_question();
-	$form->handle_action($survey_data, $form_content);
+if ($surveyQuestion->getForm()->validate()) {
+	$values = $surveyQuestion->getForm()->getSubmitValues();
+	$surveyQuestion->handle_action($surveyData, $values);
 }
 
+Display::display_header($tool_name, 'Survey');
+$surveyQuestion->getForm()->setDefaults($formData);
+
+echo $surveyQuestion->getForm()->return_form();
 // Footer
+
 Display :: display_footer();

File diff suppressed because it is too large
+ 36 - 980
main/survey/survey.lib.php


+ 5 - 3
main/survey/survey.php

@@ -4,11 +4,11 @@
 /**
  *	@package chamilo.survey
  *	@author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
- * 	@version $Id: survey.php 22573 2009-08-03 03:38:13Z yannoo $
- *
- * 	@todo use quickforms for the forms
+ *  @author Julio Montoya
  */
 
+use ChamiloSession as Session;
+
 // Language file that needs to be included
 $language_file = 'survey';
 
@@ -296,5 +296,7 @@ if ($is_survey_type_1) {
 	echo $grouplist.'</table>';
 }
 
+Session::erase('answer_count');
+
 // Footer
 Display :: display_footer();

+ 2 - 15
main/survey/survey_invite.php

@@ -74,7 +74,8 @@ $(function() {
 
 // Checking if there is another survey with this code.
 // If this is the case there will be a language choice
-$sql = "SELECT * FROM $table_survey WHERE c_id = $course_id AND code='".Database::escape_string($survey_data['code'])."'";
+$sql = "SELECT * FROM $table_survey
+		WHERE c_id = $course_id AND code='".Database::escape_string($survey_data['code'])."'";
 $result = Database::query($sql);
 if (Database::num_rows($result) > 1) {
 	Display::display_warning_message(get_lang('IdenticalSurveycodeWarning'));
@@ -105,20 +106,6 @@ foreach ($complete_user_list as & $user) {
 	$possible_users[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']);
 }
 $users = $form->addElement('advmultiselect', 'course_users', get_lang('CourseUsers'), $possible_users, 'style="width: 250px; height: 200px;"');
-$users->setElementTemplate('
-{javascript}
-<table{class}>
-<!-- BEGIN label_2 --><tr><th>{label_2}</th><!-- END label_2 -->
-<!-- BEGIN label_3 --><th>&nbsp;</th><th>{label_3}</th></tr><!-- END label_3 -->
-<tr>
-  <td valign="top">{unselected}</td>
-  <td align="center">{add}<br /><br />{remove}</td>
-  <td valign="top">{selected}</td>
-</tr>
-</table>
-');
-$users->setButtonAttributes('add', array('class' => 'btn arrowr'));
-$users->setButtonAttributes('remove', array('class' => 'btn arrowl'));
 
 // Additional users
 $form->addElement('textarea', 'additional_users', array(get_lang('AdditonalUsers'), get_lang('AdditonalUsersComment')), array('class' => 'span6', 'rows' => 5));

+ 299 - 0
main/survey/survey_question.php

@@ -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;
+    }
+}
+

+ 14 - 0
src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/Survey.php

@@ -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
+{
+
+}

+ 14 - 0
src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/SurveyQuestion.php

@@ -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
+{
+
+}

Some files were not shown because too many files changed in this diff