forked from erorus/db2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
181 lines (144 loc) · 4.87 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DB2</title>
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
</head>
<div class="box" align="center">
<body bgcolor="#343a40">
<style>
body{
Color: white;
}
h1{
Color: green;
}
td {
border: solid 1px white;
}
</style>
<table style="border: 5px solid #117a8b; border-collapse: collapse">
<?php
// error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED); // report errors
error_reporting(E_ALL & E_DEPRECATED); // no report errors
require_once __DIR__ . '/src/autoload.php';
use \Erorus\DB2\Reader;
$parent_directory = 'tests';
$file_types = 'db2';
//===================================================//
// FUNCTION: directoryToArray //
// //
// Parameters: //
// - $root: The directory to process //
// - $to_return: f=files, d=directories, b=both //
// - $file_types: the extensions of file types to //
// to return if files selected //
//===================================================//
function directoryToArray($root, $to_return='b', $file_types=false) {
$array_items = array();
if ($file_types) { $file_types=explode(',',$file_types); }
if ($handle = opendir($root)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$add_item = false;
$type = (is_dir($root. "/" . $file))?'d':'f';
$name = preg_replace("/\/\//si", "/", $file);
if ($type=='d' && ($to_return=='b' || $to_return=='d') ) {
$add_item = true;
}
if ($type=='f' && ($to_return=='b' || $to_return=='f') ) {
$fext = (explode('.',$name));
$ext = strtolower(end($fext));
// // $ext = end(explode('.',$name));
if ( !$file_types || in_array($ext, $file_types) ) {
$add_item = true;
}
}
if ($add_item) {
$array_items[] = array ( 'name'=>$name, 'type'=>$type, 'root'=>$root);
}
}
} // End While
closedir($handle);
} // End If
return $array_items;
}
if (isset($_POST['pickfile'])) {
// User has selected a file take whatever action you want based
// upon the values for folder and file
$path = $_GET['pickfile'];
} else {
echo '
<html>
<head>
<script type="text/javascript">
function changeFolder(folder) {
document.pickFile.submit();
}
</script>
</head>
<body>';
echo "<form name=\"pickFile\" method=\"POST\">\n";
$directoryList = directoryToArray($parent_directory,'d');
echo "<select name=\"folder\" onchange=\"changeFolder(this.value);\">\n";
echo '<option value=\"\">Logfolder</option>\n';
foreach ($directoryList as $folder) {
$selected = ($_POST['folder'] == $folder['name'])? 'selected' : '';
echo "<option value=\"$folder[name]\" $selected>$folder[name]</option>\n";
}
echo '</select><br><br>';
$working_folder = ($_POST['folder']) ? '/'.$_POST['folder'].'/' : '/'.$directoryList[0]['name'].'/';
$fileList = directoryToArray($parent_directory.'/'.$working_folder,'f',$file_types);
echo "<select name=\"file2\">\n";
echo '<option value=\"\">Logfiles</option>\n';
foreach ($fileList as $file) {
$selectedfile = @$_POST[file2];
echo "<option value=\"$file[name]\" $selectedfile>$file[name]</option>\n";
}
echo '</select><br><br>';
$path = __DIR__.'/'.$parent_directory.$working_folder.$selectedfile;
echo "<button type=\"submit\" name=\"pickFile\">Submit</button>\n";
}
$reader = new Reader($path);
echo '<td><font color="yellow">'.$selectedfile," - Layout: 0x", dechex($reader->getLayoutHash())," - Layout in integer: ", ($reader->getLayoutHash()), nl2br("\n");
echo '</font></td>';
if (isset($_POST['pickfile'])) {
$reader->fetchColumnNames();
print_r($reader->getRecord($_GET['pickfile']));
exit;
}
echo "<table>";
echo "<tr>";
$ColumnData = $reader->fetchColumnNames();
foreach ($ColumnData as $id => $record) {
$arr = array('(',$id + 1,')', ' ' , $record);
echo '<td><font color="gold">' ,implode( "", $arr), '</font></td>';
}
$recordNum = 0;
foreach ($reader->generateRecords() as $id => $record) {
echo "<tr><td>" .$id, ": "; // implode(',', Reader::flattenRecord($record));
$colNum = 0;
foreach ($record as $colName => $colVal) {
if ($colNum++ > 0) {
echo "<td>";
};
if (is_array($colVal)) {
echo '[', implode(',', $colVal), ']';
} else {
echo $colVal, "</td>";
}
}
echo "</tr>";
if (++$recordNum <= 0) {
// if (++$recordNum >= 10) { // Used in Examine Huge Data
break;
}
}
echo "</table>";
echo "</form>\n";
echo "</body>\n";
echo "</html>\n";
?>
</body>
</html>