forked from Luis-J-Ianez/cubecomps.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
editcomp.php
194 lines (177 loc) · 5.25 KB
/
editcomp.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?
require_once "lib.php";
include "lib_ref_admin.php";
include "db.php";
if (!$_GET["id"]) die("Invalid calling params!");
$comp = strict_mysql_query("SELECT * FROM $compstable WHERE id=".$_GET["id"]);
if (!mysql_num_rows($comp)) die("Competitor not found!");
$comp = cased_mysql_fetch_array($comp);
$color = "#6b7b71";
$light_color = "#b0c7b4";
$dark_color = "#0a1414";
?>
<html>
<head>
<TITLE>Edit competitor's details</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
body {font-family:arial,sans-serif;font-size:14px;background-color:<?=$color?>;}
table {color:black;font-size:12px;-moz-box-shadow: 6px 6px 5px <?=$dark_color?>;-webkit-box-shadow: 6px 6px 5px <?=$dark_color?>; box-shadow: 6px 6px 5px <?=$dark_color?>;background-color:<?=$light_color?>;}
td {padding:0 5px;}
td.caption {color:#2a3837;text-align:right;}
</style>
</head>
<body onload='document.frm.WCAid.focus();'>
<script>
function validateWCAid(obj)
{
var id = obj.value;
if (id=="") return;
id = id.toUpperCase();
if (!/^\d{4}[A-Z]{4}\d{2}$/.test(id))
{
alert("\""+id+"\" is not a valid WCA id!");
obj.value = "";
obj.focus();
}
}
function letter(e)
{
var evt = e ? e : event;
var ch, chrCode = 0;
if (evt.charCode!=null) chrCode = evt.charCode;
else if (evt.which!=null) chrCode = evt.which;
else if (evt.keyCode!=null) chrCode = evt.keyCode;
if (chrCode==0) return "";
return String.fromCharCode(chrCode);
}
function birthKeyPress(e)
{
var ch = letter(e);
if (((ch >= '0') && (ch <= '9')) || (ch == '-') || (ch == ''))
e.returnValue = true;
else
{
e.returnValue = false;
if (!window.event) e.preventDefault();
}
}
function validateBirth(obj)
{
var d = obj.value;
if (d=="") return "";
if (!/^\d{4}-\d{2}-\d{2}$/.test(d))
{
alert("\""+d+"\" is not a valid date format (yyyy-mm-dd)!");
obj.value = "";
obj.focus();
}
else
{
var month = d.substring(5,7);
month = parseInt(month,10);
var day = d.substring(8,10);
day = parseInt(day,10);
var year = parseInt(d.substring(0,4),10);
var dt = new Date(Date.UTC(year,month-1,day));
if (dt.getUTCDate()!=day || dt.getUTCMonth()!=month-1 || dt.getUTCFullYear()!=year)
{
alert("\""+d+"\" is not a valid date!");
obj.value = "";
obj.focus();
}
var today = new Date();
var age = ((today.getTime()-dt.getTime()) / (1000*60*60*24*365.25));
if (age < 1 || age > 130)
{
alert("The system doesn't allow ages under 1 or over 130");
obj.value = "";
obj.focus();
}
return(true);
}
}
function empty(obj,fldname)
{
var st = obj.value;
st.replace(/^\s+|\s+$/g,"");
if (st=="")
{
alert("\""+fldname+"\" can't be blank!");
obj.focus();
return true;
}
else
return false;
}
function createXMLHttpRequest()
{
var xmlHttp=null;
if (window.ActiveXObject)
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
else
if (window.XMLHttpRequest)
xmlHttp = new XMLHttpRequest();
return xmlHttp;
}
function submitForm()
{
if (!empty (document.frm.competitor,"name") &&
!empty (document.frm.birth,"birthday") &&
!empty (document.frm.country,"country") &&
!empty (document.frm.gender,"gender"))
{
var req = createXMLHttpRequest();
req.open ("GET", "updcompetitor.php?id=<?=$_GET["id"]?>"+
"&wcaid="+document.frm.WCAid.value+
"&name="+document.frm.competitor.value+
"&birthday="+document.frm.birth.value+
"&country="+document.frm.country.value+
"&gender="+document.frm.gender.value,
false);
req.send (null);
if (req.responseText != "")
alert(req.responseText);
else
{
opener.location.reload();
window.close();
}
}
return false;
}
</script>
<table>
<tr><td colspan=2> </td></tr>
<tr><td class=caption>id</td><td><b><?=$comp["id"]?></b><td></tr>
<form name=frm onsubmit="return(submitForm());">
<tr><td class=caption>WCA id</td><td><input type=text id=WCAid name=WCAid maxlength=10 style="width:90px;text-transform:uppercase;" onblur='validateWCAid(this);' value="<?=$comp["WCAid"]?>"></td></tr>
<tr><td class=caption>name</td><td><input type=text id=competitor name=competitor maxlength=50 value="<?=$comp["name"]?>" style="width:300px;"></td></tr>
<tr><td class=caption>date of birth</td><td><input type=text id=birth name=birth maxlength=10 onkeypress='birthKeyPress(event);' onblur='validateBirth(this)' value="<?=$comp["birthday"]?>" style="width:80px;"></td></tr>
<tr><td class=caption>country</td><td><select id=country name=country style="width:200px;">
<option value=""></option>
<?
$result = strict_mysql_query("SELECT * FROM countries");
while ($row=cased_mysql_fetch_array($result))
{
echo "<option value=\"" . $row["id"] . "\"";
if ($row["id"]==$comp["country_id"]) echo " selected";
echo ">" . $row["name"] . "</option>\r\n";
}
?>
</select></td></tr>
<tr><td class=caption>gender</td><td><select id=gender name=gender>
<option value=""></option>
<option value="m"<?=($comp["gender"]=="m"?" SELECTED":"")?>>male</option>
<option value="f"<?=($comp["gender"]=="f"?" SELECTED":"")?>>female</option>
</select></td></tr>
<tr><td colspan=2> </td></tr>
<tr><td><input type=button value=cancel onclick='window.close();'></td><td><input type=submit value=change></td></tr>
<tr><td colspan=2> </td></tr>
</form>
</table>
</body>
</html>
<?
mysql_close();
?>