Index: Dev/trunk/classes/ApplicationDatabaseInterface.php
===================================================================
--- Dev/trunk/classes/ApplicationDatabaseInterface.php	(revision 90)
+++ Dev/trunk/classes/ApplicationDatabaseInterface.php	(revision 91)
@@ -63,11 +63,13 @@
 
         $resultApplication = $this->applicationRDFReader->readAllApplications();
-        
-        for($aNumber = 0;$aNumber<sizeof($resultApplication[0]);$aNumber++)
+        if($resultApplication[0] != false)
         {
-            $aID = $resultApplication[0][$aNumber]['?uid']->label;
-            $aTitle = $resultApplication[1][$aNumber]['?title']->label;
-            $applicationInfo[$aID] = $aTitle;
-        }		
+            for($aNumber = 0;$aNumber<sizeof($resultApplication[0]);$aNumber++)
+            {
+                $aID = $resultApplication[0][$aNumber]['?uid']->label;
+                $aTitle = $resultApplication[1][$aNumber]['?title']->label;
+                $applicationInfo[$aID] = $aTitle;
+            }
+        }
 
         return $applicationInfo;
Index: Dev/trunk/classes/DashboardCreationDatabaseInterface.php
===================================================================
--- Dev/trunk/classes/DashboardCreationDatabaseInterface.php	(revision 91)
+++ Dev/trunk/classes/DashboardCreationDatabaseInterface.php	(revision 91)
@@ -0,0 +1,17 @@
+<?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");
+
+class DashboardCreationDatabaseInterface
+{    
+    public function __construct()
+    {
+        
+    }
+}
+
+?>
Index: Dev/trunk/classes/DashboardRDFReader.php
===================================================================
--- Dev/trunk/classes/DashboardRDFReader.php	(revision 91)
+++ Dev/trunk/classes/DashboardRDFReader.php	(revision 91)
@@ -0,0 +1,38 @@
+<?php
+
+class DashboardRDFReader
+{
+    protected $model;
+
+    protected $dashboardID;
+    protected $filePath;
+
+    public function __construct($dashboardID)
+    {
+        // Create empty MemModel
+        $factory = new ModelFactory();
+        $this->model = $factory->getDefaultModel();
+
+        $this->dashboardID = $dashboardID;
+        $this->filePath = 'data/dashboards/dashboard_'.$this->dashboardID.'.rdf';
+    }
+    
+    public function loadDashboard()
+    {
+        if(file_exists($this->filePath))
+        {
+            $this->model->load($this->filePath);
+            return true;
+        }
+        else
+        {
+            return false;
+        }
+    }
+    
+    public function getDashboardInfo()
+    {
+        
+    }
+}
+?>
Index: Dev/trunk/classes/DashboardRDFWriter.php
===================================================================
--- Dev/trunk/classes/DashboardRDFWriter.php	(revision 91)
+++ Dev/trunk/classes/DashboardRDFWriter.php	(revision 91)
@@ -0,0 +1,80 @@
+<?php
+
+class SurveyRDFWriter 
+{
+    protected $model;
+
+    protected $resourceDashboard;
+    protected $dashboardID;
+
+    protected $filePath;
+
+    public function __construct($dashboardID)
+    {
+        // Create empty MemModel
+        $factory = new ModelFactory();
+        $this->model = $factory->getDefaultModel();
+
+        $this->dashboardID = $dashboardID;	
+        $this->filePath = 'data/dashboards/';
+        if (!is_dir($this->filePath))
+            mkdir($this->filePath);	
+    }	
+
+    public function saveDashboard()
+    {	
+        $this->model->saveAs($this->filePath.'dashboard_'.$this->dashboardID.'.rdf','rdf');
+    }
+    
+    public function createDashboard($dTitle, $dDescription,$dRespondentGroup)
+    {
+        $this->resourceDashboard = new Resource(DASHBOARD.'/'.$this->dashboardID);
+
+        $resourceDashboardType = new Resource(DASHBOARD);
+        $predicateRType = new Resource(RTYPE);
+        $this->model->add(new Statement($this->resourceDashboard,$predicateRType,$resourceDashboardType));
+
+        $literalDashboardID = new Literal($this->dashboardID);
+        $predicateUniqueID = new Resource(UID);
+        $this->model->add(new Statement($this->resourceDashboard,$predicateUniqueID,$literalDashboardID));
+
+        $predicateTitle = new Resource(TITLE);		
+        $dashboardTitle = new Literal($dTitle);
+        $this->model->add(new Statement($this->resourceDashboard,$predicateTitle,$dashboardTitle));		
+
+        $predicateDescription = new Resource(DESCRIPTION);
+        $dashboardDescription = new Literal($dDescription);
+        $this->model->add(new Statement($this->resourceDashboard,$predicateDescription,$dashboardDescription));
+    }
+    
+    public function addGraph($gTitle,$gDescription,$gTypes,$gData)
+    {
+        $resourceGraph = new Resource(GRAPH);
+        
+        $predicateTitle = new Resource(TITLE);		
+        $graphTitle = new Literal($gTitle);
+        $this->model->add(new Statement($resourceGraph,$predicateTitle,$graphTitle));		
+
+        $predicateDescription = new Resource(DESCRIPTION);
+        $graphDescription = new Literal($gDescription);
+        $this->model->add(new Statement($resourceGraph,$predicateDescription,$graphDescription));
+        
+        $predicateGraphType = new Resource(GRAPH_TYPE);
+        foreach($gTypes as $gType)
+        {
+            $graphType = new Literal($gType);
+            $this->model->add(new Statement($resourceGraph,$predicateGraphType,$gType));
+        }
+        
+        $predicateData = new Resource(DATA);
+        foreach($gData as $gThis)
+        {
+            $graphData = new Literal($gThis);
+            $this->model->add(new Statement($resourceGraph,$predicateData,$graphData));
+        }
+        
+        $predicateHasGraph = new Resource(HAS_GRAPH);
+        $this->model->add(new Statement($this->resourceDashboard,$predicateHasGraph,$resourceGraph));
+    }
+}
+?>
Index: Dev/trunk/classes/QuestionRDFReader.php
===================================================================
--- Dev/trunk/classes/QuestionRDFReader.php	(revision 90)
+++ Dev/trunk/classes/QuestionRDFReader.php	(revision 91)
@@ -69,4 +69,30 @@
         return $result; 
     }
+    
+    public function readQuestionCodes()
+    {
+        $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 	?questionCode
+            WHERE 
+            {	
+                    _question	predicates:resource_type	resources:question ;
+                                predicates:question_code        ?questionCode				
+            }';
+            
+            $result = $tempmodel->sparqlQuery($querystring);
+        }
+        return $result; 
+    }
 
     public function readQuestionTitle($questionID)
Index: Dev/trunk/classes/SurveyAnswerDatabaseInterface.php
===================================================================
--- Dev/trunk/classes/SurveyAnswerDatabaseInterface.php	(revision 90)
+++ Dev/trunk/classes/SurveyAnswerDatabaseInterface.php	(revision 91)
@@ -5,6 +5,4 @@
 // Include RAP Library to write RDF files
 include(RDFAPI_INCLUDE_DIR . "RDFAPI.php");
-
-
 
 class SurveyAnswerDatabaseInterface extends SurveyCreationDatabaseInterface
Index: Dev/trunk/classes/SurveyCreationDatabaseInterface.php
===================================================================
--- Dev/trunk/classes/SurveyCreationDatabaseInterface.php	(revision 90)
+++ Dev/trunk/classes/SurveyCreationDatabaseInterface.php	(revision 91)
@@ -94,7 +94,15 @@
         }
         
-        if(!$this->checkQuestionIDExists($qID))
-        {
+        if($this->checkQuestionCodeExists($qCode))
+        {
+            return 'Question code (' . $qCode . ') already in use. Please try a new code.';
+        }
+        else if($this->checkQuestionIDExists($qID))
+        {
+            return 'Question already exists';
+        }
+        else {
             $this->questionRDFWriter->createQuestion($qTitle,$qDescription,$qType,$qID,"null","null",$qAnswers);
+            return 'Question saved';
         }
     }
@@ -201,4 +209,26 @@
         return $result;
     }
+    
+    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/SurveyCreationTool.php
===================================================================
--- Dev/trunk/classes/SurveyCreationTool.php	(revision 90)
+++ Dev/trunk/classes/SurveyCreationTool.php	(revision 91)
@@ -15,6 +15,4 @@
         $this->survey = $survey;
         $this->timeStamp = $timeStamp;
-        var_dump($_POST);
-        var_dump($survey);
         if (isset($this->survey->id))
             SurveyCreationTool::javascript($this->survey->id);
Index: Dev/trunk/classes/SurveyRDFReader.php
===================================================================
--- Dev/trunk/classes/SurveyRDFReader.php	(revision 90)
+++ Dev/trunk/classes/SurveyRDFReader.php	(revision 91)
@@ -20,5 +20,13 @@
     public function loadSurvey()
     {
-        $this->model->load($this->filePath);
+        if(file_exists($this->filePath))
+        {
+            $this->model->load($this->filePath);
+            return true;
+        }
+        else
+        {
+            return false;
+        }
     }
 
Index: Dev/trunk/doc/TODO
===================================================================
--- Dev/trunk/doc/TODO	(revision 90)
+++ Dev/trunk/doc/TODO	(revision 91)
@@ -11,4 +11,5 @@
     Load existing question
     Question code
+    Question category
 
 Application Load / Edit
Index: Dev/trunk/rdfConstants.php
===================================================================
--- Dev/trunk/rdfConstants.php	(revision 90)
+++ Dev/trunk/rdfConstants.php	(revision 91)
@@ -10,17 +10,17 @@
 
 // Resource used for RDF triples
+define('USER',SURVEYTOOL_RESOURCES_NAMESPACE . 'user');
 define('SURVEY',SURVEYTOOL_RESOURCES_NAMESPACE . 'survey');
+define('QUESTION',SURVEYTOOL_RESOURCES_NAMESPACE . 'question');
 define('APPLICATION',SURVEYTOOL_RESOURCES_NAMESPACE . 'application');
 define('SESSION',SURVEYTOOL_RESOURCES_NAMESPACE . 'session');
 define('DASHBOARD',SURVEYTOOL_RESOURCES_NAMESPACE . 'dashboard');
-define('USER',SURVEYTOOL_RESOURCES_NAMESPACE . 'user');
-define('QUESTION',SURVEYTOOL_RESOURCES_NAMESPACE . 'question');
-define('ANSWER',SURVEYTOOL_RESOURCES_NAMESPACE . 'answer');
+define('GRAPH',SURVEYTOOL_RESOURCES_NAMESPACE . 'graph');
 
 // Predicates used for RDF triples
 define('UID',SURVEYTOOL_PREDICATES_NAMESPACE . 'uid');
-define('CREATOR',SURVEYTOOL_PREDICATES_NAMESPACE . 'creator');
 define('NAME',SURVEYTOOL_PREDICATES_NAMESPACE . 'name');
 define('PASSWORD',SURVEYTOOL_PREDICATES_NAMESPACE . 'password');
+define('CREATOR',SURVEYTOOL_PREDICATES_NAMESPACE . 'creator');
 define('TITLE',SURVEYTOOL_PREDICATES_NAMESPACE . 'title');
 define('DESCRIPTION',SURVEYTOOL_PREDICATES_NAMESPACE . 'description');
@@ -30,11 +30,14 @@
 define('QTYPE',SURVEYTOOL_PREDICATES_NAMESPACE . 'question_type');
 define('QCODE',SURVEYTOOL_PREDICATES_NAMESPACE . 'question_code');
+define('ANSWERED',SURVEYTOOL_PREDICATES_NAMESPACE . 'answered');
+define('RESPONDENT',SURVEYTOOL_PREDICATES_NAMESPACE . 'respondent');
 define('QCATEGORY',SURVEYTOOL_PREDICATES_NAMESPACE . 'question_category');
 define('HAS_QUESTION',SURVEYTOOL_PREDICATES_NAMESPACE . 'has_question');
 define('HAS_ANSWER',SURVEYTOOL_PREDICATES_NAMESPACE . 'has_answer');
-define('ANSWERED',SURVEYTOOL_PREDICATES_NAMESPACE . 'answered');
-define('RESPONDENT',SURVEYTOOL_PREDICATES_NAMESPACE . 'respondent');
+define('HAS_GRAPH',SURVEYTOOL_PREDICATES_NAMESPACE . 'has_graph');
 define('HAS_PROCESS',SURVEYTOOL_PREDICATES_NAMESPACE . 'has_process');
 define('INDEX',SURVEYTOOL_PREDICATES_NAMESPACE . 'index');
+define('GRAPH_TYPE',SURVEYTOOL_PREDICATES_NAMESPACE . 'graph_type');
+define('DATA',SURVEYTOOL_PREDICATES_NAMESPACE . 'data');
 
 ?>
Index: Dev/trunk/sessioncreation.php
===================================================================
--- Dev/trunk/sessioncreation.php	(revision 90)
+++ Dev/trunk/sessioncreation.php	(revision 91)
@@ -4,6 +4,4 @@
 if (is_null($_SESSION['username']))
     redirect('index.php');
-
-var_dump($_POST);
 
 /* LOAD SURVEY */
