Index: Dev/trunk/classes/QuestionCreationTool.php
===================================================================
--- Dev/trunk/classes/QuestionCreationTool.php	(revision 114)
+++ Dev/trunk/classes/QuestionCreationTool.php	(revision 115)
@@ -7,6 +7,6 @@
  */
 class QuestionCreationTool {
+
     private $questions;
-    private $questionEditPanel;
 
     public function __construct($questions) {
@@ -24,8 +24,8 @@
                 var type = select.valueOf().value;
                 clearSpecifications();
-                                                                        
+                                                                                
                 /* set answerCount for options */
                 document.getElementById("answerSpecifications").answerCount = 1;
-                                                                        
+                                                                                
                 switch (type) {
                     case "text":
@@ -44,10 +44,10 @@
                         break;
                     default:
-                                                                                
+                                                                                        
                         break;
                 }
 
             }
-                                                                    
+                                                                            
             function clearSpecifications()
             {
@@ -56,5 +56,5 @@
                 specs.clicked = null;
                 specs.lastAnswer = null;
-                                                        
+                                                                
                 var questionType = document.getElementById("questionType");
                 var buttons = document.getElementById("questionButtons");
@@ -62,18 +62,18 @@
                     questionType.removeChild(buttons);
             }
-                                                                    
+                                                                            
             function addOption()
             {                       
                 var specs = document.getElementById("answerSpecifications");
-                                                                        
+                                                                                
                 addAddRemoveOptionButtonsOnce(specs);
                 addAnswerInput(specs);
-                                                                        
-            }
-                                                                    
+                                                                                
+            }
+                                                                            
             function removeOption()
             {
                 var specs = document.getElementById("answerSpecifications");
-                                                                        
+                                                                                
                 if(specs.lastAnswer.prev != null)
                 {
@@ -83,12 +83,12 @@
                 }
             }
-                                                                    
+                                                                            
             function addAnswerInput(specs)
             {
                 var answerCount = specs.answerCount;
-                                                                        
+                                                                                
                 /* set value for option textbox */
                 var optionStr = "Option " + answerCount;
-                                                                        
+                                                                                
                 /* the input textbox */
                 var answerInput = document.createElement("input");
@@ -97,14 +97,14 @@
                 answerInput.setAttribute("value", optionStr);
                 answerInput.className = "answerInput";
-                                                                        
+                                                                                
                 specs.appendChild(answerInput);
-                                                                        
+                                                                                
                 /* Singly linked list */
                 answerInput.prev = specs.lastAnswer; // remember last one
                 specs.lastAnswer = answerInput; // new lastAnswer
-                                                                        
+                                                                                
                 specs.answerCount++;               
             }
-                                                                    
+                                                                            
             function addAddRemoveOptionButtonsOnce(specs)
             {
@@ -116,12 +116,12 @@
                     var typeBox = document.getElementById("questionType");
                     typeBox.appendChild(buttonsDiv);
-                                                            
+                                                                    
                     addAddOptionButton(buttonsDiv);                                  
                     addRemoveOptionButton(buttonsDiv);
-                                                                            
+                                                                                    
                     specs.clicked = true;
                 }
             }
-                                                                    
+                                                                            
             function addAddOptionButton(buttonsDiv)
             {    
@@ -134,5 +134,5 @@
                 buttonsDiv.appendChild(addOpt);                                  
             }
-                                                                    
+                                                                            
             function addRemoveOptionButton(buttonsDiv)
             {
@@ -144,5 +144,5 @@
                 buttonsDiv.appendChild(removeOpt);
             }
-                                                                   
+                                                                           
             function minMax(min, max)
             {
@@ -151,16 +151,16 @@
                 if (max == null)
                     var max = '';
-                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                        
                 var specs = document.getElementById("answerSpecifications");
-                                                                                                                                                                                                                                                                                                                                                                                                                                       
+                                                                                                                                                                                                                                                                                                                                                                                                                                               
                 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='ans1' />" +
                     "<label for='max'>Max</label><input type='text' class='intBox' onchange='checkInt(this)' value='" + max + "' name='ans2' />";
-                                                                                                                                                                                                                                                                                                                                                                                                                                   
+                                                                                                                                                                                                                                                                                                                                                                                                                                           
                 specs.appendChild(answerDiv);
             }      
-                                            
+                                                    
             function checkInt(input)
             {
@@ -178,5 +178,5 @@
                 }
             }
-                            
+                                    
             function minMaxIncr(left, right, incr)
             {
@@ -191,10 +191,10 @@
                 if (incr == null)
                     var incr = '';
-                                                                                                                                                                                                                        
+                                                                                                                                                                                                                                
                 var specs = document.getElementById("answerSpecifications");
-                                                                                                                                                                                                                                                                                                                                                                                                               
+                                                                                                                                                                                                                                                                                                                                                                                                                       
                 var answerDiv = document.createElement("div");
                 answerDiv.className = "answerDiv";
-                                                                                                                                               
+                                                                                                                                                       
                 var leftLabel = document.createElement("label");
                 var rightLabel = document.createElement("label");
@@ -203,5 +203,5 @@
                 rightLabel.innerHTML = "Right label";
                 scaleLabel.innerHTML = "Scale count";
-                                                                                                                                                
+                                                                                                                                                        
                 var leftInput = document.createElement("input");
                 leftInput.type = "text";
@@ -209,5 +209,5 @@
                 leftInput.name= "ans1";
                 leftInput.setAttribute("onchange", "handleAnswerChange()");
-                                                                                                                                                
+                                                                                                                                                        
                 var rightInput = document.createElement("input");
                 rightInput.type = "text";
@@ -215,5 +215,5 @@
                 rightInput.name = "ans2";
                 rightInput.setAttribute("onchange", "handleAnswerChange()");
-                                                                                                                                                
+                                                                                                                                                        
                 var scaleInput = document.createElement("input");
                 scaleInput.type = "text";
@@ -223,5 +223,5 @@
                 scaleInput.setAttribute("onchange", "");
                 scaleInput.name = "ans3";
-                                                                                                                                                
+                                                                                                                                                        
                 answerDiv.appendChild(leftLabel);
                 answerDiv.appendChild(leftInput);
@@ -230,19 +230,19 @@
                 answerDiv.appendChild(scaleLabel);
                 answerDiv.appendChild(scaleInput);
-                                                                                                                                                                                                                                                                                                                                                                                           
+                                                                                                                                                                                                                                                                                                                                                                                                   
                 specs.appendChild(answerDiv);
             }   
-            
+                    
             function newCategory()
             {
                 var categoryBox = document.getElementById("categoryBox");
                 categoryBox.innerHTML = "";
-                
+                        
                 var categoryInput = document.createElement("input");
                 categoryInput.name = "questionCategory";
-                
+                        
                 categoryBox.appendChild(categoryInput);
             }
-                       
+                               
             function clearFields()
             {
@@ -253,14 +253,14 @@
                 clearType();
             }
-            
+                    
             function clearCategory()
             {
                 var categoryBox = document.getElementById("categoryBox");
                 categoryBox.innerHTML = "";
-                
+                        
                 var questionCategorySelect = document.createElement("select");
                 questionCategorySelect.setAttribute("name", "questionCategory");
                 questionCategorySelect.id = "questionCategorySelect";
-                
+                        
                 var newCategoryButton = document.createElement("input");
                 newCategoryButton.setAttribute("type", "button");
@@ -268,9 +268,9 @@
                 newCategoryButton.setAttribute("value", "New Category");
                 newCategoryButton.className = "surveyButton";
-                
+                        
                 categoryBox.appendChild(questionCategorySelect);
                 categoryBox.appendChild(newCategoryButton);
             }
-            
+                    
             function clearCode()
             {
@@ -278,5 +278,5 @@
                 codeInput.value = "";
             }
-            
+                    
             function clearTitle()
             {
@@ -284,5 +284,5 @@
                 titleInput.value ="";
             }
-            
+                    
             function clearDescription()
             {
@@ -290,5 +290,5 @@
                 descriptionInput.value = "";
             }
-            
+                    
             function clearType()
             {
@@ -297,5 +297,5 @@
                 clearSpecifications();
             }
-            
+                    
         </script>
         <?php
@@ -306,5 +306,5 @@
         <div id="questionListWrapper">
             <select id="questionsList" size="9999">
-                <?php $this->populateList(); ?>
+        <?php $this->populateList(); ?>
             </select>
         </div>
@@ -315,5 +315,5 @@
         ?>
         <div id="questionCreation" class="floatLeft">
-            <?php $this->displayForm(); ?>
+        <?php $this->displayForm(); ?>
         </div>
         <?php
@@ -327,9 +327,5 @@
                     <td><label for="questionCategory">Category</label></td>
                     <td id="categoryBox"><!-- Select should be filled with existing categories-->
-                        <select id="questionCategorySelect" name="questionCategory">
-                            <option value='Uncategorized' selected='selected'>Uncategorized</option>
-                        </select>
-                        <!-- New category button -->
-                        <input type="button" class="surveyButton" onclick="newCategory()" value="New Category" />
+        <?php $this->questionCategorySelect(); ?>
                     </td>
                 </tr>
@@ -365,17 +361,46 @@
         <?php
     }
+
+    private function questionCategorySelect() {
+        ?>
+        <select id="questionCategorySelect" name="questionCategory">
+            <option value='Uncategorized' selected='selected'>Uncategorized</option>
+            <?php $this->generateCategoryOptions(); ?>
+        </select>
+        <!-- New category button -->
+        <input type="button" class="surveyButton" onclick="newCategory()" value="New Category" />
+        <?php
+    }
     
-    private function populateList()
+    private function generateCategoryOptions()
     {
-        foreach ($this->questions as $question)
-        {
+        $categories = array();
+        
+        foreach ($this->questions as $question) {
+            $category = $question->category;
+            if (! array_search($category, $categories)) // if not in categories
+            {
+                array_push($categories, $category);
+            }
+        }
+        
+        // You might want to escape quotes and stuff here
+        foreach ($categories as $category) {
             ?>
-        <option value="<?php echo $question->code; ?>">
-        <?php echo $question->code . " - " . $question->title; ?>
-        </option>
+        <option value="<?php echo $category;?>"><?php echo $category; ?></option> 
         <?php
         }
     }
 
-}
-?>
+    private function populateList() {
+        foreach ($this->questions as $question) {
+            ?>
+            <option value="<?php echo $question->code; ?>">
+            <?php echo $question->code . " - " . $question->title; ?>
+            </option>
+                <?php
+            }
+        }
+
+    }
+    ?>
Index: Dev/trunk/questioncreation.php
===================================================================
--- Dev/trunk/questioncreation.php	(revision 114)
+++ Dev/trunk/questioncreation.php	(revision 115)
@@ -9,5 +9,4 @@
 
 $questions = Loader::loadFullQuestions();
-var_dump($questions);
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
