Ignore:
Timestamp:
08/03/11 22:20:43 (14 years ago)
Author:
fpvanagthoven
Message:
 
File:
1 edited

Legend:

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

    r69 r71  
    1515        $this->survey = $survey;
    1616        $this->timeStamp = $timeStamp;
    17 
     17        var_dump($_POST);
     18        var_dump($survey);
    1819        if (isset($this->survey->id))
    1920            SurveyCreationTool::javascript($this->survey->id);
     
    3839            /* autosave every 3 minutes */
    3940            setTimeout("save('<?php echo $id; ?>')", 180000);
    40                                                                                                                                                                                                            
     41                                                                                                                                                                                                                                           
    4142            var questionCount = 1;         
    42                                                                                                                                                                                                                                                                                                                                                    
     43                                                                                                                                                                                                                                                                                                                                                                                   
    4344            function getNewQuestion(title, description)
    4445            {
    4546                if (title == null)
    4647                    var title = 'Untitled Question';
    47                                                                                                                                                
     48                else {
     49                    title.replace("'", "&#39;");
     50                }
     51                                                                                                                                                                               
    4852                if (description != null)
    49                     var description = description;
     53                {
     54                    description.replace("'", "&#39;");
     55                }
    5056                else
    5157                    var description = 'Write a question description here.';
    52                                                                                                                                                                     
     58                                                                                                                                                                 
    5359                var questionDiv = document.createElement("div");
    5460                var htmlStr =
     
    5763                    "<th>Question " + questionCount + "</th>" +
    5864                    "<tr><td><label for='questionTitle'>Title</label></td>" +
    59                     "<td><input type='text' class='questionTitle' name='questionTitle" + questionCount + "' onfocus='handleFocus(this)' size='30' value='" + title + "' /></td></tr>" +
     65                    "<td><input id='questionTitle' type='text' class='questionTitle' name='questionTitle" + questionCount + "' onfocus='handleFocus(this)' size='30' /></td></tr>" +
    6066                    "<tr><td><label for='questionDescription'>Description</label></td>" +
    6167                    "<td><input type='text' class='questionDescription' name='questionDescription" + questionCount + "' onfocus='handleFocus(this)' size='60' value='" + description + "' /></td>" +
     
    7177                    "<div id='answersDiv" + questionCount + "' class='answersDiv'></div>" +
    7278                    "</div>";
    73                                                                                                                                                                                                                                                                                                                                                
     79               
     80                /* TODO: get rid of innerHTML bullshit and do dynamically so that &#39; will work */
     81                           
    7482                questionDiv.innerHTML = htmlStr;
    75                                                                                                                                                                                                                                                                                                                                                
     83                                                                                                                                                                                                                                                                                                                                                                               
    7684                return questionDiv;
    7785            }
    78                                                                                                                                                                                                                                                                                                                                    
     86                                                                                                                                                                                                                                                                                                                                                                   
    7987            function handleType(select, answers)
    8088            {
     
    8290                var type = select.valueOf().value;
    8391                var answersDiv = document.getElementById("answersDiv" + numQ );
    84                                                
     92                                                                               
    8593                removeQuestionID(numQ);
    86                                                
     94                                                                               
    8795                answersDiv.answerCount = 1;
    8896                answersDiv.clicked = null;
    89                                                                                                                                                                                                                                                                                        
     97                                                                                                                                                                                                                                                                                                                       
    9098                switch (type) {
    9199                    case 'mc':
     
    100108                        else
    101109                            addOption(numQ);
    102                                                                                                                                                                                                                                                                                                                        
     110                                                                                                                                                                                                                                                                                                                                                       
    103111                        break;
    104112                    case 'text':
     
    107115                    case 'int':   
    108116                        answersDiv.innerHTML = "";
    109                                                                                                                                                
     117                                                                                                                                                                               
    110118                        //min max
    111119                        if (answers != null)
     
    139147
    140148            }
    141                                            
     149                                                                           
    142150            function handleAnswerChange(questionNumber)
    143151            {
    144152                removeQuestionID(questionNumber);
    145153            }
    146                                            
     154                                                                           
    147155            function removeQuestionID(questionNumber)
    148156            {
     
    156164
    157165            }
    158                                                      
    159                                                                                                                                                                                                                                                                                                            
     166                                                                                    
     167                                                                                                                                                                                                                                                                                                                                           
    160168            function addOption(questionNumber, optionStr)
    161169            {       
     
    163171                var answerCount = answersDiv.answerCount;
    164172                var answerDiv = document.createElement("div");
    165                                                                                
     173                                                                                                               
    166174                if (optionStr == null)
    167175                    var optionStr = "Option " + answerCount;
    168                                                                                
    169                                                                                
     176                                                                                                               
     177                                                                                                              
    170178                answerDiv.className = "answerDiv";
    171                                                                                                                                                                                                                                                                                                                
     179                                                                                                                                                                                                                                                                                                                                               
    172180                var htmlStr = "<input type='text' name='q" +
    173181                    questionNumber + "ans" + answerCount + "' onchange='handleAnswerChange(" + questionNumber + ")' value='" + optionStr + "' />";
    174                                                                                                                                                                                                                                                                                        
     182                                                                                                                                                                                                                                                                                                                       
    175183                if (answersDiv.clicked == null)
    176184                {
     
    178186                        + " class='surveyButton' onclick='addOption(" + questionNumber + ")' value='Add Option' />" +
    179187                        "<input type='button' class='surveyButton' onclick='removeOption(" + questionNumber + ")' value='x' />";
    180                                                                                                                                                                                                                                                            
     188                                                                                                                                                                                                                                                                                           
    181189                    answersDiv.clicked = true;
    182190                }
    183                                                                                                                                                                                                                                                                                                                        
     191                                                                                                                                                                                                                                                                                                                                                      
    184192                answerDiv.innerHTML = htmlStr;
    185                                                                                                                                                                                                                                                        
     193                                                                                                                                                                                                                                                                                       
    186194                answerDiv.prev = answersDiv.lastAnswer; //singly linked list
    187195                answersDiv.lastAnswer = answerDiv;
    188                                                                                                                                                                                                                                                                                                                        
     196                                                                                                                                                                                                                                                                                                                                                      
    189197                answersDiv.appendChild(answerDiv);
    190198                answersDiv.answerCount++;
    191                                                
     199                                                                               
    192200                handleAnswerChange(questionNumber);
    193201            }
    194                                                                                                                                                                                                                                                    
     202                                                                                                                                                                                                                                                                                   
    195203            function removeOption(questionNumber)
    196204            {
    197205                var answersDiv = document.getElementById("answersDiv" + questionNumber);
    198                                                                                                                                                                                                                                                        
     206                                                                                                                                                                                                                                                                                      
    199207                if (answersDiv.lastAnswer.prev != null)
    200208                {
     
    203211                    answersDiv.answerCount--;
    204212                }
    205                                                
     213                                                                               
    206214                handleAnswerChange(questionNumber);
    207215            }
    208                                                                                                                                                                                                                                                                            
     216                                                                                                                                                                                                                                                                                                           
    209217            function minMax(questionNumber, min, max)
    210218            {
     
    213221                if (max == null)
    214222                    var max = '';
    215                                                                                                                                        
     223                                                                                                                                                                       
    216224                var answersDiv = document.getElementById("answersDiv" + questionNumber);
    217                                                                                                                                                                                                                                                                                
     225                                                                                                                                                                                                                                                                                                              
    218226                var answerDiv = document.createElement("div");
    219                                                                                                                                                                                                                                                
     227                                                                                                                                                                                                                                                                               
    220228                answerDiv.className = "answerDiv";
    221229                answerDiv.innerHTML = "<label for='min'>Min</label><input type='text' class='intBox' onchange='checkInt(this)' value='" + min + "' name='q" + questionNumber + "ans1' />" +
    222230                    "<label for='max'>Max</label><input type='text' class='intBox' onchange='checkInt(this)' value='" + max + "' name='q" + questionNumber + "ans2' />";
    223                                                                                                                                                                                                                                                                            
     231                                                                                                                                                                                                                                                                                                          
    224232                answersDiv.appendChild(answerDiv);
    225233            } 
    226                                                                                                                                                                                                                                                                            
     234                                                                                                                                                                                                                                                                                                           
    227235            function minMaxIncr(questionNumber, left, right, incr)
    228236            {
    229237                if (left == null)
    230238                    var left = '';
     239                else
     240                    left.replace("'", "&#39;");
    231241                if (right == null)
    232242                    var right = '';
     243                else
     244                    right.replace("'", "&#39;");
    233245                if (incr == null)
    234246                    var incr = '';
    235                                                                                        
     247                                                                                                                       
    236248                var answersDiv = document.getElementById("answersDiv" + questionNumber);
    237                                                                                                                                                                                                                                                                                
     249                                                                                                                                                                                                                                                                                                              
    238250                var answerDiv = document.createElement("div");
    239251                answerDiv.className = "answerDiv";
    240                 answerDiv.innerHTML = "<label>Left label</label><input type='text' value='" + left + "' onchange='handleAnswerChange(" + questionNumber + ")' name='q" + questionNumber + "ans1' />" +
    241                     "<label>Right label</label><input type='text' value='" + right + "' onchange='handleAnswerChange(" + questionNumber + ")' name='q" + questionNumber + "ans2' />" +
    242                     "<label>Scale count</label><input type='text' class='intBox' value='" + incr + "' onblur='checkInt(this)' onchange='handleAnswerChange(" + questionNumber + ")' name='q" + questionNumber + "ans3' />" +
    243                     "<div id='inputCheckFeedback'" + questionNumber + "";
    244                                                                                                                                                                                                                                                                            
     252                                               
     253                var leftLabel = document.createElement("label");
     254                var rightLabel = document.createElement("label");
     255                var scaleLabel = document.createElement("label");
     256                leftLabel.innerHTML = "Left label";
     257                rightLabel.innerHTML = "Right label";
     258                scaleLabel.innerHTML = "Scale count";
     259                                               
     260                var leftInput = document.createElement("input");
     261                leftInput.type = "text";
     262                leftInput.value = left;
     263                leftInput.name= "q" + questionNumber + "ans1";
     264                leftInput.setAttribute("onchange", "handleAnswerChange("
     265                    + questionNumber + ")");
     266                                               
     267                var rightInput = document.createElement("input");
     268                rightInput.type = "text";
     269                rightInput.value = right;
     270                rightInput.name = "q" + questionNumber + "ans2";
     271                rightInput.setAttribute("onchange", "handleAnswerChange("
     272                    + questionNumber + ")");
     273                                               
     274                var scaleInput = document.createElement("input");
     275                scaleInput.type = "text";
     276                scaleInput.className = "intBox";
     277                scaleInput.value = incr;
     278                scaleInput.setAttribute("onblur", "checkInt(this)");
     279                scaleInput.setAttribute("onchange", "handleAnswerChange("
     280                    + questionNumber + ")");
     281                                               
     282                answerDiv.appendChild(leftLabel);
     283                answerDiv.appendChild(leftInput);
     284                answerDiv.appendChild(rightLabel);
     285                answerDiv.appendChild(rightInput);
     286                answerDiv.appendChild(scaleLabel);
     287                answerDiv.appendChild(scaleInput);
     288                                                                                                                                                                                                                                                                                           
    245289                answersDiv.appendChild(answerDiv);
    246290            }         
    247                                                                                                                                                                                                                                                                                                                                  
    248                                                                                                                                                                                                                                                                                                                                          
     291                                                                                                                                                                                                                                                                                                                                                                
     292                                                                                                                                                                                                                                                                                                                                                                        
    249293            function addQuestion(title, description)
    250294            {
    251295                var questionsDiv = document.getElementById('questionsDiv');
    252296                var newQuestion = getNewQuestion(title, description);
    253                                                                                                                                                                                                                                                                        
     297                                                                                                                                                                                                                                                                                                       
    254298
    255299                newQuestion.prev = document.lastQuestion;
     
    259303                questionCount++;
    260304            }
    261                                                                                                                                                                                                                                                                    
     305                                                                                                                                                                                                                                                                                                   
    262306            function removeLastQuestion()
    263307            {
    264308                var questionsDiv = document.getElementById('questionsDiv');
    265                                                                                                                                                                                                                                                                        
     309                                                                                                                                                                                                                                                                                                       
    266310                if (document.lastQuestion.prev != null)
    267311                {
     
    275319                }               
    276320            }
    277                                                                                                                                                                                                                                              
     321                                                                                                                                                                                                                                                                            
    278322            function save(surveyID)
    279323            {
     
    283327                    var questionsDiv = document.getElementById('questionsDiv');
    284328                    form.action = "surveycreation.php";
    285                                                                                                                                                                                                                
     329                                                                                                                                                                                                                                               
    286330                    /* extra time stamp */
    287331                    var date = new Date();
     
    294338                    timeStampInput.value = timeStamp;
    295339                    timeStampInput.type = "hidden";
    296                                                                                                                                                                    
     340                                                                                                                                                                                                   
    297341                    var surveyIDInput = document.createElement("input");
    298342                    surveyIDInput.name = "surveyID";
    299343                    surveyIDInput.value = surveyID;
    300344                    surveyIDInput.type = "hidden";
    301                                                                                                                                                                                              
     345                                                                                                                                                                                                                            
    302346                    questionsDiv.appendChild(timeStampInput);
    303347                    questionsDiv.appendChild(surveyIDInput);
     
    305349                }
    306350            }
    307                                            
     351                                                                           
    308352            function selectAll(input)
    309353            {
    310354                input.select();
    311355            }
    312                                            
     356                                                                           
    313357            /* --- input checking --- */
    314358            function checksPassed()
    315359            {
    316360                var form = document.getElementById('survey');
    317                        
     361                                                       
    318362                for (var i = 0; i < form.length; i++)
    319363                {
     
    323367                return true;
    324368            }
    325                    
     369                                                   
    326370            function checkInt(input)
    327371            {
     
    339383                }
    340384            }
    341                                                                                                                                                                                                                                                                                                                                                                                                                              
     385                                                                                                                                                                                                                                                                                                                                                                                                                                                             
    342386        </script>
    343387        <?php
     
    412456                /* Put all answers in js array */
    413457                foreach ($question->answers as $numA => $answer) {
    414                     echo "answers[" . $numA . "] = '" . $answer . "'; ";
     458                    echo 'answers[' . $numA . '] = "' . $answer . '"; ';
     459                    ?>
     460                                                                             
     461                    <?php
    415462                }
    416463                ?>
    417                                                                                                                                                                    
    418                     addQuestion('<?php echo $question->title; ?>', '<?php echo $question->description; ?>');
    419                                                                                                                                                                                                                                                                    
     464                    var title = "<?php echo $question->title; ?>";
     465                    addQuestion(title, "<?php echo $question->description; ?>");
     466                                                                                                                                                                                                                                                                                                                                   
    420467                    var select = document.getElementById('<?php echo $numQ; ?>');
    421468                    var type = '<?php echo $question->type; ?>';
     
    425472                        {
    426473                            select.options[i].selected = true;
    427                             handleType(select, answers)
     474                            handleType(select, answers);
    428475                            break;
    429476                        }
    430477                    }     
    431                                                                                                    
    432                                                                                                    
     478                                                                                                                                                                   
     479                                                                                                                                                                   
    433480                    /* questionID stuff */
    434481                    var questionIDInput = document.createElement("input");
     
    437484                    questionIDInput.value = "<?php echo $question->id; ?>";
    438485                    questionIDInput.type = "hidden";
    439                                                                                                                                                                                                                                                      
     486                                                                                                                                                                                                                                                                                                                    
    440487                    document.getElementById("questionsDiv").appendChild(questionIDInput);
    441488
Note: See TracChangeset for help on using the changeset viewer.