Changeset 72


Ignore:
Timestamp:
08/04/11 11:31:06 (14 years ago)
Author:
fpvanagthoven
Message:

Okay input is now a lot more robust. Apostrophes and quotes should no longer be a problem.

Location:
Dev/trunk/classes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/classes/ApplicationCreationTool.php

    r68 r72  
    4949            $value = 'Untitled Application';
    5050        ?>
    51         <input type="text" id="applicationTitle" class="titleBox" name="applicationTitle" value="<?php echo $value; ?>" onblur="handleBlur(this)" onfocus="handleFocus(this)" />
     51        <input type="text" id="applicationTitle" class="titleBox" name="applicationTitle" value="<?php echo str_replace("\"", "&quot;", $value); ?>" onblur="handleBlur(this)" onfocus="handleFocus(this)" />
    5252        <?php
    5353    }
  • Dev/trunk/classes/SessionCreationTool.php

    r70 r72  
    152152            $value = 'Untitled Session';
    153153        ?>
    154         <input type="text" id="sessionTitle" class="titleBox" name="sessionTitle" value="<?php echo $value; ?>" onblur="handleBlur(this)" onfocus="handleFocus(this)" />
     154        <input type="text" id="sessionTitle" class="titleBox" name="sessionTitle" value="<?php echo str_replace("\"", "&quot;", $value); ?>" onblur="handleBlur(this)" onfocus="handleFocus(this)" />
    155155        <?php
    156156    }
  • Dev/trunk/classes/SurveyCreationTool.php

    r71 r72  
    3939            /* autosave every 3 minutes */
    4040            setTimeout("save('<?php echo $id; ?>')", 180000);
    41                                                                                                                                                                                                                                            
     41                                                                                                                                                                                                                                                                                                                   
    4242            var questionCount = 1;         
    43                                                                                                                                                                                                                                                                                                                                                                                    
     43                                                                                                                                                                                                                                                                                                                                                                                                                                                           
    4444            function getNewQuestion(title, description)
    4545            {
    4646                if (title == null)
    4747                    var title = 'Untitled Question';
    48                 else {
    49                     title.replace("'", "&#39;");
    50                 }
    51                                                                                                                                                                                
    52                 if (description != null)
    53                 {
    54                     description.replace("'", "&#39;");
    55                 }
    56                 else
     48                                                                                                                                                                                                                                                       
     49                if (description == null)
    5750                    var description = 'Write a question description here.';
    58                                                                                                                                                                  
     51                                                                                                                                                                                                                                        
    5952                var questionDiv = document.createElement("div");
    60                 var htmlStr =
    61                     "<div id='question" + questionCount + "' class='question'>" +
    62                     "<table class='questionTable'>" +
    63                     "<th>Question " + questionCount + "</th>" +
    64                     "<tr><td><label for='questionTitle'>Title</label></td>" +
    65                     "<td><input id='questionTitle' type='text' class='questionTitle' name='questionTitle" + questionCount + "' onfocus='handleFocus(this)' size='30' /></td></tr>" +
    66                     "<tr><td><label for='questionDescription'>Description</label></td>" +
    67                     "<td><input type='text' class='questionDescription' name='questionDescription" + questionCount + "' onfocus='handleFocus(this)' size='60' value='" + description + "' /></td>" +
    68                     "<tr><td><label for='questionType'>Answer type</label></td>" +
    69                     "<td><select id='" + questionCount + "' name='questionType" + questionCount + "' onchange='handleType(this)'><br />"+
     53                questionDiv.id = "question" + questionCount;
     54                questionDiv.className = "question";                                                                           
     55                                                                                       
     56                var questionTable = document.createElement("table");
     57                questionTable.className = "questionTable";
     58                                                                                       
     59                var th = document.createElement("th");
     60                th.innerHTML = "Question " + questionCount;
     61                                                                                       
     62                var row1 = document.createElement("tr");
     63                                                                                       
     64                var col1 = document.createElement("td");
     65                var titleLabel = document.createElement("label");
     66                titleLabel.setAttribute("for", "questionTitle");
     67                titleLabel.innerHTML = "Title";
     68                col1.appendChild(titleLabel);
     69                                                                               
     70                var col2 = document.createElement("td");
     71                var titleInput = document.createElement("input");
     72                titleInput.id = "questionTitle";
     73                titleInput.setAttribute("type", "text");
     74                titleInput.className = "questionTitle";
     75                titleInput.setAttribute("name", "questionTitle"  + questionCount);
     76                titleInput.setAttribute("onfocus", "handleFocus(this)");
     77                titleInput.setAttribute("size", "30");
     78                titleInput.setAttribute("value", title);
     79                col2.appendChild(titleInput);                       
     80
     81                row1.appendChild(col1);
     82                row1.appendChild(col2);
     83                                                                               
     84                var row2 = document.createElement("tr");
     85                var col3 = document.createElement("td");
     86                var descriptionLabel = document.createElement("label");
     87                descriptionLabel.setAttribute("for", "questionDescription");
     88                descriptionLabel.innerHTML = "Description";
     89                col3.appendChild(descriptionLabel);
     90                                                                               
     91                var col4 = document.createElement("td");
     92                var descriptionInput = document.createElement("input");
     93                descriptionInput.type = "text";
     94                descriptionInput.className = "questionDescription";
     95                descriptionInput.name = "questionDescription" + questionCount;
     96                descriptionInput.setAttribute("onfocus", "handleFocus(this)");
     97                descriptionInput.setAttribute("size", 60);
     98                descriptionInput.setAttribute("value", description);
     99                col4.appendChild(descriptionInput);
     100                                                                               
     101                row2.appendChild(col3);
     102                row2.appendChild(col4);
     103                                                       
     104                var row3 = document.createElement("tr");
     105                var col5 = document.createElement("td");
     106                var typeLabel = document.createElement("label");
     107                typeLabel.setAttribute("for", "questionType");
     108                typeLabel.innerHTML = "Type answer";
     109                col5.appendChild(typeLabel);
     110                                                       
     111                var col6 = document.createElement("td");
     112                var select = document.createElement("select");
     113                select.id = questionCount;
     114                select.setAttribute("name", "questionType" + questionCount);
     115                select.setAttribute("onchange", "handleType(this)");
     116                select.innerHTML =
    70117                    "<option value='text' selected='selected'>Text</option>" +
    71118                    "<option value='int'>Integer</option>" +
    72119                    "<option value='mc'>Multiple choice</option>" +
    73120                    "<option value='checkboxes'>Checkboxes</option>" +
    74                     "<option value='scale'>Scale</option>" +
    75                     "</select></td></tr>" +
    76                     "</table>" +
    77                     "<div id='answersDiv" + questionCount + "' class='answersDiv'></div>" +
    78                     "</div>";
    79                
    80                 /* TODO: get rid of innerHTML bullshit and do dynamically so that &#39; will work */
    81                            
    82                 questionDiv.innerHTML = htmlStr;
    83                                                                                                                                                                                                                                                                                                                                                                                
     121                    "<option value='scale'>Scale</option>";
     122                                                       
     123                col6.appendChild(select);
     124                                                       
     125                row3.appendChild(col5);
     126                row3.appendChild(col6);
     127                                                       
     128                questionTable.appendChild(th);
     129                questionTable.appendChild(row1);
     130                questionTable.appendChild(row2);
     131                questionTable.appendChild(row3);                         
     132                                                               
     133                var answerDiv = document.createElement("div");
     134                answerDiv.id = "answersDiv" + questionCount;
     135                answerDiv.className = "answersDiv";
     136                                                               
     137                questionDiv.appendChild(questionTable);
     138                questionDiv.appendChild(answerDiv);
     139                                                                                                                                                                                                                                                                                                                                                                                                                                                       
    84140                return questionDiv;
    85141            }
    86                                                                                                                                                                                                                                                                                                                                                                    
     142                                                                                                                                                                                                                                                                                                                                                                                                                                           
    87143            function handleType(select, answers)
    88144            {
     
    90146                var type = select.valueOf().value;
    91147                var answersDiv = document.getElementById("answersDiv" + numQ );
    92                                                                                
     148                                                                                                                                                       
    93149                removeQuestionID(numQ);
    94                                                                                
     150                                                                                                                                                       
    95151                answersDiv.answerCount = 1;
    96152                answersDiv.clicked = null;
    97                                                                                                                                                                                                                                                                                                                        
     153                                                                                                                                                                                                                                                                                                                                                                                               
    98154                switch (type) {
    99155                    case 'mc':
     
    108164                        else
    109165                            addOption(numQ);
    110                                                                                                                                                                                                                                                                                                                                                        
     166                                                                                                                                                                                                                                                                                                                                                                                                                               
    111167                        break;
    112168                    case 'text':
     
    115171                    case 'int':   
    116172                        answersDiv.innerHTML = "";
    117                                                                                                                                                                                
     173                                                                                                                                                                                                                                                       
    118174                        //min max
    119175                        if (answers != null)
     
    147203
    148204            }
    149                                                                            
     205                                                                                                                                                   
    150206            function handleAnswerChange(questionNumber)
    151207            {
    152208                removeQuestionID(questionNumber);
    153209            }
    154                                                                            
     210                                                                                                                                                   
    155211            function removeQuestionID(questionNumber)
    156212            {
     
    164220
    165221            }
    166                                                                                      
    167                                                                                                                                                                                                                                                                                                                                            
     222                                                                                                                                                            
     223                                                                                                                                                                                                                                                                                                                                                                                                                   
    168224            function addOption(questionNumber, optionStr)
    169225            {       
     
    171227                var answerCount = answersDiv.answerCount;
    172228                var answerDiv = document.createElement("div");
    173                                                                                                                
     229                                                                                                                                                                                       
    174230                if (optionStr == null)
    175231                    var optionStr = "Option " + answerCount;
    176                                                                                                                
    177                                                                                                                
     232                                                                                                                                                                                       
     233                                                                                                                                                                                      
    178234                answerDiv.className = "answerDiv";
     235                                                         
     236                var answerInput = document.createElement("input");
     237                answerInput.setAttribute("type", "text");
     238                answerInput.setAttribute("name", "q" + questionNumber + "ans" + answerCount);
     239                answerInput.setAttribute("onchange", "handleAnswerChange(" + questionNumber + ")");
     240                answerInput.setAttribute("value", optionStr);
     241                               
     242                answerDiv.appendChild(answerInput);
     243
     244                if (answersDiv.clicked == null)
     245                {
     246                    var addOpt = document.createElement("input");
     247                    addOpt.setAttribute("type", "button");
     248                    addOpt.setAttribute("id", "addOpt");
     249                    addOpt.setAttribute("class", "surveyButton");
     250                    addOpt.setAttribute("onclick", "addOption(" + questionNumber + ")");
     251                    addOpt.setAttribute("value", "Add Option");
     252                                   
     253                    var removeOpt = document.createElement("input");
     254                    removeOpt.setAttribute("type", "button");
     255                    removeOpt.className = "surveyButton";
     256                    removeOpt.setAttribute("onclick", "removeOption(" + questionNumber + ")");
     257                    removeOpt.setAttribute("value", "x");
     258                                   
     259                    answerDiv.appendChild(addOpt);
     260                    answerDiv.appendChild(removeOpt);
    179261                                                                                                                                                                                                                                                                                                                                               
    180                 var htmlStr = "<input type='text' name='q" +
    181                     questionNumber + "ans" + answerCount + "' onchange='handleAnswerChange(" + questionNumber + ")' value='" + optionStr + "' />";
    182                                                                                                                                                                                                                                                                                                                        
    183                 if (answersDiv.clicked == null)
    184                 {
    185                     htmlStr += "<input type='button' id='addOpt'"
    186                         + " class='surveyButton' onclick='addOption(" + questionNumber + ")' value='Add Option' />" +
    187                         "<input type='button' class='surveyButton' onclick='removeOption(" + questionNumber + ")' value='x' />";
    188                                                                                                                                                                                                                                                                                            
    189262                    answersDiv.clicked = true;
    190263                }
    191                                                                                                                                                                                                                                                                                                                                                        
    192                 answerDiv.innerHTML = htmlStr;
    193                                                                                                                                                                                                                                                                                        
     264                                                                                                                                                                                                                                                                                                                                                               
    194265                answerDiv.prev = answersDiv.lastAnswer; //singly linked list
    195266                answersDiv.lastAnswer = answerDiv;
    196                                                                                                                                                                                                                                                                                                                                                        
     267                                                                                                                                                                                                                                                                                                                                                                                                                              
    197268                answersDiv.appendChild(answerDiv);
    198269                answersDiv.answerCount++;
    199                                                                                
     270                                                                                                                                                       
    200271                handleAnswerChange(questionNumber);
    201272            }
    202                                                                                                                                                                                                                                                                                    
     273                                                                                                                                                                                                                                                                                                                                                           
    203274            function removeOption(questionNumber)
    204275            {
    205276                var answersDiv = document.getElementById("answersDiv" + questionNumber);
    206                                                                                                                                                                                                                                                                                        
     277                                                                                                                                                                                                                                                                                                                                                              
    207278                if (answersDiv.lastAnswer.prev != null)
    208279                {
     
    211282                    answersDiv.answerCount--;
    212283                }
    213                                                                                
     284                                                                                                                                                       
    214285                handleAnswerChange(questionNumber);
    215286            }
    216                                                                                                                                                                                                                                                                                                            
     287                                                                                                                                                                                                                                                                                                                                                                                   
    217288            function minMax(questionNumber, min, max)
    218289            {
     
    221292                if (max == null)
    222293                    var max = '';
    223                                                                                                                                                                        
     294                                                                                                                                                                                                                                               
    224295                var answersDiv = document.getElementById("answersDiv" + questionNumber);
    225                                                                                                                                                                                                                                                                                                                
     296                                                                                                                                                                                                                                                                                                                                                                                      
    226297                var answerDiv = document.createElement("div");
    227                                                                                                                                                                                                                                                                                
     298                                                                                                                                                                                                                                                                                                                                                       
    228299                answerDiv.className = "answerDiv";
    229300                answerDiv.innerHTML = "<label for='min'>Min</label><input type='text' class='intBox' onchange='checkInt(this)' value='" + min + "' name='q" + questionNumber + "ans1' />" +
    230301                    "<label for='max'>Max</label><input type='text' class='intBox' onchange='checkInt(this)' value='" + max + "' name='q" + questionNumber + "ans2' />";
    231                                                                                                                                                                                                                                                                                                            
     302                                                                                                                                                                                                                                                                                                                                                                                  
    232303                answersDiv.appendChild(answerDiv);
    233304            } 
    234                                                                                                                                                                                                                                                                                                            
     305                                                                                                                                                                                                                                                                                                                                                                                   
    235306            function minMaxIncr(questionNumber, left, right, incr)
    236307            {
     
    245316                if (incr == null)
    246317                    var incr = '';
    247                                                                                                                        
     318                                                                                                                                                                                               
    248319                var answersDiv = document.getElementById("answersDiv" + questionNumber);
    249                                                                                                                                                                                                                                                                                                                
     320                                                                                                                                                                                                                                                                                                                                                                                      
    250321                var answerDiv = document.createElement("div");
    251322                answerDiv.className = "answerDiv";
    252                                                
     323                                                                                                                      
    253324                var leftLabel = document.createElement("label");
    254325                var rightLabel = document.createElement("label");
     
    257328                rightLabel.innerHTML = "Right label";
    258329                scaleLabel.innerHTML = "Scale count";
    259                                                
     330                                                                                                                       
    260331                var leftInput = document.createElement("input");
    261332                leftInput.type = "text";
     
    264335                leftInput.setAttribute("onchange", "handleAnswerChange("
    265336                    + questionNumber + ")");
    266                                                
     337                                                                                                                       
    267338                var rightInput = document.createElement("input");
    268339                rightInput.type = "text";
     
    271342                rightInput.setAttribute("onchange", "handleAnswerChange("
    272343                    + questionNumber + ")");
    273                                                
     344                                                                                                                       
    274345                var scaleInput = document.createElement("input");
    275346                scaleInput.type = "text";
     
    279350                scaleInput.setAttribute("onchange", "handleAnswerChange("
    280351                    + questionNumber + ")");
    281                                                
     352                                                                                                                       
    282353                answerDiv.appendChild(leftLabel);
    283354                answerDiv.appendChild(leftInput);
     
    286357                answerDiv.appendChild(scaleLabel);
    287358                answerDiv.appendChild(scaleInput);
    288                                                                                                                                                                                                                                                                                            
     359                                                                                                                                                                                                                                                                                                                                                                  
    289360                answersDiv.appendChild(answerDiv);
    290361            }         
    291                                                                                                                                                                                                                                                                                                                                                                  
    292                                                                                                                                                                                                                                                                                                                                                                          
     362                                                                                                                                                                                                                                                                                                                                                                                                                                        
     363                                                                                                                                                                                                                                                                                                                                                                                                                                                
    293364            function addQuestion(title, description)
    294365            {
    295366                var questionsDiv = document.getElementById('questionsDiv');
    296367                var newQuestion = getNewQuestion(title, description);
    297                                                                                                                                                                                                                                                                                                        
     368                                                                                                                                                                                                                                                                                                                                                                               
    298369
    299370                newQuestion.prev = document.lastQuestion;
     
    303374                questionCount++;
    304375            }
    305                                                                                                                                                                                                                                                                                                    
     376                                                                                                                                                                                                                                                                                                                                                                           
    306377            function removeLastQuestion()
    307378            {
    308379                var questionsDiv = document.getElementById('questionsDiv');
    309                                                                                                                                                                                                                                                                                                        
     380                                                                                                                                                                                                                                                                                                                                                                               
    310381                if (document.lastQuestion.prev != null)
    311382                {
     
    319390                }               
    320391            }
    321                                                                                                                                                                                                                                                                              
     392                                                                                                                                                                                                                                                                                                                                                    
    322393            function save(surveyID)
    323394            {
     
    327398                    var questionsDiv = document.getElementById('questionsDiv');
    328399                    form.action = "surveycreation.php";
    329                                                                                                                                                                                                                                                
     400                                                                                                                                                                                                                                                                                                                       
    330401                    /* extra time stamp */
    331402                    var date = new Date();
     
    338409                    timeStampInput.value = timeStamp;
    339410                    timeStampInput.type = "hidden";
    340                                                                                                                                                                                                    
     411                                                                                                                                                                                                                                                                           
    341412                    var surveyIDInput = document.createElement("input");
    342413                    surveyIDInput.name = "surveyID";
    343414                    surveyIDInput.value = surveyID;
    344415                    surveyIDInput.type = "hidden";
    345                                                                                                                                                                                                                              
     416                                                                                                                                                                                                                                                                                                    
    346417                    questionsDiv.appendChild(timeStampInput);
    347418                    questionsDiv.appendChild(surveyIDInput);
     
    349420                }
    350421            }
    351                                                                            
     422                                                                                                                                                   
    352423            function selectAll(input)
    353424            {
    354425                input.select();
    355426            }
    356                                                                            
     427                                                                                                                                                   
    357428            /* --- input checking --- */
    358429            function checksPassed()
    359430            {
    360431                var form = document.getElementById('survey');
    361                                                        
     432                                                                                                                               
    362433                for (var i = 0; i < form.length; i++)
    363434                {
     
    367438                return true;
    368439            }
    369                                                    
     440                                                                                                                           
    370441            function checkInt(input)
    371442            {
     
    383454                }
    384455            }
    385                                                                                                                                                                                                                                                                                                                                                                                                                                                              
     456                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
    386457        </script>
    387458        <?php
     
    405476            $value = 'Untitled Survey';
    406477        ?>
    407         <input type="text" id="surveyTitle" class="titleBox" name="surveyTitle" value="<?php echo $value; ?>" onblur="handleBlur(this)" onfocus="handleFocus(this)" />
     478        <input type="text" id="surveyTitle" class="titleBox" name="surveyTitle" value="<?php echo str_replace("\"", "&quot;", $value); ?>" onblur="handleBlur(this)" onfocus="handleFocus(this)" />
    408479        <?php
    409480    }
     
    456527                /* Put all answers in js array */
    457528                foreach ($question->answers as $numA => $answer) {
    458                     echo 'answers[' . $numA . '] = "' . $answer . '"; ';
     529                    echo 'answers[' . $numA . '] = "' . addslashes($answer) . '"; ';
    459530                    ?>
    460                                                                              
     531                                                                                                                                                                                                                                                                 
    461532                    <?php
    462533                }
    463534                ?>
    464                     var title = "<?php echo $question->title; ?>";
    465                     addQuestion(title, "<?php echo $question->description; ?>");
    466                                                                                                                                                                                                                                                                                                                                    
     535
     536                    var title = "<?php echo addslashes($question->title); ?>";
     537                    addQuestion(title, "<?php echo addslashes($question->description); ?>");
     538                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
    467539                    var select = document.getElementById('<?php echo $numQ; ?>');
    468540                    var type = '<?php echo $question->type; ?>';
     
    476548                        }
    477549                    }     
    478                                                                                                                                                                    
    479                                                                                                                                                                    
     550                                                                                                                                                                                                                                                                                                                   
     551                                                                                                                                                                                                                                                                                                                   
    480552                    /* questionID stuff */
    481553                    var questionIDInput = document.createElement("input");
     
    484556                    questionIDInput.value = "<?php echo $question->id; ?>";
    485557                    questionIDInput.type = "hidden";
    486                                                                                                                                                                                                                                                                                                                      
     558                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
    487559                    document.getElementById("questionsDiv").appendChild(questionIDInput);
    488560
Note: See TracChangeset for help on using the changeset viewer.