get-typing.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. require_once("../../php/db_utils.php");
  3. try {
  4. // Connect to the database
  5. $database = db_connect();
  6. // Incoming data
  7. $canvasId = $_POST["canvas_id"];
  8. $username = $_POST["username"];
  9. // Declare query
  10. $query = 'SELECT user.name, collaborators.typing_id
  11. FROM collaborators
  12. INNER JOIN user ON collaborators.collaborator = user.username
  13. AND collaborators.canvas_id = "' . $canvasId . '"
  14. AND NOT collaborators.typing_id = ""
  15. AND NOT collaborators.collaborator = "' . $username . '";';
  16. // Run query
  17. $recordSet = db_query_return($database, $query);
  18. // Get typing ID
  19. $typing = Array();
  20. // Declare index
  21. $index = 0;
  22. // For every collaborator that is currently typing
  23. while($record = $recordSet->fetch_assoc()) {
  24. // Declare the collaborator
  25. $typing[$index]["name"] = $record["name"];
  26. // Declare the idea that is being typed in
  27. $typing[$index]["typingId"] = $record["typing_id"];
  28. // Increment index
  29. $index++;
  30. }
  31. mysqli_free_result($recordSet);
  32. echo(json_encode($typing));
  33. // Close the connection to the database
  34. db_close($database);
  35. }
  36. catch(Exception $e) {
  37. $errorMsg = $e->getMessage();
  38. print_r($errorMsg);
  39. }
  40. ?>