This repository was archived by the owner on Jan 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexportbranch.php
More file actions
100 lines (75 loc) · 2.32 KB
/
Copy pathexportbranch.php
File metadata and controls
100 lines (75 loc) · 2.32 KB
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
<?php
namespace BlasiusSecundus\WebtreesModules\BranchExport;
use Fisharebest\Webtrees\Database;
use Fisharebest\Webtrees\Filter;
use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\Session;
require_once 'branchgenerator.php';
require_once 'branchexportutils.php';
/**
* Defined in session.php
*
* @global Tree $WT_TREE
*/
global $WT_TREE;
define('WT_SCRIPT_NAME', 'modules_v3/branch_export/exportbranch.php');
require '../../includes/session.php';
header('Content-Type: text/html; charset=UTF-8');
if(!Auth::isMember($WT_TREE))
{
http_response_code(403);
return;
}
if(!Filter::checkCsrf()){
http_response_code(406);
return;
}
$cart = [];
$preset = Filter::postInteger("preset");
$use_preset = Filter::postBool("use_preset");
if($preset && $use_preset){
$preset_data = Database::prepare("SELECT * FROM ##branch_export_presets WHERE preset_id = :preset_id AND tree_id = :tree_id")->execute(["preset_id"=>$preset, "tree_id"=>$WT_TREE->getTreeId()])->fetchOneRow(\PDO::FETCH_ASSOC);
if(!$preset_data){
die("Preset does not exists or does not belongs to the current tree.");
}
$pivot = Filter::escapeHtml($preset_data["pivot"]);
$cutoff = $preset_data["cutoff"];
}
else {
$pivot = Filter::escapeHtml(Filter::post("pivot"));
$cutoff = Filter::post("cutoff");
}
//validating pivot
if(!BranchExportUtils::validatePivot($pivot)){
die("Bad pivot XREF: $pivot");
}
$pivot_indi = Individual::getInstance($pivot, $WT_TREE);
if(!$pivot_indi)
{
die("Cannot load pivot indi: $pivot");
}
//validating cutoff points
if(is_string($cutoff))
{
$cutoff = explode(",",$cutoff);
}
if($cutoff){
if(!BranchExportUtils::validateCutoffArray($cutoff)){
die("Bad cutoff XREF(s).");
}
}
else
{
$cutoff = NULL;
}
$branchgenerator = new BranchGenerator($pivot, $cutoff);
foreach($branchgenerator->generateBranch() as $item)
{
$cart[$item] = true;
}
Session::put("cart", [$WT_TREE->getTreeId() => $cart]);
Session::put("branch_export_pivot", $pivot);
Session::put("branch_export_cutoff", $cutoff);
Session::put("branch_export_preset", $preset);
header('Location:'.WT_BASE_URL.'module.php?mod=clippings&mod_action=index');