123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- /**
- * Este arquivo é parte do software linequest
- * Ambiente de questionários para a coleta de dados
- *
- * Laboratório de Informática na Educação - LInE
- * https://www.usp.br/line/
- *
- * Utilize os atributos definidos abaixo para
- * configurar o ambiente de questionários.
- *
- * @author Lucas Calion
- * @author Igor Félix
- */
- require_once ('../config/linequest.php');
- function connect () {
- global $CFG, $DB;
- $DB = new mysqli($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname);
- if ($DB->connect_error) {
- die("Connection failed: " . $DB->connect_error);
- }
- $DB->set_charset("utf8");
- }
- function switchQuestionnaireActive ($hash) {
- global $DB; connect();
- $sql = "UPDATE questionnaire SET active = not active WHERE view_hash = ?";
- if (!($stmt = $DB->prepare($sql))) {
- die("Prepare failed: (" . $DB->errno . ") " . $DB->error);
- }
- $stmt->bind_param('s', $hash);
- $stmt->execute();
- $stmt->close();
- $DB->close();
- return;
- }
- function getQuestionnairesTotal () {
- global $DB; connect();
- $sql = "SELECT count(id) FROM questionnaire";
- if (!($stmt = $DB->prepare($sql))) {
- die("Prepare failed: (" . $DB->errno . ") " . $DB->error);
- }
- $stmt->execute();
- $stmt->bind_result($count);
- $stmt->fetch();
- $stmt->free_result();
- $stmt->close();
- $DB->close();
- return $count;
- }
- function paginateQuestionnaire ($page, $no_of_records_per_page) {
- global $DB; connect();
- $sql = "SELECT title, email, view_hash, active FROM questionnaire LIMIT ?, ?";
- if (!($stmt = $DB->prepare($sql))) {
- die("Prepare failed: (" . $DB->errno . ") " . $DB->error);
- }
- if (!$stmt->bind_param("ii", $page,$no_of_records_per_page)) {
- die("Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error);
- }
- if (!$stmt->execute()) {
- die("Execute failed: (" . $stmt->errno . ") " . $stmt->error);
- }
- $stmt->store_result();
- $stmt->bind_result($title, $email, $hash, $active);
- $all_data = array();
- while ($stmt->fetch()) {
- $all_data[] = ['title' => $title, 'email' => $email, 'view_hash' => $hash, 'active' => $active];
- }
- $stmt->free_result();
- $stmt->close();
- $DB->close();
- return $all_data;
- }
|