-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathcomp_admin.php
More file actions
146 lines (124 loc) · 5.14 KB
/
Copy pathcomp_admin.php
File metadata and controls
146 lines (124 loc) · 5.14 KB
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
<?php
require 'authorisation.php';
require 'format.php';
require 'dbextra.php';
require 'template.php';
$usePk=auth('system');
$link = db_connect();
$file = __FILE__;
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 = mysqli_query($link, $query) or die('Error ' . mysqli_errno($link) . ' Competition addition failed: ' . mysqli_connect_error());
$comPk = mysqli_insert_id($link);
$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 = mysqli_query($link, $query) or die('Error ' . mysqli_errno($link) . ' Competition formula update failed: ' . mysqli_connect_error());
$query = "insert into tblCompAuth values ($usePk, $comPk, 'admin')";
$result = mysqli_query($link, $query) or die('Error ' . mysqli_errno($link) . ' CompAuth addition failed: ' . mysqli_connect_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 = mysqli_query($link, $query) or die('Error ' . mysqli_errno($link) . ' Competition update failed: ' . mysqli_connect_error());
}
$comparr = [];
$comparr[] = array ('', fb('Date Range'), fb('Name'), fb('Location'), fb('Director') );
$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 = mysqli_query($link, $sql);
while($row = mysqli_fetch_assoc($result))
{
$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;
# Makes dates Bold if Comp is Now
if ($today>=$fromdate && $today<=$todate)
{
$datestr = fb("$datefrom - $dateto");
}
else
{
$datestr = "$datefrom - $dateto";
}
$location = $row['comLocation'];
$director = $row['comMeetDirName'];
$comparr[] = array("$count.", $datestr, "<a href=\"competition_admin.php?comPk=$id\">" . $name . "</a>", $location, $director);
$count++;
}
//initializing template header
tpadmin($link,$file,$row);
echo "<form action=\"comp_admin.php\" name=\"compadmin\" method=\"post\">";
echo ftable($comparr, "", array('class="d"', 'class="l"'), '');
echo "<br><hr>";
echo "<h2>Add Competition</h2>";
echo ftable(array(
array('Name', fin('comname', '', 20), 'Type:', fselect('comptype', 'RACE', array('OLC', 'RACE', 'Free', 'Route', 'Team-RACE'))),
array('Date From:', fin('datefrom', '', 10), 'Date To:', fin('dateto', '', 10)),
array('Director:', fin('director', '', 10), 'Location:', fin('location', '', 10)),
array('Abbreviation:', fin('code', '', 10), 'Time Offset:', fin('timeoffset', '', 7))
), '', '', ''
);
echo fis('add', 'Create Competition', '');
echo "</form>";
tpfooter($file);
?>