read($fromExercise);
}
$nameTools = get_lang('QuestionPool');
$interbreadcrumb[] = array("url" => "exercice.php","name" => get_lang('Exercices'));
$interbreadcrumb[] = array("url" => "admin.php?exerciseId=".$objExercise->id, "name" => $objExercise->name);
$displayMessage = ""; // messag to be displayed if actions succesfull
if ($is_allowedToEdit) {
//Duplicating a Question
if (!isset($_POST['recup']) && $copy_question != 0 && isset($fromExercise)) {
$origin_course_id = intval($_GET['course_id']);
$origin_course_info = api_get_course_info_by_id($origin_course_id);
$current_course = api_get_course_info();
$old_question_id = $copy_question;
//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_id, $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);
}
$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);
} else if (isset($_POST['recup']) && is_array($_POST['recup']) && $fromExercise) {
$list_recup = $_POST['recup'];
foreach ($list_recup as $course_id => $question_data) {
$origin_course_id = intval($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_id, $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 (isset($_SESSION['gradebook'])){
$gradebook= $_SESSION['gradebook'];
}
if (!empty($gradebook) && $gradebook=='view') {
$interbreadcrumb[]= array ('url' => '../gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']),'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 '
';
if ($displayMessage != "") {
Display::display_confirmation_message($displayMessage);
$displayMessage = "";
}
//Form
echo '
';
//}
Display::display_footer();
// Some functions here, just for question_pool to ease the code
/*
Put the menu entry for level and type to default "Choice"
It is usefull if you change the exercice, you need to reset the other menus
hubert.borderiou 13-10-2011
*/
function reset_menu_lvl_type() {
global $exerciseLevel, $answerType;
$answerType = -1;
$exerciseLevel = -1;
}
/*
Put the menu entry for exercice and level and type to default "Choice"
It is usefull if you change the course, you need to reset the other menus
hubert.borderiou 13-10-2011
*/
function reset_menu_exo_lvl_type() {
global $exerciseId, $courseCategoryId;
reset_menu_lvl_type();
$exerciseId = 0;
$courseCategoryId = 0;
}
// return the link to admin question, if needed
// hubert.borderiou 13-10-2011
function get_a_tag_for_question($in_addA, $in_fromex, $in_questionid, $in_questiontype, $in_questionname) {
$res = $in_questionname;
if ($in_addA) {
$res = "".$res."";
}
return $res;
}
/*
$row[] = get_action_icon_for_question(
$actionIcon1, --
$fromExercise, --
$tabQuestion['id'], --
$tabQuestion['type'],
$tabQuestion['question'],
$selected_course,
$courseCategoryId,
$exerciseLevel,
$answerType,
$session_id,
$exerciseId).
" ".
get_action_icon_for_question($actionIcon2, $fromExercise, $tabQuestion['id'], $tabQuestion['type'],
$tabQuestion['question'], $selected_course, $courseCategoryId, $exerciseLevel, $answerType,
$session_id, $exerciseId);
*/
/*
Return the html code for delete, add, clone, edit a question hubert.borderiou 13-10-2011
in_action = the code of the action triggered by the button
from_exercice = the id of the current exercice from which we click on question pool
in_questionid = the id of the current question
in_questiontype = the code of the type of the current question
in_questionname = the name of the question
in_selected_course = the if of the course chosen in the FILTERING MENU
in_courseCategoryId = the id of the category chosen in the FILTERING MENU
in_exerciseLevel = the level of the exercice chosen in the FILTERING MENU
in_answerType = the code of the type of the question chosen in the FILTERING MENU
in_session_id = the id of the session_id chosen in the FILTERING MENU
in_exercice_id = the id of the exercice chosen in the FILTERING MENU
*/
function get_action_icon_for_question($in_action, $from_exercice, $in_questionid, $in_questiontype, $in_questionname, $in_selected_course, $in_courseCategoryId, $in_exerciseLevel, $in_answerType, $in_session_id, $in_exercice_id) {
$res = "";
$getParams = "&selected_course=$in_selected_course&courseCategoryId=$in_courseCategoryId&exerciseId=$in_exercice_id&exerciseLevel=$in_exerciseLevel&answerType=$in_answerType&session_id=$in_session_id";
switch ($in_action) {
case "delete" :
$res = "";
$res .= Display::return_icon("delete.gif", get_lang('Delete'));
$res .= "";
break;
case "edit" :
$res = get_a_tag_for_question(1, $from_exercice, $in_questionid, $in_questiontype, Display::return_icon("edit.gif", get_lang('Modify')));
break;
case "add":
// add if question is not already in test
$myObjEx = new Exercise();
$myObjEx->setCategoriesGrouping(false);
$myObjEx->read($from_exercice);
if (!$myObjEx->isInList($in_questionid)) {
$res = "";
$res .= Display::return_icon("view_more_stats.gif", get_lang('InsertALinkToThisQuestionInTheExercise'));
$res .= "";
} else {
$res = "-";
}
unset($myObjEx);
break;
case "clone":
$res = "";
$res .= Display::return_icon('cd.gif', get_lang('ReUseACopyInCurrentTest'));
$res .= "";
break;
default :
$res = $in_action;
break;
}
return $res;
}
/* return the icon for the question type
hubert.borderiou 13-10-2011*/
function get_question_type_for_question($in_selectedcourse, $in_questionid) {
$myObjQuestion = Question::read($in_questionid, $in_selectedcourse);
$questionType = null;
if (!empty($myObjQuestion)) {
list($typeImg, $typeExpl) = $myObjQuestion->get_type_icon_html();
$questionType = Display::tag('div', Display::return_icon($typeImg, $typeExpl, array(), 32), array());
unset($myObjQuestion);
}
return $questionType;
}
/* return the name of the category for the question in a course hubert.borderiou 13-10-2011*/
function get_question_category_for_question($course_id, $question_id) {
global $all_category_list;
$objQuestionTmp = Question :: read($question_id, $course_id);
return Testcategory::return_category_labels($objQuestionTmp->category_list, $all_category_list);
}