Index: Dev/trunk/classes/Question.php
===================================================================
--- Dev/trunk/classes/Question.php	(revision 97)
+++ Dev/trunk/classes/Question.php	(revision 98)
@@ -13,4 +13,5 @@
 class Question {
     public $id;
+    public $code;
     public $title;
     public $type;
@@ -18,7 +19,8 @@
     public $answers; // format answers['#']
     
-    public function __construct($id, $title, $type, $description = null)
+    public function __construct($id, $code, $title, $type, $description = null)
     {
         $this->id = $id;
+        $this->code = $code;
         $this->title = $title;
         $this->type = $type;
Index: Dev/trunk/classes/Survey.php
===================================================================
--- Dev/trunk/classes/Survey.php	(revision 97)
+++ Dev/trunk/classes/Survey.php	(revision 98)
@@ -48,9 +48,10 @@
         while (isset($info['questionTitle' . $numQ])) {
             $id = $info['questionID' . $numQ];
+            $code = $info['questionCode' . $numQ];
             $title = $info['questionTitle' . $numQ];
             $type = $info['questionType' . $numQ];
             $description = $info['questionDescription' . $numQ];
 
-            $question = new Question($id, $title, $type, $description);
+            $question = new Question($id, $code, $title, $type, $description);
 
             $numA = 1; //number answers
Index: Dev/trunk/classes/SurveyCreationTool.php
===================================================================
--- Dev/trunk/classes/SurveyCreationTool.php	(revision 97)
+++ Dev/trunk/classes/SurveyCreationTool.php	(revision 98)
@@ -35,29 +35,53 @@
         <script type="text/javascript" src="js/creation.js"></script>
         <script type="text/javascript">
-            /* autosave every 3 minutes */
-            setTimeout("save('<?php echo $id; ?>')", 180000);
-                                                                                                                                                                                                                                                                                                                    
+            /* autosave every 5 minutes */
+            setTimeout("save('<?php echo $id; ?>')", 300000);
+                                                                                                                                                                                                                                                                                                                            
             var questionCount = 1;          
-                                                                                                                                                                                                                                                                                                                                                                                                                                                            
-            function getNewQuestion(title, description)
-            {
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
+            function getNewQuestion(code, title, description)
+            {
+                if (code == null)
+                    var code = '';
+                        
                 if (title == null)
                     var title = 'Untitled Question';
-                                                                                                                                                                                                                                                        
+                                                                                                                                                                                                                                                                
                 if (description == null)
                     var description = 'Write a question description here.';
-                                                                                                                                                                                                                                         
+                                                                                                                                                                                                                                                 
                 var questionDiv = document.createElement("div");
                 questionDiv.id = "question" + questionCount;
                 questionDiv.className = "question";                                                                            
-                                                                                        
+                                                                                                
                 var questionTable = document.createElement("table");
                 questionTable.className = "questionTable";
-                                                                                        
+                                                                                                
                 var th = document.createElement("th");
                 th.innerHTML = "Question " + questionCount;
-                                                                                        
+
+                var row0 = document.createElement("tr");
+                        
+                var colCodeLabel = document.createElement("td");
+                var codeLabel = document.createElement("label");
+                codeLabel.setAttribute("for", "questionCode");
+                codeLabel.innerHTML = "Code";
+                colCodeLabel.appendChild(codeLabel);
+                        
+                var colCodeInput = document.createElement("td");
+                var codeInput = document.createElement("input");
+                codeInput.id = "questionCode";
+                codeInput.setAttribute("type", "text");
+                codeInput.className = "questionCode";
+                codeInput.setAttribute("name", "questionCode" + questionCount);
+                codeInput.setAttribute("size", "5");
+                codeInput.setAttribute("value", code);
+                colCodeInput.appendChild(codeInput);
+                        
+                row0.appendChild(colCodeLabel);
+                row0.appendChild(colCodeInput);
+
                 var row1 = document.createElement("tr");
-                                                                                        
+                                                                                                
                 var col1 = document.createElement("td");
                 var titleLabel = document.createElement("label");
@@ -65,5 +89,5 @@
                 titleLabel.innerHTML = "Title";
                 col1.appendChild(titleLabel);
-                                                                                
+                                                                                        
                 var col2 = document.createElement("td");
                 var titleInput = document.createElement("input");
@@ -79,5 +103,5 @@
                 row1.appendChild(col1);
                 row1.appendChild(col2);
-                                                                                
+                                                                                        
                 var row2 = document.createElement("tr");
                 var col3 = document.createElement("td");
@@ -86,5 +110,5 @@
                 descriptionLabel.innerHTML = "Description";
                 col3.appendChild(descriptionLabel);
-                                                                                
+                                                                                        
                 var col4 = document.createElement("td");
                 var descriptionInput = document.createElement("input");
@@ -93,11 +117,11 @@
                 descriptionInput.name = "questionDescription" + questionCount;
                 descriptionInput.setAttribute("onfocus", "handleFocus(this)");
-                descriptionInput.setAttribute("size", 60);
+                descriptionInput.setAttribute("size", 40);
                 descriptionInput.setAttribute("value", description);
                 col4.appendChild(descriptionInput);
-                                                                                
+                                                                                        
                 row2.appendChild(col3);
                 row2.appendChild(col4);
-                                                        
+                                                                
                 var row3 = document.createElement("tr");
                 var col5 = document.createElement("td");
@@ -106,5 +130,5 @@
                 typeLabel.innerHTML = "Type answer";
                 col5.appendChild(typeLabel);
-                                                        
+                                                                
                 var col6 = document.createElement("td");
                 var select = document.createElement("select");
@@ -118,25 +142,26 @@
                     "<option value='checkboxes'>Checkboxes</option>" +
                     "<option value='scale'>Scale</option>";
-                                                        
+                                                                
                 col6.appendChild(select);
-                                                        
+                                                                
                 row3.appendChild(col5);
                 row3.appendChild(col6);
-                                                        
+                                                                
                 questionTable.appendChild(th);
+                questionTable.appendChild(row0);
                 questionTable.appendChild(row1);
                 questionTable.appendChild(row2);
                 questionTable.appendChild(row3);                         
-                                                                
+                                                                        
                 var answerDiv = document.createElement("div");
                 answerDiv.id = "answersDiv" + questionCount;
                 answerDiv.className = "answersDiv";
-                                                                
+                                                                        
                 questionDiv.appendChild(questionTable);
                 questionDiv.appendChild(answerDiv);
-                                                                                                                                                                                                                                                                                                                                                                                                                                                        
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                
                 return questionDiv;
             }
-                                                                                                                                                                                                                                                                                                                                                                                                                                            
+                                                                                                                                                                                                                                                                                                                                                                                                                                                    
             function handleType(select, answers)
             {
@@ -144,10 +169,10 @@
                 var type = select.valueOf().value;
                 var answersDiv = document.getElementById("answersDiv" + numQ );
-                                                                                                                                                        
+                                                                                                                                                                
                 removeQuestionID(numQ);
-                                                                                                                                                        
+                                                                                                                                                                
                 answersDiv.answerCount = 1;
                 answersDiv.clicked = null;
-                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                        
                 switch (type) {
                     case 'mc':
@@ -162,5 +187,5 @@
                         else
                             addOption(numQ);
-                                                                                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                                                                        
                         break;
                     case 'text':
@@ -169,5 +194,5 @@
                     case 'int':    
                         answersDiv.innerHTML = "";
-                                                                                                                                                                                                                                                        
+                                                                                                                                                                                                                                                                
                         //min max
                         if (answers != null)
@@ -201,10 +226,10 @@
 
             }
-                                                                                                                                                    
+                                                                                                                                                            
             function handleAnswerChange(questionNumber)
             {
                 removeQuestionID(questionNumber);
             }
-                                                                                                                                                    
+                                                                                                                                                            
             function removeQuestionID(questionNumber)
             {
@@ -218,6 +243,6 @@
 
             }
-                                                                                                                                                             
-                                                                                                                                                                                                                                                                                                                                                                                                                    
+                                                                                                                                                                     
+                                                                                                                                                                                                                                                                                                                                                                                                                            
             function addOption(questionNumber, optionStr)
             {        
@@ -225,11 +250,11 @@
                 var answerCount = answersDiv.answerCount;
                 var answerDiv = document.createElement("div");
-                                                                                                                                                                                        
+                                                                                                                                                                                                
                 if (optionStr == null)
                     var optionStr = "Option " + answerCount;
-                                                                                                                                                                                        
-                                                                                                                                                                                       
+                                                                                                                                                                                                
+                                                                                                                                                                                               
                 answerDiv.className = "answerDiv";
-                                                          
+                                                                  
                 var answerInput = document.createElement("input");
                 answerInput.setAttribute("type", "text");
@@ -237,5 +262,5 @@
                 answerInput.setAttribute("onchange", "handleAnswerChange(" + questionNumber + ")");
                 answerInput.setAttribute("value", optionStr);
-                                
+                                        
                 answerDiv.appendChild(answerInput);
 
@@ -248,5 +273,5 @@
                     addOpt.setAttribute("onclick", "addOption(" + questionNumber + ")");
                     addOpt.setAttribute("value", "Add Option");
-                                    
+                                            
                     var removeOpt = document.createElement("input");
                     removeOpt.setAttribute("type", "button");
@@ -254,24 +279,24 @@
                     removeOpt.setAttribute("onclick", "removeOption(" + questionNumber + ")");
                     removeOpt.setAttribute("value", "x");
-                                    
+                                            
                     answerDiv.appendChild(addOpt);
                     answerDiv.appendChild(removeOpt);
-                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                        
                     answersDiv.clicked = true;
                 }
-                                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                        
                 answerDiv.prev = answersDiv.lastAnswer; //singly linked list
                 answersDiv.lastAnswer = answerDiv;
-                                                                                                                                                                                                                                                                                                                                                                                                                               
+                                                                                                                                                                                                                                                                                                                                                                                                                                       
                 answersDiv.appendChild(answerDiv);
                 answersDiv.answerCount++;
-                                                                                                                                                        
+                                                                                                                                                                
                 handleAnswerChange(questionNumber);
             }
-                                                                                                                                                                                                                                                                                                                                                            
+                                                                                                                                                                                                                                                                                                                                                                    
             function removeOption(questionNumber)
             {
                 var answersDiv = document.getElementById("answersDiv" + questionNumber);
-                                                                                                                                                                                                                                                                                                                                                               
+                                                                                                                                                                                                                                                                                                                                                                       
                 if (answersDiv.lastAnswer.prev != null)
                 {
@@ -280,8 +305,8 @@
                     answersDiv.answerCount--;
                 }
-                                                                                                                                                        
+                                                                                                                                                                
                 handleAnswerChange(questionNumber);
             }
-                                                                                                                                                                                                                                                                                                                                                                                    
+                                                                                                                                                                                                                                                                                                                                                                                            
             function minMax(questionNumber, min, max)
             {
@@ -290,16 +315,16 @@
                 if (max == null)
                     var max = '';
-                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                        
                 var answersDiv = document.getElementById("answersDiv" + questionNumber);
-                                                                                                                                                                                                                                                                                                                                                                                       
+                                                                                                                                                                                                                                                                                                                                                                                               
                 var answerDiv = document.createElement("div");
-                                                                                                                                                                                                                                                                                                                                                        
+                                                                                                                                                                                                                                                                                                                                                                
                 answerDiv.className = "answerDiv";
                 answerDiv.innerHTML = "<label for='min'>Min</label><input type='text' class='intBox' onchange='checkInt(this)' value='" + min + "' name='q" + questionNumber + "ans1' />" +
                     "<label for='max'>Max</label><input type='text' class='intBox' onchange='checkInt(this)' value='" + max + "' name='q" + questionNumber + "ans2' />";
-                                                                                                                                                                                                                                                                                                                                                                                   
+                                                                                                                                                                                                                                                                                                                                                                                           
                 answersDiv.appendChild(answerDiv);
             }  
-                                                                                                                                                                                                                                                                                                                                                                                    
+                                                                                                                                                                                                                                                                                                                                                                                            
             function minMaxIncr(questionNumber, left, right, incr)
             {
@@ -314,10 +339,10 @@
                 if (incr == null)
                     var incr = '';
-                                                                                                                                                                                                
+                                                                                                                                                                                                        
                 var answersDiv = document.getElementById("answersDiv" + questionNumber);
-                                                                                                                                                                                                                                                                                                                                                                                       
+                                                                                                                                                                                                                                                                                                                                                                                               
                 var answerDiv = document.createElement("div");
                 answerDiv.className = "answerDiv";
-                                                                                                                       
+                                                                                                                               
                 var leftLabel = document.createElement("label");
                 var rightLabel = document.createElement("label");
@@ -326,5 +351,5 @@
                 rightLabel.innerHTML = "Right label";
                 scaleLabel.innerHTML = "Scale count";
-                                                                                                                        
+                                                                                                                                
                 var leftInput = document.createElement("input");
                 leftInput.type = "text";
@@ -333,5 +358,5 @@
                 leftInput.setAttribute("onchange", "handleAnswerChange(" 
                     + questionNumber + ")");
-                                                                                                                        
+                                                                                                                                
                 var rightInput = document.createElement("input");
                 rightInput.type = "text";
@@ -340,5 +365,5 @@
                 rightInput.setAttribute("onchange", "handleAnswerChange(" 
                     + questionNumber + ")");
-                                                                                                                        
+                                                                                                                                
                 var scaleInput = document.createElement("input");
                 scaleInput.type = "text";
@@ -349,5 +374,5 @@
                     + questionNumber + ")");
                 scaleInput.name = "q" + questionNumber + "ans3";
-                                                                                                                        
+                                                                                                                                
                 answerDiv.appendChild(leftLabel);
                 answerDiv.appendChild(leftInput);
@@ -356,14 +381,13 @@
                 answerDiv.appendChild(scaleLabel);
                 answerDiv.appendChild(scaleInput);
-                                                                                                                                                                                                                                                                                                                                                                   
+                                                                                                                                                                                                                                                                                                                                                                           
                 answersDiv.appendChild(answerDiv);
             }         
-                                                                                                                                                                                                                                                                                                                                                                                                                                         
                                                                                                                                                                                                                                                                                                                                                                                                                                                  
-            function addQuestion(title, description)
+                                                                                                                                                                                                                                                                                                                                                                                                                                                         
+            function addQuestion(code, title, description)
             {
                 var questionsDiv = document.getElementById('questionsDiv');
-                var newQuestion = getNewQuestion(title, description);
-                                                                                                                                                                                                                                                                                                                                                                                
+                var newQuestion = getNewQuestion(code, title, description);
 
                 newQuestion.prev = document.lastQuestion;
@@ -373,10 +397,10 @@
                 questionCount++;
             }
-                                                                                                                                                                                                                                                                                                                                                                            
+                                                                                                                                                                                                                                                                                                                                                                                    
             function removeLastQuestion()
             {
                 var questionsDiv = document.getElementById('questionsDiv');
-                                                                                                                                                                                                                                                                                                                                                                                
-                if (document.lastQuestion.prev != null)
+                                                                                                                                                                                                                                                                                                                                                                                        
+                if (document.lastQuestion != null)
                 {
                     questionsDiv.removeChild(document.lastQuestion);
@@ -389,5 +413,5 @@
                 }               
             }
-                                                                                                                                                                                                                                                                                                                                                     
+                                                                                                                                                                                                                                                                                                                                                             
             function save(surveyID)
             {
@@ -397,5 +421,5 @@
                     var questionsDiv = document.getElementById('questionsDiv');
                     form.action = "surveycreation.php";
-                                                                                                                                                                                                                                                                                                                        
+                                                                                                                                                                                                                                                                                                                                
                     /* extra time stamp */
                     var date = new Date();
@@ -408,10 +432,10 @@
                     timeStampInput.value = timeStamp;
                     timeStampInput.type = "hidden";
-                                                                                                                                                                                                                                                                            
+                                                                                                                                                                                                                                                                                    
                     var surveyIDInput = document.createElement("input");
                     surveyIDInput.name = "surveyID";
                     surveyIDInput.value = surveyID;
                     surveyIDInput.type = "hidden";
-                                                                                                                                                                                                                                                                                                     
+                                                                                                                                                                                                                                                                                                             
                     questionsDiv.appendChild(timeStampInput);
                     questionsDiv.appendChild(surveyIDInput);
@@ -419,15 +443,15 @@
                 }
             }
-                                                                                                                                                    
+                                                                                                                                                            
             function selectAll(input)
             {
                 input.select();
             }
-                                                                                                                                                    
+                                                                                                                                                            
             /* --- input checking --- */
             function checksPassed()
             {
                 var form = document.getElementById('survey');
-                                                                                                                                
+                                                                                                                                        
                 for (var i = 0; i < form.length; i++)
                 {
@@ -437,5 +461,5 @@
                 return true;
             }
-                                                                                                                            
+                                                                                                                                    
             function checkInt(input)
             {
@@ -453,5 +477,5 @@
                 }
             }
-                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
         </script>
         <?php
@@ -528,12 +552,13 @@
                     echo 'answers[' . $numA . '] = "' . addslashes($answer) . '"; ';
                     ?> 
-                                                                                                                                                                                                                                                                  
+                                                                                                                                                                                                                                                                                      
                     <?php
                 }
                 ?>
-
+                    var code = "<?php echo addslashes($question->code); ?>";
                     var title = "<?php echo addslashes($question->title); ?>";
-                    addQuestion(title, "<?php echo addslashes($question->description); ?>");
-                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
+                    var description = "<?php echo addslashes($question->description); ?>";
+                    addQuestion(code, title, description);
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                     var select = document.getElementById('<?php echo $numQ; ?>');
                     var type = '<?php echo $question->type; ?>';
@@ -547,6 +572,6 @@
                         }
                     }      
-                                                                                                                                                                                                                                                                                                                    
-                                                                                                                                                                                                                                                                                                                    
+                                                                                                                                                                                                                                                                                                                                    
+                                                                                                                                                                                                                                                                                                                                    
                     /* questionID stuff */
                     var questionIDInput = document.createElement("input");
@@ -555,5 +580,5 @@
                     questionIDInput.value = "<?php echo $question->id; ?>";
                     questionIDInput.type = "hidden";
-                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
                     document.getElementById("questionsDiv").appendChild(questionIDInput);
 
