summaryrefslogtreecommitdiff
path: root/modules_v3/GEDFact_assistant/_MEDIA/media_0_inverselink.php
blob: d1b1cd3d6598f45e2927345e3984f472955ba257 (plain)
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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
<?php
namespace Fisharebest\Webtrees;

/**
 * webtrees: online genealogy
 * Copyright (C) 2015 webtrees development team
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Defined in session.php
 *
 * @global Tree $WT_TREE
 */
global $WT_TREE;

use Fisharebest\Webtrees\Functions\FunctionsPrint;

$more_links  = Filter::get('more_links');
$exist_links = Filter::get('exist_links');
$gid         = Filter::get('gid', WT_REGEX_XREF);
$update_CHAN = Filter::get('preserve_last_changed');

$controller
	->addExternalJavascript(WT_AUTOCOMPLETE_JS_URL)
	->addInlineJavascript('autocomplete();');

$paramok = true;
if (!empty($linktoid)) {
	$paramok = GedcomRecord::getInstance($linktoid, $WT_TREE)->canShow();
}

if ($action == 'choose' && $paramok) {

	?>
	<script>
	// Javascript variables
	var id_empty = "<?php echo I18N::translate('When adding a link, the ID field cannot be empty.'); ?>";

	function blankwin() {
		if (document.getElementById('gid').value == "" || document.getElementById('gid').value.length<=1) {
			alert(id_empty);
		} else {
			var iid = document.getElementById('gid').value;
			var winblank = window.open('module.php?mod=GEDFact_assistant&mod_action=media_query_3a&iid='+iid, 'winblank', 'top=100, left=200, width=400, height=20, toolbar=0, directories=0, location=0, status=0, menubar=0, resizable=1, scrollbars=1');
		}
	}

	var GEDFact_assist = 'installed';
	</script>

	<?php
	echo '<form class="medialink" name="link" method="get" action="inverselink.php">';
	echo '<input type="hidden" name="action" value="update">';
	if (!empty($mediaid)) {
		echo '<input type="hidden" name="mediaid" value="', $mediaid, '">';
	}
	if (!empty($linktoid)) {
		echo '<input type="hidden" name="linktoid" value="', $linktoid, '">';
	}
	echo '<input type="hidden" name="linkto" value="', $linkto, '">';
	echo '<input type="hidden" name="ged" value="', $WT_TREE->getNameHtml(), '">';
	echo '<table class="facts_table center">';
	echo '<tr><td class="topbottombar" colspan="2">';
	echo I18N::translate('Link to an existing media object');
	echo '</td></tr><tr><td class="descriptionbox width20 wrap">', I18N::translate('Media'), '</td>';
	echo '<td class="optionbox wrap">';
	if (!empty($mediaid)) {
		//-- Get the title of this existing Media item
		$title =
			Database::prepare("SELECT m_titl FROM `##media` where m_id=? AND m_file=?")
			->execute(array($mediaid, $WT_TREE->getTreeId()))
			->fetchOne();
		if ($title) {
			echo '<b>', $title, '</b>';
		} else {
			echo '<b>', $mediaid, '</b>';
		}
		echo '<table><tr><td>';
		//-- Get the filename of this existing Media item
		$filename =
			Database::prepare("SELECT m_filename FROM `##media` where m_id=? AND m_file=?")
			->execute(array($mediaid, $WT_TREE->getTreeId()))
			->fetchOne();
		$media = Media::getInstance($mediaid, $WT_TREE);
		echo $media->displayImage();
		echo '</td></tr></table>';
		echo '</td></tr>';
		echo '<tr><td class="descriptionbox width20 wrap">', I18N::translate('Links'), '</td>';
		echo '<td class="optionbox wrap">';
		echo "<table><tr><td>";
		echo "<table id=\"existLinkTbl\" width=\"430\" cellspacing=\"1\" >";
		echo "<tr>";
		echo '<td class="topbottombar" width="15"  style="font-weight:100;" >#</td>';
		echo '<td class="topbottombar" width="50"  style="font-weight:100;" >', I18N::translate('Record'), '</td>';
		echo '<td class="topbottombar" width="340" style="font-weight:100;" >', I18N::translate('Name'), '</td>';
		echo '<td class="topbottombar" width="20"  style="font-weight:100;" >', I18N::translate('Keep'), '</td>';
		echo '<td class="topbottombar" width="20"  style="font-weight:100;" >', I18N::translate('Remove'), '</td>';
		echo '<td class="topbottombar" width="20"  style="font-weight:100;" >', I18N::translate('Navigator'), '</td>';
		echo "</tr>";

		$links = array_merge(
			$media->linkedIndividuals('OBJE'),
			$media->linkedFamilies('OBJE'),
			$media->linkedSources('OBJE'),
			$media->linkedNotes('OBJE'), // Invalid GEDCOM - you cannot link a NOTE to an OBJE
			$media->linkedRepositories('OBJE') // Invalid GEDCOM - you cannot link a REPO to an OBJE
		);
		$i = 1;
		foreach ($links as $record) {
			echo "<tr ><td>";
			echo $i++;
			echo "</td><td id=\"existId_", $i, "\" class=\"row2\">";
			echo $record->getXref();
			echo "</td><td>";
			echo $record->getFullName();
			echo "</td>";
			echo "<td align='center'><input alt='", I18N::translate('Keep link in list'), "', title='", I18N::translate('Keep link in list'), "' type='radio' id='", $record->getXref(), "_off' name='", $record->getXref(), "' checked></td>";
			echo "<td align='center'><input alt='", I18N::translate('Remove link from list'), "', title='", I18N::translate('Remove link from list'), "' type='radio' id='", $record->getXref(), "_on'  name='", $record->getXref(), "'></td>";

			if ($record instanceof Individual) {
				?>
				<td align="center"><a href="#" class="icon-button_family" title="<?php echo I18N::translate('Family navigator'); ?>" name="family_'<?php echo $record->getXref(); ?>'" onclick="openFamNav('<?php echo $record->getXref(); ?>'); return false;"></a></td>
				<?php
			} elseif ($record instanceof Family) {
				if ($record->getHusband()) {
					$head = $record->getHusband()->getXref();
				} elseif ($record->getWife()) {
					$head = $record->getWife()->getXref();
				} else {
					$head = '';
				}
				?>
				<td align="center"><a href="#" class="icon-button_family" title="<?php echo I18N::translate('Family navigator'); ?>" name="family_'<?php echo $record->getXref(); ?>'" onclick="openFamNav('<?php echo $head; ?>');"></a></td>
				<?php
			} else {
				echo '<td></td>';
			}
			echo '</tr>';
		}

		echo "</table>";
		echo "</td></tr></table>";
		echo '</td></tr>';
	}

	if (!isset($linktoid)) { $linktoid = ""; }

	echo '<tr><td class="descriptionbox wrap">';
	echo I18N::translate('Add links');
	echo '<td class="optionbox wrap ">';
	if ($linktoid == "") {
		// ----
	} else {
		$record = Individual::getInstance($linktoid, $WT_TREE);
		echo '<b>', $record->getFullName(), '</b>';
	}
	echo '<table><tr><td>';
	echo '<input type="text" data-autocomplete-type="IFS" name="gid" id="gid" size="6" value="">';
	echo '</td><td style="padding-bottom: 2px; vertical-align: middle;">';
	echo '&nbsp;';
	echo '<img style="border-style:none;" src="', Theme::theme()->parameter('image-add'), '" alt="', I18N::translate('Add'), ' " title="', I18N::translate('Add'), '" align="middle" name="addLink" value="" onclick="blankwin(); return false;">';
	echo ' ', FunctionsPrint::printFindIndividualLink('gid');
	echo ' ', FunctionsPrint::printFindFamilyLink('gid');
	echo ' ', FunctionsPrint::printFindSourceLink('gid');
	echo '</td></tr></table>';
	echo "<sub>" . I18N::translate('Enter or search for the ID of the individual, family, or source to which this media item should be linked.') . "</sub>";
	echo '<br><br>';
	echo '<input type="hidden" name="idName" id="idName" size="36" value="Name of ID">';

?>
<script>

	function addlinks(iname) {
		// iid=document.getElementById('gid').value;
		if (document.getElementById('gid').value == "") {
			alert(id_empty);
		} else {
			addmedia_links(document.getElementById('gid'), document.getElementById('gid').value, iname );
			return false;
		}
	}

	function openFamNav(id) {
		winNav = window.open('edit_interface.php?action=addmedia_links&noteid=newnote&pid='+id, 'winNav', fam_nav_specs);
		if (window.focus) {
			winNav.focus();
		}
	}

	var ifamily = "<?php echo I18N::translate('Family navigator'); ?>";
	var remove = "<?php echo I18N::translate('Remove'); ?>";
	/* ===icons === */
	var removeLinkIcon = "<?php echo Theme::theme()->parameter('image-remove'); ?>";
	var familyNavIcon = "<?php echo Theme::theme()->parameter('image-button_family'); ?>";


var INPUT_NAME_PREFIX = 'InputCell_'; // this is being set via script
var RADIO_NAME = "totallyrad"; // this is being set via script
var TABLE_NAME = 'addlinkQueue'; // this should be named in the HTML
var ROW_BASE = 1; // first number (for display)
var hasLoaded = false;

window.onload=fillInRows;

function fillInRows() {
	hasLoaded = true;
}

// CONFIG
// myRowObject is an object for storing information about the table rows
//function myRowObject(zero, one, two, three, four, five, six, seven, eight, nine, ten, cb, ra)
function myRowObject(zero, one, two, cb, ra)
{
	this.zero	 = zero;	 // text object
	this.one	 = one;		 // input text object
	this.two	 = two;		 // input text object

	this.cb		 = cb;		 // input checkbox object
	this.ra		 = ra;		 // input radio object
}

/*
 * insertRowToTable
 * Insert and reorder
 */
//function insertRowToTable(pid, nam, label, gend, cond, yob, age, YMD, occu, birthpl)
function insertRowToTable(pid, nam, head)
{
	if (hasLoaded) {

		var tbl = document.getElementById(TABLE_NAME);
		var rowToInsertAt = "";

		// Get links list ====================================
		var links 	= document.getElementById('existLinkTbl');
		var numrows = links.rows.length;
		var strRow = '';
		for (var i=1; i<numrows; i++) {
			if (typeof links.rows[i].cells[1].textContent !== "undefined") {
				strRow += (strRow==''?'':', ') + links.rows[i].cells[1].textContent;
			} else {
				strRow += (strRow==''?'':', ') + links.rows[i].cells[1].innerText;
			}
		}
		strRow += (strRow==''?'':', ');

		//Check if id exists in Links list =================================
		if (strRow.match(pid+',')!= pid+',') {
		} else {
			rowToInsertAt = 'EXIST' ;
		}

		// Check if id exists in "Add links" list ==========================
		for (var i=0; i<tbl.tBodies[0].rows.length; i++) {
			var cellText;
			if (typeof tbl.tBodies[0].rows[i].myRow.one.textContent !== "undefined") {
				cellText = tbl.tBodies[0].rows[i].myRow.one.textContent;
			} else {
				cellText = tbl.tBodies[0].rows[i].myRow.one.innerText;
			}
			if (cellText==pid) {
				rowToInsertAt = 'EXIST';
			} else
			if (tbl.tBodies[0].rows[i].myRow && tbl.tBodies[0].rows[i].myRow.ra.getAttribute('type') == 'radio' && tbl.tBodies[0].rows[i].myRow.ra.checked) {
				rowToInsertAt = i;
				break;
			}
		}

		// If Link does not exist then add it, or show alert ===============
		if (rowToInsertAt!='EXIST') {
			rowToInsertAt = i;
			addRowToTable(rowToInsertAt, pid, nam, head);
			reorderRows(tbl, rowToInsertAt);
		}

	}
}

function removeHTMLTags(htmlString)
{
	if (htmlString) {
		var mydiv = document.createElement("div");
			mydiv.innerHTML = htmlString;
		if (typeof mydiv.textContent !== "undefined") {
			return mydiv.textContent;
		}
		return mydiv.innerText;
	}
}

/*
 * addRowToTable
 * Inserts at row 'num', or appends to the end if no arguments are passed in. Don't pass in empty strings.
 */
// function addRowToTable(num, pid, nam, label, gend, cond, yob, age, YMD, occu, birthpl)
function addRowToTable(num, pid, nam, head)
{
		if (hasLoaded) {
			var tbl = document.getElementById(TABLE_NAME);
			var nextRow = tbl.tBodies[0].rows.length;
			var iteration = nextRow + ROW_BASE;

			if (num == null) {
				num = nextRow;
			} else {
				iteration = num + ROW_BASE;
			}

			// add the row
			var row = tbl.tBodies[0].insertRow(num);

			// CONFIG: requires class
			row.className = 'descriptionbox';

			// CONFIG: This whole section can be configured

			// cell 0 - Count
			var cell0 = row.insertCell(0);
			cell0.style.fontSize="11px";
			var textNode = document.createTextNode(iteration);
			cell0.appendChild(textNode);

			// cell 1 - ID:
			var cell1 = row.insertCell(1);
			if (pid=='') {
				var txtInp1 = document.createElement('div');
				txtInp1.setAttribute('type', 'checkbox');
				if (txtInp1.checked!='') {
					txtInp1.setAttribute('value', 'no');
				} else {
					txtInp1.setAttribute('value', 'add');
				}
			} else {
				var txtInp1 = document.createElement('div');
				txtInp1.setAttribute('type', 'text');
				if (typeof txtInp1.textContent !== "undefined") {
					txtInp1.textContent = pid;
				} else {
					txtInp1.innerText = pid;
				}
			}
				txtInp1.setAttribute('id', INPUT_NAME_PREFIX + iteration + '_1');
				txtInp1.style.background='transparent';
				txtInp1.style.border='0px';
				txtInp1.style.fontSize="11px";
			cell1.appendChild(txtInp1);

			// cell 2 - Name
			var cell2 = row.insertCell(2);
			var txtInp2 = document.createElement('div');
				txtInp2.setAttribute('type', 'text');
				txtInp2.setAttribute('id', INPUT_NAME_PREFIX + iteration + '_2');
				txtInp2.style.background='transparent';
				txtInp2.style.border='0px';
				txtInp2.style.fontSize="11px";
				txtInp2.innerHTML = removeHTMLTags(unescape(nam));
			cell2.appendChild(txtInp2);

			// cell btn - remove img button
			var cellbtn = row.insertCell(3);
				cellbtn.setAttribute('align', 'center');
			var btnEl = document.createElement('img');
				btnEl.setAttribute('type', 'img');
				btnEl.setAttribute('src', removeLinkIcon);
				btnEl.setAttribute('alt', remove);
				btnEl.setAttribute('title', remove);
				btnEl.setAttribute('height', '14px');
				btnEl.onclick = function () {deleteCurrentRow(this)};
			cellbtn.appendChild(btnEl);

			// cell btn - family img button
			var cellbtn2 = row.insertCell(4);
				cellbtn2.setAttribute('align', 'center');
			if (pid.match("I")=="I" || pid.match("i")=="i") {
				var btn2El = document.createElement('img');
					btn2El.setAttribute('type', 'img');
					btn2El.setAttribute('src', familyNavIcon);
					btn2El.setAttribute('alt', ifamily);
					btn2El.setAttribute('title', ifamily);
					btn2El.onclick = function () {openFamNav(pid)};
				cellbtn2.appendChild(btn2El);
			} else if (pid.match("F")=="F" || pid.match("f")=="f") {
				var btn2El = document.createElement('img');
					btn2El.setAttribute('type', 'img');
					btn2El.setAttribute('src', familyNavIcon);
					btn2El.setAttribute('alt', ifamily);
					btn2El.setAttribute('title', ifamily);
					btn2El.onclick = function () {openFamNav(head)};
				cellbtn2.appendChild(btn2El);
			} else {
				// Show No Icon
			}

			// cell cb - input checkbox
			var cbEl = document.createElement('input');
			cbEl.type = "hidden";

			// cell ra - input radio
			//var cellra = row.insertCell(5);
			var cellra = document.createElement('input');
			cellra.type = "hidden";

			// Pass in the elements you want to reference later
			// Store the myRow object in each row
			row.myRow = new myRowObject(textNode, txtInp1, txtInp2, cbEl, cellra);
		}
}

// CONFIG: this entire function is affected by myRowObject settings
// If there isn't a checkbox in your row, then this function can’t be used.
function deleteChecked()
{
	if (hasLoaded) {
		var checkedObjArray = new Array();
		var cCount = 0;

		var tbl = document.getElementById(TABLE_NAME);
		for (var i=0; i<tbl.tBodies[0].rows.length; i++) {
			if (tbl.tBodies[0].rows[i].myRow && tbl.tBodies[0].rows[i].myRow.cb.getAttribute('type') == 'checkbox' && tbl.tBodies[0].rows[i].myRow.cb.checked) {
				checkedObjArray[cCount] = tbl.tBodies[0].rows[i];
				cCount++;
			}
		}
		if (checkedObjArray.length > 0) {
			var rIndex = checkedObjArray[0].sectionRowIndex;
			deleteRows(checkedObjArray);
			reorderRows(tbl, rIndex);
		}
	}
}

// If there isn't an element with an onclick event in your row, then this function can’t be used.
function deleteCurrentRow(obj)
{
	if (hasLoaded) {
		var delRow = obj.parentNode.parentNode;
		var tbl = delRow.parentNode.parentNode;
		var rIndex = delRow.sectionRowIndex;
		var rowArray = new Array(delRow);
		deleteRows(rowArray);
		reorderRows(tbl, rIndex);
	}
}

function reorderRows(tbl, startingIndex)
{
	if (hasLoaded) {
		if (tbl.tBodies[0].rows[startingIndex]) {
			var count = startingIndex + ROW_BASE;
			for (var i=startingIndex; i<tbl.tBodies[0].rows.length; i++) {

				// CONFIG: next line is affected by myRowObject settings
				tbl.tBodies[0].rows[i].myRow.zero.data	 = count; // text

				tbl.tBodies[0].rows[i].myRow.one.id		 = INPUT_NAME_PREFIX + count + '_1'; // input text
				tbl.tBodies[0].rows[i].myRow.two.id 	 = INPUT_NAME_PREFIX + count + '_2'; // input text

				tbl.tBodies[0].rows[i].myRow.one.name	 = INPUT_NAME_PREFIX + count + '_1'; // input text
				tbl.tBodies[0].rows[i].myRow.two.name 	 = INPUT_NAME_PREFIX + count + '_2'; // input text

				// tbl.tBodies[0].rows[i].myRow.cb.value = count; // input checkbox
				tbl.tBodies[0].rows[i].myRow.ra.value = count; // input radio

				// CONFIG: requires class named classy0 and classy1
				tbl.tBodies[0].rows[i].className = 'classy' + (count % 2);

				count++;
			}
		}
	}
}

function deleteRows(rowObjArray)
{
	if (hasLoaded) {
		for (var i=0; i<rowObjArray.length; i++) {
			var rIndex = rowObjArray[i].sectionRowIndex;
			rowObjArray[i].parentNode.deleteRow(rIndex);
		}
	}
}

function openInNewWindow(frm)
{
	// open a blank window
	var aWindow = window.open('', 'TableAddRow2NewWindow',
	'scrollbars=yes,menubar=yes,resizable=yes,location=no,toolbar=no,width=550,height=700');
	aWindow.focus();

	// set the target to the blank window
	frm.target = 'TableAddRow2NewWindow';

	// submit
	frm.submit();
}

function parseAddLinks() {
	// start with the "newly added" ID.
	var str = document.getElementById('gid').value;
	// Add in the "keep" IDs.
	var tbl = document.getElementById('addlinkQueue');
	// start at i=1 because we need to avoid header
	for (var i=1; i<tbl.rows.length; i++) {
		var tr = tbl.rows[i];
		if (typeof tr.cells[1].childNodes[0].textContent !== "undefined") {
			str += (str==''?'':',') + tr.cells[1].childNodes[0].textContent;
		} else {
			str += (str==''?'':',') + tr.cells[1].childNodes[0].innerHTML;
		}
	}
	document.link.more_links.value = str;
}

function parseRemLinks() {
	var remstr = "";
	var tbl = document.getElementById('existLinkTbl');
	// start at i=1 because we need to avoid header
	for (var i=1; i<tbl.rows.length; i++) {
		var remtr = tbl.rows[i];
		if (remtr.cells[4].childNodes[0].checked)  {
			remstr += (remstr==''?'':',') + remtr.cells[4].childNodes[0].name;
		}
	}
	document.link.exist_links.value = remstr;
}

function shiftlinks() {
	parseRemLinks();
	parseAddLinks();
	if (winNav) {
		winNav.close();
	}
}

</script>

				<table width="430" border="0" cellspacing="1" id="addlinkQueue">
					<thead>
						<tr>
							<th class="topbottombar" width="10"  style="font-weight:100;" align="left">#</th>
							<th class="topbottombar" width="55"  style="font-weight:100;" align="left"><?php echo I18N::translate('Record'); ?></th>
							<th class="topbottombar" width="370" style="font-weight:100;" align="left"><?php echo I18N::translate('Name'); ?></th>
							<th class="topbottombar" width="20"  style="font-weight:100;" align="left"><?php echo I18N::translate('Remove'); ?></th>
							<th class="topbottombar" width="20"  style="font-weight:100;" align="left"><?php echo I18N::translate('Navigator'); ?></th>
						</tr>
					</thead>
					<tbody>
					</tbody>
				</table>
			</td>
		</tr>
		<?php
		// Admin Option CHAN log update override =======================
		if (Auth::isAdmin()) {
			echo "<tr><td class=\"descriptionbox wrap width25\">";
			echo GedcomTag::getLabel('CHAN'), "</td><td class=\"optionbox wrap\">";
			if ($WT_TREE->getPreference('NO_UPDATE_CHAN')) {
				echo "<input type=\"checkbox\" checked name=\"preserve_last_changed\">";
			} else {
				echo "<input type=\"checkbox\" name=\"preserve_last_changed\">";
			}
			echo I18N::translate('Do not update the “last change” record');
			echo "</td></tr>";
		}
		?>
	</table>
	<input type="hidden" name="more_links" value="No_Values">
	<input type="hidden" name="exist_links" value="No_Values">
	<p id="save-cancel">
		<input type="submit" class="save" value="<?php echo I18N::translate('save'); ?>" onclick="shiftlinks();">
		<input type="button" class="cancel" value="<?php echo I18N::translate('close'); ?>" onclick="window.close();">
	</p>
</form>
<?php
} elseif ($action == "update" && $paramok) {
	// Unlink records indicated by radio button =========
	if ($exist_links) {
		foreach (explode(',', $exist_links) as $remLinkId) {
			$indi = GedcomRecord::getInstance($remLinkId, $WT_TREE);
			$indi->removeLinks($mediaid, $update_CHAN != 'no_change');
		}
	}
	// Add new Links ====================================
	if ($more_links) {
		// array_unique() because parseAddLinks() may includes the gid field, even
		// when it is also in the list.
		foreach (array_unique(explode(',', $more_links)) as $addLinkId) {
			$indi = GedcomRecord::getInstance($addLinkId, $WT_TREE);
			$indi->createFact('1 OBJE @' . $mediaid . '@', $update_CHAN != 'no_change');
		}
	}
	$controller->addInlineJavascript('closePopupAndReloadParent();');
}