topicID=0; $this->questionLimit=0; $this->questionList= array(); $this->answerList= array(); $this->maxNumberOfAns=0; $this->selectedAnswers= array(); $this->correct=array(); $this->wrongQuestions=array(); $this->lp_id; $this->rawToPass; $this->question=new Question(); $this->percentTest=0; } function getQuestionLimit() { return $this->questionLimit; } function setQuestionLimit($numOfQu){ $this->questionLimit= $numOfQu; } function setTopicID($id) { $this->topicID=$id; } function getTopicID(){ return $this->topicID; } function getAnswerList () { return $this->answerList; } function setRawToPass($percentage){ $this->rawToPass=$percentage; } 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).""; $queryGetQu = mysql_query($sqlGetQu); $number=mysql_num_rows($queryGetQu); if($number== $this->questionLimit){ $i=1; // zähler while($questions =mysql_fetch_array($queryGetQu ,MYSQL_BOTH )) { $this->questionList[$i]['q_id']=$questions['q_id']; // in arra speichern $this->questionList[$i]['qt_id']=$questions['qt_id']; $this->questionList[$i]['t_id']=$questions['t_id']; $this->questionList[$i]['question']=stripslashes($questions['question']); $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"; $queryGetNumber = mysql_query($sqlGetNumber); while($number =mysql_fetch_array( $queryGetNumber ,MYSQL_BOTH )) { $this->questionList[$i]['numberOfAnswers']=$number['number']; } if($this->questionList[$i]['description']==1) { // beschreibung in Session speichern falls vorhanden $sql_desc="SELECT description FROM question_description WHERE q_id=".intval($questions['q_id']).""; $query_desc=mysql_query($sql_desc); $desc = mysql_fetch_assoc($query_desc); $this->questionList[$i]['description_text']=stripslashes($desc['description']); } $i++; } $_SESSION['values']['questionList']=$this->questionList; } else { echo "
".Class_Quiz_01."
"; $value ="notEnoughQuestions"; return $value; } } function getQuestionList() { return $this->questionList; } function setQuestions() { $this->questionList=$_SESSION['values']['questionList']; } function getDBAnswers() { // Antworten zu den Frage aus DB holen for($i=1;$i<=$this->questionLimit;$i++){ $value= $this->questionList[$i]['q_id']; $sqlGetAns="SELECT a_id,answer,correct FROM answers WHERE q_id=".intval($value)." ORDER BY RAND()"; $queryGetAns = mysql_query($sqlGetAns); $j=1; // Zähler while($answers =mysql_fetch_array($queryGetAns ,MYSQL_BOTH )) { $this->answerList[$value][$j]['q_id']= $value; $this->answerList[$value][$j]['a_id']=$answers['a_id']; // in arra speichern $this->answerList[$value][$j]['answer']=stripslashes($answers['answer']); $this->answerList[$value][$j]['correct']=$answers['correct']; $j++; } } $_SESSION ['values'] ['answerList']= $this->answerList; } function setAnswers(){ $this->answerList=$_SESSION ['values']['answerList']; } function setSelectedAnswers (){ $this->selectedAnswers=$_SESSION ['values']['selectedAnswers']; } function showQuiz() { echo "
"; echo "
"; echo " ".Class_Quiz_02.""; echo ""; for($i=1;$i<=$this->questionLimit;$i++) { $value= $this->questionList[$i]['q_id']; // Value den Wert der q_id geben $question=str_replace("\n", "
", $this->questionList[$i]['question']); echo ""; echo""; if($this->questionList[$i]['qt_id']!=4) { echo" "; echo""; } // wenn der Typ nicht 4 ist anzeigen 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']==3) $this->SingleSelection($i,$value); // Kann die selbe Maske verwendet werden if($this->questionList[$i]['qt_id']==4) $this->FillInTheBlanks($i,$value,$question); } echo ""; echo ""; echo ""; echo "
".Global_08." $i: $question
"; echo""; //echo""; //echo""; echo" "; echo "
"; echo "
"; echo"
"; } function SingleSelection($i,$value){ 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']; $answerNumber=$this->answerList[$value][$j]['a_id']; if($answer!=null) { // Wenn es eine Antwort gibt soll diese angezeigt werden echo ""; echo ""; echo""; if ($answer=='true') echo" ".Class_Answer_09.""; else if ($answer=='false') echo" ".Class_Answer_10.""; else echo" $answer"; echo ""; echo ""; } } echo ""; } function MultipleChoice($i,$value){ 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']; $answerNumber=$this->answerList[$value][$j]['a_id']; if($answer!=null){ // Wenn es eine Antwort gibt soll diese angezeigt werden echo ""; echo ""; echo ""; echo " $answer "; echo ""; echo ""; } } echo ""; } function randomizeArray($answerList,$value) { $max=count($answerList[$value]); // setze Maximum $index=range(1,$max); // Kreiire Array shuffle($index); // würfle array $copy= $answerList; // kopie erstellen for($i=0;$i<$max;$i++){ $k=$index[$i]; $answerList[$value][$i+1]=$copy[$value][$k]; // zuweisen } $_SESSION ['values'] ['answerList']= $answerList; return $answerList; } function FillInTheBlanks($i,$value,$question) { echo ''; $correctAns=$this->question->getCorrectAnswerFillInTheBlanks($question); // korrekte Antworen ermitteln $numberOfAnswers=$this->questionList[$i]['numberOfAnswers']; for ($l=0;$l $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 $this->answerList[$value][$numberOfAnswers]= $addCorrect ; // an richtiger Stelle einfügen } $this->answerList=$this->randomizeArray($this->answerList,$value); $addSlashes= preg_quote($question, '[^]'); // Slash hinzufügen wenn KLammer gefunden wird $array=explode('\\',$addSlashes); // String teilen for($k=0;$k "; for ($j=1;$j<=$numberOfAnswers;$j++){ // Solange Schleife durchlaufen wie die maximale Anzahl der Antworten ist $answer=$this->answerList[$value][$j]['answer']; $answerNumber=$this->answerList[$value][$j]['a_id']; //echo $this->answerList[$value][$j]['a_id']; echo""; } echo""; } else if((strstr($array[$k],']'))){ $array[$k]=str_replace("]",'', $array[$k]); // Klammer entfernen echo $array[$k]; } else echo $array[$k]; } echo ""; echo ""; echo ""; echo ""; } function evaluateQuiz() { echo"
"; echo "
"; echo "".Class_Quiz_03."\n"; echo ""; for($i=1;$i<=count($this->questionList);$i++){ $value= $this->questionList[$i]['q_id']; // Value den Wert der q_id geben $question=str_replace("\n", "
", $this->questionList[$i]['question']); echo "\n"; echo""; echo" "; echo ""; } $this->topicID=$this->questionList[$i]['t_id']; switch($this->questionList[$i]['qt_id']){ case 1: { $this->evaluateSingleSelection($i,$value); break; } case 2: { $this->evaluateMultipleChoice($i,$value); break; } case 3: { $this->evaluateSingleSelection($i,$value); // Kann die selbe Maske verwendet werden break; } case 4:{ //$this->getDBAnswers(); $this->evaluateFillInTheBlanks($i,$value,$question); break; } } } echo "
".Global_08." $i : "; if($this->questionList[$i]['qt_id']!=4){ echo" $question
"; echo "
"; echo "
"; $this->updateStatistic(); $this->getTestResult(); $this->createLearnProgress(); } function evaluateSingleSelection($i,$value){ 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']; $answerNumber=$this->answerList[$value][$j]['a_id']; if($answer!=null) { // Wenn es eine Antwort gibt soll diese angezeigt werden echo "\n"; echo ""; echo ""; // Auswahl des Benutzers if(isset($this->selectedAnswers[$value]) && $this->selectedAnswers[$value]==$this->answerList[$value][$j]['a_id']) { echo""; } else { echo""; } echo ""; //richtige Antworten echo ""; if($this->answerList[$value][$j]['correct']==1) { echo""; $show_class="answer correct"; } else { echo""; $show_class="answer false"; } echo ""; if ($answer=='true') echo" ".Class_Answer_09.""; else if ($answer=='false') echo" ".Class_Answer_10.""; else echo"$answer"; echo ""; echo""; } 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) { $correct[]=1; } } $this->showDescription($i); if(!isset($correct)) $correct[]=0; $this->checkAnswers($correct,$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($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($this->selectedAnswers [$value][$k]==$this->answerList[$value][$j]['a_id'])$checked [$j]=1; 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 echo "\n"; echo ""; echo ""; $answer=$this->answerList[$value][$j]['answer']; $answerNumber=$this->answerList[$value][$j]['a_id']; if (!isset($checked[$j])) $checked[$j] = 0; if($checked[$j]==1) echo""; else if ($checked[$j]==0) echo""; echo ""; //richtige Antworten ausgeben echo ""; if($this->answerList[$value][$j]['correct']==1) { echo""; $show_class = "answer correct"; } else { echo""; $show_class = "answer false"; } echo ""; echo" $answer "; echo ""; echo""; if(($this->answerList[$value][$j]['correct']==1) && ($checked [$j]==1)){ //Prüfung auf Richtigkeit $correct[$j]=1; 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']==0) && ($checked [$j]==1))$correct[$j]=0; } $this->showDescription($i); $this->checkAnswers($correct,$value); } function evaluateFillInTheBlanks($i,$value,$question){ $addSlashes= preg_quote($question, '[^]'); // Slash hinzufügen wenn KLammer gefunden wird $array=explode('\\',$addSlashes); // String teilen // Was Benutzer markiert hat for($k=0;$kanswerList[$value]);$j++){ // antworten die der Benutzer ausewählt hat ausgeben $answer=$this->answerList[$value][$j]['answer']; // Amtwort wird zugewiesen if($this->selectedAnswers[$value][$k]==$this->answerList[$value][$j]['a_id']){ echo " "; if(isset($this->answerList[$value][$j]['blank']) && $this->answerList[$value][$j]['blank']==$k) $correct[]=1; else $correct[]=0; break; } } } else if((strstr($array[$k],']'))){ $array[$k]=str_replace("]",'', $array[$k]); // Klammer entfernen echo $array[$k]; } else echo $array[$k]; } echo ""; echo ""; echo "\n"; echo ""; echo ""; // Was richtig ist $addSlashes= preg_quote($question, '[^]'); // Slash hinzufügen wenn KLammer gefunden wird $array=explode('\\',$addSlashes); // String teilen //echo"
"; for($k=0;$k"; } else if((strstr($array[$k],']'))) { $array[$k]=str_replace("]",'', $array[$k]); // Klammer entfernen echo $array[$k]; } else echo $array[$k]; } echo ""; echo ""; $this->showDescription($i); $this->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 echo "\n"; if(!$check)echo""; else { $this->wrongQuestions[]=$value; echo""; } echo ""; } function updateStatistic() { for($i=1;$i<=$this->questionLimit;$i++) { $sql="SELECT count FROM statistics WHERE q_id=".intval($this->questionList[$i]['q_id']).""; $query = mysql_query($sql); while($count=mysql_fetch_array($query ,MYSQL_BOTH )){ $count=$count['count']; $count=$count+1; $sql_update="UPDATE statistics SET count=".intval($count)." WHERE q_id=".intval($this->questionList[$i]['q_id']).""; $query_update = mysql_query($sql_update); } } } function createLearnProgress() { // Lernprogress erstellen $timestamp = time(); $date= date("Y-m-d H:i:s" ,$timestamp); // aktuelles Datum und Uhrzeit berechnen $correctAnswers=$this->questionLimit-count($this->wrongQuestions); $wrongAnswers=count($this->wrongQuestions); $passed=$this->testPassed; $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->insertAnswersIncorrect(); } function insertAnswersIncorrect(){ foreach($this->wrongQuestions as $value){ $sql="INSERT INTO answers_incorrect (lp_id,q_id) VALUES ( ".intval($this->lp_id).",".intval($value).")"; $query = mysql_query($sql); } } function getTestResult(){ $wrong=count($this->wrongQuestions); $correct=$this->questionLimit-$wrong; if($wrong==0)$percentTest=100; else if(($wrong>=$this->questionLimit) || ($this->questionLimit < 1))$percentTest=0; else $percentTest=($correct/$this->questionLimit)*100; $percentTest=round($percentTest, 2); $this->percentTest=$percentTest; $this->testPassed=0; if($this->rawToPass > 0 && $this->rawToPass <= $percentTest)$value="".Class_Quiz_08.""; else $value="".Class_Quiz_09.""; echo'

'.Global_05." :
"; global $questionlimit; $questionlimit =$this->questionLimit; echo" ".Class_Quiz_04." $correct / $this->questionLimit
"; echo" ".Class_Quiz_05." $this->rawToPass % "; echo "
".Class_Quiz_06." ".$this->percentTest." % ".Class_Quiz_07." $value

"; //createLearnProgress(); if($this->rawToPass > 0 && $this->rawToPass <= $percentTest) { $this->testPassed=1; // Test has been passed, maybe a paper/PDF-certificate can be requested if ($_SERVER['SSL_CLIENT_S_DN_CN']=="CAcert WoT User") { // Sorry, we cannot issue certificates for anonymous users echo '

'.Class_Quiz_10_AnonymousCert."

"; } else { echo "
"; echo ""; echo ""; echo "
"; } } } function showDescription($i){ if(isset($_SESSION['values']['questionList'][$i]['description_text'])){ // Ausgabe der Beschreibung echo "\n"; echo ""; echo"".$_SESSION['values']['questionList'][$i]['description_text'].""; echo ""; echo ""; } } } ?>