Implemented table classes for each webpage.
This commit is contained in:
parent
12e1f06897
commit
b8ba9dc5d4
@ -1,8 +1,11 @@
|
||||
<?php
|
||||
namespace db;
|
||||
|
||||
class Query {
|
||||
private $table_name;
|
||||
private array $columns_querying = array();
|
||||
private int $limit=0;
|
||||
private string $order_by;
|
||||
|
||||
public function __construct(string $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(){
|
||||
$column_string="";
|
||||
|
||||
@ -39,13 +46,21 @@ class Query {
|
||||
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() {
|
||||
$where = "";
|
||||
return $where;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,9 @@
|
||||
<?php
|
||||
require("../Libraries/db/query.php");
|
||||
|
||||
namespace table;
|
||||
$root = $_SERVER['DOCUMENT_ROOT'];
|
||||
include("$root/Libraries/db/query.php");
|
||||
use db\Query;
|
||||
|
||||
class Table_Cell {
|
||||
private $formats = array(
|
||||
@ -62,6 +66,7 @@ class Table_Row {
|
||||
class Table {
|
||||
private Query $query;
|
||||
private $name;
|
||||
private $pretty_name;
|
||||
private $headers;
|
||||
private $rows = array();
|
||||
|
||||
@ -83,6 +88,18 @@ class Table {
|
||||
public function set_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){
|
||||
$res = $db->query($this->query->get_query_string());
|
||||
@ -108,7 +125,7 @@ class Table {
|
||||
}
|
||||
public function get_html(){
|
||||
$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\">";
|
||||
|
||||
foreach ($this->rows as $row){
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
require("class.php");
|
||||
use table\Table;
|
||||
function get_main () {
|
||||
$db = $GLOBALS["db"];
|
||||
/*
|
||||
|
@ -1,9 +1,3 @@
|
||||
<?php
|
||||
include("../Libraries/table/class.php");
|
||||
$db = new SQLite3("../../webcron.db");
|
||||
$table = new Table("crontabs");
|
||||
|
||||
$table->Load($db, "");
|
||||
|
||||
echo $table->get_html();
|
||||
echo $_SERVER['DOCUMENT_ROOT'];
|
||||
?>
|
||||
|
42
crontab.php
42
crontab.php
@ -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>
|
||||
<html>
|
||||
<head>
|
||||
@ -36,28 +41,23 @@
|
||||
<div id="content" class="content cell">
|
||||
</div>
|
||||
|
||||
<div class="double_width_menu_bar bordered_left cell">
|
||||
<div class="wrapper bordered center_text">
|
||||
All Crontabs
|
||||
<div id="log_statistics_table" class="log_table bordered">
|
||||
<div class="table_row">
|
||||
<div class="table_header">Crontab</div> <div class="table_header">Created At</div><div class="table_header">Last Modified</div>
|
||||
</div>
|
||||
<?php
|
||||
$db = new SQLite3('../webcron.db');
|
||||
$res = $db->query("SELECT crontab_path, crontab_created_timestamp, crontab_modified_timestamp FROM crontabs;");
|
||||
<div class="double_width_menu_bar bordered_left cell">
|
||||
<?php
|
||||
$columns = array(
|
||||
'crontab_path AS "Crontab Path"',
|
||||
'crontab_created_timestamp AS "Created At"',
|
||||
'crontab_modified_timestamp AS "Last Modified At"'
|
||||
);
|
||||
$table = new Table("crontabs");
|
||||
$table->set_pretty_name("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>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -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>
|
||||
<!--
|
||||
Color pallet: https://colorhunt.co/palette/b9eddd87cbb9569daa577d86
|
||||
@ -37,6 +43,7 @@
|
||||
</div>
|
||||
|
||||
<div class="double_width_menu_bar bordered_left cell">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
83
index.php
83
index.php
@ -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>
|
||||
<!--
|
||||
Color pallet: https://colorhunt.co/palette/b9eddd87cbb9569daa577d86
|
||||
@ -35,7 +41,6 @@
|
||||
<?php
|
||||
$user=shell_exec("whoami");
|
||||
echo "User: $user<br>";
|
||||
$db = new SQLite3('../webcron.db');
|
||||
$res = $db->querySingle("SELECT COUNT(job_id) FROM job_history;");
|
||||
echo "Job History Entries: $res<br>";
|
||||
$res = $db->querySingle("SELECT COUNT(log_id) FROM logs;");
|
||||
@ -44,61 +49,31 @@
|
||||
</div>
|
||||
|
||||
<div class="double_width_menu_bar bordered_left cell">
|
||||
<div class="wrapper bordered center_text">
|
||||
Log Statistics (This Week)
|
||||
<div id="log_statistics_table" class="log_table bordered">
|
||||
<div class="table_row">
|
||||
<div class="table_header">Level</div>
|
||||
<div class="table_header"># of occurances</div>
|
||||
</div>
|
||||
<?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>
|
||||
<?php
|
||||
$table = new Table("log_statistics_last_7_days");
|
||||
$table->set_pretty_name("Log Statistics (Last 7 Days)");
|
||||
$query = $table->get_query();
|
||||
$table->Load($db);
|
||||
echo $query->get_query_string();
|
||||
echo $table->get_html();
|
||||
|
||||
<div class="wrapper bordered center_text">
|
||||
Script Failures (Last 10)
|
||||
<div id="script_failures" 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>
|
||||
<?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("last_ten_failed_jobs");
|
||||
$table->set_pretty_name("Script Failures (Last 10)");
|
||||
$query = $table->get_query();
|
||||
$table->Load($db);
|
||||
echo $query->get_query_string();
|
||||
echo $table->get_html();
|
||||
|
||||
|
||||
$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>
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
<?php
|
||||
require("Libraries/db/query.php");
|
||||
use db\Query;
|
||||
|
||||
$query = new Query("crontabs");
|
||||
$query->set_limit(-1);
|
||||
|
0
webcron.db
Normal file
0
webcron.db
Normal file
Loading…
Reference in New Issue
Block a user