/
source_manager.php
executable file
·370 lines (342 loc) · 12.7 KB
/
source_manager.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<?php
/***************************************************************************
* source_manager.php *
* Yggdrasil: Source Manager *
* *
* Copyright (C) 2006-2011 by Leif B. Kristensen <leif@solumslekt.org> *
* All rights reserved. For terms of use, see LICENSE.txt *
***************************************************************************/
/*
This script will display events, relations, and subnodes associated with each
node in the source tree. It has evolved to become the central point of the
application besides the family view. I don't think that any other genealogy
app has anything like it.
*/
// *****************************************************************************
// initialization
// *****************************************************************************
require "./settings/settings.php";
require_once "./langs/$language.php";
require "./functions.php";
// we'll display only raw dates here
pg_query("SET DATESTYLE TO GERMAN");
// $self = this node, default node is root
$self = isset($_GET['node']) ? $_GET['node'] : 0;
// set $self as active source
set_last_selected_source($self);
// localized source part type label
$label = 'label_' . $language;
// get all attributes of $self in one query
$props = fetch_row_assoc("
SELECT
ecc($self) AS number_of_events,
rcc($self) AS number_of_relations,
ssc($self) AS number_of_subsources,
usc($self) AS number_of_unused_subsources,
get_source_text($self) AS source_txt,
get_prev_page($self) AS prev_page,
get_next_page($self) AS next_page,
link_expand(source_text) AS node_txt,
parent_id,
sort_order,
source_date,
part_type,
spt.$label,
spt.is_leaf
FROM
sources, source_part_types spt
WHERE
spt.part_type_id = sources.part_type
AND
source_id = $self
");
$title_prev = get_source_plain_text($props['prev_page']);
$title_next = get_source_plain_text($props['next_page']);
$title = "S:$self " . get_source_plain_text($self);
// limit title tag to a sensible length
if (mb_strlen($title) > 80)
$title = mb_substr($title, 0, 80) . '...';
// var used by header.php to display context dependent menu items
$source_manager = true;
require "./header.php";
// *****************************************************************************
// main
// *****************************************************************************
echo "<div class=\"normal\">\n";
echo "<h2>Node $self"
. node_details(
$props['number_of_events'],
$props['number_of_relations'],
$props['number_of_subsources'],
$props['number_of_unused_subsources']
)
. conc($props[$label], ': ');
if ($principal = get_source_principal($self))
echo conc($props['source_date'])
. conc(get_name_and_lifespan($principal), ' av ');
echo "</h2>\n";
// full source text
echo para(
square_brace($props['sort_order'])
. conc(square_brace($props['source_date']))
. conc($props['source_txt'])
. conc(paren(
to_url('./forms/source_edit.php',
array(
'person' => 0,
'source' => $self,
'self' => 1
), $_edit))
)
);
// displays feedback from add_source depending on outcome; (not i18n'd yet)
// see ddl/functions.sql function add_source() for details
$new = isset($_GET['new']) ? $_GET['new'] : 0;
if ($new && $new < 0) {
$new = abs($new);
echo '<p class="alert">Kilden finnes allerede, se nr. ['
. to_url($_SERVER['PHP_SELF'], array('node' => $new), $new)
. "]!</p>\n";
}
// *****************************************************************************
// experimental section: print list of persons mentioned in this source
// *****************************************************************************
if ($props['part_type'] == 1) {
if (fetch_val("
SELECT COUNT(*) FROM source_linkage WHERE source_fk=$self")) {
echo "<h3>Personer nevnt i kilden:</h3>\n";
list_mentioned($self, 1);
}
else
echo para(to_url('./forms/linkage_add.php',
array('node' => $self), 'Legg til lenke'));
}
// *****************************************************************************
// section I: print list of events cited by this source
// *****************************************************************************
if ($props['number_of_events']) {
echo "<h3>$_Events:</h3>\n<ol>";
$handle = pg_query("
SELECT
e.event_id,
e.tag_fk,
e.event_date,
get_place_name(e.place_fk) AS event_place,
link_expand(e.event_note) AS event_note,
get_event_type(e.event_id) AS event_type
FROM
events e,
event_citations s
WHERE
e.event_id = s.event_fk
AND
s.source_fk = $self
ORDER BY
get_event_type(e.event_id),
e.sort_date,
e.event_id
");
while ($row = pg_fetch_assoc($handle)) {
$event = $row['event_id'];
echo '<li>';
echo square_brace($event)
. conc(italic(get_tag_name($row['tag_fk'])))
. conc(fuzzydate($row['event_date']))
. conc($row['event_place']);
if ($row['event_type'] < 3)
// event has one or two participants, print names inline
echo conc(list_participants($event), ': ');
echo conc($row['event_note'], ': ');
echo ' ' .
paren(
to_url('./forms/source_event_edit.php',
array(
'event' => $event,
'source' => $self
), $_edit)
. ' / '
. to_url('./forms/citation_delete.php',
array(
'person' => 0,
'event' => $event,
'source' => $self
), $_delete)
);
if ($row['event_type'] == 3) {
// event has any number of participants, print names as ordered list
$subhandle = pg_query("
SELECT
person_fk,
is_principal,
sort_order
FROM
participants
WHERE
event_fk=$event
ORDER BY
sort_order
");
echo '<ul>';
while ($subrow = pg_fetch_assoc($subhandle)) {
$participant = $subrow['person_fk'];
$bp = $subrow['is_principal'] == 't' ? ' H ' : ' B ';
echo '<li> ';
// print link to edit sort order
echo to_url('./forms/source_sort_order_edit.php',
array(
'person' => $participant,
'event' => $event,
'node' => $self
),
square_brace($subrow['sort_order']),
'Edit sort order'
);
echo $bp . linked_name($participant, './family.php');
// a non-principal, eg a person mentioned as heir in a probate,
// who may or may not be described in a separate note
if ($subrow['is_principal'] == 'f') {
// print participant note if it exists
if ($note = fetch_val("
SELECT link_expand(part_note)
FROM participant_notes
WHERE person_fk = $participant
AND event_fk = $event
"))
echo ': ' . $note;
// print link to edit participant note
echo ' ' . paren(
to_url('./forms/part_note.php',
array(
'person' => $participant,
'event' => $event,
'node' => $self
), $_edit)
);
}
echo "</li>\n";
}
echo "</ul>\n";
}
echo "</li>\n";
}
echo "</ol>\n";
}
// *****************************************************************************
// section II: print list of relations cited by this source
// *****************************************************************************
if ($props['number_of_relations']) {
$child[1] = $_son;
$child[2] = $_daughter;
echo "<h3>$_Relations:</h3>\n<ol>";
$handle = pg_query("
SELECT
r.relation_id,
r.parent_fk,
r.child_fk,
get_lsurety(r.surety_fk) AS surety
FROM
relations r,
relation_citations c
WHERE
c.relation_fk = r.relation_id
AND
c.source_fk = $self
ORDER BY
get_pbdate(r.child_fk),
r.child_fk,
get_gender(r.parent_fk)
");
while ($row = pg_fetch_assoc($handle)) {
echo li(linked_name($row['child_fk'], './family.php')
. " $_is " . $row['surety'] . ' '
. $child[get_gender($row['child_fk'])] . " $_of "
. linked_name($row['parent_fk'], './family.php')
);
}
echo "</ol>\n";
}
// *****************************************************************************
// section III: print list of subsources
// *****************************************************************************
if ($props['number_of_subsources']) {
echo "<h3>$_Subsources:</h3>\n";
echo "<table>";
$handle = pg_query("
SELECT
source_id,
link_expand(source_text) AS txt,
sort_order,
source_date,
ecc(source_id) AS e,
rcc(source_id) AS r,
ssc(source_id) AS s,
usc(source_id) AS u,
spt.$label AS $label
FROM
sources, source_part_types spt
WHERE
spt.part_type_id = sources.part_type
AND
parent_id = $self
AND
source_id <> 0
ORDER BY
sort_order,
source_date,
source_text
");
// change between FALSE and TRUE to select terse / informative mode
$friendly = TRUE;
while ($row = pg_fetch_assoc($handle)) {
$id = $row['source_id'];
echo '<tr>';
if ($friendly) {
echo td(paren(to_url($_SERVER['PHP_SELF'],
array('node' => $id), $_Select)
. ' / '
. to_url('./forms/source_edit.php',
array(
'person' => 0,
'source' => $id), $_Edit)));
echo td_numeric(square_brace($row['sort_order']));
echo td(paren($row[$label]));
}
else {
echo td_numeric(square_brace(to_url($_SERVER['PHP_SELF'],
array('node' => $id), $id, $_goto)));
echo td_numeric(square_brace($row['sort_order']));
echo td(paren(to_url('./forms/source_edit.php',
array(
'person' => 0,
'source' => $id
), $row[$label], $_edit)));
}
if ($row['e'] || $row['r'] || $row['s']) {
echo td(square_brace(italic($row['source_date']))
. ' ' . $row['txt']
. node_details($row['e'], $row['r'], $row['s'], $row['u']));
}
else { // source is unused, print with gray text
if ($show_delete) { // show link for source deletion
echo td(span_type(square_brace(italic($row['source_date']))
. conc($row['txt']),"faded")
. conc(paren(to_url('./forms/source_delete.php',
array(
'node' => $self,
'id' => $id
), bold($_delete)))));
}
else
echo td(span_type(square_brace(italic($row['source_date']))
. conc($row['txt']), "faded"));
}
echo "</tr>\n";
}
echo "</table>\n";
}
if ($props['is_leaf'] == "f")
echo para(to_url('./forms/source_add.php',
array('node' => $self), $_Add_source));
echo "</div>\n";
include "./footer.php";
?>