123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- require_once("../../php/db_utils.php");
-
- try {
- // Declarations
- $collaboratorIsMember = false;
- $collaboratorExists = false;
-
- // Connect to the database
- $database = db_connect();
-
- // Incoming data
- $canvasId = $_POST["canvas_id"];
- $collaborator = $_POST["collaborator"];
-
- // Check if the collaborator is a member
- $query = 'SELECT username FROM user WHERE username = "' . $collaborator . '";';
- $recordSet = db_query_return($database, $query);
-
- $record = mysqli_fetch_assoc($recordSet);
-
- if(isset($record["username"])) {
- $collaboratorIsMember = true;
- }
-
- mysqli_free_result($recordSet);
-
- // Check if the collaborator already exists
- $query = 'SELECT * FROM collaborators WHERE canvas_id = "' . $canvasId . '" AND collaborator = "' . $collaborator . '";';
-
- $recordSet = db_query_return($database, $query);
-
- $record = mysqli_fetch_assoc($recordSet);
-
- if(isset($record["collaborator"])) {
- $collaboratorExists = true;
- }
-
- mysqli_free_result($recordSet);
-
- // If the collaborator is not already a member
- if($collaboratorIsMember == false) {
- echo(1);
- }
- // If the collaborator is already a collaborator
- else if($collaboratorExists == true) {
- echo(2);
- }
- else if($collaboratorIsMember == true && $collaboratorExists == false) {
- // Add collaborator
- $query = 'INSERT INTO collaborators (canvas_id, collaborator) VALUES ("' . $canvasId . '", "' . $collaborator . '");';
-
- echo(3);
- }
-
- // Insert new or update old description
- db_query_no_return($database, $query);
-
- // Close the connection to the database
- db_close($database);
- }
- catch(Exception $e) {
- $errorMsg = $e->getMessage();
- print_r($errorMsg);
- }
- ?>
|