This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrace_results_chg_do.php
119 lines (94 loc) · 3.52 KB
/
race_results_chg_do.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
<?
require_once("session_start.php");
if(!isset($login)) error("You do not have administrator rights\n");
require_once("results_functions.php");
#echo "<pre>"; print_r($_POST); echo "</pre>"; die();
$id = addslashes($_POST['id']);
$season = addslashes($_POST['season']);
$replay = htmlspecialchars($_POST['replay']);
$simresults = htmlspecialchars($_POST['simresults']);
$official = isset($_POST['official']) ? 1 : 0;
$driver = $_POST['driver'];
$grid = $_POST['grid'];
$pos = $_POST['pos'];
$laps = $_POST['laps'];
$hour = $_POST['hour'];
$minute = $_POST['minute'];
$second = $_POST['second'];
$ms = $_POST['ms'];
$fl = $_POST['fl'];
$status = $_POST['status'];
function has_duplicates($ar, $values_ok) {
$has = array();
if(!is_array($ar)) $ar = array($ar);
if(!is_array($values_ok)) $values_ok = array($values_ok);
foreach($ar as $a) {
if(in_array($a, $values_ok)) continue;
if(in_array($a, $has)) return true;
array_push($has, $a);
}
return false;
}
$error = "";
if(has_duplicates($driver, 0)) $error .= "Duplicate drivers selected\n";
if(has_duplicates($grid, array(0, ""))) $error .= "Duplicate grid positions selected\n";
if(has_duplicates($position, array(0, ""))) $error .= "Duplicate positions selected\n";
if(count($fl) > 1) $error .= "Only one driver can have the fastest lap\n";
if(!empty($error)) error($error);
require_once("functions.php"); // import mysql function
$link = mysqlconnect(); // call mysql function to get the link to the database
$has_qualifying = false;
$has_race = false;
$pos_pres_count = 0;
$pos_abs_count = 0;
$grid_pres_count = 0;
$grid_abs_count = 0;
if(is_array($driver)) {
$query_values = "";
for($x = 0; $x < count($driver); $x++) {
if(empty($driver[$x]))
continue;
if((int)$grid[$x] != 0) $has_qualifying = true;
if((int)$pos[$x] != 0) $has_race = true;
if(empty($pos[$x]) || $pos[$x] == "0") $pos_abs_count++;
else $pos_pres_count++;
if(empty($grid[$x]) || $grid[$x] == "0") $grid_abs_count++;
else $grid_pres_count++;
$d = addslashes($driver[$x]);
$g = addslashes($grid[$x]);
$p = addslashes($pos[$x]);
$l = addslashes($laps[$x]);
$m = $ms[$x];
if($m < 0) $m = 0;
# if($m != 0) {
# while($m < 100) {
# $m *= 10;
# }
# }
$t = ($hour[$x] * 3600000) + ($minute[$x] * 60000) + ($second[$x] * 1000) + $m;
$f = isset($fl[$x]) ? 1 : 0;
$s = addslashes($status[$x]);
$query_values .= "('$id', '$d', '$g', '$p', '$l', '$t', '$f', '$s'), ";
}
$query_values = substr($query_values, 0, -2);
if($pos_pres_count > 0 && $pos_abs_count > 0)
error("Please fill in the final positions for all drivers\n");
if($grid_pres_count > 0 && $grid_abs_count > 0)
error("Please fill in the grid positions for all drivers\n");
$query = "DELETE FROM race_driver WHERE race='$id'";
$result = mysqli_query($link,$query);
if(!$result) error("MySQL Error: " . mysqli_error($link) . "\n");
if(!empty($query_values)) {
$query = "INSERT INTO race_driver (race, team_driver, grid, position, laps, time, fastest_lap, status) VALUES $query_values";
$result = mysqli_query($link,$query);
if(!$result) error("MySQL Error: " . mysqli_error($link) . "\n");
}
}
$progress = RACE_NEW;
if($has_qualifying) $progress = RACE_QUALIFYING;
if($has_race) $progress = RACE_RACE;
$query = "UPDATE race SET result_official='$official', progress='$progress', replay='$replay', simresults='$simresults' WHERE id='$id'";
$result = mysqli_query($link,$query);
if(!$result) error("MySQL Error: " . mysqli_error($link) . "\n");
return_do(".?page=races&season=$season", "Race results succesfully modified\n$msg");
?>