Bladeren bron

Add survey meeting see BT#14957

Julio Montoya 6 jaren geleden
bovenliggende
commit
c7a0dfe326

+ 1 - 1
main/inc/lib/formvalidator/Element/DateTimePicker.php

@@ -45,7 +45,7 @@ class DateTimePicker extends HTML_QuickForm_text
         $resetFieldX = sprintf(get_lang('ResetFieldX'), $label);
 
         return '
-            <div class="input-group">
+            <div class="input-group" id="date_time_wrapper_'.$id.'">
                 <span class="input-group-addon cursor-pointer">
                     <input '.$this->_getAttrString($this->_attributes).'>
                 </span>

+ 20 - 3
main/inc/lib/formvalidator/FormValidator.class.php

@@ -16,7 +16,8 @@ class FormValidator extends HTML_QuickForm
     private $layout;
 
     /**
-     * Constructor
+     * Constructor.
+     *
      * @param string $name Name of the form
      * @param string $method (optional) Method ('post' (default) or 'get')
      * @param string $action (optional) Action (default is $PHP_SELF)
@@ -126,6 +127,7 @@ EOT;
 
     /**
      * @todo this function should be added in the element class
+     *
      * @return string
      */
     public function getDefaultElementTemplate()
@@ -244,6 +246,7 @@ EOT;
      * @param string $label
      * @param array $options
      * @param array $attributes
+     *
      * @throws
      */
     public function addSelectAjax($name, $label, $options = [], $attributes = [])
@@ -272,19 +275,33 @@ EOT;
         return $this->addElement('DateTimePicker', $name, $label, $attributes);
     }
 
+    /**
+     * @param string $name
+     * @param string $label
+     * @param array  $attributes
+     *
+     * @return HTML_QuickForm_element
+     */
+    public function addDateTimeRangePicker($name, $label, $attributes = [])
+    {
+        return $this->addElement('DateTimeRangePicker', $name, $label, $attributes);
+    }
+
     /**
      * @param string $name
      * @param string $value
+     * @param array  $attributes
      */
-    public function addHidden($name, $value)
+    public function addHidden($name, $value, $attributes = [])
     {
-        $this->addElement('hidden', $name, $value);
+        $this->addElement('hidden', $name, $value, $attributes);
     }
 
     /**
      * @param string $name
      * @param string $label
      * @param array  $attributes
+     * @param bool   $required
      *
      * @return HTML_QuickForm_textarea
      */

+ 38 - 8
main/survey/fillsurvey.php

@@ -97,7 +97,7 @@ if ($invitationcode == 'auto' && isset($_GET['scode'])) {
     // Survey_code of the survey
     $surveyCode = $_GET['scode'];
     if ($isAnonymous) {
-        $autoInvitationcode = "auto-ANONY_".md5(time())."-$surveyCode";
+        $autoInvitationcode = 'auto-ANONY_'.md5(time())."-$surveyCode";
     } else {
         // New invitation code from userid
         $autoInvitationcode = "auto-$userid-$surveyCode";
@@ -204,6 +204,14 @@ if (empty($survey_data)) {
 }
 $survey_data['survey_id'] = $survey_invitation['survey_id'];
 
+if ($survey_data['survey_type'] == '3') {
+    header('Location: '.
+        api_get_path(WEB_CODE_PATH).
+        'survey/meeting.php?cidReq='.$courseInfo['code'].'&id_session='.$sessionId.'&invitationcode='.Security::remove_XSS($invitationcode)
+    );
+    exit;
+}
+
 // Storing the answers
 if (count($_POST) > 0) {
     if ($survey_data['survey_type'] === '0') {
@@ -655,6 +663,7 @@ if (
         if (empty($paged_questions)) {
             $sql = "SELECT * FROM $table_survey_question
                     WHERE
+                        survey_question NOT LIKE '%{{%' AND 
                         c_id = $course_id AND 
                         survey_id = '".intval($survey_invitation['survey_id'])."'
                     ORDER BY sort ASC";
@@ -734,7 +743,8 @@ if (
                         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
-                        WHERE
+                        WHERE                        
+                            survey_question NOT LIKE '%{{%' AND
                             survey_question.survey_id = '".intval($survey_invitation['survey_id'])."' AND
                             survey_question.question_id IN (".implode(',', $paged_questions[$_GET['show']]).") AND
                             survey_question.c_id =  $course_id
@@ -766,7 +776,7 @@ if (
             }
         }
     } elseif ($survey_data['survey_type'] === '1') {
-        $my_survey_id = intval($survey_invitation['survey_id']);
+        $my_survey_id = (int) $survey_invitation['survey_id'];
         $current_user = Database::escape_string($survey_invitation['user']);
 
         if (isset($_POST['personality'])) {
@@ -779,7 +789,10 @@ if (
             $answer_list = [];
             // Get current user results
             $results = [];
-            $sql = "SELECT survey_group_pri, user, SUM(value) as value
+            $sql = "SELECT 
+                      survey_group_pri, 
+                      user, 
+                      SUM(value) as value
                     FROM $table_survey_answer as survey_answer
                     INNER JOIN $table_survey_question as survey_question
                     ON (survey_question.question_id = survey_answer.question_id)
@@ -799,7 +812,6 @@ if (
                 $results[] = $answer_list;
             }
 
-            //echo '<br />'; print_r($results); echo '<br />';
             // Get the total score for each group of questions
             $totals = [];
             $sql = "SELECT SUM(temp.value) as value, temp.survey_group_pri FROM
@@ -1016,6 +1028,7 @@ if (
                                 ON survey_question.question_id = survey_question_option.question_id AND
                                 survey_question_option.c_id = $course_id
                                 WHERE
+                                    survey_question NOT LIKE '%{{%' AND 
                                     survey_question.survey_id = '".$my_survey_id."' AND
                                     survey_question.c_id = $course_id AND
                                     survey_question.question_id IN (".implode(',', $paged_questions_sec[$val]).")
@@ -1126,6 +1139,7 @@ if (
                             ON survey_question.question_id = survey_question_option.question_id AND
                             survey_question_option.c_id = $course_id
                             WHERE
+                                survey_question NOT LIKE '%{{%' AND 
                                 survey_question.survey_id = '".intval($survey_invitation['survey_id'])."' AND
                                 survey_question.c_id = $course_id  AND
                                 survey_question.question_id IN (".$imploded.")
@@ -1170,9 +1184,9 @@ if (
 
 // Selecting the maximum number of pages
 $sql = "SELECT * FROM $table_survey_question
-        WHERE
+        WHERE        
             c_id = $course_id AND
-            type = '".Database::escape_string('pagebreak')."' AND
+            type = 'pagebreak' AND
             survey_id='".intval($survey_invitation['survey_id'])."'";
 $result = Database::query($sql);
 $numberofpages = Database::num_rows($result) + 1;
@@ -1224,12 +1238,27 @@ $form = new FormValidator(
 $form->addHidden('language', $p_l);
 
 if (isset($questions) && is_array($questions)) {
+    $originalShow = isset($_GET['show']) ? (int) $_GET['show'] : 0;
+
+    $questionCounter = 1;
+    if (!empty($originalShow)) {
+        $before = 0;
+        foreach ($paged_questions as $keyQuestion => $list) {
+            if ($originalShow > $keyQuestion) {
+                $before += count($list);
+            }
+        }
+        $questionCounter = $before + 1;
+    }
+
     foreach ($questions as $key => &$question) {
         $ch_type = 'ch_'.$question['type'];
+        //$questionNumber = $question['sort'];
+        $questionNumber = $questionCounter;
         $display = new $ch_type();
         // @todo move this in a function.
         $form->addHtml('<div class="survey_question '.$ch_type.'">');
-        $form->addHtml('<h5 class="title">'.$question['sort'].'. '.strip_tags($question['survey_question']).'</h5>');
+        $form->addHtml('<h5 class="title">'.$questionNumber.'. '.strip_tags($question['survey_question']).'</h5>');
         $userAnswerData = SurveyUtil::get_answers_of_question_by_user($question['survey_id'], $question['question_id']);
         $finalAnswer = null;
 
@@ -1256,6 +1285,7 @@ if (isset($questions) && is_array($questions)) {
         }
         $display->render($form, $question, $finalAnswer);
         $form->addHtml('</div>');
+        $questionCounter++;
     }
 }
 

+ 58 - 27
main/survey/preview.php

@@ -5,8 +5,8 @@
  * @package chamilo.survey
  *
  * @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 modifications
+ * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting code
+ * @author Julio Montoya <gugli100@gmail.com>, Chamilo: Personality Test modifications
  *
  * @version $Id: survey_list.php 10680 2007-01-11 21:26:23Z pcool $
  */
@@ -25,7 +25,7 @@ $table_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
 $course_id = api_get_course_int_id();
 $courseInfo = $course_id ? api_get_course_info_by_id($course_id) : [];
 $userId = api_get_user_id();
-$surveyId = intval($_GET['survey_id']);
+$surveyId = (int) $_GET['survey_id'];
 $userInvited = 0;
 $userAnonymous = 0;
 
@@ -49,12 +49,10 @@ if (!isset($_GET['survey_id']) || !is_numeric($_GET['survey_id'])) {
         true,
         Display::return_message(get_lang('InvallidSurvey'), 'error', false)
     );
-    exit;
 }
 
 // Getting the survey information
-$survey_id = intval($_GET['survey_id']);
-$survey_data = SurveyManager::get_survey($survey_id);
+$survey_data = SurveyManager::get_survey($surveyId);
 
 if (empty($survey_data)) {
     api_not_allowed(
@@ -71,12 +69,12 @@ if (api_is_allowed_to_edit()) {
         'name' => get_lang('SurveyList'),
     ];
     $interbreadcrumb[] = [
-        'url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&'.api_get_cidreq(),
+        'url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$surveyId.'&'.api_get_cidreq(),
         'name' => $urlname,
     ];
 }
 $courseCode = isset($_GET['cidReq']) ? $_GET['cidReq'] : null;
-$surveyAnonymous = SurveyManager::get_survey($survey_id, 0, $courseCode);
+$surveyAnonymous = SurveyManager::get_survey($surveyId, 0, $courseCode);
 $surveyAnonymous = $surveyAnonymous['anonymous'];
 if ($surveyAnonymous == 0 && api_is_anonymous()) {
     api_not_allowed(true);
@@ -85,11 +83,11 @@ if ($surveyAnonymous == 0 && api_is_anonymous()) {
         api_not_allowed(true);
     }
 }
-// Header
+
 Display::display_header(get_lang('SurveyPreview'));
 
 // We exit here is the first or last question is a pagebreak (which causes errors)
-SurveyUtil::check_first_last_question($survey_id, false);
+SurveyUtil::check_first_last_question($surveyId, false);
 $counter_question = 0;
 // Only a course admin is allowed to preview a survey: you are a course admin
 if (api_is_course_admin() ||
@@ -114,7 +112,7 @@ if (api_is_course_admin() ||
     if (isset($_POST['finish_survey'])) {
         echo Display::return_message(get_lang('SurveyFinished'), 'confirm');
         echo $survey_data['survey_thanks'];
-        Display :: display_footer();
+        Display::display_footer();
         exit;
     }
 
@@ -127,7 +125,10 @@ if (api_is_course_admin() ||
         $paged_questions = [];
         $counter = 0;
         $sql = "SELECT * FROM $table_survey_question
-                WHERE c_id = $course_id AND survey_id = '".$survey_id."'
+                WHERE
+                  survey_question NOT LIKE '%{{%' AND 
+                  c_id = $course_id AND 
+                  survey_id = '".$surveyId."'
                 ORDER BY sort ASC";
         $result = Database::query($sql);
         $questions_exists = true;
@@ -143,6 +144,16 @@ if (api_is_course_admin() ||
             $questions_exists = false;
         }
 
+        $sql = "SELECT count(survey_question.question_id) as count                        
+                FROM $table_survey_question survey_question
+                WHERE 
+                  survey_question.survey_id = '".$surveyId."' AND
+                  survey_question.c_id = $course_id AND 
+                  survey_question LIKE '%{{%' ";
+        $result = Database::query($sql);
+        $sourceQuestions = Database::fetch_array($result, 'ASSOC');
+        $sourceQuestions = $sourceQuestions['count'];
+
         if (array_key_exists($_GET['show'], $paged_questions)) {
             $sql = "SELECT
                         survey_question.question_id,
@@ -161,24 +172,27 @@ if (api_is_course_admin() ||
                         survey_question.question_id = survey_question_option.question_id AND
                         survey_question_option.c_id = $course_id
                     WHERE
-                        survey_question.survey_id = '".$survey_id."' AND
+                        survey_question.survey_id = '".$surveyId."' AND
                         survey_question.question_id IN (".Database::escape_string(implode(',', $paged_questions[$_GET['show']]), null, false).") AND
-                        survey_question.c_id =  $course_id
+                        survey_question.c_id = $course_id AND
+                        survey_question NOT LIKE '%{{%'                        
                     ORDER BY survey_question.sort, survey_question_option.sort ASC";
 
             $result = Database::query($sql);
             $question_counter_max = Database::num_rows($result);
             $limit = 0;
+
             while ($row = Database::fetch_array($result)) {
                 // If the type is not a pagebreak we store it in the $questions array
                 if ($row['type'] != 'pagebreak') {
-                    $questions[$row['sort']]['question_id'] = $row['question_id'];
-                    $questions[$row['sort']]['survey_id'] = $row['survey_id'];
-                    $questions[$row['sort']]['survey_question'] = $row['survey_question'];
-                    $questions[$row['sort']]['display'] = $row['display'];
-                    $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'];
+                    $sort = $row['sort'];
+                    $questions[$sort]['question_id'] = $row['question_id'];
+                    $questions[$sort]['survey_id'] = $row['survey_id'];
+                    $questions[$sort]['survey_question'] = $row['survey_question'];
+                    $questions[$sort]['display'] = $row['display'];
+                    $questions[$sort]['type'] = $row['type'];
+                    $questions[$sort]['options'][intval($row['option_sort'])] = $row['option_text'];
+                    $questions[$sort]['maximum_score'] = $row['max_value'];
                 } else {
                     // If the type is a pagebreak we are finished loading the questions for this page
                     break;
@@ -188,23 +202,29 @@ if (api_is_course_admin() ||
         }
     }
 
+    $before = 0;
+    if (isset($_GET['show']) && isset($paged_questions[$_GET['show'] -1])) {
+        $before = count($paged_questions[$_GET['show'] -1]);
+    }
+
     // Selecting the maximum number of pages
     $sql = "SELECT * FROM $table_survey_question
             WHERE
+                survey_question NOT LIKE '%{{%' AND 
                 c_id = $course_id AND
-                type = '".Database::escape_string('pagebreak')."' AND
-                survey_id = '".$survey_id."'";
+                type = 'pagebreak' AND
+                survey_id = '".$surveyId."'";
     $result = Database::query($sql);
     $numberofpages = Database::num_rows($result) + 1;
 
     // Displaying the form with the questions
+    $show = 0;
     if (isset($_GET['show'])) {
         $show = (int) $_GET['show'] + 1;
-    } else {
-        $show = 0;
     }
+    $originalShow = isset($_GET['show']) ? (int) $_GET['show'] : 0;
 
-    $url = api_get_self().'?survey_id='.$survey_id.'&show='.$show;
+    $url = api_get_self().'?survey_id='.$surveyId.'&show='.$show.'&'.api_get_cidreq();
     $form = new FormValidator(
         'question-survey',
         'post',
@@ -215,14 +235,25 @@ if (api_is_course_admin() ||
     );
 
     if (is_array($questions) && count($questions) > 0) {
+        $counter = 1;
+        if (!empty($originalShow)) {
+            $before = 0;
+            foreach ($paged_questions as $keyQuestion => $list) {
+                if ($originalShow > $keyQuestion) {
+                    $before += count($list);
+                }
+            }
+            $counter = $before + 1;
+        }
         foreach ($questions as $key => &$question) {
             $ch_type = 'ch_'.$question['type'];
             /** @var survey_question $display */
             $display = new $ch_type();
             $form->addHtml('<div class="survey_question '.$ch_type.'">');
-            $form->addHtml('<h5 class="title">'.$key.'. '.strip_tags($question['survey_question']).'</h5>');
+            $form->addHtml('<h5 class="title">'.$counter.'. '.strip_tags($question['survey_question']).'</h5>');
             $display->render($form, $question);
             $form->addHtml('</div>');
+            $counter++;
         }
     }
     $form->addHtml('<div class="start-survey">');

+ 23 - 20
main/survey/question.php

@@ -100,7 +100,7 @@ if (!in_array($_GET['type'], $possible_types)) {
     Display :: display_header($tool_name, 'Survey');
     echo $actions;
     echo Display::return_message(get_lang('TypeDoesNotExist'), 'error', false);
-    Display :: display_footer();
+    Display::display_footer();
 }
 
 $error_message = '';
@@ -115,24 +115,29 @@ $surveyQuestion = new $ch_type();
 $formData = [];
 $formData['answers'] = ['', ''];
 
-if ($_GET['type'] == 'yesno') {
-    $formData['answers'][0] = get_lang('Yes');
-    $formData['answers'][1] = get_lang('No');
+switch ($_GET['type']) {
+    case 'yesno':
+        $formData['answers'][0] = get_lang('Yes');
+        $formData['answers'][1] = get_lang('No');
+        break;
+    case '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;
+        break;
+    case 'open':
+        Display::addFlash(Display::return_message(get_lang('QuestionTags')));
+        break;
 }
 
-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;
-}
 
 // We are editing a question
 if (isset($_GET['question_id']) && !empty($_GET['question_id'])) {
@@ -150,7 +155,5 @@ if ($surveyQuestion->getForm()->validate()) {
 }
 
 Display::display_header($tool_name, 'Survey');
-
 echo $surveyQuestion->getForm()->returnForm();
-
-Display :: display_footer();
+Display::display_footer();

+ 1 - 2
main/survey/reporting.php

@@ -45,7 +45,6 @@ if (!api_is_allowed_to_edit(false, true) || $isDrhOfCourse) {
     // Show error message if the survey can be seen only by tutors
     if ($survey_data['visible_results'] == SURVEY_VISIBLE_TUTOR) {
         api_not_allowed(true);
-        exit;
     }
 
     Display::display_header(get_lang('ToolSurvey'));
@@ -125,7 +124,7 @@ if ($action == 'overview') {
     ];
     switch ($action) {
         case 'questionreport':
-            $singlePage = isset($_GET['single_page']) ? intval($_GET['single_page']) : 0;
+            $singlePage = isset($_GET['single_page']) ? (int) $_GET['single_page'] : 0;
             $tool_name = $singlePage ? get_lang('QuestionsOverallReport') : get_lang('DetailedReportByQuestion');
             break;
         case 'userreport':

+ 157 - 29
main/survey/survey.lib.php

@@ -355,6 +355,10 @@ class SurveyManager
                 'visible_results' => $values['visible_results'],
             ];
 
+            if (isset($values['survey_type']) && !empty($values['survey_type'])) {
+                $params['survey_type'] = $values['survey_type'];
+            }
+
             $params = array_merge($params, $extraParams);
             $survey_id = Database::insert($table_survey, $params);
             if ($survey_id > 0) {
@@ -710,8 +714,7 @@ class SurveyManager
             $params['session_id'] = api_get_session_id();
             $params['title'] = $params['title'].' '.get_lang('Copy');
             unset($params['iid']);
-            Database::insert($table_survey, $params);
-            $new_survey_id = Database::insert_id();
+            $new_survey_id = Database::insert($table_survey, $params);
 
             if ($new_survey_id) {
                 $sql = "UPDATE $table_survey SET survey_id = $new_survey_id
@@ -732,7 +735,7 @@ class SurveyManager
         }
 
         $sql = "SELECT * FROM $table_survey_question_group
-                WHERE c_id = $course_id AND  survey_id='".$survey_id."'";
+                WHERE c_id = $course_id AND survey_id='".$survey_id."'";
         $res = Database::query($sql);
         while ($row = Database::fetch_array($res, 'ASSOC')) {
             $params = [
@@ -772,7 +775,6 @@ class SurveyManager
             $insertId = Database::insert($table_survey_question, $params);
             $sql = "UPDATE $table_survey_question SET question_id = iid WHERE iid = $insertId";
             Database::query($sql);
-
             $question_id[$row['question_id']] = $insertId;
         }
 
@@ -803,7 +805,7 @@ class SurveyManager
     /**
      * This function duplicates a survey (and also all the question in that survey.
      *
-     * @param int $survey_id id of the survey that has to be duplicated
+     * @param int $surveyId id of the survey that has to be duplicated
      * @param int $courseId  id of the course which survey has to be duplicated
      *
      * @return true
@@ -812,7 +814,7 @@ class SurveyManager
      *
      * @version October 2007
      */
-    public static function empty_survey($survey_id, $courseId = 0)
+    public static function empty_survey($surveyId, $courseId = 0)
     {
         // Database table definitions
         $table_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
@@ -821,8 +823,9 @@ class SurveyManager
 
         $courseId = (int) $courseId;
         $courseId = empty($courseId) ? api_get_course_int_id() : $courseId;
+        $surveyId = (int) $surveyId;
 
-        $datas = self::get_survey($survey_id);
+        $datas = self::get_survey($surveyId);
         $session_where = '';
         if (api_get_session_id() != 0) {
             $session_where = ' AND session_id = "'.api_get_session_id().'" ';
@@ -835,11 +838,11 @@ class SurveyManager
         Database::query($sql);
 
         $sql = 'DELETE FROM '.$table_survey_answer.'
-		        WHERE c_id = '.$courseId.' AND survey_id='.intval($survey_id);
+		        WHERE c_id = '.$courseId.' AND survey_id='.$surveyId;
         Database::query($sql);
 
         $sql = 'UPDATE '.$table_survey.' SET invited=0, answered=0
-		        WHERE c_id = '.$courseId.' AND survey_id='.intval($survey_id);
+		        WHERE c_id = '.$courseId.' AND survey_id='.$surveyId;
         Database::query($sql);
 
         return true;
@@ -1032,8 +1035,8 @@ class SurveyManager
     /**
      * This function gets all the question of any given survey.
      *
-     * @param int $survey_id the id of the survey
-     * @param int $course_id
+     * @param int $surveyId the id of the survey
+     * @param int $courseId
      *
      * @return array containing all the questions of the survey
      *
@@ -1043,20 +1046,21 @@ class SurveyManager
      *
      * @todo one sql call should do the trick
      */
-    public static function get_questions($survey_id, $course_id = 0)
+    public static function get_questions($surveyId, $courseId = 0)
     {
-        // Table definitions
         $tbl_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
         $table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
 
-        $course_id = (int) $course_id;
-        if (empty($course_id)) {
-            $course_id = api_get_course_int_id();
+        $courseId = (int) $courseId;
+        $surveyId = (int) $surveyId;
+
+        if (empty($courseId)) {
+            $courseId = api_get_course_int_id();
         }
 
         // Getting the information of the question
         $sql = "SELECT * FROM $tbl_survey_question
-		        WHERE c_id = $course_id AND survey_id='".intval($survey_id)."'";
+		        WHERE c_id = $courseId AND survey_id='".$surveyId."'";
         $result = Database::query($sql);
         $return = [];
         while ($row = Database::fetch_array($result, 'ASSOC')) {
@@ -1067,11 +1071,12 @@ class SurveyManager
             $return[$row['question_id']]['horizontalvertical'] = $row['display'];
             $return[$row['question_id']]['maximum_score'] = $row['max_value'];
             $return[$row['question_id']]['sort'] = $row['sort'];
+            $return[$row['question_id']]['survey_question_comment'] = $row['survey_question_comment'];
         }
 
         // Getting the information of the question options
         $sql = "SELECT * FROM $table_survey_question_option
-		        WHERE c_id = $course_id AND survey_id='".intval($survey_id)."'";
+		        WHERE c_id = $courseId AND survey_id='".$surveyId."'";
         $result = Database::query($sql);
         while ($row = Database::fetch_array($result, 'ASSOC')) {
             $return[$row['question_id']]['answers'][] = $row['option_text'];
@@ -1133,7 +1138,6 @@ class SurveyManager
                 }
             }
             $course_id = api_get_course_int_id();
-
             if (!$empty_answer) {
                 // Table definitions
                 $tbl_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
@@ -1648,14 +1652,14 @@ class SurveyManager
         $course_condition = " c_id = $course_id AND ";
 
         // Table definitions
-        $table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
+        $table = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
         if ($shared) {
             $course_condition = '';
-            $table_survey_question_option = Database::get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION);
+            $table = Database::get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION);
         }
 
         // Deleting the options of the survey questions
-        $sql = "DELETE from $table_survey_question_option
+        $sql = "DELETE FROM $table
 		        WHERE
 		            $course_condition survey_id='".intval($survey_id)."' AND
 		            question_id='".intval($question_id)."'";
@@ -1887,13 +1891,15 @@ class SurveyManager
                         WITH (s.code = i.surveyCode AND s.cId = i.cId AND s.sessionId = i.sessionId)
                     INNER JOIN ChamiloCoreBundle:ExtraFieldValues efv WITH efv.itemId = s.iid
                     INNER JOIN ChamiloCoreBundle:ExtraField ef WITH efv.field = ef.id
-                    WHERE i.answered = 0
-                        AND i.cId = :course
-                        AND i.user = :user
-                        AND i.sessionId = :session
-                        AND :now BETWEEN s.availFrom AND s.availTill
-                        AND ef.variable = :variable
-                        AND efv.value = 1
+                    WHERE 
+                        i.answered = 0 AND 
+                        i.cId = :course AND 
+                        i.user = :user AND 
+                        i.sessionId = :session AND 
+                        :now BETWEEN s.availFrom AND s.availTill AND 
+                        ef.variable = :variable AND 
+                        efv.value = 1 AND 
+                        s.surveyType != 3
                     ORDER BY s.availTill ASC
                 ")
                 ->setMaxResults(1)
@@ -2084,4 +2090,126 @@ class SurveyManager
 
         return false;
     }
+
+    public static function removeMultiplicateQuestions($surveyData)
+    {
+        if (empty($surveyData)) {
+            return false;
+        }
+        $surveyId = $surveyData['survey_id'];
+        $courseId = $surveyData['c_id'];
+
+        if (empty($surveyId) || empty($courseId)) {
+            return false;
+        }
+
+        $questions = self::get_questions($surveyId);
+        foreach ($questions as $question) {
+            // Questions marked with "geneated" were created using the "multiplicate" feature.
+            if ($question['survey_question_comment'] === 'generated') {
+                self::delete_survey_question($surveyId, $question['question_id']);
+            }
+        }
+    }
+
+    /**
+     * @param array $surveyData
+     *
+     * @return bool
+     */
+    public static function multiplicateQuestions($surveyData)
+    {
+        if (empty($surveyData)) {
+            return false;
+        }
+        $surveyId = $surveyData['survey_id'];
+        $courseId = $surveyData['c_id'];
+
+        if (empty($surveyId) || empty($courseId)) {
+            return false;
+        }
+
+        $questions = self::get_questions($surveyId);
+
+        $obj = new UserGroup();
+
+        $options['where'] = [' usergroup.course_id = ? ' => $courseId];
+        $classList = $obj->getUserGroupInCourse($options);
+
+        $classTag = '{{class_name}}';
+        $studentTag = '{{student_full_name}}';
+        $classCounter = 0;
+        foreach ($classList as $class) {
+            $className = $class['name'];
+            foreach ($questions as $question) {
+                $users = $obj->get_users_by_usergroup($class['id']);
+                if (empty($users)) {
+                    continue;
+                }
+
+                $text = $question['question'];
+                if (strpos($text, $classTag) !== false) {
+                    $replacedText = str_replace($classTag, $className, $text);
+                    $values = [
+                        'c_id' => $courseId,
+                        'question_comment' => 'generated',
+                        'type' => $question['type'],
+                        'display' => $question['horizontalvertical'],
+                        'question' => $replacedText,
+                        'survey_id' => $surveyId,
+                        'question_id' => 0,
+                        'shared_question_id' => 0,
+                    ];
+                    self::save_question($surveyData, $values);
+                    $classCounter++;
+                    continue;
+                }
+
+                foreach ($users as $userId) {
+                    $userInfo = api_get_user_info($userId);
+
+                    if (strpos($text, $studentTag) !== false) {
+                        $replacedText = str_replace($studentTag, $userInfo['complete_name'], $text);
+                        $values = [
+                            'c_id' => $courseId,
+                            'question_comment' => 'generated',
+                            'type' => $question['type'],
+                            'display' => $question['horizontalvertical'],
+                            'maximum_score' => $question['maximum_score'],
+                            'question' => $replacedText,
+                            'survey_id' => $surveyId,
+                            'question_id' => 0,
+                            'shared_question_id' => 0,
+                        ];
+
+                        $answers = [];
+                        if (!empty($question['answers'])) {
+                            foreach ($question['answers'] as $answer) {
+                                $replacedText = str_replace($studentTag, $userInfo['complete_name'], $answer);
+                                $answers[] = $replacedText;
+                            }
+                        }
+                        $values['answers'] = $answers;
+                        self::save_question($surveyData, $values);
+                    }
+                }
+
+                if ($classCounter < count($classList)) {
+                    // Add end page
+                    $values = [
+                        'c_id' => $courseId,
+                        'question_comment' => 'generated',
+                        'type' => 'pagebreak',
+                        'display' => 'horizontal',
+                        'question' => get_lang('QuestionForNextClass'),
+                        'survey_id' => $surveyId,
+                        'question_id' => 0,
+                        'shared_question_id' => 0,
+                    ];
+                    self::save_question($surveyData, $values);
+                }
+
+            }
+        }
+    }
 }

+ 62 - 36
main/survey/survey.php

@@ -44,7 +44,7 @@ $table_survey_question_group = Database::get_course_table(TABLE_SURVEY_QUESTION_
 $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
 $table_user = Database::get_main_table(TABLE_MAIN_USER);
 
-$survey_id = intval($_GET['survey_id']);
+$survey_id = (int) $_GET['survey_id'];
 $course_id = api_get_course_int_id();
 $action = isset($_GET['action']) ? $_GET['action'] : null;
 
@@ -89,7 +89,9 @@ if ($is_survey_type_1 && ($action == 'addgroup' || $action == 'deletegroup')) {
     }
 
     if ($action == 'deletegroup') {
-        Database::query('DELETE FROM '.$table_survey_question_group.' WHERE c_id = '.$course_id.' AND id = '.intval($_GET['gid']).' and survey_id = '.intval($survey_id));
+        $sql = 'DELETE FROM '.$table_survey_question_group.' 
+                WHERE c_id = '.$course_id.' AND id = '.intval($_GET['gid']).' AND survey_id = '.intval($survey_id);
+        Database::query($sql);
         $sendmsg = 'GroupDeletedSuccessfully';
     }
     header('Location: '.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&sendmsg='.$sendmsg);
@@ -97,7 +99,6 @@ if ($is_survey_type_1 && ($action == 'addgroup' || $action == 'deletegroup')) {
 }
 
 // Displaying the header
-
 Display::display_header($tool_name, 'Survey');
 
 // Action handling
@@ -132,26 +133,36 @@ if (!empty($survey_data['survey_version'])) {
 SurveyUtil::check_first_last_question($_GET['survey_id']);
 
 // Action links
-$survey_actions = '<a href="'.api_get_path(WEB_CODE_PATH).'survey/create_new_survey.php?'.api_get_cidreq().'&action=edit&survey_id='.$survey_id.'">'.
-    Display::return_icon('edit.png', get_lang('EditSurvey'), '', ICON_SIZE_MEDIUM).'</a>';
+$survey_actions = '';
+if ($survey_data['survey_type'] != 3) {
+    $survey_actions = '<a href="'.api_get_path(WEB_CODE_PATH).'survey/create_new_survey.php?'.api_get_cidreq(
+        ).'&action=edit&survey_id='.$survey_id.'">'.
+        Display::return_icon('edit.png', get_lang('EditSurvey'), '', ICON_SIZE_MEDIUM).'</a>';
+}
 $survey_actions .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq().'&action=delete&survey_id='.$survey_id.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('DeleteSurvey').'?', ENT_QUOTES)).'\')) return false;">'.
     Display::return_icon('delete.png', get_lang('DeleteSurvey'), '', ICON_SIZE_MEDIUM).'</a>';
-$survey_actions .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/preview.php?'.api_get_cidreq().'&survey_id='.$survey_id.'">'.
-    Display::return_icon('preview_view.png', get_lang('Preview'), '', ICON_SIZE_MEDIUM).'</a>';
+
+if ($survey_data['survey_type'] != 3) {
+    $survey_actions .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/preview.php?'.api_get_cidreq().'&survey_id='.$survey_id.'">'.
+        Display::return_icon('preview_view.png', get_lang('Preview'), '', ICON_SIZE_MEDIUM).'</a>';
+}
+
 $survey_actions .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_invite.php?'.api_get_cidreq().'&survey_id='.$survey_id.'">'.
     Display::return_icon('mail_send.png', get_lang('Publish'), '', ICON_SIZE_MEDIUM).'</a>';
 
-if (!api_get_configuration_value('hide_survey_reporting_button')) {
-    $survey_actions .= Display::url(
-        Display::return_icon('stats.png', get_lang('Reporting'), [], ICON_SIZE_MEDIUM),
-        api_get_path(WEB_CODE_PATH).'survey/reporting.php?'.api_get_cidreq().'&survey_id='.$survey_id
-    );
+if ($survey_data['survey_type'] != 3) {
+    if (!api_get_configuration_value('hide_survey_reporting_button')) {
+        $survey_actions .= Display::url(
+            Display::return_icon('stats.png', get_lang('Reporting'), [], ICON_SIZE_MEDIUM),
+            api_get_path(WEB_CODE_PATH).'survey/reporting.php?'.api_get_cidreq().'&survey_id='.$survey_id
+        );
+    }
 }
 
 echo '<div class="actions">'.$survey_actions.'</div>';
 
+$urlQuestion = api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&action=add';
 if ($survey_data['survey_type'] == 0) {
-    $urlQuestion = api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&action=add';
     echo '<div class="well">';
     echo Display::url(
         Display::return_icon('yesno.png', get_lang('YesNo'), null, ICON_SIZE_BIG),
@@ -191,12 +202,14 @@ if ($survey_data['survey_type'] == 0) {
     );
     echo '</div>';
 } else {
-    echo '<div class="well">';
-    echo Display::url(
-        Display::return_icon('yesno.png', get_lang('YesNo'), null, ICON_SIZE_BIG),
-        $urlQuestion.'&type=personality&survey_id='.$survey_id
-    );
-    echo '</a></div>';
+    if ($survey_data['survey_type'] != 3) {
+        echo '<div class="well">';
+        echo Display::url(
+            Display::return_icon('yesno.png', get_lang('YesNo'), null, ICON_SIZE_BIG),
+            $urlQuestion.'&type=personality&survey_id='.$survey_id
+        );
+        echo '</a></div>';
+    }
 }
 
 // Displaying the table header with all the questions
@@ -218,7 +231,7 @@ echo '</thead>';
 // Displaying the table contents with all the questions
 $question_counter = 1;
 $sql = "SELECT * FROM $table_survey_question_group
-        WHERE c_id = '.$course_id.' AND survey_id = ".intval($survey_id)." 
+        WHERE c_id = $course_id AND survey_id = $survey_id 
         ORDER BY id";
 $result = Database::query($sql);
 $groups = [];
@@ -243,10 +256,16 @@ while ($row = Database::fetch_array($result, 'ASSOC')) {
     echo '<tr>';
     echo '	<td>'.$question_counter.'</td>';
     echo '	<td>';
-    if (api_strlen($row['survey_question']) > 100) {
-        echo api_substr(strip_tags($row['survey_question']), 0, 100).' ... ';
+
+    if ($survey_data['survey_type'] != 3) {
+        if (api_strlen($row['survey_question']) > 100) {
+            echo api_substr(strip_tags($row['survey_question']), 0, 100).' ... ';
+        } else {
+            echo $row['survey_question'];
+        }
     } else {
-        echo $row['survey_question'];
+        $parts = explode('@@', $row['survey_question']);
+        echo api_get_local_time($parts[0]).' - '.api_get_local_time($parts[1]);
     }
 
     if ($row['type'] == 'yesno') {
@@ -261,21 +280,28 @@ while ($row = Database::fetch_array($result, 'ASSOC')) {
     echo '<td>'.$tool_name.'</td>';
     echo '<td>'.$row['number_of_options'].'</td>';
     echo '<td>';
-    echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&action=edit&type='.$row['type'].'&survey_id='.$survey_id.'&question_id='.$row['question_id'].'">'.
-        Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>';
+    if ($survey_data['survey_type'] != 3) {
+        echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&action=edit&type='.$row['type'].'&survey_id='.$survey_id.'&question_id='.$row['question_id'].'">'.
+            Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>';
+    }
+
     echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?'.api_get_cidreq().'&action=delete&survey_id='.$survey_id.'&question_id='.$row['question_id'].'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("DeleteSurveyQuestion").'?', ENT_QUOTES, $charset)).'\')) return false;">'.
         Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>';
-    if ($question_counter > 1) {
-        echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?'.api_get_cidreq().'&action=moveup&survey_id='.$survey_id.'&question_id='.$row['question_id'].'">'.
-            Display::return_icon('up.png', get_lang('MoveUp'), '', ICON_SIZE_SMALL).'</a>';
-    } else {
-        Display::display_icon('up_na.png', '&nbsp;', '', ICON_SIZE_SMALL);
-    }
-    if ($question_counter < $question_counter_max) {
-        echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?'.api_get_cidreq().'&action=movedown&survey_id='.$survey_id.'&question_id='.$row['question_id'].'">'.
-            Display::return_icon('down.png', get_lang('MoveDown'), '', ICON_SIZE_SMALL).'</a>';
-    } else {
-        Display::display_icon('down_na.png', '&nbsp;', '', ICON_SIZE_SMALL);
+    if ($survey_data['survey_type'] != 3) {
+        if ($question_counter > 1) {
+            echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?'.api_get_cidreq(
+                ).'&action=moveup&survey_id='.$survey_id.'&question_id='.$row['question_id'].'">'.
+                Display::return_icon('up.png', get_lang('MoveUp'), '', ICON_SIZE_SMALL).'</a>';
+        } else {
+            Display::display_icon('up_na.png', '&nbsp;', '', ICON_SIZE_SMALL);
+        }
+        if ($question_counter < $question_counter_max) {
+            echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?'.api_get_cidreq(
+                ).'&action=movedown&survey_id='.$survey_id.'&question_id='.$row['question_id'].'">'.
+                Display::return_icon('down.png', get_lang('MoveDown'), '', ICON_SIZE_SMALL).'</a>';
+        } else {
+            Display::display_icon('down_na.png', '&nbsp;', '', ICON_SIZE_SMALL);
+        }
     }
     echo '	</td>';
     $question_counter++;

+ 171 - 198
main/survey/surveyUtil.class.php

@@ -235,7 +235,7 @@ class SurveyUtil
         $questions_data = [];
 
         foreach ($my_temp_questions_data as $key => &$value) {
-            if ($value['type'] != 'comment' && $value['type'] != 'pagebreak') {
+            if ($value['type'] != 'pagebreak') {
                 $questions_data[$value['sort']] = $value;
             }
         }
@@ -480,16 +480,18 @@ class SurveyUtil
                 }
 
                 $ch_type = 'ch_'.$question['type'];
-                /** @var survey_question $display */
-                $display = new $ch_type();
-
-                $url = api_get_self();
-                $form = new FormValidator('question', 'post', $url);
-                $form->addHtml('<div class="survey_question_wrapper"><div class="survey_question">');
-                $form->addHtml($question['survey_question']);
-                $display->render($form, $question, $finalAnswer);
-                $form->addHtml('</div></div>');
-                $form->display();
+                if (class_exists($ch_type)) {
+                    /** @var survey_question $display */
+                    $display = new $ch_type();
+
+                    $url = api_get_self();
+                    $form = new FormValidator('question', 'post', $url);
+                    $form->addHtml('<div class="survey_question_wrapper"><div class="survey_question">');
+                    $form->addHtml($question['survey_question']);
+                    $display->render($form, $question, $finalAnswer);
+                    $form->addHtml('</div></div>');
+                    $form->display();
+                }
             }
         }
     }
@@ -518,19 +520,19 @@ class SurveyUtil
      */
     public static function display_question_report($survey_data)
     {
-        $singlePage = isset($_GET['single_page']) ? intval($_GET['single_page']) : 0;
+        $singlePage = isset($_GET['single_page']) ? (int) $_GET['single_page'] : 0;
+        // Determining the offset of the sql statement (the n-th question of the survey)
+        $offset = !isset($_GET['question']) ? 0 : (int) $_GET['question'];
+        $currentQuestion = isset($_GET['question']) ? (int) $_GET['question'] : 0;
+        $surveyId = (int) $_GET['survey_id'];
+        $action = Security::remove_XSS($_GET['action']);
         $course_id = api_get_course_int_id();
+
         // Database table definitions
         $table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
         $table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
         $table_survey_answer = Database::get_course_table(TABLE_SURVEY_ANSWER);
-
-        // Determining the offset of the sql statement (the n-th question of the survey)
-        $offset = !isset($_GET['question']) ? 0 : intval($_GET['question']);
-        $currentQuestion = isset($_GET['question']) ? intval($_GET['question']) : 0;
         $questions = [];
-        $surveyId = intval($_GET['survey_id']);
-        $action = Security::remove_XSS($_GET['action']);
 
         echo '<div class="actions">';
         echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?survey_id='.$surveyId.'&'.api_get_cidreq().'">'.
@@ -574,9 +576,8 @@ class SurveyUtil
             $sql = "SELECT * FROM $table_survey_question
 			        WHERE
 			            c_id = $course_id AND
-                        survey_id='".intval($_GET['survey_id'])."' AND
-                        type <>'pagebreak' AND 
-                        type <>'comment'
+                        survey_id='".$surveyId."' AND
+                        type <>'pagebreak'                        
                     ORDER BY sort ASC
                     $limitStatement";
             $result = Database::query($sql);
@@ -584,10 +585,10 @@ class SurveyUtil
                 $questions[$row['question_id']] = $row;
             }
         }
-
         foreach ($questions as $question) {
             $chartData = [];
             $options = [];
+            $questionId = (int) $question['question_id'];
             echo '<div class="title-question">';
             echo strip_tags(isset($question['survey_question']) ? $question['survey_question'] : null);
             echo '</div>';
@@ -595,13 +596,13 @@ class SurveyUtil
             if ($question['type'] == 'score') {
                 /** @todo This function should return the options as this is needed further in the code */
                 $options = self::display_question_report_score($survey_data, $question, $offset);
-            } elseif ($question['type'] == 'open') {
+            } elseif ($question['type'] == 'open' || $question['type'] == 'comment') {
                 /** @todo Also get the user who has answered this */
                 $sql = "SELECT * FROM $table_survey_answer
                         WHERE
                             c_id = $course_id AND
-                            survey_id='".intval($_GET['survey_id'])."' AND
-                            question_id = '".intval($question['question_id'])."'";
+                            survey_id='".$surveyId."' AND
+                            question_id = '".$questionId."'";
                 $result = Database::query($sql);
                 while ($row = Database::fetch_array($result, 'ASSOC')) {
                     echo $row['option_id'].'<hr noshade="noshade" size="1" />';
@@ -611,8 +612,8 @@ class SurveyUtil
                 $sql = "SELECT * FROM $table_survey_question_option
                         WHERE
                             c_id = $course_id AND
-                            survey_id='".intval($_GET['survey_id'])."'
-                            AND question_id = '".intval($question['question_id'])."'
+                            survey_id='".$surveyId."'
+                            AND question_id = '".$questionId."'
                         ORDER BY sort ASC";
                 $result = Database::query($sql);
                 while ($row = Database::fetch_array($result, 'ASSOC')) {
@@ -622,8 +623,8 @@ class SurveyUtil
                 $sql = "SELECT *, count(answer_id) as total FROM $table_survey_answer
                         WHERE
                             c_id = $course_id AND
-                            survey_id='".intval($_GET['survey_id'])."'
-                            AND question_id = '".intval($question['question_id'])."'
+                            survey_id='".$surveyId."'
+                            AND question_id = '".$questionId."'
                         GROUP BY option_id, value";
                 $result = Database::query($sql);
                 $number_of_answers = [];
@@ -699,14 +700,20 @@ class SurveyUtil
                         echo ' </tr>';
                     }
                 }
+
+                $optionResult = '';
+                if (isset($option['question_id']) && isset($number_of_answers[$option['question_id']])) {
+                    if ($number_of_answers[$option['question_id']] == 0) {
+                        $optionResult = '0';
+                    } else {
+                        $optionResult = $number_of_answers[$option['question_id']];
+                    }
+                }
+
                 // displaying the table: footer (totals)
                 echo '	<tr>';
                 echo '		<td class="total"><b>'.get_lang('Total').'</b></td>';
-                echo '		<td class="total"><b>'
-                    .($number_of_answers[$option['question_id']] == 0
-                        ? '0'
-                        : $number_of_answers[$option['question_id']])
-                    .'</b></td>';
+                echo '		<td class="total"><b>'.$optionResult.'</b></td>';
                 echo '		<td class="total">&nbsp;</td>';
                 echo '		<td class="total">&nbsp;</td>';
                 echo '	</tr>';
@@ -714,6 +721,7 @@ class SurveyUtil
                 echo '</div>';
             }
         }
+
         if (isset($_GET['viewoption'])) {
             echo '<div class="answered-people">';
             echo '<h4>'.get_lang('PeopleWhoAnswered').': '
@@ -865,7 +873,7 @@ class SurveyUtil
         $table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
         $table_survey_answer = Database::get_course_table(TABLE_SURVEY_ANSWER);
 
-        $surveyId = isset($_GET['survey_id']) ? intval($_GET['survey_id']) : 0;
+        $surveyId = isset($_GET['survey_id']) ? (int) $_GET['survey_id'] : 0;
         $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : '';
 
         // Actions bar
@@ -916,7 +924,7 @@ class SurveyUtil
 
         $display_extra_user_fields = false;
         if (!(isset($_POST['submit_question_filter']) && $_POST['submit_question_filter'] ||
-                isset($_POST['export_report']) && $_POST['export_report']) ||
+            isset($_POST['export_report']) && $_POST['export_report']) ||
             !empty($_POST['fields_filter'])
         ) {
             // Show user fields section with a big th colspan that spans over all fields
@@ -940,14 +948,17 @@ class SurveyUtil
         }
 
         $course_id = api_get_course_int_id();
-        $sql = "SELECT q.question_id, q.type, q.survey_question, count(o.question_option_id) as number_of_options
+        $sql = "SELECT 
+                  q.question_id, 
+                  q.type, 
+                  q.survey_question, 
+                  count(o.question_option_id) as number_of_options
 				FROM $table_survey_question q 
 				LEFT JOIN $table_survey_question_option o
-				ON q.question_id = o.question_id
+				ON q.question_id = o.question_id AND q.c_id = o.c_id
 				WHERE 
 				    q.survey_id = '".$surveyId."' AND
-				    q.c_id = $course_id AND
-				    o.c_id = $course_id
+				    q.c_id = $course_id
 				GROUP BY q.question_id
 				ORDER BY q.sort ASC";
         $result = Database::query($sql);
@@ -960,15 +971,12 @@ class SurveyUtil
                 (is_array($_POST['questions_filter']) && in_array($row['question_id'], $_POST['questions_filter']))
             ) {
                 // We do not show comment and pagebreak question types
-                if ($row['type'] != 'comment' && $row['type'] != 'pagebreak') {
+                if ($row['type'] != 'pagebreak') {
                     echo ' <th';
-                    // <hub> modified tst to include percentage
                     if ($row['number_of_options'] > 0 && $row['type'] != 'percentage') {
-                        // </hub>
                         echo ' colspan="'.$row['number_of_options'].'"';
                     }
                     echo '>';
-
                     echo '<label><input type="checkbox" name="questions_filter[]" value="'.$row['question_id']
                         .'" checked="checked"/> ';
                     echo $row['survey_question'];
@@ -985,7 +993,8 @@ class SurveyUtil
         echo '		<th>&nbsp;</th>'; // the user column
 
         if (!(isset($_POST['submit_question_filter']) && $_POST['submit_question_filter'] ||
-                isset($_POST['export_report']) && $_POST['export_report']) || !empty($_POST['fields_filter'])) {
+            isset($_POST['export_report']) && $_POST['export_report']) || !empty($_POST['fields_filter'])
+        ) {
             //show the fields names for user fields
             foreach ($extra_user_fields as &$field) {
                 echo '<th>'.$field[3].'</th>';
@@ -994,17 +1003,21 @@ class SurveyUtil
 
         // cells with option (none for open question)
         $sql = "SELECT 	
-                    sq.question_id, sq.survey_id,
-                    sq.survey_question, sq.display,
-                    sq.sort, sq.type, sqo.question_option_id,
-                    sqo.option_text, sqo.sort as option_sort
+                    sq.question_id, 
+                    sq.survey_id,
+                    sq.survey_question, 
+                    sq.display,
+                    sq.sort, 
+                    sq.type, 
+                    sqo.question_option_id,
+                    sqo.option_text, 
+                    sqo.sort as option_sort
 				FROM $table_survey_question sq
 				LEFT JOIN $table_survey_question_option sqo
-				ON sq.question_id = sqo.question_id
+				ON sq.question_id = sqo.question_id AND sq.c_id = sqo.c_id
 				WHERE
 				    sq.survey_id = '".$surveyId."' AND
-                    sq.c_id = $course_id AND
-                    sqo.c_id = $course_id
+                    sq.c_id = $course_id
 				ORDER BY sq.sort ASC, sqo.sort ASC";
         $result = Database::query($sql);
 
@@ -1018,9 +1031,8 @@ class SurveyUtil
             if (!(isset($_POST['submit_question_filter']) && $_POST['submit_question_filter']) ||
                 (is_array($_POST['questions_filter']) && in_array($row['question_id'], $_POST['questions_filter']))
             ) {
-                // <hub> modif 05-05-2010
                 // we do not show comment and pagebreak question types
-                if ($row['type'] == 'open') {
+                if ($row['type'] == 'open' || $row['type'] == 'comment') {
                     echo '<th>&nbsp;-&nbsp;</th>';
                     $possible_answers[$row['question_id']][$row['question_option_id']] = $row['question_option_id'];
                     $display_percentage_header = 1;
@@ -1030,15 +1042,13 @@ class SurveyUtil
                     $display_percentage_header = 0;
                 } elseif ($row['type'] == 'percentage') {
                     $possible_answers[$row['question_id']][$row['question_option_id']] = $row['question_option_id'];
-                } elseif ($row['type'] != 'comment' && $row['type'] != 'pagebreak' && $row['type'] != 'percentage') {
+                } elseif ($row['type'] != 'pagebreak' && $row['type'] != 'percentage') {
                     echo '<th>';
                     echo $row['option_text'];
                     echo '</th>';
                     $possible_answers[$row['question_id']][$row['question_option_id']] = $row['question_option_id'];
                     $display_percentage_header = 1;
                 }
-                //no column at all if the question was not a question
-                // </hub>
             }
         }
 
@@ -1071,7 +1081,10 @@ class SurveyUtil
                 );
                 $answers_of_user = [];
             }
-            if (isset($questions[$row['question_id']]) && $questions[$row['question_id']]['type'] != 'open') {
+            if (isset($questions[$row['question_id']]) &&
+                $questions[$row['question_id']]['type'] != 'open' &&
+                $questions[$row['question_id']]['type'] != 'comment'
+            ) {
                 $answers_of_user[$row['question_id']][$row['option_id']] = $row;
             } else {
                 $answers_of_user[$row['question_id']][0] = $row;
@@ -1141,7 +1154,7 @@ class SurveyUtil
         if ($display_extra_user_fields) {
             // Show user fields data, if any, for this user
             $user_fields_values = UserManager::get_extra_user_data(
-                intval($user),
+                $user,
                 false,
                 false,
                 false,
@@ -1151,10 +1164,10 @@ class SurveyUtil
                 echo '<td align="center">'.$value.'</td>';
             }
         }
+
         if (is_array($possible_options)) {
-            // <hub> modified to display open answers and percentage
             foreach ($possible_options as $question_id => &$possible_option) {
-                if ($questions[$question_id]['type'] == 'open') {
+                if ($questions[$question_id]['type'] == 'open' || $questions[$question_id]['type'] == 'comment') {
                     echo '<td align="center">';
                     echo $answers_of_user[$question_id]['0']['option_id'];
                     echo '</td>';
@@ -1202,6 +1215,12 @@ class SurveyUtil
         $table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
         $table_survey_answer = Database::get_course_table(TABLE_SURVEY_ANSWER);
 
+        $surveyId = isset($_GET['survey_id']) ? (int) $_GET['survey_id'] : 0;
+
+        if (empty($surveyId)) {
+            return false;
+        }
+
         // The first column
         $return = ';';
 
@@ -1217,7 +1236,6 @@ class SurveyUtil
 
         $num = count($extra_user_fields);
         $return .= str_repeat(';', $num);
-
         $course_id = api_get_course_int_id();
 
         $sql = "SELECT
@@ -1227,9 +1245,9 @@ class SurveyUtil
                     count(options.question_option_id) as number_of_options
 				FROM $table_survey_question questions
                 LEFT JOIN $table_survey_question_option options
-				ON questions.question_id = options.question_id AND options.c_id = $course_id
+				ON questions.question_id = options.question_id AND options.c_id = questions.c_id
 				WHERE
-				    questions.survey_id = '".intval($_GET['survey_id'])."' AND
+				    questions.survey_id = '".$surveyId."' AND
                     questions.c_id = $course_id
 				GROUP BY questions.question_id
 				ORDER BY questions.sort ASC";
@@ -1244,8 +1262,8 @@ class SurveyUtil
                     in_array($row['question_id'], $_POST['questions_filter']))
             ) {
                 // We do not show comment and pagebreak question types
-                if ($row['type'] != 'comment' && $row['type'] != 'pagebreak') {
-                    if ($row['number_of_options'] == 0 && $row['type'] == 'open') {
+                if ($row['type'] != 'pagebreak') {
+                    if ($row['number_of_options'] == 0 && ($row['type'] == 'open' || $row['type'] == 'comment')) {
                         $return .= str_replace(
                             "\r\n",
                             '  ',
@@ -1265,11 +1283,10 @@ class SurveyUtil
                 }
             }
         }
-        $return .= "\n";
 
+        $return .= "\n";
         // Getting all the questions and options
         $return .= ';';
-
         // Show the fields names for user fields
         if (!empty($extra_user_fields)) {
             foreach ($extra_user_fields as &$field) {
@@ -1297,9 +1314,9 @@ class SurveyUtil
 				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
+				    survey_question_option.c_id = survey_question.c_id
 				WHERE
-				    survey_question.survey_id = '".intval($_GET['survey_id'])."' AND
+				    survey_question.survey_id = '".$surveyId."' AND
 				    survey_question.c_id = $course_id
 				ORDER BY survey_question.sort ASC, survey_question_option.sort ASC";
         $result = Database::query($sql);
@@ -1315,7 +1332,7 @@ class SurveyUtil
             )
             ) {
                 // We do not show comment and pagebreak question types
-                if ($row['type'] != 'comment' && $row['type'] != 'pagebreak') {
+                if ($row['type'] != 'pagebreak') {
                     $row['option_text'] = str_replace(["\r", "\n"], ['', ''], $row['option_text']);
                     $return .= api_html_entity_decode(strip_tags($row['option_text']), ENT_QUOTES).';';
                     $possible_answers[$row['question_id']][$row['question_option_id']] = $row['question_option_id'];
@@ -1329,7 +1346,7 @@ class SurveyUtil
         $old_user = '';
         $answers_of_user = [];
         $sql = "SELECT * FROM $table_survey_answer
-		        WHERE c_id = $course_id AND survey_id='".intval($_GET['survey_id'])."'";
+		        WHERE c_id = $course_id AND survey_id='".$surveyId."'";
         if ($user_id != 0) {
             $sql .= "AND user='".Database::escape_string($user_id)."' ";
         }
@@ -1348,7 +1365,9 @@ class SurveyUtil
                 );
                 $answers_of_user = [];
             }
-            if ($possible_answers_type[$row['question_id']] == 'open') {
+            if ($possible_answers_type[$row['question_id']] == 'open' ||
+                $possible_answers_type[$row['question_id']] == 'comment'
+            ) {
                 $temp_id = 'open'.$open_question_iterator;
                 $answers_of_user[$row['question_id']][$temp_id] = $row;
                 $open_question_iterator++;
@@ -1516,7 +1535,7 @@ class SurveyUtil
                     count(options.question_option_id) as number_of_options
 				FROM $table_survey_question questions
 				LEFT JOIN $table_survey_question_option options
-                ON questions.question_id = options.question_id AND options.c_id = $course_id
+                ON questions.question_id = options.question_id AND options.c_id = questions.c_id
 				WHERE
 				    questions.survey_id = $surveyId AND
 				    questions.c_id = $course_id
@@ -1532,8 +1551,8 @@ class SurveyUtil
                 in_array($row['question_id'], $_POST['questions_filter']))
             ) {
                 // We do not show comment and pagebreak question types
-                if ($row['type'] != 'comment' && $row['type'] != 'pagebreak') {
-                    if ($row['number_of_options'] == 0 && $row['type'] == 'open') {
+                if ($row['type'] != 'pagebreak') {
+                    if ($row['number_of_options'] == 0 && ($row['type'] == 'open' || $row['type'] == 'comment')) {
                         $worksheet->setCellValueByColumnAndRow(
                             $column,
                             $line,
@@ -1590,7 +1609,7 @@ class SurveyUtil
 				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
+				    survey_question_option.c_id = survey_question.c_id
 				WHERE 
 				    survey_question.survey_id = $surveyId AND
 				    survey_question.c_id = $course_id
@@ -1607,7 +1626,7 @@ class SurveyUtil
                 in_array($row['question_id'], $_POST['questions_filter']))
             ) {
                 // We do not show comment and pagebreak question types
-                if ($row['type'] != 'comment' && $row['type'] != 'pagebreak') {
+                if ($row['type'] != 'pagebreak') {
                     $worksheet->setCellValueByColumnAndRow(
                         $column,
                         $line,
@@ -1654,7 +1673,7 @@ class SurveyUtil
                 $line++;
                 $column = 0;
             }
-            if ($possible_answers_type[$row['question_id']] == 'open') {
+            if ($possible_answers_type[$row['question_id']] == 'open' || $possible_answers_type[$row['question_id']] == 'comment') {
                 $temp_id = 'open'.$open_question_iterator;
                 $answers_of_user[$row['question_id']][$temp_id] = $row;
                 $open_question_iterator++;
@@ -2104,75 +2123,6 @@ class SurveyUtil
         return $counter;
     }
 
-    /**
-     * Get all the information about the invitations of a certain survey.
-     *
-     * @return array Lines of invitation [user, code, date, empty element]
-     *
-     * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
-     *
-     * @version January 2007
-     *
-     * @todo use survey_id parameter instead of $_GET
-     */
-    public static function get_survey_invitations_data()
-    {
-        $course_id = api_get_course_int_id();
-        // Database table definition
-        $table_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
-        $table_user = Database::get_main_table(TABLE_MAIN_USER);
-
-        $sql = "SELECT
-					survey_invitation.user as col1,
-					survey_invitation.invitation_code as col2,
-					survey_invitation.invitation_date as col3,
-					'' as col4
-                FROM $table_survey_invitation survey_invitation
-                LEFT JOIN $table_user user
-                ON survey_invitation.user = user.user_id
-                WHERE
-                    survey_invitation.c_id = $course_id AND
-                    survey_invitation.survey_id = '".intval($_GET['survey_id'])."' AND
-                    session_id='".api_get_session_id()."'  ";
-        $res = Database::query($sql);
-        $data = [];
-        while ($row = Database::fetch_array($res)) {
-            $data[] = $row;
-        }
-
-        return $data;
-    }
-
-    /**
-     * Get the total number of survey invitations for a given survey (through $_GET['survey_id']).
-     *
-     * @return int Total number of survey invitations
-     *
-     * @todo use survey_id parameter instead of $_GET
-     *
-     * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
-     *
-     * @version January 2007
-     */
-    public static function get_number_of_survey_invitations()
-    {
-        $course_id = api_get_course_int_id();
-
-        // Database table definition
-        $table = Database::get_course_table(TABLE_SURVEY_INVITATION);
-
-        $sql = "SELECT count(user) AS total
-		        FROM $table
-		        WHERE
-                    c_id = $course_id AND
-                    survey_id='".intval($_GET['survey_id'])."' AND
-                    session_id='".api_get_session_id()."' ";
-        $res = Database::query($sql);
-        $row = Database::fetch_array($res, 'ASSOC');
-
-        return $row['total'];
-    }
-
     /**
      * Save the invitation mail.
      *
@@ -2867,6 +2817,8 @@ class SurveyUtil
             return $hideReportingButton ? '-' : $reportingLink;
         }
 
+        $type = $survey->getSurveyType();
+
         // Coach can see that only if the survey is in his session
         if (api_is_allowed_to_edit() ||
             api_is_element_in_the_session(TOOL_SURVEY, $survey_id)
@@ -2874,54 +2826,78 @@ class SurveyUtil
             $actions[] = Display::url(
                 Display::return_icon('edit.png', get_lang('Edit')),
                 $codePath.'survey/create_new_survey.php?'
-                    .http_build_query($params + ['action' => 'edit', 'survey_id' => $survey_id])
+                .http_build_query($params + ['action' => 'edit', 'survey_id' => $survey_id])
             );
+
             if (SurveyManager::survey_generation_hash_available()) {
                 $actions[] = Display::url(
                     Display::return_icon('new_link.png', get_lang('GenerateSurveyAccessLink')),
                     $codePath.'survey/generate_link.php?'.http_build_query($params + ['survey_id' => $survey_id])
                 );
             }
-            $actions[] = Display::url(
-                Display::return_icon('backup.png', get_lang('CopySurvey')),
-                $codePath.'survey/copy_survey.php?'.http_build_query($params + ['survey_id' => $survey_id])
-            );
-            $actions[] = Display::url(
-                Display::return_icon('copy.png', get_lang('DuplicateSurvey')),
-                $codePath.'survey/survey_list.php?'
+
+            if ($type != 3) {
+                $actions[] = Display::url(
+                    Display::return_icon('backup.png', get_lang('CopySurvey')),
+                    $codePath.'survey/copy_survey.php?'.http_build_query($params + ['survey_id' => $survey_id])
+                );
+
+                $actions[] = Display::url(
+                    Display::return_icon('copy.png', get_lang('DuplicateSurvey')),
+                    $codePath.'survey/survey_list.php?'
                     .http_build_query($params + ['action' => 'copy_survey', 'survey_id' => $survey_id])
-            );
+                );
 
-            $warning = addslashes(api_htmlentities(get_lang('EmptySurvey').'?', ENT_QUOTES));
-            $actions[] = Display::url(
-                Display::return_icon('clean.png', get_lang('EmptySurvey')),
-                $codePath.'survey/survey_list.php?'
+                $actions[] = Display::url(
+                    Display::return_icon('star.png', get_lang('MultiplicateSurvey')),
+                    $codePath.'survey/survey_list.php?'
+                    .http_build_query($params + ['action' => 'multiplicate', 'survey_id' => $survey_id])
+                );
+
+                $actions[] = Display::url(
+                    Display::return_icon('star_na.png', get_lang('RemoveMultiplicateQuestions')),
+                    $codePath.'survey/survey_list.php?'
+                    .http_build_query($params + ['action' => 'remove_multiplicate', 'survey_id' => $survey_id])
+                );
+
+                $warning = addslashes(api_htmlentities(get_lang('EmptySurvey').'?', ENT_QUOTES));
+                $actions[] = Display::url(
+                    Display::return_icon('clean.png', get_lang('EmptySurvey')),
+                    $codePath.'survey/survey_list.php?'
                     .http_build_query($params + ['action' => 'empty', 'survey_id' => $survey_id]),
-                [
-                    'onclick' => "javascript: if (!confirm('".$warning."')) return false;",
-                ]
+                    [
+                        'onclick' => "javascript: if (!confirm('".$warning."')) return false;",
+                    ]
+                );
+            }
+        }
+
+        if ($type != 3) {
+            $actions[] = Display::url(
+                Display::return_icon('preview_view.png', get_lang('Preview')),
+                $codePath.'survey/preview.php?'.http_build_query($params + ['survey_id' => $survey_id])
             );
         }
-        $actions[] = Display::url(
-            Display::return_icon('preview_view.png', get_lang('Preview')),
-            $codePath.'survey/preview.php?'.http_build_query($params + ['survey_id' => $survey_id])
-        );
+
         $actions[] = Display::url(
             Display::return_icon('mail_send.png', get_lang('Publish')),
             $codePath.'survey/survey_invite.php?'.http_build_query($params + ['survey_id' => $survey_id])
         );
-        $actions[] = $hideReportingButton ? null : $reportingLink;
+
+        if ($type != 3) {
+            $actions[] = $hideReportingButton ? null : $reportingLink;
+        }
 
         if (api_is_allowed_to_edit() ||
             api_is_element_in_the_session(TOOL_SURVEY, $survey_id)
         ) {
-            $warning = addslashes(api_htmlentities(get_lang("DeleteSurvey").'?', ENT_QUOTES));
+            $warning = addslashes(api_htmlentities(get_lang('DeleteSurvey').'?', ENT_QUOTES));
             $actions[] = Display::url(
                 Display::return_icon('delete.png', get_lang('Delete')),
                 $codePath.'survey/survey_list.php?'
-                    .http_build_query($params + ['action' => 'delete', 'survey_id' => $survey_id]),
+                .http_build_query($params + ['action' => 'delete', 'survey_id' => $survey_id]),
                 [
-                    'onclick' => "javascript: if(!confirm('".$warning."')) return false;",
+                    'onclick' => "javascript: if (!confirm('".$warning."')) return false;",
                 ]
             );
         }
@@ -3082,9 +3058,9 @@ class SurveyUtil
         if ($search_restriction) {
             $search_restriction = ' AND '.$search_restriction;
         }
-        $from = intval($from);
-        $number_of_items = intval($number_of_items);
-        $column = intval($column);
+        $from = (int) $from;
+        $number_of_items = (int) $number_of_items;
+        $column = (int) $column;
         if (!in_array(strtolower($direction), ['asc', 'desc'])) {
             $direction = 'asc';
         }
@@ -3111,7 +3087,8 @@ class SurveyUtil
                 survey.iid AS col9,
                 survey.session_id AS session_id,
                 survey.answered,
-                survey.invited
+                survey.invited,
+                survey.survey_type
             FROM $table_survey survey
             LEFT JOIN $table_survey_question survey_question
             ON (survey.survey_id = survey_question.survey_id AND survey_question.c_id = $course_id)
@@ -3124,22 +3101,27 @@ class SurveyUtil
             ORDER BY col$column $direction 
             LIMIT $from,$number_of_items
         ";
-
         $res = Database::query($sql);
         $surveys = [];
         $array = [];
         $efv = new ExtraFieldValue('survey');
-
         while ($survey = Database::fetch_array($res)) {
             $array[0] = $survey[0];
-
             if (self::checkHideEditionToolsByCode($survey['col2'])) {
                 $array[1] = $survey[1];
             } else {
-                $array[1] = Display::url(
-                    $survey[1],
-                    api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey[0].'&'.api_get_cidreq()
-                );
+                // Doodle
+                if ($survey['survey_type'] == 3) {
+                    $array[1] = Display::url(
+                        $survey[1],
+                        api_get_path(WEB_CODE_PATH).'survey/meeting.php?survey_id='.$survey[0].'&'.api_get_cidreq()
+                    );
+                } else {
+                    $array[1] = Display::url(
+                        $survey[1],
+                        api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey[0].'&'.api_get_cidreq()
+                    );
+                }
             }
 
             // Validation when belonging to a session
@@ -3296,7 +3278,7 @@ class SurveyUtil
     {
         $_course = api_get_course_info();
         $course_id = $_course['real_id'];
-        $user_id = intval($user_id);
+        $user_id = (int) $user_id;
         $sessionId = api_get_session_id();
         $mandatoryAllowed = api_get_configuration_value('allow_mandatory_survey');
         $allowSurveyAvailabilityDatetime = api_get_configuration_value('allow_survey_availability_datetime');
@@ -3306,16 +3288,6 @@ class SurveyUtil
         $table_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
         $table_survey = Database::get_course_table(TABLE_SURVEY);
 
-        $sql = "SELECT question_id
-                FROM $table_survey_question
-                WHERE c_id = $course_id";
-        $result = Database::query($sql);
-
-        $all_question_id = [];
-        while ($row = Database::fetch_array($result, 'ASSOC')) {
-            $all_question_id[] = $row;
-        }
-
         echo '<table id="list-survey" class="table ">';
         echo '<thead>';
         echo '<tr>';
@@ -3338,8 +3310,8 @@ class SurveyUtil
                 $table_survey_invitation survey_invitation
                 ON (
                     survey.code = survey_invitation.survey_code AND
-                    survey.c_id = survey_invitation.c_id
-                    AND survey.session_id = survey_invitation.session_id
+                    survey.c_id = survey_invitation.c_id AND 
+                    survey.session_id = survey_invitation.session_id
                 )
 				WHERE
                     survey_invitation.user = $user_id AND                    
@@ -3363,8 +3335,9 @@ class SurveyUtil
                     [],
                     ICON_SIZE_TINY
                 );
-                echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/fillsurvey.php?course='.$_course['sysCode']
-                    .'&invitationcode='.$row['invitation_code'].'&cidReq='.$_course['sysCode'].'&id_session='.$row['session_id'].'">
+                $url = api_get_path(WEB_CODE_PATH).'survey/fillsurvey.php?course='.$_course['sysCode']
+                    .'&invitationcode='.$row['invitation_code'].'&cidReq='.$_course['sysCode'].'&id_session='.$row['session_id'];
+                echo '<a href="'.$url.'">
                     '.$row['title']
                     .'</a></td>';
             } else {

+ 8 - 6
main/survey/survey_invitation.php

@@ -63,24 +63,25 @@ if ($survey_data['anonymous'] == 1) {
     );
     $answered_data = [];
 }
+$url = api_get_self().'?survey_id='.$survey_id.'&'.api_get_cidreq();
 
 if (!isset($_GET['view']) || $_GET['view'] == 'invited') {
     echo get_lang('ViewInvited').' | ';
 } else {
-    echo '	<a href="'.api_get_self().'?survey_id='.$survey_id.'&view=invited">'.
+    echo '	<a href="'.$url.'&view=invited">'.
         get_lang('ViewInvited').'</a> |';
 }
 if ($_GET['view'] == 'answered') {
     echo get_lang('ViewAnswered').' | ';
 } else {
-    echo '	<a href="'.api_get_self().'?survey_id='.$survey_id.'&view=answered">'.
+    echo '	<a href="'.$url.'&view=answered">'.
         get_lang('ViewAnswered').'</a> |';
 }
 
 if ($_GET['view'] == 'unanswered') {
     echo get_lang('ViewUnanswered');
 } else {
-    echo '	<a href="'.api_get_self().'?survey_id='.$survey_id.'&view=unanswered">'.
+    echo '	<a href="'.$url.'&view=unanswered">'.
         get_lang('ViewUnanswered').'</a>';
 }
 
@@ -118,11 +119,13 @@ while ($row = Database::fetch_assoc($res)) {
         } else {
             echo '<td>'.$row['user'].'</td>';
         }
-        echo '	<td>'.api_get_local_time($row['invitation_date']).'</td>';
+        echo '	<td>'.Display::dateToStringAgoAndLongDate($row['invitation_date']).'</td>';
         echo '	<td>';
 
         if (in_array($row['user'], $answered_data) && !api_get_configuration_value('hide_survey_reporting_button')) {
-            echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=userreport&survey_id='.$survey_id.'&user='.$row['user'].'">'.
+            echo '<a href="'.
+                api_get_path(WEB_CODE_PATH).
+                'survey/reporting.php?action=userreport&survey_id='.$survey_id.'&user='.$row['user'].'&'.api_get_cidreq().'">'.
                 get_lang('ViewAnswers').'</a>';
         } else {
             echo '-';
@@ -136,5 +139,4 @@ while ($row = Database::fetch_assoc($res)) {
 // Closing the table
 echo '</table>';
 
-// Footer
 Display::display_footer();

+ 3 - 2
main/survey/survey_invite.php

@@ -237,11 +237,12 @@ if ($form->validate()) {
     // Counting the number of people that are invited
     $total_invited = SurveyUtil::update_count_invited($survey_data['code']);
     $total_count = $count_course_users + $counter_additional_users;
+    $invitationUrl = api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?survey_id='.$survey_data['survey_id'].'&'.api_get_cidreq();
     if ($total_invited > 0) {
-        $message = '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=answered&survey_id='.$survey_data['survey_id'].'">'.
+        $message = '<a href="'.$invitationUrl.'&view=answered">'.
             $survey_data['answered'].'</a> ';
         $message .= get_lang('HaveAnswered').' ';
-        $message .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=invited&survey_id='.$survey_data['survey_id'].'">'.
+        $message .= '<a href="'.$invitationUrl.'&view=invited">'.
             $total_invited.'</a> ';
         $message .= get_lang('WereInvited');
         echo Display::return_message($message, 'normal', false);

+ 81 - 58
main/survey/survey_list.php

@@ -17,7 +17,6 @@ if (!isset($_GET['cidReq'])) {
     $cidReset = true;
 }
 
-// Including the global initialization file
 require_once __DIR__.'/../inc/global.inc.php';
 $this_section = SECTION_COURSES;
 $current_course_tool = TOOL_SURVEY;
@@ -34,6 +33,7 @@ Event::event_access_tool(TOOL_SURVEY);
  * of the code)
  */
 $courseInfo = api_get_course_info();
+$sessionId = api_get_session_id();
 $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
     $currentUserId,
     $courseInfo
@@ -73,13 +73,85 @@ if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
     $tool_name = get_lang('SurveyList');
 }
 
-if ($action == 'copy_survey') {
-    if (api_is_allowed_to_edit()) {
-        SurveyManager::copy_survey($_GET['survey_id']);
-        $message = get_lang('SurveyCopied');
-        header('Location: '.api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq());
+$listUrl = api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq();
+$surveyId = isset($_GET['survey_id']) ? $_GET['survey_id'] : 0;
+
+switch ($action) {
+    case 'remove_multiplicate':
+        $surveyData = SurveyManager::get_survey($surveyId);
+        if (!empty($surveyData)) {
+            SurveyManager::removeMultiplicateQuestions($surveyData);
+            Display::addFlash(Display::return_message(get_lang('Updated'), 'confirmation', false));
+        }
+        header('Location: '.$listUrl);
         exit;
-    }
+        break;
+    case 'multiplicate':
+        $surveyData = SurveyManager::get_survey($surveyId);
+        if (!empty($surveyData)) {
+            SurveyManager::multiplicateQuestions($surveyData);
+            Display::cleanFlashMessages();
+            Display::addFlash(Display::return_message(get_lang('Updated'), 'confirmation', false));
+        }
+        header('Location: '.$listUrl);
+        exit;
+        break;
+    case 'copy_survey':
+        if (!empty($surveyId) && api_is_allowed_to_edit()) {
+            SurveyManager::copy_survey($surveyId);
+            Display::addFlash(Display::return_message(get_lang('SurveyCopied'), 'confirmation', false));
+            header('Location: '.$listUrl);
+            exit;
+        }
+        break;
+    case 'delete':
+        if (!empty($surveyId)) {
+            // Getting the information of the survey (used for when the survey is shared)
+            $survey_data = SurveyManager::get_survey($surveyId);
+            if (api_is_session_general_coach() && $sessionId != $survey_data['session_id']) {
+                // The coach can't delete a survey not belonging to his session
+                api_not_allowed();
+            }
+            // If the survey is shared => also delete the shared content
+            if (isset($survey_data['survey_share']) &&
+                is_numeric($survey_data['survey_share'])
+            ) {
+                SurveyManager::delete_survey($survey_data['survey_share'], true);
+            }
+
+            $return = SurveyManager::delete_survey($surveyId);
+
+            if ($return) {
+                Display::addFlash(Display::return_message(get_lang('SurveyDeleted'), 'confirmation', false));
+            } else {
+                Display::addFlash(Display::return_message(get_lang('ErrorOccurred'), 'error', false));
+            }
+            header('Location: '.$listUrl);
+            exit;
+        }
+        break;
+    case 'empty':
+        $mysession = api_get_session_id();
+        if ($mysession != 0) {
+            if (!((api_is_session_general_coach() || api_is_platform_admin()) &&
+                api_is_element_in_the_session(TOOL_SURVEY, $surveyId))) {
+                // The coach can't empty a survey not belonging to his session
+                api_not_allowed();
+            }
+        } else {
+            if (!(api_is_course_admin() || api_is_platform_admin())) {
+                api_not_allowed();
+            }
+        }
+        $return = SurveyManager::empty_survey($surveyId);
+        if ($return) {
+            Display::addFlash(Display::return_message(get_lang('SurveyEmptied'), 'confirmation', false));
+        } else {
+            Display::addFlash(Display::return_message(get_lang('ErrorOccurred'), 'error', false));
+        }
+        header('Location: '.$listUrl);
+        exit;
+        break;
 }
 
 // Header
@@ -92,56 +164,6 @@ if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
     SurveyUtil::display_survey_search_form();
 }
 
-$sessionId = api_get_session_id();
-
-// Action handling: deleting a survey
-if ($action === 'delete' && isset($_GET['survey_id'])) {
-    // Getting the information of the survey (used for when the survey is shared)
-    $survey_data = SurveyManager::get_survey($_GET['survey_id']);
-    if (api_is_session_general_coach() && $sessionId != $survey_data['session_id']) {
-        // The coach can't delete a survey not belonging to his session
-        api_not_allowed();
-        exit;
-    }
-    // If the survey is shared => also delete the shared content
-    if (isset($survey_data['survey_share']) &&
-        is_numeric($survey_data['survey_share'])
-    ) {
-        SurveyManager::delete_survey($survey_data['survey_share'], true);
-    }
-
-    $return = SurveyManager::delete_survey($_GET['survey_id']);
-
-    if ($return) {
-        echo Display::return_message(get_lang('SurveyDeleted'), 'confirmation', false);
-    } else {
-        echo Display::return_message(get_lang('ErrorOccurred'), 'error', false);
-    }
-}
-
-if ($action == 'empty') {
-    $mysession = api_get_session_id();
-    if ($mysession != 0) {
-        if (!((api_is_session_general_coach() || api_is_platform_admin()) &&
-            api_is_element_in_the_session(TOOL_SURVEY, $_GET['survey_id']))) {
-            // The coach can't empty a survey not belonging to his session
-            api_not_allowed();
-            exit;
-        }
-    } else {
-        if (!(api_is_course_admin() || api_is_platform_admin())) {
-            api_not_allowed();
-            exit;
-        }
-    }
-    $return = SurveyManager::empty_survey(intval($_GET['survey_id']));
-    if ($return) {
-        echo Display::return_message(get_lang('SurveyEmptied'), 'confirmation', false);
-    } else {
-        echo Display::return_message(get_lang('ErrorOccurred'), 'error', false);
-    }
-}
-
 // Action handling: performing the same action on multiple surveys
 if (isset($_POST['action']) && $_POST['action']) {
     if (is_array($_POST['id'])) {
@@ -166,11 +188,12 @@ if (!api_is_session_general_coach() || $extend_rights_for_coachs == 'true') {
     // Action links
     echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/create_new_survey.php?'.api_get_cidreq().'&amp;action=add">'.
         Display::return_icon('new_survey.png', get_lang('CreateNewSurvey'), '', ICON_SIZE_MEDIUM).'</a> ';
+    $url = api_get_path(WEB_CODE_PATH).'survey/create_meeting.php?'.api_get_cidreq();
+    echo Display::url(Display::return_icon('add.png', get_lang('CreateNewSurvey'), '', ICON_SIZE_MEDIUM), $url);
 }
 echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;search=advanced">'.
     Display::return_icon('search.png', get_lang('Search'), '', ICON_SIZE_MEDIUM).'</a>';
 echo '</div>';
-
 // Load main content
 if (api_is_session_general_coach() && $extend_rights_for_coachs == 'false') {
     SurveyUtil::display_survey_list_for_coach();