load_shared_canvases.php 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. /* Retrieves all the canvases created by the user passed by parameter in JSON format */
  3. // Retrieve user credentials
  4. $email = $_POST['loggedin_user_email'];
  5. require_once('../../php/db_utils.php');
  6. $conn = db_connect(); // Connect to the database
  7. // Check if the username already exists
  8. if(!($result = mysqli_query($conn, 'SELECT name FROM user WHERE username = "' . $email . '";'))) {
  9. echo 400; // Wrong query
  10. }
  11. else if(mysqli_num_rows($result) != 1) { // User not registered or duplicated
  12. echo 401;
  13. }
  14. else { // User registered: Retrieve canvases
  15. if(!($result = mysqli_query($conn,
  16. 'SELECT * FROM canvas INNER JOIN collaborators ON canvas.canvas_id = collaborators.canvas_id WHERE collaborators.collaborator = "' . $email . '" AND NOT canvas.user_id = "' . $email . '" ORDER BY canvas_name;'))) {
  17. echo 400; // Wrong query
  18. }
  19. else { // Request accepted
  20. $rows = array();
  21. while($r = mysqli_fetch_assoc($result)) {
  22. $rows[] = $r;
  23. }
  24. echo json_encode($rows);
  25. }
  26. }
  27. mysqli_free_result($result);
  28. db_close($conn); // Close the database
  29. ?>