index.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. require_once('../controller/util.php');
  74. $secret = $_SESSION['hash_user'];
  75. $form_id = get_user_form($secret);
  76. $info = getQuestionaireInfoBySecret($secret);
  77. $folder = $info['view_hash'];
  78. $cleanTitle = cleanTitle($info['title']);
  79. $date = new DateTime($info['date']);
  80. $datePart = $date->format("Y-m-j");
  81. $filePath = "$datePart-$cleanTitle-$folder.html";
  82. $link = generateURI('/forms/'.$filePath);
  83. echo "<p>Link para seu questionário: <a target='_blank' href='$link'>$link</a></p>"
  84. ?>
  85. <table>
  86. <?php
  87. if (isset($_GET['pageno'])) {
  88. $pageno = $_GET['pageno'];
  89. } else {
  90. $pageno = 1;
  91. }
  92. $no_of_records_per_page = 10;
  93. $offset = ($pageno-1) * $no_of_records_per_page;
  94. $total_rows = get_total_rows($form_id);
  95. $total_pages = ceil($total_rows / $no_of_records_per_page);
  96. $res_data = get_records_pagination($form_id, $offset, $no_of_records_per_page);
  97. $all_fields = array();
  98. foreach($res_data as $form) {
  99. foreach($form as $key => $val) {
  100. if(!in_array($key, $all_fields)) {
  101. $all_fields[] = $key;
  102. }
  103. }
  104. }
  105. print '<tr> <th>id</th>';
  106. foreach($all_fields as $field) {
  107. if ($field == 'id') continue;
  108. print "<th>$field</th>";
  109. }
  110. print '</tr>';
  111. foreach($res_data as $form) {
  112. print '<tr>';
  113. print '<td>'.$form->id.'</td>';
  114. foreach($all_fields as $field) {
  115. if ($field == 'id') continue;
  116. print '<td>';
  117. if ($field === 'timestamp') {
  118. print date("H:i:s d/m/Y", $form->$field).'</td>';
  119. continue;
  120. }
  121. if (isset($form->$field)) print $form->$field.'</td>';
  122. else print '</td>';
  123. }
  124. print '</tr>';
  125. }
  126. ?>
  127. </table>
  128. <div class="total">
  129. Total de registros: <b><?= $total_rows ?></b>
  130. </div>
  131. <div class="export">
  132. Exportar como: <a href="export.php?format=csv">CSV</a>
  133. </div>
  134. <center>
  135. <div class="pagination">
  136. <a class="<?php if($pageno <= 1){ echo 'disabled'; } ?>" href="?formulario=<?= $form_id ?>&pageno=1">Primeira</a>
  137. <a class="<?php if($pageno <= 1){ echo 'disabled'; } ?>" href="<?php if($pageno <= 1){ echo '#'; } else { echo "?formulario=$form_id&pageno=".($pageno - 1); } ?>">Anterior</a>
  138. <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>
  139. <a class="<?php if($pageno >= $total_pages){ echo 'disabled'; } ?>" href="?formulario=<?= $form_id ?>&pageno=<?php echo $total_pages; ?>">Última</a>
  140. </div>
  141. </center>
  142. </body>
  143. </html>