id=0; $this->type=0; $this->topic=0; $this->allTopics=array(); $this->questionText=""; $this->typeName=""; $this->numberOfQuestions=array(); $this->answer= new Answer(); $this->description=0; $this->descriptionText=""; } function getID() { return (int) $this->id; } function setID($id) { $this->id =$id ; } function setTopic($topic){ $this->topic = $topic; $_SESSION['values']['t_id']=$this->topic; } function getTopic(){ return $this->topic; } function setAllTopics($topics){ $this->allTopics=$topics; } function getQuestionText() { return $this->questionText; } function getAllQuestions() { return $this->questionList; } function setUpdateQuestion($quText,$topic) { $help = strcmp($this->questionText, $quText); $help1 = strcmp($this->topic, $topic); if(($help==0) && ($help1==0)){ return 'none'; } else { $this->questionText = trim($quText); $this->topic=$topic; if($this->type==4) { $this->answer->setQuestionID($this->id); $this->answer->getAnswers(); $correctAns=$this->getCorrectAnswerFillInTheBlanks($this->questionText); $this->answer->setAnswersCorrect($correctAns); if($this->answer->controlAnswers()==true)$this->updateQuestion(); else return 'conflict' ; } else $this->updateQuestion(); } } function setQuestion($quText){ $this->questionText = trim($quText); } function getQuestion(){ return $this->questionText; } function setActive(){ $sql="UPDATE questions set active=".intval(1)." WHERE q_id=".intval($this->id)." "; $ok= mysql_query($sql); } function setInactive(){ $sql="UPDATE questions set active=".intval(0)." WHERE q_id=".intval($this->id)." "; $ok= mysql_query($sql); } function setDescription($description){ $_SESSION['values']['question']['description']=1; $_SESSION['values']['question']['descriptionText']=$description; } function setSession(){ $_SESSION ['values']['question']['q_id']=$this->id; $_SESSION ['values']['question']['questionText']=$this->questionText; $_SESSION ['values']['question']['t_id']=$this->topic; $_SESSION ['values']['question']['qt']=$this->type; $_SESSION ['values']['question']['description']=$this->description; $_SESSION ['values']['question']['descriptionText']=$this->descriptionText; } function unsetSession(){ unset($_SESSION ['values']['question']); } function delAllQuestions(){ for ($i=1;$i<=count($this->questionList);$i++){ $q_id=$this->questionList[$i]['q_id']; $this->delQuestion($q_id); } } function getNumberOfQuestions($topicarray){ for ($i=1;$i<=count($topicarray);$i++){ $sql="SELECT COUNT(q_id)as 'number' FROM questions WHERE t_id=".intval($topicarray[$i]['t_id']) ." "; $query = mysql_query($sql); while($numberofQuestions=mysql_fetch_array($query ,MYSQL_BOTH )){ $this->numberofQuestions[$i]=$numberofQuestions['number']; // in arra speichern } } return $this->numberofQuestions; } function getLearnpathCount($topicarray){ for ($i=1;$i<=count($topicarray);$i++){ $sql="SELECT COUNT(lp_id)as 'number' FROM learnprogress WHERE t_id=".intval($topicarray[$i]['t_id']) ." "; $query = mysql_query($sql); while($numberOfLp=mysql_fetch_array($query ,MYSQL_BOTH )) { $numberOfTests[$i]=$numberOfLp['number']; // in arra speichern } } return $numberOfTests; } function setType($type) { $accepted = array('1', '2', '3', '4'); if( in_array($type, $accepted) ) { // Wenn type in array dann zuweisen $this->type = $type; return true; } return false; } function getCorrectAnswerFillInTheBlanks($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,'()', $questionText); // gespeicherten Wert aus string löschen $answer=str_replace("]",'', $answer); // Klammer entfernen $key = array_search($answer, $array); $answer=str_replace("[",'', $answer); // Klammer entfernen $value[$i]['answer']=$answer; $value[$i]['blank']=$key; } } return($value); } function returnTypeName($type){ // if($type==0)$type=$_SESSION ['values']['question']['qt']; $sql=sprintf("SELECT `qt_desc` as `type` FROM `questiontype_v2` WHERE `qt_id`='%d' AND `lang`='%s'", intval($type), mysql_real_escape_string($_SESSION['profile']['language'])); $query = mysql_query($sql); $type = mysql_fetch_assoc($query); $this->typeName=$type['type']; return $this->typeName; } function getType() { return $this->type; } function checkQuestion(){ if(($_SESSION ['values']['question']['questionText'])!=null && $_SESSION ['values']['question']['qt']!=null ){ if($_SESSION ['values']['question']['qt']==4) $value =$this->getCorrectAnswerFillInTheBlanks($_SESSION ['values']['question']['questionText']); if(count ($value)>0 && $_SESSION ['values']['question']['qt']==4 || $_SESSION ['values']['question']['qt']!=4){ return 1; }else return 3; } else return 0; } function saveQuestion(){ if($_SESSION ['values']['question']['qt']==4) $value =$this->getCorrectAnswerFillInTheBlanks($_SESSION ['values']['question']['questionText']); if(count ($value)>0 && $this->type==4 || $this->type!=4){ $sql = 'INSERT INTO questions (question,qt_id,t_id,active,description)VALUES ("'.mysql_real_escape_string($_SESSION ['values']['question']['questionText']).'","'.intval($_SESSION ['values']['question']['qt']).'","'.intval($_SESSION ['values']['question']['t_id']).'","'.intval(0).'","'.intval($_SESSION['values']['question']['description']).'")'; // frage bis sie komplett ist inaktiv setzen $ok= mysql_query($sql); if (!$ok){ $error=mysql_errno(); if($error=='1062') return 2; } else { $questionId = mysql_insert_id(); if($_SESSION['values']['question']['description']==1){ $sql_desc = 'INSERT INTO question_description (q_id,description)VALUES ("'.intval($questionId).'","'.mysql_real_escape_string($_SESSION['values']['question']['descriptionText']).'" )'; // frage bis sie komplett ist inaktiv setzen $ok_desc= mysql_query($sql_desc); } $this->id = (int) $questionId; // ID zuweisen $_SESSION['values']['question']['q_id']=(int) $questionId; $this->createStatistic(); } return 1; }else return 3; } function loadQuestion() { $sql ='SELECT question,t_id,qt_id,description FROM questions WHERE q_id='.intval($this->id).''; $query = mysql_query($sql); if(!$query){ // Wenn Fehler $error=mysql_errno() ; } while($question =mysql_fetch_array($query,MYSQL_BOTH )){ // Prüfen ob es nicht ne bessere Art und Weise gibt als while $this->questionText=$question['question']; $this->topic=$question['t_id']; $this->type=$question['qt_id']; $this->description=$question['description']; // beschreibung aus db holen if($this->description==1){ $sql_desc="SELECT description FROM question_description WHERE q_id=".intval($this->id).""; $query_desc=mysql_query($sql_desc); $desc = mysql_fetch_assoc($query_desc); $this->descriptionText=stripslashes($desc['description']); } } $this->returnTypeName($this->type); $this->setSession(); } function showQuestionTable(){ echo"