-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmit1.php
More file actions
131 lines (120 loc) · 5.16 KB
/
Copy pathsubmit1.php
File metadata and controls
131 lines (120 loc) · 5.16 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
<?php
/**
* View/download problem texts and sample testcases
*
* Part of the DOMjudge Programming Contest Jury System and licenced
* under the GNU GPL. See README and COPYING for details.
*/
require('init.php');
$title = 'Submit';
require(LIBWWWDIR . '/header.php');
echo "<h1>Submit</h1>\n\n";
$fdata = calcFreezeData($cdata);
if (!$fdata['started'] && !checkrole('jury')) {
echo '<div class="container submitform"><div class="alert alert-danger" role="alert">Contest has not yet started - cannot submit.</div></div>';
require(LIBWWWDIR . '/footer.php');
exit;
}
$langdata = $DB->q('KEYTABLE SELECT langid AS ARRAYKEY, name, extensions, require_entry_point, entry_point_description
FROM language WHERE allow_submit = 1');
$probdata = $DB->q('TABLE SELECT probid, shortname, name FROM problem
INNER JOIN contestproblem USING (probid)
WHERE cid = %i AND allow_submit = 1
ORDER BY shortname', $cid);
print "<script>";
putgetMainExtension($langdata);
print "</script>";
$maxfiles = dbconfig_get('sourcefiles_limit', 100);
$probs = array();
$probs[''] = 'Select a problem';
foreach ($probdata as $probinfo) {
$probs[$probinfo['probid']] = $probinfo['shortname'] . ' - ' . $probinfo['name'];
}
$langs = array();
$langs[''] = 'Select a language';
foreach ($langdata as $langid => $langdata) {
$langs[$langid] = $langdata['name'];
}
?>
<div class="container submitform">
<form action="upload.php" method="post" enctype="multipart/form-data" onsubmit="return checkUploadForm();">
<div class="form-group">
<label for="probid">Problem:</label>
<select class="custom-select" name="probid" id="probid" required>
<?php
foreach ($probs as $probid => $probname) {
print ' <option value="' . specialchars($probid) . '">' . specialchars($probname) . "</option>\n";
}
?>
</select>
</div>
<div class="form-group">
<label for="langid">Language:</label>
<select class="custom-select" name="langid" id="langid" required>
<?php
foreach ($langs as $langid => $langname) {
print ' <option value="' . specialchars($langid) . '">' . specialchars($langname) . "</option>\n";
}
?>
</select>
</div>
<div class="form-group">
<label for="maincode">Source code:</label>
<textarea class="form-control" id="codearea" rows="15" autocorrect="off" autocapitalize="off"
spellcheck="false" style="font-size: 14px;"></textarea>
</div>
</form>
<button id="submitCodeBtn" class="btn btn-primary" onclick="newPostMethod()">Submit</button>
<br><br>
<a href="submit.php">Submit file -></a>
<script type="text/javascript">initFileUploads(<?=$maxfiles?>);</script>
</div>
<script type="text/javascript">
document.getElementById("submitCodeBtn").onclick = function () {
var code = document.getElementById('codearea').value;
var probid = document.getElementById('probid').value;
var langid = document.getElementById('langid').value;
if (probid.length === 0) {
alert("Please select a problem.");
return;
}
if (langid.length === 0) {
alert("Please select a language.");
return;
}
if (code.length === 0) {
alert("Source code can't be empty.");
return;
}
var boundary = "---------------------------WebkitBoundary" + Math.floor(Math.random() * 1e9 + 1);
var body = '--' + boundary + '\r\n'
+ 'Content-Disposition: form-data; name="code[]";filename="codeRaw."'+langid+'\r\n'
+ 'Content-type: application/octet-stream\r\n\r\n'
+ code + '\r\n'
+ '--' + boundary + '\r\n'
+ 'Content-Disposition: form-data; name="probid"\r\n\r\n' +
probid + '\r\n'
+ '--' + boundary + '\r\n'
+ 'Content-Disposition: form-data; name="langid"\r\n\r\n' +
langid + '\r\n'
+ '--' + boundary + '\r\n'
+ 'Content-Disposition: form-data; name="entry_point"\r\n\r\n' +
'codeRaw' + '\r\n'
+ '--' + boundary + '\r\n'
+ 'Content-Disposition: form-data; name="submit"\r\n\r\n' +
'Submit' + '\r\n'
+ '--' + boundary + '--\r\n';
console.log(body);
$.ajax({
contentType: "multipart/form-data; boundary=" + boundary,
data: body,
type: "POST",
url: "/team/upload.php",
success: function (data, status) {
window.location.href = "/team/index.php";
}
});
}
</script>
<?php
require(LIBWWWDIR . '/footer.php');