From: Banana Date: Sun, 13 Oct 2024 08:34:58 +0000 (+0200) Subject: adding individual views X-Git-Url: http://91.132.146.200/gitweb/?a=commitdiff_plain;h=ffbc86c16f29ae1731159607422ba3da461ea60f;p=aranea.git adding individual views Signed-off-by: Banana --- diff --git a/webroot/index.php b/webroot/index.php index 3ffa7cc..d556a99 100644 --- a/webroot/index.php +++ b/webroot/index.php @@ -51,8 +51,8 @@ $ViewMessage = 'view/system/message.php'; # the menu $ViewMenu = 'system/menu.php'; # valid includes -$_validPages["about"] = "about"; - +$_validPages["domains"] = "domains"; +$_validPages["urls"] = "urls"; $_requestMode = "home"; if(isset($_GET['p']) && !empty($_GET['p'])) { diff --git a/webroot/lib/base.class.php b/webroot/lib/base.class.php index aeb998f..f1fdcae 100644 --- a/webroot/lib/base.class.php +++ b/webroot/lib/base.class.php @@ -35,6 +35,14 @@ abstract class Base { */ protected array $_queryOptions; + /** + * The available sort columns. + * Used in query and sort options in FE + * + * @var array|array[] + */ + protected array $_sortOptions = array(); + /** * Set the following options which can be used in DB queries * array( @@ -46,7 +54,7 @@ abstract class Base { * * @param array $options */ - protected function setQueryOptions(array $options): void { + public function setQueryOptions(array $options): void { if(!isset($options['limit'])) $options['limit'] = 20; if(!isset($options['offset'])) $options['offset'] = false; @@ -69,6 +77,15 @@ abstract class Base { $this->_queryOptions = $options; } + /** + * Return the available sort options and the active used one + * + * @return array|array[] + */ + public function getSortOptions(): array { + return $this->_sortOptions; + } + /** * set some defaults by init of the class * diff --git a/webroot/lib/domains.class.php b/webroot/lib/domains.class.php index c551875..003cd93 100644 --- a/webroot/lib/domains.class.php +++ b/webroot/lib/domains.class.php @@ -24,6 +24,17 @@ require_once 'lib/base.class.php'; class Domains extends Base { + /** + * The available sort columns. + * Used in query and sort options in FE + * + * @var array|array[] + */ + public array $_sortOptions = array( + 'default' => array('col' => 'd.url', 'displayText' => 'URL (default)'), + 'created' => array('col' => 'd.created', 'displayText' => 'Created') + ); + /** * Domains constructor. * diff --git a/webroot/lib/management.class.php b/webroot/lib/management.class.php new file mode 100644 index 0000000..aef1cca --- /dev/null +++ b/webroot/lib/management.class.php @@ -0,0 +1,69 @@ +_DB = $databaseConnectionObject; + } + + /** + * Return the data from the stats table + * + * @return array + */ + public function stats(): array { + $ret = array(); + + $queryStr = "SELECT `action`, `value` + FROM `stats` + ORDER BY `action` ASC"; + if(QUERY_DEBUG) Helper::sysLog("[QUERY] ".__METHOD__." query: ".Helper::cleanForLog($queryStr)); + + try { + $query = $this->_DB->query($queryStr); + + if($query !== false && $query->num_rows > 0) { + while(($result = $query->fetch_assoc()) != false) { + $ret[] = $result; + } + } + } + catch (Exception $e) { + Helper::sysLog("[ERROR] ".__METHOD__." mysql catch: ".$e->getMessage()); + } + + return $ret; + } +} diff --git a/webroot/view/domains/domains.inc.php b/webroot/view/domains/domains.inc.php new file mode 100644 index 0000000..9941539 --- /dev/null +++ b/webroot/view/domains/domains.inc.php @@ -0,0 +1,91 @@ + 0, 'currentGetParameters' => array('p' => 'domains')); + +$_curPage = 1; +if(isset($_GET['page']) && !empty($_GET['page'])) { + $_curPage = trim($_GET['page']); + $_curPage = Helper::validate($_curPage,'digit') ? $_curPage : 1; +} + +$_sort = 'default'; +if(isset($_GET['s']) && !empty($_GET['s'])) { + $_sort = trim($_GET['s']); + $_sort = Helper::validate($_sort,'nospace') ? $_sort : 'default'; +} + +$_sortDirection = ''; +if(isset($_GET['sd']) && !empty($_GET['sd'])) { + $_sortDirection = trim($_GET['sd']); + $_sortDirection = Helper::validate($_sortDirection,'nospace') ? $_sortDirection : ''; +} + +$_rpp = RESULTS_PER_PAGE; +if(isset($_GET['rpp']) && !empty($_GET['rpp'])) { + $_rpp = trim($_GET['rpp']); + $_rpp = Helper::validate($_rpp,'digit') ? $_rpp : RESULTS_PER_PAGE; +} + +$queryOptions = array( + 'limit' => $_rpp, + 'offset' => ($_rpp * ($_curPage-1)), + 'sort' => $_sort, + 'sortDirection' => $_sortDirection +); +## pagination end + + + +## pagination +if(!empty($TemplateData['searchresults']['amount'])) { + $TemplateData['pagination']['pages'] = (int)ceil($TemplateData['searchresults']['amount'] / $_rpp); + $TemplateData['pagination']['curPage'] = $_curPage; + + $TemplateData['pagination']['currentGetParameters']['page'] = $_curPage; + $TemplateData['pagination']['currentGetParameters']['s'] = $_sort; + $TemplateData['pagination']['currentGetParameters']['sd'] = $_sortDirection; + $TemplateData['pagination']['currentGetParameters']['rpp'] = $_rpp; + $TemplateData['pagination']['sortOptions'] = $Domains->getSortOptions(); +} + +if($TemplateData['pagination']['pages'] > 11) { + # first pages + $TemplateData['pagination']['visibleRange'] = range(1,3); + # last pages + foreach(range($TemplateData['pagination']['pages']-2, $TemplateData['pagination']['pages']) as $e) { + $TemplateData['pagination']['visibleRange'][] = $e; + } + # pages before and after current page + $cRange = range($TemplateData['pagination']['curPage']-1, $TemplateData['pagination']['curPage']+1); + foreach($cRange as $e) { + $TemplateData['pagination']['visibleRange'][] = $e; + } + $TemplateData['pagination']['currentRangeStart'] = array_shift($cRange); + $TemplateData['pagination']['currentRangeEnd'] = array_pop($cRange); +} +else { + $TemplateData['pagination']['visibleRange'] = range(1,$TemplateData['pagination']['pages']); +} +## pagination end diff --git a/webroot/view/domains/domains.php b/webroot/view/domains/domains.php new file mode 100644 index 0000000..d3af84a --- /dev/null +++ b/webroot/view/domains/domains.php @@ -0,0 +1,19 @@ + +

Domains

diff --git a/webroot/view/home/home.inc.php b/webroot/view/home/home.inc.php index e82abee..aef0373 100644 --- a/webroot/view/home/home.inc.php +++ b/webroot/view/home/home.inc.php @@ -24,5 +24,9 @@ $Domains = new Domains($DB); require_once 'lib/urls.class.php'; $Urls = new Urls($DB); +require_once 'lib/management.class.php'; +$Management = new Management($DB); + $TemplateData['latestDomains'] = $Domains->latest(); $TemplateData['latestUrls'] = $Urls->latest(); +$TemplateData['stats'] = $Management->stats(); diff --git a/webroot/view/home/home.php b/webroot/view/home/home.php index ada5499..b69e5cf 100644 --- a/webroot/view/home/home.php +++ b/webroot/view/home/home.php @@ -19,7 +19,7 @@

Home

-
+

Latest Domains

@@ -42,7 +42,7 @@
-
+

Latest URLs

@@ -65,7 +65,7 @@
-
+

Info

@@ -76,11 +76,12 @@ $value) { + if(!empty($TemplateData['stats'])) { + foreach($TemplateData['stats'] as $k=>$value) { ?> - + + +