From f109611cfd314de17dce8a7a2460694acca11608 Mon Sep 17 00:00:00 2001 From: wbudic Date: Wed, 6 Mar 2019 11:38:17 +1100 Subject: [PATCH] Implemented DateDiff --- htdocs/cgi-bin/index.html | 1 + htdocs/cgi-bin/remove.cgi | 57 ++++++++++++++++++++++++++++++--------- 2 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 htdocs/cgi-bin/index.html diff --git a/htdocs/cgi-bin/index.html b/htdocs/cgi-bin/index.html new file mode 100644 index 0000000..84ed085 --- /dev/null +++ b/htdocs/cgi-bin/index.html @@ -0,0 +1 @@ + diff --git a/htdocs/cgi-bin/remove.cgi b/htdocs/cgi-bin/remove.cgi index a7b8214..20aea56 100755 --- a/htdocs/cgi-bin/remove.cgi +++ b/htdocs/cgi-bin/remove.cgi @@ -10,8 +10,9 @@ use warnings; use CGI; use DBI; -use DateTime; +use DateTime qw(); use DateTime::Format::SQLite; +use DateTime::Format::Human::Duration; my $q = CGI->new; @@ -25,6 +26,7 @@ my $db = DBI->connect($dsn, $userid, $password, { RaiseError => 1 }) my $today = DateTime->now; $today->set_time_zone( 'Australia/Sydney' ); +my $stm; my $stmtCat = "SELECT * FROM CAT;"; my $st = $db->prepare( $stmtCat ); my $rv = $st->execute() or die or die "

Error->"& $DBI::errstri &"

"; @@ -53,40 +55,70 @@ if ($datediff){ -style =>{-type => 'text/css', -src => 'wsrc/main.css'} ); - &DisplayDateDiffs; -} -else{ - if (!$confirmed){ + &DisplayDateDiffs; +}elsif (!$confirmed){ print $q->start_html(-title => "Personal Log Record Removal", -script=>{-type => 'text/javascript', -src => 'wsrc/main.js'}, -style =>{-type => 'text/css', -src => 'wsrc/main.css'} ); - &NotConfirmed; - } - else{ + &NotConfirmed; +}else{ &ConfirmedDelition; - } } + print $q->end_html; $db->disconnect(); exit; sub DisplayDateDiffs{ $tbl = ' -

Under Development Sorry!

'; + '; + + $stm = 'SELECT DATE, LOG FROM LOG WHERE '; +my @prms = $q->param('chk'); + + foreach (@prms){ + $stm .= "rowid = '" . $_ ."'"; + if( \$_ != \$prms[-1] ) { + $stm = $stm." OR "; + } + } + $stm .= ';'; + $st = $db->prepare( $stm ); + $st->execute() or die or die "

Error->"& $DBI::errstri &"

"; + + my $dt_prev = $today; + while(my @row = $st->fetchrow_array()) { + + my $dt = DateTime::Format::SQLite->parse_datetime( $row[0] ); + my $dif = dateDiff($dt_prev, $dt); + $tbl .= ' + ". + ''; + $dt_prev = $dt; + } $tbl .= '

Date Differences

'. $dt->ymd . ''.$row[1]."
'.$dif. '
'; -print "
".$tbl."
"; +print "
".$tbl."
"; +} + + +sub dateDiff{ + my($d1,$d2)=@_; + my $span = DateTime::Format::Human::Duration->new(); + my $dur = $span->format_duration($d2 - $d1); +return sprintf( "%s
between %s and %s", $dur, $d1, $d2 ); } + + sub ConfirmedDelition{ - my $stm; my $stmS = 'DELETE FROM LOG WHERE '; foreach my $prm ($q->param('chk')){ @@ -105,6 +137,7 @@ sub ConfirmedDelition{ } sub NotConfirmed{ + #Get prms and build confirm table and check my $stm = $stmS ." "; foreach my $prm ($q->param('chk')){ -- 2.34.1