diff --git a/main/exercise/export/aiken/aiken_classes.php b/main/exercise/export/aiken/aiken_classes.php index 8d8447eb49..89dd422962 100755 --- a/main/exercise/export/aiken/aiken_classes.php +++ b/main/exercise/export/aiken/aiken_classes.php @@ -32,6 +32,26 @@ class Aiken2Question extends Question return $answer; } + /** + * @param string $code + * + * @return bool + */ + public function addCode($code) + { + if (api_get_configuration_value('allow_question_code') && !empty($this->id)) { + $code = Database::escape_string($code); + $table = Database::get_course_table(TABLE_QUIZ_QUESTION); + $sql = "UPDATE $table SET code = '$code' + WHERE iid = {$this->id} AND c_id = {$this->course['real_id']}"; + Database::query($sql); + + return true; + } + + return false; + } + public function createAnswersForm($form) { return true; diff --git a/main/exercise/export/aiken/aiken_import.inc.php b/main/exercise/export/aiken/aiken_import.inc.php index 91085f012d..3feedbf3ba 100755 --- a/main/exercise/export/aiken/aiken_import.inc.php +++ b/main/exercise/export/aiken/aiken_import.inc.php @@ -191,9 +191,15 @@ function aiken_import_exercise($file) if (isset($question_array['description'])) { $question->updateDescription($question_array['description']); } + $type = $question->selectType(); $question->type = constant($type); $question->save($exercise); + + if (isset($question_array['code'])) { + $question->addCode($question_array['code']); + } + $last_question_id = $question->selectId(); //3. Create answer $answer = new Answer($last_question_id); @@ -297,11 +303,9 @@ function aiken_parse_file(&$exercise_info, $exercisePath, $file, $questionFile) //weight for correct answer $exercise_info['question'][$question_index]['weighting'][$correct_answer_index] = 1; } elseif (preg_match('/^SCORE:\s?(.*)/', $info, $matches)) { - //the correct answers - $correct_answer_index = array_search($matches[1], $answers_array); $exercise_info['question'][$question_index]['score'] = (float) $matches[1]; - //weight for correct answer - //$exercise_info['question'][$question_index]['weighting'][$correct_answer_index] = 1; + } elseif (preg_match('/^CODE:\s?(.*)/', $info, $matches)) { + $exercise_info['question'][$question_index]['code'] = $matches[1]; } elseif (preg_match('/^ANSWER_EXPLANATION:\s?(.*)/', $info, $matches)) { //Comment of correct answer $correct_answer_index = array_search($matches[1], $answers_array); diff --git a/main/inc/lib/glossary.lib.php b/main/inc/lib/glossary.lib.php index 816bfba183..3748d204bc 100755 --- a/main/inc/lib/glossary.lib.php +++ b/main/inc/lib/glossary.lib.php @@ -419,7 +419,7 @@ class GlossaryManager Display::return_icon('view_text.png', get_lang('TableView'), '', ICON_SIZE_MEDIUM).''; } - if (!api_is_anonymous()) { + if (api_is_allowed_to_edit(true, true, true)) { $actionsLeft .= Display::url( Display::return_icon('export_to_documents.png', get_lang('ExportToDocArea'), [], ICON_SIZE_MEDIUM), api_get_self().'?'.api_get_cidreq().'&'.http_build_query(['action' => 'export_documents']) diff --git a/main/install/configuration.dist.php b/main/install/configuration.dist.php index 2385a6805c..8ed65f9124 100755 --- a/main/install/configuration.dist.php +++ b/main/install/configuration.dist.php @@ -1067,6 +1067,10 @@ VALUES (2, 13, 'session_courses_read_only_mode', 'Lock Course In Session', 1, 1, // Hide social media links //$_configuration['hide_social_media_links'] = false; +// Allow code field in exercise questions +//ALTER TABLE c_quiz_question ADD COLUMN code VARCHAR(255) NULL DEFAULT NULL; +// $_configuration['allow_question_code'] = false; + // ------ Custom DB changes (keep this at the end) // Add user activation by confirmation email // This option prevents the new user to login in the platform if your account is not confirmed via email