-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
160 lines (132 loc) · 6.21 KB
/
index.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
<?PHP // $Id: index.php,v 1.1 2003/09/30 02:45:19 moodler Exp $
/// This page lists all the instances of programming in a particular course
/// Replace programming with the name of your module
require_once('../../config.php');
require_once('lib.php');
$id = required_param('id', PARAM_INT); // course
if (! $course = get_record('course', 'id', $id)) {
error('Course ID is incorrect');
}
require_login($course->id);
add_to_log($course->id, 'programming', 'view index', "index.php?id=$course->id", '');
/// Get all required strings
$strprogrammings = get_string('modulenameplural', 'programming');
$strprogramming = get_string('modulename', 'programming');
/// Print the header
$title = '';
include_once('pageheader.php');
$currenttab = 'result';
include_once('index_tabs.php');
/// Get all the appropriate data
if (! $programmings = get_all_instances_in_course('programming', $course)) {
notice('There are no programmings', '../../course/view.php?id='.$course->id);
die;
}
/// Print the list of instances (your module will probably extend this)
$timenow = time();
$strname = get_string('name');
$strweek = get_string('week');
$strtopic = get_string('topic');
$strlinecount = get_string('linecount', 'programming');
$strtotal = get_string('total', 'programming');
$strjudgeresult = get_string('judgeresult', 'programming');
$strna = get_string('n/a', 'programming');
$strglobalid = get_string('globalid', 'programming');
$strsubmitcount = get_string('submitcount', 'programming');
$strlanguage = get_string('language', 'programming');
$submits = "SELECT p.id, submitcount,
ps.id AS submitid, codelines, codesize, ps.timemodified,
ps.status AS status, pl.name AS lang
FROM {$CFG->prefix}programming AS p,
{$CFG->prefix}programming_result AS pr,
{$CFG->prefix}programming_submits AS ps,
{$CFG->prefix}programming_languages AS pl
WHERE p.course={$id}
AND p.id = pr.programmingid
AND pr.userid={$USER->id}
AND pr.latestsubmitid=ps.id
AND ps.language=pl.id";
$submits = get_records_sql($submits);
if (is_array($submits)) {
foreach($submits as $submit) {
if ($submit->status == PROGRAMMING_STATUS_COMPILEFAIL) {
$submit->judgeresult = get_string('CE', 'programming');
}
else if ($submit->status == PROGRAMMING_STATUS_FINISH) {
$tr = get_records('programming_test_results', 'submitid', $submit->submitid);
$submit->judgeresult = programming_contest_get_judgeresult($tr);
}
}
} else {
$submits = array();
}
if ($course->format == 'weeks') {
$table->head = array ($strweek);
$table->align = array ('CENTER');
} else if ($course->format == 'topics') {
$table->head = array ($strtopic);
$table->align = array ('CENTER');
} else if ($course->format == 'proglist') {
$table->head = array($strglobalid);
$table->align = array('CENTER');
} else {
$table->head = array ();
$table->align = array ();
}
$table->head = array_merge($table->head, array($strname, $strjudgeresult, $strlanguage, $strlinecount, $strsubmitcount));
$table->align = array_merge($table->align, array('LEFT', 'CENTER', 'CENTER', 'CENTER', 'CENTER'));
$totallines = $totalsubmit = 0;
foreach ($programmings as $programming) {
$submit = null;
if (array_key_exists($programming->id, $submits)) {
$submit = $submits[$programming->id];
}
if ($submit) {
$totallines += $submit->codelines;
$totalsubmit += $submit->submitcount;
}
$link = $resultlink = $countlink = $langlink = $codelink = '';
if (!$programming->visible) {
//Show dimmed if the mod is hidden
$link = "<a class=\"dimmed\" href=\"view.php?id=$programming->coursemodule\">$programming->name</a>";
if ($submit) {
$resultlink = '<a class="dimmed" href="result.php?a='.$submit->id.'">'.$submit->judgeresult.'</a>';
$countlink = '<a class="dimmed" href="history.php?a='.$submit->id.'">'.$submit->submitcount.'</a>';
$langlink = '<a class="dimmed" href="history.php?a='.$submit->id.'">'.$submit->lang.'</a>';
$codelink= '<a class="dimmed" href="history.php?a='.$submit->id.'">'.$submit->codelines.'</a>';
}
} else {
//Show normal if the mod is visible
$link = "<a href=\"view.php?id=$programming->coursemodule\">$programming->name</a>";
if ($submit) {
$resultlink = '<a href="result.php?a='.$submit->id.'">'.$submit->judgeresult.'</a>';
$countlink = '<a href="history.php?a='.$submit->id.'">'.$submit->submitcount.'</a>';
$langlink = '<a href="history.php?a='.$submit->id.'">'.$submit->lang.'</a>';
$codelink= '<a href="history.php?a='.$submit->id.'">'.$submit->codelines.'</a>';
}
}
if ($course->format == 'weeks' or $course->format == 'topics') {
$section = array($programming->section);
} else if ($course->format == 'proglist') {
$section = array($programming->globalid);
} else {
$section = array();
}
if ($submit) {
$table->data[] = array_merge($section, array($link, $resultlink, $langlink, $codelink, $countlink));
} else {
$table->data[] = array_merge($section, array($link, '', '', '', ''));
}
}
if (in_array($course->format, array('weeks', 'topics', 'proglist'))) {
$table->data[] = array($strtotal, '', '', '', $totallines, $totalsubmit);
} else {
$table->data[] = array($strtotal, '', '', $totallines, $totalsubmit);
}
echo '<div class="maincontent generalbox">';
echo '<h1>'.get_string('result', 'programming').'</h1>';
print_table($table);
echo '</div>';
/// Finish the page
print_footer($course);
?>