table='topics'; $this->topicName=''; $this->topics = array(); $this->topicID=0; $this->rawToPass=0; $this->numOfQu=0; $this->error=''; $this->question=new Question (); } function setTopicName($topicName){ $this->topicName=$topicName; } function setNumOfQu($numOfQu){ $this->numOfQu=$numOfQu; if(is_numeric($this->numOfQu)==true && $this->numOfQu>0) return 0; else return 1; } function setrawToPass($rawToPass){ $this->rawToPass=$rawToPass; if(is_numeric($this->rawToPass)==true && $this->rawToPass<=100 && $this->rawToPass>0) return 0; else return 1; } function setError($error){ $this->error=$error; } function setTopic($t_id){ $this->topicID=$t_id; $sql ="SELECT topic,numOfQu,percentage FROM topics WHERE t_id='".intval($t_id)."'"; // fehlt noch dass Variable genommen wird $query = mysql_query($sql)OR die(mysql_error()); while($topic = mysql_fetch_array( $query,MYSQL_BOTH )){ $this->topicName= $topic['topic']; $this->rawToPass=$topic['percentage']; $this->numOfQu=$topic['numOfQu']; } $this->setSession(); } function setInactiveTopic() { $sql="UPDATE topics SET active=".intval(0)." WHERE t_id=".intval($this->topicID).""; $ok= mysql_query($sql)OR die(mysql_error()); if (!$ok) { $error=mysql_errno() ; } } function setActiveTopic(){ $sql="UPDATE topics SET active=".intval(1)." WHERE t_id=".intval($this->topicID).""; $ok= mysql_query($sql)OR die(mysql_error()); if (!$ok){ $error=mysql_errno() ; } } function getNumOfQu (){ $sql ="SELECT numOfQu FROM topics WHERE t_id=".intval($this->topicID).""; // fehlt noch dass Variable genommen wird $query = mysql_query($sql)OR die(mysql_error()); $numOfQu = mysql_fetch_assoc($query); return $numOfQu ['numOfQu']; } function getrawToPass (){ $sql ="SELECT percentage FROM topics WHERE t_id=".intval($this->topicID).""; // fehlt noch dass Variable genommen wird $query = mysql_query($sql)OR die(mysql_error()); $rawToPass = mysql_fetch_assoc($query); return $rawToPass ['percentage']; } function setTopicID($t_id){ $this->topicID=$t_id; } function getTopicID(){ return $this->topicID; } function getTopicName(){ return $this->topicName ; } function saveTopic(){ if($this->topicName!=null && $this->numOfQu!=null &&$this->rawToPass!=null){ $sql = 'INSERT INTO topics (topic,active,numOfQu,percentage)VALUES ("'.mysql_real_escape_string($this->topicName).'","'.intval(1).'",'.intval($this->numOfQu).','.intval($this->rawToPass).') '; $ok= mysql_query($sql); if (!$ok){ $error=mysql_errno() ; if($error=='1062') return "existing"; } return "none"; } else return "missing"; } function getActiveTopic(){ $sql ='SELECT * FROM topics WHERE active="'.intval(1).'"'; $query = mysql_query($sql)OR die(mysql_error()); if(!$query){ // Wenn Fehler $error=mysql_errno() ; } else{ $i=1; while($topic =mysql_fetch_array($query,MYSQL_BOTH )){ $this->topics[$i]['t_id']=$topic['t_id']; // in arra speichern $this->topics[$i]['topic']=$topic['topic']; $this->topics[$i]['rawToPass']=$topic['percentage']; $this->topics[$i]['numOfQu']=$topic['numOfQu']; $i++; } } } function getTopic(){ $sql ='SELECT * FROM topics'; // fehlt noch dass Variable genommen wird $query = mysql_query($sql)OR die(mysql_error()); if(!$query) { // Wenn Fehler $error=mysql_errno() ; } else{ $i=1; while($topic =mysql_fetch_array($query,MYSQL_BOTH )){ $this->topics[$i]['t_id']=$topic['t_id']; // in arra speichern $this->topics[$i]['topic']=$topic['topic']; $this->topics[$i]['rawToPass']=$topic['percentage']; $this->topics[$i]['numOfQu']=$topic['numOfQu']; $this->topics[$i]['active']=$topic['active']; $i++; } } } function getTopicArray(){ // Liefert das Array mit den Topics zurück return $this->topics; } function setSession(){ $_SESSION['values']['topic']['t_id']= $this->topicID; $_SESSION['values']['topic']['topicName']= $this->topicName; $_SESSION['values']['topic']['numOfQu']=$this->numOfQu; $_SESSION['values']['topic']['rawToPass']=$this->rawToPass; } function unsetSession(){ unset($_SESSION['values']['topic']); } function showTopicTable($number){ // Topics in Tabelle anzeigen echo""; echo ""; echo""; echo""; echo""; echo""; echo" "; echo" "; echo" "; echo"\n"; for ($i=1;$i<=count($this->topics);$i++){ // Solange bis $ größer gleich Anzahl der Werte im Array echo ""; if($this->topics[$i]['active']==0) echo""; else echo""; echo""; // array Werte ausgeben echo""; echo""; echo""; if($this->topics[$i]['active']==0)echo""; else echo""; echo""; echo "\n"; } echo"
".Class_Topic_01." ".Class_Topic_02." ".Class_Topic_03." ".Class_Topic_04."
topics[$i]['t_id']."\">".stripslashes($this->topics[$i]['topic'])."topics[$i]['t_id']."\">".stripslashes($this->topics[$i]['topic'])."".$number[$i]."".$this->topics[$i]['numOfQu']." ".$this->topics[$i]['rawToPass']." % ".Class_Topic_05." ".Class_Topic_06." ".Class_Topic_07." ".Class_Topic_08."
"; } function newForm(){ echo "
"; $this->showForm(); } function updateForm(){ echo ""; $this->showForm(); } function showForm(){ // Form anzeigen um eine Formular zu erstellen if($this->error=='rawToPass')echo '
'.Class_Topic_09."
"; else if($this->error=='existing')echo '
'.Class_Topic_10."
"; else if($this->error=='numOfQu')echo '
'.Class_Topic_11."
"; echo "
"; echo " ".Button_01." "; echo""; echo""; echo""; echo""; if ($_SESSION['values']['topic']['topicName']==null && $this->error) { echo ""; } else { echo ""; } echo""; echo""; echo" "; echo""; if ($_SESSION['values']['topic']['numOfQu']==null && $this->error) { echo ""; } else { echo ""; } echo""; echo""; echo""; echo""; if ($_SESSION['values']['topic']['rawToPass']==null && $this->error) { echo ""; } else { echo ""; } echo""; echo""; echo""; echo""; echo" "; echo""; echo"
".Class_Topic_01." :
".Class_Topic_03." :
".Class_Topic_12." :
"; echo "
"; echo"
"; } function delTopic(){ // Frage ID's des Topics aus DB lesen $sqlGetQu=" SELECT q_id,qt_id,question,active FROM questions WHERE t_id =".intval($this->topicID)." ORDER BY q_id"; $queryGetQu = mysql_query($sqlGetQu)OR die(mysql_error()); $number=mysql_num_rows($queryGetQu ) ; if($number!=0){ while($questions =mysql_fetch_array($queryGetQu ,MYSQL_BOTH )){ // Antworten der Fragen löschen $sql_answers="DELETE FROM answers WHERE q_id=".intval($questions['q_id']).""; $query_answers = mysql_query($sql_answers); if (!$query_answers )$error=mysql_errno() ; } } // Fragen löschen $sql_question="DELETE FROM questions WHERE t_id=".intval($this->topicID).""; $ok_question=mysql_query($sql_question)OR die(mysql_error()); // Thema löschen $sql= "DELETE FROM topics WHERE t_id=".intval($this->topicID).""; $ok= mysql_query($sql)OR die(mysql_error()); // Lernfortschritte ebenfalls löschen $sql_del_lp="DELETE FROM learnprogress WHERE t_id=".intval($this->topicID).""; $ok_del_lp= mysql_query( $sql_del_lp)OR die(mysql_error()); if (!$ok) { $error=mysql_errno() ; } } function updateTopic(){ $sql=" UPDATE topics SET topic='".mysql_real_escape_string($this->topicName)."',numOfQu=".intval($this->numOfQu).",percentage= ".intval($this->rawToPass)." WHERE t_id=". intval($this->topicID).""; $ok= mysql_query( $sql); } } ?>