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 pathmodule.php
More file actions
1315 lines (1097 loc) · 51.5 KB
/
Copy pathmodule.php
File metadata and controls
1315 lines (1097 loc) · 51.5 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
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
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Branch Export Webtrees Module
*/
namespace BlasiusSecundus\WebtreesModules\BranchExport;
use Composer\Autoload\ClassLoader;
use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\Filter;
use Fisharebest\Webtrees\Module\AbstractModule;
use Fisharebest\Webtrees\Module\ModuleMenuInterface;
use Fisharebest\Webtrees\Module\ModuleTabInterface;
use Fisharebest\Webtrees\Module\ModuleConfigInterface;
use Fisharebest\Webtrees\Menu;
use Fisharebest\Webtrees\Controller\PageController;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Functions\FunctionsPrint;
use Fisharebest\Webtrees\Session;
use Fisharebest\Webtrees\Database;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\Family;
use Fisharebest\Webtrees\Media;
use Fisharebest\Webtrees\Note;
use Fisharebest\Webtrees\Repository;
use Fisharebest\Webtrees\Source;
use Fisharebest\Webtrees\GedcomRecord;
use Fisharebest\Webtrees\Tree;
require_once 'branchgenerator.php';
require_once 'branchexportutils.php';
define("BRANCH_EXPORT_MODULE_VERSION","1.2.0 DEV - xx.xx.2018");
define("BRANCH_EXPORT_MODULE_DB_VERSION",1);
/*
reset to v0 from v1 (for testing purposes):
ALTER TABLE `wt_branch_export_presets` CHANGE `tree_id` `l_file` INT(11) NOT NULL;
ALTER TABLE `wt_branch_export_presets` DROP `preset_id`;
ALTER TABLE wt_branch_export_presets DROP INDEX name;
DELETE FROM `wt_module_setting` WHERE `module_name` = 'branch_export' AND `setting_name` = 'current_db_version';
ALTER TABLE `wt_branch_export_presets` ADD PRIMARY KEY(`name`);
*/
/*
CREATE TABLE IF NOT EXISTS `wt_branch_export_presets` (
`preset_id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`name` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`tree_id` int(11) NOT NULL,
`pivot` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`cutoff` varchar(300) COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
*
*/
//ALTER TABLE `wt_branch_export_presets` CHANGE `l_file` `tree_id` INT(11) NOT NULL;
//ALTER TABLE `wt_branch_export_presets` DROP PRIMARY KEY
//ALTER TABLE `wt_branch_export_presets` ADD `preset_id` INT NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (`preset_id`) ;
//ALTER TABLE `wt_branch_export_presets` ADD UNIQUE( `name`, `tree_id`);
class BranchExportModule extends AbstractModule implements ModuleMenuInterface, ModuleTabInterface, ModuleConfigInterface
{
/**
*
* @var string The XREF of the pivot individual.
*/
var $PivotIndiXref = null;
/**
*
* @var Individual The pivot individual (where the branch starts).
*/
var $PivotIndi = null;
/**
*
* @var string[] XREFs of records that serve as cutoff points.
*/
var $CutoffXrefs = array();
/**
*
* @var string The ID of the currently selected preset, or "NULL" if no preset is selected.
*/
var $SelectedPreset = null;
/**
*
* @var stdClass The selected preset object (or NULL).
*/
var $SelectedPresetObj = null;
/**
*
* @var stdClass[] The list of presets.
*/
var $Presets = array();
/**
*
* @var BranchGenerator The branch generator.
*/
var $BranchGenerator = NULL;
/**
*
* @var string
*/
var $TableNameWithoutPrefix = "branch_export_presets";
/**
*
* @var boolean
*/
var $ModuleDBUpdateNecessary = false;
/**
*
* @var boolean
*/
var $ModuleDBCreationNecessary = false;
/**
*
* @var integer
*/
var $ModuleDBCurrentVersion = 0;
/**
*
* @var array
*/
var $ModuleDBInit = ["CREATE TABLE IF NOT EXISTS `##branch_export_presets` (
`preset_id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`name` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`tree_id` int(11) NOT NULL,
`pivot` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`cutoff` varchar(300) COLLATE utf8_unicode_ci NOT NULL,
UNIQUE KEY `name` (`name`,`tree_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"];
/**
*
* @var array
*/
var $ModuleDBMigration = [
//migration from version 0 to 1
0 => [
"ALTER TABLE `##branch_export_presets` CHANGE `l_file` `tree_id` INT(11) NOT NULL",
"ALTER TABLE `##branch_export_presets` DROP PRIMARY KEY",
"ALTER TABLE `##branch_export_presets` ADD `preset_id` INT NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (`preset_id`)",
"ALTER TABLE `##branch_export_presets` ADD UNIQUE( `name`, `tree_id`)"
]
];
/**
* Sets the latest DB version as the current DB version.
*/
protected function updateDBVersionSetting()
{
if($this->getCurrentDBVersion() == BRANCH_EXPORT_MODULE_DB_VERSION)
{
return;
}
$data = ["module_name"=>"branch_export","setting_name"=>"current_db_version","value"=>BRANCH_EXPORT_MODULE_DB_VERSION];
$update_succeeded = Database::prepare("UPDATE ##module_setting SET setting_value = :value WHERE module_name = :module_name AND setting_name =:setting_name")->execute($data)->rowCount() > 0;
if(!$update_succeeded)
{
Database::prepare("INSERT INTO ##module_setting SET module_name = :module_name , setting_name =:setting_name , setting_value = :value")->execute($data);
}
}
protected function getCurrentDBVersion()
{
$data = ["module_name"=>"branch_export","setting_name"=>"current_db_version"];
$db_version_row = Database::prepare("SELECT * FROM ##module_setting WHERE module_name = :module_name AND setting_name = :setting_name")->execute($data)->fetchAll();
if(!$db_version_row)
{
return 0;
}
return intval($db_version_row[0]->setting_value);
}
protected function execDBMigration($version)
{
if(isset($this->ModuleDBMigration[$version]))
{
foreach($this->ModuleDBMigration[$version] as $insctruction)
{
Database::prepare($insctruction)->execute();
}
}
}
/**
*
* Initializes the database table where presets are stored.
*/
protected function createDB()
{
foreach($this->ModuleDBInit as $instruction){
Database::prepare($instruction)->execute();
}
$this->updateDBVersionSetting();
}
/**
* Updates the DB table structure to the latest version.
*/
protected function updateDB()
{
$current_version = $this->getCurrentDBVersion();
for($i = $current_version; $i < BRANCH_EXPORT_MODULE_DB_VERSION; $i++)
{
$this->execDBMigration($i);
}
$this->updateDBVersionSetting();
}
protected function uninstall()
{
$has_permission_to_uninstall = Filter::postBool("branch_export_uninstall_db") && Auth::isAdmin();
if(!$has_permission_to_uninstall) {
http_response_code(403);
exit();
}
if(!Filter::checkCsrf()){
http_response_code(406);
exit();
}
Database::prepare("DROP TABLE IF EXISTS ##branch_export_presets")->execute();
Database::prepare("DELETE FROM ##module_setting WHERE module_name = 'branch_export'")->execute();
Database::prepare("UPDATE ##module SET status = 'disabled' WHERE module_name = 'branch_export'")->execute();
}
/**
* Initializes the DB backend for the module. Performs necessary migration operations too.
*/
protected function initDB()
{
$table_exists = Database::prepare("SHOW TABLES LIKE '##$this->TableNameWithoutPrefix'")->execute()->fetchAll();
$asked_to_create = Filter::postBool("branch_export_create_db");
$asked_to_update = Filter::postBool("branch_export_update_db");
if($asked_to_create || $asked_to_update){
if(!Filter::checkCsrf()){
http_response_code(406);
exit();
}
}
if(!$table_exists)//create data table
{
$has_permission_to_create = $asked_to_create && Auth::isAdmin();
if($has_permission_to_create){
$this->createDB();
}
else{
$this->ModuleDBCreationNecessary = true;
return;
}
}
else//update DB table, if necessary
{
$current_version = $this->getCurrentDBVersion();
$has_permission_to_update = $asked_to_update && Auth::isAdmin();
$needs_db_update = $current_version < BRANCH_EXPORT_MODULE_DB_VERSION;
if(!$has_permission_to_update && $needs_db_update)//we do not have permission from the user to migrate the DB - we indicate the need and will display a warningfor the user
{
$this->ModuleDBUpdateNecessary = true;
return;
}
//otherwise we proceed with the update
else if($needs_db_update){
$this->updateDB();
}
}
}
/**
* Used to sort indies and families for branch preview.
* @param GedcomRecord[] $records Gedcom records to sort.
*/
protected static function SortRecords(&$records)
{
uasort($records,'\Fisharebest\Webtrees\GedcomRecord::compare');
}
/**
* Clears stored branch export options if needed.
*/
protected function clearSelectionsIfNeeded()
{
if(Filter::getBool("clear_selections")){
Session::put("branch_export_preset",null);
Session::put("branch_export_pivot",null);
Session::put("branch_export_cutoff",null);
}
}
/**
* Gets the presets where the specified individual is the pivot point.
* @param string $indi_xref
* @return stdClass[]
*/
protected function getPresetsFor($indi_xref)
{
$presets = [];
foreach($this->Presets as $preset)
{
if($preset->pivot !== $indi_xref ){continue;}
$presets[] = $preset;
}
return $presets;
}
/**
* Gets the preset with the specified name.
* @param integer $id Gets the preset with this id.
* @return stdClass The preset, or null, if no preset found.
*/
protected function getPreset($id)
{
if(!$this->Presets)
{
$this->loadPresets();
}
foreach($this->Presets as $preset)
{
if($preset->preset_id === $id)
{
return $preset;
}
}
return null;
}
/**
* Loads the currently seleted preset.
*/
protected function loadSelectedPreset()
{
$this->SelectedPreset = Filter::getInteger("preset");
if($this->SelectedPreset)
{
Session::put("branch_export_preset", $this->SelectedPreset);
}
else
{
$this->SelectedPreset = Session::get("branch_export_preset");
}
$this->SelectedPresetObj = $this->getPreset($this->SelectedPreset);
}
/**
* Loads the selected pivot individual, if there is any.
*/
protected function loadSelectedPivot()
{
global $WT_TREE;
$this->PivotIndiXref = Filter::escapeHtml(Filter::get("pivot"));
if($this->PivotIndiXref && BranchExportUtils::validatePivot($this->PivotIndiXref))
{
Session::put("branch_export_pivot", $this->PivotIndiXref);
}
else if($this->PivotIndiXref === NULL)
{
$this->PivotIndiXref = Session::get("branch_export_pivot");
}
else if($this->PivotIndiXref){
$this->PivotIndiXref = NULL;
}
if ($this->PivotIndiXref) {
$this->PivotIndi = Individual::getInstance($this->PivotIndiXref, $WT_TREE);
}
else{
$this->PivotIndi = NULL;
}
}
/**
* Loads the currently selected cutoff points, if any.
*/
protected function loadCutoffPoints()
{
$this->CutoffXrefs = Filter::get("cutoff");
if(!$this->CutoffXrefs)
{
$this->CutoffXrefs = Session::get("branch_export_cutoff");
}
if(!is_array($this->CutoffXrefs) && $this->CutoffXrefs)
{
$this->CutoffXrefs = explode(",",$this->CutoffXrefs);
}
if (!$this->CutoffXrefs) {
$this->CutoffXrefs = array();
}
if(BranchExportUtils::validateCutoffArray($this->CutoffXrefs)){
Session::put("branch_export_cutoff", $this->CutoffXrefs);
}
else{
$this->CutoffXrefs = array();
}
}
/**
*
* Initializes the module.
*/
protected function init()
{
$this->initDB();
if(!$this->ModuleDBUpdateNecessary && !$this->ModuleDBCreationNecessary){
$this->cfgAction_DeletePresets();
$this->cfgAction_CopyPresets();
$this->clearSelectionsIfNeeded();
$this->loadSelectedPreset();
$this->loadSelectedPivot();
$this->loadCutoffPoints();
if($this->PivotIndi)
$this->BranchGenerator = new BranchGenerator($this->PivotIndi, $this->CutoffXrefs);
$this->loadPresets();
}
}
/**
*
* Loads the presets from the database.
*/
protected function loadPresets()
{
global $WT_TREE;
$tree_id = $WT_TREE->getTreeId();
$this->Presets = Database::prepare("SELECT * FROM ##branch_export_presets WHERE tree_id = :tree_id ORDER BY name")->execute(["tree_id"=>$tree_id])->fetchAll();
}
/**
*
* @global Tree $WT_TREE
*/
protected function numRecordOfTypeInTree($type)
{
global $WT_TREE;
$tree_id = $WT_TREE->getTreeId();
$table_name = "";
$id_field= "";
$tree_id_field = "";
$o_type = "";
switch($type)
{
case Individual::RECORD_TYPE:
$table_name="##individuals";
$id_field="i_id";
$tree_id_field="i_file";
break;
case Family::RECORD_TYPE:
$table_name="##families";
$id_field="f_id";
$tree_id_field="f_file";
break;
case Media::RECORD_TYPE:
$table_name="##media";
$id_field="m_id";
$tree_id_field="m_file";
break;
case Note::RECORD_TYPE:
$table_name="##other";
$id_field="o_id";
$tree_id_field="o_file";
$o_type = "NOTE";
break;
case Repository::RECORD_TYPE:
if(WT_SCHEMA_VERSION > 37)//after migration 37, repos are moved to its own table
{
$table_name="##repository";
$id_prefix="repository_id";
$tree_id_field="gedcom_id";
}
else//before that they were stored in the wt_other table
{
$table_name="##other";
$id_field="o_id";
$tree_id_field="o_file";
$o_type = "REPO";
}
break;
case Source::RECORD_TYPE:
$table_name="##sources";
$id_field="s_id";
$tree_id_field="s_file";
break;
}
if(!$table_name)
{
return 0;
}
$query = "SELECT COUNT(DISTINCT $id_field) FROM $table_name WHERE $tree_id_field = :tree_id";
$query_params = ["tree_id"=>$tree_id];
if($table_name === "##other")
{
$query_params["o_type"]=$o_type;
$query.=" AND o_type = :o_type";
}
return intval(Database::prepare($query)->execute($query_params)->fetchOne());
}
/**
* Gets the HTML printout of the module version (to be used in/near the page footer).
* @return string
*/
protected function getModuleVersionHTML()
{
return "<p class='branch-export-version'>".I18N::translate("Branch export module")." - v".BRANCH_EXPORT_MODULE_VERSION."</p>";
}
/**
*
* Performs the copy presets action, if needed.
*/
protected function cfgAction_CopyPresets()
{
if(Filter::post('config_action') !== 'copy_presets' || Filter::get("mod_action") !== "branch_export_config")//no need to copy presets
{
return;
}
if(!Auth::isAdmin())
{
http_response_code(403);
exit();
}
if(!Filter::checkCsrf()){
http_response_code(406);
exit();
}
$copy_to_tree_id = intval(Filter::post('copy_to_tree_id'));
$presets = Filter::post('presets');
if(!$copy_to_tree_id || !$presets)
{
return ;
}
foreach($presets as $preset)
{
$preset_data = Database::prepare("SELECT * FROM ##branch_export_presets WHERE preset_id = :preset_id")->execute(["preset_id"=>intval($preset)])->fetchAll()[0];
//now we need to assure that no preset for the target tree with the same name exists
$conflicting_preset_found = Database::prepare("SELECT * FROM ##branch_export_presets WHERE tree_id = :tree_id AND name = :name")->execute(["tree_id"=>$copy_to_tree_id,"name"=>$preset_data->name])->fetchAll();
//
if($conflicting_preset_found){
Session::put("preset_config_action_error", sprintf(I18N::translate("Preset with the same name (%s) already exists for the target tree."),$preset_data->name));
}
else{
Database::prepare("INSERT INTO ##branch_export_presets SET name = :name, pivot = :pivot, cutoff = :cutoff, tree_id = :tree_id")->execute(["name"=>$preset_data->name, "pivot"=>$preset_data->pivot, "cutoff"=>$preset_data->cutoff,"tree_id"=>$copy_to_tree_id])->rowCount();
}
}
}
/**
* Performs the delete presets action, if needed.
*/
protected function cfgAction_DeletePresets()
{
if(Filter::post('config_action') !== 'delete_presets' || Filter::get("mod_action") !== "branch_export_config"){//no need to delete presets
return;
}
if(!Auth::isAdmin())
{
http_response_code(403);
exit();
}
if(!Filter::checkCsrf()){
http_response_code(406);
exit();
}
$presets_to_delete = Filter::post('presets');
if(!$presets_to_delete)
{
return;
}
foreach($presets_to_delete as $preset)
{
Database::prepare("DELETE FROM ##branch_export_presets WHERE preset_id = :preset")->execute(["preset"=>intval($preset)])->rowCount();
}
}
protected function printDBCreateWarning()
{
?>
<div class="db-update-warning">
<h1><?php echo I18N::translate("Branch export module - database initialization needed")?></h1>
<p>
<?php echo I18N::translate("It is required to initialize the data table where the branch export module stores the branch presets. This initialization is done automatically, but we ask for your permission so you have a chance to back up your data. The update should not harm your data in any way, but it is always a good idea to create a backup first.")?>
</p>
<?php if(Auth::isAdmin()):?>
<p>
<?php echo I18N::translate("As soon as you are ready to perform the initialization, click the link below.")?>
</p>
<form action="<?php echo WT_BASE_URL?>module.php?mod=branch_export" method="post">
<input type="hidden" name="branch_export_create_db" value="1">
<?php echo Filter::getCsrf()?>
<button type="submit"><?php echo I18N::translate("Perform Initialization")?></button>
</form>
<?php else: ?>
<p>
<strong><?php echo I18N::translate("Only administrators can initialize the data table.");?></strong>
</p>
<?php endif;?>
</div>
<?php
}
/**
* Prints a warning that the module DB table must be updated. Also provides the link to perform the update.
*/
protected function printDBUpdateWarning()
{
?>
<div class="db-update-warning">
<h1><?php echo I18N::translate("Branch export module - database update needed")?></h1>
<p>
<?php echo I18N::translate("It is required to update the data table where the branch export module stores the branch presets. This update is done automatically, but we ask for your permission so you have a chance to back up your data. The update should not harm your data in any way, but it always a good idea to create a backup first.")?>
</p>
<?php if(Auth::isAdmin()):?>
<p>
<?php echo I18N::translate("As soon as you are ready to perform the update, click the link below.")?>
</p>
<form action="<?php echo WT_BASE_URL?>module.php?mod=branch_export" method="post">
<input type="hidden" name="branch_export_update_db" value="1">
<?php echo Filter::getCsrf()?>
<button type="submit"><?php echo I18N::translate("Perform Update")?></button>
</form>
<?php else: ?>
<p>
<strong><?php echo I18N::translate("Only administrators can update the database.");?></strong>
</p>
<?php endif;?>
</div>
<?php
}
/**
* Prints the branch export module config page.
*/
protected function printConfigPage()
{
$tree_list = Database::prepare("SELECT * FROM ##gedcom ORDER BY gedcom_name")->execute()->fetchAll();
$preset_list = Database::prepare("SELECT * FROM ##branch_export_presets ORDER BY name")->execute()->fetchAll();
for($i = 0; $i < count($preset_list); $i++)
{
$preset_list[$i]->orphaned = Database::prepare("SELECT COUNT(*) FROM ##gedcom WHERE gedcom_id = :tree_id")->execute(["tree_id"=>$preset_list[$i]->tree_id])->fetchOne() < 1;
}
?>
<h1 class="branch-export-heading"><?php echo I18N::translate("Branch export config")?></h1>
<?php if(!Auth::isAdmin()): ?>
<p class="admin-only-warning"><?php echo I18N::translate("Settings are only available for admins.")?></p>
<?php else:?>
<form id="branchcfg" method="post" name="branchcfg" action="module.php?mod=branch_export&mod_action=branch_export_config">
<input type="hidden" name="config_action" value="">
<?php echo Filter::getCsrf()?>
<table>
<thead>
<tr>
<td class="topbottombar" colspan="3"><h4><?php echo I18N::translate("Manage presets")?></h4></td>
</tr>
</thead>
<tbody>
<tr>
<td class="optionbox">
<h5><?php echo I18N::translate("Tree:")?></h5>
<p>
<select id="tree_id" name="tree_id">
<option value="NULL"><?php echo I18N::translate("All trees")?></option>
<optgroup label="<?php echo I18N::translate("Select specific tree")?>">
<?php foreach($tree_list as $tree):?>
<option value="<?php echo $tree->gedcom_id?>"><?php echo $tree->gedcom_name?></option>
<?php endforeach;?>
</optgroup>
</select>
</p>
</td>
<td class="optionbox">
<h5><?php echo I18N::translate("Select preset(s):")?></h5>
<p>
<select id="presets" name="presets[]" multiple>
<?php foreach($preset_list as $preset):?>
<option value="<?php echo $preset->preset_id?>" <?php echo ($preset->orphaned)?"class=\"preset-orphaned\"":""?>
data-tree="<?php echo $preset->tree_id?>"
data-pivot="<?php echo $preset->pivot?>"
data-cutoff="<?php echo htmlspecialchars($preset->cutoff)?>"><?php echo $preset->name?></option>
<?php endforeach;?>
</select>
</p>
<p>
<input type="button" id="select_orphaned" value="<?php echo I18N::translate("Select orphaned")?>">
</p>
</td>
<td class="optionbox selected-preset-details">
<table>
<caption><h5><?php echo I18N::translate("Preset details")?></h5></caption>
<tbody>
<tr>
<td><?php echo I18N::translate("Tree:")?></td>
<td id="selected_preset_tree"></td>
</tr>
<tr>
<td><?php echo I18N::translate("Name:")?></td><td id="selected_preset_name"></td>
</tr>
<tr>
<td><?php echo I18N::translate("Pivot:")?></td><td id="selected_preset_pivot"></td>
</tr>
<tr>
<td><?php echo I18N::translate("Cutoff:")?></td><td id="selected_preset_cutoff"></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td class="optionbox"></td>
<td class="optionbox" colspan="2">
<p>
<input type="submit" id="delete_presets" value="<?php echo I18N::translate("Delete selected presets")?>">
</p>
<hr>
<input type="submit" id="copy_presets" value="<?php echo I18N::translate("Copy selected presets to:")?>">
<select id="copy_to_tree_id" name="copy_to_tree_id">
<?php foreach($tree_list as $tree):?>
<option value="<?php echo $tree->gedcom_id?>"><?php echo $tree->gedcom_name?></option>
<?php endforeach;?>
</select>
</td>
</tr>
</tbody>
</table>
</form>
<form id="uninstall_branch_export_module" method="post" name="branchuninst" action="module.php?mod=branch_export&mod_action=uninstall">
<input type="hidden" name="branch_export_uninstall_db" value="1">
<?php echo Filter::getCsrf()?>
<input type="submit" id="uninstall" value="<?php echo I18N::translate("uninstall")?>">
</form>
<?php endif;
$config_error = Session::get("preset_config_action_error");
if($config_error)
{
?>
<h3 class="preset-config-error"><?php echo $config_error;?></h3>
<?php
Session::put("preset_config_action_error",null);
}
}
/**
* Loads a branch based on a preset.
*/
protected function loadPresetBranch()
{
global $WT_TREE;
$preset = $this->getPreset($this->SelectedPreset);
if(!$preset)
{
return;
}
$this->PivotIndi = Individual::getInstance($preset->pivot, $WT_TREE);
$this->CutoffXrefs = explode(",",$preset->cutoff);
$this->BranchGenerator = new BranchGenerator($this->PivotIndi, $this->CutoffXrefs);
}
/**
* Prints the cutoff point input elements. There can be as many cutoff point as the user wants.
*
* @param string $value The XREF of the individual to be used as cutoff point.
* @param integer $idx The index of the current cutoff point.
*/
protected function printCutoffpointInput($value,$idx)
{
echo "<tr class=\"branch-cutoff-row\">
<td class=\"optionbox\">";
?>
<label <?php echo "for=\"branch_cutoff_$idx\"";?> class="branch-cutoff-label"><?php echo I18N::translate("Cutoff point %d:",$idx)?></label>
<input type="text" data-autocomplete-type="INDI" name="cutoff[]" <?php echo "id=\"branch_cutoff_$idx\"";?> size="8" value="<?php echo $value;?>">
<?php echo "</td>
<td class=\"optionbox\">";
?>
<?php echo FunctionsPrint::printFindIndividualLink("branch_cutoff_$idx"); ?>
<?php echo FunctionsPrint::printFindFamilyLink("branch_cutoff_$idx"); ?>
<a class="icon-remove" title="<?php echo I18N::translate("Remove cutoff point")?>" href="#" onclick="branchExport_RemoveCutoffPoint(event)"></a>
<?php
echo "</td>
</tr>";
}
/**
* Prints branch export help content.
*/
protected function printHelp(){
$help_data = [
I18N::translate('How branch export works') =>
I18N::translate("Branch export module helps you export a portion of a tree in a way that is not possible using the built-in export features.")."<br><br>".
I18N::translate("Branch export traverses the entire tree, starting from a specific individual (called pivot point). First it will select the immediate relatives of the pivot individual (e. g. parents, children, spouses, siblings). Then continues the traversal recursively with their relatives, processing them like the pivot point - unless they are one of the predefined blocking individuals (called cutoff points). The traversal will stop when all non-blocked individuals are processed.").
"<br><br>".I18N::translate("You can use an unlimited number of cutoff points."),
I18N::translate('What records are included in the branch?') => I18N::translate("The pivot point is always included. Cutoff points are also included if they can be reached during the traversal, but the traversal algorithm will stop traversing the tree when it hits a cutoff point, and thus their relatives - that are not reachable using a different path - will not be included. If an individual is included in the branch, all linked records (families, media objects, sources, notes, repositories) are also added.")."<br><br><strong>".
I18N::translate("Note: Exporting the content of the branch requires that the Clippings cart module is installed and activated.")."</strong>",
I18N::translate('What records can be used as pivot point?') => I18N::translate("Only individuals can be used as pivot point. Any individual in the tree can be used."),
I18N::translate('What records can be used as cutoff points?') => I18N::translate("Only individuals and families can be used as cutoff points. Any individual or family in the tree can be used. Using a family as cutoff point is a shortcut for adding all individuals in that family as cutoff points.")
];
$release_log = [
"1.1.0" => [
I18N::translate("Added Hungarian and German localization"),
I18N::translate("Fixed: 'Unable to delete preset (None)' error message when pressing Delete without selecting a preset."),
I18N::translate("Fixed: when clicking Delete, the confirmation dialog used the value of the 'Name' input field instead the name of the selected Preset."),
I18N::translate("Fixed: when renaming a preset with the new name being identical to the current name, 'duplicate key' error message was displayed."),
I18N::translate("Fixed: after saving/deleting/renaming a preset the preset list was refreshed incorrectly, preventing further rename/delete operations (until page refresh)."),
I18N::translate("Several minor UI fixes and improvements for Branch export main page and config page"),
I18N::translate("User authorization is now properly checked. Only users that are members of the tree can work with the branch export module and the presets belonging to that tree.")
],
"1.0.0" =>[
I18N::translate("First public release"),
I18N::translate("Improved help section, as well as other changes/fixes to certain text elements"),
I18N::translate("Warning message is now displayed if Clippings cart module is disabled")
],
"0.9.3" => [
I18N::translate("Added install/uninstall features"),
I18N::translate("Added release log"),
I18N::translate("Added Save & Rename command"),
I18N::translate("Clicking 'Delete' will now ask for confirmation before deleting the preset"),
I18N::translate("Fixed: 'Name' field contained the id of the preset (instead of the name) after clicking 'Preview'; 'Load preset' also lost its stored value, and was reset to '(None)'.")
]
];
?>
<h1 class="branch-export-heading"><?php echo I18N::translate('Branch export help')?></h1>
<div id="branchexport_help">
<?php foreach($help_data as $title=>$content):?>
<h3><?php echo $title?></h3>
<div><p><?php echo $content?></p></div>
<?php endforeach;?>
<h3><strong><?php echo I18N::translate("Release log")?></strong></h3>
<div>
<ul>
<?php foreach($release_log as $version=>$log_items):?>
<li>
<strong><?php echo $version?></strong>:
<ul>
<?php foreach($log_items as $log_item):?>
<li><?php echo $log_item?></li>
<?php endforeach;?>
</ul>
</li>
<?php endforeach;?>
</ul>
</div>
</div>
<?php
}
/**
* Prints the main branch export UI.
*/
protected function printMainBranchInput()
{
?>
<h1 class="branch-export-heading"><?php echo $this->getTitle();?></h1>
<div>
<form method="post" name="branchexp" action="<?php echo $this->directory?>/exportbranch.php" id="branchexp">
<?php echo Filter::getCsrf();?>
<table>
<thead>
<tr>
<td colspan="2" class="topbottombar" style="text-align:center; ">
<?php echo I18N::translate('Branch export'); ?>
</td>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2" class="optionbox" style="text-align: center">
<?php echo I18N::translate('Branch settings')?>
</td>
</tr>
<tr>
<td colspan="2" class="optionbox">
<?php echo I18N::translate('Load preset:')?>
<select name="preset" id="saved_branch_presets" onchange="branchExport_OnPresetSelected(event)">
<option value="NULL"><?php echo I18N::translate('(None)')?></option>
<?php foreach($this->Presets as $export_settings):?>
<option value="<?php echo $export_settings->preset_id?>" data-pivot="<?php echo $export_settings->pivot?>" data-cutoff="<?php echo $export_settings->cutoff?>" <?php if($this->SelectedPreset == $export_settings->preset_id) echo "selected";?>><?php echo $export_settings->name?></option>
<?php endforeach;?>
</select>
</td>
</tr>
<tr>
<td class="optionbox">
<label for="branch_pivot" style="display: inline-block; min-width: 80px;" ><?php echo I18N::translate('Pivot point:')?></label>
<input type="text" data-autocomplete-type="INDI" name="pivot" id="branch_pivot" size="8" required value="<?php echo $this->PivotIndi !== null ? $this->PivotIndi->getXref(): $this->PivotIndiXref?>">
</td>
<td class="optionbox">
<?php echo FunctionsPrint::printFindIndividualLink('branch_pivot'); ?>