2023-05-27 17:12:29 +00:00
|
|
|
<?php
|
2023-05-27 19:27:46 +00:00
|
|
|
|
2023-05-27 21:42:36 +00:00
|
|
|
namespace table;
|
2023-05-27 19:27:46 +00:00
|
|
|
require("class.php");
|
2023-05-27 17:12:29 +00:00
|
|
|
function get_main () {
|
|
|
|
$db = $GLOBALS["db"];
|
|
|
|
/*
|
|
|
|
Args will be:
|
|
|
|
name: Table Name
|
|
|
|
limit: number of entries to return (default all)
|
|
|
|
columns: This will be a comma delimited list of column names (in the order that it needs to be displayed)
|
|
|
|
*/
|
|
|
|
|
|
|
|
// BEGIN: Getting Args if exists
|
|
|
|
|
|
|
|
if ( array_key_exists('action', $_GET)){
|
|
|
|
$action=$_GET['action'];
|
|
|
|
} else {
|
|
|
|
$action="show";
|
|
|
|
}
|
|
|
|
|
|
|
|
// END: Getting Args if exists
|
|
|
|
|
2023-05-27 19:27:46 +00:00
|
|
|
switch ($action){
|
|
|
|
case "show":
|
|
|
|
// BEGIN: Get show args
|
|
|
|
if ( ! array_key_exists("name", $_GET) ){
|
|
|
|
echo "A tablename was not provided with the request";
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
$name=$_GET['name'];
|
2023-05-27 19:41:14 +00:00
|
|
|
$table = new Table($name);
|
|
|
|
$query = $table->get_query();
|
2023-05-27 17:12:29 +00:00
|
|
|
}
|
|
|
|
|
2023-05-27 19:27:46 +00:00
|
|
|
if ( array_key_exists("limit", $_GET)){
|
|
|
|
$limit=$_GET['limit'];
|
|
|
|
} else {
|
|
|
|
$limit=0;
|
|
|
|
}
|
2023-05-27 17:12:29 +00:00
|
|
|
|
2023-05-27 19:41:14 +00:00
|
|
|
$query->set_limit($limit);
|
|
|
|
|
2023-05-27 19:27:46 +00:00
|
|
|
if ( array_key_exists("columns", $_GET)){
|
|
|
|
$columns = explode(',', $_GET["columns"]);
|
|
|
|
}
|
2023-05-27 19:41:14 +00:00
|
|
|
|
|
|
|
$query->set_columns($columns);
|
2023-05-27 19:27:46 +00:00
|
|
|
// END: Get show args
|
|
|
|
|
|
|
|
$query_modifier="";
|
|
|
|
if (filter_var($limit, FILTER_VALIDATE_INT)){
|
|
|
|
if ($limit > 0){
|
|
|
|
$query_modifier="WHERE LIMIT $limit";
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
$query_modifier="";
|
2023-05-27 17:12:29 +00:00
|
|
|
}
|
2023-05-27 19:41:14 +00:00
|
|
|
$table->Load($db);
|
|
|
|
$output = $table->get_html();
|
|
|
|
echo $output;
|
2023-05-27 17:12:29 +00:00
|
|
|
|
2023-05-27 19:27:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "list":
|
|
|
|
$res = $db->query("SELECT name FROM sqlite_master WHERE type='table';");
|
2023-05-27 17:12:29 +00:00
|
|
|
while ($row = $res->fetchArray()){
|
|
|
|
echo "<button onclick='getTable(\"{$row['name']}\")'>{$row['name']}</button><br> ";
|
|
|
|
}
|
2023-05-27 19:27:46 +00:00
|
|
|
break;
|
2023-05-27 17:12:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
?>
|