Index: /Dev/trunk/classes/SurveyCreationTool.php
===================================================================
--- /Dev/trunk/classes/SurveyCreationTool.php	(revision 70)
+++ /Dev/trunk/classes/SurveyCreationTool.php	(revision 71)
@@ -15,5 +15,6 @@
         $this->survey = $survey;
         $this->timeStamp = $timeStamp;
-
+        var_dump($_POST);
+        var_dump($survey);
         if (isset($this->survey->id))
             SurveyCreationTool::javascript($this->survey->id);
@@ -38,17 +39,22 @@
             /* autosave every 3 minutes */
             setTimeout("save('<?php echo $id; ?>')", 180000);
-                                                                                                                                                                                                            
+                                                                                                                                                                                                                                            
             var questionCount = 1;          
-                                                                                                                                                                                                                                                                                                                                                    
+                                                                                                                                                                                                                                                                                                                                                                                    
             function getNewQuestion(title, description)
             {
                 if (title == null)
                     var title = 'Untitled Question';
-                                                                                                                                                
+                else {
+                    title.replace("'", "&#39;");
+                }
+                                                                                                                                                                                
                 if (description != null)
-                    var description = description;
+                {
+                    description.replace("'", "&#39;");
+                }
                 else
                     var description = 'Write a question description here.';
-                                                                                                                                                                    
+                                                                                                                                                                 
                 var questionDiv = document.createElement("div");
                 var htmlStr = 
@@ -57,5 +63,5 @@
                     "<th>Question " + questionCount + "</th>" +
                     "<tr><td><label for='questionTitle'>Title</label></td>" + 
-                    "<td><input type='text' class='questionTitle' name='questionTitle" + questionCount + "' onfocus='handleFocus(this)' size='30' value='" + title + "' /></td></tr>" +
+                    "<td><input id='questionTitle' type='text' class='questionTitle' name='questionTitle" + questionCount + "' onfocus='handleFocus(this)' size='30' /></td></tr>" +
                     "<tr><td><label for='questionDescription'>Description</label></td>" + 
                     "<td><input type='text' class='questionDescription' name='questionDescription" + questionCount + "' onfocus='handleFocus(this)' size='60' value='" + description + "' /></td>" +
@@ -71,10 +77,12 @@
                     "<div id='answersDiv" + questionCount + "' class='answersDiv'></div>" +
                     "</div>";
-                                                                                                                                                                                                                                                                                                                                                
+                
+                /* TODO: get rid of innerHTML bullshit and do dynamically so that &#39; will work */
+                            
                 questionDiv.innerHTML = htmlStr;
-                                                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                                                
                 return questionDiv;
             }
-                                                                                                                                                                                                                                                                                                                                    
+                                                                                                                                                                                                                                                                                                                                                                    
             function handleType(select, answers)
             {
@@ -82,10 +90,10 @@
                 var type = select.valueOf().value;
                 var answersDiv = document.getElementById("answersDiv" + numQ );
-                                                
+                                                                                
                 removeQuestionID(numQ);
-                                                
+                                                                                
                 answersDiv.answerCount = 1;
                 answersDiv.clicked = null;
-                                                                                                                                                                                                                                                                                        
+                                                                                                                                                                                                                                                                                                                        
                 switch (type) {
                     case 'mc':
@@ -100,5 +108,5 @@
                         else
                             addOption(numQ);
-                                                                                                                                                                                                                                                                                                                        
+                                                                                                                                                                                                                                                                                                                                                        
                         break;
                     case 'text':
@@ -107,5 +115,5 @@
                     case 'int':    
                         answersDiv.innerHTML = "";
-                                                                                                                                                
+                                                                                                                                                                                
                         //min max
                         if (answers != null)
@@ -139,10 +147,10 @@
 
             }
-                                            
+                                                                            
             function handleAnswerChange(questionNumber)
             {
                 removeQuestionID(questionNumber);
             }
-                                            
+                                                                            
             function removeQuestionID(questionNumber)
             {
@@ -156,6 +164,6 @@
 
             }
-                                                     
-                                                                                                                                                                                                                                                                                                            
+                                                                                     
+                                                                                                                                                                                                                                                                                                                                            
             function addOption(questionNumber, optionStr)
             {        
@@ -163,14 +171,14 @@
                 var answerCount = answersDiv.answerCount;
                 var answerDiv = document.createElement("div");
-                                                                                
+                                                                                                                
                 if (optionStr == null)
                     var optionStr = "Option " + answerCount;
-                                                                                
-                                                                               
+                                                                                                                
+                                                                                                               
                 answerDiv.className = "answerDiv";
-                                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                                                
                 var htmlStr = "<input type='text' name='q" + 
                     questionNumber + "ans" + answerCount + "' onchange='handleAnswerChange(" + questionNumber + ")' value='" + optionStr + "' />";
-                                                                                                                                                                                                                                                                                        
+                                                                                                                                                                                                                                                                                                                        
                 if (answersDiv.clicked == null)
                 {
@@ -178,23 +186,23 @@
                         + " class='surveyButton' onclick='addOption(" + questionNumber + ")' value='Add Option' />" +
                         "<input type='button' class='surveyButton' onclick='removeOption(" + questionNumber + ")' value='x' />";
-                                                                                                                                                                                                                                                            
+                                                                                                                                                                                                                                                                                            
                     answersDiv.clicked = true;
                 }
-                                                                                                                                                                                                                                                                                                                       
+                                                                                                                                                                                                                                                                                                                                                       
                 answerDiv.innerHTML = htmlStr;
-                                                                                                                                                                                                                                                        
+                                                                                                                                                                                                                                                                                        
                 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)
                 {
@@ -203,8 +211,8 @@
                     answersDiv.answerCount--;
                 }
-                                                
+                                                                                
                 handleAnswerChange(questionNumber);
             }
-                                                                                                                                                                                                                                                                            
+                                                                                                                                                                                                                                                                                                            
             function minMax(questionNumber, min, max)
             {
@@ -213,43 +221,79 @@
                 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)
             {
                 if (left == null)
                     var left = '';
+                else
+                    left.replace("'", "&#39;");
                 if (right == null)
                     var right = '';
+                else
+                    right.replace("'", "&#39;");
                 if (incr == null)
                     var incr = '';
-                                                                                        
+                                                                                                                        
                 var answersDiv = document.getElementById("answersDiv" + questionNumber);
-                                                                                                                                                                                                                                                                               
+                                                                                                                                                                                                                                                                                                               
                 var answerDiv = document.createElement("div");
                 answerDiv.className = "answerDiv";
-                answerDiv.innerHTML = "<label>Left label</label><input type='text' value='" + left + "' onchange='handleAnswerChange(" + questionNumber + ")' name='q" + questionNumber + "ans1' />" +
-                    "<label>Right label</label><input type='text' value='" + right + "' onchange='handleAnswerChange(" + questionNumber + ")' name='q" + questionNumber + "ans2' />" +
-                    "<label>Scale count</label><input type='text' class='intBox' value='" + incr + "' onblur='checkInt(this)' onchange='handleAnswerChange(" + questionNumber + ")' name='q" + questionNumber + "ans3' />" +
-                    "<div id='inputCheckFeedback'" + questionNumber + "";
-                                                                                                                                                                                                                                                                           
+                                               
+                var leftLabel = document.createElement("label");
+                var rightLabel = document.createElement("label");
+                var scaleLabel = document.createElement("label");
+                leftLabel.innerHTML = "Left label";
+                rightLabel.innerHTML = "Right label";
+                scaleLabel.innerHTML = "Scale count";
+                                                
+                var leftInput = document.createElement("input");
+                leftInput.type = "text";
+                leftInput.value = left;
+                leftInput.name= "q" + questionNumber + "ans1";
+                leftInput.setAttribute("onchange", "handleAnswerChange(" 
+                    + questionNumber + ")");
+                                                
+                var rightInput = document.createElement("input");
+                rightInput.type = "text";
+                rightInput.value = right;
+                rightInput.name = "q" + questionNumber + "ans2";
+                rightInput.setAttribute("onchange", "handleAnswerChange(" 
+                    + questionNumber + ")");
+                                                
+                var scaleInput = document.createElement("input");
+                scaleInput.type = "text";
+                scaleInput.className = "intBox";
+                scaleInput.value = incr;
+                scaleInput.setAttribute("onblur", "checkInt(this)");
+                scaleInput.setAttribute("onchange", "handleAnswerChange(" 
+                    + questionNumber + ")");
+                                                
+                answerDiv.appendChild(leftLabel);
+                answerDiv.appendChild(leftInput);
+                answerDiv.appendChild(rightLabel);
+                answerDiv.appendChild(rightInput);
+                answerDiv.appendChild(scaleLabel);
+                answerDiv.appendChild(scaleInput);
+                                                                                                                                                                                                                                                                                           
                 answersDiv.appendChild(answerDiv);
             }         
-                                                                                                                                                                                                                                                                                                                                 
-                                                                                                                                                                                                                                                                                                                                         
+                                                                                                                                                                                                                                                                                                                                                                 
+                                                                                                                                                                                                                                                                                                                                                                         
             function addQuestion(title, description)
             {
                 var questionsDiv = document.getElementById('questionsDiv');
                 var newQuestion = getNewQuestion(title, description);
-                                                                                                                                                                                                                                                                        
+                                                                                                                                                                                                                                                                                                        
 
                 newQuestion.prev = document.lastQuestion;
@@ -259,9 +303,9 @@
                 questionCount++;
             }
-                                                                                                                                                                                                                                                                    
+                                                                                                                                                                                                                                                                                                    
             function removeLastQuestion()
             {
                 var questionsDiv = document.getElementById('questionsDiv');
-                                                                                                                                                                                                                                                                        
+                                                                                                                                                                                                                                                                                                        
                 if (document.lastQuestion.prev != null)
                 {
@@ -275,5 +319,5 @@
                 }               
             }
-                                                                                                                                                                                                                                             
+                                                                                                                                                                                                                                                                             
             function save(surveyID)
             {
@@ -283,5 +327,5 @@
                     var questionsDiv = document.getElementById('questionsDiv');
                     form.action = "surveycreation.php";
-                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                
                     /* extra time stamp */
                     var date = new Date();
@@ -294,10 +338,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);
@@ -305,15 +349,15 @@
                 }
             }
-                                            
+                                                                            
             function selectAll(input)
             {
                 input.select();
             }
-                                            
+                                                                            
             /* --- input checking --- */
             function checksPassed()
             {
                 var form = document.getElementById('survey');
-                        
+                                                        
                 for (var i = 0; i < form.length; i++)
                 {
@@ -323,5 +367,5 @@
                 return true;
             }
-                    
+                                                    
             function checkInt(input)
             {
@@ -339,5 +383,5 @@
                 }
             }
-                                                                                                                                                                                                                                                                                                                                                                                                                              
+                                                                                                                                                                                                                                                                                                                                                                                                                                                              
         </script>
         <?php
@@ -412,10 +456,13 @@
                 /* Put all answers in js array */
                 foreach ($question->answers as $numA => $answer) {
-                    echo "answers[" . $numA . "] = '" . $answer . "'; ";
+                    echo 'answers[' . $numA . '] = "' . $answer . '"; ';
+                    ?> 
+                                                                              
+                    <?php
                 }
                 ?>
-                                                                                                                                                                    
-                    addQuestion('<?php echo $question->title; ?>', '<?php echo $question->description; ?>');
-                                                                                                                                                                                                                                                                    
+                    var title = "<?php echo $question->title; ?>";
+                    addQuestion(title, "<?php echo $question->description; ?>");
+                                                                                                                                                                                                                                                                                                                                    
                     var select = document.getElementById('<?php echo $numQ; ?>');
                     var type = '<?php echo $question->type; ?>';
@@ -425,10 +472,10 @@
                         {
                             select.options[i].selected = true;
-                            handleType(select, answers)
+                            handleType(select, answers);
                             break;
                         }
                     }      
-                                                                                                    
-                                                                                                    
+                                                                                                                                                                    
+                                                                                                                                                                    
                     /* questionID stuff */
                     var questionIDInput = document.createElement("input");
@@ -437,5 +484,5 @@
                     questionIDInput.value = "<?php echo $question->id; ?>";
                     questionIDInput.type = "hidden";
-                                                                                                                                                                                                                                                     
+                                                                                                                                                                                                                                                                                                                     
                     document.getElementById("questionsDiv").appendChild(questionIDInput);
 
