index.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 th {
  28. padding-top: 12px;
  29. padding-bottom: 12px;
  30. text-align: left;
  31. background-color: #4CAF50;
  32. color: white;
  33. }
  34. .pagination {
  35. display: inline-block;
  36. margin-top: 1em;
  37. }
  38. .pagination a {
  39. color: black;
  40. float: left;
  41. padding: 8px 16px;
  42. text-decoration: none;
  43. border: 1px solid #ddd;
  44. }
  45. .pagination a:hover:not(.active) {background-color: #ddd;}
  46. .pagination a:first-child {
  47. border-top-left-radius: 5px;
  48. border-bottom-left-radius: 5px;
  49. }
  50. .pagination a:last-child {
  51. border-top-right-radius: 5px;
  52. border-bottom-right-radius: 5px;
  53. }
  54. .disabled {
  55. pointer-events: none;
  56. cursor: default;
  57. text-decoration: none;
  58. color: #918a8a !important;;
  59. background-color: #f0efef;
  60. }
  61. .export {
  62. float: right;
  63. }
  64. .total {
  65. float: left;
  66. }
  67. </style>
  68. </head>
  69. <body>
  70. <?php
  71. require_once('../controller/forms.php');
  72. $all_forms = get_forms();
  73. ?>
  74. <form>
  75. Selecione o identificador do formulário:
  76. <select name="formulario" onchange="this.form.submit()">
  77. <option></option>
  78. <?php
  79. foreach($all_forms as $form) {
  80. if ((isset($_GET['formulario'])
  81. && $_GET['formulario'] == $form)) {
  82. print "<option selected>$form</option>";
  83. } else {
  84. print "<option>$form</option>";
  85. }
  86. }
  87. ?>
  88. </select>
  89. </form>
  90. <table>
  91. <?php
  92. if ((!isset($_GET['formulario']))) exit;
  93. if (isset($_GET['pageno'])) {
  94. $pageno = $_GET['pageno'];
  95. } else {
  96. $pageno = 1;
  97. }
  98. $no_of_records_per_page = 10;
  99. $offset = ($pageno-1) * $no_of_records_per_page;
  100. $form_id = $_GET['formulario'];
  101. $total_rows = get_total_rows($form_id);
  102. $total_pages = ceil($total_rows / $no_of_records_per_page);
  103. $res_data = get_records_pagination($form_id, $offset, $no_of_records_per_page);
  104. $all_fields = array();
  105. foreach($res_data as $form) {
  106. foreach($form as $key => $val) {
  107. if(!in_array($key, $all_fields)) {
  108. $all_fields[] = $key;
  109. }
  110. }
  111. }
  112. print '<tr> <th>id</th>';
  113. foreach($all_fields as $field) {
  114. if ($field == 'id') continue;
  115. print "<th>$field</th>";
  116. }
  117. print '</tr>';
  118. foreach($res_data as $form) {
  119. print '<tr>';
  120. print '<td>'.$form->id.'</td>';
  121. foreach($all_fields as $field) {
  122. if ($field == 'id') continue;
  123. print '<td>';
  124. if ($field === 'timestamp') {
  125. print date("H:i:s d/m/Y", $form->$field).'</td>';
  126. continue;
  127. }
  128. print $form->$field.'</td>';
  129. }
  130. print '</tr>';
  131. }
  132. ?>
  133. </table>
  134. <div class="total">
  135. Total de registros: <b><?= $total_rows ?></b>
  136. </div>
  137. <div class="export">
  138. Exportar como: <a href="export.php?formulario=<?= $form_id ?>&format=csv">CSV</a>
  139. </div>
  140. <center>
  141. <div class="pagination">
  142. <a class="<?php if($pageno <= 1){ echo 'disabled'; } ?>" href="?formulario=<?= $form_id ?>&pageno=1">Primeira</a>
  143. <a class="<?php if($pageno <= 1){ echo 'disabled'; } ?>" href="<?php if($pageno <= 1){ echo '#'; } else { echo "?formulario=$form_id&pageno=".($pageno - 1); } ?>">Anterior</a>
  144. <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>
  145. <a class="<?php if($pageno >= $total_pages){ echo 'disabled'; } ?>" href="?formulario=<?= $form_id ?>&pageno=<?php echo $total_pages; ?>">Última</a>
  146. </div>
  147. </center>
  148. </body>
  149. </html>