-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.uiFeatures.php
111 lines (90 loc) · 2.85 KB
/
class.uiFeatures.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
<?php
class uiFeatures
{
protected
$masterTable
,$detailTable
,$connection
;
private
$dbPass
,$dbHost
,$dbUser
,$dbName
;
public function __construct($host, $user, $pass,$dbName)
{
$this->dbPass = $pass;
$this->dbName = $dbName;
$this->dbHost = $host;
$this->dbUser = $user;
$this->connection = $this->connectToDB();
}
private function connectToDB()
{
$connection = mysql_connect($this->dbHost, $this->dbUser, $this->dbPass);
mysql_select_db($this->dbName, $connection);
mysql_query("SET NAMES UTF8");
return $connection;
}
//$masterTable = array('table' => 'cateories', 'title' => 'title', 'pk' => 'id')
public function createAccordian($masterTable, $detailTable)
{
$this->masterTable = $masterTable;
$this->detailTable = $detailTable;
$masterQuery =
"SELECT "
.$this->masterTable['title']
.", "
.$this->masterTable['PK']
." FROM "
.$this->masterTable['table'];
$titles = mysql_query($masterQuery, $this->connection);
$acc = '<div id="accordion">';
while($titleBody = mysql_fetch_assoc($titles))
{
$text = $masterTable['title'];
$acc .= "<div class='group'>
<h3>$titleBody[$text]</h3>
<div>";
$detailQuery =
"SELECT "
.$this->detailTable['title']
." FROM "
.$this->detailTable['table']
." WHERE "
.$this->detailTable['FK']
." = "
.$titleBody['id'];
$detail = mysql_query($detailQuery, $this->connection);
while($detailBody = mysql_fetch_assoc($detail))
{
$detailText = $detailTable['title'];
$acc.= "<p>$detailBody[$detailText]</p>";
}
$acc .='</div></div>';
}
return $acc.='</div>
<script>
$(function() {
$( "#accordion" )
.accordion({
header: "> div > h3"
})
.sortable({
axis: "y",
handle: "h3",
stop: function( event, ui ) {
ui.item.children( "h3" ).triggerHandler( "focusout" );
$( this ).accordion( "refresh" );
}
});
});
</script>';
}
public function __destruct()
{
$this->connection = null;
}
}
?>