Changeset 98 for Dev


Ignore:
Timestamp:
09/01/11 15:25:59 (14 years ago)
Author:
fpvanagthoven
Message:

Question code.

Location:
Dev/trunk
Files:
5 edited

Legend:

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

    r35 r98  
    1313class Question {
    1414    public $id;
     15    public $code;
    1516    public $title;
    1617    public $type;
     
    1819    public $answers; // format answers['#']
    1920   
    20     public function __construct($id, $title, $type, $description = null)
     21    public function __construct($id, $code, $title, $type, $description = null)
    2122    {
    2223        $this->id = $id;
     24        $this->code = $code;
    2325        $this->title = $title;
    2426        $this->type = $type;
  • Dev/trunk/classes/Survey.php

    r95 r98  
    4848        while (isset($info['questionTitle' . $numQ])) {
    4949            $id = $info['questionID' . $numQ];
     50            $code = $info['questionCode' . $numQ];
    5051            $title = $info['questionTitle' . $numQ];
    5152            $type = $info['questionType' . $numQ];
    5253            $description = $info['questionDescription' . $numQ];
    5354
    54             $question = new Question($id, $title, $type, $description);
     55            $question = new Question($id, $code, $title, $type, $description);
    5556
    5657            $numA = 1; //number answers
  • Dev/trunk/classes/SurveyCreationTool.php

    r91 r98  
    3535        <script type="text/javascript" src="js/creation.js"></script>
    3636        <script type="text/javascript">
    37             /* autosave every 3 minutes */
    38             setTimeout("save('<?php echo $id; ?>')", 180000);
    39                                                                                                                                                                                                                                                                                                                    
     37            /* autosave every 5 minutes */
     38            setTimeout("save('<?php echo $id; ?>')", 300000);
     39                                                                                                                                                                                                                                                                                                                           
    4040            var questionCount = 1;         
    41                                                                                                                                                                                                                                                                                                                                                                                                                                                            
    42             function getNewQuestion(title, description)
    43             {
     41                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
     42            function getNewQuestion(code, title, description)
     43            {
     44                if (code == null)
     45                    var code = '';
     46                       
    4447                if (title == null)
    4548                    var title = 'Untitled Question';
    46                                                                                                                                                                                                                                                        
     49                                                                                                                                                                                                                                                               
    4750                if (description == null)
    4851                    var description = 'Write a question description here.';
    49                                                                                                                                                                                                                                          
     52                                                                                                                                                                                                                                                
    5053                var questionDiv = document.createElement("div");
    5154                questionDiv.id = "question" + questionCount;
    5255                questionDiv.className = "question";                                                                           
    53                                                                                        
     56                                                                                               
    5457                var questionTable = document.createElement("table");
    5558                questionTable.className = "questionTable";
    56                                                                                        
     59                                                                                               
    5760                var th = document.createElement("th");
    5861                th.innerHTML = "Question " + questionCount;
    59                                                                                        
     62
     63                var row0 = document.createElement("tr");
     64                       
     65                var colCodeLabel = document.createElement("td");
     66                var codeLabel = document.createElement("label");
     67                codeLabel.setAttribute("for", "questionCode");
     68                codeLabel.innerHTML = "Code";
     69                colCodeLabel.appendChild(codeLabel);
     70                       
     71                var colCodeInput = document.createElement("td");
     72                var codeInput = document.createElement("input");
     73                codeInput.id = "questionCode";
     74                codeInput.setAttribute("type", "text");
     75                codeInput.className = "questionCode";
     76                codeInput.setAttribute("name", "questionCode" + questionCount);
     77                codeInput.setAttribute("size", "5");
     78                codeInput.setAttribute("value", code);
     79                colCodeInput.appendChild(codeInput);
     80                       
     81                row0.appendChild(colCodeLabel);
     82                row0.appendChild(colCodeInput);
     83
    6084                var row1 = document.createElement("tr");
    61                                                                                        
     85                                                                                               
    6286                var col1 = document.createElement("td");
    6387                var titleLabel = document.createElement("label");
     
    6589                titleLabel.innerHTML = "Title";
    6690                col1.appendChild(titleLabel);
    67                                                                                
     91                                                                                       
    6892                var col2 = document.createElement("td");
    6993                var titleInput = document.createElement("input");
     
    79103                row1.appendChild(col1);
    80104                row1.appendChild(col2);
    81                                                                                
     105                                                                                       
    82106                var row2 = document.createElement("tr");
    83107                var col3 = document.createElement("td");
     
    86110                descriptionLabel.innerHTML = "Description";
    87111                col3.appendChild(descriptionLabel);
    88                                                                                
     112                                                                                       
    89113                var col4 = document.createElement("td");
    90114                var descriptionInput = document.createElement("input");
     
    93117                descriptionInput.name = "questionDescription" + questionCount;
    94118                descriptionInput.setAttribute("onfocus", "handleFocus(this)");
    95                 descriptionInput.setAttribute("size", 60);
     119                descriptionInput.setAttribute("size", 40);
    96120                descriptionInput.setAttribute("value", description);
    97121                col4.appendChild(descriptionInput);
    98                                                                                
     122                                                                                       
    99123                row2.appendChild(col3);
    100124                row2.appendChild(col4);
    101                                                        
     125                                                               
    102126                var row3 = document.createElement("tr");
    103127                var col5 = document.createElement("td");
     
    106130                typeLabel.innerHTML = "Type answer";
    107131                col5.appendChild(typeLabel);
    108                                                        
     132                                                               
    109133                var col6 = document.createElement("td");
    110134                var select = document.createElement("select");
     
    118142                    "<option value='checkboxes'>Checkboxes</option>" +
    119143                    "<option value='scale'>Scale</option>";
    120                                                        
     144                                                               
    121145                col6.appendChild(select);
    122                                                        
     146                                                               
    123147                row3.appendChild(col5);
    124148                row3.appendChild(col6);
    125                                                        
     149                                                               
    126150                questionTable.appendChild(th);
     151                questionTable.appendChild(row0);
    127152                questionTable.appendChild(row1);
    128153                questionTable.appendChild(row2);
    129154                questionTable.appendChild(row3);                         
    130                                                                
     155                                                                       
    131156                var answerDiv = document.createElement("div");
    132157                answerDiv.id = "answersDiv" + questionCount;
    133158                answerDiv.className = "answersDiv";
    134                                                                
     159                                                                       
    135160                questionDiv.appendChild(questionTable);
    136161                questionDiv.appendChild(answerDiv);
    137                                                                                                                                                                                                                                                                                                                                                                                                                                                        
     162                                                                                                                                                                                                                                                                                                                                                                                                                                                               
    138163                return questionDiv;
    139164            }
    140                                                                                                                                                                                                                                                                                                                                                                                                                                            
     165                                                                                                                                                                                                                                                                                                                                                                                                                                                   
    141166            function handleType(select, answers)
    142167            {
     
    144169                var type = select.valueOf().value;
    145170                var answersDiv = document.getElementById("answersDiv" + numQ );
    146                                                                                                                                                        
     171                                                                                                                                                               
    147172                removeQuestionID(numQ);
    148                                                                                                                                                        
     173                                                                                                                                                               
    149174                answersDiv.answerCount = 1;
    150175                answersDiv.clicked = null;
    151                                                                                                                                                                                                                                                                                                                                                                                                
     176                                                                                                                                                                                                                                                                                                                                                                                                       
    152177                switch (type) {
    153178                    case 'mc':
     
    162187                        else
    163188                            addOption(numQ);
    164                                                                                                                                                                                                                                                                                                                                                                                                                                
     189                                                                                                                                                                                                                                                                                                                                                                                                                                       
    165190                        break;
    166191                    case 'text':
     
    169194                    case 'int':   
    170195                        answersDiv.innerHTML = "";
    171                                                                                                                                                                                                                                                        
     196                                                                                                                                                                                                                                                               
    172197                        //min max
    173198                        if (answers != null)
     
    201226
    202227            }
    203                                                                                                                                                    
     228                                                                                                                                                           
    204229            function handleAnswerChange(questionNumber)
    205230            {
    206231                removeQuestionID(questionNumber);
    207232            }
    208                                                                                                                                                    
     233                                                                                                                                                           
    209234            function removeQuestionID(questionNumber)
    210235            {
     
    218243
    219244            }
    220                                                                                                                                                              
    221                                                                                                                                                                                                                                                                                                                                                                                                                    
     245                                                                                                                                                                    
     246                                                                                                                                                                                                                                                                                                                                                                                                                           
    222247            function addOption(questionNumber, optionStr)
    223248            {       
     
    225250                var answerCount = answersDiv.answerCount;
    226251                var answerDiv = document.createElement("div");
    227                                                                                                                                                                                        
     252                                                                                                                                                                                               
    228253                if (optionStr == null)
    229254                    var optionStr = "Option " + answerCount;
    230                                                                                                                                                                                        
    231                                                                                                                                                                                        
     255                                                                                                                                                                                               
     256                                                                                                                                                                                              
    232257                answerDiv.className = "answerDiv";
    233                                                          
     258                                                                 
    234259                var answerInput = document.createElement("input");
    235260                answerInput.setAttribute("type", "text");
     
    237262                answerInput.setAttribute("onchange", "handleAnswerChange(" + questionNumber + ")");
    238263                answerInput.setAttribute("value", optionStr);
    239                                
     264                                       
    240265                answerDiv.appendChild(answerInput);
    241266
     
    248273                    addOpt.setAttribute("onclick", "addOption(" + questionNumber + ")");
    249274                    addOpt.setAttribute("value", "Add Option");
    250                                    
     275                                           
    251276                    var removeOpt = document.createElement("input");
    252277                    removeOpt.setAttribute("type", "button");
     
    254279                    removeOpt.setAttribute("onclick", "removeOption(" + questionNumber + ")");
    255280                    removeOpt.setAttribute("value", "x");
    256                                    
     281                                           
    257282                    answerDiv.appendChild(addOpt);
    258283                    answerDiv.appendChild(removeOpt);
    259                                                                                                                                                                                                                                                                                                                                                
     284                                                                                                                                                                                                                                                                                                                                                       
    260285                    answersDiv.clicked = true;
    261286                }
    262                                                                                                                                                                                                                                                                                                                                                                
     287                                                                                                                                                                                                                                                                                                                                                                       
    263288                answerDiv.prev = answersDiv.lastAnswer; //singly linked list
    264289                answersDiv.lastAnswer = answerDiv;
    265                                                                                                                                                                                                                                                                                                                                                                                                                                
     290                                                                                                                                                                                                                                                                                                                                                                                                                                      
    266291                answersDiv.appendChild(answerDiv);
    267292                answersDiv.answerCount++;
    268                                                                                                                                                        
     293                                                                                                                                                               
    269294                handleAnswerChange(questionNumber);
    270295            }
    271                                                                                                                                                                                                                                                                                                                                                            
     296                                                                                                                                                                                                                                                                                                                                                                   
    272297            function removeOption(questionNumber)
    273298            {
    274299                var answersDiv = document.getElementById("answersDiv" + questionNumber);
    275                                                                                                                                                                                                                                                                                                                                                                
     300                                                                                                                                                                                                                                                                                                                                                                      
    276301                if (answersDiv.lastAnswer.prev != null)
    277302                {
     
    280305                    answersDiv.answerCount--;
    281306                }
    282                                                                                                                                                        
     307                                                                                                                                                               
    283308                handleAnswerChange(questionNumber);
    284309            }
    285                                                                                                                                                                                                                                                                                                                                                                                    
     310                                                                                                                                                                                                                                                                                                                                                                                           
    286311            function minMax(questionNumber, min, max)
    287312            {
     
    290315                if (max == null)
    291316                    var max = '';
    292                                                                                                                                                                                                                                                
     317                                                                                                                                                                                                                                                       
    293318                var answersDiv = document.getElementById("answersDiv" + questionNumber);
    294                                                                                                                                                                                                                                                                                                                                                                                        
     319                                                                                                                                                                                                                                                                                                                                                                                              
    295320                var answerDiv = document.createElement("div");
    296                                                                                                                                                                                                                                                                                                                                                        
     321                                                                                                                                                                                                                                                                                                                                                               
    297322                answerDiv.className = "answerDiv";
    298323                answerDiv.innerHTML = "<label for='min'>Min</label><input type='text' class='intBox' onchange='checkInt(this)' value='" + min + "' name='q" + questionNumber + "ans1' />" +
    299324                    "<label for='max'>Max</label><input type='text' class='intBox' onchange='checkInt(this)' value='" + max + "' name='q" + questionNumber + "ans2' />";
    300                                                                                                                                                                                                                                                                                                                                                                                    
     325                                                                                                                                                                                                                                                                                                                                                                                          
    301326                answersDiv.appendChild(answerDiv);
    302327            } 
    303                                                                                                                                                                                                                                                                                                                                                                                    
     328                                                                                                                                                                                                                                                                                                                                                                                           
    304329            function minMaxIncr(questionNumber, left, right, incr)
    305330            {
     
    314339                if (incr == null)
    315340                    var incr = '';
    316                                                                                                                                                                                                
     341                                                                                                                                                                                                       
    317342                var answersDiv = document.getElementById("answersDiv" + questionNumber);
    318                                                                                                                                                                                                                                                                                                                                                                                        
     343                                                                                                                                                                                                                                                                                                                                                                                              
    319344                var answerDiv = document.createElement("div");
    320345                answerDiv.className = "answerDiv";
    321                                                                                                                        
     346                                                                                                                              
    322347                var leftLabel = document.createElement("label");
    323348                var rightLabel = document.createElement("label");
     
    326351                rightLabel.innerHTML = "Right label";
    327352                scaleLabel.innerHTML = "Scale count";
    328                                                                                                                        
     353                                                                                                                               
    329354                var leftInput = document.createElement("input");
    330355                leftInput.type = "text";
     
    333358                leftInput.setAttribute("onchange", "handleAnswerChange("
    334359                    + questionNumber + ")");
    335                                                                                                                        
     360                                                                                                                               
    336361                var rightInput = document.createElement("input");
    337362                rightInput.type = "text";
     
    340365                rightInput.setAttribute("onchange", "handleAnswerChange("
    341366                    + questionNumber + ")");
    342                                                                                                                        
     367                                                                                                                               
    343368                var scaleInput = document.createElement("input");
    344369                scaleInput.type = "text";
     
    349374                    + questionNumber + ")");
    350375                scaleInput.name = "q" + questionNumber + "ans3";
    351                                                                                                                        
     376                                                                                                                               
    352377                answerDiv.appendChild(leftLabel);
    353378                answerDiv.appendChild(leftInput);
     
    356381                answerDiv.appendChild(scaleLabel);
    357382                answerDiv.appendChild(scaleInput);
    358                                                                                                                                                                                                                                                                                                                                                                    
     383                                                                                                                                                                                                                                                                                                                                                                          
    359384                answersDiv.appendChild(answerDiv);
    360385            }         
    361                                                                                                                                                                                                                                                                                                                                                                                                                                          
    362386                                                                                                                                                                                                                                                                                                                                                                                                                                                 
    363             function addQuestion(title, description)
     387                                                                                                                                                                                                                                                                                                                                                                                                                                                         
     388            function addQuestion(code, title, description)
    364389            {
    365390                var questionsDiv = document.getElementById('questionsDiv');
    366                 var newQuestion = getNewQuestion(title, description);
    367                                                                                                                                                                                                                                                                                                                                                                                
     391                var newQuestion = getNewQuestion(code, title, description);
    368392
    369393                newQuestion.prev = document.lastQuestion;
     
    373397                questionCount++;
    374398            }
    375                                                                                                                                                                                                                                                                                                                                                                            
     399                                                                                                                                                                                                                                                                                                                                                                                   
    376400            function removeLastQuestion()
    377401            {
    378402                var questionsDiv = document.getElementById('questionsDiv');
    379                                                                                                                                                                                                                                                                                                                                                                                
    380                 if (document.lastQuestion.prev != null)
     403                                                                                                                                                                                                                                                                                                                                                                                       
     404                if (document.lastQuestion != null)
    381405                {
    382406                    questionsDiv.removeChild(document.lastQuestion);
     
    389413                }               
    390414            }
    391                                                                                                                                                                                                                                                                                                                                                      
     415                                                                                                                                                                                                                                                                                                                                                            
    392416            function save(surveyID)
    393417            {
     
    397421                    var questionsDiv = document.getElementById('questionsDiv');
    398422                    form.action = "surveycreation.php";
    399                                                                                                                                                                                                                                                                                                                        
     423                                                                                                                                                                                                                                                                                                                               
    400424                    /* extra time stamp */
    401425                    var date = new Date();
     
    408432                    timeStampInput.value = timeStamp;
    409433                    timeStampInput.type = "hidden";
    410                                                                                                                                                                                                                                                                            
     434                                                                                                                                                                                                                                                                                   
    411435                    var surveyIDInput = document.createElement("input");
    412436                    surveyIDInput.name = "surveyID";
    413437                    surveyIDInput.value = surveyID;
    414438                    surveyIDInput.type = "hidden";
    415                                                                                                                                                                                                                                                                                                      
     439                                                                                                                                                                                                                                                                                                            
    416440                    questionsDiv.appendChild(timeStampInput);
    417441                    questionsDiv.appendChild(surveyIDInput);
     
    419443                }
    420444            }
    421                                                                                                                                                    
     445                                                                                                                                                           
    422446            function selectAll(input)
    423447            {
    424448                input.select();
    425449            }
    426                                                                                                                                                    
     450                                                                                                                                                           
    427451            /* --- input checking --- */
    428452            function checksPassed()
    429453            {
    430454                var form = document.getElementById('survey');
    431                                                                                                                                
     455                                                                                                                                       
    432456                for (var i = 0; i < form.length; i++)
    433457                {
     
    437461                return true;
    438462            }
    439                                                                                                                            
     463                                                                                                                                   
    440464            function checkInt(input)
    441465            {
     
    453477                }
    454478            }
    455                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
     479                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
    456480        </script>
    457481        <?php
     
    528552                    echo 'answers[' . $numA . '] = "' . addslashes($answer) . '"; ';
    529553                    ?>
    530                                                                                                                                                                                                                                                                  
     554                                                                                                                                                                                                                                                                                     
    531555                    <?php
    532556                }
    533557                ?>
    534 
     558                    var code = "<?php echo addslashes($question->code); ?>";
    535559                    var title = "<?php echo addslashes($question->title); ?>";
    536                     addQuestion(title, "<?php echo addslashes($question->description); ?>");
    537                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
     560                    var description = "<?php echo addslashes($question->description); ?>";
     561                    addQuestion(code, title, description);
     562                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
    538563                    var select = document.getElementById('<?php echo $numQ; ?>');
    539564                    var type = '<?php echo $question->type; ?>';
     
    547572                        }
    548573                    }     
    549                                                                                                                                                                                                                                                                                                                    
    550                                                                                                                                                                                                                                                                                                                    
     574                                                                                                                                                                                                                                                                                                                                   
     575                                                                                                                                                                                                                                                                                                                                   
    551576                    /* questionID stuff */
    552577                    var questionIDInput = document.createElement("input");
     
    555580                    questionIDInput.value = "<?php echo $question->id; ?>";
    556581                    questionIDInput.type = "hidden";
    557                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
     582                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
    558583                    document.getElementById("questionsDiv").appendChild(questionIDInput);
    559584
  • Dev/trunk/dashboard.php

    r96 r98  
    88
    99$survey = new Survey('ultimateid', 'The Epic Survey');
    10 $question1 = new Question('question1id', 'Age', 'int', 'What is your age?');
    11 $question2 = new Question('question2id', 'Identity', 'mc', 'Are you freakazoid?');
     10$question1 = new Question('question1id', 'AE340', 'Age', 'int', 'What is your age?');
     11$question2 = new Question('question2id', 'XV453', 'Identity', 'mc', 'Are you freakazoid?');
    1212$question2->answers = array('yes', 'no', 'maybe');
    1313
  • Dev/trunk/doc/TODO

    r97 r98  
    1717    Save question to database
    1818    Load existing question
    19     Question code
     19    **Question code
    2020    Question category
    2121
    2222Dashboard
    2323    Dashboard Menu
    24     **DashboardCreationTool
     24    DashboardCreationTool
    2525    Dashboard kunnen selecteren bij Session
    2626   
     
    3535
    3636
     37TODO voor Bas :D
     38Question code erbijgooien
     39
Note: See TracChangeset for help on using the changeset viewer.