$val) { if (is_string($val)) { $_POST[$key] = stripslashes($val); } elseif (is_array($val)) { foreach ($val as $key2 => $val2) { $_POST[$key][$key2] = stripslashes($val2); } } $GLOBALS[$key] = $_POST[$key]; } } // Get vars from GET if (empty($exerciseId)) { $exerciseId = isset($_GET['exerciseId'])?intval($_GET['exerciseId']):'0'; } if (empty($newQuestion)) { $newQuestion = isset($_GET['newQuestion'])?$_GET['newQuestion']:0; } if (empty($modifyAnswers)) { $modifyAnswers = isset($_GET['modifyAnswers'])?$_GET['modifyAnswers']:0; } if (empty($editQuestion)) { $editQuestion = isset($_GET['editQuestion'])?$_GET['editQuestion']:0; } if (empty($modifyQuestion)) { $modifyQuestion = isset($_GET['modifyQuestion'])?$_GET['modifyQuestion']:0; } if (empty($deleteQuestion)) { $deleteQuestion = isset($_GET['deleteQuestion'])?$_GET['deleteQuestion']:0; } $clone_question = isset($_REQUEST['clone_question']) ? $_REQUEST['clone_question']:0; if (empty($questionId)) { $questionId = isset($_SESSION['questionId'])?$_SESSION['questionId']:0; } /* Cleaning all incomplete attempts of the admin/teacher to avoid weird problems when changing the exercise settings, number of questions, etc */ delete_all_incomplete_attempts(api_get_user_id(), $exerciseId, api_get_course_int_id(), api_get_session_id()); /** @var Exercise $objExercise */ $objExercise = Session::read('objExercise'); /** @var Question $objQuestion */ $objQuestion = Session::read('objQuestion'); /** @var Answer $objAnswer */ $objAnswer = Session::read('objAnswer'); // document path $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'; // picture path $picturePath = $documentPath.'/images'; // audio path $audioPath = $documentPath.'/audio'; // the 5 types of answers $aType = array( get_lang('UniqueSelect'), get_lang('MultipleSelect'), get_lang('FillBlanks'), get_lang('Matching'), get_lang('FreeAnswer') ); // tables used in the exercise tool if (!empty($_GET['action']) && $_GET['action'] == 'exportqti2' && !empty($_GET['questionId'])) { require_once 'export/qti2/qti2_export.php'; $export = export_question($_GET['questionId'], true); $qid = (int)$_GET['questionId']; $archive_path = api_get_path(SYS_ARCHIVE_PATH); $temp_dir_short = uniqid(); $temp_zip_dir = $archive_path."/".$temp_dir_short; if (!is_dir($temp_zip_dir)) { mkdir($temp_zip_dir, api_get_permissions_for_new_directories()); } $temp_zip_file = $temp_zip_dir."/".api_get_unique_id().".zip"; $temp_xml_file = $temp_zip_dir."/qti2export_".$qid.'.xml'; file_put_contents($temp_xml_file, $export); $zip_folder = new PclZip($temp_zip_file); $zip_folder->add($temp_xml_file, PCLZIP_OPT_REMOVE_ALL_PATH); $name = 'qti2_export_'.$qid.'.zip'; DocumentManager::file_send_for_download($temp_zip_file, true, $name); unlink($temp_zip_file); unlink($temp_xml_file); rmdir($temp_zip_dir); //DocumentManager::string_send_for_download($export,true,'qti2export_q'.$_GET['questionId'].'.xml'); exit; //otherwise following clicks may become buggy } // Initializes the Exercise object. if (!is_object($objExercise)) { // construction of the Exercise object $objExercise = new Exercise(); // creation of a new exercise if wrong or not specified exercise ID if ($exerciseId) { $objExercise->read($exerciseId, true); } // saves the object into the session Session::write('objExercise', $objExercise); } if ($objExercise->fastEdition) { $htmlHeadXtra[] = api_get_jqgrid_js(); } $nbrQuestions = $objExercise->getQuestionCount(); // Initializes the Question object if ($editQuestion || $newQuestion || $modifyQuestion || $modifyAnswers) { if ($editQuestion || $newQuestion) { // reads question data if ($editQuestion) { // question not found if (!$objQuestion = Question::read($editQuestion, null, $objExercise)) { api_not_allowed(); } // saves the object into the session Session::write('objQuestion', $objQuestion); } } // Checks if the object exists. if (is_object($objQuestion)) { // gets the question ID $questionId = $objQuestion->selectId(); } } // If cancelling an exercise. if (!empty($cancelExercise)) { // existing exercise if ($exerciseId) { unset($modifyExercise); } else { // new exercise // goes back to the exercise list header('Location: '.$urlMainExercise.'exercice.php'); exit(); } } // if cancelling question creation/modification if (!empty($cancelQuestion)) { // if we are creating a new question from the question pool if (!$exerciseId && !$questionId) { // goes back to the question pool header('Location: '.$urlMainExercise.'question_pool.php'); exit(); } else { // goes back to the question viewing $editQuestion = $modifyQuestion; unset($newQuestion, $modifyQuestion); } } if (!empty($clone_question) && !empty($objExercise->id)) { $old_question_obj = Question::read($clone_question, api_get_course_int_id()); $old_question_obj->question = $old_question_obj->question.' - '.get_lang('Copy'); $new_id = $old_question_obj->duplicate(); $new_question_obj = Question::read($new_id, api_get_course_int_id()); $new_question_obj->addToList($objExercise->id); // This should be moved to the duplicate function $new_answer_obj = new Answer($clone_question, null, $objExercise); $new_answer_obj->read(); $new_answer_obj->duplicate($new_id); // Reloading tne $objExercise obj $objExercise->read($objExercise->id); header('Location: '.$urlMainExercise.'admin.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id); exit; } // if cancelling answer creation/modification if (!empty($cancelAnswers)) { // goes back to the question viewing $editQuestion = $modifyAnswers; unset($modifyAnswers); } $nameTools = get_lang('ExerciseManagement'); // modifies the query string that is used in the link of tool name if ($editQuestion || $modifyQuestion || $newQuestion || $modifyAnswers) { $nameTools = get_lang('QuestionManagement'); } if (isset($_SESSION['gradebook'])) { $gradebook = $_SESSION['gradebook']; } if (!empty($gradebook) && $gradebook == 'view') { $interbreadcrumb[] = array( 'url' => '../gradebook/'.$_SESSION['gradebook_dest'], 'name' => get_lang('ToolGradebook') ); } $interbreadcrumb[] = array("url" => $urlMainExercise."exercice.php", "name" => get_lang('Exercices')); if (isset($_GET['newQuestion']) || isset($_GET['editQuestion'])) { $interbreadcrumb[] = array("url" => $urlMainExercise."admin.php?exerciseId=".$objExercise->id, "name" => $objExercise->name); } else { $interbreadcrumb[] = array("url" => "#", "name" => $objExercise->name); } // if the question is duplicated, disable the link of tool name if (!empty($modifyIn) && $modifyIn == 'thisExercise') { if ($buttonBack) { $modifyIn = 'allExercises'; } else { $noPHP_SELF = true; } } $htmlHeadXtra[] = ''; $htmlHeadXtra[] = ''; $htmlHeadXtra[] = ''; $htmlHeadXtra[] = ''; $htmlHeadXtra[] = ''; $htmlHeadXtra[] = " "; Display::display_header($nameTools, 'Exercise'); if ($objExercise->exercise_was_added_in_lp) { if ($objExercise->force_edit_exercise_in_lp == true) { Display::display_warning_message(get_lang('ForceEditingExerciseInLPWarning')); } else { Display::display_warning_message(get_lang('EditingExerciseCauseProblemsInLP')); } } // If we are in a test $inATest = isset($exerciseId) && $exerciseId > 0; if ($inATest) { echo '
'; if (isset($_GET['hotspotadmin']) || isset($_GET['newQuestion']) || isset($_GET['myid'])) { echo ''.Display::return_icon( 'back.png', get_lang('GoBackToQuestionList'), '', ICON_SIZE_MEDIUM ).''; } if (!isset($_GET['hotspotadmin']) && !isset($_GET['newQuestion']) && !isset($_GET['myid']) && !isset($_GET['editQuestion'])) { echo ''.Display::return_icon( 'back.png', get_lang('BackToExercisesList'), '', ICON_SIZE_MEDIUM ).''; } echo ''.Display::return_icon( 'preview_view.png', get_lang('Preview'), '', ICON_SIZE_MEDIUM ).''; echo Display::url( Display::return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_MEDIUM), $urlMainExercise.'exercise_report.php?'.api_get_cidReq().'&exerciseId='.$objExercise->id ); if ($objExercise->edit_exercise_in_lp == false) { echo ''.Display::return_icon( 'settings_na.png', get_lang('ModifyExercise'), '', ICON_SIZE_MEDIUM ).''; } else { echo ''. Display::return_icon('settings.png', get_lang('ModifyExercise'), '', ICON_SIZE_MEDIUM ).''; } // @todo if you have 5000 questions this will slow down everything /* $maxScoreAllQuestions = 0; if (!empty($objExercise->questionList)) { foreach ($objExercise->questionList as $q) { $question = Question::read($q); if ($question) { $maxScoreAllQuestions += $question->selectWeighting(); } } } echo ''.sprintf(get_lang('XQuestionsWithTotalScoreY'), $objExercise->selectNbrQuestions(), $maxScoreAllQuestions ).'';*/ echo '
'; } else { // we are in create a new question from question pool not in a test echo '
'; echo ''. Display::return_icon('back.png', get_lang('GoBackToQuestionList'), '', ICON_SIZE_MEDIUM).''; echo '
'; } if (isset($_GET['message'])) { if (in_array($_GET['message'], array('ExerciseStored', 'ItemUpdated', 'ItemAdded'))) { Display::display_confirmation_message(get_lang($_GET['message'])); } } if ($newQuestion || $editQuestion) { // statement management if ($editQuestion) { $type = $objQuestion->selectType(); } else { $type = Security::remove_XSS($_REQUEST['answerType']); } echo ''; // Create/Edit question. require 'question_admin.inc.php'; } if (isset($_GET['hotspotadmin'])) { if (!is_object($objQuestion)) { $objQuestion = Question :: read($_GET['hotspotadmin']); } if (!$objQuestion) { api_not_allowed(); } require 'hotspot_admin.inc.php'; } if (!$newQuestion && !$modifyQuestion && !$editQuestion && !isset($_GET['hotspotadmin'])) { if ($objExercise->randomByCat == EXERCISE_CATEGORY_RANDOM_SHUFFLED || EXERCISE_CATEGORY_RANDOM_ORDERED) { Display::display_normal_message(get_lang('AllQuestionsMustHaveACategory')); } // Question list (drag n drop view) // @todo this bad do not require files like this if ($objExercise->fastEdition) { require 'question_list_pagination_admin.inc.php'; } else { require 'question_list_admin.inc.php'; } } Session::write('objExercise', $objExercise); Session::write('objQuestion', $objQuestion); Session::write('objAnswer', $objAnswer); Display::display_footer();