admin.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Este arquivo é parte do software linequest
  4. * Ambiente de questionários para a coleta de dados
  5. *
  6. * Laboratório de Informática na Educação - LInE
  7. * https://www.usp.br/line/
  8. *
  9. * Utilize os atributos definidos abaixo para
  10. * configurar o ambiente de questionários.
  11. *
  12. * @author Lucas Calion
  13. * @author Igor Félix
  14. */
  15. require_once ('../config/linequest.php');
  16. function connect () {
  17. global $CFG, $DB;
  18. $DB = new mysqli($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname);
  19. if ($DB->connect_error) {
  20. die("Connection failed: " . $DB->connect_error);
  21. }
  22. $DB->set_charset("utf8");
  23. }
  24. function switchQuestionnaireActive ($hash) {
  25. global $DB; connect();
  26. $sql = "UPDATE questionnaire SET active = not active WHERE view_hash = ?";
  27. if (!($stmt = $DB->prepare($sql))) {
  28. die("Prepare failed: (" . $DB->errno . ") " . $DB->error);
  29. }
  30. $stmt->bind_param('s', $hash);
  31. $stmt->execute();
  32. $stmt->close();
  33. $DB->close();
  34. return;
  35. }
  36. function getQuestionnairesTotal () {
  37. global $DB; connect();
  38. $sql = "SELECT count(id) FROM questionnaire";
  39. if (!($stmt = $DB->prepare($sql))) {
  40. die("Prepare failed: (" . $DB->errno . ") " . $DB->error);
  41. }
  42. $stmt->execute();
  43. $stmt->bind_result($count);
  44. $stmt->fetch();
  45. $stmt->free_result();
  46. $stmt->close();
  47. $DB->close();
  48. return $count;
  49. }
  50. function paginateQuestionnaire ($page, $no_of_records_per_page) {
  51. global $DB; connect();
  52. $sql = "SELECT title, email, view_hash, active FROM questionnaire LIMIT ?, ?";
  53. if (!($stmt = $DB->prepare($sql))) {
  54. die("Prepare failed: (" . $DB->errno . ") " . $DB->error);
  55. }
  56. if (!$stmt->bind_param("ii", $page,$no_of_records_per_page)) {
  57. die("Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error);
  58. }
  59. if (!$stmt->execute()) {
  60. die("Execute failed: (" . $stmt->errno . ") " . $stmt->error);
  61. }
  62. $stmt->store_result();
  63. $stmt->bind_result($title, $email, $hash, $active);
  64. $all_data = array();
  65. while ($stmt->fetch()) {
  66. $all_data[] = ['title' => $title, 'email' => $email, 'view_hash' => $hash, 'active' => $active];
  67. }
  68. $stmt->free_result();
  69. $stmt->close();
  70. $DB->close();
  71. return $all_data;
  72. }