-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
266 lines (212 loc) · 7.39 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<?php
// Starting the session
session_start();
//$mytimes = array("page_begin" => microtime(True));
# LIBRARIES
//include "./lib/config_setup.php";
//include $config['apt_to_ini_path'] . "/eb_connect_pg.php";
include "./lib/config.php";
include "./lib/html_utils.php";
include "./lib/php_utils.php";
include "./lib/php_query.php";
include "./lib/php_process.php";
include "./lib/php_write.php";
include "./lib/html_info.php";
$eb_path = "http://" . $config['ebhost'] . "/" . $config['eb_path'] . '/';
$html_path = "http://" . $config['htmlhost'] . "/";
if($config['html_path']) $html_path = $html_path . $config['html_path'] . '/';
$share_path = "http://" . $config['ebhost'] . "/" . $config['share_path'] . '/';
$_SESSION['tmp_path'] = $config['tmp_path'];
$_SESSION['full_tmp_path'] = "http://" . $config['ebhost'] . '/' . $config['tmp_path'] . '/';
# EB PATH
echo "<input type='hidden' id='eb_path' value='$eb_path' />";
# ---------------------------------------------------------------------------------------------------
# _POST AND SESSION
# ---------------------------------------------------------------------------------------------------
# POST TOKENS
$oldtoken = $_SESSION['token'];
$newtoken = $_POST['token'];
# POST => SESSION
foreach ($_POST as $key =>$value) {
//echo "$key => $value<br>";
$_SESSION[$key] = $value;
}
# STAGE
$stage = $_SESSION['stage']; // Form Stage
if (!$stage) $stage = 'sources';
# LAST ACTION - dealing with the back button
if ($_SESSION['lastaction']) $lastaction = $_SESSION['lastaction'];
if ($lastaction == 'doc') $stage = 'main';
$sources = $_SESSION['sources'];
if ((!$sources || empty($sources)) && $stage == 'main') $stage = 'sources';
$lastid = $_SESSION['lastid'];
# SOURCES
$sourceids = $_SESSION['sourceids']; //ids of the sources
# QUERY
$qobjid = $_SESSION['qobjid']; // The qobj to process. Is null if new query or repost
//echo "qobjid: $qobjid<br>";
$qterm = $_SESSION['qterm']; // the type of query
$qsources = $_SESSION['qsources']; // the sources the query applies to
if (!is_array($qsources)) $qsources = array($qsources);
# OUTPUT
$output_sid = $_SESSION['output_sid']; // OUTPUT SOURCE
$output_id = $_SESSION['output_id']; // OUTPUT ID
if ($oldtoken != $newtoken) unset($_SESSION['output_sid']);
if ($_SESSION['outputs']) $outputs = $_SESSION['outputs'];
#echo "oldtoken: $oldtoken, oldtoken: $newtoken<br>";
//echo "stage: $stage<br>";
//print_r($sources);
//echo "lastaction: $lastaction, lastid: $lastid<br>";
//echo $_SESSION['zip'], "<br>";
# ------------------------------------------------------------------------------------------------
# HTML HEADERS
# ------------------------------------------------------------------------------------------------
#HTML headers
echo '<html>';
#HEAD includes Javascript
echo '<head>';
echo "<title>Entangled Bank Integrated Database</title>";
echo '<link type="text/css" rel="stylesheet" href="' . $share_path . 'entangled_bank.css">';
echo '</head>';
#END HEAD
#BODY
echo '<script src="./scripts/utils.js" type="text/javascript"></script>';
echo "<body onload='loadScript()'>";
# --------------------------------------------------------------------------------------------------
# DATABASE CONNECTION
# --------------------------------------------------------------------------------------------------
echo "<div id='page'>";
set_time_limit(1200);
$db_handle = eb_connect_pg($config);
if ($db_handle == false) {
$stage = 'dbfail';
html_entangled_bank_header($stage, $eb_path);
# FOOTER
html_entangled_bank_footer();
#CLOSE MAIN DIV
echo "</div>";
echo "</body>";
echo '</html>';
echo exit;
}
# -----------------------------------------------------------------------------------------------------
# PRE-FORM PROCESSING
# -----------------------------------------------------------------------------------------------------
# NAME SEARCH
if ($stage == 'find') {
$name_search = query_name_search($db_handle);
$stage = 'main';
}
# EXIT QUERYING THROUGH QTERM
if ($qterm == 'finish') $stage = 'finish';
# AFTER SOURCES
if ($stage == 'getsources')
$stage = process_get_sources($db_handle, $sourceids, $lastaction);
# CANCELLING A QUERY
if ($stage == 'qcancel') {
$qobjid = null;
$stage = 'main';
}
# DELETE A QUERY
if ($stage == 'qdelete') {
process_delete_query($db_handle, $qobjid);
$qobjid = null;
$stage = 'main';
}
# DELETE ALL QUERIES
if ($stage == 'querydeleteall') {
unset ($_SESSION['qobjects']);
unset ($_SESSION['names']);
unset ($_SESSION['info']);
$stage = 'main';
}
# QSET - CREATE NEW QUERY, MANAGE QUERIES OR END QUERYING
if ($stage == 'qset')
$qobjid = process_new_query($qobjid, $qterm, $oldtoken, $newtoken, $lastaction, $lastid);
# QVERIFY - VERIFY QUERY
if ($stage == 'qverify')
$stage = process_query($db_handle, $qobjid, $qsources);
# PREPARE AND EXECUTE A QUERY
if ($stage == 'query') {
query($db_handle, $qobjid);
$qobjid = null;
unset ($_SESSION['qobjid']);
$stage = 'main';
}
# NEW OUTPUT
if ($stage == 'newoutput') {
$output_id = process_new_output($oldtoken, $newtoken, $output_sid);
$stage = 'setoutput';
}
# CANCEL OUTPUT
if ($stage == 'outputcancel') {
$c = count($outputs) - 1;
if ($outputs[$c]['status'] == 'new') unset($outputs[$c]);
$output_id = null;
$stage = 'main';
}
# DELETE OUTPUT
if ($stage == 'outputdelete') {
process_delete_output ($output_id);
$stage = 'main';
}
# DELETE ALL OUTPUTs
if ($stage == 'outputdeleteall') {
unset ($outputs);
$_SESSION['outputs'] = $outputs;
if ($_SESSION['zip']) {
$zip = $_SESSION['zip'];
$file = $config['out_path'] . "/$zip";
if (file_exists($file)) {
unlink($file);
}
unset ($_SESSION['zip']);
}
$stage = 'main';
}
# VERIFY OUTPUT POSTED DATA TO OUTPUT
if ($stage == 'outputvalidate' && $output_id) {
process_output($db_handle, $output_id);
$stage = 'main';
$output_id = null;
}
# WRITE OUTPUT FILES
if ($stage == 'write') {
write_outputs($db_handle, $config);
# DELETE OLD FILES - COULD BE BETTER MANAGED
process_cleanup($config);
$stage = 'main';
}
# ----------------------------------------------------------------------------------
# FORM
# ----------------------------------------------------------------------------------
echo '<form method="post" name="ebankform" action="' . $eb_path . 'index.php"
onsubmit="document.getElementById(\'submit-button\').disabled = true;">';
# HEADER
html_entangled_bank_header($stage, $eb_path, $html_path, $share_path);
# SELECT SOURCES
if ($stage == 'sources')
html_entangled_bank_sources($db_handle);
# MAIN INTERFACE
if ($stage == 'main' || $stage == 'write')
html_entangled_bank_main($db_handle, $oldtoken, $newtoken, $name_search, $output_id);
# QUERY SETUP
if ($stage == 'qset')
html_query($db_handle, $qobjid);
# OUTPUT DIALOGS
if ($stage == 'setoutput')
html_output($db_handle, $output_id);
# UNIQUE ID FOR FORM INSTANCE
echo '<input type="hidden" name="token" value=' . md5(uniqid()) .'>';
#CLOSE FORM
echo '</form>';
# ----------------------------------------------------------------------------------
# FOOOTER
# ----------------------------------------------------------------------------------
html_entangled_bank_footer();
pg_close($db_handle);
#CLOSE MAIN DIV
echo "</div>";
echo "</body>";
echo '</html>';
?>