Implemented table classes for each webpage.

This commit is contained in:
Tristan Ancelet 2023-05-27 15:53:50 -05:00
parent 12e1f06897
commit b8ba9dc5d4
9 changed files with 95 additions and 85 deletions

View File

@ -1,8 +1,11 @@
<?php <?php
namespace db;
class Query { class Query {
private $table_name; private $table_name;
private array $columns_querying = array(); private array $columns_querying = array();
private int $limit=0; private int $limit=0;
private string $order_by;
public function __construct(string $table_name){ public function __construct(string $table_name){
$this->table_name = $table_name; $this->table_name = $table_name;
@ -19,6 +22,10 @@ class Query {
} }
} }
public function set_order_by_column (string $order_by){
$this->order_by = $order_by;
}
private function get_columns(){ private function get_columns(){
$column_string=""; $column_string="";
@ -39,13 +46,21 @@ class Query {
return $modifier; return $modifier;
} }
private function get_order_by(){
$order_by="";
if (!empty($this->order_by)){
$order_by=" ORDER BY {$this->order_by}";
}
return $order_by;
}
private function get_where() { private function get_where() {
$where = ""; $where = "";
return $where; return $where;
} }
public function get_query_string(){ public function get_query_string(){
$query = "SELECT {$this->get_columns()} FROM {$this->table_name}{$this->get_where()}{$this->get_limit()};"; $query = "SELECT {$this->get_columns()} FROM {$this->table_name}{$this->get_where()}{$this->get_order_by()}{$this->get_limit()};";
return $query; return $query;
} }

View File

@ -1,5 +1,9 @@
<?php <?php
require("../Libraries/db/query.php");
namespace table;
$root = $_SERVER['DOCUMENT_ROOT'];
include("$root/Libraries/db/query.php");
use db\Query;
class Table_Cell { class Table_Cell {
private $formats = array( private $formats = array(
@ -62,6 +66,7 @@ class Table_Row {
class Table { class Table {
private Query $query; private Query $query;
private $name; private $name;
private $pretty_name;
private $headers; private $headers;
private $rows = array(); private $rows = array();
@ -83,6 +88,18 @@ class Table {
public function set_name($name){ public function set_name($name){
$this->name = $name; $this->name = $name;
} }
public function set_pretty_name(string $pretty_name){
$this->pretty_name = $pretty_name;
}
public function get_pretty_name(){
$output=$this->name;
if (!empty($this->pretty_name)){
$output=$this->pretty_name;
}
return $output;
}
public function Load($db){ public function Load($db){
$res = $db->query($this->query->get_query_string()); $res = $db->query($this->query->get_query_string());
@ -108,7 +125,7 @@ class Table {
} }
public function get_html(){ public function get_html(){
$output=""; $output="";
$output="{$output}<div class=\"wrapper bordered center_text\">"; $output="{$output}<div class=\"wrapper bordered center_text\">{$this->get_pretty_name()}";
$output="{$output}<div class=\"log_table bordered\">"; $output="{$output}<div class=\"log_table bordered\">";
foreach ($this->rows as $row){ foreach ($this->rows as $row){

View File

@ -1,6 +1,7 @@
<?php <?php
require("class.php"); require("class.php");
use table\Table;
function get_main () { function get_main () {
$db = $GLOBALS["db"]; $db = $GLOBALS["db"];
/* /*

View File

@ -1,9 +1,3 @@
<?php <?php
include("../Libraries/table/class.php"); echo $_SERVER['DOCUMENT_ROOT'];
$db = new SQLite3("../../webcron.db");
$table = new Table("crontabs");
$table->Load($db, "");
echo $table->get_html();
?> ?>

View File

@ -1,4 +1,9 @@
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
require "$root/Libraries/table/class.php";
use table\Table;
$db = new SQLite3("../webcron.db");
?>
<!Doctype html> <!Doctype html>
<html> <html>
<head> <head>
@ -36,28 +41,23 @@
<div id="content" class="content cell"> <div id="content" class="content cell">
</div> </div>
<div class="double_width_menu_bar bordered_left cell"> <div class="double_width_menu_bar bordered_left cell">
<div class="wrapper bordered center_text"> <?php
All Crontabs $columns = array(
<div id="log_statistics_table" class="log_table bordered"> 'crontab_path AS "Crontab Path"',
<div class="table_row"> 'crontab_created_timestamp AS "Created At"',
<div class="table_header">Crontab</div> <div class="table_header">Created At</div><div class="table_header">Last Modified</div> 'crontab_modified_timestamp AS "Last Modified At"'
</div> );
<?php $table = new Table("crontabs");
$db = new SQLite3('../webcron.db'); $table->set_pretty_name("Crontabs");
$res = $db->query("SELECT crontab_path, crontab_created_timestamp, crontab_modified_timestamp FROM crontabs;"); $query = $table->get_query();
$query->set_columns($columns);
$table->Load($db);
echo $table->get_html();
?>
while ($row = $res->fetchArray()){
echo "<div class=\"table_row\">";
echo "<div class=\"table_cell\">{$row['crontab_path']}</div> <div class=\"table_cell\">{$row['crontab_created_timestamp']}</div><div class=\"table_cell\">{$row['crontab_modified_timestamp']}</div>";
echo "</div>";
}
?>
</div>
</div>
</div>
</div> </div>
</div>
</body> </body>
</html> </html>

View File

@ -1,3 +1,9 @@
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
require "$root/Libraries/table/class.php";
use table\Table;
$db = new SQLite3("../webcron.db");
?>
<!Doctype html> <!Doctype html>
<!-- <!--
Color pallet: https://colorhunt.co/palette/b9eddd87cbb9569daa577d86 Color pallet: https://colorhunt.co/palette/b9eddd87cbb9569daa577d86
@ -37,6 +43,7 @@
</div> </div>
<div class="double_width_menu_bar bordered_left cell"> <div class="double_width_menu_bar bordered_left cell">
</div> </div>
</div> </div>

View File

@ -1,3 +1,9 @@
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
require "$root/Libraries/table/class.php";
use table\Table;
$db = new SQLite3("../webcron.db");
?>
<!Doctype html> <!Doctype html>
<!-- <!--
Color pallet: https://colorhunt.co/palette/b9eddd87cbb9569daa577d86 Color pallet: https://colorhunt.co/palette/b9eddd87cbb9569daa577d86
@ -35,7 +41,6 @@
<?php <?php
$user=shell_exec("whoami"); $user=shell_exec("whoami");
echo "User: $user<br>"; echo "User: $user<br>";
$db = new SQLite3('../webcron.db');
$res = $db->querySingle("SELECT COUNT(job_id) FROM job_history;"); $res = $db->querySingle("SELECT COUNT(job_id) FROM job_history;");
echo "Job History Entries: $res<br>"; echo "Job History Entries: $res<br>";
$res = $db->querySingle("SELECT COUNT(log_id) FROM logs;"); $res = $db->querySingle("SELECT COUNT(log_id) FROM logs;");
@ -44,61 +49,31 @@
</div> </div>
<div class="double_width_menu_bar bordered_left cell"> <div class="double_width_menu_bar bordered_left cell">
<div class="wrapper bordered center_text"> <?php
Log Statistics (This Week) $table = new Table("log_statistics_last_7_days");
<div id="log_statistics_table" class="log_table bordered"> $table->set_pretty_name("Log Statistics (Last 7 Days)");
<div class="table_row"> $query = $table->get_query();
<div class="table_header">Level</div> $table->Load($db);
<div class="table_header"># of occurances</div> echo $query->get_query_string();
</div> echo $table->get_html();
<?php
$db = new SQLite3('../webcron.db');
$res = $db->query("SELECT * FROM log_statistics_last_7_days;");
while ($row = $res->fetchArray()){
echo "<div class='table_row'>";
echo "<div class='table_cell'>{$row['log_level_name']}</div> <div class='table_cell'>{$row['count']}</div>";
echo "</div>";
}
?>
</div>
</div>
<div class="wrapper bordered center_text"> $table = new Table("last_ten_failed_jobs");
Script Failures (Last 10) $table->set_pretty_name("Script Failures (Last 10)");
<div id="script_failures" class="log_table"> $query = $table->get_query();
<div class="table_row"> $table->Load($db);
<div class="table_header">Date/Time</div> <div class="table_header">Script</div> <div class="table_header">Exit Code</div> echo $query->get_query_string();
</div> echo $table->get_html();
<?php
$db = new SQLite3('../webcron.db');
$res = $db->query("SELECT * FROM last_ten_failed_jobs;");
while ($row = $res->fetchArray()){
echo "<div class='table_row'>";
echo "<div class='table_cell'>{$row['job_timestamp']}</div> <div class='table_cell'>{$row['job_source']}</div><div class='table_cell'>{$row['job_exit_code']}</div>";
echo "</div>";
}
?>
</div>
</div>
<div class="wrapper bordered center_text">
Jobs Run (Last 10)
<div id="jobs_run_table" class="log_table">
<div class="table_row">
<div class="table_header">Date/Time</div> <div class="table_header">Script</div> <div class="table_header">Exit Code</div> <div class="table_header">Job Result</div>
</div>
<?php
$db = new SQLite3('../webcron.db');
$res = $db->query("SELECT * FROM job_history ORDER BY job_timestamp DESC LIMIT 10;");
while ($row = $res->fetchArray()){
echo "<div class='table_row'>";
echo "<div class='table_cell'>{$row['job_timestamp']}</div> <div class='table_cell'>{$row['job_source']}</div><div class='table_cell'>{$row['job_exit_code']}</div><div class='table_cell'>{$row['job_result']}</div>";
echo "</div>";
}
?>
</div>
</div>
$table = new Table("job_history");
$table->set_pretty_name("Jobs Run (Last 10)");
$query = $table->get_query();
$query->set_order_by_column("job_timestamp DESC");
$query->set_limit(10);
$table->Load($db);
echo $query->get_query_string();
echo $table->get_html();
?>
</div> </div>
</div> </div>

View File

@ -2,6 +2,7 @@
<?php <?php
require("Libraries/db/query.php"); require("Libraries/db/query.php");
use db\Query;
$query = new Query("crontabs"); $query = new Query("crontabs");
$query->set_limit(-1); $query->set_limit(-1);

0
webcron.db Normal file
View File