Changeset 29


Ignore:
Timestamp:
07/21/11 14:51:50 (14 years ago)
Author:
fpvanagthoven
Message:

ID passed. Simple Question and Survey php data classes.

Location:
Dev/trunk
Files:
2 added
3 edited

Legend:

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

    r25 r29  
    99class SurveyCreationTool {
    1010
     11    private $survey;
     12    private $timeStamp;
     13
    1114    public function __construct($survey = null, $timeStamp = null) {
     15        $this->survey = $survey;
     16        $this->timeStamp = $timeStamp;
     17
    1218        SurveyCreationTool::javascript();
    1319        ?>
     
    1521        <div id="surveyCreation"><form id="survey" action="submitsurvey.php" method="post">
    1622                <?php
    17                 SurveyCreationTool::surveyHead($timeStamp);
    18                 SurveyCreationTool::questionCreationForm();
     23                $this->surveyHead();
     24                $this->questionCreationForm();
    1925                SurveyCreationTool::addQuestionButton();
    2026                SurveyCreationTool::removeLastQuestionButton();
     
    2935            /* autosave every 3 minutes */
    3036        setTimeout("save()", 180000);
    31                    
     37                                                   
    3238        var questionCount = 1;         
    33                                                                                                                                                            
     39                                                                                                                                                                                           
    3440        function getNewQuestion()
    3541        {
     42                       
    3643            var questionDiv = document.createElement("div");
    3744            var htmlStr =
     
    4047                "<th>Question " + questionCount + "</th>" +
    4148                "<tr><td><label for='questionTitle'>Title</label></td>" +
    42                 "<td><input type='text' class='questionTitle' name='questionTitle" + questionCount + "' onfocus='handleFocus(this)' size='30' value='Untitled Question' /></td></tr>" +
     49                "<td><input type='text' class='questionTitle' name='questionTitle" + questionCount + "' onfocus='handleFocus(this)' size='30' value='' /></td></tr>" +
    4350                "<tr><td><label for='questionDescription'>Description</label></td>" +
    4451                "<td><input type='text' class='questionDescription' name='questionDescription" + questionCount + "' onfocus='handleFocus(this)' size='60' value='Write a question description here.' /></td>" +
     
    5461                "<div id='answersDiv" + questionCount + "' class='answersDiv'></div>" +
    5562                "</div>";
    56                                                                                                                                                        
     63                                                                                                                                                                                       
    5764            questionDiv.innerHTML = htmlStr;
    58                                                                                                                                                        
     65                                                                                                                                                                                       
    5966            return questionDiv;
    6067        }
    61                                                                                                                                                            
     68                                                                                                                                                                                           
    6269        function handleFocus(input)
    6370        {
     
    6976            }
    7077        }
    71                                                                                                                                                                                            
     78                                                                                                                                                                                                                           
    7279        function handleBlur(input)
    7380        {       
    7481            var surveyTitle = document.getElementById('surveyTitle');
    7582            var surveyDescription = document.getElementById('surveyDescription');
    76                                                                                                                                                                            
     83                                                                                                                                                                                                           
    7784            if (input.value == "")
    7885            {
    7986                input.style.color = "gray";
    8087                input.clicked = null;
    81                                                                                                                                                                                                    
     88                                                                                                                                                                                                                                   
    8289                if (input == surveyTitle)
    8390                {
     
    9097            }                           
    9198        }
    92                                                                                                                                            
     99                                                                                                                                                                           
    93100        function handleType(select)
    94101        {
     
    97104            answersDiv.answerCount = 1;
    98105            answersDiv.clicked = null;
    99                                                                                                
     106                                                                                                                               
    100107            switch (type) {
    101108                case 'mc':
    102109                    answersDiv.innerHTML = "";
    103110                    addOption(select.id);
    104                                                                                                                                
     111                                                                                                                                                               
    105112                    break;
    106113                case 'text':
     
    126133
    127134        }
    128                                                                                                                            
    129                                                                                                                    
     135                                                                                                                                                           
     136                                                                                                                                                   
    130137        function addOption(questionNumber)
    131138        {       
     
    134141            var answerDiv = document.createElement("div");
    135142            answerDiv.className = "answerDiv";
    136                                                                                                                        
     143                                                                                                                                                       
    137144            var htmlStr = "<input type='text' name='q" +
    138145                questionNumber + "ans" + answerCount + "' value='Option " + answerCount + "' />";
    139                                                                                                
     146                                                                                                                               
    140147            if (answersDiv.clicked == null)
    141148            {
     
    143150                    + " class='surveyButton' onclick='addOption(" + questionNumber + ")' value='Add Option' />" +
    144151                    "<input type='button' class='surveyButton' onclick='removeOption(" + questionNumber + ")' value='x' />";
    145                                                                    
     152                                                                                                   
    146153                answersDiv.clicked = true;
    147154            }
    148                                                                                                                                
     155                                                                                                                                                              
    149156            answerDiv.innerHTML = htmlStr;
    150                                                                
     157                                                                                               
    151158            answerDiv.prev = answersDiv.lastAnswer; //singly linked list
    152159            answersDiv.lastAnswer = answerDiv;
    153                                                                                                                                
     160                                                                                                                                                              
    154161            answersDiv.appendChild(answerDiv);
    155162            answersDiv.answerCount++;
    156163        }
    157                                                            
     164                                                                                           
    158165        function removeOption(questionNumber)
    159166        {
    160167            var answersDiv = document.getElementById("answersDiv" + questionNumber);
    161                                                                
     168                                                                                              
    162169            if (answersDiv.lastAnswer.prev != null)
    163170            {
     
    167174            }
    168175        }
    169                                                                                    
     176                                                                                                                   
    170177        function minMax(questionNumber)
    171178        {
    172179            var answersDiv = document.getElementById("answersDiv" + questionNumber);
    173                                                                                        
     180                                                                                                                      
    174181            var answerDiv = document.createElement("div");
    175                                                        
     182                                                                                       
    176183            answerDiv.className = "answerDiv";
    177184            answerDiv.innerHTML = "<label for='min'>Min</label><input type='text' name='q" + questionNumber + "ans1' />" +
    178185                "<label for='max'>Max</label><input type='text' name='q" + questionNumber + "ans2' />";
    179                                                                                    
     186                                                                                                                  
    180187            answersDiv.appendChild(answerDiv);
    181188        } 
    182                                                                                    
     189                                                                                                                   
    183190        function minMaxIncr(questionNumber)
    184191        {
    185192            var answersDiv = document.getElementById("answersDiv" + questionNumber);
    186                                                                                        
     193                                                                                                                      
    187194            var answerDiv = document.createElement("div");
    188195            answerDiv.className = "answerDiv";
    189196            answerDiv.innerHTML = "<label>Left label</label><input type='text' name='q" + questionNumber + "ans1' />" +
    190197                "<label>Right label</label><input type='text' name='q" + questionNumber + "ans2' />" +
    191                 "<label>Scale count</label><input type='text' name='q" + questionNumber + "ans3' />";
    192                                                                                    
     198                "<label>Scale count</label><input type='text' name='q" + questionNumber + "ans3' />" +
     199                "<div id='inputCheckFeedback'" + questionNumber + "";
     200                                                                                                                   
    193201            answersDiv.appendChild(answerDiv);
    194202        }         
    195                                                                                                                                          
    196                                                                                                                                                  
    197         function addQuestion()
     203                                                                                                                                                                        
     204                                                                                                                                                                                
     205        function addQuestion(title, description)
    198206        {
    199207            var questionsDiv = document.getElementById('questionsDiv');
    200             var newQuestion = getNewQuestion();
    201                                                                                
     208            var newQuestion = getNewQuestion(title, description);
     209                                                                                                               
    202210
    203211            newQuestion.prev = document.lastQuestion;
     
    207215            questionCount++;
    208216        }
    209                                                                            
     217                                                                                                           
    210218        function removeLastQuestion()
    211219        {
    212220            var questionsDiv = document.getElementById('questionsDiv');
    213                                                                                
     221                                                                                                               
    214222            if (document.lastQuestion.prev != null)
    215223            {
     
    223231            }               
    224232        }
    225                                                      
    226         function save()
     233                                                                                    
     234        function save(surveyID)
    227235        {
    228236            var form = document.getElementById('survey');
    229237            var questionsDiv = document.getElementById('questionsDiv');
    230238            form.action = "surveycreation.php";
    231                        
     239                                                       
    232240            /* extra time stamp */
    233241            var date = new Date();
     
    240248            timeStampInput.value = timeStamp;
    241249            timeStampInput.type = "hidden";
    242                        
     250           
     251            var surveyIDInput = document.createElement("input");
     252            surveyIDInput.name = "surveyID";
     253            surveyIDInput.value = surveyID;
     254            surveyIDInput.type = "hidden";
     255                                     
    243256            questionsDiv.appendChild(timeStampInput);
     257            questionsDiv.appendChild(surveyIDInput);
    244258            form.submit();
    245259        }
    246                                                                                    
    247                                                                                                                                                                                                                                                                    
     260                                                                                                                   
     261                                                                                                                                                                                                                                                                                                   
    248262        </script>
    249263        <?php
    250264    }
    251265
    252     private static function surveyHead($timeStamp = null) {
     266    private function surveyHead() {
    253267        ?><div id="surveyHead">
    254268        <?php
    255         SurveyCreationTool::titleBox();
    256         SurveyCreationTool::saveSurvey($timeStamp);
    257         SurveyCreationTool::descriptionBox();
     269        $this->titleBox();
     270        $this->saveSurvey();
     271        $this->descriptionBox();
    258272        ?></div>
    259273        <?php
    260274    }
    261275
    262     private static function titleBox() {
    263         ?>
    264         <input type="text" id="surveyTitle" name="surveyTitle" value="Untitled Survey" onblur="handleBlur(this)" onfocus="handleFocus(this)" />
    265         <?php
    266     }
    267 
    268     private static function saveSurvey($timeStamp = null) {
    269         if (isset($timeStamp))
    270             echo "<div id='timeStamp'>Last saved " . $timeStamp . '</div>';
    271         ?>
    272         <input id="surveySaveButton" type="button" onclick="save()" class='surveyButton' value='Save' />
    273         <?php
    274     }
    275 
    276     private static function descriptionBox() {
    277         ?>
    278         <textarea id="surveyDescription" name="surveyDescription" onblur="handleBlur(this)" onfocus="handleFocus(this)">Write a helpful description for this survey here.</textarea>
    279         <?php
    280     }
    281 
    282     private static function questionCreationForm() {
     276    private function titleBox() {
     277        if (isset($this->survey->title))
     278            $value = $this->survey->title;
     279        else
     280            $value = 'Untitled Survey';
     281        ?>
     282        <input type="text" id="surveyTitle" name="surveyTitle" value="<?php echo $value ?>" onblur="handleBlur(this)" onfocus="handleFocus(this)" />
     283        <?php
     284    }
     285
     286    private function saveSurvey() {
     287        if (isset($this->timeStamp))
     288            echo "<div id='timeStamp'>Last saved " . $this->timeStamp . '</div>';
     289        if (isset($this->survey->id))
     290            $id = $this->survey->id;
     291        else
     292            $id = null;
     293        ?>
     294        <input id="surveySaveButton" type="button" onclick="save('<?php echo $id; ?>')" class='surveyButton' value='Save' />
     295        <?php
     296    }
     297
     298    private function descriptionBox() {
     299        if (isset($this->survey->description))
     300            $value = $this->survey->description;
     301        else
     302            $value = 'Write a helpful description for this survey here.';
     303        ?>
     304        <textarea id="surveyDescription" name="surveyDescription" onblur="handleBlur(this)" onfocus="handleFocus(this)"><?php echo $value; ?></textarea>
     305        <?php
     306    }
     307
     308    private function questionCreationForm() {
    283309        ?>
    284310        <div id='questionsDiv'>
    285311        </div>
     312
    286313        <script type="text/javascript"> addQuestion(); </script>
    287314        <?php
  • Dev/trunk/css/style.css

    r25 r29  
    147147
    148148.surveyButton {
    149  
    150149    color: #888;
    151150    font-weight: bold;
    152151    background-color: #fff;
    153152    border: 2px solid #aaa;
    154     -moz-border-radius: 8px;
    155     border-radius: 8px;
     153    -moz-border-radius: 6px;
     154    border-radius: 6px;
    156155}
    157156
  • Dev/trunk/surveycreation.php

    r28 r29  
    1 <?php require 'classes/master.php';
     1<?php
     2require 'classes/master.php';
     3
     4$savedSurvey = null;
    25
    36if (isset($_POST['timeStamp']))
     
    1215        echo '<br/><br/>';
    1316        var_dump($info);
     17       
     18        $savedSurvey = Survey::getSurvey($info);
    1419}
    1520else {
    1621    $timeStamp = null;
    1722}
    18 
    1923
    2024?>
     
    3135    <body>
    3236        <div id="header">
    33                 <div id="logo">CPSFacilitator Tool </div>
    34             </div>
     37            <div id="logo">CPSFacilitator Tool </div>
     38        </div>
    3539        <div id="wrapper">
    36            
     40
    3741            <div id="content">
    3842                <?php
    39                     new SurveyCreationTool(null, $timeStamp);
     43     
     44                new SurveyCreationTool($savedSurvey, $timeStamp);
    4045                ?>
    4146            </div>
Note: See TracChangeset for help on using the changeset viewer.