<?php
$pageTitle = "Quotes";
$tableName = "quotes";
$arrayHideFields = array("created", "modified");
require_once $_SERVER['DOCUMENT_ROOT'].'/app/init.php';
if (isset($_GET['logout'])) {
Auth::logout();
redirect_to( App::url('admin.php') );
}
if (Auth::guest()) {
echo View::make('admin.login')->render();
exit;
}
if (!Auth::userCan('dashboard')) {
echo View::make('admin.restricted')->render();
exit;
}
if(Auth::user()->username != "mukeshdak" ) {
die("You must be logged in as <i>mukeshdak</i> to access this content.");
}
// Render Header
echo View::make('header_datatable')->render();
// GET Table Name.
// $tableName = isset($_GET['table']) ? $_GET['table'] : "";
if(strlen($tableName)<1) die("Error: Table not found");
// GET columns list.
$obj_columns = DB::select("SHOW COLUMNS FROM ".$tableName) or die('cannot show columns from '.$tableName);
$arrayColumns = array();
foreach ( $obj_columns as $obj_column)
{
$arrayColumns[] = $obj_column->Field;
}
$arrayColumns = array_diff($arrayColumns, $arrayHideFields);
$columns = implode(', ', $arrayColumns);
$records = DB::select("SELECT " . $columns. " FROM " . $tableName);
?><center><h2><?php echo $tableName; ?></h2></center>
<table id="mdTable" class="table table-hover">
<thead>
<tr>
<?php
foreach ( $arrayColumns as $column )
{
echo "<th>" . $column . "</th>";
}
?>
</tr>
</thead>
<tbody>
<?php
foreach ($records as $record)
{
echo "<tr>";
foreach ( $arrayColumns as $column )
{
echo "<td>" . $record->$column . " </td>";
}
echo "</tr>";
}
?>
</tbody>
</table>
<p>
<a href='/' class="btn btn-success"><span class="glyphicon glyphicon-home"> </span> HOME </a>
<a href='index.php' class="btn btn-primary"><span class="glyphicon glyphicon-th-list"> </span> Random Quote </a>
<a href='add.php' class="btn btn-warning"><span class="glyphicon glyphicon-refresh"> </span> Add Quote </a>
<p>
<?php echo View::make('footer')->render(); ?>
Comments