diff --git a/main/survey/fillsurvey.php b/main/survey/fillsurvey.php index 011adf7a52..c3bca5d408 100755 --- a/main/survey/fillsurvey.php +++ b/main/survey/fillsurvey.php @@ -663,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"; @@ -1027,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]).") @@ -1137,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.") @@ -1183,7 +1186,7 @@ if ( $sql = "SELECT * FROM $table_survey_question 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; @@ -1235,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('
'); - $form->addHtml('
'.$question['sort'].'. '.strip_tags($question['survey_question']).'
'); + $form->addHtml('
'.$questionNumber.'. '.strip_tags($question['survey_question']).'
'); $userAnswerData = SurveyUtil::get_answers_of_question_by_user($question['survey_id'], $question['question_id']); $finalAnswer = null; @@ -1267,6 +1285,7 @@ if (isset($questions) && is_array($questions)) { } $display->render($form, $question, $finalAnswer); $form->addHtml('
'); + $questionCounter++; } } diff --git a/main/survey/preview.php b/main/survey/preview.php index 50887d8e71..804e9239ab 100755 --- a/main/survey/preview.php +++ b/main/survey/preview.php @@ -83,7 +83,7 @@ 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) @@ -144,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, @@ -165,23 +175,24 @@ if (api_is_course_admin() || 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 AND - survey_question NOT LIKE '%{{%' - + 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; @@ -191,22 +202,27 @@ if (api_is_course_admin() || } } + $before = 0; + if (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 + 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='.$surveyId.'&show='.$show.'&'.api_get_cidreq(); $form = new FormValidator( @@ -219,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('
'); - $form->addHtml('
'.$key.'. '.strip_tags($question['survey_question']).'
'); + $form->addHtml('
'.$counter.'. '.strip_tags($question['survey_question']).'
'); $display->render($form, $question); $form->addHtml('
'); + $counter++; } } $form->addHtml('
'); diff --git a/main/survey/survey.lib.php b/main/survey/survey.lib.php index 8df955eb2c..0fdacadc15 100755 --- a/main/survey/survey.lib.php +++ b/main/survey/survey.lib.php @@ -2138,10 +2138,15 @@ class SurveyManager $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); @@ -2156,10 +2161,10 @@ class SurveyManager 'shared_question_id' => 0, ]; self::save_question($surveyData, $values); + $classCounter++; + continue; } - $users = $obj->get_users_by_usergroup($class['id']); - //var_dump($question); foreach ($users as $userId) { $userInfo = api_get_user_info($userId); @@ -2188,6 +2193,22 @@ class SurveyManager 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); + } + } } } diff --git a/main/survey/surveyUtil.class.php b/main/survey/surveyUtil.class.php index a1a1744176..64fefb22a5 100755 --- a/main/survey/surveyUtil.class.php +++ b/main/survey/surveyUtil.class.php @@ -2893,8 +2893,9 @@ 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')), @@ -2937,12 +2938,14 @@ class SurveyUtil ); } } + 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('mail_send.png', get_lang('Publish')), $codePath.'survey/survey_invite.php?'.http_build_query($params + ['survey_id' => $survey_id]) @@ -2959,9 +2962,9 @@ class SurveyUtil $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;", ] ); } diff --git a/main/survey/survey_list.php b/main/survey/survey_list.php index 347f1a9f93..5255c291c9 100755 --- a/main/survey/survey_list.php +++ b/main/survey/survey_list.php @@ -81,7 +81,7 @@ switch ($action) { $surveyData = SurveyManager::get_survey($surveyId); if (!empty($surveyData)) { SurveyManager::removeMultiplicateQuestions($surveyData); - Display::addFlash(Display::return_message(get_lang('Removed'), 'confirmation', false)); + Display::addFlash(Display::return_message(get_lang('Updated'), 'confirmation', false)); } header('Location: '.$listUrl); exit; @@ -90,6 +90,7 @@ switch ($action) { $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);