forked from Luis-J-Ianez/cubecomps.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib_reg.php
63 lines (60 loc) · 2.18 KB
/
lib_reg.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?
require_once "lib.php";
function compHasTimesR1($comp_id,$cat_id)
{
global $timestable;
return mysql_num_rows(strict_mysql_query("SELECT * FROM $timestable WHERE cat_id=$cat_id AND round=1 AND comp_id=$comp_id"));
}
function toggleReg($comp_id,$cat_id)
{
global $eventstable, $compstable, $regstable;
$competitor = strict_mysql_query("SELECT cat".$cat_id." AS cat FROM $compstable WHERE id=$comp_id");
if(!mysql_num_rows($competitor)) return "";
$_X = "X"; // Do not change!
$_w = "-"; // "
$event = strict_mysql_query("SELECT r1_open, r2_open, r1_groupsize FROM $eventstable WHERE id=$cat_id");
$groupsize = cased_mysql_result($event,0,"r1_groupsize");
if (mysql_num_rows($event) && !cased_mysql_result($event,0,"r2_open"))
{
if (cased_mysql_result($event,0,"r1_open"))
{
$regs = strict_mysql_query("SELECT COUNT(*) as count FROM $regstable WHERE cat_id=$cat_id AND round=1");
$nregs = cased_mysql_result($regs,0,"count");
}
else
$nregs = $groupsize;
$hl = NULL;
if (!cased_mysql_result($competitor,0,"cat"))
{
if ($nregs < $groupsize)
{
$newValue = $_X;
$result = strict_mysql_query("INSERT INTO $regstable VALUES ($cat_id,1,$comp_id)");
}
else
$newValue = $_w;
}
elseif (compHasTimesR1($comp_id,$cat_id))
return $_X;
else
{
$newValue = "";
if (cased_mysql_result($event,0,"r1_open") && cased_mysql_result($competitor,0,"cat")==$_X)
{
$waiting = strict_mysql_query("SELECT id FROM $compstable WHERE cat".$cat_id."='$_w' ORDER BY id LIMIT 1");
if (!mysql_num_rows($waiting))
strict_mysql_query("DELETE FROM $regstable WHERE cat_id=$cat_id AND round=1 AND comp_id=$comp_id");
else
{
$result = strict_mysql_query("UPDATE $compstable SET cat".$cat_id."='$_X' WHERE id=".cased_mysql_result($waiting,0,"id"));
$result = strict_mysql_query("UPDATE $regstable SET comp_id='" .cased_mysql_result($waiting,0,"id"). "' WHERE cat_id=$cat_id AND round=1 AND comp_id=$comp_id");
$hl = "td".cased_mysql_result($waiting,0,"id")."_".$cat_id;
}
}
}
$result = strict_mysql_query("UPDATE $compstable SET cat".$cat_id."='$newValue' WHERE id=$comp_id");
if ($hl) $newValue .= "/".$hl;
return $newValue;
}
}
?>