forked from Luis-J-Ianez/cubecomps.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
newcomp.php
226 lines (208 loc) · 5.42 KB
/
newcomp.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<?
// DB stuff
require_once "inc_private.php";
require_once "lib.php";
if ($test) {
mysql_connect(SQL_SERVER, SQL_TEST_USER, SQL_TEST_PASSWORD);
mysql_select_db(SQL_TEST_DBNAME);
}
else {
mysql_connect(SQL_SERVER, SQL_USER, SQL_PASSWORD);
mysql_select_db(SQL_DBNAME);
}
// message variable
$msg = "";
// form submitted ?
if ( isset($_POST["submitted"]) ) {
// let's check sent variable
$match_date = "/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/";
if( !preg_match($match_date, $_POST['date_b']) OR !preg_match($match_date, $_POST['date_e']) ) {
$msg = "Please check your dates !<br />";
}
if ( $_POST['apass1'] != $_POST['apass2'] ) {
$msg .= "Admin passwords are not the same :)<br />";
}
if ( $_POST['spass1'] != $_POST['spass2'] ) {
$msg .= "Score takers passwords not the same !<br />";
}
// this should never happen (except fake form submission :) )
if ( !preg_match("/^[A-Z]{2}$/",$_POST['country']) ) {
$msg .= "WHAT ??? Country error !!<br />";
}
if ( $msg == "" ) {
strict_mysql_query("INSERT INTO competitions (
admin_pw,
intro_pw,
country,
date_b,
date_e,
name,
place,
website
)
VALUES('".
mysql_real_escape_string($_POST['apass1']) . "','" .
mysql_real_escape_string($_POST['spass1']) . "','" .
$_POST['country'] . "','" .
$_POST['date_b'] . "','" .
$_POST['date_e'] . "','" .
mysql_real_escape_string($_POST['name']) . "','" .
mysql_real_escape_string($_POST['place']) . "','" .
mysql_real_escape_string($_POST['website']) . "'
);");
// if the SQL is successful (means no die() ), head back to the home page
header("location:./");
/*
echo "<pre>";
print_r($_POST);
echo "</pre>";
*/
}
}
// no POST data, let's display the form
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<head>
<title>Cube Competitions</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body {font-family:arial,sans-serif;font-size:12px;background-color:white;color:#004;margin:0;}
table {font-size:12px;}
img {border:0;}
a {color:black;font-weight:bold;text-decoration:none;}
a:hover {color:#CC0000;}
div.header {height:34px;font-size:20px;font-weight:bold;color:white;background-color:#000022;}
</style>
</head>
<body>
<table cellspacing="0" cellpadding="0" width="100%" height="100%">
<tr valign="top">
<td width="40%">
<table cellspacing="0" cellpadding="0" height="100%">
<tr valign="top">
<td><img src='img/home-top.gif' /></td>
</tr>
<tr valign="bottom">
<td><img src='img/home-bottom.gif' /></td>
</tr>
</table>
</td>
<td width="60%">
<br />
<br />
<img src='img/logo.gif' /><br />
<br />
<br />
<div class="header">
<img src='img/header-tip.gif' /><span style='vertical-align:8px'>Add a competition</span>
</div>
Please fill up this form :
<?php
if ( $msg != "" ) {
echo "<span style='color:red;'><br />" . $msg . "</span>";
}
?>
<form method="post">
<table border="0" cellspacing="0" cellpadding="2">
<tr>
<td>
Name :
</td>
<td>
<input type="text" name="name" value="<?=@$_POST['name'];?>" />
</td>
</tr>
<tr>
<td>
Place :
</td>
<td>
<input type="text" name="place" value="<?=@$_POST['place'];?>" />
</td>
</tr>
<tr>
<td>
Begining date :<br>
(Format : YYYY-MM-DD)
</td>
<td>
<input type="date" name="date_b" value="<?=@$_POST['date_b'];?>" />
</td>
</tr>
<tr>
<td>
Ending date :<br>
(Format : YYYY-MM-DD)
</td>
<td>
<input type="date" name="date_e" value="<?=@$_POST['date_e'];?>" />
</td>
</tr>
<tr>
<td>
Website (without http://) :
</td>
<td>
<input type="text" name="website" value="<?=@$_POST['website'];?>" />
</td>
</tr>
<tr>
<td>
Country :
</td>
<td>
<select name="country">
<?php
// let's get all the countries
$res = strict_mysql_query("SELECT * FROM `countries`;");
while( $row = cased_mysql_fetch_array($res) ) {
// utf8_encode is mandatory : the 'countries' table is encoded in latin1_swedish
echo "<option";
if ( isset($_POST['country']) && $_POST['country']==$row['id'] ) {
echo " selected=selected";
}
echo " value=\"" . $row['id'] . "\">" . utf8_encode($row['name']) . "</option>\n";
}
mysql_close();
?>
</select>
</td>
</tr>
<tr>
<td>
Admin password (twice) :
</td>
<td>
<input type="password" name="apass1" /><br>
<input type="password" name="apass2" />
</td>
</tr>
<tr><td>
Score takers password :<br />
(twice as well)
</td>
<td>
<input type="password" name="spass1" /><br>
<input type="password" name="spass2" />
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center;">
<input type="submit" name="submitted" value="Add your competition" />
</td>
</tr>
</table>
</form>
<div style='color:#444;'>
<br />
<br />
Looking for the <a href='http://live.cubecomps.com'>live results</a> site?<br />
<br />
<br />
by <a href='http://www.binarema.es' target="_blank">Binarema</a>
</div>
</td>
</tr>
</table>
</body>
</html>