function get_all_comps() {
global $db;
$q = "SELECT * FROM comp order by id desc";
$r = $db->query($q);
return $r->fetch_all();
}
function all_judges() {
global $db;
$q = "SELECT id, reg_date, active, name, status FROM users WHERE id > 2 ORDER by status DESC, id ASC;";
$r = $db->query($q);
return $r->fetch_all();
}
function get_flight($id) {
global $db;
$q = "SELECT * FROM flights WHERE id =".$id;
$r = $db->query($q);
return $r->fetch_object();
}
function get_marks($flight_id) {
global $db;
}
function is_judges($round, $db) {
//get all judges from dis
$q = "select j_teams_id from rounds_judges where round_id=".$round;
$result = $db->query($q)->num_rows;
return ($result > 0);
}
function get_round_id($round_name) {
global $db;
$cdi = $_SESSION['dis_id'];
$q = "SELECT id FROM `rounds` WHERE comp_dis_id = ".$cdi." AND name = '".$round_name."'";
$id = $db->query($q)->fetch_object()->id;
return($id);
}
function get_judges_team($round_id) {
global $db, $comp_id;
$q = "SELECT j_teams_id FROM rounds_judges WHERE round_id =". $round_id;
$j = $db->query($q)->fetch_object();
$jTeam['id'] = $j->j_teams_id;
$q = "
SELECT * FROM j_teams
LEFT JOIN j_teams_users ON j_teams.id = j_teams_users.j_teams_id
LEFT JOIN users ON j_teams_users.user_id = users.id
WHERE j_teams.comp_id = ".$comp_id." AND j_teams.id =".$jTeam['id'];
$result = $db->query($q);
while($row = $result->fetch_object()) {
$jTeam['main_user_id'] = $row->main_user_id;
$jTeam['team'][$row->user_id] = ["name" => $row->name,
"status" =>$row->status,
];
}
return $jTeam;
}
function get_starts($judges, $hash) {
global $db;
$ids = implode(",",array_keys($judges["team"]));
$q = "SELECT * FROM start_time WHERE user_id IN ($ids) AND video_hash='".$hash."'";
$result = $db->query($q); $out=[];
while($row = $result->fetch_object()) {
$out['$row->user_id'] = $row->value;
}
return $out;
}
function comp_results() {
global $db;
$scores = getallscores();
$alldis['results'] = $scores;
$q = "SELECT *, comp_disciplines.id as did FROM `comp_disciplines` LEFT JOIN disciplines ON comp_disciplines.dis_id=disciplines.id";
$result = $db->query($q);
while ($row = $result->fetch_object())
{
$di = $row->did;
$row->rounds = getrounds($di);
$row->teams = getteams($di);
$alldis["competitions"][$row->name." ".$row->class] = $row;
}
print(json_encode($alldis));
exit;
}
function getrounds($dis_id) {
global $db;
$rounds = [];
$q = "SELECT * FROM `rounds` WHERE comp_dis_id =".$dis_id." ORDER BY id ASC";
$result = $db->query($q);
while ($row = $result->fetch_object()) {
$rounds[$row->id] = $row->name;
}
return $rounds;
}
function getteams($dis_id) {
global $db;
$rounds = [];
$q = "SELECT * FROM `teams` WHERE comp_dis_id =".$dis_id;
$result = $db->query($q);
$teams = [];
$results = [];
while ($row = $result->fetch_object()) {
$teams[$row->num] = [$row->name];
}
return $teams;
}
function get_flight_result($dis_id, $team_num) {
global $db;
$q = "SELECT * FROM `flights` WHERE comp_dis_id = ".$dis_id." and team_num = '".$team_num."' AND status = 3 ORDER by round_id";
$result = $db->query($q);
if($result->num_rows > 0) {
$value = $result->fetch_object()->result;
return $value;
}
}
function getallscores() {
global $db, $comp_id;
$q = "SELECT * FROM `flights` WHERE `result` IS NOT NULL AND status = 3
AND comp_dis_id IN (SELECT id FROM `comp_disciplines` WHERE comp_id=$comp_id) ORDER BY flights.id ASC";
$result = $db->query($q);
while ($row = $result->fetch_object())
{
$scores[$row->team_num][$row->round] = $row->result;
}
return $scores;
}
function getallteams() {
global $db, $comp_id;
$q = "SELECT * FROM `flights` WHERE `result` IS NOT NULL AND status = 3
AND comp_dis_id IN (SELECT id FROM `comp_disciplines` WHERE comp_id=$comp_id) ORDER BY flights.id ASC";
$result = $db->query($q);
while ($row = $result->fetch_object())
{
$ids[$row->team_num][$row->round] = $row->id;
}
return $ids;
}
function render_tour($dis_id) {
global $init;
$rounds = getrounds($dis_id);
$count = count($rounds) + 1;
$proc = round(75/$count);
$teams = getteams($dis_id);
//var_dump($teams);
//var_dump($rounds);
$allscores = getallscores();
$allteams = getallteams();
//var_dump($allscores);
$out = "
";
return $out;
}
function make_marks($f, $u, $db) {
$logged_id = (!isset($_SESSION['user'])) ? 0 : $_SESSION['user']->id;
$me = ($u == $logged_id);
$name = $db->query('select name from users where id ='.$u)->fetch_object()->name;
$q = "SELECT id,value,seconds FROM `marks` WHERE `flight_id` = ".$f." AND `user_id` = ".$u." AND `rm` IS NULL order by id ASC";
$result = $db->query($q);
$skips=0;$busts=0;$summ=0;$count=0;
$str_marks="