index.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. session_start();
  3. if (!isset($_SESSION['auth'])) {
  4. header('Location: login.php');
  5. exit;
  6. }
  7. if (isset($_GET['logout'])) {
  8. unset($_SESSION['auth']);
  9. session_destroy();
  10. header('Location: login.php');
  11. exit;
  12. }
  13. ?>
  14. <html>
  15. <head>
  16. <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
  17. <title>LInE Quest</title>
  18. <style>
  19. body {
  20. font-family: Arial;
  21. }
  22. table {
  23. border-collapse: collapse;
  24. width: 100%;
  25. margin-bottom: 1em;
  26. }
  27. table td, table th {
  28. border: 1px solid #ddd;
  29. padding: 8px;
  30. }
  31. table tr:nth-child(even){background-color: #f2f2f2;}
  32. table tr:hover {background-color: #ddd;}
  33. table tr:hover td {border: 1px solid white;}
  34. table th {
  35. padding-top: 12px;
  36. padding-bottom: 12px;
  37. text-align: left;
  38. background-color: #4CAF50;
  39. color: white;
  40. }
  41. .pagination {
  42. display: inline-block;
  43. margin-top: 1em;
  44. }
  45. .pagination a {
  46. color: black;
  47. float: left;
  48. padding: 8px 16px;
  49. text-decoration: none;
  50. border: 1px solid #ddd;
  51. }
  52. .pagination a:hover:not(.active) {background-color: #ddd;}
  53. .pagination a:first-child {
  54. border-top-left-radius: 5px;
  55. border-bottom-left-radius: 5px;
  56. }
  57. .pagination a:last-child {
  58. border-top-right-radius: 5px;
  59. border-bottom-right-radius: 5px;
  60. }
  61. .disabled {
  62. pointer-events: none;
  63. cursor: default;
  64. text-decoration: none;
  65. color: #918a8a !important;;
  66. background-color: #f0efef;
  67. }
  68. .export {
  69. float: right;
  70. }
  71. .total {
  72. float: left;
  73. }
  74. .button {
  75. border: none;
  76. color: white;
  77. background-color: #555555;
  78. padding: 15px 32px;
  79. text-align: center;
  80. text-decoration: none;
  81. display: inline-block;
  82. font-size: 16px;
  83. }
  84. </style>
  85. </head>
  86. <body>
  87. <?php
  88. print "<p><a class='button' href='?logout'>Sair</a></p>";
  89. ?>
  90. <table>
  91. <?php
  92. require_once('../controller/admin.php');
  93. require_once('../controller/validator.php');
  94. require_once('../controller/util.php');
  95. if (isset($_GET['check'])) {
  96. try {
  97. $hash = Validator::str($_GET['check']);
  98. switchQuestionnaireActive($hash);
  99. } catch (Exception $e) {
  100. }
  101. }
  102. if (isset($_GET['pageno'])) {
  103. $pageno = Validator::int($_GET['pageno']);
  104. } else {
  105. $pageno = 1;
  106. }
  107. $no_of_records_per_page = 10;
  108. $offset = ($pageno-1) * $no_of_records_per_page;
  109. $total_rows = getQuestionnairesTotal();
  110. $total_pages = ceil($total_rows / $no_of_records_per_page);
  111. $res_data = paginateQuestionnaire($offset, $no_of_records_per_page);
  112. $all_fields = ['Título','Visualizar','Email','Ativar?'];
  113. print '<tr>';
  114. foreach($all_fields as $field) {
  115. print "<th>$field</th>";
  116. }
  117. print '</tr>';
  118. foreach($res_data as $form) {
  119. $id = $form['view_hash'];
  120. $url = generateURI("/forms/viewer.php?id=$id");
  121. $active = boolval($form['active']) ? 'checked' : '';
  122. $email = $form['email'];
  123. print '<tr>';
  124. print '<td>'.$form['title'].'</td>';
  125. print "<td><a target='_blank' href='$url'>link</a></td>";
  126. print "<td><a href='mailto:$email'>$email</a></td>";
  127. print "<td><a href='?pageno=$pageno&check=$id'><input type='checkbox' $active/></a></td>";
  128. print '</tr>';
  129. }
  130. ?>
  131. </table>
  132. <div class="total">
  133. Total de questionários: <b><?= $total_rows ?></b>
  134. </div>
  135. <center>
  136. <div class="pagination">
  137. <a class="<?php if($pageno <= 1){ echo 'disabled'; } ?>" href="?pageno=1">Primeira</a>
  138. <a class="<?php if($pageno <= 1){ echo 'disabled'; } ?>" href="<?php if($pageno <= 1){ echo '#'; } else { echo "?pageno=".($pageno - 1); } ?>">Anterior</a>
  139. <a class="<?php if($pageno >= $total_pages){ echo 'disabled'; } ?>" href="<?php if($pageno >= $total_pages){ echo '#'; } else { echo "?pageno=".($pageno + 1); } ?>">Próxima</a>
  140. <a class="<?php if($pageno >= $total_pages){ echo 'disabled'; } ?>" href="?pageno=<?php echo $total_pages; ?>">Última</a>
  141. </div>
  142. </center>
  143. </body>
  144. </html>