-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmit_homework.php
More file actions
232 lines (206 loc) · 14.4 KB
/
submit_homework.php
File metadata and controls
232 lines (206 loc) · 14.4 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
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
227
228
229
230
231
232
<?php
include __DIR__ . "/inc/_sidebar_active_class.php";
$homeworks_active_class = "sidebar_active_btn";
$active_name = "Submit Homework";
require __DIR__ . "/inc/_header.php";
$controllers->submit_homework();
?>
<main>
<div class="main_section">
<div class="row">
<div class="col-md-4 col-sm-12 border-5 border-end" style="height: auto !important;">
<div class="navbar_section">
<div class="mobile_navbar_section ">
<?php require __DIR__ . "/inc/_mobile_sidebar.php"; ?>
</div>
<div class="md_navbar_section">
<div class="logo d-flex justify-content-center mt-5 pt-5 mb-4">
<img src="/assets/img/CodeLinkPro.png" class="" width="100px" alt="">
</div>
<?php require __DIR__ . "/inc/_sidebar_items.php"; ?>
</div>
</div>
</div>
<div class="col-md-8 col-sm-12">
<div class="section_main_content mt-4">
<div class="container m-4 p-4">
<div class="greetings_section mb-4">
Good Morning, Protik !!
</div>
<div class="submit_home_work_section mt-4">
<div class="container">
<div class="section_title text-center fs-4 mb-4">
Submit your homework
</div>
<div class="section_check_title text-danger text-center fs-6 mb-4">
<?php
$result_check_homework_status = $controllers->get_data_where("homeworks", "`homework_status` = 'running'");
$result_problem_homework_status = $controllers->get_data_where("homework_problems", "`homework_problem_status` = 'running'");
if ($result_check_homework_status) {
if ($result_check_homework_status->num_rows <= 0) {
if ($result_problem_homework_status) {
if ($result_problem_homework_status->num_rows <= 0) {
echo "There are no running homeworks and so that you cannot submit any other homeworks at this moment !! <br/> <b>Homework submitting time expired !!</b>";
}
}
}
}
?>
</div>
<form action="" method="post">
<div class="mb-3 me-4 pe-4">
<select name="" id="" class="form-control me-4 pe-4">
<option value="">Select the homework</option>
<?php
$result_homework = $controllers->get_data_where("homeworks", "`homework_status` = 'running'");
if ($result_homework) {
if ($result_homework->num_rows > 0) {
while ($row = $result_homework->fetch_assoc()) {
define("GET_HOMEWORK_ID", $row["homework_id"]);
echo '<option value="' . $row['homework_id'] . '">' . $row['homework_title'] . '</option>';
}
}
}
?>
</select>
</div>
<div class="mb-3 me-4 pe-4">
<select name="" id="" class="form-control me-4 pe-4">
<option value="">Select the problem</option>
<?php
$result_problem = $controllers->get_data_where("homework_problems", "`homework_problem_status` = 'running'");
if ($result_problem) {
if ($result_problem->num_rows > 0) {
while ($row = $result_problem->fetch_assoc()) {
echo '<option value="' . $row['homework_problem_id'] . '">' . $row['homework_problem_name'] . '</option>';
}
}
}
?>
</select>
</div>
<div class="mb-3 me-4 pe-4 code_editor_section">
<div class="mt-2">
<div class="row">
<div class="col-8">
<div class="code_section_info primary-color fw-bold mt-5">
Choose a language and write your code here
</div>
</div>
<div class="col-4">
<select name="language" class="mt-5 form-control" id="language" onchange="updateLanguage()">
<option value="">Select Language</option>
<option value="python3">Python 3</option>
<option value="c">C</option>
<option value="cpp">C++</option>
<option value="java">Java</option>
<option value="php">PHP</option>
</select>
</div>
</div>
</div>
<div class="code_editor">
<div id="editor">Write your code here. To write your code firstly choose the programming language from the choose select option</div>
</div>
<textarea class="form-control d-none mt-4 pt-4" name="editor_code" id="editor_code"></textarea>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.js" integrity="sha512-ExJSN+QimtEA9CcfY0lh/4EexQwd/gHJjOkHRi5Wz9+QkGJ4PC2fFQv0XaDTY64X/gBrx2LlUHfs8OFNO91obCQ==" crossorigin="anonymous"></script>
<script>
// Initialize Ace editor
var editor = ace.edit("editor");
editor.session.setUseWrapMode(false);
function updateLanguage() {
var language = document.getElementById("language").value;
switch (language) {
case "python3":
editor.session.setMode("ace/mode/python");
editor.setValue("# Write your python programming code here");
editor.gotoLine(2);
break;
case "c":
editor.session.setMode("ace/mode/c_cpp");
editor.setValue("// Write your c programming code here");
editor.gotoLine(2);
break;
case "cpp":
editor.session.setMode("ace/mode/c_cpp");
editor.setValue("// Write your c++ programming code here");
editor.gotoLine(2);
break;
case "java":
editor.session.setMode("ace/mode/java");
editor.setValue("// Write your Java programming code here");
editor.gotoLine(2);
break;
case "php":
editor.session.setMode("ace/mode/php");
editor.setValue("// Write your php programming code here");
editor.gotoLine(2);
break;
default:
editor.session.setMode("");
}
}
// Function to update the input field with the editor's content
function updateInputField() {
var editorContent = editor.getValue();
document.getElementById("editor_code").value = editorContent;
console.log("Editor content updated:", editorContent);
}
// Initial sync from Ace editor to input field
updateInputField();
// Listen for changes in Ace editor's session and update the input field
editor.session.on('change', updateInputField);
// Logging the final input value for debugging
var finalInputValue = document.getElementById("editor_code").value;
console.log("Final input value:", finalInputValue);
</script>
</div>
<div class="mb-3 me-4 pe-4">
<?php
$controllers->homework_submit_show_input(
'<input type="file" name="homework_files" class="form-control mt-4" id="homework_files">',
'<input disabled type="file" name="homework_files" class="form-control mt-4" id="homework_files">'
);
?>
</div>
<div class="mb-3 mt-4 pt-4">
<?php
$controllers->homework_submit_show_input(
'<button type="submit" name="homework_submit" class="btn btn-outline-dark">Submit</button>',
'<button title="The button is disabled " disabled type="submit" class="btn btn-outline-dark">Submit</button>'
);
?>
</div>
<div class="show_output">
<?php
echo $output = $controllers->run_code();
$out_val = json_decode($output, true);
echo $out_val['output'];
// foreach($out_val as $key => $value){
// echo $value['output'];
// }
// echo ($out_val); //$out_val["output"];
// echo $output['output'];
// echo '<pre>' . $output . '</pre>';
?>
</div>
<div class="mb-3 mt-4 pt-4">
<button type="submit" class="btn btn-outline-primary" name="test_code">Test code</button>
</div>
<div class="mb-3 mt-4 pt-4">
<a href="/homework" class="nav-link">
<button type="button" class="btn btn-sm btn-outline-dark">Back to Homeworks</button>
</a>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
<?php
require __DIR__ . "/inc/_footer_script.php";
?>