Changeset 98 for Dev/trunk/classes
- Timestamp:
- 09/01/11 15:25:59 (14 years ago)
- Location:
- Dev/trunk/classes
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/classes/Question.php
r35 r98 13 13 class Question { 14 14 public $id; 15 public $code; 15 16 public $title; 16 17 public $type; … … 18 19 public $answers; // format answers['#'] 19 20 20 public function __construct($id, $ title, $type, $description = null)21 public function __construct($id, $code, $title, $type, $description = null) 21 22 { 22 23 $this->id = $id; 24 $this->code = $code; 23 25 $this->title = $title; 24 26 $this->type = $type; -
Dev/trunk/classes/Survey.php
r95 r98 48 48 while (isset($info['questionTitle' . $numQ])) { 49 49 $id = $info['questionID' . $numQ]; 50 $code = $info['questionCode' . $numQ]; 50 51 $title = $info['questionTitle' . $numQ]; 51 52 $type = $info['questionType' . $numQ]; 52 53 $description = $info['questionDescription' . $numQ]; 53 54 54 $question = new Question($id, $ title, $type, $description);55 $question = new Question($id, $code, $title, $type, $description); 55 56 56 57 $numA = 1; //number answers -
Dev/trunk/classes/SurveyCreationTool.php
r91 r98 35 35 <script type="text/javascript" src="js/creation.js"></script> 36 36 <script type="text/javascript"> 37 /* autosave every 3minutes */38 setTimeout("save('<?php echo $id; ?>')", 180000);39 37 /* autosave every 5 minutes */ 38 setTimeout("save('<?php echo $id; ?>')", 300000); 39 40 40 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 44 47 if (title == null) 45 48 var title = 'Untitled Question'; 46 49 47 50 if (description == null) 48 51 var description = 'Write a question description here.'; 49 52 50 53 var questionDiv = document.createElement("div"); 51 54 questionDiv.id = "question" + questionCount; 52 55 questionDiv.className = "question"; 53 56 54 57 var questionTable = document.createElement("table"); 55 58 questionTable.className = "questionTable"; 56 59 57 60 var th = document.createElement("th"); 58 61 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 60 84 var row1 = document.createElement("tr"); 61 85 62 86 var col1 = document.createElement("td"); 63 87 var titleLabel = document.createElement("label"); … … 65 89 titleLabel.innerHTML = "Title"; 66 90 col1.appendChild(titleLabel); 67 91 68 92 var col2 = document.createElement("td"); 69 93 var titleInput = document.createElement("input"); … … 79 103 row1.appendChild(col1); 80 104 row1.appendChild(col2); 81 105 82 106 var row2 = document.createElement("tr"); 83 107 var col3 = document.createElement("td"); … … 86 110 descriptionLabel.innerHTML = "Description"; 87 111 col3.appendChild(descriptionLabel); 88 112 89 113 var col4 = document.createElement("td"); 90 114 var descriptionInput = document.createElement("input"); … … 93 117 descriptionInput.name = "questionDescription" + questionCount; 94 118 descriptionInput.setAttribute("onfocus", "handleFocus(this)"); 95 descriptionInput.setAttribute("size", 60);119 descriptionInput.setAttribute("size", 40); 96 120 descriptionInput.setAttribute("value", description); 97 121 col4.appendChild(descriptionInput); 98 122 99 123 row2.appendChild(col3); 100 124 row2.appendChild(col4); 101 125 102 126 var row3 = document.createElement("tr"); 103 127 var col5 = document.createElement("td"); … … 106 130 typeLabel.innerHTML = "Type answer"; 107 131 col5.appendChild(typeLabel); 108 132 109 133 var col6 = document.createElement("td"); 110 134 var select = document.createElement("select"); … … 118 142 "<option value='checkboxes'>Checkboxes</option>" + 119 143 "<option value='scale'>Scale</option>"; 120 144 121 145 col6.appendChild(select); 122 146 123 147 row3.appendChild(col5); 124 148 row3.appendChild(col6); 125 149 126 150 questionTable.appendChild(th); 151 questionTable.appendChild(row0); 127 152 questionTable.appendChild(row1); 128 153 questionTable.appendChild(row2); 129 154 questionTable.appendChild(row3); 130 155 131 156 var answerDiv = document.createElement("div"); 132 157 answerDiv.id = "answersDiv" + questionCount; 133 158 answerDiv.className = "answersDiv"; 134 159 135 160 questionDiv.appendChild(questionTable); 136 161 questionDiv.appendChild(answerDiv); 137 162 138 163 return questionDiv; 139 164 } 140 165 141 166 function handleType(select, answers) 142 167 { … … 144 169 var type = select.valueOf().value; 145 170 var answersDiv = document.getElementById("answersDiv" + numQ ); 146 171 147 172 removeQuestionID(numQ); 148 173 149 174 answersDiv.answerCount = 1; 150 175 answersDiv.clicked = null; 151 176 152 177 switch (type) { 153 178 case 'mc': … … 162 187 else 163 188 addOption(numQ); 164 189 165 190 break; 166 191 case 'text': … … 169 194 case 'int': 170 195 answersDiv.innerHTML = ""; 171 196 172 197 //min max 173 198 if (answers != null) … … 201 226 202 227 } 203 228 204 229 function handleAnswerChange(questionNumber) 205 230 { 206 231 removeQuestionID(questionNumber); 207 232 } 208 233 209 234 function removeQuestionID(questionNumber) 210 235 { … … 218 243 219 244 } 220 221 245 246 222 247 function addOption(questionNumber, optionStr) 223 248 { … … 225 250 var answerCount = answersDiv.answerCount; 226 251 var answerDiv = document.createElement("div"); 227 252 228 253 if (optionStr == null) 229 254 var optionStr = "Option " + answerCount; 230 231 255 256 232 257 answerDiv.className = "answerDiv"; 233 258 234 259 var answerInput = document.createElement("input"); 235 260 answerInput.setAttribute("type", "text"); … … 237 262 answerInput.setAttribute("onchange", "handleAnswerChange(" + questionNumber + ")"); 238 263 answerInput.setAttribute("value", optionStr); 239 264 240 265 answerDiv.appendChild(answerInput); 241 266 … … 248 273 addOpt.setAttribute("onclick", "addOption(" + questionNumber + ")"); 249 274 addOpt.setAttribute("value", "Add Option"); 250 275 251 276 var removeOpt = document.createElement("input"); 252 277 removeOpt.setAttribute("type", "button"); … … 254 279 removeOpt.setAttribute("onclick", "removeOption(" + questionNumber + ")"); 255 280 removeOpt.setAttribute("value", "x"); 256 281 257 282 answerDiv.appendChild(addOpt); 258 283 answerDiv.appendChild(removeOpt); 259 284 260 285 answersDiv.clicked = true; 261 286 } 262 287 263 288 answerDiv.prev = answersDiv.lastAnswer; //singly linked list 264 289 answersDiv.lastAnswer = answerDiv; 265 290 266 291 answersDiv.appendChild(answerDiv); 267 292 answersDiv.answerCount++; 268 293 269 294 handleAnswerChange(questionNumber); 270 295 } 271 296 272 297 function removeOption(questionNumber) 273 298 { 274 299 var answersDiv = document.getElementById("answersDiv" + questionNumber); 275 300 276 301 if (answersDiv.lastAnswer.prev != null) 277 302 { … … 280 305 answersDiv.answerCount--; 281 306 } 282 307 283 308 handleAnswerChange(questionNumber); 284 309 } 285 310 286 311 function minMax(questionNumber, min, max) 287 312 { … … 290 315 if (max == null) 291 316 var max = ''; 292 317 293 318 var answersDiv = document.getElementById("answersDiv" + questionNumber); 294 319 295 320 var answerDiv = document.createElement("div"); 296 321 297 322 answerDiv.className = "answerDiv"; 298 323 answerDiv.innerHTML = "<label for='min'>Min</label><input type='text' class='intBox' onchange='checkInt(this)' value='" + min + "' name='q" + questionNumber + "ans1' />" + 299 324 "<label for='max'>Max</label><input type='text' class='intBox' onchange='checkInt(this)' value='" + max + "' name='q" + questionNumber + "ans2' />"; 300 325 301 326 answersDiv.appendChild(answerDiv); 302 327 } 303 328 304 329 function minMaxIncr(questionNumber, left, right, incr) 305 330 { … … 314 339 if (incr == null) 315 340 var incr = ''; 316 341 317 342 var answersDiv = document.getElementById("answersDiv" + questionNumber); 318 343 319 344 var answerDiv = document.createElement("div"); 320 345 answerDiv.className = "answerDiv"; 321 346 322 347 var leftLabel = document.createElement("label"); 323 348 var rightLabel = document.createElement("label"); … … 326 351 rightLabel.innerHTML = "Right label"; 327 352 scaleLabel.innerHTML = "Scale count"; 328 353 329 354 var leftInput = document.createElement("input"); 330 355 leftInput.type = "text"; … … 333 358 leftInput.setAttribute("onchange", "handleAnswerChange(" 334 359 + questionNumber + ")"); 335 360 336 361 var rightInput = document.createElement("input"); 337 362 rightInput.type = "text"; … … 340 365 rightInput.setAttribute("onchange", "handleAnswerChange(" 341 366 + questionNumber + ")"); 342 367 343 368 var scaleInput = document.createElement("input"); 344 369 scaleInput.type = "text"; … … 349 374 + questionNumber + ")"); 350 375 scaleInput.name = "q" + questionNumber + "ans3"; 351 376 352 377 answerDiv.appendChild(leftLabel); 353 378 answerDiv.appendChild(leftInput); … … 356 381 answerDiv.appendChild(scaleLabel); 357 382 answerDiv.appendChild(scaleInput); 358 383 359 384 answersDiv.appendChild(answerDiv); 360 385 } 361 362 386 363 function addQuestion(title, description) 387 388 function addQuestion(code, title, description) 364 389 { 365 390 var questionsDiv = document.getElementById('questionsDiv'); 366 var newQuestion = getNewQuestion(title, description); 367 391 var newQuestion = getNewQuestion(code, title, description); 368 392 369 393 newQuestion.prev = document.lastQuestion; … … 373 397 questionCount++; 374 398 } 375 399 376 400 function removeLastQuestion() 377 401 { 378 402 var questionsDiv = document.getElementById('questionsDiv'); 379 380 if (document.lastQuestion .prev!= null)403 404 if (document.lastQuestion != null) 381 405 { 382 406 questionsDiv.removeChild(document.lastQuestion); … … 389 413 } 390 414 } 391 415 392 416 function save(surveyID) 393 417 { … … 397 421 var questionsDiv = document.getElementById('questionsDiv'); 398 422 form.action = "surveycreation.php"; 399 423 400 424 /* extra time stamp */ 401 425 var date = new Date(); … … 408 432 timeStampInput.value = timeStamp; 409 433 timeStampInput.type = "hidden"; 410 434 411 435 var surveyIDInput = document.createElement("input"); 412 436 surveyIDInput.name = "surveyID"; 413 437 surveyIDInput.value = surveyID; 414 438 surveyIDInput.type = "hidden"; 415 439 416 440 questionsDiv.appendChild(timeStampInput); 417 441 questionsDiv.appendChild(surveyIDInput); … … 419 443 } 420 444 } 421 445 422 446 function selectAll(input) 423 447 { 424 448 input.select(); 425 449 } 426 450 427 451 /* --- input checking --- */ 428 452 function checksPassed() 429 453 { 430 454 var form = document.getElementById('survey'); 431 455 432 456 for (var i = 0; i < form.length; i++) 433 457 { … … 437 461 return true; 438 462 } 439 463 440 464 function checkInt(input) 441 465 { … … 453 477 } 454 478 } 455 479 456 480 </script> 457 481 <?php … … 528 552 echo 'answers[' . $numA . '] = "' . addslashes($answer) . '"; '; 529 553 ?> 530 554 531 555 <?php 532 556 } 533 557 ?> 534 558 var code = "<?php echo addslashes($question->code); ?>"; 535 559 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 538 563 var select = document.getElementById('<?php echo $numQ; ?>'); 539 564 var type = '<?php echo $question->type; ?>'; … … 547 572 } 548 573 } 549 550 574 575 551 576 /* questionID stuff */ 552 577 var questionIDInput = document.createElement("input"); … … 555 580 questionIDInput.value = "<?php echo $question->id; ?>"; 556 581 questionIDInput.type = "hidden"; 557 582 558 583 document.getElementById("questionsDiv").appendChild(questionIDInput); 559 584
Note: See TracChangeset
for help on using the changeset viewer.