A simple system for creating multiple-choice questions for an audience to answer on their phones. Responses are tallied and displayed in real-time. https://openquestion.netsyms.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

question.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. include __DIR__ . "/../bits/navbar.php";
  3. ?>
  4. <style nonce="<?php echo $SECURE_NONCE; ?>">
  5. .progress {
  6. height: 2vh;
  7. }
  8. </style>
  9. <div class="container">
  10. <?php if (!$database->has('questions', ['qcode' => $arg1])) { ?>
  11. <div class="alert alert-warning">Whoops! There isn't a question with that ID code.</div>
  12. <?php
  13. die();
  14. }
  15. ?>
  16. <?php
  17. $qid = $database->get('questions', 'qid', ['qcode' => $arg1]);
  18. ?>
  19. <div class="row my-4">
  20. <div class="col-12 col-md-6">
  21. <h1><?php echo $database->get('questions', 'qtext', ['qid' => $qid]); ?></h1>
  22. </div>
  23. <div class="col-12 col-md-6">
  24. <div class="card">
  25. <div class="card-body">
  26. <h5><?php
  27. $url = ""; //(isset($_SERVER['https']) && $_SERVER['https'] != "" ? "https" : "http") . "://";
  28. $url .= $_SERVER['HTTP_HOST'];
  29. $url .= SITE_PATH . "respond";
  30. echo $url;
  31. ?></h5>
  32. <h3>Code: <?php echo $arg1; ?></h3>
  33. </div>
  34. </div>
  35. </div>
  36. </div>
  37. <div class="list-group">
  38. <?php
  39. $total = $database->count('responses', ['qid' => $qid]);
  40. $answers = $database->select('answers', ['aid', 'atext'], ['qid' => $qid]);
  41. $colors = ["primary", "success", "danger", "info", "warning"];
  42. $color = -1;
  43. foreach ($answers as $a) {
  44. $color++;
  45. if ($color > count($colors) - 1) {
  46. $color = 0;
  47. }
  48. $votes = $database->count('responses', ['aid' => $a['aid']]);
  49. ?>
  50. <div class="list-group-item">
  51. <h3 class="d-flex"><?php echo $a['atext']; ?> <span class="small ml-auto" id="votes_<?php echo $a['aid']; ?>"><?php echo $votes; ?> votes</span></h3>
  52. <style nonce="<?php echo $SECURE_NONCE; ?>">
  53. #progress_<?php echo $a['aid']; ?> {
  54. width: <?php echo ($votes / $total) * 100.0; ?>%;
  55. }
  56. </style>
  57. <div class="progress">
  58. <div id="progress_<?php echo $a['aid']; ?>" class="progress-bar bg-<?php echo $colors[$color]; ?>" role="progressbar"></div>
  59. </div>
  60. </div>
  61. <?php
  62. }
  63. ?>
  64. </div>
  65. </div>
  66. <script nonce="<?php echo $SECURE_NONCE; ?>">
  67. setInterval(function () {
  68. $.getJSON('<?php echo SITE_PATH; ?>getresults.php', {
  69. qid: <?php echo $qid; ?>
  70. }, function (data) {
  71. var total = data['total'];
  72. var answers = data['answers'];
  73. for (var i = 0; i < answers.length; i++) {
  74. $('#progress_' + answers[i]['id']).css('width', answers[i]['percent']);
  75. $('#votes_' + answers[i]['id']).text(answers[i]['votes'] + " votes");
  76. }
  77. });
  78. }, 1000);
  79. </script>