Merge pull request #3 from INOPIAE/bug-1140

bug 1140: added the status passed to the progress table
This commit is contained in:
Bernhard Fröhlich 2013-04-07 07:50:27 -07:00
commit 7711fd61e8
2 changed files with 224 additions and 184 deletions

View file

@ -1,6 +1,6 @@
<?php <?php
class Quiz class Quiz
{ {
var $topicID; var $topicID;
var $questionLimit; var $questionLimit;
@ -14,7 +14,8 @@ class Quiz
var $rawToPass; var $rawToPass;
var $question; var $question;
var $percentTest; var $percentTest;
var $testPassed;
function Quiz(){ function Quiz(){
$this->topicID=0; $this->topicID=0;
$this->questionLimit=0; $this->questionLimit=0;
@ -29,56 +30,56 @@ class Quiz
$this->question=new Question(); $this->question=new Question();
$this->percentTest=0; $this->percentTest=0;
} }
function getQuestionLimit() { function getQuestionLimit() {
return $this->questionLimit; return $this->questionLimit;
} }
function setQuestionLimit($numOfQu){ function setQuestionLimit($numOfQu){
$this->questionLimit= $numOfQu; $this->questionLimit= $numOfQu;
} }
function setTopicID($id) { function setTopicID($id) {
$this->topicID=$id; $this->topicID=$id;
} }
function getTopicID(){ function getTopicID(){
return $this->topicID; return $this->topicID;
} }
function getAnswerList () { function getAnswerList () {
return $this->answerList; return $this->answerList;
} }
function setRawToPass($percentage){ function setRawToPass($percentage){
$this->rawToPass=$percentage; $this->rawToPass=$percentage;
} }
function generateQuestions(){ // Fragen werden random aus DB gelesen function generateQuestions(){ // Fragen werden random aus DB gelesen
$sqlGetQu=" SELECT q_id,qt_id,t_id,question,description FROM questions WHERE t_id =".intval($this->topicID)." AND active=".intval(1)." ORDER BY RAND()LIMIT ".intval($this->questionLimit).""; $sqlGetQu=" SELECT q_id,qt_id,t_id,question,description FROM questions WHERE t_id =".intval($this->topicID)." AND active=".intval(1)." ORDER BY RAND()LIMIT ".intval($this->questionLimit)."";
$queryGetQu = mysql_query($sqlGetQu); $queryGetQu = mysql_query($sqlGetQu);
$number=mysql_num_rows($queryGetQu); $number=mysql_num_rows($queryGetQu);
if($number== $this->questionLimit){ if($number== $this->questionLimit){
$i=1; // zähler $i=1; // zähler
while($questions =mysql_fetch_array($queryGetQu ,MYSQL_BOTH )) while($questions =mysql_fetch_array($queryGetQu ,MYSQL_BOTH ))
{ {
$this->questionList[$i]['q_id']=$questions['q_id']; // in arra speichern $this->questionList[$i]['q_id']=$questions['q_id']; // in arra speichern
$this->questionList[$i]['qt_id']=$questions['qt_id']; $this->questionList[$i]['qt_id']=$questions['qt_id'];
$this->questionList[$i]['t_id']=$questions['t_id']; $this->questionList[$i]['t_id']=$questions['t_id'];
$this->questionList[$i]['question']=stripslashes($questions['question']); $this->questionList[$i]['question']=stripslashes($questions['question']);
$this->questionList[$i]['description']=$questions['description']; $this->questionList[$i]['description']=$questions['description'];
$sqlGetNumber="SELECT count(a_id)as number FROM answers WHERE q_id=".intval($questions['q_id'])." GROUP BY q_id"; $sqlGetNumber="SELECT count(a_id)as number FROM answers WHERE q_id=".intval($questions['q_id'])." GROUP BY q_id";
$queryGetNumber = mysql_query($sqlGetNumber); $queryGetNumber = mysql_query($sqlGetNumber);
while($number =mysql_fetch_array( $queryGetNumber ,MYSQL_BOTH )) while($number =mysql_fetch_array( $queryGetNumber ,MYSQL_BOTH ))
{ {
$this->questionList[$i]['numberOfAnswers']=$number['number']; $this->questionList[$i]['numberOfAnswers']=$number['number'];
} }
if($this->questionList[$i]['description']==1) { if($this->questionList[$i]['description']==1) {
// beschreibung in Session speichern falls vorhanden // beschreibung in Session speichern falls vorhanden
$sql_desc="SELECT description FROM question_description WHERE q_id=".intval($questions['q_id']).""; $sql_desc="SELECT description FROM question_description WHERE q_id=".intval($questions['q_id'])."";
$query_desc=mysql_query($sql_desc); $query_desc=mysql_query($sql_desc);
$desc = mysql_fetch_assoc($query_desc); $desc = mysql_fetch_assoc($query_desc);
$this->questionList[$i]['description_text']=stripslashes($desc['description']); $this->questionList[$i]['description_text']=stripslashes($desc['description']);
} }
@ -87,31 +88,31 @@ class Quiz
$_SESSION['values']['questionList']=$this->questionList; $_SESSION['values']['questionList']=$this->questionList;
} }
else{ else{
echo "<h5>".Class_Quiz_01." </h5>"; echo "<h5>".Class_Quiz_01." </h5>";
$value ="notEnoughQuestions"; $value ="notEnoughQuestions";
return $value; return $value;
} }
} }
function getQuestionList() { function getQuestionList() {
return $this->questionList; return $this->questionList;
} }
function setQuestions() { function setQuestions() {
$this->questionList=$_SESSION['values']['questionList']; $this->questionList=$_SESSION['values']['questionList'];
} }
function getDBAnswers() { // Antworten zu den Frage aus DB holen function getDBAnswers() { // Antworten zu den Frage aus DB holen
for($i=1;$i<=$this->questionLimit;$i++){ for($i=1;$i<=$this->questionLimit;$i++){
$value= $this->questionList[$i]['q_id']; $value= $this->questionList[$i]['q_id'];
$sqlGetAns="SELECT a_id,answer,correct FROM answers WHERE q_id=".intval($value)." ORDER BY RAND()"; $sqlGetAns="SELECT a_id,answer,correct FROM answers WHERE q_id=".intval($value)." ORDER BY RAND()";
$queryGetAns = mysql_query($sqlGetAns); $queryGetAns = mysql_query($sqlGetAns);
$j=1; // Zähler $j=1; // Zähler
while($answers =mysql_fetch_array($queryGetAns ,MYSQL_BOTH )) { while($answers =mysql_fetch_array($queryGetAns ,MYSQL_BOTH )) {
$this->answerList[$value][$j]['q_id']= $value; $this->answerList[$value][$j]['q_id']= $value;
$this->answerList[$value][$j]['a_id']=$answers['a_id']; // in arra speichern $this->answerList[$value][$j]['a_id']=$answers['a_id']; // in arra speichern
$this->answerList[$value][$j]['answer']=stripslashes($answers['answer']); $this->answerList[$value][$j]['answer']=stripslashes($answers['answer']);
@ -121,17 +122,17 @@ class Quiz
} }
$_SESSION ['values'] ['answerList']= $this->answerList; $_SESSION ['values'] ['answerList']= $this->answerList;
} }
function setAnswers(){ function setAnswers(){
$this->answerList=$_SESSION ['values']['answerList']; $this->answerList=$_SESSION ['values']['answerList'];
} }
function setSelectedAnswers (){ function setSelectedAnswers (){
$this->selectedAnswers=$_SESSION ['values']['selectedAnswers']; $this->selectedAnswers=$_SESSION ['values']['selectedAnswers'];
} }
function showQuiz() { function showQuiz() {
echo "<form action='index.php?site=start_test&amp;action=evaluate' method='post'>"; echo "<form action='index.php?site=start_test&amp;action=evaluate' method='post'>";
echo "<fieldset>"; echo "<fieldset>";
echo " <legend>".Class_Quiz_02."</legend>"; echo " <legend>".Class_Quiz_02."</legend>";
echo "<table class='table_show_quiz'>"; echo "<table class='table_show_quiz'>";
@ -140,12 +141,12 @@ class Quiz
$question=str_replace("\n", "<br>", $this->questionList[$i]['question']); $question=str_replace("\n", "<br>", $this->questionList[$i]['question']);
echo "<tr>"; echo "<tr>";
echo"<td class='nr' valign='top' >".Global_08." $i: </td>"; echo"<td class='nr' valign='top' >".Global_08." $i: </td>";
if($this->questionList[$i]['qt_id']!=4) { if($this->questionList[$i]['qt_id']!=4) {
echo"<td class='question' colspan='3'>$question </td> "; echo"<td class='question' colspan='3'>$question </td> ";
echo"</tr>"; echo"</tr>";
} // wenn der Typ nicht 4 ist anzeigen } // wenn der Typ nicht 4 ist anzeigen
if($this->questionList[$i]['qt_id']==1) $this->SingleSelection($i,$value); if($this->questionList[$i]['qt_id']==1) $this->SingleSelection($i,$value);
if($this->questionList[$i]['qt_id']==2) $this->MultipleChoice($i,$value); if($this->questionList[$i]['qt_id']==2) $this->MultipleChoice($i,$value);
if($this->questionList[$i]['qt_id']==3) $this->SingleSelection($i,$value); // Kann die selbe Maske verwendet werden if($this->questionList[$i]['qt_id']==3) $this->SingleSelection($i,$value); // Kann die selbe Maske verwendet werden
@ -163,8 +164,8 @@ class Quiz
echo "</fieldset>"; echo "</fieldset>";
echo"</form>"; echo"</form>";
} }
function SingleSelection($i,$value){ function SingleSelection($i,$value){
for ($j=1;$j<=$this->questionList[$i]['numberOfAnswers'];$j++){ // Solange Schleife durchlaufen wie die maximale Anzahl der Antworten ist for ($j=1;$j<=$this->questionList[$i]['numberOfAnswers'];$j++){ // Solange Schleife durchlaufen wie die maximale Anzahl der Antworten ist
$answer=$this->answerList[$value][$j]['answer']; $answer=$this->answerList[$value][$j]['answer'];
$answerNumber=$this->answerList[$value][$j]['a_id']; $answerNumber=$this->answerList[$value][$j]['a_id'];
@ -175,13 +176,13 @@ class Quiz
if ($answer=='true') echo" <td class='answer' valign='top'>".Class_Answer_09."</td>"; if ($answer=='true') echo" <td class='answer' valign='top'>".Class_Answer_09."</td>";
else if ($answer=='false') echo" <td class='answer' valign='top'>".Class_Answer_10."</td>"; else if ($answer=='false') echo" <td class='answer' valign='top'>".Class_Answer_10."</td>";
else echo" <td class='answer' valign='top'>$answer</td>"; else echo" <td class='answer' valign='top'>$answer</td>";
echo "<td class='symbol'></td>"; echo "<td class='symbol'></td>";
echo "</tr>"; echo "</tr>";
} }
} }
echo "<tr class='padding'><td colspan='4' /></tr>"; echo "<tr class='padding'><td colspan='4' /></tr>";
} }
function MultipleChoice($i,$value){ function MultipleChoice($i,$value){
for ($j=1;$j<=$this->questionList[$i]['numberOfAnswers'];$j++){ // Solange Schleife durchlaufen wie die maximale Anzahl der Antworten ist for ($j=1;$j<=$this->questionList[$i]['numberOfAnswers'];$j++){ // Solange Schleife durchlaufen wie die maximale Anzahl der Antworten ist
$answer=$this->answerList[$value][$j]['answer']; $answer=$this->answerList[$value][$j]['answer'];
@ -191,16 +192,16 @@ class Quiz
echo "<td class='nr' valign='top' ></td>"; echo "<td class='nr' valign='top' ></td>";
echo "<td class='choice' valign='top'><input type='checkbox' class='quiz_options' value='$answerNumber' name='selectedAnswers[$value][]' /></td>"; echo "<td class='choice' valign='top'><input type='checkbox' class='quiz_options' value='$answerNumber' name='selectedAnswers[$value][]' /></td>";
echo " <td class='answer' valign='top'> $answer </td>"; echo " <td class='answer' valign='top'> $answer </td>";
echo "<td class='symbol'></td>"; echo "<td class='symbol'></td>";
echo "</tr>"; echo "</tr>";
} }
} }
echo "<tr class='padding'><td colspan='4' /></tr>"; echo "<tr class='padding'><td colspan='4' /></tr>";
} }
function randomizeArray($answerList,$value) { function randomizeArray($answerList,$value) {
$max=count($answerList[$value]); // setze Maximum $max=count($answerList[$value]); // setze Maximum
$index=range(1,$max); // Kreiire Array $index=range(1,$max); // Kreiire Array
shuffle($index); // würfle array shuffle($index); // würfle array
$copy= $answerList; // kopie erstellen $copy= $answerList; // kopie erstellen
for($i=0;$i<$max;$i++){ for($i=0;$i<$max;$i++){
@ -208,11 +209,11 @@ class Quiz
$answerList[$value][$i+1]=$copy[$value][$k]; // zuweisen $answerList[$value][$i+1]=$copy[$value][$k]; // zuweisen
} }
$_SESSION ['values'] ['answerList']= $answerList; $_SESSION ['values'] ['answerList']= $answerList;
return $answerList; return $answerList;
} }
function FillInTheBlanks($i,$value,$question) { function FillInTheBlanks($i,$value,$question) {
echo '<td class="answer" valign="top" colspan="2">'; echo '<td class="answer" valign="top" colspan="2">';
$correctAns=$this->question->getCorrectAnswerFillInTheBlanks($question); // korrekte Antworen ermitteln $correctAns=$this->question->getCorrectAnswerFillInTheBlanks($question); // korrekte Antworen ermitteln
$numberOfAnswers=$this->questionList[$i]['numberOfAnswers']; $numberOfAnswers=$this->questionList[$i]['numberOfAnswers'];
@ -220,11 +221,11 @@ class Quiz
$addCorrect = array( 'q_id' => $value, 'a_id' => $correctAns[$l+1]['answer'],'answer' =>$correctAns[$l+1]['answer'],'correct'=>1,'blank'=>$correctAns[$l+1]['blank']); $addCorrect = array( 'q_id' => $value, 'a_id' => $correctAns[$l+1]['answer'],'answer' =>$correctAns[$l+1]['answer'],'correct'=>1,'blank'=>$correctAns[$l+1]['blank']);
$numberOfAnswers=$numberOfAnswers+1; // Anzahl der Antworten erhöhen $numberOfAnswers=$numberOfAnswers+1; // Anzahl der Antworten erhöhen
$this->answerList[$value][$numberOfAnswers]= $addCorrect ; // an richtiger Stelle einfügen $this->answerList[$value][$numberOfAnswers]= $addCorrect ; // an richtiger Stelle einfügen
} }
$this->answerList=$this->randomizeArray($this->answerList,$value); $this->answerList=$this->randomizeArray($this->answerList,$value);
$addSlashes= preg_quote($question, '[^]'); // Slash hinzufügen wenn KLammer gefunden wird $addSlashes= preg_quote($question, '[^]'); // Slash hinzufügen wenn KLammer gefunden wird
$array=explode('\\',$addSlashes); // String teilen $array=explode('\\',$addSlashes); // String teilen
for($k=0;$k<count($array);$k++){ for($k=0;$k<count($array);$k++){
if((strstr($array[$k],'['))){ if((strstr($array[$k],'['))){
echo"<select name='selectedAnswers[$value][$k]' > "; echo"<select name='selectedAnswers[$value][$k]' > ";
@ -236,7 +237,7 @@ class Quiz
} }
echo"</select>"; echo"</select>";
} }
else if((strstr($array[$k],']'))){ else if((strstr($array[$k],']'))){
$array[$k]=str_replace("]",'', $array[$k]); // Klammer entfernen $array[$k]=str_replace("]",'', $array[$k]); // Klammer entfernen
echo $array[$k]; echo $array[$k];
@ -244,18 +245,18 @@ class Quiz
else echo $array[$k]; else echo $array[$k];
} }
echo "</td>"; echo "</td>";
echo "<td class='symbol'></td>"; echo "<td class='symbol'></td>";
echo "</tr>"; echo "</tr>";
echo "<tr class='padding'><td colspan='4' /></tr>"; echo "<tr class='padding'><td colspan='4' /></tr>";
} }
function evaluateQuiz() { function evaluateQuiz() {
echo"<div>"; echo"<div>";
echo "<fieldset>"; echo "<fieldset>";
echo "<legend>".Class_Quiz_03."</legend>\n"; echo "<legend>".Class_Quiz_03."</legend>\n";
echo "<table class='table_show_quiz'>"; echo "<table class='table_show_quiz'>";
for($i=1;$i<=count($this->questionList);$i++){ for($i=1;$i<=count($this->questionList);$i++){
@ -265,37 +266,37 @@ class Quiz
echo"<td class='nr' valign='top' >".Global_08." $i : </td>"; echo"<td class='nr' valign='top' >".Global_08." $i : </td>";
echo"<td class='question' colspan='3' >"; echo"<td class='question' colspan='3' >";
if($this->questionList[$i]['qt_id']!=4){ if($this->questionList[$i]['qt_id']!=4){
echo" $question </td> "; echo" $question </td> ";
echo "</tr>"; echo "</tr>";
} }
$this->topicID=$this->questionList[$i]['t_id']; $this->topicID=$this->questionList[$i]['t_id'];
switch($this->questionList[$i]['qt_id']){ switch($this->questionList[$i]['qt_id']){
case 1: {$this->evaluateSingleSelection($i,$value); case 1: {$this->evaluateSingleSelection($i,$value);
break;} break;}
case 2: {$this->evaluateMultipleChoice($i,$value); case 2: {$this->evaluateMultipleChoice($i,$value);
break;} break;}
case 3: { $this->evaluateSingleSelection($i,$value); // Kann die selbe Maske verwendet werden case 3: { $this->evaluateSingleSelection($i,$value); // Kann die selbe Maske verwendet werden
break;} break;}
case 4:{ //$this->getDBAnswers(); case 4:{ //$this->getDBAnswers();
$this->evaluateFillInTheBlanks($i,$value,$question); $this->evaluateFillInTheBlanks($i,$value,$question);
break;} break;}
} }
} }
echo "</table>"; echo "</table>";
echo "</fieldset>"; echo "</fieldset>";
echo "</div>"; echo "</div>";
$this->updateStatistic(); $this->updateStatistic();
$this->getTestResult(); $this->getTestResult();
$this->createLearnProgress(); $this->createLearnProgress();
} }
function evaluateSingleSelection($i,$value){ function evaluateSingleSelection($i,$value){
for ($j=1;$j<=$this->questionList[$i]['numberOfAnswers'];$j++) { // Solange Schleife durchlaufen wie die maximale Anzahl der Antworten ist for ($j=1;$j<=$this->questionList[$i]['numberOfAnswers'];$j++) { // Solange Schleife durchlaufen wie die maximale Anzahl der Antworten ist
$answer=$this->answerList[$value][$j]['answer']; $answer=$this->answerList[$value][$j]['answer'];
@ -324,30 +325,30 @@ class Quiz
if ($answer=='true') echo" <td class='$show_class' valign='top'>".Class_Answer_09."</td>"; if ($answer=='true') echo" <td class='$show_class' valign='top'>".Class_Answer_09."</td>";
else if ($answer=='false') echo" <td class='$show_class' valign='top'>".Class_Answer_10."</td>"; else if ($answer=='false') echo" <td class='$show_class' valign='top'>".Class_Answer_10."</td>";
else echo"<td class='$show_class' valign='top'>$answer</td>"; else echo"<td class='$show_class' valign='top'>$answer</td>";
echo "<td class ='evaluate'></td>"; echo "<td class ='evaluate'></td>";
echo"</tr>"; echo"</tr>";
} }
if(isset($this->selectedAnswers[$value]) && isset($this->answerList[$value][$j]['correct']) && if(isset($this->selectedAnswers[$value]) && isset($this->answerList[$value][$j]['correct']) &&
$this->selectedAnswers[$value]==$this->answerList[$value][$j]['a_id'] && $this->answerList[$value][$j]['correct']==1) { $this->selectedAnswers[$value]==$this->answerList[$value][$j]['a_id'] && $this->answerList[$value][$j]['correct']==1) {
$correct[]=1; $correct[]=1;
} }
} }
$this->showDescription($i); $this->showDescription($i);
if(!isset($correct)) $correct[]=0; if(!isset($correct)) $correct[]=0;
$this->checkAnswers($correct,$value); $this->checkAnswers($correct,$value);
} }
function evaluateMultipleChoice($i,$value) { function evaluateMultipleChoice($i,$value) {
for ($j=1;$j<=$this->questionList[$i]['numberOfAnswers'];$j++){ // Solange Schleife durchlaufen wie die maximale Anzahl der Antworten ist for ($j=1;$j<=$this->questionList[$i]['numberOfAnswers'];$j++){ // Solange Schleife durchlaufen wie die maximale Anzahl der Antworten ist
for($k=0;$k<$this->questionList[$i]['numberOfAnswers'];$k++){ // markieren welche Antworten der Benutzer ausgewählt hat for($k=0;$k<$this->questionList[$i]['numberOfAnswers'];$k++){ // markieren welche Antworten der Benutzer ausgewählt hat
if(isset($this->selectedAnswers [$value][$k]) && $this->selectedAnswers [$value][$k]!=null){ // wenn die Antwort nicht null ist if(isset($this->selectedAnswers [$value][$k]) && $this->selectedAnswers [$value][$k]!=null){ // wenn die Antwort nicht null ist
if($this->selectedAnswers [$value][$k]==$this->answerList[$value][$j]['a_id'])$checked [$j]=1; if($this->selectedAnswers [$value][$k]==$this->answerList[$value][$j]['a_id'])$checked [$j]=1;
else if(!isset($checked[$j]) || !$checked [$j]) $checked [$j]=0; else if(!isset($checked[$j]) || !$checked [$j]) $checked [$j]=0;
} }
} }
} }
for ($j=1;$j<=$this->questionList[$i]['numberOfAnswers'];$j++){ // antworten die der Benutzer ausewählt hat ausgeben for ($j=1;$j<=$this->questionList[$i]['numberOfAnswers'];$j++){ // antworten die der Benutzer ausewählt hat ausgeben
echo "\n<tr>"; echo "\n<tr>";
@ -357,7 +358,7 @@ class Quiz
$answerNumber=$this->answerList[$value][$j]['a_id']; $answerNumber=$this->answerList[$value][$j]['a_id'];
if (!isset($checked[$j])) $checked[$j] = 0; if (!isset($checked[$j])) $checked[$j] = 0;
if($checked[$j]==1) echo"<input type='checkbox' class='quiz_options' disabled='disabled' value='$answerNumber' checked='checked' name='userChoice[$value]' />"; if($checked[$j]==1) echo"<input type='checkbox' class='quiz_options' disabled='disabled' value='$answerNumber' checked='checked' name='userChoice[$value]' />";
else if ($checked[$j]==0) echo"<input type='checkbox' class='quiz_options' disabled='disabled' value='$answerNumber' name='userChoice[$value]' />"; else if ($checked[$j]==0) echo"<input type='checkbox' class='quiz_options' disabled='disabled' value='$answerNumber' name='userChoice[$value]' />";
echo "</td>"; echo "</td>";
//richtige Antworten ausgeben //richtige Antworten ausgeben
echo "<td class='choice' valign='top'>"; echo "<td class='choice' valign='top'>";
@ -369,26 +370,26 @@ class Quiz
$show_class = "answer false"; $show_class = "answer false";
} }
echo "</td>"; echo "</td>";
echo"<td class='$show_class' valign='top'> $answer </td>"; echo"<td class='$show_class' valign='top'> $answer </td>";
echo "<td class ='evaluate'></td>"; echo "<td class ='evaluate'></td>";
echo"</tr>"; echo"</tr>";
if(($this->answerList[$value][$j]['correct']==1) && ($checked [$j]==1)){ //Prüfung auf Richtigkeit if(($this->answerList[$value][$j]['correct']==1) && ($checked [$j]==1)){ //Prüfung auf Richtigkeit
$correct[$j]=1; $correct[$j]=1;
unset($this->answerList[$value][$j]); unset($this->answerList[$value][$j]);
} else if(($this->answerList[$value][$j]['correct']==1)&& ($checked [$j]==0))$correct[$j]=0; } else if(($this->answerList[$value][$j]['correct']==1)&& ($checked [$j]==0))$correct[$j]=0;
else if(($this->answerList[$value][$j]['correct']==0) && ($checked [$j]==1))$correct[$j]=0; else if(($this->answerList[$value][$j]['correct']==0) && ($checked [$j]==1))$correct[$j]=0;
} }
$this->showDescription($i); $this->showDescription($i);
$this->checkAnswers($correct,$value); $this->checkAnswers($correct,$value);
} }
function evaluateFillInTheBlanks($i,$value,$question){ function evaluateFillInTheBlanks($i,$value,$question){
$addSlashes= preg_quote($question, '[^]'); // Slash hinzufügen wenn KLammer gefunden wird $addSlashes= preg_quote($question, '[^]'); // Slash hinzufügen wenn KLammer gefunden wird
$array=explode('\\',$addSlashes); // String teilen $array=explode('\\',$addSlashes); // String teilen
// Was Benutzer markiert hat // Was Benutzer markiert hat
for($k=0;$k<count($array);$k++){ for($k=0;$k<count($array);$k++){
if((strstr($array[$k],'['))){ if((strstr($array[$k],'['))){
$array[$k]=str_replace("[",'', $array[$k]); // Klammer entfernen $array[$k]=str_replace("[",'', $array[$k]); // Klammer entfernen
@ -399,7 +400,7 @@ class Quiz
if(isset($this->answerList[$value][$j]['blank']) && $this->answerList[$value][$j]['blank']==$k) $correct[]=1; if(isset($this->answerList[$value][$j]['blank']) && $this->answerList[$value][$j]['blank']==$k) $correct[]=1;
else $correct[]=0; else $correct[]=0;
break; break;
} }
} }
} else if((strstr($array[$k],']'))){ } else if((strstr($array[$k],']'))){
$array[$k]=str_replace("]",'', $array[$k]); // Klammer entfernen $array[$k]=str_replace("]",'', $array[$k]); // Klammer entfernen
@ -408,16 +409,16 @@ class Quiz
} }
echo "</td>"; echo "</td>";
echo "</tr>"; echo "</tr>";
echo "\n<tr>"; echo "\n<tr>";
echo "<td class='nr' valign='top' ></td>"; echo "<td class='nr' valign='top' ></td>";
echo "<td class='question' colspan='3'>"; echo "<td class='question' colspan='3'>";
// Was richtig ist // Was richtig ist
$addSlashes= preg_quote($question, '[^]'); // Slash hinzufügen wenn KLammer gefunden wird $addSlashes= preg_quote($question, '[^]'); // Slash hinzufügen wenn KLammer gefunden wird
$array=explode('\\',$addSlashes); // String teilen $array=explode('\\',$addSlashes); // String teilen
//echo" <div id=\"quiz_fill_in_the_blank\" >"; //echo" <div id=\"quiz_fill_in_the_blank\" >";
for($k=0;$k<count($array);$k++){ for($k=0;$k<count($array);$k++){
if((strstr($array[$k],'['))){ if((strstr($array[$k],'['))){
$array[$k]=str_replace("[",'', $array[$k]); // Klammer entfernen $array[$k]=str_replace("[",'', $array[$k]); // Klammer entfernen
@ -429,11 +430,11 @@ class Quiz
} }
echo "</td>"; echo "</td>";
echo "</tr>"; echo "</tr>";
$this->showDescription($i); $this->showDescription($i);
$this->checkAnswers($correct,$value); $this->checkAnswers($correct,$value);
} }
function checkAnswers($correct,$value) { function checkAnswers($correct,$value) {
$check = in_array(0, $correct); // Prüfen ob im Array der Wert 0 ist, denn dann wurde mindestens eine Antwort falsch beantwortet $check = in_array(0, $correct); // Prüfen ob im Array der Wert 0 ist, denn dann wurde mindestens eine Antwort falsch beantwortet
echo "\n<tr>"; echo "\n<tr>";
@ -444,50 +445,61 @@ function checkAnswers($correct,$value) {
} }
echo "</tr>"; echo "</tr>";
} }
function updateStatistic() { function updateStatistic() {
for($i=1;$i<=$this->questionLimit;$i++) { for($i=1;$i<=$this->questionLimit;$i++) {
$sql="SELECT count FROM statistics WHERE q_id=".intval($this->questionList[$i]['q_id']).""; $sql="SELECT count FROM statistics WHERE q_id=".intval($this->questionList[$i]['q_id'])."";
$query = mysql_query($sql); $query = mysql_query($sql);
while($count=mysql_fetch_array($query ,MYSQL_BOTH )){ while($count=mysql_fetch_array($query ,MYSQL_BOTH )){
$count=$count['count']; $count=$count['count'];
$count=$count+1; $count=$count+1;
$sql_update="UPDATE statistics SET count=".intval($count)." WHERE q_id=".intval($this->questionList[$i]['q_id']).""; $sql_update="UPDATE statistics SET count=".intval($count)." WHERE q_id=".intval($this->questionList[$i]['q_id'])."";
$query_update = mysql_query($sql_update); $query_update = mysql_query($sql_update);
} }
} }
} }
function createLearnProgress() { // Lernprogress erstellen function createLearnProgress() { // Lernprogress erstellen
$timestamp = time(); $timestamp = time();
$date= date("Y-m-d H:i:s" ,$timestamp); // aktuelles Datum und Uhrzeit berechnen $date= date("Y-m-d H:i:s" ,$timestamp); // aktuelles Datum und Uhrzeit berechnen
$correctAnswers=$this->questionLimit-count($this->wrongQuestions); $correctAnswers=$this->questionLimit-count($this->wrongQuestions);
$wrongAnswers=count($this->wrongQuestions); $wrongAnswers=count($this->wrongQuestions);
$sql="INSERT INTO learnprogress (user_id,root,date,t_id,number,correct,wrong,percentage) VALUES ('".mysql_real_escape_string($_SESSION['profile']['id'])."','".mysql_real_escape_string($_SESSION['profile']['root'])."','$date',".intval($this->topicID).",".intval($this->questionLimit).",".intval($correctAnswers).",".intval($wrongAnswers).",".mysql_real_escape_string($this->percentTest).")"; $passed=$this->testPassed;
$query = mysql_query($sql); $sql="INSERT INTO learnprogress (user_id,root,date,t_id,number,correct,wrong,percentage,passed)
VALUES ('".mysql_real_escape_string($_SESSION['profile']['id'])."',
'".mysql_real_escape_string($_SESSION['profile']['root'])."',
'$date',
".intval($this->topicID).",
".intval($this->questionLimit).",
".intval($correctAnswers).",
".intval($wrongAnswers).",
".mysql_real_escape_string($this->percentTest).",
".intval($passed).")";
$query = mysql_query($sql);
$this->lp_id = mysql_insert_id(); $this->lp_id = mysql_insert_id();
$this->insertAnswersIncorrect(); $this->insertAnswersIncorrect();
} }
function insertAnswersIncorrect(){ function insertAnswersIncorrect(){
foreach($this->wrongQuestions as $value){ foreach($this->wrongQuestions as $value){
$sql="INSERT INTO answers_incorrect (lp_id,q_id) VALUES ( ".intval($this->lp_id).",".intval($value).")"; $sql="INSERT INTO answers_incorrect (lp_id,q_id) VALUES ( ".intval($this->lp_id).",".intval($value).")";
$query = mysql_query($sql); $query = mysql_query($sql);
} }
} }
function getTestResult(){ function getTestResult(){
$wrong=count($this->wrongQuestions); $wrong=count($this->wrongQuestions);
$correct=$this->questionLimit-$wrong; $correct=$this->questionLimit-$wrong;
if($wrong==0)$percentTest=100; if($wrong==0)$percentTest=100;
else if(($wrong>=$this->questionLimit) || ($this->questionLimit < 1))$percentTest=0; else if(($wrong>=$this->questionLimit) || ($this->questionLimit < 1))$percentTest=0;
else $percentTest=($correct/$this->questionLimit)*100; else $percentTest=($correct/$this->questionLimit)*100;
$percentTest=round($percentTest, 2); $percentTest=round($percentTest, 2);
$this->percentTest=$percentTest; $this->percentTest=$percentTest;
$this->testPassed=0;
if($this->rawToPass > 0 && $this->rawToPass <= $percentTest)$value="".Class_Quiz_08.""; if($this->rawToPass > 0 && $this->rawToPass <= $percentTest)$value="".Class_Quiz_08."";
else $value="".Class_Quiz_09.""; else $value="".Class_Quiz_09."";
echo'<p class="centered"> '.Global_05." : <br />"; echo'<p class="centered"> '.Global_05." : <br />";
global $questionlimit; global $questionlimit;
$questionlimit =$this->questionLimit; $questionlimit =$this->questionLimit;
@ -495,21 +507,22 @@ function checkAnswers($correct,$value) {
echo" ".Class_Quiz_05." <b>$this->rawToPass %</b> "; echo" ".Class_Quiz_05." <b>$this->rawToPass %</b> ";
echo "<br /> ".Class_Quiz_06." <b>".$this->percentTest." % </b> ".Class_Quiz_07." <b>$value</b> <br /></p>"; echo "<br /> ".Class_Quiz_06." <b>".$this->percentTest." % </b> ".Class_Quiz_07." <b>$value</b> <br /></p>";
//createLearnProgress(); //createLearnProgress();
if($this->rawToPass > 0 && $this->rawToPass <= $percentTest) { if($this->rawToPass > 0 && $this->rawToPass <= $percentTest) {
$this->testPassed=1;
// Test has been passed, maybe a paper/PDF-certificate can be requested // Test has been passed, maybe a paper/PDF-certificate can be requested
if ($_SERVER['SSL_CLIENT_S_DN_CN']=="CAcert WoT User") { if ($_SERVER['SSL_CLIENT_S_DN_CN']=="CAcert WoT User") {
// Sorry, we cannot issue certificates for anonymous users // Sorry, we cannot issue certificates for anonymous users
echo '<br /><p class="centered">'.Class_Quiz_10_AnonymousCert."</p>"; echo '<br /><p class="centered">'.Class_Quiz_10_AnonymousCert."</p>";
} else { } else {
echo "<form class='info' action='index.php?site=start_test&amp;action=requestCert' method='post'>"; echo "<form class='info' action='index.php?site=start_test&amp;action=requestCert' method='post'>";
echo "<input type='hidden' name='t_id' value='$this->topicID' />"; echo "<input type='hidden' name='t_id' value='$this->topicID' />";
echo "<input name='submit' class='Button_middle' type='submit' value='".Class_Quiz_11_RequestCert."' />"; echo "<input name='submit' class='Button_middle' type='submit' value='".Class_Quiz_11_RequestCert."' />";
echo "</form>"; echo "</form>";
} }
} }
} }
function showDescription($i){ function showDescription($i){
if(isset($_SESSION['values']['questionList'][$i]['description_text'])){ if(isset($_SESSION['values']['questionList'][$i]['description_text'])){
// Ausgabe der Beschreibung // Ausgabe der Beschreibung

View file

@ -7,6 +7,8 @@ class Progress
var $incorrect_answers; var $incorrect_answers;
var $percentArray; var $percentArray;
var $maximum; var $maximum;
var $passed;
var $totalresult=array();
function Progress() { function Progress() {
$this->progress=array(); $this->progress=array();
@ -15,70 +17,83 @@ class Progress
$this->topic=0; $this->topic=0;
$this->lp_id=0; $this->lp_id=0;
$this->percentArray=array(); $this->percentArray=array();
$this->passed=0;
} }
function setTopic($t_id){ function setTopic($t_id){
$this->topic=$t_id; $this->topic=$t_id;
} }
function setLp_id($lp_id){ function setLp_id($lp_id){
$this->lp_id=$lp_id; $this->lp_id=$lp_id;
} }
function setData($value){ function setData($value){
$this->progress=$value; $this->progress=$value;
} }
function getProgress(){ function getProgress(){
$sql= "SELECT lp_id,date,number,correct,wrong FROM learnprogress WHERE user_id='".mysql_real_escape_string($_SESSION['profile']['id'])."' AND t_id='".mysql_real_escape_string($this->topic)."' AND root ='".mysql_real_escape_string($_SESSION['profile']['root'])."' order by date"; $sql= "SELECT lp_id,date,number,correct,wrong, passed FROM learnprogress WHERE user_id='".mysql_real_escape_string($_SESSION['profile']['id'])."' AND t_id='".mysql_real_escape_string($this->topic)."' AND root ='".mysql_real_escape_string($_SESSION['profile']['root'])."' order by date";
$query = mysql_query($sql) OR die(mysql_error()); $query = mysql_query($sql) OR die(mysql_error());
$i=1; $i=1;
while($progress =mysql_fetch_array($query,MYSQL_BOTH )){ while($progress =mysql_fetch_array($query,MYSQL_BOTH )){
$this->progress[$i]['lp_id']=$progress['lp_id']; $this->progress[$i]['lp_id']=$progress['lp_id'];
$this->progress[$i]['date']=$progress['date']; $this->progress[$i]['date']=$progress['date'];
$this->progress[$i]['number']=$progress['number']; // in arra speichern $this->progress[$i]['number']=$progress['number']; // in arra speichern
$this->progress[$i]['correct']=$progress['correct']; $this->progress[$i]['correct']=$progress['correct'];
$this->progress[$i]['wrong']=$progress['wrong']; $this->progress[$i]['wrong']=$progress['wrong'];
$this->progress[$i]['passed']=$progress['passed'];
$i++; $i++;
} }
} }
function count() { function count() {
$numberOfTests=count($this->progress); $numberOfTests=count($this->progress);
return $numberOfTests; return $numberOfTests;
} }
function showTable() { function showTable() {
$this->totalresult['count']=0;
$this->totalresult['passed']=0;
if(count($this->progress)==0) echo "<div class='h8'>".Global_07."</div>"; if(count($this->progress)==0) echo "<div class='h8'>".Global_07."</div>";
else { else {
echo"<br /> <br />"; echo"<br /> <br />";
echo"<table class='table table_progress'>"; echo"<table class='table table_progress'>";
echo "<tr>"; echo "<tr>";
echo"<td class='th th_pos'>".Global_10."</td>"; echo"<td class='th th_pos'>".Global_10."</td>";
echo"<td class='th th_pos_date'>".Global_04."</td>"; echo"<td class='th th_pos_date'>".Global_04."</td>";
echo"<td class='th th_count'>".Class_Progress_01."</td>"; echo"<td class='th th_count'>".Class_Progress_01."</td>";
echo"<td class='th th_count'>".Global_03."</td>"; echo"<td class='th th_count'>".Global_03."</td>";
echo"<td class='th th_count'>".Statistic_04."</td>";
echo "<td class='th th_buttons'></td>"; echo "<td class='th th_buttons'></td>";
echo"</tr>"; echo"</tr>";
for ($i=1;$i<=count($this->progress);$i++){ for ($i=1;$i<=count($this->progress);$i++){
if (1==$this->progress[$i]['passed']) {
$this->totalresult['passed']+=1;
}
echo "<tr>"; echo "<tr>";
echo"<td class='td'>$i</td>"; echo"<td class='td'>$i</td>";
echo"<td class='td'>".$this->progress[$i]['date']."</td>"; echo"<td class='td'>".$this->progress[$i]['date']."</td>";
echo"<td class='td'>".$this->progress[$i]['number']."</td>"; echo"<td class='td'>".$this->progress[$i]['number']."</td>";
if ($this->progress[$i]['number'] > 0) { echo"<td class='td'>".getPassedImage($this->progress[$i]['passed'])."</td>";
$percent=($this->progress[$i]['correct']/$this->progress[$i]['number'])*100; if ($this->progress[$i]['number'] > 0) {
} else { $percent=($this->progress[$i]['correct']/$this->progress[$i]['number'])*100;
$percent = 0; } else {
} $percent = 0;
$percent=round ($percent,2); }
echo"<td class='td'>$percent %</td>"; $percent=round ($percent,2);
echo"<td class='td'> <a href='?site=progress&amp;action=showIncorrectAnswers&amp;lp_id=".$this->progress[$i]['lp_id']."&amp;t_id=$this->topic'><img src='images/details.png' class='linkimage' alt='' /></a></td>"; echo"<td class='td'>$percent %</td>";
echo "</tr>"; echo"<td class='td'> <a href='?site=progress&amp;action=showIncorrectAnswers&amp;lp_id=".$this->progress[$i]['lp_id']."&amp;t_id=$this->topic'><img src='images/details.png' class='linkimage' alt='' /></a></td>";
} echo "</tr>";
echo"</table>";
} }
$this->totalresult['count']=$i;
echo "<tr>";
echo "<td class='td' colspan='6' align='center'>".Statistic_04.' '.$this->totalresult['passed'].'/'.$this->totalresult['count']."</td>";
echo "</tr>";
echo"</table>";
}
} }
function checkProgressData(){ function checkProgressData(){
if(count($this->progress)==0) echo "<div class='h8'>".Global_07."</div>"; if(count($this->progress)==0) echo "<div class='h8'>".Global_07."</div>";
else { else {
@ -90,31 +105,31 @@ class Progress
echo '<h5 class="centered">'.Class_Progress_02." ".Class_Progress_03." $this->maximum ".Class_Progress_04.".</h5>"; echo '<h5 class="centered">'.Class_Progress_02." ".Class_Progress_03." $this->maximum ".Class_Progress_04.".</h5>";
} else $k=1; } else $k=1;
$j=0; $j=0;
for ($i=$k;$i<=$limit;$i++){ for ($i=$k;$i<=$limit;$i++){
if ($this->progress[$i]['number'] > 0) { if ($this->progress[$i]['number'] > 0) {
$percent=($this->progress[$i]['correct']/$this->progress[$i]['number'])*100; $percent=($this->progress[$i]['correct']/$this->progress[$i]['number'])*100;
} else { } else {
$percent=0; $percent=0;
} }
$this->percentArray[$j][]=$this->progress[$i]['date']; $this->percentArray[$j][]=$this->progress[$i]['date'];
$this->percentArray[$j][]=$percent; $this->percentArray[$j][]=$percent;
$j++; $j++;
} }
} }
} }
function showBalken(){ function showBalken(){
$this->checkProgressData(); $this->checkProgressData();
$this->percentArray= serialize($this->percentArray); $this->percentArray= serialize($this->percentArray);
$this->percentArray=base64_encode ($this->percentArray); $this->percentArray=base64_encode ($this->percentArray);
$titley=Global_15; $titley=Global_15;
$titlex=Global_04; $titlex=Global_04;
echo " <div id=\"learnprogress\">\n"; echo " <div id=\"learnprogress\">\n";
echo "<img src='includes/graph_bib/bar.php?data=$this->percentArray&amp;learnpath=true&amp;titley=$titley&amp;titlex=$titlex' alt='' />"; echo "<img src='includes/graph_bib/bar.php?data=$this->percentArray&amp;learnpath=true&amp;titley=$titley&amp;titlex=$titlex' alt='' />";
echo "</div>\n"; echo "</div>\n";
} }
function showGraph(){ function showGraph(){
$this->checkProgressData(); $this->checkProgressData();
@ -122,57 +137,57 @@ class Progress
$this->percentArray=base64_encode ($this->percentArray); $this->percentArray=base64_encode ($this->percentArray);
$titley=Global_15; $titley=Global_15;
$titlex=Global_04; $titlex=Global_04;
echo " <div id=\"learnprogress\">\n"; echo " <div id=\"learnprogress\">\n";
echo "<img src='includes/graph_bib/curve.php?percentArray=$this->percentArray&amp;learnpath=true&amp;titley=$titley&amp;titlex=$titlex' alt='' />"; echo "<img src='includes/graph_bib/curve.php?percentArray=$this->percentArray&amp;learnpath=true&amp;titley=$titley&amp;titlex=$titlex' alt='' />";
echo "</div>\n"; echo "</div>\n";
} }
function showPie(){ function showPie(){
echo " <div id=\"learnprogress\">\n"; echo " <div id=\"learnprogress\">\n";
echo "<img src='includes/graph_bib/pie.php' alt='' />"; echo "<img src='includes/graph_bib/pie.php' alt='' />";
echo "</div>\n"; echo "</div>\n";
} }
function getIncorrectAnswers() function getIncorrectAnswers()
{ {
$sql="SELECT q_id FROM answers_incorrect WHERE lp_id=".intval($this->lp_id).""; $sql="SELECT q_id FROM answers_incorrect WHERE lp_id=".intval($this->lp_id)."";
$query = mysql_query($sql); $query = mysql_query($sql);
$i=1; $i=1;
while($incorrect_answers =mysql_fetch_array($query,MYSQL_BOTH )) while($incorrect_answers =mysql_fetch_array($query,MYSQL_BOTH ))
{ {
$this->incorrect_answers[$i]['q_id']=$incorrect_answers['q_id']; $this->incorrect_answers[$i]['q_id']=$incorrect_answers['q_id'];
$i++; $i++;
} }
$this->showIncorrectAnswers(); $this->showIncorrectAnswers();
} }
function showIncorrectAnswers(){ function showIncorrectAnswers(){
echo "<form action='?site=progress&amp;action=showTable&amp;t_id=$this->topic' method='post'>"; echo "<form action='?site=progress&amp;action=showTable&amp;t_id=$this->topic' method='post'>";
echo "<fieldset >"; echo "<fieldset >";
echo " <legend class='table_show_incorrect'>".Class_Progress_08." </legend> "; echo " <legend class='table_show_incorrect'>".Class_Progress_08." </legend> ";
echo "<table class='table_show_incorrect'>"; echo "<table class='table_show_incorrect'>";
for ($i=1;$i<=count($this->incorrect_answers);$i++){ for ($i=1;$i<=count($this->incorrect_answers);$i++){
echo"<tr>"; echo"<tr>";
echo "<td class='nr_incorrect' valign='top'> $i.) </td>"; echo "<td class='nr_incorrect' valign='top'> $i.) </td>";
$sql="SELECT question,qt_id FROM questions WHERE q_id=".intval($this->incorrect_answers[$i]['q_id']).""; $sql="SELECT question,qt_id FROM questions WHERE q_id=".intval($this->incorrect_answers[$i]['q_id'])."";
$query = mysql_query($sql); $query = mysql_query($sql);
while($question =mysql_fetch_array($query,MYSQL_BOTH )) { while($question =mysql_fetch_array($query,MYSQL_BOTH )) {
if( $question['qt_id']==4){ if( $question['qt_id']==4){
$questionText=$this->getFIBQuestion( $question['question']); $questionText=$this->getFIBQuestion( $question['question']);
echo"<td class='question_incorrect' valign='top'>".$questionText."</td>"; echo"<td class='question_incorrect' valign='top'>".$questionText."</td>";
} }
else{ else{
echo "<td class='question_incorrect' valign='top'>". $question['question']."</td>"; echo "<td class='question_incorrect' valign='top'>". $question['question']."</td>";
} }
} }
echo"</tr>"; echo"</tr>";
} }
if($this->progress [$this->lp_id]['wrong']>count($this->incorrect_answers)) { if($this->progress [$this->lp_id]['wrong']>count($this->incorrect_answers)) {
$number=$this->progress [$this->lp_id]['wrong']-count($this->incorrect_answers); $number=$this->progress [$this->lp_id]['wrong']-count($this->incorrect_answers);
echo"<tr>"; echo"<tr>";
@ -186,9 +201,9 @@ class Progress
echo"</tr>"; echo"</tr>";
echo"</table>"; echo"</table>";
echo "</fieldset>"; echo "</fieldset>";
echo "</form>"; echo "</form>";
} }
function getFIBQuestion($question){ function getFIBQuestion($question){
$addSlashes= preg_quote( $question, '[^]'); // Slash hinzufügen wenn KLammer gefunden wird $addSlashes= preg_quote( $question, '[^]'); // Slash hinzufügen wenn KLammer gefunden wird
$array=explode('\\',$addSlashes); // String teilen $array=explode('\\',$addSlashes); // String teilen
@ -201,12 +216,24 @@ class Progress
$answer=substr ($questionText,$beginPos,$length );// den String zwischen den Klammern suchen $answer=substr ($questionText,$beginPos,$length );// den String zwischen den Klammern suchen
$questionText=str_replace($answer,'(xxx)', $questionText); // gespeicherten Wert aus string löschen $questionText=str_replace($answer,'(xxx)', $questionText); // gespeicherten Wert aus string löschen
$answer=str_replace("]",'', $answer); // Klammer entfernen $answer=str_replace("]",'', $answer); // Klammer entfernen
$key = array_search($answer, $array); $key = array_search($answer, $array);
$answer=str_replace("[",'', $answer); // Klammer entfernen $answer=str_replace("[",'', $answer); // Klammer entfernen
} }
} }
return $questionText; return $questionText;
} }
}
function getPassedImage($passed){
// returns the image depending on the status of a test result
$img="<img src='images/details.png' alt='' />";
if (0==$passed) {
$img="<img src='images/wrong.png' alt='' />";
}
if (1==$passed) {
$img="<img src='images/correct.png' alt='' />";
}
return $img;
}
}
?> ?>