From 1d1a600b1efb98fbcb2baa49c8c79fda10a5e55a Mon Sep 17 00:00:00 2001 From: Metabox Date: Thu, 16 May 2019 20:36:26 +1000 Subject: [PATCH] Subrotined fetchAutowords bug fixes. --- .../cgisess_2e753ef24d72c03527610d2b71321ecb | 1 + .../cgisess_5786940189f56ba90775b375015031a0 | 1 + .../cgisess_6cd3d053557d46298a1fbaa7d054b402 | 1 + .../cgisess_6e1acbdb23deb67566251ee45a9d5904 | 1 + .../cgisess_7dcd14aff3b905fd46843d20c85dc47c | 1 + .../cgisess_ab26eaf0df06205e2e479dd9e73e2a5e | 1 + .../cgisess_b03f7e44a56d832aca12b2d0d9885dc5 | 1 + .../cgisess_e01dfa0dd28affb0d00b72bfff0ff303 | 1 + .../cgisess_e0bd04e8964c3adabaa754ad2fc1a286 | 1 + .../cgisess_e373ebf22622cc8b85b94edab5974e30 | 1 + .../cgisess_e50018bbed297ea9dce239beac458c17 | 1 + htdocs/cgi-bin/main.cgi | 172 +++++++++++------- htdocs/cgi-bin/wsrc/main.js | 23 ++- 13 files changed, 129 insertions(+), 77 deletions(-) create mode 100644 dbLifeLog/cgisess_2e753ef24d72c03527610d2b71321ecb create mode 100644 dbLifeLog/cgisess_5786940189f56ba90775b375015031a0 create mode 100644 dbLifeLog/cgisess_6cd3d053557d46298a1fbaa7d054b402 create mode 100644 dbLifeLog/cgisess_6e1acbdb23deb67566251ee45a9d5904 create mode 100644 dbLifeLog/cgisess_7dcd14aff3b905fd46843d20c85dc47c create mode 100644 dbLifeLog/cgisess_ab26eaf0df06205e2e479dd9e73e2a5e create mode 100644 dbLifeLog/cgisess_b03f7e44a56d832aca12b2d0d9885dc5 create mode 100644 dbLifeLog/cgisess_e01dfa0dd28affb0d00b72bfff0ff303 create mode 100644 dbLifeLog/cgisess_e0bd04e8964c3adabaa754ad2fc1a286 create mode 100644 dbLifeLog/cgisess_e373ebf22622cc8b85b94edab5974e30 create mode 100644 dbLifeLog/cgisess_e50018bbed297ea9dce239beac458c17 diff --git a/dbLifeLog/cgisess_2e753ef24d72c03527610d2b71321ecb b/dbLifeLog/cgisess_2e753ef24d72c03527610d2b71321ecb new file mode 100644 index 0000000..e9db19b --- /dev/null +++ b/dbLifeLog/cgisess_2e753ef24d72c03527610d2b71321ecb @@ -0,0 +1 @@ +$D = {'_SESSION_REMOTE_ADDR' => '127.0.0.1','_SESSION_ID' => '2e753ef24d72c03527610d2b71321ecb','_SESSION_CTIME' => 1557983572,'_SESSION_ATIME' => 1557983572};;$D \ No newline at end of file diff --git a/dbLifeLog/cgisess_5786940189f56ba90775b375015031a0 b/dbLifeLog/cgisess_5786940189f56ba90775b375015031a0 new file mode 100644 index 0000000..dc3bf48 --- /dev/null +++ b/dbLifeLog/cgisess_5786940189f56ba90775b375015031a0 @@ -0,0 +1 @@ +$D = {'_SESSION_ID' => '5786940189f56ba90775b375015031a0','_SESSION_REMOTE_ADDR' => '127.0.0.1','_SESSION_CTIME' => 1557987147,'_SESSION_ATIME' => 1557987147};;$D \ No newline at end of file diff --git a/dbLifeLog/cgisess_6cd3d053557d46298a1fbaa7d054b402 b/dbLifeLog/cgisess_6cd3d053557d46298a1fbaa7d054b402 new file mode 100644 index 0000000..5df0ddb --- /dev/null +++ b/dbLifeLog/cgisess_6cd3d053557d46298a1fbaa7d054b402 @@ -0,0 +1 @@ +$D = {'_SESSION_REMOTE_ADDR' => '127.0.0.1','_SESSION_ATIME' => 1557981471,'_SESSION_ID' => '6cd3d053557d46298a1fbaa7d054b402','_SESSION_CTIME' => 1557981471};;$D \ No newline at end of file diff --git a/dbLifeLog/cgisess_6e1acbdb23deb67566251ee45a9d5904 b/dbLifeLog/cgisess_6e1acbdb23deb67566251ee45a9d5904 new file mode 100644 index 0000000..440fec4 --- /dev/null +++ b/dbLifeLog/cgisess_6e1acbdb23deb67566251ee45a9d5904 @@ -0,0 +1 @@ +$D = {'_SESSION_ATIME' => 1557960216,'_SESSION_REMOTE_ADDR' => '127.0.0.1','_SESSION_ID' => '6e1acbdb23deb67566251ee45a9d5904','_SESSION_CTIME' => 1557960216,'_SESSION_ETIME' => 1800};;$D \ No newline at end of file diff --git a/dbLifeLog/cgisess_7dcd14aff3b905fd46843d20c85dc47c b/dbLifeLog/cgisess_7dcd14aff3b905fd46843d20c85dc47c new file mode 100644 index 0000000..190bbd2 --- /dev/null +++ b/dbLifeLog/cgisess_7dcd14aff3b905fd46843d20c85dc47c @@ -0,0 +1 @@ +$D = {'_SESSION_REMOTE_ADDR' => '127.0.0.1','_SESSION_CTIME' => 1557974481,'_SESSION_ID' => '7dcd14aff3b905fd46843d20c85dc47c','_SESSION_ATIME' => 1557974481};;$D \ No newline at end of file diff --git a/dbLifeLog/cgisess_ab26eaf0df06205e2e479dd9e73e2a5e b/dbLifeLog/cgisess_ab26eaf0df06205e2e479dd9e73e2a5e new file mode 100644 index 0000000..b94b8ec --- /dev/null +++ b/dbLifeLog/cgisess_ab26eaf0df06205e2e479dd9e73e2a5e @@ -0,0 +1 @@ +$D = {'passw' => '42FAP5H0JUSZM','alias' => 'admin','_SESSION_CTIME' => 1558001039,'_SESSION_ETIME' => 1800,'_SESSION_ID' => 'ab26eaf0df06205e2e479dd9e73e2a5e','_SESSION_ATIME' => 1558002630,'database' => 'data_admin_log.db','_SESSION_REMOTE_ADDR' => '127.0.0.1'};;$D \ No newline at end of file diff --git a/dbLifeLog/cgisess_b03f7e44a56d832aca12b2d0d9885dc5 b/dbLifeLog/cgisess_b03f7e44a56d832aca12b2d0d9885dc5 new file mode 100644 index 0000000..afca6e1 --- /dev/null +++ b/dbLifeLog/cgisess_b03f7e44a56d832aca12b2d0d9885dc5 @@ -0,0 +1 @@ +$D = {'_SESSION_ATIME' => 1557965056,'_SESSION_CTIME' => 1557965056,'_SESSION_ID' => 'b03f7e44a56d832aca12b2d0d9885dc5','_SESSION_REMOTE_ADDR' => '127.0.0.1'};;$D \ No newline at end of file diff --git a/dbLifeLog/cgisess_e01dfa0dd28affb0d00b72bfff0ff303 b/dbLifeLog/cgisess_e01dfa0dd28affb0d00b72bfff0ff303 new file mode 100644 index 0000000..cbff52f --- /dev/null +++ b/dbLifeLog/cgisess_e01dfa0dd28affb0d00b72bfff0ff303 @@ -0,0 +1 @@ +$D = {'_SESSION_CTIME' => 1557995553,'_SESSION_ATIME' => 1557995553,'_SESSION_ID' => 'e01dfa0dd28affb0d00b72bfff0ff303','_SESSION_REMOTE_ADDR' => '127.0.0.1'};;$D \ No newline at end of file diff --git a/dbLifeLog/cgisess_e0bd04e8964c3adabaa754ad2fc1a286 b/dbLifeLog/cgisess_e0bd04e8964c3adabaa754ad2fc1a286 new file mode 100644 index 0000000..d687593 --- /dev/null +++ b/dbLifeLog/cgisess_e0bd04e8964c3adabaa754ad2fc1a286 @@ -0,0 +1 @@ +$D = {'_SESSION_ID' => 'e0bd04e8964c3adabaa754ad2fc1a286','_SESSION_ATIME' => 1557983463,'_SESSION_REMOTE_ADDR' => '127.0.0.1','_SESSION_CTIME' => 1557983463};;$D \ No newline at end of file diff --git a/dbLifeLog/cgisess_e373ebf22622cc8b85b94edab5974e30 b/dbLifeLog/cgisess_e373ebf22622cc8b85b94edab5974e30 new file mode 100644 index 0000000..a9e4bd7 --- /dev/null +++ b/dbLifeLog/cgisess_e373ebf22622cc8b85b94edab5974e30 @@ -0,0 +1 @@ +$D = {'_SESSION_CTIME' => 1557960412,'_SESSION_ATIME' => 1557960412,'_SESSION_ETIME' => 1800,'_SESSION_REMOTE_ADDR' => '127.0.0.1','_SESSION_ID' => 'e373ebf22622cc8b85b94edab5974e30'};;$D \ No newline at end of file diff --git a/dbLifeLog/cgisess_e50018bbed297ea9dce239beac458c17 b/dbLifeLog/cgisess_e50018bbed297ea9dce239beac458c17 new file mode 100644 index 0000000..5c293df --- /dev/null +++ b/dbLifeLog/cgisess_e50018bbed297ea9dce239beac458c17 @@ -0,0 +1 @@ +$D = {'_SESSION_ID' => 'e50018bbed297ea9dce239beac458c17','_SESSION_REMOTE_ADDR' => '127.0.0.1','_SESSION_CTIME' => 1557986965,'_SESSION_ATIME' => 1557986965};;$D \ No newline at end of file diff --git a/htdocs/cgi-bin/main.cgi b/htdocs/cgi-bin/main.cgi index 88c064f..ab45a67 100755 --- a/htdocs/cgi-bin/main.cgi +++ b/htdocs/cgi-bin/main.cgi @@ -65,10 +65,12 @@ my $tbl_rc_prev = 0; my $tbl_cur_id; my $rs_keys = $cgi->param('keywords'); my $rs_cat_idx = $cgi->param('category'); +my $prm_vc = $cgi->param("vc"); my $rs_dat_from = $cgi->param('v_from'); my $rs_dat_to = $cgi->param('v_to'); -my $rs_prev = $cgi->param('rs_prev'); +my $rs_prev = $cgi->param('rs_prev'); my $rs_cur = $cgi->param('rs_cur'); +my $rs_page = $cgi->param('rs_page'); my $stmS = "SELECT rowid, ID_CAT, DATE, LOG, AMMOUNT from LOG WHERE"; my $stmE = " ORDER BY DATE DESC;"; my $stmD = ""; @@ -133,12 +135,13 @@ my $cats = qq('; + + + my $cat_descriptions = ""; for my $key (keys %desc){ my $kv = $desc{$key}; @@ -170,9 +182,13 @@ my $tbl = qq(
CategoryEdit ); +if($prm_vc){#view category form selection + $rs_cat_idx = $prm_vc; +} + if($rs_keys){ - my @keywords = split / /, $rs_keys; + my @keywords = split / /, $rs_keys; if($rs_cat_idx){ $stmS = $stmS ." ID_CAT='".$rs_cat_idx."' AND"; }else{ @@ -195,12 +211,12 @@ if($rs_keys){ } elsif($rs_cat_idx){ - if($stmD){ - $stmt = $stmS.$stmD. " AND ID_CAT='".$rs_cat_idx."'" .$stmE; - } - else{ - $stmt = $stmS." ID_CAT='".$rs_cat_idx."'" .$stmE; - } + if($stmD){ + $stmt = $stmS.$stmD. " AND ID_CAT='".$rs_cat_idx."'" .$stmE; + } + else{ + $stmt = $stmS." ID_CAT='".$rs_cat_idx."'" .$stmE; + } } else{ if($stmD){ @@ -214,16 +230,16 @@ else{ &processSubmit; ############### # - # Enable to see main query statement issued! - #print $cgi->pre("### -> ".$stmt); + # Uncomment bellow to see main query statement issued! +# print $cgi->pre("### -> ".$stmt); + # my $tfId = 0; my $id = 0; my $tbl_start = index $stmt, "<="; my $re_a_tag = qr/.*<\/a>/si ; if($tbl_start>0){ - #check if we are at the beggining of the LOG table? - + #check if we are at the beggining of the LOG table? my $stc = $db->prepare('select rowid from LOG order by rowid DESC LIMIT 1;'); $stc->execute(); my @row =$stc->fetchrow_array(); @@ -384,12 +400,13 @@ while(my @row = $st->fetchrow_array()) { $tbl_rc += 1; if($REC_LIMIT>0 && $tbl_rc==$REC_LIMIT){ - &buildNavigationButtons; last; } -} +}#while end + +## #Fetch Keywords autocomplete we go by words larger then three. # $st = $db->prepare( 'select LOG from LOG;' ); @@ -399,45 +416,7 @@ $rv = $st->execute() or die or die "

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

"; if($rv < 0) { print "

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

"; } -while(my @row = $st->fetchrow_array()) { - my $log = $row[0]; - #Decode escaped \\n - $log =~ s/\\n/\n/gs; - $log =~ s/''/'/g; - #Replace link to empty string - my @words = split(/($re_a_tag)/si , $log) ; - foreach my $ch_i ( @words ) { - next if $ch_i =~ /$re_a_tag/; - next if index($ch_i, "-1; - $ch_i =~ s/https//gsi; - $ch_i =~ s/($RE{URI}{HTTP})//gsi; - } - $log = join(' ' , @words); - @words = split(' ', $log) ; - foreach my $word (@words) { - #remove all non alphanumerics - $word =~ s/[^a-zA-Z]//gs; - if(length($word)>2){ - $word = lc $word; - #parse for already placed words, instead of using an hash. - my $idx = index($autows, $word,0); - if($idx>0){ - my $end = index($autows,'"', $idx); - my $existing = substr($autows, $idx, $end - $idx); - next if $word eq $existing; - } - - $autows .= qq(,"$word"); - if($aw_cnt++>$AUTO_WRD_LMT){ - last; - } - } - } - -if($aw_cnt>$AUTO_WRD_LMT){ - last; -} -} +&fetchAutocomplete; #End of table? if($rs_prev && $tbl_rc < $REC_LIMIT){ @@ -518,6 +497,7 @@ $cats + $tags ); @@ -529,8 +509,8 @@ my $srh = qq( Search/View By ); -$cats =~ s/selected//g; -$srh .= qq(View by Category:$cats + +$srh .= qq(View by Category:$cats_v @@ -630,13 +610,22 @@ try{ $REC_LIMIT = 0; } - if($view_mode && $view_mode == "1"){ + if($view_mode == "1"){ if($rs_cur){ - $stmt = 'SELECT rowid, ID_CAT, DATE, LOG, AMMOUNT from LOG - where rowid <= "'.$rs_cur.'" ORDER BY DATE DESC;'; - return; - } + + if($rs_cur==$rs_prev){#Mid page back button if id ordinal. + $rs_cur += $REC_LIMIT; + $rs_prev =$rs_cur; + $rs_page--; + } + else{ + $rs_page++; + } + + $stmt = 'SELECT rowid, ID_CAT, DATE, LOG, AMMOUNT from LOG where rowid <= "'.$rs_cur.'" ORDER BY DATE DESC;;;'.$rs_page; + return; + } } if($log && $date && $cat){ @@ -666,8 +655,7 @@ try{ print $cgi->p('Insert is in the past!'); #Renumerate directly (not proper SQL but faster); $st = $db->prepare('select rowid from LOG ORDER BY DATE;'); - $st->execute(); - my @row = $st->fetchrow_array(); + $st->execute(); my $cnt = 1; while(my @row = $st->fetchrow_array()) { my $st_upd = $db->prepare("UPDATE LOG SET rowid=".$cnt. @@ -701,7 +689,7 @@ sub buildNavigationButtons{ $tbl .= qq!!; - if($rs_prev && $rs_prev>0 && $tbl_start>0){ + if($rs_prev && $rs_prev>0 && $tbl_start>0 && $rs_page>0){ $tbl = $tbl . qq! fetchrow_array()) { + my $log = $row[0]; + #Decode escaped \\n + $log =~ s/\\n/\n/gs; + $log =~ s/''/'/g; + #Replace link to empty string + my @words = split(/($re_a_tag)/si , $log) ; + foreach my $ch_i ( @words ) { + next if $ch_i =~ /$re_a_tag/; + next if index($ch_i, "-1; + $ch_i =~ s/https//gsi; + $ch_i =~ s/($RE{URI}{HTTP})//gsi; + } + $log = join(' ' , @words); + @words = split(' ', $log) ; + foreach my $word (@words) { + #remove all non alphanumerics + $word =~ s/[^a-zA-Z]//gs; + if(length($word)>2){ + $word = lc $word; + #parse for already placed words, instead of using an hash. + my $idx = index($autows, $word,0); + if($idx>0){ + my $end = index($autows,'"', $idx); + my $existing = substr($autows, $idx, $end - $idx); + next if $word eq $existing; + } + + $autows .= qq(,"$word"); + if($aw_cnt++>$AUTO_WRD_LMT){ + last; + } + } + } + + if($aw_cnt>$AUTO_WRD_LMT){ + last; + } + } + + + + } + catch{ + print "SERVER ERROR:".$_; + } +} sub getConfiguration{ my $db = shift; diff --git a/htdocs/cgi-bin/wsrc/main.js b/htdocs/cgi-bin/wsrc/main.js index 4b14eef..532b038 100644 --- a/htdocs/cgi-bin/wsrc/main.js +++ b/htdocs/cgi-bin/wsrc/main.js @@ -42,7 +42,7 @@ function loadedBody(toggle) { allowTipHover: false }); $('#el').poshytip({ - content: "This is your log entry can't be empty.", + content: "This is the log entry, can't be left empty.", className: 'tip-yellowsimple', showOn: 'focus', alignTo: 'target', @@ -77,7 +77,7 @@ function loadedBody(toggle) { _MAP.set(children[i].id, children[i].innerHTML); } - + helpSelCategory($('#ec')); } @@ -276,28 +276,31 @@ function resetView() { } function updateSelCategory(sel) { - var cat = document.getElementById("idx_cat"); - cat.value = sel.options[sel.selectedIndex].value; + if (sel.id == "ec") { + var cat = document.getElementById("idx_cat"); + cat.value = sel.options[sel.selectedIndex].value; + } } function toggleVisibility(target, ensureOff) { - var d = document.getElementById(target); - if (d.style.display === "none" || d.style.display === "" && !ensureOff) { - d.style.display = "block"; + if (!ensureOff) { + $(target).toggle(); } else { - d.style.display = "none"; + $(target).hide(); } } function helpSelCategory(sel) { - var el = document.getElementById("cat_desc"); + var desc = _MAP.get(sel.options[sel.selectedIndex].value); if (!desc) { desc = "Please select a Category!"; } - el.innerHTML = desc; + document.getElementById("cat_desc").innerHTML = desc; + $('#cat_desc').show(); + $('#cat_desc').fadeOut(5000); } function viewByCategory(btn) { -- 2.34.1