12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- require_once("../../php/db_utils.php");
-
- try {
- // Connect to the database
- $database = db_connect();
-
- // Incoming data
- $canvasId = $_POST["canvas_id"];
- $username = $_POST["username"];
-
- // Update last active of the current user
- $query = 'UPDATE collaborators SET last_active = NOW() WHERE canvas_id = "' . $canvasId . '" AND collaborator = "' . $username . '";';
-
- // Run query
- db_query_no_return($database, $query);
-
- // Get collaborators
- $query = 'SELECT user.name, collaborators.collaborator, collaborators.last_active
- FROM collaborators
- INNER JOIN user ON collaborators.collaborator = user.username
- WHERE canvas_id = "' . $canvasId . '"
- ORDER BY name ASC;';
-
- // Run query
- $recordSet = db_query_return($database, $query);
-
- // Get list of users
- $activeCollaborators = Array();
-
- // Declare index
- $index = 0;
-
- // For every collaborator
- while($record = $recordSet->fetch_assoc()) {
- // Declare the collaborator
- $activeCollaborators[$index]["name"] = $record["name"];
- $activeCollaborators[$index]["collaborator"] = $record["collaborator"];
-
- // If the user was last active within now - 7 seconds ago
- if($record["last_active"] > date("Y-m-d H:i:s", strtotime("-3607 second"))) {
- // The collaborator is active
- $activeCollaborators[$index]["active"] = 1;
- }
- else {
- // The collaborator is not active
- $activeCollaborators[$index]["active"] = 0;
- }
-
- $index++;
- }
-
- mysqli_free_result($recordSet);
-
- echo(json_encode($activeCollaborators));
-
- // Close the connection to the database
- db_close($database);
- }
- catch(Exception $e) {
- $errorMsg = $e->getMessage();
- print_r($errorMsg);
- }
- ?>
|