From a067dbf5ad9da9ab7553b722e8819ea743325af0 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Fri, 10 Jan 2020 17:46:28 +0100 Subject: [PATCH] Survey: Enable translatable survey (for textarea contents only) - refs BT#16553 --- main/survey/create_new_survey.php | 2 +- main/survey/fillsurvey.php | 4 +- main/survey/preview.php | 6 +- main/survey/question.php | 2 + main/survey/survey.lib.php | 50 +++++++------- main/survey/survey.php | 20 +++--- main/survey/survey_list.php | 2 + .../Editor/CkEditor/Toolbar/Survey.php | 14 +++- .../CkEditor/Toolbar/SurveyQuestion.php | 66 +++++++++++++++++++ 9 files changed, 127 insertions(+), 39 deletions(-) diff --git a/main/survey/create_new_survey.php b/main/survey/create_new_survey.php index 086770a232..d895f475e0 100755 --- a/main/survey/create_new_survey.php +++ b/main/survey/create_new_survey.php @@ -48,7 +48,7 @@ $survey_data = SurveyManager::get_survey($survey_id); $course_id = api_get_course_id(); $session_id = api_get_session_id(); $gradebook_link_type = 8; -$urlname = isset($survey_data['title']) ? strip_tags($survey_data['title']) : null; +$urlname = isset($survey_data['title']) ? strip_tags($survey_data['title'], '') : null; // Breadcrumbs if ($action == 'add') { diff --git a/main/survey/fillsurvey.php b/main/survey/fillsurvey.php index 8b8924403e..6d6db9fc9d 100755 --- a/main/survey/fillsurvey.php +++ b/main/survey/fillsurvey.php @@ -551,13 +551,15 @@ if ($survey_data['form_fields'] != '' && $form->setDefaults($user_data); } +$htmlHeadXtra[] = ''; + Display::display_header(get_lang('ToolSurvey')); // Displaying the survey title and subtitle (appears on every page) echo '
'; echo ''; +echo strip_tags($survey_data['survey_title'], '').'
'; if (!empty($survey_data['survey_subtitle'])) { echo '

'.strip_tags($survey_data['survey_subtitle']).'

'; } diff --git a/main/survey/preview.php b/main/survey/preview.php index 6b620bd454..0f19df74c2 100755 --- a/main/survey/preview.php +++ b/main/survey/preview.php @@ -47,6 +47,8 @@ $interbreadcrumb[] = [ 'name' => strip_tags($survey_data['title']), ]; +$htmlHeadXtra[] = ''; + $show = 0; Display::display_header(get_lang('SurveyPreview')); @@ -83,7 +85,7 @@ if (isset($_GET['show'])) { $counter = 0; $sql = "SELECT * FROM $table_survey_question WHERE - survey_question NOT LIKE '%{{%' AND + survey_question NOT LIKE '%{{%' AND c_id = $course_id AND survey_id = '".$surveyId."' ORDER BY sort ASC"; @@ -131,7 +133,7 @@ if (isset($_GET['show'])) { 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); diff --git a/main/survey/question.php b/main/survey/question.php index 2ce521f5fe..5229e85290 100755 --- a/main/survey/question.php +++ b/main/survey/question.php @@ -17,6 +17,8 @@ $(function() { }); } ); '; +$htmlHeadXtra[] = ''; + /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/ if (!api_is_allowed_to_edit(false, true)) { api_not_allowed(true); diff --git a/main/survey/survey.lib.php b/main/survey/survey.lib.php index 4504a720d5..f6d936156c 100755 --- a/main/survey/survey.lib.php +++ b/main/survey/survey.lib.php @@ -1405,12 +1405,12 @@ class SurveyManager } } - $sql = "UPDATE $table_survey_question + $sql = "UPDATE $table_survey_question SET sort = '".Database::escape_string($question_sort_two)."' WHERE c_id = $course_id AND question_id='".intval($question_id_one)."'"; Database::query($sql); - $sql = "UPDATE $table_survey_question + $sql = "UPDATE $table_survey_question SET sort = '".Database::escape_string($question_sort_one)."' WHERE c_id = $course_id AND question_id='".intval($question_id_two)."'"; Database::query($sql); @@ -1716,7 +1716,7 @@ class SurveyManager $course_id = api_get_course_int_id(); $table = Database::get_course_table(TABLE_SURVEY_ANSWER); $survey_id = (int) $survey_id; - $sql = "DELETE FROM $table + $sql = "DELETE FROM $table WHERE c_id = $course_id AND survey_id = $survey_id"; Database::query($sql); @@ -1737,7 +1737,7 @@ class SurveyManager $course_id = (int) $course_id; $survey_id = (int) $survey_id; - $sql = "SELECT DISTINCT user + $sql = "SELECT DISTINCT user FROM $table WHERE c_id = $course_id AND @@ -1787,9 +1787,9 @@ class SurveyManager ? ' ORDER BY user.firstname, user.lastname' : ' ORDER BY user.lastname, user.firstname'; $sql = "SELECT DISTINCT - answered_user.user as invited_user, - user.firstname, - user.lastname, + answered_user.user as invited_user, + user.firstname, + user.lastname, user.user_id FROM $table_survey_answer answered_user LEFT JOIN $table_user as user ON answered_user.user = user.user_id @@ -1806,7 +1806,7 @@ class SurveyManager $tblSurvey = Database::get_course_table(TABLE_SURVEY); $sql = "SELECT i.user FROM $tblInvitation i - INNER JOIN $tblSurvey s + INNER JOIN $tblSurvey s ON i.survey_code = s.code AND i.c_id = s.c_id AND i.session_id = s.session_id @@ -1930,14 +1930,14 @@ 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 AND + 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 ") @@ -1995,16 +1995,16 @@ class SurveyManager $courseId = (int) $surveyData['c_id']; $sessionId = (int) $surveyData['session_id']; - $sql = "DELETE FROM $surveyInvitationTable + $sql = "DELETE FROM $surveyInvitationTable WHERE session_id = $sessionId AND c_id = $courseId AND survey_code = '$surveyCode' "; Database::query($sql); - $sql = "DELETE FROM $surveyAnswerTable + $sql = "DELETE FROM $surveyAnswerTable WHERE survey_id = $surveyId AND c_id = $courseId "; Database::query($sql); - $sql = "UPDATE $surveyTable - SET invited = 0, answered = 0 + $sql = "UPDATE $surveyTable + SET invited = 0, answered = 0 WHERE survey_id = $surveyId AND c_id = $courseId AND session_id = $sessionId "; Database::query($sql); @@ -2052,11 +2052,11 @@ class SurveyManager $newSurveyId = Database::insert($surveyTable, $surveyData); if ($newSurveyId) { - $sql = "UPDATE $surveyTable SET survey_id = $newSurveyId + $sql = "UPDATE $surveyTable SET survey_id = $newSurveyId WHERE iid = $newSurveyId"; Database::query($sql); - $sql = "SELECT * FROM $surveyQuestionGroupTable + $sql = "SELECT * FROM $surveyQuestionGroupTable WHERE survey_id = $surveyId AND c_id = $originalCourseId "; $res = Database::query($sql); while ($row = Database::fetch_array($res, 'ASSOC')) { @@ -2075,7 +2075,7 @@ class SurveyManager } // Get questions - $sql = "SELECT * FROM $surveyQuestionTable + $sql = "SELECT * FROM $surveyQuestionTable WHERE survey_id = $surveyId AND c_id = $originalCourseId"; $res = Database::query($sql); while ($row = Database::fetch_array($res, 'ASSOC')) { @@ -2102,7 +2102,7 @@ class SurveyManager $insertId = Database::insert($surveyQuestionTable, $params); if ($insertId) { - $sql = "UPDATE $surveyQuestionTable + $sql = "UPDATE $surveyQuestionTable SET question_id = iid WHERE iid = $insertId"; Database::query($sql); @@ -2112,7 +2112,7 @@ class SurveyManager } // Get questions options - $sql = "SELECT * FROM $surveyOptionsTable + $sql = "SELECT * FROM $surveyOptionsTable WHERE survey_id = $surveyId AND c_id = $originalCourseId"; $res = Database::query($sql); diff --git a/main/survey/survey.php b/main/survey/survey.php index 95419c6969..3a00003bb5 100755 --- a/main/survey/survey.php +++ b/main/survey/survey.php @@ -92,7 +92,7 @@ if ($is_survey_type_1 && ($action == 'addgroup' || $action == 'deletegroup')) { } if ($action == 'deletegroup') { - $sql = 'DELETE FROM '.$table_survey_question_group.' + $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'; @@ -101,6 +101,8 @@ if ($is_survey_type_1 && ($action == 'addgroup' || $action == 'deletegroup')) { exit; } +$htmlHeadXtra[] = ''; + // Displaying the header Display::display_header($tool_name, 'Survey'); @@ -239,7 +241,7 @@ echo ''; // 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 = $survey_id + WHERE c_id = $course_id AND survey_id = $survey_id ORDER BY id"; $result = Database::query($sql); $groups = []; @@ -249,8 +251,8 @@ while ($row = Database::fetch_array($result)) { $sql = "SELECT survey_question.*, count(survey_question_option.question_option_id) as number_of_options FROM $table_survey_question survey_question LEFT JOIN $table_survey_question_option survey_question_option - ON - survey_question.question_id = survey_question_option.question_id AND + ON + survey_question.question_id = survey_question_option.question_id AND survey_question_option.c_id = $course_id WHERE survey_question.survey_id = ".intval($survey_id)." AND @@ -349,7 +351,7 @@ if ($is_survey_type_1) { echo '
'.get_lang('Name').''.get_lang('Description').'
'; echo '
'; if ($_GET['action'] == 'editgroup') { - $sql = 'SELECT name,description FROM '.$table_survey_question_group.' + $sql = 'SELECT name,description FROM '.$table_survey_question_group.' WHERE id = '.intval($_GET['gid']).' AND survey_id = '.intval($survey_id).' limit 1'; $rs = Database::query($sql); $editedrow = Database::fetch_array($rs, 'ASSOC'); @@ -371,11 +373,11 @@ if ($is_survey_type_1) { echo ' '.get_lang('Modify').''; echo ' '; - $sql = 'SELECT id,name,description + $sql = 'SELECT id,name,description FROM '.$table_survey_question_group.' - WHERE - c_id = '.$course_id.' AND - survey_id = '.intval($survey_id).' + WHERE + c_id = '.$course_id.' AND + survey_id = '.intval($survey_id).' ORDER BY name'; $rs = Database::query($sql); diff --git a/main/survey/survey_list.php b/main/survey/survey_list.php index c68b78c023..5cb5b00210 100755 --- a/main/survey/survey_list.php +++ b/main/survey/survey_list.php @@ -49,6 +49,8 @@ $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh( $courseInfo ); +$htmlHeadXtra[] = ''; + if ($isDrhOfCourse) { Display::display_header(get_lang('SurveyList')); // Tool introduction diff --git a/src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/Survey.php b/src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/Survey.php index d037d27256..c557fb2e81 100644 --- a/src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/Survey.php +++ b/src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/Survey.php @@ -57,7 +57,19 @@ class Survey extends Basic ['Table', '-', 'CreateDiv'], ['BulletedList', 'NumberedList', 'HorizontalRule', '-', 'Outdent', 'Indent', 'Blockquote'], ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'], - ['Bold', 'Italic', 'Underline', 'Strike', '-', 'Subscript', 'Superscript', '-', 'TextColor', 'BGColor'], + [ + 'Bold', + 'Italic', + 'Underline', + 'Strike', + '-', + 'Subscript', + 'Superscript', + '-', + 'TextColor', + 'BGColor', + api_get_configuration_value('translate_html') ? 'Language' : '', + ], [api_get_setting('allow_spellcheck') == 'true' ? 'Scayt' : ''], ['Styles', 'Format', 'Font', 'FontSize'], ['PageBreak', 'ShowBlocks', 'Source'], diff --git a/src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/SurveyQuestion.php b/src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/SurveyQuestion.php index 1406764127..6848aacee7 100644 --- a/src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/SurveyQuestion.php +++ b/src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/SurveyQuestion.php @@ -10,4 +10,70 @@ namespace Chamilo\CoreBundle\Component\Editor\CkEditor\Toolbar; */ class SurveyQuestion extends Basic { + /** + * Get the toolbar config. + * + * @return array + */ + public function getConfig() + { + if (api_get_setting('more_buttons_maximized_mode') != 'true') { + $config['toolbar'] = $this->getNormalToolbar(); + } else { + $config['toolbar_minToolbar'] = $this->getMinimizedToolbar(); + $config['toolbar_maxToolbar'] = $this->getMaximizedToolbar(); + } + + return $config; + } + /** + * Get the toolbar configuration when CKEditor is maximized. + * + * @return array + */ + protected function getMaximizedToolbar() + { + return [ + $this->getNewPageBlock(), + ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', 'inserthtml'], + ['Undo', 'Redo', '-', 'SelectAll', 'Find', '-', 'RemoveFormat'], + ['Link', 'Unlink', 'Anchor', 'Glossary'], + [ + 'Image', + 'Mapping', + 'Video', + 'Oembed', + 'Flash', + 'Youtube', + 'Audio', + 'leaflet', + 'Smiley', + 'SpecialChar', + 'Asciimath', + 'Asciisvg', + ], + '/', + ['Table', '-', 'CreateDiv'], + ['BulletedList', 'NumberedList', 'HorizontalRule', '-', 'Outdent', 'Indent', 'Blockquote'], + ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'], + [ + 'Bold', + 'Italic', + 'Underline', + 'Strike', + '-', + 'Subscript', + 'Superscript', + '-', + 'TextColor', + 'BGColor', + api_get_configuration_value('translate_html') ? 'Language' : '', + ], + [api_get_setting('allow_spellcheck') == 'true' ? 'Scayt' : ''], + ['Styles', 'Format', 'Font', 'FontSize'], + ['PageBreak', 'ShowBlocks'], + api_get_setting('enabled_wiris') == 'true' ? ['ckeditor_wiris_formulaEditor', 'ckeditor_wiris_CAS'] : [''], + ['Toolbarswitch', 'Source'], + ]; + } }