diff --git a/Libraries/table/get.php b/Libraries/table/get.php new file mode 100644 index 0000000..f38acad --- /dev/null +++ b/Libraries/table/get.php @@ -0,0 +1,95 @@ + 0){ + $query_modifier="WHERE LIMIT $limit"; + } + }else { + $query_modifier=""; + } + + $db = new SQLite3("../../webcron.db"); + + $res = $db->query("SELECT * FROM $name $query_modifier"); + echo '
'; + echo '
'; + echo '
'; + + if ( !empty($columns) ) { + foreach($columns as $column_name){ + echo "
{$column_name}
"; + } + } else { + $counter=0; + for ($i = 0; $i < $res->numColumns(); $i++ ){ + echo "
{$res->columnName($i)}
"; + $counter++; + } + } + + + 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 '
'; + } else if ($action == "list"){ + $res = $db->query("SELECT name FROM sqlite_master WHERE type='table';"); + + while ($row = $res->fetchArray()){ + echo "
"; + } + } + +} +?> \ No newline at end of file diff --git a/Libraries/test.php b/Libraries/test.php new file mode 100644 index 0000000..a6ecb0c --- /dev/null +++ b/Libraries/test.php @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/api/table.php b/api/table.php index 10560c4..04d9518 100644 --- a/api/table.php +++ b/api/table.php @@ -1,94 +1,28 @@ : + - + +GET: + - show (show individual tables) + - list (list table names) -Args will be: - action: - list: list table names - 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) */ -$db = new SQLite3("../../webcron.db"); +require('../Libraries/table/get.php'); -if ( array_key_exists('action', $_GET)){ - $action=$_GET['action']; -} else { - $action="show"; + +# Setting up DB connection +$GLOBALS['db'] = new SQLite3("../../webcron.db"); + +switch ($_SERVER['REQUEST_METHOD']) { + case 'GET': + get_main(); + break; + case 'POST': + break; } - -if ($action == "show"){ - if ( ! array_key_exists("name", $_GET) ){ - echo "A tablename was not provided with the request"; - return 1; - } else { - $name=$_GET['name']; - } - - if ( array_key_exists("limit", $_GET)){ - $limit=$_GET['limit']; - } else { - $limit=0; - } - - if ( array_key_exists("columns", $_GET)){ - $columns = explode(',', $_GET["columns"]); - } - - $query_modifier=""; - if (filter_var($limit, FILTER_VALIDATE_INT)){ - if ($limit > 0){ - $query_modifier="WHERE LIMIT $limit"; - } - }else { - $query_modifier=""; - } - - $db = new SQLite3("../../webcron.db"); - - $res = $db->query("SELECT * FROM $name $query_modifier"); - echo '
'; - echo '
'; - echo '
'; - - if ( !empty($columns) ) { - foreach($columns as $column_name){ - echo "
{$column_name}
"; - } - } else { - $counter=0; - for ($i = 0; $i < $res->numColumns(); $i++ ){ - echo "
{$res->columnName($i)}
"; - $counter++; - } - } - - - 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 '
'; -} else if ($action == "list"){ - $res = $db->query("SELECT name FROM sqlite_master WHERE type='table';"); - - while ($row = $res->fetchArray()){ - echo "
"; - } -} - + ?> \ No newline at end of file diff --git a/api/test.php b/api/test.php index 462e647..88c5d49 100644 --- a/api/test.php +++ b/api/test.php @@ -1,5 +1,6 @@