From 11262725b3d30ba678cc177c5cb98190c7b20995 Mon Sep 17 00:00:00 2001 From: INOPIAE Date: Sun, 20 Jan 2013 11:28:56 +0100 Subject: [PATCH 1/5] bug 1140: added the status passed to the progress table --- classes/Quiz.class.php | 257 +++++++++++++++++++------------------ classes/progress.class.php | 151 +++++++++++++--------- 2 files changed, 224 insertions(+), 184 deletions(-) diff --git a/classes/Quiz.class.php b/classes/Quiz.class.php index 0848c91..3465a55 100755 --- a/classes/Quiz.class.php +++ b/classes/Quiz.class.php @@ -1,6 +1,6 @@ topicID=0; $this->questionLimit=0; @@ -29,56 +30,56 @@ class Quiz $this->question=new Question(); $this->percentTest=0; } - - function getQuestionLimit() { + + 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); + $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 )) - { - + 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 )) - { + $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 + // 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); + $query_desc=mysql_query($sql_desc); $desc = mysql_fetch_assoc($query_desc); $this->questionList[$i]['description_text']=stripslashes($desc['description']); } @@ -87,31 +88,31 @@ class Quiz $_SESSION['values']['questionList']=$this->questionList; } else{ - echo "
".Class_Quiz_01."
"; - $value ="notEnoughQuestions"; + 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); + $queryGetAns = mysql_query($sqlGetAns); $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]['a_id']=$answers['a_id']; // in arra speichern $this->answerList[$value][$j]['answer']=stripslashes($answers['answer']); @@ -121,17 +122,17 @@ class Quiz } $_SESSION ['values'] ['answerList']= $this->answerList; } - + function setAnswers(){ $this->answerList=$_SESSION ['values']['answerList']; } - + function setSelectedAnswers (){ - $this->selectedAnswers=$_SESSION ['values']['selectedAnswers']; + $this->selectedAnswers=$_SESSION ['values']['selectedAnswers']; } - + function showQuiz() { - echo "
"; + echo ""; echo "
"; echo " ".Class_Quiz_02.""; echo ""; @@ -140,12 +141,12 @@ class Quiz $question=str_replace("\n", "
", $this->questionList[$i]['question']); echo ""; echo""; - - if($this->questionList[$i]['qt_id']!=4) { - 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 @@ -163,8 +164,8 @@ class Quiz echo ""; echo""; } - - 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 $answer=$this->answerList[$value][$j]['answer']; $answerNumber=$this->answerList[$value][$j]['a_id']; @@ -175,13 +176,13 @@ class Quiz if ($answer=='true') echo" "; else if ($answer=='false') echo" "; else echo" "; - echo ""; + 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']; @@ -191,16 +192,16 @@ class Quiz echo ""; echo ""; echo " "; - echo ""; + echo ""; echo ""; - } - } + } + } echo ""; } - + function randomizeArray($answerList,$value) { $max=count($answerList[$value]); // setze Maximum - $index=range(1,$max); // Kreiire Array + $index=range(1,$max); // Kreiire Array shuffle($index); // würfle array $copy= $answerList; // kopie erstellen for($i=0;$i<$max;$i++){ @@ -208,11 +209,11 @@ class Quiz $answerList[$value][$i+1]=$copy[$value][$k]; // zuweisen } $_SESSION ['values'] ['answerList']= $answerList; - return $answerList; + return $answerList; } - + function FillInTheBlanks($i,$value,$question) { - + echo '"; - echo ""; + echo ""; echo ""; echo ""; } - - - - function evaluateQuiz() { - + + + + function evaluateQuiz() { + echo"
"; echo "
"; - + echo "".Class_Quiz_03."\n"; echo "
".Global_08." $i: $question $question
".Class_Answer_09."".Class_Answer_10."$answer
$answer
'; $correctAns=$this->question->getCorrectAnswerFillInTheBlanks($question); // korrekte Antworen ermitteln $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']); $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 + $array=explode('\\',$addSlashes); // String teilen for($k=0;$k "; @@ -236,7 +237,7 @@ class Quiz } echo""; } - + else if((strstr($array[$k],']'))){ $array[$k]=str_replace("]",'', $array[$k]); // Klammer entfernen echo $array[$k]; @@ -244,18 +245,18 @@ class Quiz else echo $array[$k]; } echo "
"; for($i=1;$i<=count($this->questionList);$i++){ @@ -265,37 +266,37 @@ class Quiz echo""; echo" "; + echo" $question "; echo ""; } $this->topicID=$this->questionList[$i]['t_id']; switch($this->questionList[$i]['qt_id']){ - case 1: {$this->evaluateSingleSelection($i,$value); - + 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(); - + $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']; @@ -324,30 +325,30 @@ class Quiz 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); + $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($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; + 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"; @@ -357,7 +358,7 @@ class Quiz $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""; + else if ($checked[$j]==0) echo""; echo ""; //richtige Antworten ausgeben echo ""; @@ -369,26 +370,26 @@ class Quiz $show_class = "answer false"; } echo ""; - echo" $answer "; + 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]); + $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 + $array=explode('\\',$addSlashes); // String teilen + // Was Benutzer markiert hat for($k=0;$kanswerList[$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 @@ -408,16 +409,16 @@ class Quiz } echo ""; echo ""; - + echo "\n"; echo ""; - 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"; echo ""; - + $this->showDescription($i); - $this->checkAnswers($correct,$value); + $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"; @@ -444,50 +445,61 @@ function checkAnswers($correct,$value) { } 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']; + $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); + $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); - $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).")"; - $query = mysql_query($sql); + $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); - } + $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; @@ -495,21 +507,22 @@ function checkAnswers($correct,$value) { 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 ""; + echo ""; echo "
"; } } - } - + } + function showDescription($i){ if(isset($_SESSION['values']['questionList'][$i]['description_text'])){ // Ausgabe der Beschreibung diff --git a/classes/progress.class.php b/classes/progress.class.php index 72cf0b5..54e96c6 100755 --- a/classes/progress.class.php +++ b/classes/progress.class.php @@ -7,6 +7,8 @@ class Progress var $incorrect_answers; var $percentArray; var $maximum; + var $passed; + var $totalresult=array(); function Progress() { $this->progress=array(); @@ -15,70 +17,83 @@ class Progress $this->topic=0; $this->lp_id=0; $this->percentArray=array(); + $this->passed=0; } - + function setTopic($t_id){ $this->topic=$t_id; } - + function setLp_id($lp_id){ $this->lp_id=$lp_id; } - + function setData($value){ $this->progress=$value; } 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"; - $query = mysql_query($sql) OR die(mysql_error()); + $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()); $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]['date']=$progress['date']; $this->progress[$i]['number']=$progress['number']; // in arra speichern $this->progress[$i]['correct']=$progress['correct']; $this->progress[$i]['wrong']=$progress['wrong']; + $this->progress[$i]['passed']=$progress['passed']; $i++; } - + } - + function count() { $numberOfTests=count($this->progress); return $numberOfTests; } - + function showTable() { + $this->totalresult['count']=0; + $this->totalresult['passed']=0; if(count($this->progress)==0) echo "
".Global_07."
"; else { echo"

"; - echo""; + echo"
"; echo ""; echo""; echo""; echo""; echo""; + echo""; echo ""; echo""; - 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 ""; echo""; - echo""; - echo""; - if ($this->progress[$i]['number'] > 0) { - $percent=($this->progress[$i]['correct']/$this->progress[$i]['number'])*100; - } else { - $percent = 0; - } - $percent=round ($percent,2); - echo""; - echo""; - echo ""; - } - echo"
".Global_10."".Global_04."".Class_Progress_01."".Global_03."".Statistic_04."
$i".$this->progress[$i]['date']."".$this->progress[$i]['number']."$percent % topic'>
"; + echo"".$this->progress[$i]['date'].""; + echo"".$this->progress[$i]['number'].""; + echo"".getPassedImage($this->progress[$i]['passed']).""; + if ($this->progress[$i]['number'] > 0) { + $percent=($this->progress[$i]['correct']/$this->progress[$i]['number'])*100; + } else { + $percent = 0; + } + $percent=round ($percent,2); + echo"$percent %"; + echo" topic'>"; + echo ""; } + $this->totalresult['count']=$i; + echo ""; + echo "".Statistic_04.' '.$this->totalresult['passed'].'/'.$this->totalresult['count'].""; + echo ""; + echo""; + } } - + function checkProgressData(){ if(count($this->progress)==0) echo "
".Global_07."
"; else { @@ -90,31 +105,31 @@ class Progress echo '
'.Class_Progress_02." ".Class_Progress_03." $this->maximum ".Class_Progress_04.".
"; } else $k=1; $j=0; - - for ($i=$k;$i<=$limit;$i++){ + + for ($i=$k;$i<=$limit;$i++){ if ($this->progress[$i]['number'] > 0) { $percent=($this->progress[$i]['correct']/$this->progress[$i]['number'])*100; } else { $percent=0; } $this->percentArray[$j][]=$this->progress[$i]['date']; - $this->percentArray[$j][]=$percent; + $this->percentArray[$j][]=$percent; $j++; } } } - + function showBalken(){ - + $this->checkProgressData(); $this->percentArray= serialize($this->percentArray); $this->percentArray=base64_encode ($this->percentArray); $titley=Global_15; $titlex=Global_04; - echo "
\n"; + echo "
\n"; echo ""; - echo "
\n"; - + echo "
\n"; + } function showGraph(){ $this->checkProgressData(); @@ -122,57 +137,57 @@ class Progress $this->percentArray=base64_encode ($this->percentArray); $titley=Global_15; $titlex=Global_04; - echo "
\n"; + echo "
\n"; echo ""; - echo "
\n"; - + echo "
\n"; + } - + function showPie(){ - echo "
\n"; + echo "
\n"; echo ""; echo "
\n"; } - - + + function getIncorrectAnswers() { $sql="SELECT q_id FROM answers_incorrect WHERE lp_id=".intval($this->lp_id).""; $query = mysql_query($sql); $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']; $i++; } $this->showIncorrectAnswers(); } - - function showIncorrectAnswers(){ - echo "
"; + + function showIncorrectAnswers(){ + echo ""; echo "
"; echo " ".Class_Progress_08." "; echo ""; - - + + for ($i=1;$i<=count($this->incorrect_answers);$i++){ echo""; echo ""; $sql="SELECT question,qt_id FROM questions WHERE q_id=".intval($this->incorrect_answers[$i]['q_id']).""; $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){ $questionText=$this->getFIBQuestion( $question['question']); - + echo""; - + } else{ echo ""; } - } - echo""; - } + } + echo""; + } if($this->progress [$this->lp_id]['wrong']>count($this->incorrect_answers)) { $number=$this->progress [$this->lp_id]['wrong']-count($this->incorrect_answers); echo""; @@ -186,9 +201,9 @@ class Progress echo""; echo"
$i.) ".$questionText."". $question['question']."
"; echo "
"; - echo "
"; - } - + echo ""; + } + function getFIBQuestion($question){ $addSlashes= preg_quote( $question, '[^]'); // Slash hinzufügen wenn KLammer gefunden wird $array=explode('\\',$addSlashes); // String teilen @@ -201,12 +216,24 @@ class Progress $answer=substr ($questionText,$beginPos,$length );// den String zwischen den Klammern suchen $questionText=str_replace($answer,'(xxx)', $questionText); // gespeicherten Wert aus string löschen $answer=str_replace("]",'', $answer); // Klammer entfernen - $key = array_search($answer, $array); - $answer=str_replace("[",'', $answer); // Klammer entfernen - - } - } + $key = array_search($answer, $array); + $answer=str_replace("[",'', $answer); // Klammer entfernen + + } + } return $questionText; } - } + + function getPassedImage($passed){ + // returns the image depending on the status of a test result + $img=""; + if (0==$passed) { + $img=""; + } + if (1==$passed) { + $img=""; + } + return $img; + } + } ?> From e0538cf1a0b4019b826078ee1e5067cbbeea4e7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Fr=C3=B6hlich?= Date: Wed, 10 Apr 2013 22:22:33 +0200 Subject: [PATCH 2/5] Used the opportunity and re-formatted the file consistently, without using tabs. --- classes/Quiz.class.php | 846 ++++++++++++++++++++--------------------- 1 file changed, 422 insertions(+), 424 deletions(-) diff --git a/classes/Quiz.class.php b/classes/Quiz.class.php index 3465a55..be3ddef 100755 --- a/classes/Quiz.class.php +++ b/classes/Quiz.class.php @@ -16,7 +16,7 @@ class Quiz var $percentTest; var $testPassed; - function Quiz(){ + function Quiz(){ $this->topicID=0; $this->questionLimit=0; $this->questionList= array(); @@ -29,261 +29,261 @@ class Quiz $this->rawToPass; $this->question=new Question(); $this->percentTest=0; - } + } - function getQuestionLimit() { - return $this->questionLimit; - } + function getQuestionLimit() { + return $this->questionLimit; + } - function setQuestionLimit($numOfQu){ - $this->questionLimit= $numOfQu; - } + function setQuestionLimit($numOfQu){ + $this->questionLimit= $numOfQu; + } - function setTopicID($id) { + function setTopicID($id) { $this->topicID=$id; - } + } - function getTopicID(){ + function getTopicID(){ return $this->topicID; - } + } - function getAnswerList () { - return $this->answerList; - } + function getAnswerList () { + return $this->answerList; + } - function setRawToPass($percentage){ - $this->rawToPass=$percentage; - } + 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 )) - { + 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; - } - } + $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 getQuestionList() { + return $this->questionList; + } - function setQuestions() { - $this->questionList=$_SESSION['values']['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 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 setAnswers(){ + $this->answerList=$_SESSION ['values']['answerList']; + } function setSelectedAnswers (){ - $this->selectedAnswers=$_SESSION ['values']['selectedAnswers']; - } + $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""; + echo ""; + echo "
"; + echo " ".Class_Quiz_02.""; + echo "
".Global_08." $i:
"; + 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""; + 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
$question
"; - echo""; - //echo""; - //echo""; - echo" "; - echo "
"; - echo "
"; - echo"
"; + } + echo ""; + echo ""; + echo""; + //echo""; + //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 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 ""; - } + 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; + $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); - 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]; - } + $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 ""; - } + echo ""; + } + function evaluateQuiz() { + echo"
"; + echo "
"; - function evaluateQuiz() { + 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); - echo"
"; - echo "
"; - - echo "".Class_Quiz_03."\n"; - echo "
".Global_08." $i : "; + if($this->questionList[$i]['qt_id']!=4){ + echo" $question
"; - 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;} + 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; + } } } @@ -295,244 +295,242 @@ class Quiz $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 ""; - //richtige Antworten - echo ""; - if ($answer=='true') echo" "; - else if ($answer=='false') echo" "; - else echo""; + 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 ""; + //richtige Antworten + echo ""; + if ($answer=='true') echo" "; + else if ($answer=='false') echo" "; + else echo""; - echo ""; - echo""; - } + echo ""; + echo""; + } - 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) { - $correct[]=1; - } - } - $this->showDescription($i); + $correct[]=1; + } + } + $this->showDescription($i); - if(!isset($correct)) $correct[]=0; - $this->checkAnswers($correct,$value); - } + 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 ""; - //richtige Antworten ausgeben - echo ""; - echo""; - 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 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 ""; + //richtige Antworten ausgeben + echo ""; + echo""; + 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 ""; - echo ""; + } else echo $array[$k]; + } + echo ""; + echo ""; - echo "\n"; - echo ""; - echo ""; + if(!$check)echo""; + else { + $this->wrongQuestions[]=$value; + echo""; + } + 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 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(); - } + $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 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; + 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.""; + $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(); + 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 ""; - } - } - } + 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""; - echo ""; - echo ""; - } - } + function showDescription($i){ + if(isset($_SESSION['values']['questionList'][$i]['description_text'])){ + // Ausgabe der Beschreibung + echo "\n"; + echo ""; + echo""; + echo ""; + echo ""; + } + } } ?> From 528f9b31a3455b58b789c7d6c62e19acd068c8f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Fr=C3=B6hlich?= Date: Wed, 10 Apr 2013 22:43:51 +0200 Subject: [PATCH 3/5] Once again fixed indention --- classes/progress.class.php | 162 ++++++++++++++++++------------------- 1 file changed, 80 insertions(+), 82 deletions(-) diff --git a/classes/progress.class.php b/classes/progress.class.php index 54e96c6..2d59f58 100755 --- a/classes/progress.class.php +++ b/classes/progress.class.php @@ -25,16 +25,16 @@ class Progress } function setLp_id($lp_id){ - $this->lp_id=$lp_id; + $this->lp_id=$lp_id; } - function setData($value){ - $this->progress=$value; - } + function setData($value){ + $this->progress=$value; + } function getProgress(){ - $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()); - $i=1; + $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()); + $i=1; while($progress =mysql_fetch_array($query,MYSQL_BOTH )){ $this->progress[$i]['lp_id']=$progress['lp_id']; $this->progress[$i]['date']=$progress['date']; @@ -48,8 +48,8 @@ class Progress } function count() { - $numberOfTests=count($this->progress); - return $numberOfTests; + $numberOfTests=count($this->progress); + return $numberOfTests; } function showTable() { @@ -67,55 +67,55 @@ class Progress echo""; echo ""; echo""; - 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 ""; - echo""; - echo""; - echo""; - echo""; - if ($this->progress[$i]['number'] > 0) { - $percent=($this->progress[$i]['correct']/$this->progress[$i]['number'])*100; - } else { - $percent = 0; - } - $percent=round ($percent,2); - echo""; - echo""; - echo ""; + echo""; + echo""; + echo""; + echo""; + if ($this->progress[$i]['number'] > 0) { + $percent=($this->progress[$i]['correct']/$this->progress[$i]['number'])*100; + } else { + $percent = 0; + } + $percent=round ($percent,2); + echo""; + echo""; + echo ""; } $this->totalresult['count']=$i; - echo ""; - echo ""; - echo ""; + echo ""; + echo ""; + echo ""; echo"
".Global_08." $i : "; - if($this->questionList[$i]['qt_id']!=4){ - echo" $question
"; - // Auswahl des Benutzers - if(isset($this->selectedAnswers[$value]) && $this->selectedAnswers[$value]==$this->answerList[$value][$j]['a_id']) { - echo""; - } else { - echo""; - } - echo ""; - if($this->answerList[$value][$j]['correct']==1) { - echo""; - $show_class="answer correct"; - } else { - echo""; - $show_class="answer false"; - } - echo "".Class_Answer_09."".Class_Answer_10."$answer
"; + // Auswahl des Benutzers + if(isset($this->selectedAnswers[$value]) && $this->selectedAnswers[$value]==$this->answerList[$value][$j]['a_id']) { + echo""; + } else { + echo""; + } + echo ""; + if($this->answerList[$value][$j]['correct']==1) { + echo""; + $show_class="answer correct"; + } else { + echo""; + $show_class="answer false"; + } + echo "".Class_Answer_09."".Class_Answer_10."$answer
"; - $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 ""; - if($this->answerList[$value][$j]['correct']==1) { - echo""; - $show_class = "answer correct"; - } else { - echo""; - $show_class = "answer false"; - } - echo " $answer
"; + $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 ""; + if($this->answerList[$value][$j]['correct']==1) { + echo""; + $show_class = "answer correct"; + } else { + echo""; + $show_class = "answer false"; + } + echo " $answer
"; - $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 + // 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 "
"; + $this->showDescription($i); + $this->checkAnswers($correct,$value); + } - // Was richtig ist - $addSlashes= preg_quote($question, '[^]'); // Slash hinzufügen wenn KLammer gefunden wird - $array=explode('\\',$addSlashes); // String teilen - //echo"
"; + 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
".$_SESSION['values']['questionList'][$i]['description_text']."
".$_SESSION['values']['questionList'][$i]['description_text']."
".Statistic_04."
$i".$this->progress[$i]['date']."".$this->progress[$i]['number']."".getPassedImage($this->progress[$i]['passed'])."$percent % topic'>
$i".$this->progress[$i]['date']."".$this->progress[$i]['number']."".getPassedImage($this->progress[$i]['passed'])."$percent % topic'>
".Statistic_04.' '.$this->totalresult['passed'].'/'.$this->totalresult['count']."
".Statistic_04.' '.$this->totalresult['passed'].'/'.$this->totalresult['count']."
"; - } + } } - function checkProgressData(){ + function checkProgressData(){ if(count($this->progress)==0) echo "
".Global_07."
"; else { $percentArray=array(); $limit=count($this->progress); - if($limit>$this->maximum){ - $k=($limit-$this->maximum)+1; - $limit=($k+$this->maximum)-1; - echo '
'.Class_Progress_02." ".Class_Progress_03." $this->maximum ".Class_Progress_04.".
"; - } else $k=1; - $j=0; + if($limit>$this->maximum){ + $k=($limit-$this->maximum)+1; + $limit=($k+$this->maximum)-1; + echo '
'.Class_Progress_02." ".Class_Progress_03." $this->maximum ".Class_Progress_04.".
"; + } else $k=1; + $j=0; - for ($i=$k;$i<=$limit;$i++){ - if ($this->progress[$i]['number'] > 0) { - $percent=($this->progress[$i]['correct']/$this->progress[$i]['number'])*100; - } else { - $percent=0; + for ($i=$k;$i<=$limit;$i++){ + if ($this->progress[$i]['number'] > 0) { + $percent=($this->progress[$i]['correct']/$this->progress[$i]['number'])*100; + } else { + $percent=0; + } + $this->percentArray[$j][]=$this->progress[$i]['date']; + $this->percentArray[$j][]=$percent; + $j++; } - $this->percentArray[$j][]=$this->progress[$i]['date']; - $this->percentArray[$j][]=$percent; - $j++; - } } } @@ -156,10 +156,10 @@ class Progress $query = mysql_query($sql); $i=1; while($incorrect_answers =mysql_fetch_array($query,MYSQL_BOTH )) - { - $this->incorrect_answers[$i]['q_id']=$incorrect_answers['q_id']; - $i++; - } + { + $this->incorrect_answers[$i]['q_id']=$incorrect_answers['q_id']; + $i++; + } $this->showIncorrectAnswers(); } @@ -170,31 +170,30 @@ class Progress echo ""; - for ($i=1;$i<=count($this->incorrect_answers);$i++){ + for ($i=1;$i<=count($this->incorrect_answers);$i++){ echo""; - echo ""; - $sql="SELECT question,qt_id FROM questions WHERE q_id=".intval($this->incorrect_answers[$i]['q_id']).""; - $query = mysql_query($sql); - while($question =mysql_fetch_array($query,MYSQL_BOTH )) { + echo ""; + $sql="SELECT question,qt_id FROM questions WHERE q_id=".intval($this->incorrect_answers[$i]['q_id']).""; + $query = mysql_query($sql); + while($question =mysql_fetch_array($query,MYSQL_BOTH )) { if( $question['qt_id']==4){ - $questionText=$this->getFIBQuestion( $question['question']); + $questionText=$this->getFIBQuestion( $question['question']); - echo""; + echo""; - } - else{ + } else { echo ""; - } } - echo""; - } - if($this->progress [$this->lp_id]['wrong']>count($this->incorrect_answers)) { - $number=$this->progress [$this->lp_id]['wrong']-count($this->incorrect_answers); - echo""; - echo ""; - echo""; - echo""; } + echo""; + } + if($this->progress [$this->lp_id]['wrong']>count($this->incorrect_answers)) { + $number=$this->progress [$this->lp_id]['wrong']-count($this->incorrect_answers); + echo""; + echo ""; + echo""; + echo""; + } echo""; echo ""; echo" "; @@ -205,23 +204,22 @@ class Progress } function getFIBQuestion($question){ - $addSlashes= preg_quote( $question, '[^]'); // Slash hinzufügen wenn KLammer gefunden wird - $array=explode('\\',$addSlashes); // String teilen - $questionText= $question; - if(substr_count($question,"[")==substr_count($question,"]")) { // gleiche anzahl von Klammer auf und zu - for($i=1;$i<=substr_count($question,"[");$i++){ // Wird solange durchlaufne wie Klammern vorhanden sind - $beginPos = strpos($questionText, "["); // Anfangspunkt festlegen - $endPos=strpos($questionText, "]"); // Endpunkt festlegen - $length=(($endPos+1)-$beginPos) ; // Länge der Strings ermitteln - $answer=substr ($questionText,$beginPos,$length );// den String zwischen den Klammern suchen - $questionText=str_replace($answer,'(xxx)', $questionText); // gespeicherten Wert aus string löschen - $answer=str_replace("]",'', $answer); // Klammer entfernen - $key = array_search($answer, $array); - $answer=str_replace("[",'', $answer); // Klammer entfernen - - } - } - return $questionText; + $addSlashes= preg_quote( $question, '[^]'); // Slash hinzufügen wenn KLammer gefunden wird + $array=explode('\\',$addSlashes); // String teilen + $questionText= $question; + if(substr_count($question,"[")==substr_count($question,"]")) { // gleiche anzahl von Klammer auf und zu + for($i=1;$i<=substr_count($question,"[");$i++){ // Wird solange durchlaufne wie Klammern vorhanden sind + $beginPos = strpos($questionText, "["); // Anfangspunkt festlegen + $endPos=strpos($questionText, "]"); // Endpunkt festlegen + $length=(($endPos+1)-$beginPos) ; // Länge der Strings ermitteln + $answer=substr ($questionText,$beginPos,$length );// den String zwischen den Klammern suchen + $questionText=str_replace($answer,'(xxx)', $questionText); // gespeicherten Wert aus string löschen + $answer=str_replace("]",'', $answer); // Klammer entfernen + $key = array_search($answer, $array); + $answer=str_replace("[",'', $answer); // Klammer entfernen + } + } + return $questionText; } function getPassedImage($passed){ From a53d97b7cbc43a42e26670aa4f423f3f65fc9c78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Fr=C3=B6hlich?= Date: Wed, 10 Apr 2013 23:30:42 +0200 Subject: [PATCH 4/5] BugFix in function call --- classes/progress.class.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/classes/progress.class.php b/classes/progress.class.php index 2d59f58..38878b9 100755 --- a/classes/progress.class.php +++ b/classes/progress.class.php @@ -75,15 +75,16 @@ class Progress echo""; echo""; echo""; - echo""; if ($this->progress[$i]['number'] > 0) { $percent=($this->progress[$i]['correct']/$this->progress[$i]['number'])*100; } else { $percent = 0; } $percent=round ($percent,2); - echo""; - echo""; + echo ""; + echo ""; + echo ""; echo ""; } $this->totalresult['count']=$i; From e19037d598c9d95c2898e8fe1c70b992fa3290ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Fr=C3=B6hlich?= Date: Wed, 10 Apr 2013 23:56:15 +0200 Subject: [PATCH 5/5] bug 500: Added button to request certificate in learnprogress page if there are passed tests. --- classes/progress.class.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/classes/progress.class.php b/classes/progress.class.php index 38878b9..d4707af 100755 --- a/classes/progress.class.php +++ b/classes/progress.class.php @@ -87,11 +87,17 @@ class Progress echo $this->progress[$i]['lp_id']."&t_id=$this->topic'>"; echo ""; } - $this->totalresult['count']=$i; + $this->totalresult['count']=$i-1; echo ""; echo ""; - echo ""; + echo "\n"; echo"
$i.) $i.) ".$questionText."".$questionText."". $question['question']."
".Class_Progress_06." $number ".Class_Progress_07."
".Class_Progress_06." $number ".Class_Progress_07."
$i".$this->progress[$i]['date']."".$this->progress[$i]['number']."".getPassedImage($this->progress[$i]['passed'])."$percent % topic'>$percent %".$this->getPassedImage($this->progress[$i]['passed'])." topic'>
".Statistic_04.' '.$this->totalresult['passed'].'/'.$this->totalresult['count']."
"; + if ($this->totalresult['passed'] > 0) { + echo "
"; + echo ""; + echo ""; + echo "
"; + } } }