Fixing delete question + cosmetic changes

skala
Julio Montoya 13 years ago
parent d9d4802998
commit 97aae33521
  1. 329
      main/exercice/question.class.php
  2. 260
      main/exercice/question_pool.php

@ -57,13 +57,13 @@ abstract class Question
public $exerciseList; // array with the list of exercises which this question is in public $exerciseList; // array with the list of exercises which this question is in
public $category; public $category;
private $isContent; private $isContent;
public $course; public $course;
static $typePicture = 'new_question.png'; static $typePicture = 'new_question.png';
static $explanationLangVar = ''; static $explanationLangVar = '';
public $question_table_class = 'table table-striped'; public $question_table_class = 'table table-striped';
static $questionTypes = array( static $questionTypes = array(
UNIQUE_ANSWER => array('unique_answer.class.php' , 'UniqueAnswer'), UNIQUE_ANSWER => array('unique_answer.class.php' , 'UniqueAnswer'),
MULTIPLE_ANSWER => array('multiple_answer.class.php' , 'MultipleAnswer'), MULTIPLE_ANSWER => array('multiple_answer.class.php' , 'MultipleAnswer'),
FILL_IN_BLANKS => array('fill_blanks.class.php' , 'FillBlanks'), FILL_IN_BLANKS => array('fill_blanks.class.php' , 'FillBlanks'),
MATCHING => array('matching.class.php' , 'Matching'), MATCHING => array('matching.class.php' , 'Matching'),
FREE_ANSWER => array('freeanswer.class.php' , 'FreeAnswer'), FREE_ANSWER => array('freeanswer.class.php' , 'FreeAnswer'),
@ -75,7 +75,7 @@ abstract class Question
MULTIPLE_ANSWER_TRUE_FALSE => array('multiple_answer_true_false.class.php', 'MultipleAnswerTrueFalse'), MULTIPLE_ANSWER_TRUE_FALSE => array('multiple_answer_true_false.class.php', 'MultipleAnswerTrueFalse'),
MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE => array('multiple_answer_combination_true_false.class.php', 'MultipleAnswerCombinationTrueFalse'), MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE => array('multiple_answer_combination_true_false.class.php', 'MultipleAnswerCombinationTrueFalse'),
GLOBAL_MULTIPLE_ANSWER => array('global_multiple_answer.class.php' , 'GlobalMultipleAnswer'), GLOBAL_MULTIPLE_ANSWER => array('global_multiple_answer.class.php' , 'GlobalMultipleAnswer'),
); );
/** /**
@ -113,33 +113,34 @@ abstract class Question
* @return - boolean - true if question exists, otherwise false * @return - boolean - true if question exists, otherwise false
*/ */
static function read($id, $course_id = null) { static function read($id, $course_id = null) {
$id = intval($id); $id = intval($id);
if (!empty($course_id)) { if (!empty($course_id)) {
$course_info = api_get_course_info_by_id($course_id); $course_info = api_get_course_info_by_id($course_id);
} else { } else {
$course_info = api_get_course_info(); $course_info = api_get_course_info();
} }
$course_id = $course_info['real_id']; $course_id = $course_info['real_id'];
if (empty($course_id) || $course_id == -1 ) { if (empty($course_id) || $course_id == -1 ) {
return false; return false;
} }
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$sql = "SELECT question,description,ponderation,position,type,picture,level,extra FROM $TBL_QUESTIONS WHERE c_id = $course_id AND id = $id "; $sql = "SELECT question,description,ponderation,position,type,picture,level,extra
FROM $TBL_QUESTIONS WHERE c_id = $course_id AND id = $id ";
$result = Database::query($sql); $result = Database::query($sql);
// if the question has been found // if the question has been found
if ($object = Database::fetch_object($result)) { if ($object = Database::fetch_object($result)) {
$objQuestion = Question::getInstance($object->type); $objQuestion = Question::getInstance($object->type);
if (!empty($objQuestion)) { if (!empty($objQuestion)) {
$objQuestion->id = $id; $objQuestion->id = $id;
$objQuestion->question = $object->question; $objQuestion->question = $object->question;
$objQuestion->description = $object->description; $objQuestion->description = $object->description;
@ -250,12 +251,12 @@ abstract class Question
function selectPicture() { function selectPicture() {
return $this->picture; return $this->picture;
} }
function selectPicturePath() { function selectPicturePath() {
if (!empty($this->picture)) { if (!empty($this->picture)) {
return api_get_path(WEB_COURSE_PATH).$this->course['path'].'/document/images/'.$this->picture; return api_get_path(WEB_COURSE_PATH).$this->course['path'].'/document/images/'.$this->picture;
} }
return false; return false;
} }
/** /**
@ -316,7 +317,7 @@ abstract class Question
function updateCategory($in_category) { function updateCategory($in_category) {
$this->category=$in_category; $this->category=$in_category;
} }
/** /**
* @author - Hubert Borderiou 12-10-2011 * @author - Hubert Borderiou 12-10-2011
* @param - interger $in_positive * @param - interger $in_positive
@ -324,7 +325,7 @@ abstract class Question
function updateScoreAlwaysPositive($in_positive) { function updateScoreAlwaysPositive($in_positive) {
$this->scoreAlwaysPositive=$in_positive; $this->scoreAlwaysPositive=$in_positive;
} }
/** /**
* @author - Hubert Borderiou 12-10-2011 * @author - Hubert Borderiou 12-10-2011
* @param - interger $in_positive * @param - interger $in_positive
@ -332,7 +333,7 @@ abstract class Question
function updateUncheckedMayScore($in_positive) { function updateUncheckedMayScore($in_positive) {
$this->uncheckedMayScore=$in_positive; $this->uncheckedMayScore=$in_positive;
} }
/** /**
* @author - Hubert Borderiou 12-10-2011 * @author - Hubert Borderiou 12-10-2011
* @param - interger $in_positive * @param - interger $in_positive
@ -344,7 +345,7 @@ abstract class Question
$this->deleteCategory(); $this->deleteCategory();
} else { } else {
// update or add category for a question // update or add category for a question
$TBL_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); $TBL_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$category_id = Database::escape_string($in_category); $category_id = Database::escape_string($in_category);
$question_id = Database::escape_string($this->id); $question_id = Database::escape_string($this->id);
@ -359,8 +360,8 @@ abstract class Question
$res = Database::query($sql); $res = Database::query($sql);
} }
} }
} }
/** /**
* @author hubert borderiou 12-10-2011 * @author hubert borderiou 12-10-2011
* delete any category entry for question id * delete any category entry for question id
@ -373,7 +374,7 @@ abstract class Question
$sql = "DELETE FROM $TBL_QUESTION_REL_CATEGORY WHERE question_id=$question_id AND c_id=".api_get_course_int_id(); $sql = "DELETE FROM $TBL_QUESTION_REL_CATEGORY WHERE question_id=$question_id AND c_id=".api_get_course_int_id();
$res = Database::query($sql); $res = Database::query($sql);
} }
/** /**
* changes the question position * changes the question position
@ -405,7 +406,7 @@ abstract class Question
function updateType($type) { function updateType($type) {
$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER); $TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
$course_id = $this->course['real_id']; $course_id = $this->course['real_id'];
if (empty($course_id)) { if (empty($course_id)) {
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
} }
@ -446,8 +447,8 @@ abstract class Question
// if the question has got an ID // if the question has got an ID
if ($this->id) { if ($this->id) {
$extension = pathinfo($PictureName, PATHINFO_EXTENSION); $extension = pathinfo($PictureName, PATHINFO_EXTENSION);
$this->picture = 'quiz-'.$this->id.'.jpg'; $this->picture = 'quiz-'.$this->id.'.jpg';
$o_img = new Image($Picture); $o_img = new Image($Picture);
$o_img->send_image($picturePath.'/'.$this->picture, -1, 'jpg'); $o_img->send_image($picturePath.'/'.$this->picture, -1, 'jpg');
$document_id = add_document($this->course, '/images/'.$this->picture, 'file', filesize($picturePath.'/'.$this->picture),$this->picture); $document_id = add_document($this->course, '/images/'.$this->picture, 'file', filesize($picturePath.'/'.$this->picture),$this->picture);
@ -474,10 +475,10 @@ abstract class Question
if($this->id) { if($this->id) {
// Get dimensions from current image. // Get dimensions from current image.
$my_image = new Image($picturePath.'/'.$this->picture); $my_image = new Image($picturePath.'/'.$this->picture);
$current_image_size = $my_image->get_image_size(); $current_image_size = $my_image->get_image_size();
$current_width = $current_image_size['width']; $current_width = $current_image_size['width'];
$current_height = $current_image_size['height']; $current_height = $current_image_size['height'];
if($current_width < $Max && $current_height <$Max) if($current_width < $Max && $current_height <$Max)
return true; return true;
@ -513,10 +514,10 @@ abstract class Question
$new_height = ceil($current_height / $resize_scale); $new_height = ceil($current_height / $resize_scale);
} }
} }
$my_image->resize($new_width, $new_height); $my_image->resize($new_width, $new_height);
$result = $my_image->send_image($picturePath.'/'.$this->picture); $result = $my_image->send_image($picturePath.'/'.$this->picture);
if ($result) { if ($result) {
return true; return true;
} else { } else {
@ -558,27 +559,27 @@ abstract class Question
$course_id = $course_info['real_id']; $course_id = $course_info['real_id'];
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$destination_path = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/document/images'; $destination_path = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/document/images';
$source_path = api_get_path(SYS_COURSE_PATH).$this->course['path'].'/document/images'; $source_path = api_get_path(SYS_COURSE_PATH).$this->course['path'].'/document/images';
// if the question has got an ID and if the picture exists // if the question has got an ID and if the picture exists
if ($this->id && !empty($this->picture)) { if ($this->id && !empty($this->picture)) {
$picture=explode('.',$this->picture); $picture=explode('.',$this->picture);
$extension = $picture[sizeof($picture)-1]; $extension = $picture[sizeof($picture)-1];
$picture = 'quiz-'.$questionId.'.'.$extension; $picture = 'quiz-'.$questionId.'.'.$extension;
$result = @copy($source_path.'/'.$this->picture, $destination_path.'/'.$picture) ? true : false; $result = @copy($source_path.'/'.$this->picture, $destination_path.'/'.$picture) ? true : false;
//If copy was correct then add to the database //If copy was correct then add to the database
if ($result) { if ($result) {
$sql = "UPDATE $TBL_QUESTIONS SET picture='".Database::escape_string($picture)."' WHERE c_id = $course_id AND id='".intval($questionId)."'"; $sql = "UPDATE $TBL_QUESTIONS SET picture='".Database::escape_string($picture)."' WHERE c_id = $course_id AND id='".intval($questionId)."'";
Database::query($sql); Database::query($sql);
$document_id = add_document($course_info, '/images/'.$picture, 'file', filesize($destination_path.'/'.$picture), $picture); $document_id = add_document($course_info, '/images/'.$picture, 'file', filesize($destination_path.'/'.$picture), $picture);
if ($document_id) { if ($document_id) {
return api_item_property_update($course_info, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id()); return api_item_property_update($course_info, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id());
} }
} }
return $result; return $result;
} }
return false; return false;
} }
@ -606,7 +607,7 @@ abstract class Question
public function setTitle($title) { public function setTitle($title) {
$this->question = $title; $this->question = $title;
} }
/** /**
Sets the title Sets the title
*/ */
@ -662,8 +663,8 @@ abstract class Question
$extra = $this->extra; $extra = $this->extra;
$c_id = $this->course['real_id']; $c_id = $this->course['real_id'];
$category = $this->category; $category = $this->category;
// question already exists // question already exists
if(!empty($id)) { if(!empty($id)) {
$sql="UPDATE $TBL_QUESTIONS SET $sql="UPDATE $TBL_QUESTIONS SET
@ -693,8 +694,8 @@ abstract class Question
} }
} else { } else {
// creates a new question // creates a new question
$sql = "SELECT max(position) FROM $TBL_QUESTIONS as question, $TBL_EXERCICE_QUESTION as test_question $sql = "SELECT max(position) FROM $TBL_QUESTIONS as question, $TBL_EXERCICE_QUESTION as test_question
WHERE question.id = test_question.question_id AND WHERE question.id = test_question.question_id AND
test_question.exercice_id = '".Database::escape_string($exerciseId)."' AND test_question.exercice_id = '".Database::escape_string($exerciseId)."' AND
question.c_id = $c_id AND question.c_id = $c_id AND
test_question.c_id = $c_id "; test_question.c_id = $c_id ";
@ -702,7 +703,7 @@ abstract class Question
$current_position = Database::result($result,0,0); $current_position = Database::result($result,0,0);
$this->updatePosition($current_position+1); $this->updatePosition($current_position+1);
$position = $this->position; $position = $this->position;
$sql = "INSERT INTO $TBL_QUESTIONS (c_id, question, description, ponderation, position, type, picture, extra, level) VALUES ( $sql = "INSERT INTO $TBL_QUESTIONS (c_id, question, description, ponderation, position, type, picture, extra, level) VALUES (
$c_id, $c_id,
'".Database::escape_string($question)."', '".Database::escape_string($question)."',
'".Database::escape_string($description)."', '".Database::escape_string($description)."',
@ -712,7 +713,7 @@ abstract class Question
'".Database::escape_string($picture)."', '".Database::escape_string($picture)."',
'".Database::escape_string($extra)."', '".Database::escape_string($extra)."',
'".Database::escape_string($level)."' '".Database::escape_string($level)."'
)"; )";
Database::query($sql); Database::query($sql);
$this->id = Database::insert_id(); $this->id = Database::insert_id();
@ -722,18 +723,18 @@ abstract class Question
// If hotspot, create first answer // If hotspot, create first answer
if ($type == HOT_SPOT || $type == HOT_SPOT_ORDER) { if ($type == HOT_SPOT || $type == HOT_SPOT_ORDER) {
$TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER); $TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
$sql = "INSERT INTO $TBL_ANSWERS (c_id, id, question_id , answer , correct , comment , ponderation , position , hotspot_coordinates , hotspot_type ) $sql = "INSERT INTO $TBL_ANSWERS (c_id, id, question_id , answer , correct , comment , ponderation , position , hotspot_coordinates , hotspot_type )
VALUES (".$c_id.", '1', '".Database::escape_string($this->id)."', '', NULL , '', '10' , '1', '0;0|0|0', 'square')"; VALUES (".$c_id.", '1', '".Database::escape_string($this->id)."', '', NULL , '', '10' , '1', '0;0|0|0', 'square')";
Database::query($sql); Database::query($sql);
} }
if ($type == HOT_SPOT_DELINEATION ) { if ($type == HOT_SPOT_DELINEATION ) {
$TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER); $TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
$sql="INSERT INTO $TBL_ANSWERS (c_id, id, question_id , answer , correct , comment , ponderation , position , hotspot_coordinates , hotspot_type ) $sql="INSERT INTO $TBL_ANSWERS (c_id, id, question_id , answer , correct , comment , ponderation , position , hotspot_coordinates , hotspot_type )
VALUES (".$c_id.", '1', '".Database::escape_string($this->id)."', '', NULL , '', '10' , '1', '0;0|0|0', 'delineation')"; VALUES (".$c_id.", '1', '".Database::escape_string($this->id)."', '', NULL , '', '10' , '1', '0;0|0|0', 'delineation')";
Database::query($sql); Database::query($sql);
} }
if (api_get_setting('search_enabled')=='true') { if (api_get_setting('search_enabled')=='true') {
if ($exerciseId != 0) { if ($exerciseId != 0) {
$this -> search_engine_edit($exerciseId, TRUE); $this -> search_engine_edit($exerciseId, TRUE);
@ -877,16 +878,16 @@ abstract class Question
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$id = $this->id; $id = $this->id;
// checks if the exercise ID is not in the list // checks if the exercise ID is not in the list
if (!in_array($exerciseId,$this->exerciseList)) { if (!in_array($exerciseId,$this->exerciseList)) {
$this->exerciseList[]=$exerciseId; $this->exerciseList[]=$exerciseId;
$new_exercise = new Exercise(); $new_exercise = new Exercise();
$new_exercise->read($exerciseId); $new_exercise->read($exerciseId);
$count = $new_exercise->selectNbrQuestions(); $count = $new_exercise->selectNbrQuestions();
$count++; $count++;
$sql="INSERT INTO $TBL_EXERCICE_QUESTION (c_id, question_id, exercice_id, question_order) VALUES $sql="INSERT INTO $TBL_EXERCICE_QUESTION (c_id, question_id, exercice_id, question_order) VALUES
({$this->course['real_id']}, '".Database::escape_string($id)."','".Database::escape_string($exerciseId)."', '$count' )"; ({$this->course['real_id']}, '".Database::escape_string($id)."','".Database::escape_string($exerciseId)."', '$count' )";
Database::query($sql); Database::query($sql);
// we do not want to reindex if we had just saved adnd indexed the question // we do not want to reindex if we had just saved adnd indexed the question
if (!$fromSave) { if (!$fromSave) {
$this->search_engine_edit($exerciseId, TRUE); $this->search_engine_edit($exerciseId, TRUE);
@ -908,7 +909,7 @@ abstract class Question
// searches the position of the exercise ID in the list // searches the position of the exercise ID in the list
$pos=array_search($exerciseId,$this->exerciseList); $pos=array_search($exerciseId,$this->exerciseList);
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
// exercise not found // exercise not found
@ -923,7 +924,7 @@ abstract class Question
if (Database::num_rows($res)>0) { if (Database::num_rows($res)>0) {
$row = Database::fetch_array($res); $row = Database::fetch_array($res);
if (!empty($row['question_order'])) { if (!empty($row['question_order'])) {
$sql = "UPDATE $TBL_EXERCICE_QUESTION SET question_order = question_order-1 $sql = "UPDATE $TBL_EXERCICE_QUESTION SET question_order = question_order-1
WHERE c_id = $course_id AND exercice_id='".Database::escape_string($exerciseId)."' AND question_order > ".$row['question_order']; WHERE c_id = $course_id AND exercice_id='".Database::escape_string($exerciseId)."' AND question_order > ".$row['question_order'];
$res = Database::query($sql); $res = Database::query($sql);
} }
@ -944,49 +945,53 @@ abstract class Question
* @author - Olivier Brouckaert * @author - Olivier Brouckaert
* @param - integer $deleteFromEx - exercise ID if the question is only removed from one exercise * @param - integer $deleteFromEx - exercise ID if the question is only removed from one exercise
*/ */
function delete($deleteFromEx=0) { function delete($deleteFromEx = 0) {
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER); $TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
$TBL_QUIZ_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); $TBL_QUIZ_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$id=$this->id; $id = $this->id;
// if the question must be removed from all exercises // if the question must be removed from all exercises
if(!$deleteFromEx) { if (!$deleteFromEx) {
//update the question_order of each question to avoid inconsistencies //update the question_order of each question to avoid inconsistencies
$sql = "SELECT exercice_id, question_order FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND question_id='".Database::escape_string($id)."'"; $sql = "SELECT exercice_id, question_order FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND question_id='".Database::escape_string($id)."'";
$res = Database::query($sql); $res = Database::query($sql);
if (Database::num_rows($res)>0) { if (Database::num_rows($res) > 0) {
while ($row = Database::fetch_array($res)) { while ($row = Database::fetch_array($res)) {
if (!empty($row['question_order'])) { if (!empty($row['question_order'])) {
$sql = "UPDATE $TBL_EXERCICE_QUESTION SET question_order = question_order-1 WHERE c_id = $course_id AND exercice_id='".Database::escape_string($row['exercice_id'])."' AND question_order > ".$row['question_order']; $sql = "UPDATE $TBL_EXERCICE_QUESTION
$res = Database::query($sql); SET question_order = question_order-1
WHERE c_id = $course_id AND exercice_id='".Database::escape_string($row['exercice_id'])."' AND question_order > ".$row['question_order'];
Database::query($sql);
} }
} }
} }
$sql="DELETE FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND question_id='".Database::escape_string($id)."'";
$sql = "DELETE FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND question_id='".Database::escape_string($id)."'";
Database::query($sql); Database::query($sql);
$sql="DELETE FROM $TBL_QUESTIONS WHERE c_id = $course_id AND id='".Database::escape_string($id)."'"; $sql = "DELETE FROM $TBL_QUESTIONS WHERE c_id = $course_id AND id='".Database::escape_string($id)."'";
Database::query($sql); Database::query($sql);
$sql="DELETE FROM $TBL_REPONSES WHERE c_id = $course_id AND question_id='".Database::escape_string($id)."'"; $sql = "DELETE FROM $TBL_REPONSES WHERE c_id = $course_id AND question_id='".Database::escape_string($id)."'";
Database::query($sql); Database::query($sql);
// remove the category of this question in the question_rel_category table // remove the category of this question in the question_rel_category table
$sql = "DELETE FROM $TBL_QUIZ_QUESTION_REL_CATEGORY WHERE c_id = $course_id AND question_id='".Database::escape_string($id)."' AND c_id=".api_get_course_int_id(); $sql = "DELETE FROM $TBL_QUIZ_QUESTION_REL_CATEGORY WHERE c_id = $course_id AND question_id='".Database::escape_string($id)."' AND c_id=".api_get_course_int_id();
Database::query($sql); Database::query($sql);
api_item_property_update($this->course, TOOL_QUIZ, $id,'QuizQuestionDeleted',api_get_user_id()); api_item_property_update($this->course, TOOL_QUIZ, $id,'QuizQuestionDeleted',api_get_user_id());
$this->removePicture(); $this->removePicture();
// resets the object // resets the object
$this->Question(); $this->Question();
} else { } else {
// just removes the exercise from the list // just removes the exercise from the list
$this->removeFromList($deleteFromEx); $this->removeFromList($deleteFromEx);
if (api_get_setting('search_enabled')=='true' && extension_loaded('xapian')) { if (api_get_setting('search_enabled')=='true' && extension_loaded('xapian')) {
// disassociate question with this exercise // disassociate question with this exercise
@ -1003,8 +1008,8 @@ abstract class Question
* @param array Course info of the destination course * @param array Course info of the destination course
* @return int ID of the new question * @return int ID of the new question
*/ */
function duplicate($course_info = null) { function duplicate($course_info = null) {
if (empty($course_info)) { if (empty($course_info)) {
$course_info = $this->course; $course_info = $this->course;
} else { } else {
@ -1020,36 +1025,36 @@ abstract class Question
$type = $this->type; $type = $this->type;
$level = intval($this->level); $level = intval($this->level);
$extra = $this->extra; $extra = $this->extra;
//Using the same method used in the course copy to transform URLs //Using the same method used in the course copy to transform URLs
if ($this->course['id'] != $course_info['id']) { if ($this->course['id'] != $course_info['id']) {
$description = DocumentManager::replace_urls_inside_content_html_from_copy_course($description, $this->course['id'], $course_info['id']); $description = DocumentManager::replace_urls_inside_content_html_from_copy_course($description, $this->course['id'], $course_info['id']);
$question = DocumentManager::replace_urls_inside_content_html_from_copy_course($question, $this->course['id'], $course_info['id']); $question = DocumentManager::replace_urls_inside_content_html_from_copy_course($question, $this->course['id'], $course_info['id']);
} }
$course_id = $course_info['real_id']; $course_id = $course_info['real_id'];
//Read the source options //Read the source options
$options = self::readQuestionOption($this->id, $this->course['real_id']); $options = self::readQuestionOption($this->id, $this->course['real_id']);
//Inserting in the new course db / or the same course db //Inserting in the new course db / or the same course db
$sql = "INSERT INTO $TBL_QUESTIONS (c_id, question, description, ponderation, position, type, level, extra ) $sql = "INSERT INTO $TBL_QUESTIONS (c_id, question, description, ponderation, position, type, level, extra )
VALUES('$course_id', '".Database::escape_string($question)."','".Database::escape_string($description)."','".Database::escape_string($weighting)."','".Database::escape_string($position)."','".Database::escape_string($type)."' ,'".Database::escape_string($level)."' ,'".Database::escape_string($extra)."' )"; VALUES('$course_id', '".Database::escape_string($question)."','".Database::escape_string($description)."','".Database::escape_string($weighting)."','".Database::escape_string($position)."','".Database::escape_string($type)."' ,'".Database::escape_string($level)."' ,'".Database::escape_string($extra)."' )";
Database::query($sql); Database::query($sql);
$new_question_id = Database::insert_id(); $new_question_id = Database::insert_id();
if (!empty($options)) { if (!empty($options)) {
//Saving the quiz_options //Saving the quiz_options
foreach ($options as $item) { foreach ($options as $item) {
$item['question_id'] = $new_question_id; $item['question_id'] = $new_question_id;
$item['c_id'] = $course_id; $item['c_id'] = $course_id;
unset($item['id']); unset($item['id']);
Database::insert($TBL_QUESTION_OPTIONS, $item); Database::insert($TBL_QUESTION_OPTIONS, $item);
} }
} }
// Duplicates the picture of the hotspot // Duplicates the picture of the hotspot
$this->exportPicture($new_question_id, $course_info); $this->exportPicture($new_question_id, $course_info);
return $new_question_id; return $new_question_id;
@ -1059,19 +1064,19 @@ abstract class Question
$key = self::$questionTypes[$this->type]; $key = self::$questionTypes[$this->type];
return get_lang($key[1]); return get_lang($key[1]);
} }
static function get_question_type($type) { static function get_question_type($type) {
if ($type == ORAL_EXPRESSION && api_get_setting('enable_nanogong') != 'true') { if ($type == ORAL_EXPRESSION && api_get_setting('enable_nanogong') != 'true') {
return null; return null;
} }
return self::$questionTypes[$type]; return self::$questionTypes[$type];
} }
static function get_question_type_list() { static function get_question_type_list() {
if (api_get_setting('enable_nanogong') != 'true') { if (api_get_setting('enable_nanogong') != 'true') {
self::$questionTypes[ORAL_EXPRESSION] = null; self::$questionTypes[ORAL_EXPRESSION] = null;
unset(self::$questionTypes[ORAL_EXPRESSION]); unset(self::$questionTypes[ORAL_EXPRESSION]);
} }
return self::$questionTypes; return self::$questionTypes;
} }
@ -1081,14 +1086,14 @@ abstract class Question
* @return an instance of a Question subclass (or of Questionc class by default) * @return an instance of a Question subclass (or of Questionc class by default)
*/ */
static function getInstance($type) { static function getInstance($type) {
if (!is_null($type)) { if (!is_null($type)) {
list($file_name, $class_name) = self::get_question_type($type); list($file_name, $class_name) = self::get_question_type($type);
if (!empty($file_name)) { if (!empty($file_name)) {
include_once $file_name; include_once $file_name;
if (class_exists($class_name)) { if (class_exists($class_name)) {
return new $class_name(); return new $class_name();
} else { } else {
echo 'Can\'t instanciate class '.$class_name.' of type '.$type; echo 'Can\'t instanciate class '.$class_name.' of type '.$type;
} }
} }
} }
@ -1101,7 +1106,7 @@ abstract class Question
* @param FormValidator $form the formvalidator instance (by reference) * @param FormValidator $form the formvalidator instance (by reference)
*/ */
function createForm (&$form, $fck_config=0) { function createForm (&$form, $fck_config=0) {
echo '<style> echo '<style>
.media { display:none;} .media { display:none;}
</style>'; </style>';
echo '<script> echo '<script>
@ -1129,7 +1134,7 @@ abstract class Question
document.getElementById(\'media_icon\').innerHTML=\'&nbsp;<img style="vertical-align: middle;" src="../img/looknfeel.png" alt="" />&nbsp;'.get_lang('EnrichQuestion').'\'; document.getElementById(\'media_icon\').innerHTML=\'&nbsp;<img style="vertical-align: middle;" src="../img/looknfeel.png" alt="" />&nbsp;'.get_lang('EnrichQuestion').'\';
} }
} }
// hub 13-12-2010 // hub 13-12-2010
function visiblerDevisibler(in_id) { function visiblerDevisibler(in_id) {
if (document.getElementById(in_id)) { if (document.getElementById(in_id)) {
@ -1146,11 +1151,11 @@ abstract class Question
} }
} }
} }
} }
</script>'; </script>';
// question name // question name
$form->addElement('text', 'questionName', get_lang('Question'), array('class' => 'span6')); $form->addElement('text', 'questionName', get_lang('Question'), array('class' => 'span6'));
$form->addRule('questionName', get_lang('GiveQuestion'), 'required'); $form->addRule('questionName', get_lang('GiveQuestion'), 'required');
// default content // default content
@ -1165,11 +1170,11 @@ abstract class Question
if(is_array($fck_config)){ if(is_array($fck_config)){
$editor_config = array_merge($editor_config, $fck_config); $editor_config = array_merge($editor_config, $fck_config);
} }
if(!api_is_allowed_to_edit(null,true)) $editor_config['UserStatus'] = 'student'; if(!api_is_allowed_to_edit(null,true)) $editor_config['UserStatus'] = 'student';
$form->addElement('advanced_settings',' $form->addElement('advanced_settings','
<a href="javascript://" onclick=" return show_media()"><span id="media_icon"><img style="vertical-align: middle;" src="../img/looknfeel.png" alt="" />&nbsp;'.get_lang('EnrichQuestion').'</span></a> <a href="javascript://" onclick=" return show_media()"><span id="media_icon"><img style="vertical-align: middle;" src="../img/looknfeel.png" alt="" />&nbsp;'.get_lang('EnrichQuestion').'</span></a>
'); ');
$form -> addElement ('html','<div class="HideFCKEditor" id="HiddenFCKquestionDescription" >'); $form -> addElement ('html','<div class="HideFCKEditor" id="HiddenFCKquestionDescription" >');
@ -1178,21 +1183,21 @@ abstract class Question
// Advanced parameters // Advanced parameters
$form->addElement('advanced_settings','<a href="javascript:void(0)" onclick="visiblerDevisibler(\'id_advancedOption\')"><img id="id_advancedOptionImg" style="vertical-align:middle;" src="../img/div_show.gif" alt="" />&nbsp;'.get_lang("AdvancedParameters").'</a>'); $form->addElement('advanced_settings','<a href="javascript:void(0)" onclick="visiblerDevisibler(\'id_advancedOption\')"><img id="id_advancedOptionImg" style="vertical-align:middle;" src="../img/div_show.gif" alt="" />&nbsp;'.get_lang("AdvancedParameters").'</a>');
$select_level = array (1=>1,2=>2,3=>3,4=>4,5=>5); $select_level = array (1=>1,2=>2,3=>3,4=>4,5=>5);
$form->addElement('html','<div id="id_advancedOption" style="display:none;">'); $form->addElement('html','<div id="id_advancedOption" style="display:none;">');
$form->addElement('select', 'questionLevel',get_lang('Difficulty'), $select_level); $form->addElement('select', 'questionLevel',get_lang('Difficulty'), $select_level);
// Categories // Categories
$tabCat = Testcategory::getCategoriesIdAndName(); $tabCat = Testcategory::getCategoriesIdAndName();
$form->addElement('select', 'questionCategory', get_lang('Category'), $tabCat); $form->addElement('select', 'questionCategory', get_lang('Category'), $tabCat);
// hidden values // hidden values
$form->addElement('hidden','myid', intval($_REQUEST['myid'])); $form->addElement('hidden','myid', intval($_REQUEST['myid']));
if (!isset($_GET['fromExercise'])) { if (!isset($_GET['fromExercise'])) {
switch($answerType) { switch($answerType) {
case 1: $this->question = get_lang('DefaultUniqueQuestion'); break; case 1: $this->question = get_lang('DefaultUniqueQuestion'); break;
case 2: $this->question = get_lang('DefaultMultipleQuestion'); break; case 2: $this->question = get_lang('DefaultMultipleQuestion'); break;
@ -1202,19 +1207,19 @@ abstract class Question
case 9: $this->question = get_lang('DefaultMultipleQuestion'); break; case 9: $this->question = get_lang('DefaultMultipleQuestion'); break;
} }
} }
$form->addElement('html','</div>'); $form->addElement('html','</div>');
// default values // default values
$defaults = array(); $defaults = array();
$defaults['questionName'] = $this -> question; $defaults['questionName'] = $this -> question;
$defaults['questionDescription'] = $this -> description; $defaults['questionDescription'] = $this -> description;
$defaults['questionLevel'] = $this -> level; $defaults['questionLevel'] = $this -> level;
$defaults['questionCategory'] = $this->category; $defaults['questionCategory'] = $this->category;
//Came from he question pool //Came from he question pool
if (isset($_GET['fromExercise'])) { if (isset($_GET['fromExercise'])) {
$form->setDefaults($defaults); $form->setDefaults($defaults);
} }
if (!empty($_REQUEST['myid'])) { if (!empty($_REQUEST['myid'])) {
@ -1223,9 +1228,9 @@ abstract class Question
if ($isContent == 1) { if ($isContent == 1) {
$form->setDefaults($defaults); $form->setDefaults($defaults);
} }
} }
} }
/** /**
* function which process the creation of questions * function which process the creation of questions
@ -1259,27 +1264,27 @@ abstract class Question
/** /**
* Displays the menu of question types * Displays the menu of question types
*/ */
static function display_type_menu($objExercise) { static function display_type_menu($objExercise) {
$feedback_type = $objExercise->feedback_type; $feedback_type = $objExercise->feedback_type;
$exerciseId = $objExercise->id; $exerciseId = $objExercise->id;
// 1. by default we show all the question types // 1. by default we show all the question types
$question_type_custom_list = self::get_question_type_list(); $question_type_custom_list = self::get_question_type_list();
if (!isset($feedback_type)) { if (!isset($feedback_type)) {
$feedback_type = 0; $feedback_type = 0;
} }
if ($feedback_type == 1) { if ($feedback_type == 1) {
//2. but if it is a feedback DIRECT we only show the UNIQUE_ANSWER type that is currently available //2. but if it is a feedback DIRECT we only show the UNIQUE_ANSWER type that is currently available
$question_type_custom_list = array ( $question_type_custom_list = array (
UNIQUE_ANSWER => self::$questionTypes[UNIQUE_ANSWER], UNIQUE_ANSWER => self::$questionTypes[UNIQUE_ANSWER],
HOT_SPOT_DELINEATION => self::$questionTypes[HOT_SPOT_DELINEATION] HOT_SPOT_DELINEATION => self::$questionTypes[HOT_SPOT_DELINEATION]
); );
} else { } else {
unset($question_type_custom_list[HOT_SPOT_DELINEATION]); unset($question_type_custom_list[HOT_SPOT_DELINEATION]);
} }
echo '<div class="actionsbig">'; echo '<div class="actionsbig">';
echo '<ul class="question_menu">'; echo '<ul class="question_menu">';
@ -1295,9 +1300,9 @@ abstract class Question
if ($objExercise->edit_exercise_in_lp == false) { if ($objExercise->edit_exercise_in_lp == false) {
$img = pathinfo($img); $img = pathinfo($img);
$img = $img['filename'].'_na.'.$img['extension']; $img = $img['filename'].'_na.'.$img['extension'];
echo Display::return_icon($img,$explanation); echo Display::return_icon($img,$explanation);
} else { } else {
echo '<a href="admin.php?'.api_get_cidreq().'&newQuestion=yes&answerType='.$i.'">'.Display::return_icon($img, $explanation).'</a>'; echo '<a href="admin.php?'.api_get_cidreq().'&newQuestion=yes&answerType='.$i.'">'.Display::return_icon($img, $explanation).'</a>';
} }
echo '</div>'; echo '</div>';
echo '</li>'; echo '</li>';
@ -1306,7 +1311,7 @@ abstract class Question
echo '<li>'; echo '<li>';
echo '<div class="icon_image_content">'; echo '<div class="icon_image_content">';
if ($objExercise->edit_exercise_in_lp == false) { if ($objExercise->edit_exercise_in_lp == false) {
echo Display::return_icon('database_na.png', get_lang('GetExistingQuestion')); echo Display::return_icon('database_na.png', get_lang('GetExistingQuestion'));
} else { } else {
if ($feedback_type==1) { if ($feedback_type==1) {
echo $url = '<a href="question_pool.php?'.api_get_cidreq().'&type=1&fromExercise='.$exerciseId.'">'; echo $url = '<a href="question_pool.php?'.api_get_cidreq().'&type=1&fromExercise='.$exerciseId.'">';
@ -1314,49 +1319,49 @@ abstract class Question
echo $url = '<a href="question_pool.php?'.api_get_cidreq().'&fromExercise='.$exerciseId.'">'; echo $url = '<a href="question_pool.php?'.api_get_cidreq().'&fromExercise='.$exerciseId.'">';
} }
echo Display::return_icon('database.png', get_lang('GetExistingQuestion')); echo Display::return_icon('database.png', get_lang('GetExistingQuestion'));
} }
echo '</a>'; echo '</a>';
echo '</div></li>'; echo '</div></li>';
echo '</ul>'; echo '</ul>';
echo '</div>'; echo '</div>';
} }
static function saveQuestionOption($question_id, $name, $course_id, $position = 0) { static function saveQuestionOption($question_id, $name, $course_id, $position = 0) {
$TBL_EXERCICE_QUESTION_OPTION = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION); $TBL_EXERCICE_QUESTION_OPTION = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
$params['question_id'] = intval($question_id); $params['question_id'] = intval($question_id);
$params['name'] = $name; $params['name'] = $name;
$params['position'] = $position; $params['position'] = $position;
$params['c_id'] = $course_id; $params['c_id'] = $course_id;
$result = self::readQuestionOption($question_id, $course_id); $result = self::readQuestionOption($question_id, $course_id);
$last_id = Database::insert($TBL_EXERCICE_QUESTION_OPTION, $params); $last_id = Database::insert($TBL_EXERCICE_QUESTION_OPTION, $params);
return $last_id; return $last_id;
} }
static function deleteAllQuestionOptions($question_id, $course_id) { static function deleteAllQuestionOptions($question_id, $course_id) {
$TBL_EXERCICE_QUESTION_OPTION = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION); $TBL_EXERCICE_QUESTION_OPTION = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
Database::delete($TBL_EXERCICE_QUESTION_OPTION, array('c_id = ? AND question_id = ?'=> array($course_id, $question_id))); Database::delete($TBL_EXERCICE_QUESTION_OPTION, array('c_id = ? AND question_id = ?'=> array($course_id, $question_id)));
} }
static function updateQuestionOption($id, $params, $course_id) { static function updateQuestionOption($id, $params, $course_id) {
$TBL_EXERCICE_QUESTION_OPTION = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION); $TBL_EXERCICE_QUESTION_OPTION = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
$result = Database::update($TBL_EXERCICE_QUESTION_OPTION, $params, array('c_id = ? AND id = ?'=>array($course_id, $id))); $result = Database::update($TBL_EXERCICE_QUESTION_OPTION, $params, array('c_id = ? AND id = ?'=>array($course_id, $id)));
return $result; return $result;
} }
static function readQuestionOption($question_id, $course_id) { static function readQuestionOption($question_id, $course_id) {
$TBL_EXERCICE_QUESTION_OPTION = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION); $TBL_EXERCICE_QUESTION_OPTION = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
$result = Database::select('*', $TBL_EXERCICE_QUESTION_OPTION, array('where'=>array('c_id = ? AND question_id = ?' =>array($course_id, $question_id)), 'order'=>'id ASC')); $result = Database::select('*', $TBL_EXERCICE_QUESTION_OPTION, array('where'=>array('c_id = ? AND question_id = ?' =>array($course_id, $question_id)), 'order'=>'id ASC'));
return $result; return $result;
} }
/** /**
* Shows question title an description * Shows question title an description
* *
* @param type $feedback_type * @param type $feedback_type
* @param type $counter * @param type $counter
* @param type $score * @param type $score
*/ */
function return_header($feedback_type = null, $counter = null, $score = null) { function return_header($feedback_type = null, $counter = null, $score = null) {
$counter_label = ''; $counter_label = '';
if (!empty($counter)) { if (!empty($counter)) {
$counter_label = intval($counter); $counter_label = intval($counter);
@ -1367,7 +1372,7 @@ abstract class Question
$score_label = get_lang('Correct'); $score_label = get_lang('Correct');
$class = 'success'; $class = 'success';
} }
if ($this->type == FREE_ANSWER) { if ($this->type == FREE_ANSWER) {
if ($score['revised'] == true) { if ($score['revised'] == true) {
$score_label = get_lang('Revised'); $score_label = get_lang('Revised');
@ -1375,20 +1380,20 @@ abstract class Question
} else { } else {
$score_label = get_lang('NotRevised'); $score_label = get_lang('NotRevised');
$class = 'error'; $class = 'error';
} }
} }
$question_title = $this->question; $question_title = $this->question;
// display question category, if any // display question category, if any
$header = Testcategory::returnCategoryAndTitle($this->id); $header = Testcategory::returnCategoryAndTitle($this->id);
$header .= Display::page_subheader2($counter_label.". ".$question_title); $header .= Display::page_subheader2($counter_label.". ".$question_title);
//$header .= Display::div('<div class="rib rib-'.$class.'"><h3>'.$score_label.'</h3></div> <h4>'.($score['result']).' </h4><h5 class="'.$class.'">'.$score['result'].' </h5>', array('class'=>'ribbon')); //$header .= Display::div('<div class="rib rib-'.$class.'"><h3>'.$score_label.'</h3></div> <h4>'.($score['result']).' </h4><h5 class="'.$class.'">'.$score['result'].' </h5>', array('class'=>'ribbon'));
$header .= Display::div('<div class="rib rib-'.$class.'"><h3>'.$score_label.'</h3></div> <h4>'.$score['result'].' </h4>', array('class'=>'ribbon')); $header .= Display::div('<div class="rib rib-'.$class.'"><h3>'.$score_label.'</h3></div> <h4>'.$score['result'].' </h4>', array('class'=>'ribbon'));
$header .= Display::div($this->description, array('id'=>'question_description')); $header .= Display::div($this->description, array('id'=>'question_description'));
return $header; return $header;
} }
/** /**
* Create a question from a set of parameters * Create a question from a set of parameters
* @param int Quiz ID * @param int Quiz ID
@ -1399,15 +1404,15 @@ abstract class Question
*/ */
function create_question ($quiz_id, $question_name, $max_score = 0, $type = 1, $level = 1) { function create_question ($quiz_id, $question_name, $max_score = 0, $type = 1, $level = 1) {
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$tbl_quiz_question = Database::get_course_table(TABLE_QUIZ_QUESTION); $tbl_quiz_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
$tbl_quiz_rel_question = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); $tbl_quiz_rel_question = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$quiz_id = intval($quiz_id); $quiz_id = intval($quiz_id);
$max_score = (float) $max_score; $max_score = (float) $max_score;
$type = intval($type); $type = intval($type);
$level = intval($level); $level = intval($level);
// Get the max position // Get the max position
$sql = "SELECT max(position) as max_position" $sql = "SELECT max(position) as max_position"
." FROM $tbl_quiz_question q INNER JOIN $tbl_quiz_rel_question r" ." FROM $tbl_quiz_question q INNER JOIN $tbl_quiz_rel_question r"
@ -1416,14 +1421,14 @@ abstract class Question
$rs_max = Database::query($sql, __FILE__, __LINE__); $rs_max = Database::query($sql, __FILE__, __LINE__);
$row_max = Database::fetch_object($rs_max); $row_max = Database::fetch_object($rs_max);
$max_position = $row_max->max_position +1; $max_position = $row_max->max_position +1;
// Insert the new question // Insert the new question
$sql = "INSERT INTO $tbl_quiz_question (c_id, question, ponderation, position, type, level) $sql = "INSERT INTO $tbl_quiz_question (c_id, question, ponderation, position, type, level)
VALUES ($course_id, '".Database::escape_string($question_name)."', '$max_score', $max_position, $type, $level)"; VALUES ($course_id, '".Database::escape_string($question_name)."', '$max_score', $max_position, $type, $level)";
$rs = Database::query($sql); $rs = Database::query($sql);
// Get the question ID // Get the question ID
$question_id = Database::get_last_insert_id(); $question_id = Database::get_last_insert_id();
// Get the max question_order // Get the max question_order
$sql = "SELECT max(question_order) as max_order " $sql = "SELECT max(question_order) as max_order "
."FROM $tbl_quiz_rel_question WHERE c_id = $course_id AND exercice_id = $quiz_id "; ."FROM $tbl_quiz_rel_question WHERE c_id = $course_id AND exercice_id = $quiz_id ";
@ -1437,19 +1442,19 @@ abstract class Question
$rs = Database::query($sql); $rs = Database::query($sql);
return $question_id; return $question_id;
} }
/** /**
* return the image filename of the question type * return the image filename of the question type
* *
*/ */
public function get_type_icon_html() { public function get_type_icon_html() {
$type = $this->selectType(); $type = $this->selectType();
$tabQuestionList = Question::get_question_type_list(); // [0]=file to include [1]=type name $tabQuestionList = Question::get_question_type_list(); // [0]=file to include [1]=type name
require_once $tabQuestionList[$type][0]; require_once $tabQuestionList[$type][0];
eval('$img = '.$tabQuestionList[$type][1].'::$typePicture;'); eval('$img = '.$tabQuestionList[$type][1].'::$typePicture;');
eval('$explanation = get_lang('.$tabQuestionList[$type][1].'::$explanationLangVar);'); eval('$explanation = get_lang('.$tabQuestionList[$type][1].'::$explanationLangVar);');
return array($img, $explanation); return array($img, $explanation);
} }
} }
endif; endif;

@ -7,7 +7,7 @@
* One question can be in several exercises * One question can be in several exercises
* @package chamilo.exercise * @package chamilo.exercise
* @author Olivier Brouckaert * @author Olivier Brouckaert
* @author Julio Montoya adding support to query all questions from all session, courses, exercises * @author Julio Montoya adding support to query all questions from all session, courses, exercises
* @author Modify by hubert borderiou 2011-10-21 Question's category * @author Modify by hubert borderiou 2011-10-21 Question's category
*/ */
/** /**
@ -78,14 +78,14 @@ $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
$picturePath = $documentPath.'/images'; $picturePath = $documentPath.'/images';
if(!($objExcercise instanceOf Exercise) && !empty($fromExercise)) { if(!($objExcercise instanceOf Exercise) && !empty($fromExercise)) {
$objExercise = new Exercise(); $objExercise = new Exercise();
$objExercise->read($fromExercise); $objExercise->read($fromExercise);
} }
$nameTools = get_lang('QuestionPool'); $nameTools = get_lang('QuestionPool');
$interbreadcrumb[] = array("url" => "exercice.php","name" => get_lang('Exercices')); $interbreadcrumb[] = array("url" => "exercice.php","name" => get_lang('Exercices'));
$interbreadcrumb[] = array("url" => "admin.php?exerciseId=".$objExercise->id, "name" => $objExercise->name); $interbreadcrumb[] = array("url" => "admin.php?exerciseId=".$objExercise->id, "name" => $objExercise->name);
$displayMessage = ""; // messag to be displayed if actions succesfull $displayMessage = ""; // messag to be displayed if actions succesfull
if ($is_allowedToEdit) { if ($is_allowedToEdit) {
//Duplicating a Question //Duplicating a Question
@ -93,22 +93,22 @@ if ($is_allowedToEdit) {
$origin_course_id = intval($_GET['course_id']); $origin_course_id = intval($_GET['course_id']);
$origin_course_info = api_get_course_info_by_id($origin_course_id); $origin_course_info = api_get_course_info_by_id($origin_course_id);
$current_course = api_get_course_info(); $current_course = api_get_course_info();
$old_question_id = $copy_question; $old_question_id = $copy_question;
//Reading the source question //Reading the source question
$old_question_obj = Question::read($old_question_id, $origin_course_id); $old_question_obj = Question::read($old_question_id, $origin_course_id);
if ($old_question_obj) { if ($old_question_obj) {
$old_question_obj->updateTitle($old_question_obj->selectTitle().' - '.get_lang('Copy')); $old_question_obj->updateTitle($old_question_obj->selectTitle().' - '.get_lang('Copy'));
//Duplicating the source question, in the current course //Duplicating the source question, in the current course
$new_id = $old_question_obj->duplicate($current_course); $new_id = $old_question_obj->duplicate($current_course);
//Reading new question //Reading new question
$new_question_obj = Question::read($new_id); $new_question_obj = Question::read($new_id);
$new_question_obj->addToList($fromExercise); $new_question_obj->addToList($fromExercise);
//Reading Answers obj of the current course //Reading Answers obj of the current course
$new_answer_obj = new Answer($old_question_id, $origin_course_id); $new_answer_obj = new Answer($old_question_id, $origin_course_id);
$new_answer_obj->read(); $new_answer_obj->read();
//Duplicating the Answers in the current course //Duplicating the Answers in the current course
$new_answer_obj->duplicate($new_id, $current_course); $new_answer_obj->duplicate($new_id, $current_course);
// destruction of the Question object // destruction of the Question object
unset($new_question_obj); unset($new_question_obj);
unset($old_question_obj); unset($old_question_obj);
@ -116,15 +116,16 @@ if ($is_allowedToEdit) {
$objExercise = new Exercise(); $objExercise = new Exercise();
$objExercise->read($fromExercise); $objExercise->read($fromExercise);
} }
Session::write('objExercise', $objExercise); Session::write('objExercise', $objExercise);
} }
$displayMessage = get_lang('ItemAdded'); $displayMessage = get_lang('ItemAdded');
} }
// deletes a question from the database and all exercises // deletes a question from the database and all exercises
if ($delete) { if ($delete) {
// construction of the Question object // Construction of the Question object
// if the question exists $objQuestionTmp = Question::read($delete);
if ($objQuestionTmp = Question::read($delete)) { // if the question exists
if ($objQuestionTmp) {
// deletes the question from all exercises // deletes the question from all exercises
$objQuestionTmp->delete(); $objQuestionTmp->delete();
} }
@ -134,7 +135,7 @@ if ($is_allowedToEdit) {
// gets an existing question and copies it into a new exercise // gets an existing question and copies it into a new exercise
$objQuestionTmp = Question :: read($recup); $objQuestionTmp = Question :: read($recup);
// if the question exists // if the question exists
if($objQuestionTmp = Question :: read($recup)) { if ($objQuestionTmp) {
// adds the exercise ID represented by $fromExercise into the list of exercises for the current question // adds the exercise ID represented by $fromExercise into the list of exercises for the current question
$objQuestionTmp->addToList($fromExercise); $objQuestionTmp->addToList($fromExercise);
} }
@ -147,21 +148,20 @@ if ($is_allowedToEdit) {
} }
// adds the question ID represented by $recup into the list of questions for the current exercise // adds the question ID represented by $recup into the list of questions for the current exercise
$objExercise->addToList($recup); $objExercise->addToList($recup);
Session::write('objExercise',$objExercise); Session::write('objExercise', $objExercise);
// header("Location: admin.php?".api_get_cidreq()."&exerciseId=$fromExercise"); // header("Location: admin.php?".api_get_cidreq()."&exerciseId=$fromExercise");
// exit(); // exit();
} }
else if( isset($_POST['recup']) && is_array($_POST['recup']) && $fromExercise) { else if( isset($_POST['recup']) && is_array($_POST['recup']) && $fromExercise) {
$list_recup = $_POST['recup']; $list_recup = $_POST['recup'];
foreach ($list_recup as $course_id => $question_data) { foreach ($list_recup as $course_id => $question_data) {
$origin_course_id = intval($course_id); $origin_course_id = intval($course_id);
$origin_course_info = api_get_course_info_by_id($origin_course_id); $origin_course_info = api_get_course_info_by_id($origin_course_id);
$current_course = api_get_course_info(); $current_course = api_get_course_info();
foreach ($question_data as $old_question_id) { foreach ($question_data as $old_question_id) {
/* /*
$recup = intval($recup); $recup = intval($recup);
// if the question exists // if the question exists
@ -177,31 +177,31 @@ if ($is_allowedToEdit) {
} }
// adds the question ID represented by $recup into the list of questions for the current exercise // adds the question ID represented by $recup into the list of questions for the current exercise
$objExercise->addToList($recup); $objExercise->addToList($recup);
*/ */
//Reading the source question //Reading the source question
$old_question_obj = Question::read($old_question_id, $origin_course_id); $old_question_obj = Question::read($old_question_id, $origin_course_id);
if ($old_question_obj) { if ($old_question_obj) {
$old_question_obj->updateTitle($old_question_obj->selectTitle().' - '.get_lang('Copy')); $old_question_obj->updateTitle($old_question_obj->selectTitle().' - '.get_lang('Copy'));
//Duplicating the source question, in the current course //Duplicating the source question, in the current course
$new_id = $old_question_obj->duplicate($current_course); $new_id = $old_question_obj->duplicate($current_course);
//Reading new question //Reading new question
$new_question_obj = Question::read($new_id); $new_question_obj = Question::read($new_id);
$new_question_obj->addToList($fromExercise); $new_question_obj->addToList($fromExercise);
//Reading Answers obj of the current course //Reading Answers obj of the current course
$new_answer_obj = new Answer($old_question_id, $origin_course_id); $new_answer_obj = new Answer($old_question_id, $origin_course_id);
$new_answer_obj->read(); $new_answer_obj->read();
//Duplicating the Answers in the current course //Duplicating the Answers in the current course
$new_answer_obj->duplicate($new_id, $current_course); $new_answer_obj->duplicate($new_id, $current_course);
// destruction of the Question object // destruction of the Question object
unset($new_question_obj); unset($new_question_obj);
unset($old_question_obj); unset($old_question_obj);
if (!$objExcercise instanceOf Exercise) { if (!$objExcercise instanceOf Exercise) {
$objExercise = new Exercise(); $objExercise = new Exercise();
$objExercise->read($fromExercise); $objExercise->read($fromExercise);
@ -230,20 +230,20 @@ if (!$is_allowedToEdit) {
$confirmYourChoice = addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)); $confirmYourChoice = addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset));
$htmlHeadXtra[] = " $htmlHeadXtra[] = "
<script type='text/javascript'> <script type='text/javascript'>
function submit_form(obj) { function submit_form(obj) {
document.question_pool.submit(); document.question_pool.submit();
} }
function mark_course_id_changed() { function mark_course_id_changed() {
$('#course_id_changed').val('1'); $('#course_id_changed').val('1');
} }
function mark_exercice_id_changed() { function mark_exercice_id_changed() {
$('#exercice_id_changed').val('1'); $('#exercice_id_changed').val('1');
} }
function confirm_your_choice() { function confirm_your_choice() {
return confirm('$confirmYourChoice'); return confirm('$confirmYourChoice');
} }
@ -252,7 +252,7 @@ $htmlHeadXtra[] = "
Display::display_header($nameTools,'Exercise'); Display::display_header($nameTools,'Exercise');
// Menu // Menu
echo '<div class="actions">'; echo '<div class="actions">';
if (isset($type)) { if (isset($type)) {
$url = api_get_self().'?type=1'; $url = api_get_self().'?type=1';
@ -276,7 +276,7 @@ if ($displayMessage != "") {
} }
//Form //Form
echo '<form class="form-horizontal" name="question_pool" method="GET" action="'.$url.'">'; echo '<form class="form-horizontal" name="question_pool" method="GET" action="'.$url.'">';
//Title //Title
echo '<legend>'.$nameTools.' - '.$titleAdd.'</legend>'; echo '<legend>'.$nameTools.' - '.$titleAdd.'</legend>';
if (isset($type)) { if (isset($type)) {
@ -298,9 +298,9 @@ echo Display::form_row($labelFormRow, $select_session_html); // hub 13-10-2011
// Course list, get course list of session, or for course where user is admin // Course list, get course list of session, or for course where user is admin
if (!empty($session_id) && $session_id != '-1') { if (!empty($session_id) && $session_id != '-1') {
$course_list = SessionManager::get_course_list_by_session_id($session_id); $course_list = SessionManager::get_course_list_by_session_id($session_id);
} else { } else {
$course_list = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id()); $course_list = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id());
} }
$course_select_list = array(); $course_select_list = array();
foreach ($course_list as $item) { foreach ($course_list as $item) {
$course_select_list[$item['id']] = ""; $course_select_list[$item['id']] = "";
@ -311,14 +311,14 @@ foreach ($course_list as $item) {
} }
$select_course_html = Display::select('selected_course', $course_select_list, $selected_course, array('class'=>'chzn-select','onchange'=>'mark_course_id_changed(); submit_form(this);')); $select_course_html = Display::select('selected_course', $course_select_list, $selected_course, array('class'=>'chzn-select','onchange'=>'mark_course_id_changed(); submit_form(this);'));
echo Display::form_row(get_lang('Course'), $select_course_html); echo Display::form_row(get_lang('Course'), $select_course_html);
if (empty($selected_course) || $selected_course == '-1') { if (empty($selected_course) || $selected_course == '-1') {
$course_info = api_get_course_info(); $course_info = api_get_course_info();
reset_menu_exo_lvl_type(); // no course selected, reset menu test / difficult<EFBFBD> / type de reponse // hub 13-10-2011 reset_menu_exo_lvl_type(); // no course selected, reset menu test / difficult<EFBFBD> / type de reponse // hub 13-10-2011
} }
else { else {
$course_info = CourseManager::get_course_information_by_id($selected_course); $course_info = CourseManager::get_course_information_by_id($selected_course);
} }
// If course has changed, reset the menu default // If course has changed, reset the menu default
if ($course_id_changed) { if ($course_id_changed) {
@ -346,16 +346,16 @@ $exercise_list = get_all_exercises_for_course_id($course_info, $session_
//Exercise List //Exercise List
$my_exercise_list = array(); $my_exercise_list = array();
$my_exercise_list['0'] = get_lang('AllExercises'); $my_exercise_list['0'] = get_lang('AllExercises');
$my_exercise_list['-1'] = get_lang('OrphanQuestions'); $my_exercise_list['-1'] = get_lang('OrphanQuestions');
if (is_array($exercise_list)) { if (is_array($exercise_list)) {
foreach($exercise_list as $row) { foreach($exercise_list as $row) {
$my_exercise_list[$row['id']] = ""; $my_exercise_list[$row['id']] = "";
if ($row['id'] == $fromExercise && $selected_course == api_get_course_int_id()) { if ($row['id'] == $fromExercise && $selected_course == api_get_course_int_id()) {
$my_exercise_list[$row['id']] = ">&nbsp;&nbsp;&nbsp;&nbsp;"; // hub 13-10-2011 $my_exercise_list[$row['id']] = ">&nbsp;&nbsp;&nbsp;&nbsp;"; // hub 13-10-2011
} }
$my_exercise_list[$row['id']] .= $row['title']; $my_exercise_list[$row['id']] .= $row['title'];
} }
} }
if ($exercice_id_changed == 1) { if ($exercice_id_changed == 1) {
reset_menu_lvl_type(); reset_menu_lvl_type();
@ -363,14 +363,14 @@ if ($exercice_id_changed == 1) {
$select_exercise_html = Display::select('exerciseId', $my_exercise_list, $exerciseId, array('class'=>'chzn-select','onchange'=>'mark_exercice_id_changed(); submit_form(this);'), false); $select_exercise_html = Display::select('exerciseId', $my_exercise_list, $exerciseId, array('class'=>'chzn-select','onchange'=>'mark_exercice_id_changed(); submit_form(this);'), false);
echo Display::form_row(get_lang('Exercise'), $select_exercise_html); echo Display::form_row(get_lang('Exercise'), $select_exercise_html);
// Difficulty list (only from 0 to 5) // Difficulty list (only from 0 to 5)
$select_difficulty_html = Display::select('exerciseLevel', array(-1 => get_lang('All'), 0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5), $exerciseLevel, array('class'=>'chzn-select', 'onchange'=>'submit_form(this);'), false); $select_difficulty_html = Display::select('exerciseLevel', array(-1 => get_lang('All'), 0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5), $exerciseLevel, array('class'=>'chzn-select', 'onchange'=>'submit_form(this);'), false);
echo Display::form_row(get_lang('Difficulty'), $select_difficulty_html); echo Display::form_row(get_lang('Difficulty'), $select_difficulty_html);
// Answer type // Answer type
$question_list = Question::get_question_type_list(); $question_list = Question::get_question_type_list();
$new_question_list = array(); $new_question_list = array();
@ -394,9 +394,9 @@ foreach ($question_list as $key=>$item) {
//Answer type list //Answer type list
$select_answer_html = Display::select('answerType', $new_question_list, $answerType, array('class'=>'chzn-select','onchange'=>'submit_form(this);'), false); $select_answer_html = Display::select('answerType', $new_question_list, $answerType, array('class'=>'chzn-select','onchange'=>'submit_form(this);'), false);
echo Display::form_row(get_lang('AnswerType'), $select_answer_html); echo Display::form_row(get_lang('AnswerType'), $select_answer_html);
$button = '<button class="save" type="submit" name="name" value="'.get_lang('Filter').'">'.get_lang('Filter').'</button>'; $button = '<button class="save" type="submit" name="name" value="'.get_lang('Filter').'">'.get_lang('Filter').'</button>';
echo Display::form_row('', $button); echo Display::form_row('', $button);
echo "<input type='hidden' id='course_id_changed' name='course_id_changed' value='0' />"; echo "<input type='hidden' id='course_id_changed' name='course_id_changed' value='0' />";
echo "<input type='hidden' id='exercice_id_changed' name='exercice_id_changed' value='0' />"; echo "<input type='hidden' id='exercice_id_changed' name='exercice_id_changed' value='0' />";
?> ?>
</form> </form>
@ -407,7 +407,7 @@ echo '<input type="hidden" name="course_id" value="'.$selected_course.'">';
// if we have selected an exercise in the list-box 'Filter' // if we have selected an exercise in the list-box 'Filter'
if ($exerciseId > 0) { if ($exerciseId > 0) {
$where = ''; $where = '';
$from = ''; $from = '';
@ -421,36 +421,36 @@ if ($exerciseId > 0) {
if (isset($answerType) && $answerType > 0) { if (isset($answerType) && $answerType > 0) {
$where .= ' AND type='.$answerType; $where .= ' AND type='.$answerType;
} }
$sql = "SELECT DISTINCT $sql = "SELECT DISTINCT
id,question, id,question,
type, type,
level level
FROM FROM
$TBL_EXERCICE_QUESTION qt, $TBL_EXERCICE_QUESTION qt,
$TBL_QUESTIONS qu $TBL_QUESTIONS qu
$from $from
WHERE WHERE
qt.question_id=qu.id qt.question_id=qu.id
AND qt.exercice_id=$exerciseId AND qt.exercice_id=$exerciseId
AND qt.c_id=$selected_course AND qt.c_id=$selected_course
AND qu.c_id=$selected_course AND qu.c_id=$selected_course
$where $where
ORDER BY ORDER BY
question_order"; question_order";
$result=Database::query($sql); $result=Database::query($sql);
while($row = Database::fetch_array($result, 'ASSOC')) { while($row = Database::fetch_array($result, 'ASSOC')) {
$main_question_list[] = $row; $main_question_list[] = $row;
} }
} elseif ($exerciseId == -1) { } elseif ($exerciseId == -1) {
// //
// if we have selected the option 'Orphan questions' in the list-box 'Filter' // if we have selected the option 'Orphan questions' in the list-box 'Filter'
// //
$level_where = ''; $level_where = '';
$from = ''; $from = '';
if (isset($courseCategoryId) && $courseCategoryId > 0) { if (isset($courseCategoryId) && $courseCategoryId > 0) {
$from = ", $TBL_COURSE_REL_CATEGORY crc "; $from = ", $TBL_COURSE_REL_CATEGORY crc ";
$level_where .= " AND crc.c_id=$selected_course AND crc.question_id=qu.id AND crc.category_id=$courseCategoryId"; $level_where .= " AND crc.c_id=$selected_course AND crc.question_id=qu.id AND crc.category_id=$courseCategoryId";
} }
if (isset($exerciseLevel) && $exerciseLevel!= -1 ) { if (isset($exerciseLevel) && $exerciseLevel!= -1 ) {
$level_where = ' AND level='.$exerciseLevel; $level_where = ' AND level='.$exerciseLevel;
} }
@ -463,18 +463,18 @@ if ($exerciseId > 0) {
while($row = Database::fetch_array($result, 'ASSOC')) { while($row = Database::fetch_array($result, 'ASSOC')) {
$main_question_list[] = $row; $main_question_list[] = $row;
} }
} }
else { else {
// //
// All tests for selected course // All tests for selected course
// //
// if we have not selected any option in the list-box 'Filter' // if we have not selected any option in the list-box 'Filter'
$filter = ''; $filter = '';
$from = ''; $from = '';
if (isset($courseCategoryId) && $courseCategoryId > 0) { if (isset($courseCategoryId) && $courseCategoryId > 0) {
$from = ", $TBL_COURSE_REL_CATEGORY crc "; $from = ", $TBL_COURSE_REL_CATEGORY crc ";
$filter .= " AND crc.c_id=$selected_course AND crc.question_id=qu.id AND crc.category_id=$courseCategoryId"; $filter .= " AND crc.c_id=$selected_course AND crc.question_id=qu.id AND crc.category_id=$courseCategoryId";
} }
if (isset($exerciseLevel) && $exerciseLevel != -1) { if (isset($exerciseLevel) && $exerciseLevel != -1) {
$filter .= ' AND level='.$exerciseLevel.' '; $filter .= ' AND level='.$exerciseLevel.' ';
} }
@ -486,26 +486,26 @@ else {
// $filter .= ' AND qu.type <> '.HOT_SPOT_DELINEATION.' '; // $filter .= ' AND qu.type <> '.HOT_SPOT_DELINEATION.' ';
// } // }
// // fwhy // // fwhy
// //
// if in session // if in session
// //
if (!empty($session_id) && $session_id != '-1') { if (!empty($session_id) && $session_id != '-1') {
$main_question_list = array(); $main_question_list = array();
if (!empty($course_list)) if (!empty($course_list))
foreach ($course_list as $course_item) { foreach ($course_list as $course_item) {
if (!empty($selected_course) && $selected_course != '-1') { if (!empty($selected_course) && $selected_course != '-1') {
if ($selected_course != $course_item['id']) { if ($selected_course != $course_item['id']) {
continue; continue;
} }
} }
$exercise_list = get_all_exercises($course_item, $session_id); $exercise_list = get_all_exercises($course_item, $session_id);
if (!empty($exercise_list)) { if (!empty($exercise_list)) {
foreach ($exercise_list as $exercise) { foreach ($exercise_list as $exercise) {
$my_exercise = new Exercise($course_item['id']); $my_exercise = new Exercise($course_item['id']);
$my_exercise->read($exercise['id']); $my_exercise->read($exercise['id']);
if (!empty($my_exercise)) { if (!empty($my_exercise)) {
if (!empty($my_exercise->questionList)) { if (!empty($my_exercise->questionList)) {
foreach ($my_exercise->questionList as $question_id) { foreach ($my_exercise->questionList as $question_id) {
$question_obj = Question::read($question_id, $course_item['id']); $question_obj = Question::read($question_id, $course_item['id']);
if ($exerciseLevel != '-1') if ($exerciseLevel != '-1')
if ($exerciseLevel != $question_obj->level) { if ($exerciseLevel != $question_obj->level) {
@ -515,7 +515,7 @@ else {
if ($answerType != $question_obj->type) { if ($answerType != $question_obj->type) {
continue; continue;
} }
if ($courseCategoryId > 0 && Testcategory::getCategoryForQuestion($question_obj->id, $selected_course)) { if ($courseCategoryId > 0 && Testcategory::getCategoryForQuestion($question_obj->id, $selected_course)) {
continue; continue;
} }
@ -523,26 +523,26 @@ else {
if ($question_obj->type == HOT_SPOT_DELINEATION) { if ($question_obj->type == HOT_SPOT_DELINEATION) {
continue; continue;
} }
} }
$question_row = array( 'id' => $question_obj->id, $question_row = array( 'id' => $question_obj->id,
'question' => $question_obj->question, 'question' => $question_obj->question,
'type' => $question_obj->type, 'type' => $question_obj->type,
'level' => $question_obj->level, 'level' => $question_obj->level,
'exercise_id' => $exercise['id'], 'exercise_id' => $exercise['id'],
'course_id' => $course_item['id'], 'course_id' => $course_item['id'],
); );
$main_question_list[] = $question_row; $main_question_list[] = $question_row;
} }
} }
} }
} }
} }
} }
} }
else { else {
// //
// All tests for the course selected, not in session // All tests for the course selected, not in session
// //
$sql = "SELECT DISTINCT qu.id, question, qu.type, level, q.session_id FROM $TBL_QUESTIONS as qu, $TBL_EXERCICE_QUESTION as qt, $TBL_EXERCICES as q $from WHERE qu.c_id=$selected_course AND qt.c_id=$selected_course AND q.c_id=$selected_course AND qu.id = qt.question_id AND q.id = qt.exercice_id $filter ORDER BY session_id ASC"; $sql = "SELECT DISTINCT qu.id, question, qu.type, level, q.session_id FROM $TBL_QUESTIONS as qu, $TBL_EXERCICE_QUESTION as qt, $TBL_EXERCICES as q $from WHERE qu.c_id=$selected_course AND qt.c_id=$selected_course AND q.c_id=$selected_course AND qu.id = qt.question_id AND q.id = qt.exercice_id $filter ORDER BY session_id ASC";
$result = Database::query($sql); $result = Database::query($sql);
while($row = Database::fetch_array($result, 'ASSOC')) { while($row = Database::fetch_array($result, 'ASSOC')) {
@ -572,7 +572,7 @@ $nbrQuestions = count($main_question_list);
+----------------------+---------------------+---------------------+----------------------+ +----------------------+---------------------+---------------------+----------------------+
(*) this is the only way to delete or modify orphan questions (*) this is the only way to delete or modify orphan questions
*/ */
// //
if ($fromExercise <= 0) { // NOT IN A TEST - IN THE COURSE if ($fromExercise <= 0) { // NOT IN A TEST - IN THE COURSE
if ($selected_course == api_get_course_int_id()) { if ($selected_course == api_get_course_int_id()) {
$actionLabel = get_lang('Modify'); $actionLabel = get_lang('Modify');
@ -601,9 +601,9 @@ else { // IN A TEST - IN THE COURSE
$questionTagA = 0; $questionTagA = 0;
} }
} }
// //
// display table // display table
// //
$header = array(); $header = array();
$header[] = array(get_lang('QuestionUpperCaseFirstLetter'), false, array("style"=>"text-align:center"), ''); $header[] = array(get_lang('QuestionUpperCaseFirstLetter'), false, array("style"=>"text-align:center"), '');
$header[] = array(get_lang('Type'), false, array("style"=>"text-align:center"), array("style"=>"text-align:center"), ''); $header[] = array(get_lang('Type'), false, array("style"=>"text-align:center"), array("style"=>"text-align:center"), '');
@ -628,15 +628,15 @@ if (is_array($main_question_list)) {
$row[] = $question_type; $row[] = $question_type;
$row[] = get_question_categorie_for_question($selected_course, $tabQuestion['id']); $row[] = get_question_categorie_for_question($selected_course, $tabQuestion['id']);
$row[] = $tabQuestion['level']; $row[] = $tabQuestion['level'];
$row[] = get_action_icon_for_question($actionIcon1, $fromExercise, $tabQuestion['id'], $tabQuestion['type'], $row[] = get_action_icon_for_question($actionIcon1, $fromExercise, $tabQuestion['id'], $tabQuestion['type'],
$tabQuestion['question'], $selected_course, $courseCategoryId, $exerciseLevel, $tabQuestion['question'], $selected_course, $courseCategoryId, $exerciseLevel,
$answerType, $session_id, $exerciseId). $answerType, $session_id, $exerciseId).
"&nbsp;". "&nbsp;".
get_action_icon_for_question($actionIcon2, $fromExercise, $tabQuestion['id'], $tabQuestion['type'], get_action_icon_for_question($actionIcon2, $fromExercise, $tabQuestion['id'], $tabQuestion['type'],
$tabQuestion['question'], $selected_course, $courseCategoryId, $exerciseLevel, $answerType, $tabQuestion['question'], $selected_course, $courseCategoryId, $exerciseLevel, $answerType,
$session_id, $exerciseId); $session_id, $exerciseId);
$data[] = $row; $data[] = $row;
} }
} }
Display :: display_sortable_table($header, $data, '', array('per_page_default'=>999,'per_page'=>999,'page_nr'=>1)); Display :: display_sortable_table($header, $data, '', array('per_page_default'=>999,'per_page'=>999,'page_nr'=>1));
@ -678,7 +678,7 @@ function reset_menu_exo_lvl_type() {
$courseCategoryId = 0; $courseCategoryId = 0;
} }
// //
// return the <a> link to admin question, if needed // return the <a> link to admin question, if needed
// hubert.borderiou 13-10-2011 // hubert.borderiou 13-10-2011
function get_a_tag_for_question($in_addA, $in_fromex, $in_questionid, $in_questiontype, $in_questionname) { function get_a_tag_for_question($in_addA, $in_fromex, $in_questionid, $in_questiontype, $in_questionname) {
@ -695,24 +695,24 @@ $row[] = get_action_icon_for_question(
$actionIcon1, -- $actionIcon1, --
$fromExercise, -- $fromExercise, --
$tabQuestion['id'], -- $tabQuestion['id'], --
$tabQuestion['type'], $tabQuestion['type'],
$tabQuestion['question'], $tabQuestion['question'],
$selected_course, $selected_course,
$courseCategoryId, $courseCategoryId,
$exerciseLevel, $exerciseLevel,
$answerType, $answerType,
$session_id, $session_id,
$exerciseId). $exerciseId).
"&nbsp;". "&nbsp;".
get_action_icon_for_question($actionIcon2, $fromExercise, $tabQuestion['id'], $tabQuestion['type'], get_action_icon_for_question($actionIcon2, $fromExercise, $tabQuestion['id'], $tabQuestion['type'],
$tabQuestion['question'], $selected_course, $courseCategoryId, $exerciseLevel, $answerType, $tabQuestion['question'], $selected_course, $courseCategoryId, $exerciseLevel, $answerType,
$session_id, $exerciseId); $session_id, $exerciseId);
*/ */
// //
// return the <a> html code for delete, add, clone, edit a question // return the <a> html code for delete, add, clone, edit a question
// hubert.borderiou 13-10-2011 // hubert.borderiou 13-10-2011
// in_action = the code of the action triggered by the button // in_action = the code of the action triggered by the button
@ -720,21 +720,21 @@ $session_id, $exerciseId);
// in_questionid = the id of the current question // in_questionid = the id of the current question
// in_questiontype = the code of the type of the current question // in_questiontype = the code of the type of the current question
// in_questionname = the name of the question // in_questionname = the name of the question
// in_selected_course = the if of the course chosen in the FILTERING MENU // 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_courseCategoryId = the id of the category chosen in the FILTERING MENU
// in_exerciseLevel = the level of the exercice 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_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_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 // 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, 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 $in_selected_course, $in_courseCategoryId, $in_exerciseLevel, $in_answerType, $in_session_id, $in_exercice_id
) { ) {
$res = ""; $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"; $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) { switch ($in_action) {
case "delete" : case "delete" :
$res = "<a href='".api_get_self()."?".api_get_cidreq()."&delete=$in_questionid$getParams' onclick='return confirm_your_choice()'>"; $res = "<a href='".api_get_self()."?".api_get_cidreq()."&delete=$in_questionid$getParams' onclick='return confirm_your_choice()'>";
$res .= Display::return_icon("delete.gif", get_lang('Delete')); $res .= Display::return_icon("delete.gif", get_lang('Delete'));
$res .= "</a>"; $res .= "</a>";
@ -761,7 +761,7 @@ function get_action_icon_for_question($in_action, $from_exercice, $in_questionid
$res .= Display::return_icon('cd.gif', get_lang('ReUseACopyInCurrentTest')); $res .= Display::return_icon('cd.gif', get_lang('ReUseACopyInCurrentTest'));
$res .= "</a>"; $res .= "</a>";
break; break;
default : default :
$res = $in_action; $res = $in_action;
break; break;
} }
@ -771,9 +771,9 @@ function get_action_icon_for_question($in_action, $from_exercice, $in_questionid
// return the icon for the question type // return the icon for the question type
// hubert.borderiou 13-10-2011 // hubert.borderiou 13-10-2011
function get_question_type_for_question($in_selectedcourse, $in_questionid) { function get_question_type_for_question($in_selectedcourse, $in_questionid) {
$myObjQuestion = Question::read($in_questionid, $in_selectedcourse); $myObjQuestion = Question::read($in_questionid, $in_selectedcourse);
$questionType = null; $questionType = null;
if (!empty($myObjQuestion)) { if (!empty($myObjQuestion)) {
list($typeImg, $typeExpl) = $myObjQuestion->get_type_icon_html(); list($typeImg, $typeExpl) = $myObjQuestion->get_type_icon_html();
$questionType = Display::tag('div', Display::return_icon($typeImg, $typeExpl, array(), 32), array()); $questionType = Display::tag('div', Display::return_icon($typeImg, $typeExpl, array(), 32), array());
unset($myObjQuestion); unset($myObjQuestion);

Loading…
Cancel
Save