read($fromExercise); } if(!($objExcercise instanceOf Exercise) && !empty($exerciseId)) { $objExercise = new Exercise(); $objExercise->read($exerciseId); } if($is_allowedToEdit) { // deletes a question from the data base and all exercises if($delete) { // construction of the Question object // if the question exists if($objQuestionTmp = Question::read($delete)) { // deletes the question from all exercises $objQuestionTmp->delete(); } // destruction of the Question object unset($objQuestionTmp); } // gets an existing question and copies it into a new exercise elseif($recup && $fromExercise) { // if the question exists if($objQuestionTmp = Question :: read($recup)) { // 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(!$objExcercise 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); api_session_register('objExercise'); header("Location: admin.php?exerciseId=$fromExercise"); exit(); } } if (isset($_SESSION['gradebook'])){ $gradebook= $_SESSION['gradebook']; } if (!empty($gradebook) && $gradebook=='view') { $interbreadcrumb[]= array ( 'url' => '../gradebook/'.$_SESSION['gradebook_dest'], 'name' => get_lang('Gradebook') ); } $nameTools=get_lang('QuestionPool'); $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices')); // if admin of course if($is_allowedToEdit) { Display::display_header($nameTools,"Exercise"); ?>

'.Display::return_icon('quiz.gif', get_lang('GoBackToEx')),get_lang('GoBackToEx'),''; } else { echo ''.Display::return_icon('new_test.gif'),get_lang('NewQu'),''; } if (isset($type)) { $url = api_get_self().'?type=1'; } else { $url = api_get_self(); } ?>
'; } ?> :   '; //echo ''; //level difficulty only from 1 to 5 if (!isset($exerciseLevel)) $exerciseLevel = -1; for ($level = -1; $level <=5; $level++) { $selected =''; if ($level!=0) { if ($exerciseLevel == $level) $selected = ' selected="selected" '; if ($level==-1) { echo ''; } else { echo ''; } } } echo ' '; ?>
0) { //$sql="SELECT id,question,type FROM $TBL_EXERCICE_QUESTION,$TBL_QUESTIONS WHERE question_id=id AND exercice_id='".Database::escape_string($exerciseId)."' ORDER BY question_order LIMIT $from, ".($limitQuestPage + 1); $where = ''; if (isset($type) && $type==1) { $where = ' type = 1 AND '; } if (isset($exerciseLevel) && $exerciseLevel != -1) { $where .= ' level='.$exerciseLevel.' AND '; } $sql="SELECT id,question,type,level FROM $TBL_EXERCICE_QUESTION,$TBL_QUESTIONS WHERE $where question_id=id AND exercice_id='".Database::escape_string($exerciseId)."' ORDER BY question_order"; } elseif($exerciseId == -1) { // if we have selected the option 'Orphan questions' in the list-box 'Filter' // 1. Old logic: When a test is deleted, the correspondent records in 'quiz' and 'quiz_rel_question' tables are deleted. //$sql='SELECT id, question, type, exercice_id FROM '.$TBL_QUESTIONS.' as questions LEFT JOIN '.$TBL_EXERCICE_QUESTION.' as quizz_questions ON questions.id=quizz_questions.question_id WHERE exercice_id IS NULL LIMIT $from, '.($limitQuestPage + 1); // 2. New logic: When a test is deleted, the field 'active' takes value -1 (it is in the correspondent record in 'quiz' table). //$sql='SELECT questions.id, questions.question, questions.type, quizz_questions.exercice_id FROM '.$TBL_QUESTIONS. // ' as questions LEFT JOIN '.$TBL_EXERCICE_QUESTION.' as quizz_questions ON questions.id=quizz_questions.question_id LEFT JOIN '.$TBL_EXERCICES. // ' as exercices ON exercice_id=exercices.id WHERE exercices.active = -1 LIMIT $from, '.($limitQuestPage + 1); // 3. This is more safe to changes, it is a mix between old and new logic. /*$sql='SELECT questions.id, questions.question, questions.type, quizz_questions.exercice_id FROM '.$TBL_QUESTIONS. ' as questions LEFT JOIN '.$TBL_EXERCICE_QUESTION.' as quizz_questions ON questions.id=quizz_questions.question_id LEFT JOIN '.$TBL_EXERCICES. ' as exercices ON exercice_id=exercices.id WHERE quizz_questions.exercice_id IS NULL OR exercices.active = -1 LIMIT '.$from.', '.($limitQuestPage + 1); */ /* 4. Query changed because of the Level feature implemented $sql='SELECT id, question, type, exercice_id,level FROM '.$TBL_QUESTIONS.' as questions LEFT JOIN '.$TBL_EXERCICE_QUESTION.' as quizz_questions ON questions.id=quizz_questions.question_id AND exercice_id IS NULL '. (!is_null($exerciseLevel) && $exerciseLevel >= 0 ? 'WHERE level=\''.$exerciseLevel.'\' ' : ''); */ // 5. this is the combination of the 3 and 4 query because of the level feature implementation // we filter the type of question, because in the DirectFeedback we can only add questions with type=1 = UNIQUE_ANSWER $type_where= ''; if (isset($type) && $type==1) { $type_where = ' AND questions.type = 1 '; } $level_where = ''; if (isset($exerciseLevel) && $exerciseLevel!= -1 ) { $level_where = ' level='.$exerciseLevel.' AND '; } $sql='SELECT questions.id, questions.question, questions.type, quizz_questions.exercice_id , level FROM '.$TBL_QUESTIONS.' as questions LEFT JOIN '.$TBL_EXERCICE_QUESTION.' as quizz_questions ON questions.id=quizz_questions.question_id LEFT JOIN '.$TBL_EXERCICES.' as exercices ON exercice_id=exercices.id WHERE '.$level_where.' (quizz_questions.exercice_id IS NULL OR exercices.active = -1 ) '.$type_where.' LIMIT '.$from.', '.($limitQuestPage + 1); } else { // if we have not selected any option in the list-box 'Filter' //$sql="SELECT id,question,type FROM $TBL_QUESTIONS LIMIT $from, ".($limitQuestPage + 1); $where = ''; if (isset($type)&& $type==1){ $where = ' WHERE type = 1 '; } if (isset($exerciseLevel) && $exerciseLevel != -1) { if (strlen($where)>0) $where .= ' AND level='.$exerciseLevel.' '; else $where = ' WHERE level='.$exerciseLevel.' '; } $sql="SELECT id,question,type,level FROM $TBL_QUESTIONS $where "; // forces the value to 0 //echo $sql; $exerciseId=0; } $result=api_sql_query($sql,__FILE__,__LINE__); $nbrQuestions=Database::num_rows($result); echo '', ''; if(!empty($fromExercise)) { echo '', '', ''; } else { echo '', '', ''; } echo ''; $i=1; echo '
';
	
	echo '
'; while ($row = Database::fetch_array($result)) { // if we come from the exercise administration to get a question, // don't show the questions already used by that exercise /*if (!$fromExercise) {echo '1'; } if (!isset($objExercise)){echo '2';} if (!($objExercise instanceOf Exercise)){echo '3';} if (!$objExercise->isInList($row['id'])) {echo '4';} */ // original recipe - //if (!$fromExercise || !isset($objExercise) || !($objExercise instanceOf Exercise) || (!$objExercise->isInList($row['id']))) if (!$fromExercise || !isset($objExercise) || !($objExercise instanceOf Exercise) || (is_array($objExercise->questionList)) ) { echo ''; echo ' '; echo ' ', '', // '', ''; echo ''; // skips the last question, that is only used to know if we have or not to create a link "Next page" if($i == $limitQuestPage) { break; } $i++; } } if (!$nbrQuestions) { echo '', '', ''; } echo '
', '', '', '', '
'; echo ''; if(!empty($page)) { echo '<< ',get_lang('PreviousPage'),' |'; } elseif($nbrQuestions > $limitQuestPage) { echo '<< ',get_lang('PreviousPage'),' |'; } if($nbrQuestions > $limitQuestPage) { echo '',get_lang('NextPage'),' >>'; } elseif($page) { echo ' ',get_lang('NextPage'),' >>'; } echo '
',get_lang('Question'),'',get_lang('Level'),'',get_lang('Reuse'),'',get_lang('Question'),'',get_lang('Modify'),'',get_lang('Delete'),'
',$row['question'],''; if (empty($fromExercise)) { echo '',get_lang('Modify'),'', '', '',get_lang('Delete'),''; //'',get_lang('Delete'),''; } else { //echo $row['level'],'',get_lang('Reuse'),''; echo $row['level'],'' . '',get_lang('Reuse'),''; } echo '
',get_lang('NoQuestion'),'
'; Display::display_footer(); } else { // if not admin of course api_not_allowed(true); } ?>