Index: Dev/trunk/classes/DashboardCreationDatabaseInterface.php
===================================================================
--- Dev/trunk/classes/DashboardCreationDatabaseInterface.php	(revision 104)
+++ Dev/trunk/classes/DashboardCreationDatabaseInterface.php	(revision 105)
@@ -46,7 +46,17 @@
             while(isset($dashboard['g'.$gNumber.'type'.$tNumber]))
             {
-                
+                $gTypes[] = $dashboard['g'.$gNumber.'type'.$tNumber];
+                $tNumber++;
             }
-            
+            $gData = array();
+            $dNumber = 1;
+            while(isset($dashboard['g'.$dNumber.'datatype'.$tNumber]) && isset($dashboard['g'.$gNumber.'dataid'.$dNumber]))
+            {
+                $dData = array();
+                $dData['type'] = $dashboard['g'.$gNumber.'datatype'.$dNumber];
+                $dData['id'] = $dashboard['g'.$gNumber.'dataid'.$dNumber];
+                $gData[] = $dData;
+                $dNumber++;
+            }
         }
     }
Index: Dev/trunk/classes/QuestionCreationDatabaseInterface.php
===================================================================
--- Dev/trunk/classes/QuestionCreationDatabaseInterface.php	(revision 105)
+++ Dev/trunk/classes/QuestionCreationDatabaseInterface.php	(revision 105)
@@ -0,0 +1,115 @@
+<?php
+
+
+// Survey database interface class as intermediate for storing data from the site to the RDF database 
+require_once 'rdfConstants.php';
+
+// Include RAP Library to write RDF files
+include(RDFAPI_INCLUDE_DIR . "RDFAPI.php");
+
+/**
+ * Description of QuestionCreationDatabaseInterface
+ *
+ * @author basvannuland
+ */
+class QuestionCreationDatabaseInterface {
+   
+    protected $questionRDFWriter;
+    protected $questionRDFReader;
+    
+    public function __construct()
+    {
+        $this->questionRDFWriter = new QuestionRDFWriter();
+        $this->questionRDFReader = new QuestionRDFReader();
+    }
+    
+    public function setQuestionInfo($question)
+    {
+        $qCode = $question['questionCode'.$qNumber];
+        $qTitle = $question['questionTitle'.$qNumber];
+        $qDescription = $question['questionDescription'.$qNumber];
+        $qType = $question['questionType'.$qNumber];
+
+        $qAnswers = array();
+        $aNumber = 1;
+        while (isset($question['ans'.$aNumber]))
+        {
+            $qAnswers[] = $question['ans'.$aNumber];
+
+            $aNumber++;
+        }
+
+        if($this->checkQuestionCodeExists($qCode))
+        {
+            return 'Question code (' . $qCode . ') already in use. Please try a new code.';
+        }
+        else {
+            $this->questionRDFWriter->createQuestion($qTitle,$qDescription,$qType,$qCode,"null",$qAnswers);
+            return 'Question saved';
+        }
+        $this->questionRDFWriter->saveQuestions();          
+    }
+    
+    public function getQuestionInfo($qCode)
+    {
+        $questionInfo - array();
+        
+        $questionTitleObject = $this->questionRDFReader->readQuestionTitle($qCode);
+        $questionInfo['questionTitle'] = $questionTitleObject[0]['?questionTitle']->label;
+
+        $questionDescriptionObject = $this->questionRDFReader->readQuestionDescription($qCode);
+        $questionInfo['questionDescription'] = $questionDescriptionObject[0]['?questionDescription']->label;
+
+        $questionTypeObject = $this->questionRDFReader->readQuestionType($qCode);
+        $questionInfo['questionType'] = $questionTypeObject[0]['?questionType']->label;
+
+        $resultAnswers = $this->questionRDFReader->readQuestionAnswers($qCode);
+
+        if ($resultAnswers != null)
+        {
+            for($aNumber = 1;$aNumber<=sizeof($resultAnswers);$aNumber++)
+            {
+                $questionInfo['ans'.$aNumber] = $resultAnswers[$aNumber-1]['?answerDescription']->label;
+            }
+        }
+    }
+    
+    public function getExistingQuestions()
+    {
+        $questions = array();
+
+        $resultQuestions = $this->questionRDFReader->readQuestionCodes();
+        foreach ($resultQuestions as $questionCodeObject)
+        {
+            $questionCode = $questionCodeObject[0]['?questionCode']->label;
+            $questionTitle = $this->questionRDFReader->readQuestionTitle($questionCode);
+            $questions[$questionCode] = $questionTitle[0]['?questionTitle']->label;
+        }
+
+        return $questions;
+    }
+    
+    public function checkQuestionCodeExists($qCode)
+    {
+        $result = false;
+
+        $questionCodes = $this->questionRDFReader->readQuestionCodes();
+        
+        if ($questionCodes != null)
+        {
+            foreach($questionCodes as $questionCode)
+            {
+                $code = $questionCode['?questionCode']->label;
+                if(!strcmp($code ,$qCode))
+                {
+                    $result = true;
+                    break;
+                }
+            }
+        }
+
+        return $result;
+    }
+}
+
+?>
Index: Dev/trunk/classes/QuestionRDFReader.php
===================================================================
--- Dev/trunk/classes/QuestionRDFReader.php	(revision 104)
+++ Dev/trunk/classes/QuestionRDFReader.php	(revision 105)
@@ -31,43 +31,17 @@
     }
     
-    public function readQuestionByID($questionID)
+    public function readQuestionByCode($questionCode)
     {        
         $result = array();
-        $result['title'] = $this->readQuestionTitle($questionID);				
-        $result['description'] = $this->readQuestionDescription($questionID);
-        $result['type'] = $this->readQuestionType($questionID);
-        $result['code'] = $this->readQuestionCode($questionID);
-        $result['category'] = $this->readQuestionCategory($questionID);
-        $result['answers'] = $this->readQuestionAnswers($questionID);
+        $result['title'] = $this->readQuestionTitle($questionCode);				
+        $result['description'] = $this->readQuestionDescription($questionCode);
+        $result['type'] = $this->readQuestionType($questionCode);
+        $result['code'] = $this->readQuestionCode($questionCode);
+        $result['category'] = $this->readQuestionCategory($questionCode);
+        $result['answers'] = $this->readQuestionAnswers($questionCode);
 
         return $result;
     }
-    
-    public function readQuestionIDs()
-    {
-        $result = null;
-        
-        if(file_exists($this->filePath.'questions.rdf'))
-        {
-            // Create empty MemModel
-            $factory = new ModelFactory();
-            $tempmodel= $factory->getDefaultModel();
-            $tempmodel->load($this->filePath.'questions.rdf');
-
-            $querystring = '
-            PREFIX 	predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
-            PREFIX	resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
-            SELECT 	?questionID
-            WHERE 
-            {	
-                    _question	predicates:resource_type	resources:question ;
-                                predicates:uid			?questionID				
-            }';
-            
-            $result = $tempmodel->sparqlQuery($querystring);
-        }
-        return $result; 
-    }
-    
+     
     public function readQuestionCodes()
     {
@@ -96,5 +70,5 @@
     }
 
-    public function readQuestionTitle($questionID)
+    public function readQuestionTitle($questionCode)
     {
         $querystring = '
@@ -103,7 +77,7 @@
             SELECT  ?questionTitle
             WHERE 
-            {	
+            {
                     _question	predicates:resource_type	resources:question ;
-                                predicates:uid			"' . $questionID . '"  ;
+                                predicates:question_code    "' . $questionCode . '"  ;
                                 predicates:title		?questionTitle 		
             }';
@@ -114,5 +88,5 @@
     }
 
-    public function readQuestionDescription($questionID)
+    public function readQuestionDescription($questionCode)
     {
         $querystring = '
@@ -123,5 +97,5 @@
             {	
                     _question	predicates:resource_type	resources:question ;
-                                predicates:uid			"' . $questionID . '"  ;
+                                predicates:question_code        "' . $questionCode . '"  ;
                                 predicates:description		?questionDescription 		
             }';
@@ -132,5 +106,5 @@
     }
 
-    public function readQuestionType($questionID)
+    public function readQuestionType($questionCode)
     {
         $querystring = '
@@ -141,5 +115,5 @@
             {	
                     _question	predicates:resource_type	resources:question ;
-                                predicates:uid			"' . $questionID . '"  ;
+                                predicates:question_code	"' . $questionCode . '"  ;
                                 predicates:question_type	?questionType				
             }';
@@ -149,24 +123,6 @@
         return $result;
     }
-    
-    public function readQuestionCode($questionID)
-    {
-        $querystring = '
-            PREFIX  predicates: <' . SURVEYTOOL_PREDICATES_NAMESPACE . '>
-            PREFIX  resources: <' . SURVEYTOOL_RESOURCES_NAMESPACE . '>
-            SELECT  ?questionCode
-            WHERE 
-            {	
-                    _question	predicates:resource_type	resources:question ;
-                                predicates:uid			"' . $questionID . '"  ;
-                                predicates:question_code	?questionCode				
-            }';
-
-        $result = $this->model->sparqlQuery($querystring);
-
-        return $result;
-    }
-    
-    public function readQuestionCategory($questionID)
+        
+    public function readQuestionCategory($questionCode)
     {
         $querystring = '
@@ -177,5 +133,5 @@
             {	
                     _question	predicates:resource_type	resources:question ;
-                                predicates:uid			"' . $questionID . '"  ;
+                                predicates:question_code	"' . $questionCode . '"  ;
                                 predicates:question_category	?questionCategory				
             }';
@@ -186,5 +142,5 @@
     }
 
-    public function readQuestionAnswers($questionID)
+    public function readQuestionAnswers($questionCode)
     {
         $querystring = '
@@ -195,5 +151,5 @@
             {
                     _question	predicates:resource_type	resources:question ;
-                                predicates:uid			"' . $questionID . '"  ;
+                                predicates:question_code	"' . $questionCode . '"  ;
                                 predicates:has_answer		?answerDescription
             }';
Index: Dev/trunk/classes/QuestionRDFWriter.php
===================================================================
--- Dev/trunk/classes/QuestionRDFWriter.php	(revision 104)
+++ Dev/trunk/classes/QuestionRDFWriter.php	(revision 105)
@@ -24,7 +24,7 @@
     }
     
-    public function createQuestion($qTitle,$qDescription,$qType,$qID,$qCode,$qCategory,$qAnswers)
+    public function createQuestion($qTitle,$qDescription,$qType,$qCode,$qCategory,$qAnswers)
     {
-        $resourceQuestion = new Resource(QUESTION.'/'.$qID);
+        $resourceQuestion = new Resource(QUESTION.'/'.$qCode);
 
         $resourceQuestionType = new Resource(QUESTION);
@@ -43,8 +43,4 @@
         $resourceQuestionType = new Literal($qType);
         $this->model->add(new Statement($resourceQuestion,$predicateQType,$resourceQuestionType));
-
-        $predicateUniqueID = new Resource(UID);
-        $questionUID = new Literal($qID);
-        $this->model->add(new Statement($resourceQuestion,$predicateUniqueID,$questionUID));
         
         $predicateQCode = new Resource(QCODE);
Index: Dev/trunk/classes/SurveyCreationDatabaseInterface.php
===================================================================
--- Dev/trunk/classes/SurveyCreationDatabaseInterface.php	(revision 104)
+++ Dev/trunk/classes/SurveyCreationDatabaseInterface.php	(revision 105)
@@ -40,28 +40,8 @@
 
         $qNumber = 1;
-        while (isset($survey['questionTitle'.$qNumber]))
+        while (isset($survey['questionCode'.$qNumber]))
         {
-            $qTitle = $survey['questionTitle'.$qNumber];
-            $qDescription = $survey['questionDescription'.$qNumber];
-            $qType = $survey['questionType'.$qNumber];
-            if (isset($survey['questionID'.$qNumber]))
-                $qID = $survey['questionID'.$qNumber];
-            else
-                $qID = md5( uniqid(rand(), true) );
-
-            $qAnswers = array();
-            $aNumber = 1;
-            while (isset($survey['q'.$qNumber.'ans'.$aNumber]))
-            {
-                $qAnswers[] = $survey['q'.$qNumber.'ans'.$aNumber];
-
-                $aNumber++;
-            }
-
-            if(!$this->checkQuestionIDExists($qID))
-            {
-                $this->questionRDFWriter->createQuestion($qTitle,$qDescription,$qType,$qID,"null","null",$qAnswers);
-            }            
-            $this->surveyRDFWriter->addQuestion($qID);
+            $qCode = $survey['questionCode'.$qNumber];          
+            $this->surveyRDFWriter->addQuestion($qCode);
 
             $qNumber++;
@@ -74,20 +54,14 @@
     public function saveQuestion($questionInfo)
     {
-        $qTitle = $survey['questionTitle'.$qNumber];
-        $qDescription = $survey['questionDescription'.$qNumber];
-        $qType = $survey['questionType'.$qNumber];
-        if (isset($survey['questionID'.$qNumber]))
-            $qID = $survey['questionID'.$qNumber];
-        else
-            $qID = md5( uniqid(rand(), true) );
+        $qCode = $question['questionCode'.$qNumber];
+        $qTitle = $question['questionTitle'.$qNumber];
+        $qDescription = $question['questionDescription'.$qNumber];
+        $qType = $question['questionType'.$qNumber];
 
         $qAnswers = array();
         $aNumber = 1;
-        while (isset($survey['q'.$qNumber.'ans'.$aNumber]))
+        while (isset($question['ans'.$aNumber]))
         {
-            $aArray = array();
-            $aArray['Title'] = 'q'.$qNumber.'ans'.$aNumber;
-            $aArray['Description'] = $survey['q'.$qNumber.'ans'.$aNumber];
-            $qAnswers[] = $aArray;
+            $qAnswers[] = $question['ans'.$aNumber];
 
             $aNumber++;
@@ -98,10 +72,7 @@
             return 'Question code (' . $qCode . ') already in use. Please try a new code.';
         }
-        else if($this->checkQuestionIDExists($qID))
+        else 
         {
-            return 'Question already exists';
-        }
-        else {
-            $this->questionRDFWriter->createQuestion($qTitle,$qDescription,$qType,$qID,"null","null",$qAnswers);
+            $this->questionRDFWriter->createQuestion($qTitle,$qDescription,$qType,$qCode,"null",$qAnswers);
             return 'Question saved';
         }
@@ -178,4 +149,19 @@
     }
     
+    public function getExistingQuestions()
+    {
+        $questions = array();
+
+        $resultQuestions = $this->questionRDFReader->readQuestionCodes();
+        foreach ($resultQuestions as $questionCodeObject)
+        {
+            $questionCode = $questionCodeObject[0]['?questionCode']->label;
+            $questionTitle = $this->questionRDFReader->readQuestionTitle($questionCode);
+            $questions[$questionCode] = $questionTitle[0]['?questionTitle']->label;
+        }
+
+        return $questions;
+    }
+    
     public function getSurveyTitleByID($surveyID)
     {
@@ -184,28 +170,4 @@
         
         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;
     }
     
