Index: Dev/trunk/classes/ApplicationCreationTool.php
===================================================================
--- Dev/trunk/classes/ApplicationCreationTool.php	(revision 71)
+++ Dev/trunk/classes/ApplicationCreationTool.php	(revision 72)
@@ -49,5 +49,5 @@
             $value = 'Untitled Application';
         ?>
-        <input type="text" id="applicationTitle" class="titleBox" name="applicationTitle" value="<?php echo $value; ?>" onblur="handleBlur(this)" onfocus="handleFocus(this)" />
+        <input type="text" id="applicationTitle" class="titleBox" name="applicationTitle" value="<?php echo str_replace("\"", "&quot;", $value); ?>" onblur="handleBlur(this)" onfocus="handleFocus(this)" />
         <?php
     }
Index: Dev/trunk/classes/SessionCreationTool.php
===================================================================
--- Dev/trunk/classes/SessionCreationTool.php	(revision 71)
+++ Dev/trunk/classes/SessionCreationTool.php	(revision 72)
@@ -152,5 +152,5 @@
             $value = 'Untitled Session';
         ?>
-        <input type="text" id="sessionTitle" class="titleBox" name="sessionTitle" value="<?php echo $value; ?>" onblur="handleBlur(this)" onfocus="handleFocus(this)" />
+        <input type="text" id="sessionTitle" class="titleBox" name="sessionTitle" value="<?php echo str_replace("\"", "&quot;", $value); ?>" onblur="handleBlur(this)" onfocus="handleFocus(this)" />
         <?php
     }
Index: Dev/trunk/classes/SurveyCreationTool.php
===================================================================
--- Dev/trunk/classes/SurveyCreationTool.php	(revision 71)
+++ Dev/trunk/classes/SurveyCreationTool.php	(revision 72)
@@ -39,50 +39,106 @@
             /* 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)
-                {
-                    description.replace("'", "&#39;");
-                }
-                else
+                                                                                                                                                                                                                                                        
+                if (description == null)
                     var description = 'Write a question description here.';
-                                                                                                                                                                 
+                                                                                                                                                                                                                                         
                 var questionDiv = document.createElement("div");
-                var htmlStr = 
-                    "<div id='question" + questionCount + "' class='question'>" +
-                    "<table class='questionTable'>" +
-                    "<th>Question " + questionCount + "</th>" +
-                    "<tr><td><label for='questionTitle'>Title</label></td>" + 
-                    "<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>" +
-                    "<tr><td><label for='questionType'>Answer type</label></td>" + 
-                    "<td><select id='" + questionCount + "' name='questionType" + questionCount + "' onchange='handleType(this)'><br />"+
+                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 row1 = document.createElement("tr");
+                                                                                        
+                var col1 = document.createElement("td");
+                var titleLabel = document.createElement("label");
+                titleLabel.setAttribute("for", "questionTitle");
+                titleLabel.innerHTML = "Title";
+                col1.appendChild(titleLabel);
+                                                                                
+                var col2 = document.createElement("td");
+                var titleInput = document.createElement("input");
+                titleInput.id = "questionTitle";
+                titleInput.setAttribute("type", "text");
+                titleInput.className = "questionTitle";
+                titleInput.setAttribute("name", "questionTitle"  + questionCount);
+                titleInput.setAttribute("onfocus", "handleFocus(this)");
+                titleInput.setAttribute("size", "30");
+                titleInput.setAttribute("value", title);
+                col2.appendChild(titleInput);                        
+
+                row1.appendChild(col1);
+                row1.appendChild(col2);
+                                                                                
+                var row2 = document.createElement("tr");
+                var col3 = document.createElement("td");
+                var descriptionLabel = document.createElement("label");
+                descriptionLabel.setAttribute("for", "questionDescription");
+                descriptionLabel.innerHTML = "Description";
+                col3.appendChild(descriptionLabel);
+                                                                                
+                var col4 = document.createElement("td");
+                var descriptionInput = document.createElement("input");
+                descriptionInput.type = "text";
+                descriptionInput.className = "questionDescription";
+                descriptionInput.name = "questionDescription" + questionCount;
+                descriptionInput.setAttribute("onfocus", "handleFocus(this)");
+                descriptionInput.setAttribute("size", 60);
+                descriptionInput.setAttribute("value", description);
+                col4.appendChild(descriptionInput);
+                                                                                
+                row2.appendChild(col3);
+                row2.appendChild(col4);
+                                                        
+                var row3 = document.createElement("tr");
+                var col5 = document.createElement("td");
+                var typeLabel = document.createElement("label");
+                typeLabel.setAttribute("for", "questionType");
+                typeLabel.innerHTML = "Type answer";
+                col5.appendChild(typeLabel);
+                                                        
+                var col6 = document.createElement("td");
+                var select = document.createElement("select");
+                select.id = questionCount;
+                select.setAttribute("name", "questionType" + questionCount);
+                select.setAttribute("onchange", "handleType(this)");
+                select.innerHTML = 
                     "<option value='text' selected='selected'>Text</option>" +
                     "<option value='int'>Integer</option>" +
                     "<option value='mc'>Multiple choice</option>" +
                     "<option value='checkboxes'>Checkboxes</option>" +
-                    "<option value='scale'>Scale</option>" +
-                    "</select></td></tr>" +
-                    "</table>" +
-                    "<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;
-                                                                                                                                                                                                                                                                                                                                                                                
+                    "<option value='scale'>Scale</option>";
+                                                        
+                col6.appendChild(select);
+                                                        
+                row3.appendChild(col5);
+                row3.appendChild(col6);
+                                                        
+                questionTable.appendChild(th);
+                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)
             {
@@ -90,10 +146,10 @@
                 var type = select.valueOf().value;
                 var answersDiv = document.getElementById("answersDiv" + numQ );
-                                                                                
+                                                                                                                                                        
                 removeQuestionID(numQ);
-                                                                                
+                                                                                                                                                        
                 answersDiv.answerCount = 1;
                 answersDiv.clicked = null;
-                                                                                                                                                                                                                                                                                                                        
+                                                                                                                                                                                                                                                                                                                                                                                                
                 switch (type) {
                     case 'mc':
@@ -108,5 +164,5 @@
                         else
                             addOption(numQ);
-                                                                                                                                                                                                                                                                                                                                                        
+                                                                                                                                                                                                                                                                                                                                                                                                                                
                         break;
                     case 'text':
@@ -115,5 +171,5 @@
                     case 'int':    
                         answersDiv.innerHTML = "";
-                                                                                                                                                                                
+                                                                                                                                                                                                                                                        
                         //min max
                         if (answers != null)
@@ -147,10 +203,10 @@
 
             }
-                                                                            
+                                                                                                                                                    
             function handleAnswerChange(questionNumber)
             {
                 removeQuestionID(questionNumber);
             }
-                                                                            
+                                                                                                                                                    
             function removeQuestionID(questionNumber)
             {
@@ -164,6 +220,6 @@
 
             }
-                                                                                     
-                                                                                                                                                                                                                                                                                                                                            
+                                                                                                                                                             
+                                                                                                                                                                                                                                                                                                                                                                                                                    
             function addOption(questionNumber, optionStr)
             {        
@@ -171,38 +227,53 @@
                 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");
+                answerInput.setAttribute("name", "q" + questionNumber + "ans" + answerCount);
+                answerInput.setAttribute("onchange", "handleAnswerChange(" + questionNumber + ")");
+                answerInput.setAttribute("value", optionStr);
+                                
+                answerDiv.appendChild(answerInput);
+
+                if (answersDiv.clicked == null)
+                {
+                    var addOpt = document.createElement("input");
+                    addOpt.setAttribute("type", "button");
+                    addOpt.setAttribute("id", "addOpt");
+                    addOpt.setAttribute("class", "surveyButton");
+                    addOpt.setAttribute("onclick", "addOption(" + questionNumber + ")");
+                    addOpt.setAttribute("value", "Add Option");
+                                    
+                    var removeOpt = document.createElement("input");
+                    removeOpt.setAttribute("type", "button");
+                    removeOpt.className = "surveyButton";
+                    removeOpt.setAttribute("onclick", "removeOption(" + questionNumber + ")");
+                    removeOpt.setAttribute("value", "x");
+                                    
+                    answerDiv.appendChild(addOpt);
+                    answerDiv.appendChild(removeOpt);
                                                                                                                                                                                                                                                                                                                                                 
-                var htmlStr = "<input type='text' name='q" + 
-                    questionNumber + "ans" + answerCount + "' onchange='handleAnswerChange(" + questionNumber + ")' value='" + optionStr + "' />";
-                                                                                                                                                                                                                                                                                                                        
-                if (answersDiv.clicked == null)
-                {
-                    htmlStr += "<input type='button' id='addOpt'"
-                        + " 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)
                 {
@@ -211,8 +282,8 @@
                     answersDiv.answerCount--;
                 }
-                                                                                
+                                                                                                                                                        
                 handleAnswerChange(questionNumber);
             }
-                                                                                                                                                                                                                                                                                                            
+                                                                                                                                                                                                                                                                                                                                                                                    
             function minMax(questionNumber, min, max)
             {
@@ -221,16 +292,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)
             {
@@ -245,10 +316,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");
@@ -257,5 +328,5 @@
                 rightLabel.innerHTML = "Right label";
                 scaleLabel.innerHTML = "Scale count";
-                                                
+                                                                                                                        
                 var leftInput = document.createElement("input");
                 leftInput.type = "text";
@@ -264,5 +335,5 @@
                 leftInput.setAttribute("onchange", "handleAnswerChange(" 
                     + questionNumber + ")");
-                                                
+                                                                                                                        
                 var rightInput = document.createElement("input");
                 rightInput.type = "text";
@@ -271,5 +342,5 @@
                 rightInput.setAttribute("onchange", "handleAnswerChange(" 
                     + questionNumber + ")");
-                                                
+                                                                                                                        
                 var scaleInput = document.createElement("input");
                 scaleInput.type = "text";
@@ -279,5 +350,5 @@
                 scaleInput.setAttribute("onchange", "handleAnswerChange(" 
                     + questionNumber + ")");
-                                                
+                                                                                                                        
                 answerDiv.appendChild(leftLabel);
                 answerDiv.appendChild(leftInput);
@@ -286,14 +357,14 @@
                 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;
@@ -303,9 +374,9 @@
                 questionCount++;
             }
-                                                                                                                                                                                                                                                                                                    
+                                                                                                                                                                                                                                                                                                                                                                            
             function removeLastQuestion()
             {
                 var questionsDiv = document.getElementById('questionsDiv');
-                                                                                                                                                                                                                                                                                                        
+                                                                                                                                                                                                                                                                                                                                                                                
                 if (document.lastQuestion.prev != null)
                 {
@@ -319,5 +390,5 @@
                 }               
             }
-                                                                                                                                                                                                                                                                             
+                                                                                                                                                                                                                                                                                                                                                     
             function save(surveyID)
             {
@@ -327,5 +398,5 @@
                     var questionsDiv = document.getElementById('questionsDiv');
                     form.action = "surveycreation.php";
-                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                        
                     /* extra time stamp */
                     var date = new Date();
@@ -338,10 +409,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);
@@ -349,15 +420,15 @@
                 }
             }
-                                                                            
+                                                                                                                                                    
             function selectAll(input)
             {
                 input.select();
             }
-                                                                            
+                                                                                                                                                    
             /* --- input checking --- */
             function checksPassed()
             {
                 var form = document.getElementById('survey');
-                                                        
+                                                                                                                                
                 for (var i = 0; i < form.length; i++)
                 {
@@ -367,5 +438,5 @@
                 return true;
             }
-                                                    
+                                                                                                                            
             function checkInt(input)
             {
@@ -383,5 +454,5 @@
                 }
             }
-                                                                                                                                                                                                                                                                                                                                                                                                                                                              
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
         </script>
         <?php
@@ -405,5 +476,5 @@
             $value = 'Untitled Survey';
         ?>
-        <input type="text" id="surveyTitle" class="titleBox" name="surveyTitle" value="<?php echo $value; ?>" onblur="handleBlur(this)" onfocus="handleFocus(this)" />
+        <input type="text" id="surveyTitle" class="titleBox" name="surveyTitle" value="<?php echo str_replace("\"", "&quot;", $value); ?>" onblur="handleBlur(this)" onfocus="handleFocus(this)" />
         <?php
     }
@@ -456,13 +527,14 @@
                 /* Put all answers in js array */
                 foreach ($question->answers as $numA => $answer) {
-                    echo 'answers[' . $numA . '] = "' . $answer . '"; ';
+                    echo 'answers[' . $numA . '] = "' . addslashes($answer) . '"; ';
                     ?> 
-                                                                              
+                                                                                                                                                                                                                                                                  
                     <?php
                 }
                 ?>
-                    var title = "<?php echo $question->title; ?>";
-                    addQuestion(title, "<?php echo $question->description; ?>");
-                                                                                                                                                                                                                                                                                                                                    
+
+                    var title = "<?php echo addslashes($question->title); ?>";
+                    addQuestion(title, "<?php echo addslashes($question->description); ?>");
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                     var select = document.getElementById('<?php echo $numQ; ?>');
                     var type = '<?php echo $question->type; ?>';
@@ -476,6 +548,6 @@
                         }
                     }      
-                                                                                                                                                                    
-                                                                                                                                                                    
+                                                                                                                                                                                                                                                                                                                    
+                                                                                                                                                                                                                                                                                                                    
                     /* questionID stuff */
                     var questionIDInput = document.createElement("input");
@@ -484,5 +556,5 @@
                     questionIDInput.value = "<?php echo $question->id; ?>";
                     questionIDInput.type = "hidden";
-                                                                                                                                                                                                                                                                                                                     
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
                     document.getElementById("questionsDiv").appendChild(questionIDInput);
 
