toggle-public.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. // Check if the tag already exists
  9. $query = 'SELECT canvas_public FROM canvas WHERE canvas_id = "' . $canvasId . '";';
  10. $recordSet = db_query_return($database, $query);
  11. $record = mysqli_fetch_assoc($recordSet);
  12. $public = $record["canvas_public"];
  13. mysqli_free_result($recordSet);
  14. // If the canvas is public
  15. if($public == "0") {
  16. // Update description
  17. $query = 'UPDATE canvas SET canvas_public="1" WHERE canvas_id="' . $canvasId . '";';
  18. echo("1");
  19. }
  20. // Else if the canvas is not public
  21. else if($public == "1") {
  22. // Add new tag with the description
  23. $query = 'UPDATE canvas SET canvas_public="0" WHERE canvas_id="' . $canvasId . '";';
  24. echo("0");
  25. }
  26. // Update old project title
  27. db_query_no_return($database, $query);
  28. // Close the connection to the database
  29. db_close($database);
  30. }
  31. catch(Exception $e) {
  32. $errorMsg = $e->getMessage();
  33. print_r($errorMsg);
  34. }
  35. ?>