-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
executable file
·127 lines (102 loc) · 3.02 KB
/
test.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
<?php
$prefix = "phpft";
require_once("config.php");
require_once("includes/database.php");
class relation {
var $person1;
var $person2;
var $personArray;
var $everyone;
var $x;
function get_children($id) {
global $prefix;
// query database
$sql = "SELECT id FROM ".$prefix."_people WHERE ";
$sql.= "(mother = ".$id." OR father = ".$id.") ORDER BY birthdate";
$res = mysql_query($sql) or die(mysql_error());
while(list($id1) = mysql_fetch_row($res)) {
$this->get_connections($id,$id1);
}
}
function get_parents($id) {
global $prefix;
// query database
$sql = "SELECT B.id AS fid, C.id AS mid ";
$sql.= "FROM ".$prefix."_people A ";
$sql.= "LEFT JOIN ".$prefix."_people B on A.father = B.id ";
$sql.= "LEFT JOIN ".$prefix."_people C on A.mother = C.id ";
$sql.= "WHERE (A.id = ".$id.") LIMIT 1";
//echo $sql."<br/>";
$res = mysql_query($sql) or die(mysql_error());
list($id1,$id2) = mysql_fetch_row($res);
if($id1) {
$this->get_connections($id,$id1);
}
if($id2) {
$this->get_connections($id,$id1);
}
}
function get_siblings($id) {
global $prefix;
// query database
$sql = "SELECT B.id AS id1, C.id AS id2 ";
$sql.= "FROM ".$prefix."_siblings A ";
$sql.= "INNER JOIN ".$prefix."_people B ON A.person1 = B.id ";
$sql.= "INNER JOIN ".$prefix."_people C ON A.person2 = C.id ";
$sql.= "WHERE (A.person1 = ".$id." OR A.person2 = ".$id.") ";
//echo $sql."<br/>";
$res = mysql_query($sql) or die(mysql_error());
while(list($id1,$id2) = mysql_fetch_row($res)) {
if($id = $id1)
$this->get_connections($id,$id2);
elseif($id = $id2)
$this->get_connections($id,$id1);
}
}
function get_spouses($id) {
global $prefix;
// query database
$sql = "SELECT B.id AS id1, C.id AS id2 ";
$sql.= "FROM ".$prefix."_spouses A ";
$sql.= "INNER JOIN ".$prefix."_people B ON A.person1 = B.id ";
$sql.= "INNER JOIN ".$prefix."_people C ON A.person2 = C.id ";
$sql.= "WHERE (A.person1 = ".$id." OR A.person2 = ".$id.") ";
//echo $sql."<br/>";
$res = mysql_query($sql);
while(list($id1,$id2) = mysql_fetch_row($res)) {
if($id = $id1)
$this->get_connections($id,$id2);
elseif($id = $id2)
$this->get_connections($id,$id1);
}
}
function get_connections($i,$id) {
$this->personArray[$i] = $id;
if($id != $this->person2 && !in_array($id,$this->everyone)) {
$this->everyone[$this->x++] = $id;
$this->get_children($id);
$this->get_parents($id);
$this->get_siblings($id);
$this->get_spouses($id);
}
else {
return $this->map_points($i);
}
}
function map_points($id) {
echo "<pre>";
print_r($this->personArray);
echo "</pre>";
die;
}
function show() {
$this->everyone[0] = 0;
$this->person1 = intval(mysql_escape_string($this->person1));
echo $this->get_connections(0,$this->person1);
}
}
$map = new relation;
$map->person1 = 1;
$map->person2 = 10;
$map->show();
?>