Advertisement
reenadak

display datatable using easy login pro

Oct 29th, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.09 KB | None | 0 0
  1. <?php
  2.  
  3.     $pageTitle = "Quotes";
  4.     $tableName = "quotes";
  5.     $arrayHideFields = array("created", "modified");
  6.  
  7.  
  8. require_once $_SERVER['DOCUMENT_ROOT'].'/app/init.php';
  9.  
  10. if (isset($_GET['logout'])) {
  11.   Auth::logout();
  12.   redirect_to( App::url('admin.php') );
  13. }
  14.  
  15. if (Auth::guest()) {
  16.   echo View::make('admin.login')->render();
  17.   exit;
  18. }
  19.  
  20. if (!Auth::userCan('dashboard')) {
  21.   echo View::make('admin.restricted')->render();
  22.   exit;
  23. }
  24.  
  25. if(Auth::user()->username != "mukeshdak" ) {
  26.   die("You must be logged in as <i>mukeshdak</i> to access this content.");
  27. }
  28.  
  29. // Render Header
  30. echo View::make('header_datatable')->render();
  31.  
  32.  
  33. // GET Table Name.
  34. // $tableName = isset($_GET['table']) ? $_GET['table'] : "";
  35. if(strlen($tableName)<1) die("Error: Table not found");
  36.  
  37.  
  38. // GET columns list.
  39. $obj_columns = DB::select("SHOW COLUMNS FROM ".$tableName) or die('cannot show columns from '.$tableName);
  40.  
  41. $arrayColumns = array();
  42.  
  43. foreach ( $obj_columns as $obj_column)
  44. {
  45.     $arrayColumns[] = $obj_column->Field;
  46. }
  47.  
  48. $arrayColumns = array_diff($arrayColumns, $arrayHideFields);
  49.  
  50. $columns = implode(', ', $arrayColumns);
  51.  
  52. $records = DB::select("SELECT " . $columns. " FROM " . $tableName);
  53.  
  54. ?><center><h2><?php echo $tableName; ?></h2></center>
  55. <table id="mdTable" class="table table-hover">
  56.     <thead>
  57.         <tr>
  58.             <?php
  59.                 foreach ( $arrayColumns as $column )
  60.                 {
  61.                     echo "<th>" . $column . "</th>";
  62.                 }
  63.             ?>
  64.         </tr>
  65.     </thead>
  66.     <tbody>
  67.         <?php
  68.  
  69.             foreach ($records as $record)
  70.             {
  71.                 echo "<tr>";
  72.  
  73.                 foreach ( $arrayColumns as $column )
  74.                 {
  75.                     echo "<td>" . $record->$column . " </td>";
  76.                 }
  77.  
  78.                 echo "</tr>";                
  79.             }          
  80.         ?>
  81.     </tbody>
  82.     </table>
  83.  
  84.      <p>
  85.         <a href='/' class="btn btn-success"><span class="glyphicon glyphicon-home"> </span> HOME </a>
  86.         <a href='index.php' class="btn btn-primary"><span class="glyphicon glyphicon-th-list"> </span> Random Quote </a>
  87.         <a href='add.php' class="btn btn-warning"><span class="glyphicon glyphicon-refresh"> </span>  Add Quote </a>
  88.      <p>
  89.  
  90. <?php echo View::make('footer')->render(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement