getRole(); if ($user->getTeamId() !== null) $_SESSION["team"] = Team::fromId($user->getTeamId()); } } function quitTeam() { global $DB, $URL_BASE; header("Location: $URL_BASE"); /** @var User $user */ $user = $_SESSION["user"]; $user_id = $user->getId(); $role = $user->getRole(); if ($role == Role::ADMIN) return; if ($role == Role::PARTICIPANT) for ($i = 1; $i <= 5; ++$i) /** @noinspection SqlResolve */ $DB->exec("UPDATE `teams` SET `participant_$i` = NULL WHERE `participant_$i` = $user_id;"); else $DB->exec("UPDATE `teams` SET `encadrant` = NULL WHERE `encadrant` = $user_id;"); $user->setTeamId(null); for ($i = 1; $i <= 4; ++$i) { /** @noinspection SqlResolve */ $DB->exec("UPDATE `teams` SET `participant_$i` = `participant_" . strval($i + 1) . "`, `participant_" . strval($i + 1) . "` = NULL WHERE `participant_$i` IS NULL;"); } $DB->exec("DELETE FROM `teams` WHERE `encadrant` IS NULL OR `participant_1` IS NULL;"); $req = $DB->query("SELECT `file_id` FROM `documents` WHERE `user` = $user_id;"); while (($data = $req->fetch()) !== false) unlink("$URL_BASE/files/" . $data["file_id"]); $DB->exec("DELETE FROM `documents` WHERE `user` = $user_id;"); $_SESSION["team"] = null; unset($_SESSION["team"]); } function userExists($email) { global $DB, $YEAR; $req = $DB->prepare("SELECT `id` FROM `users` WHERE `email` = ? AND `year` = '$YEAR';"); $req->execute([$email]); return $req->fetch(); } function teamExists($name) { global $DB, $YEAR; $req = $DB->prepare("SELECT `id` FROM `teams` WHERE `name` = ? AND `year` = '$YEAR';"); $req->execute([$name]); return $req->fetch(); } function trigramExists($trigram) { global $DB, $YEAR; $req = $DB->prepare("SELECT `id` FROM `teams` WHERE `trigram` = ? AND `year` = '$YEAR';"); $req->execute([$trigram]); return $req->fetch(); } function canValidate(Team $team) { global $DB, $CONFIG; $can_validate = date("Y-m-d H:i:s") < $CONFIG->getInscriptionDate(); $can_validate &= $team->getValidationStatus() == ValidationStatus::NOT_READY; $can_validate &= $team->getEncadrantId() != null; $can_validate &= $team->getParticipants()[2] != null; if ($team->getEncadrantId() != null) { $req = $DB->prepare("SELECT COUNT(*) AS `version` FROM `documents` WHERE `user` = ? AND `problem` = ? AND `type` = ?;"); $req->execute([$team->getEncadrantId(), $team->getProblem(), "PHOTO_CONSENT"]); $d = $req->fetch(); $can_validate &= $d["version"] > 0; } for ($i = 1; $i <= 5; ++$i) { if ($team->getParticipants()[$i] === NULL) continue; $req = $DB->prepare("SELECT COUNT(*) AS `version` FROM `documents` WHERE `user` = ? AND `problem` = ? AND `type` = ?;"); $req->execute([$team->getParticipants()[$i], $team->getProblem(), "PHOTO_CONSENT"]); $d = $req->fetch(); $can_validate &= $d["version"] > 0; } return $can_validate; } function printDocuments($documents) { echo "