Skip to content

Commit

Permalink
HuMo-genealogy 6.7.9a
Browse files Browse the repository at this point in the history
  • Loading branch information
HuubMons committed Nov 12, 2024
1 parent 75961ff commit 8d84062
Show file tree
Hide file tree
Showing 23 changed files with 1,381 additions and 1,399 deletions.
55 changes: 48 additions & 7 deletions admin/controller/treesController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
require_once __DIR__ . "/../models/trees.php";
include_once(__DIR__ . "/../include/select_tree.php");

class TreesController
{
Expand All @@ -15,21 +16,61 @@ public function __construct()
public function detail($dbh, $tree_id, $db_functions, $selected_language)
{
$treesModel = new TreesModel($dbh);

$treesModel->set_tree_id($tree_id); // $tree_id from index.php.
$treesModel->set_tree_id($tree_id);
$treesModel->update_tree($dbh, $db_functions);
$trees['tree_id'] = $treesModel->get_tree_id();

$trees['language'] = $treesModel->get_language($selected_language);
// *** Select language for texts at page ***
$trees['language2'] = $treesModel->get_language2($trees['language'], $selected_language);
$trees['menu_tab'] = $treesModel->get_menu_tab();

// *** Menu tab: tree_merge ***
if ($trees['menu_tab'] == 'tree_merge') {
require_once __DIR__ . "/../models/tree_merge.php";
// *** Use a seperate model for each menu tab ***
if ($trees['menu_tab'] == 'tree_main') {
include_once(__DIR__ . "/../../include/show_tree_date.php");
include_once(__DIR__ . "/../../views/partial/select_language.php");

include(__DIR__ . '/../../languages/' . $trees['language2'] . '/language_data.php');

//require_once __DIR__ . "/../models/tree_admin.php";
$trees['language_path'] = 'index.php?page=tree&amp;tree_id=' . $trees['tree_id'] . '&amp;';
} elseif ($trees['menu_tab'] == 'tree_gedcom') {
include_once(__DIR__ . "/../include/gedcom_asciihtml.php");
include_once(__DIR__ . "/../include/gedcom_anselhtml.php");
include_once(__DIR__ . "/../include/gedcom_ansihtml.php");

// *** Support for GEDCOM files for MAC computers ***
// *** Still needed in april 2023. Will be deprecated in PHP 9.0!***
// *** TODO improve processing of line_endings ***
@ini_set('auto_detect_line_endings', TRUE);

// Because of processing very large GEDCOM files.
@set_time_limit(4000);

require_once __DIR__ . "/../models/gedcom.php";
$gedcomModel = new GedcomModel($dbh);
$trees['step'] = $gedcomModel->get_step();

if ($trees['step'] == '1') {
$upload_status = $gedcomModel->upload_gedcom();
$trees = array_merge($trees, $upload_status);

$trees['gedcom_directory'] = $gedcomModel->get_gedcom_directory();
}
} elseif ($trees['menu_tab'] == 'tree_data') {
//require_once __DIR__ . "/../models/tree_data.php";
} elseif ($trees['menu_tab'] == 'tree_text') {
require_once __DIR__ . "/../models/tree_text.php";
$tree_textModel = new TreeTextModel($dbh);

// *** Select language for texts at page ***
include(__DIR__ . '/../../languages/' . $trees['language2'] . '/language_data.php');

$tree_texts = $tree_textModel->get_tree_texts($dbh, $trees['tree_id'], $trees['language']);
$trees = array_merge($trees, $tree_texts);
} elseif ($trees['menu_tab'] == 'tree_merge') {
require_once __DIR__ . "/../models/tree_merge.php";
$treeMergeModel = new TreeMergeModel($dbh);
$trees['relatives_merge'] = $treeMergeModel->get_relatives_merge($dbh, $trees['tree_id']);

$treeMergeModel->update_settings($db_functions); // *** Store and reset tree merge settings ***
}

Expand Down
8 changes: 3 additions & 5 deletions admin/include/select_tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ function select_tree($dbh, $page, $tree_id, $menu_tab = '')
$edit_tree_array = explode(";", $group_edit_trees);
// *** Administrator can always edit in all family trees ***
if ($group_administrator == 'j' || in_array($tree_searchDb->tree_id, $edit_tree_array)) {
$selected = '';
if (isset($tree_id) && $tree_searchDb->tree_id == $tree_id) {
$selected = ' selected';
}
$treetext = show_tree_text($tree_searchDb->tree_id, $selected_language);
?>
<option value="<?= $tree_searchDb->tree_id; ?>" <?= $selected; ?>><?= $treetext['name']; ?></option>
<option value="<?= $tree_searchDb->tree_id; ?>" <?= isset($tree_id) && $tree_searchDb->tree_id == $tree_id ? 'selected' : ''; ?>>
<?= $treetext['name']; ?>
</option>
<?php
}
}
Expand Down
9 changes: 9 additions & 0 deletions admin/include/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@
$update_cls->update_v6_7_9($dbh);
}

// ***************************************
// *** Update procedure version 6.7.9a ***
// ***************************************
if ($humo_option["update_status"] > '18') {
echo '<tr><td>HuMo-genealogy update V6.7.9a</td><td style="background-color:#00FF00">OK</td></tr>';
} else {
$update_cls->update_v6_7_9a($dbh);
}

/* END OF MAIN UPDATE SCRIPT
*** VERY IMPORTANT REMARKS FOR PROGRAMMERS ***
* 1) Change update_status in install.php
Expand Down
115 changes: 96 additions & 19 deletions admin/include/update_cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -3840,6 +3840,7 @@ public function update_v6_4_1(): void
OR event_kind='death_declaration' OR event_kind='burial_witness'
OR event_kind='marriage_witness' OR event_kind='marriage_witness_rel')
";
// Bug: forgot to change event_connect_kind2 into person. Solved in later update.
$qry = $dbh->query($sql);
while ($qryDb = $qry->fetch(PDO::FETCH_OBJ)) {
$gebeurtsql = "UPDATE humo_events SET
Expand Down Expand Up @@ -4016,7 +4017,7 @@ public function update_v6_7_9($dbh): void
<td style="background-color:#00FF00"><?= __('Update in progress...'); ?><div id="information v6_7_9" style="display: inline; font-weight:bold;"></div>
</td>
</tr>
<?php
<?php
//ob_flush();
flush();

Expand Down Expand Up @@ -4077,23 +4078,23 @@ public function update_v6_7_9($dbh): void
while ($qryDb = $qry->fetch(PDO::FETCH_OBJ)) {
if ($qryDb->event_date || $qryDb->event_place || $qryDb->event_text) {
$sql_put = "INSERT INTO humo_events SET
event_tree_id='" . $qryDb->event_tree_id . "',
event_gedcomnr='',
event_order='" . $qryDb->event_order . "',
event_connect_kind='person',
event_connect_id='" . $qryDb->event_connect_id . "',
event_kind='" . $qryDb->event_connect_kind . "',
event_event='',
event_event_extra='" . safe_text_db($qryDb->event_event_extra) . "',
event_gedcom='EVEN',
event_date='" . $qryDb->event_date . "',
event_place='" . safe_text_db($qryDb->event_place) . "',
event_text='" . safe_text_db($qryDb->event_text) . "',
event_quality='" . $qryDb->event_quality . "',
event_new_user_id='" . $qryDb->event_new_user_id . "',
event_new_datetime='" . $qryDb->event_new_datetime . "',
event_changed_user_id='" . $qryDb->event_changed_user_id . "',
event_changed_datetime='" . $qryDb->event_changed_datetime . "'";
event_tree_id='" . $qryDb->event_tree_id . "',
event_gedcomnr='',
event_order='" . $qryDb->event_order . "',
event_connect_kind='person',
event_connect_id='" . $qryDb->event_connect_id . "',
event_kind='" . $qryDb->event_connect_kind . "',
event_event='',
event_event_extra='" . safe_text_db($qryDb->event_event_extra) . "',
event_gedcom='EVEN',
event_date='" . $qryDb->event_date . "',
event_place='" . safe_text_db($qryDb->event_place) . "',
event_text='" . safe_text_db($qryDb->event_text) . "',
event_quality='" . $qryDb->event_quality . "',
event_new_user_id='" . $qryDb->event_new_user_id . "',
event_new_datetime='" . $qryDb->event_new_datetime . "',
event_changed_user_id='" . $qryDb->event_changed_user_id . "',
event_changed_datetime='" . $qryDb->event_changed_datetime . "'";

$dbh->query($sql_put);
$last_insert = $dbh->lastInsertId();
Expand Down Expand Up @@ -4134,6 +4135,82 @@ public function update_v6_7_9($dbh): void
flush();
}

public function update_v6_7_9a($dbh): void
{
// ***************************************
// *** Update procedure version 6.7.9a ***
// ***************************************

// *** Show update status ***
//ob_start();
?>
<tr>
<td>HuMo-genealogy update V6.7.9a</td>
<td style="background-color:#00FF00"><?= __('Update in progress...'); ?><div id="information v6_7_9a" style="display: inline; font-weight:bold;"></div>
</td>
</tr>
<?php
//ob_flush();
flush();

// *** In some cases event_connect_kind is empty, because of bug in previous update ***
$dbh->query("UPDATE humo_events SET event_kind='ASSO', event_connect_kind='birth_declaration', event_gedcom='WITN' WHERE event_kind='birth_declaration' AND event_connect_id2 LIKE 'I%'");
$dbh->query("UPDATE humo_events SET event_kind='ASSO', event_connect_kind='death_declaration', event_gedcom='WITN' WHERE event_kind='death_declaration' AND event_connect_id2 LIKE 'I%'");

// *** Because of bug: rerun this query, also check for empty event_connect_kind2 ***
// *** Add seperate general birth_declaration and death_declaration events ***
// *** Only convert declaration events where witness is connected ***
$qry = $dbh->query("SELECT * from humo_events WHERE (event_connect_kind='birth_declaration' OR event_connect_kind='death_declaration') AND event_connect_kind2 = '' AND event_connect_id2 LIKE 'I%' AND event_order='1'");

// *** Batch processing ***
$dbh->beginTransaction();

// *** Add seperate general birth_declaration and death_declaration events ***
while ($qryDb = $qry->fetch(PDO::FETCH_OBJ)) {
if ($qryDb->event_date || $qryDb->event_place || $qryDb->event_text) {
$sql_put = "INSERT INTO humo_events SET
event_tree_id='" . $qryDb->event_tree_id . "',
event_gedcomnr='',
event_order='" . $qryDb->event_order . "',
event_connect_kind='person',
event_connect_id='" . $qryDb->event_connect_id . "',
event_kind='" . $qryDb->event_connect_kind . "',
event_event='',
event_event_extra='" . safe_text_db($qryDb->event_event_extra) . "',
event_gedcom='EVEN',
event_date='" . $qryDb->event_date . "',
event_place='" . safe_text_db($qryDb->event_place) . "',
event_text='" . safe_text_db($qryDb->event_text) . "',
event_quality='" . $qryDb->event_quality . "',
event_new_user_id='" . $qryDb->event_new_user_id . "',
event_new_datetime='" . $qryDb->event_new_datetime . "',
event_changed_user_id='" . $qryDb->event_changed_user_id . "',
event_changed_datetime='" . $qryDb->event_changed_datetime . "'";

$dbh->query($sql_put);
$last_insert = $dbh->lastInsertId();

// *** Update sources connected to these events connections ***
$dbh->query("UPDATE humo_connections SET connect_connect_id='" . $last_insert . "' WHERE connect_connect_id='" . $qryDb->event_id . "'");
}
}

// *** Commit data in database ***
$dbh->commit();

// Solve bug in a previous update.
$dbh->query("UPDATE humo_events SET event_connect_kind2='person' WHERE event_kind='ASSO' AND event_connect_id2 LIKE 'I%'");

// *** Update "update_status" ***
$dbh->query("UPDATE humo_settings SET setting_value='19' WHERE setting_variable='update_status'");

// *** Show status of database update ***
//ob_start();
echo '<script>document.getElementById("information v6_7_9a").innerHTML="Database updated!";</script>';
//ob_flush();
flush();
}



// Future update(s): remove some old datafields.
Expand Down Expand Up @@ -4183,5 +4260,5 @@ public function update_v6_7_9($dbh): void
echo '<script>document.getElementById("information").innerHTML="'.__('Update tree:').' '.$updateDb->tree_id.'";</script>';
//ob_flush();
flush();
*/
*/
} // *** End of update_cls ***
18 changes: 15 additions & 3 deletions admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
}

// *** Check HuMo-genealogy database status, will be changed if database update is needed ***
if (isset($humo_option["update_status"]) && $humo_option["update_status"] < 18) {
if (isset($humo_option["update_status"]) && $humo_option["update_status"] < 19) {
$page = 'update';
$show_menu_left = false;
}
Expand Down Expand Up @@ -680,6 +680,9 @@
if ($page === 'install') {
include_once(__DIR__ . "/views/install.php");
} elseif ($page === 'extensions') {
//require __DIR__ . '/controller/extensionsController.php';
//$controllerObj = new ExtensionsController();
//$extensions = $controllerObj->detail($dbh);
include_once(__DIR__ . "/views/extensions.php");
} elseif ($page === 'login') {
include_once(__DIR__ . "/views/login.php");
Expand Down Expand Up @@ -730,8 +733,8 @@
include_once(__DIR__ . "/views/tree_check.php");
} elseif ($page === 'latest_changes') {
include_once(__DIR__ . "/views/tree_check.php");
} elseif ($page === 'gedcom') {
include_once(__DIR__ . "/views/gedcom.php");
//} elseif ($page === 'gedcom') {
// include_once(__DIR__ . "/views/gedcom.php");
} elseif ($page === 'settings') {
require __DIR__ . '/controller/settings_adminController.php';
$controllerObj = new SettingsController();
Expand Down Expand Up @@ -762,13 +765,19 @@
$cms_pages = $controllerObj->detail($dbh);
include_once(__DIR__ . "/views/cms_pages.php");
} elseif ($page === 'backup') {
//require __DIR__ . '/controller/backupController.php';
//$controllerObj = new BackupController();
//$backup = $controllerObj->detail($dbh);
include_once(__DIR__ . "/views/backup.php");
} elseif ($page === 'notes') {
require __DIR__ . '/controller/notesController.php';
$controllerObj = new NotesController();
$notes = $controllerObj->detail($dbh);
include_once(__DIR__ . "/views/notes.php");
} elseif ($page === 'cal_date') {
//require __DIR__ . '/controller/cal_dateController.php';
//$controllerObj = new CalculateDateController();
//$cal_date = $controllerObj->detail($dbh);
include_once(__DIR__ . "/views/cal_date.php");
} elseif ($page === 'export') {
require __DIR__ . '/controller/gedcom_exportController.php';
Expand All @@ -793,6 +802,9 @@
$maps = $controllerObj->detail($dbh, $db_functions);
include_once(__DIR__ . "/views/maps.php");
} elseif ($page === 'statistics') {
//require __DIR__ . '/controller/statisticsController.php';
//$controllerObj = new StatisticsController();
//$statistics = $controllerObj->detail($dbh, $db_functions);
include_once(__DIR__ . "/views/statistics.php");
} elseif ($page === 'install_update') {
include_once(__DIR__ . "/update/install_update.php");
Expand Down
81 changes: 81 additions & 0 deletions admin/models/gedcom.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
class GedcomModel
{
public function get_step()
{
$step = '1';
if (isset($_POST['step']) && is_numeric($_POST['step'])) {
$step = $_POST['step'];
}
if (isset($_GET['step']) && is_numeric($_GET['step'])) {
$step = $_GET['step'];
}
return $step;
}

public function get_gedcom_directory()
{
$gedcom_directory = "gedcom_files";

// *** Only needed for Huub's test server ***
if (@file_exists("../../gedcom-bestanden")) {
$gedcom_directory = "../../gedcom-bestanden";
}
return $gedcom_directory;
}

public function upload_gedcom()
{
$trees['upload_success'] = '';
$trees['upload_failed'] = '';

if (isset($_POST['upload'])) {
// *** Only needed for Huub's test server ***
if (file_exists("../../gedcom-bestanden")) {
$gedcom_directory = "../../gedcom-bestanden";
} elseif (file_exists("gedcom_files")) {
$gedcom_directory = "gedcom_files";
} else {
$gedcom_directory = ".";
}

// *** Only upload .ged or .zip files ***
if (strtolower(substr($_FILES['upload_file']['name'], -4)) === '.zip' || strtolower(substr($_FILES['upload_file']['name'], -4)) === '.ged') {
$new_upload = $gedcom_directory . '/' . basename($_FILES['upload_file']['name']);
// *** Move and check for succesful upload ***
if (move_uploaded_file($_FILES['upload_file']['tmp_name'], $new_upload)) {
$trees['upload_success'] = $new_upload . '<br>' . __('File successfully uploaded.') . '</b>';
} else {
$trees['upload_failed'] = $new_upload . '<br>' . __('Upload has failed.') . '</b>';
}

// *** If file is zipped, unzip it ***
if (strtolower(substr($new_upload, -4)) === '.zip') {
$zip = new ZipArchive;
$res = $zip->open($new_upload);
if ($res === TRUE) {

// *** Only unzip .ged files ***
$check_gedcom = true;
for ($i = 0; $i < $zip->numFiles; $i++) {
$filename = $zip->getNameIndex($i);
if (strtolower(substr($filename, -4)) !== '.ged') {
$check_gedcom = false;
}
}
if ($check_gedcom) {
$zip->extractTo($gedcom_directory);
$zip->close();
$trees['upload_success'] .= '<br>Succesfully unzipped file!';
}
} else {
$trees['upload_failed'] .= '<br>Error in unzipping file!';
}
}
} else {
$trees['upload_failed'] = __('Upload has failed.');
}
}
return $trees;
}
}
Loading

0 comments on commit 8d84062

Please sign in to comment.