From ff2b799ac8aefb2329efd94d0243e1dc1c389943 Mon Sep 17 00:00:00 2001 From: Metabox Date: Tue, 1 Oct 2019 04:22:41 +1000 Subject: [PATCH] CSV Export and layout, updated. --- htdocs/cgi-bin/config.cgi | 144 +++++++++++++++--------------------- htdocs/cgi-bin/wsrc/main.js | 24 ++++-- 2 files changed, 80 insertions(+), 88 deletions(-) diff --git a/htdocs/cgi-bin/config.cgi b/htdocs/cgi-bin/config.cgi index d304e81..d1b2301 100755 --- a/htdocs/cgi-bin/config.cgi +++ b/htdocs/cgi-bin/config.cgi @@ -66,22 +66,17 @@ my $db = DBI->connect($dsn, $userid, $password, { RaiseError => 1 }) or die "

my $rv; my $dbs; my $today = DateTime->now; -my $lang = Date::Language->new($LANGUAGE); +my $lang = Date::Language->new($LANGUAGE); my $tz = $cgi->param('tz'); my $csvp = $cgi->param('csv'); - switch ($csvp){ - case "1" {&exportLogToCSV} - case "2" {&exportLogToCSV} - case "3" {&exportCategoriesToCSV} - case "4" {&exportCategoriesToCSV} - } - - if($cgi->param('data_cat')){ - &importCatCSV; - }elsif($cgi->param('data_log')){ - &importLogCSV; - } +&exportToCSV if ($csvp); + +if($cgi->param('data_cat')){ + &importCatCSV; +}elsif($cgi->param('data_log')){ + &importLogCSV; +} ##################### &getConfiguration; @@ -338,42 +333,44 @@ my $frmPASS = qq( print qq(

$frm
-
$frmVars
+
$frmVars
$frmDB
$frmPASS
-  Configuration status -> $status 
-
-

- - - - +  Configuration status -> $status  + +
+
+

CSV File Format

+ + - - - - - - -

CSV File Format

Import Categories:
-
- Import Log:
-

To Server -> $sys -> $dbname

+ + + + Export Categories: +   + + +
+ + Import Log: + + +
+ Export Log: +   + + +

For Server -> $sys -> $dbname

+
↟ Go to Top of page - -
   [Export Log to CSV]   - [View the Log in CSV Format]
-
[Export Categories to CSV]   - [View the Categories in CSV Format]
-
+
-
-
-

L-Tags Specs

+
+

L-Tags Specs

Life Log Tags are simple markup allowing fancy formatting and functionality for your logs HTML layout. @@ -424,9 +421,12 @@ print qq(


- ); - -print '
'; + +
+
+

Back to Main Log

LOGOUT

+
+); print $cgi->end_html; @@ -913,56 +913,34 @@ sub updCnf { } } -sub exportLogToCSV { - try{ - - my $csv = Text::CSV->new ( { binary => 1, strict => 1 , quote_space=>1, auto_diag => 1, eol => $/} ); - $dbs = dbExecute("SELECT * FROM LOG;"); - if($csvp==2){ - print $cgi->header(-charset=>"UTF-8", -type=>"text/html"); - print "
\n";
-            }
-            else{
-                 print $cgi->header(-charset=>"UTF-8", -type=>"application/octet-stream", -attachment=>"$dbname.csv");
-            }
-            
-         # print "ID_CAT,DATE,LOG,AMOUNT, AFLAG\n";
-            while (my $r=$dbs->fetchrow_arrayref()){ 
-                         print $csv->print(*STDOUT, $r)."\n";
-            }
-            if($csvp==1){			
-                 print "
"; - } - $dbs->finish(); - $db->disconnect(); - exit; - } - catch{ - print "SERVER ERROR->exportLogToCSV:".$_; - } -} -sub exportCategoriesToCSV { +sub exportToCSV { try{ - my $csv = Text::CSV->new ( { binary => 1, strict => 1,eol => $/ } ); - $dbs = dbExecute("SELECT ID, NAME, DESCRIPTION FROM CAT ORDER BY ID;"); - if($csvp==4){ - print $cgi->header(-charset=>"UTF-8", -type=>"text/html"); + if($csvp > 2){ + $dbs = dbExecute("SELECT ID, NAME, DESCRIPTION FROM CAT ORDER BY ID;"); + } + else{ + $dbs = dbExecute("SELECT * FROM LOG;"); + } + + if($csvp==2 || $csvp==4){ + print $cgi->header(-charset=>"UTF-8", -type=>"text/html"); print "
\n";
         }
         else{
          print $cgi->header(-charset=>"UTF-8", -type=>"application/octet-stream", -attachment=>"$dbname.categories.csv");
         }
-            
+
         #print "ID,NAME,DESCRIPTION\n";
-        while (my $row=$dbs->fetchrow_arrayref()){ 
-                print $csv->print(*STDOUT, $row),"\n";
+        while (my $row=$dbs->fetchrow_arrayref()){
+               my $out = $csv->print(*STDOUT, $row);
+                  print $out if(length $out>1);
         }
-        if($csvp==4){			
+        if($csvp==2 || $csvp==4){
              print "
"; - } - $dbs->finish(); + } + $dbs->finish(); $db->disconnect(); exit; } diff --git a/htdocs/cgi-bin/wsrc/main.js b/htdocs/cgi-bin/wsrc/main.js index 669566e..d11ae21 100644 --- a/htdocs/cgi-bin/wsrc/main.js +++ b/htdocs/cgi-bin/wsrc/main.js @@ -207,8 +207,8 @@ function validTime(val) { var fld = $("frm_entry").date; if (val != '') { if (regs = val.match(re)) { - // 12-hour value between 1 and 12 - if (regs[1] < 1 || regs[1] > 23) { + // 12-hour value between 0 and 24 + if (regs[1] < 0 || regs[1] > 23) { alert("Invalid value for hours: " + regs[1]); fld.focus(); return false; @@ -236,7 +236,6 @@ function validTime(val) { function validLog(log) { if (log == "") { - alert("Log -> entry can't be empty, can't submit!"); return false; } @@ -416,6 +415,7 @@ function resetView() { $("#frm_srch input").val(""); $("#idx_cat").val(0); $('#vc>option[value="0"]').prop('selected', true); + $('#xc>option[value="0"]').prop('selected', true); $("#frm_srch").submit(); } @@ -566,8 +566,12 @@ function display(desc){ } function viewByCategory(btn) { - $("#rs_keys").value = ""; + $("#vx").value = "0"; +} +function viewExcludeCategory(btn) { + $("#rs_keys").value = ""; + $("#xc").value = "0"; } function viewByDate(btn) { @@ -655,7 +659,7 @@ function saveRTFResult(result) { RTF_SUBMIT = false; } -function loadRTF(under, id){ +function loadRTF(under, id){ //show under log entry the document if(under){ @@ -749,3 +753,13 @@ function RGBToHex(rgb) { return "#" + r + g + b; } + + +function exportToCSV(dat, view){ + var csv; + if(dat == 'cat'){ csv = view ? 4:3; } + else + if(dat == 'log'){ csv = view ? 2:1; } + window.location = "config.cgi?csv="+csv; +} + -- 2.34.1