forked from gregorio-project/GregoBase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
history.php
66 lines (64 loc) · 2.9 KB
/
history.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
<?php
include('include/db.php');
include('include/finediff.php');
if(array_key_exists("changeset", $_GET)) {
$chgset = explode('|',$_GET['changeset']);
} else {
die('No changeset');
}
$sql1 = 'SELECT * FROM '.db('chants').' WHERE id = '.intval($chgset[1]);
$req1 = $mysqli->query($sql1) or die('Erreur SQL !<br />'.$sql1.'<br />'.$mysqli->error);
$c = $req1->fetch_assoc();
$sql1 = 'SELECT * FROM '.db('changesets').' WHERE `chant_id` = '.intval($chgset[1]).' AND `time` > '.intval($chgset[0]).' ORDER BY `time` DESC';
$req1 = $mysqli->query($sql1) or die('Erreur SQL !<br />'.$sql1.'<br />'.$mysqli->error);
while($n = $req1->fetch_assoc()) {
$sql2 = 'SELECT * FROM '.db('changes').' WHERE changeset = "'.$n['time'].'|'.$n['chant_id'].'|'.$n['user_id'].'" ORDER BY field';
$req2 = $mysqli->query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.$mysqli->error);
while($o = $req2->fetch_assoc()) {
$c[$o['field']] = $o['changed'];
}
}
$title = 'History - '.$c['incipit'];
include('include/header.php');
echo "<h2>$title</h2>\n";
$sql1 = 'SELECT * FROM '.db('changesets').' WHERE `user_id` = '.intval($chgset[2]).' AND `chant_id` = '.intval($chgset[1]).' AND `time` = '.intval($chgset[0]);
$req1 = $mysqli->query($sql1) or die('Erreur SQL !<br />'.$sql1.'<br />'.$mysqli->error);
$m = $req1->fetch_assoc();
$user_info = get_userdata($m['user_id']);
echo "<h4>".date("M d, Y",$m['time'])." (".$user_info->display_name.")</h4>\n";
echo "<p>".$m['comment']."</p>\n";
$sql2 = 'SELECT * FROM '.db('changes').' WHERE changeset = "'.$mysqli->real_escape_string($_GET['changeset']).'" ORDER BY field';
$req2 = $mysqli->query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.$mysqli->error);
while($f = $req2->fetch_assoc()) {
echo '<p><i>'.$f['field']."</i><br />\n";
$from_text = $f['changed'];
if($f['field'] == 'sources') {
$c_s = array();
$sql = 'SELECT * FROM '.db('chant_sources').' WHERE chant_id = '.intval($chgset[1]);
$req = $mysqli->query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.$mysqli->error);
while ($s = $req->fetch_assoc()) {
$c_s[] = $s;
}
$to_text = json_encode($c_s);
} elseif($f['field'] == 'tags') {
$tags = array();
$sql = 'SELECT * FROM '.db('chant_tags').' WHERE chant_id = '.intval($chgset[1]);
$req = $mysqli->query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.$mysqli->error);
while ($t = $req->fetch_assoc()) {
$sql1 = 'SELECT * FROM '.db('tags').' WHERE id = '.$t['tag_id'];
$req1 = $mysqli->query($sql1) or die('Erreur SQL !<br />'.$sql1.'<br />'.$mysqli->error);
$tt = $req1->fetch_assoc();
$tags[] = $tt['tag'];
}
natcasesort($tags);
$to_text = json_encode($tags);
} else {
$to_text = $c[$f['field']];
}
$diff = new FineDiff($from_text, $to_text, FineDiff::$wordGranularity);
$opcodes = FineDiff::getDiffOpcodes($from_text, $to_text);
echo '<tt>'.FineDiff::renderDiffToHTMLFromOpcodes($from_text, $opcodes)."</tt></p>\n";
}
echo "</ul>\n";
include('include/footer.php');
?>