From 2fcc20ee4a4a9892874ee7818f572525888b0062 Mon Sep 17 00:00:00 2001 From: wbudic Date: Fri, 12 Oct 2018 17:12:08 +1100 Subject: [PATCH] Added error checking, and subroutined navigation buttons. --- htdocs/cgi-bin/main.cgi | 105 +++++++++++++++++++++++++--------------- 1 file changed, 66 insertions(+), 39 deletions(-) diff --git a/htdocs/cgi-bin/main.cgi b/htdocs/cgi-bin/main.cgi index e3ce1a2..e3b0183 100755 --- a/htdocs/cgi-bin/main.cgi +++ b/htdocs/cgi-bin/main.cgi @@ -2,6 +2,7 @@ use strict; use warnings; +use Try::Tiny; use CGI; use DBI; @@ -77,9 +78,9 @@ my $tbl_cur_id; &processSubmit; ############### # - # Enable to see main query statment issued! + # Enable to see main query statement issued! # -# print "### -> ".$stmt; + print "### -> ".$stmt; # # @@ -92,10 +93,12 @@ if($rv < 0) { } my $tfId = 0; +my $id = 0; +my $rs_prev = $q->param('rs_prev'); while(my @row = $sth->fetchrow_array()) { - my $id = $row[0]; + $id = $row[0]; my $ct = $hshCats{@row[1]}; my $dt = DateTime::Format::SQLite->parse_datetime( $row[2] ); my $log = $row[3]; @@ -127,47 +130,17 @@ my $tfId = 0; $tbl_rc += 1; if($REC_LIMIT>0 && $tbl_rc==$REC_LIMIT){ - # - #UNDER DEVELOPMENT! - # - if(!$tbl_cur_id){ - #Following is a quick hack as previous id as current minus one might not coincide in the database table! - $tbl_cur_id = $id-1; - } - if($tfId==1){ - $tfId = 0; - }else{ - $tfId = 1; - } - - $tbl = $tbl . '†'; - - my $rs_prev = $q->param('rs_prev'); - if($rs_prev && $rs_prev>0){ - - $tbl = $tbl . ' - '; - - }else{ - $tbl = $tbl .'Top'; - } - - - $tbl = $tbl .''; - $tbl = $tbl . ''; - - $tbl = $tbl .''; + &buildNavigationButtons; last; - # - #END OF UNDER DEVELOPMENT! - # } } + #End of record set? + if($rs_prev && $tbl_rc < $REC_LIMIT){ + &buildNavigationButtons(1); + } + if($tbl_rc==0){ $tbl = $tbl . "Database is New or Empty!\n"; } @@ -208,6 +181,60 @@ $sth->finish; $dbh->disconnect(); exit; +### CGI END + + +sub buildNavigationButtons{ + # + #UNDER DEVELOPMENT! + # + my $is_end_of_rs = shift; + + + if(!$tbl_cur_id){ + #Following is a quick hack as previous id as current minus one might not + #coincide in the database table! + $tbl_cur_id = $id-1; + } + if($tfId==1){ + $tfId = 0; + }else{ + $tfId = 1; + } + + $tbl = $tbl . '†'; + + if($rs_prev && $rs_prev>0){ + + $tbl = $tbl . ' + '; + + } + else{ + $tbl = $tbl .'Top'; + } + + + $tbl = $tbl .''; + + if($is_end_of_rs == 1){ + $tbl = $tbl .'End'; + } + else{ + + $tbl = $tbl . ''; + + } + + $tbl = $tbl .''; + # + #END OF UNDER DEVELOPMENT! + # +} + sub processSubmit { -- 2.34.1