$DB->exec("UPDATE `teams` SET `".strtolower(Role::getName($role))."_$i` = NULL WHERE `".strtolower(Role::getName($role))."_$i` = $user_id;");
$user->setTeamId(null);
$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` = $user_id;");
while(($data=$req->fetch())!==false)
unlink("$URL_BASE/files/".$data["file_id"]);
$DB->exec("DELETE FROM `documents` WHERE `user` = $user_id;");
if($DB->exec("DELETE FROM `teams` WHERE `encadrant_1` IS NULL AND `participant_1` IS NULL;")>0){
$team_id=$user->getTeamId();
$req=$DB->query("SELECT `file_id` FROM `solutions` WHERE `team` = $team_id;");
while(($data=$req->fetch())!==false)
unlink("$URL_BASE/files/".$data["file_id"]);
$DB->exec("DELETE FROM `solutions` WHERE `team` = $team_id;");
$req=$DB->query("SELECT `file_id` FROM `syntheses` WHERE `team` = $team_id;");
while(($data=$req->fetch())!==false)
unlink("$URL_BASE/files/".$data["file_id"]);
$DB->exec("DELETE FROM `syntheses` WHERE `team` = $team_id;");
}
$_SESSION["team"]=null;
unset($_SESSION["team"]);
}
functionuserExists($email)
{
global$DB,$YEAR;
$req=$DB->prepare("SELECT `id` FROM `users` WHERE `email` = ? AND `year` = '$YEAR';");
$req->execute([$email]);
return$req->fetch();
}
functionteamExists($name)
{
global$DB,$YEAR;
$req=$DB->prepare("SELECT `id` FROM `teams` WHERE `name` = ? AND `year` = '$YEAR';");
$req->execute([$name]);
return$req->fetch();
}
functiontrigramExists($trigram)
{
global$DB,$YEAR;
$req=$DB->prepare("SELECT `id` FROM `teams` WHERE `trigram` = ? AND `year` = '$YEAR';");
$req->execute([$trigram]);
return$req->fetch();
}
functiontournamentExists($name)
{
global$DB,$YEAR;
$req=$DB->prepare("SELECT `id` FROM `tournaments` WHERE `name` = ? AND `year` = '$YEAR';");