|
@@ -1,10 +1,10 @@
|
|
|
-<?php // $Id: question_pool.php 18159 2009-02-02 17:30:00Z herodoto $
|
|
|
+<?php // $Id: question_pool.php 18411 2009-02-10 17:59:08Z juliomontoya $
|
|
|
|
|
|
/*
|
|
|
==============================================================================
|
|
|
Dokeos - elearning and course management software
|
|
|
|
|
|
- Copyright (c) 2004-2008 Dokeos SPRL
|
|
|
+ Copyright (c) 2004-2009 Dokeos SPRL
|
|
|
Copyright (c) 2003 Ghent University (UGent)
|
|
|
Copyright (c) 2001 Universite catholique de Louvain (UCL)
|
|
|
Copyright (c) various contributors
|
|
@@ -30,7 +30,7 @@
|
|
|
* One question can be in several exercises
|
|
|
* @package dokeos.exercise
|
|
|
* @author Olivier Brouckaert
|
|
|
-* @version $Id: question_pool.php 18159 2009-02-02 17:30:00Z herodoto $
|
|
|
+* @version $Id: question_pool.php 18411 2009-02-10 17:59:08Z juliomontoya $
|
|
|
*/
|
|
|
|
|
|
// name of the language file that needs to be included
|
|
@@ -39,7 +39,6 @@ $language_file='exercice';
|
|
|
include('exercise.class.php');
|
|
|
include('question.class.php');
|
|
|
include('answer.class.php');
|
|
|
-
|
|
|
include('../inc/global.inc.php');
|
|
|
|
|
|
$this_section=SECTION_COURSES;
|
|
@@ -70,6 +69,11 @@ if(!empty($_GET['page'])){
|
|
|
$page = intval($_GET['page']);
|
|
|
}
|
|
|
|
|
|
+//only that type of question
|
|
|
+if(!empty($_GET['type'])){
|
|
|
+ $type = intval($_GET['type']);
|
|
|
+}
|
|
|
+
|
|
|
// maximum number of questions on a same page
|
|
|
$limitQuestPage=50;
|
|
|
|
|
@@ -127,9 +131,7 @@ if($is_allowedToEdit)
|
|
|
}
|
|
|
// 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();
|
|
|
}
|
|
@@ -149,106 +151,149 @@ if($is_allowedToEdit)
|
|
|
|
|
|
<div class="actions">
|
|
|
<?php
|
|
|
- if(!empty($fromExercise))
|
|
|
- {
|
|
|
+ if(!empty($fromExercise)) {
|
|
|
echo '<a href="admin.php?',api_get_cidreq(),'&exerciseId=',$fromExercise,'">'.Display::return_icon('quiz.gif', get_lang('GoBackToEx')),get_lang('GoBackToEx'),'</a>';
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
echo '<a href="admin.php?',api_get_cidreq(),'&newQuestion=yes">'.Display::return_icon('new_test.gif'),get_lang('NewQu'),'</a>';
|
|
|
+ }
|
|
|
+ if (isset($type)) {
|
|
|
+ $url = api_get_self().'?type=1';
|
|
|
+ } else {
|
|
|
+ $url = api_get_self();
|
|
|
}
|
|
|
?>
|
|
|
-
|
|
|
- <form method="get" action="<?php echo api_get_self(); ?>" style="display:inline;">
|
|
|
+
|
|
|
+ <form method="get" action="<?php echo $url; ?>" style="display:inline;">
|
|
|
+ <?php
|
|
|
+ if (isset($type)) {
|
|
|
+ echo '<input type="hidden" name="type" value="1">';
|
|
|
+ }
|
|
|
+ ?>
|
|
|
<input type="hidden" name="fromExercise" value="<?php echo $fromExercise; ?>">
|
|
|
|
|
|
<?php echo get_lang('Filter'); ?> :
|
|
|
<select name="exerciseId">
|
|
|
<option value="0">-- <?php echo get_lang('AllExercises'); ?> --</option>
|
|
|
<option value="-1" <?php if($exerciseId == -1) echo 'selected="selected"'; ?>>-- <?php echo get_lang('OrphanQuestions'); ?> --</option>
|
|
|
-
|
|
|
<?php
|
|
|
$sql="SELECT id,title FROM $TBL_EXERCICES WHERE id<>'".Database::escape_string($fromExercise)."' AND active<>'-1' ORDER BY id";
|
|
|
$result=api_sql_query($sql,__FILE__,__LINE__);
|
|
|
|
|
|
// shows a list-box allowing to filter questions
|
|
|
- while($row=Database::fetch_array($result))
|
|
|
- {
|
|
|
+ while($row=Database::fetch_array($result)) {
|
|
|
?>
|
|
|
<option value="<?php echo $row['id']; ?>" <?php if($exerciseId == $row['id']) echo 'selected="selected"'; ?>><?php echo $row['title']; ?></option>
|
|
|
<?php
|
|
|
}
|
|
|
?>
|
|
|
</select>
|
|
|
-
|
|
|
- <?php echo get_lang('Difficulty'); ?> : <select name="exerciseLevel">
|
|
|
- <option value="-1">-- <?php echo get_lang('AllExercises'); ?> --</option>
|
|
|
- <?php
|
|
|
- $sql = "SELECT MAX(level) FROM $TBL_QUESTIONS";
|
|
|
- $result = api_sql_query($sql,__FILE__,__LINE__);
|
|
|
- if ($row = Database::fetch_array($result)) {
|
|
|
- $maxLevel = $row[0];
|
|
|
- } else {
|
|
|
- $maxLevel = -1;
|
|
|
- }
|
|
|
- for ($level = 0; $level <= $maxLevel; $level++) {
|
|
|
- ?>
|
|
|
- <option value="<?php echo $level; ?>" <?php if($exerciseLevel == $level) echo 'selected="selected"'; ?>><?php echo $level; ?></option>
|
|
|
- <?php
|
|
|
+
|
|
|
+ <?php
|
|
|
+ echo get_lang('Difficulty');
|
|
|
+ echo ' : <select name="exerciseLevel">';
|
|
|
+ //echo '<option value="-1">-- '.get_lang('AllExercises').' --</option>';
|
|
|
+ if (!isset($exerciseLevel)) $exerciseLevel = -1;
|
|
|
+
|
|
|
+ for ($level = -1; $level <=5; $level++) {
|
|
|
+ $selected ='';
|
|
|
+ if ($exerciseLevel == $level)
|
|
|
+ $selected = ' selected="selected" ';
|
|
|
+ if ($level==-1) {
|
|
|
+ echo '<option value="'.$level.'" '.$selected.'>-- '.get_lang('AllExercises').' --</option>';
|
|
|
+ } else {
|
|
|
+ echo '<option value="'.$level.'" '.$selected.'>'.$level.'</option>';
|
|
|
+ }
|
|
|
}
|
|
|
- ?>
|
|
|
-
|
|
|
- </select>
|
|
|
-
|
|
|
-
|
|
|
- <input type="submit" value="<?php echo get_lang('Ok'); ?>">
|
|
|
+ echo '</select> ';
|
|
|
+ ?>
|
|
|
+ <input type="submit" value="<?php echo get_lang('Ok'); ?>">
|
|
|
</form>
|
|
|
</div>
|
|
|
|
|
|
<table class="data_table">
|
|
|
<?php
|
|
|
$from=$page*$limitQuestPage;
|
|
|
-
|
|
|
// if we have selected an exercise in the list-box 'Filter'
|
|
|
- if($exerciseId > 0)
|
|
|
- {
|
|
|
+ if ($exerciseId > 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);
|
|
|
- $sql="SELECT id,question,type,level FROM $TBL_EXERCICE_QUESTION,$TBL_QUESTIONS WHERE question_id=id AND exercice_id='".Database::escape_string($exerciseId)."' ".
|
|
|
- (!is_null($exerciseLevel) && $exerciseLevel >= 0 ? 'AND level=\''.$exerciseLevel.'\' ' : '')."ORDER BY question_order";
|
|
|
- }
|
|
|
- // if we have selected the option 'Orphan questions' in the list-box 'Filter'
|
|
|
- elseif($exerciseId == -1)
|
|
|
- {
|
|
|
- // Old logic: When a test is deleted, the correspondent records in 'quiz' and 'quiz_rel_question' tables are deleted.
|
|
|
+ $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);
|
|
|
|
|
|
- // New logic: When a test is deleted, the field 'active' takes value -1 (it is in the correspondent record in 'quiz' table).
|
|
|
+ // 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);
|
|
|
|
|
|
- // This is more safe to changes, it is a mix between old and new logic.
|
|
|
+ // 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);
|
|
|
-
|
|
|
+ ' as exercices ON exercice_id=exercices.id WHERE quizz_questions.exercice_id IS NULL OR exercices.active = -1 LIMIT '.$from.', '.($limitQuestPage + 1);
|
|
|
*/
|
|
|
- $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 '.
|
|
|
+
|
|
|
+ /* 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);
|
|
|
|
|
|
- }
|
|
|
- // if we have not selected any option in the list-box 'Filter'
|
|
|
- else
|
|
|
- {
|
|
|
+ } 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);
|
|
|
- $sql="SELECT id,question,type,level FROM $TBL_QUESTIONS ".
|
|
|
- (!is_null($exerciseLevel) && $exerciseLevel >= 0 ? 'WHERE level=\''.$exerciseLevel.'\' ' : '');
|
|
|
+ $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);
|
|
|
|
|
@@ -260,21 +305,15 @@ if($is_allowedToEdit)
|
|
|
echo '</td>',
|
|
|
'<td align="right">';
|
|
|
|
|
|
- if(!empty($page))
|
|
|
- {
|
|
|
+ if(!empty($page)) {
|
|
|
echo '<a href="',api_get_self(),'?',api_get_cidreq(),'&exerciseId=',$exerciseId,'&fromExercise=',$fromExercise,'&page=',($page-1),'"><< ',get_lang('PreviousPage'),'</a> |';
|
|
|
- }
|
|
|
- elseif($nbrQuestions > $limitQuestPage)
|
|
|
- {
|
|
|
+ } elseif($nbrQuestions > $limitQuestPage) {
|
|
|
echo '<< ',get_lang('PreviousPage'),' |';
|
|
|
}
|
|
|
|
|
|
- if($nbrQuestions > $limitQuestPage)
|
|
|
- {
|
|
|
+ if($nbrQuestions > $limitQuestPage) {
|
|
|
echo '<a href="',api_get_self(),'?',api_get_cidreq(),'&exerciseId=',$exerciseId,'&fromExercise=',$fromExercise,'&page=',($page+1),'">',get_lang('NextPage'),' >></a>';
|
|
|
- }
|
|
|
- elseif($page)
|
|
|
- {
|
|
|
+ } elseif($page) {
|
|
|
echo ' ',get_lang('NextPage'),' >>';
|
|
|
}
|
|
|
echo '</td>
|
|
@@ -284,23 +323,21 @@ if($is_allowedToEdit)
|
|
|
</tr>
|
|
|
<tr bgcolor="#e6e6e6">';
|
|
|
|
|
|
- if(!empty($fromExercise))
|
|
|
- {
|
|
|
+ if(!empty($fromExercise)) {
|
|
|
echo '<th>',get_lang('Question'),'</th>',
|
|
|
'<th>',get_lang('Level'),'</th>',
|
|
|
'<th>',get_lang('Reuse'),'</th>';
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
echo '<td width="60%" align="center">',get_lang('Question'),'</td>',
|
|
|
'<td width="20%" align="center">',get_lang('Modify'),'</td>',
|
|
|
'<td width="20%" align="center">',get_lang('Delete'),'</td>';
|
|
|
}
|
|
|
echo '</tr>';
|
|
|
$i=1;
|
|
|
- //print_r($objExercise->questionList);
|
|
|
- while ($row = Database::fetch_array($result))
|
|
|
- {
|
|
|
+ echo '<pre>';
|
|
|
+
|
|
|
+ echo '</pre>';
|
|
|
+ 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
|
|
|
|
|
@@ -312,32 +349,27 @@ if($is_allowedToEdit)
|
|
|
|
|
|
// original recipe -
|
|
|
//if (!$fromExercise || !isset($objExercise) || !($objExercise instanceOf Exercise) || (!$objExercise->isInList($row['id'])))
|
|
|
- if (!$fromExercise || !isset($objExercise) || !($objExercise instanceOf Exercise) || (is_array($objExercise->questionList)) )
|
|
|
- {
|
|
|
+ if (!$fromExercise || !isset($objExercise) || !($objExercise instanceOf Exercise) || (is_array($objExercise->questionList)) ) {
|
|
|
echo '<tr ',($i%2==0?'class="row_odd"':'class="row_even"'),'>';
|
|
|
echo ' <td><a href="admin.php?',api_get_cidreq(),'&editQuestion=',$row['id'],'&fromExercise=',$fromExercise,'">',$row['question'],'</a></td>';
|
|
|
echo ' <td>';
|
|
|
- if (empty($fromExercise))
|
|
|
- {
|
|
|
+ if (empty($fromExercise)) {
|
|
|
echo '<a href="admin.php?',api_get_cidreq(),'?editQuestion=',$row['id'],'"><img src="../img/edit.gif" border="0" alt="',get_lang('Modify'),'"></a>',
|
|
|
'</td>',
|
|
|
'<td align="center">',
|
|
|
'<a href="',api_get_self(),'?',api_get_cidreq(),'&exerciseId=',$exerciseId,'&delete=',$row['id'],'" onclick="javascript:if(!confirm(\'',addslashes(htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)),'\')) return false;"><img src="../img/delete.gif" border="0" alt="',get_lang('Delete'),'"></a>';
|
|
|
//'<a href="',api_get_self(),'?',api_get_cidreq(),'&exerciseId=',$exerciseId,'&delete=',$row['id'],'" onclick="javascript:if(!confirm(\'',addslashes(htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)),'\')) return false;"><img src="../img/delete.gif" border="0" alt="',get_lang('Delete'),'"></a>';
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
//echo $row['level'],'</td>',
|
|
|
// '<td><a href="',api_get_self(),'?',api_get_cidreq(),'&recup=',$row['id'],'&fromExercise=',$fromExercise,'"><img src="../img/view_more_stats.gif" border="0" alt="',get_lang('Reuse'),'"></a>';
|
|
|
echo $row['level'],'</td>',
|
|
|
'<td><a href="',api_get_self(),'?',api_get_cidreq(),'&recup=',$row['id'],'&fromExercise=',$fromExercise,'"><img src="../img/view_more_stats.gif" border="0" alt="',get_lang('Reuse'),'"></a>';
|
|
|
}
|
|
|
- echo ' </td>';
|
|
|
+ echo '</td>';
|
|
|
echo '</tr>';
|
|
|
|
|
|
// skips the last question, that is only used to know if we have or not to create a link "Next page"
|
|
|
- if($i == $limitQuestPage)
|
|
|
- {
|
|
|
+ if($i == $limitQuestPage) {
|
|
|
break;
|
|
|
}
|
|
|
|
|
@@ -345,18 +377,16 @@ if($is_allowedToEdit)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if(!$nbrQuestions)
|
|
|
- {
|
|
|
+ if (!$nbrQuestions) {
|
|
|
echo '<tr>',
|
|
|
'<td colspan="',($fromExercise?3:3),'">',get_lang('NoQuestion'),'</td>',
|
|
|
'</tr>';
|
|
|
}
|
|
|
echo '</table>';
|
|
|
Display::display_footer();
|
|
|
-}
|
|
|
-// if not admin of course
|
|
|
-else
|
|
|
-{
|
|
|
+} else {
|
|
|
+ // if not admin of course
|
|
|
api_not_allowed(true);
|
|
|
}
|
|
|
-?>
|
|
|
+
|
|
|
+?>
|