answerList=0; $this->type=0; $this->changedAnswers=0; $this->answersCorrect=0; $this->missing=0; $this->answerList = array(); $this->action="index.php?site=collect_question&action=setAnswers"; } function setChangedAnswers($changed_answers){ $this->changedAnswers=$changed_answers; } function setQuestionType($type) { $this->type=$type; } function setMissing() { $this->missing=true; } function setAnswerType($type) { $this->type=$type; } function setType(){ switch ($this->type) { case 1 : { // Einfachauswahl $this->formHead(); $this->ShowFormSingleSelection(); break; } case 2 : { // Mehrfachauswahl $this->formHead(); $this->ShowFormMultipleChoice(); break; } case 3 : { //Richtig/Falsch $this->formHead(); $this->ShowFormCorrectWrong(); break; } case 4 : { //Lückentext mit Auswahl $this->ShowFormFillInTheBlanks(); break; } } } function showAnswers() { echo"
"; echo "
"; echo " ".Class_Answer_01." "; echo ""; for ($i=0;$ianswerList);$i++){ echo ""; echo ""; echo" "; echo""; } echo ""; echo ""; if($this->type!=3)echo""; echo ""; echo "
"; if ($this->answerList[$i]['correct']==1)echo ""; else echo ""; echo "
"; echo "
"; echo"
"; } function setAnswersCorrect($correctAnswers){ $this->answersCorrect=$correctAnswers; } function setQuestionID($q_id){ $this->quID= $q_id; } function getAnswers(){ $sql="SELECT a_id, answer, correct FROM answers WHERE q_id=".intval($_SESSION['values']['question']['q_id']).""; $query= mysql_query($sql); $i=0; // zähler while($answers =mysql_fetch_array($query ,MYSQL_BOTH )){ $this->answerList[$i]['a_id']=$answers['a_id']; // in arra speichern $this->answerList[$i]['answer']=$answers['answer']; $this->answerList[$i]['correct']=$answers['correct']; $i++; } $_SESSION['values']['answerList']=$this->answerList; } function setAnswerList(){ $this->answerList=$_SESSION ['values']['answerList']; } function changeCorrect($a_id){ switch ($this->type){ case 1 : { // Einfachauswahl nur eine Antwort darf richtig sein for ($i=0;$ianswerList);$i++){ if($this->answerList[$i]['a_id']==$a_id){ $this->answerList[$i] ['correct']=1; } else $this->answerList [$i] ['correct']=0; } $_SESSION ['values']['answerList']=$this->answerList; break; } case 2: { // Mehrfachauswahl mehrere Antworten können richtig sein $copy=$this->answerList; for ($i=0;$ianswerList);$i++){ if($copy [$i]['a_id']==$a_id){ if($copy[$i]['correct']==1) $copy [$i] ['correct']=0; else $copy [$i] ['correct']=1; } } for ($i=0;$ianswerList);$i++){ if($copy[$i]['correct']==1)$check[$i]=1; else $check[$i]=0; } $check_answers_true = in_array(1,$check); $check_answers_false= in_array (0,$check); if(($check_answers_true) && ($check_answers_false)) $this->answerList=$copy; else echo "

".Class_Answer_08."

"; break; } case 3: { // Richtig Falsch for ($i=0;$ianswerList);$i++){ if($this->answerList[$i]['a_id']==$a_id){ if( $this->answerList[$i] ['correct']==1) $this->answerList[$i] ['correct']=0; else $this->answerList[$i] ['correct']=1; } else{ if( $this->answerList[$i] ['correct']==1) $this->answerList[$i] ['correct']=0; else $this->answerList[$i] ['correct']=1; } } break; } } } function updateChangedAnswers() { $this->answerList=$_SESSION['values']['answerList']; for ($i=0;$ianswerList);$i++){ $help = strcmp($this->answerList [$i] ['answer'],$this->changedAnswers[$i] ); // Vergleich der Antworten if($help!=0) { // wenn ein Unterschied besteht dann Update $this->answerList [$i] ['answer']=$this->changedAnswers[$i]; // Zur späteren korrekten Anzeige Wert überschreiben $sql="UPDATE answers SET answer='".mysql_real_escape_string($this->changedAnswers[$i])."', correct='".intval($this->answerList [$i] ['correct'])."' WHERE a_id=".intval($this->answerList [$i] ['a_id']).""; $query = mysql_query($sql); } } } function updateTruthFalse(){ for ($i=0;$ianswerList);$i++){ $sql="UPDATE answers SET answer='".mysql_real_escape_string($this->answerList [$i] ['answer'])."', correct='".intval($this->answerList [$i] ['correct'])."' WHERE a_id=".intval($this->answerList [$i] ['a_id']).""; $query = mysql_query($sql); } } function delAllAnswers($questionArray) { for ($i=0;$idelAnswers ($q_id); } } function delAnswers ($q_id){ $sql="DELETE FROM answers WHERE q_id=".intval($q_id).""; $query = mysql_query($sql); if (!$query){ $error=mysql_errno() ; } } function addAnswer() { $addAnswer = array( 'id' => 0, 'answer' => '','correct' => 0); $this->answerList[] = $addAnswer; } function minusAnswer(){ if(count($this->answerList)>2){ // Prüfen ob mindestens 2 Antwortmöglichkeiten $delAnswer = array_pop($this->answerList); } } function formHead(){ echo "
"; echo "
"; echo"".Class_Answer_02." "; echo ""; echo ""; echo""; echo""; echo ""; } function ShowFormSingleSelection(){ for($i=0;$ianswerList);$i++){ echo ""; echo""; printf("", $extrastyle, stripslashes($this->answerList[$i]['answer'])); echo""; } $_SESSION ['values']['answerList']=$this->answerList; echo ""; echo""; echo""; echo ""; echo ""; echo""; echo" "; echo ""; echo"
".Global_03." ".Class_Answer_03."
"; if (isset($this->answerList[$i]['id'])) { printf('', $this->answerList[$i]['id']); } else { printf(''); } if ($this->missing) { $extrastyle = ' marked'; } else { $extrastyle = ''; } if ($this->answerList[$i]['correct'] == 1) { printf("", $extrastyle, $i); } else { printf('', $extrastyle, $i); } echo "
"; echo"
"; echo"
"; echo"
"; } function ShowFormMultipleChoice(){ $i = 0; foreach( $this->answerList as $answer ){ echo ""; if (isset($this->answerList[$i]['id'])) { printf('', $this->answerList[$i]['id']); } else { printf(''); } if ($this->missing == true) { $extrastyle = ' marked'; } else { $extrastyle = ''; } if ($this->answerList[$i]['correct'] == 1) { printf("", $extrastyle, $i); } else { printf("", $extrastyle, $i); } echo ""; printf("", $extrastyle, stripslashes($this->answerList[$i]['answer'])); echo""; $i++; } echo ""; echo""; echo" "; echo""; echo""; echo ""; echo""; echo" "; echo ""; echo ""; echo""; } function ShowFormCorrectWrong(){ $answerPossible=array("".Class_Answer_09."", "".Class_Answer_10.""); $i = 0; foreach( $this->answerList as $answer ) { echo ""; printf('', $this->answerList[$i]['id']); if ($this->missing==true) { $extrastyle = ' marked'; } else { $extrastyle = ''; } if ($this->answerList[$i]['correct']==1) { printf("", $extrastyle, $i); } else { printf("", $extrastyle, $i); } echo ""; printf("", stripslashes($answerPossible[$i])); echo ""; $i++; } echo ""; echo""; echo" "; echo ""; echo""; echo ""; echo""; } function ShowFormFillInTheBlanks(){ echo "
"; echo "
"; echo"".Antworten." "; echo ""; $i = 0; foreach($this->answerList as $answer ){ echo ""; echo""; if($this->missing==true){ echo" "; } else { echo" "; } $i++; echo""; } echo ""; echo""; echo" "; echo ""; echo ""; echo""; echo" "; echo""; echo"
"; printf('', $this->answerList[$i]['id']); echo"
"; echo"
"; echo "
"; echo"
"; } function controlAnswers(){ for($i=0;$ianswerList);$i++){ for($j=1;$j<=count($this->answersCorrect);$j++){ $compare=$this->answersCorrect[$j]['answer']; $help=strcmp($this->answerList[$i]['answer'], $compare) ; if($help==0){ $this->answerList[$i]['answer']=''; $foundIncorrect[]=1; } } } if(count($foundIncorrect)>0) { return false; } else return true; } function checkNumberOfAnswers(){ for($i=0;$ianswerList);$i++){ $help=strcmp($this->answerList[$i]['answer'],''); if($help!=0)$check[]=1; } if(count($check)>=2)return true; else return false; } function checkAnswer(){ if(($this->type==4) && ($this->controlAnswers()==true)||$this->type!=4){ if(($this->pruefungCorrect()==true) || ($this->type==4)){ // pruefung ob eine Frage als richtig markiert wurde außer bei Lückentext if($this->checkNumberOfAnswers()==true) { return 1; } else { echo"

".Class_Answer_04."
"; if($this->type==4)echo"
".Class_Answer_04."
"; $this->setMissing(); $this->setType(); } } else{ if( $this->type !=3)echo"
".Class_Answer_05."
"; else echo"
".Class_Answer_06."
"; $this->setMissing(); $this->setType(); // wenn Antwort nicht ausgefüllt dann zurück zur Maske } }else { echo"
".Class_Answer_07."
"; $this->setMissing(); $this->setType();} return 0; } function saveAnswer(){ // Fehlt noch Prüfung nach Fragetyp etc // correct wird noch nicht gescheit angezeigt if(($this->type==4) && ($this->controlAnswers()==true)||$this->type!=4){ if(($this->pruefungCorrect()==true) || ($this->type==4)){ // pruefung ob eine Frage als richtig markiert wurde außer bei Lückentext if($this->checkNumberOfAnswers()==true) { $sql_del="DELETE FROM answers WHERE q_id=".intval($_SESSION['values']['question']['q_id']).""; $ok_del= mysql_query($sql_del); for ($i=0;$ianswerList);$i++){ $answer=$this->answerList[$i]['answer']; $correct=$this->answerList[$i]['correct']; if($answer!=''){ // wenn in antwort was drin steht if($answer == Class_Answer_09)$answer='true'; else if($answer == Class_Answer_10) $answer='false'; $sql="INSERT INTO answers (q_id,answer,correct) VALUES (".intval($_SESSION['values']['question']['q_id']).",'".mysql_real_escape_string($answer)."',".intval($correct).")"; $ok= mysql_query($sql); } } unset ($_SESSION ['values']['answerList']); return true; } else { echo"

".Class_Answer_04."
"; if($this->type==4)echo"
".Class_Answer_04."
"; $this->setMissing(); $this->setType(); } } else{ if( $this->type !=3)echo"
".Class_Answer_05."
"; else echo"
".Class_Answer_06."
"; $this->setMissing(); $this->setType(); // wenn Antwort nicht ausgefüllt dann zurück zur Maske } }else { echo"
".Class_Answer_07."
"; $this->setMissing(); $this->setType();} return false; } function pruefungCorrect(){ $this->answerList=$_SESSION['values']['answerList']; for ($i=0;$i<=count($this->answerList);$i++) { if($this->answerList[$i]['correct']==1){ return true; // wenn mindestens eine Frage als korrekt markiert ist dann speichere } } return false; } function updateAnswers($q_id) { for($i=0;$ianswerList);$i++){ $sql="INSERT INTO answers (q_id,answer,correct) VALUES (".intval($q_id).",'".mysql_real_escape_string($this->answerList[$i]['answer'])."','".intval($this->answerList[$i]['correct'])."')"; $ok= mysql_query($sql); } } } ?>