-
Notifications
You must be signed in to change notification settings - Fork 12
/
source.php
128 lines (126 loc) · 4.26 KB
/
source.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
<?php
include('include/db.php');
include('include/sources.php');
if(array_key_exists("id", $_GET)) {
$s = intval($_GET['id']);
} else {
die('No id');
}
$chants = array();
if($s == "none") {
$sql1 = 'SELECT * FROM '.db('chants').' c WHERE NOT EXISTS (SELECT * FROM '.db('chant_sources').' cs WHERE c.id = cs.chant_id)';
$req1 = $mysqli->query($sql1) or die('Erreur SQL !<br />'.$sql1.'<br />'.$mysqli->error);
while($c = $req1->fetch_assoc()) {
$chants[''][] = array($c['id'],1,1);
}
} else {
$sql1 = 'SELECT * FROM '.db('chant_sources').' WHERE `source` = "'.$s.'" ORDER BY sequence ASC';
$req1 = $mysqli->query($sql1) or die('Erreur SQL !<br />'.$sql1.'<br />'.$mysqli->error);
while($c = $req1->fetch_assoc()) {
$chants[$c['page']][] = array($c['chant_id'],$c['sequence'],$c['extent']);
}
}
if(array_key_exists($s, $sources)) {
$title = 'Sources - '.($sources[$s]['period']?$sources[$s]['period']:$sources[$s]['year'])." - ".$sources[$s]['editor']." - ".$sources[$s]['title'];
} else {
$title = 'Sources - no source';
}
include('include/header.php');
echo "<h2>$title</h2>\n";
if(array_key_exists('images', $_GET) && $_GET['images'] == '1') {
$ipp = 25;
if(is_array($sources[$s]['pages'])) {
$urls = $sources[$s]['urls'];
$np = count($sources[$s]['pages']);
$start = array_key_exists('index', $_GET) ? intval($_GET['index']*$ipp) : 0;
if($start > $np) $start = 0;
$n = [];
for($i = 0; $i < $np; $i += $ipp) {
$n[$i] = ($i == $start) ? '' : '<a href="source.php?id='.$s.'&images=1&index='.($i/$ipp).'">';
$n[$i] .= $sources[$s]['pages'][$i].'-'.$sources[$s]['pages'][min($i+$ipp-1, $np-1)];
$n[$i] .= ($i == $start) ? '' : '</a>';
}
echo "<p><b>Pages</b> ".implode(' | ', $n)."</p>\n";
echo "<p><i>".$sources[$s]['caption']."</i></p>\n";
echo "<table>\n<tr><th>Page</th><th>Incipit</th></tr>";
for($i = $start; $i < min($start+$ipp, $np); $i++) {
$p = $sources[$s]['pages'][$i];
echo "<tr><td>$p</td><td>";
echo "<ul class=\"incipit\">\n";
if(array_key_exists($p,$chants)) {
$ch = $chants[$p];
foreach($ch as $c) {
$t = chant_from_id($c[0]);
if($t) {
echo '<li class="usage-marker '.$t[0].'">';
if($t[2]) {
echo '<a href="chant.php?id='.$c[0].'">'.format_incipit($t[1])."</a>";
} else {
echo '<span class="todo">'.format_incipit($t[1]).'</span> (<a href="chant_edit.php?id='.$c[0].'">TODO</a>)';
}
echo "</li>\n";
}
}
}
echo '<li class="add-chant"><a href="chant_edit.php?source='.$s.'&page='.$p.'">Add chant</a></li>'."\n";
echo "</ul>\n";
echo "</td>\n";
if(is_dir('./sources/'.$s)) {
echo '<td>';
if(is_array($urls)) echo '<a target="_new" href="'.$urls[0].$urls[1][$i].$urls[2].'">';
echo '<img src="sources/'.$s.'/'.$i.'.png" />';
if(is_array($urls)) echo '</a>';
echo '</td>';
}
}
echo "</table>\n";
echo "<p><b>Pages</b> ".implode(' | ', $n)."</p>\n";
}
} else {
if(is_array($sources[$s]['pages'])) {
echo '<p><a href="source.php?id='.$s.'&images=1">Show source images</a></p>'."\n";
}
echo "<table>\n<tr>".($s == "none"?"":"<th>Page</th>")."<th>Incipit</th></tr>";
if(is_array($sources[$s]['pages'])) {
foreach($sources[$s]['pages'] as $p) {
if(array_key_exists($p,$chants)) {
echo "<tr>".($s == "none"?"":"<td>$p</td>")."<td>";
echo "<ul class=\"incipit\">\n";
$ch = $chants[$p];
unset($chants[$p]);
foreach($ch as $c) {
$t = chant_from_id($c[0]);
if($t) {
echo '<li class="usage-marker '.$t[0].'">';
if($t[2]) {
echo '<a href="chant.php?id='.$c[0].'">'.format_incipit($t[1])."</a>";
} else {
echo '<span class="todo">'.format_incipit($t[1]).'</span>';
}
echo "</li>\n";
}
}
echo "</ul>\n";
echo "</td></tr>\n";
}
}
}
uksort($chants, 'strnatcmp');
foreach($chants as $p => $ch) {
echo "<tr>".($s == "none"?"":"<td>$p</td>")."<td><ul class=\"incipit\">";
$l = array();
foreach($ch as $c) {
$t = chant_from_id($c[0]);
$l[] = $t[1]."=-=".$t[0]."=-=".$c[0]."=-=".$c[1]."=-=".$c[2];
}
natcasesort($l);
foreach($l as $ll) {
$ll = explode('=-=',$ll);
echo '<li class="usage-marker '.$ll[1].'"><a href="chant.php?id='.$ll[2].'">'.$ll[0]."</a></li>\n";
}
echo "</ul></td></tr>\n";
}
echo "</table>\n";
}
include('include/footer.php');
?>