Initial commit
This commit is contained in:
282
application/view/sql/index.php
Normal file
282
application/view/sql/index.php
Normal file
@@ -0,0 +1,282 @@
|
||||
<div class="dbmanager-container">
|
||||
<div class="dbmanager-sidebar">
|
||||
<h3>Databases</h3>
|
||||
<ul class="db-tree">
|
||||
<?php foreach ($this->databases as $db): ?>
|
||||
<li class="db-item <?php echo ($db === $this->database_name) ? 'active' : ''; ?>">
|
||||
<a href="<?php echo Config::get('URL'); ?>sql/index/<?php echo urlencode($db); ?>" class="db-link">
|
||||
<?php echo htmlspecialchars($db); ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
|
||||
<div class="db-actions">
|
||||
<a href="<?php echo Config::get('URL'); ?>database/index" class="btn" style="display:block;text-align:center;">Back to Databases</a>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($this->history)): ?>
|
||||
<div style="margin-top:20px;">
|
||||
<h4>Query History</h4>
|
||||
<ul class="query-history">
|
||||
<?php foreach (array_slice($this->history, 0, 10) as $item): ?>
|
||||
<li class="history-item" onclick="document.getElementById('sql_query').value = this.dataset.query;" data-query="<?php echo htmlspecialchars($item['query_text']); ?>">
|
||||
<?php echo htmlspecialchars(substr($item['query_text'], 0, 40)); ?>...
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<a href="<?php echo Config::get('URL'); ?>sql/clearHistory" class="btn btn-small btn-danger" style="margin-top:10px;">Clear History</a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="dbmanager-content">
|
||||
<h2>SQL Console</h2>
|
||||
<p>Database: <strong><?php echo htmlspecialchars($this->database_name); ?></strong></p>
|
||||
|
||||
<form method="post" action="<?php echo Config::get('URL'); ?>sql/execute" id="sql-form">
|
||||
<input type="hidden" name="database_name" value="<?php echo htmlspecialchars($this->database_name); ?>">
|
||||
|
||||
<div class="sql-editor">
|
||||
<textarea name="sql_query" id="sql_query" rows="6" placeholder="Enter your SQL query here...
|
||||
Example: SELECT * FROM users LIMIT 10"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="sql-actions">
|
||||
<button type="submit" class="btn">Execute Query</button>
|
||||
<button type="button" class="btn" style="background:#6c757d;" onclick="document.getElementById('sql_query').value = '';">Clear</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div id="sql-result" class="sql-result">
|
||||
<?php
|
||||
// Check for session result
|
||||
$result = Session::get('sql_result');
|
||||
if ($result) {
|
||||
Session::set('sql_result', null);
|
||||
|
||||
if ($result['success']) {
|
||||
echo '<div class="result-success">';
|
||||
echo '<p>' . htmlspecialchars($result['message']) . '</p>';
|
||||
echo '<p class="execution-time">Execution time: ' . $result['execution_time'] . ' ms</p>';
|
||||
|
||||
if (!empty($result['result'])) {
|
||||
echo '<div class="table-wrapper"><table class="data-table"><thead><tr>';
|
||||
foreach (array_keys($result['result'][0]) as $col) {
|
||||
echo '<th>' . htmlspecialchars($col) . '</th>';
|
||||
}
|
||||
echo '</tr></thead><tbody>';
|
||||
foreach ($result['result'] as $row) {
|
||||
echo '<tr>';
|
||||
foreach ($row as $value) {
|
||||
echo '<td>' . ($value === null ? '<span style="color:#999;">NULL</span>' : htmlspecialchars(substr($value, 0, 100))) . '</td>';
|
||||
}
|
||||
echo '</tr>';
|
||||
}
|
||||
echo '</tbody></table></div>';
|
||||
}
|
||||
echo '</div>';
|
||||
} else {
|
||||
echo '<div class="result-error">';
|
||||
echo '<p><strong>Error:</strong> ' . htmlspecialchars($result['message']) . '</p>';
|
||||
if (!empty($result['error'])) {
|
||||
echo '<p class="error-details">' . htmlspecialchars($result['error']) . '</p>';
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.dbmanager-container {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.dbmanager-sidebar {
|
||||
width: 250px;
|
||||
background: #f5f5f5;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.dbmanager-sidebar h3, .dbmanager-sidebar h4 {
|
||||
margin: 0 0 10px 0;
|
||||
font-size: 14px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.db-tree {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0 0 20px 0;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.db-item {
|
||||
padding: 5px 10px;
|
||||
border-radius: 3px;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.db-item:hover {
|
||||
background: #e0e0e0;
|
||||
}
|
||||
|
||||
.db-item.active {
|
||||
background: #007bff;
|
||||
}
|
||||
|
||||
.db-item.active .db-link {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.db-link {
|
||||
text-decoration: none;
|
||||
color: #333;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.query-history {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.history-item {
|
||||
padding: 5px;
|
||||
font-size: 11px;
|
||||
color: #666;
|
||||
cursor: pointer;
|
||||
border-bottom: 1px solid #ddd;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.history-item:hover {
|
||||
background: #e0e0e0;
|
||||
}
|
||||
|
||||
.db-actions {
|
||||
border-top: 1px solid #ddd;
|
||||
padding-top: 15px;
|
||||
}
|
||||
|
||||
.dbmanager-content {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.dbmanager-content h2 {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.sql-editor textarea {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
font-family: 'Consolas', 'Monaco', monospace;
|
||||
font-size: 14px;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 5px;
|
||||
resize: vertical;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.sql-actions {
|
||||
margin-top: 10px;
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.sql-result {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.result-success {
|
||||
background: #d4edda;
|
||||
border: 1px solid #c3e6cb;
|
||||
border-radius: 5px;
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.result-error {
|
||||
background: #f8d7da;
|
||||
border: 1px solid #f5c6cb;
|
||||
border-radius: 5px;
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.execution-time {
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.error-details {
|
||||
font-family: monospace;
|
||||
font-size: 12px;
|
||||
color: #721c24;
|
||||
}
|
||||
|
||||
.table-wrapper {
|
||||
overflow-x: auto;
|
||||
margin-top: 15px;
|
||||
}
|
||||
|
||||
.data-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 12px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.data-table th,
|
||||
.data-table td {
|
||||
padding: 8px;
|
||||
text-align: left;
|
||||
border: 1px solid #ddd;
|
||||
max-width: 200px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.data-table th {
|
||||
background: #f8f9fa;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.btn {
|
||||
display: inline-block;
|
||||
padding: 8px 16px;
|
||||
text-decoration: none;
|
||||
border-radius: 3px;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
border: none;
|
||||
background: #007bff;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
background: #0056b3;
|
||||
}
|
||||
|
||||
.btn-small {
|
||||
padding: 4px 8px;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background: #dc3545;
|
||||
}
|
||||
|
||||
.btn-danger:hover {
|
||||
background: #c82333;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user