-
Notifications
You must be signed in to change notification settings - Fork 51
/
index.php
295 lines (261 loc) · 11.2 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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<?php
/**
* This file is a part of MyWebSQL package
* @file: index.php
* @author Samnan ur Rehman
* @copyright (c) 2008-2014 Samnan ur Rehman
* @web http://mywebsql.net
* @license http://mywebsql.net/license
*/
define('BASE_PATH', dirname(__FILE__));
header("Content-Type: text/html;charset=utf-8");
header("X-Frame-Options: SAMEORIGIN");
include_once(BASE_PATH . "/lib/session.php");
Session::init();
date_default_timezone_set('UTC');
include(BASE_PATH . '/modules/configuration.php');
initConfiguration();
// buffer unless we are in the download module (it will handle the buffering itself)
if (v($_REQUEST["type"]) != "dl") {
include_once(BASE_PATH . "/lib/output.php");
Output::buffer();
} else {
$_REQUEST["type"] = 'download';
}
if (defined("TRACE_FILEPATH") && TRACE_FILEPATH && defined("TRACE_MESSAGES") && TRACE_MESSAGES)
ini_set("error_log", TRACE_FILEPATH);
include_once(BASE_PATH . "/lib/util.php");
require( BASE_PATH . '/modules/auth.php');
$auth_module = new MyWebSQL_Authentication();
if (!$auth_module->authenticate()) {
if (v($_REQUEST["q"]) == "wrkfrm")
echo view('session_expired');
else {
include(BASE_PATH . "/modules/splash.php");
$form = view( 'auth', array(
'LOGINID' => htmlspecialchars( $auth_module->getUserName() ),
'SERVER_NAME' => htmlspecialchars( $auth_module->getCustomServer() ),
'SERVER_TYPE' => htmlspecialchars( $auth_module->getCustomServerType() ),
) );
echo getSplashScreen($auth_module->getError(), $form);
}
Output::flush();
exit();
}
unset($auth_module);
$_db_info = getDBClass();
include_once($_db_info[0]);
$_db_class = $_db_info[1];
$DB = new $_db_class();
unset($_db_info);
unset($_db_class);
if (v($_REQUEST["db"]) && ( Session::get('db', 'name') != v($_REQUEST["db"]) ) ) {
Session::set('db', 'changed', true);
Session::set('db', 'name', $_REQUEST["db"]);
if (v($_GET["x"]) == 1)
echo '<div id="results">1</div>'; // success
else
header('Location: '.EXTERNAL_PATH);
exit;
}
// after this, we need the user set options to be visible everywhere
include_once(BASE_PATH . "/lib/options.php");
if (v($_REQUEST["q"]) == "wrkfrm") {
if (!$DB->connect(DB_HOST, DB_USER, DB_PASS, getDbName() ))
die(showDBError());
execute_request($DB);
$DB->disconnect();
include_once(BASE_PATH . "/lib/output.php");
Output::flush();
exit();
}
include(BASE_PATH . "/lib/html.php");
include(BASE_PATH. "/lib/interface.php");
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset='utf-8';" />
<title>MyWebSQL</title>
<link rel="stylesheet" type="text/css" href="cache.php?css=theme,default" />
<link rel="SHORTCUT ICON" href="favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="stylesheet" type="text/css" href="cache.php?css=menu,treeview,results,context,alerts" />
<script type="text/javascript" language="javascript" src="cache.php?script=jquery,mobile,<?php echo $DB->name(); ?>"></script>
<!--[if lt IE 8]>
<script type="text/javascript" language="javascript" src="cache.php?script=json2"></script>
<![endif]-->
</head>
<body class="mainbody">
<?php
if (!$DB->connect(DB_HOST,DB_USER,DB_PASS,getDbName())) {
include(BASE_PATH . "/modules/splash.php");
die(getSplashScreen(showDBError()));
}
if (Session::get('session', 'init') != '1') {
// session just started, so we load information here
Session::set('db', 'user', $DB->getCurrentUser(), true);
Session::set('session', 'init', 1);
}
$KEY_CODES = getKeyCodes();
?>
<div id="editToolbar">
<div class="tb-header ui-widget-header"><span class="fname"></span></div>
<div class="tb-row">Type: <span class="ftype"></span></div>
<div class="tb-row">[ <?php echo str_replace('{{KEY}}', $KEY_CODES['KEYCODE_SETNULL'][1], __('Press {{KEY}} to set NULL')); ?> ]</div>
</div>
<div id="inplace-text">
<div class="tb-row"><textarea rows="4" cols="20"></textarea></div>
</div>
<div class="ui-layout-north">
<div id="main_header">
<a target="_blank" href="<?php echo PROJECT_SITEURL;?>"><img src="img/logo.png" class="logo" alt="MyWebSQL" width="45" height="38" border="0" /></a>
<div class="title">
<div class="main">MyWebSQL</div>
<div class="version"><?php echo __('version') . ' ' . APP_VERSION; ?></div>
</div>
<div class="info">
<span class="server"><?php echo htmlspecialchars(Session::get('auth', 'server_name', true)); ?></span> - <?php echo htmlspecialchars(Session::get('db', 'version_comment')); ?> <?php echo htmlspecialchars(Session::get('db', 'version_full')); ?><br />
<?php echo str_replace('{{USER}}', htmlspecialchars(Session::get('db', 'user', true)), __('Logged in as: {{USER}}')); ?>
</div>
<div class="updates ui-state-active"></div>
</div>
<div id="toolbarHolder">
<?php
echo getMenuBarHTML();
?>
</div>
</div>
<div class="ui-layout-west">
<div id="db_combo" class="ui-state-default">
<?php $db_list = printDbList($DB); ?>
</div>
<div id="object_list" class="ui-state-default">
<?php echo getDatabaseTreeHTML($DB, $db_list); ?>
</div>
<div id="object-filter" class="ui-state-default">
<input type="text" id="object-filter-text" size="5" placeholder="Type to filter object list" data-placeholder="<?php echo __('Type to filter object list'); ?>" />
</div>
</div>
<div class="ui-layout-center">
<div id="screenContent" class="ui-layout-data-center">
<ul>
<li><a href="#tab-results" id="headerResults"><?php echo __('Results'); ?></a></li>
<li><a href="#tab-messages" id="headerMessages"><?php echo __('Messages'); ?></a></li>
<li><a href="#tab-info" id="headerInfo"><?php echo __('Information'); ?></a></li>
<li><a href="#tab-history" id="headerHistory"><?php echo __('History'); ?></a></li>
</ul>
<div id="screen-pane-buttons">
<button id="sp-results-maximize" title="<?php echo __('Maximize/Restore Results Pane'); ?>"></button>
</div>
<div class="ui-layout-content ui-corner-bottom">
<div id="tab-results">
<div id="results-div"><div class="message" style="text-align:center"><?php echo __('There are no results to show in this view'); ?></div></div>
<div id="rec_pager">
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="ui-state-default">
<tr>
<td id="recordCounter" class="footer" nowrap="nowrap"> </td>
<td id="timeCounter" class="footer" nowrap="nowrap"> </td>
<td id="modifyFlag" class="footer" nowrap="nowrap"><!--button id="nav_refresh">Refresh results</button--></td>
<td id="messageContainer" class="footer" nowrap="nowrap"><?php echo __('Please wait'); ?> ...</td>
<td id="pagingContainer" class="footer" nowrap="nowrap"></td>
</tr>
</table>
</div>
</div>
<div id="tab-messages">
<div id="messages-div"></div>
</div>
<div id="tab-info" class="ui-widget">
<div id="info-div"></div>
</div>
<div id="tab-history">
<table id="sql-history" width="100%"><tbody><tr><td></td></tr></tbody></table>
</div>
</div>
</div>
<div id="sql-editor-pane" class="ui-layout-data-south">
<ul>
<li><a href="#editor_container"><?php echo __('SQL Editor'); ?></a></li>
<li><a href="#editor_container2"><?php echo __('SQL Editor'); ?> 2</a></li>
<li><a href="#editor_container3"><?php echo __('SQL Editor'); ?> 3</a></li>
</ul>
<div id="editor_container">
<textarea class="sql-editor" id="commandEditor" name="commandEditor" rows="5" cols="40"></textarea>
</div>
<div id="editor_container2">
<textarea class="sql-editor" id="commandEditor2" name="commandEditor2" rows="5" cols="40"></textarea>
</div>
<div id="editor_container3">
<textarea class="sql-editor" id="commandEditor3" name="commandEditor3" rows="5" cols="40"></textarea>
</div>
<div id="nav_bar">
<button id="nav_queryall"><?php echo __('Query All'); ?></button>
<button id="nav_query"><?php echo __('Query'); ?></button>
<button id="nav_addrec"><?php echo __('Add Record'); ?></button>
<button id="nav_copyrec"><?php echo __('Copy Record(s)'); ?></button>
<button id="nav_delete"><?php echo __('Delete Record(s)'); ?></button>
<button id="nav_update"><?php echo __('Update Record(s)'); ?></button>
<button id="nav_gensql"><?php echo __('Generate SQL'); ?></button>
</div>
<div id="loader">
<img width="60" height="12" id="loaderImg" src="themes/<?php echo THEME_PATH; ?>/images/loading.gif" alt="<?php echo __('Loading'); ?>..." />
</div>
</div>
</div>
<div class="ui-layout-south">
<div id="taskbar" class="ui-state-default">
<button class="min-all" title="<?php echo __('Minimize All'); ?>"><?php echo __('Minimize All'); ?></button>
</div>
</div>
<?php include(BASE_PATH . '/modules/views/dialogs.php'); ?>
<iframe src="javascript:false" name="wrkfrm" id="wrkfrm" frameborder="0" width="0" height="0"></iframe>
<div id="screen-wait" class="ui-widget-overlay">
<div><span><?php echo __('Loading'); ?>...</span><img src="themes/<?php echo THEME_PATH; ?>/images/loading.gif" alt="" /></div>
<div class="compat-notice" style="display:none;margin:200px auto;width:530px;color: #222222;font-family:segoe ui;font-size:13pt;font-weight:bold">
<?php echo __('Your browser appears to be very old and does not support all features required to run MyWebSQL.'); ?><br /><br />
<?php echo __('Try using a newer version of the browser to run this application.'); ?>
</div>
</div>
<script type="text/javascript" language="javascript">
var THEME_PATH = "<?php echo THEME_PATH;?>";
var EXTERNAL_PATH = "<?php echo EXTERNAL_PATH; ?>";
var COOKIE_LIFETIME = <?php echo COOKIE_LIFETIME; ?>; // hours
var MAX_TEXT_LENGTH_DISPLAY = <?php echo MAX_TEXT_LENGTH_DISPLAY; ?>;
var APP_LANGUAGE = "<?php echo LANGUAGE; ?>";
var APP_VERSION = "<?php echo APP_VERSION; ?>";
var DB_DRIVER = "<?php echo Session::get('db', 'driver'); ?>";
var DB_VERSION = <?php echo Session::get('db', 'version'); ?>;
var DB = db_<?php echo $DB->name(); ?>;
var commandEditor = null;
var commandEditor2 = null;
var commandEditor3 = null;
<?php
include(BASE_PATH . '/config/updates.php');
if($AUTOUPDATE_CHECK === TRUE && Session::get('updates', 'check') == '' ) {
if (in_array(date('D'), $AUTOUPDATE_DAYS)) {
echo "\n\t$(function() { helpCheckUpdates(); });\n";
}
}
if (Session::get('db', 'changed')) {
echo 'document.getElementById("messageContainer").innerHTML = "Database changed to: '.htmlspecialchars(Session::get('db', 'name')).'";';
Session::del('db', 'changed');
}
else
echo 'document.getElementById("messageContainer").innerHTML = "Connected to: '.htmlspecialchars(DB_HOST).' as '.htmlspecialchars(DB_USER).'";';
?>
</script>
<script type="text/javascript" language="javascript" src="cache.php?script=layout,ui,dialogs,context,alerts,cookies,select,interface,options,treeview,common,taskbar,settings,query,tables,clipboard"></script>
<?php
$DB->disconnect();
echo getContextMenusHTML();
updateSqlEditor();
echo getHotkeysHTML();
echo getGeneratedJS();
?>
</body></html>
<?php
Output::flush();
?>