index.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. session_start();
  3. if (!isset($_SESSION['hash_user'])) {
  4. header('Location: login.php');
  5. exit;
  6. }
  7. ?>
  8. <html>
  9. <head>
  10. <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
  11. <title>LInE Quest</title>
  12. <style>
  13. body {
  14. font-family: Arial;
  15. }
  16. table {
  17. border-collapse: collapse;
  18. width: 100%;
  19. margin-bottom: 1em;
  20. }
  21. table td, table th {
  22. border: 1px solid #ddd;
  23. padding: 8px;
  24. }
  25. table tr:nth-child(even){background-color: #f2f2f2;}
  26. table tr:hover {background-color: #ddd;}
  27. table tr:hover td {border: 1px solid white;}
  28. table th {
  29. padding-top: 12px;
  30. padding-bottom: 12px;
  31. text-align: left;
  32. background-color: #4CAF50;
  33. color: white;
  34. }
  35. .pagination {
  36. display: inline-block;
  37. margin-top: 1em;
  38. }
  39. .pagination a {
  40. color: black;
  41. float: left;
  42. padding: 8px 16px;
  43. text-decoration: none;
  44. border: 1px solid #ddd;
  45. }
  46. .pagination a:hover:not(.active) {background-color: #ddd;}
  47. .pagination a:first-child {
  48. border-top-left-radius: 5px;
  49. border-bottom-left-radius: 5px;
  50. }
  51. .pagination a:last-child {
  52. border-top-right-radius: 5px;
  53. border-bottom-right-radius: 5px;
  54. }
  55. .disabled {
  56. pointer-events: none;
  57. cursor: default;
  58. text-decoration: none;
  59. color: #918a8a !important;;
  60. background-color: #f0efef;
  61. }
  62. .export {
  63. float: right;
  64. }
  65. .total {
  66. float: left;
  67. }
  68. </style>
  69. </head>
  70. <body>
  71. <?php
  72. require_once('../controller/forms.php');
  73. $secret = $_SESSION['hash_user'];
  74. $form_id = get_user_form($secret);
  75. $info = getQuestionaireInfoBySecret($secret);
  76. $folder = $info['view_hash'];
  77. $cleanTitle = cleanTitle($info['title']);
  78. $date = new DateTime($info['date']);
  79. $datePart = $date->format("Y-m-j");
  80. $filePath = "$datePart-$cleanTitle-$folder.html";
  81. $link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ?
  82. "https" : "http") . "://" . $_SERVER['HTTP_HOST'] .
  83. '/forms/'.$filePath;
  84. echo "<p>Link para seu questionário: <a target='_blank' href='$link'>$link</a></p>"
  85. ?>
  86. <table>
  87. <?php
  88. if (isset($_GET['pageno'])) {
  89. $pageno = $_GET['pageno'];
  90. } else {
  91. $pageno = 1;
  92. }
  93. $no_of_records_per_page = 10;
  94. $offset = ($pageno-1) * $no_of_records_per_page;
  95. $total_rows = get_total_rows($form_id);
  96. $total_pages = ceil($total_rows / $no_of_records_per_page);
  97. $res_data = get_records_pagination($form_id, $offset, $no_of_records_per_page);
  98. $all_fields = array();
  99. foreach($res_data as $form) {
  100. foreach($form as $key => $val) {
  101. if(!in_array($key, $all_fields)) {
  102. $all_fields[] = $key;
  103. }
  104. }
  105. }
  106. print '<tr> <th>id</th>';
  107. foreach($all_fields as $field) {
  108. if ($field == 'id') continue;
  109. print "<th>$field</th>";
  110. }
  111. print '</tr>';
  112. foreach($res_data as $form) {
  113. print '<tr>';
  114. print '<td>'.$form->id.'</td>';
  115. foreach($all_fields as $field) {
  116. if ($field == 'id') continue;
  117. print '<td>';
  118. if ($field === 'timestamp') {
  119. print date("H:i:s d/m/Y", $form->$field).'</td>';
  120. continue;
  121. }
  122. if (isset($form->$field)) print $form->$field.'</td>';
  123. else print '</td>';
  124. }
  125. print '</tr>';
  126. }
  127. ?>
  128. </table>
  129. <div class="total">
  130. Total de registros: <b><?= $total_rows ?></b>
  131. </div>
  132. <div class="export">
  133. Exportar como: <a href="export.php?format=csv">CSV</a>
  134. </div>
  135. <center>
  136. <div class="pagination">
  137. <a class="<?php if($pageno <= 1){ echo 'disabled'; } ?>" href="?formulario=<?= $form_id ?>&pageno=1">Primeira</a>
  138. <a class="<?php if($pageno <= 1){ echo 'disabled'; } ?>" href="<?php if($pageno <= 1){ echo '#'; } else { echo "?formulario=$form_id&pageno=".($pageno - 1); } ?>">Anterior</a>
  139. <a class="<?php if($pageno >= $total_pages){ echo 'disabled'; } ?>" href="<?php if($pageno >= $total_pages){ echo '#'; } else { echo "?formulario=$form_id&pageno=".($pageno + 1); } ?>">Próxima</a>
  140. <a class="<?php if($pageno >= $total_pages){ echo 'disabled'; } ?>" href="?formulario=<?= $form_id ?>&pageno=<?php echo $total_pages; ?>">Última</a>
  141. </div>
  142. </center>
  143. </body>
  144. </html>