浏览代码

Fixed validated the sessions, in some parts of the exercises CT#973

Carlos Vargas 15 年之前
父节点
当前提交
fb6e016deb
共有 2 个文件被更改,包括 19 次插入20 次删除
  1. 4 1
      main/exercice/question_create.php
  2. 15 19
      main/exercice/question_pool.php

+ 4 - 1
main/exercice/question_create.php

@@ -44,9 +44,12 @@ $form->addElement('static','','<script src="'.api_get_path(WEB_LIBRARY_PATH).'ja
 							<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.customselect.js" type="text/javascript"></script>');
 $form->addElement('static','select_question_type', get_lang('QuestionType'),'<div id="questiontypes"></div>');
 
+//session id
+$session_id  = api_get_session_id();
+
 // the exercices
 $tbl_exercices = Database :: get_course_table(TABLE_QUIZ_TEST);
-$sql = "SELECT id,title,type,description, results_disabled FROM $tbl_exercices WHERE active<>'-1' ORDER BY title ASC";
+$sql = "SELECT id,title,type,description, results_disabled FROM $tbl_exercices WHERE active<>'-1' AND session_id=".$session_id." ORDER BY title ASC";
 $result = Database::query($sql);
 $exercises['-'] = '-'.get_lang('SelectExercice').'-';
 while ($row = Database :: fetch_array($result)) {

+ 15 - 19
main/exercice/question_pool.php

@@ -212,7 +212,7 @@ if($is_allowedToEdit)
 	?>
 	<input type="hidden" name="fromExercise" value="<?php echo $fromExercise; ?>">
 
-	<?php echo get_lang('Filter'); ?> :
+	<?php echo get_lang('Exercice'); ?> :
 	<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>
@@ -275,7 +275,7 @@ if($is_allowedToEdit)
 		echo '</select> ';
 	?>
 
-	<button class="save" type="submit" name="name" value="<?php echo get_lang('Ok') ?>"><?php echo get_lang('Ok') ?></button>
+	<button class="save" type="submit" name="name" value="<?php echo get_lang('Ok') ?>"><?php echo get_lang('Filter') ?></button>
 	<?php
 	echo '<a href="admin.php?',api_get_cidreq(),'&exerciseId=',$fromExercise,'">'.Display::return_icon('message_reply_forum.png', get_lang('GoBackToQuestionList')),get_lang('GoBackToQuestionList'),'</a>';
 	/*if(!empty($fromExercise)) {
@@ -354,7 +354,7 @@ if($is_allowedToEdit)
 			$answer_where = ' questions.type='.$answerType.' AND ';
 		}
 
-		$sql='SELECT questions.id, questions.question, questions.type, quizz_questions.exercice_id , level
+		$sql='SELECT questions.id, questions.question, questions.type, quizz_questions.exercice_id , level, session_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
@@ -365,29 +365,22 @@ if($is_allowedToEdit)
 		// 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 = '';
+		$filter = '';
 
-		if (isset($type)&& $type==1){
-			$where = ' WHERE type = 1 ';
+		if (isset($type) && $type==1){
+			$filter  .= ' AND qu.type = 1 ';
 		}
 
 
 		if (isset($exerciseLevel) && $exerciseLevel != -1) {
-			if (strlen($where)>0)
-				$where .= ' AND level='.$exerciseLevel.' ';
-			else
-				$where = ' WHERE level='.$exerciseLevel.' ';
+			$filter .= ' AND level='.$exerciseLevel.' ';
 		}
 
 		if (isset($answerType) && $answerType != -1) {
-			if (strlen($where)>0)
-				$where .= ' AND type='.$answerType.' ';
-			else
-				$where = ' WHERE type='.$answerType.' ';
+			$filter .= ' AND qu.type='.$answerType.' ';
 		}
 
-		$sql="SELECT id,question,type,level FROM $TBL_QUESTIONS $where ";
-
+		$sql="SELECT qu.id, question, qu.type, level, q.session_id FROM $TBL_QUESTIONS as qu, $TBL_EXERCICE_QUESTION as qt, $TBL_EXERCICES as q WHERE q.id=qt.exercice_id AND qu.id=qt.question_id AND qt.exercice_id<>".$fromExercise." $filter ORDER BY session_id ASC";
 		// forces the value to 0
 		//echo $sql;
 		$exerciseId=0;
@@ -437,6 +430,7 @@ if($is_allowedToEdit)
 	echo '<pre>';
 
 	echo '</pre>';
+	$session_id  = api_get_session_id();
 	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
@@ -464,10 +458,12 @@ if($is_allowedToEdit)
                 //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 align="center"><a href="',api_get_self(),'?',api_get_cidreq(),'&recup=',$row['id'],'&fromExercise=',$fromExercise,'">' .
-							'<img src="../img/view_more_stats.gif" border="0" title="'.get_lang('Reuse').'" alt="'.get_lang('Reuse').'"></a>';
+							'<td align="center"><a href="',api_get_self(),'?',api_get_cidreq(),'&recup=',$row['id'],'&fromExercise=',$fromExercise,'">';
+				if ($row['session_id'] == $session_id){
+					echo '<img src="../img/view_more_stats.gif" border="0" title="'.get_lang('Reuse').'" alt="'.get_lang('Reuse').'"></a>';
+				}
 							
-					echo ' <a href="',api_get_self(),'?',api_get_cidreq(),'&copy_question=',$row['id'],'&fromExercise=',$fromExercise,'">' .
+				echo ' <a href="',api_get_self(),'?',api_get_cidreq(),'&copy_question=',$row['id'],'&fromExercise=',$fromExercise,'">' .
 							'<img src="../img/cd.gif" border="0" title="'.get_lang('ReUseACopyInCurrentTest').'" alt="'.get_lang('ReUseACopyInCurrentTest').'"></a>';
 			}
             echo '</td>';