-
Notifications
You must be signed in to change notification settings - Fork 2
/
comp_admin.php
149 lines (132 loc) · 5.11 KB
/
comp_admin.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<html>
<head>
<link HREF="xcstyle.css" REL="stylesheet" TYPE="text/css">
</head>
<body>
<div id="container">
<div id="vhead"><h1>airScore admin</h1></div>
<?php
require 'authorisation.php';
require 'format.php';
require 'dbextra.php';
adminbar(0);
?>
<p><h2>Competition Administration</h2></p>
<?php
$usePk=auth('system');
$link = db_connect();
if (reqexists('add'))
{
$comname = reqsval('comname');
$datefrom = reqsval('datefrom');
$dateto = reqsval('dateto');
$location = reqsval('location');
$director = reqsval('director');
$comptype = reqsval('comptype');
$comcode = reqsval('code');
$timeoffset = reqfval('timeoffset');
if ($comname == '')
{
echo "<b>Can't create a competition with no name</b>";
}
else
{
$query = "insert into tblCompetition (comName, comLocation, comDateFrom, comDateTo, comMeetDirName, forPk, comType, comCode, comTimeOffset) values ('$comname','$location', '$datefrom', '$dateto', '$director', 0, '$comptype', '$comcode', $timeoffset)";
$result = mysql_query($query, $link) or die('Competition addition failed: ' . mysql_error());
$comPk = mysql_insert_id();
$regarr = [];
$regarr['comPk'] = $comPk;
$regarr['forClass'] = 'gap';
$regarr['forVersion'] = '2007';
$regarr['forNomDistance'] = 35.0;
$regarr['forMinDistance'] = 5.0;
$regarr['forNomTime'] = 90;
$regarr['forNomGoal'] = 30.0;
$regarr['forGoalSSpenalty'] = 1.0;
$regarr['forLinearDist'] = 0.5;
$regarr['forDiffDist'] = 3.0;
$regarr['forDiffRamp'] = 'flexible';
$regarr['forDiffCalc'] = 'lo';
$regarr['forDistMeasure'] = 'average';
if (reqexists('weightstart'))
{
$regarr['forWeightStart'] = 0.125;
$regarr['forWeightArrival'] = 0.175;
$regarr['forWeightSpeed'] = 0.7;
}
$clause = "comPk=$comPk";
$forPk = insertup($link, 'tblFormula', 'forPk', $clause, $regarr);
$query = "update tblCompetition set forPk=$forPk where $clause";
$result = mysql_query($query, $link) or die('Competition formula update failed: ' . mysql_error());
$query = "insert into tblCompAuth values ($usePk, $comPk, 'admin')";
$result = mysql_query($query, $link) or die('CompAuth addition failed: ' . mysql_error());
}
}
if (reqexists('update'))
{
$comPk = reqival('comPk');
$comname = reqsval('comname');
$datefrom = reqsval('datefrom');
$dateto = reqsval('dateto');
$location = reqsval('location');
$director = reqsval('director');
$sanction = reqsval('sanction');
$formula = reqsval('formula');
$comptype = reqsval('comptype');
$comcode = reqsval('code');
$timeoffset = reqfval('timeoffset');
check_admin('admin',$usePk,$comPk);
$query = "update tblCompetition set comName='$comname', comLocation='$comLocation', comDateFrom='$datefrom', comDateTo='$dateto', comDirector='$director', forPk='$formula', comSanction='$sanction', comType='$comptype', comCode='$comcode', comTimeOffset=$timeoffset where comPk=$comPk";
$result = mysql_query($query, $link) or die('Competition update failed: ' . mysql_error());
}
$comparr = [];
$comparr[] = array ('', fb('Date Range'), fb('Name'), fb('Location'), fb('Director') );
echo "<form action=\"comp_admin.php\" name=\"compadmin\" method=\"post\">";
$count = 1;
if (is_admin('admin', $usePk, -1))
{
$sql = "SELECT C.* FROM tblCompetition C order by C.comName like '%test%', C.comDateTo desc";
}
else
{
$sql = "SELECT C.* FROM tblCompAuth A, tblCompetition C where (A.comPk=C.comPk and A.usePk=$usePk) or (C.comName like '%test%') group by C.comName order by C.comName like '%test%', C.comDateTo desc";
}
$result = mysql_query($sql,$link);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$id = $row['comPk'];
$name = $row['comName'];
$datefrom = substr($row['comDateFrom'], 0, 10);
$dateto = substr($row['comDateTo'], 0, 10);
$today = time();
$fromdate = strtotime($datefrom);
$todate = strtotime($dateto) + 24*3600;
if ($today>=$fromdate && $today<=$todate)
{
$datestr = fb("$datefrom - $dateto");
}
else
{
$datestr = "$datefrom - $dateto";
}
$location = $row['comLocation'];
$director = $row['comMeetDirName'];
$comparr[] = ["$count.", $datestr, "<a href=\"competition.php?comPk=$id\">" . $name . "</a>", $location, $director];
$count++;
}
echo ftable($comparr, "border=\"0\" cellpadding=\"2\" cellspacing=\"0\" alternate-colours=\"yes\" valign=\"top\" align=\"left\"", ['class="d"', 'class="l"'], '');
echo "<br><hr>";
echo "<h2>Add Competition</h2>";
echo ftable([
['Name', fin('comname', '', 20), 'Type:', fselect('comptype', 'RACE', ['OLC', 'RACE', 'Free', 'Route', 'Team-RACE'])],
['Date From:', fin('datefrom', '', 10), 'Date To:', fin('dateto', '', 10)],
['Director:', fin('director', '', 10), 'Location:', fin('location', '', 10)],
['Abbreviation:', fin('code', '', 10), 'Time Offset:', fin('timeoffset', '', 7)]
], '', '', ''
);
echo fis('add', 'Create Competition', '');
echo "</form>";
?>
</div>
</body>
</html>