-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
160 lines (145 loc) · 4.71 KB
/
index.php
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
<?php
session_start();
$basedir = __DIR__;
require_once "$basedir/vendor/autoload.php";
require_once "$basedir/init.php";
//$i18n = new I18n();
function get_translation($i18nstring,$lang=null,$str_translations=null) {
global $config;
if(!$lang) {
$lang = $config['lang']??"fr";
}
if(!$str_translations) {
$str_translations= $config['translations'][$lang];
}
if(isset($str_translations[$i18nstring])) {
return $str_translations[$i18nstring];
} else {
return $i18nstring;
}
}
function apachelog($foo) {
if(is_array($foo)) {
$foo = print_r($foo,true);
}
file_put_contents('php://stderr', print_r($foo, TRUE)) ;
}
$action = $_GET['action'] ?? $_POST['action']??'';
$user = new UserModel($config);
$userId = $user->getCurrentUserId();
$config['current-user']=$userId;
if (!$userId) {
header("Location: login.php");
exit();
}
$treeController = new TreeController($config);
$memberController = new MemberController($config);
switch ($action) {
case 'list_trees':
$treeController->listTrees();
break;
case 'add_tree':
$treeController->addTree();
break;
case 'view_tree':
$treeController->viewTree();
break;
case 'get_tree_data':
$treeController->getTreeData();
break;
case 'delete_tree':
$treeController->deleteTree();
break;
case 'edit_tree':
case 'list_members':
$treeId = $_GET['tree_id'];
$page = $_GET['page'] ?? 1;
$treeController->listMembers($treeId, $page);
break;
case 'add_member':
$treeId = $_GET['tree_id'];
$memberController->addMember($treeId);
break;
case 'add_tag':
$response = $memberController->addTag();
echo $response;
exit;
break;
case 'delete_tag':
if($memberController->deleteTag()) {
echo json_encode(['status' => 'success']);
} else {
echo json_encode(['status' => 'error']);
}
break;
case 'reload_tags':
$tags = $memberController->listTags();
break;
case 'view_member':
case 'edit_member':
$memberId = $_GET['member_id'];
$memberController->editMember($memberId);
break;
case 'get_relationship_types':
$memberId = $_GET['tree_id']??1;
echo $memberController->getRelationshipTypes($memberId);
break;
case 'delete_member':
// Handle deleting member
//include 'controllers/MemberController.php';
//$memberController = new MemberController();
$memberId = isset($_POST['member_id']) ? $_POST['member_id'] : null;
$treeId = isset($_POST['treeId']) ? $_POST['treeId'] : null;
$member = $memberController->getMemberById($memberId);
$treeId=$member['family_tree_id']??false;
if($memberId) {
$success = $memberController->deleteMember($memberId);
if($treeId){
header("Location: index.php?action=list_members&tree_id=$treeId");
} else {
header("Location: index.php?action=list_trees");
}
}
$treeController->listMembers($treeId??1,$page);
// Redirect or display appropriate message after deletion
break;
case 'autocomplete_member':
$term = $_GET['term'];
$memberId = $_GET['member_id']??1;
$tree = $_GET['tree_id']??1;
//apachelog($tree);
$memberController->autocompleteMember($term,$memberId,$tree);
exit;
case 'search_members':
$treeController->searchMembers();
break;
case 'swap_relationship':
//apachelog($_POST['relationship_id']);
$memberController->swapRelationshipAction();
// /apachelog("hello world");
break;
case 'add_relationship':
$memberId = $_POST['member_id'] ?? '';
$personId2 = $_POST['member2_id'] ?? '';
$relationshipTypeId = $_POST['relationship_type'] ?? '';
$controller = new MemberController($config);
//apachelog($_POST);
$controller->addRelationship($memberId, $personId2, $relationshipTypeId);
break;
case 'update_relationship':
//apachelog($_POST);
$memberController->updateRelationship($_POST);
break;
case 'get_relationships':
$memberId = $_GET['member_id'] ?? '';
$memberController->getRelationships($memberId);
break;
case 'delete_relationship':
$relationshipId = $_POST['relationship_id'] ?? '';
$controller = new MemberController($config);
$controller->deleteRelationship($relationshipId);
break;
default:
header("Location: index.php?action=list_trees");
exit();
}