From 9ff758f28dd04ad50e1577484fb810a6fb9439cd Mon Sep 17 00:00:00 2001 From: wbudic Date: Sun, 14 Oct 2018 19:39:46 +1100 Subject: [PATCH] Checking implemented for navigation buttons if top or end of table --- htdocs/cgi-bin/main.cgi | 64 ++++++++++++++++++++---------------- htdocs/cgi-bin/remove.cgi | 2 +- htdocs/cgi-bin/wsrc/main.css | 4 +-- 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/htdocs/cgi-bin/main.cgi b/htdocs/cgi-bin/main.cgi index 7c61224..39f61b9 100755 --- a/htdocs/cgi-bin/main.cgi +++ b/htdocs/cgi-bin/main.cgi @@ -24,7 +24,7 @@ my $dbh = DBI->connect($dsn, $userid, $password, { RaiseError => 1 }) #SETTINGS HERE! -my $REC_LIMIT = 0; +my $REC_LIMIT = 25; my $TIME_ZONE = 'Australia/Sydney'; #END OF SETTINGS @@ -75,6 +75,8 @@ my $tbl_rc_prev = 0; my $tbl_cur_id; +my $rs_prev = $q->param('rs_prev'); +my $rs_cur = $q->param('rs_cur'); ############### &processSubmit; @@ -82,7 +84,7 @@ my $tbl_cur_id; # # Enable to see main query statement issued! # -# print "### -> ".$stmt; + print "### -> ".$stmt; # # @@ -96,7 +98,18 @@ if($rv < 0) { my $tfId = 0; my $id = 0; -my $rs_prev = $q->param('rs_prev'); +my $tbl_start = index $stmt, "<="; + +if($tbl_start>0){ + #check if we are at the beggining of the LOG table? + + my $sthc = $dbh->prepare('select rowid from LOG order by rowid DESC LIMIT 1;'); + $sthc->execute(); + my @row =$sthc->fetchrow_array(); + if($row[0] == $rs_prev && $rs_cur == $rs_prev){ + $tbl_start = -1; + } +} while(my @row = $sth->fetchrow_array()) { @@ -122,16 +135,16 @@ my $rs_prev = $q->param('rs_prev'); $tfId = 1; } - $tbl = $tbl . ''. - $dt->ymd . '' . - '' . $dt->hms . "" . '' . $log . ''. + $tbl = $tbl . ''. $dt->ymd . ''. + '' . $dt->hms . "" . + '' . $log . ''. '' . $amm .''. '' . $ct .''. ' - '; + + '; $tbl_rc += 1; if($REC_LIMIT>0 && $tbl_rc==$REC_LIMIT){ @@ -141,9 +154,14 @@ my $rs_prev = $q->param('rs_prev'); } } - #End of record set? + #End of table? if($rs_prev && $tbl_rc < $REC_LIMIT){ - &buildNavigationButtons(1); + $sth = $dbh->prepare( "SELECT count(*) FROM LOG;" ); + $sth->execute(); + my @row = $sth->fetchrow_array(); + if($row[0]>$REC_LIMIT){ + &buildNavigationButtons(1); + } } if($tbl_rc==0){ @@ -162,7 +180,7 @@ my $frm = qq( Date:hms . qq(">Category: - Log: + Log: ).$cats.qq( Ammount: @@ -191,12 +209,9 @@ exit; 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! @@ -210,7 +225,7 @@ sub buildNavigationButtons{ $tbl = $tbl . '†'; - if($rs_prev && $rs_prev>0){ + if($rs_prev && $rs_prev>0 && $tbl_start>0){ $tbl = $tbl . ' Top'; + $tbl = $tbl .'Top'.$tbl_start; } @@ -235,10 +250,7 @@ sub buildNavigationButtons{ } - $tbl = $tbl .''; - # - #END OF UNDER DEVELOPMENT! - # + $tbl = $tbl .''; } sub processSubmit { @@ -273,16 +285,10 @@ try{ } if($view_mode && $view_mode == "1"){ - # - #UNDER DEVELOPMENT - # - - my $rs = $q->param("rs_cur"); - my $rs_prev = $q->param("rs_prev"); - if($rs){ + if($rs_cur){ $stmt = 'SELECT rowid, ID_CAT, DATE, LOG, AMMOUNT from LOG - where rowid <= "'.$rs.'" ORDER BY rowid DESC, DATE DESC;'; + where rowid <= "'.$rs_cur.'" ORDER BY rowid DESC, DATE DESC;'; return; } } diff --git a/htdocs/cgi-bin/remove.cgi b/htdocs/cgi-bin/remove.cgi index 658d01d..e04c26e 100755 --- a/htdocs/cgi-bin/remove.cgi +++ b/htdocs/cgi-bin/remove.cgi @@ -129,6 +129,6 @@ if($r_cnt>1){ '; -print '
' . $tbl .'
'; +print '
' . $tbl .'
'; } diff --git a/htdocs/cgi-bin/wsrc/main.css b/htdocs/cgi-bin/wsrc/main.css index 3f977c5..48e6af7 100644 --- a/htdocs/cgi-bin/wsrc/main.css +++ b/htdocs/cgi-bin/wsrc/main.css @@ -12,13 +12,13 @@ p { table, th, td{ border-collapse: collapse; - width: 680px; + width: 740px; padding-bottom: 5px; } div{ - width: 700px; + width: 740px; text-align: center; vertical-align: middle; } -- 2.34.1