Changeset 72
- Timestamp:
- 08/04/11 11:31:06 (14 years ago)
- Location:
- Dev/trunk/classes
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/classes/ApplicationCreationTool.php
r68 r72 49 49 $value = 'Untitled Application'; 50 50 ?> 51 <input type="text" id="applicationTitle" class="titleBox" name="applicationTitle" value="<?php echo $value; ?>" onblur="handleBlur(this)" onfocus="handleFocus(this)" />51 <input type="text" id="applicationTitle" class="titleBox" name="applicationTitle" value="<?php echo str_replace("\"", """, $value); ?>" onblur="handleBlur(this)" onfocus="handleFocus(this)" /> 52 52 <?php 53 53 } -
Dev/trunk/classes/SessionCreationTool.php
r70 r72 152 152 $value = 'Untitled Session'; 153 153 ?> 154 <input type="text" id="sessionTitle" class="titleBox" name="sessionTitle" value="<?php echo $value; ?>" onblur="handleBlur(this)" onfocus="handleFocus(this)" />154 <input type="text" id="sessionTitle" class="titleBox" name="sessionTitle" value="<?php echo str_replace("\"", """, $value); ?>" onblur="handleBlur(this)" onfocus="handleFocus(this)" /> 155 155 <?php 156 156 } -
Dev/trunk/classes/SurveyCreationTool.php
r71 r72 39 39 /* autosave every 3 minutes */ 40 40 setTimeout("save('<?php echo $id; ?>')", 180000); 41 41 42 42 var questionCount = 1; 43 43 44 44 function getNewQuestion(title, description) 45 45 { 46 46 if (title == null) 47 47 var title = 'Untitled Question'; 48 else { 49 title.replace("'", "'"); 50 } 51 52 if (description != null) 53 { 54 description.replace("'", "'"); 55 } 56 else 48 49 if (description == null) 57 50 var description = 'Write a question description here.'; 58 51 59 52 var questionDiv = document.createElement("div"); 60 var htmlStr = 61 "<div id='question" + questionCount + "' class='question'>" + 62 "<table class='questionTable'>" + 63 "<th>Question " + questionCount + "</th>" + 64 "<tr><td><label for='questionTitle'>Title</label></td>" + 65 "<td><input id='questionTitle' type='text' class='questionTitle' name='questionTitle" + questionCount + "' onfocus='handleFocus(this)' size='30' /></td></tr>" + 66 "<tr><td><label for='questionDescription'>Description</label></td>" + 67 "<td><input type='text' class='questionDescription' name='questionDescription" + questionCount + "' onfocus='handleFocus(this)' size='60' value='" + description + "' /></td>" + 68 "<tr><td><label for='questionType'>Answer type</label></td>" + 69 "<td><select id='" + questionCount + "' name='questionType" + questionCount + "' onchange='handleType(this)'><br />"+ 53 questionDiv.id = "question" + questionCount; 54 questionDiv.className = "question"; 55 56 var questionTable = document.createElement("table"); 57 questionTable.className = "questionTable"; 58 59 var th = document.createElement("th"); 60 th.innerHTML = "Question " + questionCount; 61 62 var row1 = document.createElement("tr"); 63 64 var col1 = document.createElement("td"); 65 var titleLabel = document.createElement("label"); 66 titleLabel.setAttribute("for", "questionTitle"); 67 titleLabel.innerHTML = "Title"; 68 col1.appendChild(titleLabel); 69 70 var col2 = document.createElement("td"); 71 var titleInput = document.createElement("input"); 72 titleInput.id = "questionTitle"; 73 titleInput.setAttribute("type", "text"); 74 titleInput.className = "questionTitle"; 75 titleInput.setAttribute("name", "questionTitle" + questionCount); 76 titleInput.setAttribute("onfocus", "handleFocus(this)"); 77 titleInput.setAttribute("size", "30"); 78 titleInput.setAttribute("value", title); 79 col2.appendChild(titleInput); 80 81 row1.appendChild(col1); 82 row1.appendChild(col2); 83 84 var row2 = document.createElement("tr"); 85 var col3 = document.createElement("td"); 86 var descriptionLabel = document.createElement("label"); 87 descriptionLabel.setAttribute("for", "questionDescription"); 88 descriptionLabel.innerHTML = "Description"; 89 col3.appendChild(descriptionLabel); 90 91 var col4 = document.createElement("td"); 92 var descriptionInput = document.createElement("input"); 93 descriptionInput.type = "text"; 94 descriptionInput.className = "questionDescription"; 95 descriptionInput.name = "questionDescription" + questionCount; 96 descriptionInput.setAttribute("onfocus", "handleFocus(this)"); 97 descriptionInput.setAttribute("size", 60); 98 descriptionInput.setAttribute("value", description); 99 col4.appendChild(descriptionInput); 100 101 row2.appendChild(col3); 102 row2.appendChild(col4); 103 104 var row3 = document.createElement("tr"); 105 var col5 = document.createElement("td"); 106 var typeLabel = document.createElement("label"); 107 typeLabel.setAttribute("for", "questionType"); 108 typeLabel.innerHTML = "Type answer"; 109 col5.appendChild(typeLabel); 110 111 var col6 = document.createElement("td"); 112 var select = document.createElement("select"); 113 select.id = questionCount; 114 select.setAttribute("name", "questionType" + questionCount); 115 select.setAttribute("onchange", "handleType(this)"); 116 select.innerHTML = 70 117 "<option value='text' selected='selected'>Text</option>" + 71 118 "<option value='int'>Integer</option>" + 72 119 "<option value='mc'>Multiple choice</option>" + 73 120 "<option value='checkboxes'>Checkboxes</option>" + 74 "<option value='scale'>Scale</option>" + 75 "</select></td></tr>" + 76 "</table>" + 77 "<div id='answersDiv" + questionCount + "' class='answersDiv'></div>" + 78 "</div>"; 79 80 /* TODO: get rid of innerHTML bullshit and do dynamically so that ' will work */ 81 82 questionDiv.innerHTML = htmlStr; 83 121 "<option value='scale'>Scale</option>"; 122 123 col6.appendChild(select); 124 125 row3.appendChild(col5); 126 row3.appendChild(col6); 127 128 questionTable.appendChild(th); 129 questionTable.appendChild(row1); 130 questionTable.appendChild(row2); 131 questionTable.appendChild(row3); 132 133 var answerDiv = document.createElement("div"); 134 answerDiv.id = "answersDiv" + questionCount; 135 answerDiv.className = "answersDiv"; 136 137 questionDiv.appendChild(questionTable); 138 questionDiv.appendChild(answerDiv); 139 84 140 return questionDiv; 85 141 } 86 142 87 143 function handleType(select, answers) 88 144 { … … 90 146 var type = select.valueOf().value; 91 147 var answersDiv = document.getElementById("answersDiv" + numQ ); 92 148 93 149 removeQuestionID(numQ); 94 150 95 151 answersDiv.answerCount = 1; 96 152 answersDiv.clicked = null; 97 153 98 154 switch (type) { 99 155 case 'mc': … … 108 164 else 109 165 addOption(numQ); 110 166 111 167 break; 112 168 case 'text': … … 115 171 case 'int': 116 172 answersDiv.innerHTML = ""; 117 173 118 174 //min max 119 175 if (answers != null) … … 147 203 148 204 } 149 205 150 206 function handleAnswerChange(questionNumber) 151 207 { 152 208 removeQuestionID(questionNumber); 153 209 } 154 210 155 211 function removeQuestionID(questionNumber) 156 212 { … … 164 220 165 221 } 166 167 222 223 168 224 function addOption(questionNumber, optionStr) 169 225 { … … 171 227 var answerCount = answersDiv.answerCount; 172 228 var answerDiv = document.createElement("div"); 173 229 174 230 if (optionStr == null) 175 231 var optionStr = "Option " + answerCount; 176 177 232 233 178 234 answerDiv.className = "answerDiv"; 235 236 var answerInput = document.createElement("input"); 237 answerInput.setAttribute("type", "text"); 238 answerInput.setAttribute("name", "q" + questionNumber + "ans" + answerCount); 239 answerInput.setAttribute("onchange", "handleAnswerChange(" + questionNumber + ")"); 240 answerInput.setAttribute("value", optionStr); 241 242 answerDiv.appendChild(answerInput); 243 244 if (answersDiv.clicked == null) 245 { 246 var addOpt = document.createElement("input"); 247 addOpt.setAttribute("type", "button"); 248 addOpt.setAttribute("id", "addOpt"); 249 addOpt.setAttribute("class", "surveyButton"); 250 addOpt.setAttribute("onclick", "addOption(" + questionNumber + ")"); 251 addOpt.setAttribute("value", "Add Option"); 252 253 var removeOpt = document.createElement("input"); 254 removeOpt.setAttribute("type", "button"); 255 removeOpt.className = "surveyButton"; 256 removeOpt.setAttribute("onclick", "removeOption(" + questionNumber + ")"); 257 removeOpt.setAttribute("value", "x"); 258 259 answerDiv.appendChild(addOpt); 260 answerDiv.appendChild(removeOpt); 179 261 180 var htmlStr = "<input type='text' name='q" +181 questionNumber + "ans" + answerCount + "' onchange='handleAnswerChange(" + questionNumber + ")' value='" + optionStr + "' />";182 183 if (answersDiv.clicked == null)184 {185 htmlStr += "<input type='button' id='addOpt'"186 + " class='surveyButton' onclick='addOption(" + questionNumber + ")' value='Add Option' />" +187 "<input type='button' class='surveyButton' onclick='removeOption(" + questionNumber + ")' value='x' />";188 189 262 answersDiv.clicked = true; 190 263 } 191 192 answerDiv.innerHTML = htmlStr; 193 264 194 265 answerDiv.prev = answersDiv.lastAnswer; //singly linked list 195 266 answersDiv.lastAnswer = answerDiv; 196 267 197 268 answersDiv.appendChild(answerDiv); 198 269 answersDiv.answerCount++; 199 270 200 271 handleAnswerChange(questionNumber); 201 272 } 202 273 203 274 function removeOption(questionNumber) 204 275 { 205 276 var answersDiv = document.getElementById("answersDiv" + questionNumber); 206 277 207 278 if (answersDiv.lastAnswer.prev != null) 208 279 { … … 211 282 answersDiv.answerCount--; 212 283 } 213 284 214 285 handleAnswerChange(questionNumber); 215 286 } 216 287 217 288 function minMax(questionNumber, min, max) 218 289 { … … 221 292 if (max == null) 222 293 var max = ''; 223 294 224 295 var answersDiv = document.getElementById("answersDiv" + questionNumber); 225 296 226 297 var answerDiv = document.createElement("div"); 227 298 228 299 answerDiv.className = "answerDiv"; 229 300 answerDiv.innerHTML = "<label for='min'>Min</label><input type='text' class='intBox' onchange='checkInt(this)' value='" + min + "' name='q" + questionNumber + "ans1' />" + 230 301 "<label for='max'>Max</label><input type='text' class='intBox' onchange='checkInt(this)' value='" + max + "' name='q" + questionNumber + "ans2' />"; 231 302 232 303 answersDiv.appendChild(answerDiv); 233 304 } 234 305 235 306 function minMaxIncr(questionNumber, left, right, incr) 236 307 { … … 245 316 if (incr == null) 246 317 var incr = ''; 247 318 248 319 var answersDiv = document.getElementById("answersDiv" + questionNumber); 249 320 250 321 var answerDiv = document.createElement("div"); 251 322 answerDiv.className = "answerDiv"; 252 323 253 324 var leftLabel = document.createElement("label"); 254 325 var rightLabel = document.createElement("label"); … … 257 328 rightLabel.innerHTML = "Right label"; 258 329 scaleLabel.innerHTML = "Scale count"; 259 330 260 331 var leftInput = document.createElement("input"); 261 332 leftInput.type = "text"; … … 264 335 leftInput.setAttribute("onchange", "handleAnswerChange(" 265 336 + questionNumber + ")"); 266 337 267 338 var rightInput = document.createElement("input"); 268 339 rightInput.type = "text"; … … 271 342 rightInput.setAttribute("onchange", "handleAnswerChange(" 272 343 + questionNumber + ")"); 273 344 274 345 var scaleInput = document.createElement("input"); 275 346 scaleInput.type = "text"; … … 279 350 scaleInput.setAttribute("onchange", "handleAnswerChange(" 280 351 + questionNumber + ")"); 281 352 282 353 answerDiv.appendChild(leftLabel); 283 354 answerDiv.appendChild(leftInput); … … 286 357 answerDiv.appendChild(scaleLabel); 287 358 answerDiv.appendChild(scaleInput); 288 359 289 360 answersDiv.appendChild(answerDiv); 290 361 } 291 292 362 363 293 364 function addQuestion(title, description) 294 365 { 295 366 var questionsDiv = document.getElementById('questionsDiv'); 296 367 var newQuestion = getNewQuestion(title, description); 297 368 298 369 299 370 newQuestion.prev = document.lastQuestion; … … 303 374 questionCount++; 304 375 } 305 376 306 377 function removeLastQuestion() 307 378 { 308 379 var questionsDiv = document.getElementById('questionsDiv'); 309 380 310 381 if (document.lastQuestion.prev != null) 311 382 { … … 319 390 } 320 391 } 321 392 322 393 function save(surveyID) 323 394 { … … 327 398 var questionsDiv = document.getElementById('questionsDiv'); 328 399 form.action = "surveycreation.php"; 329 400 330 401 /* extra time stamp */ 331 402 var date = new Date(); … … 338 409 timeStampInput.value = timeStamp; 339 410 timeStampInput.type = "hidden"; 340 411 341 412 var surveyIDInput = document.createElement("input"); 342 413 surveyIDInput.name = "surveyID"; 343 414 surveyIDInput.value = surveyID; 344 415 surveyIDInput.type = "hidden"; 345 416 346 417 questionsDiv.appendChild(timeStampInput); 347 418 questionsDiv.appendChild(surveyIDInput); … … 349 420 } 350 421 } 351 422 352 423 function selectAll(input) 353 424 { 354 425 input.select(); 355 426 } 356 427 357 428 /* --- input checking --- */ 358 429 function checksPassed() 359 430 { 360 431 var form = document.getElementById('survey'); 361 432 362 433 for (var i = 0; i < form.length; i++) 363 434 { … … 367 438 return true; 368 439 } 369 440 370 441 function checkInt(input) 371 442 { … … 383 454 } 384 455 } 385 456 386 457 </script> 387 458 <?php … … 405 476 $value = 'Untitled Survey'; 406 477 ?> 407 <input type="text" id="surveyTitle" class="titleBox" name="surveyTitle" value="<?php echo $value; ?>" onblur="handleBlur(this)" onfocus="handleFocus(this)" />478 <input type="text" id="surveyTitle" class="titleBox" name="surveyTitle" value="<?php echo str_replace("\"", """, $value); ?>" onblur="handleBlur(this)" onfocus="handleFocus(this)" /> 408 479 <?php 409 480 } … … 456 527 /* Put all answers in js array */ 457 528 foreach ($question->answers as $numA => $answer) { 458 echo 'answers[' . $numA . '] = "' . $answer. '"; ';529 echo 'answers[' . $numA . '] = "' . addslashes($answer) . '"; '; 459 530 ?> 460 531 461 532 <?php 462 533 } 463 534 ?> 464 var title = "<?php echo $question->title; ?>"; 465 addQuestion(title, "<?php echo $question->description; ?>"); 466 535 536 var title = "<?php echo addslashes($question->title); ?>"; 537 addQuestion(title, "<?php echo addslashes($question->description); ?>"); 538 467 539 var select = document.getElementById('<?php echo $numQ; ?>'); 468 540 var type = '<?php echo $question->type; ?>'; … … 476 548 } 477 549 } 478 479 550 551 480 552 /* questionID stuff */ 481 553 var questionIDInput = document.createElement("input"); … … 484 556 questionIDInput.value = "<?php echo $question->id; ?>"; 485 557 questionIDInput.type = "hidden"; 486 558 487 559 document.getElementById("questionsDiv").appendChild(questionIDInput); 488 560
Note: See TracChangeset
for help on using the changeset viewer.