index.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. $all_forms = get_forms();
  74. ?>
  75. <form>
  76. Selecione o identificador do formulário:
  77. <select name="formulario" onchange="this.form.submit()">
  78. <option></option>
  79. <?php
  80. foreach($all_forms as $form) {
  81. if ((isset($_GET['formulario'])
  82. && $_GET['formulario'] == $form)) {
  83. print "<option selected>$form</option>";
  84. } else {
  85. print "<option>$form</option>";
  86. }
  87. }
  88. ?>
  89. </select>
  90. </form>
  91. <table>
  92. <?php
  93. if ((!isset($_GET['formulario']))) exit;
  94. if (isset($_GET['pageno'])) {
  95. $pageno = $_GET['pageno'];
  96. } else {
  97. $pageno = 1;
  98. }
  99. $no_of_records_per_page = 10;
  100. $offset = ($pageno-1) * $no_of_records_per_page;
  101. $form_id = $_GET['formulario'];
  102. $total_rows = get_total_rows($form_id);
  103. $total_pages = ceil($total_rows / $no_of_records_per_page);
  104. $res_data = get_records_pagination($form_id, $offset, $no_of_records_per_page);
  105. $all_fields = array();
  106. foreach($res_data as $form) {
  107. foreach($form as $key => $val) {
  108. if(!in_array($key, $all_fields)) {
  109. $all_fields[] = $key;
  110. }
  111. }
  112. }
  113. print '<tr> <th>id</th>';
  114. foreach($all_fields as $field) {
  115. if ($field == 'id') continue;
  116. print "<th>$field</th>";
  117. }
  118. print '</tr>';
  119. foreach($res_data as $form) {
  120. print '<tr>';
  121. print '<td>'.$form->id.'</td>';
  122. foreach($all_fields as $field) {
  123. if ($field == 'id') continue;
  124. print '<td>';
  125. if ($field === 'timestamp') {
  126. print date("H:i:s d/m/Y", $form->$field).'</td>';
  127. continue;
  128. }
  129. if (isset($form->$field)) print $form->$field.'</td>';
  130. else print '</td>';
  131. }
  132. print '</tr>';
  133. }
  134. ?>
  135. </table>
  136. <div class="total">
  137. Total de registros: <b><?= $total_rows ?></b>
  138. </div>
  139. <div class="export">
  140. Exportar como: <a href="export.php?formulario=<?= $form_id ?>&format=csv">CSV</a>
  141. </div>
  142. <center>
  143. <div class="pagination">
  144. <a class="<?php if($pageno <= 1){ echo 'disabled'; } ?>" href="?formulario=<?= $form_id ?>&pageno=1">Primeira</a>
  145. <a class="<?php if($pageno <= 1){ echo 'disabled'; } ?>" href="<?php if($pageno <= 1){ echo '#'; } else { echo "?formulario=$form_id&pageno=".($pageno - 1); } ?>">Anterior</a>
  146. <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>
  147. <a class="<?php if($pageno >= $total_pages){ echo 'disabled'; } ?>" href="?formulario=<?= $form_id ?>&pageno=<?php echo $total_pages; ?>">Última</a>
  148. </div>
  149. </center>
  150. </body>
  151. </html>