read($fromExercise); } $nameTools = get_lang('QuestionPool'); $interbreadcrumb[] = ["url" => "exercise.php?".api_get_cidreq(), "name" => get_lang('Exercises')]; if (!empty($objExercise)) { $interbreadcrumb[] = [ "url" => "admin.php?exerciseId=".$objExercise->id."&".api_get_cidreq(), "name" => $objExercise->selectTitle(true) ]; } // message to be displayed if actions successful $displayMessage = ''; if ($is_allowedToEdit) { // Duplicating a Question if (!isset($_POST['recup']) && $question_copy != 0 && isset($fromExercise)) { $origin_course_id = (int) $_GET['course_id']; $origin_course_info = api_get_course_info_by_id($origin_course_id); $current_course = api_get_course_info(); $old_question_id = $question_copy; // Reading the source question $old_question_obj = Question::read($old_question_id, $origin_course_id); $courseId = $current_course['real_id']; if ($old_question_obj) { $old_question_obj->updateTitle( $old_question_obj->selectTitle().' - '.get_lang('Copy') ); //Duplicating the source question, in the current course $new_id = $old_question_obj->duplicate($current_course); //Reading new question $new_question_obj = Question::read($new_id); $new_question_obj->addToList($fromExercise); //Reading Answers obj of the current course $new_answer_obj = new Answer($old_question_id, $origin_course_id); $new_answer_obj->read(); //Duplicating the Answers in the current course $new_answer_obj->duplicate($new_question_obj, $current_course); // destruction of the Question object unset($new_question_obj); unset($old_question_obj); $objExercise = new Exercise($courseId); $objExercise->read($fromExercise); Session::write('objExercise', $objExercise); } $displayMessage = get_lang('ItemAdded'); } // Deletes a question from the database and all exercises if ($delete) { // Construction of the Question object $objQuestionTmp = Question::read($delete); // if the question exists if ($objQuestionTmp) { // deletes the question from all exercises $objQuestionTmp->delete(); } // destruction of the Question object unset($objQuestionTmp); } elseif ($recup && $fromExercise) { // gets an existing question and copies it into a new exercise $objQuestionTmp = Question :: read($recup); // if the question exists if ($objQuestionTmp) { /* Adds the exercise ID represented by $fromExercise into the list of exercises for the current question */ $objQuestionTmp->addToList($fromExercise); } // destruction of the Question object unset($objQuestionTmp); if (!$objExercise instanceof Exercise) { $objExercise = new Exercise(); $objExercise->read($fromExercise); } // Adds the question ID represented by $recup into the list of questions for the current exercise $objExercise->addToList($recup); Session::write('objExercise', $objExercise); } elseif (isset($_POST['recup']) && is_array($_POST['recup']) && $fromExercise) { $list_recup = $_POST['recup']; foreach ($list_recup as $course_id => $question_data) { $origin_course_id = (int) $course_id; $origin_course_info = api_get_course_info_by_id($origin_course_id); $current_course = api_get_course_info(); foreach ($question_data as $old_question_id) { //Reading the source question $old_question_obj = Question::read($old_question_id, $origin_course_id); if ($old_question_obj) { $old_question_obj->updateTitle( $old_question_obj->selectTitle().' - '.get_lang('Copy') ); // Duplicating the source question, in the current course $new_id = $old_question_obj->duplicate($current_course); // Reading new question $new_question_obj = Question::read($new_id); $new_question_obj->addToList($fromExercise); //Reading Answers obj of the current course $new_answer_obj = new Answer($old_question_id, $origin_course_id); $new_answer_obj->read(); //Duplicating the Answers in the current course $new_answer_obj->duplicate($new_question_obj, $current_course); // destruction of the Question object unset($new_question_obj); unset($old_question_obj); if (!$objExercise instanceof Exercise) { $objExercise = new Exercise(); $objExercise->read($fromExercise); } } } } Session::write('objExercise', $objExercise); } } if (api_is_in_gradebook()) { $interbreadcrumb[] = [ 'url' => Category::getUrl(), 'name' => get_lang('ToolGradebook') ]; } // if admin of course if (!$is_allowedToEdit) { api_not_allowed(true); } $confirmYourChoice = addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)); $htmlHeadXtra[] = " "; Display::display_header($nameTools, 'Exercise'); // Menu echo '