xref: /webtrees/app/Module/ClippingsCartModule.php (revision 1e71bdc0ba6fc5add8fed9a3beb51cfca09e47dd)
1<?php
2namespace Fisharebest\Webtrees;
3
4/**
5 * webtrees: online genealogy
6 * Copyright (C) 2015 webtrees development team
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19use Zend_Session;
20
21/**
22 * Class ClippingsCartModule
23 */
24class ClippingsCartModule extends Module implements ModuleMenuInterface, ModuleSidebarInterface {
25
26	/** {@inheritdoc} */
27	public function getTitle() {
28		return /* I18N: Name of a module */ I18N::translate('Clippings cart');
29	}
30
31	/** {@inheritdoc} */
32	public function getDescription() {
33		return /* I18N: Description of the “Clippings cart” module */ I18N::translate('Select records from your family tree and save them as a GEDCOM file.');
34	}
35
36	/** {@inheritdoc} */
37	public function defaultAccessLevel() {
38		return Auth::PRIV_USER;
39	}
40
41	/** {@inheritdoc} */
42	public function modAction($mod_action) {
43		switch ($mod_action) {
44		case 'ajax':
45			$html = $this->getSidebarAjaxContent();
46			Zend_Session::writeClose();
47			header('Content-Type: text/html; charset=UTF-8');
48			echo $html;
49			break;
50		case 'index':
51			global $controller, $WT_SESSION, $WT_TREE;
52
53			$MAX_PEDIGREE_GENERATIONS = $WT_TREE->getPreference('MAX_PEDIGREE_GENERATIONS');
54
55			$clip_ctrl = new ClippingsCart;
56
57			$controller = new PageController;
58			$controller
59				->setPageTitle($this->getTitle())
60				->PageHeader()
61				->addExternalJavascript(WT_AUTOCOMPLETE_JS_URL)
62				->addInlineJavascript('autocomplete();');
63
64			echo '<script>';
65			echo 'function radAncestors(elementid) {var radFamilies=document.getElementById(elementid);radFamilies.checked=true;}';
66			echo '</script>';
67
68			if (!$WT_SESSION->cart[$WT_TREE->getTreeId()]) {
69				echo '<h2>', I18N::translate('Family tree clippings cart'), '</h2>';
70			}
71
72			if ($clip_ctrl->action == 'add') {
73				$person = GedcomRecord::getInstance($clip_ctrl->id, $WT_TREE);
74				echo '<h3><a href="', $person->getHtmlUrl(), '">' . $person->getFullName(), '</a></h3>';
75				if ($clip_ctrl->type === 'FAM') { ?>
76					<form action="module.php" method="get">
77					<input type="hidden" name="mod" value="clippings">
78					<input type="hidden" name="mod_action" value="index">
79					<table>
80						<tr><td class="topbottombar"><?php echo I18N::translate('Which other links from this family would you like to add?'); ?>
81						<input type="hidden" name="id" value="<?php echo $clip_ctrl->id; ?>">
82						<input type="hidden" name="type" value="<?php echo $clip_ctrl->type; ?>">
83						<input type="hidden" name="action" value="add1"></td></tr>
84						<tr><td class="optionbox"><input type="radio" name="others" checked value="none"><?php echo I18N::translate('Add just this family record.'); ?></td></tr>
85						<tr><td class="optionbox"><input type="radio" name="others" value="parents"><?php echo I18N::translate('Add parents’ records together with this family record.'); ?></td></tr>
86						<tr><td class="optionbox"><input type="radio" name="others" value="members"><?php echo I18N::translate('Add parents’ and children’s records together with this family record.'); ?></td></tr>
87						<tr><td class="optionbox"><input type="radio" name="others" value="descendants"><?php echo I18N::translate('Add parents’ and all descendants’ records together with this family record.'); ?></td></tr>
88						<tr><td class="topbottombar"><input type="submit" value="<?php echo I18N::translate('Continue adding'); ?>"></td></tr>
89
90					</table>
91					</form>
92				<?php } elseif ($clip_ctrl->type === 'INDI') { ?>
93					<form action="module.php" method="get">
94					<input type="hidden" name="mod" value="clippings">
95					<input type="hidden" name="mod_action" value="index">
96					<table>
97						<tr><td class="topbottombar"><?php echo I18N::translate('Which links from this individual would you also like to add?'); ?>
98						<input type="hidden" name="id" value="<?php echo $clip_ctrl->id; ?>">
99						<input type="hidden" name="type" value="<?php echo $clip_ctrl->type; ?>">
100						<input type="hidden" name="action" value="add1"></td></tr>
101						<tr><td class="optionbox"><input type="radio" name="others" checked value="none"><?php echo I18N::translate('Add just this individual.'); ?></td></tr>
102						<tr><td class="optionbox"><input type="radio" name="others" value="parents"><?php echo I18N::translate('Add this individual, his parents, and siblings.'); ?></td></tr>
103						<tr><td class="optionbox"><input type="radio" name="others" value="ancestors" id="ancestors"><?php echo I18N::translate('Add this individual and his direct line ancestors.'); ?><br>
104							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo I18N::translate('Number of generations'); ?> <input type="text" size="5" name="level1" value="<?php echo $MAX_PEDIGREE_GENERATIONS; ?>" onfocus="radAncestors('ancestors');"></td></tr>
105						<tr><td class="optionbox"><input type="radio" name="others" value="ancestorsfamilies" id="ancestorsfamilies"><?php echo I18N::translate('Add this individual, his direct line ancestors, and their families.'); ?><br >
106							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo I18N::translate('Number of generations'); ?> <input type="text" size="5" name="level2" value="<?php echo $MAX_PEDIGREE_GENERATIONS; ?>" onfocus="radAncestors('ancestorsfamilies');"></td></tr>
107						<tr><td class="optionbox"><input type="radio" name="others" value="members"><?php echo I18N::translate('Add this individual, his spouse, and children.'); ?></td></tr>
108						<tr><td class="optionbox"><input type="radio" name="others" value="descendants" id="descendants"><?php echo I18N::translate('Add this individual, his spouse, and all descendants.'); ?><br >
109							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo I18N::translate('Number of generations'); ?> <input type="text" size="5" name="level3" value="<?php echo $MAX_PEDIGREE_GENERATIONS; ?>" onfocus="radAncestors('descendants');"></td></tr>
110						<tr><td class="topbottombar"><input type="submit" value="<?php echo I18N::translate('Continue adding'); ?>">
111					</table>
112					</form>
113				<?php } elseif ($clip_ctrl->type === 'SOUR') { ?>
114					<form action="module.php" method="get">
115					<input type="hidden" name="mod" value="clippings">
116					<input type="hidden" name="mod_action" value="index">
117					<table>
118						<tr><td class="topbottombar"><?php echo I18N::translate('Which records linked to this source should be added?'); ?>
119						<input type="hidden" name="id" value="<?php echo $clip_ctrl->id; ?>">
120						<input type="hidden" name="type" value="<?php echo $clip_ctrl->type; ?>">
121						<input type="hidden" name="action" value="add1"></td></tr>
122						<tr><td class="optionbox"><input type="radio" name="others" checked value="none"><?php echo I18N::translate('Add just this source.'); ?></td></tr>
123						<tr><td class="optionbox"><input type="radio" name="others" value="linked"><?php echo I18N::translate('Add this source and families/individuals linked to it.'); ?></td></tr>
124						<tr><td class="topbottombar"><input type="submit" value="<?php echo I18N::translate('Continue adding'); ?>">
125					</table>
126					</form>
127				<?php }
128				}
129
130			if (!$WT_SESSION->cart[$WT_TREE->getTreeId()]) {
131				if ($clip_ctrl->action != 'add') {
132
133					echo I18N::translate('The clippings cart allows you to take extracts (“clippings”) from this family tree and bundle them up into a single file for downloading and subsequent importing into your own genealogy program.  The downloadable file is recorded in GEDCOM format.<br><ul><li>How to take clippings?<br>This is really simple.  Whenever you see a clickable name (individual, family, or source) you can go to the Details page of that name.  There you will see the <b>Add to clippings cart</b> option.  When you click that link you will be offered several options to download.</li><li>How to download?<br>Once you have items in your cart, you can download them just by clicking the “Download” link.  Follow the instructions and links.</li></ul>');
134					?>
135					<form method="get" name="addin" action="module.php">
136					<input type="hidden" name="mod" value="clippings">
137					<input type="hidden" name="mod_action" value="index">
138					<table>
139					<tr>
140						<td colspan="2" class="topbottombar" style="text-align:center; ">
141							<?php echo I18N::translate('Enter an individual, family, or source ID'); ?>
142						</td>
143					</tr>
144					<tr>
145						<td class="optionbox">
146							<input type="hidden" name="action" value="add">
147							<input type="text" data-autocomplete-type="IFSRO" name="id" id="cart_item_id" size="5">
148						</td>
149						<td class="optionbox">
150							<?php echo print_findindi_link('cart_item_id'); ?>
151							<?php echo print_findfamily_link('cart_item_id'); ?>
152							<?php echo print_findsource_link('cart_item_id', ''); ?>
153							<input type="submit" value="<?php echo I18N::translate('Add'); ?>">
154
155						</td>
156					</tr>
157					</table>
158					</form>
159					<?php
160				}
161
162				// -- end new lines
163				echo I18N::translate('Your clippings cart is empty.');
164			} else {
165				// Keep track of the INDI from the parent page, otherwise it will
166				// get lost after ajax updates
167				$pid = Filter::get('pid', WT_REGEX_XREF);
168
169				if ($clip_ctrl->action != 'download' && $clip_ctrl->action != 'add') { ?>
170					<table><tr><td class="width33" valign="top" rowspan="3">
171					<form method="get" action="module.php">
172					<input type="hidden" name="mod" value="clippings">
173					<input type="hidden" name="mod_action" value="index">
174					<input type="hidden" name="action" value="download">
175					<input type="hidden" name="pid" value="<?php echo $pid; ?>">
176					<table>
177					<tr><td colspan="2" class="topbottombar"><h2><?php echo I18N::translate('Download'); ?></h2></td></tr>
178					<tr>
179						<td class="descriptionbox width50 wrap">
180							<?php echo I18N::translate('To reduce the size of the download, you can compress the data into a .ZIP file.  You will need to uncompress the .ZIP file before you can use it.'); ?>
181						</td>
182						<td class="optionbox wrap">
183							<input type="checkbox" name="Zip" value="yes">
184							<?php echo I18N::translate('Zip file(s)'); ?>
185						</td>
186					</tr>
187					<tr>
188						<td class="descriptionbox width50 wrap">
189							<?php echo I18N::translate('Include media (automatically zips files)'), help_link('include_media'); ?>
190						</td>
191					<td class="optionbox"><input type="checkbox" name="IncludeMedia" value="yes"></td></tr>
192
193					<?php if (Auth::isManager($WT_TREE)) {	?>
194						<tr><td class="descriptionbox width50 wrap"><?php echo I18N::translate('Apply privacy settings'), help_link('apply_privacy'); ?></td>
195						<td class="optionbox">
196							<input type="radio" name="privatize_export" value="none" checked> <?php echo I18N::translate('None'); ?><br>
197							<input type="radio" name="privatize_export" value="gedadmin"> <?php echo I18N::translate('Manager'); ?><br>
198							<input type="radio" name="privatize_export" value="user"> <?php echo I18N::translate('Member'); ?><br>
199							<input type="radio" name="privatize_export" value="visitor"> <?php echo I18N::translate('Visitor'); ?>
200						</td></tr>
201					<?php } elseif (Auth::isMember($WT_TREE)) { ?>
202						<tr><td class="descriptionbox width50 wrap"><?php echo I18N::translate('Apply privacy settings'), help_link('apply_privacy'); ?></td>
203						<td class="optionbox">
204							<input type="radio" name="privatize_export" value="user" checked> <?php echo I18N::translate('Member'); ?><br>
205							<input type="radio" name="privatize_export" value="visitor"> <?php echo I18N::translate('Visitor'); ?>
206						</td></tr>
207					<?php } ?>
208
209					<tr><td class="descriptionbox width50 wrap"><?php echo I18N::translate('Convert from UTF-8 to ISO-8859-1'), help_link('utf8_ansi'); ?></td>
210					<td class="optionbox"><input type="checkbox" name="convert" value="yes"></td></tr>
211
212					<tr><td class="descriptionbox width50 wrap"><?php echo I18N::translate('Add the GEDCOM media path to filenames'), help_link('GEDCOM_MEDIA_PATH'); ?></td>
213					<td class="optionbox">
214						<input type="checkbox" name="conv_path" value="<?php echo Filter::escapeHtml($WT_TREE->getPreference('GEDCOM_MEDIA_PATH')); ?>">
215						<span dir="auto"><?php echo Filter::escapeHtml($WT_TREE->getPreference('GEDCOM_MEDIA_PATH')); ?></span>
216					</td></tr>
217
218					<tr><td class="topbottombar" colspan="2">
219					<input type="submit" value="<?php echo I18N::translate('Download'); ?>">
220					</form>
221					</td></tr>
222					</table>
223					</td></tr>
224					</table>
225					<br>
226
227					<form method="get" name="addin" action="module.php">
228					<input type="hidden" name="mod" value="clippings">
229					<input type="hidden" name="mod_action" value="index">
230					<table>
231					<tr>
232						<td colspan="2" class="topbottombar" style="text-align:center; ">
233							<?php echo I18N::translate('Enter an individual, family, or source ID'); ?>
234						</td>
235					</tr>
236					<tr>
237						<td class="optionbox">
238							<input type="hidden" name="action" value="add">
239							<input type="text" data-autocomplete-type="IFSRO" name="id" id="cart_item_id" size="8">
240						</td>
241						<td class="optionbox">
242							<?php echo print_findindi_link('cart_item_id'); ?>
243							<?php echo print_findfamily_link('cart_item_id'); ?>
244							<?php echo print_findsource_link('cart_item_id'); ?>
245							<input type="submit" value="<?php echo I18N::translate('Add'); ?>">
246
247						</td>
248					</tr>
249					</table>
250					</form>
251
252
253				<?php } ?>
254				<br><a href="module.php?mod=clippings&amp;mod_action=index&amp;action=empty"><?php echo I18N::translate('Empty the clippings cart'); ?></a>
255				</td></tr>
256
257				<tr><td class="topbottombar"><h2><?php echo I18N::translate('Family tree clippings cart'); ?></h2></td></tr>
258
259				<tr><td valign="top">
260				<table id="mycart" class="sortable list_table width100">
261					<tr>
262						<th class="list_label"><?php echo I18N::translate('Record'); ?></th>
263						<th class="list_label"><?php echo I18N::translate('Remove'); ?></th>
264					</tr>
265			<?php
266				foreach (array_keys($WT_SESSION->cart[$WT_TREE->getTreeId()]) as $xref) {
267					$record = GedcomRecord::getInstance($xref, $WT_TREE);
268					if ($record) {
269						switch ($record::RECORD_TYPE) {
270						case 'INDI': $icon = 'icon-indis'; break;
271						case 'FAM':  $icon = 'icon-sfamily'; break;
272						case 'SOUR': $icon = 'icon-source'; break;
273						case 'REPO': $icon = 'icon-repository'; break;
274						case 'NOTE': $icon = 'icon-note'; break;
275						case 'OBJE': $icon = 'icon-media'; break;
276						default:     $icon = 'icon-clippings'; break;
277						}
278						?>
279						<tr><td class="list_value">
280							<i class="<?php echo $icon; ?>"></i>
281						<?php
282						echo '<a href="', $record->getHtmlUrl(), '">', $record->getFullName(), '</a>';
283						?>
284						</td>
285						<td class="list_value center vmiddle"><a href="module.php?mod=clippings&amp;mod_action=index&amp;action=remove&amp;id=<?php echo $xref; ?>" class="icon-remove" title="<?php echo I18N::translate('Remove'); ?>"></a></td>
286					</tr>
287					<?php
288					}
289				}
290			?>
291				</table>
292				</td></tr></table>
293			<?php
294			}
295			break;
296		default:
297			http_response_code(404);
298			break;
299		}
300	}
301
302	/** {@inheritdoc} */
303	public function defaultMenuOrder() {
304		return 20;
305	}
306
307	/** {@inheritdoc} */
308	public function getMenu() {
309		global $controller, $WT_TREE;
310
311		if (Auth::isSearchEngine()) {
312			return null;
313		}
314		//-- main clippings menu item
315		$menu = new Menu($this->getTitle(), 'module.php?mod=clippings&amp;mod_action=index&amp;ged=' . $WT_TREE->getNameUrl(), 'menu-clippings');
316		if (isset($controller->record)) {
317			$submenu = new Menu($this->getTitle(), 'module.php?mod=clippings&amp;mod_action=index&amp;ged=' . $WT_TREE->getNameUrl(), 'menu-clippingscart');
318			$menu->addSubmenu($submenu);
319		}
320		if (!empty($controller->record) && $controller->record->canShow()) {
321			$submenu = new Menu(I18N::translate('Add to clippings cart'), 'module.php?mod=clippings&amp;mod_action=index&amp;action=add&amp;id=' . $controller->record->getXref(), 'menu-clippingsadd');
322			$menu->addSubmenu($submenu);
323		}
324		return $menu;
325	}
326
327	/** {@inheritdoc} */
328	public function defaultSidebarOrder() {
329		return 60;
330	}
331
332	/** {@inheritdoc} */
333	public function hasSidebarContent() {
334		if (Auth::isSearchEngine()) {
335			return false;
336		} else {
337			// Creating a controller has the side effect of initialising the cart
338			new ClippingsCart;
339
340			return true;
341		}
342	}
343
344	/** {@inheritdoc} */
345	public function getSidebarContent() {
346		global $controller;
347
348		$controller->addInlineJavascript('
349				jQuery("#sb_clippings_content").on("click", ".add_cart, .remove_cart", function() {
350					jQuery("#sb_clippings_content").load(this.href);
351					return false;
352				});
353			');
354
355		return '<div id="sb_clippings_content">' . $this->getCartList() . '</div>';
356	}
357
358	/** {@inheritdoc} */
359	public function getSidebarAjaxContent() {
360		global $WT_SESSION, $WT_TREE;
361
362		$clip_ctrl         = new ClippingsCart;
363		$add               = Filter::get('add', WT_REGEX_XREF);
364		$add1              = Filter::get('add1', WT_REGEX_XREF);
365		$remove            = Filter::get('remove', WT_REGEX_XREF);
366		$others            = Filter::get('others');
367		$clip_ctrl->level1 = Filter::getInteger('level1');
368		$clip_ctrl->level2 = Filter::getInteger('level2');
369		$clip_ctrl->level3 = Filter::getInteger('level3');
370		if ($add) {
371			$record = GedcomRecord::getInstance($add, $WT_TREE);
372			if ($record) {
373				$clip_ctrl->id   = $record->getXref();
374				$clip_ctrl->type = $record::RECORD_TYPE;
375				$clip_ctrl->addClipping($record);
376			}
377		} elseif ($add1) {
378			$record = Individual::getInstance($add1, $WT_TREE);
379			if ($record) {
380				$clip_ctrl->id = $record->getXref();
381				$clip_ctrl->type = $record::RECORD_TYPE;
382				if ($others == 'parents') {
383					foreach ($record->getChildFamilies() as $family) {
384						$clip_ctrl->addClipping($family);
385						$clip_ctrl->addFamilyMembers($family);
386					}
387				} elseif ($others == 'ancestors') {
388					$clip_ctrl->addAncestorsToCart($record, $clip_ctrl->level1);
389				} elseif ($others == 'ancestorsfamilies') {
390					$clip_ctrl->addAncestorsToCartFamilies($record, $clip_ctrl->level2);
391				} elseif ($others == 'members') {
392					foreach ($record->getSpouseFamilies() as $family) {
393						$clip_ctrl->addClipping($family);
394						$clip_ctrl->addFamilyMembers($family);
395					}
396				} elseif ($others == 'descendants') {
397					foreach ($record->getSpouseFamilies() as $family) {
398						$clip_ctrl->addClipping($family);
399						$clip_ctrl->addFamilyDescendancy($family, $clip_ctrl->level3);
400					}
401				}
402			}
403		} elseif ($remove) {
404			unset ($WT_SESSION->cart[$WT_TREE->getTreeId()][$remove]);
405		} elseif (isset($_REQUEST['empty'])) {
406			$WT_SESSION->cart[$WT_TREE->getTreeId()] = array();
407		} elseif (isset($_REQUEST['download'])) {
408			return $this->downloadForm($clip_ctrl);
409		}
410		return $this->getCartList();
411	}
412
413	/**
414	 * A list for the side bar.
415	 *
416	 * @return string
417	 */
418	public function getCartList() {
419		global $WT_SESSION, $WT_TREE;
420
421		// Keep track of the INDI from the parent page, otherwise it will
422		// get lost after ajax updates
423		$pid = Filter::get('pid', WT_REGEX_XREF);
424
425		if (!$WT_SESSION->cart[$WT_TREE->getTreeId()]) {
426			$out = I18N::translate('Your clippings cart is empty.');
427		} else {
428			$out = '<ul>';
429			foreach (array_keys($WT_SESSION->cart[$WT_TREE->getTreeId()]) as $xref) {
430				$record = GedcomRecord::getInstance($xref, $WT_TREE);
431				if ($record instanceof Individual || $record instanceof Family) {
432					switch ($record::RECORD_TYPE) {
433					case 'INDI':
434						$icon = 'icon-indis';
435						break;
436					case 'FAM':
437						$icon = 'icon-sfamily';
438						break;
439					}
440					$out .= '<li>';
441					if (!empty($icon)) {
442						$out .= '<i class="' . $icon . '"></i>';
443					}
444					$out .= '<a href="' . $record->getHtmlUrl() . '">';
445					if ($record instanceof Individual) {
446						$out .= $record->getSexImage();
447					}
448					$out .= ' ' . $record->getFullName() . ' ';
449					if ($record instanceof Individual && $record->canShow()) {
450						$out .= ' (' . $record->getLifeSpan() . ')';
451					}
452					$out .= '</a>';
453					$out .= '<a class="icon-remove remove_cart" href="module.php?mod=' . $this->getName() . '&amp;mod_action=ajax&amp;sb_action=clippings&amp;remove=' . $xref . '&amp;pid=' . $pid . '" title="' . I18N::translate('Remove') . '"></a>';
454					$out .= '</li>';
455				}
456			}
457			$out .= '</ul>';
458		}
459
460		if ($WT_SESSION->cart[$WT_TREE->getTreeId()]) {
461			$out .=
462				'<br><a href="module.php?mod=' . $this->getName() . '&amp;mod_action=ajax&amp;sb_action=clippings&amp;empty=true&amp;pid=' . $pid . '" class="remove_cart">' .
463				I18N::translate('Empty the clippings cart') .
464				'</a>' .
465				'<br>' .
466				'<a href="module.php?mod=' . $this->getName() . '&amp;mod_action=ajax&amp;sb_action=clippings&amp;download=true&amp;pid=' . $pid . '" class="add_cart">' .
467				I18N::translate('Download') .
468				'</a>';
469		}
470		$record = Individual::getInstance($pid, $WT_TREE);
471		if ($record && !array_key_exists($record->getXref(), $WT_SESSION->cart[$WT_TREE->getTreeId()])) {
472			$out .= '<br><a href="module.php?mod=' . $this->getName() . '&amp;mod_action=ajax&amp;sb_action=clippings&amp;add=' . $pid . '&amp;pid=' . $pid . '" class="add_cart"><i class="icon-clippings"></i> ' . I18N::translate('Add %s to the clippings cart', $record->getFullName()) . '</a>';
473		}
474		return $out;
475	}
476
477	/**
478	 * @param Individual $person
479	 *
480	 * @return string
481	 */
482	public function askAddOptions(Individual $person) {
483		$MAX_PEDIGREE_GENERATIONS = $person->getTree()->getPreference('MAX_PEDIGREE_GENERATIONS');
484
485		$out = '<h3><a href="' . $person->getHtmlUrl() . '">' . $person->getFullName() . '</a></h3>';
486		$out .= '<script>';
487		$out .= 'function radAncestors(elementid) {var radFamilies=document.getElementById(elementid);radFamilies.checked=true;}
488			function continueAjax(frm) {
489				var others = jQuery("input[name=\'others\']:checked").val();
490				var link = "module.php?mod='.$this->getName() . '&mod_action=ajax&sb_action=clippings&add1="+frm.pid.value+"&others="+others+"&level1="+frm.level1.value+"&level2="+frm.level2.value+"&level3="+frm.level3.value;
491				jQuery("#sb_clippings_content").load(link);
492			}';
493		$out .= '</script>';
494		if ($person instanceof Family) {
495			$out .= '<form action="module.php" method="get" onsubmit="continueAjax(this); return false;">
496			<input type="hidden" name="mod" value="clippings">
497			<input type="hidden" name="mod_action" value="index">
498			<table>
499			<tr><td class="topbottombar">' . I18N::translate('Which other links from this family would you like to add?') . '
500			<input type="hidden" name="pid" value="'.$person->getXref() . '">
501			<input type="hidden" name="type" value="'.$person::RECORD_TYPE . '">
502			<input type="hidden" name="action" value="add1"></td></tr>
503			<tr><td class="optionbox"><input type="radio" name="others" checked value="none">'. I18N::translate('Add just this family record.') . '</td></tr>
504			<tr><td class="optionbox"><input type="radio" name="others" value="parents">'. I18N::translate('Add parents’ records together with this family record.') . '</td></tr>
505			<tr><td class="optionbox"><input type="radio" name="others" value="members">'. I18N::translate('Add parents’ and children’s records together with this family record.') . '</td></tr>
506			<tr><td class="optionbox"><input type="radio" name="others" value="descendants">'. I18N::translate('Add parents’ and all descendants’ records together with this family record.') . '</td></tr>
507			<tr><td class="topbottombar"><input type="submit" value="'. I18N::translate('Continue adding') . '"></td></tr>
508			</table>
509			</form>';
510		} elseif ($person instanceof Individual) {
511			$out .= '<form action="module.php" method="get" onsubmit="continueAjax(this); return false;">
512			<input type="hidden" name="mod" value="clippings">
513			<input type="hidden" name="mod_action" value="index">
514		' . I18N::translate('Which links from this individual would you also like to add?') . '
515		<input type="hidden" name="pid" value="'.$person->getXref() . '">
516		<input type="hidden" name="type" value="'.$person::RECORD_TYPE . '">
517		<input type="hidden" name="action" value="add1">
518		<ul>
519		<li><input type="radio" name="others" checked value="none">'. I18N::translate('Add just this individual.') . '</li>
520		<li><input type="radio" name="others" value="parents">'. I18N::translate('Add this individual, his parents, and siblings.') . '</li>
521		<li><input type="radio" name="others" value="ancestors" id="ancestors">'. I18N::translate('Add this individual and his direct line ancestors.') . '<br>
522				'. I18N::translate('Number of generations') . '<input type="text" size="4" name="level1" value="' . $MAX_PEDIGREE_GENERATIONS . '" onfocus="radAncestors(\'ancestors\');"></li>
523		<li><input type="radio" name="others" value="ancestorsfamilies" id="ancestorsfamilies">'. I18N::translate('Add this individual, his direct line ancestors, and their families.') . '<br>
524				'. I18N::translate('Number of generations') . ' <input type="text" size="4" name="level2" value="' . $MAX_PEDIGREE_GENERATIONS . '" onfocus="radAncestors(\'ancestorsfamilies\');"></li>
525		<li><input type="radio" name="others" value="members">'. I18N::translate('Add this individual, his spouse, and children.') . '</li>
526		<li><input type="radio" name="others" value="descendants" id="descendants">'. I18N::translate('Add this individual, his spouse, and all descendants.') . '<br >
527				'. I18N::translate('Number of generations') . ' <input type="text" size="4" name="level3" value="' . $MAX_PEDIGREE_GENERATIONS . '" onfocus="radAncestors(\'descendants\');"></li>
528		</ul>
529		<input type="submit" value="'. I18N::translate('Continue adding') . '">
530		</form>';
531		} else if ($person instanceof Source) {
532			$out .= '<form action="module.php" method="get" onsubmit="continueAjax(this); return false;">
533		<input type="hidden" name="mod" value="clippings">
534		<input type="hidden" name="mod_action" value="index">
535		<table>
536		<tr><td class="topbottombar">' . I18N::translate('Which records linked to this source should be added?') . '
537		<input type="hidden" name="pid" value="'.$person->getXref() . '">
538		<input type="hidden" name="type" value="'.$person::RECORD_TYPE . '">
539		<input type="hidden" name="action" value="add1"></td></tr>
540		<tr><td class="optionbox"><input type="radio" name="others" checked value="none">'. I18N::translate('Add just this source.') . '</td></tr>
541		<tr><td class="optionbox"><input type="radio" name="others" value="linked">'. I18N::translate('Add this source and families/individuals linked to it.') . '</td></tr>
542		<tr><td class="topbottombar"><input type="submit" value="'. I18N::translate('Continue adding') . '">
543		</table>
544		</form>';
545		} else {
546			return $this->getSidebarContent();
547		}
548		return $out;
549	}
550
551	/**
552	 * @param ClippingsCart $clip_ctrl
553	 *
554	 * @return string
555	 */
556	public function downloadForm(ClippingsCart $clip_ctrl) {
557		global $WT_TREE;
558
559		$pid = Filter::get('pid', WT_REGEX_XREF);
560
561		$out = '<script>';
562		$out .= 'function cancelDownload() {
563				var link = "module.php?mod=' . $this->getName() . '&mod_action=ajax&sb_action=clippings&pid=' . $pid . '";
564				jQuery("#sb_clippings_content").load(link);
565			}';
566		$out .= '</script>';
567		$out .= '<form method="get" action="module.php">
568		<input type="hidden" name="mod" value="clippings">
569		<input type="hidden" name="mod_action" value="index">
570		<input type="hidden" name="pid" value="' .$pid . '">
571		<input type="hidden" name="action" value="download">
572		<table>
573		<tr><td colspan="2" class="topbottombar"><h2>'. I18N::translate('Download') . '</h2></td></tr>
574		<tr><td class="descriptionbox width50 wrap">'. I18N::translate('Zip file(s)') . '</td>
575		<td class="optionbox"><input type="checkbox" name="Zip" value="yes" checked></td></tr>
576
577		<tr><td class="descriptionbox width50 wrap">'. I18N::translate('Include media (automatically zips files)') . help_link('include_media') . '</td>
578		<td class="optionbox"><input type="checkbox" name="IncludeMedia" value="yes" checked></td></tr>
579		';
580
581		if (Auth::isManager($WT_TREE)) {
582			$out .=
583				'<tr><td class="descriptionbox width50 wrap">' . I18N::translate('Apply privacy settings') . help_link('apply_privacy') . '</td>' .
584				'<td class="optionbox">' .
585				'	<input type="radio" name="privatize_export" value="none" checked> ' . I18N::translate('None') . '<br>' .
586				'	<input type="radio" name="privatize_export" value="gedadmin"> ' . I18N::translate('Manager') . '<br>' .
587				'	<input type="radio" name="privatize_export" value="user"> ' . I18N::translate('Member') . '<br>' .
588				'	<input type="radio" name="privatize_export" value="visitor"> ' . I18N::translate('Visitor') .
589				'</td></tr>';
590		} elseif (Auth::isMember($WT_TREE)) {
591			$out .=
592				'<tr><td class="descriptionbox width50 wrap">' . I18N::translate('Apply privacy settings') . help_link('apply_privacy') . '</td>' .
593				'<td class="list_value">' .
594				'	<input type="radio" name="privatize_export" value="user" checked> ' . I18N::translate('Member') . '<br>' .
595				'	<input type="radio" name="privatize_export" value="visitor"> ' . I18N::translate('Visitor') .
596				'</td></tr>';
597		}
598
599		$out .= '
600		<tr><td class="descriptionbox width50 wrap">'. I18N::translate('Convert from UTF-8 to ISO-8859-1') . help_link('utf8_ansi') . '</td>
601		<td class="optionbox"><input type="checkbox" name="convert" value="yes"></td></tr>
602
603		<tr>
604		<td class="descriptionbox width50 wrap">'. I18N::translate('Add the GEDCOM media path to filenames') . help_link('GEDCOM_MEDIA_PATH') . '</td>
605		<td class="optionbox">
606		<input type="checkbox" name="conv_path" value="' . Filter::escapeHtml($WT_TREE->getPreference('GEDCOM_MEDIA_PATH')) . '">
607		<span dir="auto">' . Filter::escapeHtml($WT_TREE->getPreference('GEDCOM_MEDIA_PATH')) . '</span></td>
608		</tr>
609
610		<input type="hidden" name="conv_path" value="'.$clip_ctrl->conv_path . '">
611
612		</td></tr>
613
614		<tr><td class="topbottombar" colspan="2">
615		<input type="button" value="'. I18N::translate('Cancel') . '" onclick="cancelDownload();">
616		<input type="submit" value="'. I18N::translate('Download') . '">
617		</form>';
618
619		return $out;
620	}
621
622}
623