Index: Dev/trunk/classes/SurveyCreationDatabaseInterface.php
===================================================================
--- Dev/trunk/classes/SurveyDatabaseInterface.php	(revision 80)
+++ Dev/trunk/classes/SurveyCreationDatabaseInterface.php	(revision 82)
@@ -12,5 +12,6 @@
     protected $surveyRDFWriter;
     protected $surveyRDFReader;
-
+    protected $questionRDFWriter;
+    protected $questionRDFReader;
 
     public function __construct($surveyID)
@@ -23,7 +24,9 @@
         $this->surveyRDFWriter = new SurveyRDFWriter($surveyUID);
         $this->surveyRDFReader = new SurveyRDFReader($surveyUID);
+        $this->questionRDFWriter = new QuestionRDFWriter();
+        $this->questionRDFReader = new QuestionRDFReader();
     }
 
-    public function setSurveyInfo($survey)
+    public function setSurveyInfo($survey,$user)
     {
         $sTitle = $survey['surveyTitle'];
@@ -32,5 +35,5 @@
         $this->surveyRDFWriter->createSurvey($sTitle,$sDescription);
 
-        $sUserID = "Creator";
+        $sUserID = $user['username'];
 
         $this->surveyRDFWriter->setUserData($sUserID);
@@ -59,5 +62,9 @@
             }
 
-            $this->surveyRDFWriter->addQuestion($qTitle,$qDescription,$qType,$qID,$qAnswers);
+            if(!$this->checkQuestionIDExists($qID))
+            {
+                $this->questionRDFWriter->createQuestion($qTitle,$qDescription,$qType,$qID,"null","null",$qAnswers);
+            }            
+            $this->surveyRDFWriter->addQuestion($qID);
 
             $qNumber++;
@@ -65,4 +72,5 @@
 
         $this->surveyRDFWriter->saveSurvey();
+        $this->questionRDFWriter->saveQuestions();
     }
 
@@ -71,29 +79,45 @@
         $surveyInfo = array();
 
+        $this->questionRDFReader->loadQuestions();
+        
         $resultSurvey = $this->surveyRDFReader->getSurveyInfo();
+        
+        $surveyInfo['surveyID'] = $resultSurvey['info'][0]['?uid']->label;
+        $surveyInfo['surveyTitle'] = $resultSurvey['info'][0]['?title']->label;
+        $surveyInfo['surveyDescription'] = $resultSurvey['info'][0]['?description']->label;
+        $surveyInfo['surveyCreator'] = $resultSurvey['info'][0]['?creator']->label;
+        $surveyQuestionIDs = $resultSurvey['questionIDs'];
+        
+        if($surveyQuestionIDs != false)
+        {
+            $qNumber = 1;
+            foreach($surveyQuestionIDs as $qID)
+            {
+                $questionID = $qID['?questionID']->label;
+                $surveyInfo['questionID'.$qNumber] = $questionID;
 
-        $surveyInfo['surveyID'] = substr($resultSurvey[0][0]['?uid'],9,strlen($resultSurvey[0][0]['?uid'])-11);
-        $surveyInfo['surveyTitle'] = substr($resultSurvey[0][0]['?title'],9,strlen($resultSurvey[0][0]['?title'])-11);
-        $surveyInfo['surveyDescription'] = substr($resultSurvey[0][0]['?description'],9,strlen($resultSurvey[0][0]['?description'])-11);
-        $surveyInfo['surveyCreator'] = substr($resultSurvey[0][0]['?creator'],9,strlen($resultSurvey[0][0]['?creator'])-11);
+                $questionTitleObject = $this->questionRDFReader->readQuestionTitle($questionID);
+                $surveyInfo['questionTitle'.$qNumber] = $questionTitleObject[0]['?questionTitle']->label;
 
-        for($qNumber = 1;$qNumber<=sizeof($resultSurvey[1][0]);$qNumber++)
-        {
-            $surveyInfo['questionID'.$qNumber] = substr($resultSurvey[1][3][$qNumber-1]['?questionID'],9,strlen($resultSurvey[1][3][$qNumber-1]['?questionID'])-11);
-            $surveyInfo['questionTitle'.$qNumber] = substr($resultSurvey[1][0][$qNumber-1]['?questionTitle'],9,strlen($resultSurvey[1][0][$qNumber-1]['?questionTitle'])-11);
-            $surveyInfo['questionDescription'.$qNumber] = substr($resultSurvey[1][1][$qNumber-1]['?questionDescription'],9,strlen($resultSurvey[1][1][$qNumber-1]['?questionDescription'])-11);
-            $surveyInfo['questionType'.$qNumber] = substr($resultSurvey[1][2][$qNumber-1]['?questionType'],9,strlen($resultSurvey[1][2][$qNumber-1]['?questionType'])-11);
+                $questionDescriptionObject = $this->questionRDFReader->readQuestionDescription($questionID);
+                $surveyInfo['questionDescription'.$qNumber] = $questionDescriptionObject[0]['?questionDescription']->label;
 
-            $resultAnswers = $this->surveyRDFReader->readSurveyAnswers($surveyInfo['questionID'.$qNumber]);
+                $questionTypeObject = $this->questionRDFReader->readQuestionType($questionID);
+                $surveyInfo['questionType'.$qNumber] = $questionTypeObject[0]['?questionType']->label;
 
-            if ($resultAnswers != null)
-            {
-                for($aNumber = 1;$aNumber<=sizeof($resultAnswers);$aNumber++)
+                $resultAnswers = $this->questionRDFReader->readQuestionAnswers($questionID);
+
+                if ($resultAnswers != null)
                 {
-                    $surveyInfo['q'.$qNumber.'ans'.$aNumber] = substr($resultAnswers[$aNumber-1]['?answerDescription'],9,strlen($resultAnswers[$aNumber-1]['?answerDescription'])-11);
+                    for($aNumber = 1;$aNumber<=sizeof($resultAnswers);$aNumber++)
+                    {
+                        $surveyInfo['q'.$qNumber.'ans'.$aNumber] = $resultAnswers[$aNumber-1]['?answerDescription']->label;
+                    }
                 }
+                $resultAnswers = null;
+                $qNumber++;
             }
         }
-
+        
         return $surveyInfo;
     }
@@ -111,9 +135,9 @@
             }
         }
-
+        
         foreach($surveyIDs as $surveyID)
         {
             $surveyTitle = $this->surveyRDFReader->getSurveyTitleByID($surveyID);
-            $surveys[$surveyID] = substr($surveyTitle[0]['?title'],9,strlen($surveyTitle[0]['?title'])-11);
+            $surveys[$surveyID] = $surveyTitle[0]['?title']->label;
         }
 
@@ -124,9 +148,32 @@
     {
         $surveyTitleLiteral = $this->surveyRDFReader->getSurveyTitleByID($surveyID);
-        $surveyTitle = substr($surveyTitle[0]['?title'],9,strlen($surveyTitle[0]['?title'])-11);
+        $surveyTitle = $surveyTitle[0]['?title']->label;
         
         return $surveyTitle;
     }
 
+    
+    
+    public function checkQuestionIDExists($qID)
+    {
+        $result = false;
+
+        $questionIDs = $this->questionRDFReader->readQuestionIDs();
+        
+        if ($questionIDs != null)
+        {
+            foreach($questionIDs as $questionID)
+            {
+                $id = $questionID['?questionID']->label;
+                if(!strcmp($id ,$qID))
+                {
+                    $result = true;
+                    break;
+                }
+            }
+        }
+
+        return $result;
+    }
 }
 ?>
