forked from hit-moodle/moodle-local_onlinejudge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
details.php
136 lines (108 loc) · 4.63 KB
/
details.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
<?php
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Online Judge for Moodle //
// https://github.com/hit-moodle/moodle-local_onlinejudge //
// //
// Copyright (C) 2009 onwards Sun Zhigang http://sunner.cn //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
/**
* Displays details of one task
*
* @package local_onlinejudge
* @copyright 2011 Sun Zhigang (http://sunner.cn)
* @author Sun Zhigang
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(__FILE__).'/../../config.php');
require_once($CFG->dirroot.'/local/onlinejudge/judgelib.php');
require_login(SITEID, false);
$taskid = required_param('task', PARAM_INT);
$ajax = optional_param('ajax', 0, PARAM_BOOL);
$task = onlinejudge_get_task($taskid);
if (empty($task)) {
print_error('invalidtaskid', 'local_onlinejudge', '', $taskid);
}
$context = get_context_instance(CONTEXT_MODULE, $task->cmid);
$PAGE->set_url('/mod/assignment/type/onlinejudge/details.php');
$PAGE->set_pagelayout('popup');
$PAGE->set_context($context);
$PAGE->set_title(get_string('details', 'local_onlinejudge'));
$PAGE->set_heading(get_string('details', 'local_onlinejudge'));
$PAGE->set_course($COURSE);
$PAGE->navbar->add(get_string('details', 'local_onlinejudge'));
if ($ajax) {
@header('Content-Type: text/plain; charset=utf-8');
} else {
echo $OUTPUT->header();
}
if ($task->userid != $USER->id) {
require_capability('local/onlinejudge:viewsensitive', $context);
}
// fields of table tasks which should be shown to teachers
$sensitive_fields = array('stdout', 'stderr', 'infoteacher');
// fields of table tasks which should be shown to students
$normal_fields = array('compileroutput', 'memusage', 'cpuusage', 'infostudent');
$task = (array)$task; // Easier to enum
$table = new html_table();
$table->attributes['class'] = 'generaltable';
foreach ($task as $key => $content) {
if ((!in_array($key, $normal_fields) and !in_array($key, $sensitive_fields))
or (in_array($key, $sensitive_fields) and !has_capability('local/onlinejudge:viewsensitive', $context))) {
continue;
}
$titlecell = new html_table_cell();
$contentcell = new html_table_cell();
$titlecell->text = get_string($key, 'local_onlinejudge');
if (in_array($key, $sensitive_fields)) {
$titlecell->text .= '*';
}
if (empty($content)) {
$content = get_string('notavailable');
} else {
$formatter = 'format_'.$key;
if (function_exists($formatter)) {
$content = $formatter($content);
}
}
$contentcell->text = $content;
$row = new html_table_row(array($titlecell, $contentcell));
$table->data[] = $row;
}
echo html_writer::table($table);
if (has_capability('local/onlinejudge:viewsensitive', $context)) {
print_string('notesensitive', 'local_onlinejudge');
}
if (!$ajax) {
echo $OUTPUT->footer();
}
function format_compileroutput($string) {
return '<pre>'.htmlspecialchars($string).'</pre>';
}
function format_cpuusage($string) {
return $string.' '.get_string('sec');
}
function format_memusage($string) {
return display_size($string);
}
function format_stdout($string) {
return format_compileroutput($string);
}
function format_stderr($string) {
return format_compileroutput($string);
}