devilbox/.devilbox/www/htdocs/db_pgsql.php

127 lines
3.5 KiB
PHP
Raw Normal View History

2016-11-15 18:39:11 +00:00
<?php require '../config.php'; ?>
<?php loadClass('Helper')->authPage(); ?>
2017-05-15 06:56:17 +00:00
<?php
// Also required for JS calls (see bottom of this page)
$len_table = 4;
$len_size = 9;
?>
2016-11-15 18:39:11 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
2017-05-15 06:56:17 +00:00
<?php echo loadClass('Html')->getHead(); ?>
2016-11-15 18:39:11 +00:00
</head>
<body>
2017-05-15 06:56:17 +00:00
<?php echo loadClass('Html')->getNavbar(); ?>
2016-11-15 18:39:11 +00:00
<div class="container">
<h1>PostgreSQL Databases</h1>
<br/>
<br/>
<div class="row">
<div class="col-md-12">
2017-05-15 06:56:17 +00:00
<?php if (!loadClass('Pgsql')->isAvailable()): ?>
2017-05-08 07:43:43 +00:00
<p>PgSQL container is not running.</p>
<?php else: ?>
<table class="table table-striped ">
<thead class="thead-inverse ">
<tr>
<th>Name</th>
<th>Charset</th>
<th>Collation</th>
<th>Tables</th>
<th>Size</th>
</th>
</thead>
<tbody>
2017-05-15 06:56:17 +00:00
<?php foreach (loadClass('Pgsql')->getDatabases() as $name => $database): ?>
2017-05-08 07:43:43 +00:00
<tr class="table-info">
<th>
<?php echo $name;?>
</th>
<td><?php echo $database['charset'];?></td>
<td><?php echo $database['collation'];?></td>
2016-11-15 18:39:11 +00:00
<td colspan="2"></td>
</tr>
2017-05-08 07:43:43 +00:00
<?php foreach ($database['schemas'] as $schema => $data): ?>
<tr>
<td><?php echo $schema;?></td>
<td colspan="2"></td>
<td><code><span class="table" id="table-<?php echo $name.'-'.$schema;?>"><?php echo str_repeat('&nbsp;', $len_table);?></span></code></td>
<td><code><span class="size" id="size-<?php echo $name.'-'.$schema;?>"><?php echo str_repeat('&nbsp;', $len_size);?></span></code></td>
</tr>
<input type="hidden" name="schema[]" data-database="<?php echo $name;?>" class="schema" value="<?php echo $schema;?>" />
<?php endforeach; ?>
2016-11-15 18:39:11 +00:00
2017-05-08 07:43:43 +00:00
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
2016-11-15 18:39:11 +00:00
</div>
</div>
</div><!-- /.container -->
2017-05-15 06:56:17 +00:00
<?php echo loadClass('Html')->getFooter(); ?>
2016-11-15 18:39:11 +00:00
<script>
// self executing function here
(function() {
// your page initialization code here
// the DOM will be available here
function updateData(database, schema) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
var res = null;
var size = 0;
var tables = 0;
var i;
if (this.readyState == 4 && this.status == 200) {
res = JSON.parse(this.response);
// Normalize size output
size = res.size == 0 ? '0sss MB' : res.size + ' MB';
if (size.length < <?php echo $len_size;?>) {
for (i = size.length; i < <?php echo $len_size;?>; ++i) {
size = '&nbsp;' + size;
}
}
size = size.replace('sss', '&nbsp;&nbsp;&nbsp;');
// Normalize tables output
tables = res.table;
if (tables.length < <?php echo $len_table;?>) {
for (i = tables.length; i < <?php echo $len_table;?>; ++i) {
tables = '&nbsp;' + tables;
}
}
document.getElementById('size-' + database + '-' + schema).innerHTML = size;
document.getElementById('table-' + database + '-' + schema).innerHTML = tables;
}
};
xhttp.open('GET', '_ajax_callback.php?type=postgres&database=' + database + '&schema=' + schema, true);
xhttp.send();
}
var schemas = document.getElementsByName('schema[]');
var schema;
var database;
for (i = 0; i < schemas.length; i++) {
schema = schemas[i].value;
database = schemas[i].getAttribute('data-database');
updateData(database, schema);
}
})();
</script>
</body>
</html>