index.php 4.3 KB

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