-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistory_diff.php
64 lines (47 loc) · 1.86 KB
/
history_diff.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
<?php
require_once('../../config.php');
require_once('lib.php');
$a = optional_param('a', 0, PARAM_INT); // programming ID
$s1 = required_param('s1', PARAM_INT);
$s2 = required_param('s2', PARAM_INT);
if (! $programming = get_record('programming', 'id', $a)) {
error('Course module is incorrect');
}
if (! $course = get_record('course', 'id', $programming->course)) {
error('Course is misconfigured');
}
if (! $cm = get_coursemodule_from_instance('programming', $programming->id, $course->id)) {
error('Course Module ID was incorrect');
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_login($course->id);
require_capability('mod/programming:viewhistory', $context);
$submit1 = get_record('programming_submits', 'id', $s1);
$submit2 = get_record('programming_submits', 'id', $s2);
if ($submit1->userid != $USER->id || $submit2->userid != $USER->id) {
require_capability('mod/programming:viewotherprogram', $context);
}
/// Print the page header
$pagename = get_string('submithistory', 'programming');
$CFG->scripts[] = 'js/dp/shCore.js';
$CFG->scripts[] = 'js/dp/shBrushCSharp.js';
$CFG->scripts[] = 'history.js';
$CFG->stylesheets[] = 'js/dp/SyntaxHighlighter.css';
include_once('pageheader.php');
/// Print tabs
$currenttab = 'history';
include_once('tabs.php');
/// Print page content
ini_set("include_path", ".:./lib");
require_once('Text/Diff.php');
require_once('text_diff_render_html.php');
$lines1 = explode("\n", $submit1->code);
$lines2 = explode("\n", $submit2->code);
$diff = new Text_Diff('auto', array($lines1, $lines2));
$renderer = new Text_Diff_Renderer_html();
echo '<pre>';
echo $renderer->render($diff);
echo '</pre>';
/// Finish the page
print_footer($course);
?>