exec("UPDATE `users` SET `role` = 'ADMIN' WHERE `id` = '" . $_SESSION["user_id"] . "';"); quitTeam(); header("Location: $URL_BASE"); exit(); } if (isset($_SESSION["user_id"]) && isset($_GET["be-organizer"])) { $DB->exec("UPDATE `users` SET `role` = 'ORGANIZER' WHERE `id` = '" . $_SESSION["user_id"] . "';"); quitTeam(); header("Location: $URL_BASE"); exit(); } if (isset($_SESSION["user_id"]) && isset($_GET["be-participant"])) { $DB->exec("UPDATE `users` SET `role` = 'PARTICIPANT' WHERE `id` = '" . $_SESSION["user_id"] . "';"); quitTeam(); header("Location: $URL_BASE"); exit(); } if (isset($_SESSION["user_id"]) && isset($_GET["be-encadrant"])) { $DB->exec("UPDATE `users` SET `role` = 'ENCADRANT' WHERE `id` = '" . $_SESSION["user_id"] . "';"); quitTeam(); header("Location: $URL_BASE"); exit(); } function quitTeam() { global $DB, $URL_BASE; if ($_SESSION["role"] == "ADMIN" || $_SESSION["role"] == "ORGANIZER") return; for ($i = 1; $i <= ($_SESSION["role"] == "PARTICIPANT" ? 6 : 2); ++$i) /** @noinspection SqlResolve */ $DB->exec("UPDATE `teams` SET `" . strtolower($_SESSION["role"]) . "_$i` = NULL WHERE `" . strtolower($_SESSION["role"]) . "_$i` = " . $_SESSION["user_id"] . ";"); $DB->exec("UPDATE `users` SET `team_id` = NULL WHERE `id` = " . $_SESSION["user_id"] . ";"); $DB->exec("UPDATE `teams` SET `encadrant_1` = `encadrant_2`, `encadrant_2` = NULL WHERE `encadrant_1` IS NULL;"); for ($i = 1; $i <= 5; ++$i) { /** @noinspection SqlResolve */ $DB->exec("UPDATE `teams` SET `participant_$i` = `participant_" . strval($i + 1) . "`, `participant_" . strval($i + 1) . "` = NULL WHERE `participant_$i` IS NULL;"); } $req = $DB->query("SELECT `file_id` FROM `documents` WHERE `user` = '" . $_SESSION["user_id"] . "';"); while (($data = $req->fetch()) !== false) unlink("$URL_BASE/files/" . $data["file_id"]); $DB->exec("DELETE FROM `documents` WHERE `user` = '" . $_SESSION["user_id"] . "';"); if ($DB->exec("DELETE FROM `teams` WHERE `encadrant_1` IS NULL AND `participant_1` IS NULL;") > 0) { $req = $DB->query("SELECT `file_id` FROM `solutions` WHERE `team` = '" . $_SESSION["team_id"] . "';"); while (($data = $req->fetch()) !== false) unlink("$URL_BASE/files/" . $data["file_id"]); $DB->exec("DELETE FROM `solutions` WHERE `team` = " . $_SESSION["team_id"] . ";"); $req = $DB->query("SELECT `file_id` FROM `syntheses` WHERE `team` = '" . $_SESSION["team_id"] . "';"); while (($data = $req->fetch()) !== false) unlink("$URL_BASE/files/" . $data["file_id"]); $DB->exec("DELETE FROM `syntheses` WHERE `team` = " . $_SESSION["team_id"] . ";"); } unset($_SESSION["team_id"]); unset($_SESSION["team_validation_status"]); } ?>