-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtables.inc.php
147 lines (138 loc) · 3.87 KB
/
tables.inc.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
<?php
require_once('functions.inc.php');
function print_thead_key($key,$value,$prefix='') {
if(is_string($value)||is_numeric($value)||is_bool($value)||is_null($value)) {
if($prefix===0 && $key==='extra_metadata') {
echo "\t\t".'<th>0->extra_metadata->is_yaoi</th>'."\r\n";
echo "\t\t".'<th>0->extra_metadata->is_yuri</th>'."\r\n";
}
else echo "\t\t".'<th>'.(strlen($prefix)>0?$prefix.'->':'').$key.'</th>'."\r\n";
}
else if(is_array($value)) {
foreach($value as $k2=>$v2)
{
print_thead_key($k2,$v2,(strlen($prefix>0)?$prefix.'->':'').$key);
}
}
else if(is_object($value)) {
foreach(get_object_vars($value) as $k2=>$v2)
{
print_thead_key($k2,$v2,(strlen($prefix)>0?$prefix.'->':'').$key);
}
}
else {
var_dump($key,$value,$prefix);die();
}
}
function print_thead_value($key,$value,$prefix='') {
if(is_string($value)||is_numeric($value)||is_bool($value)||is_null($value)) {
echo "\t\t".'<th>'.$value.'</th>'."\r\n";
}
else if(is_array($value)) {
foreach($value as $k2=>$v2)
{
print_thead_key($k2,$v2,(strlen($prefix>0)?$prefix.'->':'').$key);
}
}
else if(is_object($value)) {
foreach(get_object_vars($value) as $k2=>$v2)
{
print_thead_key($k2,$v2,(strlen($prefix)>0?$prefix.'->':'').$key);
}
}
else {
var_dump($key,$value,$prefix);die();
}
}
function print_tbody_value($key,$value,$prefix='') {
//var_dump($value, is_string($value), is_numeric($value), is_bool($value), is_null($value), is_array($value), is_object($value));
if(is_string($value)||is_numeric($value)||is_bool($value)||is_null($value)) {
if($prefix===0 && $key==='extra_metadata') {
echo "\t\t".'<td></td>'."\r\n";
echo "\t\t".'<td></td>'."\r\n";
}
else echo "\t\t".'<td>'.strval($value).'</td>'."\r\n";
}
else if(is_array($value)) {
foreach($value as $k2=>$v2)
{
print_tbody_value($k2,$v2,(strlen($prefix>0)?$prefix.'->':'').$key);
}
}
else if(is_object($value)) {
foreach(get_object_vars($value) as $k2=>$v2)
{
print_tbody_value($k2,$v2,(strlen($prefix>0)?$prefix.'->':'').$key);
}
}
else {
var_dump($value);die();
}
}
function print_thead_k($ar) {
$keys=NULL;
//if(is_array($ar)) $keys=array_keys($ar);
//else if( is_object($ar) && (get_class($ar)=='stdClass') ) $keys=array_keys(get_object_vars($ar));
if(is_array($ar)) $keys=$ar;
else if( is_object($ar) && (get_class($ar)=='stdClass') ) $keys=get_object_vars($ar);
//keys
echo "\t".'<tr>'."\r\n";
foreach($keys as $k2=>$v2) {
print_thead_key($k2,$v2);
}
echo "\t".'</tr>'."\r\n";
}
function print_thead_v($ar) {
$keys=NULL;
//if(is_array($ar)) $keys=array_keys($ar);
//else if( is_object($ar) && (get_class($ar)=='stdClass') ) $keys=array_keys(get_object_vars($ar));
if(is_array($ar)) $keys=$ar;
else if( is_object($ar) && (get_class($ar)=='stdClass') ) $keys=get_object_vars($ar);
//keys
echo "\t".'<tr>'."\r\n";
foreach($keys as $k2=>$v2) {
print_thead_value($k2,$v2);
}
echo "\t".'</tr>'."\r\n";
}
function print_tbody($ar,$keys=NULL) {
if($keys==NULL) {
if(is_array($ar)) {
$values=$ar;
$keys=array_keys($ar);
}
else if( is_object($ar) && (get_class($ar)=='stdClass') ) {
$values=get_object_vars($ar);
$keys=array_keys($values);
}
}
else {
$values=$ar;
}
assert(count(array_diff_key($values,array_combine($keys,range(1,count($keys)))))==0) or die('wrong keys.');
//values
echo "\t".'<tr>'."\r\n";
foreach($keys as $k)
{
if(array_key_exists($k, $values)) $v=$values[$k]; else $v='';
print_tbody_value($k,$v);
}
echo "\t".'</tr>'."\r\n";
}
function print_table($ar)
{
if(!is_array($ar)) return;
if(count($ar)==0) return;
echo '<table border="1">'."\r\n";
reset($ar);
$k1=key($ar);
//keys
print_thead_k($ar[$k1]);
//values
foreach($ar as $k=>$v)
{
print_tbody($v);
}
echo '</table>'."\r\n";
}
?>