diff --git a/Libraries/table/class.php b/Libraries/table/class.php
new file mode 100644
index 0000000..60eed09
--- /dev/null
+++ b/Libraries/table/class.php
@@ -0,0 +1,117 @@
+ "
";
+
+ foreach ($this->cells as $cell){
+ $output="{$output}{$cell->get_html()}";
+ }
+
+ $output="{$output}
";
+ return $output;
+ }
+
+}
+
+class Table {
+ private $name;
+ private $headers;
+ private $rows = array();
+
+ public function __construct($name){
+ $this->set_name($name);
+ }
+
+ private function add_row(){
+ $row = new Table_Row();
+ array_push($this->rows, $row);
+ return $row;
+ }
+
+ public function set_name($name){
+ $this->name = $name;
+ }
+
+ public function Load($db, $query_modifier){
+ $res = $db->query("SELECT * FROM $this->name $query_modifier");
+
+ // Getting header row
+ $col_count=0;
+ $header_row = $this->add_row();
+
+ for ($i = 0; $i < $res->numColumns(); $i++ ){
+ $value = $res->columnName($i);
+ $header_row->add_cell($value, "Header");
+ $col_count++;
+ }
+
+ while ($db_row = $res->fetchArray()){
+ $row = $this->add_row();
+
+ for ($i = 0; $i < $col_count; $i++){
+ $value = $db_row[$i];
+ $row->add_cell($value, "Normal");
+ }
+ }
+ }
+ public function get_html(){
+ $output="";
+ $output="{$output}';
- echo '
';
- echo '
';
+ if ( array_key_exists("columns", $_GET)){
+ $columns = explode(',', $_GET["columns"]);
+ }
+ // END: Get show args
- if ( !empty($columns) ) {
- foreach($columns as $column_name){
- echo "";
- }
- } else {
- $counter=0;
- for ($i = 0; $i < $res->numColumns(); $i++ ){
- echo "";
- $counter++;
- }
+ $query_modifier="";
+ if (filter_var($limit, FILTER_VALIDATE_INT)){
+ if ($limit > 0){
+ $query_modifier="WHERE LIMIT $limit";
+ }
+ }else {
+ $query_modifier="";
}
-
- echo '
';
- while ($row = $res->fetchArray()){
- echo "
";
-
+ $res = $db->query("SELECT * FROM $name $query_modifier");
+ echo '
';
+ echo '
';
+ echo '
';
if ( !empty($columns) ) {
foreach($columns as $column_name){
- echo "
{$row[$column_name]}
";
+ echo "";
}
} else {
- for ($i = 0; $i < $counter; $i++){
- echo "
{$row[$i]}
";
+ $counter=0;
+ for ($i = 0; $i < $res->numColumns(); $i++ ){
+ echo "";
+ $counter++;
}
}
- echo "
";
- }
- echo '
';
- echo '
';
- } else if ($action == "list"){
- $res = $db->query("SELECT name FROM sqlite_master WHERE type='table';");
+ echo '
';
+ while ($row = $res->fetchArray()){
+ echo "
";
+ if ( !empty($columns) ) {
+ foreach($columns as $column_name){
+ echo "
{$row[$column_name]}
";
+ }
+ } else {
+ for ($i = 0; $i < $counter; $i++){
+ echo "
{$row[$i]}
";
+ }
+ }
+ echo "
";
+ }
+ echo '
';
+ echo '
';
+ break;
+
+ case "list":
+ $res = $db->query("SELECT name FROM sqlite_master WHERE type='table';");
while ($row = $res->fetchArray()){
echo "