1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- require_once("../../php/db_utils.php");
-
- try {
- // Declarations
- $ownerExists = false;
-
- // Connect to the database
- $database = db_connect();
-
- // Incoming data
- $canvasId = $_POST["canvas_id"];
-
- // Check if the collaborator is a member
- $query = 'SELECT collaborator
- FROM collaborators
- WHERE canvas_id = "' . $canvasId . '"
- AND collaborator = (SELECT canvas.user_id
- FROM collaborators
- INNER JOIN canvas ON canvas.canvas_id = collaborators.canvas_id
- AND canvas.canvas_id = "' . $canvasId . '"
- LIMIT 1);';
-
- $recordSet = db_query_return($database, $query);
-
- $record = mysqli_fetch_assoc($recordSet);
-
- if(isset($record["collaborator"])) {
- $ownerExists = true;
- }
-
- // If the owner does not already exist
- if($ownerExists == false) {
- // Add owner
- $query = 'INSERT INTO collaborators (canvas_id, collaborator)
- VALUES ("' . $canvasId . '",
- (SELECT user_id
- FROM canvas
- WHERE canvas_id = "' . $canvasId . '"
- LIMIT 1));';
-
- // 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);
- }
- ?>
|